@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 @@
|
|
|
1
|
+
{"version":3,"file":"heatmap-BK18EBgJ.cjs","names":["round","resolveLabels","formatNumber","extent","seriesKey","insets","axisSize","estimateTextWidth","innerRect","band","labelKey","h","thinTicks","bandTicks","axis","seriesLegend","cleanData","cleanSeries","seriesTable"],"sources":["../src/charts/heatmap.ts"],"sourcesContent":["import type { ChartType, LegendItem, RenderContext } from '../chart.ts'\nimport { axis, axisSize, bandTicks, thinTicks } from '../components/axis.ts'\nimport { formatNumber, type Locale, type NumberFormat } from '../format.ts'\nimport type { Hit, HitItem, Interaction } from '../interaction.ts'\nimport { estimateTextWidth, type InsetsInput, innerRect, insets, round } from '../layout.ts'\nimport { band } from '../scales/band.ts'\nimport { extent } from '../scales/extent.ts'\nimport { h, type StyleValue } from '../vnode.ts'\nimport {\n type CartesianData,\n type Label,\n labelKey,\n resolveLabels,\n type Series,\n seriesKey,\n seriesLegend,\n seriesTable,\n} from './cartesian.ts'\nimport { cleanData, cleanSeries } from './clean.ts'\n\n/** A band of values drawn in one color, with its own legend entry. */\nexport interface HeatmapRange {\n /** Lowest value in the band (inclusive). Leave it out for \"everything below `to`\". */\n from?: number\n /** Value where the band ends (exclusive). Leave it out on the last band. */\n to?: number\n /**\n * Any CSS color, including `var(--tc-color-3)`.\n * Values that could inject CSS (`;`, quotes, `url()` …) are ignored, so colors from user data are safe.\n */\n color: string\n /** Legend and tooltip name, e.g. `'High'`. Defaults to the range, e.g. `10–30`. */\n name?: string\n}\n\nexport interface HeatmapOptions {\n /** Columns are the labels, rows are the series (first series on top). */\n data: CartesianData\n /** Value shown with the lightest shade (or the first color). Defaults to the smaller of `0` and the data minimum. */\n min?: number\n /** Value shown with the full color (or the last color). Defaults to the data maximum. */\n max?: number\n /**\n * Discrete bands of values, each in its own color and legend entry (which\n * also hides the band's cells). Takes precedence over `colors` and `colorBy`.\n */\n ranges?: readonly HeatmapRange[]\n /**\n * A continuous scale through two or more colors (any CSS color, including\n * `var(--tc-…)`), from `min` to `max`. For values around a reference\n * point, use two hues with a neutral middle, e.g.\n * `['var(--tc-color-1)', 'var(--tc-grid-color)', 'var(--tc-color-8)']`.\n * Values that could inject CSS are ignored, as for series colors.\n */\n colors?: readonly string[]\n /** Value placed on the middle color of `colors` (e.g. `0` for changes). Defaults to halfway. */\n mid?: number\n /**\n * `'series'` shades every row in its own palette color (with a legend of\n * the rows); `'value'` (the default) uses one hue, `--tc-heat-color`.\n */\n colorBy?: 'value' | 'series'\n /** Space between cells in pixels, drawn as surface. Defaults to `2`. */\n gap?: number\n /** Corner radius of the cells. Defaults to `3`. */\n radius?: number\n /** Format of the values (tooltip, table). */\n format?: NumberFormat\n /** Column labels along the bottom. */\n x?: { show?: boolean; format?: (label: Label, index: number) => string }\n /** Row names on the left. */\n y?: { show?: boolean }\n /** Extra space around the grid, in pixels. */\n padding?: InsetsInput\n}\n\n/** Share of the full color at the minimum, so zero still reads as a value, not a gap. */\nconst FLOOR = 0.08\n\nconst EMPTY = 'var(--tc-heat-empty,var(--tc-grid-color))'\n\n/** Cell color at `share` (0…1) of the way from the empty shade to `color`. */\nconst shade = (share: number, color = 'var(--tc-heat-color,var(--tc-color-1))'): string =>\n `color-mix(in oklab,${color} ${round(share * 100)}%,${EMPTY})`\n\n/** Legend key of a range. */\nconst rangeKey = (range: HeatmapRange, index: number): string => range.name ?? `range-${index + 1}`\n\n/** The first range containing `v` (`from` inclusive, `to` exclusive). */\nconst rangeOf = (ranges: readonly HeatmapRange[], v: number): number =>\n ranges.findIndex((r) => (r.from === undefined || v >= r.from) && (r.to === undefined || v < r.to))\n\n/** Color of a palette slot by series index, as the CSS classes would pick it. */\nconst slotColor = (series: Series, index: number): string =>\n series.color ?? (index < 8 ? `var(--tc-color-${index + 1})` : 'var(--tc-color-other)')\n\n/** How one cell is painted: inline style, the tooltip swatch, and whether it is drawn empty. */\ninterface Paint {\n style?: StyleValue\n color: string\n empty?: boolean\n}\n\n/** A rounded rectangle as path data, for the hover ring. */\nfunction ringPath(x: number, y: number, w: number, hgt: number, r: number): string {\n const rr = Math.max(0, Math.min(r, w / 2, hgt / 2))\n const n = round\n return (\n `M${n(x + rr)},${n(y)}H${n(x + w - rr)}A${n(rr)},${n(rr)},0,0,1,${n(x + w)},${n(y + rr)}` +\n `V${n(y + hgt - rr)}A${n(rr)},${n(rr)},0,0,1,${n(x + w - rr)},${n(y + hgt)}` +\n `H${n(x + rr)}A${n(rr)},${n(rr)},0,0,1,${n(x)},${n(y + hgt - rr)}` +\n `V${n(y + rr)}A${n(rr)},${n(rr)},0,0,1,${n(x + rr)},${n(y)}Z`\n )\n}\n\nfunction renderHeatmap(options: HeatmapOptions, ctx: RenderContext) {\n const { width, height, fontSize, locale } = ctx\n const { gap = 2, radius = 3 } = options\n const labels = resolveLabels(options.data)\n const formatLabel = options.x?.format ?? ((label: Label) => String(label))\n const value = formatNumber(options.format, locale)\n\n // Color domain.\n const all = options.data.series.flatMap((s) => s.values)\n const [dataMin, dataMax] = extent(all) ?? [0, 1]\n const lo = options.min ?? Math.min(0, dataMin)\n const hi = options.max ?? dataMax\n /** Position of a value in the domain, 0…1 (through `mid` for a scale with a middle). */\n const position = (v: number) => {\n const { mid } = options\n let t: number\n if (mid !== undefined && options.colors && lo < mid && mid < hi) {\n t = v <= mid ? ((v - lo) / (mid - lo)) * 0.5 : 0.5 + ((v - mid) / (hi - mid)) * 0.5\n } else {\n t = hi > lo ? (v - lo) / (hi - lo) : v > lo ? 1 : 0\n }\n return Math.min(1, Math.max(0, t))\n }\n const share = (v: number) => FLOOR + (1 - FLOOR) * position(v)\n\n const ranges = options.ranges?.length ? options.ranges : undefined\n const stops = !ranges && options.colors && options.colors.length >= 2 ? options.colors : undefined\n const bySeries = !ranges && !stops && options.colorBy === 'series'\n // Rows hidden from the legend (rows are legend entries when colored by series).\n const rows = bySeries\n ? options.data.series.filter((s) => !ctx.hidden.has(seriesKey(s)))\n : options.data.series\n const slot = (row: Series) => options.data.series.indexOf(row)\n\n /** How the cell of `row` with value `v` is painted in the active color mode. */\n const paint = (v: number, row: Series): Paint => {\n if (ranges) {\n const index = rangeOf(ranges, v)\n const range = ranges[index]\n if (!range || ctx.hidden.has(rangeKey(range, index))) return { color: EMPTY, empty: true }\n return { style: { '--tc-cell-fill': range.color }, color: range.color }\n }\n if (stops) {\n const at = position(v) * (stops.length - 1)\n const k = Math.min(stops.length - 2, Math.floor(at))\n const u = round((at - k) * 100)\n const from = stops[k] as string\n const color =\n u <= 0\n ? from\n : u >= 100\n ? (stops[k + 1] as string)\n : `color-mix(in oklab,${stops[k + 1]} ${u}%,${from})`\n return { style: { '--tc-cell-fill': color }, color }\n }\n const pct = share(v)\n return {\n style: `--tc-heat:${round(pct * 100)}%`,\n color: bySeries ? shade(pct, slotColor(row, slot(row))) : shade(pct),\n }\n }\n\n // Margins for the labels, then one band per column and per row.\n const pad = insets(options.padding, 0)\n const showX = options.x?.show !== false && labels.length > 0\n const showY = options.y?.show !== false && rows.length > 0\n const rowTicks = rows.map((s, i) => ({ value: i, position: 0, label: s.name }))\n const left = showY ? axisSize('left', rowTicks, fontSize) : 0\n const bottom = showX ? axisSize('bottom', [{ value: 0, position: 0, label: 'M' }], fontSize) : 0\n // The last column label is centered on its column: what is wider than half a\n // column needs room on the right.\n const lastLabel = showX\n ? estimateTextWidth(\n formatLabel(labels[labels.length - 1] as Label, labels.length - 1),\n fontSize,\n )\n : 0\n const halfColumn = (width - pad.left - pad.right - left) / Math.max(1, labels.length) / 2\n const area = innerRect(width, height, {\n top: pad.top,\n right: pad.right + Math.max(0, Math.ceil(lastLabel / 2 - halfColumn)),\n bottom: pad.bottom + bottom,\n left: pad.left + left,\n })\n const x = band(\n labels.map((_, i) => i),\n [area.x, area.x + area.width],\n )\n const y = band(\n rows.map((_, i) => i),\n [area.y, area.y + area.height],\n )\n const cellW = Math.max(0, x.bandwidth - gap)\n const cellH = Math.max(0, y.bandwidth - gap)\n const cellX = (i: number) => x.at(i) + gap / 2\n const cellY = (j: number) => y.at(j) + gap / 2\n const valueAt = (i: number, j: number) => {\n const v = rows[j]?.values[i]\n return v != null && Number.isFinite(v) ? v : null\n }\n\n // One hit per column; every row is an item, the hovered row is active.\n const hitAt = (i: number, row = 0): Hit | null => {\n if (i < 0 || i >= labels.length || rows.length === 0) return null\n const j = Math.max(0, Math.min(rows.length - 1, row))\n const items: HitItem[] = rows.map((s, r) => {\n const v = valueAt(i, r)\n const range = ranges && v !== null ? ranges[rangeOf(ranges, v)] : undefined\n return {\n name: s.name,\n seriesIndex: r,\n value: v,\n // With ranges, the band's name says what the value means.\n text: v === null ? '–' : range?.name ? `${value(v)} · ${range.name}` : value(v),\n x: cellX(i) + cellW / 2,\n y: cellY(r) + cellH / 2,\n box: { x: cellX(i), y: cellY(r), width: cellW, height: cellH },\n color: v === null ? 'var(--tc-grid-color)' : paint(v, s).color,\n }\n })\n return {\n index: i,\n label: labelKey(labels[i] as Label),\n title: formatLabel(labels[i] as Label, i),\n x: cellX(i) + cellW / 2,\n area,\n items,\n seriesIndex: j,\n // A ring just outside the hovered cell.\n mark: {\n d: ringPath(cellX(i) - 2, cellY(j) - 2, cellW + 4, cellH + 4, radius + 2),\n x: 0,\n y: 0,\n },\n }\n }\n\n const interaction: Interaction = {\n count: labels.length,\n hitIndex: (i, row) => hitAt(i, row),\n hitTest(px, py) {\n if (px < area.x || px > area.x + area.width || py < area.y || py > area.y + area.height) {\n return null\n }\n const i = Math.min(labels.length - 1, Math.floor((px - area.x) / (x.step || 1)))\n const j = Math.min(rows.length - 1, Math.floor((py - area.y) / (y.step || 1)))\n return hitAt(i, j)\n },\n }\n ctx.onHitTest(interaction)\n\n const cells = rows.map((s, j) =>\n h(\n 'g',\n {\n key: seriesKey(s),\n // Colored by series, a row takes its palette slot like any series.\n class: ['tc-heatmap-row', bySeries && ['tc-series', `tc-series-${slot(s) + 1}`]],\n 'data-series': s.name,\n style: bySeries ? { '--tc-series-color': s.color } : undefined,\n },\n labels.map((label, i) => {\n const v = valueAt(i, j)\n const painted = v === null ? undefined : paint(v, s)\n return h('rect', {\n key: labelKey(label),\n class: ['tc-cell', (v === null || painted?.empty) && 'tc-cell-empty'],\n x: round(cellX(i)),\n y: round(cellY(j)),\n width: round(cellW),\n height: round(cellH),\n rx: round(Math.min(radius, cellW / 2, cellH / 2)),\n style: painted?.style,\n })\n }),\n ),\n )\n\n const xTicks = showX\n ? thinTicks(\n bandTicks(x, (_, i) => formatLabel(labels[i] as Label, i)),\n 'bottom',\n fontSize,\n )\n : []\n const yTicks = showY ? bandTicks(y, (_, j) => rows[j]?.name ?? '') : []\n\n return [\n h('g', { class: 'tc-heatmap-cells' }, cells),\n showX && axis({ position: 'bottom', ticks: xTicks, area }),\n showY && axis({ position: 'left', ticks: yTicks, area }),\n ]\n}\n\n/** Legend: the ranges, or the rows when colored by series; none for a single scale. */\nfunction heatmapLegend(options: HeatmapOptions): LegendItem[] {\n const { ranges } = options\n if (ranges?.length) {\n // The legend is asked with the whole config, so the names follow its locale.\n const value = formatNumber(options.format, (options as { locale?: Locale }).locale)\n return ranges.map((range, index) => ({\n key: rangeKey(range, index),\n name:\n range.name ??\n (range.from === undefined\n ? `< ${value(range.to ?? 0)}`\n : range.to === undefined\n ? `≥ ${value(range.from)}`\n : `${value(range.from)}–${value(range.to)}`),\n index,\n color: range.color,\n }))\n }\n if (options.colors && options.colors.length >= 2) return []\n return options.colorBy === 'series' ? seriesLegend(options.data) : []\n}\n\n/**\n * Heatmap: a grid of cells, one row per series and one column per label,\n * shaded from light to the full color by value (a single hue, so it reads\n * as magnitude). Set the hue with `--tc-heat-color`, or color the cells by\n * `ranges` of values, a `colors` scale (with a `mid` for diverging data),\n * or one palette color per row with `colorBy: 'series'`.\n *\n * ```ts\n * new Chart('#el', {\n * type: heatmap,\n * data: { labels: ['W1', 'W2', 'W3'], series: [{ name: 'Mon', values: [2, 4, 0] }] },\n * })\n * ```\n */\nexport const heatmap: ChartType<HeatmapOptions> = {\n name: 'heatmap',\n clean: cleanData(cleanSeries),\n render: renderHeatmap,\n legend: heatmapLegend,\n valueLabels: { marks: 'cell', format: (options) => options.format },\n // Cells are formatted as in the tooltip: `format` is the value format here, not `y.format`.\n table: (options, ctx, limit) =>\n seriesTable(\n { data: options.data, ...(options.x ? { x: options.x } : {}), y: { format: options.format } },\n ctx,\n limit,\n ),\n}\n"],"mappings":";;;;;;;;AA6EA,MAAM,QAAQ;AAEd,MAAM,QAAQ;;AAGd,MAAM,SAAS,OAAe,QAAQ,6CACpC,sBAAsB,MAAM,GAAGA,eAAAA,MAAM,QAAQ,GAAG,EAAE,IAAI,MAAM;;AAG9D,MAAM,YAAY,OAAqB,UAA0B,MAAM,QAAQ,SAAS,QAAQ;;AAGhG,MAAM,WAAW,QAAiC,MAChD,OAAO,WAAW,OAAO,EAAE,SAAS,KAAA,KAAa,KAAK,EAAE,UAAU,EAAE,OAAO,KAAA,KAAa,IAAI,EAAE,GAAG;;AAGnG,MAAM,aAAa,QAAgB,UACjC,OAAO,UAAU,QAAQ,IAAI,kBAAkB,QAAQ,EAAE,KAAK;;AAUhE,SAAS,SAAS,GAAW,GAAW,GAAW,KAAa,GAAmB;CACjF,MAAM,KAAK,KAAK,IAAI,GAAG,KAAK,IAAI,GAAG,IAAI,GAAG,MAAM,CAAC,CAAC;CAClD,MAAM,IAAIA,eAAAA;CACV,OACE,IAAI,EAAE,IAAI,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,IAAI,IAAI,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,SAAS,EAAE,IAAI,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,EAAA,GAClF,EAAE,IAAI,MAAM,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,SAAS,EAAE,IAAI,IAAI,EAAE,EAAE,GAAG,EAAE,IAAI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EAAE,OAAO;EAAQ,SAAS,YAAY,QAAQ;CAAO;CAElE,QAAQ,SAAS,KAAK,UACpBC,kBAAAA,YACE;EAAE,MAAM,QAAQ;EAAM,GAAI,QAAQ,IAAI,EAAE,GAAG,QAAQ,EAAE,IAAI,CAAC;EAAI,GAAG,EAAE,QAAQ,QAAQ,OAAO;CAAE,GAC5F,KACA,KACF;AACJ"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { a as InsetsInput } from "./annotations-Bp7HwtF5.js";
|
|
2
|
+
import { Q as CartesianData, a as ChartType, tt as Label } from "./chart-DyN7bcx8.js";
|
|
3
|
+
import { c as NumberFormat } from "./time-CHjiY9Q4.js";
|
|
4
|
+
//#region src/charts/heatmap.d.ts
|
|
5
|
+
/** A band of values drawn in one color, with its own legend entry. */
|
|
6
|
+
interface HeatmapRange {
|
|
7
|
+
/** Lowest value in the band (inclusive). Leave it out for "everything below `to`". */
|
|
8
|
+
from?: number;
|
|
9
|
+
/** Value where the band ends (exclusive). Leave it out on the last band. */
|
|
10
|
+
to?: number;
|
|
11
|
+
/**
|
|
12
|
+
* Any CSS color, including `var(--tc-color-3)`.
|
|
13
|
+
* Values that could inject CSS (`;`, quotes, `url()` …) are ignored, so colors from user data are safe.
|
|
14
|
+
*/
|
|
15
|
+
color: string;
|
|
16
|
+
/** Legend and tooltip name, e.g. `'High'`. Defaults to the range, e.g. `10–30`. */
|
|
17
|
+
name?: string;
|
|
18
|
+
}
|
|
19
|
+
interface HeatmapOptions {
|
|
20
|
+
/** Columns are the labels, rows are the series (first series on top). */
|
|
21
|
+
data: CartesianData;
|
|
22
|
+
/** Value shown with the lightest shade (or the first color). Defaults to the smaller of `0` and the data minimum. */
|
|
23
|
+
min?: number;
|
|
24
|
+
/** Value shown with the full color (or the last color). Defaults to the data maximum. */
|
|
25
|
+
max?: number;
|
|
26
|
+
/**
|
|
27
|
+
* Discrete bands of values, each in its own color and legend entry (which
|
|
28
|
+
* also hides the band's cells). Takes precedence over `colors` and `colorBy`.
|
|
29
|
+
*/
|
|
30
|
+
ranges?: readonly HeatmapRange[];
|
|
31
|
+
/**
|
|
32
|
+
* A continuous scale through two or more colors (any CSS color, including
|
|
33
|
+
* `var(--tc-…)`), from `min` to `max`. For values around a reference
|
|
34
|
+
* point, use two hues with a neutral middle, e.g.
|
|
35
|
+
* `['var(--tc-color-1)', 'var(--tc-grid-color)', 'var(--tc-color-8)']`.
|
|
36
|
+
* Values that could inject CSS are ignored, as for series colors.
|
|
37
|
+
*/
|
|
38
|
+
colors?: readonly string[];
|
|
39
|
+
/** Value placed on the middle color of `colors` (e.g. `0` for changes). Defaults to halfway. */
|
|
40
|
+
mid?: number;
|
|
41
|
+
/**
|
|
42
|
+
* `'series'` shades every row in its own palette color (with a legend of
|
|
43
|
+
* the rows); `'value'` (the default) uses one hue, `--tc-heat-color`.
|
|
44
|
+
*/
|
|
45
|
+
colorBy?: "value" | "series";
|
|
46
|
+
/** Space between cells in pixels, drawn as surface. Defaults to `2`. */
|
|
47
|
+
gap?: number;
|
|
48
|
+
/** Corner radius of the cells. Defaults to `3`. */
|
|
49
|
+
radius?: number;
|
|
50
|
+
/** Format of the values (tooltip, table). */
|
|
51
|
+
format?: NumberFormat;
|
|
52
|
+
/** Column labels along the bottom. */
|
|
53
|
+
x?: {
|
|
54
|
+
show?: boolean;
|
|
55
|
+
format?: (label: Label, index: number) => string;
|
|
56
|
+
};
|
|
57
|
+
/** Row names on the left. */
|
|
58
|
+
y?: {
|
|
59
|
+
show?: boolean;
|
|
60
|
+
};
|
|
61
|
+
/** Extra space around the grid, in pixels. */
|
|
62
|
+
padding?: InsetsInput;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Heatmap: a grid of cells, one row per series and one column per label,
|
|
66
|
+
* shaded from light to the full color by value (a single hue, so it reads
|
|
67
|
+
* as magnitude). Set the hue with `--tc-heat-color`, or color the cells by
|
|
68
|
+
* `ranges` of values, a `colors` scale (with a `mid` for diverging data),
|
|
69
|
+
* or one palette color per row with `colorBy: 'series'`.
|
|
70
|
+
*
|
|
71
|
+
* ```ts
|
|
72
|
+
* new Chart('#el', {
|
|
73
|
+
* type: heatmap,
|
|
74
|
+
* data: { labels: ['W1', 'W2', 'W3'], series: [{ name: 'Mon', values: [2, 4, 0] }] },
|
|
75
|
+
* })
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
declare const heatmap: ChartType<HeatmapOptions>;
|
|
79
|
+
//#endregion
|
|
80
|
+
export { HeatmapRange as n, heatmap as r, HeatmapOptions as t };
|
|
81
|
+
//# sourceMappingURL=heatmap-BectCEeE.d.ts.map
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { a as InsetsInput } from "./annotations-lyt0I3HU.cjs";
|
|
2
|
+
import { Q as CartesianData, a as ChartType, tt as Label } from "./chart-D7ooEFnk.cjs";
|
|
3
|
+
import { c as NumberFormat } from "./time-CNVnt-B2.cjs";
|
|
4
|
+
//#region src/charts/heatmap.d.ts
|
|
5
|
+
/** A band of values drawn in one color, with its own legend entry. */
|
|
6
|
+
interface HeatmapRange {
|
|
7
|
+
/** Lowest value in the band (inclusive). Leave it out for "everything below `to`". */
|
|
8
|
+
from?: number;
|
|
9
|
+
/** Value where the band ends (exclusive). Leave it out on the last band. */
|
|
10
|
+
to?: number;
|
|
11
|
+
/**
|
|
12
|
+
* Any CSS color, including `var(--tc-color-3)`.
|
|
13
|
+
* Values that could inject CSS (`;`, quotes, `url()` …) are ignored, so colors from user data are safe.
|
|
14
|
+
*/
|
|
15
|
+
color: string;
|
|
16
|
+
/** Legend and tooltip name, e.g. `'High'`. Defaults to the range, e.g. `10–30`. */
|
|
17
|
+
name?: string;
|
|
18
|
+
}
|
|
19
|
+
interface HeatmapOptions {
|
|
20
|
+
/** Columns are the labels, rows are the series (first series on top). */
|
|
21
|
+
data: CartesianData;
|
|
22
|
+
/** Value shown with the lightest shade (or the first color). Defaults to the smaller of `0` and the data minimum. */
|
|
23
|
+
min?: number;
|
|
24
|
+
/** Value shown with the full color (or the last color). Defaults to the data maximum. */
|
|
25
|
+
max?: number;
|
|
26
|
+
/**
|
|
27
|
+
* Discrete bands of values, each in its own color and legend entry (which
|
|
28
|
+
* also hides the band's cells). Takes precedence over `colors` and `colorBy`.
|
|
29
|
+
*/
|
|
30
|
+
ranges?: readonly HeatmapRange[];
|
|
31
|
+
/**
|
|
32
|
+
* A continuous scale through two or more colors (any CSS color, including
|
|
33
|
+
* `var(--tc-…)`), from `min` to `max`. For values around a reference
|
|
34
|
+
* point, use two hues with a neutral middle, e.g.
|
|
35
|
+
* `['var(--tc-color-1)', 'var(--tc-grid-color)', 'var(--tc-color-8)']`.
|
|
36
|
+
* Values that could inject CSS are ignored, as for series colors.
|
|
37
|
+
*/
|
|
38
|
+
colors?: readonly string[];
|
|
39
|
+
/** Value placed on the middle color of `colors` (e.g. `0` for changes). Defaults to halfway. */
|
|
40
|
+
mid?: number;
|
|
41
|
+
/**
|
|
42
|
+
* `'series'` shades every row in its own palette color (with a legend of
|
|
43
|
+
* the rows); `'value'` (the default) uses one hue, `--tc-heat-color`.
|
|
44
|
+
*/
|
|
45
|
+
colorBy?: "value" | "series";
|
|
46
|
+
/** Space between cells in pixels, drawn as surface. Defaults to `2`. */
|
|
47
|
+
gap?: number;
|
|
48
|
+
/** Corner radius of the cells. Defaults to `3`. */
|
|
49
|
+
radius?: number;
|
|
50
|
+
/** Format of the values (tooltip, table). */
|
|
51
|
+
format?: NumberFormat;
|
|
52
|
+
/** Column labels along the bottom. */
|
|
53
|
+
x?: {
|
|
54
|
+
show?: boolean;
|
|
55
|
+
format?: (label: Label, index: number) => string;
|
|
56
|
+
};
|
|
57
|
+
/** Row names on the left. */
|
|
58
|
+
y?: {
|
|
59
|
+
show?: boolean;
|
|
60
|
+
};
|
|
61
|
+
/** Extra space around the grid, in pixels. */
|
|
62
|
+
padding?: InsetsInput;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Heatmap: a grid of cells, one row per series and one column per label,
|
|
66
|
+
* shaded from light to the full color by value (a single hue, so it reads
|
|
67
|
+
* as magnitude). Set the hue with `--tc-heat-color`, or color the cells by
|
|
68
|
+
* `ranges` of values, a `colors` scale (with a `mid` for diverging data),
|
|
69
|
+
* or one palette color per row with `colorBy: 'series'`.
|
|
70
|
+
*
|
|
71
|
+
* ```ts
|
|
72
|
+
* new Chart('#el', {
|
|
73
|
+
* type: heatmap,
|
|
74
|
+
* data: { labels: ['W1', 'W2', 'W3'], series: [{ name: 'Mon', values: [2, 4, 0] }] },
|
|
75
|
+
* })
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
declare const heatmap: ChartType<HeatmapOptions>;
|
|
79
|
+
//#endregion
|
|
80
|
+
export { HeatmapRange as n, heatmap as r, HeatmapOptions as t };
|
|
81
|
+
//# sourceMappingURL=heatmap-CCso6m61.d.cts.map
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import { a as round, i as insets, n as estimateTextWidth, r as innerRect } from "./layout-B3hiqVEw.js";
|
|
2
|
+
import { t as h } from "./vnode-tCWItoUH.js";
|
|
3
|
+
import { r as formatNumber } from "./format-lStwuc1L.js";
|
|
4
|
+
import { E as bandTicks, O as thinTicks, T as axisSize, f as seriesKey, m as seriesTable, o as labelKey, p as seriesLegend, u as resolveLabels, w as axis, x as band } from "./cartesian-Cr0AF0nG.js";
|
|
5
|
+
import { t as extent } from "./extent-BAMZo0Nq.js";
|
|
6
|
+
import { r as cleanSeries, t as cleanData } from "./clean-o1vDEhFV.js";
|
|
7
|
+
//#region src/charts/heatmap.ts
|
|
8
|
+
/** Share of the full color at the minimum, so zero still reads as a value, not a gap. */
|
|
9
|
+
const FLOOR = .08;
|
|
10
|
+
const EMPTY = "var(--tc-heat-empty,var(--tc-grid-color))";
|
|
11
|
+
/** Cell color at `share` (0…1) of the way from the empty shade to `color`. */
|
|
12
|
+
const shade = (share, color = "var(--tc-heat-color,var(--tc-color-1))") => `color-mix(in oklab,${color} ${round(share * 100)}%,${EMPTY})`;
|
|
13
|
+
/** Legend key of a range. */
|
|
14
|
+
const rangeKey = (range, index) => range.name ?? `range-${index + 1}`;
|
|
15
|
+
/** The first range containing `v` (`from` inclusive, `to` exclusive). */
|
|
16
|
+
const rangeOf = (ranges, v) => ranges.findIndex((r) => (r.from === void 0 || v >= r.from) && (r.to === void 0 || v < r.to));
|
|
17
|
+
/** Color of a palette slot by series index, as the CSS classes would pick it. */
|
|
18
|
+
const slotColor = (series, index) => series.color ?? (index < 8 ? `var(--tc-color-${index + 1})` : "var(--tc-color-other)");
|
|
19
|
+
/** A rounded rectangle as path data, for the hover ring. */
|
|
20
|
+
function ringPath(x, y, w, hgt, r) {
|
|
21
|
+
const rr = Math.max(0, Math.min(r, w / 2, hgt / 2));
|
|
22
|
+
const n = round;
|
|
23
|
+
return `M${n(x + rr)},${n(y)}H${n(x + w - rr)}A${n(rr)},${n(rr)},0,0,1,${n(x + w)},${n(y + rr)}V${n(y + hgt - rr)}A${n(rr)},${n(rr)},0,0,1,${n(x + w - rr)},${n(y + hgt)}H${n(x + rr)}A${n(rr)},${n(rr)},0,0,1,${n(x)},${n(y + hgt - rr)}V${n(y + rr)}A${n(rr)},${n(rr)},0,0,1,${n(x + rr)},${n(y)}Z`;
|
|
24
|
+
}
|
|
25
|
+
function renderHeatmap(options, ctx) {
|
|
26
|
+
const { width, height, fontSize, locale } = ctx;
|
|
27
|
+
const { gap = 2, radius = 3 } = options;
|
|
28
|
+
const labels = resolveLabels(options.data);
|
|
29
|
+
const formatLabel = options.x?.format ?? ((label) => String(label));
|
|
30
|
+
const value = formatNumber(options.format, locale);
|
|
31
|
+
const all = options.data.series.flatMap((s) => s.values);
|
|
32
|
+
const [dataMin, dataMax] = extent(all) ?? [0, 1];
|
|
33
|
+
const lo = options.min ?? Math.min(0, dataMin);
|
|
34
|
+
const hi = options.max ?? dataMax;
|
|
35
|
+
/** Position of a value in the domain, 0…1 (through `mid` for a scale with a middle). */
|
|
36
|
+
const position = (v) => {
|
|
37
|
+
const { mid } = options;
|
|
38
|
+
let t;
|
|
39
|
+
if (mid !== void 0 && options.colors && lo < mid && mid < hi) t = v <= mid ? (v - lo) / (mid - lo) * .5 : .5 + (v - mid) / (hi - mid) * .5;
|
|
40
|
+
else t = hi > lo ? (v - lo) / (hi - lo) : v > lo ? 1 : 0;
|
|
41
|
+
return Math.min(1, Math.max(0, t));
|
|
42
|
+
};
|
|
43
|
+
const share = (v) => FLOOR + .92 * position(v);
|
|
44
|
+
const ranges = options.ranges?.length ? options.ranges : void 0;
|
|
45
|
+
const stops = !ranges && options.colors && options.colors.length >= 2 ? options.colors : void 0;
|
|
46
|
+
const bySeries = !ranges && !stops && options.colorBy === "series";
|
|
47
|
+
const rows = bySeries ? options.data.series.filter((s) => !ctx.hidden.has(seriesKey(s))) : options.data.series;
|
|
48
|
+
const slot = (row) => options.data.series.indexOf(row);
|
|
49
|
+
/** How the cell of `row` with value `v` is painted in the active color mode. */
|
|
50
|
+
const paint = (v, row) => {
|
|
51
|
+
if (ranges) {
|
|
52
|
+
const index = rangeOf(ranges, v);
|
|
53
|
+
const range = ranges[index];
|
|
54
|
+
if (!range || ctx.hidden.has(rangeKey(range, index))) return {
|
|
55
|
+
color: EMPTY,
|
|
56
|
+
empty: true
|
|
57
|
+
};
|
|
58
|
+
return {
|
|
59
|
+
style: { "--tc-cell-fill": range.color },
|
|
60
|
+
color: range.color
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
if (stops) {
|
|
64
|
+
const at = position(v) * (stops.length - 1);
|
|
65
|
+
const k = Math.min(stops.length - 2, Math.floor(at));
|
|
66
|
+
const u = round((at - k) * 100);
|
|
67
|
+
const from = stops[k];
|
|
68
|
+
const color = u <= 0 ? from : u >= 100 ? stops[k + 1] : `color-mix(in oklab,${stops[k + 1]} ${u}%,${from})`;
|
|
69
|
+
return {
|
|
70
|
+
style: { "--tc-cell-fill": color },
|
|
71
|
+
color
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
const pct = share(v);
|
|
75
|
+
return {
|
|
76
|
+
style: `--tc-heat:${round(pct * 100)}%`,
|
|
77
|
+
color: bySeries ? shade(pct, slotColor(row, slot(row))) : shade(pct)
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
const pad = insets(options.padding, 0);
|
|
81
|
+
const showX = options.x?.show !== false && labels.length > 0;
|
|
82
|
+
const showY = options.y?.show !== false && rows.length > 0;
|
|
83
|
+
const rowTicks = rows.map((s, i) => ({
|
|
84
|
+
value: i,
|
|
85
|
+
position: 0,
|
|
86
|
+
label: s.name
|
|
87
|
+
}));
|
|
88
|
+
const left = showY ? axisSize("left", rowTicks, fontSize) : 0;
|
|
89
|
+
const bottom = showX ? axisSize("bottom", [{
|
|
90
|
+
value: 0,
|
|
91
|
+
position: 0,
|
|
92
|
+
label: "M"
|
|
93
|
+
}], fontSize) : 0;
|
|
94
|
+
const lastLabel = showX ? estimateTextWidth(formatLabel(labels[labels.length - 1], labels.length - 1), fontSize) : 0;
|
|
95
|
+
const halfColumn = (width - pad.left - pad.right - left) / Math.max(1, labels.length) / 2;
|
|
96
|
+
const area = innerRect(width, height, {
|
|
97
|
+
top: pad.top,
|
|
98
|
+
right: pad.right + Math.max(0, Math.ceil(lastLabel / 2 - halfColumn)),
|
|
99
|
+
bottom: pad.bottom + bottom,
|
|
100
|
+
left: pad.left + left
|
|
101
|
+
});
|
|
102
|
+
const x = band(labels.map((_, i) => i), [area.x, area.x + area.width]);
|
|
103
|
+
const y = band(rows.map((_, i) => i), [area.y, area.y + area.height]);
|
|
104
|
+
const cellW = Math.max(0, x.bandwidth - gap);
|
|
105
|
+
const cellH = Math.max(0, y.bandwidth - gap);
|
|
106
|
+
const cellX = (i) => x.at(i) + gap / 2;
|
|
107
|
+
const cellY = (j) => y.at(j) + gap / 2;
|
|
108
|
+
const valueAt = (i, j) => {
|
|
109
|
+
const v = rows[j]?.values[i];
|
|
110
|
+
return v != null && Number.isFinite(v) ? v : null;
|
|
111
|
+
};
|
|
112
|
+
const hitAt = (i, row = 0) => {
|
|
113
|
+
if (i < 0 || i >= labels.length || rows.length === 0) return null;
|
|
114
|
+
const j = Math.max(0, Math.min(rows.length - 1, row));
|
|
115
|
+
const items = rows.map((s, r) => {
|
|
116
|
+
const v = valueAt(i, r);
|
|
117
|
+
const range = ranges && v !== null ? ranges[rangeOf(ranges, v)] : void 0;
|
|
118
|
+
return {
|
|
119
|
+
name: s.name,
|
|
120
|
+
seriesIndex: r,
|
|
121
|
+
value: v,
|
|
122
|
+
text: v === null ? "–" : range?.name ? `${value(v)} · ${range.name}` : value(v),
|
|
123
|
+
x: cellX(i) + cellW / 2,
|
|
124
|
+
y: cellY(r) + cellH / 2,
|
|
125
|
+
box: {
|
|
126
|
+
x: cellX(i),
|
|
127
|
+
y: cellY(r),
|
|
128
|
+
width: cellW,
|
|
129
|
+
height: cellH
|
|
130
|
+
},
|
|
131
|
+
color: v === null ? "var(--tc-grid-color)" : paint(v, s).color
|
|
132
|
+
};
|
|
133
|
+
});
|
|
134
|
+
return {
|
|
135
|
+
index: i,
|
|
136
|
+
label: labelKey(labels[i]),
|
|
137
|
+
title: formatLabel(labels[i], i),
|
|
138
|
+
x: cellX(i) + cellW / 2,
|
|
139
|
+
area,
|
|
140
|
+
items,
|
|
141
|
+
seriesIndex: j,
|
|
142
|
+
mark: {
|
|
143
|
+
d: ringPath(cellX(i) - 2, cellY(j) - 2, cellW + 4, cellH + 4, radius + 2),
|
|
144
|
+
x: 0,
|
|
145
|
+
y: 0
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
};
|
|
149
|
+
const interaction = {
|
|
150
|
+
count: labels.length,
|
|
151
|
+
hitIndex: (i, row) => hitAt(i, row),
|
|
152
|
+
hitTest(px, py) {
|
|
153
|
+
if (px < area.x || px > area.x + area.width || py < area.y || py > area.y + area.height) return null;
|
|
154
|
+
const i = Math.min(labels.length - 1, Math.floor((px - area.x) / (x.step || 1)));
|
|
155
|
+
const j = Math.min(rows.length - 1, Math.floor((py - area.y) / (y.step || 1)));
|
|
156
|
+
return hitAt(i, j);
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
ctx.onHitTest(interaction);
|
|
160
|
+
const cells = rows.map((s, j) => h("g", {
|
|
161
|
+
key: seriesKey(s),
|
|
162
|
+
class: ["tc-heatmap-row", bySeries && ["tc-series", `tc-series-${slot(s) + 1}`]],
|
|
163
|
+
"data-series": s.name,
|
|
164
|
+
style: bySeries ? { "--tc-series-color": s.color } : void 0
|
|
165
|
+
}, labels.map((label, i) => {
|
|
166
|
+
const v = valueAt(i, j);
|
|
167
|
+
const painted = v === null ? void 0 : paint(v, s);
|
|
168
|
+
return h("rect", {
|
|
169
|
+
key: labelKey(label),
|
|
170
|
+
class: ["tc-cell", (v === null || painted?.empty) && "tc-cell-empty"],
|
|
171
|
+
x: round(cellX(i)),
|
|
172
|
+
y: round(cellY(j)),
|
|
173
|
+
width: round(cellW),
|
|
174
|
+
height: round(cellH),
|
|
175
|
+
rx: round(Math.min(radius, cellW / 2, cellH / 2)),
|
|
176
|
+
style: painted?.style
|
|
177
|
+
});
|
|
178
|
+
})));
|
|
179
|
+
const xTicks = showX ? thinTicks(bandTicks(x, (_, i) => formatLabel(labels[i], i)), "bottom", fontSize) : [];
|
|
180
|
+
const yTicks = showY ? bandTicks(y, (_, j) => rows[j]?.name ?? "") : [];
|
|
181
|
+
return [
|
|
182
|
+
h("g", { class: "tc-heatmap-cells" }, cells),
|
|
183
|
+
showX && axis({
|
|
184
|
+
position: "bottom",
|
|
185
|
+
ticks: xTicks,
|
|
186
|
+
area
|
|
187
|
+
}),
|
|
188
|
+
showY && axis({
|
|
189
|
+
position: "left",
|
|
190
|
+
ticks: yTicks,
|
|
191
|
+
area
|
|
192
|
+
})
|
|
193
|
+
];
|
|
194
|
+
}
|
|
195
|
+
/** Legend: the ranges, or the rows when colored by series; none for a single scale. */
|
|
196
|
+
function heatmapLegend(options) {
|
|
197
|
+
const { ranges } = options;
|
|
198
|
+
if (ranges?.length) {
|
|
199
|
+
const value = formatNumber(options.format, options.locale);
|
|
200
|
+
return ranges.map((range, index) => ({
|
|
201
|
+
key: rangeKey(range, index),
|
|
202
|
+
name: range.name ?? (range.from === void 0 ? `< ${value(range.to ?? 0)}` : range.to === void 0 ? `≥ ${value(range.from)}` : `${value(range.from)}–${value(range.to)}`),
|
|
203
|
+
index,
|
|
204
|
+
color: range.color
|
|
205
|
+
}));
|
|
206
|
+
}
|
|
207
|
+
if (options.colors && options.colors.length >= 2) return [];
|
|
208
|
+
return options.colorBy === "series" ? seriesLegend(options.data) : [];
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Heatmap: a grid of cells, one row per series and one column per label,
|
|
212
|
+
* shaded from light to the full color by value (a single hue, so it reads
|
|
213
|
+
* as magnitude). Set the hue with `--tc-heat-color`, or color the cells by
|
|
214
|
+
* `ranges` of values, a `colors` scale (with a `mid` for diverging data),
|
|
215
|
+
* or one palette color per row with `colorBy: 'series'`.
|
|
216
|
+
*
|
|
217
|
+
* ```ts
|
|
218
|
+
* new Chart('#el', {
|
|
219
|
+
* type: heatmap,
|
|
220
|
+
* data: { labels: ['W1', 'W2', 'W3'], series: [{ name: 'Mon', values: [2, 4, 0] }] },
|
|
221
|
+
* })
|
|
222
|
+
* ```
|
|
223
|
+
*/
|
|
224
|
+
const heatmap = {
|
|
225
|
+
name: "heatmap",
|
|
226
|
+
clean: cleanData(cleanSeries),
|
|
227
|
+
render: renderHeatmap,
|
|
228
|
+
legend: heatmapLegend,
|
|
229
|
+
valueLabels: {
|
|
230
|
+
marks: "cell",
|
|
231
|
+
format: (options) => options.format
|
|
232
|
+
},
|
|
233
|
+
table: (options, ctx, limit) => seriesTable({
|
|
234
|
+
data: options.data,
|
|
235
|
+
...options.x ? { x: options.x } : {},
|
|
236
|
+
y: { format: options.format }
|
|
237
|
+
}, ctx, limit)
|
|
238
|
+
};
|
|
239
|
+
//#endregion
|
|
240
|
+
export { heatmap as t };
|
|
241
|
+
|
|
242
|
+
//# sourceMappingURL=heatmap-DSZ2bVIa.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"heatmap-DSZ2bVIa.js","names":[],"sources":["../src/charts/heatmap.ts"],"sourcesContent":["import type { ChartType, LegendItem, RenderContext } from '../chart.ts'\nimport { axis, axisSize, bandTicks, thinTicks } from '../components/axis.ts'\nimport { formatNumber, type Locale, type NumberFormat } from '../format.ts'\nimport type { Hit, HitItem, Interaction } from '../interaction.ts'\nimport { estimateTextWidth, type InsetsInput, innerRect, insets, round } from '../layout.ts'\nimport { band } from '../scales/band.ts'\nimport { extent } from '../scales/extent.ts'\nimport { h, type StyleValue } from '../vnode.ts'\nimport {\n type CartesianData,\n type Label,\n labelKey,\n resolveLabels,\n type Series,\n seriesKey,\n seriesLegend,\n seriesTable,\n} from './cartesian.ts'\nimport { cleanData, cleanSeries } from './clean.ts'\n\n/** A band of values drawn in one color, with its own legend entry. */\nexport interface HeatmapRange {\n /** Lowest value in the band (inclusive). Leave it out for \"everything below `to`\". */\n from?: number\n /** Value where the band ends (exclusive). Leave it out on the last band. */\n to?: number\n /**\n * Any CSS color, including `var(--tc-color-3)`.\n * Values that could inject CSS (`;`, quotes, `url()` …) are ignored, so colors from user data are safe.\n */\n color: string\n /** Legend and tooltip name, e.g. `'High'`. Defaults to the range, e.g. `10–30`. */\n name?: string\n}\n\nexport interface HeatmapOptions {\n /** Columns are the labels, rows are the series (first series on top). */\n data: CartesianData\n /** Value shown with the lightest shade (or the first color). Defaults to the smaller of `0` and the data minimum. */\n min?: number\n /** Value shown with the full color (or the last color). Defaults to the data maximum. */\n max?: number\n /**\n * Discrete bands of values, each in its own color and legend entry (which\n * also hides the band's cells). Takes precedence over `colors` and `colorBy`.\n */\n ranges?: readonly HeatmapRange[]\n /**\n * A continuous scale through two or more colors (any CSS color, including\n * `var(--tc-…)`), from `min` to `max`. For values around a reference\n * point, use two hues with a neutral middle, e.g.\n * `['var(--tc-color-1)', 'var(--tc-grid-color)', 'var(--tc-color-8)']`.\n * Values that could inject CSS are ignored, as for series colors.\n */\n colors?: readonly string[]\n /** Value placed on the middle color of `colors` (e.g. `0` for changes). Defaults to halfway. */\n mid?: number\n /**\n * `'series'` shades every row in its own palette color (with a legend of\n * the rows); `'value'` (the default) uses one hue, `--tc-heat-color`.\n */\n colorBy?: 'value' | 'series'\n /** Space between cells in pixels, drawn as surface. Defaults to `2`. */\n gap?: number\n /** Corner radius of the cells. Defaults to `3`. */\n radius?: number\n /** Format of the values (tooltip, table). */\n format?: NumberFormat\n /** Column labels along the bottom. */\n x?: { show?: boolean; format?: (label: Label, index: number) => string }\n /** Row names on the left. */\n y?: { show?: boolean }\n /** Extra space around the grid, in pixels. */\n padding?: InsetsInput\n}\n\n/** Share of the full color at the minimum, so zero still reads as a value, not a gap. */\nconst FLOOR = 0.08\n\nconst EMPTY = 'var(--tc-heat-empty,var(--tc-grid-color))'\n\n/** Cell color at `share` (0…1) of the way from the empty shade to `color`. */\nconst shade = (share: number, color = 'var(--tc-heat-color,var(--tc-color-1))'): string =>\n `color-mix(in oklab,${color} ${round(share * 100)}%,${EMPTY})`\n\n/** Legend key of a range. */\nconst rangeKey = (range: HeatmapRange, index: number): string => range.name ?? `range-${index + 1}`\n\n/** The first range containing `v` (`from` inclusive, `to` exclusive). */\nconst rangeOf = (ranges: readonly HeatmapRange[], v: number): number =>\n ranges.findIndex((r) => (r.from === undefined || v >= r.from) && (r.to === undefined || v < r.to))\n\n/** Color of a palette slot by series index, as the CSS classes would pick it. */\nconst slotColor = (series: Series, index: number): string =>\n series.color ?? (index < 8 ? `var(--tc-color-${index + 1})` : 'var(--tc-color-other)')\n\n/** How one cell is painted: inline style, the tooltip swatch, and whether it is drawn empty. */\ninterface Paint {\n style?: StyleValue\n color: string\n empty?: boolean\n}\n\n/** A rounded rectangle as path data, for the hover ring. */\nfunction ringPath(x: number, y: number, w: number, hgt: number, r: number): string {\n const rr = Math.max(0, Math.min(r, w / 2, hgt / 2))\n const n = round\n return (\n `M${n(x + rr)},${n(y)}H${n(x + w - rr)}A${n(rr)},${n(rr)},0,0,1,${n(x + w)},${n(y + rr)}` +\n `V${n(y + hgt - rr)}A${n(rr)},${n(rr)},0,0,1,${n(x + w - rr)},${n(y + hgt)}` +\n `H${n(x + rr)}A${n(rr)},${n(rr)},0,0,1,${n(x)},${n(y + hgt - rr)}` +\n `V${n(y + rr)}A${n(rr)},${n(rr)},0,0,1,${n(x + rr)},${n(y)}Z`\n )\n}\n\nfunction renderHeatmap(options: HeatmapOptions, ctx: RenderContext) {\n const { width, height, fontSize, locale } = ctx\n const { gap = 2, radius = 3 } = options\n const labels = resolveLabels(options.data)\n const formatLabel = options.x?.format ?? ((label: Label) => String(label))\n const value = formatNumber(options.format, locale)\n\n // Color domain.\n const all = options.data.series.flatMap((s) => s.values)\n const [dataMin, dataMax] = extent(all) ?? [0, 1]\n const lo = options.min ?? Math.min(0, dataMin)\n const hi = options.max ?? dataMax\n /** Position of a value in the domain, 0…1 (through `mid` for a scale with a middle). */\n const position = (v: number) => {\n const { mid } = options\n let t: number\n if (mid !== undefined && options.colors && lo < mid && mid < hi) {\n t = v <= mid ? ((v - lo) / (mid - lo)) * 0.5 : 0.5 + ((v - mid) / (hi - mid)) * 0.5\n } else {\n t = hi > lo ? (v - lo) / (hi - lo) : v > lo ? 1 : 0\n }\n return Math.min(1, Math.max(0, t))\n }\n const share = (v: number) => FLOOR + (1 - FLOOR) * position(v)\n\n const ranges = options.ranges?.length ? options.ranges : undefined\n const stops = !ranges && options.colors && options.colors.length >= 2 ? options.colors : undefined\n const bySeries = !ranges && !stops && options.colorBy === 'series'\n // Rows hidden from the legend (rows are legend entries when colored by series).\n const rows = bySeries\n ? options.data.series.filter((s) => !ctx.hidden.has(seriesKey(s)))\n : options.data.series\n const slot = (row: Series) => options.data.series.indexOf(row)\n\n /** How the cell of `row` with value `v` is painted in the active color mode. */\n const paint = (v: number, row: Series): Paint => {\n if (ranges) {\n const index = rangeOf(ranges, v)\n const range = ranges[index]\n if (!range || ctx.hidden.has(rangeKey(range, index))) return { color: EMPTY, empty: true }\n return { style: { '--tc-cell-fill': range.color }, color: range.color }\n }\n if (stops) {\n const at = position(v) * (stops.length - 1)\n const k = Math.min(stops.length - 2, Math.floor(at))\n const u = round((at - k) * 100)\n const from = stops[k] as string\n const color =\n u <= 0\n ? from\n : u >= 100\n ? (stops[k + 1] as string)\n : `color-mix(in oklab,${stops[k + 1]} ${u}%,${from})`\n return { style: { '--tc-cell-fill': color }, color }\n }\n const pct = share(v)\n return {\n style: `--tc-heat:${round(pct * 100)}%`,\n color: bySeries ? shade(pct, slotColor(row, slot(row))) : shade(pct),\n }\n }\n\n // Margins for the labels, then one band per column and per row.\n const pad = insets(options.padding, 0)\n const showX = options.x?.show !== false && labels.length > 0\n const showY = options.y?.show !== false && rows.length > 0\n const rowTicks = rows.map((s, i) => ({ value: i, position: 0, label: s.name }))\n const left = showY ? axisSize('left', rowTicks, fontSize) : 0\n const bottom = showX ? axisSize('bottom', [{ value: 0, position: 0, label: 'M' }], fontSize) : 0\n // The last column label is centered on its column: what is wider than half a\n // column needs room on the right.\n const lastLabel = showX\n ? estimateTextWidth(\n formatLabel(labels[labels.length - 1] as Label, labels.length - 1),\n fontSize,\n )\n : 0\n const halfColumn = (width - pad.left - pad.right - left) / Math.max(1, labels.length) / 2\n const area = innerRect(width, height, {\n top: pad.top,\n right: pad.right + Math.max(0, Math.ceil(lastLabel / 2 - halfColumn)),\n bottom: pad.bottom + bottom,\n left: pad.left + left,\n })\n const x = band(\n labels.map((_, i) => i),\n [area.x, area.x + area.width],\n )\n const y = band(\n rows.map((_, i) => i),\n [area.y, area.y + area.height],\n )\n const cellW = Math.max(0, x.bandwidth - gap)\n const cellH = Math.max(0, y.bandwidth - gap)\n const cellX = (i: number) => x.at(i) + gap / 2\n const cellY = (j: number) => y.at(j) + gap / 2\n const valueAt = (i: number, j: number) => {\n const v = rows[j]?.values[i]\n return v != null && Number.isFinite(v) ? v : null\n }\n\n // One hit per column; every row is an item, the hovered row is active.\n const hitAt = (i: number, row = 0): Hit | null => {\n if (i < 0 || i >= labels.length || rows.length === 0) return null\n const j = Math.max(0, Math.min(rows.length - 1, row))\n const items: HitItem[] = rows.map((s, r) => {\n const v = valueAt(i, r)\n const range = ranges && v !== null ? ranges[rangeOf(ranges, v)] : undefined\n return {\n name: s.name,\n seriesIndex: r,\n value: v,\n // With ranges, the band's name says what the value means.\n text: v === null ? '–' : range?.name ? `${value(v)} · ${range.name}` : value(v),\n x: cellX(i) + cellW / 2,\n y: cellY(r) + cellH / 2,\n box: { x: cellX(i), y: cellY(r), width: cellW, height: cellH },\n color: v === null ? 'var(--tc-grid-color)' : paint(v, s).color,\n }\n })\n return {\n index: i,\n label: labelKey(labels[i] as Label),\n title: formatLabel(labels[i] as Label, i),\n x: cellX(i) + cellW / 2,\n area,\n items,\n seriesIndex: j,\n // A ring just outside the hovered cell.\n mark: {\n d: ringPath(cellX(i) - 2, cellY(j) - 2, cellW + 4, cellH + 4, radius + 2),\n x: 0,\n y: 0,\n },\n }\n }\n\n const interaction: Interaction = {\n count: labels.length,\n hitIndex: (i, row) => hitAt(i, row),\n hitTest(px, py) {\n if (px < area.x || px > area.x + area.width || py < area.y || py > area.y + area.height) {\n return null\n }\n const i = Math.min(labels.length - 1, Math.floor((px - area.x) / (x.step || 1)))\n const j = Math.min(rows.length - 1, Math.floor((py - area.y) / (y.step || 1)))\n return hitAt(i, j)\n },\n }\n ctx.onHitTest(interaction)\n\n const cells = rows.map((s, j) =>\n h(\n 'g',\n {\n key: seriesKey(s),\n // Colored by series, a row takes its palette slot like any series.\n class: ['tc-heatmap-row', bySeries && ['tc-series', `tc-series-${slot(s) + 1}`]],\n 'data-series': s.name,\n style: bySeries ? { '--tc-series-color': s.color } : undefined,\n },\n labels.map((label, i) => {\n const v = valueAt(i, j)\n const painted = v === null ? undefined : paint(v, s)\n return h('rect', {\n key: labelKey(label),\n class: ['tc-cell', (v === null || painted?.empty) && 'tc-cell-empty'],\n x: round(cellX(i)),\n y: round(cellY(j)),\n width: round(cellW),\n height: round(cellH),\n rx: round(Math.min(radius, cellW / 2, cellH / 2)),\n style: painted?.style,\n })\n }),\n ),\n )\n\n const xTicks = showX\n ? thinTicks(\n bandTicks(x, (_, i) => formatLabel(labels[i] as Label, i)),\n 'bottom',\n fontSize,\n )\n : []\n const yTicks = showY ? bandTicks(y, (_, j) => rows[j]?.name ?? '') : []\n\n return [\n h('g', { class: 'tc-heatmap-cells' }, cells),\n showX && axis({ position: 'bottom', ticks: xTicks, area }),\n showY && axis({ position: 'left', ticks: yTicks, area }),\n ]\n}\n\n/** Legend: the ranges, or the rows when colored by series; none for a single scale. */\nfunction heatmapLegend(options: HeatmapOptions): LegendItem[] {\n const { ranges } = options\n if (ranges?.length) {\n // The legend is asked with the whole config, so the names follow its locale.\n const value = formatNumber(options.format, (options as { locale?: Locale }).locale)\n return ranges.map((range, index) => ({\n key: rangeKey(range, index),\n name:\n range.name ??\n (range.from === undefined\n ? `< ${value(range.to ?? 0)}`\n : range.to === undefined\n ? `≥ ${value(range.from)}`\n : `${value(range.from)}–${value(range.to)}`),\n index,\n color: range.color,\n }))\n }\n if (options.colors && options.colors.length >= 2) return []\n return options.colorBy === 'series' ? seriesLegend(options.data) : []\n}\n\n/**\n * Heatmap: a grid of cells, one row per series and one column per label,\n * shaded from light to the full color by value (a single hue, so it reads\n * as magnitude). Set the hue with `--tc-heat-color`, or color the cells by\n * `ranges` of values, a `colors` scale (with a `mid` for diverging data),\n * or one palette color per row with `colorBy: 'series'`.\n *\n * ```ts\n * new Chart('#el', {\n * type: heatmap,\n * data: { labels: ['W1', 'W2', 'W3'], series: [{ name: 'Mon', values: [2, 4, 0] }] },\n * })\n * ```\n */\nexport const heatmap: ChartType<HeatmapOptions> = {\n name: 'heatmap',\n clean: cleanData(cleanSeries),\n render: renderHeatmap,\n legend: heatmapLegend,\n valueLabels: { marks: 'cell', format: (options) => options.format },\n // Cells are formatted as in the tooltip: `format` is the value format here, not `y.format`.\n table: (options, ctx, limit) =>\n seriesTable(\n { data: options.data, ...(options.x ? { x: options.x } : {}), y: { format: options.format } },\n ctx,\n limit,\n ),\n}\n"],"mappings":";;;;;;;;AA6EA,MAAM,QAAQ;AAEd,MAAM,QAAQ;;AAGd,MAAM,SAAS,OAAe,QAAQ,6CACpC,sBAAsB,MAAM,GAAG,MAAM,QAAQ,GAAG,EAAE,IAAI,MAAM;;AAG9D,MAAM,YAAY,OAAqB,UAA0B,MAAM,QAAQ,SAAS,QAAQ;;AAGhG,MAAM,WAAW,QAAiC,MAChD,OAAO,WAAW,OAAO,EAAE,SAAS,KAAA,KAAa,KAAK,EAAE,UAAU,EAAE,OAAO,KAAA,KAAa,IAAI,EAAE,GAAG;;AAGnG,MAAM,aAAa,QAAgB,UACjC,OAAO,UAAU,QAAQ,IAAI,kBAAkB,QAAQ,EAAE,KAAK;;AAUhE,SAAS,SAAS,GAAW,GAAW,GAAW,KAAa,GAAmB;CACjF,MAAM,KAAK,KAAK,IAAI,GAAG,KAAK,IAAI,GAAG,IAAI,GAAG,MAAM,CAAC,CAAC;CAClD,MAAM,IAAI;CACV,OACE,IAAI,EAAE,IAAI,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,IAAI,IAAI,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,SAAS,EAAE,IAAI,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,EAAA,GAClF,EAAE,IAAI,MAAM,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,SAAS,EAAE,IAAI,IAAI,EAAE,EAAE,GAAG,EAAE,IAAI,GAAG,EAAA,GACrE,EAAE,IAAI,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,SAAS,EAAE,CAAC,EAAE,GAAG,EAAE,IAAI,MAAM,EAAE,EAAA,GAC3D,EA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AAE,UAAU;GAAU,OAAO;GAAQ;EAAK,CAAC;EACzD,SAAS,KAAK;GAAE,UAAU;GAAQ,OAAO;GAAQ;EAAK,CAAC;CACzD;AACF;;AAGA,SAAS,cAAc,SAAuC;CAC5D,MAAM,EAAE,WAAW;CACnB,IAAI,QAAQ,QAAQ;EAElB,MAAM,QAAQ,aAAa,QAAQ,QAAS,QAAgC,MAAM;EAClF,OAAO,OAAO,KAAK,OAAO,WAAW;GACnC,KAAK,SAAS,OAAO,KAAK;GAC1B,MACE,MAAM,SACL,MAAM,SAAS,KAAA,IACZ,KAAK,MAAM,MAAM,MAAM,CAAC,MACxB,MAAM,OAAO,KAAA,IACX,KAAK,MAAM,MAAM,IAAI,MACrB,GAAG,MAAM,MAAM,IAAI,EAAE,GAAG,MAAM,MAAM,EAAE;GAC9C;GACA,OAAO,MAAM;EACf,EAAE;CACJ;CACA,IAAI,QAAQ,UAAU,QAAQ,OAAO,UAAU,GAAG,OAAO,CAAC;CAC1D,OAAO,QAAQ,YAAY,WAAW,aAAa,QAAQ,IAAI,IAAI,CAAC;AACtE;;;;;;;;;;;;;;;AAgBA,MAAa,UAAqC;CAChD,MAAM;CACN,OAAO,UAAU,WAAW;CAC5B,QAAQ;CACR,QAAQ;CACR,aAAa;EAAE,OAAO;EAAQ,SAAS,YAAY,QAAQ;CAAO;CAElE,QAAQ,SAAS,KAAK,UACpB,YACE;EAAE,MAAM,QAAQ;EAAM,GAAI,QAAQ,IAAI,EAAE,GAAG,QAAQ,EAAE,IAAI,CAAC;EAAI,GAAG,EAAE,QAAQ,QAAQ,OAAO;CAAE,GAC5F,KACA,KACF;AACJ"}
|
package/dist/heatmap.cjs
ADDED
package/dist/heatmap.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { l as VNode } from "./vnode-BUflsBsa.cjs";
|
|
2
|
+
//#region src/render/hydrate.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Hydrate `el` for the root `vnode` when it is foreign markup (not rendered
|
|
5
|
+
* here) with the root's tag in namespace `ns`. Returns whether it did.
|
|
6
|
+
*/
|
|
7
|
+
declare function hydrate(el: Element, vnode: VNode, ns: string): boolean;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { hydrate as t };
|
|
10
|
+
//# sourceMappingURL=hydrate-CTTmQy0x.d.cts.map
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
const require_dom = require("./dom-CLF868Qs.cjs");
|
|
2
|
+
//#region src/render/hydrate.ts
|
|
3
|
+
/** Whether existing DOM `node` can stand for `vnode` in namespace `ns`. */
|
|
4
|
+
function matches(node, vnode, ns) {
|
|
5
|
+
return node.nodeType === 1 && node.localName === vnode.tag && node.namespaceURI === ns;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Claim server-rendered DOM for a tree: the element takes the vnode's
|
|
9
|
+
* attributes (extra ones are removed), and its children are matched by
|
|
10
|
+
* position: text with text, elements with the same tag (hydrated in turn).
|
|
11
|
+
* Anything that does not match is created in place, leftovers are removed.
|
|
12
|
+
* Afterwards the nodes are tracked like freshly rendered ones.
|
|
13
|
+
*/
|
|
14
|
+
function hydrateElement(el, vnode) {
|
|
15
|
+
const current = {};
|
|
16
|
+
for (const name of el.getAttributeNames()) current[name] = el.getAttribute(name);
|
|
17
|
+
if (current.style) current.style = "";
|
|
18
|
+
require_dom.patchAttrs(el, current, vnode.attrs);
|
|
19
|
+
const texts = vnode.children.some((child) => typeof child === "string");
|
|
20
|
+
for (const node of Array.from(el.childNodes)) if (node.nodeType === 8 || !texts && node.nodeType === 3) el.removeChild(node);
|
|
21
|
+
const ns = require_dom.childNamespace(el);
|
|
22
|
+
let node = el.firstChild;
|
|
23
|
+
for (const child of vnode.children) {
|
|
24
|
+
const next = node ? node.nextSibling : null;
|
|
25
|
+
if (typeof child === "string" ? node?.nodeType === 3 : node && matches(node, child, child.tag === "svg" ? "http://www.w3.org/2000/svg" : ns)) {
|
|
26
|
+
if (typeof child === "string") {
|
|
27
|
+
if (node.data !== child) node.data = child;
|
|
28
|
+
require_dom.rendered.set(node, child);
|
|
29
|
+
} else hydrateElement(node, child);
|
|
30
|
+
node = next;
|
|
31
|
+
} else {
|
|
32
|
+
const created = require_dom.createNode(child, ns, el.ownerDocument);
|
|
33
|
+
if (created) el.insertBefore(created, node);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
while (node) {
|
|
37
|
+
const extra = node;
|
|
38
|
+
node = node.nextSibling;
|
|
39
|
+
el.removeChild(extra);
|
|
40
|
+
}
|
|
41
|
+
require_dom.rendered.set(el, vnode);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Hydrate `el` for the root `vnode` when it is foreign markup (not rendered
|
|
45
|
+
* here) with the root's tag in namespace `ns`. Returns whether it did.
|
|
46
|
+
*/
|
|
47
|
+
function hydrate(el, vnode, ns) {
|
|
48
|
+
if (require_dom.rendered.has(el) || !matches(el, vnode, ns)) return false;
|
|
49
|
+
hydrateElement(el, vnode);
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
//#endregion
|
|
53
|
+
Object.defineProperty(exports, "hydrate", {
|
|
54
|
+
enumerable: true,
|
|
55
|
+
get: function() {
|
|
56
|
+
return hydrate;
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
//# sourceMappingURL=hydrate-CxwTXDqO.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hydrate-CxwTXDqO.cjs","names":["childNamespace","createNode","rendered"],"sources":["../src/render/hydrate.ts"],"sourcesContent":["import type { Attrs, VNode } from '../vnode.ts'\nimport { childNamespace, createNode, patchAttrs, rendered, SVG_NS } from './dom.ts'\n\n/** Whether existing DOM `node` can stand for `vnode` in namespace `ns`. */\nfunction matches(node: Node, vnode: VNode, ns: string): node is Element {\n return (\n node.nodeType === 1 &&\n (node as Element).localName === vnode.tag &&\n (node as Element).namespaceURI === ns\n )\n}\n\n/**\n * Claim server-rendered DOM for a tree: the element takes the vnode's\n * attributes (extra ones are removed), and its children are matched by\n * position: text with text, elements with the same tag (hydrated in turn).\n * Anything that does not match is created in place, leftovers are removed.\n * Afterwards the nodes are tracked like freshly rendered ones.\n */\nexport function hydrateElement(el: Element, vnode: VNode): void {\n // The server attributes are the previous state to patch from.\n const current: Attrs = {}\n for (const name of el.getAttributeNames()) current[name] = el.getAttribute(name) as string\n // A strict CSP ignores style attributes in markup: set them again, through the CSSOM.\n if (current.style) current.style = ''\n patchAttrs(el, current, vnode.attrs)\n\n // Comments never stand for anything, and neither does text where the tree has none\n // (whitespace between elements). Text only ever sits in leaf elements here.\n const texts = vnode.children.some((child) => typeof child === 'string')\n for (const node of Array.from(el.childNodes)) {\n if (node.nodeType === 8 || (!texts && node.nodeType === 3)) el.removeChild(node)\n }\n\n const ns = childNamespace(el)\n let node: Node | null = el.firstChild\n for (const child of vnode.children) {\n const next: Node | null = node ? node.nextSibling : null\n if (\n typeof child === 'string'\n ? node?.nodeType === 3\n : node && matches(node, child, child.tag === 'svg' ? SVG_NS : ns)\n ) {\n if (typeof child === 'string') {\n if ((node as Text).data !== child) (node as Text).data = child\n rendered.set(node as Node, child)\n } else {\n hydrateElement(node as Element, child)\n }\n node = next\n } else {\n const created = createNode(child, ns, el.ownerDocument)\n if (created) el.insertBefore(created, node)\n }\n }\n while (node) {\n const extra: Node = node\n node = node.nextSibling\n el.removeChild(extra)\n }\n rendered.set(el, vnode)\n}\n\n/**\n * Hydrate `el` for the root `vnode` when it is foreign markup (not rendered\n * here) with the root's tag in namespace `ns`. Returns whether it did.\n */\nexport function hydrate(el: Element, vnode: VNode, ns: string): boolean {\n if (rendered.has(el) || !matches(el, vnode, ns)) return false\n hydrateElement(el, vnode)\n return true\n}\n"],"mappings":";;;AAIA,SAAS,QAAQ,MAAY,OAAc,IAA6B;CACtE,OACE,KAAK,aAAa,KACjB,KAAiB,cAAc,MAAM,OACrC,KAAiB,iBAAiB;AAEvC;;;;;;;;AASA,SAAgB,eAAe,IAAa,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|
|
|
1
|
+
import { l as VNode } from "./vnode-BUflsBsa.js";
|
|
2
|
+
//#region src/render/hydrate.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Hydrate `el` for the root `vnode` when it is foreign markup (not rendered
|
|
5
|
+
* here) with the root's tag in namespace `ns`. Returns whether it did.
|
|
6
|
+
*/
|
|
7
|
+
declare function hydrate(el: Element, vnode: VNode, ns: string): boolean;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { hydrate as t };
|
|
10
|
+
//# sourceMappingURL=hydrate-CzfxLfTv.d.ts.map
|