@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,43 @@
|
|
|
1
|
+
import { a as InsetsInput } from "./annotations-lyt0I3HU.cjs";
|
|
2
|
+
import { a as ChartType, tt as Label } from "./chart-Qa417fJo.cjs";
|
|
3
|
+
import { c as NumberFormat } from "./time-CNVnt-B2.cjs";
|
|
4
|
+
import { t as Curve } from "./path-CwB28da0.cjs";
|
|
5
|
+
//#region src/charts/sparkline.d.ts
|
|
6
|
+
interface SparklineOptions {
|
|
7
|
+
/** The values; `null` leaves a gap. */
|
|
8
|
+
data: readonly (number | null | undefined)[];
|
|
9
|
+
/** Labels for the tooltip, one per value (e.g. dates). */
|
|
10
|
+
labels?: readonly Label[];
|
|
11
|
+
/** Name shown in the tooltip. Defaults to `'Value'`. */
|
|
12
|
+
name?: string;
|
|
13
|
+
/**
|
|
14
|
+
* `'line'` (default), `'area'`, `'bar'`, or `'tristate'`: only the sign
|
|
15
|
+
* counts, as a full bar up (win), down (loss) or a tick on the middle (draw).
|
|
16
|
+
*/
|
|
17
|
+
variant?: "line" | "area" | "bar" | "tristate";
|
|
18
|
+
/** Interpolation for lines and areas. Defaults to `'monotone'`. */
|
|
19
|
+
curve?: Curve;
|
|
20
|
+
/** Dot on the last value. Defaults to `'last'`. */
|
|
21
|
+
point?: "last" | "none";
|
|
22
|
+
/** Mark the minimum and maximum values. */
|
|
23
|
+
markers?: "minmax" | "none";
|
|
24
|
+
/** Dot radius in pixels. Defaults to `3`. */
|
|
25
|
+
pointRadius?: number;
|
|
26
|
+
/** Include zero in the value range. Defaults to `true` for areas and bars, `false` for lines. */
|
|
27
|
+
zero?: boolean;
|
|
28
|
+
/** Format of values in the tooltip. */
|
|
29
|
+
format?: NumberFormat;
|
|
30
|
+
/** Extra space around the plot, in pixels. */
|
|
31
|
+
padding?: InsetsInput;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Sparkline: a tiny line, area or bar chart without axes, for stat tiles.
|
|
35
|
+
*
|
|
36
|
+
* ```ts
|
|
37
|
+
* new Chart('#el', { type: sparkline, data: [3, 5, 4, 7, 6], height: 40 })
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
declare const sparkline: ChartType<SparklineOptions>;
|
|
41
|
+
//#endregion
|
|
42
|
+
export { sparkline as n, SparklineOptions as t };
|
|
43
|
+
//# sourceMappingURL=sparkline-BG13V4Pz.d.cts.map
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { a as round, i as insets, r as innerRect } from "./layout-B3hiqVEw.js";
|
|
2
|
+
import { t as h } from "./vnode-tCWItoUH.js";
|
|
3
|
+
import { r as formatNumber } from "./format-lStwuc1L.js";
|
|
4
|
+
import { b as linear, o as labelKey, r as domainOf } from "./cartesian-Cr0AF0nG.js";
|
|
5
|
+
import { c as numbers, o as label, t as cleanData } from "./clean-o1vDEhFV.js";
|
|
6
|
+
import { n as areaPath, r as linePath, t as fadeMask } from "./fade-D3NxH5Qg.js";
|
|
7
|
+
import { t as barPath } from "./bar-DM16NUvV.js";
|
|
8
|
+
import { t as circlePath } from "./circle-Z7YfCoCM.js";
|
|
9
|
+
//#region src/charts/sparkline.ts
|
|
10
|
+
function renderSparkline(options, ctx) {
|
|
11
|
+
const { variant = "line", curve = "monotone", point = "last", markers = "none", pointRadius = 3, name = "Value" } = options;
|
|
12
|
+
const values = options.data.map((v) => v == null || !Number.isFinite(v) ? null : v);
|
|
13
|
+
const count = values.length;
|
|
14
|
+
const overhang = point === "last" || markers === "minmax" ? pointRadius + 2 : 2;
|
|
15
|
+
const pad = insets(options.padding, 0);
|
|
16
|
+
const area = innerRect(ctx.width, ctx.height, {
|
|
17
|
+
top: pad.top + overhang,
|
|
18
|
+
right: pad.right + overhang,
|
|
19
|
+
bottom: pad.bottom + overhang,
|
|
20
|
+
left: pad.left + overhang
|
|
21
|
+
});
|
|
22
|
+
const tristate = variant === "tristate";
|
|
23
|
+
const zero = options.zero ?? variant !== "line";
|
|
24
|
+
const domain = tristate ? [-1, 1] : domainOf(values, { nice: false }, zero, 2);
|
|
25
|
+
const bars = variant === "bar" || tristate;
|
|
26
|
+
const gap = 1;
|
|
27
|
+
const slot = count > 0 ? area.width / count : 0;
|
|
28
|
+
const xAt = (i) => bars ? area.x + slot * i + slot / 2 : area.x + (count > 1 ? area.width * i / (count - 1) : area.width / 2);
|
|
29
|
+
const y = linear(domain, [area.y + area.height, area.y]);
|
|
30
|
+
const baseline = y(Math.min(Math.max(0, domain[0]), domain[1]));
|
|
31
|
+
const points = values.map((v, i) => v === null ? null : [xAt(i), y(v)]);
|
|
32
|
+
const format = formatNumber(options.format, ctx.locale);
|
|
33
|
+
const labelOf = (i) => {
|
|
34
|
+
const label = options.labels?.[i];
|
|
35
|
+
return label === void 0 ? "" : String(label);
|
|
36
|
+
};
|
|
37
|
+
const yOf = (v) => y(tristate ? Math.sign(v) : v);
|
|
38
|
+
const hitFor = (i) => {
|
|
39
|
+
const value = values[i];
|
|
40
|
+
if (value === void 0) return null;
|
|
41
|
+
const px = xAt(i);
|
|
42
|
+
const item = {
|
|
43
|
+
name,
|
|
44
|
+
seriesIndex: 0,
|
|
45
|
+
value,
|
|
46
|
+
text: value === null ? "–" : format(value),
|
|
47
|
+
x: px,
|
|
48
|
+
y: value === null ? null : yOf(value)
|
|
49
|
+
};
|
|
50
|
+
const hit = {
|
|
51
|
+
index: i,
|
|
52
|
+
label: labelKey(options.labels?.[i] ?? i + 1),
|
|
53
|
+
title: labelOf(i),
|
|
54
|
+
x: px,
|
|
55
|
+
area,
|
|
56
|
+
items: [item]
|
|
57
|
+
};
|
|
58
|
+
if (value !== null) hit.mark = {
|
|
59
|
+
d: circlePath(pointRadius + 3),
|
|
60
|
+
x: px,
|
|
61
|
+
y: yOf(value)
|
|
62
|
+
};
|
|
63
|
+
return hit;
|
|
64
|
+
};
|
|
65
|
+
const interaction = {
|
|
66
|
+
count,
|
|
67
|
+
hitIndex: (i) => hitFor(i),
|
|
68
|
+
hitTest(px, py) {
|
|
69
|
+
if (count === 0 || py < area.y - overhang || py > area.y + area.height + overhang) return null;
|
|
70
|
+
const i = bars ? Math.floor((px - area.x) / slot) : Math.round((px - area.x) / Math.max(1, area.width) * (count - 1));
|
|
71
|
+
return hitFor(Math.max(0, Math.min(count - 1, i)));
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
ctx.onHitTest(interaction);
|
|
75
|
+
const marks = [];
|
|
76
|
+
if (tristate) {
|
|
77
|
+
const width = Math.max(1, slot - gap);
|
|
78
|
+
marks.push(h("line", {
|
|
79
|
+
class: "tc-sparkline-zero",
|
|
80
|
+
x1: area.x,
|
|
81
|
+
x2: area.x + area.width,
|
|
82
|
+
y1: round(baseline),
|
|
83
|
+
y2: round(baseline)
|
|
84
|
+
}));
|
|
85
|
+
values.forEach((v, i) => {
|
|
86
|
+
if (v === null) return;
|
|
87
|
+
const sign = Math.sign(v);
|
|
88
|
+
const tick = Math.min(2, area.height / 2);
|
|
89
|
+
const [from, to] = sign === 0 ? [baseline + tick / 2, baseline - tick / 2] : [baseline, y(sign)];
|
|
90
|
+
marks.push(h("path", {
|
|
91
|
+
key: i,
|
|
92
|
+
class: [
|
|
93
|
+
"tc-bar",
|
|
94
|
+
sign < 0 && "tc-bar-negative",
|
|
95
|
+
sign < 0 ? "tc-tristate-loss" : sign > 0 ? "tc-tristate-win" : "tc-tristate-draw"
|
|
96
|
+
],
|
|
97
|
+
d: barPath(xAt(i) - width / 2, width, from, to, sign === 0 ? 0 : Math.min(2, width / 2))
|
|
98
|
+
}));
|
|
99
|
+
});
|
|
100
|
+
} else if (bars) {
|
|
101
|
+
const width = Math.max(1, slot - gap);
|
|
102
|
+
values.forEach((v, i) => {
|
|
103
|
+
if (v === null) return;
|
|
104
|
+
marks.push(h("path", {
|
|
105
|
+
key: i,
|
|
106
|
+
class: ["tc-bar", v < 0 && "tc-bar-negative"],
|
|
107
|
+
d: barPath(xAt(i) - width / 2, width, baseline, y(v), Math.min(2, width / 2))
|
|
108
|
+
}));
|
|
109
|
+
});
|
|
110
|
+
} else {
|
|
111
|
+
if (variant === "area") marks.push(h("path", {
|
|
112
|
+
class: "tc-area tc-area-gradient",
|
|
113
|
+
d: areaPath(points, baseline, { curve }),
|
|
114
|
+
mask: `url(#${ctx.id}-fade)`
|
|
115
|
+
}));
|
|
116
|
+
marks.push(h("path", {
|
|
117
|
+
class: "tc-line",
|
|
118
|
+
d: linePath(points, { curve })
|
|
119
|
+
}));
|
|
120
|
+
}
|
|
121
|
+
const dotAt = (i, cls) => {
|
|
122
|
+
const v = values[i];
|
|
123
|
+
return v == null ? null : h("circle", {
|
|
124
|
+
key: `${cls}-${i}`,
|
|
125
|
+
class: ["tc-point", cls],
|
|
126
|
+
cx: round(xAt(i)),
|
|
127
|
+
cy: round(y(v)),
|
|
128
|
+
r: pointRadius
|
|
129
|
+
});
|
|
130
|
+
};
|
|
131
|
+
const extremes = [];
|
|
132
|
+
if (markers === "minmax") {
|
|
133
|
+
let min = -1;
|
|
134
|
+
let max = -1;
|
|
135
|
+
values.forEach((v, i) => {
|
|
136
|
+
if (v === null) return;
|
|
137
|
+
if (min === -1 || v < values[min]) min = i;
|
|
138
|
+
if (max === -1 || v > values[max]) max = i;
|
|
139
|
+
});
|
|
140
|
+
if (min !== -1) extremes.push(dotAt(min, "tc-point-min"));
|
|
141
|
+
if (max !== -1 && max !== min) extremes.push(dotAt(max, "tc-point-max"));
|
|
142
|
+
}
|
|
143
|
+
let last = -1;
|
|
144
|
+
if (point === "last") {
|
|
145
|
+
for (let i = count - 1; i >= 0; i--) if (values[i] !== null) {
|
|
146
|
+
last = i;
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return [variant === "area" && h("defs", null, fadeMask(`${ctx.id}-fade`)), h("g", { class: "tc-series tc-series-1 tc-sparkline" }, marks, extremes, last !== -1 && !bars && dotAt(last, "tc-point-last"))];
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Sparkline: a tiny line, area or bar chart without axes, for stat tiles.
|
|
154
|
+
*
|
|
155
|
+
* ```ts
|
|
156
|
+
* new Chart('#el', { type: sparkline, data: [3, 5, 4, 7, 6], height: 40 })
|
|
157
|
+
* ```
|
|
158
|
+
*/
|
|
159
|
+
const sparkline = {
|
|
160
|
+
name: "sparkline",
|
|
161
|
+
clean: (options) => ({
|
|
162
|
+
...cleanData(numbers)(options),
|
|
163
|
+
labels: Array.isArray(options.labels) ? options.labels.map(label) : void 0
|
|
164
|
+
}),
|
|
165
|
+
render: renderSparkline,
|
|
166
|
+
keyboard: false
|
|
167
|
+
};
|
|
168
|
+
//#endregion
|
|
169
|
+
export { sparkline as t };
|
|
170
|
+
|
|
171
|
+
//# sourceMappingURL=sparkline-BQzt27Fr.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sparkline-BQzt27Fr.js","names":[],"sources":["../src/charts/sparkline.ts"],"sourcesContent":["import type { ChartType, RenderContext } from '../chart.ts'\nimport { fadeMask } from '../components/fade.ts'\nimport { formatNumber, type NumberFormat } from '../format.ts'\nimport type { Hit, HitItem, Interaction } from '../interaction.ts'\nimport { type InsetsInput, innerRect, insets, round } from '../layout.ts'\nimport { linear } from '../scales/linear.ts'\nimport { barPath } from '../shapes/bar.ts'\nimport { circlePath } from '../shapes/circle.ts'\nimport { areaPath, type Curve, linePath, type Point } from '../shapes/path.ts'\nimport { h } from '../vnode.ts'\nimport { domainOf, type Label, labelKey } from './cartesian.ts'\nimport { cleanData, label, numbers } from './clean.ts'\n\nexport interface SparklineOptions {\n /** The values; `null` leaves a gap. */\n data: readonly (number | null | undefined)[]\n /** Labels for the tooltip, one per value (e.g. dates). */\n labels?: readonly Label[]\n /** Name shown in the tooltip. Defaults to `'Value'`. */\n name?: string\n /**\n * `'line'` (default), `'area'`, `'bar'`, or `'tristate'`: only the sign\n * counts, as a full bar up (win), down (loss) or a tick on the middle (draw).\n */\n variant?: 'line' | 'area' | 'bar' | 'tristate'\n /** Interpolation for lines and areas. Defaults to `'monotone'`. */\n curve?: Curve\n /** Dot on the last value. Defaults to `'last'`. */\n point?: 'last' | 'none'\n /** Mark the minimum and maximum values. */\n markers?: 'minmax' | 'none'\n /** Dot radius in pixels. Defaults to `3`. */\n pointRadius?: number\n /** Include zero in the value range. Defaults to `true` for areas and bars, `false` for lines. */\n zero?: boolean\n /** Format of values in the tooltip. */\n format?: NumberFormat\n /** Extra space around the plot, in pixels. */\n padding?: InsetsInput\n}\n\nfunction renderSparkline(options: SparklineOptions, ctx: RenderContext) {\n const {\n variant = 'line',\n curve = 'monotone',\n point = 'last',\n markers = 'none',\n pointRadius = 3,\n name = 'Value',\n } = options\n const values = options.data.map((v) => (v == null || !Number.isFinite(v) ? null : v))\n // (No log option on sparklines, so finite is all that matters here.)\n const count = values.length\n const dots = point === 'last' || markers === 'minmax'\n // Room for the stroke and dots so nothing is clipped at the edges.\n const overhang = dots ? pointRadius + 2 : 2\n const pad = insets(options.padding, 0)\n const area = innerRect(ctx.width, ctx.height, {\n top: pad.top + overhang,\n right: pad.right + overhang,\n bottom: pad.bottom + overhang,\n left: pad.left + overhang,\n })\n const tristate = variant === 'tristate'\n const zero = options.zero ?? variant !== 'line'\n // Tristate bars span half the height each way, whatever the magnitude.\n const domain: [number, number] = tristate ? [-1, 1] : domainOf(values, { nice: false }, zero, 2)\n\n const bars = variant === 'bar' || tristate\n const gap = 1\n const slot = count > 0 ? area.width / count : 0\n const xAt = (i: number) =>\n bars\n ? area.x + slot * i + slot / 2\n : area.x + (count > 1 ? (area.width * i) / (count - 1) : area.width / 2)\n const y = linear(domain, [area.y + area.height, area.y])\n const baseline = y(Math.min(Math.max(0, domain[0]), domain[1]))\n const points: Point[] = values.map((v, i) => (v === null ? null : [xAt(i), y(v)]))\n\n const format = formatNumber(options.format, ctx.locale)\n const labelOf = (i: number) => {\n const label = options.labels?.[i]\n return label === undefined ? '' : String(label)\n }\n // Where a value is drawn: a tristate bar ends at its sign, not its magnitude.\n const yOf = (v: number) => y(tristate ? Math.sign(v) : v)\n const hitFor = (i: number): Hit | null => {\n const value = values[i]\n if (value === undefined) return null\n const px = xAt(i)\n const item: HitItem = {\n name,\n seriesIndex: 0,\n value,\n text: value === null ? '–' : format(value),\n x: px,\n y: value === null ? null : yOf(value),\n }\n const hit: Hit = {\n index: i,\n label: labelKey(options.labels?.[i] ?? i + 1),\n title: labelOf(i),\n x: px,\n area,\n items: [item],\n }\n if (value !== null) hit.mark = { d: circlePath(pointRadius + 3), x: px, y: yOf(value) }\n return hit\n }\n const interaction: Interaction = {\n count,\n hitIndex: (i) => hitFor(i),\n hitTest(px, py) {\n if (count === 0 || py < area.y - overhang || py > area.y + area.height + overhang) return null\n const i = bars\n ? Math.floor((px - area.x) / slot)\n : Math.round(((px - area.x) / Math.max(1, area.width)) * (count - 1))\n return hitFor(Math.max(0, Math.min(count - 1, i)))\n },\n }\n ctx.onHitTest(interaction)\n\n const marks = []\n if (tristate) {\n const width = Math.max(1, slot - gap)\n marks.push(\n h('line', {\n class: 'tc-sparkline-zero',\n x1: area.x,\n x2: area.x + area.width,\n y1: round(baseline),\n y2: round(baseline),\n }),\n )\n values.forEach((v, i) => {\n if (v === null) return\n const sign = Math.sign(v)\n // A draw is a short tick centered on the middle line.\n const tick = Math.min(2, area.height / 2)\n const [from, to] =\n sign === 0 ? [baseline + tick / 2, baseline - tick / 2] : [baseline, y(sign)]\n marks.push(\n h('path', {\n key: i,\n class: [\n 'tc-bar',\n sign < 0 && 'tc-bar-negative',\n sign < 0 ? 'tc-tristate-loss' : sign > 0 ? 'tc-tristate-win' : 'tc-tristate-draw',\n ],\n d: barPath(xAt(i) - width / 2, width, from, to, sign === 0 ? 0 : Math.min(2, width / 2)),\n }),\n )\n })\n } else if (bars) {\n const width = Math.max(1, slot - gap)\n values.forEach((v, i) => {\n if (v === null) return\n marks.push(\n h('path', {\n key: i,\n class: ['tc-bar', v < 0 && 'tc-bar-negative'],\n d: barPath(xAt(i) - width / 2, width, baseline, y(v), Math.min(2, width / 2)),\n }),\n )\n })\n } else {\n if (variant === 'area') {\n marks.push(\n h('path', {\n class: 'tc-area tc-area-gradient',\n d: areaPath(points, baseline, { curve }),\n mask: `url(#${ctx.id}-fade)`,\n }),\n )\n }\n marks.push(h('path', { class: 'tc-line', d: linePath(points, { curve }) }))\n }\n\n const dotAt = (i: number, cls: string) => {\n const v = values[i]\n return v == null\n ? null\n : h('circle', {\n key: `${cls}-${i}`,\n class: ['tc-point', cls],\n cx: round(xAt(i)),\n cy: round(y(v)),\n r: pointRadius,\n })\n }\n const extremes = []\n if (markers === 'minmax') {\n let min = -1\n let max = -1\n values.forEach((v, i) => {\n if (v === null) return\n if (min === -1 || v < (values[min] as number)) min = i\n if (max === -1 || v > (values[max] as number)) max = i\n })\n if (min !== -1) extremes.push(dotAt(min, 'tc-point-min'))\n if (max !== -1 && max !== min) extremes.push(dotAt(max, 'tc-point-max'))\n }\n let last = -1\n if (point === 'last') {\n for (let i = count - 1; i >= 0; i--) {\n if (values[i] !== null) {\n last = i\n break\n }\n }\n }\n\n return [\n variant === 'area' && h('defs', null, fadeMask(`${ctx.id}-fade`)),\n h(\n 'g',\n { class: 'tc-series tc-series-1 tc-sparkline' },\n marks,\n extremes,\n last !== -1 && !bars && dotAt(last, 'tc-point-last'),\n ),\n ]\n}\n\n/**\n * Sparkline: a tiny line, area or bar chart without axes, for stat tiles.\n *\n * ```ts\n * new Chart('#el', { type: sparkline, data: [3, 5, 4, 7, 6], height: 40 })\n * ```\n */\nexport const sparkline: ChartType<SparklineOptions> = {\n name: 'sparkline',\n // The labels too: they come from outside like the values.\n clean: (options) => ({\n ...cleanData(numbers)(options),\n labels: Array.isArray(options.labels) ? options.labels.map(label) : undefined,\n }),\n render: renderSparkline,\n // Decorative by default: opt in with `keyboard: true`.\n keyboard: false,\n}\n"],"mappings":";;;;;;;;;AAyCA,SAAS,gBAAgB,SAA2B,KAAoB;CACtE,MAAM,EACJ,UAAU,QACV,QAAQ,YACR,QAAQ,QACR,UAAU,QACV,cAAc,GACd,OAAO,YACL;CACJ,MAAM,SAAS,QAAQ,KAAK,KAAK,MAAO,KAAK,QAAQ,CAAC,OAAO,SAAS,CAAC,IAAI,OAAO,CAAE;CAEpF,MAAM,QAAQ,OAAO;CAGrB,MAAM,WAFO,UAAU,UAAU,YAAY,WAErB,cAAc,IAAI;CAC1C,MAAM,MAAM,OAAO,QAAQ,SAAS,CAAC;CACrC,MAAM,OAAO,UAAU,IAAI,OAAO,IAAI,QAAQ;EAC5C,KAAK,IAAI,MAAM;EACf,OAAO,IAAI,QAAQ;EACnB,QAAQ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GAAG,MAAM;GACvB,IAAI,MAAM,MAAM;GAChB,IAAI,QAAQ,MAAM,IAAK,OAAO,MAAiB,MAAM;GACrD,IAAI,QAAQ,MAAM,IAAK,OAAO,MAAiB,MAAM;EACvD,CAAC;EACD,IAAI,QAAQ,IAAI,SAAS,KAAK,MAAM,KAAK,cAAc,CAAC;EACxD,IAAI,QAAQ,MAAM,QAAQ,KAAK,SAAS,KAAK,MAAM,KAAK,cAAc,CAAC;CACzE;CACA,IAAI,OAAO;CACX,IAAI,UAAU,QACP;OAAA,IAAI,IAAI,QAAQ,GAAG,KAAK,GAAG,KAC9B,IAAI,OAAO,OAAO,MAAM;GACtB,OAAO;GACP;EACF;;CAIJ,OAAO,CACL,YAAY,UAAU,EAAE,QAAQ,MAAM,SAAS,GAAG,IAAI,GAAG,MAAM,CAAC,GAChE,EACE,KACA,EAAE,OAAO,qCAAqC,GAC9C,OACA,UACA,SAAS,MAAM,CAAC,QAAQ,MAAM,MAAM,eAAe,CACrD,CACF;AACF;;;;;;;;AASA,MAAa,YAAyC;CACpD,MAAM;CAEN,QAAQ,aAAa;EACnB,GAAG,UAAU,OAAO,CAAC,CAAC,OAAO;EAC7B,QAAQ,MAAM,QAAQ,QAAQ,MAAM,IAAI,QAAQ,OAAO,IAAI,KAAK,IAAI,KAAA;CACtE;CACA,QAAQ;CAER,UAAU;AACZ"}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
const require_layout = require("./layout-CtMBhNd9.cjs");
|
|
2
|
+
const require_vnode = require("./vnode-CkQ27Cxe.cjs");
|
|
3
|
+
const require_format = require("./format-B0yKXBTH.cjs");
|
|
4
|
+
const require_cartesian = require("./cartesian-BoDfgBCV.cjs");
|
|
5
|
+
const require_clean = require("./clean-Byl6kzf0.cjs");
|
|
6
|
+
const require_fade = require("./fade-Cs74puQS.cjs");
|
|
7
|
+
const require_bar = require("./bar-DGuUN3nc.cjs");
|
|
8
|
+
const require_circle = require("./circle-BQMuAfls.cjs");
|
|
9
|
+
//#region src/charts/sparkline.ts
|
|
10
|
+
function renderSparkline(options, ctx) {
|
|
11
|
+
const { variant = "line", curve = "monotone", point = "last", markers = "none", pointRadius = 3, name = "Value" } = options;
|
|
12
|
+
const values = options.data.map((v) => v == null || !Number.isFinite(v) ? null : v);
|
|
13
|
+
const count = values.length;
|
|
14
|
+
const overhang = point === "last" || markers === "minmax" ? pointRadius + 2 : 2;
|
|
15
|
+
const pad = require_layout.insets(options.padding, 0);
|
|
16
|
+
const area = require_layout.innerRect(ctx.width, ctx.height, {
|
|
17
|
+
top: pad.top + overhang,
|
|
18
|
+
right: pad.right + overhang,
|
|
19
|
+
bottom: pad.bottom + overhang,
|
|
20
|
+
left: pad.left + overhang
|
|
21
|
+
});
|
|
22
|
+
const tristate = variant === "tristate";
|
|
23
|
+
const zero = options.zero ?? variant !== "line";
|
|
24
|
+
const domain = tristate ? [-1, 1] : require_cartesian.domainOf(values, { nice: false }, zero, 2);
|
|
25
|
+
const bars = variant === "bar" || tristate;
|
|
26
|
+
const gap = 1;
|
|
27
|
+
const slot = count > 0 ? area.width / count : 0;
|
|
28
|
+
const xAt = (i) => bars ? area.x + slot * i + slot / 2 : area.x + (count > 1 ? area.width * i / (count - 1) : area.width / 2);
|
|
29
|
+
const y = require_cartesian.linear(domain, [area.y + area.height, area.y]);
|
|
30
|
+
const baseline = y(Math.min(Math.max(0, domain[0]), domain[1]));
|
|
31
|
+
const points = values.map((v, i) => v === null ? null : [xAt(i), y(v)]);
|
|
32
|
+
const format = require_format.formatNumber(options.format, ctx.locale);
|
|
33
|
+
const labelOf = (i) => {
|
|
34
|
+
const label = options.labels?.[i];
|
|
35
|
+
return label === void 0 ? "" : String(label);
|
|
36
|
+
};
|
|
37
|
+
const yOf = (v) => y(tristate ? Math.sign(v) : v);
|
|
38
|
+
const hitFor = (i) => {
|
|
39
|
+
const value = values[i];
|
|
40
|
+
if (value === void 0) return null;
|
|
41
|
+
const px = xAt(i);
|
|
42
|
+
const item = {
|
|
43
|
+
name,
|
|
44
|
+
seriesIndex: 0,
|
|
45
|
+
value,
|
|
46
|
+
text: value === null ? "–" : format(value),
|
|
47
|
+
x: px,
|
|
48
|
+
y: value === null ? null : yOf(value)
|
|
49
|
+
};
|
|
50
|
+
const hit = {
|
|
51
|
+
index: i,
|
|
52
|
+
label: require_cartesian.labelKey(options.labels?.[i] ?? i + 1),
|
|
53
|
+
title: labelOf(i),
|
|
54
|
+
x: px,
|
|
55
|
+
area,
|
|
56
|
+
items: [item]
|
|
57
|
+
};
|
|
58
|
+
if (value !== null) hit.mark = {
|
|
59
|
+
d: require_circle.circlePath(pointRadius + 3),
|
|
60
|
+
x: px,
|
|
61
|
+
y: yOf(value)
|
|
62
|
+
};
|
|
63
|
+
return hit;
|
|
64
|
+
};
|
|
65
|
+
const interaction = {
|
|
66
|
+
count,
|
|
67
|
+
hitIndex: (i) => hitFor(i),
|
|
68
|
+
hitTest(px, py) {
|
|
69
|
+
if (count === 0 || py < area.y - overhang || py > area.y + area.height + overhang) return null;
|
|
70
|
+
const i = bars ? Math.floor((px - area.x) / slot) : Math.round((px - area.x) / Math.max(1, area.width) * (count - 1));
|
|
71
|
+
return hitFor(Math.max(0, Math.min(count - 1, i)));
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
ctx.onHitTest(interaction);
|
|
75
|
+
const marks = [];
|
|
76
|
+
if (tristate) {
|
|
77
|
+
const width = Math.max(1, slot - gap);
|
|
78
|
+
marks.push(require_vnode.h("line", {
|
|
79
|
+
class: "tc-sparkline-zero",
|
|
80
|
+
x1: area.x,
|
|
81
|
+
x2: area.x + area.width,
|
|
82
|
+
y1: require_layout.round(baseline),
|
|
83
|
+
y2: require_layout.round(baseline)
|
|
84
|
+
}));
|
|
85
|
+
values.forEach((v, i) => {
|
|
86
|
+
if (v === null) return;
|
|
87
|
+
const sign = Math.sign(v);
|
|
88
|
+
const tick = Math.min(2, area.height / 2);
|
|
89
|
+
const [from, to] = sign === 0 ? [baseline + tick / 2, baseline - tick / 2] : [baseline, y(sign)];
|
|
90
|
+
marks.push(require_vnode.h("path", {
|
|
91
|
+
key: i,
|
|
92
|
+
class: [
|
|
93
|
+
"tc-bar",
|
|
94
|
+
sign < 0 && "tc-bar-negative",
|
|
95
|
+
sign < 0 ? "tc-tristate-loss" : sign > 0 ? "tc-tristate-win" : "tc-tristate-draw"
|
|
96
|
+
],
|
|
97
|
+
d: require_bar.barPath(xAt(i) - width / 2, width, from, to, sign === 0 ? 0 : Math.min(2, width / 2))
|
|
98
|
+
}));
|
|
99
|
+
});
|
|
100
|
+
} else if (bars) {
|
|
101
|
+
const width = Math.max(1, slot - gap);
|
|
102
|
+
values.forEach((v, i) => {
|
|
103
|
+
if (v === null) return;
|
|
104
|
+
marks.push(require_vnode.h("path", {
|
|
105
|
+
key: i,
|
|
106
|
+
class: ["tc-bar", v < 0 && "tc-bar-negative"],
|
|
107
|
+
d: require_bar.barPath(xAt(i) - width / 2, width, baseline, y(v), Math.min(2, width / 2))
|
|
108
|
+
}));
|
|
109
|
+
});
|
|
110
|
+
} else {
|
|
111
|
+
if (variant === "area") marks.push(require_vnode.h("path", {
|
|
112
|
+
class: "tc-area tc-area-gradient",
|
|
113
|
+
d: require_fade.areaPath(points, baseline, { curve }),
|
|
114
|
+
mask: `url(#${ctx.id}-fade)`
|
|
115
|
+
}));
|
|
116
|
+
marks.push(require_vnode.h("path", {
|
|
117
|
+
class: "tc-line",
|
|
118
|
+
d: require_fade.linePath(points, { curve })
|
|
119
|
+
}));
|
|
120
|
+
}
|
|
121
|
+
const dotAt = (i, cls) => {
|
|
122
|
+
const v = values[i];
|
|
123
|
+
return v == null ? null : require_vnode.h("circle", {
|
|
124
|
+
key: `${cls}-${i}`,
|
|
125
|
+
class: ["tc-point", cls],
|
|
126
|
+
cx: require_layout.round(xAt(i)),
|
|
127
|
+
cy: require_layout.round(y(v)),
|
|
128
|
+
r: pointRadius
|
|
129
|
+
});
|
|
130
|
+
};
|
|
131
|
+
const extremes = [];
|
|
132
|
+
if (markers === "minmax") {
|
|
133
|
+
let min = -1;
|
|
134
|
+
let max = -1;
|
|
135
|
+
values.forEach((v, i) => {
|
|
136
|
+
if (v === null) return;
|
|
137
|
+
if (min === -1 || v < values[min]) min = i;
|
|
138
|
+
if (max === -1 || v > values[max]) max = i;
|
|
139
|
+
});
|
|
140
|
+
if (min !== -1) extremes.push(dotAt(min, "tc-point-min"));
|
|
141
|
+
if (max !== -1 && max !== min) extremes.push(dotAt(max, "tc-point-max"));
|
|
142
|
+
}
|
|
143
|
+
let last = -1;
|
|
144
|
+
if (point === "last") {
|
|
145
|
+
for (let i = count - 1; i >= 0; i--) if (values[i] !== null) {
|
|
146
|
+
last = i;
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return [variant === "area" && require_vnode.h("defs", null, require_fade.fadeMask(`${ctx.id}-fade`)), require_vnode.h("g", { class: "tc-series tc-series-1 tc-sparkline" }, marks, extremes, last !== -1 && !bars && dotAt(last, "tc-point-last"))];
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Sparkline: a tiny line, area or bar chart without axes, for stat tiles.
|
|
154
|
+
*
|
|
155
|
+
* ```ts
|
|
156
|
+
* new Chart('#el', { type: sparkline, data: [3, 5, 4, 7, 6], height: 40 })
|
|
157
|
+
* ```
|
|
158
|
+
*/
|
|
159
|
+
const sparkline = {
|
|
160
|
+
name: "sparkline",
|
|
161
|
+
clean: (options) => ({
|
|
162
|
+
...require_clean.cleanData(require_clean.numbers)(options),
|
|
163
|
+
labels: Array.isArray(options.labels) ? options.labels.map(require_clean.label) : void 0
|
|
164
|
+
}),
|
|
165
|
+
render: renderSparkline,
|
|
166
|
+
keyboard: false
|
|
167
|
+
};
|
|
168
|
+
//#endregion
|
|
169
|
+
Object.defineProperty(exports, "sparkline", {
|
|
170
|
+
enumerable: true,
|
|
171
|
+
get: function() {
|
|
172
|
+
return sparkline;
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
//# sourceMappingURL=sparkline-BS9-hltA.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sparkline-BS9-hltA.cjs","names":["insets","innerRect","domainOf","linear","formatNumber","labelKey","circlePath","h","round","barPath","areaPath","linePath","fadeMask","cleanData","numbers","label"],"sources":["../src/charts/sparkline.ts"],"sourcesContent":["import type { ChartType, RenderContext } from '../chart.ts'\nimport { fadeMask } from '../components/fade.ts'\nimport { formatNumber, type NumberFormat } from '../format.ts'\nimport type { Hit, HitItem, Interaction } from '../interaction.ts'\nimport { type InsetsInput, innerRect, insets, round } from '../layout.ts'\nimport { linear } from '../scales/linear.ts'\nimport { barPath } from '../shapes/bar.ts'\nimport { circlePath } from '../shapes/circle.ts'\nimport { areaPath, type Curve, linePath, type Point } from '../shapes/path.ts'\nimport { h } from '../vnode.ts'\nimport { domainOf, type Label, labelKey } from './cartesian.ts'\nimport { cleanData, label, numbers } from './clean.ts'\n\nexport interface SparklineOptions {\n /** The values; `null` leaves a gap. */\n data: readonly (number | null | undefined)[]\n /** Labels for the tooltip, one per value (e.g. dates). */\n labels?: readonly Label[]\n /** Name shown in the tooltip. Defaults to `'Value'`. */\n name?: string\n /**\n * `'line'` (default), `'area'`, `'bar'`, or `'tristate'`: only the sign\n * counts, as a full bar up (win), down (loss) or a tick on the middle (draw).\n */\n variant?: 'line' | 'area' | 'bar' | 'tristate'\n /** Interpolation for lines and areas. Defaults to `'monotone'`. */\n curve?: Curve\n /** Dot on the last value. Defaults to `'last'`. */\n point?: 'last' | 'none'\n /** Mark the minimum and maximum values. */\n markers?: 'minmax' | 'none'\n /** Dot radius in pixels. Defaults to `3`. */\n pointRadius?: number\n /** Include zero in the value range. Defaults to `true` for areas and bars, `false` for lines. */\n zero?: boolean\n /** Format of values in the tooltip. */\n format?: NumberFormat\n /** Extra space around the plot, in pixels. */\n padding?: InsetsInput\n}\n\nfunction renderSparkline(options: SparklineOptions, ctx: RenderContext) {\n const {\n variant = 'line',\n curve = 'monotone',\n point = 'last',\n markers = 'none',\n pointRadius = 3,\n name = 'Value',\n } = options\n const values = options.data.map((v) => (v == null || !Number.isFinite(v) ? null : v))\n // (No log option on sparklines, so finite is all that matters here.)\n const count = values.length\n const dots = point === 'last' || markers === 'minmax'\n // Room for the stroke and dots so nothing is clipped at the edges.\n const overhang = dots ? pointRadius + 2 : 2\n const pad = insets(options.padding, 0)\n const area = innerRect(ctx.width, ctx.height, {\n top: pad.top + overhang,\n right: pad.right + overhang,\n bottom: pad.bottom + overhang,\n left: pad.left + overhang,\n })\n const tristate = variant === 'tristate'\n const zero = options.zero ?? variant !== 'line'\n // Tristate bars span half the height each way, whatever the magnitude.\n const domain: [number, number] = tristate ? [-1, 1] : domainOf(values, { nice: false }, zero, 2)\n\n const bars = variant === 'bar' || tristate\n const gap = 1\n const slot = count > 0 ? area.width / count : 0\n const xAt = (i: number) =>\n bars\n ? area.x + slot * i + slot / 2\n : area.x + (count > 1 ? (area.width * i) / (count - 1) : area.width / 2)\n const y = linear(domain, [area.y + area.height, area.y])\n const baseline = y(Math.min(Math.max(0, domain[0]), domain[1]))\n const points: Point[] = values.map((v, i) => (v === null ? null : [xAt(i), y(v)]))\n\n const format = formatNumber(options.format, ctx.locale)\n const labelOf = (i: number) => {\n const label = options.labels?.[i]\n return label === undefined ? '' : String(label)\n }\n // Where a value is drawn: a tristate bar ends at its sign, not its magnitude.\n const yOf = (v: number) => y(tristate ? Math.sign(v) : v)\n const hitFor = (i: number): Hit | null => {\n const value = values[i]\n if (value === undefined) return null\n const px = xAt(i)\n const item: HitItem = {\n name,\n seriesIndex: 0,\n value,\n text: value === null ? '–' : format(value),\n x: px,\n y: value === null ? null : yOf(value),\n }\n const hit: Hit = {\n index: i,\n label: labelKey(options.labels?.[i] ?? i + 1),\n title: labelOf(i),\n x: px,\n area,\n items: [item],\n }\n if (value !== null) hit.mark = { d: circlePath(pointRadius + 3), x: px, y: yOf(value) }\n return hit\n }\n const interaction: Interaction = {\n count,\n hitIndex: (i) => hitFor(i),\n hitTest(px, py) {\n if (count === 0 || py < area.y - overhang || py > area.y + area.height + overhang) return null\n const i = bars\n ? Math.floor((px - area.x) / slot)\n : Math.round(((px - area.x) / Math.max(1, area.width)) * (count - 1))\n return hitFor(Math.max(0, Math.min(count - 1, i)))\n },\n }\n ctx.onHitTest(interaction)\n\n const marks = []\n if (tristate) {\n const width = Math.max(1, slot - gap)\n marks.push(\n h('line', {\n class: 'tc-sparkline-zero',\n x1: area.x,\n x2: area.x + area.width,\n y1: round(baseline),\n y2: round(baseline),\n }),\n )\n values.forEach((v, i) => {\n if (v === null) return\n const sign = Math.sign(v)\n // A draw is a short tick centered on the middle line.\n const tick = Math.min(2, area.height / 2)\n const [from, to] =\n sign === 0 ? [baseline + tick / 2, baseline - tick / 2] : [baseline, y(sign)]\n marks.push(\n h('path', {\n key: i,\n class: [\n 'tc-bar',\n sign < 0 && 'tc-bar-negative',\n sign < 0 ? 'tc-tristate-loss' : sign > 0 ? 'tc-tristate-win' : 'tc-tristate-draw',\n ],\n d: barPath(xAt(i) - width / 2, width, from, to, sign === 0 ? 0 : Math.min(2, width / 2)),\n }),\n )\n })\n } else if (bars) {\n const width = Math.max(1, slot - gap)\n values.forEach((v, i) => {\n if (v === null) return\n marks.push(\n h('path', {\n key: i,\n class: ['tc-bar', v < 0 && 'tc-bar-negative'],\n d: barPath(xAt(i) - width / 2, width, baseline, y(v), Math.min(2, width / 2)),\n }),\n )\n })\n } else {\n if (variant === 'area') {\n marks.push(\n h('path', {\n class: 'tc-area tc-area-gradient',\n d: areaPath(points, baseline, { curve }),\n mask: `url(#${ctx.id}-fade)`,\n }),\n )\n }\n marks.push(h('path', { class: 'tc-line', d: linePath(points, { curve }) }))\n }\n\n const dotAt = (i: number, cls: string) => {\n const v = values[i]\n return v == null\n ? null\n : h('circle', {\n key: `${cls}-${i}`,\n class: ['tc-point', cls],\n cx: round(xAt(i)),\n cy: round(y(v)),\n r: pointRadius,\n })\n }\n const extremes = []\n if (markers === 'minmax') {\n let min = -1\n let max = -1\n values.forEach((v, i) => {\n if (v === null) return\n if (min === -1 || v < (values[min] as number)) min = i\n if (max === -1 || v > (values[max] as number)) max = i\n })\n if (min !== -1) extremes.push(dotAt(min, 'tc-point-min'))\n if (max !== -1 && max !== min) extremes.push(dotAt(max, 'tc-point-max'))\n }\n let last = -1\n if (point === 'last') {\n for (let i = count - 1; i >= 0; i--) {\n if (values[i] !== null) {\n last = i\n break\n }\n }\n }\n\n return [\n variant === 'area' && h('defs', null, fadeMask(`${ctx.id}-fade`)),\n h(\n 'g',\n { class: 'tc-series tc-series-1 tc-sparkline' },\n marks,\n extremes,\n last !== -1 && !bars && dotAt(last, 'tc-point-last'),\n ),\n ]\n}\n\n/**\n * Sparkline: a tiny line, area or bar chart without axes, for stat tiles.\n *\n * ```ts\n * new Chart('#el', { type: sparkline, data: [3, 5, 4, 7, 6], height: 40 })\n * ```\n */\nexport const sparkline: ChartType<SparklineOptions> = {\n name: 'sparkline',\n // The labels too: they come from outside like the values.\n clean: (options) => ({\n ...cleanData(numbers)(options),\n labels: Array.isArray(options.labels) ? options.labels.map(label) : undefined,\n }),\n render: renderSparkline,\n // Decorative by default: opt in with `keyboard: true`.\n keyboard: false,\n}\n"],"mappings":";;;;;;;;;AAyCA,SAAS,gBAAgB,SAA2B,KAAoB;CACtE,MAAM,EACJ,UAAU,QACV,QAAQ,YACR,QAAQ,QACR,UAAU,QACV,cAAc,GACd,OAAO,YACL;CACJ,MAAM,SAAS,QAAQ,KAAK,KAAK,MAAO,KAAK,QAAQ,CAAC,OAAO,SAAS,CAAC,IAAI,OAAO,CAAE;CAEpF,MAAM,QAAQ,OAAO;CAGrB,MAAM,WAFO,UAAU,UAAU,YAAY,WAErB,cAAc,IAAI;CAC1C,MAAM,MAAMA,eAAAA,OAAO,QAAQ,SAAS,CAAC;CACrC,MAAM,OAAOC,eAAAA,UAAU,IAAI,OAAO,IAAI,QAAQ;EAC5C,KAAK,IAAI,MAAM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{ c as NumberFormat } from "./time-CHjiY9Q4.js";
|
|
4
|
+
import { t as Curve } from "./path-CwB28da0.js";
|
|
5
|
+
//#region src/charts/sparkline.d.ts
|
|
6
|
+
interface SparklineOptions {
|
|
7
|
+
/** The values; `null` leaves a gap. */
|
|
8
|
+
data: readonly (number | null | undefined)[];
|
|
9
|
+
/** Labels for the tooltip, one per value (e.g. dates). */
|
|
10
|
+
labels?: readonly Label[];
|
|
11
|
+
/** Name shown in the tooltip. Defaults to `'Value'`. */
|
|
12
|
+
name?: string;
|
|
13
|
+
/**
|
|
14
|
+
* `'line'` (default), `'area'`, `'bar'`, or `'tristate'`: only the sign
|
|
15
|
+
* counts, as a full bar up (win), down (loss) or a tick on the middle (draw).
|
|
16
|
+
*/
|
|
17
|
+
variant?: "line" | "area" | "bar" | "tristate";
|
|
18
|
+
/** Interpolation for lines and areas. Defaults to `'monotone'`. */
|
|
19
|
+
curve?: Curve;
|
|
20
|
+
/** Dot on the last value. Defaults to `'last'`. */
|
|
21
|
+
point?: "last" | "none";
|
|
22
|
+
/** Mark the minimum and maximum values. */
|
|
23
|
+
markers?: "minmax" | "none";
|
|
24
|
+
/** Dot radius in pixels. Defaults to `3`. */
|
|
25
|
+
pointRadius?: number;
|
|
26
|
+
/** Include zero in the value range. Defaults to `true` for areas and bars, `false` for lines. */
|
|
27
|
+
zero?: boolean;
|
|
28
|
+
/** Format of values in the tooltip. */
|
|
29
|
+
format?: NumberFormat;
|
|
30
|
+
/** Extra space around the plot, in pixels. */
|
|
31
|
+
padding?: InsetsInput;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Sparkline: a tiny line, area or bar chart without axes, for stat tiles.
|
|
35
|
+
*
|
|
36
|
+
* ```ts
|
|
37
|
+
* new Chart('#el', { type: sparkline, data: [3, 5, 4, 7, 6], height: 40 })
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
declare const sparkline: ChartType<SparklineOptions>;
|
|
41
|
+
//#endregion
|
|
42
|
+
export { sparkline as n, SparklineOptions as t };
|
|
43
|
+
//# sourceMappingURL=sparkline-iWuXbKpd.d.ts.map
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { f as seriesKey } from "./cartesian-Cr0AF0nG.js";
|
|
2
|
+
//#region src/charts/stack.ts
|
|
3
|
+
/**
|
|
4
|
+
* Stack series per category: positive values grow up from zero and
|
|
5
|
+
* negative values down from zero, each on their own running total (like
|
|
6
|
+
* d3's diverging offset), so gains and losses never interleave. Returns one
|
|
7
|
+
* array per series with a segment per category, or `null` for no segment.
|
|
8
|
+
*/
|
|
9
|
+
function stackSeries(series, count, options = {}) {
|
|
10
|
+
const { percent = false, nullAsZero = false, hidden } = options;
|
|
11
|
+
const visible = series.map((s) => !hidden?.has(seriesKey(s)));
|
|
12
|
+
const out = series.map(() => new Array(count).fill(null));
|
|
13
|
+
for (let i = 0; i < count; i++) {
|
|
14
|
+
let total = 0;
|
|
15
|
+
if (percent) series.forEach((s, j) => {
|
|
16
|
+
const v = s.values[i];
|
|
17
|
+
if (visible[j] && v != null) total += Math.abs(v);
|
|
18
|
+
});
|
|
19
|
+
let up = 0;
|
|
20
|
+
let down = 0;
|
|
21
|
+
let lastUp;
|
|
22
|
+
let lastDown;
|
|
23
|
+
for (let j = 0; j < series.length; j++) {
|
|
24
|
+
const s = series[j];
|
|
25
|
+
if (!visible[j]) continue;
|
|
26
|
+
const raw = s.values[i];
|
|
27
|
+
const valid = raw != null;
|
|
28
|
+
if (!valid && !nullAsZero) continue;
|
|
29
|
+
let v = valid ? raw : 0;
|
|
30
|
+
if (percent) v = total === 0 ? 0 : v / total;
|
|
31
|
+
const row = out[j];
|
|
32
|
+
if (v < 0) {
|
|
33
|
+
const segment = {
|
|
34
|
+
y0: down,
|
|
35
|
+
y1: down + v
|
|
36
|
+
};
|
|
37
|
+
row[i] = segment;
|
|
38
|
+
down += v;
|
|
39
|
+
lastDown = segment;
|
|
40
|
+
} else {
|
|
41
|
+
const segment = {
|
|
42
|
+
y0: up,
|
|
43
|
+
y1: up + v
|
|
44
|
+
};
|
|
45
|
+
row[i] = segment;
|
|
46
|
+
up += v;
|
|
47
|
+
lastUp = segment;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (percent) {
|
|
51
|
+
if (lastUp && Math.abs(up - 1) < 1e-9) lastUp.y1 = 1;
|
|
52
|
+
if (lastDown && Math.abs(down + 1) < 1e-9) lastDown.y1 = -1;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return out;
|
|
56
|
+
}
|
|
57
|
+
/** Every segment boundary, for the value domain. */
|
|
58
|
+
function stackBounds(stacks) {
|
|
59
|
+
const values = [];
|
|
60
|
+
for (const row of stacks) for (const segment of row) if (segment) values.push(segment.y0, segment.y1);
|
|
61
|
+
return values;
|
|
62
|
+
}
|
|
63
|
+
//#endregion
|
|
64
|
+
export { stackSeries as n, stackBounds as t };
|
|
65
|
+
|
|
66
|
+
//# sourceMappingURL=stack-DRbwTeF3.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stack-DRbwTeF3.js","names":[],"sources":["../src/charts/stack.ts"],"sourcesContent":["import { type Series, seriesKey } from './cartesian.ts'\n\n/** Stack series on top of each other; `'percent'` normalizes every category to 100%. */\nexport type StackMode = boolean | 'percent'\n\n/** A stacked segment from `y0` to `y1` (in data units). */\nexport interface Segment {\n y0: number\n y1: number\n}\n\nexport interface StackOptions {\n /** Normalize each category by the sum of absolute values. */\n percent?: boolean\n /** Count missing values as zero (areas) instead of leaving no segment (bars). */\n nullAsZero?: boolean\n /** Keys of hidden series, which get no segment and do not stack. */\n hidden?: ReadonlySet<string>\n}\n\n/**\n * Stack series per category: positive values grow up from zero and\n * negative values down from zero, each on their own running total (like\n * d3's diverging offset), so gains and losses never interleave. Returns one\n * array per series with a segment per category, or `null` for no segment.\n */\nexport function stackSeries(\n series: readonly Series[],\n count: number,\n options: StackOptions = {},\n): (Segment | null)[][] {\n const { percent = false, nullAsZero = false, hidden } = options\n const visible = series.map((s) => !hidden?.has(seriesKey(s)))\n const out = series.map(() => new Array<Segment | null>(count).fill(null))\n\n for (let i = 0; i < count; i++) {\n let total = 0\n if (percent) {\n series.forEach((s, j) => {\n const v = s.values[i]\n if (visible[j] && v != null) total += Math.abs(v)\n })\n }\n let up = 0\n let down = 0\n let lastUp: Segment | undefined\n let lastDown: Segment | undefined\n for (let j = 0; j < series.length; j++) {\n const s = series[j] as Series\n if (!visible[j]) continue\n const raw = s.values[i]\n const valid = raw != null\n if (!valid && !nullAsZero) continue\n let v = valid ? (raw as number) : 0\n if (percent) v = total === 0 ? 0 : v / total\n const row = out[j] as (Segment | null)[]\n if (v < 0) {\n const segment: Segment = { y0: down, y1: down + v }\n row[i] = segment\n down += v\n lastDown = segment\n } else {\n const segment: Segment = { y0: up, y1: up + v }\n row[i] = segment\n up += v\n lastUp = segment\n }\n }\n // Shares must end exactly at ±100%: floating point drift (1.0000000000000002)\n // would otherwise make nice() stretch the axis to 120%, or leave a hairline gap.\n if (percent) {\n if (lastUp && Math.abs(up - 1) < 1e-9) lastUp.y1 = 1\n if (lastDown && Math.abs(down + 1) < 1e-9) lastDown.y1 = -1\n }\n }\n return out\n}\n\n/** Every segment boundary, for the value domain. */\nexport function stackBounds(stacks: readonly (Segment | null)[][]): number[] {\n const values: number[] = []\n for (const row of stacks) {\n for (const segment of row) if (segment) values.push(segment.y0, segment.y1)\n }\n return values\n}\n"],"mappings":";;;;;;;;AA0BA,SAAgB,YACd,QACA,OACA,UAAwB,CAAC,GACH;CACtB,MAAM,EAAE,UAAU,OAAO,aAAa,OAAO,WAAW;CACxD,MAAM,UAAU,OAAO,KAAK,MAAM,CAAC,QAAQ,IAAI,UAAU,CAAC,CAAC,CAAC;CAC5D,MAAM,MAAM,OAAO,UAAU,IAAI,MAAsB,KAAK,CAAC,CAAC,KAAK,IAAI,CAAC;CAExE,KAAK,IAAI,IAAI,GAAG,IAAI,OAAO,KAAK;EAC9B,IAAI,QAAQ;E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