@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,134 @@
|
|
|
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
|
+
//#region src/charts/value-labels.ts
|
|
5
|
+
/** Space between a mark and its label, and around labels. */
|
|
6
|
+
const GAP = 4;
|
|
7
|
+
const overlaps = (a, b) => a.x < b.x + b.width && b.x < a.x + a.width && a.y < b.y + b.height && b.y < a.y + a.height;
|
|
8
|
+
const contains = (outer, inner) => inner.x >= outer.x - 1 && inner.y >= outer.y - 1 && inner.x + inner.width <= outer.x + outer.width + 1 && inner.y + inner.height <= outer.y + outer.height + 1;
|
|
9
|
+
/** The labels layer of a chart, or `null` when nothing gets one. */
|
|
10
|
+
function valueLabels(config, interaction, ctx) {
|
|
11
|
+
const option = config.valueLabels;
|
|
12
|
+
const options = typeof option === "object" ? option : {};
|
|
13
|
+
const { fontSize, locale } = ctx;
|
|
14
|
+
const spec = config.type.valueLabels;
|
|
15
|
+
const pie = spec?.marks === "slice";
|
|
16
|
+
const cell = spec?.marks === "cell";
|
|
17
|
+
const stacked = !!config.stacked;
|
|
18
|
+
const format = options.format ? require_format.formatNumber(options.format, locale) : pie ? (v) => require_format.getNumberFormat(locale, {
|
|
19
|
+
style: "percent",
|
|
20
|
+
maximumFractionDigits: 1
|
|
21
|
+
}).format(v) : spec?.format ? require_format.formatNumber(spec.format(config), locale) : void 0;
|
|
22
|
+
const height = fontSize;
|
|
23
|
+
const items = [];
|
|
24
|
+
const last = /* @__PURE__ */ new Map();
|
|
25
|
+
let total = 0;
|
|
26
|
+
for (let i = 0; i < interaction.count; i++) {
|
|
27
|
+
const hit = interaction.hitIndex(i);
|
|
28
|
+
for (const item of hit?.items ?? []) {
|
|
29
|
+
if (item.value === null || item.y === null || !hit) continue;
|
|
30
|
+
total += Math.abs(item.value);
|
|
31
|
+
if (!pie && !item.box && options.points !== "all") last.set(item.seriesIndex, items.length);
|
|
32
|
+
items.push([
|
|
33
|
+
`${i}-${item.seriesIndex}`,
|
|
34
|
+
item,
|
|
35
|
+
hit
|
|
36
|
+
]);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
const marks = items.flatMap(([, item]) => item.box ? [item.box] : []);
|
|
40
|
+
const placed = [];
|
|
41
|
+
items.forEach(([key, item, hit], n) => {
|
|
42
|
+
const { area } = hit;
|
|
43
|
+
if (!pie && !item.box && options.points !== "all" && last.get(item.seriesIndex) !== n) return;
|
|
44
|
+
const value = item.value;
|
|
45
|
+
const share = value / (total || 1);
|
|
46
|
+
const text = format ? format(pie ? share : value) : item.text;
|
|
47
|
+
const width = require_layout.estimateTextWidth(text, fontSize);
|
|
48
|
+
const at = (x, y, inside) => {
|
|
49
|
+
if (!item.box && !pie) x = Math.max(area.x + width / 2 + 2, Math.min(x, area.x + area.width - width / 2 - 2));
|
|
50
|
+
return {
|
|
51
|
+
key,
|
|
52
|
+
text,
|
|
53
|
+
x,
|
|
54
|
+
y,
|
|
55
|
+
inside,
|
|
56
|
+
box: {
|
|
57
|
+
x: x - width / 2 - 2,
|
|
58
|
+
y: y - height / 2,
|
|
59
|
+
width: width + 4,
|
|
60
|
+
height
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
const y = item.y;
|
|
65
|
+
const candidates = [];
|
|
66
|
+
const { box } = item;
|
|
67
|
+
if (pie) candidates.push(at(item.x, y, true));
|
|
68
|
+
else if (box) {
|
|
69
|
+
const horizontal = hit.axis === "y";
|
|
70
|
+
const down = value < 0;
|
|
71
|
+
if (!stacked && !cell) {
|
|
72
|
+
const reach = (horizontal ? width / 2 : height / 2) + GAP;
|
|
73
|
+
const sign = down ? 1 : -1;
|
|
74
|
+
const along = y + sign * reach;
|
|
75
|
+
candidates.push(horizontal ? at(item.x - sign * reach, y, false) : at(item.x, along, false), ...horizontal ? [] : [at(box.x + width / 2 - 3, along, false), at(box.x + box.width - width / 2 + 3, along, false)], horizontal ? at(item.x + sign * reach, y, true) : at(item.x, y - sign * reach, true));
|
|
76
|
+
} else candidates.push(at(box.x + box.width / 2, box.y + box.height / 2, true));
|
|
77
|
+
} else {
|
|
78
|
+
const side = width / 2 + GAP + 4;
|
|
79
|
+
candidates.push(at(item.x, y - height / 2 - GAP - 2, false), at(item.x, y + height / 2 + GAP + 2, false), at(item.x - side, y, false), at(item.x + side, y, false));
|
|
80
|
+
}
|
|
81
|
+
const room = {
|
|
82
|
+
...area,
|
|
83
|
+
y: 0,
|
|
84
|
+
height: area.y + area.height
|
|
85
|
+
};
|
|
86
|
+
const fits = (p, slim = {
|
|
87
|
+
...p.box,
|
|
88
|
+
x: p.box.x + 5,
|
|
89
|
+
width: p.box.width - 10
|
|
90
|
+
}) => contains(pie ? area : room, p.box) && (!p.inside || !box || contains(box, p.box)) && (!pie || sliceFits(item, area, share, p.box)) && !placed.some((other) => overlaps(other.box, p.box)) && !marks.some((mark) => mark !== box && overlaps(mark, slim));
|
|
91
|
+
const spot = candidates.find((p) => fits(p));
|
|
92
|
+
if (spot) placed.push(spot);
|
|
93
|
+
});
|
|
94
|
+
if (!placed.length) return null;
|
|
95
|
+
return require_vnode.h("g", {
|
|
96
|
+
key: "value-labels",
|
|
97
|
+
class: "tc-value-labels",
|
|
98
|
+
"aria-hidden": "true"
|
|
99
|
+
}, placed.map((p) => require_vnode.h("text", {
|
|
100
|
+
key: p.key,
|
|
101
|
+
class: ["tc-value-label", p.inside && "tc-value-label-inside"],
|
|
102
|
+
style: `transform:translate(${require_layout.round(p.x)}px,${require_layout.round(p.y)}px)`,
|
|
103
|
+
"text-anchor": "middle",
|
|
104
|
+
dy: "0.35em"
|
|
105
|
+
}, p.text)));
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Whether a label fits its slice: it sits at the slice's centroid, where the
|
|
109
|
+
* slice is about its share of the circle wide and twice the distance to the
|
|
110
|
+
* outer edge deep.
|
|
111
|
+
*/
|
|
112
|
+
function sliceFits(item, area, share, label) {
|
|
113
|
+
const outer = area.width / 2;
|
|
114
|
+
const radius = Math.hypot(item.x - area.x - outer, item.y - area.y - outer);
|
|
115
|
+
const depth = 2 * (outer - radius);
|
|
116
|
+
return label.width <= share * 2 * Math.PI * radius && label.height <= depth;
|
|
117
|
+
}
|
|
118
|
+
/** The step that adds the labels over the content of charts with `valueLabels`. */
|
|
119
|
+
const labelsStep = (config, content, interaction, ctx) => config.valueLabels && interaction ? [content, valueLabels(config, interaction, ctx)] : content;
|
|
120
|
+
//#endregion
|
|
121
|
+
Object.defineProperty(exports, "labelsStep", {
|
|
122
|
+
enumerable: true,
|
|
123
|
+
get: function() {
|
|
124
|
+
return labelsStep;
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
Object.defineProperty(exports, "valueLabels", {
|
|
128
|
+
enumerable: true,
|
|
129
|
+
get: function() {
|
|
130
|
+
return valueLabels;
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
//# sourceMappingURL=value-labels-B0WJoJ7x.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"value-labels-B0WJoJ7x.cjs","names":["formatNumber","getNumberFormat","estimateTextWidth","h","round"],"sources":["../src/charts/value-labels.ts"],"sourcesContent":["/**\n * Value labels: the value written on each mark, for charts read at a\n * glance. They are worked out from the chart's interaction, so every type\n * gets them the same way: bars at their end (inside when there is no room\n * outside), stacked segments and heatmap cells in their middle, lines and\n * points above their point (the last one by default), slices in their\n * middle with their share. A label that does not fit its mark or the plot,\n * or that would cover another one, is left out: labels never overlap.\n */\nimport type { ChartConfig, RenderContext } from '../chart.ts'\nimport type { PostStep } from '../features.ts'\nimport { formatNumber, getNumberFormat, type NumberFormat } from '../format.ts'\nimport type { Hit, HitItem, Interaction } from '../interaction.ts'\nimport { estimateTextWidth, type Rect, round } from '../layout.ts'\nimport { h, type VNode } from '../vnode.ts'\n\nexport interface ValueLabelOptions {\n /** Format of the values. Defaults to the value axis format (slices: their share in percent). */\n format?: NumberFormat\n /** Which points of lines, areas and scatters get a label. Defaults to `'last'`. */\n points?: 'last' | 'all'\n}\n\n/** Space between a mark and its label, and around labels. */\nconst GAP = 4\n\ninterface Placed {\n key: string\n text: string\n x: number\n y: number\n inside: boolean\n box: Rect\n}\n\nconst overlaps = (a: Rect, b: Rect): boolean =>\n a.x < b.x + b.width && b.x < a.x + a.width && a.y < b.y + b.height && b.y < a.y + a.height\n\nconst contains = (outer: Rect, inner: Rect): boolean =>\n inner.x >= outer.x - 1 &&\n inner.y >= outer.y - 1 &&\n inner.x + inner.width <= outer.x + outer.width + 1 &&\n inner.y + inner.height <= outer.y + outer.height + 1\n\n/** The labels layer of a chart, or `null` when nothing gets one. */\nexport function valueLabels(\n config: ChartConfig<object>,\n interaction: Interaction,\n ctx: RenderContext,\n): VNode | null {\n const option = config.valueLabels\n const options: ValueLabelOptions = typeof option === 'object' ? option : {}\n const { fontSize, locale } = ctx\n // What the chart type says about its marks (slices, cells) and its number format.\n const spec = config.type.valueLabels\n const pie = spec?.marks === 'slice'\n const cell = spec?.marks === 'cell'\n const stacked = !!(config as { stacked?: unknown }).stacked\n const format = options.format\n ? formatNumber(options.format, locale)\n : pie\n ? (v: number) =>\n getNumberFormat(locale, { style: 'percent', maximumFractionDigits: 1 }).format(v)\n : spec?.format\n ? formatNumber(spec.format(config), locale)\n : undefined\n // Numbers have no descenders: one em is their height, with room to spare.\n const height = fontSize\n\n // Candidates in order of priority: every hit's items, and for points only the\n // last one of each series unless all are asked for.\n const items: [string, HitItem, Hit][] = []\n const last = new Map<number, number>()\n let total = 0\n for (let i = 0; i < interaction.count; i++) {\n const hit = interaction.hitIndex(i)\n for (const item of hit?.items ?? []) {\n if (item.value === null || item.y === null || !hit) continue\n total += Math.abs(item.value)\n if (!pie && !item.box && options.points !== 'all') last.set(item.seriesIndex, items.length)\n items.push([`${i}-${item.seriesIndex}`, item, hit])\n }\n }\n\n // Marks a label must not cover: every bar and cell but its own.\n const marks = items.flatMap(([, item]) => (item.box ? [item.box] : []))\n const placed: Placed[] = []\n items.forEach(([key, item, hit], n) => {\n const { area } = hit\n if (!pie && !item.box && options.points !== 'all' && last.get(item.seriesIndex) !== n) return\n const value = item.value as number\n const share = value / (total || 1)\n const text = format ? format(pie ? share : value) : item.text\n const width = estimateTextWidth(text, fontSize)\n const at = (x: number, y: number, inside: boolean): Placed => {\n // A point's label at the plot's edge (the last point) moves in.\n if (!item.box && !pie) {\n x = Math.max(area.x + width / 2 + 2, Math.min(x, area.x + area.width - width / 2 - 2))\n }\n return {\n key,\n text,\n x,\n y,\n inside,\n box: { x: x - width / 2 - 2, y: y - height / 2, width: width + 4, height },\n }\n }\n const y = item.y as number\n const candidates: Placed[] = []\n const { box } = item\n if (pie) {\n candidates.push(at(item.x, y, true))\n } else if (box) {\n const horizontal = hit.axis === 'y'\n const down = value < 0\n if (!stacked && !cell) {\n // Beyond the bar's end, then just inside it.\n const reach = (horizontal ? width / 2 : height / 2) + GAP\n const sign = down ? 1 : -1\n const along = y + sign * reach\n candidates.push(\n horizontal ? at(item.x - sign * reach, y, false) : at(item.x, along, false),\n // A label wider than its bar may lean off a taller neighbour.\n ...(horizontal\n ? []\n : [\n at(box.x + width / 2 - 3, along, false),\n at(box.x + box.width - width / 2 + 3, along, false),\n ]),\n horizontal ? at(item.x + sign * reach, y, true) : at(item.x, y - sign * reach, true),\n )\n } else {\n candidates.push(at(box.x + box.width / 2, box.y + box.height / 2, true))\n }\n } else {\n // Above the point, below it, or beside it (the end of a line, at the plot's edge).\n const side = width / 2 + GAP + 4\n candidates.push(\n at(item.x, y - height / 2 - GAP - 2, false),\n at(item.x, y + height / 2 + GAP + 2, false),\n at(item.x - side, y, false),\n at(item.x + side, y, false),\n )\n }\n // Labels may rise into the margin above the plot, not over the axes.\n const room = { ...area, y: 0, height: area.y + area.height }\n // Glyphs leave a little room at their sides (`slim`): a label may brush a neighbour.\n const fits = (p: Placed, slim = { ...p.box, x: p.box.x + 5, width: p.box.width - 10 }) =>\n contains(pie ? area : room, p.box) &&\n (!p.inside || !box || contains(box, p.box)) &&\n (!pie || sliceFits(item, area, share, p.box)) &&\n !placed.some((other) => overlaps(other.box, p.box)) &&\n !marks.some((mark) => mark !== box && overlaps(mark, slim))\n const spot = candidates.find((p) => fits(p))\n if (spot) placed.push(spot)\n })\n\n if (!placed.length) return null\n return h(\n 'g',\n { key: 'value-labels', class: 'tc-value-labels', 'aria-hidden': 'true' },\n placed.map((p) =>\n h(\n 'text',\n {\n key: p.key,\n class: ['tc-value-label', p.inside && 'tc-value-label-inside'],\n style: `transform:translate(${round(p.x)}px,${round(p.y)}px)`,\n 'text-anchor': 'middle',\n dy: '0.35em',\n },\n p.text,\n ),\n ),\n )\n}\n\n/**\n * Whether a label fits its slice: it sits at the slice's centroid, where the\n * slice is about its share of the circle wide and twice the distance to the\n * outer edge deep.\n */\nfunction sliceFits(item: HitItem, area: Rect, share: number, label: Rect): boolean {\n const outer = area.width / 2\n const radius = Math.hypot(item.x - area.x - outer, (item.y as number) - area.y - outer)\n const depth = 2 * (outer - radius)\n return label.width <= share * 2 * Math.PI * radius && label.height <= depth\n}\n\n/** The step that adds the labels over the content of charts with `valueLabels`. */\nexport const labelsStep: PostStep = (config, content, interaction, ctx) =>\n config.valueLabels && interaction ? [content, valueLabels(config, interaction, ctx)] : content\n"],"mappings":";;;;;AAwBA,MAAM,MAAM;AAWZ,MAAM,YAAY,GAAS,MACzB,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,IAAI,EAAE;AAEtF,MAAM,YAAY,OAAa,UAC7B,MAAM,KAAK,MAAM,IAAI,KACrB,MAAM,KAAK,MAAM,IAAI,KACrB,M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ACA;EAAE,KAAK;EAAgB,OAAO;EAAmB,eAAe;CAAO,GACvE,OAAO,KAAK,MACVA,cAAAA,EACE,QACA;EACE,KAAK,EAAE;EACP,OAAO,CAAC,kBAAkB,EAAE,UAAU,uBAAuB;EAC7D,OAAO,uBAAuBC,eAAAA,MAAM,EAAE,CAAC,EAAE,KAAKA,eAAAA,MAAM,EAAE,CAAC,EAAE;EACzD,eAAe;EACf,IAAI;CACN,GACA,EAAE,IACJ,CACF,CACF;AACF;;;;;;AAOA,SAAS,UAAU,MAAe,MAAY,OAAe,OAAsB;CACjF,MAAM,QAAQ,KAAK,QAAQ;CAC3B,MAAM,SAAS,KAAK,MAAM,KAAK,IAAI,KAAK,IAAI,OAAQ,KAAK,IAAe,KAAK,IAAI,KAAK;CACtF,MAAM,QAAQ,KAAK,QAAQ;CAC3B,OAAO,MAAM,SAAS,QAAQ,IAAI,KAAK,KAAK,UAAU,MAAM,UAAU;AACxE;;AAGA,MAAa,cAAwB,QAAQ,SAAS,aAAa,QACjE,OAAO,eAAe,cAAc,CAAC,SAAS,YAAY,QAAQ,aAAa,GAAG,CAAC,IAAI"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { a as round, n as estimateTextWidth } from "./layout-B3hiqVEw.js";
|
|
2
|
+
import { t as h } from "./vnode-tCWItoUH.js";
|
|
3
|
+
import { o as getNumberFormat, r as formatNumber } from "./format-lStwuc1L.js";
|
|
4
|
+
//#region src/charts/value-labels.ts
|
|
5
|
+
/** Space between a mark and its label, and around labels. */
|
|
6
|
+
const GAP = 4;
|
|
7
|
+
const overlaps = (a, b) => a.x < b.x + b.width && b.x < a.x + a.width && a.y < b.y + b.height && b.y < a.y + a.height;
|
|
8
|
+
const contains = (outer, inner) => inner.x >= outer.x - 1 && inner.y >= outer.y - 1 && inner.x + inner.width <= outer.x + outer.width + 1 && inner.y + inner.height <= outer.y + outer.height + 1;
|
|
9
|
+
/** The labels layer of a chart, or `null` when nothing gets one. */
|
|
10
|
+
function valueLabels(config, interaction, ctx) {
|
|
11
|
+
const option = config.valueLabels;
|
|
12
|
+
const options = typeof option === "object" ? option : {};
|
|
13
|
+
const { fontSize, locale } = ctx;
|
|
14
|
+
const spec = config.type.valueLabels;
|
|
15
|
+
const pie = spec?.marks === "slice";
|
|
16
|
+
const cell = spec?.marks === "cell";
|
|
17
|
+
const stacked = !!config.stacked;
|
|
18
|
+
const format = options.format ? formatNumber(options.format, locale) : pie ? (v) => getNumberFormat(locale, {
|
|
19
|
+
style: "percent",
|
|
20
|
+
maximumFractionDigits: 1
|
|
21
|
+
}).format(v) : spec?.format ? formatNumber(spec.format(config), locale) : void 0;
|
|
22
|
+
const height = fontSize;
|
|
23
|
+
const items = [];
|
|
24
|
+
const last = /* @__PURE__ */ new Map();
|
|
25
|
+
let total = 0;
|
|
26
|
+
for (let i = 0; i < interaction.count; i++) {
|
|
27
|
+
const hit = interaction.hitIndex(i);
|
|
28
|
+
for (const item of hit?.items ?? []) {
|
|
29
|
+
if (item.value === null || item.y === null || !hit) continue;
|
|
30
|
+
total += Math.abs(item.value);
|
|
31
|
+
if (!pie && !item.box && options.points !== "all") last.set(item.seriesIndex, items.length);
|
|
32
|
+
items.push([
|
|
33
|
+
`${i}-${item.seriesIndex}`,
|
|
34
|
+
item,
|
|
35
|
+
hit
|
|
36
|
+
]);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
const marks = items.flatMap(([, item]) => item.box ? [item.box] : []);
|
|
40
|
+
const placed = [];
|
|
41
|
+
items.forEach(([key, item, hit], n) => {
|
|
42
|
+
const { area } = hit;
|
|
43
|
+
if (!pie && !item.box && options.points !== "all" && last.get(item.seriesIndex) !== n) return;
|
|
44
|
+
const value = item.value;
|
|
45
|
+
const share = value / (total || 1);
|
|
46
|
+
const text = format ? format(pie ? share : value) : item.text;
|
|
47
|
+
const width = estimateTextWidth(text, fontSize);
|
|
48
|
+
const at = (x, y, inside) => {
|
|
49
|
+
if (!item.box && !pie) x = Math.max(area.x + width / 2 + 2, Math.min(x, area.x + area.width - width / 2 - 2));
|
|
50
|
+
return {
|
|
51
|
+
key,
|
|
52
|
+
text,
|
|
53
|
+
x,
|
|
54
|
+
y,
|
|
55
|
+
inside,
|
|
56
|
+
box: {
|
|
57
|
+
x: x - width / 2 - 2,
|
|
58
|
+
y: y - height / 2,
|
|
59
|
+
width: width + 4,
|
|
60
|
+
height
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
const y = item.y;
|
|
65
|
+
const candidates = [];
|
|
66
|
+
const { box } = item;
|
|
67
|
+
if (pie) candidates.push(at(item.x, y, true));
|
|
68
|
+
else if (box) {
|
|
69
|
+
const horizontal = hit.axis === "y";
|
|
70
|
+
const down = value < 0;
|
|
71
|
+
if (!stacked && !cell) {
|
|
72
|
+
const reach = (horizontal ? width / 2 : height / 2) + GAP;
|
|
73
|
+
const sign = down ? 1 : -1;
|
|
74
|
+
const along = y + sign * reach;
|
|
75
|
+
candidates.push(horizontal ? at(item.x - sign * reach, y, false) : at(item.x, along, false), ...horizontal ? [] : [at(box.x + width / 2 - 3, along, false), at(box.x + box.width - width / 2 + 3, along, false)], horizontal ? at(item.x + sign * reach, y, true) : at(item.x, y - sign * reach, true));
|
|
76
|
+
} else candidates.push(at(box.x + box.width / 2, box.y + box.height / 2, true));
|
|
77
|
+
} else {
|
|
78
|
+
const side = width / 2 + GAP + 4;
|
|
79
|
+
candidates.push(at(item.x, y - height / 2 - GAP - 2, false), at(item.x, y + height / 2 + GAP + 2, false), at(item.x - side, y, false), at(item.x + side, y, false));
|
|
80
|
+
}
|
|
81
|
+
const room = {
|
|
82
|
+
...area,
|
|
83
|
+
y: 0,
|
|
84
|
+
height: area.y + area.height
|
|
85
|
+
};
|
|
86
|
+
const fits = (p, slim = {
|
|
87
|
+
...p.box,
|
|
88
|
+
x: p.box.x + 5,
|
|
89
|
+
width: p.box.width - 10
|
|
90
|
+
}) => contains(pie ? area : room, p.box) && (!p.inside || !box || contains(box, p.box)) && (!pie || sliceFits(item, area, share, p.box)) && !placed.some((other) => overlaps(other.box, p.box)) && !marks.some((mark) => mark !== box && overlaps(mark, slim));
|
|
91
|
+
const spot = candidates.find((p) => fits(p));
|
|
92
|
+
if (spot) placed.push(spot);
|
|
93
|
+
});
|
|
94
|
+
if (!placed.length) return null;
|
|
95
|
+
return h("g", {
|
|
96
|
+
key: "value-labels",
|
|
97
|
+
class: "tc-value-labels",
|
|
98
|
+
"aria-hidden": "true"
|
|
99
|
+
}, placed.map((p) => h("text", {
|
|
100
|
+
key: p.key,
|
|
101
|
+
class: ["tc-value-label", p.inside && "tc-value-label-inside"],
|
|
102
|
+
style: `transform:translate(${round(p.x)}px,${round(p.y)}px)`,
|
|
103
|
+
"text-anchor": "middle",
|
|
104
|
+
dy: "0.35em"
|
|
105
|
+
}, p.text)));
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Whether a label fits its slice: it sits at the slice's centroid, where the
|
|
109
|
+
* slice is about its share of the circle wide and twice the distance to the
|
|
110
|
+
* outer edge deep.
|
|
111
|
+
*/
|
|
112
|
+
function sliceFits(item, area, share, label) {
|
|
113
|
+
const outer = area.width / 2;
|
|
114
|
+
const radius = Math.hypot(item.x - area.x - outer, item.y - area.y - outer);
|
|
115
|
+
const depth = 2 * (outer - radius);
|
|
116
|
+
return label.width <= share * 2 * Math.PI * radius && label.height <= depth;
|
|
117
|
+
}
|
|
118
|
+
/** The step that adds the labels over the content of charts with `valueLabels`. */
|
|
119
|
+
const labelsStep = (config, content, interaction, ctx) => config.valueLabels && interaction ? [content, valueLabels(config, interaction, ctx)] : content;
|
|
120
|
+
//#endregion
|
|
121
|
+
export { valueLabels as n, labelsStep as t };
|
|
122
|
+
|
|
123
|
+
//# sourceMappingURL=value-labels-IZIQPhfk.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"value-labels-IZIQPhfk.js","names":[],"sources":["../src/charts/value-labels.ts"],"sourcesContent":["/**\n * Value labels: the value written on each mark, for charts read at a\n * glance. They are worked out from the chart's interaction, so every type\n * gets them the same way: bars at their end (inside when there is no room\n * outside), stacked segments and heatmap cells in their middle, lines and\n * points above their point (the last one by default), slices in their\n * middle with their share. A label that does not fit its mark or the plot,\n * or that would cover another one, is left out: labels never overlap.\n */\nimport type { ChartConfig, RenderContext } from '../chart.ts'\nimport type { PostStep } from '../features.ts'\nimport { formatNumber, getNumberFormat, type NumberFormat } from '../format.ts'\nimport type { Hit, HitItem, Interaction } from '../interaction.ts'\nimport { estimateTextWidth, type Rect, round } from '../layout.ts'\nimport { h, type VNode } from '../vnode.ts'\n\nexport interface ValueLabelOptions {\n /** Format of the values. Defaults to the value axis format (slices: their share in percent). */\n format?: NumberFormat\n /** Which points of lines, areas and scatters get a label. Defaults to `'last'`. */\n points?: 'last' | 'all'\n}\n\n/** Space between a mark and its label, and around labels. */\nconst GAP = 4\n\ninterface Placed {\n key: string\n text: string\n x: number\n y: number\n inside: boolean\n box: Rect\n}\n\nconst overlaps = (a: Rect, b: Rect): boolean =>\n a.x < b.x + b.width && b.x < a.x + a.width && a.y < b.y + b.height && b.y < a.y + a.height\n\nconst contains = (outer: Rect, inner: Rect): boolean =>\n inner.x >= outer.x - 1 &&\n inner.y >= outer.y - 1 &&\n inner.x + inner.width <= outer.x + outer.width + 1 &&\n inner.y + inner.height <= outer.y + outer.height + 1\n\n/** The labels layer of a chart, or `null` when nothing gets one. */\nexport function valueLabels(\n config: ChartConfig<object>,\n interaction: Interaction,\n ctx: RenderContext,\n): VNode | null {\n const option = config.valueLabels\n const options: ValueLabelOptions = typeof option === 'object' ? option : {}\n const { fontSize, locale } = ctx\n // What the chart type says about its marks (slices, cells) and its number format.\n const spec = config.type.valueLabels\n const pie = spec?.marks === 'slice'\n const cell = spec?.marks === 'cell'\n const stacked = !!(config as { stacked?: unknown }).stacked\n const format = options.format\n ? formatNumber(options.format, locale)\n : pie\n ? (v: number) =>\n getNumberFormat(locale, { style: 'percent', maximumFractionDigits: 1 }).format(v)\n : spec?.format\n ? formatNumber(spec.format(config), locale)\n : undefined\n // Numbers have no descenders: one em is their height, with room to spare.\n const height = fontSize\n\n // Candidates in order of priority: every hit's items, and for points only the\n // last one of each series unless all are asked for.\n const items: [string, HitItem, Hit][] = []\n const last = new Map<number, number>()\n let total = 0\n for (let i = 0; i < interaction.count; i++) {\n const hit = interaction.hitIndex(i)\n for (const item of hit?.items ?? []) {\n if (item.value === null || item.y === null || !hit) continue\n total += Math.abs(item.value)\n if (!pie && !item.box && options.points !== 'all') last.set(item.seriesIndex, items.length)\n items.push([`${i}-${item.seriesIndex}`, item, hit])\n }\n }\n\n // Marks a label must not cover: every bar and cell but its own.\n const marks = items.flatMap(([, item]) => (item.box ? [item.box] : []))\n const placed: Placed[] = []\n items.forEach(([key, item, hit], n) => {\n const { area } = hit\n if (!pie && !item.box && options.points !== 'all' && last.get(item.seriesIndex) !== n) return\n const value = item.value as number\n const share = value / (total || 1)\n const text = format ? format(pie ? share : value) : item.text\n const width = estimateTextWidth(text, fontSize)\n const at = (x: number, y: number, inside: boolean): Placed => {\n // A point's label at the plot's edge (the last point) moves in.\n if (!item.box && !pie) {\n x = Math.max(area.x + width / 2 + 2, Math.min(x, area.x + area.width - width / 2 - 2))\n }\n return {\n key,\n text,\n x,\n y,\n inside,\n box: { x: x - width / 2 - 2, y: y - height / 2, width: width + 4, height },\n }\n }\n const y = item.y as number\n const candidates: Placed[] = []\n const { box } = item\n if (pie) {\n candidates.push(at(item.x, y, true))\n } else if (box) {\n const horizontal = hit.axis === 'y'\n const down = value < 0\n if (!stacked && !cell) {\n // Beyond the bar's end, then just inside it.\n const reach = (horizontal ? width / 2 : height / 2) + GAP\n const sign = down ? 1 : -1\n const along = y + sign * reach\n candidates.push(\n horizontal ? at(item.x - sign * reach, y, false) : at(item.x, along, false),\n // A label wider than its bar may lean off a taller neighbour.\n ...(horizontal\n ? []\n : [\n at(box.x + width / 2 - 3, along, false),\n at(box.x + box.width - width / 2 + 3, along, false),\n ]),\n horizontal ? at(item.x + sign * reach, y, true) : at(item.x, y - sign * reach, true),\n )\n } else {\n candidates.push(at(box.x + box.width / 2, box.y + box.height / 2, true))\n }\n } else {\n // Above the point, below it, or beside it (the end of a line, at the plot's edge).\n const side = width / 2 + GAP + 4\n candidates.push(\n at(item.x, y - height / 2 - GAP - 2, false),\n at(item.x, y + height / 2 + GAP + 2, false),\n at(item.x - side, y, false),\n at(item.x + side, y, false),\n )\n }\n // Labels may rise into the margin above the plot, not over the axes.\n const room = { ...area, y: 0, height: area.y + area.height }\n // Glyphs leave a little room at their sides (`slim`): a label may brush a neighbour.\n const fits = (p: Placed, slim = { ...p.box, x: p.box.x + 5, width: p.box.width - 10 }) =>\n contains(pie ? area : room, p.box) &&\n (!p.inside || !box || contains(box, p.box)) &&\n (!pie || sliceFits(item, area, share, p.box)) &&\n !placed.some((other) => overlaps(other.box, p.box)) &&\n !marks.some((mark) => mark !== box && overlaps(mark, slim))\n const spot = candidates.find((p) => fits(p))\n if (spot) placed.push(spot)\n })\n\n if (!placed.length) return null\n return h(\n 'g',\n { key: 'value-labels', class: 'tc-value-labels', 'aria-hidden': 'true' },\n placed.map((p) =>\n h(\n 'text',\n {\n key: p.key,\n class: ['tc-value-label', p.inside && 'tc-value-label-inside'],\n style: `transform:translate(${round(p.x)}px,${round(p.y)}px)`,\n 'text-anchor': 'middle',\n dy: '0.35em',\n },\n p.text,\n ),\n ),\n )\n}\n\n/**\n * Whether a label fits its slice: it sits at the slice's centroid, where the\n * slice is about its share of the circle wide and twice the distance to the\n * outer edge deep.\n */\nfunction sliceFits(item: HitItem, area: Rect, share: number, label: Rect): boolean {\n const outer = area.width / 2\n const radius = Math.hypot(item.x - area.x - outer, (item.y as number) - area.y - outer)\n const depth = 2 * (outer - radius)\n return label.width <= share * 2 * Math.PI * radius && label.height <= depth\n}\n\n/** The step that adds the labels over the content of charts with `valueLabels`. */\nexport const labelsStep: PostStep = (config, content, interaction, ctx) =>\n config.valueLabels && interaction ? [content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C,OAAO,MAAM,UAAU,SAAS,MAAM,KAAK,EAAE,GAAG,CAAC,KAClD,CAAC,MAAM,MAAM,SAAS,SAAS,OAAO,SAAS,MAAM,IAAI,CAAC;EAC5D,MAAM,OAAO,WAAW,MAAM,MAAM,KAAK,CAAC,CAAC;EAC3C,IAAI,MAAM,OAAO,KAAK,IAAI;CAC5B,CAAC;CAED,IAAI,CAAC,OAAO,QAAQ,OAAO;CAC3B,OAAO,EACL,KACA;EAAE,KAAK;EAAgB,OAAO;EAAmB,eAAe;CAAO,GACvE,OAAO,KAAK,MACV,EACE,QACA;EACE,KAAK,EAAE;EACP,OAAO,CAAC,kBAAkB,EAAE,UAAU,uBAAuB;EAC7D,OAAO,uBAAuB,MAAM,EAAE,CAAC,EAAE,KAAK,MAAM,EAAE,CAAC,EAAE;EACzD,eAAe;EACf,IAAI;CACN,GACA,EAAE,IACJ,CACF,CACF;AACF;;;;;;AAOA,SAAS,UAAU,MAAe,MAAY,OAAe,OAAsB;CACjF,MAAM,QAAQ,KAAK,QAAQ;CAC3B,MAAM,SAAS,KAAK,MAAM,KAAK,IAAI,KAAK,IAAI,OAAQ,KAAK,IAAe,KAAK,IAAI,KAAK;CACtF,MAAM,QAAQ,KAAK,QAAQ;CAC3B,OAAO,MAAM,SAAS,QAAQ,IAAI,KAAK,KAAK,UAAU,MAAM,UAAU;AACxE;;AAGA,MAAa,cAAwB,QAAQ,SAAS,aAAa,QACjE,OAAO,eAAe,cAAc,CAAC,SAAS,YAAY,QAAQ,aAAa,GAAG,CAAC,IAAI"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_features = require("./features-BclHgg2W.cjs");
|
|
3
|
+
const require_value_labels = require("./value-labels-B0WJoJ7x.cjs");
|
|
4
|
+
//#region src/value-labels.ts
|
|
5
|
+
/**
|
|
6
|
+
* Standalone entry: `import '@tabler/charts/value-labels'` enables
|
|
7
|
+
* `valueLabels` (values written on the marks) on the core.
|
|
8
|
+
*/
|
|
9
|
+
require_features.addPost(require_value_labels.labelsStep);
|
|
10
|
+
//#endregion
|
|
11
|
+
exports.labelsStep = require_value_labels.labelsStep;
|
|
12
|
+
exports.valueLabels = require_value_labels.valueLabels;
|
|
13
|
+
|
|
14
|
+
//# sourceMappingURL=value-labels.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"value-labels.cjs","names":["addPost","labelsStep"],"sources":["../src/value-labels.ts"],"sourcesContent":["/**\n * Standalone entry: `import '@tabler/charts/value-labels'` enables\n * `valueLabels` (values written on the marks) on the core.\n */\nimport { labelsStep, valueLabels } from './charts/value-labels.ts'\nimport { addPost } from './features.ts'\n\naddPost(labelsStep)\n\nexport type { ValueLabelOptions } from './charts/value-labels.ts'\nexport { labelsStep, valueLabels }\n"],"mappings":";;;;;;;;AAOAA,iBAAAA,QAAQC,qBAAAA,UAAU"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { t as addPost } from "./features-wASyHGic.js";
|
|
2
|
+
import { n as valueLabels, t as labelsStep } from "./value-labels-IZIQPhfk.js";
|
|
3
|
+
//#region src/value-labels.ts
|
|
4
|
+
/**
|
|
5
|
+
* Standalone entry: `import '@tabler/charts/value-labels'` enables
|
|
6
|
+
* `valueLabels` (values written on the marks) on the core.
|
|
7
|
+
*/
|
|
8
|
+
addPost(labelsStep);
|
|
9
|
+
//#endregion
|
|
10
|
+
export { labelsStep, valueLabels };
|
|
11
|
+
|
|
12
|
+
//# sourceMappingURL=value-labels.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"value-labels.js","names":[],"sources":["../src/value-labels.ts"],"sourcesContent":["/**\n * Standalone entry: `import '@tabler/charts/value-labels'` enables\n * `valueLabels` (values written on the marks) on the core.\n */\nimport { labelsStep, valueLabels } from './charts/value-labels.ts'\nimport { addPost } from './features.ts'\n\naddPost(labelsStep)\n\nexport type { ValueLabelOptions } from './charts/value-labels.ts'\nexport { labelsStep, valueLabels }\n"],"mappings":";;;;;;;AAOA,QAAQ,UAAU"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
//#region src/vnode.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Minimal virtual node tree shared by the string (SSR) and DOM renderers.
|
|
4
|
+
*
|
|
5
|
+
* VNodes are plain, serializable data: no event handlers, no component
|
|
6
|
+
* functions. Interaction is handled by event delegation on the root element,
|
|
7
|
+
* so the same tree can be rendered on the server, in a worker or in tests.
|
|
8
|
+
*/
|
|
9
|
+
/** Value accepted for a single attribute. `false`, `null`, `undefined` and non-finite numbers omit it. */
|
|
10
|
+
type AttrValue = string | number | boolean | null | undefined;
|
|
11
|
+
/** Normalized attributes stored on a {@link VNode}. */
|
|
12
|
+
type Attrs = Record<string, string | number>;
|
|
13
|
+
/** Identity used by the DOM renderer to match nodes between renders. */
|
|
14
|
+
type Key = string | number;
|
|
15
|
+
/** Class list: strings, falsy values (skipped) and nested arrays. */
|
|
16
|
+
type ClassValue = string | false | null | undefined | ClassValue[];
|
|
17
|
+
/** Inline styles: a raw string or a map of properties (custom properties included). */
|
|
18
|
+
type StyleValue = string | Record<string, string | number | null | undefined>;
|
|
19
|
+
/** Props accepted by {@link h}. */
|
|
20
|
+
interface Props {
|
|
21
|
+
[name: string]: AttrValue | ClassValue | StyleValue;
|
|
22
|
+
key?: Key | null | undefined;
|
|
23
|
+
class?: ClassValue;
|
|
24
|
+
style?: StyleValue | null | undefined;
|
|
25
|
+
}
|
|
26
|
+
/** A normalized child: an element node or a text node. */
|
|
27
|
+
type Child = VNode | string;
|
|
28
|
+
/** Anything that can be passed as a child to {@link h}; falsy values are skipped. */
|
|
29
|
+
type ChildInput = Child | number | boolean | null | undefined | ChildInput[];
|
|
30
|
+
interface VNode {
|
|
31
|
+
/** Element name, e.g. `svg`, `g`, `path`. */
|
|
32
|
+
tag: string;
|
|
33
|
+
/** Normalized attributes, without `key`. */
|
|
34
|
+
attrs: Attrs;
|
|
35
|
+
/** Flattened children with adjacent text merged. */
|
|
36
|
+
children: Child[];
|
|
37
|
+
/** Optional identity used by the keyed DOM patcher. */
|
|
38
|
+
key: Key | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* The arc a path draws (radii, angles, pad angle, corner radius), kept out
|
|
41
|
+
* of the markup: the DOM patcher sweeps from the arc of the last render to
|
|
42
|
+
* this one (see `sweep`).
|
|
43
|
+
*/
|
|
44
|
+
arc?: readonly number[];
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Create a virtual node.
|
|
48
|
+
*
|
|
49
|
+
* ```ts
|
|
50
|
+
* h('g', { class: ['tc-series', `tc-series-${i}`], key: series.id },
|
|
51
|
+
* h('path', { class: 'tc-line', d }),
|
|
52
|
+
* )
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
declare function h(tag: string, props?: Props | null, ...children: ChildInput[]): VNode;
|
|
56
|
+
/** Join a class value into a space separated string. */
|
|
57
|
+
declare function normalizeClass(value: ClassValue): string;
|
|
58
|
+
/**
|
|
59
|
+
* Serialize a style value into a CSS declaration list. In a map, values that
|
|
60
|
+
* could inject CSS (see {@link UNSAFE}) are left out, so use one for values
|
|
61
|
+
* from data; a raw string is taken as it is.
|
|
62
|
+
*/
|
|
63
|
+
declare function normalizeStyle(value: StyleValue | null | undefined): string;
|
|
64
|
+
//#endregion
|
|
65
|
+
export { ClassValue as a, StyleValue as c, normalizeClass as d, normalizeStyle as f, ChildInput as i, VNode as l, Attrs as n, Key as o, Child as r, Props as s, AttrValue as t, h as u };
|
|
66
|
+
//# sourceMappingURL=vnode-BUflsBsa.d.cts.map
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
//#region src/vnode.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Minimal virtual node tree shared by the string (SSR) and DOM renderers.
|
|
4
|
+
*
|
|
5
|
+
* VNodes are plain, serializable data: no event handlers, no component
|
|
6
|
+
* functions. Interaction is handled by event delegation on the root element,
|
|
7
|
+
* so the same tree can be rendered on the server, in a worker or in tests.
|
|
8
|
+
*/
|
|
9
|
+
/** Value accepted for a single attribute. `false`, `null`, `undefined` and non-finite numbers omit it. */
|
|
10
|
+
type AttrValue = string | number | boolean | null | undefined;
|
|
11
|
+
/** Normalized attributes stored on a {@link VNode}. */
|
|
12
|
+
type Attrs = Record<string, string | number>;
|
|
13
|
+
/** Identity used by the DOM renderer to match nodes between renders. */
|
|
14
|
+
type Key = string | number;
|
|
15
|
+
/** Class list: strings, falsy values (skipped) and nested arrays. */
|
|
16
|
+
type ClassValue = string | false | null | undefined | ClassValue[];
|
|
17
|
+
/** Inline styles: a raw string or a map of properties (custom properties included). */
|
|
18
|
+
type StyleValue = string | Record<string, string | number | null | undefined>;
|
|
19
|
+
/** Props accepted by {@link h}. */
|
|
20
|
+
interface Props {
|
|
21
|
+
[name: string]: AttrValue | ClassValue | StyleValue;
|
|
22
|
+
key?: Key | null | undefined;
|
|
23
|
+
class?: ClassValue;
|
|
24
|
+
style?: StyleValue | null | undefined;
|
|
25
|
+
}
|
|
26
|
+
/** A normalized child: an element node or a text node. */
|
|
27
|
+
type Child = VNode | string;
|
|
28
|
+
/** Anything that can be passed as a child to {@link h}; falsy values are skipped. */
|
|
29
|
+
type ChildInput = Child | number | boolean | null | undefined | ChildInput[];
|
|
30
|
+
interface VNode {
|
|
31
|
+
/** Element name, e.g. `svg`, `g`, `path`. */
|
|
32
|
+
tag: string;
|
|
33
|
+
/** Normalized attributes, without `key`. */
|
|
34
|
+
attrs: Attrs;
|
|
35
|
+
/** Flattened children with adjacent text merged. */
|
|
36
|
+
children: Child[];
|
|
37
|
+
/** Optional identity used by the keyed DOM patcher. */
|
|
38
|
+
key: Key | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* The arc a path draws (radii, angles, pad angle, corner radius), kept out
|
|
41
|
+
* of the markup: the DOM patcher sweeps from the arc of the last render to
|
|
42
|
+
* this one (see `sweep`).
|
|
43
|
+
*/
|
|
44
|
+
arc?: readonly number[];
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Create a virtual node.
|
|
48
|
+
*
|
|
49
|
+
* ```ts
|
|
50
|
+
* h('g', { class: ['tc-series', `tc-series-${i}`], key: series.id },
|
|
51
|
+
* h('path', { class: 'tc-line', d }),
|
|
52
|
+
* )
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
declare function h(tag: string, props?: Props | null, ...children: ChildInput[]): VNode;
|
|
56
|
+
/** Join a class value into a space separated string. */
|
|
57
|
+
declare function normalizeClass(value: ClassValue): string;
|
|
58
|
+
/**
|
|
59
|
+
* Serialize a style value into a CSS declaration list. In a map, values that
|
|
60
|
+
* could inject CSS (see {@link UNSAFE}) are left out, so use one for values
|
|
61
|
+
* from data; a raw string is taken as it is.
|
|
62
|
+
*/
|
|
63
|
+
declare function normalizeStyle(value: StyleValue | null | undefined): string;
|
|
64
|
+
//#endregion
|
|
65
|
+
export { ClassValue as a, StyleValue as c, normalizeClass as d, normalizeStyle as f, ChildInput as i, VNode as l, Attrs as n, Key as o, Child as r, Props as s, AttrValue as t, h as u };
|
|
66
|
+
//# sourceMappingURL=vnode-BUflsBsa.d.ts.map
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
//#region src/vnode.ts
|
|
2
|
+
/**
|
|
3
|
+
* Create a virtual node.
|
|
4
|
+
*
|
|
5
|
+
* ```ts
|
|
6
|
+
* h('g', { class: ['tc-series', `tc-series-${i}`], key: series.id },
|
|
7
|
+
* h('path', { class: 'tc-line', d }),
|
|
8
|
+
* )
|
|
9
|
+
* ```
|
|
10
|
+
*/
|
|
11
|
+
function h(tag, props, ...children) {
|
|
12
|
+
const attrs = {};
|
|
13
|
+
let key;
|
|
14
|
+
if (props) for (const name in props) {
|
|
15
|
+
const value = props[name];
|
|
16
|
+
if (name === "key") {
|
|
17
|
+
if (value != null) key = value;
|
|
18
|
+
} else if (name === "class") {
|
|
19
|
+
const cls = normalizeClass(value);
|
|
20
|
+
if (cls) attrs.class = cls;
|
|
21
|
+
} else if (name === "style") {
|
|
22
|
+
const style = normalizeStyle(value);
|
|
23
|
+
if (style) attrs.style = style;
|
|
24
|
+
} else if (value === true) attrs[name] = "";
|
|
25
|
+
else if (typeof value === "string") attrs[name] = value;
|
|
26
|
+
else if (typeof value === "number" && Number.isFinite(value)) attrs[name] = value;
|
|
27
|
+
}
|
|
28
|
+
const out = [];
|
|
29
|
+
flattenChildren(children, out);
|
|
30
|
+
return {
|
|
31
|
+
tag,
|
|
32
|
+
attrs,
|
|
33
|
+
children: out,
|
|
34
|
+
key
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/** Join a class value into a space separated string. */
|
|
38
|
+
function normalizeClass(value) {
|
|
39
|
+
if (!value) return "";
|
|
40
|
+
if (typeof value === "string") return value;
|
|
41
|
+
let result = "";
|
|
42
|
+
for (const item of value) {
|
|
43
|
+
const cls = normalizeClass(item);
|
|
44
|
+
if (cls) result = result ? `${result} ${cls}` : cls;
|
|
45
|
+
}
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Values that could leave their declaration (`;`, braces, quotes, escapes,
|
|
50
|
+
* comments) or load something (`url()` and friends). Colors and dashes often
|
|
51
|
+
* come from user data, and `red;position:fixed` would restyle the chart's
|
|
52
|
+
* elements, `url(…)` would make the browser request it. A reference to an
|
|
53
|
+
* element of the page, `url(#id)` (pattern fills), loads nothing and passes.
|
|
54
|
+
*/
|
|
55
|
+
const UNSAFE = /[;{}<>"'\\]|\/\*|\b(?:url(?!\(#[\w-]+\))|src|attr|image|image-set|cross-fade|element|expression)\s*\(/i;
|
|
56
|
+
/**
|
|
57
|
+
* Serialize a style value into a CSS declaration list. In a map, values that
|
|
58
|
+
* could inject CSS (see {@link UNSAFE}) are left out, so use one for values
|
|
59
|
+
* from data; a raw string is taken as it is.
|
|
60
|
+
*/
|
|
61
|
+
function normalizeStyle(value) {
|
|
62
|
+
if (!value) return "";
|
|
63
|
+
if (typeof value === "string") return value;
|
|
64
|
+
let result = "";
|
|
65
|
+
for (const prop in value) {
|
|
66
|
+
const v = value[prop];
|
|
67
|
+
if (v == null || v === "" || UNSAFE.test(String(v))) continue;
|
|
68
|
+
result += `${result ? ";" : ""}${prop}:${v}`;
|
|
69
|
+
}
|
|
70
|
+
return result;
|
|
71
|
+
}
|
|
72
|
+
function flattenChildren(input, out) {
|
|
73
|
+
for (const child of input) {
|
|
74
|
+
if (child == null || typeof child === "boolean") continue;
|
|
75
|
+
if (Array.isArray(child)) {
|
|
76
|
+
flattenChildren(child, out);
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
if (typeof child === "object") {
|
|
80
|
+
out.push(child);
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
const text = String(child);
|
|
84
|
+
if (text === "") continue;
|
|
85
|
+
const last = out.length - 1;
|
|
86
|
+
if (last >= 0 && typeof out[last] === "string") out[last] += text;
|
|
87
|
+
else out.push(text);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
//#endregion
|
|
91
|
+
Object.defineProperty(exports, "h", {
|
|
92
|
+
enumerable: true,
|
|
93
|
+
get: function() {
|
|
94
|
+
return h;
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
Object.defineProperty(exports, "normalizeClass", {
|
|
98
|
+
enumerable: true,
|
|
99
|
+
get: function() {
|
|
100
|
+
return normalizeClass;
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
Object.defineProperty(exports, "normalizeStyle", {
|
|
104
|
+
enumerable: true,
|
|
105
|
+
get: function() {
|
|
106
|
+
return normalizeStyle;
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
//# sourceMappingURL=vnode-CkQ27Cxe.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vnode-CkQ27Cxe.cjs","names":[],"sources":["../src/vnode.ts"],"sourcesContent":["/**\n * Minimal virtual node tree shared by the string (SSR) and DOM renderers.\n *\n * VNodes are plain, serializable data: no event handlers, no component\n * functions. Interaction is handled by event delegation on the root element,\n * so the same tree can be rendered on the server, in a worker or in tests.\n */\n\n/** Value accepted for a single attribute. `false`, `null`, `undefined` and non-finite numbers omit it. */\nexport type AttrValue = string | number | boolean | null | undefined\n\n/** Normalized attributes stored on a {@link VNode}. */\nexport type Attrs = Record<string, string | number>\n\n/** Identity used by the DOM renderer to match nodes between renders. */\nexport type Key = string | number\n\n/** Class list: strings, falsy values (skipped) and nested arrays. */\nexport type ClassValue = string | false | null | undefined | ClassValue[]\n\n/** Inline styles: a raw string or a map of properties (custom properties included). */\nexport type StyleValue = string | Record<string, string | number | null | undefined>\n\n/** Props accepted by {@link h}. */\nexport interface Props {\n [name: string]: AttrValue | ClassValue | StyleValue\n key?: Key | null | undefined\n class?: ClassValue\n style?: StyleValue | null | undefined\n}\n\n/** A normalized child: an element node or a text node. */\nexport type Child = VNode | string\n\n/** Anything that can be passed as a child to {@link h}; falsy values are skipped. */\nexport type ChildInput = Child | number | boolean | null | undefined | ChildInput[]\n\nexport interface VNode {\n /** Element name, e.g. `svg`, `g`, `path`. */\n tag: string\n /** Normalized attributes, without `key`. */\n attrs: Attrs\n /** Flattened children with adjacent text merged. */\n children: Child[]\n /** Optional identity used by the keyed DOM patcher. */\n key: Key | undefined\n /**\n * The arc a path draws (radii, angles, pad angle, corner radius), kept out\n * of the markup: the DOM patcher sweeps from the arc of the last render to\n * this one (see `sweep`).\n */\n arc?: readonly number[]\n}\n\n/**\n * Create a virtual node.\n *\n * ```ts\n * h('g', { class: ['tc-series', `tc-series-${i}`], key: series.id },\n * h('path', { class: 'tc-line', d }),\n * )\n * ```\n */\nexport function h(tag: string, props?: Props | null, ...children: ChildInput[]): VNode {\n const attrs: Attrs = {}\n let key: Key | undefined\n\n if (props) {\n for (const name in props) {\n const value = props[name]\n if (name === 'key') {\n if (value != null) key = value as Key\n } else if (name === 'class') {\n const cls = normalizeClass(value as ClassValue)\n if (cls) attrs.class = cls\n } else if (name === 'style') {\n const style = normalizeStyle(value as StyleValue | null | undefined)\n if (style) attrs.style = style\n } else if (value === true) {\n attrs[name] = ''\n } else if (typeof value === 'string') {\n attrs[name] = value\n } else if (typeof value === 'number' && Number.isFinite(value)) {\n attrs[name] = value\n }\n }\n }\n\n const out: Child[] = []\n flattenChildren(children, out)\n\n return { tag, attrs, children: out, key }\n}\n\n/** Join a class value into a space separated string. */\nexport function normalizeClass(value: ClassValue): string {\n if (!value) return ''\n if (typeof value === 'string') return value\n let result = ''\n for (const item of value) {\n const cls = normalizeClass(item)\n if (cls) result = result ? `${result} ${cls}` : cls\n }\n return result\n}\n\n/**\n * Values that could leave their declaration (`;`, braces, quotes, escapes,\n * comments) or load something (`url()` and friends). Colors and dashes often\n * come from user data, and `red;position:fixed` would restyle the chart's\n * elements, `url(…)` would make the browser request it. A reference to an\n * element of the page, `url(#id)` (pattern fills), loads nothing and passes.\n */\nconst UNSAFE =\n /[;{}<>\"'\\\\]|\\/\\*|\\b(?:url(?!\\(#[\\w-]+\\))|src|attr|image|image-set|cross-fade|element|expression)\\s*\\(/i\n\n/**\n * Serialize a style value into a CSS declaration list. In a map, values that\n * could inject CSS (see {@link UNSAFE}) are left out, so use one for values\n * from data; a raw string is taken as it is.\n */\nexport function normalizeStyle(value: StyleValue | null | undefined): string {\n if (!value) return ''\n if (typeof value === 'string') return value\n let result = ''\n for (const prop in value) {\n const v = value[prop]\n if (v == null || v === '' || UNSAFE.test(String(v))) continue\n result += `${result ? ';' : ''}${prop}:${v}`\n }\n return result\n}\n\nfunction flattenChildren(input: ChildInput[], out: Child[]): void {\n for (const child of input) {\n if (child == null || typeof child === 'boolean') continue\n if (Array.isArray(child)) {\n flattenChildren(child, out)\n continue\n }\n if (typeof child === 'object') {\n out.push(child)\n continue\n }\n const text = String(child)\n if (text === '') continue\n const last = out.length - 1\n if (last >= 0 && typeof out[last] === 'string') {\n out[last] += text\n } else {\n out.push(text)\n }\n }\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