@tabler/charts 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +258 -2
- package/dist/annotations-Bp7HwtF5.d.ts +86 -0
- package/dist/annotations-BszTTjf9.js +202 -0
- package/dist/annotations-BszTTjf9.js.map +1 -0
- package/dist/annotations-DpETO8dE.cjs +213 -0
- package/dist/annotations-DpETO8dE.cjs.map +1 -0
- package/dist/annotations-lyt0I3HU.d.cts +86 -0
- package/dist/annotations.cjs +14 -0
- package/dist/annotations.cjs.map +1 -0
- package/dist/annotations.d.cts +2 -0
- package/dist/annotations.d.ts +2 -0
- package/dist/annotations.js +12 -0
- package/dist/annotations.js.map +1 -0
- package/dist/arc-BXpLrt9b.cjs +301 -0
- package/dist/arc-BXpLrt9b.cjs.map +1 -0
- package/dist/arc-a1tRTEw7.js +278 -0
- package/dist/arc-a1tRTEw7.js.map +1 -0
- package/dist/area-CF__HOwL.d.ts +20 -0
- package/dist/area-DIxaAbYZ.d.cts +20 -0
- package/dist/area-DQsLERhx.js +26 -0
- package/dist/area-DQsLERhx.js.map +1 -0
- package/dist/area-sHCE3pg5.cjs +31 -0
- package/dist/area-sHCE3pg5.cjs.map +1 -0
- package/dist/area.cjs +3 -0
- package/dist/area.d.cts +2 -0
- package/dist/area.d.ts +2 -0
- package/dist/area.js +2 -0
- package/dist/band-DTcNDAFO.d.cts +50 -0
- package/dist/band-DTcNDAFO.d.ts +50 -0
- package/dist/bar-BBM8RhoL.d.ts +43 -0
- package/dist/bar-C-7zR2qp.cjs +243 -0
- package/dist/bar-C-7zR2qp.cjs.map +1 -0
- package/dist/bar-CRKLDg98.d.cts +43 -0
- package/dist/bar-DGuUN3nc.cjs +67 -0
- package/dist/bar-DGuUN3nc.cjs.map +1 -0
- package/dist/bar-DM16NUvV.js +56 -0
- package/dist/bar-DM16NUvV.js.map +1 -0
- package/dist/bar-jZEoao74.js +238 -0
- package/dist/bar-jZEoao74.js.map +1 -0
- package/dist/bar.cjs +3 -0
- package/dist/bar.d.cts +2 -0
- package/dist/bar.d.ts +2 -0
- package/dist/bar.js +2 -0
- package/dist/candlestick-B5r1w3kc.cjs +150 -0
- package/dist/candlestick-B5r1w3kc.cjs.map +1 -0
- package/dist/candlestick-D_vV0_XZ.d.ts +44 -0
- package/dist/candlestick-DuXwAFID.js +145 -0
- package/dist/candlestick-DuXwAFID.js.map +1 -0
- package/dist/candlestick-__pXl_pV.d.cts +44 -0
- package/dist/candlestick.cjs +11 -0
- package/dist/candlestick.cjs.map +1 -0
- package/dist/candlestick.d.cts +2 -0
- package/dist/candlestick.d.ts +2 -0
- package/dist/candlestick.js +10 -0
- package/dist/candlestick.js.map +1 -0
- package/dist/cartesian-BoDfgBCV.cjs +900 -0
- package/dist/cartesian-BoDfgBCV.cjs.map +1 -0
- package/dist/cartesian-Cr0AF0nG.js +709 -0
- package/dist/cartesian-Cr0AF0nG.js.map +1 -0
- package/dist/chart-BF2CK9I_.js +790 -0
- package/dist/chart-BF2CK9I_.js.map +1 -0
- package/dist/chart-CowF_lWY.cjs +903 -0
- package/dist/chart-CowF_lWY.cjs.map +1 -0
- package/dist/chart-D7ooEFnk.d.cts +933 -0
- package/dist/chart-DyN7bcx8.d.ts +933 -0
- package/dist/circle-BQMuAfls.cjs +12 -0
- package/dist/circle-BQMuAfls.cjs.map +1 -0
- package/dist/circle-Z7YfCoCM.js +7 -0
- package/dist/circle-Z7YfCoCM.js.map +1 -0
- package/dist/clean-Byl6kzf0.cjs +115 -0
- package/dist/clean-Byl6kzf0.cjs.map +1 -0
- package/dist/clean-o1vDEhFV.js +56 -0
- package/dist/clean-o1vDEhFV.js.map +1 -0
- package/dist/core-CegR_j55.js +884 -0
- package/dist/core-CegR_j55.js.map +1 -0
- package/dist/core-D1vO1LrC.d.cts +220 -0
- package/dist/core-DcbemzGf.d.ts +220 -0
- package/dist/core-RzS9IQO5.cjs +985 -0
- package/dist/core-RzS9IQO5.cjs.map +1 -0
- package/dist/core.cjs +115 -0
- package/dist/core.d.cts +21 -0
- package/dist/core.d.ts +21 -0
- package/dist/core.js +25 -0
- package/dist/dates-Btm7Zm6W.cjs +32 -0
- package/dist/dates-Btm7Zm6W.cjs.map +1 -0
- package/dist/dates-CG-FvioW.js +27 -0
- package/dist/dates-CG-FvioW.js.map +1 -0
- package/dist/decimate-BGg9XgF0.d.ts +17 -0
- package/dist/decimate-C87cl_Sp.js +84 -0
- package/dist/decimate-C87cl_Sp.js.map +1 -0
- package/dist/decimate-CNSpgGa5.d.cts +17 -0
- package/dist/decimate-tLhDk1ys.cjs +95 -0
- package/dist/decimate-tLhDk1ys.cjs.map +1 -0
- package/dist/decimate.cjs +14 -0
- package/dist/decimate.cjs.map +1 -0
- package/dist/decimate.d.cts +2 -0
- package/dist/decimate.d.ts +2 -0
- package/dist/decimate.js +12 -0
- package/dist/decimate.js.map +1 -0
- package/dist/dom-CLF868Qs.cjs +222 -0
- package/dist/dom-CLF868Qs.cjs.map +1 -0
- package/dist/dom-vP3IcMak.js +175 -0
- package/dist/dom-vP3IcMak.js.map +1 -0
- package/dist/export-chart-9w8t3rjZ.js +232 -0
- package/dist/export-chart-9w8t3rjZ.js.map +1 -0
- package/dist/export-chart-BhhYgksr.cjs +249 -0
- package/dist/export-chart-BhhYgksr.cjs.map +1 -0
- package/dist/export.cjs +18 -0
- package/dist/export.cjs.map +1 -0
- package/dist/export.d.cts +2 -0
- package/dist/export.d.ts +2 -0
- package/dist/export.js +15 -0
- package/dist/export.js.map +1 -0
- package/dist/extent-BAMZo0Nq.js +19 -0
- package/dist/extent-BAMZo0Nq.js.map +1 -0
- package/dist/extent-DsFWvAHJ.cjs +24 -0
- package/dist/extent-DsFWvAHJ.cjs.map +1 -0
- package/dist/fade-Cs74puQS.cjs +217 -0
- package/dist/fade-Cs74puQS.cjs.map +1 -0
- package/dist/fade-D3NxH5Qg.js +200 -0
- package/dist/fade-D3NxH5Qg.js.map +1 -0
- package/dist/features-BclHgg2W.cjs +48 -0
- package/dist/features-BclHgg2W.cjs.map +1 -0
- package/dist/features-wASyHGic.js +25 -0
- package/dist/features-wASyHGic.js.map +1 -0
- package/dist/format-B0yKXBTH.cjs +183 -0
- package/dist/format-B0yKXBTH.cjs.map +1 -0
- package/dist/format-lStwuc1L.js +142 -0
- package/dist/format-lStwuc1L.js.map +1 -0
- package/dist/gauge-D-FYhuds.cjs +236 -0
- package/dist/gauge-D-FYhuds.cjs.map +1 -0
- package/dist/gauge-DP_EB2z3.d.cts +65 -0
- package/dist/gauge-Dh423FHh.js +231 -0
- package/dist/gauge-Dh423FHh.js.map +1 -0
- package/dist/gauge-zpia05t2.d.ts +65 -0
- package/dist/gauge.cjs +3 -0
- package/dist/gauge.d.cts +2 -0
- package/dist/gauge.d.ts +2 -0
- package/dist/gauge.js +2 -0
- package/dist/heatmap-BK18EBgJ.cjs +247 -0
- package/dist/heatmap-BK18EBgJ.cjs.map +1 -0
- package/dist/heatmap-BectCEeE.d.ts +81 -0
- package/dist/heatmap-CCso6m61.d.cts +81 -0
- package/dist/heatmap-DSZ2bVIa.js +242 -0
- package/dist/heatmap-DSZ2bVIa.js.map +1 -0
- package/dist/heatmap.cjs +3 -0
- package/dist/heatmap.d.cts +2 -0
- package/dist/heatmap.d.ts +2 -0
- package/dist/heatmap.js +2 -0
- package/dist/hydrate-CTTmQy0x.d.cts +10 -0
- package/dist/hydrate-CxwTXDqO.cjs +60 -0
- package/dist/hydrate-CxwTXDqO.cjs.map +1 -0
- package/dist/hydrate-CzfxLfTv.d.ts +10 -0
- package/dist/hydrate-DDNIHYv_.js +55 -0
- package/dist/hydrate-DDNIHYv_.js.map +1 -0
- package/dist/hydrate.cjs +13 -0
- package/dist/hydrate.cjs.map +1 -0
- package/dist/hydrate.d.cts +2 -0
- package/dist/hydrate.d.ts +2 -0
- package/dist/hydrate.js +12 -0
- package/dist/hydrate.js.map +1 -0
- package/dist/index.cjs +214 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +46 -0
- package/dist/index.d.ts +46 -0
- package/dist/index.js +115 -0
- package/dist/index.js.map +1 -0
- package/dist/layout-B3hiqVEw.js +69 -0
- package/dist/layout-B3hiqVEw.js.map +1 -0
- package/dist/layout-CtMBhNd9.cjs +98 -0
- package/dist/layout-CtMBhNd9.cjs.map +1 -0
- package/dist/line-B3Ed6u7j.js +120 -0
- package/dist/line-B3Ed6u7j.js.map +1 -0
- package/dist/line-CN4uZ9ZX.d.ts +47 -0
- package/dist/line-W7VD_qs1.d.cts +47 -0
- package/dist/line-fQbtP_jL.cjs +131 -0
- package/dist/line-fQbtP_jL.cjs.map +1 -0
- package/dist/line.cjs +14 -0
- package/dist/line.cjs.map +1 -0
- package/dist/line.d.cts +2 -0
- package/dist/line.d.ts +2 -0
- package/dist/line.js +13 -0
- package/dist/line.js.map +1 -0
- package/dist/log-CaofN3-n.d.cts +48 -0
- package/dist/log-CaofN3-n.d.ts +48 -0
- package/dist/log-axis-83rSpvL5.cjs +130 -0
- package/dist/log-axis-83rSpvL5.cjs.map +1 -0
- package/dist/log-axis-B_uvvOFc.js +113 -0
- package/dist/log-axis-B_uvvOFc.js.map +1 -0
- package/dist/log.cjs +17 -0
- package/dist/log.cjs.map +1 -0
- package/dist/log.d.cts +2 -0
- package/dist/log.d.ts +2 -0
- package/dist/log.js +16 -0
- package/dist/log.js.map +1 -0
- package/dist/morph-BMxz3X2b.d.cts +10 -0
- package/dist/morph-BMxz3X2b.d.ts +10 -0
- package/dist/morph-Bgg-24l8.js +36 -0
- package/dist/morph-Bgg-24l8.js.map +1 -0
- package/dist/morph-CqYDu1bY.cjs +41 -0
- package/dist/morph-CqYDu1bY.cjs.map +1 -0
- package/dist/morph.cjs +14 -0
- package/dist/morph.cjs.map +1 -0
- package/dist/morph.d.cts +2 -0
- package/dist/morph.d.ts +2 -0
- package/dist/morph.js +13 -0
- package/dist/morph.js.map +1 -0
- package/dist/named-BWWb5LQJ.cjs +50 -0
- package/dist/named-BWWb5LQJ.cjs.map +1 -0
- package/dist/named-DE15TOgh.js +33 -0
- package/dist/named-DE15TOgh.js.map +1 -0
- package/dist/parliament-1Zv2Xh0D.d.ts +69 -0
- package/dist/parliament-CpWnoEvG.cjs +308 -0
- package/dist/parliament-CpWnoEvG.cjs.map +1 -0
- package/dist/parliament-DdrLVZwt.d.cts +69 -0
- package/dist/parliament-Dw0sOERi.js +303 -0
- package/dist/parliament-Dw0sOERi.js.map +1 -0
- package/dist/parliament.cjs +3 -0
- package/dist/parliament.d.cts +2 -0
- package/dist/parliament.d.ts +2 -0
- package/dist/parliament.js +2 -0
- package/dist/path-CwB28da0.d.cts +29 -0
- package/dist/path-CwB28da0.d.ts +29 -0
- package/dist/patterns-DtgcnA8o.js +85 -0
- package/dist/patterns-DtgcnA8o.js.map +1 -0
- package/dist/patterns-LfcQAWCy.cjs +102 -0
- package/dist/patterns-LfcQAWCy.cjs.map +1 -0
- package/dist/patterns.cjs +15 -0
- package/dist/patterns.cjs.map +1 -0
- package/dist/patterns.d.cts +2 -0
- package/dist/patterns.d.ts +2 -0
- package/dist/patterns.js +12 -0
- package/dist/patterns.js.map +1 -0
- package/dist/pie-5z1fDdKO.d.ts +58 -0
- package/dist/pie-BF9yI5mE.d.cts +58 -0
- package/dist/pie-BxTZt6Go.cjs +212 -0
- package/dist/pie-BxTZt6Go.cjs.map +1 -0
- package/dist/pie-DzUXDTcn.js +201 -0
- package/dist/pie-DzUXDTcn.js.map +1 -0
- package/dist/pie.cjs +4 -0
- package/dist/pie.d.cts +2 -0
- package/dist/pie.d.ts +2 -0
- package/dist/pie.js +2 -0
- package/dist/point-shapes-CGl4dugc.cjs +166 -0
- package/dist/point-shapes-CGl4dugc.cjs.map +1 -0
- package/dist/point-shapes-DI84NNpI.js +155 -0
- package/dist/point-shapes-DI84NNpI.js.map +1 -0
- package/dist/point-shapes.cjs +15 -0
- package/dist/point-shapes.cjs.map +1 -0
- package/dist/point-shapes.d.cts +2 -0
- package/dist/point-shapes.d.ts +2 -0
- package/dist/point-shapes.js +13 -0
- package/dist/point-shapes.js.map +1 -0
- package/dist/radar-1-EryihA.d.ts +60 -0
- package/dist/radar-CYPab_I4.js +285 -0
- package/dist/radar-CYPab_I4.js.map +1 -0
- package/dist/radar-CoGUNNSb.cjs +290 -0
- package/dist/radar-CoGUNNSb.cjs.map +1 -0
- package/dist/radar-DBW4O0Vt.d.cts +60 -0
- package/dist/radar.cjs +3 -0
- package/dist/radar.d.cts +2 -0
- package/dist/radar.d.ts +2 -0
- package/dist/radar.js +2 -0
- package/dist/sankey-B4PNKusJ.js +420 -0
- package/dist/sankey-B4PNKusJ.js.map +1 -0
- package/dist/sankey-Bacx4fVe.cjs +425 -0
- package/dist/sankey-Bacx4fVe.cjs.map +1 -0
- package/dist/sankey-DuGI3Qc5.d.cts +67 -0
- package/dist/sankey-OV_WoPrl.d.ts +67 -0
- package/dist/sankey.cjs +3 -0
- package/dist/sankey.d.cts +2 -0
- package/dist/sankey.d.ts +2 -0
- package/dist/sankey.js +2 -0
- package/dist/scatter-BqzgJqdX.d.ts +61 -0
- package/dist/scatter-DbxLyZX0.d.cts +61 -0
- package/dist/scatter-DgMN9zRy.cjs +250 -0
- package/dist/scatter-DgMN9zRy.cjs.map +1 -0
- package/dist/scatter-kgtgR318.js +245 -0
- package/dist/scatter-kgtgR318.js.map +1 -0
- package/dist/scatter.cjs +3 -0
- package/dist/scatter.d.cts +2 -0
- package/dist/scatter.d.ts +2 -0
- package/dist/scatter.js +2 -0
- package/dist/sparkline-BQzt27Fr.js +171 -0
- package/dist/sparkline-BQzt27Fr.js.map +1 -0
- package/dist/sparkline-BS9-hltA.cjs +176 -0
- package/dist/sparkline-BS9-hltA.cjs.map +1 -0
- package/dist/sparkline-BfyO_oNM.d.ts +43 -0
- package/dist/sparkline-CWlJDKyh.d.cts +43 -0
- package/dist/sparkline.cjs +3 -0
- package/dist/sparkline.d.cts +2 -0
- package/dist/sparkline.d.ts +2 -0
- package/dist/sparkline.js +2 -0
- package/dist/stack-CpR6RGKd.d.cts +6 -0
- package/dist/stack-CpR6RGKd.d.ts +6 -0
- package/dist/stack-DRbwTeF3.js +66 -0
- package/dist/stack-DRbwTeF3.js.map +1 -0
- package/dist/stack-DVhJWaki.cjs +77 -0
- package/dist/stack-DVhJWaki.cjs.map +1 -0
- package/dist/style.css +2 -0
- package/dist/sweep-CbfR7--d.js +60 -0
- package/dist/sweep-CbfR7--d.js.map +1 -0
- package/dist/sweep-DaTEDDuC.cjs +71 -0
- package/dist/sweep-DaTEDDuC.cjs.map +1 -0
- package/dist/time-CHjiY9Q4.d.ts +112 -0
- package/dist/time-CNVnt-B2.d.cts +112 -0
- package/dist/time-axis-Bc9eHX1r.js +365 -0
- package/dist/time-axis-Bc9eHX1r.js.map +1 -0
- package/dist/time-axis-VSX34_Tb.cjs +382 -0
- package/dist/time-axis-VSX34_Tb.cjs.map +1 -0
- package/dist/time.cjs +22 -0
- package/dist/time.cjs.map +1 -0
- package/dist/time.d.cts +2 -0
- package/dist/time.d.ts +2 -0
- package/dist/time.js +20 -0
- package/dist/time.js.map +1 -0
- package/dist/tween-BCYd0RTY.js +40 -0
- package/dist/tween-BCYd0RTY.js.map +1 -0
- package/dist/tween-CIGBlryn.cjs +51 -0
- package/dist/tween-CIGBlryn.cjs.map +1 -0
- package/dist/value-labels-B0WJoJ7x.cjs +134 -0
- package/dist/value-labels-B0WJoJ7x.cjs.map +1 -0
- package/dist/value-labels-IZIQPhfk.js +123 -0
- package/dist/value-labels-IZIQPhfk.js.map +1 -0
- package/dist/value-labels.cjs +14 -0
- package/dist/value-labels.cjs.map +1 -0
- package/dist/value-labels.d.cts +2 -0
- package/dist/value-labels.d.ts +2 -0
- package/dist/value-labels.js +12 -0
- package/dist/value-labels.js.map +1 -0
- package/dist/vnode-BUflsBsa.d.cts +66 -0
- package/dist/vnode-BUflsBsa.d.ts +66 -0
- package/dist/vnode-CkQ27Cxe.cjs +110 -0
- package/dist/vnode-CkQ27Cxe.cjs.map +1 -0
- package/dist/vnode-tCWItoUH.js +93 -0
- package/dist/vnode-tCWItoUH.js.map +1 -0
- package/package.json +320 -3
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { $ as CartesianOptions, a as ChartType } from "./chart-DyN7bcx8.js";
|
|
2
|
+
import { t as Curve } from "./path-CwB28da0.js";
|
|
3
|
+
import { t as StackMode } from "./stack-CpR6RGKd.js";
|
|
4
|
+
//#region src/charts/bar.d.ts
|
|
5
|
+
interface BarOptions extends CartesianOptions {
|
|
6
|
+
/** Corner radius of the data end of each bar (or stack). Defaults to `4`. */
|
|
7
|
+
radius?: number;
|
|
8
|
+
/** Maximum bar thickness in pixels; leftover band space stays empty. Defaults to `24`. */
|
|
9
|
+
maxBarWidth?: number;
|
|
10
|
+
/** Gap between bars of a group, or between stacked segments, in pixels. Defaults to `2`. */
|
|
11
|
+
gap?: number;
|
|
12
|
+
/** Share of each category left empty between groups, `0…1`. Defaults to `0.3`. */
|
|
13
|
+
groupPadding?: number;
|
|
14
|
+
/**
|
|
15
|
+
* Stack series in one bar per category instead of side by side; `'percent'`
|
|
16
|
+
* shows each category as 100%. Negative values stack down from zero.
|
|
17
|
+
*/
|
|
18
|
+
stacked?: StackMode;
|
|
19
|
+
/**
|
|
20
|
+
* `'horizontal'` lays categories out along y with bars growing right
|
|
21
|
+
* (left for negative values). The `x` / `y` options keep describing the
|
|
22
|
+
* category / value axis. Defaults to `'vertical'`.
|
|
23
|
+
*/
|
|
24
|
+
orientation?: "vertical" | "horizontal";
|
|
25
|
+
/** Interpolation of series drawn as lines (`series.type`). Defaults to `'monotone'`. */
|
|
26
|
+
curve?: Curve;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Bar chart: vertical bars per category, grouped side by side or stacked,
|
|
30
|
+
* growing from zero (negative values grow down).
|
|
31
|
+
*
|
|
32
|
+
* ```ts
|
|
33
|
+
* new Chart('#el', {
|
|
34
|
+
* type: bar,
|
|
35
|
+
* data: { labels: ['Q1', 'Q2'], series: [{ name: '2025', values: [3, 5] }] },
|
|
36
|
+
* stacked: true,
|
|
37
|
+
* })
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
declare const bar: ChartType<BarOptions>;
|
|
41
|
+
//#endregion
|
|
42
|
+
export { bar as n, BarOptions as t };
|
|
43
|
+
//# sourceMappingURL=bar-BBM8RhoL.d.ts.map
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
const require_layout = require("./layout-CtMBhNd9.cjs");
|
|
2
|
+
const require_vnode = require("./vnode-CkQ27Cxe.cjs");
|
|
3
|
+
const require_cartesian = require("./cartesian-BoDfgBCV.cjs");
|
|
4
|
+
const require_features = require("./features-BclHgg2W.cjs");
|
|
5
|
+
const require_clean = require("./clean-Byl6kzf0.cjs");
|
|
6
|
+
const require_stack = require("./stack-DVhJWaki.cjs");
|
|
7
|
+
const require_bar = require("./bar-DGuUN3nc.cjs");
|
|
8
|
+
//#region src/charts/horizontal.ts
|
|
9
|
+
/**
|
|
10
|
+
* Cartesian layout with categories along y (labels on the left) and values
|
|
11
|
+
* along x (labels at the bottom), for horizontal bars. Only bar charts use
|
|
12
|
+
* it, so it lives outside `cartesianLayout()` and stays out of other bundles.
|
|
13
|
+
*/
|
|
14
|
+
function horizontalLayout(options, ctx, layout) {
|
|
15
|
+
const yOptions = options.y ?? {};
|
|
16
|
+
const xOptions = options.x ?? {};
|
|
17
|
+
const { fontSize, width, height } = ctx;
|
|
18
|
+
const overhang = layout.overhang ?? 0;
|
|
19
|
+
const pad = require_layout.insets(options.padding);
|
|
20
|
+
const labels = require_cartesian.resolveLabels(options.data);
|
|
21
|
+
const format = require_cartesian.labelFormatter(options, ctx);
|
|
22
|
+
const value = require_cartesian.valueAxis(options, ctx, layout, Math.round(width / 80));
|
|
23
|
+
const probeValues = value.probe;
|
|
24
|
+
const showValues = yOptions.show !== false;
|
|
25
|
+
const showCategories = xOptions.show !== false && labels.length > 0;
|
|
26
|
+
const probeCategories = labels.map((label, i) => ({
|
|
27
|
+
value: require_cartesian.labelKey(label),
|
|
28
|
+
position: 0,
|
|
29
|
+
label: format(label, i)
|
|
30
|
+
}));
|
|
31
|
+
const edgeLabel = (tick) => showValues && tick ? Math.ceil(require_layout.estimateTextWidth(tick.label, fontSize) / 2) : 0;
|
|
32
|
+
const margins = {
|
|
33
|
+
top: pad.top + Math.max(overhang, 4),
|
|
34
|
+
right: pad.right + Math.max(edgeLabel(probeValues[probeValues.length - 1]), overhang, 8),
|
|
35
|
+
bottom: pad.bottom + Math.max(showValues ? require_cartesian.axisSize("bottom", probeValues, fontSize) : 0, overhang, 4),
|
|
36
|
+
left: pad.left + Math.max(showCategories ? require_cartesian.axisSize("left", probeCategories, fontSize) : 0, edgeLabel(probeValues[0]), overhang, 8)
|
|
37
|
+
};
|
|
38
|
+
const area = require_layout.innerRect(width, height, margins);
|
|
39
|
+
const keys = labels.map(require_cartesian.labelKey);
|
|
40
|
+
const x = require_cartesian.band(keys, [area.y, area.y + area.height], {
|
|
41
|
+
paddingInner: layout.paddingInner ?? .3,
|
|
42
|
+
paddingOuter: layout.paddingOuter ?? .15
|
|
43
|
+
});
|
|
44
|
+
const y = value.scale([area.x, area.x + area.width]);
|
|
45
|
+
const yTicks = require_cartesian.thinTicks(value.ticks(y), "bottom", fontSize);
|
|
46
|
+
const xTicks = showCategories ? require_cartesian.thinTicks(require_cartesian.bandTicks(x, (_, i) => format(labels[i], i)), "left", fontSize) : [];
|
|
47
|
+
return require_cartesian.finishLayout(options, ctx, overhang, {
|
|
48
|
+
area,
|
|
49
|
+
labels,
|
|
50
|
+
x,
|
|
51
|
+
y,
|
|
52
|
+
horizontal: true,
|
|
53
|
+
xTicks,
|
|
54
|
+
yTicks
|
|
55
|
+
}, keys);
|
|
56
|
+
}
|
|
57
|
+
//#endregion
|
|
58
|
+
//#region src/charts/bar.ts
|
|
59
|
+
/**
|
|
60
|
+
* Bar chart: vertical bars per category, grouped side by side or stacked,
|
|
61
|
+
* growing from zero (negative values grow down).
|
|
62
|
+
*
|
|
63
|
+
* ```ts
|
|
64
|
+
* new Chart('#el', {
|
|
65
|
+
* type: bar,
|
|
66
|
+
* data: { labels: ['Q1', 'Q2'], series: [{ name: '2025', values: [3, 5] }] },
|
|
67
|
+
* stacked: true,
|
|
68
|
+
* })
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
const bar = {
|
|
72
|
+
name: "bar",
|
|
73
|
+
clean: require_clean.cleanData(require_clean.cleanSeries),
|
|
74
|
+
render(options, ctx) {
|
|
75
|
+
const { radius = 4, maxBarWidth = 24, gap = 2, groupPadding = .3, stacked = false, orientation = "vertical", curve = "monotone" } = options;
|
|
76
|
+
const horizontal = orientation === "horizontal";
|
|
77
|
+
const { series } = options.data;
|
|
78
|
+
const count = require_cartesian.resolveLabels(options.data).length;
|
|
79
|
+
const isLine = (index) => (series[index]?.type ?? "bar") !== "bar";
|
|
80
|
+
const lineKeys = series.filter((_, index) => isLine(index)).map(require_cartesian.seriesKey);
|
|
81
|
+
const stackHidden = lineKeys.length ? /* @__PURE__ */ new Set([...ctx.hidden, ...lineKeys]) : ctx.hidden;
|
|
82
|
+
const stacks = stacked ? require_stack.stackSeries(series, count, {
|
|
83
|
+
percent: stacked === "percent",
|
|
84
|
+
hidden: stackHidden
|
|
85
|
+
}) : null;
|
|
86
|
+
const layoutOptions = {
|
|
87
|
+
scale: "band",
|
|
88
|
+
zero: true,
|
|
89
|
+
paddingInner: groupPadding,
|
|
90
|
+
paddingOuter: groupPadding / 2,
|
|
91
|
+
...stacks ? { values: [...require_stack.stackBounds(stacks), ...series.flatMap((s, index) => isLine(index) ? s.values : [])] } : {},
|
|
92
|
+
...stacked === "percent" ? { tickFormat: { style: "percent" } } : {}
|
|
93
|
+
};
|
|
94
|
+
const layout = horizontal ? horizontalLayout(options, ctx, layoutOptions) : require_cartesian.cartesianLayout(options, ctx, layoutOptions);
|
|
95
|
+
const { x, y, labels } = layout;
|
|
96
|
+
const slots = /* @__PURE__ */ new Map();
|
|
97
|
+
series.forEach((s, index) => {
|
|
98
|
+
if (!ctx.hidden.has(require_cartesian.seriesKey(s)) && !isLine(index)) slots.set(index, slots.size);
|
|
99
|
+
});
|
|
100
|
+
const order = [...slots.keys()];
|
|
101
|
+
const columns = stacks ? 1 : Math.max(1, slots.size);
|
|
102
|
+
const barWidth = Math.max(0, Math.min(maxBarWidth, (x.bandwidth - (stacks ? 0 : gap * (columns - 1))) / columns));
|
|
103
|
+
const groupWidth = barWidth * columns + (stacks ? 0 : gap * (columns - 1));
|
|
104
|
+
const offset = (x.bandwidth - groupWidth) / 2;
|
|
105
|
+
const barLeft = (seriesIndex, i) => x.at(i) + offset + (stacks ? 0 : (slots.get(seriesIndex) ?? 0) * (barWidth + gap));
|
|
106
|
+
/** Data extent of a bar: from zero to the value, or its stacked segment. */
|
|
107
|
+
const segment = (seriesIndex, i) => {
|
|
108
|
+
if (stacks) return stacks[seriesIndex]?.[i] ?? null;
|
|
109
|
+
const v = series[seriesIndex]?.values[i];
|
|
110
|
+
return require_cartesian.plottable(v, options.y) ? {
|
|
111
|
+
y0: 0,
|
|
112
|
+
y1: v
|
|
113
|
+
} : null;
|
|
114
|
+
};
|
|
115
|
+
const outer = labels.map((_, i) => {
|
|
116
|
+
let up = -1;
|
|
117
|
+
let down = -1;
|
|
118
|
+
for (const index of order) {
|
|
119
|
+
const seg = segment(index, i);
|
|
120
|
+
if (!seg) continue;
|
|
121
|
+
if (seg.y1 > seg.y0) up = index;
|
|
122
|
+
else if (seg.y1 < seg.y0) down = index;
|
|
123
|
+
}
|
|
124
|
+
return {
|
|
125
|
+
up,
|
|
126
|
+
down
|
|
127
|
+
};
|
|
128
|
+
});
|
|
129
|
+
ctx.onHitTest(require_cartesian.categoryInteraction(layout, options, ctx, (seriesIndex, i, v) => {
|
|
130
|
+
if (isLine(seriesIndex)) {
|
|
131
|
+
const across = x.at(i) + x.bandwidth / 2;
|
|
132
|
+
return horizontal ? {
|
|
133
|
+
x: y(v),
|
|
134
|
+
y: across
|
|
135
|
+
} : {
|
|
136
|
+
x: across,
|
|
137
|
+
y: y(v)
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
const left = barLeft(seriesIndex, i);
|
|
141
|
+
const seg = segment(seriesIndex, i);
|
|
142
|
+
const end = y(seg?.y1 ?? 0);
|
|
143
|
+
const base = y(seg?.y0 ?? 0);
|
|
144
|
+
const lo = Math.min(end, base);
|
|
145
|
+
const length = Math.abs(end - base);
|
|
146
|
+
return horizontal ? {
|
|
147
|
+
x: end,
|
|
148
|
+
y: left + barWidth / 2,
|
|
149
|
+
box: {
|
|
150
|
+
x: lo,
|
|
151
|
+
y: left,
|
|
152
|
+
width: length,
|
|
153
|
+
height: barWidth
|
|
154
|
+
}
|
|
155
|
+
} : {
|
|
156
|
+
x: left + barWidth / 2,
|
|
157
|
+
y: end,
|
|
158
|
+
box: {
|
|
159
|
+
x: left,
|
|
160
|
+
y: lo,
|
|
161
|
+
width: barWidth,
|
|
162
|
+
height: length
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
}, (px, py, i) => {
|
|
166
|
+
const across = horizontal ? py : px;
|
|
167
|
+
const along = horizontal ? px : py;
|
|
168
|
+
if (stacks) {
|
|
169
|
+
const left = barLeft(0, i);
|
|
170
|
+
if (across < left - gap / 2 || across > left + barWidth + gap / 2) return void 0;
|
|
171
|
+
return order.find((index) => {
|
|
172
|
+
const seg = segment(index, i);
|
|
173
|
+
if (!seg) return false;
|
|
174
|
+
const a = y(seg.y0);
|
|
175
|
+
const b = y(seg.y1);
|
|
176
|
+
return along >= Math.min(a, b) - gap / 2 && along <= Math.max(a, b) + gap / 2;
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
const slot = Math.floor((across - (x.at(i) + offset) + gap / 2) / (barWidth + gap));
|
|
180
|
+
const seriesIndex = order[slot];
|
|
181
|
+
return seriesIndex !== void 0 && segment(seriesIndex, i) ? seriesIndex : void 0;
|
|
182
|
+
}));
|
|
183
|
+
const groups = series.map((s, index) => slots.has(index) && require_vnode.h("g", require_cartesian.seriesAttrs(s, index), labels.map((label, i) => {
|
|
184
|
+
const seg = segment(index, i);
|
|
185
|
+
if (!seg) return null;
|
|
186
|
+
const negative = seg.y1 < seg.y0;
|
|
187
|
+
const away = (negative ? 1 : -1) * (horizontal ? -1 : 1);
|
|
188
|
+
const inner = seg.y0 === 0 ? 0 : away * gap;
|
|
189
|
+
const rounded = !stacks || (negative ? outer[i]?.down : outer[i]?.up) === index;
|
|
190
|
+
const draw = horizontal ? require_bar.hbarPath : require_bar.barPath;
|
|
191
|
+
return require_vnode.h("path", {
|
|
192
|
+
key: require_cartesian.labelKey(label),
|
|
193
|
+
class: [
|
|
194
|
+
"tc-bar",
|
|
195
|
+
negative && "tc-bar-negative",
|
|
196
|
+
horizontal && "tc-bar-horizontal"
|
|
197
|
+
],
|
|
198
|
+
d: draw(barLeft(index, i), barWidth, y(seg.y0) + inner, y(seg.y1), rounded ? radius : 0)
|
|
199
|
+
});
|
|
200
|
+
})));
|
|
201
|
+
const paths = lineKeys.length ? require_features.feature("line") : null;
|
|
202
|
+
const baseline = y(Math.min(Math.max(0, y.domain[0]), y.domain[1]));
|
|
203
|
+
const lines = series.map((s, index) => {
|
|
204
|
+
if (!paths) return null;
|
|
205
|
+
if (!isLine(index) || ctx.hidden.has(require_cartesian.seriesKey(s))) return null;
|
|
206
|
+
const points = labels.map((_, i) => {
|
|
207
|
+
const v = s.values[i];
|
|
208
|
+
if (!require_cartesian.plottable(v, options.y)) return null;
|
|
209
|
+
const center = x.at(i) + x.bandwidth / 2;
|
|
210
|
+
return horizontal ? [y(v), center] : [center, y(v)];
|
|
211
|
+
});
|
|
212
|
+
const filled = s.type === "area" && !horizontal;
|
|
213
|
+
return require_vnode.h("g", require_cartesian.seriesAttrs(s, index), filled && require_vnode.h("path", {
|
|
214
|
+
class: "tc-area",
|
|
215
|
+
d: paths.areaPath(points, baseline, { curve })
|
|
216
|
+
}), require_vnode.h("path", {
|
|
217
|
+
class: "tc-line",
|
|
218
|
+
d: paths.linePath(points, { curve })
|
|
219
|
+
}));
|
|
220
|
+
});
|
|
221
|
+
return [
|
|
222
|
+
require_vnode.h("defs", { key: "defs" }, layout.clip.def),
|
|
223
|
+
layout.background,
|
|
224
|
+
require_vnode.h("g", {
|
|
225
|
+
key: "series",
|
|
226
|
+
class: "tc-series-list",
|
|
227
|
+
"clip-path": layout.clip.url
|
|
228
|
+
}, groups, lines),
|
|
229
|
+
layout.foreground
|
|
230
|
+
];
|
|
231
|
+
},
|
|
232
|
+
legend: (options) => require_cartesian.seriesLegend(options.data),
|
|
233
|
+
table: (options, ctx, limit) => require_cartesian.seriesTable(options, ctx, limit)
|
|
234
|
+
};
|
|
235
|
+
//#endregion
|
|
236
|
+
Object.defineProperty(exports, "bar", {
|
|
237
|
+
enumerable: true,
|
|
238
|
+
get: function() {
|
|
239
|
+
return bar;
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
//# sourceMappingURL=bar-C-7zR2qp.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bar-C-7zR2qp.cjs","names":["insets","resolveLabels","labelFormatter","valueAxis","labelKey","estimateTextWidth","axisSize","innerRect","band","thinTicks","bandTicks","finishLayout","cleanData","cleanSeries","resolveLabels","seriesKey","stackSeries","stackBounds","cartesianLayout","plottable","categoryInteraction","h","seriesAttrs","hbarPath","barPath","labelKey","feature","seriesLegend","seriesTable"],"sources":["../src/charts/horizontal.ts","../src/charts/bar.ts"],"sourcesContent":["import type { RenderContext } from '../chart.ts'\nimport { axisSize, bandTicks, type Tick, thinTicks } from '../components/axis.ts'\nimport { estimateTextWidth, innerRect, insets } from '../layout.ts'\nimport { type BandKey, band } from '../scales/band.ts'\nimport {\n type CartesianLayout,\n type CartesianLayoutOptions,\n type CartesianOptions,\n EDGE,\n finishLayout,\n type Label,\n labelFormatter,\n labelKey,\n resolveLabels,\n TICK_SPACING_X,\n valueAxis,\n} from './cartesian.ts'\n\n/**\n * Cartesian layout with categories along y (labels on the left) and values\n * along x (labels at the bottom), for horizontal bars. Only bar charts use\n * it, so it lives outside `cartesianLayout()` and stays out of other bundles.\n */\nexport function horizontalLayout(\n options: CartesianOptions,\n ctx: RenderContext,\n layout: CartesianLayoutOptions,\n): CartesianLayout {\n const yOptions = options.y ?? {}\n const xOptions = options.x ?? {}\n const { fontSize, width, height } = ctx\n const overhang = layout.overhang ?? 0\n const pad = insets(options.padding)\n const labels = resolveLabels(options.data)\n const format = labelFormatter(options, ctx)\n const value = valueAxis(options, ctx, layout, Math.round(width / TICK_SPACING_X))\n const probeValues = value.probe\n const showValues = yOptions.show !== false\n const showCategories = xOptions.show !== false && labels.length > 0\n\n const probeCategories: Tick[] = labels.map((label, i) => ({\n value: labelKey(label),\n position: 0,\n label: format(label, i),\n }))\n const edgeLabel = (tick: Tick | undefined) =>\n showValues && tick ? Math.ceil(estimateTextWidth(tick.label, fontSize) / 2) : 0\n\n const margins = {\n top: pad.top + Math.max(overhang, EDGE / 2),\n right: pad.right + Math.max(edgeLabel(probeValues[probeValues.length - 1]), overhang, EDGE),\n bottom:\n pad.bottom +\n Math.max(showValues ? axisSize('bottom', probeValues, fontSize) : 0, overhang, EDGE / 2),\n left:\n pad.left +\n Math.max(\n showCategories ? axisSize('left', probeCategories, fontSize) : 0,\n edgeLabel(probeValues[0]),\n overhang,\n EDGE,\n ),\n }\n const area = innerRect(width, height, margins)\n\n const keys = labels.map(labelKey)\n const x = band(keys, [area.y, area.y + area.height], {\n paddingInner: layout.paddingInner ?? 0.3,\n paddingOuter: layout.paddingOuter ?? 0.15,\n })\n const y = value.scale([area.x, area.x + area.width])\n const yTicks = thinTicks(value.ticks(y), 'bottom', fontSize)\n const xTicks = showCategories\n ? thinTicks(\n bandTicks(x, (_: BandKey, i) => format(labels[i] as Label, i)),\n 'left',\n fontSize,\n )\n : []\n\n // The value axis runs along x here, categories along y.\n return finishLayout(\n options,\n ctx,\n overhang,\n { area, labels, x, y, horizontal: true, xTicks, yTicks },\n keys,\n )\n}\n","import type { ChartType } from '../chart.ts'\nimport { feature } from '../features.ts'\nimport { barPath, hbarPath } from '../shapes/bar.ts'\nimport type { Curve, Point } from '../shapes/path.ts'\nimport { h } from '../vnode.ts'\nimport {\n type CartesianLayoutOptions,\n type CartesianOptions,\n cartesianLayout,\n categoryInteraction,\n labelKey,\n plottable,\n resolveLabels,\n seriesAttrs,\n seriesKey,\n seriesLegend,\n seriesTable,\n} from './cartesian.ts'\nimport { cleanData, cleanSeries } from './clean.ts'\nimport { horizontalLayout } from './horizontal.ts'\nimport { type Segment, type StackMode, stackBounds, stackSeries } from './stack.ts'\n\nexport interface BarOptions extends CartesianOptions {\n /** Corner radius of the data end of each bar (or stack). Defaults to `4`. */\n radius?: number\n /** Maximum bar thickness in pixels; leftover band space stays empty. Defaults to `24`. */\n maxBarWidth?: number\n /** Gap between bars of a group, or between stacked segments, in pixels. Defaults to `2`. */\n gap?: number\n /** Share of each category left empty between groups, `0…1`. Defaults to `0.3`. */\n groupPadding?: number\n /**\n * Stack series in one bar per category instead of side by side; `'percent'`\n * shows each category as 100%. Negative values stack down from zero.\n */\n stacked?: StackMode\n /**\n * `'horizontal'` lays categories out along y with bars growing right\n * (left for negative values). The `x` / `y` options keep describing the\n * category / value axis. Defaults to `'vertical'`.\n */\n orientation?: 'vertical' | 'horizontal'\n /** Interpolation of series drawn as lines (`series.type`). Defaults to `'monotone'`. */\n curve?: Curve\n}\n\n/**\n * Bar chart: vertical bars per category, grouped side by side or stacked,\n * growing from zero (negative values grow down).\n *\n * ```ts\n * new Chart('#el', {\n * type: bar,\n * data: { labels: ['Q1', 'Q2'], series: [{ name: '2025', values: [3, 5] }] },\n * stacked: true,\n * })\n * ```\n */\nexport const bar: ChartType<BarOptions> = {\n name: 'bar',\n clean: cleanData(cleanSeries),\n render(options, ctx) {\n const {\n radius = 4,\n maxBarWidth = 24,\n gap = 2,\n groupPadding = 0.3,\n stacked = false,\n orientation = 'vertical',\n curve = 'monotone',\n } = options\n const horizontal = orientation === 'horizontal'\n const { series } = options.data\n const count = resolveLabels(options.data).length\n // Series drawn as lines sit on top of the bars and stay out of the stacks.\n const isLine = (index: number) => (series[index]?.type ?? 'bar') !== 'bar'\n const lineKeys = series.filter((_, index) => isLine(index)).map(seriesKey)\n const stackHidden = lineKeys.length ? new Set([...ctx.hidden, ...lineKeys]) : ctx.hidden\n const stacks = stacked\n ? stackSeries(series, count, { percent: stacked === 'percent', hidden: stackHidden })\n : null\n\n const layoutOptions: CartesianLayoutOptions = {\n scale: 'band',\n zero: true,\n paddingInner: groupPadding,\n paddingOuter: groupPadding / 2,\n ...(stacks\n ? {\n values: [\n ...stackBounds(stacks),\n ...series.flatMap((s, index) => (isLine(index) ? s.values : [])),\n ],\n }\n : {}),\n ...(stacked === 'percent' ? { tickFormat: { style: 'percent' } } : {}),\n }\n const layout = horizontal\n ? horizontalLayout(options, ctx, layoutOptions)\n : cartesianLayout(options, ctx, layoutOptions)\n const { x, y, labels } = layout\n\n // Hidden series keep their color slot but give up their place in the group.\n const slots = new Map<number, number>()\n series.forEach((s, index) => {\n if (!ctx.hidden.has(seriesKey(s)) && !isLine(index)) slots.set(index, slots.size)\n })\n const order = [...slots.keys()]\n const columns = stacks ? 1 : Math.max(1, slots.size)\n\n const barWidth = Math.max(\n 0,\n Math.min(maxBarWidth, (x.bandwidth - (stacks ? 0 : gap * (columns - 1))) / columns),\n )\n const groupWidth = barWidth * columns + (stacks ? 0 : gap * (columns - 1))\n const offset = (x.bandwidth - groupWidth) / 2\n const barLeft = (seriesIndex: number, i: number) =>\n x.at(i) + offset + (stacks ? 0 : (slots.get(seriesIndex) ?? 0) * (barWidth + gap))\n\n /** Data extent of a bar: from zero to the value, or its stacked segment. */\n const segment = (seriesIndex: number, i: number): Segment | null => {\n if (stacks) return stacks[seriesIndex]?.[i] ?? null\n const v = series[seriesIndex]?.values[i]\n return plottable(v, options.y) ? { y0: 0, y1: v } : null\n }\n\n // In a stack only the outermost segment of each sign gets rounded.\n const outer = labels.map((_, i) => {\n let up = -1\n let down = -1\n for (const index of order) {\n const seg = segment(index, i)\n if (!seg) continue\n if (seg.y1 > seg.y0) up = index\n else if (seg.y1 < seg.y0) down = index\n }\n return { up, down }\n })\n\n ctx.onHitTest(\n categoryInteraction(\n layout,\n options,\n ctx,\n (seriesIndex, i, v) => {\n if (isLine(seriesIndex)) {\n const across = x.at(i) + x.bandwidth / 2\n return horizontal ? { x: y(v), y: across } : { x: across, y: y(v) }\n }\n const left = barLeft(seriesIndex, i)\n const seg = segment(seriesIndex, i)\n const end = y(seg?.y1 ?? 0)\n const base = y(seg?.y0 ?? 0)\n // The bar's box, for value labels inside it.\n const lo = Math.min(end, base)\n const length = Math.abs(end - base)\n return horizontal\n ? {\n x: end,\n y: left + barWidth / 2,\n box: { x: lo, y: left, width: length, height: barWidth },\n }\n : {\n x: left + barWidth / 2,\n y: end,\n box: { x: left, y: lo, width: barWidth, height: length },\n }\n },\n (px, py, i) => {\n // Pointer position across the categories and along the values.\n const across = horizontal ? py : px\n const along = horizontal ? px : py\n if (stacks) {\n // The segment under the pointer, within the column (gaps included).\n const left = barLeft(0, i)\n if (across < left - gap / 2 || across > left + barWidth + gap / 2) return undefined\n return order.find((index) => {\n const seg = segment(index, i)\n if (!seg) return false\n const a = y(seg.y0)\n const b = y(seg.y1)\n return along >= Math.min(a, b) - gap / 2 && along <= Math.max(a, b) + gap / 2\n })\n }\n // The bar under the pointer, gaps included, so thin bars are easy to hit.\n const slot = Math.floor((across - (x.at(i) + offset) + gap / 2) / (barWidth + gap))\n const seriesIndex = order[slot]\n return seriesIndex !== undefined && segment(seriesIndex, i) ? seriesIndex : undefined\n },\n ),\n )\n\n const groups = series.map(\n (s, index) =>\n slots.has(index) &&\n h(\n 'g',\n seriesAttrs(s, index),\n labels.map((label, i) => {\n const seg = segment(index, i)\n if (!seg) return null\n const negative = seg.y1 < seg.y0\n // Leave a surface-colored gap where this segment sits on another one;\n // positive values grow toward smaller y, but toward larger x.\n const away = (negative ? 1 : -1) * (horizontal ? -1 : 1)\n const inner = seg.y0 === 0 ? 0 : away * gap\n const rounded = !stacks || (negative ? outer[i]?.down : outer[i]?.up) === index\n const draw = horizontal ? hbarPath : barPath\n return h('path', {\n key: labelKey(label),\n class: ['tc-bar', negative && 'tc-bar-negative', horizontal && 'tc-bar-horizontal'],\n d: draw(\n barLeft(index, i),\n barWidth,\n y(seg.y0) + inner,\n y(seg.y1),\n rounded ? radius : 0,\n ),\n })\n }),\n ),\n )\n\n // Lines through the band centers, drawn after (over) every bar. The path\n // generators come with the line module, so plain bar charts do not ship them.\n const paths = lineKeys.length ? feature('line') : null\n const baseline = y(Math.min(Math.max(0, y.domain[0]), y.domain[1]))\n const lines = series.map((s, index) => {\n if (!paths) return null\n if (!isLine(index) || ctx.hidden.has(seriesKey(s))) return null\n const points = labels.map((_, i): Point => {\n const v = s.values[i]\n if (!plottable(v, options.y)) return null\n const center = x.at(i) + x.bandwidth / 2\n return horizontal ? [y(v), center] : [center, y(v)]\n })\n // Areas need a vertical baseline; sideways they fall back to a line.\n const filled = s.type === 'area' && !horizontal\n return h(\n 'g',\n seriesAttrs(s, index),\n filled && h('path', { class: 'tc-area', d: paths.areaPath(points, baseline, { curve }) }),\n h('path', { class: 'tc-line', d: paths.linePath(points, { curve }) }),\n )\n })\n\n return [\n h('defs', { key: 'defs' }, layout.clip.def),\n layout.background,\n // Layers are keyed: an annotation band or a grid that comes and goes must not\n // shift the series list onto another node (that would recreate every series).\n h(\n 'g',\n { key: 'series', class: 'tc-series-list', 'clip-path': layout.clip.url },\n groups,\n lines,\n ),\n layout.foreground,\n ]\n },\n legend: (options) => seriesLegend(options.data),\n table: (options, ctx, limit) => seriesTable(options, ctx, limit),\n}\n"],"mappings":";;;;;;;;;;;;;AAuBA,SAAgB,iBACd,SACA,KACA,QACiB;CACjB,MAAM,WAAW,QAAQ,KAAK,CAAC;CAC/B,MAAM,WAAW,QAAQ,K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SAAS,KAAK,KAAK;AACjE"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { $ as CartesianOptions, a as ChartType } from "./chart-D7ooEFnk.cjs";
|
|
2
|
+
import { t as Curve } from "./path-CwB28da0.cjs";
|
|
3
|
+
import { t as StackMode } from "./stack-CpR6RGKd.cjs";
|
|
4
|
+
//#region src/charts/bar.d.ts
|
|
5
|
+
interface BarOptions extends CartesianOptions {
|
|
6
|
+
/** Corner radius of the data end of each bar (or stack). Defaults to `4`. */
|
|
7
|
+
radius?: number;
|
|
8
|
+
/** Maximum bar thickness in pixels; leftover band space stays empty. Defaults to `24`. */
|
|
9
|
+
maxBarWidth?: number;
|
|
10
|
+
/** Gap between bars of a group, or between stacked segments, in pixels. Defaults to `2`. */
|
|
11
|
+
gap?: number;
|
|
12
|
+
/** Share of each category left empty between groups, `0…1`. Defaults to `0.3`. */
|
|
13
|
+
groupPadding?: number;
|
|
14
|
+
/**
|
|
15
|
+
* Stack series in one bar per category instead of side by side; `'percent'`
|
|
16
|
+
* shows each category as 100%. Negative values stack down from zero.
|
|
17
|
+
*/
|
|
18
|
+
stacked?: StackMode;
|
|
19
|
+
/**
|
|
20
|
+
* `'horizontal'` lays categories out along y with bars growing right
|
|
21
|
+
* (left for negative values). The `x` / `y` options keep describing the
|
|
22
|
+
* category / value axis. Defaults to `'vertical'`.
|
|
23
|
+
*/
|
|
24
|
+
orientation?: "vertical" | "horizontal";
|
|
25
|
+
/** Interpolation of series drawn as lines (`series.type`). Defaults to `'monotone'`. */
|
|
26
|
+
curve?: Curve;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Bar chart: vertical bars per category, grouped side by side or stacked,
|
|
30
|
+
* growing from zero (negative values grow down).
|
|
31
|
+
*
|
|
32
|
+
* ```ts
|
|
33
|
+
* new Chart('#el', {
|
|
34
|
+
* type: bar,
|
|
35
|
+
* data: { labels: ['Q1', 'Q2'], series: [{ name: '2025', values: [3, 5] }] },
|
|
36
|
+
* stacked: true,
|
|
37
|
+
* })
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
declare const bar: ChartType<BarOptions>;
|
|
41
|
+
//#endregion
|
|
42
|
+
export { bar as n, BarOptions as t };
|
|
43
|
+
//# sourceMappingURL=bar-CRKLDg98.d.cts.map
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
const require_layout = require("./layout-CtMBhNd9.cjs");
|
|
2
|
+
//#region src/shapes/bar.ts
|
|
3
|
+
/** Rounded for path data, without a `-0`. */
|
|
4
|
+
const round = (value) => {
|
|
5
|
+
const rounded = require_layout.round(value);
|
|
6
|
+
return rounded === 0 ? 0 : rounded;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Path of a vertical bar from `baseline` to `value` (both y in pixels),
|
|
10
|
+
* `x`…`x + width` wide. Only the data end is rounded, with `radius` clamped
|
|
11
|
+
* to half the width and to the bar height; the baseline end stays square.
|
|
12
|
+
* Works for bars growing up (value above baseline) and down (negative values).
|
|
13
|
+
* Square corners are zero-radius arcs and every side is an `L`, so every
|
|
14
|
+
* bar path, vertical or horizontal, has the same commands and CSS can
|
|
15
|
+
* transition `d` between rounded and square (stacking) and between
|
|
16
|
+
* orientations.
|
|
17
|
+
*/
|
|
18
|
+
function barPath(x, width, baseline, value, radius = 0) {
|
|
19
|
+
const w = Math.max(0, width);
|
|
20
|
+
const height = Math.abs(baseline - value);
|
|
21
|
+
const r = Math.max(0, Math.min(radius, w / 2, height));
|
|
22
|
+
const x0 = round(x);
|
|
23
|
+
const x1 = round(x + w);
|
|
24
|
+
const b = round(baseline);
|
|
25
|
+
const v = round(value);
|
|
26
|
+
const up = value <= baseline;
|
|
27
|
+
const edge = round(up ? value + r : value - r);
|
|
28
|
+
const sweep = up ? 1 : 0;
|
|
29
|
+
const rr = round(r);
|
|
30
|
+
return `M${x0},${b}L${x0},${edge}A${rr},${rr},0,0,${sweep},${round(x + r)},${v}L${round(x + w - r)},${v}A${rr},${rr},0,0,${sweep},${x1},${edge}L${x1},${b}Z`;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Path of a horizontal bar from `baseline` to `value` (both x in pixels),
|
|
34
|
+
* `y`…`y + height` tall. Only the data end is rounded, with `radius` clamped
|
|
35
|
+
* to half the height and to the bar length; the baseline end stays square.
|
|
36
|
+
* Works for bars growing right (positive values) and left (negative values).
|
|
37
|
+
* Same commands as `barPath`, so a chart can morph between orientations.
|
|
38
|
+
*/
|
|
39
|
+
function hbarPath(y, height, baseline, value, radius = 0) {
|
|
40
|
+
const hgt = Math.max(0, height);
|
|
41
|
+
const length = Math.abs(value - baseline);
|
|
42
|
+
const r = Math.max(0, Math.min(radius, hgt / 2, length));
|
|
43
|
+
const y0 = round(y);
|
|
44
|
+
const y1 = round(y + hgt);
|
|
45
|
+
const b = round(baseline);
|
|
46
|
+
const v = round(value);
|
|
47
|
+
const right = value >= baseline;
|
|
48
|
+
const edge = round(right ? value - r : value + r);
|
|
49
|
+
const sweep = right ? 1 : 0;
|
|
50
|
+
const rr = round(r);
|
|
51
|
+
return `M${b},${y0}L${edge},${y0}A${rr},${rr},0,0,${sweep},${v},${round(y + r)}L${v},${round(y + hgt - r)}A${rr},${rr},0,0,${sweep},${edge},${y1}L${b},${y1}Z`;
|
|
52
|
+
}
|
|
53
|
+
//#endregion
|
|
54
|
+
Object.defineProperty(exports, "barPath", {
|
|
55
|
+
enumerable: true,
|
|
56
|
+
get: function() {
|
|
57
|
+
return barPath;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
Object.defineProperty(exports, "hbarPath", {
|
|
61
|
+
enumerable: true,
|
|
62
|
+
get: function() {
|
|
63
|
+
return hbarPath;
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
//# sourceMappingURL=bar-DGuUN3nc.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bar-DGuUN3nc.cjs","names":["to2"],"sources":["../src/shapes/bar.ts"],"sourcesContent":["import { round as to2 } from '../layout.ts'\n\n/** Rounded for path data, without a `-0`. */\nconst round = (value: number): number => {\n const rounded = to2(value)\n return rounded === 0 ? 0 : rounded\n}\n\n/**\n * Path of a vertical bar from `baseline` to `value` (both y in pixels),\n * `x`…`x + width` wide. Only the data end is rounded, with `radius` clamped\n * to half the width and to the bar height; the baseline end stays square.\n * Works for bars growing up (value above baseline) and down (negative values).\n * Square corners are zero-radius arcs and every side is an `L`, so every\n * bar path, vertical or horizontal, has the same commands and CSS can\n * transition `d` between rounded and square (stacking) and between\n * orientations.\n */\nexport function barPath(\n x: number,\n width: number,\n baseline: number,\n value: number,\n radius = 0,\n): string {\n const w = Math.max(0, width)\n const height = Math.abs(baseline - value)\n const r = Math.max(0, Math.min(radius, w / 2, height))\n const x0 = round(x)\n const x1 = round(x + w)\n const b = round(baseline)\n const v = round(value)\n\n const up = value <= baseline\n const edge = round(up ? value + r : value - r)\n const sweep = up ? 1 : 0\n const rr = round(r)\n return (\n `M${x0},${b}L${x0},${edge}` +\n `A${rr},${rr},0,0,${sweep},${round(x + r)},${v}` +\n `L${round(x + w - r)},${v}` +\n `A${rr},${rr},0,0,${sweep},${x1},${edge}` +\n `L${x1},${b}Z`\n )\n}\n\n/**\n * Path of a horizontal bar from `baseline` to `value` (both x in pixels),\n * `y`…`y + height` tall. Only the data end is rounded, with `radius` clamped\n * to half the height and to the bar length; the baseline end stays square.\n * Works for bars growing right (positive values) and left (negative values).\n * Same commands as `barPath`, so a chart can morph between orientations.\n */\nexport function hbarPath(\n y: number,\n height: number,\n baseline: number,\n value: number,\n radius = 0,\n): string {\n const hgt = Math.max(0, height)\n const length = Math.abs(value - baseline)\n const r = Math.max(0, Math.min(radius, hgt / 2, length))\n const y0 = round(y)\n const y1 = round(y + hgt)\n const b = round(baseline)\n const v = round(value)\n\n const right = value >= baseline\n const edge = round(right ? value - r : value + r)\n const sweep = right ? 1 : 0\n const rr = round(r)\n return (\n `M${b},${y0}L${edge},${y0}` +\n `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;CACvD,MAAM,KAAK,MAAM,CAAC;CAClB,MAAM,KAAK,MAAM,IAAI,GAAG;CACxB,MAAM,IAAI,MAAM,QAAQ;CACxB,MAAM,IAAI,MAAM,KAAK;CAErB,MAAM,QAAQ,SAAS;CACvB,MAAM,OAAO,MAAM,QAAQ,QAAQ,IAAI,QAAQ,CAAC;CAChD,MAAM,QAAQ,QAAQ,IAAI;CAC1B,MAAM,KAAK,MAAM,CAAC;CAClB,OACE,IAAI,EAAE,GAAG,GAAG,GAAG,KAAK,GAAG,GAAA,GACnB,GAAG,GAAG,GAAG,OAAO,MAAM,GAAG,EAAE,GAAG,MAAM,IAAI,CAAC,EAAA,GACzC,EAAE,GAAG,MAAM,IAAI,MAAM,CAAC,EAAA,GACtB,GAAG,GAAG,GAAG,OAAO,MAAM,GAAG,KAAK,GAAG,GAAA,GACjC,EAAE,GAAG,GAAG;AAEhB"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { a as round$1 } from "./layout-B3hiqVEw.js";
|
|
2
|
+
//#region src/shapes/bar.ts
|
|
3
|
+
/** Rounded for path data, without a `-0`. */
|
|
4
|
+
const round = (value) => {
|
|
5
|
+
const rounded = round$1(value);
|
|
6
|
+
return rounded === 0 ? 0 : rounded;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Path of a vertical bar from `baseline` to `value` (both y in pixels),
|
|
10
|
+
* `x`…`x + width` wide. Only the data end is rounded, with `radius` clamped
|
|
11
|
+
* to half the width and to the bar height; the baseline end stays square.
|
|
12
|
+
* Works for bars growing up (value above baseline) and down (negative values).
|
|
13
|
+
* Square corners are zero-radius arcs and every side is an `L`, so every
|
|
14
|
+
* bar path, vertical or horizontal, has the same commands and CSS can
|
|
15
|
+
* transition `d` between rounded and square (stacking) and between
|
|
16
|
+
* orientations.
|
|
17
|
+
*/
|
|
18
|
+
function barPath(x, width, baseline, value, radius = 0) {
|
|
19
|
+
const w = Math.max(0, width);
|
|
20
|
+
const height = Math.abs(baseline - value);
|
|
21
|
+
const r = Math.max(0, Math.min(radius, w / 2, height));
|
|
22
|
+
const x0 = round(x);
|
|
23
|
+
const x1 = round(x + w);
|
|
24
|
+
const b = round(baseline);
|
|
25
|
+
const v = round(value);
|
|
26
|
+
const up = value <= baseline;
|
|
27
|
+
const edge = round(up ? value + r : value - r);
|
|
28
|
+
const sweep = up ? 1 : 0;
|
|
29
|
+
const rr = round(r);
|
|
30
|
+
return `M${x0},${b}L${x0},${edge}A${rr},${rr},0,0,${sweep},${round(x + r)},${v}L${round(x + w - r)},${v}A${rr},${rr},0,0,${sweep},${x1},${edge}L${x1},${b}Z`;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Path of a horizontal bar from `baseline` to `value` (both x in pixels),
|
|
34
|
+
* `y`…`y + height` tall. Only the data end is rounded, with `radius` clamped
|
|
35
|
+
* to half the height and to the bar length; the baseline end stays square.
|
|
36
|
+
* Works for bars growing right (positive values) and left (negative values).
|
|
37
|
+
* Same commands as `barPath`, so a chart can morph between orientations.
|
|
38
|
+
*/
|
|
39
|
+
function hbarPath(y, height, baseline, value, radius = 0) {
|
|
40
|
+
const hgt = Math.max(0, height);
|
|
41
|
+
const length = Math.abs(value - baseline);
|
|
42
|
+
const r = Math.max(0, Math.min(radius, hgt / 2, length));
|
|
43
|
+
const y0 = round(y);
|
|
44
|
+
const y1 = round(y + hgt);
|
|
45
|
+
const b = round(baseline);
|
|
46
|
+
const v = round(value);
|
|
47
|
+
const right = value >= baseline;
|
|
48
|
+
const edge = round(right ? value - r : value + r);
|
|
49
|
+
const sweep = right ? 1 : 0;
|
|
50
|
+
const rr = round(r);
|
|
51
|
+
return `M${b},${y0}L${edge},${y0}A${rr},${rr},0,0,${sweep},${v},${round(y + r)}L${v},${round(y + hgt - r)}A${rr},${rr},0,0,${sweep},${edge},${y1}L${b},${y1}Z`;
|
|
52
|
+
}
|
|
53
|
+
//#endregion
|
|
54
|
+
export { hbarPath as n, barPath as t };
|
|
55
|
+
|
|
56
|
+
//# sourceMappingURL=bar-DM16NUvV.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bar-DM16NUvV.js","names":["to2"],"sources":["../src/shapes/bar.ts"],"sourcesContent":["import { round as to2 } from '../layout.ts'\n\n/** Rounded for path data, without a `-0`. */\nconst round = (value: number): number => {\n const rounded = to2(value)\n return rounded === 0 ? 0 : rounded\n}\n\n/**\n * Path of a vertical bar from `baseline` to `value` (both y in pixels),\n * `x`…`x + width` wide. Only the data end is rounded, with `radius` clamped\n * to half the width and to the bar height; the baseline end stays square.\n * Works for bars growing up (value above baseline) and down (negative values).\n * Square corners are zero-radius arcs and every side is an `L`, so every\n * bar path, vertical or horizontal, has the same commands and CSS can\n * transition `d` between rounded and square (stacking) and between\n * orientations.\n */\nexport function barPath(\n x: number,\n width: number,\n baseline: number,\n value: number,\n radius = 0,\n): string {\n const w = Math.max(0, width)\n const height = Math.abs(baseline - value)\n const r = Math.max(0, Math.min(radius, w / 2, height))\n const x0 = round(x)\n const x1 = round(x + w)\n const b = round(baseline)\n const v = round(value)\n\n const up = value <= baseline\n const edge = round(up ? value + r : value - r)\n const sweep = up ? 1 : 0\n const rr = round(r)\n return (\n `M${x0},${b}L${x0},${edge}` +\n `A${rr},${rr},0,0,${sweep},${round(x + r)},${v}` +\n `L${round(x + w - r)},${v}` +\n `A${rr},${rr},0,0,${sweep},${x1},${edge}` +\n `L${x1},${b}Z`\n )\n}\n\n/**\n * Path of a horizontal bar from `baseline` to `value` (both x in pixels),\n * `y`…`y + height` tall. Only the data end is rounded, with `radius` clamped\n * to half the height and to the bar length; the baseline end stays square.\n * Works for bars growing right (positive values) and left (negative values).\n * Same commands as `barPath`, so a chart can morph between orientations.\n */\nexport function hbarPath(\n y: number,\n height: number,\n baseline: number,\n value: number,\n radius = 0,\n): string {\n const hgt = Math.max(0, height)\n const length = Math.abs(value - baseline)\n const r = Math.max(0, Math.min(radius, hgt / 2, length))\n const y0 = round(y)\n const y1 = round(y + hgt)\n const b = round(baseline)\n const v = round(value)\n\n const right = value >= baseline\n const edge = round(right ? value - r : value + r)\n const sweep = right ? 1 : 0\n const rr = round(r)\n return (\n `M${b},${y0}L${edge},${y0}` +\n `A${rr},${rr},0,0,${sweep},${v},${round(y + r)}` +\n `L${v},${round(y + hgt - r)}` +\n `A${rr},${rr},0,0,${sweep},${edge},${y1}` +\n `L${b},${y1}Z`\n )\n}\n"],"mappings":";;;AAGA,MAAM,SAAS,UAA0B;CACvC,MAAM,UAAUA,QAAI,KAAK;CACzB,OAAO,YAAY,IAAI,IAAI;AAC7B;;;;;;;;;;;AAYA,SAAgB,QACd,GACA,OACA,UACA,OACA,SAAS,GACD;CACR,MAAM,IAAI,KAAK,IAAI,GAAG,KAAK;CAC3B,MAAM,SAAS,KAAK,IAAI,WAAW,KAAK;CACxC,MAAM,IAAI,KAAK,IAAI,GAAG,KAAK,IAAI,QAAQ,IAAI,GAAG,MAAM,CAAC;CACrD,MAAM,KAAK,MAAM,CAAC;CAClB,MAAM,KAAK,MAAM,IAAI,CAAC;CACtB,MAAM,IAAI,MAAM,QAAQ;CACxB,MAAM,IAAI,MAAM,KAAK;CAErB,MAAM,KAAK,SAAS;CACpB,MAAM,OAAO,MAAM,KAAK,QAAQ,IAAI,QAAQ,CAAC;CAC7C,MAAM,QAAQ,KAAK,IAAI;CACvB,MAAM,KAAK,MAAM,CAAC;CAClB,OACE,IAAI,GAAG,GAAG,EAAE,GAAG,GAAG,GAAG,KAAA,GACjB,GAAG,GAAG,GAAG,OAAO,MAAM,GAAG,MAAM,IAAI,CAAC,EAAE,GAAG,EAAA,GACzC,MAAM,IAAI,IAAI,CAAC,EAAE,GAAG,EAAA,GACpB,GAAG,GAAG,GAAG,OAAO,MAAM,GAAG,GAAG,GAAG,KAAA,GAC/B,GAAG,GAAG,EAAE;AAEhB;;;;;;;;AASA,SAAgB,SACd,GACA,QACA,UACA,OACA,SAAS,GACD;CACR,MAAM,MAAM,KAAK,IAAI,GAAG,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