tiny-spark 1.2.1 → 1.2.3

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.
@@ -8,12 +8,12 @@ var e = "http://www.w3.org/2000/svg", t = 1e3, n = /* @__PURE__ */ function(e) {
8
8
  }({}), a = {
9
9
  name: "tiny-spark",
10
10
  private: !1,
11
- version: "1.2.1",
11
+ version: "1.2.3",
12
12
  type: "module",
13
13
  description: "An elegant, reactive and responsive sparkline chart solution without dependency.",
14
14
  author: "Alec Lloyd Probert",
15
- main: "dist/tiny-spark.umd.js",
16
- module: "dist/tiny-spark.es.js",
15
+ main: "./dist/tiny-spark.es.js",
16
+ exports: "./dist/tiny-spark.es.js",
17
17
  keywords: [
18
18
  "sparkline",
19
19
  "chart",
@@ -35,7 +35,7 @@ var e = "http://www.w3.org/2000/svg", t = 1e3, n = /* @__PURE__ */ function(e) {
35
35
  devDependencies: {
36
36
  "@types/node": "^24.0.8",
37
37
  typescript: "~5.8.3",
38
- vite: "^8.0.10"
38
+ vite: "^8.2.1"
39
39
  }
40
40
  };
41
41
  //#endregion
@@ -73,7 +73,11 @@ function l(e) {
73
73
  let t = e.length - 1, n = [`${s(e[0].x)},${s(e[0].y)}`], r = [], i = [], a = [], o = [];
74
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
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]);
76
+ for (let e = 1; e < t; e += 1) if (a[e - 1] * a[e] <= 0) o[e] = 0;
77
+ else {
78
+ let t = 2 * a[e - 1] * a[e] / (a[e - 1] + a[e]);
79
+ o[e] = t;
80
+ }
77
81
  for (let r = 0; r < t; r += 1) {
78
82
  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
83
  n.push(`C ${s(d)},${s(f)} ${s(p)},${s(m)} ${s(a)},${s(c)}`);
@@ -94,7 +98,11 @@ function d(e) {
94
98
  let t = r.length - 1, i = [], a = [], o = [], c = [];
95
99
  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
100
  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]);
101
+ for (let e = 1; e < t; e += 1) if (o[e - 1] * o[e] <= 0) c[e] = 0;
102
+ else {
103
+ let t = 2 * o[e - 1] * o[e] / (o[e - 1] + o[e]);
104
+ c[e] = t;
105
+ }
98
106
  n += `${e === 0 ? "" : "M"}${s(r[0].x)},${s(r[0].y)} `;
99
107
  for (let e = 0; e < t; e += 1) {
100
108
  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;
@@ -162,7 +170,11 @@ function h(e, t, n = !1, r = !0) {
162
170
  let n = e.length - 1, i = [], a = [], o = [], s = [];
163
171
  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
172
  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]);
173
+ for (let e = 1; e < n; e += 1) if (o[e - 1] * o[e] <= 0) s[e] = 0;
174
+ else {
175
+ let t = 2 * o[e - 1] * o[e] / (o[e - 1] + o[e]);
176
+ s[e] = t;
177
+ }
166
178
  let c = `M${e[0].x},${t}`;
167
179
  c += ` L${e[0].x},${e[0].y}`;
168
180
  for (let t = 0; t < n; t += 1) {
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "tiny-spark",
3
3
  "private": false,
4
- "version": "1.2.1",
4
+ "version": "1.2.3",
5
5
  "type": "module",
6
6
  "description": "An elegant, reactive and responsive sparkline chart solution without dependency.",
7
7
  "author": "Alec Lloyd Probert",
8
- "main": "dist/tiny-spark.umd.js",
9
- "module": "dist/tiny-spark.es.js",
8
+ "main": "./dist/tiny-spark.es.js",
9
+ "exports": "./dist/tiny-spark.es.js",
10
10
  "keywords": [
11
11
  "sparkline",
12
12
  "chart",
@@ -30,6 +30,6 @@
30
30
  "devDependencies": {
31
31
  "@types/node": "^24.0.8",
32
32
  "typescript": "~5.8.3",
33
- "vite": "^8.0.10"
33
+ "vite": "^8.2.1"
34
34
  }
35
35
  }
@@ -1,10 +0,0 @@
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
- <div class="tiny-spark-tooltip-content">
3
- ${n.d?`${n.d}: `:``}${[null,void 0].includes(n.v)?`-`:C(t,Number(n.v))}
4
- </div>
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
-
7
- [data-set] data attribute is missing.
8
- Provide an array of numbers, for example:
9
-
10
- data-set="[1, 2, 3]"`)}function M(e){return JSON.stringify(e)}e.render=k,e.tinyFormat=M});