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