diff --git a/README.md b/README.md index 0d40b1f..55b41db 100644 --- a/README.md +++ b/README.md @@ -15,97 +15,97 @@ A Web Component that builds an SVG Sparkline. ```html - + ``` ### With curve ```html - + ``` ### Start and End labels ```html - + ``` ### Animated ```html - + ``` ### Defined Animation Duration ```html - + ``` ### Defined Animation Delay ```html - + ``` ### Defined color ```html - + ``` ### With gradient ```html - + ``` ### Defined gradient color ```html - + ``` ### Filled ```html - + ``` ### Defined fill color ```html - + ``` ### Defined endpoint color ```html - + ``` ### Defined endpoint width ```html - + ``` ### Without endpoint ```html - + ``` ### Defined line width ```html - + ``` ### Defined width and height ```html - + ``` ## Features diff --git a/demo.html b/demo.html index ff99045..3ac16db 100644 --- a/demo.html +++ b/demo.html @@ -17,74 +17,74 @@

General usage example

- +

With curve

- +

Start and End labels

- +

Animated

Only animates when the prefers-reduced-motion media query has the value no-preference.

Waits until the sparkline is visible in the viewport to initate the animation.

- +

Defined Animation Duration

- +

Defined Animation Delay

- +

Defined color

- +

With gradient

- +

Defined gradient color

- +

Filled

- +

Defined fill color

- +

Defined endpoint color

- +

Without endpoint

- +

Defined endpoint width

- +

Defined line width

Doesn’t look great when the line-width is greater than the endpoint-width!

- +

Defined width and height

- +

Server-rendered and hydrated

- + Start Sparkline ranging from 1 to 10. diff --git a/package.json b/package.json index 1413967..a73952b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@chrisburnell/svg-sparkline", - "version": "1.0.8", + "version": "1.0.9", "description": "A Web Component that builds an SVG Sparkline.", "main": "svg-sparkline.js", "scripts": { diff --git a/svg-sparkline.js b/svg-sparkline.js index 6b96d58..8833782 100644 --- a/svg-sparkline.js +++ b/svg-sparkline.js @@ -19,7 +19,8 @@ class SVGSparkline extends HTMLElement { padding: var(--svg-sparkline-padding, 0.375rem); overflow: visible; } - svg:has(title) { + :host(:not([curve])) svg:has(title), + :host(:not([curve="true"])) svg:has(title) { overflow-y: hidden; } svg[aria-hidden] { @@ -282,11 +283,11 @@ class SVGSparkline extends HTMLElement { return [x, y] } - bezierCommand(point, i, a) { + bezierCommand(point, i, a, maxY) { const [csx, csy] = this.controlPoint(i - 1, a[i - 1], i - 2, a[i - 2], i, point) const [cex, cey] = this.controlPoint(i, point, i - 1, a[i - 1], i + 1, a[i + 1], true) - return `C ${this.maxDecimals(csx)},${this.maxDecimals(csy)} ${this.maxDecimals(cex)},${this.maxDecimals(cey)} ${i},${point}` + return `C ${this.maxDecimals(csx)},${Math.min(maxY, this.maxDecimals(csy))} ${this.maxDecimals(cex)},${Math.min(maxY, this.maxDecimals(cey))} ${i},${point}` } getPath(values, curve) { @@ -296,7 +297,7 @@ class SVGSparkline extends HTMLElement { .map((point) => Math.max(...values) - point + 1) // generate a string .reduce((acc, point, i, a) => { - return i < 1 ? `M 0,${point}` : `${acc} ${curve ? this.bezierCommand(point, i, a) : this.lineCommand(point, i)}` + return i < 1 ? `M 0,${point}` : `${acc} ${curve ? this.bezierCommand(point, i, a, this.getAdjustedMaxY(values)) : this.lineCommand(point, i)}` }, "") ) }