tiny-spark 1.0.0 → 1.2.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 +10 -0
- package/dist/tiny-spark.es.js +338 -276
- package/dist/tiny-spark.umd.js +4 -4
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -44,12 +44,18 @@ Render a line chart:
|
|
|
44
44
|
data-id="myId"
|
|
45
45
|
data-type="line"
|
|
46
46
|
data-curve="true"
|
|
47
|
+
data-cut-null="false"
|
|
47
48
|
data-set="[1, 2, 3, 5, 8, 13]"
|
|
48
49
|
data-dates='["01-2026", "02-2026", "03-2026", "04-2026", "05-2026", "06-2026"]'
|
|
49
50
|
data-responsive
|
|
50
51
|
data-animation="true"
|
|
51
52
|
data-line-color="#4A4A4A"
|
|
52
53
|
data-area-color="#1A1A1A10"
|
|
54
|
+
data-gradient-from="#FF0000"
|
|
55
|
+
data-gradient-to="#FFAA00"
|
|
56
|
+
data-temperature-colors="['#00FF00', '#FF0000']"
|
|
57
|
+
data-gradient-from-opacity="1"
|
|
58
|
+
data-gradient-to-opacity="1"
|
|
53
59
|
data-line-thickness="4"
|
|
54
60
|
data-plot-color="#2A2A2A"
|
|
55
61
|
data-plot-radius="2"
|
|
@@ -79,6 +85,10 @@ Render a bar chart:
|
|
|
79
85
|
data-responsive
|
|
80
86
|
data-animation="true"
|
|
81
87
|
data-line-thickness="4"
|
|
88
|
+
data-gradient-from="#FF0000"
|
|
89
|
+
data-gradient-to="#FFAA00"
|
|
90
|
+
data-gradient-from-opacity="1"
|
|
91
|
+
data-gradient-to-opacity="1"
|
|
82
92
|
data-plot-color="#2A2A2A"
|
|
83
93
|
data-number-locale="en-US"
|
|
84
94
|
data-number-rounding="2"
|
package/dist/tiny-spark.es.js
CHANGED
|
@@ -1,262 +1,275 @@
|
|
|
1
|
-
const
|
|
2
|
-
var
|
|
3
|
-
const
|
|
4
|
-
version:
|
|
1
|
+
const A = "http://www.w3.org/2000/svg";
|
|
2
|
+
var ot = /* @__PURE__ */ ((t) => (t.BAR = "bar", t.LINE = "line", t))(ot || {}), 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.CUT_NULL = "cutNull", t.GRADIENT_FROM = "gradientFrom", t.GRADIENT_TO = "gradientTo", t.GRADIENT_FROM_OPACITY = "gradientFromOpacity", t.GRADIENT_TO_OPACITY = "gradientToOpacity", t.TEMPERATURE_COLORS = "temperatureColors", t))(g || {}), H = /* @__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.CUT_NULL = "data-cut-null", t.GRADIENT_FROM = "data-gradient-from", t.GRADIENT_TO = "data-gradient-to", t.GRADIENT_FROM_OPACITY = "data-gradient-from-opacity", t.GRADIENT_TO_OPACITY = "data-gradient-to-opacity", t.TEMPERATURE_COLORS = "data-temperature-colors", t))(H || {});
|
|
3
|
+
const ft = "1.2.0", gt = {
|
|
4
|
+
version: ft
|
|
5
5
|
};
|
|
6
|
-
function
|
|
7
|
-
const { width:
|
|
8
|
-
let
|
|
9
|
-
if (!(t.dataset.type && t.dataset.type === "bar") &&
|
|
10
|
-
const
|
|
11
|
-
|
|
6
|
+
function mt(t) {
|
|
7
|
+
const { width: r, height: n } = t.parentElement.getBoundingClientRect(), o = { width: 300, height: 100 }, s = String(f(t, g.SHOW_LAST_VALUE, "false")) === "true", e = at(t), c = e && e.length ? e.at(-1) : null;
|
|
8
|
+
let i = 0;
|
|
9
|
+
if (!(t.dataset.type && t.dataset.type === "bar") && s && ![null, void 0].includes(c)) {
|
|
10
|
+
const u = Number(String(f(t, g.NUMBER_ROUNDING, 0)));
|
|
11
|
+
i = 6 + c.toFixed(u).length * (Number(f(t, g.LAST_VALUE_FONT_SIZE, 12)) / 2);
|
|
12
12
|
}
|
|
13
|
-
const a = `0 0 ${(
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
return
|
|
17
|
-
svg:
|
|
18
|
-
svgId:
|
|
19
|
-
width:
|
|
20
|
-
height: n ||
|
|
13
|
+
const a = `0 0 ${(r || o.width) + i} ${n || o.height}`, y = document.createElementNS(A, "svg"), _ = t.dataset.id;
|
|
14
|
+
y.id = _, y.setAttribute("viewBox", a), y.style.width = "100%", y.style.height = "100%";
|
|
15
|
+
const d = document.createElementNS(A, "desc");
|
|
16
|
+
return d.setAttribute("aria-hidden", "true"), d.innerHTML = `Composed with tiny-spark v${gt.version}`, y.appendChild(d), {
|
|
17
|
+
svg: y,
|
|
18
|
+
svgId: _,
|
|
19
|
+
width: r || o.width,
|
|
20
|
+
height: n || o.height,
|
|
21
21
|
viewBox: a
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
|
-
function
|
|
25
|
-
return isNaN(t) ?
|
|
24
|
+
function C(t, r = 0) {
|
|
25
|
+
return isNaN(t) ? r : t;
|
|
26
26
|
}
|
|
27
|
-
function
|
|
28
|
-
let
|
|
27
|
+
function et(t) {
|
|
28
|
+
let r = [];
|
|
29
29
|
for (let n = 0; n < t.length; n += 1)
|
|
30
|
-
|
|
31
|
-
return
|
|
30
|
+
r.push(`${C(t[n].x)},${C(t[n].y)} `);
|
|
31
|
+
return r.join(" ").trim();
|
|
32
32
|
}
|
|
33
|
-
function
|
|
33
|
+
function nt(t) {
|
|
34
34
|
if (t.length < 2) return "0,0";
|
|
35
|
-
const
|
|
36
|
-
for (let
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
for (let
|
|
40
|
-
if (e[
|
|
41
|
-
|
|
35
|
+
const r = t.length - 1, n = [`${C(t[0].x)},${C(t[0].y)}`], o = [], s = [], e = [], c = [];
|
|
36
|
+
for (let i = 0; i < r; i += 1)
|
|
37
|
+
o[i] = t[i + 1].x - t[i].x, s[i] = t[i + 1].y - t[i].y, e[i] = s[i] / o[i];
|
|
38
|
+
c[0] = e[0], c[r] = e[r - 1];
|
|
39
|
+
for (let i = 1; i < r; i += 1)
|
|
40
|
+
if (e[i - 1] * e[i] <= 0)
|
|
41
|
+
c[i] = 0;
|
|
42
42
|
else {
|
|
43
|
-
const
|
|
44
|
-
|
|
43
|
+
const m = 2 * e[i - 1] * e[i] / (e[i - 1] + e[i]);
|
|
44
|
+
c[i] = m;
|
|
45
45
|
}
|
|
46
|
-
for (let
|
|
47
|
-
const
|
|
48
|
-
n.push(`C ${
|
|
46
|
+
for (let i = 0; i < r; i += 1) {
|
|
47
|
+
const m = t[i].x, O = t[i].y, a = t[i + 1].x, y = t[i + 1].y, _ = c[i], d = c[i + 1], u = m + (a - m) / 3, I = O + _ * (a - m) / 3, $ = a - (a - m) / 3, F = y - d * (a - m) / 3;
|
|
48
|
+
n.push(`C ${C(u)},${C(I)} ${C($)},${C(F)} ${C(a)},${C(y)}`);
|
|
49
49
|
}
|
|
50
50
|
return n.join(" ");
|
|
51
51
|
}
|
|
52
|
-
function
|
|
53
|
-
const
|
|
52
|
+
function yt(t) {
|
|
53
|
+
const r = [];
|
|
54
54
|
let n = [];
|
|
55
|
-
for (const
|
|
56
|
-
|
|
57
|
-
return n.length > 1 &&
|
|
55
|
+
for (const o of t)
|
|
56
|
+
o.v == null || Number.isNaN(o.x) || Number.isNaN(o.y) ? (n.length > 1 && r.push(n), n = []) : n.push(o);
|
|
57
|
+
return n.length > 1 && r.push(n), r;
|
|
58
58
|
}
|
|
59
|
-
function
|
|
60
|
-
const
|
|
61
|
-
if (!
|
|
59
|
+
function ht(t) {
|
|
60
|
+
const r = yt(t);
|
|
61
|
+
if (!r.length) return "";
|
|
62
62
|
let n = "";
|
|
63
|
-
for (const [
|
|
64
|
-
if (
|
|
65
|
-
const e =
|
|
63
|
+
for (const [o, s] of r.entries()) {
|
|
64
|
+
if (s.length < 2) continue;
|
|
65
|
+
const e = s.length - 1, c = [], i = [], m = [], O = [];
|
|
66
66
|
for (let a = 0; a < e; a += 1)
|
|
67
|
-
|
|
68
|
-
|
|
67
|
+
c[a] = s[a + 1].x - s[a].x, i[a] = s[a + 1].y - s[a].y, m[a] = i[a] / c[a];
|
|
68
|
+
O[0] = m[0], O[e] = m[e - 1];
|
|
69
69
|
for (let a = 1; a < e; a += 1)
|
|
70
|
-
if (
|
|
71
|
-
|
|
70
|
+
if (m[a - 1] * m[a] <= 0)
|
|
71
|
+
O[a] = 0;
|
|
72
72
|
else {
|
|
73
|
-
const
|
|
74
|
-
|
|
73
|
+
const y = 2 * m[a - 1] * m[a] / (m[a - 1] + m[a]);
|
|
74
|
+
O[a] = y;
|
|
75
75
|
}
|
|
76
|
-
n += `${
|
|
76
|
+
n += `${o === 0 ? "" : "M"}${C(s[0].x)},${C(s[0].y)} `;
|
|
77
77
|
for (let a = 0; a < e; a += 1) {
|
|
78
|
-
const
|
|
79
|
-
n += `C${
|
|
78
|
+
const y = s[a].x, _ = s[a].y, d = s[a + 1].x, u = s[a + 1].y, I = O[a], $ = O[a + 1], F = y + (d - y) / 3, k = _ + I * (d - y) / 3, L = d - (d - y) / 3, w = u - $ * (d - y) / 3;
|
|
79
|
+
n += `C${C(F)},${C(k)} ${C(L)},${C(w)} ${C(d)},${C(u)} `;
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
return n.trim();
|
|
83
83
|
}
|
|
84
|
-
function
|
|
85
|
-
let
|
|
86
|
-
const
|
|
87
|
-
for (let
|
|
88
|
-
const e = t[
|
|
89
|
-
if (!
|
|
84
|
+
function bt(t) {
|
|
85
|
+
let r = "", n = !1;
|
|
86
|
+
const o = (s) => s.v != null && Number.isFinite(s.x) && Number.isFinite(s.y);
|
|
87
|
+
for (let s = 0; s < t.length; s++) {
|
|
88
|
+
const e = t[s];
|
|
89
|
+
if (!o(e))
|
|
90
90
|
continue;
|
|
91
|
-
const
|
|
91
|
+
const c = `${C(e.x)},${C(e.y)}`;
|
|
92
92
|
if (!n)
|
|
93
|
-
|
|
93
|
+
r += c, n = !0;
|
|
94
94
|
else {
|
|
95
|
-
const
|
|
96
|
-
|
|
95
|
+
const i = t[s - 1], m = o(i) ? "L" : "M";
|
|
96
|
+
r += `${m}${c}`;
|
|
97
97
|
}
|
|
98
|
-
|
|
98
|
+
r += " ";
|
|
99
99
|
}
|
|
100
|
-
return
|
|
100
|
+
return r.trim();
|
|
101
101
|
}
|
|
102
|
-
function
|
|
103
|
-
const
|
|
102
|
+
function Nt(t) {
|
|
103
|
+
const r = [];
|
|
104
104
|
let n = [];
|
|
105
|
-
for (const
|
|
106
|
-
!
|
|
107
|
-
return n.length &&
|
|
105
|
+
for (const o of t)
|
|
106
|
+
!o || o.v == null || Number.isNaN(o.x) || Number.isNaN(o.y) ? (n.length && r.push(n), n = []) : n.push(o);
|
|
107
|
+
return n.length && r.push(n), r;
|
|
108
108
|
}
|
|
109
|
-
function
|
|
109
|
+
function Ot(t, r) {
|
|
110
110
|
if (!t[0]) return [-10, -10, "", -10, -10].toString();
|
|
111
|
-
const n =
|
|
112
|
-
return n.length ? n.map((
|
|
113
|
-
const
|
|
114
|
-
return
|
|
115
|
-
|
|
116
|
-
}), [
|
|
111
|
+
const n = Nt(t);
|
|
112
|
+
return n.length ? n.map((o) => {
|
|
113
|
+
const s = { x: o[0].x, y: r }, e = { x: o.at(-1)?.x, y: r }, c = [];
|
|
114
|
+
return o.forEach((i) => {
|
|
115
|
+
c.push(`${i.x},${i.y} `);
|
|
116
|
+
}), [s.x, s.y, ...c, e.x, e.y].toString();
|
|
117
117
|
}).join(";") : "";
|
|
118
118
|
}
|
|
119
|
-
function
|
|
120
|
-
function
|
|
121
|
-
const
|
|
122
|
-
let
|
|
123
|
-
for (const
|
|
124
|
-
!
|
|
125
|
-
return
|
|
119
|
+
function St(t, r, n = !1, o = !0) {
|
|
120
|
+
function s(c) {
|
|
121
|
+
const i = [];
|
|
122
|
+
let m = [];
|
|
123
|
+
for (const O of c)
|
|
124
|
+
!O || O.v == null || Number.isNaN(O.x) || Number.isNaN(O.y) ? (m.length > 1 && i.push(m), m = []) : m.push(O);
|
|
125
|
+
return m.length > 1 && i.push(m), i;
|
|
126
126
|
}
|
|
127
|
-
return (n ?
|
|
128
|
-
if (
|
|
129
|
-
const
|
|
130
|
-
for (let
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
for (let
|
|
134
|
-
if (a[
|
|
135
|
-
|
|
127
|
+
return (n ? s(t) : [t]).map((c) => {
|
|
128
|
+
if (c.length < 2) return "";
|
|
129
|
+
const i = c.length - 1, m = [], O = [], a = [], y = [];
|
|
130
|
+
for (let d = 0; d < i; d += 1)
|
|
131
|
+
m[d] = c[d + 1].x - c[d].x, O[d] = c[d + 1].y - c[d].y, a[d] = O[d] / m[d];
|
|
132
|
+
y[0] = a[0], y[i] = a[i - 1];
|
|
133
|
+
for (let d = 1; d < i; d += 1)
|
|
134
|
+
if (a[d - 1] * a[d] <= 0)
|
|
135
|
+
y[d] = 0;
|
|
136
136
|
else {
|
|
137
|
-
const
|
|
138
|
-
|
|
137
|
+
const u = 2 * a[d - 1] * a[d] / (a[d - 1] + a[d]);
|
|
138
|
+
y[d] = u;
|
|
139
139
|
}
|
|
140
|
-
let
|
|
141
|
-
|
|
142
|
-
for (let
|
|
143
|
-
const
|
|
144
|
-
|
|
140
|
+
let _ = `M${c[0].x},${r}`;
|
|
141
|
+
_ += ` L${c[0].x},${c[0].y}`;
|
|
142
|
+
for (let d = 0; d < i; d += 1) {
|
|
143
|
+
const u = c[d].x, I = c[d].y, $ = c[d + 1].x, F = c[d + 1].y, k = y[d], L = y[d + 1], w = u + ($ - u) / 3, B = I + k * ($ - u) / 3, N = $ - ($ - u) / 3, Y = F - L * ($ - u) / 3;
|
|
144
|
+
_ += ` C${w},${B} ${N},${Y} ${$},${F}`;
|
|
145
145
|
}
|
|
146
|
-
return
|
|
146
|
+
return _ += ` L${c[i].x},${r} ${o ? "Z" : ""}`, _;
|
|
147
147
|
}).filter(Boolean);
|
|
148
148
|
}
|
|
149
|
-
function
|
|
149
|
+
function xt(t, r = 1e3, n) {
|
|
150
150
|
t.style.opacity = "1";
|
|
151
|
-
const
|
|
152
|
-
t.style.strokeDasharray = String(
|
|
153
|
-
t.style.transition = "", t.removeEventListener("transitionend",
|
|
151
|
+
const o = t.getTotalLength();
|
|
152
|
+
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() {
|
|
153
|
+
t.style.transition = "", t.removeEventListener("transitionend", s), n && n();
|
|
154
154
|
});
|
|
155
155
|
}
|
|
156
|
-
function
|
|
157
|
-
|
|
158
|
-
const
|
|
159
|
-
e.setAttribute("id",
|
|
160
|
-
const
|
|
161
|
-
|
|
162
|
-
let
|
|
163
|
-
|
|
164
|
-
|
|
156
|
+
function Ct(t, r, n = 1e3) {
|
|
157
|
+
r.style.opacity = "1";
|
|
158
|
+
const o = r.getBBox(), s = o.width, e = document.createElementNS("http://www.w3.org/2000/svg", "clipPath"), c = "clip-" + Math.random().toString(36).substr(2, 9);
|
|
159
|
+
e.setAttribute("id", c);
|
|
160
|
+
const i = document.createElementNS("http://www.w3.org/2000/svg", "rect");
|
|
161
|
+
i.setAttribute("x", o.x.toString()), i.setAttribute("y", o.y.toString()), i.setAttribute("width", "0"), i.setAttribute("height", o.height.toString()), e.appendChild(i);
|
|
162
|
+
let m = t.querySelector("defs");
|
|
163
|
+
m || (m = document.createElementNS("http://www.w3.org/2000/svg", "defs"), t.insertBefore(m, t.firstChild)), m.appendChild(e), r.setAttribute("clip-path", `url(#${c})`), i.style.transition = `width ${n}ms ease-out`, i.getBoundingClientRect(), i.setAttribute("width", s.toString()), i.addEventListener("transitionend", function O() {
|
|
164
|
+
r.removeAttribute("clip-path"), e.parentNode && e.parentNode.removeChild(e), i.removeEventListener("transitionend", O);
|
|
165
165
|
});
|
|
166
166
|
}
|
|
167
|
-
function
|
|
167
|
+
function At() {
|
|
168
168
|
return document.querySelectorAll(".tiny-spark");
|
|
169
169
|
}
|
|
170
|
-
function
|
|
171
|
-
return Object.keys(t.dataset).includes(
|
|
170
|
+
function st(t, r) {
|
|
171
|
+
return Object.keys(t.dataset).includes(r);
|
|
172
172
|
}
|
|
173
|
-
function
|
|
174
|
-
return
|
|
173
|
+
function f(t, r, n) {
|
|
174
|
+
return st(t, r) ? t.dataset[r] : n;
|
|
175
175
|
}
|
|
176
|
-
function
|
|
176
|
+
function It(t) {
|
|
177
177
|
if (!t) return {
|
|
178
178
|
color: "#1A1A1A",
|
|
179
179
|
backgroundColor: "#FFFFFF"
|
|
180
180
|
};
|
|
181
|
-
const
|
|
182
|
-
return { color: n, backgroundColor:
|
|
181
|
+
const r = window.getComputedStyle(t), n = r.getPropertyValue("color") || "#1A1A1A", o = r.getPropertyValue("background-color"), s = r.getPropertyValue("background");
|
|
182
|
+
return { color: n, backgroundColor: o || s || "#FFFFFF" };
|
|
183
183
|
}
|
|
184
|
-
function
|
|
184
|
+
function W() {
|
|
185
185
|
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(t) {
|
|
186
|
-
const
|
|
187
|
-
return (t == "x" ?
|
|
186
|
+
const r = Math.random() * 16 | 0;
|
|
187
|
+
return (t == "x" ? r : r & 3 | 8).toString(16);
|
|
188
188
|
});
|
|
189
189
|
}
|
|
190
|
-
function
|
|
191
|
-
const
|
|
192
|
-
if (!
|
|
193
|
-
const n =
|
|
190
|
+
function at(t) {
|
|
191
|
+
const r = t.getAttribute(H.SET);
|
|
192
|
+
if (!r) return [];
|
|
193
|
+
const n = r.replace(/,(?=,)/g, ",null").replace(/\[,/g, "[null,").replace(/,\]/g, ",null]");
|
|
194
194
|
try {
|
|
195
|
-
const
|
|
196
|
-
return Array.isArray(
|
|
197
|
-
} catch (
|
|
198
|
-
return console.error("Error parsing data-set:",
|
|
195
|
+
const o = JSON.parse(n);
|
|
196
|
+
return Array.isArray(o) && o.every((s) => typeof s == "number" || [null, void 0].includes(s)) ? o : (console.warn("data-set is not an array of numbers."), []);
|
|
197
|
+
} catch (o) {
|
|
198
|
+
return console.error("Error parsing data-set:", o), [];
|
|
199
199
|
}
|
|
200
200
|
}
|
|
201
|
-
function
|
|
202
|
-
|
|
203
|
-
|
|
201
|
+
function _t(t, r) {
|
|
202
|
+
return r <= 1 ? "0%" : `${t * 100 / (r - 1)}%`;
|
|
203
|
+
}
|
|
204
|
+
function $t(t) {
|
|
205
|
+
const r = t.getAttribute(H.DATES);
|
|
206
|
+
if (!r) return [];
|
|
204
207
|
try {
|
|
205
|
-
const n = JSON.parse(
|
|
206
|
-
return Array.isArray(n) && n.every((
|
|
208
|
+
const n = JSON.parse(r.replaceAll("'", '"'));
|
|
209
|
+
return Array.isArray(n) && n.every((o) => typeof o == "string") ? n : (console.warn("data-dates is not an array of strings"), []);
|
|
207
210
|
} catch (n) {
|
|
208
211
|
return console.error("Error parsing data-dates", n), [];
|
|
209
212
|
}
|
|
210
213
|
}
|
|
211
|
-
function
|
|
214
|
+
function Lt(t) {
|
|
215
|
+
const r = t.getAttribute(H.TEMPERATURE_COLORS);
|
|
216
|
+
if (!r) return [];
|
|
217
|
+
try {
|
|
218
|
+
const n = JSON.parse(r.replaceAll("'", '"'));
|
|
219
|
+
return Array.isArray(n) && n.every((o) => typeof o == "string") ? n : (console.warn("data-temperature-colors is not an array of strings"), []);
|
|
220
|
+
} catch (n) {
|
|
221
|
+
return console.error("Error parsing data-temperature-colors", n), [];
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
function rt(t) {
|
|
212
225
|
return {
|
|
213
226
|
min: Math.min(...t),
|
|
214
227
|
max: Math.max(...t)
|
|
215
228
|
};
|
|
216
229
|
}
|
|
217
|
-
function
|
|
230
|
+
function lt() {
|
|
218
231
|
return new Promise((t) => setTimeout(t, 0));
|
|
219
232
|
}
|
|
220
|
-
function
|
|
221
|
-
const n = String(
|
|
222
|
-
return
|
|
233
|
+
function ut(t, r) {
|
|
234
|
+
const n = String(f(t, g.NUMBER_LOCALE, navigator.language || "en-US")), o = Number(String(f(t, g.NUMBER_ROUNDING, 0)));
|
|
235
|
+
return r.toLocaleString(n, {
|
|
223
236
|
useGrouping: !0,
|
|
224
|
-
minimumFractionDigits:
|
|
225
|
-
maximumFractionDigits:
|
|
237
|
+
minimumFractionDigits: o,
|
|
238
|
+
maximumFractionDigits: o
|
|
226
239
|
});
|
|
227
240
|
}
|
|
228
|
-
function
|
|
241
|
+
function Rt(t, r, n) {
|
|
229
242
|
if (!t.createSVGPoint || !t.getScreenCTM)
|
|
230
|
-
|
|
231
|
-
const
|
|
232
|
-
if (!
|
|
233
|
-
|
|
234
|
-
const
|
|
235
|
-
|
|
236
|
-
const e =
|
|
243
|
+
return console.error("Your browser does not support SVG coordinate transformation."), { x: 0, y: 0 };
|
|
244
|
+
const o = t.getScreenCTM();
|
|
245
|
+
if (!o)
|
|
246
|
+
return console.error("Cannot obtain the screen CTM."), { x: 0, y: 0 };
|
|
247
|
+
const s = t.createSVGPoint();
|
|
248
|
+
s.x = r, s.y = n;
|
|
249
|
+
const e = s.matrixTransform(o);
|
|
237
250
|
return { x: e.x, y: e.y };
|
|
238
251
|
}
|
|
239
|
-
const
|
|
240
|
-
function
|
|
241
|
-
let e =
|
|
242
|
-
if (!
|
|
252
|
+
const J = {};
|
|
253
|
+
function it(t, r, n, o, s) {
|
|
254
|
+
let e = J[o];
|
|
255
|
+
if (!s) {
|
|
243
256
|
e && (cancelAnimationFrame(e.frameId), e.frameId = null, e.tool.style.opacity = "0");
|
|
244
257
|
return;
|
|
245
258
|
}
|
|
246
|
-
const
|
|
259
|
+
const c = r.dataset.type === ot.BAR, { x: i, y: m } = Rt(
|
|
247
260
|
t,
|
|
248
261
|
n.x,
|
|
249
|
-
|
|
262
|
+
c && !n.isPositive ? n.bar.y : n.y
|
|
250
263
|
);
|
|
251
264
|
if (!e) {
|
|
252
|
-
const
|
|
253
|
-
|
|
265
|
+
const u = document.createElement("div");
|
|
266
|
+
u.classList.add("tiny-spark-tooltip"), u.setAttribute("id", `tooltip_${o}`), u.setAttribute("role", "tooltip"), u.setAttribute("aria-live", "polite"), u.style.position = "fixed", u.style.pointerEvents = "none", u.style.opacity = "0", u.style.willChange = "top, left", document.body.appendChild(u), e = J[o] = {
|
|
254
267
|
targetX: 0,
|
|
255
268
|
targetY: 0,
|
|
256
269
|
displayX: 0,
|
|
257
270
|
displayY: 0,
|
|
258
271
|
frameId: null,
|
|
259
|
-
tool:
|
|
272
|
+
tool: u,
|
|
260
273
|
width: 0,
|
|
261
274
|
height: 0,
|
|
262
275
|
hasSnapped: !1
|
|
@@ -264,149 +277,198 @@ function J(t, i, n, s, r) {
|
|
|
264
277
|
}
|
|
265
278
|
e.tool.setAttribute("aria-hidden", "false"), e.tool.innerHTML = `
|
|
266
279
|
<div class="tiny-spark-tooltip-content">
|
|
267
|
-
${n.d ? `${n.d}: ` : ""}${[null, void 0].includes(n.v) ? "-" :
|
|
280
|
+
${n.d ? `${n.d}: ` : ""}${[null, void 0].includes(n.v) ? "-" : ut(r, Number(n.v))}
|
|
268
281
|
</div>
|
|
269
282
|
`;
|
|
270
|
-
const { width:
|
|
271
|
-
e.width =
|
|
272
|
-
const
|
|
273
|
-
if (e.targetX =
|
|
283
|
+
const { width: O, height: a } = e.tool.getBoundingClientRect();
|
|
284
|
+
e.width = O, e.height = a;
|
|
285
|
+
const y = Number(f(r, g.PLOT_RADIUS, 3));
|
|
286
|
+
if (e.targetX = i - e.width / 2, e.targetY = m - e.height - y * 1.5, !e.hasSnapped) {
|
|
274
287
|
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;
|
|
275
288
|
return;
|
|
276
289
|
}
|
|
277
|
-
const
|
|
278
|
-
function
|
|
279
|
-
e.displayX += (e.targetX - e.displayX) *
|
|
290
|
+
const _ = Number(f(r, g.TOOLTIP_SMOOTHING, 1)) / 10;
|
|
291
|
+
function d() {
|
|
292
|
+
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(d);
|
|
280
293
|
}
|
|
281
|
-
e.frameId == null &&
|
|
294
|
+
e.frameId == null && d();
|
|
295
|
+
}
|
|
296
|
+
function q({ id: t, colorStart: r, colorEnd: n, opacityStart: o, opacityEnd: s }) {
|
|
297
|
+
const e = document.createElementNS(A, "linearGradient");
|
|
298
|
+
e.setAttribute("id", t), e.setAttribute("x1", "0"), e.setAttribute("x2", "0"), e.setAttribute("y1", "0"), e.setAttribute("y2", "1");
|
|
299
|
+
const c = document.createElementNS(A, "stop");
|
|
300
|
+
c.setAttribute("offset", "0%"), c.setAttribute("stop-color", r), c.setAttribute("stop-opacity", String(o));
|
|
301
|
+
const i = document.createElementNS(A, "stop");
|
|
302
|
+
return i.setAttribute("offset", "100%"), i.setAttribute("stop-color", n), i.setAttribute("stop-opacity", String(s)), [c, i].forEach((m) => {
|
|
303
|
+
e.appendChild(m);
|
|
304
|
+
}), e;
|
|
282
305
|
}
|
|
283
|
-
function
|
|
306
|
+
function vt(t) {
|
|
284
307
|
t.innerHTML = "";
|
|
285
308
|
}
|
|
286
|
-
function
|
|
309
|
+
function Ft(t, r) {
|
|
287
310
|
const n = t.dataset.type && t.dataset.type === "bar";
|
|
288
|
-
let
|
|
289
|
-
|
|
290
|
-
const { svg:
|
|
291
|
-
left:
|
|
292
|
-
top:
|
|
293
|
-
width:
|
|
294
|
-
height:
|
|
295
|
-
bottom:
|
|
296
|
-
},
|
|
297
|
-
let
|
|
311
|
+
let o = r;
|
|
312
|
+
vt(t);
|
|
313
|
+
const { svg: s, svgId: e, width: c, height: i, viewBox: m } = mt(t), { color: O, backgroundColor: a } = It(t), y = { T: 12, R: 12, B: 12, L: 12 }, _ = W(), d = String(f(t, g.SHOW_LAST_VALUE, "false")) === "true", u = {
|
|
314
|
+
left: y.L,
|
|
315
|
+
top: y.T,
|
|
316
|
+
width: c - y.L - y.R,
|
|
317
|
+
height: i - y.T - y.B,
|
|
318
|
+
bottom: i - y.B
|
|
319
|
+
}, I = at(t), { min: $ } = rt(I), F = I.map((l) => [null, void 0].includes(l) ? l : l + ($ < 0 ? Math.abs($) : 0)), { max: k } = rt(F);
|
|
320
|
+
let L = u.width / (I.length - 1) === 1 / 0 ? u.width : u.width / (I.length - 1);
|
|
298
321
|
if (n) {
|
|
299
|
-
const [
|
|
300
|
-
|
|
322
|
+
const [l, h, b, p] = m.split(" ");
|
|
323
|
+
s.setAttribute("viewBox", `${Number(l) - L / 2} ${h} ${Number(b) + L} ${p}`);
|
|
301
324
|
}
|
|
302
|
-
const
|
|
303
|
-
const
|
|
304
|
-
w:
|
|
305
|
-
h:
|
|
306
|
-
},
|
|
325
|
+
const w = !I.some((l) => l >= 0), B = $t(t), N = F.map((l, h) => {
|
|
326
|
+
const b = {
|
|
327
|
+
w: F.length === 1 ? L / 2 : 0,
|
|
328
|
+
h: F.length === 1 ? u.height / 2 : 0
|
|
329
|
+
}, p = u.left + L * h + b.w, S = (1 - (l || 0) / k) * u.height + b.h + y.T, E = (1 - ($ < 0 ? Math.abs($) : 0) / k) * u.height + y.T + b.h, G = I[h] >= 0;
|
|
307
330
|
return {
|
|
308
|
-
y:
|
|
309
|
-
x:
|
|
310
|
-
v:
|
|
311
|
-
d:
|
|
331
|
+
y: w && I.length === 1 ? u.top + u.height / 2 : S,
|
|
332
|
+
x: p,
|
|
333
|
+
v: I[h],
|
|
334
|
+
d: B[h] || null,
|
|
312
335
|
isPositive: G,
|
|
313
336
|
bar: {
|
|
314
|
-
x:
|
|
315
|
-
y:
|
|
316
|
-
h:
|
|
317
|
-
w:
|
|
337
|
+
x: p - L / 2,
|
|
338
|
+
y: I.length === 1 ? u.top : G ? S : w ? u.top : E,
|
|
339
|
+
h: I.length === 1 ? u.height : G ? E - S : w && I.length === 0 ? u.height : isNaN(S - E) ? 0 : S - E,
|
|
340
|
+
w: L
|
|
318
341
|
}
|
|
319
342
|
};
|
|
320
343
|
});
|
|
321
|
-
function
|
|
322
|
-
const
|
|
323
|
-
return
|
|
344
|
+
function Y() {
|
|
345
|
+
const l = document.createElementNS(A, "path");
|
|
346
|
+
return l.classList.add("tiny-spark-line-area"), l;
|
|
347
|
+
}
|
|
348
|
+
function ct(l) {
|
|
349
|
+
const h = document.createElementNS(A, "defs");
|
|
350
|
+
return h.appendChild(q({
|
|
351
|
+
id: l,
|
|
352
|
+
colorStart: String(f(t, g.GRADIENT_FROM, "#FFFFFF")),
|
|
353
|
+
colorEnd: String(f(t, g.GRADIENT_TO, "#FFFFFF")),
|
|
354
|
+
opacityStart: Math.max(0, Math.min(1, Number(f(t, g.GRADIENT_FROM_OPACITY, 1)))),
|
|
355
|
+
opacityEnd: Math.max(0, Math.min(1, Number(f(t, g.GRADIENT_TO_OPACITY, 1))))
|
|
356
|
+
})), h;
|
|
357
|
+
}
|
|
358
|
+
function dt(l) {
|
|
359
|
+
const h = document.createElementNS(A, "defs");
|
|
360
|
+
return h.appendChild(q({
|
|
361
|
+
id: `pos_${l}`,
|
|
362
|
+
colorStart: String(f(t, g.GRADIENT_FROM, "#FFFFFF")),
|
|
363
|
+
colorEnd: String(f(t, g.GRADIENT_TO, "#FFFFFF")),
|
|
364
|
+
opacityStart: Math.max(0, Math.min(1, Number(f(t, g.GRADIENT_FROM_OPACITY, 1)))),
|
|
365
|
+
opacityEnd: Math.max(0, Math.min(1, Number(f(t, g.GRADIENT_TO_OPACITY, 1))))
|
|
366
|
+
})), h.appendChild(q({
|
|
367
|
+
id: `neg_${l}`,
|
|
368
|
+
colorStart: String(f(t, g.GRADIENT_TO, "#FFFFFF")),
|
|
369
|
+
colorEnd: String(f(t, g.GRADIENT_FROM, "#FFFFFF")),
|
|
370
|
+
opacityStart: Math.max(0, Math.min(1, Number(f(t, g.GRADIENT_TO_OPACITY, 1)))),
|
|
371
|
+
opacityEnd: Math.max(0, Math.min(1, Number(f(t, g.GRADIENT_FROM_OPACITY, 1))))
|
|
372
|
+
})), h;
|
|
324
373
|
}
|
|
325
|
-
const
|
|
326
|
-
|
|
327
|
-
const
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
374
|
+
const v = [...N].map((l) => [null, void 0, 1 / 0, -1 / 0, NaN, "NaN"].includes(l.v) ? { ...l, v: null } : l), Q = t.getAttribute("data-animation"), R = document.createElementNS(A, "path");
|
|
375
|
+
R.classList.add("tiny-spark-line-path");
|
|
376
|
+
const P = Y(), U = [], V = !!f(t, g.GRADIENT_FROM, "") && !!f(t, g.GRADIENT_TO, ""), M = W();
|
|
377
|
+
if (!n) {
|
|
378
|
+
!t.dataset.curve || t.dataset.curve === "true" ? !t.dataset.cutNull || t.dataset.cutNull === "false" ? R.setAttribute("d", `M ${nt(v)}`) : R.setAttribute("d", `M ${ht(v)}`) : !t.dataset.cutNull || t.dataset.cutNull === "false" ? R.setAttribute("d", `M ${et(v)}`) : R.setAttribute("d", `M ${bt(v)}`), R.setAttribute("fill", "none");
|
|
379
|
+
const l = Lt(t);
|
|
380
|
+
if (l.length) {
|
|
381
|
+
const h = W(), b = document.createElementNS(A, "defs"), p = document.createElementNS(A, "linearGradient");
|
|
382
|
+
p.setAttribute("gradientTransform", "rotate(90)"), p.setAttribute("id", h), l.forEach((S, E) => {
|
|
383
|
+
const G = document.createElementNS(A, "stop");
|
|
384
|
+
G.setAttribute("offset", _t(E, l.length)), G.setAttribute("stop-color", S), p.appendChild(G);
|
|
385
|
+
}), b.appendChild(p), s.prepend(b), R.setAttribute("stroke", `url(#${h})`);
|
|
386
|
+
} else
|
|
387
|
+
R.setAttribute("stroke", String(f(t, g.LINE_COLOR, O)));
|
|
388
|
+
R.setAttribute("stroke-width", String(f(t, g.LINE_THICKNESS, 2))), R.setAttribute("stroke-linecap", "round"), Q === "true" && o && (R.style.opacity = "0", P.style.opacity = "0"), V && s.appendChild(ct(M)), N.length && (!t.dataset.curve || t.dataset.curve === "true" ? !t.dataset.cutNull || t.dataset.cutNull === "false" ? P.setAttribute("d", `M ${v[0].x},${u.bottom} ${nt(v)} L ${v.at(-1).x},${u.bottom} Z`) : St(v, u.bottom, !0, !0).forEach((b) => {
|
|
389
|
+
const p = Y();
|
|
390
|
+
p.setAttribute("d", b), V ? p.setAttribute("fill", `url(#${M})`) : p.setAttribute("fill", String(f(t, g.AREA_COLOR, "transparent"))), U.push(p);
|
|
391
|
+
}) : !t.dataset.cutNull || t.dataset.cutNull === "false" ? P.setAttribute("d", `M ${v[0].x},${u.bottom} ${et(v)} L ${v.at(-1).x},${u.bottom} Z`) : Ot(v, u.bottom).split(";").forEach((b) => {
|
|
392
|
+
const p = Y();
|
|
393
|
+
p.setAttribute("d", `M ${b} Z`), V ? p.setAttribute("fill", `url(#${M})`) : p.setAttribute("fill", String(f(t, g.AREA_COLOR, "transparent"))), U.push(p);
|
|
394
|
+
})), V ? P.setAttribute("fill", `url(#${M})`) : P.setAttribute("fill", String(f(t, g.AREA_COLOR, "transparent"))), N.length > 1 && (U.length ? U.forEach((h) => {
|
|
395
|
+
s.appendChild(h);
|
|
396
|
+
}) : s.appendChild(P), s.appendChild(R));
|
|
397
|
+
}
|
|
398
|
+
const Z = [];
|
|
399
|
+
N.forEach((l, h) => {
|
|
400
|
+
const b = document.createElementNS(A, "line");
|
|
401
|
+
b.classList.add("tiny-spark-indicator"), b.setAttribute("id", `indicator_${e}_${h}`), b.setAttribute("x1", String(u.left + (N.length === 1 ? u.width / 2 : h * L))), b.setAttribute("x2", String(u.left + (N.length === 1 ? u.width / 2 : h * L))), b.setAttribute("y1", String(u.top)), b.setAttribute("y2", String(u.bottom)), b.setAttribute("stroke", String(f(t, g.INDICATOR_COLOR, "#1A1A1A"))), b.setAttribute("stroke-width", String(f(t, g.INDICATOR_WIDTH, "1"))), b.setAttribute("stroke-linecap", "round"), b.style.pointerEvents = "none", b.style.opacity = "0", Z.push(b), s.appendChild(b);
|
|
341
402
|
});
|
|
342
|
-
let
|
|
343
|
-
const
|
|
344
|
-
n &&
|
|
345
|
-
if (![null, void 0].includes(
|
|
346
|
-
const
|
|
347
|
-
|
|
403
|
+
let D = [], K = [];
|
|
404
|
+
const T = Number(String(f(t, g.PLOT_RADIUS, 0))) > 0, pt = !String(f(t, g.HIDE_PLOTS_ABOVE, "")) || N.length <= Number(String(f(t, g.HIDE_PLOTS_ABOVE, 0))), j = T && pt, X = document.createElementNS(A, "g");
|
|
405
|
+
n && (V && s.appendChild(dt(M)), N.forEach(({ bar: l, v: h }, b) => {
|
|
406
|
+
if (![null, void 0].includes(h)) {
|
|
407
|
+
const p = document.createElementNS(A, "rect");
|
|
408
|
+
p.classList.add("tiny-spark-datapoint-bar"), p.setAttribute("x", String(l.x)), p.setAttribute("y", String(l.y)), p.setAttribute("width", String(l.w)), p.setAttribute("height", String(l.h)), V ? h >= 0 ? p.setAttribute("fill", `url(#pos_${M})`) : p.setAttribute("fill", `url(#neg_${M})`) : p.setAttribute("fill", String(f(t, g.PLOT_COLOR, String(f(t, "lineColor", O))))), p.style.opacity = N.length === 1 ? "1" : "0", p.style.transition = `opacity ${b * (1e3 * 2 / N.length)}ms ease-in`, K.push(p), X.appendChild(p);
|
|
348
409
|
}
|
|
349
|
-
}),
|
|
350
|
-
if (![null, void 0].includes(
|
|
351
|
-
const
|
|
352
|
-
|
|
410
|
+
}), s.appendChild(X)), T && !n && (N.forEach(({ x: l, y: h, v: b }, p) => {
|
|
411
|
+
if (![null, void 0].includes(b)) {
|
|
412
|
+
const S = document.createElementNS(A, "circle");
|
|
413
|
+
S.classList.add("tiny-spark-datapoint-circle"), S.classList.add(`circle-${e}`), S.setAttribute("id", `circle_${e}_${p}`), S.setAttribute("cx", String(l || 0)), S.setAttribute("cy", String(h || 0)), S.setAttribute("r", String(f(t, g.PLOT_RADIUS, 3))), S.setAttribute("fill", String(f(t, g.PLOT_COLOR, String(f(t, "lineColor", O))))), S.setAttribute("stroke", a), S.style.opacity = N.length === 1 ? "1" : "0", S.style.transition = `opacity ${p * (1e3 * 2 / N.length)}ms ease-in`, S.style.pointerEvents = "none", D.push(S), j && X.appendChild(S);
|
|
353
414
|
}
|
|
354
|
-
});
|
|
415
|
+
}), s.appendChild(X));
|
|
355
416
|
let x = null;
|
|
356
|
-
if (
|
|
357
|
-
const
|
|
358
|
-
x = document.createElementNS(
|
|
417
|
+
if (d && N.length && N.at(-1)) {
|
|
418
|
+
const l = Number(f(t, g.LAST_VALUE_FONT_SIZE, 12));
|
|
419
|
+
x = document.createElementNS(A, "text"), x.classList.add("tiny-spark-last-value"), x.setAttribute("id", _), n ? (x.setAttribute("x", String(N.at(-1).x + Number(f(t, g.LINE_THICKNESS, 2)))), x.setAttribute("y", N.at(-1)?.isPositive ? String(N.at(-1).y - l / 3) : String(N.at(-1).bar.y + N.at(-1).bar.h + l)), x.setAttribute("text-anchor", "middle")) : (x.setAttribute("x", String(N.at(-1).x + 6 + Number(f(t, g.LINE_THICKNESS, 2)))), x.setAttribute("y", String(N.at(-1).y + l / 3)), x.setAttribute("text-anchor", "start")), x.setAttribute("font-size", String(l) + "px"), x.setAttribute("fill", String(f(t, g.LAST_VALUE_COLOR, String(f(t, g.INDICATOR_COLOR, "#1A1A1A"))))), x.innerHTML = ut(t, Number(N.at(-1).v)), x.style.opacity = N.length === 1 ? "1" : "0", s.appendChild(x);
|
|
359
420
|
}
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
421
|
+
const tt = document.createElementNS(A, "g");
|
|
422
|
+
N.forEach((l, h) => {
|
|
423
|
+
const b = D[h], p = document.createElementNS(A, "rect");
|
|
424
|
+
p.classList.add("tiny-spark-tooltip-trap"), p.setAttribute("x", `${N.length === 1 ? 0 : u.left + h * L - L / 2}`), p.setAttribute("y", `${u.top}`), p.setAttribute("height", `${u.height}`), p.setAttribute("width", `${L}`), p.setAttribute("fill", "transparent"), p.setAttribute("aria-describedby", `tooltip_${e}`), p.addEventListener("mouseenter", () => {
|
|
425
|
+
it(s, t, l, e, !0), j ? document.getElementById(`circle_${e}_${h}`)?.setAttribute("r", String(Number(f(t, g.PLOT_RADIUS, 3)) * 1.5)) : s.appendChild(b), Z[h].style.opacity = "1", d && x && (h === N.length - 1 ? x.style.opacity = "0" : x.style.opacity = "1");
|
|
426
|
+
}), p.addEventListener("mouseout", () => {
|
|
427
|
+
it(s, t, l, e, !1), j ? document.getElementById(`circle_${e}_${h}`)?.setAttribute("r", String(Number(f(t, g.PLOT_RADIUS, 3)))) : b.remove(), Z.forEach((S) => S.style.opacity = "0"), d && x && (x.style.opacity = "1");
|
|
428
|
+
}), tt.appendChild(p);
|
|
429
|
+
}), s.appendChild(tt), Q === "true" && o ? lt().then(() => {
|
|
430
|
+
D.forEach((l) => {
|
|
431
|
+
l.style.opacity = "1";
|
|
432
|
+
}), K.forEach((l) => {
|
|
433
|
+
l.style.opacity = "1";
|
|
434
|
+
}), xt(R, 1e3, () => {
|
|
373
435
|
x && (x.style.opacity = "1");
|
|
374
|
-
}),
|
|
375
|
-
}) : (
|
|
376
|
-
|
|
377
|
-
}),
|
|
378
|
-
|
|
379
|
-
}), x && (x.style.opacity = "1")), t.appendChild(
|
|
380
|
-
const
|
|
381
|
-
|
|
436
|
+
}), Ct(s, P);
|
|
437
|
+
}) : (D.forEach((l) => {
|
|
438
|
+
l.style.opacity = "1";
|
|
439
|
+
}), K.forEach((l) => {
|
|
440
|
+
l.style.opacity = "1";
|
|
441
|
+
}), x && (x.style.opacity = "1")), t.appendChild(s), t.addEventListener("mouseleave", () => {
|
|
442
|
+
const l = J[e];
|
|
443
|
+
l && (cancelAnimationFrame(l.frameId), l.frameId = null, l.tool.style.opacity = "0", l.hasSnapped = !1);
|
|
382
444
|
});
|
|
383
445
|
}
|
|
384
|
-
function
|
|
385
|
-
const t =
|
|
386
|
-
t.length && Array.from(t).forEach((
|
|
387
|
-
if (!
|
|
388
|
-
const
|
|
389
|
-
|
|
446
|
+
function Pt() {
|
|
447
|
+
const t = At();
|
|
448
|
+
t.length && Array.from(t).forEach((r) => {
|
|
449
|
+
if (!r.dataset.id) {
|
|
450
|
+
const o = W();
|
|
451
|
+
r.setAttribute("data-id", o);
|
|
390
452
|
}
|
|
391
|
-
const n =
|
|
392
|
-
|
|
393
|
-
const
|
|
394
|
-
e.forEach(() =>
|
|
453
|
+
const n = r;
|
|
454
|
+
wt(n), n.__renderCount = 0, z(n), lt().then(() => {
|
|
455
|
+
const o = new ResizeObserver((e) => {
|
|
456
|
+
e.forEach(() => z(n));
|
|
395
457
|
});
|
|
396
|
-
n.parentElement &&
|
|
397
|
-
for (const
|
|
398
|
-
if (
|
|
399
|
-
|
|
458
|
+
n.parentElement && o.observe(n.parentElement), new MutationObserver((e) => {
|
|
459
|
+
for (const c of e)
|
|
460
|
+
if (c.type === "attributes" && c.attributeName && Object.values(H).includes(c.attributeName)) {
|
|
461
|
+
z(n);
|
|
400
462
|
break;
|
|
401
463
|
}
|
|
402
464
|
}).observe(n, { attributes: !0 });
|
|
403
465
|
});
|
|
404
466
|
});
|
|
405
467
|
}
|
|
406
|
-
function
|
|
407
|
-
|
|
468
|
+
function z(t) {
|
|
469
|
+
st(t, "set") && Ft(t, t.__renderCount < 2), t.__renderCount += 1;
|
|
408
470
|
}
|
|
409
|
-
function
|
|
471
|
+
function wt(t) {
|
|
410
472
|
t.dataset.set || console.error(
|
|
411
473
|
`Tiny-spark exception:
|
|
412
474
|
|
|
@@ -416,10 +478,10 @@ Provide an array of numbers, for example:
|
|
|
416
478
|
data-set="[1, 2, 3]"`
|
|
417
479
|
);
|
|
418
480
|
}
|
|
419
|
-
function
|
|
481
|
+
function Mt(t) {
|
|
420
482
|
return JSON.stringify(t);
|
|
421
483
|
}
|
|
422
484
|
export {
|
|
423
|
-
|
|
424
|
-
|
|
485
|
+
Pt as render,
|
|
486
|
+
Mt as tinyFormat
|
|
425
487
|
};
|
package/dist/tiny-spark.umd.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
(function(P,w){typeof exports=="object"&&typeof module<"u"?w(exports):typeof define=="function"&&define.amd?define(["exports"],w):(P=typeof globalThis<"u"?globalThis:P||self,w(P.TinySpark={}))})(this,function(P){"use strict";const w="http://www.w3.org/2000/svg";var q=(t=>(t.BAR="bar",t.LINE="line",t))(q||{}),h=(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.CUT_NULL="cutNull",t))(h||{}),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.TYPE="data-type",t.TOOLTIP_SMOOTHING="data-tooltip-smoothing",t.CUT_NULL="data-cut-null",t))(z||{});const rt={version:"1.0.0"};function at(t){const{width:i,height:n}=t.parentElement.getBoundingClientRect(),s={width:300,height:100},r=String(p(t,h.SHOW_LAST_VALUE,"false"))==="true",e=T(t),d=e&&e.length?e.at(-1):null;let o=0;if(!(t.dataset.type&&t.dataset.type==="bar")&&r&&![null,void 0].includes(d)){const l=Number(String(p(t,h.NUMBER_ROUNDING,0)));o=6+d.toFixed(l).length*(Number(p(t,h.LAST_VALUE_FONT_SIZE,12))/2)}const a=`0 0 ${(i||s.width)+o} ${n||s.height}`,g=document.createElementNS(w,"svg"),v=t.dataset.id;g.id=v,g.setAttribute("viewBox",a),g.style.width="100%",g.style.height="100%";const u=document.createElementNS(w,"desc");return u.setAttribute("aria-hidden","true"),u.innerHTML=`Composed with tiny-spark v${rt.version}`,g.appendChild(u),{svg:g,svgId:v,width:i||s.width,height:n||s.height,viewBox:a}}function L(t,i=0){return isNaN(t)?i:t}function D(t){let i=[];for(let n=0;n<t.length;n+=1)i.push(`${L(t[n].x)},${L(t[n].y)} `);return i.join(" ").trim()}function E(t){if(t.length<2)return"0,0";const i=t.length-1,n=[`${L(t[0].x)},${L(t[0].y)}`],s=[],r=[],e=[],d=[];for(let o=0;o<i;o+=1)s[o]=t[o+1].x-t[o].x,r[o]=t[o+1].y-t[o].y,e[o]=r[o]/s[o];d[0]=e[0],d[i]=e[i-1];for(let o=1;o<i;o+=1)if(e[o-1]*e[o]<=0)d[o]=0;else{const f=2*e[o-1]*e[o]/(e[o-1]+e[o]);d[o]=f}for(let o=0;o<i;o+=1){const f=t[o].x,S=t[o].y,a=t[o+1].x,g=t[o+1].y,v=d[o],u=d[o+1],l=f+(a-f)/3,C=S+v*(a-f)/3,$=a-(a-f)/3,R=g-u*(a-f)/3;n.push(`C ${L(l)},${L(C)} ${L($)},${L(R)} ${L(a)},${L(g)}`)}return n.join(" ")}function lt(t){const i=[];let n=[];for(const s of t)s.v==null||Number.isNaN(s.x)||Number.isNaN(s.y)?(n.length>1&&i.push(n),n=[]):n.push(s);return n.length>1&&i.push(n),i}function ut(t){const i=lt(t);if(!i.length)return"";let n="";for(const[s,r]of i.entries()){if(r.length<2)continue;const e=r.length-1,d=[],o=[],f=[],S=[];for(let a=0;a<e;a+=1)d[a]=r[a+1].x-r[a].x,o[a]=r[a+1].y-r[a].y,f[a]=o[a]/d[a];S[0]=f[0],S[e]=f[e-1];for(let a=1;a<e;a+=1)if(f[a-1]*f[a]<=0)S[a]=0;else{const g=2*f[a-1]*f[a]/(f[a-1]+f[a]);S[a]=g}n+=`${s===0?"":"M"}${L(r[0].x)},${L(r[0].y)} `;for(let a=0;a<e;a+=1){const g=r[a].x,v=r[a].y,u=r[a+1].x,l=r[a+1].y,C=S[a],$=S[a+1],R=g+(u-g)/3,V=v+C*(u-g)/3,I=u-(u-g)/3,k=l-$*(u-g)/3;n+=`C${L(R)},${L(V)} ${L(I)},${L(k)} ${L(u)},${L(l)} `}}return n.trim()}function ct(t){let i="",n=!1;const s=r=>r.v!=null&&Number.isFinite(r.x)&&Number.isFinite(r.y);for(let r=0;r<t.length;r++){const e=t[r];if(!s(e))continue;const d=`${L(e.x)},${L(e.y)}`;if(!n)i+=d,n=!0;else{const o=t[r-1],f=s(o)?"L":"M";i+=`${f}${d}`}i+=" "}return i.trim()}function dt(t){const i=[];let n=[];for(const s of t)!s||s.v==null||Number.isNaN(s.x)||Number.isNaN(s.y)?(n.length&&i.push(n),n=[]):n.push(s);return n.length&&i.push(n),i}function ft(t,i){if(!t[0])return[-10,-10,"",-10,-10].toString();const n=dt(t);return n.length?n.map(s=>{const r={x:s[0].x,y:i},e={x:s.at(-1)?.x,y:i},d=[];return s.forEach(o=>{d.push(`${o.x},${o.y} `)}),[r.x,r.y,...d,e.x,e.y].toString()}).join(";"):""}function gt(t,i,n=!1,s=!0){function r(d){const o=[];let f=[];for(const S of d)!S||S.v==null||Number.isNaN(S.x)||Number.isNaN(S.y)?(f.length>1&&o.push(f),f=[]):f.push(S);return f.length>1&&o.push(f),o}return(n?r(t):[t]).map(d=>{if(d.length<2)return"";const o=d.length-1,f=[],S=[],a=[],g=[];for(let u=0;u<o;u+=1)f[u]=d[u+1].x-d[u].x,S[u]=d[u+1].y-d[u].y,a[u]=S[u]/f[u];g[0]=a[0],g[o]=a[o-1];for(let u=1;u<o;u+=1)if(a[u-1]*a[u]<=0)g[u]=0;else{const l=2*a[u-1]*a[u]/(a[u-1]+a[u]);g[u]=l}let v=`M${d[0].x},${i}`;v+=` L${d[0].x},${d[0].y}`;for(let u=0;u<o;u+=1){const l=d[u].x,C=d[u].y,$=d[u+1].x,R=d[u+1].y,V=g[u],I=g[u+1],k=l+($-l)/3,B=C+V*($-l)/3,m=$-($-l)/3,F=R-I*($-l)/3;v+=` C${k},${B} ${m},${F} ${$},${R}`}return v+=` L${d[o].x},${i} ${s?"Z":""}`,v}).filter(Boolean)}function yt(t,i=1e3,n){t.style.opacity="1";const s=t.getTotalLength();t.style.strokeDasharray=String(s),t.style.strokeDashoffset=String(s),t.getBoundingClientRect(),t.style.transition=`stroke-dashoffset ${i}ms ease-in-out`,t.style.strokeDashoffset="0",t.addEventListener("transitionend",function r(){t.style.transition="",t.removeEventListener("transitionend",r),n&&n()})}function pt(t,i,n=1e3){i.style.opacity="1";const s=i.getBBox(),r=s.width,e=document.createElementNS("http://www.w3.org/2000/svg","clipPath"),d="clip-"+Math.random().toString(36).substr(2,9);e.setAttribute("id",d);const o=document.createElementNS("http://www.w3.org/2000/svg","rect");o.setAttribute("x",s.x.toString()),o.setAttribute("y",s.y.toString()),o.setAttribute("width","0"),o.setAttribute("height",s.height.toString()),e.appendChild(o);let f=t.querySelector("defs");f||(f=document.createElementNS("http://www.w3.org/2000/svg","defs"),t.insertBefore(f,t.firstChild)),f.appendChild(e),i.setAttribute("clip-path",`url(#${d})`),o.style.transition=`width ${n}ms ease-out`,o.getBoundingClientRect(),o.setAttribute("width",r.toString()),o.addEventListener("transitionend",function S(){i.removeAttribute("clip-path"),e.parentNode&&e.parentNode.removeChild(e),o.removeEventListener("transitionend",S)})}function ht(){return document.querySelectorAll(".tiny-spark")}function J(t,i){return Object.keys(t.dataset).includes(i)}function p(t,i,n){return J(t,i)?t.dataset[i]:n}function mt(t){if(!t)return{color:"#1A1A1A",backgroundColor:"#FFFFFF"};const i=window.getComputedStyle(t),n=i.getPropertyValue("color")||"#1A1A1A",s=i.getPropertyValue("background-color"),r=i.getPropertyValue("background");return{color:n,backgroundColor:s||r||"#FFFFFF"}}function Q(){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 T(t){const i=t.getAttribute("data-set");if(!i)return[];const n=i.replace(/,(?=,)/g,",null").replace(/\[,/g,"[null,").replace(/,\]/g,",null]");try{const s=JSON.parse(n);return Array.isArray(s)&&s.every(r=>typeof r=="number"||[null,void 0].includes(r))?s:(console.warn("data-set is not an array of numbers."),[])}catch(s){return console.error("Error parsing data-set:",s),[]}}function bt(t){const i=t.getAttribute("data-dates");if(!i)return[];try{const n=JSON.parse(i);return Array.isArray(n)&&n.every(s=>typeof s=="string")?n:(console.warn("data-dates is not an array of strings"),[])}catch(n){return console.error("Error parsing data-dates",n),[]}}function tt(t){return{min:Math.min(...t),max:Math.max(...t)}}function et(){return new Promise(t=>setTimeout(t,0))}function nt(t,i){const n=String(p(t,h.NUMBER_LOCALE,navigator.language||"en-US")),s=Number(String(p(t,h.NUMBER_ROUNDING,0)));return i.toLocaleString(n,{useGrouping:!0,minimumFractionDigits:s,maximumFractionDigits:s})}function St(t,i,n){if(!t.createSVGPoint||!t.getScreenCTM)throw new Error("Your browser does not support SVG coordinate transformation.");const s=t.getScreenCTM();if(!s)throw new Error("Cannot obtain the screen CTM.");const r=t.createSVGPoint();r.x=i,r.y=n;const e=r.matrixTransform(s);return{x:e.x,y:e.y}}const Y={};function it(t,i,n,s,r){let e=Y[s];if(!r){e&&(cancelAnimationFrame(e.frameId),e.frameId=null,e.tool.style.opacity="0");return}const d=i.dataset.type===q.BAR,{x:o,y:f}=St(t,n.x,d&&!n.isPositive?n.bar.y:n.y);if(!e){const l=document.createElement("div");l.classList.add("tiny-spark-tooltip"),l.setAttribute("id",`tooltip_${s}`),l.setAttribute("role","tooltip"),l.setAttribute("aria-live","polite"),l.style.position="fixed",l.style.pointerEvents="none",l.style.opacity="0",l.style.willChange="top, left",document.body.appendChild(l),e=Y[s]={targetX:0,targetY:0,displayX:0,displayY:0,frameId:null,tool:l,width:0,height:0,hasSnapped:!1}}e.tool.setAttribute("aria-hidden","false"),e.tool.innerHTML=`
|
|
1
|
+
(function(w,x){typeof exports=="object"&&typeof module<"u"?x(exports):typeof define=="function"&&define.amd?define(["exports"],x):(w=typeof globalThis<"u"?globalThis:w||self,x(w.TinySpark={}))})(this,function(w){"use strict";const x="http://www.w3.org/2000/svg";var T=(t=>(t.BAR="bar",t.LINE="line",t))(T||{}),m=(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.CUT_NULL="cutNull",t.GRADIENT_FROM="gradientFrom",t.GRADIENT_TO="gradientTo",t.GRADIENT_FROM_OPACITY="gradientFromOpacity",t.GRADIENT_TO_OPACITY="gradientToOpacity",t.TEMPERATURE_COLORS="temperatureColors",t))(m||{}),H=(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.CUT_NULL="data-cut-null",t.GRADIENT_FROM="data-gradient-from",t.GRADIENT_TO="data-gradient-to",t.GRADIENT_FROM_OPACITY="data-gradient-from-opacity",t.GRADIENT_TO_OPACITY="data-gradient-to-opacity",t.TEMPERATURE_COLORS="data-temperature-colors",t))(H||{});const dt={version:"1.2.0"};function ft(t){const{width:r,height:n}=t.parentElement.getBoundingClientRect(),o={width:300,height:100},s=String(p(t,m.SHOW_LAST_VALUE,"false"))==="true",e=rt(t),c=e&&e.length?e.at(-1):null;let i=0;if(!(t.dataset.type&&t.dataset.type==="bar")&&s&&![null,void 0].includes(c)){const u=Number(String(p(t,m.NUMBER_ROUNDING,0)));i=6+c.toFixed(u).length*(Number(p(t,m.LAST_VALUE_FONT_SIZE,12))/2)}const a=`0 0 ${(r||o.width)+i} ${n||o.height}`,y=document.createElementNS(x,"svg"),_=t.dataset.id;y.id=_,y.setAttribute("viewBox",a),y.style.width="100%",y.style.height="100%";const d=document.createElementNS(x,"desc");return d.setAttribute("aria-hidden","true"),d.innerHTML=`Composed with tiny-spark v${dt.version}`,y.appendChild(d),{svg:y,svgId:_,width:r||o.width,height:n||o.height,viewBox:a}}function A(t,r=0){return isNaN(t)?r:t}function tt(t){let r=[];for(let n=0;n<t.length;n+=1)r.push(`${A(t[n].x)},${A(t[n].y)} `);return r.join(" ").trim()}function et(t){if(t.length<2)return"0,0";const r=t.length-1,n=[`${A(t[0].x)},${A(t[0].y)}`],o=[],s=[],e=[],c=[];for(let i=0;i<r;i+=1)o[i]=t[i+1].x-t[i].x,s[i]=t[i+1].y-t[i].y,e[i]=s[i]/o[i];c[0]=e[0],c[r]=e[r-1];for(let i=1;i<r;i+=1)if(e[i-1]*e[i]<=0)c[i]=0;else{const g=2*e[i-1]*e[i]/(e[i-1]+e[i]);c[i]=g}for(let i=0;i<r;i+=1){const g=t[i].x,N=t[i].y,a=t[i+1].x,y=t[i+1].y,_=c[i],d=c[i+1],u=g+(a-g)/3,I=N+_*(a-g)/3,$=a-(a-g)/3,F=y-d*(a-g)/3;n.push(`C ${A(u)},${A(I)} ${A($)},${A(F)} ${A(a)},${A(y)}`)}return n.join(" ")}function pt(t){const r=[];let n=[];for(const o of t)o.v==null||Number.isNaN(o.x)||Number.isNaN(o.y)?(n.length>1&&r.push(n),n=[]):n.push(o);return n.length>1&&r.push(n),r}function mt(t){const r=pt(t);if(!r.length)return"";let n="";for(const[o,s]of r.entries()){if(s.length<2)continue;const e=s.length-1,c=[],i=[],g=[],N=[];for(let a=0;a<e;a+=1)c[a]=s[a+1].x-s[a].x,i[a]=s[a+1].y-s[a].y,g[a]=i[a]/c[a];N[0]=g[0],N[e]=g[e-1];for(let a=1;a<e;a+=1)if(g[a-1]*g[a]<=0)N[a]=0;else{const y=2*g[a-1]*g[a]/(g[a-1]+g[a]);N[a]=y}n+=`${o===0?"":"M"}${A(s[0].x)},${A(s[0].y)} `;for(let a=0;a<e;a+=1){const y=s[a].x,_=s[a].y,d=s[a+1].x,u=s[a+1].y,I=N[a],$=N[a+1],F=y+(d-y)/3,V=_+I*(d-y)/3,L=d-(d-y)/3,P=u-$*(d-y)/3;n+=`C${A(F)},${A(V)} ${A(L)},${A(P)} ${A(d)},${A(u)} `}}return n.trim()}function gt(t){let r="",n=!1;const o=s=>s.v!=null&&Number.isFinite(s.x)&&Number.isFinite(s.y);for(let s=0;s<t.length;s++){const e=t[s];if(!o(e))continue;const c=`${A(e.x)},${A(e.y)}`;if(!n)r+=c,n=!0;else{const i=t[s-1],g=o(i)?"L":"M";r+=`${g}${c}`}r+=" "}return r.trim()}function yt(t){const r=[];let n=[];for(const o of t)!o||o.v==null||Number.isNaN(o.x)||Number.isNaN(o.y)?(n.length&&r.push(n),n=[]):n.push(o);return n.length&&r.push(n),r}function ht(t,r){if(!t[0])return[-10,-10,"",-10,-10].toString();const n=yt(t);return n.length?n.map(o=>{const s={x:o[0].x,y:r},e={x:o.at(-1)?.x,y:r},c=[];return o.forEach(i=>{c.push(`${i.x},${i.y} `)}),[s.x,s.y,...c,e.x,e.y].toString()}).join(";"):""}function bt(t,r,n=!1,o=!0){function s(c){const i=[];let g=[];for(const N of c)!N||N.v==null||Number.isNaN(N.x)||Number.isNaN(N.y)?(g.length>1&&i.push(g),g=[]):g.push(N);return g.length>1&&i.push(g),i}return(n?s(t):[t]).map(c=>{if(c.length<2)return"";const i=c.length-1,g=[],N=[],a=[],y=[];for(let d=0;d<i;d+=1)g[d]=c[d+1].x-c[d].x,N[d]=c[d+1].y-c[d].y,a[d]=N[d]/g[d];y[0]=a[0],y[i]=a[i-1];for(let d=1;d<i;d+=1)if(a[d-1]*a[d]<=0)y[d]=0;else{const u=2*a[d-1]*a[d]/(a[d-1]+a[d]);y[d]=u}let _=`M${c[0].x},${r}`;_+=` L${c[0].x},${c[0].y}`;for(let d=0;d<i;d+=1){const u=c[d].x,I=c[d].y,$=c[d+1].x,F=c[d+1].y,V=y[d],L=y[d+1],P=u+($-u)/3,q=I+V*($-u)/3,O=$-($-u)/3,U=F-L*($-u)/3;_+=` C${P},${q} ${O},${U} ${$},${F}`}return _+=` L${c[i].x},${r} ${o?"Z":""}`,_}).filter(Boolean)}function Ot(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 Nt(t,r,n=1e3){r.style.opacity="1";const o=r.getBBox(),s=o.width,e=document.createElementNS("http://www.w3.org/2000/svg","clipPath"),c="clip-"+Math.random().toString(36).substr(2,9);e.setAttribute("id",c);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()),e.appendChild(i);let g=t.querySelector("defs");g||(g=document.createElementNS("http://www.w3.org/2000/svg","defs"),t.insertBefore(g,t.firstChild)),g.appendChild(e),r.setAttribute("clip-path",`url(#${c})`),i.style.transition=`width ${n}ms ease-out`,i.getBoundingClientRect(),i.setAttribute("width",s.toString()),i.addEventListener("transitionend",function N(){r.removeAttribute("clip-path"),e.parentNode&&e.parentNode.removeChild(e),i.removeEventListener("transitionend",N)})}function St(){return document.querySelectorAll(".tiny-spark")}function nt(t,r){return Object.keys(t.dataset).includes(r)}function p(t,r,n){return nt(t,r)?t.dataset[r]:n}function xt(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 D(){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 rt(t){const r=t.getAttribute(H.SET);if(!r)return[];const n=r.replace(/,(?=,)/g,",null").replace(/\[,/g,"[null,").replace(/,\]/g,",null]");try{const o=JSON.parse(n);return Array.isArray(o)&&o.every(s=>typeof s=="number"||[null,void 0].includes(s))?o:(console.warn("data-set is not an array of numbers."),[])}catch(o){return console.error("Error parsing data-set:",o),[]}}function Ct(t,r){return r<=1?"0%":`${t*100/(r-1)}%`}function At(t){const r=t.getAttribute(H.DATES);if(!r)return[];try{const n=JSON.parse(r.replaceAll("'",'"'));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 It(t){const r=t.getAttribute(H.TEMPERATURE_COLORS);if(!r)return[];try{const n=JSON.parse(r.replaceAll("'",'"'));return Array.isArray(n)&&n.every(o=>typeof o=="string")?n:(console.warn("data-temperature-colors is not an array of strings"),[])}catch(n){return console.error("Error parsing data-temperature-colors",n),[]}}function it(t){return{min:Math.min(...t),max:Math.max(...t)}}function ot(){return new Promise(t=>setTimeout(t,0))}function st(t,r){const n=String(p(t,m.NUMBER_LOCALE,navigator.language||"en-US")),o=Number(String(p(t,m.NUMBER_ROUNDING,0)));return r.toLocaleString(n,{useGrouping:!0,minimumFractionDigits:o,maximumFractionDigits:o})}function _t(t,r,n){if(!t.createSVGPoint||!t.getScreenCTM)return console.error("Your browser does not support SVG coordinate transformation."),{x:0,y:0};const o=t.getScreenCTM();if(!o)return console.error("Cannot obtain the screen CTM."),{x:0,y:0};const s=t.createSVGPoint();s.x=r,s.y=n;const e=s.matrixTransform(o);return{x:e.x,y:e.y}}const Z={};function at(t,r,n,o,s){let e=Z[o];if(!s){e&&(cancelAnimationFrame(e.frameId),e.frameId=null,e.tool.style.opacity="0");return}const c=r.dataset.type===T.BAR,{x:i,y:g}=_t(t,n.x,c&&!n.isPositive?n.bar.y:n.y);if(!e){const u=document.createElement("div");u.classList.add("tiny-spark-tooltip"),u.setAttribute("id",`tooltip_${o}`),u.setAttribute("role","tooltip"),u.setAttribute("aria-live","polite"),u.style.position="fixed",u.style.pointerEvents="none",u.style.opacity="0",u.style.willChange="top, left",document.body.appendChild(u),e=Z[o]={targetX:0,targetY:0,displayX:0,displayY:0,frameId:null,tool:u,width:0,height:0,hasSnapped:!1}}e.tool.setAttribute("aria-hidden","false"),e.tool.innerHTML=`
|
|
2
2
|
<div class="tiny-spark-tooltip-content">
|
|
3
|
-
${n.d?`${n.d}: `:""}${[null,void 0].includes(n.v)?"-":
|
|
3
|
+
${n.d?`${n.d}: `:""}${[null,void 0].includes(n.v)?"-":st(r,Number(n.v))}
|
|
4
4
|
</div>
|
|
5
|
-
`;const{width:S,height:a}=e.tool.getBoundingClientRect();e.width=S,e.height=a;const g=Number(p(i,h.PLOT_RADIUS,3));if(e.targetX=o-e.width/2,e.targetY=f-e.height-g*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 v=Number(p(i,h.TOOLTIP_SMOOTHING,1))/10;function u(){e.displayX+=(e.targetX-e.displayX)*v,e.displayY+=(e.targetY-e.displayY)*v,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(u)}e.frameId==null&&u()}function Nt(t){t.innerHTML=""}function Ot(t,i){const n=t.dataset.type&&t.dataset.type==="bar";let s=i;Nt(t);const{svg:r,svgId:e,width:d,height:o,viewBox:f}=at(t),{color:S,backgroundColor:a}=mt(t),g={T:12,R:12,B:12,L:12},v=Q(),u=String(p(t,h.SHOW_LAST_VALUE,"false"))==="true",l={left:g.L,top:g.T,width:d-g.L-g.R,height:o-g.T-g.B,bottom:o-g.B},C=T(t),{min:$}=tt(C),R=C.map(c=>[null,void 0].includes(c)?c:c+($<0?Math.abs($):0)),{max:V}=tt(R);let I=l.width/(C.length-1)===1/0?l.width:l.width/(C.length-1);if(n){const[c,N,y,b]=f.split(" ");r.setAttribute("viewBox",`${Number(c)-I/2} ${N} ${Number(y)+I} ${b}`)}const k=!C.some(c=>c>=0),B=bt(t),m=R.map((c,N)=>{const y={w:R.length===1?I/2:0,h:R.length===1?l.height/2:0},b=l.left+I*N+y.w,x=(1-(c||0)/V)*l.height+y.h+g.T,X=(1-($<0?Math.abs($):0)/V)*l.height+g.T+y.h,K=C[N]>=0;return{y:k&&C.length===1?l.top+l.height/2:x,x:b,v:C[N],d:B[N]||null,isPositive:K,bar:{x:b-I/2,y:C.length===1?l.top:K?x:k?l.top:X,h:C.length===1?l.height:K?X-x:k&&C.length===0?l.height:isNaN(x-X)?0:x-X,w:I}}});function F(){const c=document.createElementNS(w,"path");return c.classList.add("tiny-spark-line-area"),c}const A=[...m].map(c=>[null,void 0,1/0,-1/0,NaN,"NaN"].includes(c.v)?{...c,v:null}:c),ot=t.getAttribute("data-animation"),_=document.createElementNS(w,"path");_.classList.add("tiny-spark-line-path");const M=F(),H=[];n||(!t.dataset.curve||t.dataset.curve==="true"?!t.dataset.cutNull||t.dataset.cutNull==="false"?_.setAttribute("d",`M ${E(A)}`):_.setAttribute("d",`M ${ut(A)}`):!t.dataset.cutNull||t.dataset.cutNull==="false"?_.setAttribute("d",`M ${D(A)}`):_.setAttribute("d",`M ${ct(A)}`),_.setAttribute("fill","none"),_.setAttribute("stroke",String(p(t,h.LINE_COLOR,S))),_.setAttribute("stroke-width",String(p(t,h.LINE_THICKNESS,2))),_.setAttribute("stroke-linecap","round"),ot==="true"&&s&&(_.style.opacity="0",M.style.opacity="0"),m.length&&(!t.dataset.curve||t.dataset.curve==="true"?!t.dataset.cutNull||t.dataset.cutNull==="false"?M.setAttribute("d",`M ${A[0].x},${l.bottom} ${E(A)} L ${A.at(-1).x},${l.bottom} Z`):gt(A,l.bottom,!0,!0).forEach(N=>{const y=F();y.setAttribute("d",N),y.setAttribute("fill",String(p(t,h.AREA_COLOR,"transparent"))),H.push(y)}):!t.dataset.cutNull||t.dataset.cutNull==="false"?M.setAttribute("d",`M ${A[0].x},${l.bottom} ${D(A)} L ${A.at(-1).x},${l.bottom} Z`):ft(A,l.bottom).split(";").forEach(N=>{const y=F();y.setAttribute("d",`M ${N} Z`),y.setAttribute("fill",String(p(t,h.AREA_COLOR,"transparent"))),H.push(y)})),M.setAttribute("fill",String(p(t,h.AREA_COLOR,"transparent"))),m.length>1&&(H.length?H.forEach(c=>{r.appendChild(c)}):r.appendChild(M),r.appendChild(_)));const G=[];m.forEach((c,N)=>{const y=document.createElementNS(w,"line");y.classList.add("tiny-spark-indicator"),y.setAttribute("id",`indicator_${e}_${N}`),y.setAttribute("x1",String(l.left+(m.length===1?l.width/2:N*I))),y.setAttribute("x2",String(l.left+(m.length===1?l.width/2:N*I))),y.setAttribute("y1",String(l.top)),y.setAttribute("y2",String(l.bottom)),y.setAttribute("stroke",String(p(t,h.INDICATOR_COLOR,"#1A1A1A"))),y.setAttribute("stroke-width",String(p(t,h.INDICATOR_WIDTH,"1"))),y.setAttribute("stroke-linecap","round"),y.style.pointerEvents="none",y.style.opacity="0",G.push(y),r.appendChild(y)});let U=[],Z=[];const st=Number(String(p(t,h.PLOT_RADIUS,0)))>0,vt=!String(p(t,h.HIDE_PLOTS_ABOVE,""))||m.length<=Number(String(p(t,h.HIDE_PLOTS_ABOVE,0))),j=st&&vt;n&&m.forEach(({bar:c,v:N},y)=>{if(![null,void 0].includes(N)){const b=document.createElementNS(w,"rect");b.classList.add("tiny-spark-datapoint-bar"),b.setAttribute("x",String(c.x)),b.setAttribute("y",String(c.y)),b.setAttribute("width",String(c.w)),b.setAttribute("height",String(c.h)),b.setAttribute("fill",String(p(t,h.PLOT_COLOR,String(p(t,"lineColor",S))))),b.style.opacity=m.length===1?"1":"0",b.style.transition=`opacity ${y*(1e3*2/m.length)}ms ease-in`,Z.push(b),r.appendChild(b)}}),st&&!n&&m.forEach(({x:c,y:N,v:y},b)=>{if(![null,void 0].includes(y)){const x=document.createElementNS(w,"circle");x.classList.add("tiny-spark-datapoint-circle"),x.classList.add(`circle-${e}`),x.setAttribute("id",`circle_${e}_${b}`),x.setAttribute("cx",String(c||0)),x.setAttribute("cy",String(N||0)),x.setAttribute("r",String(p(t,h.PLOT_RADIUS,3))),x.setAttribute("fill",String(p(t,h.PLOT_COLOR,String(p(t,"lineColor",S))))),x.setAttribute("stroke",a),x.style.opacity=m.length===1?"1":"0",x.style.transition=`opacity ${b*(1e3*2/m.length)}ms ease-in`,x.style.pointerEvents="none",U.push(x),j&&r.appendChild(x)}});let O=null;if(u&&m.length&&m.at(-1)){const c=Number(p(t,h.LAST_VALUE_FONT_SIZE,12));O=document.createElementNS(w,"text"),O.classList.add("tiny-spark-last-value"),O.setAttribute("id",v),n?(O.setAttribute("x",String(m.at(-1).x+Number(p(t,h.LINE_THICKNESS,2)))),O.setAttribute("y",m.at(-1)?.isPositive?String(m.at(-1).y-c/3):String(m.at(-1).bar.y+m.at(-1).bar.h+c)),O.setAttribute("text-anchor","middle")):(O.setAttribute("x",String(m.at(-1).x+6+Number(p(t,h.LINE_THICKNESS,2)))),O.setAttribute("y",String(m.at(-1).y+c/3)),O.setAttribute("text-anchor","start")),O.setAttribute("font-size",String(c)+"px"),O.setAttribute("fill",String(p(t,h.LAST_VALUE_COLOR,String(p(t,h.INDICATOR_COLOR,"#1A1A1A"))))),O.innerHTML=nt(t,Number(m.at(-1).v)),O.style.opacity=m.length===1?"1":"0",r.appendChild(O)}m.forEach((c,N)=>{const y=U[N],b=document.createElementNS(w,"rect");b.classList.add("tiny-spark-tooltip-trap"),b.setAttribute("x",`${m.length===1?0:l.left+N*I-I/2}`),b.setAttribute("y",`${l.top}`),b.setAttribute("height",`${l.height}`),b.setAttribute("width",`${I}`),b.setAttribute("fill","transparent"),b.setAttribute("aria-describedby",`tooltip_${e}`),b.addEventListener("mouseenter",()=>{it(r,t,c,e,!0),j?document.getElementById(`circle_${e}_${N}`)?.setAttribute("r",String(Number(p(t,h.PLOT_RADIUS,3))*1.5)):r.appendChild(y),G[N].style.opacity="1",u&&O&&(N===m.length-1?O.style.opacity="0":O.style.opacity="1")}),b.addEventListener("mouseout",()=>{it(r,t,c,e,!1),j?document.getElementById(`circle_${e}_${N}`)?.setAttribute("r",String(Number(p(t,h.PLOT_RADIUS,3)))):y.remove(),G.forEach(x=>x.style.opacity="0"),u&&O&&(O.style.opacity="1")}),r.appendChild(b)}),ot==="true"&&s?et().then(()=>{U.forEach(c=>{c.style.opacity="1"}),Z.forEach(c=>{c.style.opacity="1"}),yt(_,1e3,()=>{O&&(O.style.opacity="1")}),pt(r,M)}):(U.forEach(c=>{c.style.opacity="1"}),Z.forEach(c=>{c.style.opacity="1"}),O&&(O.style.opacity="1")),t.appendChild(r),t.addEventListener("mouseleave",()=>{const c=Y[e];c&&(cancelAnimationFrame(c.frameId),c.frameId=null,c.tool.style.opacity="0",c.hasSnapped=!1)})}function xt(){const t=ht();t.length&&Array.from(t).forEach(i=>{if(!i.dataset.id){const s=Q();i.setAttribute("data-id",s)}const n=i;Lt(n),n.__renderCount=0,W(n),et().then(()=>{const s=new ResizeObserver(e=>{e.forEach(()=>W(n))});n.parentElement&&s.observe(n.parentElement),new MutationObserver(e=>{for(const d of e)if(d.type==="attributes"&&d.attributeName&&Object.values(z).includes(d.attributeName)){W(n);break}}).observe(n,{attributes:!0})})})}function W(t){J(t,"set")&&Ot(t,t.__renderCount<2),t.__renderCount+=1}function Lt(t){t.dataset.set||console.error(`Tiny-spark exception:
|
|
5
|
+
`;const{width:N,height:a}=e.tool.getBoundingClientRect();e.width=N,e.height=a;const y=Number(p(r,m.PLOT_RADIUS,3));if(e.targetX=i-e.width/2,e.targetY=g-e.height-y*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(p(r,m.TOOLTIP_SMOOTHING,1))/10;function d(){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(d)}e.frameId==null&&d()}function j({id:t,colorStart:r,colorEnd:n,opacityStart:o,opacityEnd:s}){const e=document.createElementNS(x,"linearGradient");e.setAttribute("id",t),e.setAttribute("x1","0"),e.setAttribute("x2","0"),e.setAttribute("y1","0"),e.setAttribute("y2","1");const c=document.createElementNS(x,"stop");c.setAttribute("offset","0%"),c.setAttribute("stop-color",r),c.setAttribute("stop-opacity",String(o));const i=document.createElementNS(x,"stop");return i.setAttribute("offset","100%"),i.setAttribute("stop-color",n),i.setAttribute("stop-opacity",String(s)),[c,i].forEach(g=>{e.appendChild(g)}),e}function $t(t){t.innerHTML=""}function Lt(t,r){const n=t.dataset.type&&t.dataset.type==="bar";let o=r;$t(t);const{svg:s,svgId:e,width:c,height:i,viewBox:g}=ft(t),{color:N,backgroundColor:a}=xt(t),y={T:12,R:12,B:12,L:12},_=D(),d=String(p(t,m.SHOW_LAST_VALUE,"false"))==="true",u={left:y.L,top:y.T,width:c-y.L-y.R,height:i-y.T-y.B,bottom:i-y.B},I=rt(t),{min:$}=it(I),F=I.map(l=>[null,void 0].includes(l)?l:l+($<0?Math.abs($):0)),{max:V}=it(F);let L=u.width/(I.length-1)===1/0?u.width:u.width/(I.length-1);if(n){const[l,h,b,f]=g.split(" ");s.setAttribute("viewBox",`${Number(l)-L/2} ${h} ${Number(b)+L} ${f}`)}const P=!I.some(l=>l>=0),q=At(t),O=F.map((l,h)=>{const b={w:F.length===1?L/2:0,h:F.length===1?u.height/2:0},f=u.left+L*h+b.w,S=(1-(l||0)/V)*u.height+b.h+y.T,Y=(1-($<0?Math.abs($):0)/V)*u.height+y.T+b.h,k=I[h]>=0;return{y:P&&I.length===1?u.top+u.height/2:S,x:f,v:I[h],d:q[h]||null,isPositive:k,bar:{x:f-L/2,y:I.length===1?u.top:k?S:P?u.top:Y,h:I.length===1?u.height:k?Y-S:P&&I.length===0?u.height:isNaN(S-Y)?0:S-Y,w:L}}});function U(){const l=document.createElementNS(x,"path");return l.classList.add("tiny-spark-line-area"),l}function wt(l){const h=document.createElementNS(x,"defs");return h.appendChild(j({id:l,colorStart:String(p(t,m.GRADIENT_FROM,"#FFFFFF")),colorEnd:String(p(t,m.GRADIENT_TO,"#FFFFFF")),opacityStart:Math.max(0,Math.min(1,Number(p(t,m.GRADIENT_FROM_OPACITY,1)))),opacityEnd:Math.max(0,Math.min(1,Number(p(t,m.GRADIENT_TO_OPACITY,1))))})),h}function Pt(l){const h=document.createElementNS(x,"defs");return h.appendChild(j({id:`pos_${l}`,colorStart:String(p(t,m.GRADIENT_FROM,"#FFFFFF")),colorEnd:String(p(t,m.GRADIENT_TO,"#FFFFFF")),opacityStart:Math.max(0,Math.min(1,Number(p(t,m.GRADIENT_FROM_OPACITY,1)))),opacityEnd:Math.max(0,Math.min(1,Number(p(t,m.GRADIENT_TO_OPACITY,1))))})),h.appendChild(j({id:`neg_${l}`,colorStart:String(p(t,m.GRADIENT_TO,"#FFFFFF")),colorEnd:String(p(t,m.GRADIENT_FROM,"#FFFFFF")),opacityStart:Math.max(0,Math.min(1,Number(p(t,m.GRADIENT_TO_OPACITY,1)))),opacityEnd:Math.max(0,Math.min(1,Number(p(t,m.GRADIENT_FROM_OPACITY,1))))})),h}const R=[...O].map(l=>[null,void 0,1/0,-1/0,NaN,"NaN"].includes(l.v)?{...l,v:null}:l),lt=t.getAttribute("data-animation"),v=document.createElementNS(x,"path");v.classList.add("tiny-spark-line-path");const M=U(),X=[],E=!!p(t,m.GRADIENT_FROM,"")&&!!p(t,m.GRADIENT_TO,""),G=D();if(!n){!t.dataset.curve||t.dataset.curve==="true"?!t.dataset.cutNull||t.dataset.cutNull==="false"?v.setAttribute("d",`M ${et(R)}`):v.setAttribute("d",`M ${mt(R)}`):!t.dataset.cutNull||t.dataset.cutNull==="false"?v.setAttribute("d",`M ${tt(R)}`):v.setAttribute("d",`M ${gt(R)}`),v.setAttribute("fill","none");const l=It(t);if(l.length){const h=D(),b=document.createElementNS(x,"defs"),f=document.createElementNS(x,"linearGradient");f.setAttribute("gradientTransform","rotate(90)"),f.setAttribute("id",h),l.forEach((S,Y)=>{const k=document.createElementNS(x,"stop");k.setAttribute("offset",Ct(Y,l.length)),k.setAttribute("stop-color",S),f.appendChild(k)}),b.appendChild(f),s.prepend(b),v.setAttribute("stroke",`url(#${h})`)}else v.setAttribute("stroke",String(p(t,m.LINE_COLOR,N)));v.setAttribute("stroke-width",String(p(t,m.LINE_THICKNESS,2))),v.setAttribute("stroke-linecap","round"),lt==="true"&&o&&(v.style.opacity="0",M.style.opacity="0"),E&&s.appendChild(wt(G)),O.length&&(!t.dataset.curve||t.dataset.curve==="true"?!t.dataset.cutNull||t.dataset.cutNull==="false"?M.setAttribute("d",`M ${R[0].x},${u.bottom} ${et(R)} L ${R.at(-1).x},${u.bottom} Z`):bt(R,u.bottom,!0,!0).forEach(b=>{const f=U();f.setAttribute("d",b),E?f.setAttribute("fill",`url(#${G})`):f.setAttribute("fill",String(p(t,m.AREA_COLOR,"transparent"))),X.push(f)}):!t.dataset.cutNull||t.dataset.cutNull==="false"?M.setAttribute("d",`M ${R[0].x},${u.bottom} ${tt(R)} L ${R.at(-1).x},${u.bottom} Z`):ht(R,u.bottom).split(";").forEach(b=>{const f=U();f.setAttribute("d",`M ${b} Z`),E?f.setAttribute("fill",`url(#${G})`):f.setAttribute("fill",String(p(t,m.AREA_COLOR,"transparent"))),X.push(f)})),E?M.setAttribute("fill",`url(#${G})`):M.setAttribute("fill",String(p(t,m.AREA_COLOR,"transparent"))),O.length>1&&(X.length?X.forEach(h=>{s.appendChild(h)}):s.appendChild(M),s.appendChild(v))}const z=[];O.forEach((l,h)=>{const b=document.createElementNS(x,"line");b.classList.add("tiny-spark-indicator"),b.setAttribute("id",`indicator_${e}_${h}`),b.setAttribute("x1",String(u.left+(O.length===1?u.width/2:h*L))),b.setAttribute("x2",String(u.left+(O.length===1?u.width/2:h*L))),b.setAttribute("y1",String(u.top)),b.setAttribute("y2",String(u.bottom)),b.setAttribute("stroke",String(p(t,m.INDICATOR_COLOR,"#1A1A1A"))),b.setAttribute("stroke-width",String(p(t,m.INDICATOR_WIDTH,"1"))),b.setAttribute("stroke-linecap","round"),b.style.pointerEvents="none",b.style.opacity="0",z.push(b),s.appendChild(b)});let W=[],J=[];const ut=Number(String(p(t,m.PLOT_RADIUS,0)))>0,Mt=!String(p(t,m.HIDE_PLOTS_ABOVE,""))||O.length<=Number(String(p(t,m.HIDE_PLOTS_ABOVE,0))),Q=ut&&Mt,B=document.createElementNS(x,"g");n&&(E&&s.appendChild(Pt(G)),O.forEach(({bar:l,v:h},b)=>{if(![null,void 0].includes(h)){const f=document.createElementNS(x,"rect");f.classList.add("tiny-spark-datapoint-bar"),f.setAttribute("x",String(l.x)),f.setAttribute("y",String(l.y)),f.setAttribute("width",String(l.w)),f.setAttribute("height",String(l.h)),E?h>=0?f.setAttribute("fill",`url(#pos_${G})`):f.setAttribute("fill",`url(#neg_${G})`):f.setAttribute("fill",String(p(t,m.PLOT_COLOR,String(p(t,"lineColor",N))))),f.style.opacity=O.length===1?"1":"0",f.style.transition=`opacity ${b*(1e3*2/O.length)}ms ease-in`,J.push(f),B.appendChild(f)}}),s.appendChild(B)),ut&&!n&&(O.forEach(({x:l,y:h,v:b},f)=>{if(![null,void 0].includes(b)){const S=document.createElementNS(x,"circle");S.classList.add("tiny-spark-datapoint-circle"),S.classList.add(`circle-${e}`),S.setAttribute("id",`circle_${e}_${f}`),S.setAttribute("cx",String(l||0)),S.setAttribute("cy",String(h||0)),S.setAttribute("r",String(p(t,m.PLOT_RADIUS,3))),S.setAttribute("fill",String(p(t,m.PLOT_COLOR,String(p(t,"lineColor",N))))),S.setAttribute("stroke",a),S.style.opacity=O.length===1?"1":"0",S.style.transition=`opacity ${f*(1e3*2/O.length)}ms ease-in`,S.style.pointerEvents="none",W.push(S),Q&&B.appendChild(S)}}),s.appendChild(B));let C=null;if(d&&O.length&&O.at(-1)){const l=Number(p(t,m.LAST_VALUE_FONT_SIZE,12));C=document.createElementNS(x,"text"),C.classList.add("tiny-spark-last-value"),C.setAttribute("id",_),n?(C.setAttribute("x",String(O.at(-1).x+Number(p(t,m.LINE_THICKNESS,2)))),C.setAttribute("y",O.at(-1)?.isPositive?String(O.at(-1).y-l/3):String(O.at(-1).bar.y+O.at(-1).bar.h+l)),C.setAttribute("text-anchor","middle")):(C.setAttribute("x",String(O.at(-1).x+6+Number(p(t,m.LINE_THICKNESS,2)))),C.setAttribute("y",String(O.at(-1).y+l/3)),C.setAttribute("text-anchor","start")),C.setAttribute("font-size",String(l)+"px"),C.setAttribute("fill",String(p(t,m.LAST_VALUE_COLOR,String(p(t,m.INDICATOR_COLOR,"#1A1A1A"))))),C.innerHTML=st(t,Number(O.at(-1).v)),C.style.opacity=O.length===1?"1":"0",s.appendChild(C)}const ct=document.createElementNS(x,"g");O.forEach((l,h)=>{const b=W[h],f=document.createElementNS(x,"rect");f.classList.add("tiny-spark-tooltip-trap"),f.setAttribute("x",`${O.length===1?0:u.left+h*L-L/2}`),f.setAttribute("y",`${u.top}`),f.setAttribute("height",`${u.height}`),f.setAttribute("width",`${L}`),f.setAttribute("fill","transparent"),f.setAttribute("aria-describedby",`tooltip_${e}`),f.addEventListener("mouseenter",()=>{at(s,t,l,e,!0),Q?document.getElementById(`circle_${e}_${h}`)?.setAttribute("r",String(Number(p(t,m.PLOT_RADIUS,3))*1.5)):s.appendChild(b),z[h].style.opacity="1",d&&C&&(h===O.length-1?C.style.opacity="0":C.style.opacity="1")}),f.addEventListener("mouseout",()=>{at(s,t,l,e,!1),Q?document.getElementById(`circle_${e}_${h}`)?.setAttribute("r",String(Number(p(t,m.PLOT_RADIUS,3)))):b.remove(),z.forEach(S=>S.style.opacity="0"),d&&C&&(C.style.opacity="1")}),ct.appendChild(f)}),s.appendChild(ct),lt==="true"&&o?ot().then(()=>{W.forEach(l=>{l.style.opacity="1"}),J.forEach(l=>{l.style.opacity="1"}),Ot(v,1e3,()=>{C&&(C.style.opacity="1")}),Nt(s,M)}):(W.forEach(l=>{l.style.opacity="1"}),J.forEach(l=>{l.style.opacity="1"}),C&&(C.style.opacity="1")),t.appendChild(s),t.addEventListener("mouseleave",()=>{const l=Z[e];l&&(cancelAnimationFrame(l.frameId),l.frameId=null,l.tool.style.opacity="0",l.hasSnapped=!1)})}function vt(){const t=St();t.length&&Array.from(t).forEach(r=>{if(!r.dataset.id){const o=D();r.setAttribute("data-id",o)}const n=r;Rt(n),n.__renderCount=0,K(n),ot().then(()=>{const o=new ResizeObserver(e=>{e.forEach(()=>K(n))});n.parentElement&&o.observe(n.parentElement),new MutationObserver(e=>{for(const c of e)if(c.type==="attributes"&&c.attributeName&&Object.values(H).includes(c.attributeName)){K(n);break}}).observe(n,{attributes:!0})})})}function K(t){nt(t,"set")&&Lt(t,t.__renderCount<2),t.__renderCount+=1}function Rt(t){t.dataset.set||console.error(`Tiny-spark exception:
|
|
6
6
|
|
|
7
7
|
[data-set] data attribute is missing.
|
|
8
8
|
Provide an array of numbers, for example:
|
|
9
9
|
|
|
10
|
-
data-set="[1, 2, 3]"`)}function
|
|
10
|
+
data-set="[1, 2, 3]"`)}function Ft(t){return JSON.stringify(t)}w.render=vt,w.tinyFormat=Ft,Object.defineProperty(w,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": "1.
|
|
4
|
+
"version": "1.2.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": "^24.0.8",
|
|
32
32
|
"typescript": "~5.8.3",
|
|
33
|
-
"vite": "^7.
|
|
33
|
+
"vite": "^7.2.2"
|
|
34
34
|
}
|
|
35
35
|
}
|