ml-time-graph 1.1.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/USAGE.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  *[← README](README.md) · [Deutsch](README.de.md)*
4
4
 
5
+ **Contents:** [Install](#install) · [Quick start](#quick-start) · [Series](#series) ·
6
+ [Thresholds](#thresholds-incident-analysis) · [Fill regions](#fill-regions-the-structured-way) ·
7
+ [Legend](#legend) · [Axes](#axes) · [Localization](#localization-i18n) · [Gaps](#gaps) ·
8
+ [Statistic overlays](#statistic-overlays) · [Aggregation](#aggregation--helpers) ·
9
+ [Annotations](#annotations-custom-overlays) · [Interaction & tooltips](#interaction--tooltips) ·
10
+ [Server-side](#server-side-rendering-node) · [Package exports](#package-exports) · [Renderer](#renderer)
11
+
5
12
  ## Install
6
13
 
7
14
  ```bash
@@ -359,12 +366,72 @@ chart.renderCommands();
359
366
  const { x, y } = chart.project(time, value, axis); // data → pixel
360
367
  ```
361
368
 
362
- ## Interaction
369
+ ## Interaction & tooltips
370
+
371
+ ### Tooltips — `attachTooltip` (built-in)
372
+
373
+ One line wires a DOM tooltip that snaps to the nearest sample per series, draws a
374
+ "pick" ring on each matched point, and **flips across the cursor to stay inside
375
+ the chart** (right/below in the left/top half, left/above past 50%):
376
+
377
+ ```ts
378
+ import { mount, attachTooltip } from 'ml-time-graph';
379
+
380
+ const chart = mount('#chart', { series });
381
+ const detach = attachTooltip(document.querySelector('#chart')!, chart, {
382
+ format: (samples) =>
383
+ `<div>${new Date(samples[0].time).toLocaleString()}</div>` +
384
+ samples.map((s) => `<div>${s.series.name}: ${s.value}</div>`).join(''),
385
+ });
386
+ // …later:
387
+ detach(); // removes the listeners + pick markers
388
+ ```
389
+
390
+ `attachTooltip(target, chart, options?)` returns a cleanup function. The `target`
391
+ must already contain the rendered `<svg>` (mount / render first). Each hover
392
+ yields one `TooltipSample` per series — `{ seriesIndex, series, time, value, x, y }`.
393
+
394
+ Options: `format` (HTML; default = time header + `name: value` rows),
395
+ `snapRadius` (px, default ∞), `className` (default `mlc-tooltip`), and
396
+ `showPicks` / `pickRadius` / `picksClassName` for the markers. Style the box via
397
+ the `.mlc-tooltip` CSS class — **don't set `transform`**; placement (incl. the
398
+ flip) is computed in JS.
399
+
400
+ ### Zoom / pan
401
+
402
+ Zoom, pan and minimap are **not** baked into the chart. Map pixels back to data
403
+ with `chart.invertTime(px)` / `chart.invertValue(py, axisIndex)` and wire the
404
+ interaction in your app, or pull the optional `Zoom` / `Minimap` helpers from the
405
+ [`ml-time-graph/interaction`](#package-exports) subpath. See the demo gallery's
406
+ "Fridge" (range slider) and "Interaction" pages.
407
+
408
+ ## Server-side rendering (Node)
409
+
410
+ `SVGRenderer` needs no DOM, so the same code runs in Node — set explicit
411
+ `width`/`height` (there's no element to measure) and write the string out:
412
+
413
+ ```ts
414
+ import { MLTimeGraph, SVGRenderer } from 'ml-time-graph';
415
+ import { writeFileSync } from 'node:fs';
416
+
417
+ const chart = new MLTimeGraph({ width: 800, height: 400, series });
418
+ const { content } = new SVGRenderer().render(chart.renderCommands());
419
+ writeFileSync('chart.svg', content);
420
+ ```
421
+
422
+ Useful for report generation, PDF embedding (via a headless browser), and email
423
+ attachments. For a Node-free backend, the Go port
424
+ [`go-time-graph`](https://gitlab.com/mlc0911/mlctimegraph/-/tree/main/go-time-graph)
425
+ renders the same JSON config to identical SVG.
426
+
427
+ ## Package exports
363
428
 
364
- Zoom/pan and tooltips are intentionally **not** baked into the chart. Map pixels to
365
- data with `chart.invertTime(px)` / `chart.invertValue(py, axisIndex)` and build the
366
- interaction in your appsee the demo gallery's "Fridge" (range slider) and
367
- "Interaction" (tooltip) pages.
429
+ | Import | Contents |
430
+ | :--- | :--- |
431
+ | `ml-time-graph` | The rendering API `mount`, `MLTimeGraph`, `SVGRenderer`, `attachTooltip`, and all option/data types. |
432
+ | `ml-time-graph/analyze` | Statistics companion — `aggregateBySlot`, `downsample`, `detectGaps`, `mkt` / `rollingMkt`, `stdDev`, `StatsAggregator`, … (see [Aggregation](#aggregation--helpers)). |
433
+ | `ml-time-graph/interaction` | Optional interaction primitives — `Zoom`, `Minimap`, `Tooltip` (lower-level than `attachTooltip`). |
434
+ | `ml-time-graph/internals` | Building blocks for **custom renderers** — the abstract `Renderer`, free render-functions, scales, axis classes, the `DrawCommand` model. |
368
435
 
369
436
  ## Renderer
370
437
 
package/dist/index.d.ts CHANGED
@@ -294,7 +294,8 @@ interface TooltipOptions {
294
294
  * Returns a cleanup function that removes the listeners and the tooltip
295
295
  * element. Idempotent — calling cleanup twice is a no-op.
296
296
  *
297
- * Style the tooltip via CSS:
297
+ * Style the tooltip via CSS. Do NOT set `transform` — placement (incl. the
298
+ * flip that keeps the box inside the chart) is computed in JS via `transform`:
298
299
  *
299
300
  * ```css
300
301
  * .mlc-tooltip {
@@ -306,7 +307,6 @@ interface TooltipOptions {
306
307
  * border: 1px solid rgba(217, 119, 6, 0.35);
307
308
  * border-radius: 4px;
308
309
  * font-size: 12px;
309
- * transform: translate(8px, 8px);
310
310
  * box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
311
311
  * }
312
312
  * .mlc-tooltip__time { opacity: 0.7; margin-bottom: 4px; font-weight: 600; }
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- var nt=class r{_config;constructor(t){this._config=t;}compute(){let{width:t,height:e,margin:n}=this._config;return {totalWidth:t,totalHeight:e,chartWidth:t-n.left-n.right,chartHeight:e-n.top-n.bottom,chartX:n.left,chartY:n.top,margin:n}}static default(t=800,e=400){return new r({width:t,height:e,margin:{top:20,right:20,bottom:40,left:60}})}};function it(r){return r&&r.toString().normalize("NFKD").replace(/[̀-ͯ]/g,"").toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,50)||"unnamed"}var U=class{#t;#e;constructor(t){this.#t=[...t.domain],this.#e=[...t.range];}map(t){let e=Number(t),[n,s]=this.#t,[i,o]=this.#e;return s===n?i:i+(e-n)/(s-n)*(o-i)}invert(t){let[e,n]=this.#t,[s,i]=this.#e;return i===s?e:e+(t-s)/(i-s)*(n-e)}domain(){return [...this.#t]}range(){return [...this.#e]}},G=[{label:"second",ms:1e3},{label:"2_seconds",ms:2e3},{label:"5_seconds",ms:5e3},{label:"10_seconds",ms:1e4},{label:"30_seconds",ms:3e4},{label:"minute",ms:6e4},{label:"5_minutes",ms:3e5},{label:"15_minutes",ms:9e5},{label:"30_minutes",ms:18e5},{label:"hour",ms:36e5},{label:"3_hours",ms:108e5},{label:"6_hours",ms:216e5},{label:"day",ms:864e5},{label:"week",ms:6048e5},{label:"month",ms:2592e6},{label:"3_months",ms:7776e6},{label:"6_months",ms:15552e6},{label:"year",ms:31536e6},{label:"2_years",ms:63072e6},{label:"5_years",ms:15768e7}],J=class{#t;#e;constructor(t){this.#t=new U({domain:t.domain,range:t.range}),this.#e=t.locale||(typeof navigator<"u"?navigator.language:"en-US");}map(t){return this.#t.map(Number(t))}invert(t){return this.#t.invert(t)}domain(){return this.#t.domain()}range(){return this.#t.range()}get locale(){return this.#e}tickInterval(t,e=3,n=12){let[s,i]=this.#t.domain(),o=i-s;if(o<=0)return {interval:G[0].ms};let a=o/t,l=G[0].ms;for(let u of G)if(u.ms>=a){l=u.ms;break}let h=l,d=Math.round(o/h);for(;d>n&&h<G[G.length-1].ms;){let u=G.findIndex(m=>m.ms===h);h=G[Math.min(u+1,G.length-1)].ms,d=Math.round(o/h);}for(;d<e&&h>G[0].ms;){let u=G.findIndex(m=>m.ms===h);h=G[Math.max(u-1,0)].ms,d=Math.round(o/h);}return {interval:h}}ticks(t){let e=t?.minTicks??5,n=t?.maxTicks??12,{interval:s}=this.tickInterval((e+n)/2,e,n),[i,o]=this.#t.domain(),a=[],l=Math.ceil(i/s)*s;for(let h=l;h<=o;h+=s)a.push(h);return a}format(t,e){return new Intl.DateTimeFormat(this.#e,e).format(new Date(t))}};var c={stroke:"#4285f4",strokeWidth:2,pointSize:4,pointThreshold:100,gapThreshold:0,fill:"none",hatch:null,bandFill:"#4285f4",bandOpacity:.6,bandAvgLine:"#e53e3e",minColor:"#3b82f6",maxColor:"#ef4444",avgColor:"#64748b",areaFillAlpha:"4285f433",axisColor:"#ccc",tickColor:"#ddd",textColor:"#777",textSize:11,axisLabelColor:"#444",axisLabelSize:12,gridStroke:"#e2e8f0",gridStrokeWidth:1,gridOpacity:1,legendStroke:"#ccc",legendText:"#333",legendFont:11,annotationColor:"#334155",annotationWidth:1.5,annotationHead:9,annotationRadius:4,annotationFontSize:11,thresholdColor:"#666",thresholdLine:"dashed",thresholdFillOpacity:.12,thresholdFontSize:10,highlightColor:"#fbbf24",highlightOpacity:.2,highlightLabelColor:"#92400e",markerColor:"#f59e0b",markerSize:5,gapFill:"#fff",gapStroke:"#ccc",gapStrokeWidth:1,gapFontColor:"#999",gapFontSize:10,gapFillOpacity:.15,tooltipBg:"#fff",tooltipBorder:"#cbd5e1",tooltipText:"#1e293b",tooltipValue:"#3b82f6",tooltipCrosshair:"#94a3b8",tooltipSnapRadius:20,statsLineColor:"#94a3b8",statsLabelColor:"#64748b",minimapStroke:"#94a3b8",minimapBg:"#f8f9fa",minimapBrush:"#3b82f644",palette:["#4285f4","#ea4335","#22c55e","#fbbc05","#9334ea","#12b5e5","#fb923c","#6366f1"]};function St(r,t="classic-diagonal",e="rgba(200, 220, 255, 0.3)",n="#4D88FF",s=2){if(t==="none")return `
1
+ var nt=class r{_config;constructor(t){this._config=t;}compute(){let{width:t,height:e,margin:n}=this._config;return {totalWidth:t,totalHeight:e,chartWidth:t-n.left-n.right,chartHeight:e-n.top-n.bottom,chartX:n.left,chartY:n.top,margin:n}}static default(t=800,e=400){return new r({width:t,height:e,margin:{top:20,right:20,bottom:40,left:60}})}};function it(r){return r&&r.toString().normalize("NFKD").replace(/[̀-ͯ]/g,"").toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,50)||"unnamed"}var U=class{#t;#e;constructor(t){this.#t=[...t.domain],this.#e=[...t.range];}map(t){let e=Number(t),[n,s]=this.#t,[i,o]=this.#e;return s===n?i:i+(e-n)/(s-n)*(o-i)}invert(t){let[e,n]=this.#t,[s,i]=this.#e;return i===s?e:e+(t-s)/(i-s)*(n-e)}domain(){return [...this.#t]}range(){return [...this.#e]}},V=[{label:"second",ms:1e3},{label:"2_seconds",ms:2e3},{label:"5_seconds",ms:5e3},{label:"10_seconds",ms:1e4},{label:"30_seconds",ms:3e4},{label:"minute",ms:6e4},{label:"5_minutes",ms:3e5},{label:"15_minutes",ms:9e5},{label:"30_minutes",ms:18e5},{label:"hour",ms:36e5},{label:"3_hours",ms:108e5},{label:"6_hours",ms:216e5},{label:"day",ms:864e5},{label:"week",ms:6048e5},{label:"month",ms:2592e6},{label:"3_months",ms:7776e6},{label:"6_months",ms:15552e6},{label:"year",ms:31536e6},{label:"2_years",ms:63072e6},{label:"5_years",ms:15768e7}],J=class{#t;#e;constructor(t){this.#t=new U({domain:t.domain,range:t.range}),this.#e=t.locale||(typeof navigator<"u"?navigator.language:"en-US");}map(t){return this.#t.map(Number(t))}invert(t){return this.#t.invert(t)}domain(){return this.#t.domain()}range(){return this.#t.range()}get locale(){return this.#e}tickInterval(t,e=3,n=12){let[s,i]=this.#t.domain(),o=i-s;if(o<=0)return {interval:V[0].ms};let a=o/t,l=V[0].ms;for(let m of V)if(m.ms>=a){l=m.ms;break}let h=l,d=Math.round(o/h);for(;d>n&&h<V[V.length-1].ms;){let m=V.findIndex(u=>u.ms===h);h=V[Math.min(m+1,V.length-1)].ms,d=Math.round(o/h);}for(;d<e&&h>V[0].ms;){let m=V.findIndex(u=>u.ms===h);h=V[Math.max(m-1,0)].ms,d=Math.round(o/h);}return {interval:h}}ticks(t){let e=t?.minTicks??5,n=t?.maxTicks??12,{interval:s}=this.tickInterval((e+n)/2,e,n),[i,o]=this.#t.domain(),a=[],l=Math.ceil(i/s)*s;for(let h=l;h<=o;h+=s)a.push(h);return a}format(t,e){return new Intl.DateTimeFormat(this.#e,e).format(new Date(t))}};var c={stroke:"#4285f4",strokeWidth:2,pointSize:4,pointThreshold:100,gapThreshold:0,fill:"none",hatch:null,bandFill:"#4285f4",bandOpacity:.6,bandAvgLine:"#e53e3e",minColor:"#3b82f6",maxColor:"#ef4444",avgColor:"#64748b",areaFillAlpha:"4285f433",axisColor:"#ccc",tickColor:"#ddd",textColor:"#777",textSize:11,axisLabelColor:"#444",axisLabelSize:12,gridStroke:"#e2e8f0",gridStrokeWidth:1,gridOpacity:1,legendStroke:"#ccc",legendText:"#333",legendFont:11,annotationColor:"#334155",annotationWidth:1.5,annotationHead:9,annotationRadius:4,annotationFontSize:11,thresholdColor:"#666",thresholdLine:"dashed",thresholdFillOpacity:.12,thresholdFontSize:10,highlightColor:"#fbbf24",highlightOpacity:.2,highlightLabelColor:"#92400e",markerColor:"#f59e0b",markerSize:5,gapFill:"#fff",gapStroke:"#ccc",gapStrokeWidth:1,gapFontColor:"#999",gapFontSize:10,gapFillOpacity:.15,tooltipBg:"#fff",tooltipBorder:"#cbd5e1",tooltipText:"#1e293b",tooltipValue:"#3b82f6",tooltipCrosshair:"#94a3b8",tooltipSnapRadius:20,statsLineColor:"#94a3b8",statsLabelColor:"#64748b",minimapStroke:"#94a3b8",minimapBg:"#f8f9fa",minimapBrush:"#3b82f644",palette:["#4285f4","#ea4335","#22c55e","#fbbc05","#9334ea","#12b5e5","#fb923c","#6366f1"]};function St(r,t="classic-diagonal",e="rgba(200, 220, 255, 0.3)",n="#4D88FF",s=2){if(t==="none")return `
2
2
  <pattern id="${r}" width="10" height="10" patternUnits="userSpaceOnUse">
3
3
  <rect width="10" height="10" fill="${e}" />
4
4
  </pattern>
@@ -25,14 +25,14 @@ var nt=class r{_config;constructor(t){this._config=t;}compute(){let{width:t,heig
25
25
  ${h}
26
26
  ${l}
27
27
  </pattern>
28
- `.trim()}function Rt(r,t=2){let e=t;switch(r){case "dotted":return {strokeDasharray:`0, ${e*2}`,strokeLinecap:"round"};case "sparse-dots":return {strokeDasharray:`0, ${e*4}`,strokeLinecap:"round"};case "dashed":return {strokeDasharray:`${e*3}, ${e*2}`,strokeLinecap:"butt"};case "long-dash":return {strokeDasharray:`${e*6}, ${e*3}`,strokeLinecap:"butt"};case "dense-dash":return {strokeDasharray:`${e*1.5}, ${e*1.5}`,strokeLinecap:"butt"};case "dash-dot":return {strokeDasharray:`${e*4}, ${e*2}, 0, ${e*2}`,strokeLinecap:"round"};case "dash-dot-dot":return {strokeDasharray:`${e*5}, ${e*2}, 0, ${e*2}, 0, ${e*2}`,strokeLinecap:"round"};case "loose-dash":return {strokeDasharray:`${e*3}, ${e*4}`,strokeLinecap:"butt"};default:return {strokeDasharray:"none",strokeLinecap:"butt"}}}var rt={axisColor:c.axisColor,tickColor:c.tickColor,textColor:c.textColor,textSize:c.textSize},tt=class{#t;#e;constructor(t){this.#t=new J({domain:t.domain,range:t.xRange,locale:t.locale}),this.#e=t;}get scale(){return this.#t}get axisColor(){return (this.#e.colors??rt).axisColor}get tickColor(){return (this.#e.colors??rt).tickColor}get textColor(){return (this.#e.colors??rt).textColor}get textSize(){return (this.#e.colors??rt).textSize}generateTicks(){let t=this.#e.minTicks??5,e=this.#e.maxTicks??12,s=this.#t.ticks({minTicks:t,maxTicks:e}).map(i=>({time:i,x:this.#t.map(i),label:this.tickLabel(i)}));return this.antiOverlap(s)}tickLabel(t){if(this.#e.format)return this.#e.format(new Date(t));let e=this.#e.minTicks??5,n=this.#e.maxTicks??12,{interval:s}=this.#t.tickInterval((e+n)/2,e,n),i={};return s<6e4?(i.hour="2-digit",i.minute="2-digit",i.second="2-digit"):s<36e5||s<864e5?(i.hour="2-digit",i.minute="2-digit"):s<31536e6?(i.day="numeric",i.month="short",s>=2592e6&&(i.day=void 0,i.month="long")):(i.year="numeric",s<2*31536e6&&(i.month="short")),this.#t.format(t,i)}antiOverlap(t){if(t.length<=1)return t;let e=60,n=[t[0]];for(let s=1;s<t.length;s++){let i=n[n.length-1].x;Math.abs(t[s].x-i)>=e&&n.push(t[s]);}return n}render(){let t=this.generateTicks(),e=this.#e.colors??rt,n=this.#e.y??0,s=[],[i]=this.#t.range();s.push({type:"line",x1:i,y1:n,x2:t[t.length-1]?.x??i,y2:n,stroke:e.axisColor,strokeWidth:e.axisWidth});for(let o of t)s.push({type:"line",x1:o.x,y1:n,x2:o.x,y2:n+6,stroke:e.tickColor,strokeWidth:e.axisWidth}),s.push({type:"text",content:o.label,x:o.x,y:n+e.textSize+6,anchor:"middle",fontSize:e.textSize,fill:e.textColor});return s}};var st={axisColor:"#ccc",tickColor:"#ddd",textColor:"#777",textSize:12};function ae(r){return Math.abs(r)>=1e6?`${(r/1e6).toFixed(1)}M`:Math.abs(r)>=1e3?`${(r/1e3).toFixed(1)}k`:Number.isInteger(r)?String(r):r.toFixed(1)}function le(r){let t=new Array(r.length).fill(false),e=0;for(;e<r.length;){let n=e;for(;n+1<r.length&&r[n+1].label===r[e].label;)n++;for(let s=e+1;s<n;s++)t[s]=true;e=n+1;}return t}var lt=class{#t;#e;constructor(t){this.#t=new U({domain:t.domain,range:t.range}),this.#e=t;}get scale(){return this.#t}get axisColor(){return (this.#e.colors??st).axisColor}get tickColor(){return (this.#e.colors??st).tickColor}get textColor(){return (this.#e.colors??st).textColor}get textSize(){return (this.#e.colors??st).textSize}generateTicks(){let t=this.#e.format??ae,e=6,[n,s]=this.#t.domain(),i=s-n;if(i===0)return [{value:n,position:this.#t.map(n),label:t(n)}];let o=i/e,a=Math.pow(10,Math.floor(Math.log10(o))),l=o/a,h;l<=1.5?h=a:l<=3?h=2*a:l<=7?h=5*a:h=10*a;let d=[],u=Math.ceil(n/h)*h;for(let m=u;m<=s;m+=h)d.push({value:m,position:this.#t.map(m),label:t(m)});return d}render(){let t=this.generateTicks(),e=this.#e.colors??st,n=this.#e.x??0,s=this.#e.orientation??"vertical",i=this.#e.position??"left",o=this.#e.suppressLabelsNear??[],a=this.#e.suppressTolerancePx??8,l=d=>o.some(u=>Math.abs(u-d)<=a),h=[];if(s==="vertical"){let[d,u]=this.#t.range();h.push({type:"line",x1:n,y1:d,x2:n,y2:u,stroke:e.axisColor,strokeWidth:e.axisWidth});let m=le(t);t.forEach((f,p)=>{let b=l(f.position),x=m[p]?{opacity:0}:{};i==="left"?(h.push({type:"line",x1:n-4,y1:f.position,x2:n,y2:f.position,stroke:e.tickColor,strokeWidth:e.axisWidth}),b||h.push({type:"text",content:f.label,x:n-8,y:f.position+4,anchor:"end",fontSize:11,fill:e.textColor,...x})):(h.push({type:"line",x1:n,y1:f.position,x2:n+4,y2:f.position,stroke:e.tickColor,strokeWidth:e.axisWidth}),b||h.push({type:"text",content:f.label,x:n+8,y:f.position+4,anchor:"start",fontSize:11,fill:e.textColor,...x}));});}else {let[d,u]=this.#t.range();h.push({type:"line",x1:d,y1:n,x2:u,y2:n,stroke:e.axisColor,strokeWidth:e.axisWidth});for(let m of t)h.push({type:"line",x1:m.position,y1:n,x2:m.position,y2:n+6,stroke:e.tickColor,strokeWidth:e.axisWidth}),h.push({type:"text",content:m.label,x:m.position,y:n+18,anchor:"middle",fontSize:e.textSize,fill:e.textColor});}return h}};var F=class{static interpolateDataPoint(r,t,e){return {time:r.time+e*(t.time-r.time),value:(r.value??0)+e*((t.value??0)-(r.value??0))}}static interpolateAggregatedPoint(r,t,e){let n=(s,i)=>s!==null&&i!==null?s+e*(i-s):null;return {time:r.time+e*(t.time-r.time),min:n(r.min,t.min),max:n(r.max,t.max),avg:n(r.avg,t.avg),count:Math.round(r.count+e*(t.count-r.count))}}static getRuns(r,t,e=0){let n=[...r].sort((a,l)=>a.time-l.time),s=[],i=[],o=null;for(let a of n){let l=t(a),h=e>0&&o&&a.time-o.time>e;(l||h)&&i.length&&(s.push(i),i=[]),l||i.push(a),o=a;}return i.length&&s.push(i),s}static splitByBoundaries(r,t,e,n){if(r.length===0)return [];if(t.length===0)return [{data:r,zoneIndex:0}];let s=[...t].sort((l,h)=>l-h),i=[],o=l=>{let h=0;for(let d=0;d<s.length&&l>=s[d];d++)h=d+1;return h},a=[r[0]];for(let l=1;l<r.length;l++){let h=r[l-1],d=r[l],u=e(h),m=e(d),f;m>u?f=s.filter(p=>p>u&&p<=m):m<u?f=s.filter(p=>p>=m&&p<u).reverse():f=[];for(let p of f){let b=(p-u)/(m-u),x=n(h,d,b);a.push(x),i.push({data:a,zoneIndex:o((u+p)/2)}),a=[x];}a.push(d);}if(a.length>0){let l=e(a[0]),h=e(a[a.length-1]);i.push({data:a,zoneIndex:o((l+h)/2)});}return i}static splitByThreshold(r,t,e,n){let s=this.splitByBoundaries(r,[t],e,n),i={above:[],below:[]};for(let o of s)o.zoneIndex===0?i.below.push(o.data):i.above.push(o.data);return i}};function Ot(r,t=6e4){if(r.length<2)return [];let e=[...r].sort((s,i)=>s.time-i.time),n=[];for(let s=1;s<e.length;s++)e[s].time-e[s-1].time>t&&n.push({startTime:e[s-1].time,endTime:e[s].time});return n}function he(r,t=83144){let e=t/8.314,n=0,s=0;for(let o of r)o!==null&&(n+=Math.exp(-e/(o+273.15)),s++);if(s===0)return null;let i=n/s;return e/-Math.log(i)-273.15}function jt(r,t,e=83144){let n=new Array(r.length),s=0;for(let i=0;i<r.length;i++){let o=r[i].time,a=o-t;for(;s<i&&r[s].time<a;)s++;let l=r.slice(s,i+1).map(d=>d.value),h=he(l,e);n[i]={time:o,value:h,synthetic:true};}return n}function de(r){let t=0,e=0;for(let i of r)i!==null&&(t+=i,e++);if(e===0)return null;let n=t/e,s=0;for(let i of r){if(i===null)continue;let o=i-n;s+=o*o;}return Math.sqrt(s/e)}function me(r){let t=0,e=0;for(let i of r)i!==null&&(t+=i,e++);if(e<2)return null;let n=t/e,s=0;for(let i of r){if(i===null)continue;let o=i-n;s+=o*o;}return Math.sqrt(s/(e-1))}function It(r,t,e=false){let n=new Array(r.length),s=0,i=e?me:de;for(let o=0;o<r.length;o++){let a=r[o].time,l=a-t;for(;s<o&&r[s].time<l;)s++;let h=r.slice(s,o+1).map(u=>u.value),d=i(h);n[o]={time:a,value:d,synthetic:true};}return n}function Gt(r){return {id:r.id,line:{stroke:r.stroke??c.stroke,strokeWidth:r.strokeWidth??c.strokeWidth,smoothing:r.smoothing??false,dashed:r.dashed??false},fill:r.fill??c.areaFillAlpha,markers:{type:r.pointStyle??"none",size:r.pointSize??c.pointSize,stroke:r.stroke??c.stroke,fill:"#ffffff"},shadow:{color:r.shadowColor??"transparent",blur:r.shadowBlur??0,offsetX:r.shadowOffsetX??0,offsetY:r.shadowOffsetY??0}}}function ht(r,t,e){let n=[],s=r.reduce((o,a)=>o+a.data.length,0),i=Gt(e);for(let o=0;o<r.length;o++){let a=r[o];a.data.length>=2?n.push({type:"path",id:e.id?`${e.id}-line-${o}`:void 0,points:a.data.map(l=>({x:t.timeScale.map(l.time),y:t.valueScale.map(l.value)})),stroke:a.color??i.line.stroke,strokeWidth:i.line.strokeWidth,smoothing:i.line.smoothing,dashed:i.line.dashed,shadowColor:i.shadow.color,shadowBlur:i.shadow.blur,shadowOffsetX:i.shadow.offsetX,shadowOffsetY:i.shadow.offsetY,fill:"none"}):a.data.length===1&&s===1&&n.push({type:"circle",cx:t.timeScale.map(a.data[0].time),cy:t.valueScale.map(a.data[0].value),r:Math.max(i.markers.size,i.line.strokeWidth),fill:a.color??i.line.stroke,shadowColor:i.shadow.color,shadowBlur:i.shadow.blur});}return n}function wt(r,t,e,n){if(r.length<2)return [];let s=F.splitByBoundaries(r,e.boundaries,e.getValue,e.interpolate),i=[];for(let o=0;o<s.length;o++){let a=s[o];if(a.data.length<2)continue;let l=e.getColor(a.zoneIndex);if(!l)continue;let h=a.data.map(u=>({x:t.timeScale.map(u.time),y:t.valueScale.map(e.yLow(u))})),d=a.data.map(u=>({x:t.timeScale.map(u.time),y:t.valueScale.map(e.yHigh(u))})).reverse();i.push({type:"path",id:n?.id?`${n.id}-fill-${o}`:void 0,points:[...h,...d],fill:l,hatch:e.getHatch?.(a.zoneIndex),stroke:"none"});}return i}function Et(r,t,e,n){let s=Gt(e);if(!s.markers.type||s.markers.type==="none")return [];let i=[];for(let o=0;o<r.length;o++){let a=r[o],l=t.timeScale.map(a.time),h=t.valueScale.map(a.value),d=n(a),u=e.pointStroke??d,m=e.pointFill??d,f=e.pointStrokeWidth??1.5,p=e.id?`${e.id}-marker-${o}`:void 0;ue(i,p,s.markers.type,l,h,s.markers.size,u,m,f);}return i}function ue(r,t,e,n,s,i,o,a,l){switch(e){case "circle":r.push({type:"circle",cx:n,cy:s,r:i,fill:a,stroke:o,strokeWidth:l,id:t});break;case "square":r.push({type:"rect",x:n-i,y:s-i,w:i*2,h:i*2,fill:a,stroke:o,strokeWidth:l,id:t});break;case "cross":r.push({type:"line",x1:n-i,y1:s-i,x2:n+i,y2:s+i,stroke:o,strokeWidth:l,id:t}),r.push({type:"line",x1:n-i,y1:s+i,x2:n+i,y2:s-i,stroke:o,strokeWidth:l,id:t});break;case "diamond":r.push({type:"path",points:[{x:n,y:s-i},{x:n+i,y:s},{x:n,y:s+i},{x:n-i,y:s}],fill:a,stroke:o,strokeWidth:l,id:t});break;case "triangle":r.push({type:"path",points:[{x:n,y:s-i},{x:n+i,y:s+i},{x:n-i,y:s+i}],fill:a,stroke:o,strokeWidth:l,id:t});break;case "star":{let h=[];for(let d=0;d<10;d++){let u=d%2===0?i:i*.5,m=Math.PI/2*3+d*Math.PI/5;h.push({x:n+u*Math.cos(m),y:s+u*Math.sin(m)});}r.push({type:"path",points:h,fill:a,stroke:o,strokeWidth:l,id:t});break}case "arrow":r.push({type:"path",points:[{x:n-i,y:s+i},{x:n,y:s-i},{x:n+i,y:s+i}],stroke:o,strokeWidth:l,fill:"none",id:t});break;default:r.push({type:"circle",cx:n,cy:s,r:i,fill:a,stroke:o,strokeWidth:l,id:t});}}var et=class r{#t;#e;static uidcnt=0;#n;constructor(t,e=[]){this.#t=t.id??"id"+Date.now+ ++r.uidcnt,this.#e=t.timeScale,this.#n=e;}get id(){return this.#t}get timeScale(){return this.#e}get data(){return this.#n}};var dt=class extends et{#t;constructor(t){super(t,t.data),this.#t=t;}render(){let t=this.#t,e=t.minColor??c.minColor,n=t.maxColor??c.maxColor,s=t.avgColor??c.avgColor,i=t.avgDashed??true,o=t.smoothing??false,a=t.strokeWidth??c.strokeWidth,l=F.getRuns(this.data,u=>u.min===null||u.max===null||u.avg===null);if(l.length===0)return [];let h={timeScale:this.timeScale,valueScale:t.valueScale},d=[];for(let u of l)u.length<2||(t.fillToMax&&d.push(...wt(u,h,{boundaries:[],yLow:m=>m.avg,yHigh:m=>m.max,getValue:m=>m.avg,interpolate:F.interpolateAggregatedPoint,getColor:()=>t.fillToMax,getHatch:()=>t.fillToMaxHatch},{id:this.id?`${this.id}-fillToMax`:void 0})),t.fillToMin&&d.push(...wt(u,h,{boundaries:[],yLow:m=>m.avg,yHigh:m=>m.min,getValue:m=>m.avg,interpolate:F.interpolateAggregatedPoint,getColor:()=>t.fillToMin,getHatch:()=>t.fillToMinHatch},{id:this.id?`${this.id}-fillToMin`:void 0})),d.push(...ht([{data:u.map(m=>({time:m.time,value:m.max}))}],h,{stroke:n,strokeWidth:a,smoothing:o,id:this.id?`${this.id}-max`:void 0}),...ht([{data:u.map(m=>({time:m.time,value:m.min}))}],h,{stroke:e,strokeWidth:a,smoothing:o,id:this.id?`${this.id}-min`:void 0}),...ht([{data:u.map(m=>({time:m.time,value:m.avg}))}],h,{stroke:s,strokeWidth:a,smoothing:o,dashed:i,id:this.id?`${this.id}-avg`:void 0})));return d}};var mt=class extends et{#t;constructor(t){super(t,t.data),this.#t=t;}opacity(t){if(!(this.#t.countOpacity??false))return .6;let e=Math.max(...this.data.map(n=>n.count));return e===0?.2:.2+.8*t/e}render(){let t=this.#t,e=t.fill??c.bandFill,n=t.hatch,s=t.avgLine??false,i=t.avgLineColor??c.bandAvgLine,o=t.bandWidth??10,a=[];for(let l of this.data){if(l.min===null||l.max===null)continue;let h=this.timeScale.map(l.time),d=t.valueScale.map(l.max),u=t.valueScale.map(l.min),m=o,f=this.data.indexOf(l);if(a.push({type:"rect",x:h-m/2,y:d,w:m,h:u-d,fill:e,hatch:n,opacity:this.opacity(l.count),id:this.id?`${this.id}-slot-${f}`:void 0}),s&&l.avg!==null){let p=t.valueScale.map(l.avg);a.push({type:"line",x1:h-m/2,y1:p,x2:h+m/2,y2:p,stroke:i,strokeWidth:1,id:this.id?`${this.id}-avg-${f}`:void 0});}}return a}};function ce(r){return r==="dotted"?{dash:"dotted"}:r==="dashed"?{dash:"dashed"}:{}}function Vt(r){let{thresholds:t,valueScale:e,xRange:n}=r,[s,i]=n,[o,a]=e.range(),l=Math.min(o,a),h=Math.max(o,a),d=[],u=[];for(let m of t){let f=m.color??c.thresholdColor,p=e.map(m.value);m.fill==="above"?d.push({type:"rect",x:s,y:l,w:i-s,h:Math.max(0,p-l),fill:f,hatch:m.fillHatch,opacity:m.fillOpacity??.12,id:m.id?`${m.id}-fill`:void 0}):m.fill==="below"&&d.push({type:"rect",x:s,y:p,w:i-s,h:Math.max(0,h-p),fill:f,hatch:m.fillHatch,opacity:m.fillOpacity??.12,id:m.id?`${m.id}-fill`:void 0});let b=m.line??c.thresholdLine;if(b!=="none"){let x=ce(b),w={type:"line",x1:s,y1:p,x2:i,y2:p,stroke:f,strokeWidth:1,...x,id:m.id?`${m.id}-line`:void 0};m.shadowColor&&(w.shadowColor=m.shadowColor,w.shadowBlur=m.shadowBlur??4,w.shadowOffsetX=m.shadowOffsetX??0,w.shadowOffsetY=m.shadowOffsetY??2),d.push(w);}if(m.label!==false){let x=m.label&&typeof m.label=="object"?m.label:void 0,w=typeof m.label=="string"?m.label:x?.text??m.name,k=x?.position??"right";u.push({...pe(w,k,s,i,p,f,x),id:m.id?`${m.id}-label`:void 0});}}return {inside:d,labels:u}}function pe(r,t,e,n,s,i,o){let a=(e+n)/2,l={type:"text",content:r,fontSize:c.thresholdFontSize,fill:i},h=o?{...o.rotate!==void 0&&{rotate:o.rotate},...o.textBaseline!==void 0&&{textBaseline:o.textBaseline}}:{};switch(t){case "left":return {...l,...h,x:e+4,y:s-4,anchor:"start"};case "above":return {...l,...h,x:a,y:s-6,anchor:"middle"};case "below":return {...l,...h,x:a,y:s+14,anchor:"middle"};case "center":return {...l,...h,x:a,y:s-4,anchor:"middle"};case "outside-left":return {...l,...h,x:e-6,y:s+3,anchor:"end",textBaseline:h.textBaseline??"middle"};case "outside-right":return {...l,...h,x:n+6,y:s+3,anchor:"start",textBaseline:h.textBaseline??"middle"};default:return {...l,...h,x:n-4,y:s-4,anchor:"end"}}}function zt(r){let{gaps:t,timeScale:e,yRange:n,fill:s=c.gapFill,hatch:i,fillOpacity:o=c.gapFillOpacity,stroke:a=c.gapStroke,strokeWidth:l=c.gapStrokeWidth,dashed:h=true,fontSize:d=c.gapFontSize,fontFill:u=c.gapFontColor,labelBaseline:m="middle",labelRotate:f}=r,[p,b]=n,x=[];for(let w of t){let k=e.map(w.startTime),O=e.map(w.endTime),L=w.fill??s,R=w.hatch??i,W=w.fillOpacity??o,H=w.label??"",j=w.rotate??f,$=w.labelBaseline??m;if(w.style==="dashed_border"||!w.style?x.push({type:"rect",x:k,y:p,w:O-k,h:b-p,fill:L,hatch:R,opacity:W,stroke:a,strokeWidth:l,dashed:h}):w.style==="empty"&&x.push({type:"rect",x:k,y:p,w:O-k,h:b-p,fill:L,hatch:R,opacity:W}),H){let y=fe(p,b,$),v=$==="above"?"top":$==="below"?"bottom":"middle";x.push({type:"text",content:H,x:(k+O)/2,y,anchor:"middle",fontSize:d,fill:u,textBaseline:v,rotate:j});}}return x}function fe(r,t,e){switch(e){case "above":return r-12;case "below":return t+4;default:return (r+t)/2}}var ut=class{#t;constructor(t,e,n,s){this.#t={...t,xRange:e,y:n,height:s};}render(){let{items:t,timeScale:e,background:n,hatch:s,showAxis:i,xRange:o,y:a,height:l}=this.#t,h=[];n&&h.push({type:"rect",x:o[0],y:a,w:o[1]-o[0],h:l,fill:n,opacity:.04,stroke:"#ddd",strokeWidth:.25});for(let d of t){let u=e.map(d.startTime),m=e.map(d.endTime);if(!(m-u<1)&&(h.push({type:"rect",x:u,y:a,w:m-u,h:l,hatch:d.hatch??s,fill:d.fill??"#6b728044",stroke:d.stroke,strokeWidth:d.strokeWidth??0}),d.label)){let f=d.labelFontSize??10;h.push({type:"text",content:d.label,x:(u+m)/2,y:this.#e(d.labelBaseline,f),anchor:"middle",fontSize:f,fill:d.labelFill??"#333"});}}if(i){let d=new tt({domain:e.domain(),xRange:o,y:a+l+4});h.push({type:"group",cssClass:"annotation-band-axis",commands:d.render()});}return h}#e(t,e){let{y:n,height:s}=this.#t;switch(t){case "top":return n+e*.9;case "bottom":return n+s-e*.25;default:return n+s/2+e*.35}}};function Nt(r){let{highlights:t,timeScale:e,yRange:n,height:s}=r,[i,o]=n,a=[];for(let l of t){let h=e.map(l.startTime),d=e.map(l.endTime);a.push({type:"rect",x:h,y:i,w:d-h,h:o-i,fill:l.color??c.highlightColor,opacity:l.opacity??c.highlightOpacity}),l.label&&a.push({type:"text",content:l.label,x:(h+d)/2,y:ge(l.labelPosition??"top",i,o,s),anchor:"middle",fontSize:c.annotationFontSize,fill:l.color??c.highlightLabelColor,rotate:l.rotate});}return a}function ge(r,t,e,n){switch(r){case "above":return t-5;case "below":return n!==void 0?n-5:e+14;case "center":return (t+e)/2+4;case "bottom":return e-6;default:return t+14}}function Yt(r){let{markers:t,timeScale:e,valueScale:n,yRange:s=[0,300]}=r,[i,o]=s,a=[];for(let l of t){let h=e.map(l.time),d=l.color??c.markerColor,u=l.pointStyle??(l.value!==void 0?"circle":"none"),m=l.lineStyle??"full";if(l.value!==void 0){let f=n.map(l.value);if(m==="to-value"?a.push({type:"line",x1:h,y1:o,x2:h,y2:f,stroke:d,strokeWidth:1,dashed:true}):m==="to-top"?a.push({type:"line",x1:h,y1:i,x2:h,y2:f,stroke:d,strokeWidth:1,dashed:true}):m==="full"&&a.push({type:"line",x1:h,y1:i,x2:h,y2:o,stroke:d,strokeWidth:1}),u!=="none"&&ye(a,h,f,d,u),l.label){let p=m==="to-value"?f-10:i-6;a.push({type:"text",content:l.label,x:h,y:p,anchor:"middle",fontSize:11,fill:d});}}else a.push({type:"line",x1:h,y1:i,x2:h,y2:o,stroke:d,strokeWidth:1}),l.label&&a.push({type:"text",content:l.label,x:h,y:i-6,anchor:"middle",fontSize:11,fill:d});}return a}function ye(r,t,e,n,s){let i=c.markerSize;switch(s){case "circle":r.push({type:"circle",cx:t,cy:e,r:i,fill:n});break;case "square":r.push({type:"rect",x:t-i,y:e-i,w:i*2,h:i*2,fill:n});break;case "cross":r.push({type:"line",x1:t-i,y1:e-i,x2:t+i,y2:e+i,stroke:n,strokeWidth:2}),r.push({type:"line",x1:t-i,y1:e+i,x2:t+i,y2:e-i,stroke:n,strokeWidth:2});break;case "arrow":r.push({type:"path",points:[{x:t-i,y:e+i},{x:t,y:e-i},{x:t+i,y:e+i}],stroke:n,strokeWidth:2,fill:"none"});break;case "diamond":r.push({type:"path",points:[{x:t,y:e-i},{x:t+i,y:e},{x:t,y:e+i},{x:t-i,y:e}],fill:n,stroke:"none"});break;case "triangle":r.push({type:"path",points:[{x:t,y:e-i},{x:t+i,y:e+i},{x:t-i,y:e+i}],fill:n,stroke:"none"});break;case "star":{let o=[],a=i*.4;for(let l=0;l<10;l++){let h=l%2===0?i:a,d=Math.PI/2*3+l*Math.PI/5;o.push({x:t+h*Math.cos(d),y:e+h*Math.sin(d)});}r.push({type:"path",points:o,fill:n,stroke:"none"});break}case "plus":r.push({type:"line",x1:t-i,y1:e,x2:t+i,y2:e,stroke:n,strokeWidth:2}),r.push({type:"line",x1:t,y1:e-i,x2:t,y2:e+i,stroke:n,strokeWidth:2});break;case "triangle-down":r.push({type:"path",points:[{x:t,y:e+i},{x:t+i,y:e-i},{x:t-i,y:e-i}],fill:n,stroke:"none"});break;case "hexagon":{let o=[];for(let a=0;a<6;a++){let l=a*(Math.PI/3);o.push({x:t+i*Math.cos(l),y:e+i*Math.sin(l)});}r.push({type:"path",points:o,fill:n,stroke:"none"});break}case "hourglass":r.push({type:"path",points:[{x:t-i,y:e-i},{x:t+i,y:e-i},{x:t-i,y:e+i},{x:t+i,y:e+i}],fill:n,stroke:"none"});break;case "line-horizontal":r.push({type:"line",x1:t-i,y1:e,x2:t+i,y2:e,stroke:n,strokeWidth:2});break}}function Xt(r){let{annotations:t,timeScale:e,valueScales:n}=r,s=[],i=o=>{let a=n.get(o.axis??0)??n.values().next().value;return {x:e.map(o.time),y:a?a.map(o.value):0}};for(let o of t){let a=[],l=h=>a.push(h);switch(o.type){case "line":{let h=i(o.from),d=i(o.to);l({type:"line",x1:h.x,y1:h.y,x2:d.x,y2:d.y,stroke:o.color??c.annotationColor,strokeWidth:o.width??c.annotationWidth,dash:o.dash});break}case "arrow":{let h=i(o.from),d=i(o.to),u=o.color??c.annotationColor,m=o.headSize??c.annotationHead;l({type:"line",x1:h.x,y1:h.y,x2:d.x,y2:d.y,stroke:u,strokeWidth:o.width??c.annotationWidth});let f=Math.hypot(d.x-h.x,d.y-h.y)||1,p=(d.x-h.x)/f,b=(d.y-h.y)/f,x=d.x-p*m,w=d.y-b*m;l({type:"path",points:[{x:d.x,y:d.y},{x:x-b*m*.5,y:w+p*m*.5},{x:x+b*m*.5,y:w-p*m*.5}],fill:u,stroke:"none"});break}case "rect":{let h=i(o.from),d=i(o.to);l({type:"rect",x:Math.min(h.x,d.x),y:Math.min(h.y,d.y),w:Math.abs(d.x-h.x),h:Math.abs(d.y-h.y),fill:o.fill??"none",stroke:o.stroke,opacity:o.opacity});break}case "point":{let h=i(o.at),d=o.color??"#334155",u=o.radius??c.annotationRadius,m=o.shape??"circle";m==="circle"?l({type:"circle",cx:h.x,cy:h.y,r:u,fill:d}):m==="square"?l({type:"rect",x:h.x-u,y:h.y-u,w:u*2,h:u*2,fill:d}):(l({type:"line",x1:h.x-u,y1:h.y-u,x2:h.x+u,y2:h.y+u,stroke:d,strokeWidth:1.5}),l({type:"line",x1:h.x-u,y1:h.y+u,x2:h.x+u,y2:h.y-u,stroke:d,strokeWidth:1.5}));break}case "label":{let h=i(o.at);l({type:"text",content:o.text,x:h.x+(o.dx??0),y:h.y+(o.dy??0),anchor:o.anchor??"middle",fontSize:c.annotationFontSize,fill:o.color??c.annotationColor,rotate:o.rotate});break}}if(o.id&&a.length>0){let h=it(o.id);s.push({type:"group",cssClass:`annotation annotation--${h}`,commands:a});}else s.push(...a);}return s}var K=12,ct=8,_t=20,be=11,kt=18,vt=r=>r.length*be*.6;function qt(r,t="vertical"){if(t==="horizontal"){let n=0;for(let s of r)n+=K+ct+vt(s.name)+kt;return {width:Math.max(0,n-kt),height:_t}}let e=0;for(let n of r)e=Math.max(e,vt(n.name));return {width:K+ct+e,height:r.length*_t}}function Ut(r){let{items:t,x:e,y:n,orientation:s="vertical"}=r,i=[],o=e;return t.forEach((a,l)=>{let h=s==="horizontal"?o:e,d=s==="horizontal"?n:n+l*_t;i.push({type:"rect",x:h,y:d,w:K,h:K,fill:a.color,stroke:c.legendStroke,strokeWidth:1}),i.push({type:"text",content:a.name,x:h+K+ct,y:d+K-2,fontSize:c.legendFont,fill:c.legendText}),s==="horizontal"&&(o+=K+ct+vt(a.name)+kt);}),{type:"group",cssClass:"chart-legend",commands:i}}function Kt(r){let{xTicks:t,yTicks:e,xRange:n,yRange:s,stroke:i=c.gridStroke,strokeWidth:o=c.gridStrokeWidth,dashed:a=false,opacity:l=c.gridOpacity}=r,h=[];if(e)for(let d of e)h.push({type:"line",x1:n[0],y1:d,x2:n[1],y2:d,stroke:i,strokeWidth:o,dashed:a,opacity:l});if(t)for(let d of t)h.push({type:"line",x1:d,y1:s[0],x2:d,y2:s[1],stroke:i,strokeWidth:o,dashed:a,opacity:l});return h}function Zt(r,t,e){let n=r??t;if(n==="series")return null;if(n==="chartTop")return e.chartTop;if(n==="chartBottom")return e.chartBottom;if(typeof n=="object"&&"threshold"in n){let s=e.thresholds.get(n.threshold);if(!s)throw new Error(`fillSpec region references unknown threshold '${n.threshold}'`);return e.valueScale.map(s.value)}return typeof n=="object"&&"value"in n?e.valueScale.map(n.value):null}function xe(r){return typeof r=="string"?{color:r}:{color:r.color,hatch:r.hatch}}function Qt(r,t,e){let n=Zt(r.from,"chartBottom",t),s=Zt(r.to,"series",t),{color:i,hatch:o}=xe(r.fill),a={type:"path",fill:i,hatch:o,stroke:"none",...t.idPrefix&&{id:`${t.idPrefix}-fill-r${e}`}};if(n!==null&&s!==null){let m=t.timeScale.range(),f=m[0],p=m[1],b=Math.min(n,s),x=Math.max(n,s);return [{...a,points:[{x:f,y:b},{x:p,y:b},{x:p,y:x},{x:f,y:x}]}]}let l=n??s,h=[],d=Se(r,t);if(d===null){let m=t.valueScale.domain();d=(n??s)===t.chartBottom?m[0]:m[1];}let u=Jt(r.outer,t);for(let m of t.runs){if(m.length<2)continue;let f=F.splitByThreshold(m,d,b=>b.value??d,F.interpolateDataPoint),p=r.side==="above"?f.above:r.side==="below"?f.below:[...f.above,...f.below];if(u!==null&&r.side){let b=r.side==="above"?"below":"above";p=p.flatMap(x=>{if(x.length<2)return [];let w=F.splitByThreshold(x,u,k=>k.value??u,F.interpolateDataPoint);return b==="above"?w.above:w.below});}for(let b of p){if(b.length<2)continue;let x=b.map(k=>({x:t.timeScale.map(k.time),y:t.valueScale.map(k.value)})),w=[...x].reverse().map(k=>({x:k.x,y:l}));h.push({...a,smoothing:t.smoothing,smoothCount:x.length,points:[...x,...w]});}}return h}function Se(r,t){let e=r.from==="series"?r.to:r.from;return Jt(e,t)}function Jt(r,t){return r===void 0||r==="series"||r==="chartTop"||r==="chartBottom"?null:typeof r=="object"&&"threshold"in r?t.thresholds.get(r.threshold)?.value??null:typeof r=="object"&&"value"in r?r.value:null}function te(r,t){if(typeof r=="string"||!("regions"in r))return Qt({fill:r},t,0);let e=[];return r.regions.forEach((n,s)=>{e.push(...Qt(n,t,s));}),e}function ee(r,t){let e=new Array(r.length),n=0;for(let s=0;s<r.length;s++){let i=r[s].time,o=i-t;for(;n<s&&r[n].time<o;)n++;let a=0,l=0;for(let h=n;h<=s;h++){let d=r[h].value;d!==null&&(a+=d,l++);}e[s]={time:i,value:l===0?null:a/l,synthetic:true};}return e}function ie(r){let t=r.style?.line,e=t&&!Array.isArray(t)?t:void 0;return {color:e?.color??c.stroke,width:e?.width??c.strokeWidth,dash:e?.style,smoothing:e?.smoothing??false}}function ne(r,t,e,n){let s=r.filter(l=>l.value!==null);if(s.length<2)return [];let i=s.map(l=>({x:t.timeScale.map(l.time),y:t.valueScale.map(l.value)})),o=ie(e);return [{type:"path",id:t.idPrefix?`${t.idPrefix}-overlay-${n}`:`overlay-${n}`,points:i,stroke:o.color,strokeWidth:o.width,smoothing:o.smoothing,dash:o.dash,fill:"none"}]}function re(r,t){switch(r.kind){case "movingAverage":{r.type;let e=ee(t.data,r.window);return ne(e,t,r,"movingAvg")}case "movingMkt":{let e=jt(t.data,r.window,r.activationEnergy);return ne(e,t,r,"movingMkt")}case "limits":{let e=[],n=t.timeScale.range(),s=n[0],i=n[1],o=ie(r),a=o.color,l=o.width,h=o.dash??"dashed",d=t.idPrefix?`${t.idPrefix}-`:"";return r.high!==void 0&&e.push({type:"line",id:`${d}overlay-limit-high`,x1:s,y1:t.valueScale.map(r.high),x2:i,y2:t.valueScale.map(r.high),stroke:a,strokeWidth:l,dash:h}),r.low!==void 0&&e.push({type:"line",id:`${d}overlay-limit-low`,x1:s,y1:t.valueScale.map(r.low),x2:i,y2:t.valueScale.map(r.low),stroke:a,strokeWidth:l,dash:h}),e}case "stdDevBand":{let e=r.multiplier??1,n=ee(t.data,r.window),s=It(t.data,r.window),i=[],o=[];for(let b=0;b<n.length;b++){let x=n[b].value,w=s[b].value;if(x===null||w===null)continue;let k=t.timeScale.map(n[b].time);i.push({x:k,y:t.valueScale.map(x+e*w)}),o.push({x:k,y:t.valueScale.map(x-e*w)});}if(i.length<2)return [];let a=t.idPrefix?`${t.idPrefix}-`:"",l=[],d=(typeof r.style?.fill=="string"||r.style?.fill&&!("regions"in r.style.fill)?r.style.fill:void 0)??"#94a3b833",{color:u,hatch:m}=we(d);l.push({type:"path",id:`${a}overlay-stdDevBand`,points:[...i,...[...o].reverse()],fill:u,hatch:m,stroke:"none"});let f=r.style?.line,p=f&&!Array.isArray(f)?f:void 0;if(p){let b=n.filter(x=>x.value!==null).map(x=>({x:t.timeScale.map(x.time),y:t.valueScale.map(x.value)}));b.length>=2&&l.push({type:"path",id:`${a}overlay-stdDevBand-mean`,points:b,stroke:p.color??c.stroke,strokeWidth:p.width??1.5,smoothing:p.smoothing,dash:p.style,fill:"none"});}return l}}}function we(r){return typeof r=="string"?{color:r}:{color:r.color,hatch:r.hatch}}function _e(r){if(!r)return {gaps:[],autoDetect:false,minGapMs:6e4};if(Array.isArray(r))return {gaps:r,autoDetect:false,minGapMs:6e4};let t=r.regions??[],e=r.style;return {gaps:t.map(s=>{let i={...e,...s.style},o=i.fill,a,l;return typeof o=="string"?a=o:o&&(a=o.color,l=o.hatch),{startTime:s.startTime,endTime:s.endTime,label:s.label,fill:a,hatch:l,fillOpacity:i.opacity,labelBaseline:i.label?.baseline,rotate:i.label?.rotate,style:i.display==="filled"||i.display==="bridge_line"?void 0:i.display}}),autoDetect:r.autoDetect??false,minGapMs:r.minGapMs??6e4}}function pt(r){return "showAs"in r&&!!r.showAs}var Z=class{_layout;_renderer;_locale;_legend;_markers;_thresholds;_highlights;_gaps;_gapsAutoDetect;_gapsMinGapMs;_annotations;_annotationBands;_disabledAnnotations=new Set;_annotationSeq=0;_axes;_series;_annotationBandHeight=0;_timeScale;_valueScales=new Map;constructor(t={}){this._layout=new nt({width:t.width??800,height:t.height??400,margin:t.margin??{top:20,right:20,bottom:40,left:60}}).compute(),this._renderer=t.renderer,this._locale=t.locale,this._legend=t.legend,this._markers=t.markers??[],this._thresholds=t.thresholds??[],this._highlights=t.highlights??[];let e=_e(t.gaps);this._gaps=e.gaps,this._gapsAutoDetect=e.autoDetect,this._gapsMinGapMs=e.minGapMs,this._annotations=t.annotations??[],this._annotationBands=t.annotationBands??[],this._axes=t.axes,this._series=[],t.series&&this.setData(t.series);}getWidth(){return this._layout.totalWidth}getHeight(){return this._layout.totalHeight+this._annotationBandTotalHeight()}get series(){return this._series}_annotationBandTotalHeight(){let t=0;for(let e of this._annotationBands){let n=e.height??12,s=e.spacing??0;(e.showAxis??false)&&(t+=26+s),t+=n+s;}return t}setData(t){this._series=t.filter(e=>Array.isArray(e.data));}addAnnotation(t){let e=t.id??`anno-${++this._annotationSeq}`;return this._annotations.push({...t,id:e}),e}removeAnnotation(t){let e=this._annotations.length;return this._annotations=this._annotations.filter(n=>n.id!==t),this._disabledAnnotations.delete(t),this._annotations.length<e}setAnnotations(t){this._annotations=[...t],this._disabledAnnotations.clear();}clearAnnotations(){this._annotations=[],this._disabledAnnotations.clear();}getAnnotations(){return this._annotations}disableAnnotation(t){this._disabledAnnotations.add(t);}enableAnnotation(t){this._disabledAnnotations.delete(t);}_axisIndexOf(t){return t.yAxisIndex??0}_timesOf(t){return t.data.map(e=>e.time)}_valuesOf(t){if(pt(t)){let e=[];for(let n of t.data)n.min!==null&&e.push(n.min),n.max!==null&&e.push(n.max);return e}return t.data.map(e=>e.value).filter(e=>e!==null)}renderCommands(){if(this._series.length===0)return [];let t=this._legendItems(),e=(this._legend?.show??false)&&t.length>0,n=this._legend?.position??"inside-right",s=this._legend?.orientation??"vertical",i=e?qt(t,s):{width:0},o=this._layout;if(e&&(n==="outside-right"||n==="outside-left")){let g=i.width+16,S={...this._layout.margin};n==="outside-right"?S.right+=g:S.left+=g,o=new nt({width:this._layout.totalWidth,height:this._layout.totalHeight,margin:S}).compute();}let{chartX:a,chartY:l,chartWidth:h,chartHeight:d}=o,u=[a,a+h],m=[l,l+d],f=[];for(let g of this._series)g.data.sort((S,_)=>S.time-_.time);let p=new Map,b=1/0,x=-1/0,w=false;for(let g of this._series){let S=this._axisIndexOf(g),_=p.get(S);_?_.push(g):p.set(S,[g]);for(let T of this._timesOf(g))T<b&&(b=T),T>x&&(x=T),w=true;}if(!w)return [];let k=this._axes?.x?.domain,O=k&&k!=="auto"?k:[b,x];this._timeScale=new J({domain:O,range:u,locale:this._locale});let L=g=>({axisColor:g?.color??c.axisColor,tickColor:g?.color??c.tickColor,textColor:c.textColor,textSize:c.textSize,axisWidth:g?.width}),R=new tt({domain:O,xRange:u,y:l+d,locale:this._locale,format:this._axes?.x?.format,maxTicks:this._axes?.x?.ticks?.major,colors:L(this._axes?.x?.axis)});this._valueScales.clear();let W=Array.from(p.keys()).sort((g,S)=>g-S),H,j=0,$=0;for(let g of W){let S=p.get(g),_=1/0,T=-1/0,M=false;for(let Y of S)for(let at of this._valuesOf(Y))at<_&&(_=at),at>T&&(T=at),M=true;if(!M)continue;let B;this._axes?.y&&this._axes.y.length>g?B=this._axes.y[g]:g===0?B=this._axes?.left:g===1&&(B=this._axes?.right);let yt=B?.domain,Q=yt&&yt!=="auto"?yt:[_,T],Ft=new U({domain:Q,range:[l+d,l]});this._valueScales.set(g,Ft);let Wt=this._thresholds.filter(Y=>(Y.axisIndex??0)===g&&Y.label!==false&&Y.value>=Math.min(Q[0],Q[1])&&Y.value<=Math.max(Q[0],Q[1])).map(Y=>Ft.map(Y.value)),bt=B?.position??(g===0?"left":"right"),xt;bt==="right"?(xt=a+h+$*50,$++):(xt=a-j*50,j++);let Ht=new lt({domain:Q,range:[l+d,l],x:xt,position:bt,format:B?.format,ticks:B?.ticks?.major,colors:L(B?.axis),suppressLabelsNear:Wt.length?Wt:void 0});g===0&&(H=Ht),f.push({type:"group",cssClass:`value-axis ${bt}`,commands:Ht.render()});}let y=this._valueScales.get(0)??this._valueScales.get(W[0]);f.push({type:"group",cssClass:"time-axis",commands:R.render()});let v=null,C=this._axes?.x?.grid?.major,A=this._axes?.left?.grid?.major;if(C!==void 0||A!==void 0){let g=C!==false,S=A!==false&&!!H,_=g?R.generateTicks().map(M=>M.x):void 0,T=S?H.generateTicks().map(M=>M.position):void 0;if(_||T){let M=(C&&typeof C=="object"?C:void 0)??(A&&typeof A=="object"?A:void 0);v={type:"group",cssClass:"chart-grid",commands:Kt({xTicks:_,yTicks:T,xRange:u,yRange:m,stroke:M?.color,opacity:M?.opacity,dashed:M?.style==="dashed"})};}}if(this._highlights.length>0&&f.push({type:"group",cssClass:"highlights",commands:Nt({highlights:this._highlights,timeScale:this._timeScale,yRange:m,height:o.totalHeight})}),this._thresholds.length>0&&y){let g=[],S=[];for(let _ of this._thresholds){let T=_.id??it(_.name),M=this._valueScales.get(_.axisIndex??0)??y,B=Vt({thresholds:[_],valueScale:M,xRange:u});B.inside.length&&g.push({type:"group",cssClass:`threshold threshold--${T}`,id:`threshold-${T}`,commands:B.inside}),B.labels.length&&S.push({type:"group",cssClass:`threshold-label threshold-label--${T}`,commands:B.labels});}g.length&&f.push({type:"group",cssClass:"thresholds",commands:g,clipRect:{x:a,y:l,w:h,h:d}}),S.length&&f.push({type:"group",cssClass:"threshold-labels",commands:S});}let D=this._gaps;if(this._gapsAutoDetect){let g=[];for(let S of this._series)pt(S)||g.push(...Ot(S.data,this._gapsMinGapMs));g.length>0&&(D=[...this._gaps,...g]);}D.length>0&&f.push({type:"group",cssClass:"gaps",commands:zt({gaps:D,timeScale:this._timeScale,yRange:m})});let E=new Map(this._thresholds.map(g=>[g.name,g]));for(let g of this._series){if(g.data.length===0)continue;let S=this._valueScales.get(this._axisIndexOf(g));if(!S)continue;let _=g.id??it(g.name);f.push({type:"group",cssClass:`series series--${_}`,id:`series-${_}`,commands:this._renderSeries(g,S,E)});}v&&f.push(v);let V=this._markers.map(g=>({...g}));for(let g of V)if(g.value===void 0&&(g.lineStyle==="to-value"||g.lineStyle==="to-top")){let S=this._series[g.seriesIndex??0];S&&!pt(S)&&S.data.length>=2&&(g.value=this._interpolateValue(g.time,S.data));}V.length>0&&y&&f.push({type:"group",cssClass:"markers",commands:Yt({markers:V,timeScale:this._timeScale,valueScale:y,yRange:m})});let N=this._annotations.filter(g=>!g.id||!this._disabledAnnotations.has(g.id));if(N.length>0&&f.push({type:"group",cssClass:"annotations",commands:Xt({annotations:N,timeScale:this._timeScale,valueScales:this._valueScales})}),this._annotationBands.length>0){let g=l+d+this._layout.margin.bottom,S=0;this._annotationBands.forEach(_=>{let T=_.height??12,M=_.spacing??0,B=g+S;(_.showAxis??false)&&(S+=26+M),S+=T+M,f.push({type:"group",cssClass:"annotation-band",commands:new ut({name:_.name,showAxis:_.showAxis??false,items:_.items,timeScale:this._timeScale,background:_.background,hatch:_.hatch},[a,a+h],B,T).render()});});}if(e&&n!=="separate"){let g,S;n==="inside-right"?(g=a+h-i.width-8,S=l+8):n==="inside-left"?(g=a+8,S=l+8):n==="outside-right"?(g=a+h+16,S=l):(g=8,S=l),f.push(Ut({items:t,x:g,y:S,orientation:s}));}let P=this._axes?.left?.label,I=this._axes?.right?.label,q=this._axes?.x?.label;if(P||I||q){let g=[],S=l+d/2,_=this._axes?.left?.labels,T=this._axes?.right?.labels,M=this._axes?.x?.labels;P&&g.push({type:"text",content:P,x:14,y:S,anchor:"middle",fontSize:_?.fontSize??c.axisLabelSize,fill:_?.color??c.axisLabelColor,rotate:-90}),I&&g.push({type:"text",content:I,x:o.totalWidth-14,y:S,anchor:"middle",fontSize:T?.fontSize??c.axisLabelSize,fill:T?.color??c.axisLabelColor,rotate:90}),q&&g.push({type:"text",content:q,x:a+h/2,y:o.totalHeight-6,anchor:"middle",fontSize:M?.fontSize??c.axisLabelSize,fill:M?.color??c.axisLabelColor}),g.length&&f.push({type:"group",cssClass:"axis-labels",commands:g});}return f}_renderSeries(t,e,n){let s=this._timeScale,i={timeScale:s,valueScale:e};if(pt(t)){let y=t.style?.line&&!Array.isArray(t.style.line)?t.style.line:void 0,v=typeof t.style?.fill=="string"?t.style.fill:void 0;return t.showAs==="minmaxavg"?new dt({data:t.data,timeScale:s,valueScale:e,minColor:t.minColor,maxColor:t.maxColor,avgColor:t.avgColor,avgDashed:t.avgDashed,fillToMax:t.fillToMax,fillToMaxHatch:t.fillToMaxHatch,fillToMin:t.fillToMin,fillToMinHatch:t.fillToMinHatch,smoothing:y?.smoothing,strokeWidth:y?.width,id:t.id}).render():new mt({data:t.data,timeScale:s,valueScale:e,fill:v??y?.color,avgLine:t.avgLine,countOpacity:t.countOpacity,id:t.id}).render()}let o=t,a=t.style?.line&&!Array.isArray(t.style.line)?t.style.line:void 0,l=a?.gapThreshold??c.gapThreshold,h=F.getRuns(t.data,y=>y.value===null,l),d=h.reduce((y,v)=>y+v.length,0);if(d===0)return [];let u=[],m=t.style?.markers,f=t.style?.shadow,p={stroke:a?.color??c.stroke,strokeWidth:a?.width??c.strokeWidth,smoothing:a?.smoothing,dashed:a?.style==="dashed",pointStyle:m?.type,pointSize:m?.size,pointStroke:m?.stroke,pointFill:m?.fill,pointStrokeWidth:m?.strokeWidth,shadowColor:f?.color,shadowBlur:f?.blur,shadowOffsetX:f?.offsetX,shadowOffsetY:f?.offsetY,id:t.id},b=t.style?.line,x=b&&!Array.isArray(b)?b:void 0,w=x?.color,k=x?.width,O=x?.style,L=x?.smoothing,R=t.style?.fill;if(R!==void 0){let y=e.range(),v=Math.min(y[0],y[1]),C=Math.max(y[0],y[1]);u.push(...te(R,{runs:h,timeScale:s,valueScale:e,thresholds:n,chartTop:v,chartBottom:C,smoothing:a?.smoothing,idPrefix:t.id}));}let W=o.colorByThresholds??[],H=W.map(y=>n.get(y)).filter(y=>!!y).map(y=>y.value).sort((y,v)=>y-v),j=(y,v)=>{let C=p.stroke;for(let A of v){let D=n.get(A);D&&y>=D.value&&(C=D.color??C);}return C};for(let y of h){if(y.length<2)continue;let v=F.splitByBoundaries(y,H,C=>C.value,F.interpolateDataPoint);for(let C=0;C<v.length;C++){let A=v[C];if(A.data.length<2)continue;let D=(A.data[0].value+A.data[A.data.length-1].value)/2,E=o.id,V=A.data.map(P=>({x:s.map(P.time),y:e.map(P.value)})),N=E?`${E}-line-${C}`:void 0;b===false||(b&&Array.isArray(b)?b.forEach((P,I)=>{u.push({type:"path",id:N?`${N}-${I}`:void 0,points:V,stroke:P.color??j(D,W),strokeWidth:P.width??p.strokeWidth,smoothing:P.smoothing??p.smoothing,dash:P.style,opacity:P.opacity,fill:"none",shadowColor:p.shadowColor,shadowBlur:p.shadowBlur,shadowOffsetX:p.shadowOffsetX,shadowOffsetY:p.shadowOffsetY});}):u.push({type:"path",id:N,points:V,stroke:w??j(D,W),strokeWidth:k??p.strokeWidth,smoothing:L??p.smoothing,dash:O,fill:"none",shadowColor:p.shadowColor,shadowBlur:p.shadowBlur,shadowOffsetX:p.shadowOffsetX,shadowOffsetY:p.shadowOffsetY}));}p.pointStyle&&p.pointStyle!=="none"&&d<=(m?.threshold??c.pointThreshold)&&u.push(...Et(y,i,p,C=>j(C.value,W)));}let $=t.overlays;if($&&$.length>0){let y=e.range(),v={data:t.data,timeScale:s,valueScale:e,chartTop:Math.min(y[0],y[1]),chartBottom:Math.max(y[0],y[1]),idPrefix:t.id};for(let C of $)u.push(...re(C,v));}if(t.style?.gap&&h.length>1){let y=e.range(),v=Math.min(y[0],y[1]),C=Math.max(y[0],y[1]),A=t.style.gap,D=A.fill,E,V;typeof D=="string"?E=D:D&&(E=D.color,V=D.hatch);let N=A.opacity??.15,P=A.bridge;for(let I=1;I<h.length;I++){let q=h[I-1][h[I-1].length-1],g=h[I][0],S=s.map(q.time),_=s.map(g.time);if(A.display==="bridge_line"){if(q.value===null||g.value===null)continue;let T=e.map(q.value),M=e.map(g.value);u.push({type:"line",x1:S,y1:T,x2:_,y2:M,stroke:P?.color??(typeof t.style?.line=="object"&&!Array.isArray(t.style.line)?t.style.line.color:void 0)??c.stroke,strokeWidth:P?.width??1.5,dash:P?.style??"dotted"});}else E!==void 0?u.push({type:"rect",x:S,y:v,w:_-S,h:C-v,fill:E,hatch:V,opacity:N,stroke:"none"}):A.display!=="empty"&&u.push({type:"rect",x:S,y:v,w:_-S,h:C-v,stroke:c.gapStroke,strokeWidth:1,dashed:true,fill:"none"});}}return u}_interpolateValue(t,e){for(let n=1;n<e.length;n++){let s=e[n-1],i=e[n];if(!(s.value===null||i.value===null)&&t>=s.time&&t<=i.time){let o=(t-s.time)/(i.time-s.time);return s.value+o*(i.value-s.value)}}}legendItems(){return this._legendItems()}_legendItems(){return this._series.map(t=>{let e=t.style?.line&&!Array.isArray(t.style.line)?t.style.line:void 0;return {name:t.name,color:e?.color??c.stroke}})}get renderer(){return this._renderer}get layout(){return this._layout}get timeScale(){return this._timeScale}get valueScales(){return this._valueScales}invertTime(t){return this._timeScale?this._timeScale.invert(t):0}invertValue(t,e=0){let n=this._valueScales.get(e);return n?n.invert(t):0}project(t,e,n=0){let s=this._timeScale?this._timeScale.map(t):0,i=this._valueScales.get(n);return {x:s,y:i?i.map(e):0}}};var ft=class{};var z=1e3,X=class extends ft{#t="100%";#e="100%";#n=new Map;#i=new Map;#r=new Map;constructor(t){super(),t?.width!==void 0&&(this.#t=t.width),t?.height!==void 0&&(this.#e=t.height);}render(t){this.#n.clear(),this.#i.clear(),this.#r.clear();let e=t.map(l=>this._toSVG(l)).join(`
28
+ `.trim()}function Rt(r,t=2){let e=t;switch(r){case "dotted":return {strokeDasharray:`0, ${e*2}`,strokeLinecap:"round"};case "sparse-dots":return {strokeDasharray:`0, ${e*4}`,strokeLinecap:"round"};case "dashed":return {strokeDasharray:`${e*3}, ${e*2}`,strokeLinecap:"butt"};case "long-dash":return {strokeDasharray:`${e*6}, ${e*3}`,strokeLinecap:"butt"};case "dense-dash":return {strokeDasharray:`${e*1.5}, ${e*1.5}`,strokeLinecap:"butt"};case "dash-dot":return {strokeDasharray:`${e*4}, ${e*2}, 0, ${e*2}`,strokeLinecap:"round"};case "dash-dot-dot":return {strokeDasharray:`${e*5}, ${e*2}, 0, ${e*2}, 0, ${e*2}`,strokeLinecap:"round"};case "loose-dash":return {strokeDasharray:`${e*3}, ${e*4}`,strokeLinecap:"butt"};default:return {strokeDasharray:"none",strokeLinecap:"butt"}}}var rt={axisColor:c.axisColor,tickColor:c.tickColor,textColor:c.textColor,textSize:c.textSize},tt=class{#t;#e;constructor(t){this.#t=new J({domain:t.domain,range:t.xRange,locale:t.locale}),this.#e=t;}get scale(){return this.#t}get axisColor(){return (this.#e.colors??rt).axisColor}get tickColor(){return (this.#e.colors??rt).tickColor}get textColor(){return (this.#e.colors??rt).textColor}get textSize(){return (this.#e.colors??rt).textSize}generateTicks(){let t=this.#e.minTicks??5,e=this.#e.maxTicks??12,s=this.#t.ticks({minTicks:t,maxTicks:e}).map(i=>({time:i,x:this.#t.map(i),label:this.tickLabel(i)}));return this.antiOverlap(s)}tickLabel(t){if(this.#e.format)return this.#e.format(new Date(t));let e=this.#e.minTicks??5,n=this.#e.maxTicks??12,{interval:s}=this.#t.tickInterval((e+n)/2,e,n),i={};return s<6e4?(i.hour="2-digit",i.minute="2-digit",i.second="2-digit"):s<36e5||s<864e5?(i.hour="2-digit",i.minute="2-digit"):s<31536e6?(i.day="numeric",i.month="short",s>=2592e6&&(i.day=void 0,i.month="long")):(i.year="numeric",s<2*31536e6&&(i.month="short")),this.#t.format(t,i)}antiOverlap(t){if(t.length<=1)return t;let e=60,n=[t[0]];for(let s=1;s<t.length;s++){let i=n[n.length-1].x;Math.abs(t[s].x-i)>=e&&n.push(t[s]);}return n}render(){let t=this.generateTicks(),e=this.#e.colors??rt,n=this.#e.y??0,s=[],[i]=this.#t.range();s.push({type:"line",x1:i,y1:n,x2:t[t.length-1]?.x??i,y2:n,stroke:e.axisColor,strokeWidth:e.axisWidth});for(let o of t)s.push({type:"line",x1:o.x,y1:n,x2:o.x,y2:n+6,stroke:e.tickColor,strokeWidth:e.axisWidth}),s.push({type:"text",content:o.label,x:o.x,y:n+e.textSize+6,anchor:"middle",fontSize:e.textSize,fill:e.textColor});return s}};var st={axisColor:"#ccc",tickColor:"#ddd",textColor:"#777",textSize:12};function ae(r){return Math.abs(r)>=1e6?`${(r/1e6).toFixed(1)}M`:Math.abs(r)>=1e3?`${(r/1e3).toFixed(1)}k`:Number.isInteger(r)?String(r):r.toFixed(1)}function le(r){let t=new Array(r.length).fill(false),e=0;for(;e<r.length;){let n=e;for(;n+1<r.length&&r[n+1].label===r[e].label;)n++;for(let s=e+1;s<n;s++)t[s]=true;e=n+1;}return t}var lt=class{#t;#e;constructor(t){this.#t=new U({domain:t.domain,range:t.range}),this.#e=t;}get scale(){return this.#t}get axisColor(){return (this.#e.colors??st).axisColor}get tickColor(){return (this.#e.colors??st).tickColor}get textColor(){return (this.#e.colors??st).textColor}get textSize(){return (this.#e.colors??st).textSize}generateTicks(){let t=this.#e.format??ae,e=6,[n,s]=this.#t.domain(),i=s-n;if(i===0)return [{value:n,position:this.#t.map(n),label:t(n)}];let o=i/e,a=Math.pow(10,Math.floor(Math.log10(o))),l=o/a,h;l<=1.5?h=a:l<=3?h=2*a:l<=7?h=5*a:h=10*a;let d=[],m=Math.ceil(n/h)*h;for(let u=m;u<=s;u+=h)d.push({value:u,position:this.#t.map(u),label:t(u)});return d}render(){let t=this.generateTicks(),e=this.#e.colors??st,n=this.#e.x??0,s=this.#e.orientation??"vertical",i=this.#e.position??"left",o=this.#e.suppressLabelsNear??[],a=this.#e.suppressTolerancePx??8,l=d=>o.some(m=>Math.abs(m-d)<=a),h=[];if(s==="vertical"){let[d,m]=this.#t.range();h.push({type:"line",x1:n,y1:d,x2:n,y2:m,stroke:e.axisColor,strokeWidth:e.axisWidth});let u=le(t);t.forEach((f,p)=>{let y=l(f.position),b=u[p]?{opacity:0}:{};i==="left"?(h.push({type:"line",x1:n-4,y1:f.position,x2:n,y2:f.position,stroke:e.tickColor,strokeWidth:e.axisWidth}),y||h.push({type:"text",content:f.label,x:n-8,y:f.position+4,anchor:"end",fontSize:11,fill:e.textColor,...b})):(h.push({type:"line",x1:n,y1:f.position,x2:n+4,y2:f.position,stroke:e.tickColor,strokeWidth:e.axisWidth}),y||h.push({type:"text",content:f.label,x:n+8,y:f.position+4,anchor:"start",fontSize:11,fill:e.textColor,...b}));});}else {let[d,m]=this.#t.range();h.push({type:"line",x1:d,y1:n,x2:m,y2:n,stroke:e.axisColor,strokeWidth:e.axisWidth});for(let u of t)h.push({type:"line",x1:u.position,y1:n,x2:u.position,y2:n+6,stroke:e.tickColor,strokeWidth:e.axisWidth}),h.push({type:"text",content:u.label,x:u.position,y:n+18,anchor:"middle",fontSize:e.textSize,fill:e.textColor});}return h}};var W=class{static interpolateDataPoint(r,t,e){return {time:r.time+e*(t.time-r.time),value:(r.value??0)+e*((t.value??0)-(r.value??0))}}static interpolateAggregatedPoint(r,t,e){let n=(s,i)=>s!==null&&i!==null?s+e*(i-s):null;return {time:r.time+e*(t.time-r.time),min:n(r.min,t.min),max:n(r.max,t.max),avg:n(r.avg,t.avg),count:Math.round(r.count+e*(t.count-r.count))}}static getRuns(r,t,e=0){let n=[...r].sort((a,l)=>a.time-l.time),s=[],i=[],o=null;for(let a of n){let l=t(a),h=e>0&&o&&a.time-o.time>e;(l||h)&&i.length&&(s.push(i),i=[]),l||i.push(a),o=a;}return i.length&&s.push(i),s}static splitByBoundaries(r,t,e,n){if(r.length===0)return [];if(t.length===0)return [{data:r,zoneIndex:0}];let s=[...t].sort((l,h)=>l-h),i=[],o=l=>{let h=0;for(let d=0;d<s.length&&l>=s[d];d++)h=d+1;return h},a=[r[0]];for(let l=1;l<r.length;l++){let h=r[l-1],d=r[l],m=e(h),u=e(d),f;u>m?f=s.filter(p=>p>m&&p<=u):u<m?f=s.filter(p=>p>=u&&p<m).reverse():f=[];for(let p of f){let y=(p-m)/(u-m),b=n(h,d,y);a.push(b),i.push({data:a,zoneIndex:o((m+p)/2)}),a=[b];}a.push(d);}if(a.length>0){let l=e(a[0]),h=e(a[a.length-1]);i.push({data:a,zoneIndex:o((l+h)/2)});}return i}static splitByThreshold(r,t,e,n){let s=this.splitByBoundaries(r,[t],e,n),i={above:[],below:[]};for(let o of s)o.zoneIndex===0?i.below.push(o.data):i.above.push(o.data);return i}};function Ot(r,t=6e4){if(r.length<2)return [];let e=[...r].sort((s,i)=>s.time-i.time),n=[];for(let s=1;s<e.length;s++)e[s].time-e[s-1].time>t&&n.push({startTime:e[s-1].time,endTime:e[s].time});return n}function he(r,t=83144){let e=t/8.314,n=0,s=0;for(let o of r)o!==null&&(n+=Math.exp(-e/(o+273.15)),s++);if(s===0)return null;let i=n/s;return e/-Math.log(i)-273.15}function jt(r,t,e=83144){let n=new Array(r.length),s=0;for(let i=0;i<r.length;i++){let o=r[i].time,a=o-t;for(;s<i&&r[s].time<a;)s++;let l=r.slice(s,i+1).map(d=>d.value),h=he(l,e);n[i]={time:o,value:h,synthetic:true};}return n}function de(r){let t=0,e=0;for(let i of r)i!==null&&(t+=i,e++);if(e===0)return null;let n=t/e,s=0;for(let i of r){if(i===null)continue;let o=i-n;s+=o*o;}return Math.sqrt(s/e)}function ue(r){let t=0,e=0;for(let i of r)i!==null&&(t+=i,e++);if(e<2)return null;let n=t/e,s=0;for(let i of r){if(i===null)continue;let o=i-n;s+=o*o;}return Math.sqrt(s/(e-1))}function It(r,t,e=false){let n=new Array(r.length),s=0,i=e?ue:de;for(let o=0;o<r.length;o++){let a=r[o].time,l=a-t;for(;s<o&&r[s].time<l;)s++;let h=r.slice(s,o+1).map(m=>m.value),d=i(h);n[o]={time:a,value:d,synthetic:true};}return n}function Gt(r){return {id:r.id,line:{stroke:r.stroke??c.stroke,strokeWidth:r.strokeWidth??c.strokeWidth,smoothing:r.smoothing??false,dashed:r.dashed??false},fill:r.fill??c.areaFillAlpha,markers:{type:r.pointStyle??"none",size:r.pointSize??c.pointSize,stroke:r.stroke??c.stroke,fill:"#ffffff"},shadow:{color:r.shadowColor??"transparent",blur:r.shadowBlur??0,offsetX:r.shadowOffsetX??0,offsetY:r.shadowOffsetY??0}}}function ht(r,t,e){let n=[],s=r.reduce((o,a)=>o+a.data.length,0),i=Gt(e);for(let o=0;o<r.length;o++){let a=r[o];a.data.length>=2?n.push({type:"path",id:e.id?`${e.id}-line-${o}`:void 0,points:a.data.map(l=>({x:t.timeScale.map(l.time),y:t.valueScale.map(l.value)})),stroke:a.color??i.line.stroke,strokeWidth:i.line.strokeWidth,smoothing:i.line.smoothing,dashed:i.line.dashed,shadowColor:i.shadow.color,shadowBlur:i.shadow.blur,shadowOffsetX:i.shadow.offsetX,shadowOffsetY:i.shadow.offsetY,fill:"none"}):a.data.length===1&&s===1&&n.push({type:"circle",cx:t.timeScale.map(a.data[0].time),cy:t.valueScale.map(a.data[0].value),r:Math.max(i.markers.size,i.line.strokeWidth),fill:a.color??i.line.stroke,shadowColor:i.shadow.color,shadowBlur:i.shadow.blur});}return n}function wt(r,t,e,n){if(r.length<2)return [];let s=W.splitByBoundaries(r,e.boundaries,e.getValue,e.interpolate),i=[];for(let o=0;o<s.length;o++){let a=s[o];if(a.data.length<2)continue;let l=e.getColor(a.zoneIndex);if(!l)continue;let h=a.data.map(m=>({x:t.timeScale.map(m.time),y:t.valueScale.map(e.yLow(m))})),d=a.data.map(m=>({x:t.timeScale.map(m.time),y:t.valueScale.map(e.yHigh(m))})).reverse();i.push({type:"path",id:n?.id?`${n.id}-fill-${o}`:void 0,points:[...h,...d],fill:l,hatch:e.getHatch?.(a.zoneIndex),stroke:"none"});}return i}function Et(r,t,e,n){let s=Gt(e);if(!s.markers.type||s.markers.type==="none")return [];let i=[];for(let o=0;o<r.length;o++){let a=r[o],l=t.timeScale.map(a.time),h=t.valueScale.map(a.value),d=n(a),m=e.pointStroke??d,u=e.pointFill??d,f=e.pointStrokeWidth??1.5,p=e.id?`${e.id}-marker-${o}`:void 0;me(i,p,s.markers.type,l,h,s.markers.size,m,u,f);}return i}function me(r,t,e,n,s,i,o,a,l){switch(e){case "circle":r.push({type:"circle",cx:n,cy:s,r:i,fill:a,stroke:o,strokeWidth:l,id:t});break;case "square":r.push({type:"rect",x:n-i,y:s-i,w:i*2,h:i*2,fill:a,stroke:o,strokeWidth:l,id:t});break;case "cross":r.push({type:"line",x1:n-i,y1:s-i,x2:n+i,y2:s+i,stroke:o,strokeWidth:l,id:t}),r.push({type:"line",x1:n-i,y1:s+i,x2:n+i,y2:s-i,stroke:o,strokeWidth:l,id:t});break;case "diamond":r.push({type:"path",points:[{x:n,y:s-i},{x:n+i,y:s},{x:n,y:s+i},{x:n-i,y:s}],fill:a,stroke:o,strokeWidth:l,id:t});break;case "triangle":r.push({type:"path",points:[{x:n,y:s-i},{x:n+i,y:s+i},{x:n-i,y:s+i}],fill:a,stroke:o,strokeWidth:l,id:t});break;case "star":{let h=[];for(let d=0;d<10;d++){let m=d%2===0?i:i*.5,u=Math.PI/2*3+d*Math.PI/5;h.push({x:n+m*Math.cos(u),y:s+m*Math.sin(u)});}r.push({type:"path",points:h,fill:a,stroke:o,strokeWidth:l,id:t});break}case "arrow":r.push({type:"path",points:[{x:n-i,y:s+i},{x:n,y:s-i},{x:n+i,y:s+i}],stroke:o,strokeWidth:l,fill:"none",id:t});break;default:r.push({type:"circle",cx:n,cy:s,r:i,fill:a,stroke:o,strokeWidth:l,id:t});}}var et=class r{#t;#e;static uidcnt=0;#n;constructor(t,e=[]){this.#t=t.id??"id"+Date.now+ ++r.uidcnt,this.#e=t.timeScale,this.#n=e;}get id(){return this.#t}get timeScale(){return this.#e}get data(){return this.#n}};var dt=class extends et{#t;constructor(t){super(t,t.data),this.#t=t;}render(){let t=this.#t,e=t.minColor??c.minColor,n=t.maxColor??c.maxColor,s=t.avgColor??c.avgColor,i=t.avgDashed??true,o=t.smoothing??false,a=t.strokeWidth??c.strokeWidth,l=W.getRuns(this.data,m=>m.min===null||m.max===null||m.avg===null);if(l.length===0)return [];let h={timeScale:this.timeScale,valueScale:t.valueScale},d=[];for(let m of l)m.length<2||(t.fillToMax&&d.push(...wt(m,h,{boundaries:[],yLow:u=>u.avg,yHigh:u=>u.max,getValue:u=>u.avg,interpolate:W.interpolateAggregatedPoint,getColor:()=>t.fillToMax,getHatch:()=>t.fillToMaxHatch},{id:this.id?`${this.id}-fillToMax`:void 0})),t.fillToMin&&d.push(...wt(m,h,{boundaries:[],yLow:u=>u.avg,yHigh:u=>u.min,getValue:u=>u.avg,interpolate:W.interpolateAggregatedPoint,getColor:()=>t.fillToMin,getHatch:()=>t.fillToMinHatch},{id:this.id?`${this.id}-fillToMin`:void 0})),d.push(...ht([{data:m.map(u=>({time:u.time,value:u.max}))}],h,{stroke:n,strokeWidth:a,smoothing:o,id:this.id?`${this.id}-max`:void 0}),...ht([{data:m.map(u=>({time:u.time,value:u.min}))}],h,{stroke:e,strokeWidth:a,smoothing:o,id:this.id?`${this.id}-min`:void 0}),...ht([{data:m.map(u=>({time:u.time,value:u.avg}))}],h,{stroke:s,strokeWidth:a,smoothing:o,dashed:i,id:this.id?`${this.id}-avg`:void 0})));return d}};var ut=class extends et{#t;constructor(t){super(t,t.data),this.#t=t;}opacity(t){if(!(this.#t.countOpacity??false))return .6;let e=Math.max(...this.data.map(n=>n.count));return e===0?.2:.2+.8*t/e}render(){let t=this.#t,e=t.fill??c.bandFill,n=t.hatch,s=t.avgLine??false,i=t.avgLineColor??c.bandAvgLine,o=t.bandWidth??10,a=[];for(let l of this.data){if(l.min===null||l.max===null)continue;let h=this.timeScale.map(l.time),d=t.valueScale.map(l.max),m=t.valueScale.map(l.min),u=o,f=this.data.indexOf(l);if(a.push({type:"rect",x:h-u/2,y:d,w:u,h:m-d,fill:e,hatch:n,opacity:this.opacity(l.count),id:this.id?`${this.id}-slot-${f}`:void 0}),s&&l.avg!==null){let p=t.valueScale.map(l.avg);a.push({type:"line",x1:h-u/2,y1:p,x2:h+u/2,y2:p,stroke:i,strokeWidth:1,id:this.id?`${this.id}-avg-${f}`:void 0});}}return a}};function ce(r){return r==="dotted"?{dash:"dotted"}:r==="dashed"?{dash:"dashed"}:{}}function Vt(r){let{thresholds:t,valueScale:e,xRange:n}=r,[s,i]=n,[o,a]=e.range(),l=Math.min(o,a),h=Math.max(o,a),d=[],m=[];for(let u of t){let f=u.color??c.thresholdColor,p=e.map(u.value);u.fill==="above"?d.push({type:"rect",x:s,y:l,w:i-s,h:Math.max(0,p-l),fill:f,hatch:u.fillHatch,opacity:u.fillOpacity??.12,id:u.id?`${u.id}-fill`:void 0}):u.fill==="below"&&d.push({type:"rect",x:s,y:p,w:i-s,h:Math.max(0,h-p),fill:f,hatch:u.fillHatch,opacity:u.fillOpacity??.12,id:u.id?`${u.id}-fill`:void 0});let y=u.line??c.thresholdLine;if(y!=="none"){let b=ce(y),S={type:"line",x1:s,y1:p,x2:i,y2:p,stroke:f,strokeWidth:1,...b,id:u.id?`${u.id}-line`:void 0};u.shadowColor&&(S.shadowColor=u.shadowColor,S.shadowBlur=u.shadowBlur??4,S.shadowOffsetX=u.shadowOffsetX??0,S.shadowOffsetY=u.shadowOffsetY??2),d.push(S);}if(u.label!==false){let b=u.label&&typeof u.label=="object"?u.label:void 0,S=typeof u.label=="string"?u.label:b?.text??u.name,k=b?.position??"right";m.push({...pe(S,k,s,i,p,f,b),id:u.id?`${u.id}-label`:void 0});}}return {inside:d,labels:m}}function pe(r,t,e,n,s,i,o){let a=(e+n)/2,l={type:"text",content:r,fontSize:c.thresholdFontSize,fill:i},h=o?{...o.rotate!==void 0&&{rotate:o.rotate},...o.textBaseline!==void 0&&{textBaseline:o.textBaseline}}:{};switch(t){case "left":return {...l,...h,x:e+4,y:s-4,anchor:"start"};case "above":return {...l,...h,x:a,y:s-6,anchor:"middle"};case "below":return {...l,...h,x:a,y:s+14,anchor:"middle"};case "center":return {...l,...h,x:a,y:s-4,anchor:"middle"};case "outside-left":return {...l,...h,x:e-6,y:s+3,anchor:"end",textBaseline:h.textBaseline??"middle"};case "outside-right":return {...l,...h,x:n+6,y:s+3,anchor:"start",textBaseline:h.textBaseline??"middle"};default:return {...l,...h,x:n-4,y:s-4,anchor:"end"}}}function zt(r){let{gaps:t,timeScale:e,yRange:n,fill:s=c.gapFill,hatch:i,fillOpacity:o=c.gapFillOpacity,stroke:a=c.gapStroke,strokeWidth:l=c.gapStrokeWidth,dashed:h=true,fontSize:d=c.gapFontSize,fontFill:m=c.gapFontColor,labelBaseline:u="middle",labelRotate:f}=r,[p,y]=n,b=[];for(let S of t){let k=e.map(S.startTime),I=e.map(S.endTime),D=S.fill??s,O=S.hatch??i,H=S.fillOpacity??o,R=S.label??"",G=S.rotate??f,B=S.labelBaseline??u;if(S.style==="dashed_border"||!S.style?b.push({type:"rect",x:k,y:p,w:I-k,h:y-p,fill:D,hatch:O,opacity:H,stroke:a,strokeWidth:l,dashed:h}):S.style==="empty"&&b.push({type:"rect",x:k,y:p,w:I-k,h:y-p,fill:D,hatch:O,opacity:H}),R){let w=fe(p,y,B),v=B==="above"?"top":B==="below"?"bottom":"middle";b.push({type:"text",content:R,x:(k+I)/2,y:w,anchor:"middle",fontSize:d,fill:m,textBaseline:v,rotate:G});}}return b}function fe(r,t,e){switch(e){case "above":return r-12;case "below":return t+4;default:return (r+t)/2}}var mt=class{#t;constructor(t,e,n,s){this.#t={...t,xRange:e,y:n,height:s};}render(){let{items:t,timeScale:e,background:n,hatch:s,showAxis:i,xRange:o,y:a,height:l}=this.#t,h=[];n&&h.push({type:"rect",x:o[0],y:a,w:o[1]-o[0],h:l,fill:n,opacity:.04,stroke:"#ddd",strokeWidth:.25});for(let d of t){let m=e.map(d.startTime),u=e.map(d.endTime);if(!(u-m<1)&&(h.push({type:"rect",x:m,y:a,w:u-m,h:l,hatch:d.hatch??s,fill:d.fill??"#6b728044",stroke:d.stroke,strokeWidth:d.strokeWidth??0}),d.label)){let f=d.labelFontSize??10;h.push({type:"text",content:d.label,x:(m+u)/2,y:this.#e(d.labelBaseline,f),anchor:"middle",fontSize:f,fill:d.labelFill??"#333"});}}if(i){let d=new tt({domain:e.domain(),xRange:o,y:a+l+4});h.push({type:"group",cssClass:"annotation-band-axis",commands:d.render()});}return h}#e(t,e){let{y:n,height:s}=this.#t;switch(t){case "top":return n+e*.9;case "bottom":return n+s-e*.25;default:return n+s/2+e*.35}}};function Nt(r){let{highlights:t,timeScale:e,yRange:n,height:s}=r,[i,o]=n,a=[];for(let l of t){let h=e.map(l.startTime),d=e.map(l.endTime);a.push({type:"rect",x:h,y:i,w:d-h,h:o-i,fill:l.color??c.highlightColor,opacity:l.opacity??c.highlightOpacity}),l.label&&a.push({type:"text",content:l.label,x:(h+d)/2,y:ge(l.labelPosition??"top",i,o,s),anchor:"middle",fontSize:c.annotationFontSize,fill:l.color??c.highlightLabelColor,rotate:l.rotate});}return a}function ge(r,t,e,n){switch(r){case "above":return t-5;case "below":return n!==void 0?n-5:e+14;case "center":return (t+e)/2+4;case "bottom":return e-6;default:return t+14}}function Yt(r){let{markers:t,timeScale:e,valueScale:n,yRange:s=[0,300]}=r,[i,o]=s,a=[];for(let l of t){let h=e.map(l.time),d=l.color??c.markerColor,m=l.pointStyle??(l.value!==void 0?"circle":"none"),u=l.lineStyle??"full";if(l.value!==void 0){let f=n.map(l.value);if(u==="to-value"?a.push({type:"line",x1:h,y1:o,x2:h,y2:f,stroke:d,strokeWidth:1,dashed:true}):u==="to-top"?a.push({type:"line",x1:h,y1:i,x2:h,y2:f,stroke:d,strokeWidth:1,dashed:true}):u==="full"&&a.push({type:"line",x1:h,y1:i,x2:h,y2:o,stroke:d,strokeWidth:1}),m!=="none"&&ye(a,h,f,d,m),l.label){let p=u==="to-value"?f-10:i-6;a.push({type:"text",content:l.label,x:h,y:p,anchor:"middle",fontSize:11,fill:d});}}else a.push({type:"line",x1:h,y1:i,x2:h,y2:o,stroke:d,strokeWidth:1}),l.label&&a.push({type:"text",content:l.label,x:h,y:i-6,anchor:"middle",fontSize:11,fill:d});}return a}function ye(r,t,e,n,s){let i=c.markerSize;switch(s){case "circle":r.push({type:"circle",cx:t,cy:e,r:i,fill:n});break;case "square":r.push({type:"rect",x:t-i,y:e-i,w:i*2,h:i*2,fill:n});break;case "cross":r.push({type:"line",x1:t-i,y1:e-i,x2:t+i,y2:e+i,stroke:n,strokeWidth:2}),r.push({type:"line",x1:t-i,y1:e+i,x2:t+i,y2:e-i,stroke:n,strokeWidth:2});break;case "arrow":r.push({type:"path",points:[{x:t-i,y:e+i},{x:t,y:e-i},{x:t+i,y:e+i}],stroke:n,strokeWidth:2,fill:"none"});break;case "diamond":r.push({type:"path",points:[{x:t,y:e-i},{x:t+i,y:e},{x:t,y:e+i},{x:t-i,y:e}],fill:n,stroke:"none"});break;case "triangle":r.push({type:"path",points:[{x:t,y:e-i},{x:t+i,y:e+i},{x:t-i,y:e+i}],fill:n,stroke:"none"});break;case "star":{let o=[],a=i*.4;for(let l=0;l<10;l++){let h=l%2===0?i:a,d=Math.PI/2*3+l*Math.PI/5;o.push({x:t+h*Math.cos(d),y:e+h*Math.sin(d)});}r.push({type:"path",points:o,fill:n,stroke:"none"});break}case "plus":r.push({type:"line",x1:t-i,y1:e,x2:t+i,y2:e,stroke:n,strokeWidth:2}),r.push({type:"line",x1:t,y1:e-i,x2:t,y2:e+i,stroke:n,strokeWidth:2});break;case "triangle-down":r.push({type:"path",points:[{x:t,y:e+i},{x:t+i,y:e-i},{x:t-i,y:e-i}],fill:n,stroke:"none"});break;case "hexagon":{let o=[];for(let a=0;a<6;a++){let l=a*(Math.PI/3);o.push({x:t+i*Math.cos(l),y:e+i*Math.sin(l)});}r.push({type:"path",points:o,fill:n,stroke:"none"});break}case "hourglass":r.push({type:"path",points:[{x:t-i,y:e-i},{x:t+i,y:e-i},{x:t-i,y:e+i},{x:t+i,y:e+i}],fill:n,stroke:"none"});break;case "line-horizontal":r.push({type:"line",x1:t-i,y1:e,x2:t+i,y2:e,stroke:n,strokeWidth:2});break}}function Xt(r){let{annotations:t,timeScale:e,valueScales:n}=r,s=[],i=o=>{let a=n.get(o.axis??0)??n.values().next().value;return {x:e.map(o.time),y:a?a.map(o.value):0}};for(let o of t){let a=[],l=h=>a.push(h);switch(o.type){case "line":{let h=i(o.from),d=i(o.to);l({type:"line",x1:h.x,y1:h.y,x2:d.x,y2:d.y,stroke:o.color??c.annotationColor,strokeWidth:o.width??c.annotationWidth,dash:o.dash});break}case "arrow":{let h=i(o.from),d=i(o.to),m=o.color??c.annotationColor,u=o.headSize??c.annotationHead;l({type:"line",x1:h.x,y1:h.y,x2:d.x,y2:d.y,stroke:m,strokeWidth:o.width??c.annotationWidth});let f=Math.hypot(d.x-h.x,d.y-h.y)||1,p=(d.x-h.x)/f,y=(d.y-h.y)/f,b=d.x-p*u,S=d.y-y*u;l({type:"path",points:[{x:d.x,y:d.y},{x:b-y*u*.5,y:S+p*u*.5},{x:b+y*u*.5,y:S-p*u*.5}],fill:m,stroke:"none"});break}case "rect":{let h=i(o.from),d=i(o.to);l({type:"rect",x:Math.min(h.x,d.x),y:Math.min(h.y,d.y),w:Math.abs(d.x-h.x),h:Math.abs(d.y-h.y),fill:o.fill??"none",stroke:o.stroke,opacity:o.opacity});break}case "point":{let h=i(o.at),d=o.color??"#334155",m=o.radius??c.annotationRadius,u=o.shape??"circle";u==="circle"?l({type:"circle",cx:h.x,cy:h.y,r:m,fill:d}):u==="square"?l({type:"rect",x:h.x-m,y:h.y-m,w:m*2,h:m*2,fill:d}):(l({type:"line",x1:h.x-m,y1:h.y-m,x2:h.x+m,y2:h.y+m,stroke:d,strokeWidth:1.5}),l({type:"line",x1:h.x-m,y1:h.y+m,x2:h.x+m,y2:h.y-m,stroke:d,strokeWidth:1.5}));break}case "label":{let h=i(o.at);l({type:"text",content:o.text,x:h.x+(o.dx??0),y:h.y+(o.dy??0),anchor:o.anchor??"middle",fontSize:c.annotationFontSize,fill:o.color??c.annotationColor,rotate:o.rotate});break}}if(o.id&&a.length>0){let h=it(o.id);s.push({type:"group",cssClass:`annotation annotation--${h}`,commands:a});}else s.push(...a);}return s}var K=12,ct=8,_t=20,be=11,kt=18,vt=r=>r.length*be*.6;function qt(r,t="vertical"){if(t==="horizontal"){let n=0;for(let s of r)n+=K+ct+vt(s.name)+kt;return {width:Math.max(0,n-kt),height:_t}}let e=0;for(let n of r)e=Math.max(e,vt(n.name));return {width:K+ct+e,height:r.length*_t}}function Ut(r){let{items:t,x:e,y:n,orientation:s="vertical"}=r,i=[],o=e;return t.forEach((a,l)=>{let h=s==="horizontal"?o:e,d=s==="horizontal"?n:n+l*_t;i.push({type:"rect",x:h,y:d,w:K,h:K,fill:a.color,stroke:c.legendStroke,strokeWidth:1}),i.push({type:"text",content:a.name,x:h+K+ct,y:d+K-2,fontSize:c.legendFont,fill:c.legendText}),s==="horizontal"&&(o+=K+ct+vt(a.name)+kt);}),{type:"group",cssClass:"chart-legend",commands:i}}function Kt(r){let{xTicks:t,yTicks:e,xRange:n,yRange:s,stroke:i=c.gridStroke,strokeWidth:o=c.gridStrokeWidth,dashed:a=false,opacity:l=c.gridOpacity}=r,h=[];if(e)for(let d of e)h.push({type:"line",x1:n[0],y1:d,x2:n[1],y2:d,stroke:i,strokeWidth:o,dashed:a,opacity:l});if(t)for(let d of t)h.push({type:"line",x1:d,y1:s[0],x2:d,y2:s[1],stroke:i,strokeWidth:o,dashed:a,opacity:l});return h}function Zt(r,t,e){let n=r??t;if(n==="series")return null;if(n==="chartTop")return e.chartTop;if(n==="chartBottom")return e.chartBottom;if(typeof n=="object"&&"threshold"in n){let s=e.thresholds.get(n.threshold);if(!s)throw new Error(`fillSpec region references unknown threshold '${n.threshold}'`);return e.valueScale.map(s.value)}return typeof n=="object"&&"value"in n?e.valueScale.map(n.value):null}function xe(r){return typeof r=="string"?{color:r}:{color:r.color,hatch:r.hatch}}function Qt(r,t,e){let n=Zt(r.from,"chartBottom",t),s=Zt(r.to,"series",t),{color:i,hatch:o}=xe(r.fill),a={type:"path",fill:i,hatch:o,stroke:"none",...t.idPrefix&&{id:`${t.idPrefix}-fill-r${e}`}};if(n!==null&&s!==null){let u=t.timeScale.range(),f=u[0],p=u[1],y=Math.min(n,s),b=Math.max(n,s);return [{...a,points:[{x:f,y},{x:p,y},{x:p,y:b},{x:f,y:b}]}]}let l=n??s,h=[],d=Se(r,t);if(d===null){let u=t.valueScale.domain();d=(n??s)===t.chartBottom?u[0]:u[1];}let m=Jt(r.outer,t);for(let u of t.runs){if(u.length<2)continue;let f=W.splitByThreshold(u,d,y=>y.value??d,W.interpolateDataPoint),p=r.side==="above"?f.above:r.side==="below"?f.below:[...f.above,...f.below];if(m!==null&&r.side){let y=r.side==="above"?"below":"above";p=p.flatMap(b=>{if(b.length<2)return [];let S=W.splitByThreshold(b,m,k=>k.value??m,W.interpolateDataPoint);return y==="above"?S.above:S.below});}for(let y of p){if(y.length<2)continue;let b=y.map(k=>({x:t.timeScale.map(k.time),y:t.valueScale.map(k.value)})),S=[...b].reverse().map(k=>({x:k.x,y:l}));h.push({...a,smoothing:t.smoothing,smoothCount:b.length,points:[...b,...S]});}}return h}function Se(r,t){let e=r.from==="series"?r.to:r.from;return Jt(e,t)}function Jt(r,t){return r===void 0||r==="series"||r==="chartTop"||r==="chartBottom"?null:typeof r=="object"&&"threshold"in r?t.thresholds.get(r.threshold)?.value??null:typeof r=="object"&&"value"in r?r.value:null}function te(r,t){if(typeof r=="string"||!("regions"in r))return Qt({fill:r},t,0);let e=[];return r.regions.forEach((n,s)=>{e.push(...Qt(n,t,s));}),e}function ee(r,t){let e=new Array(r.length),n=0;for(let s=0;s<r.length;s++){let i=r[s].time,o=i-t;for(;n<s&&r[n].time<o;)n++;let a=0,l=0;for(let h=n;h<=s;h++){let d=r[h].value;d!==null&&(a+=d,l++);}e[s]={time:i,value:l===0?null:a/l,synthetic:true};}return e}function ie(r){let t=r.style?.line,e=t&&!Array.isArray(t)?t:void 0;return {color:e?.color??c.stroke,width:e?.width??c.strokeWidth,dash:e?.style,smoothing:e?.smoothing??false}}function ne(r,t,e,n){let s=r.filter(l=>l.value!==null);if(s.length<2)return [];let i=s.map(l=>({x:t.timeScale.map(l.time),y:t.valueScale.map(l.value)})),o=ie(e);return [{type:"path",id:t.idPrefix?`${t.idPrefix}-overlay-${n}`:`overlay-${n}`,points:i,stroke:o.color,strokeWidth:o.width,smoothing:o.smoothing,dash:o.dash,fill:"none"}]}function re(r,t){switch(r.kind){case "movingAverage":{r.type;let e=ee(t.data,r.window);return ne(e,t,r,"movingAvg")}case "movingMkt":{let e=jt(t.data,r.window,r.activationEnergy);return ne(e,t,r,"movingMkt")}case "limits":{let e=[],n=t.timeScale.range(),s=n[0],i=n[1],o=ie(r),a=o.color,l=o.width,h=o.dash??"dashed",d=t.idPrefix?`${t.idPrefix}-`:"";return r.high!==void 0&&e.push({type:"line",id:`${d}overlay-limit-high`,x1:s,y1:t.valueScale.map(r.high),x2:i,y2:t.valueScale.map(r.high),stroke:a,strokeWidth:l,dash:h}),r.low!==void 0&&e.push({type:"line",id:`${d}overlay-limit-low`,x1:s,y1:t.valueScale.map(r.low),x2:i,y2:t.valueScale.map(r.low),stroke:a,strokeWidth:l,dash:h}),e}case "stdDevBand":{let e=r.multiplier??1,n=ee(t.data,r.window),s=It(t.data,r.window),i=[],o=[];for(let y=0;y<n.length;y++){let b=n[y].value,S=s[y].value;if(b===null||S===null)continue;let k=t.timeScale.map(n[y].time);i.push({x:k,y:t.valueScale.map(b+e*S)}),o.push({x:k,y:t.valueScale.map(b-e*S)});}if(i.length<2)return [];let a=t.idPrefix?`${t.idPrefix}-`:"",l=[],d=(typeof r.style?.fill=="string"||r.style?.fill&&!("regions"in r.style.fill)?r.style.fill:void 0)??"#94a3b833",{color:m,hatch:u}=we(d);l.push({type:"path",id:`${a}overlay-stdDevBand`,points:[...i,...[...o].reverse()],fill:m,hatch:u,stroke:"none"});let f=r.style?.line,p=f&&!Array.isArray(f)?f:void 0;if(p){let y=n.filter(b=>b.value!==null).map(b=>({x:t.timeScale.map(b.time),y:t.valueScale.map(b.value)}));y.length>=2&&l.push({type:"path",id:`${a}overlay-stdDevBand-mean`,points:y,stroke:p.color??c.stroke,strokeWidth:p.width??1.5,smoothing:p.smoothing,dash:p.style,fill:"none"});}return l}}}function we(r){return typeof r=="string"?{color:r}:{color:r.color,hatch:r.hatch}}function _e(r){if(!r)return {gaps:[],autoDetect:false,minGapMs:6e4};if(Array.isArray(r))return {gaps:r,autoDetect:false,minGapMs:6e4};let t=r.regions??[],e=r.style;return {gaps:t.map(s=>{let i={...e,...s.style},o=i.fill,a,l;return typeof o=="string"?a=o:o&&(a=o.color,l=o.hatch),{startTime:s.startTime,endTime:s.endTime,label:s.label,fill:a,hatch:l,fillOpacity:i.opacity,labelBaseline:i.label?.baseline,rotate:i.label?.rotate,style:i.display==="filled"||i.display==="bridge_line"?void 0:i.display}}),autoDetect:r.autoDetect??false,minGapMs:r.minGapMs??6e4}}function pt(r){return "showAs"in r&&!!r.showAs}var Z=class{_layout;_renderer;_locale;_legend;_markers;_thresholds;_highlights;_gaps;_gapsAutoDetect;_gapsMinGapMs;_annotations;_annotationBands;_disabledAnnotations=new Set;_annotationSeq=0;_axes;_series;_annotationBandHeight=0;_timeScale;_valueScales=new Map;constructor(t={}){this._layout=new nt({width:t.width??800,height:t.height??400,margin:t.margin??{top:20,right:20,bottom:40,left:60}}).compute(),this._renderer=t.renderer,this._locale=t.locale,this._legend=t.legend,this._markers=t.markers??[],this._thresholds=t.thresholds??[],this._highlights=t.highlights??[];let e=_e(t.gaps);this._gaps=e.gaps,this._gapsAutoDetect=e.autoDetect,this._gapsMinGapMs=e.minGapMs,this._annotations=t.annotations??[],this._annotationBands=t.annotationBands??[],this._axes=t.axes,this._series=[],t.series&&this.setData(t.series);}getWidth(){return this._layout.totalWidth}getHeight(){return this._layout.totalHeight+this._annotationBandTotalHeight()}get series(){return this._series}_annotationBandTotalHeight(){let t=0;for(let e of this._annotationBands){let n=e.height??12,s=e.spacing??0;(e.showAxis??false)&&(t+=26+s),t+=n+s;}return t}setData(t){this._series=t.filter(e=>Array.isArray(e.data));}addAnnotation(t){let e=t.id??`anno-${++this._annotationSeq}`;return this._annotations.push({...t,id:e}),e}removeAnnotation(t){let e=this._annotations.length;return this._annotations=this._annotations.filter(n=>n.id!==t),this._disabledAnnotations.delete(t),this._annotations.length<e}setAnnotations(t){this._annotations=[...t],this._disabledAnnotations.clear();}clearAnnotations(){this._annotations=[],this._disabledAnnotations.clear();}getAnnotations(){return this._annotations}disableAnnotation(t){this._disabledAnnotations.add(t);}enableAnnotation(t){this._disabledAnnotations.delete(t);}_axisIndexOf(t){return t.yAxisIndex??0}_timesOf(t){return t.data.map(e=>e.time)}_valuesOf(t){if(pt(t)){let e=[];for(let n of t.data)n.min!==null&&e.push(n.min),n.max!==null&&e.push(n.max);return e}return t.data.map(e=>e.value).filter(e=>e!==null)}renderCommands(){if(this._series.length===0)return [];let t=this._legendItems(),e=(this._legend?.show??false)&&t.length>0,n=this._legend?.position??"inside-right",s=this._legend?.orientation??"vertical",i=e?qt(t,s):{width:0},o=this._layout;if(e&&(n==="outside-right"||n==="outside-left")){let g=i.width+16,x={...this._layout.margin};n==="outside-right"?x.right+=g:x.left+=g,o=new nt({width:this._layout.totalWidth,height:this._layout.totalHeight,margin:x}).compute();}let{chartX:a,chartY:l,chartWidth:h,chartHeight:d}=o,m=[a,a+h],u=[l,l+d],f=[];for(let g of this._series)g.data.sort((x,_)=>x.time-_.time);let p=new Map,y=1/0,b=-1/0,S=false;for(let g of this._series){let x=this._axisIndexOf(g),_=p.get(x);_?_.push(g):p.set(x,[g]);for(let A of this._timesOf(g))A<y&&(y=A),A>b&&(b=A),S=true;}if(!S)return [];let k=this._axes?.x?.domain,I=k&&k!=="auto"?k:[y,b];this._timeScale=new J({domain:I,range:m,locale:this._locale});let D=g=>({axisColor:g?.color??c.axisColor,tickColor:g?.color??c.tickColor,textColor:c.textColor,textSize:c.textSize,axisWidth:g?.width}),O=new tt({domain:I,xRange:m,y:l+d,locale:this._locale,format:this._axes?.x?.format,maxTicks:this._axes?.x?.ticks?.major,colors:D(this._axes?.x?.axis)});this._valueScales.clear();let H=Array.from(p.keys()).sort((g,x)=>g-x),R,G=0,B=0;for(let g of H){let x=p.get(g),_=1/0,A=-1/0,L=false;for(let Y of x)for(let at of this._valuesOf(Y))at<_&&(_=at),at>A&&(A=at),L=true;if(!L)continue;let F;this._axes?.y&&this._axes.y.length>g?F=this._axes.y[g]:g===0?F=this._axes?.left:g===1&&(F=this._axes?.right);let yt=F?.domain,Q=yt&&yt!=="auto"?yt:[_,A],Ft=new U({domain:Q,range:[l+d,l]});this._valueScales.set(g,Ft);let Wt=this._thresholds.filter(Y=>(Y.axisIndex??0)===g&&Y.label!==false&&Y.value>=Math.min(Q[0],Q[1])&&Y.value<=Math.max(Q[0],Q[1])).map(Y=>Ft.map(Y.value)),bt=F?.position??(g===0?"left":"right"),xt;bt==="right"?(xt=a+h+B*50,B++):(xt=a-G*50,G++);let Ht=new lt({domain:Q,range:[l+d,l],x:xt,position:bt,format:F?.format,ticks:F?.ticks?.major,colors:D(F?.axis),suppressLabelsNear:Wt.length?Wt:void 0});g===0&&(R=Ht),f.push({type:"group",cssClass:`value-axis ${bt}`,commands:Ht.render()});}let w=this._valueScales.get(0)??this._valueScales.get(H[0]);f.push({type:"group",cssClass:"time-axis",commands:O.render()});let v=null,C=this._axes?.x?.grid?.major,M=this._axes?.left?.grid?.major;if(C!==void 0||M!==void 0){let g=C!==false,x=M!==false&&!!R,_=g?O.generateTicks().map(L=>L.x):void 0,A=x?R.generateTicks().map(L=>L.position):void 0;if(_||A){let L=(C&&typeof C=="object"?C:void 0)??(M&&typeof M=="object"?M:void 0);v={type:"group",cssClass:"chart-grid",commands:Kt({xTicks:_,yTicks:A,xRange:m,yRange:u,stroke:L?.color,opacity:L?.opacity,dashed:L?.style==="dashed"})};}}if(this._highlights.length>0&&f.push({type:"group",cssClass:"highlights",commands:Nt({highlights:this._highlights,timeScale:this._timeScale,yRange:u,height:o.totalHeight})}),this._thresholds.length>0&&w){let g=[],x=[];for(let _ of this._thresholds){let A=_.id??it(_.name),L=this._valueScales.get(_.axisIndex??0)??w,F=Vt({thresholds:[_],valueScale:L,xRange:m});F.inside.length&&g.push({type:"group",cssClass:`threshold threshold--${A}`,id:`threshold-${A}`,commands:F.inside}),F.labels.length&&x.push({type:"group",cssClass:`threshold-label threshold-label--${A}`,commands:F.labels});}g.length&&f.push({type:"group",cssClass:"thresholds",commands:g,clipRect:{x:a,y:l,w:h,h:d}}),x.length&&f.push({type:"group",cssClass:"threshold-labels",commands:x});}let T=this._gaps;if(this._gapsAutoDetect){let g=[];for(let x of this._series)pt(x)||g.push(...Ot(x.data,this._gapsMinGapMs));g.length>0&&(T=[...this._gaps,...g]);}T.length>0&&f.push({type:"group",cssClass:"gaps",commands:zt({gaps:T,timeScale:this._timeScale,yRange:u})});let $=new Map(this._thresholds.map(g=>[g.name,g]));for(let g of this._series){if(g.data.length===0)continue;let x=this._valueScales.get(this._axisIndexOf(g));if(!x)continue;let _=g.id??it(g.name);f.push({type:"group",cssClass:`series series--${_}`,id:`series-${_}`,commands:this._renderSeries(g,x,$)});}v&&f.push(v);let j=this._markers.map(g=>({...g}));for(let g of j)if(g.value===void 0&&(g.lineStyle==="to-value"||g.lineStyle==="to-top")){let x=this._series[g.seriesIndex??0];x&&!pt(x)&&x.data.length>=2&&(g.value=this._interpolateValue(g.time,x.data));}j.length>0&&w&&f.push({type:"group",cssClass:"markers",commands:Yt({markers:j,timeScale:this._timeScale,valueScale:w,yRange:u})});let z=this._annotations.filter(g=>!g.id||!this._disabledAnnotations.has(g.id));if(z.length>0&&f.push({type:"group",cssClass:"annotations",commands:Xt({annotations:z,timeScale:this._timeScale,valueScales:this._valueScales})}),this._annotationBands.length>0){let g=l+d+this._layout.margin.bottom,x=0;this._annotationBands.forEach(_=>{let A=_.height??12,L=_.spacing??0,F=g+x;(_.showAxis??false)&&(x+=26+L),x+=A+L,f.push({type:"group",cssClass:"annotation-band",commands:new mt({name:_.name,showAxis:_.showAxis??false,items:_.items,timeScale:this._timeScale,background:_.background,hatch:_.hatch},[a,a+h],F,A).render()});});}if(e&&n!=="separate"){let g,x;n==="inside-right"?(g=a+h-i.width-8,x=l+8):n==="inside-left"?(g=a+8,x=l+8):n==="outside-right"?(g=a+h+16,x=l):(g=8,x=l),f.push(Ut({items:t,x:g,y:x,orientation:s}));}let P=this._axes?.left?.label,E=this._axes?.right?.label,q=this._axes?.x?.label;if(P||E||q){let g=[],x=l+d/2,_=this._axes?.left?.labels,A=this._axes?.right?.labels,L=this._axes?.x?.labels;P&&g.push({type:"text",content:P,x:14,y:x,anchor:"middle",fontSize:_?.fontSize??c.axisLabelSize,fill:_?.color??c.axisLabelColor,rotate:-90}),E&&g.push({type:"text",content:E,x:o.totalWidth-14,y:x,anchor:"middle",fontSize:A?.fontSize??c.axisLabelSize,fill:A?.color??c.axisLabelColor,rotate:90}),q&&g.push({type:"text",content:q,x:a+h/2,y:o.totalHeight-6,anchor:"middle",fontSize:L?.fontSize??c.axisLabelSize,fill:L?.color??c.axisLabelColor}),g.length&&f.push({type:"group",cssClass:"axis-labels",commands:g});}return f}_renderSeries(t,e,n){let s=this._timeScale,i={timeScale:s,valueScale:e};if(pt(t)){let w=t.style?.line&&!Array.isArray(t.style.line)?t.style.line:void 0,v=typeof t.style?.fill=="string"?t.style.fill:void 0;return t.showAs==="minmaxavg"?new dt({data:t.data,timeScale:s,valueScale:e,minColor:t.minColor,maxColor:t.maxColor,avgColor:t.avgColor,avgDashed:t.avgDashed,fillToMax:t.fillToMax,fillToMaxHatch:t.fillToMaxHatch,fillToMin:t.fillToMin,fillToMinHatch:t.fillToMinHatch,smoothing:w?.smoothing,strokeWidth:w?.width,id:t.id}).render():new ut({data:t.data,timeScale:s,valueScale:e,fill:v??w?.color,avgLine:t.avgLine,countOpacity:t.countOpacity,id:t.id}).render()}let o=t,a=t.style?.line&&!Array.isArray(t.style.line)?t.style.line:void 0,l=a?.gapThreshold??c.gapThreshold,h=W.getRuns(t.data,w=>w.value===null,l),d=h.reduce((w,v)=>w+v.length,0);if(d===0)return [];let m=[],u=t.style?.markers,f=t.style?.shadow,p={stroke:a?.color??c.stroke,strokeWidth:a?.width??c.strokeWidth,smoothing:a?.smoothing,dashed:a?.style==="dashed",pointStyle:u?.type,pointSize:u?.size,pointStroke:u?.stroke,pointFill:u?.fill,pointStrokeWidth:u?.strokeWidth,shadowColor:f?.color,shadowBlur:f?.blur,shadowOffsetX:f?.offsetX,shadowOffsetY:f?.offsetY,id:t.id},y=t.style?.line,b=y&&!Array.isArray(y)?y:void 0,S=b?.color,k=b?.width,I=b?.style,D=b?.smoothing,O=t.style?.fill;if(O!==void 0){let w=e.range(),v=Math.min(w[0],w[1]),C=Math.max(w[0],w[1]);m.push(...te(O,{runs:h,timeScale:s,valueScale:e,thresholds:n,chartTop:v,chartBottom:C,smoothing:a?.smoothing,idPrefix:t.id}));}let H=o.colorByThresholds??[],R=H.map(w=>n.get(w)).filter(w=>!!w).map(w=>w.value).sort((w,v)=>w-v),G=(w,v)=>{let C=p.stroke;for(let M of v){let T=n.get(M);T&&w>=T.value&&(C=T.color??C);}return C};for(let w of h){if(w.length<2)continue;let v=W.splitByBoundaries(w,R,C=>C.value,W.interpolateDataPoint);for(let C=0;C<v.length;C++){let M=v[C];if(M.data.length<2)continue;let T=(M.data[0].value+M.data[M.data.length-1].value)/2,$=o.id,j=M.data.map(P=>({x:s.map(P.time),y:e.map(P.value)})),z=$?`${$}-line-${C}`:void 0;y===false||(y&&Array.isArray(y)?y.forEach((P,E)=>{m.push({type:"path",id:z?`${z}-${E}`:void 0,points:j,stroke:P.color??G(T,H),strokeWidth:P.width??p.strokeWidth,smoothing:P.smoothing??p.smoothing,dash:P.style,opacity:P.opacity,fill:"none",shadowColor:p.shadowColor,shadowBlur:p.shadowBlur,shadowOffsetX:p.shadowOffsetX,shadowOffsetY:p.shadowOffsetY});}):m.push({type:"path",id:z,points:j,stroke:S??G(T,H),strokeWidth:k??p.strokeWidth,smoothing:D??p.smoothing,dash:I,fill:"none",shadowColor:p.shadowColor,shadowBlur:p.shadowBlur,shadowOffsetX:p.shadowOffsetX,shadowOffsetY:p.shadowOffsetY}));}p.pointStyle&&p.pointStyle!=="none"&&d<=(u?.threshold??c.pointThreshold)&&m.push(...Et(w,i,p,C=>G(C.value,H)));}let B=t.overlays;if(B&&B.length>0){let w=e.range(),v={data:t.data,timeScale:s,valueScale:e,chartTop:Math.min(w[0],w[1]),chartBottom:Math.max(w[0],w[1]),idPrefix:t.id};for(let C of B)m.push(...re(C,v));}if(t.style?.gap&&h.length>1){let w=e.range(),v=Math.min(w[0],w[1]),C=Math.max(w[0],w[1]),M=t.style.gap,T=M.fill,$,j;typeof T=="string"?$=T:T&&($=T.color,j=T.hatch);let z=M.opacity??.15,P=M.bridge;for(let E=1;E<h.length;E++){let q=h[E-1][h[E-1].length-1],g=h[E][0],x=s.map(q.time),_=s.map(g.time);if(M.display==="bridge_line"){if(q.value===null||g.value===null)continue;let A=e.map(q.value),L=e.map(g.value);m.push({type:"line",x1:x,y1:A,x2:_,y2:L,stroke:P?.color??(typeof t.style?.line=="object"&&!Array.isArray(t.style.line)?t.style.line.color:void 0)??c.stroke,strokeWidth:P?.width??1.5,dash:P?.style??"dotted"});}else $!==void 0?m.push({type:"rect",x,y:v,w:_-x,h:C-v,fill:$,hatch:j,opacity:z,stroke:"none"}):M.display!=="empty"&&m.push({type:"rect",x,y:v,w:_-x,h:C-v,stroke:c.gapStroke,strokeWidth:1,dashed:true,fill:"none"});}}return m}_interpolateValue(t,e){for(let n=1;n<e.length;n++){let s=e[n-1],i=e[n];if(!(s.value===null||i.value===null)&&t>=s.time&&t<=i.time){let o=(t-s.time)/(i.time-s.time);return s.value+o*(i.value-s.value)}}}legendItems(){return this._legendItems()}_legendItems(){return this._series.map(t=>{let e=t.style?.line&&!Array.isArray(t.style.line)?t.style.line:void 0;return {name:t.name,color:e?.color??c.stroke}})}get renderer(){return this._renderer}get layout(){return this._layout}get timeScale(){return this._timeScale}get valueScales(){return this._valueScales}invertTime(t){return this._timeScale?this._timeScale.invert(t):0}invertValue(t,e=0){let n=this._valueScales.get(e);return n?n.invert(t):0}project(t,e,n=0){let s=this._timeScale?this._timeScale.map(t):0,i=this._valueScales.get(n);return {x:s,y:i?i.map(e):0}}};var ft=class{};var N=1e3,X=class extends ft{#t="100%";#e="100%";#n=new Map;#i=new Map;#r=new Map;constructor(t){super(),t?.width!==void 0&&(this.#t=t.width),t?.height!==void 0&&(this.#e=t.height);}render(t){this.#n.clear(),this.#i.clear(),this.#r.clear();let e=t.map(l=>this._toSVG(l)).join(`
29
29
  `),n="",s=[];for(let[,l]of this.#n)s.push(l);for(let[,l]of this.#i)s.push(l);for(let[,l]of this.#r)s.push(l);s.length>0&&(n=` <defs>
30
30
  ${s.join(`
31
31
  `)}
32
32
  </defs>
33
33
  `);let i=typeof this.#t=="number"?`${this.#t}`:this.#t,o=typeof this.#e=="number"?`${this.#e}`:this.#e,a=typeof this.#t=="number"&&typeof this.#e=="number"?` viewBox="0 0 ${this.#t} ${this.#e}"`:"";return {type:"svg",content:`<svg xmlns="http://www.w3.org/2000/svg" width="${i}" height="${o}"${a}>
34
34
  ${n} ${e}
35
- </svg>`}}_toSVG(t){switch(t.type){case "path":return this._path(t);case "line":return this._line(t);case "rect":return this._rect(t);case "circle":return this._circle(t);case "text":return this.#h(t);case "gradient":return this._gradient(t);case "gap":return this._gap(t);case "group":return this._group(t)}}#a(t,e,n){if(t.length===0)return "";if(!e||t.length<3)return t.map((a,l)=>`${l===0?"M":"L"}${a.x},${a.y}`).join(" ");let s=n!=null&&n<t.length?Math.max(n,2):t.length,i=a=>Math.round(a*100)/100,o=`M${t[0].x},${t[0].y}`;for(let a=0;a<s-1;a++){let l=t[a-1]??t[a],h=t[a],d=t[a+1],u=t[a+2]&&a+2<s?t[a+2]:d,m=i(h.x+(d.x-l.x)/6),f=i(h.y+(d.y-l.y)/6),p=i(d.x-(u.x-h.x)/6),b=i(d.y-(u.y-h.y)/6);(m=(m*z|0)/z,f=(f*z|0)/z,p=(p*z|0)/z,b=(b*z|0)/z),o+=` C${m},${f} ${p},${b} ${d.x},${d.y}`;}for(let a=s;a<t.length;a++)o+=` L${t[a].x},${t[a].y}`;return o}_hatchPattern(t,e){let n=`hatch-${t}-${this._hatchIndex++}`;if(this.#r.has(n))return n;let s=St(n,t,e??"rgba(200,220,255,0.3)");return this.#r.set(n,s),n}_hatchIndex=0;_path(t){let e=this.#a(t.points,t.smoothing,t.smoothCount),n=[];if(t.hatch){let o=this._hatchPattern(t.hatch,t.fill);n.push(`fill="url(#${o})"`);}else n.push(`fill="${t.fill?this._esc(t.fill):"none"}"`);t.stroke&&n.push(`stroke="${this._esc(t.stroke)}"`),t.strokeWidth&&n.push(`stroke-width="${t.strokeWidth}"`);let s=this.#o(t.dash,t.dashed,t.strokeWidth);s&&(n.push(`stroke-dasharray="${s.strokeDasharray}"`),s.strokeLinecap&&n.push(`stroke-linecap="${s.strokeLinecap}"`)),t.opacity!==void 0&&n.push(`opacity="${t.opacity}"`),t.id&&n.push(`id="${this._esc(t.id)}"`);let i=this.#s(t);return i&&n.push(`filter="url(#${i})"`),`<path d="${e}" ${n.join(" ")} />`}_line(t){let e=[];t.stroke&&e.push(`stroke="${this._esc(t.stroke)}"`),t.strokeWidth&&e.push(`stroke-width="${t.strokeWidth}"`);let n=this.#o(t.dash,t.dashed,t.strokeWidth);n&&(e.push(`stroke-dasharray="${n.strokeDasharray}"`),n.strokeLinecap&&e.push(`stroke-linecap="${n.strokeLinecap}"`)),t.opacity!==void 0&&e.push(`opacity="${t.opacity}"`),t.id&&e.push(`id="${this._esc(t.id)}"`);let s=this.#s(t);return s&&e.push(`filter="url(#${s})"`),`<line x1="${t.x1}" y1="${t.y1}" x2="${t.x2}" y2="${t.y2}" ${e.join(" ")} />`}_rect(t){let e=[];if(t.hatch){let s=this._hatchPattern(t.hatch,t.fill);e.push(`fill="url(#${s})"`);}else t.fill!==void 0&&e.push(`fill="${this._esc(t.fill)}"`);t.stroke&&e.push(`stroke="${this._esc(t.stroke)}"`),t.strokeWidth&&e.push(`stroke-width="${t.strokeWidth}"`),t.opacity!==void 0&&e.push(`opacity="${t.opacity}"`),t.dashed&&e.push('stroke-dasharray="4,4"'),t.id&&e.push(`id="${this._esc(t.id)}"`);let n=this.#s(t);return n&&e.push(`filter="url(#${n})"`),`<rect x="${t.x}" y="${t.y}" width="${t.w}" height="${t.h}" ${e.join(" ")} />`}_circle(t){let e=[];if(t.hatch){let s=this._hatchPattern(t.hatch,t.fill);e.push(`fill="url(#${s})"`);}else t.fill&&e.push(`fill="${this._esc(t.fill)}"`);t.stroke&&e.push(`stroke="${this._esc(t.stroke)}"`),t.strokeWidth&&e.push(`stroke-width="${t.strokeWidth}"`),t.id&&e.push(`id="${this._esc(t.id)}"`);let n=this.#s(t);return n&&e.push(`filter="url(#${n})"`),`<circle cx="${t.cx}" cy="${t.cy}" r="${t.r}" ${e.join(" ")} />`}#o(t,e,n){return t==="dashed"||!t&&e?{strokeDasharray:"4,4"}:t==="dotted"?{strokeDasharray:"2,4"}:!t||t==="solid"?null:Rt(t,n??2)}#s(t){if(!t.shadowColor)return null;let e=t.shadowBlur??0,n=t.shadowOffsetX??0,s=t.shadowOffsetY??0;if(!e&&!n&&!s)return null;let i=`shadow_${e}_${n}_${s}`;if(this.#n.has(i))return i;let o=`<filter id="${i}" x="-50%" y="-50%" width="200%" height="200%">
35
+ </svg>`}}_toSVG(t){switch(t.type){case "path":return this._path(t);case "line":return this._line(t);case "rect":return this._rect(t);case "circle":return this._circle(t);case "text":return this.#h(t);case "gradient":return this._gradient(t);case "gap":return this._gap(t);case "group":return this._group(t)}}#a(t,e,n){if(t.length===0)return "";if(!e||t.length<3)return t.map((a,l)=>`${l===0?"M":"L"}${a.x},${a.y}`).join(" ");let s=n!=null&&n<t.length?Math.max(n,2):t.length,i=a=>Math.round(a*100)/100,o=`M${t[0].x},${t[0].y}`;for(let a=0;a<s-1;a++){let l=t[a-1]??t[a],h=t[a],d=t[a+1],m=t[a+2]&&a+2<s?t[a+2]:d,u=i(h.x+(d.x-l.x)/6),f=i(h.y+(d.y-l.y)/6),p=i(d.x-(m.x-h.x)/6),y=i(d.y-(m.y-h.y)/6);(u=(u*N|0)/N,f=(f*N|0)/N,p=(p*N|0)/N,y=(y*N|0)/N),o+=` C${u},${f} ${p},${y} ${d.x},${d.y}`;}for(let a=s;a<t.length;a++)o+=` L${t[a].x},${t[a].y}`;return o}_hatchPattern(t,e){let n=`hatch-${t}-${this._hatchIndex++}`;if(this.#r.has(n))return n;let s=St(n,t,e??"rgba(200,220,255,0.3)");return this.#r.set(n,s),n}_hatchIndex=0;_path(t){let e=this.#a(t.points,t.smoothing,t.smoothCount),n=[];if(t.hatch){let o=this._hatchPattern(t.hatch,t.fill);n.push(`fill="url(#${o})"`);}else n.push(`fill="${t.fill?this._esc(t.fill):"none"}"`);t.stroke&&n.push(`stroke="${this._esc(t.stroke)}"`),t.strokeWidth&&n.push(`stroke-width="${t.strokeWidth}"`);let s=this.#o(t.dash,t.dashed,t.strokeWidth);s&&(n.push(`stroke-dasharray="${s.strokeDasharray}"`),s.strokeLinecap&&n.push(`stroke-linecap="${s.strokeLinecap}"`)),t.opacity!==void 0&&n.push(`opacity="${t.opacity}"`),t.id&&n.push(`id="${this._esc(t.id)}"`);let i=this.#s(t);return i&&n.push(`filter="url(#${i})"`),`<path d="${e}" ${n.join(" ")} />`}_line(t){let e=[];t.stroke&&e.push(`stroke="${this._esc(t.stroke)}"`),t.strokeWidth&&e.push(`stroke-width="${t.strokeWidth}"`);let n=this.#o(t.dash,t.dashed,t.strokeWidth);n&&(e.push(`stroke-dasharray="${n.strokeDasharray}"`),n.strokeLinecap&&e.push(`stroke-linecap="${n.strokeLinecap}"`)),t.opacity!==void 0&&e.push(`opacity="${t.opacity}"`),t.id&&e.push(`id="${this._esc(t.id)}"`);let s=this.#s(t);return s&&e.push(`filter="url(#${s})"`),`<line x1="${t.x1}" y1="${t.y1}" x2="${t.x2}" y2="${t.y2}" ${e.join(" ")} />`}_rect(t){let e=[];if(t.hatch){let s=this._hatchPattern(t.hatch,t.fill);e.push(`fill="url(#${s})"`);}else t.fill!==void 0&&e.push(`fill="${this._esc(t.fill)}"`);t.stroke&&e.push(`stroke="${this._esc(t.stroke)}"`),t.strokeWidth&&e.push(`stroke-width="${t.strokeWidth}"`),t.opacity!==void 0&&e.push(`opacity="${t.opacity}"`),t.dashed&&e.push('stroke-dasharray="4,4"'),t.id&&e.push(`id="${this._esc(t.id)}"`);let n=this.#s(t);return n&&e.push(`filter="url(#${n})"`),`<rect x="${t.x}" y="${t.y}" width="${t.w}" height="${t.h}" ${e.join(" ")} />`}_circle(t){let e=[];if(t.hatch){let s=this._hatchPattern(t.hatch,t.fill);e.push(`fill="url(#${s})"`);}else t.fill&&e.push(`fill="${this._esc(t.fill)}"`);t.stroke&&e.push(`stroke="${this._esc(t.stroke)}"`),t.strokeWidth&&e.push(`stroke-width="${t.strokeWidth}"`),t.id&&e.push(`id="${this._esc(t.id)}"`);let n=this.#s(t);return n&&e.push(`filter="url(#${n})"`),`<circle cx="${t.cx}" cy="${t.cy}" r="${t.r}" ${e.join(" ")} />`}#o(t,e,n){return t==="dashed"||!t&&e?{strokeDasharray:"4,4"}:t==="dotted"?{strokeDasharray:"2,4"}:!t||t==="solid"?null:Rt(t,n??2)}#s(t){if(!t.shadowColor)return null;let e=t.shadowBlur??0,n=t.shadowOffsetX??0,s=t.shadowOffsetY??0;if(!e&&!n&&!s)return null;let i=`shadow_${e}_${n}_${s}`;if(this.#n.has(i))return i;let o=`<filter id="${i}" x="-50%" y="-50%" width="200%" height="200%">
36
36
  <feDropShadow dx="${n}" dy="${s}" stdDeviation="${e/2}" flood-color="${this._esc(t.shadowColor)}" />
37
37
  </filter>`;return this.#n.set(i,o),i}#l(t,e,n,s,i){this.#i.has(t)||this.#i.set(t,`<clipPath id="${t}">
38
38
  <rect x="${e}" y="${n}" width="${s}" height="${i}" />
@@ -47,7 +47,7 @@ ${n}
47
47
  `)}`).join(`
48
48
  `),n=t.cssClass?` class="${this._esc(t.cssClass)}"`:"",s=t.id?` id="${this._esc(t.id)}"`:"",i=t.plotClipId||(t.clipRect?"clip-plot":null),o=i?` clip-path="url(#${this._esc(i)})"`:"";return `<g${n}${s}${o}>
49
49
  ${e}
50
- </g>`}_esc(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}};var se="http://www.w3.org/2000/svg";function ke(r){let t=r.style?.line;return t&&!Array.isArray(t)&&t.color?t.color:c.stroke}function oe(r){return r.replace(/[&<>"']/g,t=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"})[t])}function ve(r){if(r.length===0)return "";let t=new Date(r[0].time).toLocaleString(),e=r.map(n=>`<div><span class="mlc-tooltip__name">${oe(n.series.name)}:</span> ${n.value.toFixed(2)}</div>`);return `<div class="mlc-tooltip__time">${oe(t)}</div>${e.join("")}`}function Ce(r,t){if(r.length===0)return;let e=0,n=r.length-1;for(;e<n;){let o=e+n>>1;r[o].time<t?e=o+1:n=o;}let s=r[Math.max(0,e-1)],i=r[e];return Math.abs(s.time-t)<=Math.abs(i.time-t)?s:i}function Te(r){return "value"in r?r.value:r.avg}function ot(r,t,e={}){let n=r.querySelector("svg");if(!n)throw new Error("attachTooltip: target has no <svg> child (did you mount the chart first?)");let s=e.format??ve,i=e.snapRadius??1/0,o=e.className??"mlc-tooltip",a=e.showPicks??true,l=e.pickRadius??5,h=e.picksClassName??"mlc-tooltip-picks",d=document.createElement("div");d.className=o,d.style.position="absolute",d.style.pointerEvents="none",d.style.display="none",getComputedStyle(r).position==="static"&&(r.style.position="relative"),r.appendChild(d);let u=null;a&&(u=document.createElementNS(se,"g"),u.setAttribute("class",h),u.setAttribute("pointer-events","none"),n.appendChild(u));let m=()=>{u&&u.replaceChildren();},f=t.series.map((w,k)=>({data:w.data.map(L=>({time:L.time,value:Te(L)})).filter(L=>L.value!==null).sort((L,R)=>L.time-R.time),series:w,index:k})),p=w=>{let k=n.getBoundingClientRect(),O=t.getWidth?.()??k.width,L=(w.clientX-k.left)*O/Math.max(1,k.width);t.getHeight?.()??k.height;let W=t.invertTime(L);if(!Number.isFinite(W)){d.style.display="none";return}let H=[];for(let $ of f){let y=Ce($.data,W);if(!y)continue;let v=t.project(y.time,y.value,$.series.yAxisIndex??0).x,C=t.project(y.time,y.value,$.series.yAxisIndex??0).y;Math.abs(v-L)>i||H.push({seriesIndex:$.index,series:$.series,time:y.time,value:y.value,x:v,y:C});}if(H.length===0){d.style.display="none",m();return}d.innerHTML=s(H);let j=r.getBoundingClientRect();if(d.style.left=`${w.clientX-j.left}px`,d.style.top=`${w.clientY-j.top}px`,d.style.display="",u){u.replaceChildren();for(let $ of H){let y=document.createElementNS(se,"circle");y.setAttribute("cx",String($.x)),y.setAttribute("cy",String($.y)),y.setAttribute("r",String(l)),y.setAttribute("fill","#ffffff"),y.setAttribute("stroke",ke($.series)),y.setAttribute("stroke-width","2"),y.setAttribute("class",`${h}__dot`),u.appendChild(y);}}},b=()=>{d.style.display="none",m();};n.addEventListener("mousemove",p),n.addEventListener("mouseleave",b);let x=false;return ()=>{x||(x=true,n.removeEventListener("mousemove",p),n.removeEventListener("mouseleave",b),d.remove(),u&&u.remove());}}function $e(r,t={}){let e=typeof r=="string"?document.querySelector(r):r;if(!e)throw new Error(`mount: target ${typeof r=="string"?`'${r}'`:""} not found`);let{tooltip:n,...s}=t,i=s.width??e.clientWidth??800,o=s.height??350,a=new Z({...s,width:i,height:o}),{content:l}=new X().render(a.renderCommands());e.innerHTML=l;let h=e.querySelector("svg");return h&&(h.setAttribute("viewBox",`0 0 ${i} ${a.getHeight()}`),h.setAttribute("width","100%"),h.setAttribute("height",String(a.getHeight()))),n?.show&&ot(e,a,n),a}var Ct=class{_opts;_series=[];_thresholds=[];_annotations=[];_highlights=[];_markers=[];_bands=[];_tooltip;constructor(t,e){this._opts={},t!==void 0&&(this._opts.width=t),e!==void 0&&(this._opts.height=e);}setWidth(t){return this._opts.width=t,this}setHeight(t){return this._opts.height=t,this}setSize(t,e){return this._opts.width=t,this._opts.height=e,this}setMargin(t,e,n,s){return typeof t=="object"?this._opts.margin=t:this._opts.margin={top:t,right:e??0,bottom:n??0,left:s??0},this}setLocale(t){return this._opts.locale=t,this}setAxes(t){return this._opts.axes=t,this}setXAxis(t){return this._opts.axes={...this._opts.axes,x:{...this._opts.axes?.x,...t}},this}setLeftAxis(t){return this._opts.axes={...this._opts.axes,left:{...this._opts.axes?.left,...t}},this}setRightAxis(t){return this._opts.axes={...this._opts.axes,right:{...this._opts.axes?.right,...t}},this}setYAxis(t,e){this._opts.axes||(this._opts.axes={}),this._opts.axes.y||(this._opts.axes.y=[]);let n=[...this._opts.axes.y];for(;n.length<=t;)n.push({});return n[t]={...n[t],...e},this._opts.axes.y=n,this}setLegend(t,e,n){return typeof t=="object"?this._opts.legend=t:this._opts.legend={show:t,position:e,orientation:n},this}setGaps(t){return this._opts.gaps=t,this}setTooltip(t){return this._tooltip={show:true,...t},this}addSeries(t){return this._series.push(t),this}addSeriesAll(t){return this._series.push(...t),this}addThreshold(t){return this._thresholds.push(t),this}addThresholds(t){return this._thresholds.push(...t),this}addAnnotation(t){return this._annotations.push(t),this}addAnnotations(t){return this._annotations.push(...t),this}addHighlight(t){return this._highlights.push(t),this}addMarker(t){return this._markers.push(t),this}addAnnotationBand(t){return this._bands.push(t),this}clear(t){return (!t||t==="series")&&(this._series=[]),(!t||t==="thresholds")&&(this._thresholds=[]),(!t||t==="annotations")&&(this._annotations=[]),(!t||t==="highlights")&&(this._highlights=[]),(!t||t==="markers")&&(this._markers=[]),(!t||t==="bands")&&(this._bands=[]),this}toOptions(){return {...this._opts,series:this._series.length?this._series:this._opts.series,thresholds:this._thresholds.length?this._thresholds:this._opts.thresholds,annotations:this._annotations.length?this._annotations:this._opts.annotations,highlights:this._highlights.length?this._highlights:this._opts.highlights,markers:this._markers.length?this._markers:this._opts.markers,annotationBands:this._bands.length?this._bands:this._opts.annotationBands}}build(){return new Z(this.toOptions())}getSvg(){let t=this.build(),{content:e}=new X().render(t.renderCommands());return e}mount(t){let e=typeof t=="string"?document.querySelector(t):t;if(!e)throw new Error(`GraphBuilder.mount: target ${typeof t=="string"?`'${t}'`:""} not found`);this._opts.width||(this._opts.width=e.clientWidth||800);let n=this.build(),{content:s}=new X().render(n.renderCommands());e.innerHTML=s;let i=e.querySelector("svg");if(i){let o=this._opts.width??800;i.setAttribute("viewBox",`0 0 ${o} ${n.getHeight()}`),i.setAttribute("width","100%"),i.setAttribute("height",String(n.getHeight()));}return this._tooltip?.show&&ot(e,n,this._tooltip),n}},Tt=class{_series;constructor(t){this._series={name:t,data:[]};}addPoint(t,e){return this._series.data.push({time:t,value:e}),this}addPoints(t){return this._series.data.push(...t),this}addFloats(t,e){let n=Math.min(t.length,e.length);for(let s=0;s<n;s++)this._series.data.push({time:t[s],value:e[s]});return this}addNullPoint(t){return this._series.data.push({time:t,value:null}),this}setStyle(t){return this._series.style=t,this}setLineStyle(t,e,n){return this._series.style||(this._series.style={}),this._series.style.line={color:t,width:e,style:n},this}setSmoothing(t){return this._series.style||(this._series.style={}),!this._series.style.line||typeof this._series.style.line=="boolean"?this._series.style.line={smoothing:t}:Array.isArray(this._series.style.line)?this._series.style.line.length===0?this._series.style.line=[{smoothing:t}]:this._series.style.line[0].smoothing=t:this._series.style.line.smoothing=t,this}setFill(t){return this._series.style||(this._series.style={}),this._series.style.fill=t,this}setID(t){return this._series.id=t,this}setColorByThresholds(t){return this._series.colorByThresholds=t,this}build(){return this._series}},$t=class{_threshold;constructor(t,e){this._threshold={name:t,value:e};}setColor(t){return this._threshold.color=t,this}setLine(t){return this._threshold.line=t,this}setFill(t,e){return this._threshold.fill=t,this._threshold.fillOpacity=e,this}setFillHatch(t){return this._threshold.fillHatch=t,this}setLabel(t,e){return this._threshold.label={text:t,position:e},this}setID(t){return this._threshold.id=t,this}build(){return this._threshold}},At=class{_marker;constructor(t){this._marker={time:t};}setValue(t){return this._marker.value=t,this}setLabel(t){return this._marker.label=t,this}setColor(t){return this._marker.color=t,this}setPointStyle(t){return this._marker.pointStyle=t,this}setLineStyle(t){return t==="none"?delete this._marker.lineStyle:this._marker.lineStyle=t,this}setSeriesIndex(t){return this._marker.seriesIndex=t,this}build(){return this._marker}},Mt=class{_highlight;constructor(t,e){this._highlight={startTime:t,endTime:e};}setLabel(t){return this._highlight.label=t,this}setColor(t){return this._highlight.color=t,this}setOpacity(t){return this._highlight.opacity=t,this}setLabelPosition(t){return this._highlight.labelPosition=t,this}setRotate(t){return this._highlight.rotate=t,this}build(){return this._highlight}},Lt=class{_ann;constructor(t){this._ann={type:t};}setID(t){return this._ann.id=t,this}setTitle(t){return this._ann.title=t,this}setFrom(t,e,n){return this._ann.from={time:t,value:e,axis:n},this}setTo(t,e,n){return this._ann.to={time:t,value:e,axis:n},this}setAt(t,e,n){return this._ann.at={time:t,value:e,axis:n},this}setColor(t){return this._ann.color=t,this}setWidth(t){return this._ann.width=t,this}setDash(t){return this._ann.dash=t,this}setHeadSize(t){return this._ann.headSize=t,this}setFill(t){return this._ann.fill=t,this}setHatch(t){return this._ann.hatch=t,this}setStroke(t){return this._ann.stroke=t,this}setOpacity(t){return this._ann.opacity=t,this}setRadius(t){return this._ann.radius=t,this}setShape(t){return this._ann.shape=t,this}setText(t){return this._ann.text=t,this}setAnchor(t){return this._ann.anchor=t,this}setDx(t){return this._ann.dx=t,this}setDy(t){return this._ann.dy=t,this}setRotate(t){return this._ann.rotate=t,this}build(){return this._ann}},Dt=class{_band;constructor(t){this._band={name:t,items:[]};}setHeight(t){return this._band.height=t,this}setSpacing(t){return this._band.spacing=t,this}setHatch(t){return this._band.hatch=t,this}setShowAxis(t){return this._band.showAxis=t,this}setShowInLegend(t){return this._band.showInLegend=t,this}setBackground(t){return this._band.background=t,this}addItem(t){return this._band.items.push(t),this}build(){return this._band}},Pt=class{_item;constructor(t,e){this._item={startTime:t,endTime:e};}setFill(t){return this._item.fill=t,this}setHatch(t){return this._item.hatch=t,this}setStroke(t){return this._item.stroke=t,this}setStrokeWidth(t){return this._item.strokeWidth=t,this}setLabel(t,e,n,s){return this._item.label=t,e!==void 0&&(this._item.labelFontSize=e),n!==void 0&&(this._item.labelFill=n),s!==void 0&&(this._item.labelBaseline=s),this}build(){return this._item}};function Ae(r){let{thresholds:t,colors:e,hatches:n}=r;if(e.length!==t.length+1)throw new Error(`fillBetweenThresholds: expected ${t.length+1} colors for ${t.length} thresholds, got ${e.length}`);if(n!==void 0&&n.length!==e.length)throw new Error(`fillBetweenThresholds: hatches length (${n.length}) must equal colors length (${e.length})`);return {regions:e.map((i,o)=>{let a=n?.[o],l=a?{color:i,hatch:a}:i;return o===0?{to:{threshold:t[0]},fill:l}:o===e.length-1?{from:{threshold:t[t.length-1]},fill:l}:{from:{threshold:t[o-1]},to:{threshold:t[o]},fill:l}})}}function Bt(r){if(!r||typeof r!="object")throw new Error("DataPoint: object expected");let{time:t,value:e,annotation:n}=r;if(typeof t!="number"||isNaN(t))throw new Error(`DataPoint: invalid time=${t}`);if(e!==null&&(typeof e!="number"||isNaN(e)))throw new Error(`DataPoint: invalid value=${e}`);return {time:t,value:e,annotation:n&&typeof n=="string"?n:void 0}}function Me(r){if(Array.isArray(r))return r.map(Bt);if(r&&typeof r=="object"){let t=r,e=t.name,n=t.data,s=t.sensorType,i=t.enumMap,o=t.color,a=t.lineWidth,l=t.smoothing,h=t.seriesType;if(!e||!e.length)throw new Error("Series: name required");if(!Array.isArray(n))throw new Error("Series: data must be an array");let d=o!==void 0||a!==void 0||l!==void 0?{color:o,width:a,smoothing:l}:void 0;return {name:e,data:n.map(Bt),sensorType:s??"numeric",enumMap:i,seriesType:h,...d&&{style:{line:d}}}}throw new Error("parseSeries: object or DataPoint[] expected")}function Le(r){if(!r||typeof r!="object")throw new Error("parseAggregated: object expected");let t=r,e=t.name,n=t.data,s=t.showAs,i=t.avgLine,o=t.countOpacity,a=t.color;if(!e||!e.length)throw new Error("AggregatedSeries: name required");if(!Array.isArray(n))throw new Error("AggregatedSeries: data must be an array");return {name:e,data:De(n),showAs:s,avgLine:i,countOpacity:o,...a!==void 0&&{style:{line:{color:a},fill:a}}}}function De(r){let t=e=>typeof e=="number"?e:null;return r.map(e=>{let n=e;return {time:n.time??0,min:t(n.min),max:t(n.max),avg:t(n.avg),count:typeof n.count=="number"?n.count:0}})}var gt={...c};function Pe(r){gt={...gt,...r};}function Be(){return gt}function Fe(){gt={...c};}/*!
50
+ </g>`}_esc(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}};var se="http://www.w3.org/2000/svg";function ke(r){let t=r.style?.line;return t&&!Array.isArray(t)&&t.color?t.color:c.stroke}function oe(r){return r.replace(/[&<>"']/g,t=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"})[t])}function ve(r){if(r.length===0)return "";let t=new Date(r[0].time).toLocaleString(),e=r.map(n=>`<div><span class="mlc-tooltip__name">${oe(n.series.name)}:</span> ${n.value.toFixed(2)}</div>`);return `<div class="mlc-tooltip__time">${oe(t)}</div>${e.join("")}`}function Ce(r,t){if(r.length===0)return;let e=0,n=r.length-1;for(;e<n;){let o=e+n>>1;r[o].time<t?e=o+1:n=o;}let s=r[Math.max(0,e-1)],i=r[e];return Math.abs(s.time-t)<=Math.abs(i.time-t)?s:i}function Te(r){return "value"in r?r.value:r.avg}function ot(r,t,e={}){let n=r.querySelector("svg");if(!n)throw new Error("attachTooltip: target has no <svg> child (did you mount the chart first?)");let s=e.format??ve,i=e.snapRadius??1/0,o=e.className??"mlc-tooltip",a=e.showPicks??true,l=e.pickRadius??5,h=e.picksClassName??"mlc-tooltip-picks",d=document.createElement("div");d.className=o,d.style.position="absolute",d.style.pointerEvents="none",d.style.display="none",getComputedStyle(r).position==="static"&&(r.style.position="relative"),r.appendChild(d);let m=null;a&&(m=document.createElementNS(se,"g"),m.setAttribute("class",h),m.setAttribute("pointer-events","none"),n.appendChild(m));let u=()=>{m&&m.replaceChildren();},f=t.series.map((S,k)=>({data:S.data.map(D=>({time:D.time,value:Te(D)})).filter(D=>D.value!==null).sort((D,O)=>D.time-O.time),series:S,index:k})),p=S=>{let k=n.getBoundingClientRect(),I=t.getWidth?.()??k.width,D=(S.clientX-k.left)*I/Math.max(1,k.width);t.getHeight?.()??k.height;let H=t.invertTime(D);if(!Number.isFinite(H)){d.style.display="none";return}let R=[];for(let T of f){let $=Ce(T.data,H);if(!$)continue;let j=t.project($.time,$.value,T.series.yAxisIndex??0).x,z=t.project($.time,$.value,T.series.yAxisIndex??0).y;Math.abs(j-D)>i||R.push({seriesIndex:T.index,series:T.series,time:$.time,value:$.value,x:j,y:z});}if(R.length===0){d.style.display="none",u();return}d.innerHTML=s(R);let G=r.getBoundingClientRect(),B=12,w=(S.clientX-k.left)/Math.max(1,k.width),v=(S.clientY-k.top)/Math.max(1,k.height),C=w<.5?`${B}px`:`calc(-100% - ${B}px)`,M=v<.5?`${B}px`:`calc(-100% - ${B}px)`;if(d.style.left=`${S.clientX-G.left}px`,d.style.top=`${S.clientY-G.top}px`,d.style.transform=`translate(${C}, ${M})`,d.style.display="",m){m.replaceChildren();for(let T of R){let $=document.createElementNS(se,"circle");$.setAttribute("cx",String(T.x)),$.setAttribute("cy",String(T.y)),$.setAttribute("r",String(l)),$.setAttribute("fill","#ffffff"),$.setAttribute("stroke",ke(T.series)),$.setAttribute("stroke-width","2"),$.setAttribute("class",`${h}__dot`),m.appendChild($);}}},y=()=>{d.style.display="none",u();};n.addEventListener("mousemove",p),n.addEventListener("mouseleave",y);let b=false;return ()=>{b||(b=true,n.removeEventListener("mousemove",p),n.removeEventListener("mouseleave",y),d.remove(),m&&m.remove());}}function $e(r,t={}){let e=typeof r=="string"?document.querySelector(r):r;if(!e)throw new Error(`mount: target ${typeof r=="string"?`'${r}'`:""} not found`);let{tooltip:n,...s}=t,i=s.width??e.clientWidth??800,o=s.height??350,a=new Z({...s,width:i,height:o}),{content:l}=new X().render(a.renderCommands());e.innerHTML=l;let h=e.querySelector("svg");return h&&(h.setAttribute("viewBox",`0 0 ${i} ${a.getHeight()}`),h.setAttribute("width","100%"),h.setAttribute("height",String(a.getHeight()))),n?.show&&ot(e,a,n),a}var Ct=class{_opts;_series=[];_thresholds=[];_annotations=[];_highlights=[];_markers=[];_bands=[];_tooltip;constructor(t,e){this._opts={},t!==void 0&&(this._opts.width=t),e!==void 0&&(this._opts.height=e);}setWidth(t){return this._opts.width=t,this}setHeight(t){return this._opts.height=t,this}setSize(t,e){return this._opts.width=t,this._opts.height=e,this}setMargin(t,e,n,s){return typeof t=="object"?this._opts.margin=t:this._opts.margin={top:t,right:e??0,bottom:n??0,left:s??0},this}setLocale(t){return this._opts.locale=t,this}setAxes(t){return this._opts.axes=t,this}setXAxis(t){return this._opts.axes={...this._opts.axes,x:{...this._opts.axes?.x,...t}},this}setLeftAxis(t){return this._opts.axes={...this._opts.axes,left:{...this._opts.axes?.left,...t}},this}setRightAxis(t){return this._opts.axes={...this._opts.axes,right:{...this._opts.axes?.right,...t}},this}setYAxis(t,e){this._opts.axes||(this._opts.axes={}),this._opts.axes.y||(this._opts.axes.y=[]);let n=[...this._opts.axes.y];for(;n.length<=t;)n.push({});return n[t]={...n[t],...e},this._opts.axes.y=n,this}setLegend(t,e,n){return typeof t=="object"?this._opts.legend=t:this._opts.legend={show:t,position:e,orientation:n},this}setGaps(t){return this._opts.gaps=t,this}setTooltip(t){return this._tooltip={show:true,...t},this}addSeries(t){return this._series.push(t),this}addSeriesAll(t){return this._series.push(...t),this}addThreshold(t){return this._thresholds.push(t),this}addThresholds(t){return this._thresholds.push(...t),this}addAnnotation(t){return this._annotations.push(t),this}addAnnotations(t){return this._annotations.push(...t),this}addHighlight(t){return this._highlights.push(t),this}addMarker(t){return this._markers.push(t),this}addAnnotationBand(t){return this._bands.push(t),this}clear(t){return (!t||t==="series")&&(this._series=[]),(!t||t==="thresholds")&&(this._thresholds=[]),(!t||t==="annotations")&&(this._annotations=[]),(!t||t==="highlights")&&(this._highlights=[]),(!t||t==="markers")&&(this._markers=[]),(!t||t==="bands")&&(this._bands=[]),this}toOptions(){return {...this._opts,series:this._series.length?this._series:this._opts.series,thresholds:this._thresholds.length?this._thresholds:this._opts.thresholds,annotations:this._annotations.length?this._annotations:this._opts.annotations,highlights:this._highlights.length?this._highlights:this._opts.highlights,markers:this._markers.length?this._markers:this._opts.markers,annotationBands:this._bands.length?this._bands:this._opts.annotationBands}}build(){return new Z(this.toOptions())}getSvg(){let t=this.build(),{content:e}=new X().render(t.renderCommands());return e}mount(t){let e=typeof t=="string"?document.querySelector(t):t;if(!e)throw new Error(`GraphBuilder.mount: target ${typeof t=="string"?`'${t}'`:""} not found`);this._opts.width||(this._opts.width=e.clientWidth||800);let n=this.build(),{content:s}=new X().render(n.renderCommands());e.innerHTML=s;let i=e.querySelector("svg");if(i){let o=this._opts.width??800;i.setAttribute("viewBox",`0 0 ${o} ${n.getHeight()}`),i.setAttribute("width","100%"),i.setAttribute("height",String(n.getHeight()));}return this._tooltip?.show&&ot(e,n,this._tooltip),n}},Tt=class{_series;constructor(t){this._series={name:t,data:[]};}addPoint(t,e){return this._series.data.push({time:t,value:e}),this}addPoints(t){return this._series.data.push(...t),this}addFloats(t,e){let n=Math.min(t.length,e.length);for(let s=0;s<n;s++)this._series.data.push({time:t[s],value:e[s]});return this}addNullPoint(t){return this._series.data.push({time:t,value:null}),this}setStyle(t){return this._series.style=t,this}setLineStyle(t,e,n){return this._series.style||(this._series.style={}),this._series.style.line={color:t,width:e,style:n},this}setSmoothing(t){return this._series.style||(this._series.style={}),!this._series.style.line||typeof this._series.style.line=="boolean"?this._series.style.line={smoothing:t}:Array.isArray(this._series.style.line)?this._series.style.line.length===0?this._series.style.line=[{smoothing:t}]:this._series.style.line[0].smoothing=t:this._series.style.line.smoothing=t,this}setFill(t){return this._series.style||(this._series.style={}),this._series.style.fill=t,this}setID(t){return this._series.id=t,this}setColorByThresholds(t){return this._series.colorByThresholds=t,this}build(){return this._series}},$t=class{_threshold;constructor(t,e){this._threshold={name:t,value:e};}setColor(t){return this._threshold.color=t,this}setLine(t){return this._threshold.line=t,this}setFill(t,e){return this._threshold.fill=t,this._threshold.fillOpacity=e,this}setFillHatch(t){return this._threshold.fillHatch=t,this}setLabel(t,e){return this._threshold.label={text:t,position:e},this}setID(t){return this._threshold.id=t,this}build(){return this._threshold}},At=class{_marker;constructor(t){this._marker={time:t};}setValue(t){return this._marker.value=t,this}setLabel(t){return this._marker.label=t,this}setColor(t){return this._marker.color=t,this}setPointStyle(t){return this._marker.pointStyle=t,this}setLineStyle(t){return t==="none"?delete this._marker.lineStyle:this._marker.lineStyle=t,this}setSeriesIndex(t){return this._marker.seriesIndex=t,this}build(){return this._marker}},Mt=class{_highlight;constructor(t,e){this._highlight={startTime:t,endTime:e};}setLabel(t){return this._highlight.label=t,this}setColor(t){return this._highlight.color=t,this}setOpacity(t){return this._highlight.opacity=t,this}setLabelPosition(t){return this._highlight.labelPosition=t,this}setRotate(t){return this._highlight.rotate=t,this}build(){return this._highlight}},Lt=class{_ann;constructor(t){this._ann={type:t};}setID(t){return this._ann.id=t,this}setTitle(t){return this._ann.title=t,this}setFrom(t,e,n){return this._ann.from={time:t,value:e,axis:n},this}setTo(t,e,n){return this._ann.to={time:t,value:e,axis:n},this}setAt(t,e,n){return this._ann.at={time:t,value:e,axis:n},this}setColor(t){return this._ann.color=t,this}setWidth(t){return this._ann.width=t,this}setDash(t){return this._ann.dash=t,this}setHeadSize(t){return this._ann.headSize=t,this}setFill(t){return this._ann.fill=t,this}setHatch(t){return this._ann.hatch=t,this}setStroke(t){return this._ann.stroke=t,this}setOpacity(t){return this._ann.opacity=t,this}setRadius(t){return this._ann.radius=t,this}setShape(t){return this._ann.shape=t,this}setText(t){return this._ann.text=t,this}setAnchor(t){return this._ann.anchor=t,this}setDx(t){return this._ann.dx=t,this}setDy(t){return this._ann.dy=t,this}setRotate(t){return this._ann.rotate=t,this}build(){return this._ann}},Dt=class{_band;constructor(t){this._band={name:t,items:[]};}setHeight(t){return this._band.height=t,this}setSpacing(t){return this._band.spacing=t,this}setHatch(t){return this._band.hatch=t,this}setShowAxis(t){return this._band.showAxis=t,this}setShowInLegend(t){return this._band.showInLegend=t,this}setBackground(t){return this._band.background=t,this}addItem(t){return this._band.items.push(t),this}build(){return this._band}},Pt=class{_item;constructor(t,e){this._item={startTime:t,endTime:e};}setFill(t){return this._item.fill=t,this}setHatch(t){return this._item.hatch=t,this}setStroke(t){return this._item.stroke=t,this}setStrokeWidth(t){return this._item.strokeWidth=t,this}setLabel(t,e,n,s){return this._item.label=t,e!==void 0&&(this._item.labelFontSize=e),n!==void 0&&(this._item.labelFill=n),s!==void 0&&(this._item.labelBaseline=s),this}build(){return this._item}};function Ae(r){let{thresholds:t,colors:e,hatches:n}=r;if(e.length!==t.length+1)throw new Error(`fillBetweenThresholds: expected ${t.length+1} colors for ${t.length} thresholds, got ${e.length}`);if(n!==void 0&&n.length!==e.length)throw new Error(`fillBetweenThresholds: hatches length (${n.length}) must equal colors length (${e.length})`);return {regions:e.map((i,o)=>{let a=n?.[o],l=a?{color:i,hatch:a}:i;return o===0?{to:{threshold:t[0]},fill:l}:o===e.length-1?{from:{threshold:t[t.length-1]},fill:l}:{from:{threshold:t[o-1]},to:{threshold:t[o]},fill:l}})}}function Bt(r){if(!r||typeof r!="object")throw new Error("DataPoint: object expected");let{time:t,value:e,annotation:n}=r;if(typeof t!="number"||isNaN(t))throw new Error(`DataPoint: invalid time=${t}`);if(e!==null&&(typeof e!="number"||isNaN(e)))throw new Error(`DataPoint: invalid value=${e}`);return {time:t,value:e,annotation:n&&typeof n=="string"?n:void 0}}function Me(r){if(Array.isArray(r))return r.map(Bt);if(r&&typeof r=="object"){let t=r,e=t.name,n=t.data,s=t.sensorType,i=t.enumMap,o=t.color,a=t.lineWidth,l=t.smoothing,h=t.seriesType;if(!e||!e.length)throw new Error("Series: name required");if(!Array.isArray(n))throw new Error("Series: data must be an array");let d=o!==void 0||a!==void 0||l!==void 0?{color:o,width:a,smoothing:l}:void 0;return {name:e,data:n.map(Bt),sensorType:s??"numeric",enumMap:i,seriesType:h,...d&&{style:{line:d}}}}throw new Error("parseSeries: object or DataPoint[] expected")}function Le(r){if(!r||typeof r!="object")throw new Error("parseAggregated: object expected");let t=r,e=t.name,n=t.data,s=t.showAs,i=t.avgLine,o=t.countOpacity,a=t.color;if(!e||!e.length)throw new Error("AggregatedSeries: name required");if(!Array.isArray(n))throw new Error("AggregatedSeries: data must be an array");return {name:e,data:De(n),showAs:s,avgLine:i,countOpacity:o,...a!==void 0&&{style:{line:{color:a},fill:a}}}}function De(r){let t=e=>typeof e=="number"?e:null;return r.map(e=>{let n=e;return {time:n.time??0,min:t(n.min),max:t(n.max),avg:t(n.avg),count:typeof n.count=="number"?n.count:0}})}var gt={...c};function Pe(r){gt={...gt,...r};}function Be(){return gt}function Fe(){gt={...c};}/*!
51
51
  * MLTimeGraph — Copyright (c) 2026 Michael Lechner
52
52
  * MIT with Attribution: free use incl. commercial requires visible credit to
53
53
  * "Michael Lechner". Commercial license (no attribution) on request. See LICENSE.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ml-time-graph",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "TypeScript library for time-series chart rendering — DOM-free SVG output (works in the browser and on the server).",
5
5
  "type": "module",
6
6
  "module": "./dist/index.js",