From 46320e5d67cb1dae3ca812400bd85ab1ae7d36ef Mon Sep 17 00:00:00 2001 From: Chris Burnell Date: Mon, 19 Feb 2024 17:00:57 +0800 Subject: [PATCH] refactor: don't need linearGradient for fills; fix: values of 0 should not be filled underneath --- README.md | 32 +++++++++++----------- demo.html | 71 +++++++++++++++++++++++++----------------------- package.json | 2 +- svg-sparkline.js | 12 ++++++-- 4 files changed, 63 insertions(+), 54 deletions(-) diff --git a/README.md b/README.md index 2e85e2c..0d40b1f 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 cdc52dc..ff99045 100644 --- a/demo.html +++ b/demo.html @@ -15,73 +15,76 @@ -

General usage example

+

General usage example

- +

-

With curve

+

With curve

- +

-

Start and End labels

+

Start and End labels

- +

-

Animated

+

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 Duration

- +

-

Defined Animation Delay

+

Defined Animation Delay

- +

-

Defined color

+

Defined color

- +

-

With gradient

+

With gradient

- +

-

Defined gradient color

+

Defined gradient color

- +

-

Filled

+

Filled

- +

-

Defined fill color

+

Defined fill color

- +

-

Defined endpoint color

+

Defined endpoint color

- +

-

Without endpoint

+

Without endpoint

- +

-

Defined endpoint width

+

Defined endpoint width

- +

-

Defined line width

+

Defined line width

+

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

- +

-

Defined width and height

+

Defined width and height

- +

-

Server-rendered and hydrated

+

Server-rendered and hydrated

- + Start Sparkline ranging from 1 to 10. diff --git a/package.json b/package.json index fc6f01d..c25e681 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@chrisburnell/svg-sparkline", - "version": "1.0.6", + "version": "1.0.7", "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 b75da92..9e9bff6 100644 --- a/svg-sparkline.js +++ b/svg-sparkline.js @@ -112,8 +112,9 @@ class SVGSparkline extends HTMLElement { Sparkline ranging from ${this.getMinY(this.values)} to ${this.getMaxY(this.values)}. `) - if (this.gradient || this.fill) { - const gradientID = this.makeID(6) + let gradientID + if (this.gradient) { + gradientID = this.makeID(6) content.push(` @@ -121,6 +122,11 @@ class SVGSparkline extends HTMLElement { + `) + } + + if (this.gradient || this.fill) { + content.push(`