tiny-spark 0.4.1 → 0.4.2

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.
@@ -34,11 +34,11 @@ function B(t) {
34
34
  if (i[e - 1] * i[e] <= 0)
35
35
  d[e] = 0;
36
36
  else {
37
- const h = 2 * i[e - 1] * i[e] / (i[e - 1] + i[e]);
38
- d[e] = h;
37
+ const m = 2 * i[e - 1] * i[e] / (i[e - 1] + i[e]);
38
+ d[e] = m;
39
39
  }
40
40
  for (let e = 0; e < r; e += 1) {
41
- const h = t[e].x, p = t[e].y, O = t[e + 1].x, L = t[e + 1].y, u = d[e], _ = d[e + 1], R = h + (O - h) / 3, A = p + u * (O - h) / 3, k = O - (O - h) / 3, C = L - _ * (O - h) / 3;
41
+ const m = t[e].x, p = t[e].y, O = t[e + 1].x, L = t[e + 1].y, u = d[e], _ = d[e + 1], R = m + (O - m) / 3, A = p + u * (O - m) / 3, k = O - (O - m) / 3, C = L - _ * (O - m) / 3;
42
42
  n.push(`C ${N(R)},${N(A)} ${N(k)},${N(C)} ${N(O)},${N(L)}`);
43
43
  }
44
44
  return n.join(" ");
@@ -56,8 +56,8 @@ function Q(t, r, n = 1e3) {
56
56
  i.setAttribute("id", d);
57
57
  const e = document.createElementNS("http://www.w3.org/2000/svg", "rect");
58
58
  e.setAttribute("x", o.x.toString()), e.setAttribute("y", o.y.toString()), e.setAttribute("width", "0"), e.setAttribute("height", o.height.toString()), i.appendChild(e);
59
- let h = t.querySelector("defs");
60
- h || (h = document.createElementNS("http://www.w3.org/2000/svg", "defs"), t.insertBefore(h, t.firstChild)), h.appendChild(i), r.setAttribute("clip-path", `url(#${d})`), e.style.transition = `width ${n}ms ease-out`, e.getBoundingClientRect(), e.setAttribute("width", s.toString()), e.addEventListener("transitionend", function p() {
59
+ let m = t.querySelector("defs");
60
+ m || (m = document.createElementNS("http://www.w3.org/2000/svg", "defs"), t.insertBefore(m, t.firstChild)), m.appendChild(i), r.setAttribute("clip-path", `url(#${d})`), e.style.transition = `width ${n}ms ease-out`, e.getBoundingClientRect(), e.setAttribute("width", s.toString()), e.addEventListener("transitionend", function p() {
61
61
  r.removeAttribute("clip-path"), i.parentNode && i.parentNode.removeChild(i), e.removeEventListener("transitionend", p);
62
62
  });
63
63
  }
@@ -138,8 +138,8 @@ function G(t, r, n, o, s) {
138
138
  e.style.opacity = "0", e.classList.add("tiny-spark-tooltip"), e.setAttribute("id", `tooltip_${o}`), e.style.pointerEvents = "none", e.style.position = "fixed", e.style.top = d + "px", e.style.left = i + "px", e.style.width = "fit-content", e.innerHTML = `
139
139
  <div class="tiny-spark-tooltip-content">${n.d ? `${n.d}: ` : ""}${[null, void 0].includes(n.v) ? "-" : E(r, Number(n.v))}</div>
140
140
  `, document.body.appendChild(e), F().then(() => {
141
- const { width: h, height: p } = e.getBoundingClientRect();
142
- e.style.left = `${i - h / 2}px`, e.style.top = `${d - p - Number(String(Number(a(r, l.PLOT_RADIUS, 3)) * 1.5))}px`;
141
+ const { width: m, height: p } = e.getBoundingClientRect();
142
+ e.style.left = `${i - m / 2}px`, e.style.top = `${d - p - Number(String(Number(a(r, l.PLOT_RADIUS, 3)) * 1.5))}px`;
143
143
  }).then(() => {
144
144
  e.style.opacity = "1";
145
145
  });
@@ -154,13 +154,13 @@ function ot(t) {
154
154
  function it(t, r) {
155
155
  let n = r;
156
156
  ot(t);
157
- const { svg: o, svgId: s, width: i, height: d } = J(t), { color: e, backgroundColor: h } = tt(t), p = { T: 12, R: 12, B: 12, L: 12 }, O = K(), L = String(a(t, l.SHOW_LAST_VALUE, "false")) === "true", u = {
157
+ const { svg: o, svgId: s, width: i, height: d } = J(t), { color: e, backgroundColor: m } = tt(t), p = { T: 12, R: 12, B: 12, L: 12 }, O = K(), L = String(a(t, l.SHOW_LAST_VALUE, "false")) === "true", u = {
158
158
  left: p.L,
159
159
  top: p.T,
160
160
  width: i - p.L - p.R,
161
161
  height: d - p.T - p.B,
162
162
  bottom: d - p.B
163
- }, _ = j(t), { min: R } = D(_), A = _.map((g) => [null, void 0].includes(g) ? g : g + (R < 0 ? Math.abs(R) : 0)), { max: k } = D(A), C = u.width / (_.length - 1) === 1 / 0 ? u.width : u.width / (_.length - 1), X = et(t), m = A.map((g, b) => {
163
+ }, _ = j(t), { min: R } = D(_), A = _.map((g) => [null, void 0].includes(g) ? g : g + (R < 0 ? Math.abs(R) : 0)), { max: k } = D(A), C = u.width / (_.length - 1) === 1 / 0 ? u.width : u.width / (_.length - 1), X = et(t), h = A.map((g, b) => {
164
164
  const f = {
165
165
  w: A.length === 1 ? C / 2 : 0,
166
166
  h: A.length === 1 ? u.height / 2 : 0
@@ -171,39 +171,39 @@ function it(t, r) {
171
171
  v: g,
172
172
  d: X[b] || null
173
173
  };
174
- }), v = [...m].filter(({ v: g }) => ![null, void 0].includes(g)), x = document.createElementNS(I, "path");
174
+ }), v = [...h].filter(({ v: g }) => ![null, void 0].includes(g)), x = document.createElementNS(I, "path");
175
175
  x.classList.add("tiny-spark-line-path"), !t.dataset.curve || t.dataset.curve === "true" ? x.setAttribute("d", `M ${B(v)}`) : x.setAttribute("d", `M ${W(v)}`), x.setAttribute("fill", "none"), x.setAttribute("stroke", String(a(t, l.LINE_COLOR, e))), x.setAttribute("stroke-width", String(a(t, l.LINE_THICKNESS, 2))), x.setAttribute("stroke-linecap", "round");
176
176
  const w = document.createElementNS(I, "path");
177
177
  w.classList.add("tiny-spark-line-area");
178
178
  const H = t.getAttribute("data-animation");
179
- H === "true" && n && (x.style.opacity = "0", w.style.opacity = "0"), m.length && (!t.dataset.curve || t.dataset.curve === "true" ? w.setAttribute("d", `M ${v[0].x},${u.bottom} ${B(v)} L ${v.at(-1).x},${u.bottom} Z`) : w.setAttribute("d", `M ${v[0].x},${u.bottom} ${W(v)} L ${v.at(-1).x},${u.bottom} Z`)), w.setAttribute("fill", String(a(t, l.AREA_COLOR, "transparent"))), m.length > 1 && (o.appendChild(w), o.appendChild(x));
179
+ H === "true" && n && (x.style.opacity = "0", w.style.opacity = "0"), h.length && (!t.dataset.curve || t.dataset.curve === "true" ? w.setAttribute("d", `M ${v[0].x},${u.bottom} ${B(v)} L ${v.at(-1).x},${u.bottom} Z`) : w.setAttribute("d", `M ${v[0].x},${u.bottom} ${W(v)} L ${v.at(-1).x},${u.bottom} Z`)), w.setAttribute("fill", String(a(t, l.AREA_COLOR, "transparent"))), h.length > 1 && (o.appendChild(w), o.appendChild(x));
180
180
  const P = [];
181
- m.forEach((g, b) => {
181
+ h.forEach((g, b) => {
182
182
  const f = document.createElementNS(I, "line");
183
- f.classList.add("tiny-spark-indicator"), f.setAttribute("id", `indicator_${s}_${b}`), f.setAttribute("x1", String(u.left + (m.length === 1 ? u.width / 2 : b * C))), f.setAttribute("x2", String(u.left + (m.length === 1 ? u.width / 2 : b * C))), f.setAttribute("y1", String(u.top)), f.setAttribute("y2", String(u.bottom)), f.setAttribute("stroke", String(a(t, l.INDICATOR_COLOR, "#1A1A1A"))), f.setAttribute("stroke-width", String(a(t, l.INDICATOR_WIDTH, "1"))), f.setAttribute("stroke-linecap", "round"), f.style.pointerEvents = "none", f.style.opacity = "0", P.push(f), o.appendChild(f);
183
+ f.classList.add("tiny-spark-indicator"), f.setAttribute("id", `indicator_${s}_${b}`), f.setAttribute("x1", String(u.left + (h.length === 1 ? u.width / 2 : b * C))), f.setAttribute("x2", String(u.left + (h.length === 1 ? u.width / 2 : b * C))), f.setAttribute("y1", String(u.top)), f.setAttribute("y2", String(u.bottom)), f.setAttribute("stroke", String(a(t, l.INDICATOR_COLOR, "#1A1A1A"))), f.setAttribute("stroke-width", String(a(t, l.INDICATOR_WIDTH, "1"))), f.setAttribute("stroke-linecap", "round"), f.style.pointerEvents = "none", f.style.opacity = "0", P.push(f), o.appendChild(f);
184
184
  });
185
185
  let $ = [];
186
- const M = Number(String(a(t, l.PLOT_RADIUS, 0))) > 0, q = !String(a(t, l.HIDE_PLOTS_ABOVE, "")) || m.length <= Number(String(a(t, l.HIDE_PLOTS_ABOVE, 0))), V = M && q;
187
- M && m.forEach(({ x: g, y: b, v: f }, S) => {
186
+ const M = Number(String(a(t, l.PLOT_RADIUS, 0))) > 0, q = !String(a(t, l.HIDE_PLOTS_ABOVE, "")) || h.length <= Number(String(a(t, l.HIDE_PLOTS_ABOVE, 0))), V = M && q;
187
+ M && h.forEach(({ x: g, y: b, v: f }, S) => {
188
188
  if (![null, void 0].includes(f)) {
189
189
  const c = document.createElementNS(I, "circle");
190
- c.classList.add("tiny-spark-datapoint-circle"), c.classList.add(`circle-${s}`), c.setAttribute("id", `circle_${s}_${S}`), c.setAttribute("cx", String(g || 0)), c.setAttribute("cy", String(b || 0)), c.setAttribute("r", String(a(t, l.PLOT_RADIUS, 3))), c.setAttribute("fill", String(a(t, l.PLOT_COLOR, String(a(t, "lineColor", e))))), c.setAttribute("stroke", h), c.style.opacity = "0", c.style.transition = `opacity ${S * (1e3 * 2 / m.length)}ms ease-in`, c.style.pointerEvents = "none", $.push(c), V && o.appendChild(c);
190
+ c.classList.add("tiny-spark-datapoint-circle"), c.classList.add(`circle-${s}`), c.setAttribute("id", `circle_${s}_${S}`), c.setAttribute("cx", String(g || 0)), c.setAttribute("cy", String(b || 0)), c.setAttribute("r", String(a(t, l.PLOT_RADIUS, 3))), c.setAttribute("fill", String(a(t, l.PLOT_COLOR, String(a(t, "lineColor", e))))), c.setAttribute("stroke", m), c.style.opacity = h.length === 1 ? "1" : "0", c.style.transition = `opacity ${S * (1e3 * 2 / h.length)}ms ease-in`, c.style.pointerEvents = "none", $.push(c), V && o.appendChild(c);
191
191
  }
192
192
  });
193
193
  let y = null;
194
- if (L && m.length && m.at(-1)) {
194
+ if (L && h.length && h.at(-1)) {
195
195
  const g = Number(a(t, l.LAST_VALUE_FONT_SIZE, 12));
196
- y = document.createElementNS(I, "text"), y.classList.add("tiny-spark-last-value"), y.setAttribute("id", O), y.setAttribute("x", String(m.at(-1).x + 6 + Number(a(t, l.LINE_THICKNESS, 2)))), y.setAttribute("y", String(m.at(-1).y + g / 3)), y.setAttribute("text-anchor", "start"), y.setAttribute("font-size", String(g) + "px"), y.setAttribute("fill", String(a(t, l.LAST_VALUE_COLOR, String(a(t, l.INDICATOR_COLOR, "#1A1A1A"))))), y.innerHTML = E(t, Number(m.at(-1).v)), y.style.opacity = "0", o.appendChild(y);
196
+ y = document.createElementNS(I, "text"), y.classList.add("tiny-spark-last-value"), y.setAttribute("id", O), y.setAttribute("x", String(h.at(-1).x + 6 + Number(a(t, l.LINE_THICKNESS, 2)))), y.setAttribute("y", String(h.at(-1).y + g / 3)), y.setAttribute("text-anchor", "start"), y.setAttribute("font-size", String(g) + "px"), y.setAttribute("fill", String(a(t, l.LAST_VALUE_COLOR, String(a(t, l.INDICATOR_COLOR, "#1A1A1A"))))), y.innerHTML = E(t, Number(h.at(-1).v)), y.style.opacity = h.length === 1 ? "1" : "0", o.appendChild(y);
197
197
  }
198
- m.forEach((g, b) => {
198
+ h.forEach((g, b) => {
199
199
  const f = $[b], S = document.createElementNS(I, "rect");
200
- S.classList.add("tiny-spark-tooltip-trap"), S.setAttribute("x", `${m.length === 1 ? 0 : u.left + b * C - C / 2}`), S.setAttribute("y", `${u.top}`), S.setAttribute("height", `${u.height}`), S.setAttribute("width", `${C}`), S.setAttribute("fill", "transparent"), S.addEventListener("mouseenter", () => {
200
+ S.classList.add("tiny-spark-tooltip-trap"), S.setAttribute("x", `${h.length === 1 ? 0 : u.left + b * C - C / 2}`), S.setAttribute("y", `${u.top}`), S.setAttribute("height", `${u.height}`), S.setAttribute("width", `${C}`), S.setAttribute("fill", "transparent"), S.addEventListener("mouseenter", () => {
201
201
  if (G(o, t, g, s, !0), V) {
202
202
  const c = document.getElementById(`circle_${s}_${b}`);
203
203
  c == null || c.setAttribute("r", String(Number(a(t, l.PLOT_RADIUS, 3)) * 1.5));
204
204
  } else
205
205
  o.appendChild(f);
206
- P[b].style.opacity = "1", L && y && (b === m.length - 1 ? y.style.opacity = "0" : y.style.opacity = "1");
206
+ P[b].style.opacity = "1", L && y && (b === h.length - 1 ? y.style.opacity = "0" : y.style.opacity = "1");
207
207
  }), S.addEventListener("mouseout", () => {
208
208
  if (G(o, t, g, s, !1), V) {
209
209
  const c = document.getElementById(`circle_${s}_${b}`);
@@ -1,6 +1,6 @@
1
- (function(I,x){typeof exports=="object"&&typeof module<"u"?x(exports):typeof define=="function"&&define.amd?define(["exports"],x):(I=typeof globalThis<"u"?globalThis:I||self,x(I.TinySpark={}))})(this,function(I){"use strict";const x="http://www.w3.org/2000/svg";var a=(t=>(t.ANIMATION="animation",t.AREA_COLOR="areaColor",t.CURVE="curve",t.DATES="dates",t.ID="id",t.INDICATOR_COLOR="indicatorColor",t.INDICATOR_WIDTH="indicatorWidth",t.LINE_COLOR="lineColor",t.LINE_THICKNESS="lineThickness",t.NUMBER_LOCALE="numberLocale",t.NUMBER_ROUNDING="numberRounding",t.NUMBER_SHOW_ON="numberShowOn",t.PLOT_COLOR="plotColor",t.PLOT_RADIUS="plotRadius",t.SET="set",t.HIDE_PLOTS_ABOVE="hidePlotsAbove",t.SHOW_LAST_VALUE="showLastValue",t.LAST_VALUE_FONT_SIZE="lastValueFontSize",t.LAST_VALUE_COLOR="lastValueColor",t))(a||{}),M=(t=>(t.ANIMATION="data-animation",t.AREA_COLOR="data-area-color",t.CURVE="data-curve",t.DATES="data-dates",t.ID="data-id",t.INDICATOR_COLOR="data-indicator-color",t.INDICATOR_WIDTH="data-indicator-width",t.LINE_COLOR="data-line-color",t.LINE_THICKNESS="data-line-thickness",t.NUMBER_LOCALE="data-number-locale",t.NUMBER_ROUNDING="data-number-rounding",t.NUMBER_SHOW_ON="data-number-show-on",t.PLOT_COLOR="data-plot-color",t.PLOT_RADIUS="data-plot-radius",t.SET="data-set",t.HIDE_PLOTS_ABOVE="data-hide-plots-above",t.SHOW_LAST_VALUE="data-show-last-value",t.LAST_VALUE_FONT_SIZE="data-last-value-font-size",t.LAST_VALUE_COLOR="data-last-value-color",t))(M||{});function q(t){const{width:r,height:n}=t.parentElement.getBoundingClientRect(),o={width:300,height:100},s=String(l(t,a.SHOW_LAST_VALUE,"false"))==="true",i=j(t),c=i&&i.length?i.at(-1):null;let e=0;if(s&&![null,void 0].includes(c)){const u=Number(String(l(t,a.NUMBER_ROUNDING,0)));e=6+c.toFixed(u).length*(Number(l(t,a.LAST_VALUE_FONT_SIZE,12))/2)}const h=`0 0 ${(r||o.width)+e} ${n||o.height}`,S=document.createElementNS(x,"svg"),C=t.dataset.id;return S.id=C,S.setAttribute("viewBox",h),S.style.width="100%",S.style.height="100%",{svg:S,svgId:C,width:r||o.width,height:n||o.height}}function N(t,r=0){return isNaN(t)?r:t}function W(t){let r=[];for(let n=0;n<t.length;n+=1)r.push(`${N(t[n].x)},${N(t[n].y)} `);return r.join(" ").trim()}function B(t){if(t.length<1)return"0,0";const r=t.length-1,n=[`${N(t[0].x)},${N(t[0].y)}`],o=[],s=[],i=[],c=[];for(let e=0;e<r;e+=1)o[e]=t[e+1].x-t[e].x,s[e]=t[e+1].y-t[e].y,i[e]=s[e]/o[e];c[0]=i[0],c[r]=i[r-1];for(let e=1;e<r;e+=1)if(i[e-1]*i[e]<=0)c[e]=0;else{const p=2*i[e-1]*i[e]/(i[e-1]+i[e]);c[e]=p}for(let e=0;e<r;e+=1){const p=t[e].x,h=t[e].y,S=t[e+1].x,C=t[e+1].y,u=c[e],A=c[e+1],$=p+(S-p)/3,R=h+u*(S-p)/3,F=S-(S-p)/3,v=C-A*(S-p)/3;n.push(`C ${N($)},${N(R)} ${N(F)},${N(v)} ${N(S)},${N(C)}`)}return n.join(" ")}function J(t,r=1e3,n){t.style.opacity="1";const o=t.getTotalLength();t.style.strokeDasharray=String(o),t.style.strokeDashoffset=String(o),t.getBoundingClientRect(),t.style.transition=`stroke-dashoffset ${r}ms ease-in-out`,t.style.strokeDashoffset="0",t.addEventListener("transitionend",function s(){t.style.transition="",t.removeEventListener("transitionend",s),n&&n()})}function Y(t,r,n=1e3){r.style.opacity="1";const o=r.getBBox(),s=o.width,i=document.createElementNS("http://www.w3.org/2000/svg","clipPath"),c="clip-"+Math.random().toString(36).substr(2,9);i.setAttribute("id",c);const e=document.createElementNS("http://www.w3.org/2000/svg","rect");e.setAttribute("x",o.x.toString()),e.setAttribute("y",o.y.toString()),e.setAttribute("width","0"),e.setAttribute("height",o.height.toString()),i.appendChild(e);let p=t.querySelector("defs");p||(p=document.createElementNS("http://www.w3.org/2000/svg","defs"),t.insertBefore(p,t.firstChild)),p.appendChild(i),r.setAttribute("clip-path",`url(#${c})`),e.style.transition=`width ${n}ms ease-out`,e.getBoundingClientRect(),e.setAttribute("width",s.toString()),e.addEventListener("transitionend",function h(){r.removeAttribute("clip-path"),i.parentNode&&i.parentNode.removeChild(i),e.removeEventListener("transitionend",h)})}function Q(){return document.querySelectorAll(".tiny-spark")}function D(t,r){return Object.keys(t.dataset).includes(r)}function l(t,r,n){return D(t,r)?t.dataset[r]:n}function T(t){if(!t)return{color:"#1A1A1A",backgroundColor:"#FFFFFF"};const r=window.getComputedStyle(t),n=r.getPropertyValue("color")||"#1A1A1A",o=r.getPropertyValue("background-color"),s=r.getPropertyValue("background");return{color:n,backgroundColor:o||s||"#FFFFFF"}}function G(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){const r=Math.random()*16|0;return(t=="x"?r:r&3|8).toString(16)})}function j(t){const r=t.getAttribute("data-set");if(!r)return[];try{const n=JSON.parse(r);return Array.isArray(n)&&n.every(o=>typeof o=="number"||[null,void 0].includes(o))?n:(console.warn("data-set is not an array of numbers."),[])}catch(n){return console.error("Error parsing data-set:",n),[]}}function tt(t){const r=t.getAttribute("data-dates");if(!r)return[];try{const n=JSON.parse(r);return Array.isArray(n)&&n.every(o=>typeof o=="string")?n:(console.warn("data-dates is not an array of strings"),[])}catch(n){return console.error("Error parsing data-dates",n),[]}}function z(t){return{min:Math.min(...t),max:Math.max(...t)}}function P(){return new Promise(t=>setTimeout(t,0))}function Z(t,r){const n=String(l(t,a.NUMBER_LOCALE,navigator.language||"en-US")),o=Number(String(l(t,a.NUMBER_ROUNDING,0)));return r.toLocaleString(n,{useGrouping:!0,minimumFractionDigits:o,maximumFractionDigits:o})}function et(t,r,n){if(!t.createSVGPoint||!t.getScreenCTM)throw new Error("Your browser does not support SVG coordinate transformation.");const o=t.getScreenCTM();if(!o)throw new Error("Cannot obtain the screen CTM.");const s=t.createSVGPoint();s.x=r,s.y=n;const i=s.matrixTransform(o);return{x:i.x,y:i.y}}function K(t,r,n,o,s){if(nt(o),!s)return;const{x:i,y:c}=et(t,n.x,n.y),e=document.createElement("div");e.style.opacity="0",e.classList.add("tiny-spark-tooltip"),e.setAttribute("id",`tooltip_${o}`),e.style.pointerEvents="none",e.style.position="fixed",e.style.top=c+"px",e.style.left=i+"px",e.style.width="fit-content",e.innerHTML=`
1
+ (function(I,x){typeof exports=="object"&&typeof module<"u"?x(exports):typeof define=="function"&&define.amd?define(["exports"],x):(I=typeof globalThis<"u"?globalThis:I||self,x(I.TinySpark={}))})(this,function(I){"use strict";const x="http://www.w3.org/2000/svg";var a=(t=>(t.ANIMATION="animation",t.AREA_COLOR="areaColor",t.CURVE="curve",t.DATES="dates",t.ID="id",t.INDICATOR_COLOR="indicatorColor",t.INDICATOR_WIDTH="indicatorWidth",t.LINE_COLOR="lineColor",t.LINE_THICKNESS="lineThickness",t.NUMBER_LOCALE="numberLocale",t.NUMBER_ROUNDING="numberRounding",t.NUMBER_SHOW_ON="numberShowOn",t.PLOT_COLOR="plotColor",t.PLOT_RADIUS="plotRadius",t.SET="set",t.HIDE_PLOTS_ABOVE="hidePlotsAbove",t.SHOW_LAST_VALUE="showLastValue",t.LAST_VALUE_FONT_SIZE="lastValueFontSize",t.LAST_VALUE_COLOR="lastValueColor",t))(a||{}),M=(t=>(t.ANIMATION="data-animation",t.AREA_COLOR="data-area-color",t.CURVE="data-curve",t.DATES="data-dates",t.ID="data-id",t.INDICATOR_COLOR="data-indicator-color",t.INDICATOR_WIDTH="data-indicator-width",t.LINE_COLOR="data-line-color",t.LINE_THICKNESS="data-line-thickness",t.NUMBER_LOCALE="data-number-locale",t.NUMBER_ROUNDING="data-number-rounding",t.NUMBER_SHOW_ON="data-number-show-on",t.PLOT_COLOR="data-plot-color",t.PLOT_RADIUS="data-plot-radius",t.SET="data-set",t.HIDE_PLOTS_ABOVE="data-hide-plots-above",t.SHOW_LAST_VALUE="data-show-last-value",t.LAST_VALUE_FONT_SIZE="data-last-value-font-size",t.LAST_VALUE_COLOR="data-last-value-color",t))(M||{});function q(t){const{width:r,height:n}=t.parentElement.getBoundingClientRect(),o={width:300,height:100},s=String(l(t,a.SHOW_LAST_VALUE,"false"))==="true",i=j(t),c=i&&i.length?i.at(-1):null;let e=0;if(s&&![null,void 0].includes(c)){const u=Number(String(l(t,a.NUMBER_ROUNDING,0)));e=6+c.toFixed(u).length*(Number(l(t,a.LAST_VALUE_FONT_SIZE,12))/2)}const m=`0 0 ${(r||o.width)+e} ${n||o.height}`,S=document.createElementNS(x,"svg"),C=t.dataset.id;return S.id=C,S.setAttribute("viewBox",m),S.style.width="100%",S.style.height="100%",{svg:S,svgId:C,width:r||o.width,height:n||o.height}}function N(t,r=0){return isNaN(t)?r:t}function W(t){let r=[];for(let n=0;n<t.length;n+=1)r.push(`${N(t[n].x)},${N(t[n].y)} `);return r.join(" ").trim()}function B(t){if(t.length<1)return"0,0";const r=t.length-1,n=[`${N(t[0].x)},${N(t[0].y)}`],o=[],s=[],i=[],c=[];for(let e=0;e<r;e+=1)o[e]=t[e+1].x-t[e].x,s[e]=t[e+1].y-t[e].y,i[e]=s[e]/o[e];c[0]=i[0],c[r]=i[r-1];for(let e=1;e<r;e+=1)if(i[e-1]*i[e]<=0)c[e]=0;else{const h=2*i[e-1]*i[e]/(i[e-1]+i[e]);c[e]=h}for(let e=0;e<r;e+=1){const h=t[e].x,m=t[e].y,S=t[e+1].x,C=t[e+1].y,u=c[e],A=c[e+1],$=h+(S-h)/3,R=m+u*(S-h)/3,F=S-(S-h)/3,v=C-A*(S-h)/3;n.push(`C ${N($)},${N(R)} ${N(F)},${N(v)} ${N(S)},${N(C)}`)}return n.join(" ")}function J(t,r=1e3,n){t.style.opacity="1";const o=t.getTotalLength();t.style.strokeDasharray=String(o),t.style.strokeDashoffset=String(o),t.getBoundingClientRect(),t.style.transition=`stroke-dashoffset ${r}ms ease-in-out`,t.style.strokeDashoffset="0",t.addEventListener("transitionend",function s(){t.style.transition="",t.removeEventListener("transitionend",s),n&&n()})}function Y(t,r,n=1e3){r.style.opacity="1";const o=r.getBBox(),s=o.width,i=document.createElementNS("http://www.w3.org/2000/svg","clipPath"),c="clip-"+Math.random().toString(36).substr(2,9);i.setAttribute("id",c);const e=document.createElementNS("http://www.w3.org/2000/svg","rect");e.setAttribute("x",o.x.toString()),e.setAttribute("y",o.y.toString()),e.setAttribute("width","0"),e.setAttribute("height",o.height.toString()),i.appendChild(e);let h=t.querySelector("defs");h||(h=document.createElementNS("http://www.w3.org/2000/svg","defs"),t.insertBefore(h,t.firstChild)),h.appendChild(i),r.setAttribute("clip-path",`url(#${c})`),e.style.transition=`width ${n}ms ease-out`,e.getBoundingClientRect(),e.setAttribute("width",s.toString()),e.addEventListener("transitionend",function m(){r.removeAttribute("clip-path"),i.parentNode&&i.parentNode.removeChild(i),e.removeEventListener("transitionend",m)})}function Q(){return document.querySelectorAll(".tiny-spark")}function D(t,r){return Object.keys(t.dataset).includes(r)}function l(t,r,n){return D(t,r)?t.dataset[r]:n}function T(t){if(!t)return{color:"#1A1A1A",backgroundColor:"#FFFFFF"};const r=window.getComputedStyle(t),n=r.getPropertyValue("color")||"#1A1A1A",o=r.getPropertyValue("background-color"),s=r.getPropertyValue("background");return{color:n,backgroundColor:o||s||"#FFFFFF"}}function G(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){const r=Math.random()*16|0;return(t=="x"?r:r&3|8).toString(16)})}function j(t){const r=t.getAttribute("data-set");if(!r)return[];try{const n=JSON.parse(r);return Array.isArray(n)&&n.every(o=>typeof o=="number"||[null,void 0].includes(o))?n:(console.warn("data-set is not an array of numbers."),[])}catch(n){return console.error("Error parsing data-set:",n),[]}}function tt(t){const r=t.getAttribute("data-dates");if(!r)return[];try{const n=JSON.parse(r);return Array.isArray(n)&&n.every(o=>typeof o=="string")?n:(console.warn("data-dates is not an array of strings"),[])}catch(n){return console.error("Error parsing data-dates",n),[]}}function z(t){return{min:Math.min(...t),max:Math.max(...t)}}function P(){return new Promise(t=>setTimeout(t,0))}function Z(t,r){const n=String(l(t,a.NUMBER_LOCALE,navigator.language||"en-US")),o=Number(String(l(t,a.NUMBER_ROUNDING,0)));return r.toLocaleString(n,{useGrouping:!0,minimumFractionDigits:o,maximumFractionDigits:o})}function et(t,r,n){if(!t.createSVGPoint||!t.getScreenCTM)throw new Error("Your browser does not support SVG coordinate transformation.");const o=t.getScreenCTM();if(!o)throw new Error("Cannot obtain the screen CTM.");const s=t.createSVGPoint();s.x=r,s.y=n;const i=s.matrixTransform(o);return{x:i.x,y:i.y}}function K(t,r,n,o,s){if(nt(o),!s)return;const{x:i,y:c}=et(t,n.x,n.y),e=document.createElement("div");e.style.opacity="0",e.classList.add("tiny-spark-tooltip"),e.setAttribute("id",`tooltip_${o}`),e.style.pointerEvents="none",e.style.position="fixed",e.style.top=c+"px",e.style.left=i+"px",e.style.width="fit-content",e.innerHTML=`
2
2
  <div class="tiny-spark-tooltip-content">${n.d?`${n.d}: `:""}${[null,void 0].includes(n.v)?"-":Z(r,Number(n.v))}</div>
3
- `,document.body.appendChild(e),P().then(()=>{const{width:p,height:h}=e.getBoundingClientRect();e.style.left=`${i-p/2}px`,e.style.top=`${c-h-Number(String(Number(l(r,a.PLOT_RADIUS,3))*1.5))}px`}).then(()=>{e.style.opacity="1"})}function nt(t){const r=document.getElementById(`tooltip_${t}`);r==null||r.remove()}function rt(t){t.innerHTML=""}function ot(t,r){let n=r;rt(t);const{svg:o,svgId:s,width:i,height:c}=q(t),{color:e,backgroundColor:p}=T(t),h={T:12,R:12,B:12,L:12},S=G(),C=String(l(t,a.SHOW_LAST_VALUE,"false"))==="true",u={left:h.L,top:h.T,width:i-h.L-h.R,height:c-h.T-h.B,bottom:c-h.B},A=j(t),{min:$}=z(A),R=A.map(g=>[null,void 0].includes(g)?g:g+($<0?Math.abs($):0)),{max:F}=z(R),v=u.width/(A.length-1)===1/0?u.width:u.width/(A.length-1),lt=tt(t),m=R.map((g,b)=>{const f={w:R.length===1?v/2:0,h:R.length===1?u.height/2:0};return{y:(1-(g||0)/F)*u.height+h.T+f.h,x:u.left+v*b+f.w,v:g,d:lt[b]||null}}),w=[...m].filter(({v:g})=>![null,void 0].includes(g)),L=document.createElementNS(x,"path");L.classList.add("tiny-spark-line-path"),!t.dataset.curve||t.dataset.curve==="true"?L.setAttribute("d",`M ${B(w)}`):L.setAttribute("d",`M ${W(w)}`),L.setAttribute("fill","none"),L.setAttribute("stroke",String(l(t,a.LINE_COLOR,e))),L.setAttribute("stroke-width",String(l(t,a.LINE_THICKNESS,2))),L.setAttribute("stroke-linecap","round");const _=document.createElementNS(x,"path");_.classList.add("tiny-spark-line-area");const E=t.getAttribute("data-animation");E==="true"&&n&&(L.style.opacity="0",_.style.opacity="0"),m.length&&(!t.dataset.curve||t.dataset.curve==="true"?_.setAttribute("d",`M ${w[0].x},${u.bottom} ${B(w)} L ${w.at(-1).x},${u.bottom} Z`):_.setAttribute("d",`M ${w[0].x},${u.bottom} ${W(w)} L ${w.at(-1).x},${u.bottom} Z`)),_.setAttribute("fill",String(l(t,a.AREA_COLOR,"transparent"))),m.length>1&&(o.appendChild(_),o.appendChild(L));const U=[];m.forEach((g,b)=>{const f=document.createElementNS(x,"line");f.classList.add("tiny-spark-indicator"),f.setAttribute("id",`indicator_${s}_${b}`),f.setAttribute("x1",String(u.left+(m.length===1?u.width/2:b*v))),f.setAttribute("x2",String(u.left+(m.length===1?u.width/2:b*v))),f.setAttribute("y1",String(u.top)),f.setAttribute("y2",String(u.bottom)),f.setAttribute("stroke",String(l(t,a.INDICATOR_COLOR,"#1A1A1A"))),f.setAttribute("stroke-width",String(l(t,a.INDICATOR_WIDTH,"1"))),f.setAttribute("stroke-linecap","round"),f.style.pointerEvents="none",f.style.opacity="0",U.push(f),o.appendChild(f)});let k=[];const X=Number(String(l(t,a.PLOT_RADIUS,0)))>0,ut=!String(l(t,a.HIDE_PLOTS_ABOVE,""))||m.length<=Number(String(l(t,a.HIDE_PLOTS_ABOVE,0))),H=X&&ut;X&&m.forEach(({x:g,y:b,v:f},O)=>{if(![null,void 0].includes(f)){const d=document.createElementNS(x,"circle");d.classList.add("tiny-spark-datapoint-circle"),d.classList.add(`circle-${s}`),d.setAttribute("id",`circle_${s}_${O}`),d.setAttribute("cx",String(g||0)),d.setAttribute("cy",String(b||0)),d.setAttribute("r",String(l(t,a.PLOT_RADIUS,3))),d.setAttribute("fill",String(l(t,a.PLOT_COLOR,String(l(t,"lineColor",e))))),d.setAttribute("stroke",p),d.style.opacity="0",d.style.transition=`opacity ${O*(1e3*2/m.length)}ms ease-in`,d.style.pointerEvents="none",k.push(d),H&&o.appendChild(d)}});let y=null;if(C&&m.length&&m.at(-1)){const g=Number(l(t,a.LAST_VALUE_FONT_SIZE,12));y=document.createElementNS(x,"text"),y.classList.add("tiny-spark-last-value"),y.setAttribute("id",S),y.setAttribute("x",String(m.at(-1).x+6+Number(l(t,a.LINE_THICKNESS,2)))),y.setAttribute("y",String(m.at(-1).y+g/3)),y.setAttribute("text-anchor","start"),y.setAttribute("font-size",String(g)+"px"),y.setAttribute("fill",String(l(t,a.LAST_VALUE_COLOR,String(l(t,a.INDICATOR_COLOR,"#1A1A1A"))))),y.innerHTML=Z(t,Number(m.at(-1).v)),y.style.opacity="0",o.appendChild(y)}m.forEach((g,b)=>{const f=k[b],O=document.createElementNS(x,"rect");O.classList.add("tiny-spark-tooltip-trap"),O.setAttribute("x",`${m.length===1?0:u.left+b*v-v/2}`),O.setAttribute("y",`${u.top}`),O.setAttribute("height",`${u.height}`),O.setAttribute("width",`${v}`),O.setAttribute("fill","transparent"),O.addEventListener("mouseenter",()=>{if(K(o,t,g,s,!0),H){const d=document.getElementById(`circle_${s}_${b}`);d==null||d.setAttribute("r",String(Number(l(t,a.PLOT_RADIUS,3))*1.5))}else o.appendChild(f);U[b].style.opacity="1",C&&y&&(b===m.length-1?y.style.opacity="0":y.style.opacity="1")}),O.addEventListener("mouseout",()=>{if(K(o,t,g,s,!1),H){const d=document.getElementById(`circle_${s}_${b}`);d==null||d.setAttribute("r",String(Number(l(t,a.PLOT_RADIUS,3))))}else f.remove();U.forEach(d=>d.style.opacity="0"),C&&y&&(y.style.opacity="1")}),o.appendChild(O)}),E==="true"&&n?P().then(()=>{k.forEach(g=>{g.style.opacity="1"}),J(L,1e3,()=>{y&&(y.style.opacity="1")}),Y(o,_)}):(k.forEach(g=>{g.style.opacity="1"}),y&&(y.style.opacity="1")),t.appendChild(o)}function it(){const t=Q();t.length&&Array.from(t).forEach(r=>{if(!r.dataset.id){const o=G();r.setAttribute("data-id",o)}const n=r;st(n),n.__renderCount=0,V(n),P().then(()=>{const o=new ResizeObserver(i=>{i.forEach(()=>V(n))});n.parentElement&&o.observe(n.parentElement),new MutationObserver(i=>{for(const c of i)if(c.type==="attributes"&&c.attributeName&&Object.values(M).includes(c.attributeName)){V(n);break}}).observe(n,{attributes:!0})})})}function V(t){D(t,"set")&&ot(t,t.__renderCount<2),t.__renderCount+=1}function st(t){t.dataset.set||console.error(`Tiny-spark exception:
3
+ `,document.body.appendChild(e),P().then(()=>{const{width:h,height:m}=e.getBoundingClientRect();e.style.left=`${i-h/2}px`,e.style.top=`${c-m-Number(String(Number(l(r,a.PLOT_RADIUS,3))*1.5))}px`}).then(()=>{e.style.opacity="1"})}function nt(t){const r=document.getElementById(`tooltip_${t}`);r==null||r.remove()}function rt(t){t.innerHTML=""}function ot(t,r){let n=r;rt(t);const{svg:o,svgId:s,width:i,height:c}=q(t),{color:e,backgroundColor:h}=T(t),m={T:12,R:12,B:12,L:12},S=G(),C=String(l(t,a.SHOW_LAST_VALUE,"false"))==="true",u={left:m.L,top:m.T,width:i-m.L-m.R,height:c-m.T-m.B,bottom:c-m.B},A=j(t),{min:$}=z(A),R=A.map(g=>[null,void 0].includes(g)?g:g+($<0?Math.abs($):0)),{max:F}=z(R),v=u.width/(A.length-1)===1/0?u.width:u.width/(A.length-1),lt=tt(t),p=R.map((g,b)=>{const f={w:R.length===1?v/2:0,h:R.length===1?u.height/2:0};return{y:(1-(g||0)/F)*u.height+m.T+f.h,x:u.left+v*b+f.w,v:g,d:lt[b]||null}}),w=[...p].filter(({v:g})=>![null,void 0].includes(g)),L=document.createElementNS(x,"path");L.classList.add("tiny-spark-line-path"),!t.dataset.curve||t.dataset.curve==="true"?L.setAttribute("d",`M ${B(w)}`):L.setAttribute("d",`M ${W(w)}`),L.setAttribute("fill","none"),L.setAttribute("stroke",String(l(t,a.LINE_COLOR,e))),L.setAttribute("stroke-width",String(l(t,a.LINE_THICKNESS,2))),L.setAttribute("stroke-linecap","round");const _=document.createElementNS(x,"path");_.classList.add("tiny-spark-line-area");const E=t.getAttribute("data-animation");E==="true"&&n&&(L.style.opacity="0",_.style.opacity="0"),p.length&&(!t.dataset.curve||t.dataset.curve==="true"?_.setAttribute("d",`M ${w[0].x},${u.bottom} ${B(w)} L ${w.at(-1).x},${u.bottom} Z`):_.setAttribute("d",`M ${w[0].x},${u.bottom} ${W(w)} L ${w.at(-1).x},${u.bottom} Z`)),_.setAttribute("fill",String(l(t,a.AREA_COLOR,"transparent"))),p.length>1&&(o.appendChild(_),o.appendChild(L));const U=[];p.forEach((g,b)=>{const f=document.createElementNS(x,"line");f.classList.add("tiny-spark-indicator"),f.setAttribute("id",`indicator_${s}_${b}`),f.setAttribute("x1",String(u.left+(p.length===1?u.width/2:b*v))),f.setAttribute("x2",String(u.left+(p.length===1?u.width/2:b*v))),f.setAttribute("y1",String(u.top)),f.setAttribute("y2",String(u.bottom)),f.setAttribute("stroke",String(l(t,a.INDICATOR_COLOR,"#1A1A1A"))),f.setAttribute("stroke-width",String(l(t,a.INDICATOR_WIDTH,"1"))),f.setAttribute("stroke-linecap","round"),f.style.pointerEvents="none",f.style.opacity="0",U.push(f),o.appendChild(f)});let k=[];const X=Number(String(l(t,a.PLOT_RADIUS,0)))>0,ut=!String(l(t,a.HIDE_PLOTS_ABOVE,""))||p.length<=Number(String(l(t,a.HIDE_PLOTS_ABOVE,0))),H=X&&ut;X&&p.forEach(({x:g,y:b,v:f},O)=>{if(![null,void 0].includes(f)){const d=document.createElementNS(x,"circle");d.classList.add("tiny-spark-datapoint-circle"),d.classList.add(`circle-${s}`),d.setAttribute("id",`circle_${s}_${O}`),d.setAttribute("cx",String(g||0)),d.setAttribute("cy",String(b||0)),d.setAttribute("r",String(l(t,a.PLOT_RADIUS,3))),d.setAttribute("fill",String(l(t,a.PLOT_COLOR,String(l(t,"lineColor",e))))),d.setAttribute("stroke",h),d.style.opacity=p.length===1?"1":"0",d.style.transition=`opacity ${O*(1e3*2/p.length)}ms ease-in`,d.style.pointerEvents="none",k.push(d),H&&o.appendChild(d)}});let y=null;if(C&&p.length&&p.at(-1)){const g=Number(l(t,a.LAST_VALUE_FONT_SIZE,12));y=document.createElementNS(x,"text"),y.classList.add("tiny-spark-last-value"),y.setAttribute("id",S),y.setAttribute("x",String(p.at(-1).x+6+Number(l(t,a.LINE_THICKNESS,2)))),y.setAttribute("y",String(p.at(-1).y+g/3)),y.setAttribute("text-anchor","start"),y.setAttribute("font-size",String(g)+"px"),y.setAttribute("fill",String(l(t,a.LAST_VALUE_COLOR,String(l(t,a.INDICATOR_COLOR,"#1A1A1A"))))),y.innerHTML=Z(t,Number(p.at(-1).v)),y.style.opacity=p.length===1?"1":"0",o.appendChild(y)}p.forEach((g,b)=>{const f=k[b],O=document.createElementNS(x,"rect");O.classList.add("tiny-spark-tooltip-trap"),O.setAttribute("x",`${p.length===1?0:u.left+b*v-v/2}`),O.setAttribute("y",`${u.top}`),O.setAttribute("height",`${u.height}`),O.setAttribute("width",`${v}`),O.setAttribute("fill","transparent"),O.addEventListener("mouseenter",()=>{if(K(o,t,g,s,!0),H){const d=document.getElementById(`circle_${s}_${b}`);d==null||d.setAttribute("r",String(Number(l(t,a.PLOT_RADIUS,3))*1.5))}else o.appendChild(f);U[b].style.opacity="1",C&&y&&(b===p.length-1?y.style.opacity="0":y.style.opacity="1")}),O.addEventListener("mouseout",()=>{if(K(o,t,g,s,!1),H){const d=document.getElementById(`circle_${s}_${b}`);d==null||d.setAttribute("r",String(Number(l(t,a.PLOT_RADIUS,3))))}else f.remove();U.forEach(d=>d.style.opacity="0"),C&&y&&(y.style.opacity="1")}),o.appendChild(O)}),E==="true"&&n?P().then(()=>{k.forEach(g=>{g.style.opacity="1"}),J(L,1e3,()=>{y&&(y.style.opacity="1")}),Y(o,_)}):(k.forEach(g=>{g.style.opacity="1"}),y&&(y.style.opacity="1")),t.appendChild(o)}function it(){const t=Q();t.length&&Array.from(t).forEach(r=>{if(!r.dataset.id){const o=G();r.setAttribute("data-id",o)}const n=r;st(n),n.__renderCount=0,V(n),P().then(()=>{const o=new ResizeObserver(i=>{i.forEach(()=>V(n))});n.parentElement&&o.observe(n.parentElement),new MutationObserver(i=>{for(const c of i)if(c.type==="attributes"&&c.attributeName&&Object.values(M).includes(c.attributeName)){V(n);break}}).observe(n,{attributes:!0})})})}function V(t){D(t,"set")&&ot(t,t.__renderCount<2),t.__renderCount+=1}function st(t){t.dataset.set||console.error(`Tiny-spark exception:
4
4
 
5
5
  [data-set] data attribute is missing.
6
6
  Provide an array of numbers, for example:
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "tiny-spark",
3
3
  "private": false,
4
- "version": "0.4.1",
4
+ "version": "0.4.2",
5
5
  "type": "module",
6
6
  "description": "An elegant, reactive and responsive sparkline chart solution without dependency.",
7
7
  "author": "Alec Lloyd Probert",