@tabler/charts 0.0.0-stage → 0.0.1-alpha.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 +248 -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/area-BFvkc-ZM.d.cts +20 -0
- package/dist/area-DQsLERhx.js +26 -0
- package/dist/area-DQsLERhx.js.map +1 -0
- package/dist/area-DaO4MQl4.d.ts +20 -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-C-7zR2qp.cjs +243 -0
- package/dist/bar-C-7zR2qp.cjs.map +1 -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-DdsDxk3W.d.ts +43 -0
- package/dist/bar-a0h9KC8A.d.cts +43 -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-BKdPyorY.d.cts +44 -0
- package/dist/candlestick-BnUG1SGi.d.ts +44 -0
- package/dist/candlestick-DuXwAFID.js +145 -0
- package/dist/candlestick-DuXwAFID.js.map +1 -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-Qa417fJo.d.cts +927 -0
- package/dist/chart-iJGxMz9z.d.ts +927 -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-C7fPm6t7.cjs +976 -0
- package/dist/core-C7fPm6t7.cjs.map +1 -0
- package/dist/core-CjgbhS_v.d.ts +219 -0
- package/dist/core-CnGFKojH.d.cts +219 -0
- package/dist/core-plobgBC7.js +875 -0
- package/dist/core-plobgBC7.js.map +1 -0
- package/dist/core.cjs +113 -0
- package/dist/core.d.cts +20 -0
- package/dist/core.d.ts +20 -0
- package/dist/core.js +24 -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-CEfkWXSu.cjs +235 -0
- package/dist/gauge-CEfkWXSu.cjs.map +1 -0
- package/dist/gauge-Cu9jttC0.d.ts +65 -0
- package/dist/gauge-Cu_OFxBd.d.cts +65 -0
- package/dist/gauge-_ljQHrMN.js +230 -0
- package/dist/gauge-_ljQHrMN.js.map +1 -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-BwS-y0c6.d.cts +81 -0
- package/dist/heatmap-DSZ2bVIa.js +242 -0
- package/dist/heatmap-DSZ2bVIa.js.map +1 -0
- package/dist/heatmap-PhLPXIg1.d.ts +81 -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 +211 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +45 -0
- package/dist/index.d.ts +45 -0
- package/dist/index.js +113 -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-CMDGH6q5.d.cts +47 -0
- package/dist/line-D5kb8e6w.d.ts +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/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-B8UlOZiq.d.ts +58 -0
- package/dist/pie-C1Pa6W_l.cjs +211 -0
- package/dist/pie-C1Pa6W_l.cjs.map +1 -0
- package/dist/pie-DnQQmxkk.d.cts +58 -0
- package/dist/pie-RnMTQWMS.js +200 -0
- package/dist/pie-RnMTQWMS.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-BB13CGmq.d.cts +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-pFI6fvOq.d.ts +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-B9JYnx7e.d.cts +67 -0
- package/dist/sankey-Bacx4fVe.cjs +425 -0
- package/dist/sankey-Bacx4fVe.cjs.map +1 -0
- package/dist/sankey-Bm518bqL.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-Bl7nasE6.d.ts +61 -0
- package/dist/scatter-DgMN9zRy.cjs +250 -0
- package/dist/scatter-DgMN9zRy.cjs.map +1 -0
- package/dist/scatter-DrJ8xYz4.d.cts +61 -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-BG13V4Pz.d.cts +43 -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-iWuXbKpd.d.ts +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-Duowaput.cjs +369 -0
- package/dist/sweep-Duowaput.cjs.map +1 -0
- package/dist/sweep-WSgn2etB.js +334 -0
- package/dist/sweep-WSgn2etB.js.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 +310 -3
|
@@ -0,0 +1,976 @@
|
|
|
1
|
+
const require_layout = require("./layout-CtMBhNd9.cjs");
|
|
2
|
+
const require_vnode = require("./vnode-CkQ27Cxe.cjs");
|
|
3
|
+
const require_format = require("./format-B0yKXBTH.cjs");
|
|
4
|
+
const require_cartesian = require("./cartesian-BoDfgBCV.cjs");
|
|
5
|
+
const require_features = require("./features-BclHgg2W.cjs");
|
|
6
|
+
const require_chart = require("./chart-CowF_lWY.cjs");
|
|
7
|
+
const require_dom = require("./dom-CLF868Qs.cjs");
|
|
8
|
+
//#region src/plugins/download.ts
|
|
9
|
+
const NAMES = {
|
|
10
|
+
png: "PNG",
|
|
11
|
+
svg: "SVG",
|
|
12
|
+
jpeg: "JPEG",
|
|
13
|
+
webp: "WebP"
|
|
14
|
+
};
|
|
15
|
+
const DEFAULT_FORMATS = ["png", "svg"];
|
|
16
|
+
function resolve(option) {
|
|
17
|
+
return option === true ? {} : Array.isArray(option) ? { formats: option } : option;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* A download menu in the chart's corner (`.tc-download`): a button that opens
|
|
21
|
+
* a list of file formats, PNG and SVG by default. Shown with the `download`
|
|
22
|
+
* option. The files come from `@tabler/charts/export`, which must be imported
|
|
23
|
+
* (the chart says so otherwise): that way charts without a download never
|
|
24
|
+
* carry the export code.
|
|
25
|
+
*/
|
|
26
|
+
function download() {
|
|
27
|
+
return {
|
|
28
|
+
name: "download",
|
|
29
|
+
install(chart) {
|
|
30
|
+
const host = chart.element;
|
|
31
|
+
const doc = host.ownerDocument;
|
|
32
|
+
let el;
|
|
33
|
+
let options = {};
|
|
34
|
+
const addedClass = !host.classList.contains("tc-container");
|
|
35
|
+
const toggle = () => el?.querySelector(".tc-download-toggle");
|
|
36
|
+
const menu = () => el?.querySelector(".tc-download-menu");
|
|
37
|
+
const items = () => Array.from(el?.querySelectorAll(".tc-download-item") ?? []);
|
|
38
|
+
const setOpen = (open) => {
|
|
39
|
+
const list = menu();
|
|
40
|
+
if (!list) return;
|
|
41
|
+
list.hidden = !open;
|
|
42
|
+
toggle()?.setAttribute("aria-expanded", String(open));
|
|
43
|
+
if (open) doc.addEventListener("pointerdown", onOutside, true);
|
|
44
|
+
else doc.removeEventListener("pointerdown", onOutside, true);
|
|
45
|
+
};
|
|
46
|
+
const isOpen = () => menu()?.hidden === false;
|
|
47
|
+
const onOutside = (event) => {
|
|
48
|
+
if (!el?.contains(event.target)) setOpen(false);
|
|
49
|
+
};
|
|
50
|
+
const onClick = (event) => {
|
|
51
|
+
const target = event.target;
|
|
52
|
+
if (target.closest(".tc-download-toggle")) {
|
|
53
|
+
setOpen(!isOpen());
|
|
54
|
+
if (isOpen()) items()[0]?.focus();
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const format = target.closest(".tc-download-item")?.getAttribute("data-format");
|
|
58
|
+
if (!format) return;
|
|
59
|
+
setOpen(false);
|
|
60
|
+
toggle()?.focus();
|
|
61
|
+
require_features.feature("export")(chart, {
|
|
62
|
+
...options,
|
|
63
|
+
format
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
const onKey = (event) => {
|
|
67
|
+
if (event.key === "Escape" && isOpen()) {
|
|
68
|
+
event.preventDefault();
|
|
69
|
+
setOpen(false);
|
|
70
|
+
toggle()?.focus();
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (event.key !== "ArrowDown" && event.key !== "ArrowUp") return;
|
|
74
|
+
const list = items();
|
|
75
|
+
if (!list.length) return;
|
|
76
|
+
event.preventDefault();
|
|
77
|
+
if (!isOpen()) setOpen(true);
|
|
78
|
+
list[(list.indexOf(doc.activeElement) + (event.key === "ArrowDown" ? 1 : -1) + list.length) % list.length]?.focus();
|
|
79
|
+
};
|
|
80
|
+
const onBlur = (event) => {
|
|
81
|
+
if (!el?.contains(event.relatedTarget)) setOpen(false);
|
|
82
|
+
};
|
|
83
|
+
const remove = () => {
|
|
84
|
+
if (!el) return;
|
|
85
|
+
setOpen(false);
|
|
86
|
+
require_dom.render(el, null);
|
|
87
|
+
el.remove();
|
|
88
|
+
el = void 0;
|
|
89
|
+
if (addedClass) host.classList.remove("tc-container");
|
|
90
|
+
};
|
|
91
|
+
return {
|
|
92
|
+
afterRender({ config, changed }) {
|
|
93
|
+
const option = config.download;
|
|
94
|
+
if (!option || typeof document === "undefined") {
|
|
95
|
+
remove();
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
if (!changed && el?.isConnected) return;
|
|
99
|
+
require_features.feature("export");
|
|
100
|
+
options = resolve(option);
|
|
101
|
+
const formats = options.formats?.length ? options.formats : DEFAULT_FORMATS;
|
|
102
|
+
if (!el) {
|
|
103
|
+
el = doc.createElement("div");
|
|
104
|
+
el.className = "tc-download";
|
|
105
|
+
el.addEventListener("click", onClick);
|
|
106
|
+
el.addEventListener("keydown", onKey);
|
|
107
|
+
el.addEventListener("focusout", onBlur);
|
|
108
|
+
}
|
|
109
|
+
require_dom.render(el, require_vnode.h("div", { class: "tc-download-box" }, require_vnode.h("button", {
|
|
110
|
+
type: "button",
|
|
111
|
+
class: "tc-download-toggle",
|
|
112
|
+
"aria-label": options.label ?? "Download",
|
|
113
|
+
"aria-haspopup": "menu",
|
|
114
|
+
"aria-expanded": "false"
|
|
115
|
+
}, require_vnode.h("svg", {
|
|
116
|
+
viewBox: "0 0 24 24",
|
|
117
|
+
width: "16",
|
|
118
|
+
height: "16",
|
|
119
|
+
"aria-hidden": "true",
|
|
120
|
+
fill: "none",
|
|
121
|
+
stroke: "currentColor",
|
|
122
|
+
"stroke-width": "2",
|
|
123
|
+
"stroke-linecap": "round",
|
|
124
|
+
"stroke-linejoin": "round"
|
|
125
|
+
}, require_vnode.h("path", { d: "M4 17v2a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-2M7 11l5 5 5-5M12 4v12" }))), require_vnode.h("div", {
|
|
126
|
+
class: "tc-download-menu",
|
|
127
|
+
role: "menu",
|
|
128
|
+
hidden: ""
|
|
129
|
+
}, formats.map((format) => require_vnode.h("button", {
|
|
130
|
+
key: format,
|
|
131
|
+
type: "button",
|
|
132
|
+
role: "menuitem",
|
|
133
|
+
class: "tc-download-item",
|
|
134
|
+
"data-format": format
|
|
135
|
+
}, NAMES[format] ?? format)))));
|
|
136
|
+
host.classList.add("tc-container");
|
|
137
|
+
if (!el.isConnected) host.appendChild(el);
|
|
138
|
+
},
|
|
139
|
+
destroy: remove
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
//#endregion
|
|
145
|
+
//#region src/components/hover.ts
|
|
146
|
+
/** Series wrapper so hover marks pick up the series color from CSS. */
|
|
147
|
+
function seriesGroup(seriesIndex, color, child) {
|
|
148
|
+
return require_vnode.h("g", {
|
|
149
|
+
key: seriesIndex,
|
|
150
|
+
class: ["tc-series", `tc-series-${seriesIndex + 1}`],
|
|
151
|
+
style: { "--tc-series-color": color }
|
|
152
|
+
}, child);
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Hover marks drawn below the series: a band behind the hovered category of
|
|
156
|
+
* band charts (bars), or a vertical crosshair for point charts (lines).
|
|
157
|
+
*/
|
|
158
|
+
function hoverUnderlay(hit, crosshair = true) {
|
|
159
|
+
const { area } = hit;
|
|
160
|
+
return require_vnode.h("g", {
|
|
161
|
+
class: "tc-hover",
|
|
162
|
+
"aria-hidden": "true"
|
|
163
|
+
}, hit.mark ? null : hit.band ? require_vnode.h("rect", {
|
|
164
|
+
class: "tc-hover-band",
|
|
165
|
+
x: require_layout.round(hit.band.x),
|
|
166
|
+
y: require_layout.round(hit.band.y),
|
|
167
|
+
width: require_layout.round(hit.band.width),
|
|
168
|
+
height: require_layout.round(hit.band.height)
|
|
169
|
+
}) : crosshair && require_vnode.h("line", hit.guide ? {
|
|
170
|
+
class: "tc-crosshair",
|
|
171
|
+
x1: require_layout.round(hit.guide.x1),
|
|
172
|
+
x2: require_layout.round(hit.guide.x2),
|
|
173
|
+
y1: require_layout.round(hit.guide.y1),
|
|
174
|
+
y2: require_layout.round(hit.guide.y2)
|
|
175
|
+
} : {
|
|
176
|
+
class: "tc-crosshair",
|
|
177
|
+
x1: require_layout.round(hit.x),
|
|
178
|
+
x2: require_layout.round(hit.x),
|
|
179
|
+
y1: require_layout.round(area.y),
|
|
180
|
+
y2: require_layout.round(area.y + area.height)
|
|
181
|
+
}));
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Hover marks drawn above the series: the hit's own mark (pie slices), or
|
|
185
|
+
* an active dot on every point of point charts (of the series' `shape`, if given).
|
|
186
|
+
*/
|
|
187
|
+
function hoverOverlay(hit, radius = 4, shape) {
|
|
188
|
+
const { mark } = hit;
|
|
189
|
+
if (mark) {
|
|
190
|
+
const item = hit.items.find((i) => i.seriesIndex === hit.seriesIndex) ?? hit.items[0];
|
|
191
|
+
return require_vnode.h("g", {
|
|
192
|
+
class: "tc-hover",
|
|
193
|
+
"aria-hidden": "true"
|
|
194
|
+
}, item && seriesGroup(item.seriesIndex, item.color, require_vnode.h("path", {
|
|
195
|
+
class: "tc-hover-mark",
|
|
196
|
+
d: mark.d,
|
|
197
|
+
style: `transform:translate(${require_layout.round(mark.x)}px,${require_layout.round(mark.y)}px)`
|
|
198
|
+
})));
|
|
199
|
+
}
|
|
200
|
+
return require_vnode.h("g", {
|
|
201
|
+
class: "tc-hover",
|
|
202
|
+
"aria-hidden": "true"
|
|
203
|
+
}, !hit.band && hit.items.map((item) => item.y !== null && seriesGroup(item.seriesIndex, item.color, shape ? require_vnode.h("path", {
|
|
204
|
+
class: "tc-point tc-point-active tc-marker",
|
|
205
|
+
d: shape(item.seriesIndex, item.x, item.y, radius)
|
|
206
|
+
}) : require_vnode.h("circle", {
|
|
207
|
+
class: "tc-point tc-point-active",
|
|
208
|
+
cx: require_layout.round(item.x),
|
|
209
|
+
cy: require_layout.round(item.y),
|
|
210
|
+
r: radius
|
|
211
|
+
}))));
|
|
212
|
+
}
|
|
213
|
+
//#endregion
|
|
214
|
+
//#region src/plugins/pointer.ts
|
|
215
|
+
const listening = /* @__PURE__ */ new WeakSet();
|
|
216
|
+
/**
|
|
217
|
+
* Turn pointer input on the chart's element into highlights and `hover` /
|
|
218
|
+
* `click` events (once per chart, however many plugins ask). Returns the
|
|
219
|
+
* function that stops listening, or nothing when already listening.
|
|
220
|
+
*/
|
|
221
|
+
function listenPointer(chart) {
|
|
222
|
+
const el = chart.element;
|
|
223
|
+
if (listening.has(chart) || typeof el.addEventListener !== "function") return void 0;
|
|
224
|
+
listening.add(chart);
|
|
225
|
+
const local = (event) => {
|
|
226
|
+
const svg = el.querySelector("svg.tc-chart");
|
|
227
|
+
if (!svg) return void 0;
|
|
228
|
+
const { width, height } = chart.size;
|
|
229
|
+
return require_chart.toChartPoint(svg, event.clientX, event.clientY, width, height);
|
|
230
|
+
};
|
|
231
|
+
const onMove = (event) => {
|
|
232
|
+
const point = local(event);
|
|
233
|
+
if (point) chart.highlightAt(point.x, point.y, event);
|
|
234
|
+
};
|
|
235
|
+
const onLeave = (event) => {
|
|
236
|
+
if (event.pointerType !== "touch" && chart.highlightSource === "pointer") chart.clearHighlight(event);
|
|
237
|
+
};
|
|
238
|
+
const onClick = (event) => {
|
|
239
|
+
const point = local(event);
|
|
240
|
+
const hit = point ? chart.hitTest(point.x, point.y) : null;
|
|
241
|
+
if (hit) chart.emit("click", {
|
|
242
|
+
hit,
|
|
243
|
+
event
|
|
244
|
+
});
|
|
245
|
+
};
|
|
246
|
+
el.addEventListener("pointermove", onMove);
|
|
247
|
+
el.addEventListener("pointerdown", onMove);
|
|
248
|
+
el.addEventListener("pointerleave", onLeave);
|
|
249
|
+
el.addEventListener("click", onClick);
|
|
250
|
+
return () => {
|
|
251
|
+
listening.delete(chart);
|
|
252
|
+
el.removeEventListener("pointermove", onMove);
|
|
253
|
+
el.removeEventListener("pointerdown", onMove);
|
|
254
|
+
el.removeEventListener("pointerleave", onLeave);
|
|
255
|
+
el.removeEventListener("click", onClick);
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Pointer input: hovering highlights what is under the pointer and emits
|
|
260
|
+
* `hover`, clicking emits `click`. The highlight and tooltip plugins turn it
|
|
261
|
+
* on themselves; add it to a bare `Chart` that only needs the events.
|
|
262
|
+
*/
|
|
263
|
+
function pointer() {
|
|
264
|
+
return {
|
|
265
|
+
name: "pointer",
|
|
266
|
+
install(chart) {
|
|
267
|
+
const stop = listenPointer(chart);
|
|
268
|
+
return stop ? { destroy: stop } : {};
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
//#endregion
|
|
273
|
+
//#region src/plugins/highlight.ts
|
|
274
|
+
/**
|
|
275
|
+
* Draws the highlighted category: a crosshair (or a band behind bars) under
|
|
276
|
+
* the series and active dots above them. `crosshair: false` keeps the dots.
|
|
277
|
+
*/
|
|
278
|
+
function highlight() {
|
|
279
|
+
return {
|
|
280
|
+
name: "highlight",
|
|
281
|
+
install(chart) {
|
|
282
|
+
const stop = listenPointer(chart);
|
|
283
|
+
return {
|
|
284
|
+
layers: (hit, config) => ({
|
|
285
|
+
under: hoverUnderlay(hit, config.crosshair !== false),
|
|
286
|
+
over: hoverOverlay(hit, 4, require_cartesian.markerShape(config))
|
|
287
|
+
}),
|
|
288
|
+
...stop ? { destroy: stop } : {}
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
//#endregion
|
|
294
|
+
//#region src/a11y.ts
|
|
295
|
+
/**
|
|
296
|
+
* An HTML table of the chart data, for screen readers (visually hidden by
|
|
297
|
+
* default) or as a visible fallback. Every cell is text, escaped by the renderer.
|
|
298
|
+
*/
|
|
299
|
+
function tableContent(table, caption) {
|
|
300
|
+
const [corner = "", ...headers] = table.columns;
|
|
301
|
+
return require_vnode.h("table", { class: "tc-table" }, caption && require_vnode.h("caption", null, caption), require_vnode.h("thead", null, require_vnode.h("tr", null, require_vnode.h("th", { scope: "col" }, corner), headers.map((name, i) => require_vnode.h("th", {
|
|
302
|
+
key: i,
|
|
303
|
+
scope: "col"
|
|
304
|
+
}, name)))), require_vnode.h("tbody", null, table.rows.map(([head = "", ...cells], i) => require_vnode.h("tr", { key: i }, require_vnode.h("th", { scope: "row" }, head), cells.map((cell, j) => require_vnode.h("td", { key: j }, cell))))));
|
|
305
|
+
}
|
|
306
|
+
/** Short sentence describing a hit, announced during keyboard navigation. */
|
|
307
|
+
function describeHit(hit) {
|
|
308
|
+
const values = (hit.seriesIndex === void 0 ? hit.items : hit.items.filter((item) => item.seriesIndex === hit.seriesIndex)).map((item) => `${item.name} ${item.text}`).join(", ");
|
|
309
|
+
return hit.title ? `${hit.title}: ${values}` : values;
|
|
310
|
+
}
|
|
311
|
+
//#endregion
|
|
312
|
+
//#region src/plugins/keyboard.ts
|
|
313
|
+
/**
|
|
314
|
+
* Keyboard navigation: the SVG becomes focusable; arrow keys walk
|
|
315
|
+
* categories, Up/Down walk series, Home/End jump, Escape (or leaving)
|
|
316
|
+
* clears. Every step is announced through a polite live region.
|
|
317
|
+
*/
|
|
318
|
+
/** The config's `keyboard` option, else the chart type's default, else on. */
|
|
319
|
+
const enabled = (config) => config.keyboard ?? config.type.keyboard ?? true;
|
|
320
|
+
function keyboard() {
|
|
321
|
+
return {
|
|
322
|
+
name: "keyboard",
|
|
323
|
+
install(chart) {
|
|
324
|
+
const host = chart.element;
|
|
325
|
+
let live;
|
|
326
|
+
/**
|
|
327
|
+
* The live region, added when the chart takes focus: screen readers only
|
|
328
|
+
* announce changes of a region that was already there, so one created
|
|
329
|
+
* with its first message would stay silent for that message.
|
|
330
|
+
*/
|
|
331
|
+
const region = () => {
|
|
332
|
+
if (!live) {
|
|
333
|
+
live = host.ownerDocument.createElement("div");
|
|
334
|
+
live.className = "tc-sr-only";
|
|
335
|
+
live.setAttribute("aria-live", "polite");
|
|
336
|
+
live.setAttribute("aria-atomic", "true");
|
|
337
|
+
host.appendChild(live);
|
|
338
|
+
}
|
|
339
|
+
return live;
|
|
340
|
+
};
|
|
341
|
+
const announce = (text) => {
|
|
342
|
+
region().textContent = text;
|
|
343
|
+
};
|
|
344
|
+
const go = (index, seriesIndex) => {
|
|
345
|
+
const hit = chart.highlightIndex(index, seriesIndex);
|
|
346
|
+
if (hit) announce(describeHit(hit));
|
|
347
|
+
};
|
|
348
|
+
/** Returns whether the key was handled. */
|
|
349
|
+
const handle = (key) => {
|
|
350
|
+
const interaction = chart.interaction;
|
|
351
|
+
if (!interaction || interaction.count === 0) return false;
|
|
352
|
+
const current = chart.highlightSource === "index" ? chart.active : null;
|
|
353
|
+
const last = interaction.count - 1;
|
|
354
|
+
const index = current?.index;
|
|
355
|
+
const focused = current?.seriesIndex;
|
|
356
|
+
const series = current?.items.map((item) => item.seriesIndex) ?? [];
|
|
357
|
+
const at = focused === void 0 ? -1 : series.indexOf(focused);
|
|
358
|
+
switch (key) {
|
|
359
|
+
case "ArrowRight":
|
|
360
|
+
go(index === void 0 ? 0 : Math.min(last, index + 1), focused);
|
|
361
|
+
return true;
|
|
362
|
+
case "ArrowLeft":
|
|
363
|
+
go(index === void 0 ? last : Math.max(0, index - 1), focused);
|
|
364
|
+
return true;
|
|
365
|
+
case "Home":
|
|
366
|
+
go(0, focused);
|
|
367
|
+
return true;
|
|
368
|
+
case "End":
|
|
369
|
+
go(last, focused);
|
|
370
|
+
return true;
|
|
371
|
+
case "ArrowDown":
|
|
372
|
+
case "ArrowUp": {
|
|
373
|
+
if (index === void 0 || series.length === 0) {
|
|
374
|
+
go(0);
|
|
375
|
+
return true;
|
|
376
|
+
}
|
|
377
|
+
const step = key === "ArrowDown" ? 1 : -1;
|
|
378
|
+
const next = at === -1 ? step > 0 ? 0 : series.length - 1 : at + step;
|
|
379
|
+
go(index, next < 0 || next >= series.length ? void 0 : series[next]);
|
|
380
|
+
return true;
|
|
381
|
+
}
|
|
382
|
+
case "Escape":
|
|
383
|
+
if (!current) return false;
|
|
384
|
+
chart.clearHighlight();
|
|
385
|
+
return true;
|
|
386
|
+
default: return false;
|
|
387
|
+
}
|
|
388
|
+
};
|
|
389
|
+
const isChart = (target) => target?.matches?.("svg.tc-chart") === true;
|
|
390
|
+
const onKey = (event) => {
|
|
391
|
+
const { key } = event;
|
|
392
|
+
if (!enabled(chart.config) || !isChart(event.target)) return;
|
|
393
|
+
if (handle(key)) event.preventDefault();
|
|
394
|
+
};
|
|
395
|
+
const onBlur = (event) => {
|
|
396
|
+
if (isChart(event.target) && chart.highlightSource === "index") chart.clearHighlight();
|
|
397
|
+
};
|
|
398
|
+
const onFocus = (event) => {
|
|
399
|
+
if (enabled(chart.config) && isChart(event.target)) region();
|
|
400
|
+
};
|
|
401
|
+
host.addEventListener("keydown", onKey);
|
|
402
|
+
host.addEventListener("focusin", onFocus);
|
|
403
|
+
host.addEventListener("focusout", onBlur);
|
|
404
|
+
return {
|
|
405
|
+
svgAttrs: (config) => enabled(config) ? { tabindex: 0 } : void 0,
|
|
406
|
+
destroy() {
|
|
407
|
+
host.removeEventListener("keydown", onKey);
|
|
408
|
+
host.removeEventListener("focusin", onFocus);
|
|
409
|
+
host.removeEventListener("focusout", onBlur);
|
|
410
|
+
live?.remove();
|
|
411
|
+
}
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
//#endregion
|
|
417
|
+
//#region src/plugins/legend.ts
|
|
418
|
+
/**
|
|
419
|
+
* An HTML legend (`.tc-legend`) with toggle buttons, above or below the SVG.
|
|
420
|
+
* Shown for two or more entries unless the `legend` option says otherwise.
|
|
421
|
+
*/
|
|
422
|
+
function legend() {
|
|
423
|
+
return {
|
|
424
|
+
name: "legend",
|
|
425
|
+
install(chart) {
|
|
426
|
+
const host = chart.element;
|
|
427
|
+
let el = host.querySelector(":scope > .tc-legend") ?? void 0;
|
|
428
|
+
let adopt = el?.firstElementChild ?? null;
|
|
429
|
+
let bound = false;
|
|
430
|
+
const onClick = (event) => {
|
|
431
|
+
const key = (event.target.closest?.(".tc-legend-item"))?.getAttribute("data-key");
|
|
432
|
+
if (key != null) chart.toggleSeries(key);
|
|
433
|
+
};
|
|
434
|
+
const remove = () => {
|
|
435
|
+
if (!el) return;
|
|
436
|
+
require_dom.render(el, null);
|
|
437
|
+
el.removeEventListener("click", onClick);
|
|
438
|
+
bound = false;
|
|
439
|
+
el.remove();
|
|
440
|
+
el = void 0;
|
|
441
|
+
};
|
|
442
|
+
/** Keep the legend right before or after the SVG, whatever else lives in the container. */
|
|
443
|
+
const place = () => {
|
|
444
|
+
if (!el) return;
|
|
445
|
+
const svg = host.querySelector(":scope > svg.tc-chart");
|
|
446
|
+
if (el.dataset.position === "bottom") {
|
|
447
|
+
if (!svg) {
|
|
448
|
+
if (!el.isConnected) host.appendChild(el);
|
|
449
|
+
} else if (svg.nextElementSibling !== el) svg.after(el);
|
|
450
|
+
} else if (!el.isConnected || el.nextElementSibling !== svg) host.insertBefore(el, svg ?? host.firstChild);
|
|
451
|
+
};
|
|
452
|
+
return {
|
|
453
|
+
beforeRender({ legend, hidden }) {
|
|
454
|
+
if (!legend.show || typeof document === "undefined") {
|
|
455
|
+
remove();
|
|
456
|
+
return;
|
|
457
|
+
}
|
|
458
|
+
if (!el) {
|
|
459
|
+
el = host.ownerDocument.createElement("div");
|
|
460
|
+
el.className = "tc-legend";
|
|
461
|
+
}
|
|
462
|
+
if (!bound) {
|
|
463
|
+
el.addEventListener("click", onClick);
|
|
464
|
+
bound = true;
|
|
465
|
+
}
|
|
466
|
+
el.dataset.position = legend.position;
|
|
467
|
+
require_dom.render(el, require_chart.legendContent(legend.items, hidden), adopt);
|
|
468
|
+
adopt = null;
|
|
469
|
+
place();
|
|
470
|
+
},
|
|
471
|
+
reservedHeight() {
|
|
472
|
+
if (!el?.isConnected) return 0;
|
|
473
|
+
const { marginTop, marginBottom } = getComputedStyle(el);
|
|
474
|
+
return el.offsetHeight + (Number.parseFloat(marginTop) || 0) + (Number.parseFloat(marginBottom) || 0);
|
|
475
|
+
},
|
|
476
|
+
afterRender: place,
|
|
477
|
+
destroy: remove
|
|
478
|
+
};
|
|
479
|
+
}
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
//#endregion
|
|
483
|
+
//#region src/plugins/sync.ts
|
|
484
|
+
/** Charts by `sync` group, held weakly: a chart taken out without destroy() is let go. */
|
|
485
|
+
const groups = /* @__PURE__ */ new Map();
|
|
486
|
+
/** The index of each category label, per render of a chart. */
|
|
487
|
+
const indexes = /* @__PURE__ */ new WeakMap();
|
|
488
|
+
/** Set while a highlight is passed on, so the charts it reaches do not pass it on again. */
|
|
489
|
+
let passing = false;
|
|
490
|
+
/** The index of the category with `label` in a chart's current render, if it has one. */
|
|
491
|
+
function indexOf(interaction, label) {
|
|
492
|
+
let index = indexes.get(interaction);
|
|
493
|
+
if (!index) {
|
|
494
|
+
index = /* @__PURE__ */ new Map();
|
|
495
|
+
for (let i = 0; i < interaction.count; i++) {
|
|
496
|
+
const hit = interaction.hitIndex(i);
|
|
497
|
+
if (hit && !index.has(hit.label)) index.set(hit.label, i);
|
|
498
|
+
}
|
|
499
|
+
indexes.set(interaction, index);
|
|
500
|
+
}
|
|
501
|
+
return index.get(label);
|
|
502
|
+
}
|
|
503
|
+
/**
|
|
504
|
+
* Shared hover across charts: charts with the same `sync` group highlight
|
|
505
|
+
* the category under the pointer in any of them (with its crosshair and
|
|
506
|
+
* tooltip), matched by label, and clear together when it leaves. Keyboard
|
|
507
|
+
* highlights stay in their own chart.
|
|
508
|
+
*/
|
|
509
|
+
function sync() {
|
|
510
|
+
return {
|
|
511
|
+
name: "sync",
|
|
512
|
+
install(chart) {
|
|
513
|
+
const self = new WeakRef(chart);
|
|
514
|
+
let group;
|
|
515
|
+
/** The name of the group joined: the config may have moved on before the next render. */
|
|
516
|
+
let joined;
|
|
517
|
+
/** Leave the group, and take it off the list when it is empty. */
|
|
518
|
+
const leave = () => {
|
|
519
|
+
group?.delete(self);
|
|
520
|
+
if (joined && group?.size === 0 && groups.get(joined) === group) groups.delete(joined);
|
|
521
|
+
};
|
|
522
|
+
/** Join the group of the current config, leaving the one before. */
|
|
523
|
+
const join = () => {
|
|
524
|
+
const name = chart.config.sync;
|
|
525
|
+
const next = name ? groups.get(name) ?? /* @__PURE__ */ new Set() : void 0;
|
|
526
|
+
if (next === group) return;
|
|
527
|
+
leave();
|
|
528
|
+
if (name && next) {
|
|
529
|
+
next.add(self);
|
|
530
|
+
groups.set(name, next);
|
|
531
|
+
}
|
|
532
|
+
group = next;
|
|
533
|
+
joined = name;
|
|
534
|
+
};
|
|
535
|
+
join();
|
|
536
|
+
const off = chart.on("hover", ({ hit }) => {
|
|
537
|
+
if (passing || !group || hit && chart.highlightSource !== "pointer") return;
|
|
538
|
+
passing = true;
|
|
539
|
+
try {
|
|
540
|
+
for (const ref of group) {
|
|
541
|
+
const other = ref.deref();
|
|
542
|
+
if (!other) group.delete(ref);
|
|
543
|
+
if (!other || other === chart) continue;
|
|
544
|
+
const index = hit && other.interaction && indexOf(other.interaction, hit.label);
|
|
545
|
+
if (index === void 0 || index === null) other.clearHighlight();
|
|
546
|
+
else other.highlightIndex(index);
|
|
547
|
+
}
|
|
548
|
+
} finally {
|
|
549
|
+
passing = false;
|
|
550
|
+
}
|
|
551
|
+
});
|
|
552
|
+
return {
|
|
553
|
+
afterRender: join,
|
|
554
|
+
destroy() {
|
|
555
|
+
off();
|
|
556
|
+
leave();
|
|
557
|
+
}
|
|
558
|
+
};
|
|
559
|
+
}
|
|
560
|
+
};
|
|
561
|
+
}
|
|
562
|
+
//#endregion
|
|
563
|
+
//#region src/idle.ts
|
|
564
|
+
/**
|
|
565
|
+
* Work that can wait until the browser is idle, such as hidden data tables:
|
|
566
|
+
* it runs in an idle callback (within a second at the latest), or with
|
|
567
|
+
* `flush()`. A module of its own, so charts without such work do not ship it.
|
|
568
|
+
*/
|
|
569
|
+
const idle = /* @__PURE__ */ new Map();
|
|
570
|
+
let pending = false;
|
|
571
|
+
function drain() {
|
|
572
|
+
pending = false;
|
|
573
|
+
let count = 0;
|
|
574
|
+
while (idle.size > 0) {
|
|
575
|
+
const tasks = Array.from(idle.values());
|
|
576
|
+
idle.clear();
|
|
577
|
+
for (const task of tasks) {
|
|
578
|
+
require_chart.run(task);
|
|
579
|
+
count++;
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
return count;
|
|
583
|
+
}
|
|
584
|
+
/** Run `task` once the browser is idle, replacing any idle task already queued for `key`. */
|
|
585
|
+
function scheduleIdle(key, task) {
|
|
586
|
+
require_chart.flushHooks.idle = drain;
|
|
587
|
+
idle.set(key, task);
|
|
588
|
+
if (pending) return;
|
|
589
|
+
pending = true;
|
|
590
|
+
if (typeof requestIdleCallback === "function") requestIdleCallback(drain, { timeout: 1e3 });
|
|
591
|
+
else setTimeout(drain, 100);
|
|
592
|
+
}
|
|
593
|
+
/** Drop the idle task queued for `key`, if any. */
|
|
594
|
+
function cancelIdle(key) {
|
|
595
|
+
idle.delete(key);
|
|
596
|
+
}
|
|
597
|
+
//#endregion
|
|
598
|
+
//#region src/plugins/table.ts
|
|
599
|
+
/**
|
|
600
|
+
* The chart data as an HTML table next to the SVG: visually hidden for
|
|
601
|
+
* screen readers by default, visible with `table: 'visible'`.
|
|
602
|
+
*/
|
|
603
|
+
const DEFAULT_MAX_ROWS = 1e3;
|
|
604
|
+
function dataTable() {
|
|
605
|
+
return {
|
|
606
|
+
name: "table",
|
|
607
|
+
install(chart) {
|
|
608
|
+
const host = chart.element;
|
|
609
|
+
let el = host.querySelector(":scope > .tc-table-wrap") ?? void 0;
|
|
610
|
+
let adopt = el?.firstElementChild ?? null;
|
|
611
|
+
/** The table option of the last table, to tell its changes from new data. */
|
|
612
|
+
let shown;
|
|
613
|
+
const key = {};
|
|
614
|
+
const remove = () => {
|
|
615
|
+
cancelIdle(key);
|
|
616
|
+
if (!el) return;
|
|
617
|
+
require_dom.render(el, null);
|
|
618
|
+
el.remove();
|
|
619
|
+
el = void 0;
|
|
620
|
+
};
|
|
621
|
+
const update = (config, size, hidden) => {
|
|
622
|
+
const option = config.table ?? true;
|
|
623
|
+
const maxRows = typeof option === "object" && option.maxRows ? option.maxRows : DEFAULT_MAX_ROWS;
|
|
624
|
+
const table = option !== false && typeof document !== "undefined" ? config.type.table?.(config, require_chart.renderContext(config, size, chart.id, () => {}, hidden, chart.fontSize), maxRows) : void 0;
|
|
625
|
+
if (!table) {
|
|
626
|
+
remove();
|
|
627
|
+
return;
|
|
628
|
+
}
|
|
629
|
+
const visible = option === "visible" || typeof option === "object" && option.visible === true;
|
|
630
|
+
let caption = config.title;
|
|
631
|
+
const total = table.total ?? table.rows.length;
|
|
632
|
+
const rows = table.rows.length > maxRows ? {
|
|
633
|
+
columns: table.columns,
|
|
634
|
+
rows: table.rows.slice(0, maxRows)
|
|
635
|
+
} : table;
|
|
636
|
+
if (total > rows.rows.length) {
|
|
637
|
+
const n = require_format.getNumberFormat(config.locale);
|
|
638
|
+
const note = `${n.format(rows.rows.length)} of ${n.format(total)} rows`;
|
|
639
|
+
caption = caption ? `${caption} (${note})` : note;
|
|
640
|
+
}
|
|
641
|
+
if (!el) el = host.ownerDocument.createElement("div");
|
|
642
|
+
el.className = visible ? "tc-table-wrap" : "tc-table-wrap tc-sr-only";
|
|
643
|
+
require_dom.render(el, tableContent(rows, caption), adopt);
|
|
644
|
+
adopt = null;
|
|
645
|
+
const svg = host.querySelector(":scope > svg.tc-chart");
|
|
646
|
+
const after = host.querySelector(":scope > .tc-legend[data-position=\"bottom\"]") ?? svg;
|
|
647
|
+
if (after && after.nextElementSibling !== el) after.after(el);
|
|
648
|
+
else if (!el.isConnected) host.appendChild(el);
|
|
649
|
+
};
|
|
650
|
+
return {
|
|
651
|
+
afterRender({ config, size, hidden, changed }) {
|
|
652
|
+
if (!changed && el?.isConnected) return;
|
|
653
|
+
const option = config.table ?? true;
|
|
654
|
+
const same = shown === option;
|
|
655
|
+
shown = option;
|
|
656
|
+
if (same && el?.isConnected && el.classList.contains("tc-sr-only")) scheduleIdle(key, () => update(config, size, hidden));
|
|
657
|
+
else {
|
|
658
|
+
cancelIdle(key);
|
|
659
|
+
update(config, size, hidden);
|
|
660
|
+
}
|
|
661
|
+
},
|
|
662
|
+
destroy: remove
|
|
663
|
+
};
|
|
664
|
+
}
|
|
665
|
+
};
|
|
666
|
+
}
|
|
667
|
+
//#endregion
|
|
668
|
+
//#region src/tooltip.ts
|
|
669
|
+
/**
|
|
670
|
+
* Where a tooltip for `hit` belongs, in chart pixels: the pointer when it
|
|
671
|
+
* drives the highlight, otherwise the focused value (keyboard).
|
|
672
|
+
*/
|
|
673
|
+
function hitAnchor(hit, pointer) {
|
|
674
|
+
if (pointer) return pointer;
|
|
675
|
+
const item = hit.items.find((i) => i.seriesIndex === hit.seriesIndex) ?? hit.items[0];
|
|
676
|
+
if (hit.guide && item?.y != null) return {
|
|
677
|
+
x: item.x,
|
|
678
|
+
y: item.y
|
|
679
|
+
};
|
|
680
|
+
if (hit.axis === "y") return {
|
|
681
|
+
x: item?.x ?? hit.x,
|
|
682
|
+
y: hit.y ?? hit.area.y
|
|
683
|
+
};
|
|
684
|
+
return {
|
|
685
|
+
x: hit.x,
|
|
686
|
+
y: item?.y ?? hit.area.y + hit.area.height / 2
|
|
687
|
+
};
|
|
688
|
+
}
|
|
689
|
+
/** Default tooltip content: the category title and one row per series. */
|
|
690
|
+
function tooltipContent(hit, options = {}) {
|
|
691
|
+
const body = options.format ? options.format(hit) : [
|
|
692
|
+
hit.title && require_vnode.h("div", { class: "tc-tooltip-title" }, hit.title),
|
|
693
|
+
hit.items.map((item) => require_vnode.h("div", {
|
|
694
|
+
key: item.seriesIndex,
|
|
695
|
+
class: [
|
|
696
|
+
"tc-tooltip-item",
|
|
697
|
+
"tc-series",
|
|
698
|
+
`tc-series-${item.seriesIndex + 1}`,
|
|
699
|
+
hit.seriesIndex === item.seriesIndex && "tc-tooltip-item-active"
|
|
700
|
+
],
|
|
701
|
+
style: { "--tc-series-color": item.color }
|
|
702
|
+
}, require_vnode.h("span", { class: "tc-tooltip-swatch" }), require_vnode.h("span", { class: "tc-tooltip-name" }, item.name), require_vnode.h("span", { class: "tc-tooltip-value" }, item.text))),
|
|
703
|
+
options.footer && require_vnode.h("div", { class: "tc-tooltip-footer" }, options.footer(hit))
|
|
704
|
+
];
|
|
705
|
+
return require_vnode.h("div", { class: "tc-tooltip-content" }, body);
|
|
706
|
+
}
|
|
707
|
+
/**
|
|
708
|
+
* Place a `width × height` tooltip next to an anchor within `bounds` (from
|
|
709
|
+
* `bounds.x`, `bounds.y`, 0 by default): right of the anchor, or left when it
|
|
710
|
+
* would overflow, vertically centered on the pointer and clamped.
|
|
711
|
+
*/
|
|
712
|
+
function placeTooltip(anchor, size, bounds, offset = 12) {
|
|
713
|
+
const { x: left = 0, y: top = 0 } = bounds;
|
|
714
|
+
const fitsRight = anchor.x + offset + size.width <= left + bounds.width;
|
|
715
|
+
const fitsLeft = anchor.x - offset - size.width >= left;
|
|
716
|
+
const side = fitsRight || !fitsLeft ? "right" : "left";
|
|
717
|
+
const rawX = side === "right" ? anchor.x + offset : anchor.x - offset - size.width;
|
|
718
|
+
const x = Math.max(left, Math.min(rawX, left + bounds.width - size.width));
|
|
719
|
+
const y = Math.max(top, Math.min(anchor.y - size.height / 2, top + bounds.height - size.height));
|
|
720
|
+
return {
|
|
721
|
+
x: Math.round(x),
|
|
722
|
+
y: Math.round(y),
|
|
723
|
+
side
|
|
724
|
+
};
|
|
725
|
+
}
|
|
726
|
+
//#endregion
|
|
727
|
+
//#region src/plugins/tooltip.ts
|
|
728
|
+
/**
|
|
729
|
+
* Where a tooltip in `el` can show without being cut off: the box of the
|
|
730
|
+
* nearest element that clips its overflow (`el` itself, an ancestor, across
|
|
731
|
+
* shadow roots), within the viewport.
|
|
732
|
+
*/
|
|
733
|
+
function room(el) {
|
|
734
|
+
let left = 0;
|
|
735
|
+
let top = 0;
|
|
736
|
+
let right = innerWidth;
|
|
737
|
+
let bottom = innerHeight;
|
|
738
|
+
for (let node = el; node;) {
|
|
739
|
+
const style = getComputedStyle(node);
|
|
740
|
+
if (style.overflowX !== "visible" || style.overflowY !== "visible") {
|
|
741
|
+
const box = node.getBoundingClientRect();
|
|
742
|
+
left = Math.max(left, box.left);
|
|
743
|
+
top = Math.max(top, box.top);
|
|
744
|
+
right = Math.min(right, box.right);
|
|
745
|
+
bottom = Math.min(bottom, box.bottom);
|
|
746
|
+
break;
|
|
747
|
+
}
|
|
748
|
+
node = node.parentElement ?? (node.getRootNode().host || null);
|
|
749
|
+
}
|
|
750
|
+
return {
|
|
751
|
+
left,
|
|
752
|
+
top,
|
|
753
|
+
right,
|
|
754
|
+
bottom
|
|
755
|
+
};
|
|
756
|
+
}
|
|
757
|
+
/** Tooltips to place: each measures where it goes, and returns what moves it there. */
|
|
758
|
+
const waiting = [];
|
|
759
|
+
/**
|
|
760
|
+
* Place the waiting tooltips, in the frame that rendered their charts: all
|
|
761
|
+
* are measured before any is moved, so the page is laid out once for the
|
|
762
|
+
* frame. Measured and moved one by one, twelve charts sharing a hover laid
|
|
763
|
+
* the page out twelve times.
|
|
764
|
+
*/
|
|
765
|
+
function placeAll() {
|
|
766
|
+
for (const move of waiting.splice(0).map((measure) => measure())) move?.();
|
|
767
|
+
}
|
|
768
|
+
/**
|
|
769
|
+
* An HTML tooltip (`.tc-tooltip`) for the highlighted category, placed next
|
|
770
|
+
* to it inside the chart element. Configure it with the `tooltip` option.
|
|
771
|
+
*/
|
|
772
|
+
function tooltip() {
|
|
773
|
+
return {
|
|
774
|
+
name: "tooltip",
|
|
775
|
+
install(chart) {
|
|
776
|
+
const stop = listenPointer(chart);
|
|
777
|
+
const el = chart.element;
|
|
778
|
+
const addedClass = !el.classList.contains("tc-container");
|
|
779
|
+
el.classList.add("tc-container");
|
|
780
|
+
let tip;
|
|
781
|
+
/** Counts the renders, so a placement still waiting knows when it is out of date. */
|
|
782
|
+
let turns = 0;
|
|
783
|
+
return {
|
|
784
|
+
afterRender() {
|
|
785
|
+
const option = chart.config.tooltip;
|
|
786
|
+
const hit = chart.active;
|
|
787
|
+
const anchor = hit && hitAnchor(hit, chart.pointer);
|
|
788
|
+
if (option === false || typeof document === "undefined" || !hit || !anchor || !Number.isFinite(anchor.x) || !Number.isFinite(anchor.y)) {
|
|
789
|
+
turns++;
|
|
790
|
+
tip?.removeAttribute("data-visible");
|
|
791
|
+
return;
|
|
792
|
+
}
|
|
793
|
+
if (!tip) {
|
|
794
|
+
tip = el.ownerDocument.createElement("div");
|
|
795
|
+
tip.className = "tc-tooltip";
|
|
796
|
+
tip.setAttribute("aria-hidden", "true");
|
|
797
|
+
el.appendChild(tip);
|
|
798
|
+
}
|
|
799
|
+
require_dom.render(tip, tooltipContent(hit, typeof option === "object" ? option : void 0));
|
|
800
|
+
const shown = tip;
|
|
801
|
+
const turn = ++turns;
|
|
802
|
+
waiting.push(() => {
|
|
803
|
+
const svg = el.querySelector("svg.tc-chart");
|
|
804
|
+
if (!svg || turn !== turns) return void 0;
|
|
805
|
+
const { width, height } = chart.size;
|
|
806
|
+
const box = el.getBoundingClientRect();
|
|
807
|
+
const rect = svg.getBoundingClientRect();
|
|
808
|
+
const k = box.width > 0 && el.offsetWidth > 0 ? box.width / el.offsetWidth : 1;
|
|
809
|
+
const sx = rect.width > 0 ? rect.width / width / k : 1;
|
|
810
|
+
const sy = rect.height > 0 ? rect.height / height / k : 1;
|
|
811
|
+
const origin = {
|
|
812
|
+
x: (rect.left - box.left) / k - el.clientLeft,
|
|
813
|
+
y: (rect.top - box.top) / k - el.clientTop
|
|
814
|
+
};
|
|
815
|
+
const ax = hit.axis === "y" || hit.guide ? anchor.x : hit.x;
|
|
816
|
+
const ay = hit.axis === "y" ? hit.y ?? anchor.y : anchor.y;
|
|
817
|
+
const clip = room(el);
|
|
818
|
+
const place = placeTooltip({
|
|
819
|
+
x: origin.x + ax * sx,
|
|
820
|
+
y: origin.y + ay * sy
|
|
821
|
+
}, {
|
|
822
|
+
width: shown.offsetWidth,
|
|
823
|
+
height: shown.offsetHeight
|
|
824
|
+
}, {
|
|
825
|
+
x: (clip.left - box.left) / k - el.clientLeft,
|
|
826
|
+
y: (clip.top - box.top) / k - el.clientTop,
|
|
827
|
+
width: (clip.right - clip.left) / k,
|
|
828
|
+
height: (clip.bottom - clip.top) / k
|
|
829
|
+
});
|
|
830
|
+
return () => {
|
|
831
|
+
shown.style.transform = `translate(${place.x}px, ${place.y}px)`;
|
|
832
|
+
shown.dataset.side = place.side;
|
|
833
|
+
if (!shown.hasAttribute("data-visible")) {
|
|
834
|
+
getComputedStyle(shown).transform;
|
|
835
|
+
shown.setAttribute("data-visible", "");
|
|
836
|
+
}
|
|
837
|
+
};
|
|
838
|
+
});
|
|
839
|
+
require_chart.schedule(waiting, placeAll);
|
|
840
|
+
},
|
|
841
|
+
destroy() {
|
|
842
|
+
turns++;
|
|
843
|
+
if (tip) {
|
|
844
|
+
require_dom.render(tip, null);
|
|
845
|
+
tip.remove();
|
|
846
|
+
}
|
|
847
|
+
if (addedClass) el.classList.remove("tc-container");
|
|
848
|
+
stop?.();
|
|
849
|
+
}
|
|
850
|
+
};
|
|
851
|
+
}
|
|
852
|
+
};
|
|
853
|
+
}
|
|
854
|
+
//#endregion
|
|
855
|
+
//#region src/plugins/index.ts
|
|
856
|
+
/** The built-in plugins installed by the default `Chart` from `@tabler/charts`. */
|
|
857
|
+
function defaultPlugins() {
|
|
858
|
+
return [
|
|
859
|
+
highlight(),
|
|
860
|
+
legend(),
|
|
861
|
+
tooltip(),
|
|
862
|
+
dataTable(),
|
|
863
|
+
keyboard(),
|
|
864
|
+
sync(),
|
|
865
|
+
download()
|
|
866
|
+
];
|
|
867
|
+
}
|
|
868
|
+
//#endregion
|
|
869
|
+
//#region src/core.ts
|
|
870
|
+
/** Version of the `@tabler/charts` package. */
|
|
871
|
+
const VERSION = "0.0.0";
|
|
872
|
+
//#endregion
|
|
873
|
+
Object.defineProperty(exports, "VERSION", {
|
|
874
|
+
enumerable: true,
|
|
875
|
+
get: function() {
|
|
876
|
+
return VERSION;
|
|
877
|
+
}
|
|
878
|
+
});
|
|
879
|
+
Object.defineProperty(exports, "dataTable", {
|
|
880
|
+
enumerable: true,
|
|
881
|
+
get: function() {
|
|
882
|
+
return dataTable;
|
|
883
|
+
}
|
|
884
|
+
});
|
|
885
|
+
Object.defineProperty(exports, "defaultPlugins", {
|
|
886
|
+
enumerable: true,
|
|
887
|
+
get: function() {
|
|
888
|
+
return defaultPlugins;
|
|
889
|
+
}
|
|
890
|
+
});
|
|
891
|
+
Object.defineProperty(exports, "describeHit", {
|
|
892
|
+
enumerable: true,
|
|
893
|
+
get: function() {
|
|
894
|
+
return describeHit;
|
|
895
|
+
}
|
|
896
|
+
});
|
|
897
|
+
Object.defineProperty(exports, "download", {
|
|
898
|
+
enumerable: true,
|
|
899
|
+
get: function() {
|
|
900
|
+
return download;
|
|
901
|
+
}
|
|
902
|
+
});
|
|
903
|
+
Object.defineProperty(exports, "highlight", {
|
|
904
|
+
enumerable: true,
|
|
905
|
+
get: function() {
|
|
906
|
+
return highlight;
|
|
907
|
+
}
|
|
908
|
+
});
|
|
909
|
+
Object.defineProperty(exports, "hitAnchor", {
|
|
910
|
+
enumerable: true,
|
|
911
|
+
get: function() {
|
|
912
|
+
return hitAnchor;
|
|
913
|
+
}
|
|
914
|
+
});
|
|
915
|
+
Object.defineProperty(exports, "hoverOverlay", {
|
|
916
|
+
enumerable: true,
|
|
917
|
+
get: function() {
|
|
918
|
+
return hoverOverlay;
|
|
919
|
+
}
|
|
920
|
+
});
|
|
921
|
+
Object.defineProperty(exports, "hoverUnderlay", {
|
|
922
|
+
enumerable: true,
|
|
923
|
+
get: function() {
|
|
924
|
+
return hoverUnderlay;
|
|
925
|
+
}
|
|
926
|
+
});
|
|
927
|
+
Object.defineProperty(exports, "keyboard", {
|
|
928
|
+
enumerable: true,
|
|
929
|
+
get: function() {
|
|
930
|
+
return keyboard;
|
|
931
|
+
}
|
|
932
|
+
});
|
|
933
|
+
Object.defineProperty(exports, "legend", {
|
|
934
|
+
enumerable: true,
|
|
935
|
+
get: function() {
|
|
936
|
+
return legend;
|
|
937
|
+
}
|
|
938
|
+
});
|
|
939
|
+
Object.defineProperty(exports, "placeTooltip", {
|
|
940
|
+
enumerable: true,
|
|
941
|
+
get: function() {
|
|
942
|
+
return placeTooltip;
|
|
943
|
+
}
|
|
944
|
+
});
|
|
945
|
+
Object.defineProperty(exports, "pointer", {
|
|
946
|
+
enumerable: true,
|
|
947
|
+
get: function() {
|
|
948
|
+
return pointer;
|
|
949
|
+
}
|
|
950
|
+
});
|
|
951
|
+
Object.defineProperty(exports, "sync", {
|
|
952
|
+
enumerable: true,
|
|
953
|
+
get: function() {
|
|
954
|
+
return sync;
|
|
955
|
+
}
|
|
956
|
+
});
|
|
957
|
+
Object.defineProperty(exports, "tableContent", {
|
|
958
|
+
enumerable: true,
|
|
959
|
+
get: function() {
|
|
960
|
+
return tableContent;
|
|
961
|
+
}
|
|
962
|
+
});
|
|
963
|
+
Object.defineProperty(exports, "tooltip", {
|
|
964
|
+
enumerable: true,
|
|
965
|
+
get: function() {
|
|
966
|
+
return tooltip;
|
|
967
|
+
}
|
|
968
|
+
});
|
|
969
|
+
Object.defineProperty(exports, "tooltipContent", {
|
|
970
|
+
enumerable: true,
|
|
971
|
+
get: function() {
|
|
972
|
+
return tooltipContent;
|
|
973
|
+
}
|
|
974
|
+
});
|
|
975
|
+
|
|
976
|
+
//# sourceMappingURL=core-C7fPm6t7.cjs.map
|