@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,238 @@
|
|
|
1
|
+
import { i as insets, n as estimateTextWidth, r as innerRect } from "./layout-B3hiqVEw.js";
|
|
2
|
+
import { t as h } from "./vnode-tCWItoUH.js";
|
|
3
|
+
import { E as bandTicks, O as thinTicks, T as axisSize, _ as valueAxis, a as labelFormatter, d as seriesAttrs, f as seriesKey, i as finishLayout, l as plottable, m as seriesTable, n as categoryInteraction, o as labelKey, p as seriesLegend, t as cartesianLayout, u as resolveLabels, x as band } from "./cartesian-Cr0AF0nG.js";
|
|
4
|
+
import { n as feature } from "./features-wASyHGic.js";
|
|
5
|
+
import { r as cleanSeries, t as cleanData } from "./clean-o1vDEhFV.js";
|
|
6
|
+
import { n as stackSeries, t as stackBounds } from "./stack-DRbwTeF3.js";
|
|
7
|
+
import { n as hbarPath, t as barPath } from "./bar-DM16NUvV.js";
|
|
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 = insets(options.padding);
|
|
20
|
+
const labels = resolveLabels(options.data);
|
|
21
|
+
const format = labelFormatter(options, ctx);
|
|
22
|
+
const value = 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: labelKey(label),
|
|
28
|
+
position: 0,
|
|
29
|
+
label: format(label, i)
|
|
30
|
+
}));
|
|
31
|
+
const edgeLabel = (tick) => showValues && tick ? Math.ceil(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 ? axisSize("bottom", probeValues, fontSize) : 0, overhang, 4),
|
|
36
|
+
left: pad.left + Math.max(showCategories ? axisSize("left", probeCategories, fontSize) : 0, edgeLabel(probeValues[0]), overhang, 8)
|
|
37
|
+
};
|
|
38
|
+
const area = innerRect(width, height, margins);
|
|
39
|
+
const keys = labels.map(labelKey);
|
|
40
|
+
const x = 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 = thinTicks(value.ticks(y), "bottom", fontSize);
|
|
46
|
+
const xTicks = showCategories ? thinTicks(bandTicks(x, (_, i) => format(labels[i], i)), "left", fontSize) : [];
|
|
47
|
+
return 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: cleanData(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 = resolveLabels(options.data).length;
|
|
79
|
+
const isLine = (index) => (series[index]?.type ?? "bar") !== "bar";
|
|
80
|
+
const lineKeys = series.filter((_, index) => isLine(index)).map(seriesKey);
|
|
81
|
+
const stackHidden = lineKeys.length ? /* @__PURE__ */ new Set([...ctx.hidden, ...lineKeys]) : ctx.hidden;
|
|
82
|
+
const stacks = stacked ? 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: [...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) : 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(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 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(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) && h("g", 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 ? hbarPath : barPath;
|
|
191
|
+
return h("path", {
|
|
192
|
+
key: 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 ? 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(seriesKey(s))) return null;
|
|
206
|
+
const points = labels.map((_, i) => {
|
|
207
|
+
const v = s.values[i];
|
|
208
|
+
if (!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 h("g", seriesAttrs(s, index), filled && h("path", {
|
|
214
|
+
class: "tc-area",
|
|
215
|
+
d: paths.areaPath(points, baseline, { curve })
|
|
216
|
+
}), h("path", {
|
|
217
|
+
class: "tc-line",
|
|
218
|
+
d: paths.linePath(points, { curve })
|
|
219
|
+
}));
|
|
220
|
+
});
|
|
221
|
+
return [
|
|
222
|
+
h("defs", { key: "defs" }, layout.clip.def),
|
|
223
|
+
layout.background,
|
|
224
|
+
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) => seriesLegend(options.data),
|
|
233
|
+
table: (options, ctx, limit) => seriesTable(options, ctx, limit)
|
|
234
|
+
};
|
|
235
|
+
//#endregion
|
|
236
|
+
export { bar as t };
|
|
237
|
+
|
|
238
|
+
//# sourceMappingURL=bar-jZEoao74.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bar-jZEoao74.js","names":[],"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,KAAK,CAAC;CAC/B,MAAM,EAAE,UAAU,OAAO,WAAW;CACpC,MAAM,WAAW,OAAO,YAAY;CACpC,MAAM,MAAM,OAAO,QAAQ,OAAO;CAClC,MAAM,SAAS,cAAc,QAAQ,IAAI;CACzC,MAAM,SAAS,eAAe,SAAS,GAAG;CAC1C,MAAM,QAAQ,UAAU,SAAS,KAAK,QAAQ,KAAK,MAAM,QAAA,EAAsB,CAAC;CAChF,MAAM,cAAc,MAAM;CAC1B,MAAM,aAAa,SAAS,SAAS;CACrC,MAAM,iBAAiB,SAAS,SAAS,SAAS,OAAO,SAAS;CAElE,MAAM,kBAA0B,OAAO,KAAK,OAAO,OAAO;EACxD,OAAO,SAAS,KAAK;EACrB,UAAU;EACV,OAAO,OAAO,OAAO,CAAC;CACxB,EAAE;CACF,MAAM,aAAa,SACjB,cAAc,OAAO,KAAK,KAAK,kBAAkB,KAAK,OAAO,QAAQ,IAAI,CAAC,IAAI;CA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C;EAED,OAAO;GACL,EAAE,QAAQ,EAAE,KAAK,OAAO,GAAG,OAAO,KAAK,GAAG;GAC1C,OAAO;GAGP,EACE,KACA;IAAE,KAAK;IAAU,OAAO;IAAkB,aAAa,OAAO,KAAK;GAAI,GACvE,QACA,KACF;GACA,OAAO;EACT;CACF;CACA,SAAS,YAAY,aAAa,QAAQ,IAAI;CAC9C,QAAQ,SAAS,KAAK,UAAU,YAAY,SAAS,KAAK,KAAK;AACjE"}
|
package/dist/bar.cjs
ADDED
package/dist/bar.d.cts
ADDED
package/dist/bar.d.ts
ADDED
package/dist/bar.js
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
const require_layout = require("./layout-CtMBhNd9.cjs");
|
|
2
|
+
const require_vnode = require("./vnode-CkQ27Cxe.cjs");
|
|
3
|
+
const require_cartesian = require("./cartesian-BoDfgBCV.cjs");
|
|
4
|
+
const require_clean = require("./clean-Byl6kzf0.cjs");
|
|
5
|
+
//#region src/charts/candlestick.ts
|
|
6
|
+
/**
|
|
7
|
+
* A rounded rectangle with the same commands whatever its size and radius
|
|
8
|
+
* (a zero radius draws square corners), so CSS can morph one into another.
|
|
9
|
+
*/
|
|
10
|
+
const bodyPath = (x, y, w, h, r) => {
|
|
11
|
+
const a = `A${r},${r},0,0,1,`;
|
|
12
|
+
return `M${require_layout.round(x + r)},${y}H${require_layout.round(x + w - r)}${a}${require_layout.round(x + w)},${require_layout.round(y + r)}V${require_layout.round(y + h - r)}${a}${require_layout.round(x + w - r)},${require_layout.round(y + h)}H${require_layout.round(x + r)}${a}${x},${require_layout.round(y + h - r)}V${require_layout.round(y + r)}${a}${require_layout.round(x + r)},${y}Z`;
|
|
13
|
+
};
|
|
14
|
+
const UP = "var(--tc-up-color,var(--tc-color-6))";
|
|
15
|
+
const DOWN = "var(--tc-negative-color,var(--tc-color-8))";
|
|
16
|
+
/** Whether every price can be placed on the value axis (positive ones only on a log axis). */
|
|
17
|
+
const valid = (c, axis) => [
|
|
18
|
+
c.open,
|
|
19
|
+
c.high,
|
|
20
|
+
c.low,
|
|
21
|
+
c.close
|
|
22
|
+
].every((v) => require_cartesian.plottable(v, axis));
|
|
23
|
+
/** The candles as four series, for the shared axes, tooltip and table. */
|
|
24
|
+
function asCartesian(options) {
|
|
25
|
+
const pick = (key) => options.data.map((c) => valid(c, options.y) ? c[key] : null);
|
|
26
|
+
const out = { data: {
|
|
27
|
+
labels: options.data.map((c) => c.x),
|
|
28
|
+
series: [
|
|
29
|
+
{
|
|
30
|
+
name: "Open",
|
|
31
|
+
values: pick("open")
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
name: "High",
|
|
35
|
+
values: pick("high")
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
name: "Low",
|
|
39
|
+
values: pick("low")
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
name: "Close",
|
|
43
|
+
values: pick("close")
|
|
44
|
+
}
|
|
45
|
+
]
|
|
46
|
+
} };
|
|
47
|
+
if (options.x) out.x = options.x;
|
|
48
|
+
if (options.y) out.y = options.y;
|
|
49
|
+
if (options.padding !== void 0) out.padding = options.padding;
|
|
50
|
+
if (options.annotations) out.annotations = options.annotations;
|
|
51
|
+
return out;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Candlestick (OHLC) chart: per period a wick from low to high and a body
|
|
55
|
+
* from open to close, green when it closed higher (`--tc-up-color`) and red
|
|
56
|
+
* when lower (`--tc-negative-color`).
|
|
57
|
+
*
|
|
58
|
+
* ```ts
|
|
59
|
+
* new Chart('#el', {
|
|
60
|
+
* type: candlestick,
|
|
61
|
+
* data: [{ x: '2026-01-01', open: 98, high: 102, low: 89, close: 94 }],
|
|
62
|
+
* x: { type: 'time' },
|
|
63
|
+
* })
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
const candlestick = {
|
|
67
|
+
name: "candlestick",
|
|
68
|
+
clean: require_clean.cleanData((data) => require_clean.records(data, (c) => ({
|
|
69
|
+
...c,
|
|
70
|
+
x: require_clean.label(c.x),
|
|
71
|
+
open: require_clean.finite(c.open),
|
|
72
|
+
high: require_clean.finite(c.high),
|
|
73
|
+
low: require_clean.finite(c.low),
|
|
74
|
+
close: require_clean.finite(c.close)
|
|
75
|
+
}))),
|
|
76
|
+
render(options, ctx) {
|
|
77
|
+
const { maxCandleWidth = 16, groupPadding = .3, radius = 1 } = options;
|
|
78
|
+
const cartesian = asCartesian(options);
|
|
79
|
+
const layout = require_cartesian.cartesianLayout(cartesian, ctx, {
|
|
80
|
+
scale: "band",
|
|
81
|
+
zero: false,
|
|
82
|
+
paddingInner: groupPadding,
|
|
83
|
+
paddingOuter: groupPadding / 2
|
|
84
|
+
});
|
|
85
|
+
const { x, y, labels } = layout;
|
|
86
|
+
const width = Math.max(1, Math.min(maxCandleWidth, x.bandwidth));
|
|
87
|
+
const center = (i) => x.at(i) + x.bandwidth / 2;
|
|
88
|
+
const up = (c) => c.close >= c.open;
|
|
89
|
+
const base = require_cartesian.categoryInteraction(layout, cartesian, ctx, (_, i, v) => ({
|
|
90
|
+
x: center(i),
|
|
91
|
+
y: y(v)
|
|
92
|
+
}));
|
|
93
|
+
const paint = (hit) => {
|
|
94
|
+
const candle = hit ? options.data[hit.index] : void 0;
|
|
95
|
+
if (!hit || !candle) return hit;
|
|
96
|
+
const color = up(candle) ? UP : DOWN;
|
|
97
|
+
return {
|
|
98
|
+
...hit,
|
|
99
|
+
items: hit.items.map((item) => ({
|
|
100
|
+
...item,
|
|
101
|
+
color
|
|
102
|
+
}))
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
const interaction = {
|
|
106
|
+
count: base.count,
|
|
107
|
+
hitIndex: (i, s) => paint(base.hitIndex(i, s)),
|
|
108
|
+
hitTest: (px, py) => paint(base.hitTest(px, py))
|
|
109
|
+
};
|
|
110
|
+
ctx.onHitTest(interaction);
|
|
111
|
+
const candles = options.data.map((c, i) => {
|
|
112
|
+
if (!valid(c, options.y)) return null;
|
|
113
|
+
const cx = require_layout.round(center(i));
|
|
114
|
+
const top = y(Math.max(c.open, c.close));
|
|
115
|
+
const bottom = Math.max(y(Math.min(c.open, c.close)), top + 1);
|
|
116
|
+
const left = require_layout.round(center(i) - width / 2);
|
|
117
|
+
const r = require_layout.round(Math.min(radius, width / 2, (bottom - top) / 2));
|
|
118
|
+
return require_vnode.h("g", {
|
|
119
|
+
key: require_cartesian.labelKey(labels[i]),
|
|
120
|
+
class: ["tc-candle", up(c) ? "tc-candle-up" : "tc-candle-down"]
|
|
121
|
+
}, require_vnode.h("path", {
|
|
122
|
+
class: "tc-candle-wick",
|
|
123
|
+
d: `M${cx},${require_layout.round(y(c.high))}V${require_layout.round(y(c.low))}`
|
|
124
|
+
}), require_vnode.h("path", {
|
|
125
|
+
class: "tc-candle-body",
|
|
126
|
+
d: bodyPath(left, require_layout.round(top), require_layout.round(width), require_layout.round(bottom - top), r)
|
|
127
|
+
}));
|
|
128
|
+
});
|
|
129
|
+
return [
|
|
130
|
+
require_vnode.h("defs", { key: "defs" }, layout.clip.def),
|
|
131
|
+
layout.background,
|
|
132
|
+
require_vnode.h("g", {
|
|
133
|
+
key: "series",
|
|
134
|
+
class: "tc-series-list tc-candles",
|
|
135
|
+
"clip-path": layout.clip.url
|
|
136
|
+
}, candles),
|
|
137
|
+
layout.foreground
|
|
138
|
+
];
|
|
139
|
+
},
|
|
140
|
+
table: (options, ctx, limit) => require_cartesian.seriesTable(asCartesian(options), ctx, limit)
|
|
141
|
+
};
|
|
142
|
+
//#endregion
|
|
143
|
+
Object.defineProperty(exports, "candlestick", {
|
|
144
|
+
enumerable: true,
|
|
145
|
+
get: function() {
|
|
146
|
+
return candlestick;
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
//# sourceMappingURL=candlestick-B5r1w3kc.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"candlestick-B5r1w3kc.cjs","names":["round","plottable","cleanData","records","label","finite","cartesianLayout","categoryInteraction","h","labelKey","seriesTable"],"sources":["../src/charts/candlestick.ts"],"sourcesContent":["import type { ChartType } from '../chart.ts'\nimport type { Hit, Interaction } from '../interaction.ts'\nimport type { InsetsInput } from '../layout.ts'\nimport { round } from '../layout.ts'\nimport { h } from '../vnode.ts'\nimport type { Annotation } from './annotations.ts'\nimport {\n type CartesianData,\n type CartesianOptions,\n type CategoryAxisOptions,\n cartesianLayout,\n categoryInteraction,\n type Label,\n labelKey,\n plottable,\n seriesTable,\n type ValueAxisOptions,\n} from './cartesian.ts'\nimport { cleanData, finite, label, records } from './clean.ts'\n\n/** One period: where the price opened, its range and where it closed. */\nexport interface Candle {\n /** The period (a date for `x: { type: 'time' }`, or any label). */\n x: Label\n open: number\n high: number\n low: number\n close: number\n}\n\n/**\n * A rounded rectangle with the same commands whatever its size and radius\n * (a zero radius draws square corners), so CSS can morph one into another.\n */\nconst bodyPath = (x: number, y: number, w: number, h: number, r: number): string => {\n const a = `A${r},${r},0,0,1,`\n return `M${round(x + r)},${y}H${round(x + w - r)}${a}${round(x + w)},${round(y + r)}V${round(y + h - r)}${a}${round(x + w - r)},${round(y + h)}H${round(x + r)}${a}${x},${round(y + h - r)}V${round(y + r)}${a}${round(x + r)},${y}Z`\n}\n\nexport interface CandlestickOptions {\n data: readonly Candle[]\n /** Maximum candle body width in pixels. Defaults to `16`. */\n maxCandleWidth?: number\n /** Share of each period left empty between candles, `0…1`. Defaults to `0.3`. */\n groupPadding?: number\n /** Extra space around the plot area, in pixels. */\n padding?: InsetsInput\n /** Corner radius of the bodies. Defaults to `1`. */\n radius?: number\n x?: CategoryAxisOptions\n y?: ValueAxisOptions\n /** Reference lines and bands, e.g. a price target or a trading halt. */\n annotations?: readonly Annotation[]\n}\n\nconst UP = 'var(--tc-up-color,var(--tc-color-6))'\nconst DOWN = 'var(--tc-negative-color,var(--tc-color-8))'\n\n/** Whether every price can be placed on the value axis (positive ones only on a log axis). */\nconst valid = (c: Candle, axis: ValueAxisOptions | undefined): boolean =>\n [c.open, c.high, c.low, c.close].every((v) => plottable(v, axis))\n\n/** The candles as four series, for the shared axes, tooltip and table. */\nfunction asCartesian(options: CandlestickOptions): CartesianOptions {\n const pick = (key: 'open' | 'high' | 'low' | 'close') =>\n options.data.map((c) => (valid(c, options.y) ? c[key] : null))\n const data: CartesianData = {\n labels: options.data.map((c) => c.x),\n series: [\n { name: 'Open', values: pick('open') },\n { name: 'High', values: pick('high') },\n { name: 'Low', values: pick('low') },\n { name: 'Close', values: pick('close') },\n ],\n }\n const out: CartesianOptions = { data }\n if (options.x) out.x = options.x\n if (options.y) out.y = options.y\n if (options.padding !== undefined) out.padding = options.padding\n if (options.annotations) out.annotations = options.annotations\n return out\n}\n\n/**\n * Candlestick (OHLC) chart: per period a wick from low to high and a body\n * from open to close, green when it closed higher (`--tc-up-color`) and red\n * when lower (`--tc-negative-color`).\n *\n * ```ts\n * new Chart('#el', {\n * type: candlestick,\n * data: [{ x: '2026-01-01', open: 98, high: 102, low: 89, close: 94 }],\n * x: { type: 'time' },\n * })\n * ```\n */\nexport const candlestick: ChartType<CandlestickOptions> = {\n name: 'candlestick',\n clean: cleanData((data) =>\n records(data, (c) => ({\n ...c,\n x: label(c.x),\n open: finite(c.open),\n high: finite(c.high),\n low: finite(c.low),\n close: finite(c.close),\n })),\n ),\n render(options, ctx) {\n const { maxCandleWidth = 16, groupPadding = 0.3, radius = 1 } = options\n const cartesian = asCartesian(options)\n const layout = cartesianLayout(cartesian, ctx, {\n scale: 'band',\n zero: false,\n paddingInner: groupPadding,\n paddingOuter: groupPadding / 2,\n })\n const { x, y, labels } = layout\n const width = Math.max(1, Math.min(maxCandleWidth, x.bandwidth))\n const center = (i: number) => x.at(i) + x.bandwidth / 2\n const up = (c: Candle) => c.close >= c.open\n\n const base = categoryInteraction(layout, cartesian, ctx, (_, i, v) => ({\n x: center(i),\n y: y(v),\n }))\n // Tooltip swatches take the color of the candle, not four palette slots.\n const paint = (hit: Hit | null): Hit | null => {\n const candle = hit ? options.data[hit.index] : undefined\n if (!hit || !candle) return hit\n const color = up(candle) ? UP : DOWN\n return { ...hit, items: hit.items.map((item) => ({ ...item, color })) }\n }\n const interaction: Interaction = {\n count: base.count,\n hitIndex: (i, s) => paint(base.hitIndex(i, s)),\n hitTest: (px, py) => paint(base.hitTest(px, py)),\n }\n ctx.onHitTest(interaction)\n\n const candles = options.data.map((c, i) => {\n if (!valid(c, options.y)) return null\n const cx = round(center(i))\n const top = y(Math.max(c.open, c.close))\n // A flat period still shows a 1px body.\n const bottom = Math.max(y(Math.min(c.open, c.close)), top + 1)\n const left = round(center(i) - width / 2)\n const r = round(Math.min(radius, width / 2, (bottom - top) / 2))\n return h(\n 'g',\n {\n key: labelKey(labels[i] as Label),\n class: ['tc-candle', up(c) ? 'tc-candle-up' : 'tc-candle-down'],\n },\n h('path', {\n class: 'tc-candle-wick',\n d: `M${cx},${round(y(c.high))}V${round(y(c.low))}`,\n }),\n // A path, not a rect, so it morphs between updates (d), in Safari too.\n h('path', {\n class: 'tc-candle-body',\n d: bodyPath(left, round(top), round(width), round(bottom - top), r),\n }),\n )\n })\n\n return [\n h('defs', { key: 'defs' }, layout.clip.def),\n layout.background,\n h(\n 'g',\n { key: 'series', class: 'tc-series-list tc-candles', 'clip-path': layout.clip.url },\n candles,\n ),\n layout.foreground,\n ]\n },\n table: (options, ctx, limit) => seriesTable(asCartesian(options), ctx, limit),\n}\n"],"mappings":";;;;;;;;;AAkCA,MAAM,YAAY,GAAW,GAAW,GAAW,GAAW,MAAsB;CAClF,MAAM,IAAI,IAAI,EAAE,GAAG,EAAE;CACrB,OAAO,IAAIA,eAAAA,MAAM,IAAI,CAAC,EAAE,GAAG,EAAE,GAAGA,eAAAA,MAAM,IAAI,IAAI,CAAC,IAAI,IAAIA,eAAAA,MAAM,IAAI,CAAC,EAAE,GAAGA,eAAAA,MAAM,IAAI,CAAC,EAAE,GAAGA,eAAAA,MAAM,IAAI,IAAI,CAAC,IAAI,IAAIA,eAAAA,MA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|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { a as InsetsInput, t as Annotation } from "./annotations-Bp7HwtF5.js";
|
|
2
|
+
import { a as ChartType, et as CategoryAxisOptions, rt as ValueAxisOptions, tt as Label } from "./chart-DyN7bcx8.js";
|
|
3
|
+
//#region src/charts/candlestick.d.ts
|
|
4
|
+
/** One period: where the price opened, its range and where it closed. */
|
|
5
|
+
interface Candle {
|
|
6
|
+
/** The period (a date for `x: { type: 'time' }`, or any label). */
|
|
7
|
+
x: Label;
|
|
8
|
+
open: number;
|
|
9
|
+
high: number;
|
|
10
|
+
low: number;
|
|
11
|
+
close: number;
|
|
12
|
+
}
|
|
13
|
+
interface CandlestickOptions {
|
|
14
|
+
data: readonly Candle[];
|
|
15
|
+
/** Maximum candle body width in pixels. Defaults to `16`. */
|
|
16
|
+
maxCandleWidth?: number;
|
|
17
|
+
/** Share of each period left empty between candles, `0…1`. Defaults to `0.3`. */
|
|
18
|
+
groupPadding?: number;
|
|
19
|
+
/** Extra space around the plot area, in pixels. */
|
|
20
|
+
padding?: InsetsInput;
|
|
21
|
+
/** Corner radius of the bodies. Defaults to `1`. */
|
|
22
|
+
radius?: number;
|
|
23
|
+
x?: CategoryAxisOptions;
|
|
24
|
+
y?: ValueAxisOptions;
|
|
25
|
+
/** Reference lines and bands, e.g. a price target or a trading halt. */
|
|
26
|
+
annotations?: readonly Annotation[];
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Candlestick (OHLC) chart: per period a wick from low to high and a body
|
|
30
|
+
* from open to close, green when it closed higher (`--tc-up-color`) and red
|
|
31
|
+
* when lower (`--tc-negative-color`).
|
|
32
|
+
*
|
|
33
|
+
* ```ts
|
|
34
|
+
* new Chart('#el', {
|
|
35
|
+
* type: candlestick,
|
|
36
|
+
* data: [{ x: '2026-01-01', open: 98, high: 102, low: 89, close: 94 }],
|
|
37
|
+
* x: { type: 'time' },
|
|
38
|
+
* })
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
declare const candlestick: ChartType<CandlestickOptions>;
|
|
42
|
+
//#endregion
|
|
43
|
+
export { CandlestickOptions as n, candlestick as r, Candle as t };
|
|
44
|
+
//# sourceMappingURL=candlestick-D_vV0_XZ.d.ts.map
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { a as round } from "./layout-B3hiqVEw.js";
|
|
2
|
+
import { t as h } from "./vnode-tCWItoUH.js";
|
|
3
|
+
import { l as plottable, m as seriesTable, n as categoryInteraction, o as labelKey, t as cartesianLayout } from "./cartesian-Cr0AF0nG.js";
|
|
4
|
+
import { i as finite, l as records, o as label, t as cleanData } from "./clean-o1vDEhFV.js";
|
|
5
|
+
//#region src/charts/candlestick.ts
|
|
6
|
+
/**
|
|
7
|
+
* A rounded rectangle with the same commands whatever its size and radius
|
|
8
|
+
* (a zero radius draws square corners), so CSS can morph one into another.
|
|
9
|
+
*/
|
|
10
|
+
const bodyPath = (x, y, w, h, r) => {
|
|
11
|
+
const a = `A${r},${r},0,0,1,`;
|
|
12
|
+
return `M${round(x + r)},${y}H${round(x + w - r)}${a}${round(x + w)},${round(y + r)}V${round(y + h - r)}${a}${round(x + w - r)},${round(y + h)}H${round(x + r)}${a}${x},${round(y + h - r)}V${round(y + r)}${a}${round(x + r)},${y}Z`;
|
|
13
|
+
};
|
|
14
|
+
const UP = "var(--tc-up-color,var(--tc-color-6))";
|
|
15
|
+
const DOWN = "var(--tc-negative-color,var(--tc-color-8))";
|
|
16
|
+
/** Whether every price can be placed on the value axis (positive ones only on a log axis). */
|
|
17
|
+
const valid = (c, axis) => [
|
|
18
|
+
c.open,
|
|
19
|
+
c.high,
|
|
20
|
+
c.low,
|
|
21
|
+
c.close
|
|
22
|
+
].every((v) => plottable(v, axis));
|
|
23
|
+
/** The candles as four series, for the shared axes, tooltip and table. */
|
|
24
|
+
function asCartesian(options) {
|
|
25
|
+
const pick = (key) => options.data.map((c) => valid(c, options.y) ? c[key] : null);
|
|
26
|
+
const out = { data: {
|
|
27
|
+
labels: options.data.map((c) => c.x),
|
|
28
|
+
series: [
|
|
29
|
+
{
|
|
30
|
+
name: "Open",
|
|
31
|
+
values: pick("open")
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
name: "High",
|
|
35
|
+
values: pick("high")
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
name: "Low",
|
|
39
|
+
values: pick("low")
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
name: "Close",
|
|
43
|
+
values: pick("close")
|
|
44
|
+
}
|
|
45
|
+
]
|
|
46
|
+
} };
|
|
47
|
+
if (options.x) out.x = options.x;
|
|
48
|
+
if (options.y) out.y = options.y;
|
|
49
|
+
if (options.padding !== void 0) out.padding = options.padding;
|
|
50
|
+
if (options.annotations) out.annotations = options.annotations;
|
|
51
|
+
return out;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Candlestick (OHLC) chart: per period a wick from low to high and a body
|
|
55
|
+
* from open to close, green when it closed higher (`--tc-up-color`) and red
|
|
56
|
+
* when lower (`--tc-negative-color`).
|
|
57
|
+
*
|
|
58
|
+
* ```ts
|
|
59
|
+
* new Chart('#el', {
|
|
60
|
+
* type: candlestick,
|
|
61
|
+
* data: [{ x: '2026-01-01', open: 98, high: 102, low: 89, close: 94 }],
|
|
62
|
+
* x: { type: 'time' },
|
|
63
|
+
* })
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
const candlestick = {
|
|
67
|
+
name: "candlestick",
|
|
68
|
+
clean: cleanData((data) => records(data, (c) => ({
|
|
69
|
+
...c,
|
|
70
|
+
x: label(c.x),
|
|
71
|
+
open: finite(c.open),
|
|
72
|
+
high: finite(c.high),
|
|
73
|
+
low: finite(c.low),
|
|
74
|
+
close: finite(c.close)
|
|
75
|
+
}))),
|
|
76
|
+
render(options, ctx) {
|
|
77
|
+
const { maxCandleWidth = 16, groupPadding = .3, radius = 1 } = options;
|
|
78
|
+
const cartesian = asCartesian(options);
|
|
79
|
+
const layout = cartesianLayout(cartesian, ctx, {
|
|
80
|
+
scale: "band",
|
|
81
|
+
zero: false,
|
|
82
|
+
paddingInner: groupPadding,
|
|
83
|
+
paddingOuter: groupPadding / 2
|
|
84
|
+
});
|
|
85
|
+
const { x, y, labels } = layout;
|
|
86
|
+
const width = Math.max(1, Math.min(maxCandleWidth, x.bandwidth));
|
|
87
|
+
const center = (i) => x.at(i) + x.bandwidth / 2;
|
|
88
|
+
const up = (c) => c.close >= c.open;
|
|
89
|
+
const base = categoryInteraction(layout, cartesian, ctx, (_, i, v) => ({
|
|
90
|
+
x: center(i),
|
|
91
|
+
y: y(v)
|
|
92
|
+
}));
|
|
93
|
+
const paint = (hit) => {
|
|
94
|
+
const candle = hit ? options.data[hit.index] : void 0;
|
|
95
|
+
if (!hit || !candle) return hit;
|
|
96
|
+
const color = up(candle) ? UP : DOWN;
|
|
97
|
+
return {
|
|
98
|
+
...hit,
|
|
99
|
+
items: hit.items.map((item) => ({
|
|
100
|
+
...item,
|
|
101
|
+
color
|
|
102
|
+
}))
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
const interaction = {
|
|
106
|
+
count: base.count,
|
|
107
|
+
hitIndex: (i, s) => paint(base.hitIndex(i, s)),
|
|
108
|
+
hitTest: (px, py) => paint(base.hitTest(px, py))
|
|
109
|
+
};
|
|
110
|
+
ctx.onHitTest(interaction);
|
|
111
|
+
const candles = options.data.map((c, i) => {
|
|
112
|
+
if (!valid(c, options.y)) return null;
|
|
113
|
+
const cx = round(center(i));
|
|
114
|
+
const top = y(Math.max(c.open, c.close));
|
|
115
|
+
const bottom = Math.max(y(Math.min(c.open, c.close)), top + 1);
|
|
116
|
+
const left = round(center(i) - width / 2);
|
|
117
|
+
const r = round(Math.min(radius, width / 2, (bottom - top) / 2));
|
|
118
|
+
return h("g", {
|
|
119
|
+
key: labelKey(labels[i]),
|
|
120
|
+
class: ["tc-candle", up(c) ? "tc-candle-up" : "tc-candle-down"]
|
|
121
|
+
}, h("path", {
|
|
122
|
+
class: "tc-candle-wick",
|
|
123
|
+
d: `M${cx},${round(y(c.high))}V${round(y(c.low))}`
|
|
124
|
+
}), h("path", {
|
|
125
|
+
class: "tc-candle-body",
|
|
126
|
+
d: bodyPath(left, round(top), round(width), round(bottom - top), r)
|
|
127
|
+
}));
|
|
128
|
+
});
|
|
129
|
+
return [
|
|
130
|
+
h("defs", { key: "defs" }, layout.clip.def),
|
|
131
|
+
layout.background,
|
|
132
|
+
h("g", {
|
|
133
|
+
key: "series",
|
|
134
|
+
class: "tc-series-list tc-candles",
|
|
135
|
+
"clip-path": layout.clip.url
|
|
136
|
+
}, candles),
|
|
137
|
+
layout.foreground
|
|
138
|
+
];
|
|
139
|
+
},
|
|
140
|
+
table: (options, ctx, limit) => seriesTable(asCartesian(options), ctx, limit)
|
|
141
|
+
};
|
|
142
|
+
//#endregion
|
|
143
|
+
export { candlestick as t };
|
|
144
|
+
|
|
145
|
+
//# sourceMappingURL=candlestick-DuXwAFID.js.map
|