@tabler/charts 0.0.0-stage → 0.1.0
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/LICENSE +21 -0
- package/README.md +258 -2
- package/dist/annotations-Bp7HwtF5.d.ts +86 -0
- package/dist/annotations-BszTTjf9.js +202 -0
- package/dist/annotations-BszTTjf9.js.map +1 -0
- package/dist/annotations-DpETO8dE.cjs +213 -0
- package/dist/annotations-DpETO8dE.cjs.map +1 -0
- package/dist/annotations-lyt0I3HU.d.cts +86 -0
- package/dist/annotations.cjs +14 -0
- package/dist/annotations.cjs.map +1 -0
- package/dist/annotations.d.cts +2 -0
- package/dist/annotations.d.ts +2 -0
- package/dist/annotations.js +12 -0
- package/dist/annotations.js.map +1 -0
- package/dist/arc-BXpLrt9b.cjs +301 -0
- package/dist/arc-BXpLrt9b.cjs.map +1 -0
- package/dist/arc-a1tRTEw7.js +278 -0
- package/dist/arc-a1tRTEw7.js.map +1 -0
- package/dist/area-CF__HOwL.d.ts +20 -0
- package/dist/area-DIxaAbYZ.d.cts +20 -0
- package/dist/area-DQsLERhx.js +26 -0
- package/dist/area-DQsLERhx.js.map +1 -0
- package/dist/area-sHCE3pg5.cjs +31 -0
- package/dist/area-sHCE3pg5.cjs.map +1 -0
- package/dist/area.cjs +3 -0
- package/dist/area.d.cts +2 -0
- package/dist/area.d.ts +2 -0
- package/dist/area.js +2 -0
- package/dist/band-DTcNDAFO.d.cts +50 -0
- package/dist/band-DTcNDAFO.d.ts +50 -0
- package/dist/bar-BBM8RhoL.d.ts +43 -0
- package/dist/bar-C-7zR2qp.cjs +243 -0
- package/dist/bar-C-7zR2qp.cjs.map +1 -0
- package/dist/bar-CRKLDg98.d.cts +43 -0
- package/dist/bar-DGuUN3nc.cjs +67 -0
- package/dist/bar-DGuUN3nc.cjs.map +1 -0
- package/dist/bar-DM16NUvV.js +56 -0
- package/dist/bar-DM16NUvV.js.map +1 -0
- package/dist/bar-jZEoao74.js +238 -0
- package/dist/bar-jZEoao74.js.map +1 -0
- package/dist/bar.cjs +3 -0
- package/dist/bar.d.cts +2 -0
- package/dist/bar.d.ts +2 -0
- package/dist/bar.js +2 -0
- package/dist/candlestick-B5r1w3kc.cjs +150 -0
- package/dist/candlestick-B5r1w3kc.cjs.map +1 -0
- package/dist/candlestick-D_vV0_XZ.d.ts +44 -0
- package/dist/candlestick-DuXwAFID.js +145 -0
- package/dist/candlestick-DuXwAFID.js.map +1 -0
- package/dist/candlestick-__pXl_pV.d.cts +44 -0
- package/dist/candlestick.cjs +11 -0
- package/dist/candlestick.cjs.map +1 -0
- package/dist/candlestick.d.cts +2 -0
- package/dist/candlestick.d.ts +2 -0
- package/dist/candlestick.js +10 -0
- package/dist/candlestick.js.map +1 -0
- package/dist/cartesian-BoDfgBCV.cjs +900 -0
- package/dist/cartesian-BoDfgBCV.cjs.map +1 -0
- package/dist/cartesian-Cr0AF0nG.js +709 -0
- package/dist/cartesian-Cr0AF0nG.js.map +1 -0
- package/dist/chart-BF2CK9I_.js +790 -0
- package/dist/chart-BF2CK9I_.js.map +1 -0
- package/dist/chart-CowF_lWY.cjs +903 -0
- package/dist/chart-CowF_lWY.cjs.map +1 -0
- package/dist/chart-D7ooEFnk.d.cts +933 -0
- package/dist/chart-DyN7bcx8.d.ts +933 -0
- package/dist/circle-BQMuAfls.cjs +12 -0
- package/dist/circle-BQMuAfls.cjs.map +1 -0
- package/dist/circle-Z7YfCoCM.js +7 -0
- package/dist/circle-Z7YfCoCM.js.map +1 -0
- package/dist/clean-Byl6kzf0.cjs +115 -0
- package/dist/clean-Byl6kzf0.cjs.map +1 -0
- package/dist/clean-o1vDEhFV.js +56 -0
- package/dist/clean-o1vDEhFV.js.map +1 -0
- package/dist/core-CegR_j55.js +884 -0
- package/dist/core-CegR_j55.js.map +1 -0
- package/dist/core-D1vO1LrC.d.cts +220 -0
- package/dist/core-DcbemzGf.d.ts +220 -0
- package/dist/core-RzS9IQO5.cjs +985 -0
- package/dist/core-RzS9IQO5.cjs.map +1 -0
- package/dist/core.cjs +115 -0
- package/dist/core.d.cts +21 -0
- package/dist/core.d.ts +21 -0
- package/dist/core.js +25 -0
- package/dist/dates-Btm7Zm6W.cjs +32 -0
- package/dist/dates-Btm7Zm6W.cjs.map +1 -0
- package/dist/dates-CG-FvioW.js +27 -0
- package/dist/dates-CG-FvioW.js.map +1 -0
- package/dist/decimate-BGg9XgF0.d.ts +17 -0
- package/dist/decimate-C87cl_Sp.js +84 -0
- package/dist/decimate-C87cl_Sp.js.map +1 -0
- package/dist/decimate-CNSpgGa5.d.cts +17 -0
- package/dist/decimate-tLhDk1ys.cjs +95 -0
- package/dist/decimate-tLhDk1ys.cjs.map +1 -0
- package/dist/decimate.cjs +14 -0
- package/dist/decimate.cjs.map +1 -0
- package/dist/decimate.d.cts +2 -0
- package/dist/decimate.d.ts +2 -0
- package/dist/decimate.js +12 -0
- package/dist/decimate.js.map +1 -0
- package/dist/dom-CLF868Qs.cjs +222 -0
- package/dist/dom-CLF868Qs.cjs.map +1 -0
- package/dist/dom-vP3IcMak.js +175 -0
- package/dist/dom-vP3IcMak.js.map +1 -0
- package/dist/export-chart-9w8t3rjZ.js +232 -0
- package/dist/export-chart-9w8t3rjZ.js.map +1 -0
- package/dist/export-chart-BhhYgksr.cjs +249 -0
- package/dist/export-chart-BhhYgksr.cjs.map +1 -0
- package/dist/export.cjs +18 -0
- package/dist/export.cjs.map +1 -0
- package/dist/export.d.cts +2 -0
- package/dist/export.d.ts +2 -0
- package/dist/export.js +15 -0
- package/dist/export.js.map +1 -0
- package/dist/extent-BAMZo0Nq.js +19 -0
- package/dist/extent-BAMZo0Nq.js.map +1 -0
- package/dist/extent-DsFWvAHJ.cjs +24 -0
- package/dist/extent-DsFWvAHJ.cjs.map +1 -0
- package/dist/fade-Cs74puQS.cjs +217 -0
- package/dist/fade-Cs74puQS.cjs.map +1 -0
- package/dist/fade-D3NxH5Qg.js +200 -0
- package/dist/fade-D3NxH5Qg.js.map +1 -0
- package/dist/features-BclHgg2W.cjs +48 -0
- package/dist/features-BclHgg2W.cjs.map +1 -0
- package/dist/features-wASyHGic.js +25 -0
- package/dist/features-wASyHGic.js.map +1 -0
- package/dist/format-B0yKXBTH.cjs +183 -0
- package/dist/format-B0yKXBTH.cjs.map +1 -0
- package/dist/format-lStwuc1L.js +142 -0
- package/dist/format-lStwuc1L.js.map +1 -0
- package/dist/gauge-D-FYhuds.cjs +236 -0
- package/dist/gauge-D-FYhuds.cjs.map +1 -0
- package/dist/gauge-DP_EB2z3.d.cts +65 -0
- package/dist/gauge-Dh423FHh.js +231 -0
- package/dist/gauge-Dh423FHh.js.map +1 -0
- package/dist/gauge-zpia05t2.d.ts +65 -0
- package/dist/gauge.cjs +3 -0
- package/dist/gauge.d.cts +2 -0
- package/dist/gauge.d.ts +2 -0
- package/dist/gauge.js +2 -0
- package/dist/heatmap-BK18EBgJ.cjs +247 -0
- package/dist/heatmap-BK18EBgJ.cjs.map +1 -0
- package/dist/heatmap-BectCEeE.d.ts +81 -0
- package/dist/heatmap-CCso6m61.d.cts +81 -0
- package/dist/heatmap-DSZ2bVIa.js +242 -0
- package/dist/heatmap-DSZ2bVIa.js.map +1 -0
- package/dist/heatmap.cjs +3 -0
- package/dist/heatmap.d.cts +2 -0
- package/dist/heatmap.d.ts +2 -0
- package/dist/heatmap.js +2 -0
- package/dist/hydrate-CTTmQy0x.d.cts +10 -0
- package/dist/hydrate-CxwTXDqO.cjs +60 -0
- package/dist/hydrate-CxwTXDqO.cjs.map +1 -0
- package/dist/hydrate-CzfxLfTv.d.ts +10 -0
- package/dist/hydrate-DDNIHYv_.js +55 -0
- package/dist/hydrate-DDNIHYv_.js.map +1 -0
- package/dist/hydrate.cjs +13 -0
- package/dist/hydrate.cjs.map +1 -0
- package/dist/hydrate.d.cts +2 -0
- package/dist/hydrate.d.ts +2 -0
- package/dist/hydrate.js +12 -0
- package/dist/hydrate.js.map +1 -0
- package/dist/index.cjs +214 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +46 -0
- package/dist/index.d.ts +46 -0
- package/dist/index.js +115 -0
- package/dist/index.js.map +1 -0
- package/dist/layout-B3hiqVEw.js +69 -0
- package/dist/layout-B3hiqVEw.js.map +1 -0
- package/dist/layout-CtMBhNd9.cjs +98 -0
- package/dist/layout-CtMBhNd9.cjs.map +1 -0
- package/dist/line-B3Ed6u7j.js +120 -0
- package/dist/line-B3Ed6u7j.js.map +1 -0
- package/dist/line-CN4uZ9ZX.d.ts +47 -0
- package/dist/line-W7VD_qs1.d.cts +47 -0
- package/dist/line-fQbtP_jL.cjs +131 -0
- package/dist/line-fQbtP_jL.cjs.map +1 -0
- package/dist/line.cjs +14 -0
- package/dist/line.cjs.map +1 -0
- package/dist/line.d.cts +2 -0
- package/dist/line.d.ts +2 -0
- package/dist/line.js +13 -0
- package/dist/line.js.map +1 -0
- package/dist/log-CaofN3-n.d.cts +48 -0
- package/dist/log-CaofN3-n.d.ts +48 -0
- package/dist/log-axis-83rSpvL5.cjs +130 -0
- package/dist/log-axis-83rSpvL5.cjs.map +1 -0
- package/dist/log-axis-B_uvvOFc.js +113 -0
- package/dist/log-axis-B_uvvOFc.js.map +1 -0
- package/dist/log.cjs +17 -0
- package/dist/log.cjs.map +1 -0
- package/dist/log.d.cts +2 -0
- package/dist/log.d.ts +2 -0
- package/dist/log.js +16 -0
- package/dist/log.js.map +1 -0
- package/dist/morph-BMxz3X2b.d.cts +10 -0
- package/dist/morph-BMxz3X2b.d.ts +10 -0
- package/dist/morph-Bgg-24l8.js +36 -0
- package/dist/morph-Bgg-24l8.js.map +1 -0
- package/dist/morph-CqYDu1bY.cjs +41 -0
- package/dist/morph-CqYDu1bY.cjs.map +1 -0
- package/dist/morph.cjs +14 -0
- package/dist/morph.cjs.map +1 -0
- package/dist/morph.d.cts +2 -0
- package/dist/morph.d.ts +2 -0
- package/dist/morph.js +13 -0
- package/dist/morph.js.map +1 -0
- package/dist/named-BWWb5LQJ.cjs +50 -0
- package/dist/named-BWWb5LQJ.cjs.map +1 -0
- package/dist/named-DE15TOgh.js +33 -0
- package/dist/named-DE15TOgh.js.map +1 -0
- package/dist/parliament-1Zv2Xh0D.d.ts +69 -0
- package/dist/parliament-CpWnoEvG.cjs +308 -0
- package/dist/parliament-CpWnoEvG.cjs.map +1 -0
- package/dist/parliament-DdrLVZwt.d.cts +69 -0
- package/dist/parliament-Dw0sOERi.js +303 -0
- package/dist/parliament-Dw0sOERi.js.map +1 -0
- package/dist/parliament.cjs +3 -0
- package/dist/parliament.d.cts +2 -0
- package/dist/parliament.d.ts +2 -0
- package/dist/parliament.js +2 -0
- package/dist/path-CwB28da0.d.cts +29 -0
- package/dist/path-CwB28da0.d.ts +29 -0
- package/dist/patterns-DtgcnA8o.js +85 -0
- package/dist/patterns-DtgcnA8o.js.map +1 -0
- package/dist/patterns-LfcQAWCy.cjs +102 -0
- package/dist/patterns-LfcQAWCy.cjs.map +1 -0
- package/dist/patterns.cjs +15 -0
- package/dist/patterns.cjs.map +1 -0
- package/dist/patterns.d.cts +2 -0
- package/dist/patterns.d.ts +2 -0
- package/dist/patterns.js +12 -0
- package/dist/patterns.js.map +1 -0
- package/dist/pie-5z1fDdKO.d.ts +58 -0
- package/dist/pie-BF9yI5mE.d.cts +58 -0
- package/dist/pie-BxTZt6Go.cjs +212 -0
- package/dist/pie-BxTZt6Go.cjs.map +1 -0
- package/dist/pie-DzUXDTcn.js +201 -0
- package/dist/pie-DzUXDTcn.js.map +1 -0
- package/dist/pie.cjs +4 -0
- package/dist/pie.d.cts +2 -0
- package/dist/pie.d.ts +2 -0
- package/dist/pie.js +2 -0
- package/dist/point-shapes-CGl4dugc.cjs +166 -0
- package/dist/point-shapes-CGl4dugc.cjs.map +1 -0
- package/dist/point-shapes-DI84NNpI.js +155 -0
- package/dist/point-shapes-DI84NNpI.js.map +1 -0
- package/dist/point-shapes.cjs +15 -0
- package/dist/point-shapes.cjs.map +1 -0
- package/dist/point-shapes.d.cts +2 -0
- package/dist/point-shapes.d.ts +2 -0
- package/dist/point-shapes.js +13 -0
- package/dist/point-shapes.js.map +1 -0
- package/dist/radar-1-EryihA.d.ts +60 -0
- package/dist/radar-CYPab_I4.js +285 -0
- package/dist/radar-CYPab_I4.js.map +1 -0
- package/dist/radar-CoGUNNSb.cjs +290 -0
- package/dist/radar-CoGUNNSb.cjs.map +1 -0
- package/dist/radar-DBW4O0Vt.d.cts +60 -0
- package/dist/radar.cjs +3 -0
- package/dist/radar.d.cts +2 -0
- package/dist/radar.d.ts +2 -0
- package/dist/radar.js +2 -0
- package/dist/sankey-B4PNKusJ.js +420 -0
- package/dist/sankey-B4PNKusJ.js.map +1 -0
- package/dist/sankey-Bacx4fVe.cjs +425 -0
- package/dist/sankey-Bacx4fVe.cjs.map +1 -0
- package/dist/sankey-DuGI3Qc5.d.cts +67 -0
- package/dist/sankey-OV_WoPrl.d.ts +67 -0
- package/dist/sankey.cjs +3 -0
- package/dist/sankey.d.cts +2 -0
- package/dist/sankey.d.ts +2 -0
- package/dist/sankey.js +2 -0
- package/dist/scatter-BqzgJqdX.d.ts +61 -0
- package/dist/scatter-DbxLyZX0.d.cts +61 -0
- package/dist/scatter-DgMN9zRy.cjs +250 -0
- package/dist/scatter-DgMN9zRy.cjs.map +1 -0
- package/dist/scatter-kgtgR318.js +245 -0
- package/dist/scatter-kgtgR318.js.map +1 -0
- package/dist/scatter.cjs +3 -0
- package/dist/scatter.d.cts +2 -0
- package/dist/scatter.d.ts +2 -0
- package/dist/scatter.js +2 -0
- package/dist/sparkline-BQzt27Fr.js +171 -0
- package/dist/sparkline-BQzt27Fr.js.map +1 -0
- package/dist/sparkline-BS9-hltA.cjs +176 -0
- package/dist/sparkline-BS9-hltA.cjs.map +1 -0
- package/dist/sparkline-BfyO_oNM.d.ts +43 -0
- package/dist/sparkline-CWlJDKyh.d.cts +43 -0
- package/dist/sparkline.cjs +3 -0
- package/dist/sparkline.d.cts +2 -0
- package/dist/sparkline.d.ts +2 -0
- package/dist/sparkline.js +2 -0
- package/dist/stack-CpR6RGKd.d.cts +6 -0
- package/dist/stack-CpR6RGKd.d.ts +6 -0
- package/dist/stack-DRbwTeF3.js +66 -0
- package/dist/stack-DRbwTeF3.js.map +1 -0
- package/dist/stack-DVhJWaki.cjs +77 -0
- package/dist/stack-DVhJWaki.cjs.map +1 -0
- package/dist/style.css +2 -0
- package/dist/sweep-CbfR7--d.js +60 -0
- package/dist/sweep-CbfR7--d.js.map +1 -0
- package/dist/sweep-DaTEDDuC.cjs +71 -0
- package/dist/sweep-DaTEDDuC.cjs.map +1 -0
- package/dist/time-CHjiY9Q4.d.ts +112 -0
- package/dist/time-CNVnt-B2.d.cts +112 -0
- package/dist/time-axis-Bc9eHX1r.js +365 -0
- package/dist/time-axis-Bc9eHX1r.js.map +1 -0
- package/dist/time-axis-VSX34_Tb.cjs +382 -0
- package/dist/time-axis-VSX34_Tb.cjs.map +1 -0
- package/dist/time.cjs +22 -0
- package/dist/time.cjs.map +1 -0
- package/dist/time.d.cts +2 -0
- package/dist/time.d.ts +2 -0
- package/dist/time.js +20 -0
- package/dist/time.js.map +1 -0
- package/dist/tween-BCYd0RTY.js +40 -0
- package/dist/tween-BCYd0RTY.js.map +1 -0
- package/dist/tween-CIGBlryn.cjs +51 -0
- package/dist/tween-CIGBlryn.cjs.map +1 -0
- package/dist/value-labels-B0WJoJ7x.cjs +134 -0
- package/dist/value-labels-B0WJoJ7x.cjs.map +1 -0
- package/dist/value-labels-IZIQPhfk.js +123 -0
- package/dist/value-labels-IZIQPhfk.js.map +1 -0
- package/dist/value-labels.cjs +14 -0
- package/dist/value-labels.cjs.map +1 -0
- package/dist/value-labels.d.cts +2 -0
- package/dist/value-labels.d.ts +2 -0
- package/dist/value-labels.js +12 -0
- package/dist/value-labels.js.map +1 -0
- package/dist/vnode-BUflsBsa.d.cts +66 -0
- package/dist/vnode-BUflsBsa.d.ts +66 -0
- package/dist/vnode-CkQ27Cxe.cjs +110 -0
- package/dist/vnode-CkQ27Cxe.cjs.map +1 -0
- package/dist/vnode-tCWItoUH.js +93 -0
- package/dist/vnode-tCWItoUH.js.map +1 -0
- package/package.json +320 -3
|
@@ -0,0 +1,790 @@
|
|
|
1
|
+
import { t as h } from "./vnode-tCWItoUH.js";
|
|
2
|
+
import { n as feature, r as features } from "./features-wASyHGic.js";
|
|
3
|
+
import { a as render, c as isValidTag, s as isValidAttr } from "./dom-vP3IcMak.js";
|
|
4
|
+
//#region src/interaction.ts
|
|
5
|
+
/** Identity of a hit, used to emit hover changes only when it changes. */
|
|
6
|
+
function hitKey(hit) {
|
|
7
|
+
return hit ? `${hit.index}:${hit.seriesIndex ?? ""}` : "";
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Convert a pointer position to chart pixels, accounting for the SVG being
|
|
11
|
+
* scaled by CSS (e.g. `max-width: 100%`).
|
|
12
|
+
*/
|
|
13
|
+
function toChartPoint(svg, clientX, clientY, width, height) {
|
|
14
|
+
const rect = svg.getBoundingClientRect();
|
|
15
|
+
const sx = rect.width > 0 ? width / rect.width : 1;
|
|
16
|
+
const sy = rect.height > 0 ? height / rect.height : 1;
|
|
17
|
+
return {
|
|
18
|
+
x: (clientX - rect.left) * sx,
|
|
19
|
+
y: (clientY - rect.top) * sy
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region src/legend.ts
|
|
24
|
+
/**
|
|
25
|
+
* Legend content: one toggle button per entry. Buttons are native, so they
|
|
26
|
+
* are focusable and work with Enter/Space; `aria-pressed` reflects visibility.
|
|
27
|
+
*/
|
|
28
|
+
function legendContent(items, hidden) {
|
|
29
|
+
return h("div", { class: "tc-legend-items" }, items.map((item) => {
|
|
30
|
+
const off = hidden.has(item.key);
|
|
31
|
+
return h("button", {
|
|
32
|
+
key: item.key,
|
|
33
|
+
type: "button",
|
|
34
|
+
class: [
|
|
35
|
+
"tc-legend-item",
|
|
36
|
+
"tc-series",
|
|
37
|
+
`tc-series-${item.index + 1}`,
|
|
38
|
+
off && "tc-legend-item-hidden"
|
|
39
|
+
],
|
|
40
|
+
style: { "--tc-series-color": item.color },
|
|
41
|
+
"aria-pressed": off ? "false" : "true",
|
|
42
|
+
"data-key": item.key
|
|
43
|
+
}, h("span", {
|
|
44
|
+
class: "tc-legend-swatch",
|
|
45
|
+
"aria-hidden": "true"
|
|
46
|
+
}), h("span", { class: "tc-legend-name" }, item.name));
|
|
47
|
+
}));
|
|
48
|
+
}
|
|
49
|
+
/** Keys hidden by default, from the entries' own `hidden` flags. */
|
|
50
|
+
function defaultHidden(items) {
|
|
51
|
+
return new Set(items.filter((item) => item.hidden).map((item) => item.key));
|
|
52
|
+
}
|
|
53
|
+
//#endregion
|
|
54
|
+
//#region src/render/string.ts
|
|
55
|
+
const SVG_NS = "http://www.w3.org/2000/svg";
|
|
56
|
+
/** Root tags treated as HTML when no namespace is given. */
|
|
57
|
+
const HTML_ROOTS = /* @__PURE__ */ new Set([
|
|
58
|
+
"a",
|
|
59
|
+
"b",
|
|
60
|
+
"button",
|
|
61
|
+
"caption",
|
|
62
|
+
"div",
|
|
63
|
+
"em",
|
|
64
|
+
"i",
|
|
65
|
+
"label",
|
|
66
|
+
"li",
|
|
67
|
+
"ol",
|
|
68
|
+
"p",
|
|
69
|
+
"section",
|
|
70
|
+
"small",
|
|
71
|
+
"span",
|
|
72
|
+
"strong",
|
|
73
|
+
"table",
|
|
74
|
+
"tbody",
|
|
75
|
+
"td",
|
|
76
|
+
"th",
|
|
77
|
+
"thead",
|
|
78
|
+
"tr",
|
|
79
|
+
"ul"
|
|
80
|
+
]);
|
|
81
|
+
/** HTML elements that never have content and must not get a closing tag. */
|
|
82
|
+
const VOID = /* @__PURE__ */ new Set([
|
|
83
|
+
"area",
|
|
84
|
+
"base",
|
|
85
|
+
"br",
|
|
86
|
+
"col",
|
|
87
|
+
"embed",
|
|
88
|
+
"hr",
|
|
89
|
+
"img",
|
|
90
|
+
"input",
|
|
91
|
+
"link",
|
|
92
|
+
"meta",
|
|
93
|
+
"source",
|
|
94
|
+
"track",
|
|
95
|
+
"wbr"
|
|
96
|
+
]);
|
|
97
|
+
/**
|
|
98
|
+
* Serialize a VNode tree to markup (SSR, static export): SVG trees as
|
|
99
|
+
* XML-compatible SVG, HTML trees (legend, table, tooltip) as HTML.
|
|
100
|
+
*
|
|
101
|
+
* Empty elements self-close only inside SVG; in HTML they get an explicit
|
|
102
|
+
* closing tag (`<th></th>`), since `<th/>` would open an element there.
|
|
103
|
+
* Text and attribute values are escaped. Invalid tag or attribute names and
|
|
104
|
+
* inline event handlers (`on*`) are dropped, so data coming from chart
|
|
105
|
+
* options can never inject markup or scripts.
|
|
106
|
+
*/
|
|
107
|
+
function renderToString(node, options = {}) {
|
|
108
|
+
if (typeof node === "string") return escapeText(node);
|
|
109
|
+
return renderNode(options.xmlns !== false && node.tag === "svg" && node.attrs.xmlns === void 0 ? {
|
|
110
|
+
...node,
|
|
111
|
+
attrs: {
|
|
112
|
+
xmlns: SVG_NS,
|
|
113
|
+
...node.attrs
|
|
114
|
+
}
|
|
115
|
+
} : node, options.namespace ? options.namespace === "svg" : !HTML_ROOTS.has(node.tag));
|
|
116
|
+
}
|
|
117
|
+
function renderNode(node, parentInSvg) {
|
|
118
|
+
const { tag, attrs, children } = node;
|
|
119
|
+
if (!isValidTag(tag)) return "";
|
|
120
|
+
const inSvg = parentInSvg || tag === "svg";
|
|
121
|
+
let out = `<${tag}`;
|
|
122
|
+
for (const name in attrs) {
|
|
123
|
+
if (!isValidAttr(name)) continue;
|
|
124
|
+
out += ` ${name}="${escapeAttr(String(attrs[name]))}"`;
|
|
125
|
+
}
|
|
126
|
+
if (children.length === 0) {
|
|
127
|
+
if (inSvg) return `${out}/>`;
|
|
128
|
+
if (VOID.has(tag.toLowerCase())) return `${out}>`;
|
|
129
|
+
}
|
|
130
|
+
out += ">";
|
|
131
|
+
const childInSvg = inSvg && tag !== "foreignObject";
|
|
132
|
+
for (const child of children) out += typeof child === "string" ? escapeText(child) : renderNode(child, childInSvg);
|
|
133
|
+
return `${out}</${tag}>`;
|
|
134
|
+
}
|
|
135
|
+
const TEXT_RE = /[&<>]/;
|
|
136
|
+
const ATTR_RE = /[&"<>]/;
|
|
137
|
+
const TEXT_RE_G = /[&<>]/g;
|
|
138
|
+
const ATTR_RE_G = /[&"<>]/g;
|
|
139
|
+
const ENTITIES = {
|
|
140
|
+
"&": "&",
|
|
141
|
+
"<": "<",
|
|
142
|
+
">": ">",
|
|
143
|
+
"\"": """
|
|
144
|
+
};
|
|
145
|
+
const replaceEntity = (char) => ENTITIES[char];
|
|
146
|
+
/** Escape text content. */
|
|
147
|
+
function escapeText(value) {
|
|
148
|
+
return TEXT_RE.test(value) ? value.replace(TEXT_RE_G, replaceEntity) : value;
|
|
149
|
+
}
|
|
150
|
+
/** Escape a double-quoted attribute value. */
|
|
151
|
+
function escapeAttr(value) {
|
|
152
|
+
return ATTR_RE.test(value) ? value.replace(ATTR_RE_G, replaceEntity) : value;
|
|
153
|
+
}
|
|
154
|
+
//#endregion
|
|
155
|
+
//#region src/resize.ts
|
|
156
|
+
const listeners = /* @__PURE__ */ new WeakMap();
|
|
157
|
+
/** Elements observed while in the document. */
|
|
158
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
159
|
+
let observer;
|
|
160
|
+
function getObserver() {
|
|
161
|
+
if (observer || typeof ResizeObserver !== "function") return observer;
|
|
162
|
+
observer = new ResizeObserver((entries) => {
|
|
163
|
+
for (const { target, contentRect } of entries) if (target.isConnected) {
|
|
164
|
+
seen.add(target);
|
|
165
|
+
listeners.get(target)?.(contentRect.width, contentRect.height);
|
|
166
|
+
} else if (seen.has(target)) {
|
|
167
|
+
seen.delete(target);
|
|
168
|
+
observer?.unobserve(target);
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
return observer;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Call `listener` with the content size of `el` whenever it changes.
|
|
175
|
+
* Returns a function that stops observing. No-op where `ResizeObserver`
|
|
176
|
+
* is unavailable (SSR, old browsers). Observing again is harmless.
|
|
177
|
+
*/
|
|
178
|
+
function observeResize(el, listener) {
|
|
179
|
+
const ro = getObserver();
|
|
180
|
+
if (!ro) return () => {};
|
|
181
|
+
listeners.set(el, listener);
|
|
182
|
+
ro.observe(el);
|
|
183
|
+
return () => {
|
|
184
|
+
if (listeners.get(el) !== listener) return;
|
|
185
|
+
listeners.delete(el);
|
|
186
|
+
ro.unobserve(el);
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
//#endregion
|
|
190
|
+
//#region src/scheduler.ts
|
|
191
|
+
/**
|
|
192
|
+
* Batches work from all charts into a single animation frame. Scheduling the
|
|
193
|
+
* same key twice before the flush runs its latest task once.
|
|
194
|
+
*/
|
|
195
|
+
const queue = /* @__PURE__ */ new Map();
|
|
196
|
+
let pending = false;
|
|
197
|
+
const requestFrame = (callback) => {
|
|
198
|
+
if (typeof requestAnimationFrame === "function") requestAnimationFrame(callback);
|
|
199
|
+
else queueMicrotask(callback);
|
|
200
|
+
};
|
|
201
|
+
/**
|
|
202
|
+
* Run a task; an error it throws is reported on its own (as an uncaught
|
|
203
|
+
* error, in the console and to `window.onerror`) instead of stopping the
|
|
204
|
+
* tasks of other charts in the same frame.
|
|
205
|
+
*/
|
|
206
|
+
function run(task) {
|
|
207
|
+
try {
|
|
208
|
+
task();
|
|
209
|
+
} catch (error) {
|
|
210
|
+
setTimeout(() => {
|
|
211
|
+
throw error;
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
/** Run `task` in the next frame, replacing any task already queued for `key`. */
|
|
216
|
+
function schedule(key, task) {
|
|
217
|
+
queue.set(key, task);
|
|
218
|
+
if (!pending) {
|
|
219
|
+
pending = true;
|
|
220
|
+
requestFrame(flush);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
/** Work `flush()` also runs: the idle queue (`idle.ts`), once something uses it. */
|
|
224
|
+
const flushHooks = {};
|
|
225
|
+
/** Drop the task queued for `key`, if any. */
|
|
226
|
+
function cancel(key) {
|
|
227
|
+
queue.delete(key);
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Run queued tasks now, idle ones too; returns how many ran. Tasks queued
|
|
231
|
+
* meanwhile run too, but each key only once: a task queued again after it
|
|
232
|
+
* ran (a chart updated from its own `render` handler) waits for the next
|
|
233
|
+
* frame, instead of looping in this one and freezing the page.
|
|
234
|
+
*/
|
|
235
|
+
function flush() {
|
|
236
|
+
pending = false;
|
|
237
|
+
let count = 0;
|
|
238
|
+
const ran = /* @__PURE__ */ new Set();
|
|
239
|
+
const later = /* @__PURE__ */ new Map();
|
|
240
|
+
do {
|
|
241
|
+
for (const [key, task] of queue) {
|
|
242
|
+
queue.delete(key);
|
|
243
|
+
if (ran.has(key)) later.set(key, task);
|
|
244
|
+
else {
|
|
245
|
+
ran.add(key);
|
|
246
|
+
run(task);
|
|
247
|
+
count++;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
count += flushHooks.idle?.() ?? 0;
|
|
251
|
+
} while (queue.size > 0);
|
|
252
|
+
for (const [key, task] of later) schedule(key, task);
|
|
253
|
+
return count;
|
|
254
|
+
}
|
|
255
|
+
//#endregion
|
|
256
|
+
//#region src/chart.ts
|
|
257
|
+
const DEFAULT_WIDTH = 600;
|
|
258
|
+
const DEFAULT_ASPECT_RATIO = 2;
|
|
259
|
+
const DEFAULT_FONT_SIZE = 12;
|
|
260
|
+
let uid = 0;
|
|
261
|
+
const nextId = () => `tc-${++uid}`;
|
|
262
|
+
/** Resolve the final pixel size from options and the measured container size. */
|
|
263
|
+
function resolveSize(options, measured) {
|
|
264
|
+
const measuredWidth = measured?.width ?? 0;
|
|
265
|
+
const width = Math.max(0, Math.round(Number.isFinite(options.width) ? options.width : measuredWidth > 0 ? measuredWidth : DEFAULT_WIDTH));
|
|
266
|
+
const ratio = options.aspectRatio && options.aspectRatio > 0 ? options.aspectRatio : DEFAULT_ASPECT_RATIO;
|
|
267
|
+
const height = Number.isFinite(options.height) ? options.height : options.height === "container" && (measured?.height ?? 0) > 0 ? measured?.height : width / ratio;
|
|
268
|
+
return {
|
|
269
|
+
width,
|
|
270
|
+
height: Math.max(0, Math.round(height))
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
/** Run the chart type's `render()` for a config and size. */
|
|
274
|
+
function renderContent(config, size, id, onHitTest, hidden, fontSize) {
|
|
275
|
+
let found;
|
|
276
|
+
const ctx = renderContext(config, size, id, (interaction) => {
|
|
277
|
+
found = interaction;
|
|
278
|
+
onHitTest(interaction);
|
|
279
|
+
}, hidden, fontSize);
|
|
280
|
+
const content = config.type.render(config, ctx);
|
|
281
|
+
return features.post ? features.post(config, content, found, ctx) : content;
|
|
282
|
+
}
|
|
283
|
+
/** Render context for a config and size (also used by plugins such as the data table). */
|
|
284
|
+
function renderContext(config, size, id, onHitTest, hidden, measuredFontSize) {
|
|
285
|
+
return {
|
|
286
|
+
width: size.width,
|
|
287
|
+
height: size.height,
|
|
288
|
+
fontSize: config.fontSize ?? measuredFontSize ?? DEFAULT_FONT_SIZE,
|
|
289
|
+
locale: config.locale,
|
|
290
|
+
id,
|
|
291
|
+
onHitTest,
|
|
292
|
+
hidden
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* The config as cleaned by its chart type, without the options that are
|
|
297
|
+
* numbers nothing can be drawn with (NaN, ±Infinity, from a division or a
|
|
298
|
+
* parse gone wrong outside): their defaults apply, as if they were left out.
|
|
299
|
+
*/
|
|
300
|
+
function cleanData(config) {
|
|
301
|
+
const out = { ...config.type?.clean ? config.type.clean(config) : config };
|
|
302
|
+
for (const key in out) if (typeof out[key] === "number" && !Number.isFinite(out[key])) delete out[key];
|
|
303
|
+
return out;
|
|
304
|
+
}
|
|
305
|
+
function assertType(config) {
|
|
306
|
+
if (!config.type || typeof config.type.render !== "function") throw new TypeError("@tabler/charts: `type` must be a chart type such as line.");
|
|
307
|
+
}
|
|
308
|
+
/** Legend entries of a config, and whether the legend is shown. */
|
|
309
|
+
function resolveLegend(config) {
|
|
310
|
+
const items = config.type.legend?.(config) ?? [];
|
|
311
|
+
const option = config.legend;
|
|
312
|
+
return {
|
|
313
|
+
items,
|
|
314
|
+
show: option === void 0 ? items.length >= 2 : option !== false && items.length > 0,
|
|
315
|
+
position: typeof option === "object" && option.position === "bottom" ? "bottom" : "top"
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* The chart's accessible name: its `title`, or else the chart type and its
|
|
320
|
+
* legend entries ("line chart: Visitors, Sign-ups"), since an image without
|
|
321
|
+
* a name is announced as nothing at all. Set `title` for a name in the
|
|
322
|
+
* page's language.
|
|
323
|
+
*/
|
|
324
|
+
function chartLabel(config) {
|
|
325
|
+
if (config.title) return config.title;
|
|
326
|
+
const names = (config.type.legend?.(config) ?? []).map((item) => item.name).filter(Boolean);
|
|
327
|
+
const shown = names.slice(0, 6).join(", ");
|
|
328
|
+
return `${config.type.name} chart${names.length ? `: ${shown}${names.length > 6 ? ", …" : ""}` : ""}`;
|
|
329
|
+
}
|
|
330
|
+
/** Elements beyond which charts skip transitions unless `animate: true`. */
|
|
331
|
+
const ANIMATION_LIMIT = 1e3;
|
|
332
|
+
/** Number of elements in chart content. */
|
|
333
|
+
const countNodes = (child) => Array.isArray(child) ? child.reduce((n, c) => n + countNodes(c), 0) : child && typeof child === "object" ? 1 + countNodes(child.children) : 0;
|
|
334
|
+
/** Whether a chart renders without transitions: asked to, or too big to animate cheaply. */
|
|
335
|
+
const isStatic = (config, content) => config.animate === false || config.animate !== true && countNodes(content) > ANIMATION_LIMIT;
|
|
336
|
+
/** Wrap chart content (and hover layers) in the accessible root `<svg>`. */
|
|
337
|
+
function composeChart(config, size, id, still, content, underlay, overlay, extraAttrs) {
|
|
338
|
+
const { width, height } = size;
|
|
339
|
+
const descId = config.description ? `${id}-desc` : void 0;
|
|
340
|
+
const { patterns } = config;
|
|
341
|
+
const fills = patterns === false ? void 0 : (patterns === true ? feature("patterns") : features.patterns)?.(config, id);
|
|
342
|
+
return h("svg", {
|
|
343
|
+
class: [
|
|
344
|
+
"tc-chart",
|
|
345
|
+
`tc-chart-${config.type.name}`,
|
|
346
|
+
still && "tc-static",
|
|
347
|
+
fills?.[0],
|
|
348
|
+
config.class
|
|
349
|
+
],
|
|
350
|
+
style: fills?.[1],
|
|
351
|
+
viewBox: `0 0 ${width} ${height}`,
|
|
352
|
+
width,
|
|
353
|
+
height,
|
|
354
|
+
role: "img",
|
|
355
|
+
"aria-label": chartLabel(config),
|
|
356
|
+
"aria-describedby": descId,
|
|
357
|
+
...extraAttrs
|
|
358
|
+
}, descId && h("desc", {
|
|
359
|
+
key: "desc",
|
|
360
|
+
id: descId
|
|
361
|
+
}, config.description), fills?.[2], underlay && h("g", {
|
|
362
|
+
key: "hover-under",
|
|
363
|
+
class: "tc-hover-layer"
|
|
364
|
+
}, underlay), content, overlay && h("g", {
|
|
365
|
+
key: "hover-over",
|
|
366
|
+
class: "tc-hover-layer"
|
|
367
|
+
}, overlay));
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* Build the VNode tree of a chart: a pure function of the config and size,
|
|
371
|
+
* shared by the DOM chart and server-side rendering.
|
|
372
|
+
*/
|
|
373
|
+
function buildChart(config, size, id = config.id ?? "tc", onHitTest = () => {}) {
|
|
374
|
+
assertType(config);
|
|
375
|
+
config = cleanData(config);
|
|
376
|
+
const hidden = defaultHidden(resolveLegend(config).items);
|
|
377
|
+
const content = renderContent(config, size, id, onHitTest, hidden);
|
|
378
|
+
const base = config;
|
|
379
|
+
return composeChart(base, size, id, isStatic(base, content), content);
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* Render a chart to an SVG string, e.g. on the server.
|
|
383
|
+
*
|
|
384
|
+
* ```ts
|
|
385
|
+
* chartToString({ type: line, data, id: 'sales', locale: 'en-US' }, { width: 600, height: 300 })
|
|
386
|
+
* ```
|
|
387
|
+
*/
|
|
388
|
+
function chartToString(config, size) {
|
|
389
|
+
return renderToString(buildChart(config, size));
|
|
390
|
+
}
|
|
391
|
+
/** The name of every chart event, for adapters that pass them all on. */
|
|
392
|
+
const chartEvents = [
|
|
393
|
+
"hover",
|
|
394
|
+
"click",
|
|
395
|
+
"legend-toggle",
|
|
396
|
+
"render"
|
|
397
|
+
];
|
|
398
|
+
/** The chart on each element. */
|
|
399
|
+
const mounted = /* @__PURE__ */ new WeakMap();
|
|
400
|
+
/**
|
|
401
|
+
* A chart bound to a DOM element: measures its container, renders SVG into
|
|
402
|
+
* it and re-renders on `update()` and resize (batched per animation frame).
|
|
403
|
+
* Features such as the tooltip, the legend and pointer input (`hover` /
|
|
404
|
+
* `click` events, from `pointer()`, which the highlight and tooltip plugins
|
|
405
|
+
* turn on themselves) are plugins; the `Chart` exported by `@tabler/charts`
|
|
406
|
+
* installs the built-in ones.
|
|
407
|
+
*
|
|
408
|
+
* ```ts
|
|
409
|
+
* const chart = new Chart('#sales', { type: line, data })
|
|
410
|
+
* chart.update({ data: next })
|
|
411
|
+
* ```
|
|
412
|
+
*/
|
|
413
|
+
var Chart = class {
|
|
414
|
+
/** Element the chart renders into. */
|
|
415
|
+
element;
|
|
416
|
+
/** Id prefix used for elements inside the chart. */
|
|
417
|
+
id;
|
|
418
|
+
#cfg;
|
|
419
|
+
/** Container size changes, from the shared ResizeObserver. */
|
|
420
|
+
#onResize = (width, height) => {
|
|
421
|
+
const followsHeight = this.#cfg.height === "container";
|
|
422
|
+
const changed = width !== this.#measured.width || followsHeight && height !== this.#measured.height;
|
|
423
|
+
this.#measured = {
|
|
424
|
+
width,
|
|
425
|
+
height
|
|
426
|
+
};
|
|
427
|
+
if (changed && (width || height)) {
|
|
428
|
+
this.#font = void 0;
|
|
429
|
+
this.#markResizing();
|
|
430
|
+
this.#schedule();
|
|
431
|
+
}
|
|
432
|
+
};
|
|
433
|
+
#measured = {};
|
|
434
|
+
#handlers = /* @__PURE__ */ new Map();
|
|
435
|
+
#unobserve;
|
|
436
|
+
#plugins = [];
|
|
437
|
+
#destroyed = false;
|
|
438
|
+
#current;
|
|
439
|
+
#source;
|
|
440
|
+
#hovered = "";
|
|
441
|
+
#hit = null;
|
|
442
|
+
/** Chart type output of the last render, reused while only the highlight changes. */
|
|
443
|
+
#cache;
|
|
444
|
+
#resizeTimer;
|
|
445
|
+
/** Visibility set by the user, overriding each entry's default. */
|
|
446
|
+
#toggled = /* @__PURE__ */ new Map();
|
|
447
|
+
/** Server-rendered svg to take over on the first render, if any. */
|
|
448
|
+
#adopt;
|
|
449
|
+
/**
|
|
450
|
+
* The measured `--tc-font-size` (`undefined` reads it again). Reading it
|
|
451
|
+
* forces the browser to restyle the page, so new data alone reuses it.
|
|
452
|
+
*/
|
|
453
|
+
#font;
|
|
454
|
+
constructor(target, config, defaultPlugins = []) {
|
|
455
|
+
const element = typeof target === "string" ? document.querySelector(target) : target;
|
|
456
|
+
if (!element) throw new Error(`@tabler/charts: element "${String(target)}" not found.`);
|
|
457
|
+
mounted.get(element)?.destroy();
|
|
458
|
+
mounted.set(element, this);
|
|
459
|
+
this.element = element;
|
|
460
|
+
this.#cfg = cleanData(config);
|
|
461
|
+
this.id = config.id ?? nextId();
|
|
462
|
+
this.#adopt = element.querySelector(":scope > svg.tc-chart");
|
|
463
|
+
this.#measure();
|
|
464
|
+
this.#unobserve = observeResize(element, this.#onResize);
|
|
465
|
+
try {
|
|
466
|
+
for (const plugin of [...defaultPlugins, ...config.plugins ?? []]) this.#plugins.push(plugin.install(this));
|
|
467
|
+
this.render();
|
|
468
|
+
} catch (error) {
|
|
469
|
+
this.destroy();
|
|
470
|
+
throw error;
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
/** Current configuration. */
|
|
474
|
+
get config() {
|
|
475
|
+
return this.#cfg;
|
|
476
|
+
}
|
|
477
|
+
/** Size of the last render. */
|
|
478
|
+
get size() {
|
|
479
|
+
let measured = this.#measured;
|
|
480
|
+
if (this.#cfg.height === "container" && measured.height) {
|
|
481
|
+
let reserved = 0;
|
|
482
|
+
for (const plugin of this.#plugins) reserved += plugin.reservedHeight?.() ?? 0;
|
|
483
|
+
if (reserved) measured = {
|
|
484
|
+
...measured,
|
|
485
|
+
height: measured.height - reserved
|
|
486
|
+
};
|
|
487
|
+
}
|
|
488
|
+
return resolveSize(this.#cfg, measured);
|
|
489
|
+
}
|
|
490
|
+
/** Font size used by the last render (explicit, measured, or the default). */
|
|
491
|
+
get fontSize() {
|
|
492
|
+
return this.#cache?.fontSize ?? this.#cfg.fontSize ?? DEFAULT_FONT_SIZE;
|
|
493
|
+
}
|
|
494
|
+
/** How pointer and keyboard map to data for the current render. */
|
|
495
|
+
get interaction() {
|
|
496
|
+
return this.#current;
|
|
497
|
+
}
|
|
498
|
+
/** The highlighted category (hover or keyboard), or `null`. */
|
|
499
|
+
get active() {
|
|
500
|
+
return this.#hit;
|
|
501
|
+
}
|
|
502
|
+
/**
|
|
503
|
+
* The pointer in chart pixels while it drives the highlight (`undefined`
|
|
504
|
+
* for keyboard highlights). `hitAnchor(chart.active, chart.pointer)` gives
|
|
505
|
+
* where a tooltip belongs either way.
|
|
506
|
+
*/
|
|
507
|
+
get pointer() {
|
|
508
|
+
const source = this.#source;
|
|
509
|
+
return this.#hit && source?.kind === "pointer" ? {
|
|
510
|
+
x: source.x,
|
|
511
|
+
y: source.y
|
|
512
|
+
} : void 0;
|
|
513
|
+
}
|
|
514
|
+
/** Whether the highlight comes from the pointer or from `highlightIndex()` (keyboard). */
|
|
515
|
+
get highlightSource() {
|
|
516
|
+
return this.#hit ? this.#source?.kind : void 0;
|
|
517
|
+
}
|
|
518
|
+
/**
|
|
519
|
+
* Highlight a category by index (and optionally one series in it), as
|
|
520
|
+
* keyboard navigation does. Returns the hit, or `null` for an invalid index.
|
|
521
|
+
*/
|
|
522
|
+
highlightIndex(index, seriesIndex) {
|
|
523
|
+
const hit = this.#current?.hitIndex(index, seriesIndex) ?? null;
|
|
524
|
+
if (!hit) return null;
|
|
525
|
+
this.#source = {
|
|
526
|
+
kind: "index",
|
|
527
|
+
index,
|
|
528
|
+
seriesIndex
|
|
529
|
+
};
|
|
530
|
+
this.#setHover(hit);
|
|
531
|
+
return hit;
|
|
532
|
+
}
|
|
533
|
+
/**
|
|
534
|
+
* Highlight what lies at a point in chart pixels, as the pointer does (the
|
|
535
|
+
* `pointer()` plugin calls it). Returns the hit, or `null` for none.
|
|
536
|
+
*/
|
|
537
|
+
highlightAt(x, y, event) {
|
|
538
|
+
const hit = this.hitTest(x, y);
|
|
539
|
+
this.#source = {
|
|
540
|
+
kind: "pointer",
|
|
541
|
+
x,
|
|
542
|
+
y
|
|
543
|
+
};
|
|
544
|
+
this.#setHover(hit, event);
|
|
545
|
+
return hit;
|
|
546
|
+
}
|
|
547
|
+
/** Remove any highlight. */
|
|
548
|
+
clearHighlight(event) {
|
|
549
|
+
this.#source = void 0;
|
|
550
|
+
this.#setHover(null, event);
|
|
551
|
+
}
|
|
552
|
+
/**
|
|
553
|
+
* Show or hide a legend entry (series) by key, name or index; toggles when
|
|
554
|
+
* `hidden` is omitted. Re-renders in the next frame.
|
|
555
|
+
*/
|
|
556
|
+
toggleSeries(target, hidden) {
|
|
557
|
+
const { items } = resolveLegend(this.#cfg);
|
|
558
|
+
const item = typeof target === "number" ? items.find((entry) => entry.index === target) : items.find((entry) => entry.key === target) ?? items.find((entry) => entry.name === target);
|
|
559
|
+
if (!item) return this;
|
|
560
|
+
const next = hidden ?? !this.#hiddenSet(items).has(item.key);
|
|
561
|
+
this.#toggled.set(item.key, next);
|
|
562
|
+
this.emit("legend-toggle", {
|
|
563
|
+
key: item.key,
|
|
564
|
+
name: item.name,
|
|
565
|
+
index: item.index,
|
|
566
|
+
hidden: next
|
|
567
|
+
});
|
|
568
|
+
this.#schedule();
|
|
569
|
+
return this;
|
|
570
|
+
}
|
|
571
|
+
/** Whether a legend entry is hidden. */
|
|
572
|
+
isHidden(key) {
|
|
573
|
+
return this.#hiddenSet(resolveLegend(this.#cfg).items).has(key);
|
|
574
|
+
}
|
|
575
|
+
/** Merge `options` into the configuration and re-render in the next frame. */
|
|
576
|
+
update(options) {
|
|
577
|
+
this.#cfg = cleanData({
|
|
578
|
+
...this.#cfg,
|
|
579
|
+
...options
|
|
580
|
+
});
|
|
581
|
+
for (const key in options) if (key !== "data") this.#font = void 0;
|
|
582
|
+
this.#schedule();
|
|
583
|
+
return this;
|
|
584
|
+
}
|
|
585
|
+
/**
|
|
586
|
+
* Replace the whole configuration and re-render in the next frame: options
|
|
587
|
+
* left out go back to their defaults (`update()` would keep them).
|
|
588
|
+
*/
|
|
589
|
+
setConfig(config) {
|
|
590
|
+
this.#cfg = cleanData(config);
|
|
591
|
+
this.#font = void 0;
|
|
592
|
+
this.#schedule();
|
|
593
|
+
return this;
|
|
594
|
+
}
|
|
595
|
+
/** Replace the data and re-render in the next frame. */
|
|
596
|
+
setData(data) {
|
|
597
|
+
return this.update({ data });
|
|
598
|
+
}
|
|
599
|
+
/**
|
|
600
|
+
* Re-measure the container and re-render in the next frame. Call it when a
|
|
601
|
+
* container taken out of the page without `destroy()` comes back.
|
|
602
|
+
*/
|
|
603
|
+
resize() {
|
|
604
|
+
if (!this.#destroyed) this.#unobserve = observeResize(this.element, this.#onResize);
|
|
605
|
+
this.#measure();
|
|
606
|
+
this.#font = void 0;
|
|
607
|
+
this.#schedule();
|
|
608
|
+
return this;
|
|
609
|
+
}
|
|
610
|
+
/** Render synchronously now. */
|
|
611
|
+
render() {
|
|
612
|
+
if (this.#destroyed) return this;
|
|
613
|
+
cancel(this);
|
|
614
|
+
const cfg = this.#cfg;
|
|
615
|
+
const config = cfg;
|
|
616
|
+
assertType(config);
|
|
617
|
+
const legend = resolveLegend(cfg);
|
|
618
|
+
const hidden = this.#hiddenSet(legend.items);
|
|
619
|
+
for (const plugin of this.#plugins) plugin.beforeRender?.({
|
|
620
|
+
config,
|
|
621
|
+
legend,
|
|
622
|
+
hidden
|
|
623
|
+
});
|
|
624
|
+
const size = this.size;
|
|
625
|
+
const { content, stale, changed } = this.#content(size, hidden);
|
|
626
|
+
if (stale) this.#refreshHighlight();
|
|
627
|
+
const adopted = this.#adopt;
|
|
628
|
+
render(this.element, this.#compose(content, size), adopted);
|
|
629
|
+
this.#adopt = null;
|
|
630
|
+
if (adopted) this.#markResizing();
|
|
631
|
+
for (const plugin of this.#plugins) plugin.afterRender?.({
|
|
632
|
+
config,
|
|
633
|
+
legend,
|
|
634
|
+
hidden,
|
|
635
|
+
size,
|
|
636
|
+
stale,
|
|
637
|
+
changed
|
|
638
|
+
});
|
|
639
|
+
if (stale) this.emit("render", { size });
|
|
640
|
+
return this;
|
|
641
|
+
}
|
|
642
|
+
/**
|
|
643
|
+
* The chart type's output for the current config, size, hidden series and
|
|
644
|
+
* font size: built again when one of them changed (`stale`; `changed` when
|
|
645
|
+
* it is what the chart shows, not only its size), else the one of the last render.
|
|
646
|
+
*/
|
|
647
|
+
#content(size, hidden) {
|
|
648
|
+
const cfg = this.#cfg;
|
|
649
|
+
const hiddenKey = [...hidden].sort().join("\0");
|
|
650
|
+
this.#font ??= cfg.fontSize ?? this.#measureFontSize();
|
|
651
|
+
const fontSize = cfg.fontSize ?? this.#font;
|
|
652
|
+
let cache = this.#cache;
|
|
653
|
+
const changed = !cache || cache.cfg !== cfg || cache.hidden !== hiddenKey;
|
|
654
|
+
const stale = changed || cache?.width !== size.width || cache.height !== size.height || cache.fontSize !== fontSize;
|
|
655
|
+
if (!cache || stale) {
|
|
656
|
+
this.#current = void 0;
|
|
657
|
+
const content = renderContent(cfg, size, this.id, (interaction) => {
|
|
658
|
+
this.#current = interaction;
|
|
659
|
+
}, hidden, fontSize);
|
|
660
|
+
cache = {
|
|
661
|
+
cfg,
|
|
662
|
+
width: size.width,
|
|
663
|
+
height: size.height,
|
|
664
|
+
hidden: hiddenKey,
|
|
665
|
+
fontSize,
|
|
666
|
+
content,
|
|
667
|
+
still: isStatic(cfg, content)
|
|
668
|
+
};
|
|
669
|
+
this.#cache = cache;
|
|
670
|
+
}
|
|
671
|
+
return {
|
|
672
|
+
content: cache,
|
|
673
|
+
stale,
|
|
674
|
+
changed
|
|
675
|
+
};
|
|
676
|
+
}
|
|
677
|
+
/** Keep the highlight (and its consumers, like tooltips) in sync with new data or layout. */
|
|
678
|
+
#refreshHighlight() {
|
|
679
|
+
const source = this.#source;
|
|
680
|
+
if (!source) return;
|
|
681
|
+
const next = source.kind === "pointer" ? this.hitTest(source.x, source.y) : this.#current?.hitIndex(source.index, source.seriesIndex) ?? null;
|
|
682
|
+
this.#setHover(next, void 0, true, false);
|
|
683
|
+
}
|
|
684
|
+
/** The root svg: the content, with the plugins' hover layers and attributes. */
|
|
685
|
+
#compose(content, size) {
|
|
686
|
+
const config = this.#cfg;
|
|
687
|
+
const hit = this.#hit;
|
|
688
|
+
const under = [];
|
|
689
|
+
const over = [];
|
|
690
|
+
let attrs;
|
|
691
|
+
for (const plugin of this.#plugins) {
|
|
692
|
+
if (hit && plugin.layers) {
|
|
693
|
+
const layer = plugin.layers(hit, config);
|
|
694
|
+
under.push(layer.under);
|
|
695
|
+
over.push(layer.over);
|
|
696
|
+
}
|
|
697
|
+
const extra = plugin.svgAttrs?.(config);
|
|
698
|
+
if (extra) attrs = {
|
|
699
|
+
...attrs,
|
|
700
|
+
...extra
|
|
701
|
+
};
|
|
702
|
+
}
|
|
703
|
+
return composeChart(config, size, this.id, content.still, content.content, under.length ? under : void 0, over.length ? over : void 0, attrs);
|
|
704
|
+
}
|
|
705
|
+
/** What lies at a point in chart pixels, or `null`. */
|
|
706
|
+
hitTest(x, y) {
|
|
707
|
+
return this.#current?.hitTest(x, y) ?? null;
|
|
708
|
+
}
|
|
709
|
+
/** Subscribe to an event; returns a function that unsubscribes. */
|
|
710
|
+
on(name, handler) {
|
|
711
|
+
let set = this.#handlers.get(name);
|
|
712
|
+
if (!set) {
|
|
713
|
+
set = /* @__PURE__ */ new Set();
|
|
714
|
+
this.#handlers.set(name, set);
|
|
715
|
+
}
|
|
716
|
+
set.add(handler);
|
|
717
|
+
return () => {
|
|
718
|
+
set.delete(handler);
|
|
719
|
+
};
|
|
720
|
+
}
|
|
721
|
+
/** Remove the chart from the DOM and stop observing its container. */
|
|
722
|
+
destroy() {
|
|
723
|
+
if (this.#destroyed) return;
|
|
724
|
+
this.#destroyed = true;
|
|
725
|
+
if (mounted.get(this.element) === this) mounted.delete(this.element);
|
|
726
|
+
cancel(this);
|
|
727
|
+
clearTimeout(this.#resizeTimer);
|
|
728
|
+
this.#unobserve();
|
|
729
|
+
for (const plugin of this.#plugins) plugin.destroy?.();
|
|
730
|
+
this.#handlers.clear();
|
|
731
|
+
render(this.element, null);
|
|
732
|
+
}
|
|
733
|
+
/**
|
|
734
|
+
* Update the highlighted hit: emit `hover` when it changed (or when
|
|
735
|
+
* `force`d after new data) and re-render the hover layers in the next frame.
|
|
736
|
+
*/
|
|
737
|
+
#setHover(hit, event, force = false, rerender = true) {
|
|
738
|
+
const key = hitKey(hit);
|
|
739
|
+
if (!force && key === this.#hovered) return;
|
|
740
|
+
if (force && key === "" && this.#hovered === "") return;
|
|
741
|
+
this.#hovered = key;
|
|
742
|
+
this.#hit = hit;
|
|
743
|
+
this.emit("hover", event ? {
|
|
744
|
+
hit,
|
|
745
|
+
event
|
|
746
|
+
} : { hit });
|
|
747
|
+
if (rerender) this.#schedule();
|
|
748
|
+
}
|
|
749
|
+
#hiddenSet(items) {
|
|
750
|
+
const hidden = /* @__PURE__ */ new Set();
|
|
751
|
+
for (const item of items) if (this.#toggled.get(item.key) ?? item.hidden) hidden.add(item.key);
|
|
752
|
+
return hidden;
|
|
753
|
+
}
|
|
754
|
+
/** Suspend transitions while the container keeps resizing (see `[data-resizing]` in CSS). */
|
|
755
|
+
#markResizing() {
|
|
756
|
+
const svg = this.element.querySelector(":scope > svg.tc-chart");
|
|
757
|
+
if (!svg) return;
|
|
758
|
+
svg.setAttribute("data-resizing", "");
|
|
759
|
+
clearTimeout(this.#resizeTimer);
|
|
760
|
+
this.#resizeTimer = setTimeout(() => svg.removeAttribute("data-resizing"), 200);
|
|
761
|
+
}
|
|
762
|
+
#schedule() {
|
|
763
|
+
if (!this.#destroyed) schedule(this, () => this.render());
|
|
764
|
+
}
|
|
765
|
+
/** The `--tc-font-size` in effect on the container, in pixels (browser only). */
|
|
766
|
+
#measureFontSize() {
|
|
767
|
+
if (typeof getComputedStyle !== "function") return void 0;
|
|
768
|
+
const value = Number.parseFloat(getComputedStyle(this.element).getPropertyValue("--tc-font-size"));
|
|
769
|
+
return Number.isFinite(value) && value > 0 ? value : void 0;
|
|
770
|
+
}
|
|
771
|
+
/** Measure the content box, matching what `ResizeObserver` reports. */
|
|
772
|
+
#measure() {
|
|
773
|
+
const el = this.element;
|
|
774
|
+
const style = typeof getComputedStyle === "function" ? getComputedStyle(el) : void 0;
|
|
775
|
+
const px = (value) => Number.parseFloat(value ?? "") || 0;
|
|
776
|
+
this.#measured = {
|
|
777
|
+
width: el.clientWidth - px(style?.paddingLeft) - px(style?.paddingRight),
|
|
778
|
+
height: el.clientHeight - px(style?.paddingTop) - px(style?.paddingBottom)
|
|
779
|
+
};
|
|
780
|
+
}
|
|
781
|
+
/** Call the handlers of an event (plugins emit `click`, for instance). */
|
|
782
|
+
emit(name, event) {
|
|
783
|
+
const set = this.#handlers.get(name);
|
|
784
|
+
if (set) for (const handler of set) handler(event);
|
|
785
|
+
}
|
|
786
|
+
};
|
|
787
|
+
//#endregion
|
|
788
|
+
export { defaultHidden as _, chartToString as a, resolveSize as c, flushHooks as d, run as f, renderToString as g, escapeText as h, chartLabel as i, cancel as l, escapeAttr as m, buildChart as n, renderContext as o, schedule as p, chartEvents as r, resolveLegend as s, Chart as t, flush as u, legendContent as v, toChartPoint as y };
|
|
789
|
+
|
|
790
|
+
//# sourceMappingURL=chart-BF2CK9I_.js.map
|