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