@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,213 @@
|
|
|
1
|
+
const require_layout = require("./layout-CtMBhNd9.cjs");
|
|
2
|
+
const require_vnode = require("./vnode-CkQ27Cxe.cjs");
|
|
3
|
+
const require_cartesian = require("./cartesian-BoDfgBCV.cjs");
|
|
4
|
+
const require_clean = require("./clean-Byl6kzf0.cjs");
|
|
5
|
+
//#region src/charts/annotations.ts
|
|
6
|
+
/** Pixel span of a category (or a date on a time axis), or `undefined` if it is not on the axis. */
|
|
7
|
+
function categorySpan(scales, label) {
|
|
8
|
+
if (scales.time) {
|
|
9
|
+
const p = scales.time(new Date(require_cartesian.toMs(label)));
|
|
10
|
+
return Number.isFinite(p) ? [p, p] : void 0;
|
|
11
|
+
}
|
|
12
|
+
const i = scales.keys.indexOf(require_cartesian.labelKey(label));
|
|
13
|
+
return i < 0 ? void 0 : [scales.band.at(i), scales.band.at(i) + scales.band.bandwidth];
|
|
14
|
+
}
|
|
15
|
+
/** A value or a [from, to] pair, cleaned by `f`; `null` when anything is off. */
|
|
16
|
+
const span = (v, f) => {
|
|
17
|
+
if (!Array.isArray(v)) return f(v);
|
|
18
|
+
const pair = v.map(f);
|
|
19
|
+
return pair.length === 2 && !pair.includes(null) ? pair : null;
|
|
20
|
+
};
|
|
21
|
+
/** Annotations from outside: lines or bands at finite values or labels, with text labels. */
|
|
22
|
+
const cleanAnnotations = (v) => v === void 0 ? v : require_clean.records(v, (a) => ({
|
|
23
|
+
...a,
|
|
24
|
+
y: a.y === void 0 ? a.y : span(a.y, require_clean.finite),
|
|
25
|
+
x: a.x === void 0 ? a.x : span(a.x, require_clean.label),
|
|
26
|
+
label: a.label == null ? void 0 : require_clean.text(a.label),
|
|
27
|
+
color: typeof a.color === "string" ? a.color : void 0
|
|
28
|
+
})).filter((a) => a.y !== null && a.x !== null && (a.x ?? a.y) !== void 0);
|
|
29
|
+
const isPair = (v) => Array.isArray(v);
|
|
30
|
+
/** Values the value axis should include so every annotation shows. */
|
|
31
|
+
function annotationValues(annotations) {
|
|
32
|
+
const out = [];
|
|
33
|
+
for (const a of cleanAnnotations(annotations) ?? []) {
|
|
34
|
+
if (a.y === void 0) continue;
|
|
35
|
+
for (const v of isPair(a.y) ? a.y : [a.y]) if (Number.isFinite(v)) out.push(v);
|
|
36
|
+
}
|
|
37
|
+
return out;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Annotation layers: bands go below the series, lines and labels above
|
|
41
|
+
* them. Annotations outside the plot area are skipped.
|
|
42
|
+
*/
|
|
43
|
+
function annotationLayers(annotations, scales) {
|
|
44
|
+
annotations = cleanAnnotations(annotations);
|
|
45
|
+
if (!annotations?.length) return {
|
|
46
|
+
under: null,
|
|
47
|
+
over: null
|
|
48
|
+
};
|
|
49
|
+
const { area, horizontal, fontSize } = scales;
|
|
50
|
+
const bands = [];
|
|
51
|
+
const lines = [];
|
|
52
|
+
const x0 = area.x;
|
|
53
|
+
const x1 = area.x + area.width;
|
|
54
|
+
const y0 = area.y;
|
|
55
|
+
const y1 = area.y + area.height;
|
|
56
|
+
const inside = (p, lo, hi) => p >= lo - .5 && p <= hi + .5;
|
|
57
|
+
const pad = 4;
|
|
58
|
+
/**
|
|
59
|
+
* Where an annotation lands: the pixel span it covers within the plot, and
|
|
60
|
+
* whether it runs across x (a vertical line); `undefined` when it is off
|
|
61
|
+
* the plot or names nothing on the axes.
|
|
62
|
+
*/
|
|
63
|
+
const geometry = (a) => {
|
|
64
|
+
let span;
|
|
65
|
+
let vertical;
|
|
66
|
+
if (a.y !== void 0) {
|
|
67
|
+
const [from, to] = isPair(a.y) ? a.y : [a.y, a.y];
|
|
68
|
+
if (!Number.isFinite(from) || !Number.isFinite(to)) return void 0;
|
|
69
|
+
span = [scales.value(from), scales.value(to)];
|
|
70
|
+
vertical = horizontal;
|
|
71
|
+
} else if (a.x !== void 0) {
|
|
72
|
+
const [from, to] = isPair(a.x) ? a.x : [a.x, a.x];
|
|
73
|
+
const start = categorySpan(scales, from);
|
|
74
|
+
const stop = categorySpan(scales, to);
|
|
75
|
+
if (!start || !stop) return void 0;
|
|
76
|
+
span = isPair(a.x) ? [Math.min(start[0], stop[0]), Math.max(start[1], stop[1])] : [(start[0] + start[1]) / 2, (start[0] + start[1]) / 2];
|
|
77
|
+
vertical = !horizontal;
|
|
78
|
+
} else return;
|
|
79
|
+
const lo = Math.min(span[0], span[1]);
|
|
80
|
+
const hi = Math.max(span[0], span[1]);
|
|
81
|
+
const [min, max] = vertical ? [x0, x1] : [y0, y1];
|
|
82
|
+
if (!inside(lo, min, max) && !inside(hi, min, max) && !(lo < min && hi > max)) return void 0;
|
|
83
|
+
return {
|
|
84
|
+
a0: Math.max(lo, min),
|
|
85
|
+
a1: Math.min(hi, max),
|
|
86
|
+
vertical
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
const shapes = annotations.map(geometry);
|
|
90
|
+
/** Boxes labels keep clear of: the labels placed so far, and every line. */
|
|
91
|
+
const placed = [];
|
|
92
|
+
const obstacles = [];
|
|
93
|
+
shapes.forEach((g, i) => {
|
|
94
|
+
if (!g || g.a1 - g.a0 > .5) return;
|
|
95
|
+
const at = g.a0;
|
|
96
|
+
obstacles.push([i, g.vertical ? [
|
|
97
|
+
at - 1.5,
|
|
98
|
+
y0,
|
|
99
|
+
at + 1.5,
|
|
100
|
+
y1
|
|
101
|
+
] : [
|
|
102
|
+
x0,
|
|
103
|
+
at - 1.5,
|
|
104
|
+
x1,
|
|
105
|
+
at + 1.5
|
|
106
|
+
]]);
|
|
107
|
+
});
|
|
108
|
+
const apart = (box, [l, t, r, b]) => box[2] <= l || box[0] >= r || box[3] <= t || box[1] >= b;
|
|
109
|
+
const clearOfLabels = (box) => placed.every((p) => apart(box, p));
|
|
110
|
+
const clear = (box, own) => clearOfLabels(box) && obstacles.every(([i, l]) => i === own || apart(box, l));
|
|
111
|
+
annotations.forEach((a, index) => {
|
|
112
|
+
const key = a.id ?? index;
|
|
113
|
+
const attrs = (part) => ({
|
|
114
|
+
key: part ? `${key}-${part}` : key,
|
|
115
|
+
class: [
|
|
116
|
+
"tc-annotation",
|
|
117
|
+
a.y !== void 0 ? "tc-annotation-y" : "tc-annotation-x",
|
|
118
|
+
a.class
|
|
119
|
+
],
|
|
120
|
+
style: { "--tc-annotation-color": a.color }
|
|
121
|
+
});
|
|
122
|
+
const end = a.position !== "start";
|
|
123
|
+
const shape = shapes[index];
|
|
124
|
+
if (!shape) return;
|
|
125
|
+
const { a0, a1, vertical } = shape;
|
|
126
|
+
let label;
|
|
127
|
+
if (a.label) {
|
|
128
|
+
const w = require_layout.estimateTextWidth(a.label, fontSize * .92);
|
|
129
|
+
const line = a1 - a0 <= .5;
|
|
130
|
+
const spots = [];
|
|
131
|
+
if (vertical) {
|
|
132
|
+
const after = a0 + pad;
|
|
133
|
+
const before = line ? a0 - pad - w : Math.max(x0, a1 - pad - w);
|
|
134
|
+
const sides = after + w <= x1 ? [after, before] : [before, after];
|
|
135
|
+
const top = end ? y0 + fontSize : y1 - pad;
|
|
136
|
+
const step = (end ? 1 : -1) * fontSize * 1.2;
|
|
137
|
+
for (const x of sides) {
|
|
138
|
+
if (x < x0 || x + w > x1) continue;
|
|
139
|
+
for (let k = 0; k < 3; k++) spots.push([x, top + k * step]);
|
|
140
|
+
}
|
|
141
|
+
if (!spots.length) spots.push([Math.max(x0 + pad, sides[0]), top]);
|
|
142
|
+
} else {
|
|
143
|
+
const near = end ? x1 - pad - w : x0 + pad;
|
|
144
|
+
const far = end ? x0 + pad : x1 - pad - w;
|
|
145
|
+
for (const x of [near, far]) if (line) spots.push([x, a0 - pad], [x, a0 + fontSize]);
|
|
146
|
+
else spots.push([x, a0 + fontSize], [x, a1 - pad]);
|
|
147
|
+
}
|
|
148
|
+
const box = ([x, y]) => [
|
|
149
|
+
x,
|
|
150
|
+
y - fontSize,
|
|
151
|
+
x + w,
|
|
152
|
+
y + fontSize * .25
|
|
153
|
+
];
|
|
154
|
+
const spot = spots.find((s) => clear(box(s), index)) ?? spots.find((s) => clearOfLabels(box(s))) ?? spots[0];
|
|
155
|
+
placed.push(box(spot));
|
|
156
|
+
label = require_vnode.h("text", {
|
|
157
|
+
class: "tc-annotation-label",
|
|
158
|
+
x: require_layout.round(spot[0]),
|
|
159
|
+
y: require_layout.round(spot[1])
|
|
160
|
+
}, a.label);
|
|
161
|
+
}
|
|
162
|
+
if (a1 - a0 > .5) {
|
|
163
|
+
const d = vertical ? `M${require_layout.round(a0)},${require_layout.round(y0)}H${require_layout.round(a1)}V${require_layout.round(y1)}H${require_layout.round(a0)}Z` : `M${require_layout.round(x0)},${require_layout.round(a0)}H${require_layout.round(x1)}V${require_layout.round(a1)}H${require_layout.round(x0)}Z`;
|
|
164
|
+
bands.push(require_vnode.h("g", attrs(), require_vnode.h("path", {
|
|
165
|
+
class: "tc-annotation-band",
|
|
166
|
+
d
|
|
167
|
+
})));
|
|
168
|
+
if (label) lines.push(require_vnode.h("g", attrs("label"), label));
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
const at = require_layout.round(a0);
|
|
172
|
+
lines.push(require_vnode.h("g", attrs(), require_vnode.h("line", vertical ? {
|
|
173
|
+
class: "tc-annotation-line",
|
|
174
|
+
x1: at,
|
|
175
|
+
x2: at,
|
|
176
|
+
y1: require_layout.round(y0),
|
|
177
|
+
y2: require_layout.round(y1)
|
|
178
|
+
} : {
|
|
179
|
+
class: "tc-annotation-line",
|
|
180
|
+
x1: require_layout.round(x0),
|
|
181
|
+
x2: require_layout.round(x1),
|
|
182
|
+
y1: at,
|
|
183
|
+
y2: at
|
|
184
|
+
}), label));
|
|
185
|
+
});
|
|
186
|
+
return {
|
|
187
|
+
under: bands.length ? require_vnode.h("g", {
|
|
188
|
+
key: "annotations-under",
|
|
189
|
+
class: "tc-annotations",
|
|
190
|
+
"aria-hidden": "true"
|
|
191
|
+
}, bands) : null,
|
|
192
|
+
over: lines.length ? require_vnode.h("g", {
|
|
193
|
+
key: "annotations-over",
|
|
194
|
+
class: "tc-annotations",
|
|
195
|
+
"aria-hidden": "true"
|
|
196
|
+
}, lines) : null
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
//#endregion
|
|
200
|
+
Object.defineProperty(exports, "annotationLayers", {
|
|
201
|
+
enumerable: true,
|
|
202
|
+
get: function() {
|
|
203
|
+
return annotationLayers;
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
Object.defineProperty(exports, "annotationValues", {
|
|
207
|
+
enumerable: true,
|
|
208
|
+
get: function() {
|
|
209
|
+
return annotationValues;
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
//# sourceMappingURL=annotations-DpETO8dE.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"annotations-DpETO8dE.cjs","names":["toMs","labelKey","records","finite","label","text","estimateTextWidth","h","round"],"sources":["../src/charts/annotations.ts"],"sourcesContent":["import { estimateTextWidth, type Rect, round } from '../layout.ts'\nimport type { BandKey, BandScale } from '../scales/band.ts'\nimport { type ClassValue, h, type VNode } from '../vnode.ts'\nimport { labelKey, toMs } from './cartesian.ts'\nimport { finite, label, records, text } from './clean.ts'\n\n/** A category label, a number, or a date (on a time axis). */\ntype AnnotationLabel = string | number | Date\n\n/**\n * A reference line or band drawn with the series: a target on the value\n * axis (`y: 99.9`), a normal range (`y: [40, 60]`), an event on the category\n * axis (`x: 'Jun'`, or a date on a time axis) or a period (`x: [from, to]`).\n */\nexport interface Annotation {\n /** A line at a value, or a band between two values, on the value axis. */\n y?: number | readonly [number, number]\n /** A line at a category (or a date on a time axis), or a band between two, on the category axis. */\n x?: AnnotationLabel | readonly [AnnotationLabel, AnnotationLabel]\n /** Short text next to the line or inside the band. */\n label?: string\n /** Where the label sits along the line or band. Defaults to `'end'` (right, or top). */\n position?: 'start' | 'end'\n /**\n * Any CSS color; sets `--tc-annotation-color`.\n * Values that could inject CSS (`;`, quotes, `url()` …) are ignored, so colors from user data are safe.\n */\n color?: string\n /** Extra classes on the annotation group. */\n class?: ClassValue\n /** Stable identity for keyed updates. Defaults to the position in the list. */\n id?: string\n}\n\n/** How the layout maps data to pixels for annotations. */\nexport interface AnnotationScales {\n area: Rect\n /** Whether categories run along y (horizontal bars). */\n horizontal: boolean\n fontSize: number\n /** Pixel position of a value along the value axis. */\n value: (v: number) => number\n /** The category scale, and the keys of its categories in order. */\n band: BandScale\n keys: readonly BandKey[]\n /** Pixel position of a date, when the category axis is a time axis. */\n time?: ((date: Date) => number) | undefined\n}\n\n/** Pixel span of a category (or a date on a time axis), or `undefined` if it is not on the axis. */\nfunction categorySpan(\n scales: AnnotationScales,\n label: AnnotationLabel,\n): readonly [number, number] | undefined {\n if (scales.time) {\n const p = scales.time(new Date(toMs(label)))\n return Number.isFinite(p) ? [p, p] : undefined\n }\n const i = scales.keys.indexOf(labelKey(label))\n return i < 0 ? undefined : [scales.band.at(i), scales.band.at(i) + scales.band.bandwidth]\n}\n\n/** A value or a [from, to] pair, cleaned by `f`; `null` when anything is off. */\nconst span = <T>(v: unknown, f: (x: unknown) => T | null): T | readonly T[] | null => {\n if (!Array.isArray(v)) return f(v)\n const pair = v.map(f)\n return pair.length === 2 && !pair.includes(null) ? (pair as T[]) : null\n}\n\n/** Annotations from outside: lines or bands at finite values or labels, with text labels. */\nexport const cleanAnnotations = (v: unknown): Annotation[] | undefined =>\n v === undefined\n ? v\n : (records(v, (a) => ({\n ...a,\n y: a.y === undefined ? a.y : span(a.y, finite),\n x: a.x === undefined ? a.x : span(a.x, label),\n label: a.label == null ? undefined : text(a.label),\n color: typeof a.color === 'string' ? a.color : undefined,\n })).filter((a) => a.y !== null && a.x !== null && (a.x ?? a.y) !== undefined) as Annotation[])\n\nconst isPair = <T>(v: T | readonly [T, T]): v is readonly [T, T] => Array.isArray(v)\n\n/** Values the value axis should include so every annotation shows. */\nexport function annotationValues(annotations: readonly Annotation[] | undefined): number[] {\n const out: number[] = []\n for (const a of cleanAnnotations(annotations) ?? []) {\n if (a.y === undefined) continue\n for (const v of isPair(a.y) ? a.y : [a.y]) if (Number.isFinite(v)) out.push(v)\n }\n return out\n}\n\n/**\n * Annotation layers: bands go below the series, lines and labels above\n * them. Annotations outside the plot area are skipped.\n */\nexport function annotationLayers(\n annotations: readonly Annotation[] | undefined,\n scales: AnnotationScales,\n): { under: VNode | null; over: VNode | null } {\n // Annotations may come from outside (thresholds from an API).\n annotations = cleanAnnotations(annotations)\n if (!annotations?.length) return { under: null, over: null }\n const { area, horizontal, fontSize } = scales\n const bands: VNode[] = []\n const lines: VNode[] = []\n // Plot edges: \"across\" is the axis the annotation spans, \"along\" the one it marks.\n const x0 = area.x\n const x1 = area.x + area.width\n const y0 = area.y\n const y1 = area.y + area.height\n const inside = (p: number, lo: number, hi: number) => p >= lo - 0.5 && p <= hi + 0.5\n const pad = 4\n /**\n * Where an annotation lands: the pixel span it covers within the plot, and\n * whether it runs across x (a vertical line); `undefined` when it is off\n * the plot or names nothing on the axes.\n */\n const geometry = (a: Annotation): { a0: number; a1: number; vertical: boolean } | undefined => {\n let span: readonly [number, number]\n let vertical: boolean\n if (a.y !== undefined) {\n const [from, to] = isPair(a.y) ? a.y : [a.y, a.y]\n if (!Number.isFinite(from) || !Number.isFinite(to)) return undefined\n span = [scales.value(from), scales.value(to)]\n vertical = horizontal\n } else if (a.x !== undefined) {\n const [from, to] = isPair(a.x) ? a.x : [a.x, a.x]\n const start = categorySpan(scales, from)\n const stop = categorySpan(scales, to)\n if (!start || !stop) return undefined\n // A single category: its center; a range: from the start of one to the end of the other.\n span = isPair(a.x)\n ? [Math.min(start[0], stop[0]), Math.max(start[1], stop[1])]\n : [(start[0] + start[1]) / 2, (start[0] + start[1]) / 2]\n vertical = !horizontal\n } else {\n return undefined\n }\n const lo = Math.min(span[0], span[1])\n const hi = Math.max(span[0], span[1])\n const [min, max] = vertical ? [x0, x1] : [y0, y1]\n if (!inside(lo, min, max) && !inside(hi, min, max) && !(lo < min && hi > max)) return undefined\n return { a0: Math.max(lo, min), a1: Math.min(hi, max), vertical }\n }\n const shapes = annotations.map(geometry)\n\n type Box = [number, number, number, number]\n /** Boxes labels keep clear of: the labels placed so far, and every line. */\n const placed: Box[] = []\n const obstacles: [number, Box][] = []\n shapes.forEach((g, i) => {\n if (!g || g.a1 - g.a0 > 0.5) return\n const at = g.a0\n obstacles.push([i, g.vertical ? [at - 1.5, y0, at + 1.5, y1] : [x0, at - 1.5, x1, at + 1.5]])\n })\n const apart = (box: Box, [l, t, r, b]: Box) =>\n box[2] <= l || box[0] >= r || box[3] <= t || box[1] >= b\n const clearOfLabels = (box: Box) => placed.every((p) => apart(box, p))\n const clear = (box: Box, own: number) =>\n clearOfLabels(box) && obstacles.every(([i, l]) => i === own || apart(box, l))\n\n annotations.forEach((a, index) => {\n const key = a.id ?? index\n // Groups are named by axis; the line, band and label inside by what they are.\n const attrs = (part?: string) => ({\n key: part ? `${key}-${part}` : key,\n class: ['tc-annotation', a.y !== undefined ? 'tc-annotation-y' : 'tc-annotation-x', a.class],\n style: { '--tc-annotation-color': a.color },\n })\n const end = a.position !== 'start'\n\n const shape = shapes[index]\n if (!shape) return\n const { a0, a1, vertical } = shape\n\n // Label: candidate spots in order of preference, inside the plot area; the\n // first that covers neither an earlier label nor another line wins (or the first one).\n let label: VNode | false | undefined\n if (a.label) {\n const w = estimateTextWidth(a.label, fontSize * 0.92)\n const line = a1 - a0 <= 0.5\n // [left edge, baseline] of each spot.\n const spots: [number, number][] = []\n if (vertical) {\n // Beside a line or at the start of a band; on the other side if it would\n // run out, and then on the other side anyway, stepping along the line.\n const after = a0 + pad\n const before = line ? a0 - pad - w : Math.max(x0, a1 - pad - w)\n const sides = after + w <= x1 ? [after, before] : [before, after]\n const top = end ? y0 + fontSize : y1 - pad\n const step = (end ? 1 : -1) * fontSize * 1.2\n for (const x of sides) {\n if (x < x0 || x + w > x1) continue\n for (let k = 0; k < 3; k++) spots.push([x, top + k * step])\n }\n if (!spots.length) spots.push([Math.max(x0 + pad, sides[0] as number), top])\n } else {\n // At the preferred end above or below, then at the other end.\n const near = end ? x1 - pad - w : x0 + pad\n const far = end ? x0 + pad : x1 - pad - w\n for (const x of [near, far]) {\n if (line) spots.push([x, a0 - pad], [x, a0 + fontSize])\n else spots.push([x, a0 + fontSize], [x, a1 - pad])\n }\n }\n const box = ([x, y]: [number, number]): Box => [x, y - fontSize, x + w, y + fontSize * 0.25]\n // Nothing free: at least keep off the other labels; a line through text reads better than text on text.\n const spot =\n spots.find((s) => clear(box(s), index)) ??\n spots.find((s) => clearOfLabels(box(s))) ??\n (spots[0] as [number, number])\n placed.push(box(spot))\n label = h(\n 'text',\n { class: 'tc-annotation-label', x: round(spot[0]), y: round(spot[1]) },\n a.label,\n )\n }\n\n if (a1 - a0 > 0.5) {\n // A band below the series; its label goes with the lines, above them.\n const d = vertical\n ? `M${round(a0)},${round(y0)}H${round(a1)}V${round(y1)}H${round(a0)}Z`\n : `M${round(x0)},${round(a0)}H${round(x1)}V${round(a1)}H${round(x0)}Z`\n bands.push(h('g', attrs(), h('path', { class: 'tc-annotation-band', d })))\n if (label) lines.push(h('g', attrs('label'), label))\n return\n }\n // A line across the plot area.\n const at = round(a0)\n lines.push(\n h(\n 'g',\n attrs(),\n h(\n 'line',\n vertical\n ? { class: 'tc-annotation-line', x1: at, x2: at, y1: round(y0), y2: round(y1) }\n : { class: 'tc-annotation-line', x1: round(x0), x2: round(x1), y1: at, y2: at },\n ),\n label,\n ),\n )\n })\n\n return {\n under: bands.length\n ? h('g', { key: 'annotations-under', class: 'tc-annotations', 'aria-hidden': 'true' }, bands)\n : null,\n over: lines.length\n ? h('g', { key: 'annotations-over', class: 'tc-annotations', 'aria-hidden': 'true' }, lines)\n : null,\n }\n}\n"],"mappings":";;;;;;AAkDA,SAAS,aACP,QACA,OACuC;CACvC,IAAI,OAAO,MAAM;EACf,MAAM,IAAI,OAAO,KAAK,IAAI,KAAKA,kBAAA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ACE,KACA,MAAM,GACNA,cAAAA,EACE,QACA,WACI;GAAE,OAAO;GAAsB,IAAI;GAAI,IAAI;GAAI,IAAIC,eAAAA,MAAM,EAAE;GAAG,IAAIA,eAAAA,MAAM,EAAE;EAAE,IAC5E;GAAE,OAAO;GAAsB,IAAIA,eAAAA,MAAM,EAAE;GAAG,IAAIA,eAAAA,MAAM,EAAE;GAAG,IAAI;GAAI,IAAI;EAAG,CAClF,GACA,KACF,CACF;CACF,CAAC;CAED,OAAO;EACL,OAAO,MAAM,SACTD,cAAAA,EAAE,KAAK;GAAE,KAAK;GAAqB,OAAO;GAAkB,eAAe;EAAO,GAAG,KAAK,IAC1F;EACJ,MAAM,MAAM,SACRA,cAAAA,EAAE,KAAK;GAAE,KAAK;GAAoB,OAAO;GAAkB,eAAe;EAAO,GAAG,KAAK,IACzF;CACN;AACF"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { n as BandScale, t as BandKey } from "./band-DTcNDAFO.cjs";
|
|
2
|
+
import { a as ClassValue, l as VNode } from "./vnode-BUflsBsa.cjs";
|
|
3
|
+
//#region src/layout.d.ts
|
|
4
|
+
/** Axis-aligned rectangle in pixels. */
|
|
5
|
+
interface Rect {
|
|
6
|
+
x: number;
|
|
7
|
+
y: number;
|
|
8
|
+
width: number;
|
|
9
|
+
height: number;
|
|
10
|
+
}
|
|
11
|
+
/** Space around a box, in pixels. */
|
|
12
|
+
interface Insets {
|
|
13
|
+
top: number;
|
|
14
|
+
right: number;
|
|
15
|
+
bottom: number;
|
|
16
|
+
left: number;
|
|
17
|
+
}
|
|
18
|
+
/** Insets given as one number for all sides or per side. */
|
|
19
|
+
type InsetsInput = number | Partial<Insets>;
|
|
20
|
+
/** Normalize an {@link InsetsInput}; missing sides fall back to `fallback`. */
|
|
21
|
+
declare function insets(value: InsetsInput | undefined, fallback?: number): Insets;
|
|
22
|
+
/** Rectangle left inside `width × height` after `margins`; never negative. */
|
|
23
|
+
declare function innerRect(width: number, height: number, margins: Insets): Rect;
|
|
24
|
+
/**
|
|
25
|
+
* Estimate the rendered width of `text` without a DOM, for layout on the
|
|
26
|
+
* server and in workers. Tuned for common UI sans-serif fonts; deterministic,
|
|
27
|
+
* so SSR and client layouts agree.
|
|
28
|
+
*/
|
|
29
|
+
declare function estimateTextWidth(text: string, fontSize: number): number;
|
|
30
|
+
/** Line height used for single-line labels, relative to the font size. */
|
|
31
|
+
declare const LINE_HEIGHT = 1.25;
|
|
32
|
+
//#endregion
|
|
33
|
+
//#region src/charts/annotations.d.ts
|
|
34
|
+
/** A category label, a number, or a date (on a time axis). */
|
|
35
|
+
type AnnotationLabel = string | number | Date;
|
|
36
|
+
/**
|
|
37
|
+
* A reference line or band drawn with the series: a target on the value
|
|
38
|
+
* axis (`y: 99.9`), a normal range (`y: [40, 60]`), an event on the category
|
|
39
|
+
* axis (`x: 'Jun'`, or a date on a time axis) or a period (`x: [from, to]`).
|
|
40
|
+
*/
|
|
41
|
+
interface Annotation {
|
|
42
|
+
/** A line at a value, or a band between two values, on the value axis. */
|
|
43
|
+
y?: number | readonly [number, number];
|
|
44
|
+
/** A line at a category (or a date on a time axis), or a band between two, on the category axis. */
|
|
45
|
+
x?: AnnotationLabel | readonly [AnnotationLabel, AnnotationLabel];
|
|
46
|
+
/** Short text next to the line or inside the band. */
|
|
47
|
+
label?: string;
|
|
48
|
+
/** Where the label sits along the line or band. Defaults to `'end'` (right, or top). */
|
|
49
|
+
position?: "start" | "end";
|
|
50
|
+
/**
|
|
51
|
+
* Any CSS color; sets `--tc-annotation-color`.
|
|
52
|
+
* Values that could inject CSS (`;`, quotes, `url()` …) are ignored, so colors from user data are safe.
|
|
53
|
+
*/
|
|
54
|
+
color?: string;
|
|
55
|
+
/** Extra classes on the annotation group. */
|
|
56
|
+
class?: ClassValue;
|
|
57
|
+
/** Stable identity for keyed updates. Defaults to the position in the list. */
|
|
58
|
+
id?: string;
|
|
59
|
+
}
|
|
60
|
+
/** How the layout maps data to pixels for annotations. */
|
|
61
|
+
interface AnnotationScales {
|
|
62
|
+
area: Rect;
|
|
63
|
+
/** Whether categories run along y (horizontal bars). */
|
|
64
|
+
horizontal: boolean;
|
|
65
|
+
fontSize: number;
|
|
66
|
+
/** Pixel position of a value along the value axis. */
|
|
67
|
+
value: (v: number) => number;
|
|
68
|
+
/** The category scale, and the keys of its categories in order. */
|
|
69
|
+
band: BandScale;
|
|
70
|
+
keys: readonly BandKey[];
|
|
71
|
+
/** Pixel position of a date, when the category axis is a time axis. */
|
|
72
|
+
time?: ((date: Date) => number) | undefined;
|
|
73
|
+
}
|
|
74
|
+
/** Values the value axis should include so every annotation shows. */
|
|
75
|
+
declare function annotationValues(annotations: readonly Annotation[] | undefined): number[];
|
|
76
|
+
/**
|
|
77
|
+
* Annotation layers: bands go below the series, lines and labels above
|
|
78
|
+
* them. Annotations outside the plot area are skipped.
|
|
79
|
+
*/
|
|
80
|
+
declare function annotationLayers(annotations: readonly Annotation[] | undefined, scales: AnnotationScales): {
|
|
81
|
+
under: VNode | null;
|
|
82
|
+
over: VNode | null;
|
|
83
|
+
};
|
|
84
|
+
//#endregion
|
|
85
|
+
export { InsetsInput as a, estimateTextWidth as c, Insets as i, innerRect as l, annotationLayers as n, LINE_HEIGHT as o, annotationValues as r, Rect as s, Annotation as t, insets as u };
|
|
86
|
+
//# sourceMappingURL=annotations-lyt0I3HU.d.cts.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_features = require("./features-BclHgg2W.cjs");
|
|
3
|
+
const require_annotations = require("./annotations-DpETO8dE.cjs");
|
|
4
|
+
//#region src/annotations.ts
|
|
5
|
+
/** Standalone entry: `import '@tabler/charts/annotations'` enables `annotations` in cartesian charts. */
|
|
6
|
+
require_features.register({ annotations: {
|
|
7
|
+
layers: require_annotations.annotationLayers,
|
|
8
|
+
values: require_annotations.annotationValues
|
|
9
|
+
} });
|
|
10
|
+
//#endregion
|
|
11
|
+
exports.annotationLayers = require_annotations.annotationLayers;
|
|
12
|
+
exports.annotationValues = require_annotations.annotationValues;
|
|
13
|
+
|
|
14
|
+
//# sourceMappingURL=annotations.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"annotations.cjs","names":["register","annotationLayers","annotationValues"],"sources":["../src/annotations.ts"],"sourcesContent":["/** Standalone entry: `import '@tabler/charts/annotations'` enables `annotations` in cartesian charts. */\nimport { annotationLayers, annotationValues } from './charts/annotations.ts'\nimport { register } from './features.ts'\n\nregister({ annotations: { layers: annotationLayers, values: annotationValues } })\n\nexport type { Annotation } from './charts/annotations.ts'\nexport { annotationLayers, annotationValues }\n"],"mappings":";;;;;AAIAA,iBAAAA,SAAS,EAAE,aAAa;CAAE,QAAQC,oBAAAA;CAAkB,QAAQC,oBAAAA;AAAiB,EAAE,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { i as register } from "./features-wASyHGic.js";
|
|
2
|
+
import { n as annotationValues, t as annotationLayers } from "./annotations-BszTTjf9.js";
|
|
3
|
+
//#region src/annotations.ts
|
|
4
|
+
/** Standalone entry: `import '@tabler/charts/annotations'` enables `annotations` in cartesian charts. */
|
|
5
|
+
register({ annotations: {
|
|
6
|
+
layers: annotationLayers,
|
|
7
|
+
values: annotationValues
|
|
8
|
+
} });
|
|
9
|
+
//#endregion
|
|
10
|
+
export { annotationLayers, annotationValues };
|
|
11
|
+
|
|
12
|
+
//# sourceMappingURL=annotations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"annotations.js","names":[],"sources":["../src/annotations.ts"],"sourcesContent":["/** Standalone entry: `import '@tabler/charts/annotations'` enables `annotations` in cartesian charts. */\nimport { annotationLayers, annotationValues } from './charts/annotations.ts'\nimport { register } from './features.ts'\n\nregister({ annotations: { layers: annotationLayers, values: annotationValues } })\n\nexport type { Annotation } from './charts/annotations.ts'\nexport { annotationLayers, annotationValues }\n"],"mappings":";;;;AAIA,SAAS,EAAE,aAAa;CAAE,QAAQ;CAAkB,QAAQ;AAAiB,EAAE,CAAC"}
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
//#region src/shapes/arc.ts
|
|
2
|
+
/**
|
|
3
|
+
* Annular sector paths with padding and rounded corners, ported from
|
|
4
|
+
* d3-shape's `arc()` (ISC license, Mike Bostock) so geometry matches d3.
|
|
5
|
+
*
|
|
6
|
+
* Angles are in radians, clockwise from 12 o'clock; paths are centered on
|
|
7
|
+
* the origin (translate the group to place them).
|
|
8
|
+
*/
|
|
9
|
+
const EPSILON = 1e-12;
|
|
10
|
+
const PI = Math.PI;
|
|
11
|
+
const HALF_PI = PI / 2;
|
|
12
|
+
const TAU = 2 * PI;
|
|
13
|
+
/** Degrees to radians. */
|
|
14
|
+
const DEG = Math.PI / 180;
|
|
15
|
+
const asin = (x) => x >= 1 ? HALF_PI : x <= -1 ? -HALF_PI : Math.asin(x);
|
|
16
|
+
const acos = (x) => x > 1 ? 0 : x < -1 ? PI : Math.acos(x);
|
|
17
|
+
function intersect(x0, y0, x1, y1, x2, y2, x3, y3) {
|
|
18
|
+
const x10 = x1 - x0;
|
|
19
|
+
const y10 = y1 - y0;
|
|
20
|
+
const x32 = x3 - x2;
|
|
21
|
+
const y32 = y3 - y2;
|
|
22
|
+
let t = y32 * x10 - x32 * y10;
|
|
23
|
+
if (t * t < EPSILON) return void 0;
|
|
24
|
+
t = (x32 * (y0 - y2) - y32 * (x0 - x2)) / t;
|
|
25
|
+
return [x0 + t * x10, y0 + t * y10];
|
|
26
|
+
}
|
|
27
|
+
/** Center and tangent points of a rounded corner between a radial edge and an arc. */
|
|
28
|
+
function cornerTangents(x0, y0, x1, y1, r1, rc, cw) {
|
|
29
|
+
const x01 = x0 - x1;
|
|
30
|
+
const y01 = y0 - y1;
|
|
31
|
+
const lo = (cw ? rc : -rc) / Math.sqrt(x01 * x01 + y01 * y01);
|
|
32
|
+
const ox = lo * y01;
|
|
33
|
+
const oy = -lo * x01;
|
|
34
|
+
const x11 = x0 + ox;
|
|
35
|
+
const y11 = y0 + oy;
|
|
36
|
+
const x10 = x1 + ox;
|
|
37
|
+
const y10 = y1 + oy;
|
|
38
|
+
const x00 = (x11 + x10) / 2;
|
|
39
|
+
const y00 = (y11 + y10) / 2;
|
|
40
|
+
const dx = x10 - x11;
|
|
41
|
+
const dy = y10 - y11;
|
|
42
|
+
const d2 = dx * dx + dy * dy;
|
|
43
|
+
const r = r1 - rc;
|
|
44
|
+
const D = x11 * y10 - x10 * y11;
|
|
45
|
+
const d = (dy < 0 ? -1 : 1) * Math.sqrt(Math.max(0, r * r * d2 - D * D));
|
|
46
|
+
let cx0 = (D * dy - dx * d) / d2;
|
|
47
|
+
let cy0 = (-D * dx - dy * d) / d2;
|
|
48
|
+
const cx1 = (D * dy + dx * d) / d2;
|
|
49
|
+
const cy1 = (-D * dx + dy * d) / d2;
|
|
50
|
+
const dx0 = cx0 - x00;
|
|
51
|
+
const dy0 = cy0 - y00;
|
|
52
|
+
const dx1 = cx1 - x00;
|
|
53
|
+
const dy1 = cy1 - y00;
|
|
54
|
+
if (dx0 * dx0 + dy0 * dy0 > dx1 * dx1 + dy1 * dy1) {
|
|
55
|
+
cx0 = cx1;
|
|
56
|
+
cy0 = cy1;
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
cx: cx0,
|
|
60
|
+
cy: cy0,
|
|
61
|
+
x01: -ox,
|
|
62
|
+
y01: -oy,
|
|
63
|
+
x11: cx0 * (r1 / r - 1),
|
|
64
|
+
y11: cy0 * (r1 / r - 1)
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Padded angles, clamped corner radii and edge points of a partial sector,
|
|
69
|
+
* shared by both path generators so they agree exactly.
|
|
70
|
+
*/
|
|
71
|
+
function sector(options, r0, r1, a0, a1, da, cw) {
|
|
72
|
+
let a01 = a0;
|
|
73
|
+
let a11 = a1;
|
|
74
|
+
let a00 = a0;
|
|
75
|
+
let a10 = a1;
|
|
76
|
+
let da0 = da;
|
|
77
|
+
let da1 = da;
|
|
78
|
+
const ap = (options.padAngle ?? 0) / 2;
|
|
79
|
+
const rp = ap > EPSILON ? options.padRadius ?? Math.sqrt(r0 * r0 + r1 * r1) : 0;
|
|
80
|
+
const rc = Math.min(Math.abs(r1 - r0) / 2, options.cornerRadius ?? 0);
|
|
81
|
+
let rc0 = rc;
|
|
82
|
+
let rc1 = rc;
|
|
83
|
+
if (rp > EPSILON) {
|
|
84
|
+
let p0 = asin(rp / r0 * Math.sin(ap));
|
|
85
|
+
let p1 = asin(rp / r1 * Math.sin(ap));
|
|
86
|
+
da0 -= p0 * 2;
|
|
87
|
+
if (da0 > EPSILON) {
|
|
88
|
+
p0 *= cw ? 1 : -1;
|
|
89
|
+
a00 += p0;
|
|
90
|
+
a10 -= p0;
|
|
91
|
+
} else {
|
|
92
|
+
da0 = 0;
|
|
93
|
+
a00 = a10 = (a0 + a1) / 2;
|
|
94
|
+
}
|
|
95
|
+
da1 -= p1 * 2;
|
|
96
|
+
if (da1 > EPSILON) {
|
|
97
|
+
p1 *= cw ? 1 : -1;
|
|
98
|
+
a01 += p1;
|
|
99
|
+
a11 -= p1;
|
|
100
|
+
} else {
|
|
101
|
+
da1 = 0;
|
|
102
|
+
a01 = a11 = (a0 + a1) / 2;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
const x01 = r1 * Math.cos(a01);
|
|
106
|
+
const y01 = r1 * Math.sin(a01);
|
|
107
|
+
const x10 = r0 * Math.cos(a10);
|
|
108
|
+
const y10 = r0 * Math.sin(a10);
|
|
109
|
+
const x11 = r1 * Math.cos(a11);
|
|
110
|
+
const y11 = r1 * Math.sin(a11);
|
|
111
|
+
const x00 = r0 * Math.cos(a00);
|
|
112
|
+
const y00 = r0 * Math.sin(a00);
|
|
113
|
+
if (rc > EPSILON && da < PI) {
|
|
114
|
+
const oc = intersect(x01, y01, x00, y00, x11, y11, x10, y10);
|
|
115
|
+
if (oc) {
|
|
116
|
+
const ax = x01 - oc[0];
|
|
117
|
+
const ay = y01 - oc[1];
|
|
118
|
+
const bx = x11 - oc[0];
|
|
119
|
+
const by = y11 - oc[1];
|
|
120
|
+
const cos = (ax * bx + ay * by) / (Math.sqrt(ax * ax + ay * ay) * Math.sqrt(bx * bx + by * by));
|
|
121
|
+
const kc = 1 / Math.sin(acos(cos) / 2);
|
|
122
|
+
const lc = Math.sqrt(oc[0] * oc[0] + oc[1] * oc[1]);
|
|
123
|
+
rc0 = Math.min(rc, (r0 - lc) / (kc - 1));
|
|
124
|
+
rc1 = Math.min(rc, (r1 - lc) / (kc + 1));
|
|
125
|
+
} else rc0 = rc1 = 0;
|
|
126
|
+
}
|
|
127
|
+
return {
|
|
128
|
+
a00,
|
|
129
|
+
a01,
|
|
130
|
+
a10,
|
|
131
|
+
a11,
|
|
132
|
+
da0,
|
|
133
|
+
da1,
|
|
134
|
+
rc,
|
|
135
|
+
rc0,
|
|
136
|
+
rc1,
|
|
137
|
+
x01,
|
|
138
|
+
y01,
|
|
139
|
+
x10,
|
|
140
|
+
y10,
|
|
141
|
+
x11,
|
|
142
|
+
y11,
|
|
143
|
+
x00,
|
|
144
|
+
y00
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
/** Midpoint of an arc, e.g. to anchor a tooltip or label (like d3's `arc.centroid`). */
|
|
148
|
+
function arcCentroid(options) {
|
|
149
|
+
const r = (options.innerRadius + options.outerRadius) / 2;
|
|
150
|
+
const a = (options.startAngle + options.endAngle) / 2 - HALF_PI;
|
|
151
|
+
return [Math.cos(a) * r, Math.sin(a) * r];
|
|
152
|
+
}
|
|
153
|
+
/** Pad angle giving a constant `gap` (in pixels) between arcs of a ring. */
|
|
154
|
+
function padAngleForGap(gap, innerRadius, outerRadius) {
|
|
155
|
+
const rp = Math.sqrt(innerRadius * innerRadius + outerRadius * outerRadius);
|
|
156
|
+
return rp > 0 ? 2 * Math.asin(Math.min(1, gap / 2 / rp)) : 0;
|
|
157
|
+
}
|
|
158
|
+
/** Angle of a point around the origin. */
|
|
159
|
+
const angleOf = (x, y) => Math.atan2(y, x);
|
|
160
|
+
/**
|
|
161
|
+
* The same sector as {@link arcPath}, drawn with a fixed command structure:
|
|
162
|
+
* every corner is always present (zero length when there is none) and each
|
|
163
|
+
* ring is split into two half arcs, so the large-arc flag never flips.
|
|
164
|
+
* Paths of different angles therefore keep their commands while an arc is
|
|
165
|
+
* redrawn frame by frame, turning to its new angles (see `sweep`).
|
|
166
|
+
*/
|
|
167
|
+
function arcPathStable(options) {
|
|
168
|
+
const k = 10 ** Math.max(0, Math.min(12, Math.floor(options.precision ?? 2)));
|
|
169
|
+
const n = (v) => {
|
|
170
|
+
const r = Math.round(v * k) / k;
|
|
171
|
+
return String(r === 0 ? 0 : r);
|
|
172
|
+
};
|
|
173
|
+
let d = "";
|
|
174
|
+
const move = (x, y) => {
|
|
175
|
+
d += `M${n(x)},${n(y)}`;
|
|
176
|
+
};
|
|
177
|
+
const line = (x, y) => {
|
|
178
|
+
d += `L${n(x)},${n(y)}`;
|
|
179
|
+
};
|
|
180
|
+
const arc = (r, sweep, x, y) => {
|
|
181
|
+
d += `A${n(r)},${n(r)},0,0,${sweep},${n(x)},${n(y)}`;
|
|
182
|
+
};
|
|
183
|
+
/** Two half arcs of radius `r` around the origin from angle `a0` to `a1`. */
|
|
184
|
+
const ring = (r, a0, a1, ccw) => {
|
|
185
|
+
let delta = ccw ? a0 - a1 : a1 - a0;
|
|
186
|
+
delta = (delta % TAU + TAU) % TAU;
|
|
187
|
+
if (delta < EPSILON && Math.abs(a1 - a0) > EPSILON) delta = TAU;
|
|
188
|
+
const mid = ccw ? a0 - delta / 2 : a0 + delta / 2;
|
|
189
|
+
const sweep = ccw ? 0 : 1;
|
|
190
|
+
arc(r, sweep, r * Math.cos(mid), r * Math.sin(mid));
|
|
191
|
+
arc(r, sweep, r * Math.cos(a1), r * Math.sin(a1));
|
|
192
|
+
};
|
|
193
|
+
let r0 = Math.max(0, options.innerRadius);
|
|
194
|
+
let r1 = Math.max(0, options.outerRadius);
|
|
195
|
+
if (r1 < r0) [r0, r1] = [r1, r0];
|
|
196
|
+
const a0 = options.startAngle - HALF_PI;
|
|
197
|
+
const a1 = options.endAngle - HALF_PI;
|
|
198
|
+
const da = Math.abs(a1 - a0);
|
|
199
|
+
const cw = a1 > a0;
|
|
200
|
+
const outerSweep = cw ? 1 : 0;
|
|
201
|
+
if (!(r1 > EPSILON)) {
|
|
202
|
+
move(0, 0);
|
|
203
|
+
for (let i = 0; i < 4; i++) arc(0, outerSweep, 0, 0);
|
|
204
|
+
line(0, 0);
|
|
205
|
+
for (let i = 0; i < 4; i++) arc(0, outerSweep, 0, 0);
|
|
206
|
+
return `${d}Z`;
|
|
207
|
+
}
|
|
208
|
+
if (da > TAU - EPSILON) {
|
|
209
|
+
const ox = r1 * Math.cos(a0);
|
|
210
|
+
const oy = r1 * Math.sin(a0);
|
|
211
|
+
move(ox, oy);
|
|
212
|
+
arc(r1, outerSweep, ox, oy);
|
|
213
|
+
ring(r1, a0, a0 + (cw ? TAU : -TAU) * (1 - 1e-9), !cw);
|
|
214
|
+
arc(r1, outerSweep, ox, oy);
|
|
215
|
+
const ix = r0 * Math.cos(a0);
|
|
216
|
+
const iy = r0 * Math.sin(a0);
|
|
217
|
+
line(ix, iy);
|
|
218
|
+
arc(r0, outerSweep, ix, iy);
|
|
219
|
+
if (r0 > EPSILON) ring(r0, a0, a0 + (cw ? -TAU : TAU) * (1 - 1e-9), cw);
|
|
220
|
+
else for (let i = 0; i < 2; i++) arc(0, outerSweep, 0, 0);
|
|
221
|
+
arc(r0, outerSweep, ix, iy);
|
|
222
|
+
return `${d}Z`;
|
|
223
|
+
}
|
|
224
|
+
const { a00, a01, a10, a11, da0, da1, rc, rc0, rc1, x01, y01, x10, y10, x11, y11, x00, y00 } = sector(options, r0, r1, a0, a1, da, cw);
|
|
225
|
+
if (da1 > EPSILON && rc1 > EPSILON) {
|
|
226
|
+
const t0 = cornerTangents(x00, y00, x01, y01, r1, rc1, cw);
|
|
227
|
+
const t1 = cornerTangents(x11, y11, x10, y10, r1, rc1, cw);
|
|
228
|
+
move(t0.cx + t0.x01, t0.cy + t0.y01);
|
|
229
|
+
if (rc1 < rc) {
|
|
230
|
+
const ex = t1.cx + t1.x01;
|
|
231
|
+
const ey = t1.cy + t1.y01;
|
|
232
|
+
arc(rc1, outerSweep, ex, ey);
|
|
233
|
+
arc(r1, outerSweep, ex, ey);
|
|
234
|
+
arc(r1, outerSweep, ex, ey);
|
|
235
|
+
arc(rc1, outerSweep, ex, ey);
|
|
236
|
+
} else {
|
|
237
|
+
arc(rc1, outerSweep, t0.cx + t0.x11, t0.cy + t0.y11);
|
|
238
|
+
ring(r1, angleOf(t0.cx + t0.x11, t0.cy + t0.y11), angleOf(t1.cx + t1.x11, t1.cy + t1.y11), !cw);
|
|
239
|
+
arc(rc1, outerSweep, t1.cx + t1.x01, t1.cy + t1.y01);
|
|
240
|
+
}
|
|
241
|
+
} else {
|
|
242
|
+
move(x01, y01);
|
|
243
|
+
arc(r1, outerSweep, x01, y01);
|
|
244
|
+
if (da1 > EPSILON) ring(r1, a01, a11, !cw);
|
|
245
|
+
else for (let i = 0; i < 2; i++) arc(r1, outerSweep, x01, y01);
|
|
246
|
+
arc(r1, outerSweep, x11, y11);
|
|
247
|
+
}
|
|
248
|
+
if (!(r0 > EPSILON) || !(da0 > EPSILON)) {
|
|
249
|
+
line(x10, y10);
|
|
250
|
+
for (let i = 0; i < 4; i++) arc(r0, outerSweep, x10, y10);
|
|
251
|
+
} else if (rc0 > EPSILON) {
|
|
252
|
+
const t0 = cornerTangents(x10, y10, x11, y11, r0, -rc0, cw);
|
|
253
|
+
const t1 = cornerTangents(x01, y01, x00, y00, r0, -rc0, cw);
|
|
254
|
+
line(t0.cx + t0.x01, t0.cy + t0.y01);
|
|
255
|
+
if (rc0 < rc) {
|
|
256
|
+
const ex = t1.cx + t1.x01;
|
|
257
|
+
const ey = t1.cy + t1.y01;
|
|
258
|
+
arc(rc0, outerSweep, ex, ey);
|
|
259
|
+
arc(r0, outerSweep, ex, ey);
|
|
260
|
+
arc(r0, outerSweep, ex, ey);
|
|
261
|
+
arc(rc0, outerSweep, ex, ey);
|
|
262
|
+
} else {
|
|
263
|
+
arc(rc0, outerSweep, t0.cx + t0.x11, t0.cy + t0.y11);
|
|
264
|
+
ring(r0, angleOf(t0.cx + t0.x11, t0.cy + t0.y11), angleOf(t1.cx + t1.x11, t1.cy + t1.y11), cw);
|
|
265
|
+
arc(rc0, outerSweep, t1.cx + t1.x01, t1.cy + t1.y01);
|
|
266
|
+
}
|
|
267
|
+
} else {
|
|
268
|
+
line(x10, y10);
|
|
269
|
+
arc(r0, outerSweep, x10, y10);
|
|
270
|
+
ring(r0, a10, a00, cw);
|
|
271
|
+
arc(r0, outerSweep, x00, y00);
|
|
272
|
+
}
|
|
273
|
+
return `${d}Z`;
|
|
274
|
+
}
|
|
275
|
+
//#endregion
|
|
276
|
+
Object.defineProperty(exports, "DEG", {
|
|
277
|
+
enumerable: true,
|
|
278
|
+
get: function() {
|
|
279
|
+
return DEG;
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
Object.defineProperty(exports, "arcCentroid", {
|
|
283
|
+
enumerable: true,
|
|
284
|
+
get: function() {
|
|
285
|
+
return arcCentroid;
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
Object.defineProperty(exports, "arcPathStable", {
|
|
289
|
+
enumerable: true,
|
|
290
|
+
get: function() {
|
|
291
|
+
return arcPathStable;
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
Object.defineProperty(exports, "padAngleForGap", {
|
|
295
|
+
enumerable: true,
|
|
296
|
+
get: function() {
|
|
297
|
+
return padAngleForGap;
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
//# sourceMappingURL=arc-BXpLrt9b.cjs.map
|