tiny-spark 0.4.2 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -35,11 +35,14 @@ Calling render again will re-trigger the animation (if data-animation is set to
35
35
  Just set up a div with a "tiny-spark" class, with a few data attributes to configure the chart.
36
36
  Note that providing data-id is optional, a unique id will be generated if you don't.
37
37
 
38
+ Render a line chart:
39
+
38
40
  ```html
39
41
  <div style="width: 100%">
40
42
  <div
41
43
  class="tiny-spark"
42
44
  data-id="myId"
45
+ data-type="line"
43
46
  data-curve="true"
44
47
  data-set="[1, 2, 3, 5, 8, 13]"
45
48
  data-dates='["01-2026", "02-2026", "03-2026", "04-2026", "05-2026", "06-2026"]'
@@ -62,6 +65,30 @@ Note that providing data-id is optional, a unique id will be generated if you do
62
65
  </div>
63
66
  ```
64
67
 
68
+ Render a bar chart:
69
+
70
+ ```html
71
+ <div style="width: 100%">
72
+ <div
73
+ class="tiny-spark"
74
+ data-id="myId"
75
+ data-type="bar"
76
+ data-set="[1, 2, 3, 5, 8, 13]"
77
+ data-dates='["01-2026", "02-2026", "03-2026", "04-2026", "05-2026", "06-2026"]'
78
+ data-responsive
79
+ data-animation="true"
80
+ data-line-thickness="4"
81
+ data-plot-color="#2A2A2A"
82
+ data-number-locale="en-US"
83
+ data-number-rounding="2"
84
+ data-indicator-width="0"
85
+ data-show-last-value="true"
86
+ data-last-value-font-size="12"
87
+ data-last-value-color="#1A1A1A"
88
+ ></div>
89
+ </div>
90
+ ```
91
+
65
92
  ## Styling
66
93
 
67
94
  tiny-spark is headless.
@@ -1,253 +1,279 @@
1
- const I = "http://www.w3.org/2000/svg";
2
- var l = /* @__PURE__ */ ((t) => (t.ANIMATION = "animation", t.AREA_COLOR = "areaColor", t.CURVE = "curve", t.DATES = "dates", t.ID = "id", t.INDICATOR_COLOR = "indicatorColor", t.INDICATOR_WIDTH = "indicatorWidth", t.LINE_COLOR = "lineColor", t.LINE_THICKNESS = "lineThickness", t.NUMBER_LOCALE = "numberLocale", t.NUMBER_ROUNDING = "numberRounding", t.NUMBER_SHOW_ON = "numberShowOn", t.PLOT_COLOR = "plotColor", t.PLOT_RADIUS = "plotRadius", t.SET = "set", t.HIDE_PLOTS_ABOVE = "hidePlotsAbove", t.SHOW_LAST_VALUE = "showLastValue", t.LAST_VALUE_FONT_SIZE = "lastValueFontSize", t.LAST_VALUE_COLOR = "lastValueColor", t))(l || {}), z = /* @__PURE__ */ ((t) => (t.ANIMATION = "data-animation", t.AREA_COLOR = "data-area-color", t.CURVE = "data-curve", t.DATES = "data-dates", t.ID = "data-id", t.INDICATOR_COLOR = "data-indicator-color", t.INDICATOR_WIDTH = "data-indicator-width", t.LINE_COLOR = "data-line-color", t.LINE_THICKNESS = "data-line-thickness", t.NUMBER_LOCALE = "data-number-locale", t.NUMBER_ROUNDING = "data-number-rounding", t.NUMBER_SHOW_ON = "data-number-show-on", t.PLOT_COLOR = "data-plot-color", t.PLOT_RADIUS = "data-plot-radius", t.SET = "data-set", t.HIDE_PLOTS_ABOVE = "data-hide-plots-above", t.SHOW_LAST_VALUE = "data-show-last-value", t.LAST_VALUE_FONT_SIZE = "data-last-value-font-size", t.LAST_VALUE_COLOR = "data-last-value-color", t))(z || {});
3
- function J(t) {
4
- const { width: r, height: n } = t.parentElement.getBoundingClientRect(), o = { width: 300, height: 100 }, s = String(a(t, l.SHOW_LAST_VALUE, "false")) === "true", i = j(t), d = i && i.length ? i.at(-1) : null;
5
- let e = 0;
6
- if (s && ![null, void 0].includes(d)) {
7
- const u = Number(String(a(t, l.NUMBER_ROUNDING, 0)));
8
- e = 6 + d.toFixed(u).length * (Number(a(t, l.LAST_VALUE_FONT_SIZE, 12)) / 2);
1
+ const w = "http://www.w3.org/2000/svg";
2
+ var Y = /* @__PURE__ */ ((t) => (t.BAR = "bar", t.LINE = "line", t))(Y || {}), f = /* @__PURE__ */ ((t) => (t.ANIMATION = "animation", t.AREA_COLOR = "areaColor", t.CURVE = "curve", t.DATES = "dates", t.ID = "id", t.INDICATOR_COLOR = "indicatorColor", t.INDICATOR_WIDTH = "indicatorWidth", t.LINE_COLOR = "lineColor", t.LINE_THICKNESS = "lineThickness", t.NUMBER_LOCALE = "numberLocale", t.NUMBER_ROUNDING = "numberRounding", t.NUMBER_SHOW_ON = "numberShowOn", t.PLOT_COLOR = "plotColor", t.PLOT_RADIUS = "plotRadius", t.SET = "set", t.HIDE_PLOTS_ABOVE = "hidePlotsAbove", t.SHOW_LAST_VALUE = "showLastValue", t.LAST_VALUE_FONT_SIZE = "lastValueFontSize", t.LAST_VALUE_COLOR = "lastValueColor", t))(f || {}), Q = /* @__PURE__ */ ((t) => (t.ANIMATION = "data-animation", t.AREA_COLOR = "data-area-color", t.CURVE = "data-curve", t.DATES = "data-dates", t.ID = "data-id", t.INDICATOR_COLOR = "data-indicator-color", t.INDICATOR_WIDTH = "data-indicator-width", t.LINE_COLOR = "data-line-color", t.LINE_THICKNESS = "data-line-thickness", t.NUMBER_LOCALE = "data-number-locale", t.NUMBER_ROUNDING = "data-number-rounding", t.NUMBER_SHOW_ON = "data-number-show-on", t.PLOT_COLOR = "data-plot-color", t.PLOT_RADIUS = "data-plot-radius", t.SET = "data-set", t.HIDE_PLOTS_ABOVE = "data-hide-plots-above", t.SHOW_LAST_VALUE = "data-show-last-value", t.LAST_VALUE_FONT_SIZE = "data-last-value-font-size", t.LAST_VALUE_COLOR = "data-last-value-color", t))(Q || {});
3
+ function ot(t) {
4
+ const { width: n, height: e } = t.parentElement.getBoundingClientRect(), o = { width: 300, height: 100 }, l = String(y(t, f.SHOW_LAST_VALUE, "false")) === "true", r = et(t), h = r && r.length ? r.at(-1) : null;
5
+ let i = 0;
6
+ if (!(t.dataset.type && t.dataset.type === "bar") && l && ![null, void 0].includes(h)) {
7
+ const I = Number(String(y(t, f.NUMBER_ROUNDING, 0)));
8
+ i = 6 + h.toFixed(I).length * (Number(y(t, f.LAST_VALUE_FONT_SIZE, 12)) / 2);
9
9
  }
10
- const p = `0 0 ${(r || o.width) + e} ${n || o.height}`, O = document.createElementNS(I, "svg"), L = t.dataset.id;
11
- return O.id = L, O.setAttribute("viewBox", p), O.style.width = "100%", O.style.height = "100%", {
12
- svg: O,
13
- svgId: L,
14
- width: r || o.width,
15
- height: n || o.height
10
+ const O = `0 0 ${(n || o.width) + i} ${e || o.height}`, S = document.createElementNS(w, "svg"), $ = t.dataset.id;
11
+ return S.id = $, S.setAttribute("viewBox", O), S.style.width = "100%", S.style.height = "100%", {
12
+ svg: S,
13
+ svgId: $,
14
+ width: n || o.width,
15
+ height: e || o.height,
16
+ viewBox: O
16
17
  };
17
18
  }
18
- function N(t, r = 0) {
19
- return isNaN(t) ? r : t;
19
+ function v(t, n = 0) {
20
+ return isNaN(t) ? n : t;
20
21
  }
21
- function W(t) {
22
- let r = [];
23
- for (let n = 0; n < t.length; n += 1)
24
- r.push(`${N(t[n].x)},${N(t[n].y)} `);
25
- return r.join(" ").trim();
22
+ function j(t) {
23
+ let n = [];
24
+ for (let e = 0; e < t.length; e += 1)
25
+ n.push(`${v(t[e].x)},${v(t[e].y)} `);
26
+ return n.join(" ").trim();
26
27
  }
27
- function B(t) {
28
+ function X(t) {
28
29
  if (t.length < 1) return "0,0";
29
- const r = t.length - 1, n = [`${N(t[0].x)},${N(t[0].y)}`], o = [], s = [], i = [], d = [];
30
- for (let e = 0; e < r; e += 1)
31
- o[e] = t[e + 1].x - t[e].x, s[e] = t[e + 1].y - t[e].y, i[e] = s[e] / o[e];
32
- d[0] = i[0], d[r] = i[r - 1];
33
- for (let e = 1; e < r; e += 1)
34
- if (i[e - 1] * i[e] <= 0)
35
- d[e] = 0;
30
+ const n = t.length - 1, e = [`${v(t[0].x)},${v(t[0].y)}`], o = [], l = [], r = [], h = [];
31
+ for (let i = 0; i < n; i += 1)
32
+ o[i] = t[i + 1].x - t[i].x, l[i] = t[i + 1].y - t[i].y, r[i] = l[i] / o[i];
33
+ h[0] = r[0], h[n] = r[n - 1];
34
+ for (let i = 1; i < n; i += 1)
35
+ if (r[i - 1] * r[i] <= 0)
36
+ h[i] = 0;
36
37
  else {
37
- const m = 2 * i[e - 1] * i[e] / (i[e - 1] + i[e]);
38
- d[e] = m;
38
+ const a = 2 * r[i - 1] * r[i] / (r[i - 1] + r[i]);
39
+ h[i] = a;
39
40
  }
40
- for (let e = 0; e < r; e += 1) {
41
- const m = t[e].x, p = t[e].y, O = t[e + 1].x, L = t[e + 1].y, u = d[e], _ = d[e + 1], R = m + (O - m) / 3, A = p + u * (O - m) / 3, k = O - (O - m) / 3, C = L - _ * (O - m) / 3;
42
- n.push(`C ${N(R)},${N(A)} ${N(k)},${N(C)} ${N(O)},${N(L)}`);
41
+ for (let i = 0; i < n; i += 1) {
42
+ const a = t[i].x, L = t[i].y, O = t[i + 1].x, S = t[i + 1].y, $ = h[i], I = h[i + 1], c = a + (O - a) / 3, x = L + $ * (O - a) / 3, R = O - (O - a) / 3, P = S - I * (O - a) / 3;
43
+ e.push(`C ${v(c)},${v(x)} ${v(R)},${v(P)} ${v(O)},${v(S)}`);
43
44
  }
44
- return n.join(" ");
45
+ return e.join(" ");
45
46
  }
46
- function Y(t, r = 1e3, n) {
47
+ function st(t, n = 1e3, e) {
47
48
  t.style.opacity = "1";
48
49
  const o = t.getTotalLength();
49
- t.style.strokeDasharray = String(o), t.style.strokeDashoffset = String(o), t.getBoundingClientRect(), t.style.transition = `stroke-dashoffset ${r}ms ease-in-out`, t.style.strokeDashoffset = "0", t.addEventListener("transitionend", function s() {
50
- t.style.transition = "", t.removeEventListener("transitionend", s), n && n();
50
+ t.style.strokeDasharray = String(o), t.style.strokeDashoffset = String(o), t.getBoundingClientRect(), t.style.transition = `stroke-dashoffset ${n}ms ease-in-out`, t.style.strokeDashoffset = "0", t.addEventListener("transitionend", function l() {
51
+ t.style.transition = "", t.removeEventListener("transitionend", l), e && e();
51
52
  });
52
53
  }
53
- function Q(t, r, n = 1e3) {
54
- r.style.opacity = "1";
55
- const o = r.getBBox(), s = o.width, i = document.createElementNS("http://www.w3.org/2000/svg", "clipPath"), d = "clip-" + Math.random().toString(36).substr(2, 9);
56
- i.setAttribute("id", d);
57
- const e = document.createElementNS("http://www.w3.org/2000/svg", "rect");
58
- e.setAttribute("x", o.x.toString()), e.setAttribute("y", o.y.toString()), e.setAttribute("width", "0"), e.setAttribute("height", o.height.toString()), i.appendChild(e);
59
- let m = t.querySelector("defs");
60
- m || (m = document.createElementNS("http://www.w3.org/2000/svg", "defs"), t.insertBefore(m, t.firstChild)), m.appendChild(i), r.setAttribute("clip-path", `url(#${d})`), e.style.transition = `width ${n}ms ease-out`, e.getBoundingClientRect(), e.setAttribute("width", s.toString()), e.addEventListener("transitionend", function p() {
61
- r.removeAttribute("clip-path"), i.parentNode && i.parentNode.removeChild(i), e.removeEventListener("transitionend", p);
54
+ function at(t, n, e = 1e3) {
55
+ n.style.opacity = "1";
56
+ const o = n.getBBox(), l = o.width, r = document.createElementNS("http://www.w3.org/2000/svg", "clipPath"), h = "clip-" + Math.random().toString(36).substr(2, 9);
57
+ r.setAttribute("id", h);
58
+ const i = document.createElementNS("http://www.w3.org/2000/svg", "rect");
59
+ i.setAttribute("x", o.x.toString()), i.setAttribute("y", o.y.toString()), i.setAttribute("width", "0"), i.setAttribute("height", o.height.toString()), r.appendChild(i);
60
+ let a = t.querySelector("defs");
61
+ a || (a = document.createElementNS("http://www.w3.org/2000/svg", "defs"), t.insertBefore(a, t.firstChild)), a.appendChild(r), n.setAttribute("clip-path", `url(#${h})`), i.style.transition = `width ${e}ms ease-out`, i.getBoundingClientRect(), i.setAttribute("width", l.toString()), i.addEventListener("transitionend", function L() {
62
+ n.removeAttribute("clip-path"), r.parentNode && r.parentNode.removeChild(r), i.removeEventListener("transitionend", L);
62
63
  });
63
64
  }
64
- function T() {
65
+ function lt() {
65
66
  return document.querySelectorAll(".tiny-spark");
66
67
  }
67
- function Z(t, r) {
68
- return Object.keys(t.dataset).includes(r);
68
+ function T(t, n) {
69
+ return Object.keys(t.dataset).includes(n);
69
70
  }
70
- function a(t, r, n) {
71
- return Z(t, r) ? t.dataset[r] : n;
71
+ function y(t, n, e) {
72
+ return T(t, n) ? t.dataset[n] : e;
72
73
  }
73
- function tt(t) {
74
+ function ut(t) {
74
75
  if (!t) return {
75
76
  color: "#1A1A1A",
76
77
  backgroundColor: "#FFFFFF"
77
78
  };
78
- const r = window.getComputedStyle(t), n = r.getPropertyValue("color") || "#1A1A1A", o = r.getPropertyValue("background-color"), s = r.getPropertyValue("background");
79
- return { color: n, backgroundColor: o || s || "#FFFFFF" };
79
+ const n = window.getComputedStyle(t), e = n.getPropertyValue("color") || "#1A1A1A", o = n.getPropertyValue("background-color"), l = n.getPropertyValue("background");
80
+ return { color: e, backgroundColor: o || l || "#FFFFFF" };
80
81
  }
81
- function K() {
82
+ function tt() {
82
83
  return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(t) {
83
- const r = Math.random() * 16 | 0;
84
- return (t == "x" ? r : r & 3 | 8).toString(16);
84
+ const n = Math.random() * 16 | 0;
85
+ return (t == "x" ? n : n & 3 | 8).toString(16);
85
86
  });
86
87
  }
87
- function j(t) {
88
- const r = t.getAttribute("data-set");
89
- if (!r) return [];
88
+ function et(t) {
89
+ const n = t.getAttribute("data-set");
90
+ if (!n) return [];
90
91
  try {
91
- const n = JSON.parse(r);
92
- return Array.isArray(n) && n.every((o) => typeof o == "number" || [null, void 0].includes(o)) ? n : (console.warn("data-set is not an array of numbers."), []);
93
- } catch (n) {
94
- return console.error("Error parsing data-set:", n), [];
92
+ const e = JSON.parse(n);
93
+ return Array.isArray(e) && e.every((o) => typeof o == "number" || [null, void 0].includes(o)) ? e : (console.warn("data-set is not an array of numbers."), []);
94
+ } catch (e) {
95
+ return console.error("Error parsing data-set:", e), [];
95
96
  }
96
97
  }
97
- function et(t) {
98
- const r = t.getAttribute("data-dates");
99
- if (!r) return [];
98
+ function dt(t) {
99
+ const n = t.getAttribute("data-dates");
100
+ if (!n) return [];
100
101
  try {
101
- const n = JSON.parse(r);
102
- return Array.isArray(n) && n.every((o) => typeof o == "string") ? n : (console.warn("data-dates is not an array of strings"), []);
103
- } catch (n) {
104
- return console.error("Error parsing data-dates", n), [];
102
+ const e = JSON.parse(n);
103
+ return Array.isArray(e) && e.every((o) => typeof o == "string") ? e : (console.warn("data-dates is not an array of strings"), []);
104
+ } catch (e) {
105
+ return console.error("Error parsing data-dates", e), [];
105
106
  }
106
107
  }
107
- function D(t) {
108
+ function q(t) {
108
109
  return {
109
110
  min: Math.min(...t),
110
111
  max: Math.max(...t)
111
112
  };
112
113
  }
113
- function F() {
114
+ function E() {
114
115
  return new Promise((t) => setTimeout(t, 0));
115
116
  }
116
- function E(t, r) {
117
- const n = String(a(t, l.NUMBER_LOCALE, navigator.language || "en-US")), o = Number(String(a(t, l.NUMBER_ROUNDING, 0)));
118
- return r.toLocaleString(n, {
117
+ function nt(t, n) {
118
+ const e = String(y(t, f.NUMBER_LOCALE, navigator.language || "en-US")), o = Number(String(y(t, f.NUMBER_ROUNDING, 0)));
119
+ return n.toLocaleString(e, {
119
120
  useGrouping: !0,
120
121
  minimumFractionDigits: o,
121
122
  maximumFractionDigits: o
122
123
  });
123
124
  }
124
- function nt(t, r, n) {
125
+ function k(t, n, e) {
125
126
  if (!t.createSVGPoint || !t.getScreenCTM)
126
127
  throw new Error("Your browser does not support SVG coordinate transformation.");
127
128
  const o = t.getScreenCTM();
128
129
  if (!o)
129
130
  throw new Error("Cannot obtain the screen CTM.");
130
- const s = t.createSVGPoint();
131
- s.x = r, s.y = n;
132
- const i = s.matrixTransform(o);
133
- return { x: i.x, y: i.y };
131
+ const l = t.createSVGPoint();
132
+ l.x = n, l.y = e;
133
+ const r = l.matrixTransform(o);
134
+ return { x: r.x, y: r.y };
134
135
  }
135
- function G(t, r, n, o, s) {
136
- if (rt(o), !s) return;
137
- const { x: i, y: d } = nt(t, n.x, n.y), e = document.createElement("div");
138
- e.style.opacity = "0", e.classList.add("tiny-spark-tooltip"), e.setAttribute("id", `tooltip_${o}`), e.style.pointerEvents = "none", e.style.position = "fixed", e.style.top = d + "px", e.style.left = i + "px", e.style.width = "fit-content", e.innerHTML = `
139
- <div class="tiny-spark-tooltip-content">${n.d ? `${n.d}: ` : ""}${[null, void 0].includes(n.v) ? "-" : E(r, Number(n.v))}</div>
140
- `, document.body.appendChild(e), F().then(() => {
141
- const { width: m, height: p } = e.getBoundingClientRect();
142
- e.style.left = `${i - m / 2}px`, e.style.top = `${d - p - Number(String(Number(a(r, l.PLOT_RADIUS, 3)) * 1.5))}px`;
136
+ function J(t, n, e, o, l) {
137
+ if (ct(o), !l) return;
138
+ const r = n.dataset.type && n.dataset.type === Y.BAR;
139
+ let h = 0, i = 0;
140
+ r ? (h = k(t, e.x, e.y).x, i = k(t, e.x, e.y).y) : (console.log("here"), h = k(t, e.x, e.y).x, e.isPositive ? i = k(t, e.x, e.y).y : i = k(t, e.x, e.bar.y + e.bar.h).y);
141
+ const a = document.createElement("div");
142
+ a.style.opacity = "0", a.classList.add("tiny-spark-tooltip"), a.setAttribute("id", `tooltip_${o}`), a.setAttribute("role", "tooltip"), a.setAttribute("aria-live", "polite"), a.setAttribute("aria-hidden", String(!l)), a.style.pointerEvents = "none", a.style.position = "fixed", a.style.top = i + "px", a.style.left = h + "px", a.style.width = "fit-content", a.innerHTML = `
143
+ <div class="tiny-spark-tooltip-content">${e.d ? `${e.d}: ` : ""}${[null, void 0].includes(e.v) ? "-" : nt(n, Number(e.v))}</div>
144
+ `, document.body.appendChild(a), E().then(() => {
145
+ const { width: L, height: O } = a.getBoundingClientRect();
146
+ a.style.left = `${h - L / 2}px`, a.style.top = `${i - O - Number(String(Number(y(n, f.PLOT_RADIUS, 3)) * 1.5))}px`;
143
147
  }).then(() => {
144
- e.style.opacity = "1";
148
+ a.style.opacity = "1";
145
149
  });
146
150
  }
147
- function rt(t) {
148
- const r = document.getElementById(`tooltip_${t}`);
149
- r == null || r.remove();
151
+ function ct(t) {
152
+ const n = document.getElementById(`tooltip_${t}`);
153
+ n == null || n.remove();
150
154
  }
151
- function ot(t) {
155
+ function gt(t) {
152
156
  t.innerHTML = "";
153
157
  }
154
- function it(t, r) {
155
- let n = r;
156
- ot(t);
157
- const { svg: o, svgId: s, width: i, height: d } = J(t), { color: e, backgroundColor: m } = tt(t), p = { T: 12, R: 12, B: 12, L: 12 }, O = K(), L = String(a(t, l.SHOW_LAST_VALUE, "false")) === "true", u = {
158
- left: p.L,
159
- top: p.T,
160
- width: i - p.L - p.R,
161
- height: d - p.T - p.B,
162
- bottom: d - p.B
163
- }, _ = j(t), { min: R } = D(_), A = _.map((g) => [null, void 0].includes(g) ? g : g + (R < 0 ? Math.abs(R) : 0)), { max: k } = D(A), C = u.width / (_.length - 1) === 1 / 0 ? u.width : u.width / (_.length - 1), X = et(t), h = A.map((g, b) => {
164
- const f = {
165
- w: A.length === 1 ? C / 2 : 0,
166
- h: A.length === 1 ? u.height / 2 : 0
167
- };
158
+ function yt(t, n) {
159
+ var Z;
160
+ const e = t.dataset.type && t.dataset.type === "bar";
161
+ let o = n;
162
+ gt(t);
163
+ const { svg: l, svgId: r, width: h, height: i, viewBox: a } = ot(t), { color: L, backgroundColor: O } = ut(t), S = { T: 12, R: 12, B: 12, L: 12 }, $ = tt(), I = String(y(t, f.SHOW_LAST_VALUE, "false")) === "true", c = {
164
+ left: S.L,
165
+ top: S.T,
166
+ width: h - S.L - S.R,
167
+ height: i - S.T - S.B,
168
+ bottom: i - S.B
169
+ }, x = et(t), { min: R } = q(x), P = x.map((s) => [null, void 0].includes(s) ? s : s + (R < 0 ? Math.abs(R) : 0)), { max: G } = q(P);
170
+ let N = c.width / (x.length - 1) === 1 / 0 ? c.width : c.width / (x.length - 1);
171
+ if (e) {
172
+ const [s, m, b, u] = a.split(" ");
173
+ l.setAttribute("viewBox", `${Number(s) - N / 2} ${m} ${Number(b) + N} ${u}`);
174
+ }
175
+ const F = !x.some((s) => s >= 0), it = dt(t), g = P.map((s, m) => {
176
+ const b = {
177
+ w: P.length === 1 ? N / 2 : 0,
178
+ h: P.length === 1 ? c.height / 2 : 0
179
+ }, u = c.left + N * m + b.w, d = (1 - (s || 0) / G) * c.height + b.h + S.T, U = (1 - (R < 0 ? Math.abs(R) : 0) / G) * c.height + S.T + b.h, W = x[m] >= 0;
168
180
  return {
169
- y: (1 - (g || 0) / k) * u.height + p.T + f.h,
170
- x: u.left + C * b + f.w,
171
- v: g,
172
- d: X[b] || null
181
+ y: F && x.length === 1 ? c.top + c.height / 2 : d,
182
+ x: u,
183
+ v: x[m],
184
+ d: it[m] || null,
185
+ isPositive: W,
186
+ bar: {
187
+ x: u - N / 2,
188
+ y: x.length === 1 ? c.top : W ? d : F ? c.top : U,
189
+ h: x.length === 1 ? c.height : W ? U - d : F && x.length === 0 ? c.height : isNaN(d - U) ? 0 : d - U,
190
+ w: N
191
+ }
173
192
  };
174
- }), v = [...h].filter(({ v: g }) => ![null, void 0].includes(g)), x = document.createElementNS(I, "path");
175
- x.classList.add("tiny-spark-line-path"), !t.dataset.curve || t.dataset.curve === "true" ? x.setAttribute("d", `M ${B(v)}`) : x.setAttribute("d", `M ${W(v)}`), x.setAttribute("fill", "none"), x.setAttribute("stroke", String(a(t, l.LINE_COLOR, e))), x.setAttribute("stroke-width", String(a(t, l.LINE_THICKNESS, 2))), x.setAttribute("stroke-linecap", "round");
176
- const w = document.createElementNS(I, "path");
177
- w.classList.add("tiny-spark-line-area");
178
- const H = t.getAttribute("data-animation");
179
- H === "true" && n && (x.style.opacity = "0", w.style.opacity = "0"), h.length && (!t.dataset.curve || t.dataset.curve === "true" ? w.setAttribute("d", `M ${v[0].x},${u.bottom} ${B(v)} L ${v.at(-1).x},${u.bottom} Z`) : w.setAttribute("d", `M ${v[0].x},${u.bottom} ${W(v)} L ${v.at(-1).x},${u.bottom} Z`)), w.setAttribute("fill", String(a(t, l.AREA_COLOR, "transparent"))), h.length > 1 && (o.appendChild(w), o.appendChild(x));
180
- const P = [];
181
- h.forEach((g, b) => {
182
- const f = document.createElementNS(I, "line");
183
- f.classList.add("tiny-spark-indicator"), f.setAttribute("id", `indicator_${s}_${b}`), f.setAttribute("x1", String(u.left + (h.length === 1 ? u.width / 2 : b * C))), f.setAttribute("x2", String(u.left + (h.length === 1 ? u.width / 2 : b * C))), f.setAttribute("y1", String(u.top)), f.setAttribute("y2", String(u.bottom)), f.setAttribute("stroke", String(a(t, l.INDICATOR_COLOR, "#1A1A1A"))), f.setAttribute("stroke-width", String(a(t, l.INDICATOR_WIDTH, "1"))), f.setAttribute("stroke-linecap", "round"), f.style.pointerEvents = "none", f.style.opacity = "0", P.push(f), o.appendChild(f);
193
+ }), A = [...g].filter(({ v: s }) => ![null, void 0].includes(s)), z = t.getAttribute("data-animation"), C = document.createElementNS(w, "path");
194
+ C.classList.add("tiny-spark-line-path");
195
+ const _ = document.createElementNS(w, "path");
196
+ _.classList.add("tiny-spark-line-area"), e || (!t.dataset.curve || t.dataset.curve === "true" ? C.setAttribute("d", `M ${X(A)}`) : C.setAttribute("d", `M ${j(A)}`), C.setAttribute("fill", "none"), C.setAttribute("stroke", String(y(t, f.LINE_COLOR, L))), C.setAttribute("stroke-width", String(y(t, f.LINE_THICKNESS, 2))), C.setAttribute("stroke-linecap", "round"), z === "true" && o && (C.style.opacity = "0", _.style.opacity = "0"), g.length && (!t.dataset.curve || t.dataset.curve === "true" ? _.setAttribute("d", `M ${A[0].x},${c.bottom} ${X(A)} L ${A.at(-1).x},${c.bottom} Z`) : _.setAttribute("d", `M ${A[0].x},${c.bottom} ${j(A)} L ${A.at(-1).x},${c.bottom} Z`)), _.setAttribute("fill", String(y(t, f.AREA_COLOR, "transparent"))), g.length > 1 && (l.appendChild(_), l.appendChild(C)));
197
+ const H = [];
198
+ g.forEach((s, m) => {
199
+ const b = document.createElementNS(w, "line");
200
+ b.classList.add("tiny-spark-indicator"), b.setAttribute("id", `indicator_${r}_${m}`), b.setAttribute("x1", String(c.left + (g.length === 1 ? c.width / 2 : m * N))), b.setAttribute("x2", String(c.left + (g.length === 1 ? c.width / 2 : m * N))), b.setAttribute("y1", String(c.top)), b.setAttribute("y2", String(c.bottom)), b.setAttribute("stroke", String(y(t, f.INDICATOR_COLOR, "#1A1A1A"))), b.setAttribute("stroke-width", String(y(t, f.INDICATOR_WIDTH, "1"))), b.setAttribute("stroke-linecap", "round"), b.style.pointerEvents = "none", b.style.opacity = "0", H.push(b), l.appendChild(b);
184
201
  });
185
- let $ = [];
186
- const M = Number(String(a(t, l.PLOT_RADIUS, 0))) > 0, q = !String(a(t, l.HIDE_PLOTS_ABOVE, "")) || h.length <= Number(String(a(t, l.HIDE_PLOTS_ABOVE, 0))), V = M && q;
187
- M && h.forEach(({ x: g, y: b, v: f }, S) => {
188
- if (![null, void 0].includes(f)) {
189
- const c = document.createElementNS(I, "circle");
190
- c.classList.add("tiny-spark-datapoint-circle"), c.classList.add(`circle-${s}`), c.setAttribute("id", `circle_${s}_${S}`), c.setAttribute("cx", String(g || 0)), c.setAttribute("cy", String(b || 0)), c.setAttribute("r", String(a(t, l.PLOT_RADIUS, 3))), c.setAttribute("fill", String(a(t, l.PLOT_COLOR, String(a(t, "lineColor", e))))), c.setAttribute("stroke", m), c.style.opacity = h.length === 1 ? "1" : "0", c.style.transition = `opacity ${S * (1e3 * 2 / h.length)}ms ease-in`, c.style.pointerEvents = "none", $.push(c), V && o.appendChild(c);
202
+ let V = [], M = [];
203
+ const K = Number(String(y(t, f.PLOT_RADIUS, 0))) > 0, rt = !String(y(t, f.HIDE_PLOTS_ABOVE, "")) || g.length <= Number(String(y(t, f.HIDE_PLOTS_ABOVE, 0))), B = K && rt;
204
+ e && g.forEach(({ bar: s, v: m }, b) => {
205
+ if (![null, void 0].includes(m)) {
206
+ const u = document.createElementNS(w, "rect");
207
+ u.classList.add("tiny-spark-datapoint-bar"), u.setAttribute("x", String(s.x)), u.setAttribute("y", String(s.y)), u.setAttribute("width", String(s.w)), u.setAttribute("height", String(s.h)), u.setAttribute("fill", String(y(t, f.PLOT_COLOR, String(y(t, "lineColor", L))))), u.style.opacity = g.length === 1 ? "1" : "0", u.style.transition = `opacity ${b * (1e3 * 2 / g.length)}ms ease-in`, M.push(u), l.appendChild(u);
208
+ }
209
+ }), K && !e && g.forEach(({ x: s, y: m, v: b }, u) => {
210
+ if (![null, void 0].includes(b)) {
211
+ const d = document.createElementNS(w, "circle");
212
+ d.classList.add("tiny-spark-datapoint-circle"), d.classList.add(`circle-${r}`), d.setAttribute("id", `circle_${r}_${u}`), d.setAttribute("cx", String(s || 0)), d.setAttribute("cy", String(m || 0)), d.setAttribute("r", String(y(t, f.PLOT_RADIUS, 3))), d.setAttribute("fill", String(y(t, f.PLOT_COLOR, String(y(t, "lineColor", L))))), d.setAttribute("stroke", O), d.style.opacity = g.length === 1 ? "1" : "0", d.style.transition = `opacity ${u * (1e3 * 2 / g.length)}ms ease-in`, d.style.pointerEvents = "none", V.push(d), B && l.appendChild(d);
191
213
  }
192
214
  });
193
- let y = null;
194
- if (L && h.length && h.at(-1)) {
195
- const g = Number(a(t, l.LAST_VALUE_FONT_SIZE, 12));
196
- y = document.createElementNS(I, "text"), y.classList.add("tiny-spark-last-value"), y.setAttribute("id", O), y.setAttribute("x", String(h.at(-1).x + 6 + Number(a(t, l.LINE_THICKNESS, 2)))), y.setAttribute("y", String(h.at(-1).y + g / 3)), y.setAttribute("text-anchor", "start"), y.setAttribute("font-size", String(g) + "px"), y.setAttribute("fill", String(a(t, l.LAST_VALUE_COLOR, String(a(t, l.INDICATOR_COLOR, "#1A1A1A"))))), y.innerHTML = E(t, Number(h.at(-1).v)), y.style.opacity = h.length === 1 ? "1" : "0", o.appendChild(y);
215
+ let p = null;
216
+ if (I && g.length && g.at(-1)) {
217
+ const s = Number(y(t, f.LAST_VALUE_FONT_SIZE, 12));
218
+ p = document.createElementNS(w, "text"), p.classList.add("tiny-spark-last-value"), p.setAttribute("id", $), e ? (p.setAttribute("x", String(g.at(-1).x + Number(y(t, f.LINE_THICKNESS, 2)))), p.setAttribute("y", (Z = g.at(-1)) != null && Z.isPositive ? String(g.at(-1).y - s / 3) : String(g.at(-1).bar.y + g.at(-1).bar.h + s)), p.setAttribute("text-anchor", "middle")) : (p.setAttribute("x", String(g.at(-1).x + 6 + Number(y(t, f.LINE_THICKNESS, 2)))), p.setAttribute("y", String(g.at(-1).y + s / 3)), p.setAttribute("text-anchor", "start")), p.setAttribute("font-size", String(s) + "px"), p.setAttribute("fill", String(y(t, f.LAST_VALUE_COLOR, String(y(t, f.INDICATOR_COLOR, "#1A1A1A"))))), p.innerHTML = nt(t, Number(g.at(-1).v)), p.style.opacity = g.length === 1 ? "1" : "0", l.appendChild(p);
197
219
  }
198
- h.forEach((g, b) => {
199
- const f = $[b], S = document.createElementNS(I, "rect");
200
- S.classList.add("tiny-spark-tooltip-trap"), S.setAttribute("x", `${h.length === 1 ? 0 : u.left + b * C - C / 2}`), S.setAttribute("y", `${u.top}`), S.setAttribute("height", `${u.height}`), S.setAttribute("width", `${C}`), S.setAttribute("fill", "transparent"), S.addEventListener("mouseenter", () => {
201
- if (G(o, t, g, s, !0), V) {
202
- const c = document.getElementById(`circle_${s}_${b}`);
203
- c == null || c.setAttribute("r", String(Number(a(t, l.PLOT_RADIUS, 3)) * 1.5));
220
+ g.forEach((s, m) => {
221
+ const b = V[m], u = document.createElementNS(w, "rect");
222
+ u.classList.add("tiny-spark-tooltip-trap"), u.setAttribute("x", `${g.length === 1 ? 0 : c.left + m * N - N / 2}`), u.setAttribute("y", `${c.top}`), u.setAttribute("height", `${c.height}`), u.setAttribute("width", `${N}`), u.setAttribute("fill", "transparent"), u.setAttribute("aria-describedby", `tooltip_${r}`), u.addEventListener("mouseenter", () => {
223
+ if (J(l, t, s, r, !0), B) {
224
+ const d = document.getElementById(`circle_${r}_${m}`);
225
+ d == null || d.setAttribute("r", String(Number(y(t, f.PLOT_RADIUS, 3)) * 1.5));
204
226
  } else
205
- o.appendChild(f);
206
- P[b].style.opacity = "1", L && y && (b === h.length - 1 ? y.style.opacity = "0" : y.style.opacity = "1");
207
- }), S.addEventListener("mouseout", () => {
208
- if (G(o, t, g, s, !1), V) {
209
- const c = document.getElementById(`circle_${s}_${b}`);
210
- c == null || c.setAttribute("r", String(Number(a(t, l.PLOT_RADIUS, 3))));
227
+ l.appendChild(b);
228
+ H[m].style.opacity = "1", I && p && (m === g.length - 1 ? p.style.opacity = "0" : p.style.opacity = "1");
229
+ }), u.addEventListener("mouseout", () => {
230
+ if (J(l, t, s, r, !1), B) {
231
+ const d = document.getElementById(`circle_${r}_${m}`);
232
+ d == null || d.setAttribute("r", String(Number(y(t, f.PLOT_RADIUS, 3))));
211
233
  } else
212
- f.remove();
213
- P.forEach((c) => c.style.opacity = "0"), L && y && (y.style.opacity = "1");
214
- }), o.appendChild(S);
215
- }), H === "true" && n ? F().then(() => {
216
- $.forEach((g) => {
217
- g.style.opacity = "1";
218
- }), Y(x, 1e3, () => {
219
- y && (y.style.opacity = "1");
220
- }), Q(o, w);
221
- }) : ($.forEach((g) => {
222
- g.style.opacity = "1";
223
- }), y && (y.style.opacity = "1")), t.appendChild(o);
234
+ b.remove();
235
+ H.forEach((d) => d.style.opacity = "0"), I && p && (p.style.opacity = "1");
236
+ }), l.appendChild(u);
237
+ }), z === "true" && o ? E().then(() => {
238
+ V.forEach((s) => {
239
+ s.style.opacity = "1";
240
+ }), M.forEach((s) => {
241
+ s.style.opacity = "1";
242
+ }), st(C, 1e3, () => {
243
+ p && (p.style.opacity = "1");
244
+ }), at(l, _);
245
+ }) : (V.forEach((s) => {
246
+ s.style.opacity = "1";
247
+ }), M.forEach((s) => {
248
+ s.style.opacity = "1";
249
+ }), p && (p.style.opacity = "1")), t.appendChild(l);
224
250
  }
225
- function at() {
226
- const t = T();
227
- t.length && Array.from(t).forEach((r) => {
228
- if (!r.dataset.id) {
229
- const o = K();
230
- r.setAttribute("data-id", o);
251
+ function ft() {
252
+ const t = lt();
253
+ t.length && Array.from(t).forEach((n) => {
254
+ if (!n.dataset.id) {
255
+ const o = tt();
256
+ n.setAttribute("data-id", o);
231
257
  }
232
- const n = r;
233
- st(n), n.__renderCount = 0, U(n), F().then(() => {
234
- const o = new ResizeObserver((i) => {
235
- i.forEach(() => U(n));
258
+ const e = n;
259
+ bt(e), e.__renderCount = 0, D(e), E().then(() => {
260
+ const o = new ResizeObserver((r) => {
261
+ r.forEach(() => D(e));
236
262
  });
237
- n.parentElement && o.observe(n.parentElement), new MutationObserver((i) => {
238
- for (const d of i)
239
- if (d.type === "attributes" && d.attributeName && Object.values(z).includes(d.attributeName)) {
240
- U(n);
263
+ e.parentElement && o.observe(e.parentElement), new MutationObserver((r) => {
264
+ for (const h of r)
265
+ if (h.type === "attributes" && h.attributeName && Object.values(Q).includes(h.attributeName)) {
266
+ D(e);
241
267
  break;
242
268
  }
243
- }).observe(n, { attributes: !0 });
269
+ }).observe(e, { attributes: !0 });
244
270
  });
245
271
  });
246
272
  }
247
- function U(t) {
248
- Z(t, "set") && it(t, t.__renderCount < 2), t.__renderCount += 1;
273
+ function D(t) {
274
+ T(t, "set") && yt(t, t.__renderCount < 2), t.__renderCount += 1;
249
275
  }
250
- function st(t) {
276
+ function bt(t) {
251
277
  t.dataset.set || console.error(
252
278
  `Tiny-spark exception:
253
279
 
@@ -257,10 +283,10 @@ Provide an array of numbers, for example:
257
283
  data-set="[1, 2, 3]"`
258
284
  );
259
285
  }
260
- function lt(t) {
286
+ function ht(t) {
261
287
  return JSON.stringify(t);
262
288
  }
263
289
  export {
264
- at as render,
265
- lt as tinyFormat
290
+ ft as render,
291
+ ht as tinyFormat
266
292
  };
@@ -1,8 +1,8 @@
1
- (function(I,x){typeof exports=="object"&&typeof module<"u"?x(exports):typeof define=="function"&&define.amd?define(["exports"],x):(I=typeof globalThis<"u"?globalThis:I||self,x(I.TinySpark={}))})(this,function(I){"use strict";const x="http://www.w3.org/2000/svg";var a=(t=>(t.ANIMATION="animation",t.AREA_COLOR="areaColor",t.CURVE="curve",t.DATES="dates",t.ID="id",t.INDICATOR_COLOR="indicatorColor",t.INDICATOR_WIDTH="indicatorWidth",t.LINE_COLOR="lineColor",t.LINE_THICKNESS="lineThickness",t.NUMBER_LOCALE="numberLocale",t.NUMBER_ROUNDING="numberRounding",t.NUMBER_SHOW_ON="numberShowOn",t.PLOT_COLOR="plotColor",t.PLOT_RADIUS="plotRadius",t.SET="set",t.HIDE_PLOTS_ABOVE="hidePlotsAbove",t.SHOW_LAST_VALUE="showLastValue",t.LAST_VALUE_FONT_SIZE="lastValueFontSize",t.LAST_VALUE_COLOR="lastValueColor",t))(a||{}),M=(t=>(t.ANIMATION="data-animation",t.AREA_COLOR="data-area-color",t.CURVE="data-curve",t.DATES="data-dates",t.ID="data-id",t.INDICATOR_COLOR="data-indicator-color",t.INDICATOR_WIDTH="data-indicator-width",t.LINE_COLOR="data-line-color",t.LINE_THICKNESS="data-line-thickness",t.NUMBER_LOCALE="data-number-locale",t.NUMBER_ROUNDING="data-number-rounding",t.NUMBER_SHOW_ON="data-number-show-on",t.PLOT_COLOR="data-plot-color",t.PLOT_RADIUS="data-plot-radius",t.SET="data-set",t.HIDE_PLOTS_ABOVE="data-hide-plots-above",t.SHOW_LAST_VALUE="data-show-last-value",t.LAST_VALUE_FONT_SIZE="data-last-value-font-size",t.LAST_VALUE_COLOR="data-last-value-color",t))(M||{});function q(t){const{width:r,height:n}=t.parentElement.getBoundingClientRect(),o={width:300,height:100},s=String(l(t,a.SHOW_LAST_VALUE,"false"))==="true",i=j(t),c=i&&i.length?i.at(-1):null;let e=0;if(s&&![null,void 0].includes(c)){const u=Number(String(l(t,a.NUMBER_ROUNDING,0)));e=6+c.toFixed(u).length*(Number(l(t,a.LAST_VALUE_FONT_SIZE,12))/2)}const m=`0 0 ${(r||o.width)+e} ${n||o.height}`,S=document.createElementNS(x,"svg"),C=t.dataset.id;return S.id=C,S.setAttribute("viewBox",m),S.style.width="100%",S.style.height="100%",{svg:S,svgId:C,width:r||o.width,height:n||o.height}}function N(t,r=0){return isNaN(t)?r:t}function W(t){let r=[];for(let n=0;n<t.length;n+=1)r.push(`${N(t[n].x)},${N(t[n].y)} `);return r.join(" ").trim()}function B(t){if(t.length<1)return"0,0";const r=t.length-1,n=[`${N(t[0].x)},${N(t[0].y)}`],o=[],s=[],i=[],c=[];for(let e=0;e<r;e+=1)o[e]=t[e+1].x-t[e].x,s[e]=t[e+1].y-t[e].y,i[e]=s[e]/o[e];c[0]=i[0],c[r]=i[r-1];for(let e=1;e<r;e+=1)if(i[e-1]*i[e]<=0)c[e]=0;else{const h=2*i[e-1]*i[e]/(i[e-1]+i[e]);c[e]=h}for(let e=0;e<r;e+=1){const h=t[e].x,m=t[e].y,S=t[e+1].x,C=t[e+1].y,u=c[e],A=c[e+1],$=h+(S-h)/3,R=m+u*(S-h)/3,F=S-(S-h)/3,v=C-A*(S-h)/3;n.push(`C ${N($)},${N(R)} ${N(F)},${N(v)} ${N(S)},${N(C)}`)}return n.join(" ")}function J(t,r=1e3,n){t.style.opacity="1";const o=t.getTotalLength();t.style.strokeDasharray=String(o),t.style.strokeDashoffset=String(o),t.getBoundingClientRect(),t.style.transition=`stroke-dashoffset ${r}ms ease-in-out`,t.style.strokeDashoffset="0",t.addEventListener("transitionend",function s(){t.style.transition="",t.removeEventListener("transitionend",s),n&&n()})}function Y(t,r,n=1e3){r.style.opacity="1";const o=r.getBBox(),s=o.width,i=document.createElementNS("http://www.w3.org/2000/svg","clipPath"),c="clip-"+Math.random().toString(36).substr(2,9);i.setAttribute("id",c);const e=document.createElementNS("http://www.w3.org/2000/svg","rect");e.setAttribute("x",o.x.toString()),e.setAttribute("y",o.y.toString()),e.setAttribute("width","0"),e.setAttribute("height",o.height.toString()),i.appendChild(e);let h=t.querySelector("defs");h||(h=document.createElementNS("http://www.w3.org/2000/svg","defs"),t.insertBefore(h,t.firstChild)),h.appendChild(i),r.setAttribute("clip-path",`url(#${c})`),e.style.transition=`width ${n}ms ease-out`,e.getBoundingClientRect(),e.setAttribute("width",s.toString()),e.addEventListener("transitionend",function m(){r.removeAttribute("clip-path"),i.parentNode&&i.parentNode.removeChild(i),e.removeEventListener("transitionend",m)})}function Q(){return document.querySelectorAll(".tiny-spark")}function D(t,r){return Object.keys(t.dataset).includes(r)}function l(t,r,n){return D(t,r)?t.dataset[r]:n}function T(t){if(!t)return{color:"#1A1A1A",backgroundColor:"#FFFFFF"};const r=window.getComputedStyle(t),n=r.getPropertyValue("color")||"#1A1A1A",o=r.getPropertyValue("background-color"),s=r.getPropertyValue("background");return{color:n,backgroundColor:o||s||"#FFFFFF"}}function G(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){const r=Math.random()*16|0;return(t=="x"?r:r&3|8).toString(16)})}function j(t){const r=t.getAttribute("data-set");if(!r)return[];try{const n=JSON.parse(r);return Array.isArray(n)&&n.every(o=>typeof o=="number"||[null,void 0].includes(o))?n:(console.warn("data-set is not an array of numbers."),[])}catch(n){return console.error("Error parsing data-set:",n),[]}}function tt(t){const r=t.getAttribute("data-dates");if(!r)return[];try{const n=JSON.parse(r);return Array.isArray(n)&&n.every(o=>typeof o=="string")?n:(console.warn("data-dates is not an array of strings"),[])}catch(n){return console.error("Error parsing data-dates",n),[]}}function z(t){return{min:Math.min(...t),max:Math.max(...t)}}function P(){return new Promise(t=>setTimeout(t,0))}function Z(t,r){const n=String(l(t,a.NUMBER_LOCALE,navigator.language||"en-US")),o=Number(String(l(t,a.NUMBER_ROUNDING,0)));return r.toLocaleString(n,{useGrouping:!0,minimumFractionDigits:o,maximumFractionDigits:o})}function et(t,r,n){if(!t.createSVGPoint||!t.getScreenCTM)throw new Error("Your browser does not support SVG coordinate transformation.");const o=t.getScreenCTM();if(!o)throw new Error("Cannot obtain the screen CTM.");const s=t.createSVGPoint();s.x=r,s.y=n;const i=s.matrixTransform(o);return{x:i.x,y:i.y}}function K(t,r,n,o,s){if(nt(o),!s)return;const{x:i,y:c}=et(t,n.x,n.y),e=document.createElement("div");e.style.opacity="0",e.classList.add("tiny-spark-tooltip"),e.setAttribute("id",`tooltip_${o}`),e.style.pointerEvents="none",e.style.position="fixed",e.style.top=c+"px",e.style.left=i+"px",e.style.width="fit-content",e.innerHTML=`
2
- <div class="tiny-spark-tooltip-content">${n.d?`${n.d}: `:""}${[null,void 0].includes(n.v)?"-":Z(r,Number(n.v))}</div>
3
- `,document.body.appendChild(e),P().then(()=>{const{width:h,height:m}=e.getBoundingClientRect();e.style.left=`${i-h/2}px`,e.style.top=`${c-m-Number(String(Number(l(r,a.PLOT_RADIUS,3))*1.5))}px`}).then(()=>{e.style.opacity="1"})}function nt(t){const r=document.getElementById(`tooltip_${t}`);r==null||r.remove()}function rt(t){t.innerHTML=""}function ot(t,r){let n=r;rt(t);const{svg:o,svgId:s,width:i,height:c}=q(t),{color:e,backgroundColor:h}=T(t),m={T:12,R:12,B:12,L:12},S=G(),C=String(l(t,a.SHOW_LAST_VALUE,"false"))==="true",u={left:m.L,top:m.T,width:i-m.L-m.R,height:c-m.T-m.B,bottom:c-m.B},A=j(t),{min:$}=z(A),R=A.map(g=>[null,void 0].includes(g)?g:g+($<0?Math.abs($):0)),{max:F}=z(R),v=u.width/(A.length-1)===1/0?u.width:u.width/(A.length-1),lt=tt(t),p=R.map((g,b)=>{const f={w:R.length===1?v/2:0,h:R.length===1?u.height/2:0};return{y:(1-(g||0)/F)*u.height+m.T+f.h,x:u.left+v*b+f.w,v:g,d:lt[b]||null}}),w=[...p].filter(({v:g})=>![null,void 0].includes(g)),L=document.createElementNS(x,"path");L.classList.add("tiny-spark-line-path"),!t.dataset.curve||t.dataset.curve==="true"?L.setAttribute("d",`M ${B(w)}`):L.setAttribute("d",`M ${W(w)}`),L.setAttribute("fill","none"),L.setAttribute("stroke",String(l(t,a.LINE_COLOR,e))),L.setAttribute("stroke-width",String(l(t,a.LINE_THICKNESS,2))),L.setAttribute("stroke-linecap","round");const _=document.createElementNS(x,"path");_.classList.add("tiny-spark-line-area");const E=t.getAttribute("data-animation");E==="true"&&n&&(L.style.opacity="0",_.style.opacity="0"),p.length&&(!t.dataset.curve||t.dataset.curve==="true"?_.setAttribute("d",`M ${w[0].x},${u.bottom} ${B(w)} L ${w.at(-1).x},${u.bottom} Z`):_.setAttribute("d",`M ${w[0].x},${u.bottom} ${W(w)} L ${w.at(-1).x},${u.bottom} Z`)),_.setAttribute("fill",String(l(t,a.AREA_COLOR,"transparent"))),p.length>1&&(o.appendChild(_),o.appendChild(L));const U=[];p.forEach((g,b)=>{const f=document.createElementNS(x,"line");f.classList.add("tiny-spark-indicator"),f.setAttribute("id",`indicator_${s}_${b}`),f.setAttribute("x1",String(u.left+(p.length===1?u.width/2:b*v))),f.setAttribute("x2",String(u.left+(p.length===1?u.width/2:b*v))),f.setAttribute("y1",String(u.top)),f.setAttribute("y2",String(u.bottom)),f.setAttribute("stroke",String(l(t,a.INDICATOR_COLOR,"#1A1A1A"))),f.setAttribute("stroke-width",String(l(t,a.INDICATOR_WIDTH,"1"))),f.setAttribute("stroke-linecap","round"),f.style.pointerEvents="none",f.style.opacity="0",U.push(f),o.appendChild(f)});let k=[];const X=Number(String(l(t,a.PLOT_RADIUS,0)))>0,ut=!String(l(t,a.HIDE_PLOTS_ABOVE,""))||p.length<=Number(String(l(t,a.HIDE_PLOTS_ABOVE,0))),H=X&&ut;X&&p.forEach(({x:g,y:b,v:f},O)=>{if(![null,void 0].includes(f)){const d=document.createElementNS(x,"circle");d.classList.add("tiny-spark-datapoint-circle"),d.classList.add(`circle-${s}`),d.setAttribute("id",`circle_${s}_${O}`),d.setAttribute("cx",String(g||0)),d.setAttribute("cy",String(b||0)),d.setAttribute("r",String(l(t,a.PLOT_RADIUS,3))),d.setAttribute("fill",String(l(t,a.PLOT_COLOR,String(l(t,"lineColor",e))))),d.setAttribute("stroke",h),d.style.opacity=p.length===1?"1":"0",d.style.transition=`opacity ${O*(1e3*2/p.length)}ms ease-in`,d.style.pointerEvents="none",k.push(d),H&&o.appendChild(d)}});let y=null;if(C&&p.length&&p.at(-1)){const g=Number(l(t,a.LAST_VALUE_FONT_SIZE,12));y=document.createElementNS(x,"text"),y.classList.add("tiny-spark-last-value"),y.setAttribute("id",S),y.setAttribute("x",String(p.at(-1).x+6+Number(l(t,a.LINE_THICKNESS,2)))),y.setAttribute("y",String(p.at(-1).y+g/3)),y.setAttribute("text-anchor","start"),y.setAttribute("font-size",String(g)+"px"),y.setAttribute("fill",String(l(t,a.LAST_VALUE_COLOR,String(l(t,a.INDICATOR_COLOR,"#1A1A1A"))))),y.innerHTML=Z(t,Number(p.at(-1).v)),y.style.opacity=p.length===1?"1":"0",o.appendChild(y)}p.forEach((g,b)=>{const f=k[b],O=document.createElementNS(x,"rect");O.classList.add("tiny-spark-tooltip-trap"),O.setAttribute("x",`${p.length===1?0:u.left+b*v-v/2}`),O.setAttribute("y",`${u.top}`),O.setAttribute("height",`${u.height}`),O.setAttribute("width",`${v}`),O.setAttribute("fill","transparent"),O.addEventListener("mouseenter",()=>{if(K(o,t,g,s,!0),H){const d=document.getElementById(`circle_${s}_${b}`);d==null||d.setAttribute("r",String(Number(l(t,a.PLOT_RADIUS,3))*1.5))}else o.appendChild(f);U[b].style.opacity="1",C&&y&&(b===p.length-1?y.style.opacity="0":y.style.opacity="1")}),O.addEventListener("mouseout",()=>{if(K(o,t,g,s,!1),H){const d=document.getElementById(`circle_${s}_${b}`);d==null||d.setAttribute("r",String(Number(l(t,a.PLOT_RADIUS,3))))}else f.remove();U.forEach(d=>d.style.opacity="0"),C&&y&&(y.style.opacity="1")}),o.appendChild(O)}),E==="true"&&n?P().then(()=>{k.forEach(g=>{g.style.opacity="1"}),J(L,1e3,()=>{y&&(y.style.opacity="1")}),Y(o,_)}):(k.forEach(g=>{g.style.opacity="1"}),y&&(y.style.opacity="1")),t.appendChild(o)}function it(){const t=Q();t.length&&Array.from(t).forEach(r=>{if(!r.dataset.id){const o=G();r.setAttribute("data-id",o)}const n=r;st(n),n.__renderCount=0,V(n),P().then(()=>{const o=new ResizeObserver(i=>{i.forEach(()=>V(n))});n.parentElement&&o.observe(n.parentElement),new MutationObserver(i=>{for(const c of i)if(c.type==="attributes"&&c.attributeName&&Object.values(M).includes(c.attributeName)){V(n);break}}).observe(n,{attributes:!0})})})}function V(t){D(t,"set")&&ot(t,t.__renderCount<2),t.__renderCount+=1}function st(t){t.dataset.set||console.error(`Tiny-spark exception:
1
+ (function(I,N){typeof exports=="object"&&typeof module<"u"?N(exports):typeof define=="function"&&define.amd?define(["exports"],N):(I=typeof globalThis<"u"?globalThis:I||self,N(I.TinySpark={}))})(this,function(I){"use strict";const N="http://www.w3.org/2000/svg";var j=(t=>(t.BAR="bar",t.LINE="line",t))(j||{}),f=(t=>(t.ANIMATION="animation",t.AREA_COLOR="areaColor",t.CURVE="curve",t.DATES="dates",t.ID="id",t.INDICATOR_COLOR="indicatorColor",t.INDICATOR_WIDTH="indicatorWidth",t.LINE_COLOR="lineColor",t.LINE_THICKNESS="lineThickness",t.NUMBER_LOCALE="numberLocale",t.NUMBER_ROUNDING="numberRounding",t.NUMBER_SHOW_ON="numberShowOn",t.PLOT_COLOR="plotColor",t.PLOT_RADIUS="plotRadius",t.SET="set",t.HIDE_PLOTS_ABOVE="hidePlotsAbove",t.SHOW_LAST_VALUE="showLastValue",t.LAST_VALUE_FONT_SIZE="lastValueFontSize",t.LAST_VALUE_COLOR="lastValueColor",t))(f||{}),z=(t=>(t.ANIMATION="data-animation",t.AREA_COLOR="data-area-color",t.CURVE="data-curve",t.DATES="data-dates",t.ID="data-id",t.INDICATOR_COLOR="data-indicator-color",t.INDICATOR_WIDTH="data-indicator-width",t.LINE_COLOR="data-line-color",t.LINE_THICKNESS="data-line-thickness",t.NUMBER_LOCALE="data-number-locale",t.NUMBER_ROUNDING="data-number-rounding",t.NUMBER_SHOW_ON="data-number-show-on",t.PLOT_COLOR="data-plot-color",t.PLOT_RADIUS="data-plot-radius",t.SET="data-set",t.HIDE_PLOTS_ABOVE="data-hide-plots-above",t.SHOW_LAST_VALUE="data-show-last-value",t.LAST_VALUE_FONT_SIZE="data-last-value-font-size",t.LAST_VALUE_COLOR="data-last-value-color",t))(z||{});function rt(t){const{width:n,height:e}=t.parentElement.getBoundingClientRect(),o={width:300,height:100},l=String(g(t,f.SHOW_LAST_VALUE,"false"))==="true",r=J(t),h=r&&r.length?r.at(-1):null;let i=0;if(!(t.dataset.type&&t.dataset.type==="bar")&&l&&![null,void 0].includes(h)){const _=Number(String(g(t,f.NUMBER_ROUNDING,0)));i=6+h.toFixed(_).length*(Number(g(t,f.LAST_VALUE_FONT_SIZE,12))/2)}const O=`0 0 ${(n||o.width)+i} ${e||o.height}`,S=document.createElementNS(N,"svg"),R=t.dataset.id;return S.id=R,S.setAttribute("viewBox",O),S.style.width="100%",S.style.height="100%",{svg:S,svgId:R,width:n||o.width,height:e||o.height,viewBox:O}}function C(t,n=0){return isNaN(t)?n:t}function K(t){let n=[];for(let e=0;e<t.length;e+=1)n.push(`${C(t[e].x)},${C(t[e].y)} `);return n.join(" ").trim()}function Z(t){if(t.length<1)return"0,0";const n=t.length-1,e=[`${C(t[0].x)},${C(t[0].y)}`],o=[],l=[],r=[],h=[];for(let i=0;i<n;i+=1)o[i]=t[i+1].x-t[i].x,l[i]=t[i+1].y-t[i].y,r[i]=l[i]/o[i];h[0]=r[0],h[n]=r[n-1];for(let i=1;i<n;i+=1)if(r[i-1]*r[i]<=0)h[i]=0;else{const a=2*r[i-1]*r[i]/(r[i-1]+r[i]);h[i]=a}for(let i=0;i<n;i+=1){const a=t[i].x,v=t[i].y,O=t[i+1].x,S=t[i+1].y,R=h[i],_=h[i+1],c=a+(O-a)/3,x=v+R*(O-a)/3,P=O-(O-a)/3,k=S-_*(O-a)/3;e.push(`C ${C(c)},${C(x)} ${C(P)},${C(k)} ${C(O)},${C(S)}`)}return e.join(" ")}function ot(t,n=1e3,e){t.style.opacity="1";const o=t.getTotalLength();t.style.strokeDasharray=String(o),t.style.strokeDashoffset=String(o),t.getBoundingClientRect(),t.style.transition=`stroke-dashoffset ${n}ms ease-in-out`,t.style.strokeDashoffset="0",t.addEventListener("transitionend",function l(){t.style.transition="",t.removeEventListener("transitionend",l),e&&e()})}function st(t,n,e=1e3){n.style.opacity="1";const o=n.getBBox(),l=o.width,r=document.createElementNS("http://www.w3.org/2000/svg","clipPath"),h="clip-"+Math.random().toString(36).substr(2,9);r.setAttribute("id",h);const i=document.createElementNS("http://www.w3.org/2000/svg","rect");i.setAttribute("x",o.x.toString()),i.setAttribute("y",o.y.toString()),i.setAttribute("width","0"),i.setAttribute("height",o.height.toString()),r.appendChild(i);let a=t.querySelector("defs");a||(a=document.createElementNS("http://www.w3.org/2000/svg","defs"),t.insertBefore(a,t.firstChild)),a.appendChild(r),n.setAttribute("clip-path",`url(#${h})`),i.style.transition=`width ${e}ms ease-out`,i.getBoundingClientRect(),i.setAttribute("width",l.toString()),i.addEventListener("transitionend",function v(){n.removeAttribute("clip-path"),r.parentNode&&r.parentNode.removeChild(r),i.removeEventListener("transitionend",v)})}function at(){return document.querySelectorAll(".tiny-spark")}function X(t,n){return Object.keys(t.dataset).includes(n)}function g(t,n,e){return X(t,n)?t.dataset[n]:e}function lt(t){if(!t)return{color:"#1A1A1A",backgroundColor:"#FFFFFF"};const n=window.getComputedStyle(t),e=n.getPropertyValue("color")||"#1A1A1A",o=n.getPropertyValue("background-color"),l=n.getPropertyValue("background");return{color:e,backgroundColor:o||l||"#FFFFFF"}}function q(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){const n=Math.random()*16|0;return(t=="x"?n:n&3|8).toString(16)})}function J(t){const n=t.getAttribute("data-set");if(!n)return[];try{const e=JSON.parse(n);return Array.isArray(e)&&e.every(o=>typeof o=="number"||[null,void 0].includes(o))?e:(console.warn("data-set is not an array of numbers."),[])}catch(e){return console.error("Error parsing data-set:",e),[]}}function ut(t){const n=t.getAttribute("data-dates");if(!n)return[];try{const e=JSON.parse(n);return Array.isArray(e)&&e.every(o=>typeof o=="string")?e:(console.warn("data-dates is not an array of strings"),[])}catch(e){return console.error("Error parsing data-dates",e),[]}}function Y(t){return{min:Math.min(...t),max:Math.max(...t)}}function M(){return new Promise(t=>setTimeout(t,0))}function Q(t,n){const e=String(g(t,f.NUMBER_LOCALE,navigator.language||"en-US")),o=Number(String(g(t,f.NUMBER_ROUNDING,0)));return n.toLocaleString(e,{useGrouping:!0,minimumFractionDigits:o,maximumFractionDigits:o})}function V(t,n,e){if(!t.createSVGPoint||!t.getScreenCTM)throw new Error("Your browser does not support SVG coordinate transformation.");const o=t.getScreenCTM();if(!o)throw new Error("Cannot obtain the screen CTM.");const l=t.createSVGPoint();l.x=n,l.y=e;const r=l.matrixTransform(o);return{x:r.x,y:r.y}}function T(t,n,e,o,l){if(dt(o),!l)return;const r=n.dataset.type&&n.dataset.type===j.BAR;let h=0,i=0;r?(h=V(t,e.x,e.y).x,i=V(t,e.x,e.y).y):(console.log("here"),h=V(t,e.x,e.y).x,e.isPositive?i=V(t,e.x,e.y).y:i=V(t,e.x,e.bar.y+e.bar.h).y);const a=document.createElement("div");a.style.opacity="0",a.classList.add("tiny-spark-tooltip"),a.setAttribute("id",`tooltip_${o}`),a.setAttribute("role","tooltip"),a.setAttribute("aria-live","polite"),a.setAttribute("aria-hidden",String(!l)),a.style.pointerEvents="none",a.style.position="fixed",a.style.top=i+"px",a.style.left=h+"px",a.style.width="fit-content",a.innerHTML=`
2
+ <div class="tiny-spark-tooltip-content">${e.d?`${e.d}: `:""}${[null,void 0].includes(e.v)?"-":Q(n,Number(e.v))}</div>
3
+ `,document.body.appendChild(a),M().then(()=>{const{width:v,height:O}=a.getBoundingClientRect();a.style.left=`${h-v/2}px`,a.style.top=`${i-O-Number(String(Number(g(n,f.PLOT_RADIUS,3))*1.5))}px`}).then(()=>{a.style.opacity="1"})}function dt(t){const n=document.getElementById(`tooltip_${t}`);n==null||n.remove()}function ct(t){t.innerHTML=""}function gt(t,n){var it;const e=t.dataset.type&&t.dataset.type==="bar";let o=n;ct(t);const{svg:l,svgId:r,width:h,height:i,viewBox:a}=rt(t),{color:v,backgroundColor:O}=lt(t),S={T:12,R:12,B:12,L:12},R=q(),_=String(g(t,f.SHOW_LAST_VALUE,"false"))==="true",c={left:S.L,top:S.T,width:h-S.L-S.R,height:i-S.T-S.B,bottom:i-S.B},x=J(t),{min:P}=Y(x),k=x.map(s=>[null,void 0].includes(s)?s:s+(P<0?Math.abs(P):0)),{max:tt}=Y(k);let L=c.width/(x.length-1)===1/0?c.width:c.width/(x.length-1);if(e){const[s,m,b,u]=a.split(" ");l.setAttribute("viewBox",`${Number(s)-L/2} ${m} ${Number(b)+L} ${u}`)}const B=!x.some(s=>s>=0),ht=ut(t),y=k.map((s,m)=>{const b={w:k.length===1?L/2:0,h:k.length===1?c.height/2:0},u=c.left+L*m+b.w,d=(1-(s||0)/tt)*c.height+b.h+S.T,F=(1-(P<0?Math.abs(P):0)/tt)*c.height+S.T+b.h,G=x[m]>=0;return{y:B&&x.length===1?c.top+c.height/2:d,x:u,v:x[m],d:ht[m]||null,isPositive:G,bar:{x:u-L/2,y:x.length===1?c.top:G?d:B?c.top:F,h:x.length===1?c.height:G?F-d:B&&x.length===0?c.height:isNaN(d-F)?0:d-F,w:L}}}),w=[...y].filter(({v:s})=>![null,void 0].includes(s)),et=t.getAttribute("data-animation"),A=document.createElementNS(N,"path");A.classList.add("tiny-spark-line-path");const $=document.createElementNS(N,"path");$.classList.add("tiny-spark-line-area"),e||(!t.dataset.curve||t.dataset.curve==="true"?A.setAttribute("d",`M ${Z(w)}`):A.setAttribute("d",`M ${K(w)}`),A.setAttribute("fill","none"),A.setAttribute("stroke",String(g(t,f.LINE_COLOR,v))),A.setAttribute("stroke-width",String(g(t,f.LINE_THICKNESS,2))),A.setAttribute("stroke-linecap","round"),et==="true"&&o&&(A.style.opacity="0",$.style.opacity="0"),y.length&&(!t.dataset.curve||t.dataset.curve==="true"?$.setAttribute("d",`M ${w[0].x},${c.bottom} ${Z(w)} L ${w.at(-1).x},${c.bottom} Z`):$.setAttribute("d",`M ${w[0].x},${c.bottom} ${K(w)} L ${w.at(-1).x},${c.bottom} Z`)),$.setAttribute("fill",String(g(t,f.AREA_COLOR,"transparent"))),y.length>1&&(l.appendChild($),l.appendChild(A)));const W=[];y.forEach((s,m)=>{const b=document.createElementNS(N,"line");b.classList.add("tiny-spark-indicator"),b.setAttribute("id",`indicator_${r}_${m}`),b.setAttribute("x1",String(c.left+(y.length===1?c.width/2:m*L))),b.setAttribute("x2",String(c.left+(y.length===1?c.width/2:m*L))),b.setAttribute("y1",String(c.top)),b.setAttribute("y2",String(c.bottom)),b.setAttribute("stroke",String(g(t,f.INDICATOR_COLOR,"#1A1A1A"))),b.setAttribute("stroke-width",String(g(t,f.INDICATOR_WIDTH,"1"))),b.setAttribute("stroke-linecap","round"),b.style.pointerEvents="none",b.style.opacity="0",W.push(b),l.appendChild(b)});let U=[],D=[];const nt=Number(String(g(t,f.PLOT_RADIUS,0)))>0,pt=!String(g(t,f.HIDE_PLOTS_ABOVE,""))||y.length<=Number(String(g(t,f.HIDE_PLOTS_ABOVE,0))),E=nt&&pt;e&&y.forEach(({bar:s,v:m},b)=>{if(![null,void 0].includes(m)){const u=document.createElementNS(N,"rect");u.classList.add("tiny-spark-datapoint-bar"),u.setAttribute("x",String(s.x)),u.setAttribute("y",String(s.y)),u.setAttribute("width",String(s.w)),u.setAttribute("height",String(s.h)),u.setAttribute("fill",String(g(t,f.PLOT_COLOR,String(g(t,"lineColor",v))))),u.style.opacity=y.length===1?"1":"0",u.style.transition=`opacity ${b*(1e3*2/y.length)}ms ease-in`,D.push(u),l.appendChild(u)}}),nt&&!e&&y.forEach(({x:s,y:m,v:b},u)=>{if(![null,void 0].includes(b)){const d=document.createElementNS(N,"circle");d.classList.add("tiny-spark-datapoint-circle"),d.classList.add(`circle-${r}`),d.setAttribute("id",`circle_${r}_${u}`),d.setAttribute("cx",String(s||0)),d.setAttribute("cy",String(m||0)),d.setAttribute("r",String(g(t,f.PLOT_RADIUS,3))),d.setAttribute("fill",String(g(t,f.PLOT_COLOR,String(g(t,"lineColor",v))))),d.setAttribute("stroke",O),d.style.opacity=y.length===1?"1":"0",d.style.transition=`opacity ${u*(1e3*2/y.length)}ms ease-in`,d.style.pointerEvents="none",U.push(d),E&&l.appendChild(d)}});let p=null;if(_&&y.length&&y.at(-1)){const s=Number(g(t,f.LAST_VALUE_FONT_SIZE,12));p=document.createElementNS(N,"text"),p.classList.add("tiny-spark-last-value"),p.setAttribute("id",R),e?(p.setAttribute("x",String(y.at(-1).x+Number(g(t,f.LINE_THICKNESS,2)))),p.setAttribute("y",(it=y.at(-1))!=null&&it.isPositive?String(y.at(-1).y-s/3):String(y.at(-1).bar.y+y.at(-1).bar.h+s)),p.setAttribute("text-anchor","middle")):(p.setAttribute("x",String(y.at(-1).x+6+Number(g(t,f.LINE_THICKNESS,2)))),p.setAttribute("y",String(y.at(-1).y+s/3)),p.setAttribute("text-anchor","start")),p.setAttribute("font-size",String(s)+"px"),p.setAttribute("fill",String(g(t,f.LAST_VALUE_COLOR,String(g(t,f.INDICATOR_COLOR,"#1A1A1A"))))),p.innerHTML=Q(t,Number(y.at(-1).v)),p.style.opacity=y.length===1?"1":"0",l.appendChild(p)}y.forEach((s,m)=>{const b=U[m],u=document.createElementNS(N,"rect");u.classList.add("tiny-spark-tooltip-trap"),u.setAttribute("x",`${y.length===1?0:c.left+m*L-L/2}`),u.setAttribute("y",`${c.top}`),u.setAttribute("height",`${c.height}`),u.setAttribute("width",`${L}`),u.setAttribute("fill","transparent"),u.setAttribute("aria-describedby",`tooltip_${r}`),u.addEventListener("mouseenter",()=>{if(T(l,t,s,r,!0),E){const d=document.getElementById(`circle_${r}_${m}`);d==null||d.setAttribute("r",String(Number(g(t,f.PLOT_RADIUS,3))*1.5))}else l.appendChild(b);W[m].style.opacity="1",_&&p&&(m===y.length-1?p.style.opacity="0":p.style.opacity="1")}),u.addEventListener("mouseout",()=>{if(T(l,t,s,r,!1),E){const d=document.getElementById(`circle_${r}_${m}`);d==null||d.setAttribute("r",String(Number(g(t,f.PLOT_RADIUS,3))))}else b.remove();W.forEach(d=>d.style.opacity="0"),_&&p&&(p.style.opacity="1")}),l.appendChild(u)}),et==="true"&&o?M().then(()=>{U.forEach(s=>{s.style.opacity="1"}),D.forEach(s=>{s.style.opacity="1"}),ot(A,1e3,()=>{p&&(p.style.opacity="1")}),st(l,$)}):(U.forEach(s=>{s.style.opacity="1"}),D.forEach(s=>{s.style.opacity="1"}),p&&(p.style.opacity="1")),t.appendChild(l)}function yt(){const t=at();t.length&&Array.from(t).forEach(n=>{if(!n.dataset.id){const o=q();n.setAttribute("data-id",o)}const e=n;ft(e),e.__renderCount=0,H(e),M().then(()=>{const o=new ResizeObserver(r=>{r.forEach(()=>H(e))});e.parentElement&&o.observe(e.parentElement),new MutationObserver(r=>{for(const h of r)if(h.type==="attributes"&&h.attributeName&&Object.values(z).includes(h.attributeName)){H(e);break}}).observe(e,{attributes:!0})})})}function H(t){X(t,"set")&&gt(t,t.__renderCount<2),t.__renderCount+=1}function ft(t){t.dataset.set||console.error(`Tiny-spark exception:
4
4
 
5
5
  [data-set] data attribute is missing.
6
6
  Provide an array of numbers, for example:
7
7
 
8
- data-set="[1, 2, 3]"`)}function at(t){return JSON.stringify(t)}I.render=it,I.tinyFormat=at,Object.defineProperty(I,Symbol.toStringTag,{value:"Module"})});
8
+ data-set="[1, 2, 3]"`)}function bt(t){return JSON.stringify(t)}I.render=yt,I.tinyFormat=bt,Object.defineProperty(I,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "tiny-spark",
3
3
  "private": false,
4
- "version": "0.4.2",
4
+ "version": "0.5.0",
5
5
  "type": "module",
6
6
  "description": "An elegant, reactive and responsive sparkline chart solution without dependency.",
7
7
  "author": "Alec Lloyd Probert",
@@ -30,6 +30,6 @@
30
30
  "devDependencies": {
31
31
  "@types/node": "^22.13.13",
32
32
  "typescript": "~5.7.2",
33
- "vite": "^6.2.6"
33
+ "vite": "^6.3.4"
34
34
  }
35
35
  }