@tabler/charts 0.0.0-stage → 0.0.1-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +248 -2
- package/dist/annotations-Bp7HwtF5.d.ts +86 -0
- package/dist/annotations-BszTTjf9.js +202 -0
- package/dist/annotations-BszTTjf9.js.map +1 -0
- package/dist/annotations-DpETO8dE.cjs +213 -0
- package/dist/annotations-DpETO8dE.cjs.map +1 -0
- package/dist/annotations-lyt0I3HU.d.cts +86 -0
- package/dist/annotations.cjs +14 -0
- package/dist/annotations.cjs.map +1 -0
- package/dist/annotations.d.cts +2 -0
- package/dist/annotations.d.ts +2 -0
- package/dist/annotations.js +12 -0
- package/dist/annotations.js.map +1 -0
- package/dist/area-BFvkc-ZM.d.cts +20 -0
- package/dist/area-DQsLERhx.js +26 -0
- package/dist/area-DQsLERhx.js.map +1 -0
- package/dist/area-DaO4MQl4.d.ts +20 -0
- package/dist/area-sHCE3pg5.cjs +31 -0
- package/dist/area-sHCE3pg5.cjs.map +1 -0
- package/dist/area.cjs +3 -0
- package/dist/area.d.cts +2 -0
- package/dist/area.d.ts +2 -0
- package/dist/area.js +2 -0
- package/dist/band-DTcNDAFO.d.cts +50 -0
- package/dist/band-DTcNDAFO.d.ts +50 -0
- package/dist/bar-C-7zR2qp.cjs +243 -0
- package/dist/bar-C-7zR2qp.cjs.map +1 -0
- package/dist/bar-DGuUN3nc.cjs +67 -0
- package/dist/bar-DGuUN3nc.cjs.map +1 -0
- package/dist/bar-DM16NUvV.js +56 -0
- package/dist/bar-DM16NUvV.js.map +1 -0
- package/dist/bar-DdsDxk3W.d.ts +43 -0
- package/dist/bar-a0h9KC8A.d.cts +43 -0
- package/dist/bar-jZEoao74.js +238 -0
- package/dist/bar-jZEoao74.js.map +1 -0
- package/dist/bar.cjs +3 -0
- package/dist/bar.d.cts +2 -0
- package/dist/bar.d.ts +2 -0
- package/dist/bar.js +2 -0
- package/dist/candlestick-B5r1w3kc.cjs +150 -0
- package/dist/candlestick-B5r1w3kc.cjs.map +1 -0
- package/dist/candlestick-BKdPyorY.d.cts +44 -0
- package/dist/candlestick-BnUG1SGi.d.ts +44 -0
- package/dist/candlestick-DuXwAFID.js +145 -0
- package/dist/candlestick-DuXwAFID.js.map +1 -0
- package/dist/candlestick.cjs +11 -0
- package/dist/candlestick.cjs.map +1 -0
- package/dist/candlestick.d.cts +2 -0
- package/dist/candlestick.d.ts +2 -0
- package/dist/candlestick.js +10 -0
- package/dist/candlestick.js.map +1 -0
- package/dist/cartesian-BoDfgBCV.cjs +900 -0
- package/dist/cartesian-BoDfgBCV.cjs.map +1 -0
- package/dist/cartesian-Cr0AF0nG.js +709 -0
- package/dist/cartesian-Cr0AF0nG.js.map +1 -0
- package/dist/chart-BF2CK9I_.js +790 -0
- package/dist/chart-BF2CK9I_.js.map +1 -0
- package/dist/chart-CowF_lWY.cjs +903 -0
- package/dist/chart-CowF_lWY.cjs.map +1 -0
- package/dist/chart-Qa417fJo.d.cts +927 -0
- package/dist/chart-iJGxMz9z.d.ts +927 -0
- package/dist/circle-BQMuAfls.cjs +12 -0
- package/dist/circle-BQMuAfls.cjs.map +1 -0
- package/dist/circle-Z7YfCoCM.js +7 -0
- package/dist/circle-Z7YfCoCM.js.map +1 -0
- package/dist/clean-Byl6kzf0.cjs +115 -0
- package/dist/clean-Byl6kzf0.cjs.map +1 -0
- package/dist/clean-o1vDEhFV.js +56 -0
- package/dist/clean-o1vDEhFV.js.map +1 -0
- package/dist/core-C7fPm6t7.cjs +976 -0
- package/dist/core-C7fPm6t7.cjs.map +1 -0
- package/dist/core-CjgbhS_v.d.ts +219 -0
- package/dist/core-CnGFKojH.d.cts +219 -0
- package/dist/core-plobgBC7.js +875 -0
- package/dist/core-plobgBC7.js.map +1 -0
- package/dist/core.cjs +113 -0
- package/dist/core.d.cts +20 -0
- package/dist/core.d.ts +20 -0
- package/dist/core.js +24 -0
- package/dist/dates-Btm7Zm6W.cjs +32 -0
- package/dist/dates-Btm7Zm6W.cjs.map +1 -0
- package/dist/dates-CG-FvioW.js +27 -0
- package/dist/dates-CG-FvioW.js.map +1 -0
- package/dist/decimate-BGg9XgF0.d.ts +17 -0
- package/dist/decimate-C87cl_Sp.js +84 -0
- package/dist/decimate-C87cl_Sp.js.map +1 -0
- package/dist/decimate-CNSpgGa5.d.cts +17 -0
- package/dist/decimate-tLhDk1ys.cjs +95 -0
- package/dist/decimate-tLhDk1ys.cjs.map +1 -0
- package/dist/decimate.cjs +14 -0
- package/dist/decimate.cjs.map +1 -0
- package/dist/decimate.d.cts +2 -0
- package/dist/decimate.d.ts +2 -0
- package/dist/decimate.js +12 -0
- package/dist/decimate.js.map +1 -0
- package/dist/dom-CLF868Qs.cjs +222 -0
- package/dist/dom-CLF868Qs.cjs.map +1 -0
- package/dist/dom-vP3IcMak.js +175 -0
- package/dist/dom-vP3IcMak.js.map +1 -0
- package/dist/export-chart-9w8t3rjZ.js +232 -0
- package/dist/export-chart-9w8t3rjZ.js.map +1 -0
- package/dist/export-chart-BhhYgksr.cjs +249 -0
- package/dist/export-chart-BhhYgksr.cjs.map +1 -0
- package/dist/export.cjs +18 -0
- package/dist/export.cjs.map +1 -0
- package/dist/export.d.cts +2 -0
- package/dist/export.d.ts +2 -0
- package/dist/export.js +15 -0
- package/dist/export.js.map +1 -0
- package/dist/extent-BAMZo0Nq.js +19 -0
- package/dist/extent-BAMZo0Nq.js.map +1 -0
- package/dist/extent-DsFWvAHJ.cjs +24 -0
- package/dist/extent-DsFWvAHJ.cjs.map +1 -0
- package/dist/fade-Cs74puQS.cjs +217 -0
- package/dist/fade-Cs74puQS.cjs.map +1 -0
- package/dist/fade-D3NxH5Qg.js +200 -0
- package/dist/fade-D3NxH5Qg.js.map +1 -0
- package/dist/features-BclHgg2W.cjs +48 -0
- package/dist/features-BclHgg2W.cjs.map +1 -0
- package/dist/features-wASyHGic.js +25 -0
- package/dist/features-wASyHGic.js.map +1 -0
- package/dist/format-B0yKXBTH.cjs +183 -0
- package/dist/format-B0yKXBTH.cjs.map +1 -0
- package/dist/format-lStwuc1L.js +142 -0
- package/dist/format-lStwuc1L.js.map +1 -0
- package/dist/gauge-CEfkWXSu.cjs +235 -0
- package/dist/gauge-CEfkWXSu.cjs.map +1 -0
- package/dist/gauge-Cu9jttC0.d.ts +65 -0
- package/dist/gauge-Cu_OFxBd.d.cts +65 -0
- package/dist/gauge-_ljQHrMN.js +230 -0
- package/dist/gauge-_ljQHrMN.js.map +1 -0
- package/dist/gauge.cjs +3 -0
- package/dist/gauge.d.cts +2 -0
- package/dist/gauge.d.ts +2 -0
- package/dist/gauge.js +2 -0
- package/dist/heatmap-BK18EBgJ.cjs +247 -0
- package/dist/heatmap-BK18EBgJ.cjs.map +1 -0
- package/dist/heatmap-BwS-y0c6.d.cts +81 -0
- package/dist/heatmap-DSZ2bVIa.js +242 -0
- package/dist/heatmap-DSZ2bVIa.js.map +1 -0
- package/dist/heatmap-PhLPXIg1.d.ts +81 -0
- package/dist/heatmap.cjs +3 -0
- package/dist/heatmap.d.cts +2 -0
- package/dist/heatmap.d.ts +2 -0
- package/dist/heatmap.js +2 -0
- package/dist/hydrate-CTTmQy0x.d.cts +10 -0
- package/dist/hydrate-CxwTXDqO.cjs +60 -0
- package/dist/hydrate-CxwTXDqO.cjs.map +1 -0
- package/dist/hydrate-CzfxLfTv.d.ts +10 -0
- package/dist/hydrate-DDNIHYv_.js +55 -0
- package/dist/hydrate-DDNIHYv_.js.map +1 -0
- package/dist/hydrate.cjs +13 -0
- package/dist/hydrate.cjs.map +1 -0
- package/dist/hydrate.d.cts +2 -0
- package/dist/hydrate.d.ts +2 -0
- package/dist/hydrate.js +12 -0
- package/dist/hydrate.js.map +1 -0
- package/dist/index.cjs +211 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +45 -0
- package/dist/index.d.ts +45 -0
- package/dist/index.js +113 -0
- package/dist/index.js.map +1 -0
- package/dist/layout-B3hiqVEw.js +69 -0
- package/dist/layout-B3hiqVEw.js.map +1 -0
- package/dist/layout-CtMBhNd9.cjs +98 -0
- package/dist/layout-CtMBhNd9.cjs.map +1 -0
- package/dist/line-B3Ed6u7j.js +120 -0
- package/dist/line-B3Ed6u7j.js.map +1 -0
- package/dist/line-CMDGH6q5.d.cts +47 -0
- package/dist/line-D5kb8e6w.d.ts +47 -0
- package/dist/line-fQbtP_jL.cjs +131 -0
- package/dist/line-fQbtP_jL.cjs.map +1 -0
- package/dist/line.cjs +14 -0
- package/dist/line.cjs.map +1 -0
- package/dist/line.d.cts +2 -0
- package/dist/line.d.ts +2 -0
- package/dist/line.js +13 -0
- package/dist/line.js.map +1 -0
- package/dist/log-CaofN3-n.d.cts +48 -0
- package/dist/log-CaofN3-n.d.ts +48 -0
- package/dist/log-axis-83rSpvL5.cjs +130 -0
- package/dist/log-axis-83rSpvL5.cjs.map +1 -0
- package/dist/log-axis-B_uvvOFc.js +113 -0
- package/dist/log-axis-B_uvvOFc.js.map +1 -0
- package/dist/log.cjs +17 -0
- package/dist/log.cjs.map +1 -0
- package/dist/log.d.cts +2 -0
- package/dist/log.d.ts +2 -0
- package/dist/log.js +16 -0
- package/dist/log.js.map +1 -0
- package/dist/morph-BMxz3X2b.d.cts +10 -0
- package/dist/morph-BMxz3X2b.d.ts +10 -0
- package/dist/morph-Bgg-24l8.js +36 -0
- package/dist/morph-Bgg-24l8.js.map +1 -0
- package/dist/morph-CqYDu1bY.cjs +41 -0
- package/dist/morph-CqYDu1bY.cjs.map +1 -0
- package/dist/morph.cjs +14 -0
- package/dist/morph.cjs.map +1 -0
- package/dist/morph.d.cts +2 -0
- package/dist/morph.d.ts +2 -0
- package/dist/morph.js +13 -0
- package/dist/morph.js.map +1 -0
- package/dist/named-BWWb5LQJ.cjs +50 -0
- package/dist/named-BWWb5LQJ.cjs.map +1 -0
- package/dist/named-DE15TOgh.js +33 -0
- package/dist/named-DE15TOgh.js.map +1 -0
- package/dist/path-CwB28da0.d.cts +29 -0
- package/dist/path-CwB28da0.d.ts +29 -0
- package/dist/patterns-DtgcnA8o.js +85 -0
- package/dist/patterns-DtgcnA8o.js.map +1 -0
- package/dist/patterns-LfcQAWCy.cjs +102 -0
- package/dist/patterns-LfcQAWCy.cjs.map +1 -0
- package/dist/patterns.cjs +15 -0
- package/dist/patterns.cjs.map +1 -0
- package/dist/patterns.d.cts +2 -0
- package/dist/patterns.d.ts +2 -0
- package/dist/patterns.js +12 -0
- package/dist/patterns.js.map +1 -0
- package/dist/pie-B8UlOZiq.d.ts +58 -0
- package/dist/pie-C1Pa6W_l.cjs +211 -0
- package/dist/pie-C1Pa6W_l.cjs.map +1 -0
- package/dist/pie-DnQQmxkk.d.cts +58 -0
- package/dist/pie-RnMTQWMS.js +200 -0
- package/dist/pie-RnMTQWMS.js.map +1 -0
- package/dist/pie.cjs +4 -0
- package/dist/pie.d.cts +2 -0
- package/dist/pie.d.ts +2 -0
- package/dist/pie.js +2 -0
- package/dist/point-shapes-CGl4dugc.cjs +166 -0
- package/dist/point-shapes-CGl4dugc.cjs.map +1 -0
- package/dist/point-shapes-DI84NNpI.js +155 -0
- package/dist/point-shapes-DI84NNpI.js.map +1 -0
- package/dist/point-shapes.cjs +15 -0
- package/dist/point-shapes.cjs.map +1 -0
- package/dist/point-shapes.d.cts +2 -0
- package/dist/point-shapes.d.ts +2 -0
- package/dist/point-shapes.js +13 -0
- package/dist/point-shapes.js.map +1 -0
- package/dist/radar-BB13CGmq.d.cts +60 -0
- package/dist/radar-CYPab_I4.js +285 -0
- package/dist/radar-CYPab_I4.js.map +1 -0
- package/dist/radar-CoGUNNSb.cjs +290 -0
- package/dist/radar-CoGUNNSb.cjs.map +1 -0
- package/dist/radar-pFI6fvOq.d.ts +60 -0
- package/dist/radar.cjs +3 -0
- package/dist/radar.d.cts +2 -0
- package/dist/radar.d.ts +2 -0
- package/dist/radar.js +2 -0
- package/dist/sankey-B4PNKusJ.js +420 -0
- package/dist/sankey-B4PNKusJ.js.map +1 -0
- package/dist/sankey-B9JYnx7e.d.cts +67 -0
- package/dist/sankey-Bacx4fVe.cjs +425 -0
- package/dist/sankey-Bacx4fVe.cjs.map +1 -0
- package/dist/sankey-Bm518bqL.d.ts +67 -0
- package/dist/sankey.cjs +3 -0
- package/dist/sankey.d.cts +2 -0
- package/dist/sankey.d.ts +2 -0
- package/dist/sankey.js +2 -0
- package/dist/scatter-Bl7nasE6.d.ts +61 -0
- package/dist/scatter-DgMN9zRy.cjs +250 -0
- package/dist/scatter-DgMN9zRy.cjs.map +1 -0
- package/dist/scatter-DrJ8xYz4.d.cts +61 -0
- package/dist/scatter-kgtgR318.js +245 -0
- package/dist/scatter-kgtgR318.js.map +1 -0
- package/dist/scatter.cjs +3 -0
- package/dist/scatter.d.cts +2 -0
- package/dist/scatter.d.ts +2 -0
- package/dist/scatter.js +2 -0
- package/dist/sparkline-BG13V4Pz.d.cts +43 -0
- package/dist/sparkline-BQzt27Fr.js +171 -0
- package/dist/sparkline-BQzt27Fr.js.map +1 -0
- package/dist/sparkline-BS9-hltA.cjs +176 -0
- package/dist/sparkline-BS9-hltA.cjs.map +1 -0
- package/dist/sparkline-iWuXbKpd.d.ts +43 -0
- package/dist/sparkline.cjs +3 -0
- package/dist/sparkline.d.cts +2 -0
- package/dist/sparkline.d.ts +2 -0
- package/dist/sparkline.js +2 -0
- package/dist/stack-CpR6RGKd.d.cts +6 -0
- package/dist/stack-CpR6RGKd.d.ts +6 -0
- package/dist/stack-DRbwTeF3.js +66 -0
- package/dist/stack-DRbwTeF3.js.map +1 -0
- package/dist/stack-DVhJWaki.cjs +77 -0
- package/dist/stack-DVhJWaki.cjs.map +1 -0
- package/dist/style.css +2 -0
- package/dist/sweep-Duowaput.cjs +369 -0
- package/dist/sweep-Duowaput.cjs.map +1 -0
- package/dist/sweep-WSgn2etB.js +334 -0
- package/dist/sweep-WSgn2etB.js.map +1 -0
- package/dist/time-CHjiY9Q4.d.ts +112 -0
- package/dist/time-CNVnt-B2.d.cts +112 -0
- package/dist/time-axis-Bc9eHX1r.js +365 -0
- package/dist/time-axis-Bc9eHX1r.js.map +1 -0
- package/dist/time-axis-VSX34_Tb.cjs +382 -0
- package/dist/time-axis-VSX34_Tb.cjs.map +1 -0
- package/dist/time.cjs +22 -0
- package/dist/time.cjs.map +1 -0
- package/dist/time.d.cts +2 -0
- package/dist/time.d.ts +2 -0
- package/dist/time.js +20 -0
- package/dist/time.js.map +1 -0
- package/dist/tween-BCYd0RTY.js +40 -0
- package/dist/tween-BCYd0RTY.js.map +1 -0
- package/dist/tween-CIGBlryn.cjs +51 -0
- package/dist/tween-CIGBlryn.cjs.map +1 -0
- package/dist/value-labels-B0WJoJ7x.cjs +134 -0
- package/dist/value-labels-B0WJoJ7x.cjs.map +1 -0
- package/dist/value-labels-IZIQPhfk.js +123 -0
- package/dist/value-labels-IZIQPhfk.js.map +1 -0
- package/dist/value-labels.cjs +14 -0
- package/dist/value-labels.cjs.map +1 -0
- package/dist/value-labels.d.cts +2 -0
- package/dist/value-labels.d.ts +2 -0
- package/dist/value-labels.js +12 -0
- package/dist/value-labels.js.map +1 -0
- package/dist/vnode-BUflsBsa.d.cts +66 -0
- package/dist/vnode-BUflsBsa.d.ts +66 -0
- package/dist/vnode-CkQ27Cxe.cjs +110 -0
- package/dist/vnode-CkQ27Cxe.cjs.map +1 -0
- package/dist/vnode-tCWItoUH.js +93 -0
- package/dist/vnode-tCWItoUH.js.map +1 -0
- package/package.json +310 -3
|
@@ -0,0 +1,420 @@
|
|
|
1
|
+
import { a as round, i as insets, n as estimateTextWidth, r as innerRect, t as LINE_HEIGHT } from "./layout-B3hiqVEw.js";
|
|
2
|
+
import { t as h } from "./vnode-tCWItoUH.js";
|
|
3
|
+
import { n as formatDetail } from "./format-lStwuc1L.js";
|
|
4
|
+
import { a as isRecord, i as finite, l as records, s as named, t as cleanData, u as text } from "./clean-o1vDEhFV.js";
|
|
5
|
+
//#region src/charts/sankey.ts
|
|
6
|
+
/** Space between a node and its label. */
|
|
7
|
+
const LABEL_GAP = 8;
|
|
8
|
+
/** Largest share of the width one side's labels may take. */
|
|
9
|
+
const MAX_LABEL_SHARE = .3;
|
|
10
|
+
/** Pixels around a node that still count as hovering it. */
|
|
11
|
+
const HOVER_SLOP = 2;
|
|
12
|
+
/** `text`, cut short with an ellipsis to fit `width` pixels. */
|
|
13
|
+
function truncate(text, width, fontSize) {
|
|
14
|
+
if (estimateTextWidth(text, fontSize) <= width) return text;
|
|
15
|
+
let end = text.length;
|
|
16
|
+
while (end > 0 && estimateTextWidth(`${text.slice(0, end)}…`, fontSize) > width) end--;
|
|
17
|
+
return end > 0 ? `${text.slice(0, end).trimEnd()}…` : "";
|
|
18
|
+
}
|
|
19
|
+
/** The color of a node for hover and tooltip swatches. */
|
|
20
|
+
const colorOf = (node) => node.data.color ?? `var(--tc-color-${node.slot})`;
|
|
21
|
+
/** The visible nodes and links, in data order, with their columns. */
|
|
22
|
+
function graph(data, hidden, justify) {
|
|
23
|
+
const byName = /* @__PURE__ */ new Map();
|
|
24
|
+
const nodes = [];
|
|
25
|
+
const node = (name, data) => {
|
|
26
|
+
let found = byName.get(name);
|
|
27
|
+
if (!found) {
|
|
28
|
+
found = {
|
|
29
|
+
data: data ?? { name },
|
|
30
|
+
index: nodes.length,
|
|
31
|
+
slot: 1,
|
|
32
|
+
column: 0,
|
|
33
|
+
value: 0,
|
|
34
|
+
x: 0,
|
|
35
|
+
y: 0,
|
|
36
|
+
height: 0,
|
|
37
|
+
ins: [],
|
|
38
|
+
outs: []
|
|
39
|
+
};
|
|
40
|
+
byName.set(name, found);
|
|
41
|
+
nodes.push(found);
|
|
42
|
+
}
|
|
43
|
+
return found;
|
|
44
|
+
};
|
|
45
|
+
const declared = new Map((data.nodes ?? []).map((n) => [n.name, n]));
|
|
46
|
+
/** A legend key hides every node of its color, see `sankeyLegend`. */
|
|
47
|
+
const isHidden = (name) => {
|
|
48
|
+
const n = declared.get(name);
|
|
49
|
+
return hidden.has(name) || n?.color !== void 0 && hidden.has(legendKey(data, n.color));
|
|
50
|
+
};
|
|
51
|
+
const links = [];
|
|
52
|
+
data.links.forEach((link, index) => {
|
|
53
|
+
if (link.from === link.to || isHidden(link.from) || isHidden(link.to)) return;
|
|
54
|
+
const source = node(link.from, declared.get(link.from));
|
|
55
|
+
const target = node(link.to, declared.get(link.to));
|
|
56
|
+
const out = {
|
|
57
|
+
data: link,
|
|
58
|
+
index,
|
|
59
|
+
source,
|
|
60
|
+
target,
|
|
61
|
+
sy: 0,
|
|
62
|
+
ty: 0,
|
|
63
|
+
width: 0
|
|
64
|
+
};
|
|
65
|
+
links.push(out);
|
|
66
|
+
if (link.value <= 0) return;
|
|
67
|
+
source.outs.push(out);
|
|
68
|
+
target.ins.push(out);
|
|
69
|
+
});
|
|
70
|
+
for (const n of nodes) n.value = Math.max(n.outs.reduce((sum, l) => sum + l.data.value, 0), n.ins.reduce((sum, l) => sum + l.data.value, 0));
|
|
71
|
+
for (let pass = 0; pass < nodes.length; pass++) {
|
|
72
|
+
let changed = false;
|
|
73
|
+
for (const link of links) if (link.data.value > 0 && link.target.column <= link.source.column) {
|
|
74
|
+
link.target.column = link.source.column + 1;
|
|
75
|
+
changed = true;
|
|
76
|
+
}
|
|
77
|
+
if (!changed) break;
|
|
78
|
+
}
|
|
79
|
+
const last = nodes.reduce((max, n) => Math.max(max, n.column), 0);
|
|
80
|
+
if (justify) {
|
|
81
|
+
for (const n of nodes) if (n.outs.length === 0) n.column = last;
|
|
82
|
+
}
|
|
83
|
+
const order = [...declared.keys()];
|
|
84
|
+
nodes.sort((a, b) => {
|
|
85
|
+
if (a.column !== b.column) return a.column - b.column;
|
|
86
|
+
const ia = order.indexOf(a.data.name);
|
|
87
|
+
const ib = order.indexOf(b.data.name);
|
|
88
|
+
if (ia !== -1 && ib !== -1) return ia - ib;
|
|
89
|
+
if (ia !== ib) return ia === -1 ? 1 : -1;
|
|
90
|
+
return a.index - b.index;
|
|
91
|
+
});
|
|
92
|
+
const slots = /* @__PURE__ */ new Map();
|
|
93
|
+
nodes.forEach((n, index) => {
|
|
94
|
+
n.index = index;
|
|
95
|
+
const slot = (slots.get(n.column) ?? 0) + 1;
|
|
96
|
+
slots.set(n.column, slot);
|
|
97
|
+
n.slot = (slot - 1) % 8 + 1;
|
|
98
|
+
});
|
|
99
|
+
return {
|
|
100
|
+
nodes,
|
|
101
|
+
links,
|
|
102
|
+
columns: last + 1
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
/** Key of the legend entry of `color`: the first node that wears it. */
|
|
106
|
+
const legendKey = (data, color) => (data.nodes ?? []).find((n) => n.color === color)?.name ?? color;
|
|
107
|
+
function layout(options, ctx) {
|
|
108
|
+
const { width, height, fontSize, locale } = ctx;
|
|
109
|
+
const nodeWidth = Math.max(1, options.nodeWidth ?? 12);
|
|
110
|
+
const nodePadding = Math.max(0, options.nodePadding ?? 16);
|
|
111
|
+
const area = innerRect(width, height, insets(options.padding));
|
|
112
|
+
const { nodes, links, columns } = graph(options.data, ctx.hidden, options.align !== "left");
|
|
113
|
+
const format = formatDetail(options.format, locale);
|
|
114
|
+
const texts = nodes.map((n) => [n.data.name, format(n.value)]);
|
|
115
|
+
const widest = (match) => nodes.reduce((max, n, i) => {
|
|
116
|
+
if (!match(n)) return max;
|
|
117
|
+
const [name, value] = texts[i];
|
|
118
|
+
return Math.max(max, estimateTextWidth(name, fontSize), estimateTextWidth(value, fontSize));
|
|
119
|
+
}, 0);
|
|
120
|
+
const cap = area.width * MAX_LABEL_SHARE;
|
|
121
|
+
const left = columns > 1 ? Math.min(cap, widest((n) => n.column === 0)) : 0;
|
|
122
|
+
const right = Math.min(cap, widest((n) => n.column === columns - 1));
|
|
123
|
+
const plot = {
|
|
124
|
+
x: area.x + (left ? left + LABEL_GAP : 0),
|
|
125
|
+
y: area.y,
|
|
126
|
+
width: Math.max(0, area.width - (left ? left + LABEL_GAP : 0) - (right ? right + LABEL_GAP : 0)),
|
|
127
|
+
height: area.height
|
|
128
|
+
};
|
|
129
|
+
const step = columns > 1 ? (plot.width - nodeWidth) / (columns - 1) : 0;
|
|
130
|
+
const byColumn = Array.from({ length: columns }, () => []);
|
|
131
|
+
for (const n of nodes) byColumn[n.column]?.push(n);
|
|
132
|
+
const pad = byColumn.reduce((min, col) => col.length > 1 ? Math.min(min, plot.height / 2 / (col.length - 1)) : min, nodePadding);
|
|
133
|
+
let k = Number.POSITIVE_INFINITY;
|
|
134
|
+
for (const col of byColumn) {
|
|
135
|
+
const sum = col.reduce((s, n) => s + n.value, 0);
|
|
136
|
+
if (sum > 0) k = Math.min(k, (plot.height - (col.length - 1) * pad) / sum);
|
|
137
|
+
}
|
|
138
|
+
if (!Number.isFinite(k) || k < 0) k = 0;
|
|
139
|
+
byColumn.forEach((col, c) => {
|
|
140
|
+
const total = col.reduce((s, n) => s + n.value * k, 0) + (col.length - 1) * pad;
|
|
141
|
+
let y = plot.y + (plot.height - total) / 2;
|
|
142
|
+
for (const n of col) {
|
|
143
|
+
n.x = plot.x + (columns > 1 ? c * step : (plot.width - nodeWidth) / 2);
|
|
144
|
+
n.y = y;
|
|
145
|
+
n.height = n.value * k;
|
|
146
|
+
y += n.height + pad;
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
for (const n of nodes) {
|
|
150
|
+
let y = n.y;
|
|
151
|
+
for (const link of [...n.outs].sort((a, b) => a.target.y - b.target.y)) {
|
|
152
|
+
link.sy = y;
|
|
153
|
+
link.width = link.data.value * k;
|
|
154
|
+
y += link.width;
|
|
155
|
+
}
|
|
156
|
+
y = n.y;
|
|
157
|
+
for (const link of [...n.ins].sort((a, b) => a.source.y - b.source.y)) {
|
|
158
|
+
link.ty = y;
|
|
159
|
+
y += link.data.value * k;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return {
|
|
163
|
+
nodes,
|
|
164
|
+
links,
|
|
165
|
+
plot,
|
|
166
|
+
nodeWidth,
|
|
167
|
+
labels: nodes.map((n, i) => {
|
|
168
|
+
const [name, value] = texts[i];
|
|
169
|
+
const side = n.column === 0 && columns > 1 ? "left" : "right";
|
|
170
|
+
const room = side === "left" ? left : n.column === columns - 1 ? right : step - nodeWidth - 16;
|
|
171
|
+
const col = byColumn[n.column];
|
|
172
|
+
const at = col.indexOf(n);
|
|
173
|
+
const showValue = [col[at - 1], col[at + 1]].filter((o) => !!o).reduce((min, o) => Math.min(min, (n.height + o.height) / 2 + pad), Number.POSITIVE_INFINITY) >= fontSize * (1 + LINE_HEIGHT);
|
|
174
|
+
return {
|
|
175
|
+
side,
|
|
176
|
+
name: truncate(name, room, fontSize),
|
|
177
|
+
value: showValue ? truncate(value, room, fontSize) : ""
|
|
178
|
+
};
|
|
179
|
+
})
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
/** Path of a link: two cubic Béziers between the slices at its ends. */
|
|
183
|
+
function linkPath(link, nodeWidth) {
|
|
184
|
+
const x0 = link.source.x + nodeWidth;
|
|
185
|
+
const x1 = link.target.x;
|
|
186
|
+
const xm = (x0 + x1) / 2;
|
|
187
|
+
const { sy, ty, width } = link;
|
|
188
|
+
const p = (...v) => v.map(round).join(",");
|
|
189
|
+
return `M${p(x0, sy)}C${p(xm, sy, xm, ty, x1, ty)}L${p(x1, ty + width)}C${p(xm, ty + width, xm, sy + width, x0, sy + width)}Z`;
|
|
190
|
+
}
|
|
191
|
+
/** A point on a cubic Bézier with control points `a`, `b`, `c`, `d`. */
|
|
192
|
+
const cubic = (a, b, c, d, t) => {
|
|
193
|
+
const u = 1 - t;
|
|
194
|
+
return u * u * u * a + 3 * u * u * t * b + 3 * u * t * t * c + t * t * t * d;
|
|
195
|
+
};
|
|
196
|
+
/** Whether `(px, py)` lies inside the ribbon of `link`. */
|
|
197
|
+
function inLink(link, nodeWidth, px, py) {
|
|
198
|
+
const x0 = link.source.x + nodeWidth;
|
|
199
|
+
const x1 = link.target.x;
|
|
200
|
+
if (px < Math.min(x0, x1) || px > Math.max(x0, x1) || x0 === x1) return false;
|
|
201
|
+
const xm = (x0 + x1) / 2;
|
|
202
|
+
let lo = 0;
|
|
203
|
+
let hi = 1;
|
|
204
|
+
for (let i = 0; i < 20; i++) {
|
|
205
|
+
const mid = (lo + hi) / 2;
|
|
206
|
+
if (cubic(x0, xm, xm, x1, mid) < px === x1 > x0) lo = mid;
|
|
207
|
+
else hi = mid;
|
|
208
|
+
}
|
|
209
|
+
const top = cubic(link.sy, link.sy, link.ty, link.ty, (lo + hi) / 2);
|
|
210
|
+
return py >= top && py <= top + link.width;
|
|
211
|
+
}
|
|
212
|
+
function renderSankey(options, ctx) {
|
|
213
|
+
const { nodes, links, plot, nodeWidth, labels } = layout(options, ctx);
|
|
214
|
+
const drawn = links.filter((link) => link.data.value > 0);
|
|
215
|
+
const formatValue = formatDetail(options.format, ctx.locale);
|
|
216
|
+
const nodeMark = (n) => ({
|
|
217
|
+
d: `M0,0h${round(nodeWidth)}v${round(n.height)}h${round(-nodeWidth)}Z`,
|
|
218
|
+
x: n.x,
|
|
219
|
+
y: n.y
|
|
220
|
+
});
|
|
221
|
+
const linkItem = (link) => ({
|
|
222
|
+
name: `${link.source.data.name} → ${link.target.data.name}`,
|
|
223
|
+
seriesIndex: link.index,
|
|
224
|
+
color: colorOf(link.source),
|
|
225
|
+
value: link.data.value,
|
|
226
|
+
text: formatValue(link.data.value),
|
|
227
|
+
x: (link.source.x + nodeWidth + link.target.x) / 2,
|
|
228
|
+
y: cubic(link.sy, link.sy, link.ty, link.ty, .5) + link.width / 2
|
|
229
|
+
});
|
|
230
|
+
const hitNode = (n, linkIndex) => {
|
|
231
|
+
const own = {
|
|
232
|
+
name: n.data.name,
|
|
233
|
+
seriesIndex: links.length + n.index,
|
|
234
|
+
color: colorOf(n),
|
|
235
|
+
value: n.value,
|
|
236
|
+
text: formatValue(n.value),
|
|
237
|
+
x: n.x + nodeWidth / 2,
|
|
238
|
+
y: n.y + n.height / 2
|
|
239
|
+
};
|
|
240
|
+
const flows = [...n.ins, ...n.outs].map(linkItem);
|
|
241
|
+
const focused = flows.find((item) => item.seriesIndex === linkIndex);
|
|
242
|
+
const link = focused && drawn.find((l) => l.index === linkIndex);
|
|
243
|
+
return {
|
|
244
|
+
index: n.index,
|
|
245
|
+
label: n.data.name,
|
|
246
|
+
title: "",
|
|
247
|
+
x: own.x,
|
|
248
|
+
area: plot,
|
|
249
|
+
items: [own, ...flows],
|
|
250
|
+
seriesIndex: focused ? linkIndex : own.seriesIndex,
|
|
251
|
+
mark: link ? {
|
|
252
|
+
d: linkPath(link, nodeWidth),
|
|
253
|
+
x: 0,
|
|
254
|
+
y: 0
|
|
255
|
+
} : nodeMark(n)
|
|
256
|
+
};
|
|
257
|
+
};
|
|
258
|
+
const hitLink = (link) => {
|
|
259
|
+
const item = linkItem(link);
|
|
260
|
+
return {
|
|
261
|
+
index: link.source.index,
|
|
262
|
+
label: link.source.data.name,
|
|
263
|
+
title: "",
|
|
264
|
+
x: item.x,
|
|
265
|
+
area: plot,
|
|
266
|
+
items: [item],
|
|
267
|
+
seriesIndex: link.index,
|
|
268
|
+
mark: {
|
|
269
|
+
d: linkPath(link, nodeWidth),
|
|
270
|
+
x: 0,
|
|
271
|
+
y: 0
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
};
|
|
275
|
+
const interaction = {
|
|
276
|
+
count: nodes.length,
|
|
277
|
+
hitTest(px, py) {
|
|
278
|
+
const n = nodes.find((n) => px >= n.x - HOVER_SLOP && px <= n.x + nodeWidth + HOVER_SLOP && py >= n.y - HOVER_SLOP && py <= n.y + n.height + HOVER_SLOP);
|
|
279
|
+
if (n) return hitNode(n);
|
|
280
|
+
const link = drawn.find((l) => inLink(l, nodeWidth, px, py));
|
|
281
|
+
return link ? hitLink(link) : null;
|
|
282
|
+
},
|
|
283
|
+
hitIndex(index, seriesIndex) {
|
|
284
|
+
const n = nodes[index];
|
|
285
|
+
return n ? hitNode(n, seriesIndex) : null;
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
ctx.onHitTest(interaction);
|
|
289
|
+
return [
|
|
290
|
+
h("g", {
|
|
291
|
+
key: "links",
|
|
292
|
+
class: "tc-sankey-links"
|
|
293
|
+
}, drawn.map((link) => h("path", {
|
|
294
|
+
key: `${link.source.data.name}→${link.target.data.name}#${link.index}`,
|
|
295
|
+
class: [
|
|
296
|
+
"tc-series",
|
|
297
|
+
`tc-series-${link.source.slot}`,
|
|
298
|
+
"tc-sankey-link"
|
|
299
|
+
],
|
|
300
|
+
style: { "--tc-series-color": link.source.data.color },
|
|
301
|
+
d: linkPath(link, nodeWidth)
|
|
302
|
+
}))),
|
|
303
|
+
h("g", {
|
|
304
|
+
key: "nodes",
|
|
305
|
+
class: "tc-sankey-nodes"
|
|
306
|
+
}, nodes.map((n) => h("g", {
|
|
307
|
+
key: n.data.name,
|
|
308
|
+
class: ["tc-series", `tc-series-${n.slot}`],
|
|
309
|
+
"data-series": n.data.name,
|
|
310
|
+
style: { "--tc-series-color": n.data.color }
|
|
311
|
+
}, h("rect", {
|
|
312
|
+
class: "tc-sankey-node",
|
|
313
|
+
x: round(n.x),
|
|
314
|
+
y: round(n.y),
|
|
315
|
+
width: round(nodeWidth),
|
|
316
|
+
height: round(n.height)
|
|
317
|
+
})))),
|
|
318
|
+
h("g", {
|
|
319
|
+
key: "labels",
|
|
320
|
+
class: "tc-sankey-labels",
|
|
321
|
+
"aria-hidden": "true"
|
|
322
|
+
}, nodes.map((n, i) => {
|
|
323
|
+
const label = labels[i];
|
|
324
|
+
if (!label.name && !label.value) return null;
|
|
325
|
+
const x = round(label.side === "left" ? n.x - LABEL_GAP : n.x + nodeWidth + LABEL_GAP);
|
|
326
|
+
const y = round(n.y + n.height / 2);
|
|
327
|
+
const anchor = label.side === "left" ? "end" : "start";
|
|
328
|
+
return h("g", {
|
|
329
|
+
key: n.data.name,
|
|
330
|
+
class: "tc-sankey-label"
|
|
331
|
+
}, h("text", {
|
|
332
|
+
class: "tc-value-label tc-sankey-name",
|
|
333
|
+
x,
|
|
334
|
+
y,
|
|
335
|
+
dy: label.value ? "-0.25em" : "0.35em",
|
|
336
|
+
"text-anchor": anchor
|
|
337
|
+
}, label.name), label.value && h("text", {
|
|
338
|
+
class: "tc-tick-label tc-sankey-value",
|
|
339
|
+
x,
|
|
340
|
+
y,
|
|
341
|
+
dy: "0.95em",
|
|
342
|
+
"text-anchor": anchor
|
|
343
|
+
}, label.value));
|
|
344
|
+
}))
|
|
345
|
+
];
|
|
346
|
+
}
|
|
347
|
+
/** One legend entry per custom color, named after the first node wearing it. */
|
|
348
|
+
function sankeyLegend(options) {
|
|
349
|
+
const seen = /* @__PURE__ */ new Map();
|
|
350
|
+
for (const n of options.data.nodes ?? []) if (n.color && !seen.has(n.color)) {
|
|
351
|
+
const item = {
|
|
352
|
+
key: n.name,
|
|
353
|
+
name: n.name,
|
|
354
|
+
index: seen.size,
|
|
355
|
+
color: n.color
|
|
356
|
+
};
|
|
357
|
+
if (n.hidden) item.hidden = true;
|
|
358
|
+
seen.set(n.color, item);
|
|
359
|
+
}
|
|
360
|
+
return [...seen.values()];
|
|
361
|
+
}
|
|
362
|
+
function sankeyTable(options, ctx) {
|
|
363
|
+
const { links } = graph(options.data, ctx.hidden, true);
|
|
364
|
+
const value = formatDetail(options.format, ctx.locale);
|
|
365
|
+
return {
|
|
366
|
+
columns: [
|
|
367
|
+
"From",
|
|
368
|
+
"To",
|
|
369
|
+
"Value"
|
|
370
|
+
],
|
|
371
|
+
rows: links.map((link) => [
|
|
372
|
+
link.data.from,
|
|
373
|
+
link.data.to,
|
|
374
|
+
value(link.data.value)
|
|
375
|
+
])
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
/** Nodes and links from users, APIs and JSON, in the shape the layout expects. */
|
|
379
|
+
const cleanSankey = (data) => {
|
|
380
|
+
const d = isRecord(data) ? data : {};
|
|
381
|
+
return {
|
|
382
|
+
...d,
|
|
383
|
+
nodes: Array.isArray(d.nodes) ? records(d.nodes, (r) => named(r)) : void 0,
|
|
384
|
+
links: records(d.links, (r) => ({
|
|
385
|
+
from: text(r.from),
|
|
386
|
+
to: text(r.to),
|
|
387
|
+
value: Math.max(0, finite(r.value) ?? 0)
|
|
388
|
+
}))
|
|
389
|
+
};
|
|
390
|
+
};
|
|
391
|
+
/**
|
|
392
|
+
* Sankey diagram: flows between nodes, as ribbons whose width is their
|
|
393
|
+
* value. Nodes are made from the links (or declared, to set their order and
|
|
394
|
+
* colors) and placed in columns by the longest path from a source.
|
|
395
|
+
*
|
|
396
|
+
* ```ts
|
|
397
|
+
* new Chart('#el', {
|
|
398
|
+
* type: sankey,
|
|
399
|
+
* data: {
|
|
400
|
+
* links: [
|
|
401
|
+
* { from: 'Wages', to: 'Income', value: 60 },
|
|
402
|
+
* { from: 'Dividends', to: 'Income', value: 15 },
|
|
403
|
+
* { from: 'Income', to: 'Rent', value: 30 },
|
|
404
|
+
* { from: 'Income', to: 'Savings', value: 45 },
|
|
405
|
+
* ],
|
|
406
|
+
* },
|
|
407
|
+
* })
|
|
408
|
+
* ```
|
|
409
|
+
*/
|
|
410
|
+
const sankey = {
|
|
411
|
+
name: "sankey",
|
|
412
|
+
clean: cleanData(cleanSankey),
|
|
413
|
+
render: renderSankey,
|
|
414
|
+
legend: sankeyLegend,
|
|
415
|
+
table: sankeyTable
|
|
416
|
+
};
|
|
417
|
+
//#endregion
|
|
418
|
+
export { sankey as t };
|
|
419
|
+
|
|
420
|
+
//# sourceMappingURL=sankey-B4PNKusJ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sankey-B4PNKusJ.js","names":[],"sources":["../src/charts/sankey.ts"],"sourcesContent":["import type { DataTable } from '../a11y.ts'\nimport type { ChartType, RenderContext } from '../chart.ts'\nimport { formatDetail, type NumberFormat } from '../format.ts'\nimport type { Hit, HitItem, Interaction } from '../interaction.ts'\nimport {\n estimateTextWidth,\n type InsetsInput,\n innerRect,\n insets,\n LINE_HEIGHT,\n type Rect,\n round,\n} from '../layout.ts'\nimport type { LegendItem } from '../legend.ts'\nimport { type ChildInput, h } from '../vnode.ts'\nimport { cleanData, finite, isRecord, named, records, text } from './clean.ts'\n\n/** A node of the flow; nodes left out are made from the links. */\nexport interface SankeyNode {\n name: string\n /**\n * Custom color; overrides the palette slot via `--tc-series-color`. Nodes\n * sharing a color form one legend entry, named after the first of them.\n * Values that could inject CSS (`;`, quotes, `url()` …) are ignored, so colors from user data are safe.\n */\n color?: string\n /** Start hidden (toggle it back from the legend, with every node of its color). */\n hidden?: boolean\n}\n\n/** A flow between two nodes, by name. */\nexport interface SankeyLink {\n from: string\n to: string\n /** Non-negative value; negative values count as zero. */\n value: number\n}\n\nexport interface SankeyData {\n /** Optional: sets the stacking order within a column, and colors. */\n nodes?: readonly SankeyNode[]\n links: readonly SankeyLink[]\n}\n\nexport interface SankeyOptions {\n data: SankeyData\n /** Width of the node bars in pixels. Defaults to `12`. */\n nodeWidth?: number\n /** Vertical gap between the nodes of a column in pixels. Defaults to `16`. */\n nodePadding?: number\n /** Format of the values (labels, tooltips and the table). */\n format?: NumberFormat\n /**\n * `'justify'` (default) puts every node without outgoing flows in the last\n * column; `'left'` leaves it in the column after its sources.\n */\n align?: 'justify' | 'left'\n /** Extra space around the diagram, in pixels. */\n padding?: InsetsInput\n}\n\ninterface Node {\n data: SankeyNode\n index: number\n /** Palette slot, 1-based: the node's position in its column. */\n slot: number\n column: number\n value: number\n x: number\n y: number\n height: number\n ins: Link[]\n outs: Link[]\n}\n\ninterface Link {\n data: SankeyLink\n index: number\n source: Node\n target: Node\n /** Top of the slice at the source and at the target. */\n sy: number\n ty: number\n width: number\n}\n\ninterface Layout {\n nodes: Node[]\n links: Link[]\n /** The columns' extent, between the label margins. */\n plot: Rect\n nodeWidth: number\n labels: NodeLabel[]\n}\n\n/** A node's label: the name and the value under it, cut to fit (empty when hidden). */\ninterface NodeLabel {\n side: 'left' | 'right'\n name: string\n value: string\n}\n\n/** Space between a node and its label. */\nconst LABEL_GAP = 8\n/** Largest share of the width one side's labels may take. */\nconst MAX_LABEL_SHARE = 0.3\n/** Pixels around a node that still count as hovering it. */\nconst HOVER_SLOP = 2\n\n/** `text`, cut short with an ellipsis to fit `width` pixels. */\nfunction truncate(text: string, width: number, fontSize: number): string {\n if (estimateTextWidth(text, fontSize) <= width) return text\n let end = text.length\n while (end > 0 && estimateTextWidth(`${text.slice(0, end)}…`, fontSize) > width) end--\n return end > 0 ? `${text.slice(0, end).trimEnd()}…` : ''\n}\n\n/** The color of a node for hover and tooltip swatches. */\nconst colorOf = (node: Node): string => node.data.color ?? `var(--tc-color-${node.slot})`\n\n/** The visible nodes and links, in data order, with their columns. */\nfunction graph(data: SankeyData, hidden: ReadonlySet<string>, justify: boolean) {\n const byName = new Map<string, Node>()\n const nodes: Node[] = []\n const node = (name: string, data?: SankeyNode): Node => {\n let found = byName.get(name)\n if (!found) {\n found = {\n data: data ?? { name },\n index: nodes.length,\n slot: 1,\n column: 0,\n value: 0,\n x: 0,\n y: 0,\n height: 0,\n ins: [],\n outs: [],\n }\n byName.set(name, found)\n nodes.push(found)\n }\n return found\n }\n const declared = new Map((data.nodes ?? []).map((n) => [n.name, n]))\n /** A legend key hides every node of its color, see `sankeyLegend`. */\n const isHidden = (name: string) => {\n const n = declared.get(name)\n return hidden.has(name) || (n?.color !== undefined && hidden.has(legendKey(data, n.color)))\n }\n const links: Link[] = []\n data.links.forEach((link, index) => {\n if (link.from === link.to || isHidden(link.from) || isHidden(link.to)) return\n const source = node(link.from, declared.get(link.from))\n const target = node(link.to, declared.get(link.to))\n const out: Link = { data: link, index, source, target, sy: 0, ty: 0, width: 0 }\n links.push(out)\n if (link.value <= 0) return\n source.outs.push(out)\n target.ins.push(out)\n })\n for (const n of nodes) {\n n.value = Math.max(\n n.outs.reduce((sum, l) => sum + l.data.value, 0),\n n.ins.reduce((sum, l) => sum + l.data.value, 0),\n )\n }\n // Column: the longest path from a source, passes bounded so cycles end.\n for (let pass = 0; pass < nodes.length; pass++) {\n let changed = false\n for (const link of links) {\n if (link.data.value > 0 && link.target.column <= link.source.column) {\n link.target.column = link.source.column + 1\n changed = true\n }\n }\n if (!changed) break\n }\n const last = nodes.reduce((max, n) => Math.max(max, n.column), 0)\n if (justify) for (const n of nodes) if (n.outs.length === 0) n.column = last\n // Stack order within a column: declared nodes first, then first appearance.\n const order = [...declared.keys()]\n nodes.sort((a, b) => {\n if (a.column !== b.column) return a.column - b.column\n const ia = order.indexOf(a.data.name)\n const ib = order.indexOf(b.data.name)\n if (ia !== -1 && ib !== -1) return ia - ib\n if (ia !== ib) return ia === -1 ? 1 : -1\n return a.index - b.index\n })\n const slots = new Map<number, number>()\n nodes.forEach((n, index) => {\n n.index = index\n const slot = (slots.get(n.column) ?? 0) + 1\n slots.set(n.column, slot)\n n.slot = ((slot - 1) % 8) + 1\n })\n return { nodes, links, columns: last + 1 }\n}\n\n/** Key of the legend entry of `color`: the first node that wears it. */\nconst legendKey = (data: SankeyData, color: string): string =>\n (data.nodes ?? []).find((n) => n.color === color)?.name ?? color\n\nfunction layout(options: SankeyOptions, ctx: RenderContext): Layout {\n const { width, height, fontSize, locale } = ctx\n const nodeWidth = Math.max(1, options.nodeWidth ?? 12)\n const nodePadding = Math.max(0, options.nodePadding ?? 16)\n const area = innerRect(width, height, insets(options.padding))\n const { nodes, links, columns } = graph(options.data, ctx.hidden, options.align !== 'left')\n const format = formatDetail(options.format, locale)\n\n // Labels take their room from the sides: the first column's to its left,\n // the last column's to its right, the rest to the right of their node.\n const texts = nodes.map((n) => [n.data.name, format(n.value)] as const)\n const widest = (match: (n: Node) => boolean) =>\n nodes.reduce((max, n, i) => {\n if (!match(n)) return max\n const [name, value] = texts[i] as readonly [string, string]\n return Math.max(max, estimateTextWidth(name, fontSize), estimateTextWidth(value, fontSize))\n }, 0)\n const cap = area.width * MAX_LABEL_SHARE\n const left =\n columns > 1\n ? Math.min(\n cap,\n widest((n) => n.column === 0),\n )\n : 0\n const right = Math.min(\n cap,\n widest((n) => n.column === columns - 1),\n )\n const plot: Rect = {\n x: area.x + (left ? left + LABEL_GAP : 0),\n y: area.y,\n width: Math.max(\n 0,\n area.width - (left ? left + LABEL_GAP : 0) - (right ? right + LABEL_GAP : 0),\n ),\n height: area.height,\n }\n const step = columns > 1 ? (plot.width - nodeWidth) / (columns - 1) : 0\n\n // Heights: one scale for every column, so values compare across them.\n const byColumn: Node[][] = Array.from({ length: columns }, () => [])\n for (const n of nodes) byColumn[n.column]?.push(n)\n const pad = byColumn.reduce(\n (min, col) => (col.length > 1 ? Math.min(min, plot.height / 2 / (col.length - 1)) : min),\n nodePadding,\n )\n let k = Number.POSITIVE_INFINITY\n for (const col of byColumn) {\n const sum = col.reduce((s, n) => s + n.value, 0)\n if (sum > 0) k = Math.min(k, (plot.height - (col.length - 1) * pad) / sum)\n }\n if (!Number.isFinite(k) || k < 0) k = 0\n byColumn.forEach((col, c) => {\n const total = col.reduce((s, n) => s + n.value * k, 0) + (col.length - 1) * pad\n let y = plot.y + (plot.height - total) / 2\n for (const n of col) {\n n.x = plot.x + (columns > 1 ? c * step : (plot.width - nodeWidth) / 2)\n n.y = y\n n.height = n.value * k\n y += n.height + pad\n }\n })\n // Slices: flows leave and enter in the order of the node at the other end.\n for (const n of nodes) {\n let y = n.y\n for (const link of [...n.outs].sort((a, b) => a.target.y - b.target.y)) {\n link.sy = y\n link.width = link.data.value * k\n y += link.width\n }\n y = n.y\n for (const link of [...n.ins].sort((a, b) => a.source.y - b.source.y)) {\n link.ty = y\n y += link.data.value * k\n }\n }\n\n const labels = nodes.map((n, i): NodeLabel => {\n const [name, value] = texts[i] as readonly [string, string]\n const side: 'left' | 'right' = n.column === 0 && columns > 1 ? 'left' : 'right'\n const room =\n side === 'left' ? left : n.column === columns - 1 ? right : step - nodeWidth - LABEL_GAP * 2\n // Crowded columns keep only the names: the value line would run into the next label.\n const col = byColumn[n.column] as Node[]\n const at = col.indexOf(n)\n const neighbours = [col[at - 1], col[at + 1]].filter((o): o is Node => !!o)\n const spacing = neighbours.reduce(\n (min, o) => Math.min(min, (n.height + o.height) / 2 + pad),\n Number.POSITIVE_INFINITY,\n )\n const showValue = spacing >= fontSize * (1 + LINE_HEIGHT)\n return {\n side,\n name: truncate(name, room, fontSize),\n value: showValue ? truncate(value, room, fontSize) : '',\n }\n })\n return { nodes, links, plot, nodeWidth, labels }\n}\n\n/** Path of a link: two cubic Béziers between the slices at its ends. */\nfunction linkPath(link: Link, nodeWidth: number): string {\n const x0 = link.source.x + nodeWidth\n const x1 = link.target.x\n const xm = (x0 + x1) / 2\n const { sy, ty, width } = link\n const p = (...v: number[]) => v.map(round).join(',')\n return `M${p(x0, sy)}C${p(xm, sy, xm, ty, x1, ty)}L${p(x1, ty + width)}C${p(xm, ty + width, xm, sy + width, x0, sy + width)}Z`\n}\n\n/** A point on a cubic Bézier with control points `a`, `b`, `c`, `d`. */\nconst cubic = (a: number, b: number, c: number, d: number, t: number): number => {\n const u = 1 - t\n return u * u * u * a + 3 * u * u * t * b + 3 * u * t * t * c + t * t * t * d\n}\n\n/** Whether `(px, py)` lies inside the ribbon of `link`. */\nfunction inLink(link: Link, nodeWidth: number, px: number, py: number): boolean {\n const x0 = link.source.x + nodeWidth\n const x1 = link.target.x\n if (px < Math.min(x0, x1) || px > Math.max(x0, x1) || x0 === x1) return false\n const xm = (x0 + x1) / 2\n // x(t) is monotone, so bisection finds the t under the pointer.\n let lo = 0\n let hi = 1\n for (let i = 0; i < 20; i++) {\n const mid = (lo + hi) / 2\n if (cubic(x0, xm, xm, x1, mid) < px === x1 > x0) lo = mid\n else hi = mid\n }\n const top = cubic(link.sy, link.sy, link.ty, link.ty, (lo + hi) / 2)\n return py >= top && py <= top + link.width\n}\n\nfunction renderSankey(options: SankeyOptions, ctx: RenderContext): ChildInput {\n const { nodes, links, plot, nodeWidth, labels } = layout(options, ctx)\n const drawn = links.filter((link) => link.data.value > 0)\n const formatValue = formatDetail(options.format, ctx.locale)\n\n const nodeMark = (n: Node) => ({\n d: `M0,0h${round(nodeWidth)}v${round(n.height)}h${round(-nodeWidth)}Z`,\n x: n.x,\n y: n.y,\n })\n const linkItem = (link: Link): HitItem => ({\n name: `${link.source.data.name} → ${link.target.data.name}`,\n seriesIndex: link.index,\n color: colorOf(link.source),\n value: link.data.value,\n text: formatValue(link.data.value),\n x: (link.source.x + nodeWidth + link.target.x) / 2,\n y: cubic(link.sy, link.sy, link.ty, link.ty, 0.5) + link.width / 2,\n })\n const hitNode = (n: Node, linkIndex?: number): Hit => {\n const own: HitItem = {\n name: n.data.name,\n seriesIndex: links.length + n.index,\n color: colorOf(n),\n value: n.value,\n text: formatValue(n.value),\n x: n.x + nodeWidth / 2,\n y: n.y + n.height / 2,\n }\n const flows = [...n.ins, ...n.outs].map(linkItem)\n const focused = flows.find((item) => item.seriesIndex === linkIndex)\n const link = focused && drawn.find((l) => l.index === linkIndex)\n return {\n index: n.index,\n label: n.data.name,\n title: '',\n x: own.x,\n area: plot,\n items: [own, ...flows],\n seriesIndex: focused ? linkIndex : own.seriesIndex,\n mark: link ? { d: linkPath(link, nodeWidth), x: 0, y: 0 } : nodeMark(n),\n }\n }\n const hitLink = (link: Link): Hit => {\n const item = linkItem(link)\n return {\n index: link.source.index,\n label: link.source.data.name,\n title: '',\n x: item.x,\n area: plot,\n items: [item],\n seriesIndex: link.index,\n mark: { d: linkPath(link, nodeWidth), x: 0, y: 0 },\n }\n }\n\n const interaction: Interaction = {\n count: nodes.length,\n hitTest(px, py) {\n const n = nodes.find(\n (n) =>\n px >= n.x - HOVER_SLOP &&\n px <= n.x + nodeWidth + HOVER_SLOP &&\n py >= n.y - HOVER_SLOP &&\n py <= n.y + n.height + HOVER_SLOP,\n )\n if (n) return hitNode(n)\n const link = drawn.find((l) => inLink(l, nodeWidth, px, py))\n return link ? hitLink(link) : null\n },\n hitIndex(index, seriesIndex) {\n const n = nodes[index]\n return n ? hitNode(n, seriesIndex) : null\n },\n }\n ctx.onHitTest(interaction)\n\n return [\n h(\n 'g',\n { key: 'links', class: 'tc-sankey-links' },\n drawn.map((link) =>\n h('path', {\n key: `${link.source.data.name}→${link.target.data.name}#${link.index}`,\n class: ['tc-series', `tc-series-${link.source.slot}`, 'tc-sankey-link'],\n style: { '--tc-series-color': link.source.data.color },\n d: linkPath(link, nodeWidth),\n }),\n ),\n ),\n h(\n 'g',\n { key: 'nodes', class: 'tc-sankey-nodes' },\n nodes.map((n) =>\n h(\n 'g',\n {\n key: n.data.name,\n class: ['tc-series', `tc-series-${n.slot}`],\n 'data-series': n.data.name,\n style: { '--tc-series-color': n.data.color },\n },\n h('rect', {\n class: 'tc-sankey-node',\n x: round(n.x),\n y: round(n.y),\n width: round(nodeWidth),\n height: round(n.height),\n }),\n ),\n ),\n ),\n h(\n 'g',\n { key: 'labels', class: 'tc-sankey-labels', 'aria-hidden': 'true' },\n nodes.map((n, i) => {\n const label = labels[i] as NodeLabel\n if (!label.name && !label.value) return null\n const x = round(label.side === 'left' ? n.x - LABEL_GAP : n.x + nodeWidth + LABEL_GAP)\n const y = round(n.y + n.height / 2)\n const anchor = label.side === 'left' ? 'end' : 'start'\n return h(\n 'g',\n { key: n.data.name, class: 'tc-sankey-label' },\n h(\n 'text',\n {\n class: 'tc-value-label tc-sankey-name',\n x,\n y,\n dy: label.value ? '-0.25em' : '0.35em',\n 'text-anchor': anchor,\n },\n label.name,\n ),\n label.value &&\n h(\n 'text',\n {\n class: 'tc-tick-label tc-sankey-value',\n x,\n y,\n dy: '0.95em',\n 'text-anchor': anchor,\n },\n label.value,\n ),\n )\n }),\n ),\n ]\n}\n\n/** One legend entry per custom color, named after the first node wearing it. */\nfunction sankeyLegend(options: SankeyOptions): LegendItem[] {\n const seen = new Map<string, LegendItem>()\n for (const n of options.data.nodes ?? []) {\n if (n.color && !seen.has(n.color)) {\n const item: LegendItem = { key: n.name, name: n.name, index: seen.size, color: n.color }\n if (n.hidden) item.hidden = true\n seen.set(n.color, item)\n }\n }\n return [...seen.values()]\n}\n\nfunction sankeyTable(options: SankeyOptions, ctx: RenderContext): DataTable {\n const { links } = graph(options.data, ctx.hidden, true)\n const value = formatDetail(options.format, ctx.locale)\n return {\n columns: ['From', 'To', 'Value'],\n rows: links.map((link) => [link.data.from, link.data.to, value(link.data.value)]),\n }\n}\n\n/** Nodes and links from users, APIs and JSON, in the shape the layout expects. */\nconst cleanSankey = (data: unknown): unknown => {\n const d = isRecord(data) ? data : {}\n return {\n ...d,\n nodes: Array.isArray(d.nodes) ? records(d.nodes, (r) => named(r)) : undefined,\n links: records(d.links, (r) => ({\n from: text(r.from),\n to: text(r.to),\n value: Math.max(0, finite(r.value) ?? 0),\n })),\n }\n}\n\n/**\n * Sankey diagram: flows between nodes, as ribbons whose width is their\n * value. Nodes are made from the links (or declared, to set their order and\n * colors) and placed in columns by the longest path from a source.\n *\n * ```ts\n * new Chart('#el', {\n * type: sankey,\n * data: {\n * links: [\n * { from: 'Wages', to: 'Income', value: 60 },\n * { from: 'Dividends', to: 'Income', value: 15 },\n * { from: 'Income', to: 'Rent', value: 30 },\n * { from: 'Income', to: 'Savings', value: 45 },\n * ],\n * },\n * })\n * ```\n */\nexport const sankey: ChartType<SankeyOptions> = {\n name: 'sankey',\n clean: cleanData(cleanSankey),\n render: renderSankey,\n legend: sankeyLegend,\n table: sankeyTable,\n}\n"],"mappings":";;;;;;AAuGA,MAAM,YAAY;;AAElB,MAAM,kBAAkB;;AAExB,MAAM,aAAa;;AAGnB,SAAS,SAAS,MAAc,OAAe,UAA0B;CACvE,IAAI,kBAAkB,MAAM,QAAQ,KAAK,OAAO,OAAO;CACvD,IAAI,MAAM,KAAK;CACf,OAAO,MAAM,KAAK,kBAAkB,GAAG,KAAK,MAAM,GAAG,GAAG,EAAE,IAAI,QAAQ,IAAI,OAAO;CACjF,OAAO,MAAM,IAAI,GAAG,KAAK,MAAM,GAAG,GAAG,CAAC,CAAC,QAAQ,EAAE,KAAK;AACxD;;AAGA,MAAM,WAAW,SAAuB,KAAK,KAAK,SAAS,kBAAkB,KAAK,KAAK;;AAGvF,SAAS,MAAM,MAAkB,QAA6B,SAAkB;CAC9E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AQ,IAAI;CACtD,MAAM,QAAQ,aAAa,QAAQ,QAAQ,IAAI,MAAM;CACrD,OAAO;EACL,SAAS;GAAC;GAAQ;GAAM;EAAO;EAC/B,MAAM,MAAM,KAAK,SAAS;GAAC,KAAK,KAAK;GAAM,KAAK,KAAK;GAAI,MAAM,KAAK,KAAK,KAAK;EAAC,CAAC;CAClF;AACF;;AAGA,MAAM,eAAe,SAA2B;CAC9C,MAAM,IAAI,SAAS,IAAI,IAAI,OAAO,CAAC;CACnC,OAAO;EACL,GAAG;EACH,OAAO,MAAM,QAAQ,EAAE,KAAK,IAAI,QAAQ,EAAE,QAAQ,MAAM,MAAM,CAAC,CAAC,IAAI,KAAA;EACpE,OAAO,QAAQ,EAAE,QAAQ,OAAO;GAC9B,MAAM,KAAK,EAAE,IAAI;GACjB,IAAI,KAAK,EAAE,EAAE;GACb,OAAO,KAAK,IAAI,GAAG,OAAO,EAAE,KAAK,KAAK,CAAC;EACzC,EAAE;CACJ;AACF;;;;;;;;;;;;;;;;;;;;AAqBA,MAAa,SAAmC;CAC9C,MAAM;CACN,OAAO,UAAU,WAAW;CAC5B,QAAQ;CACR,QAAQ;CACR,OAAO;AACT"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { a as InsetsInput } from "./annotations-lyt0I3HU.cjs";
|
|
2
|
+
import { a as ChartType } from "./chart-Qa417fJo.cjs";
|
|
3
|
+
import { c as NumberFormat } from "./time-CNVnt-B2.cjs";
|
|
4
|
+
//#region src/charts/sankey.d.ts
|
|
5
|
+
/** A node of the flow; nodes left out are made from the links. */
|
|
6
|
+
interface SankeyNode {
|
|
7
|
+
name: string;
|
|
8
|
+
/**
|
|
9
|
+
* Custom color; overrides the palette slot via `--tc-series-color`. Nodes
|
|
10
|
+
* sharing a color form one legend entry, named after the first of them.
|
|
11
|
+
* Values that could inject CSS (`;`, quotes, `url()` …) are ignored, so colors from user data are safe.
|
|
12
|
+
*/
|
|
13
|
+
color?: string;
|
|
14
|
+
/** Start hidden (toggle it back from the legend, with every node of its color). */
|
|
15
|
+
hidden?: boolean;
|
|
16
|
+
}
|
|
17
|
+
/** A flow between two nodes, by name. */
|
|
18
|
+
interface SankeyLink {
|
|
19
|
+
from: string;
|
|
20
|
+
to: string;
|
|
21
|
+
/** Non-negative value; negative values count as zero. */
|
|
22
|
+
value: number;
|
|
23
|
+
}
|
|
24
|
+
interface SankeyData {
|
|
25
|
+
/** Optional: sets the stacking order within a column, and colors. */
|
|
26
|
+
nodes?: readonly SankeyNode[];
|
|
27
|
+
links: readonly SankeyLink[];
|
|
28
|
+
}
|
|
29
|
+
interface SankeyOptions {
|
|
30
|
+
data: SankeyData;
|
|
31
|
+
/** Width of the node bars in pixels. Defaults to `12`. */
|
|
32
|
+
nodeWidth?: number;
|
|
33
|
+
/** Vertical gap between the nodes of a column in pixels. Defaults to `16`. */
|
|
34
|
+
nodePadding?: number;
|
|
35
|
+
/** Format of the values (labels, tooltips and the table). */
|
|
36
|
+
format?: NumberFormat;
|
|
37
|
+
/**
|
|
38
|
+
* `'justify'` (default) puts every node without outgoing flows in the last
|
|
39
|
+
* column; `'left'` leaves it in the column after its sources.
|
|
40
|
+
*/
|
|
41
|
+
align?: "justify" | "left";
|
|
42
|
+
/** Extra space around the diagram, in pixels. */
|
|
43
|
+
padding?: InsetsInput;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Sankey diagram: flows between nodes, as ribbons whose width is their
|
|
47
|
+
* value. Nodes are made from the links (or declared, to set their order and
|
|
48
|
+
* colors) and placed in columns by the longest path from a source.
|
|
49
|
+
*
|
|
50
|
+
* ```ts
|
|
51
|
+
* new Chart('#el', {
|
|
52
|
+
* type: sankey,
|
|
53
|
+
* data: {
|
|
54
|
+
* links: [
|
|
55
|
+
* { from: 'Wages', to: 'Income', value: 60 },
|
|
56
|
+
* { from: 'Dividends', to: 'Income', value: 15 },
|
|
57
|
+
* { from: 'Income', to: 'Rent', value: 30 },
|
|
58
|
+
* { from: 'Income', to: 'Savings', value: 45 },
|
|
59
|
+
* ],
|
|
60
|
+
* },
|
|
61
|
+
* })
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
declare const sankey: ChartType<SankeyOptions>;
|
|
65
|
+
//#endregion
|
|
66
|
+
export { sankey as a, SankeyOptions as i, SankeyLink as n, SankeyNode as r, SankeyData as t };
|
|
67
|
+
//# sourceMappingURL=sankey-B9JYnx7e.d.cts.map
|