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