@tabler/charts 0.2.0 → 0.4.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/README.md +165 -17
- package/dist/{annotations-DdRdeBUB.cjs → annotations--m-HzMBM.cjs} +87 -11
- package/dist/annotations--m-HzMBM.cjs.map +1 -0
- package/dist/{annotations-B02GR_KU.d.ts → annotations-CCDUC1lW.d.ts} +16 -30
- package/dist/{annotations-CHafaGd4.d.cts → annotations-CqZM1z9R.d.cts} +16 -30
- package/dist/{annotations-D0YQ0IoA.js → annotations-DGITy6th.js} +87 -11
- package/dist/annotations-DGITy6th.js.map +1 -0
- package/dist/annotations.cjs +2 -2
- package/dist/annotations.d.cts +1 -1
- package/dist/annotations.d.ts +1 -1
- package/dist/annotations.js +2 -2
- package/dist/{area-0-L1bG9B.js → area-BN0uE9R0.js} +4 -3
- package/dist/area-BN0uE9R0.js.map +1 -0
- package/dist/{area-CJX9219z.d.cts → area-D6LNLk3r.d.cts} +2 -2
- package/dist/{area-d11XePuw.d.ts → area-DEFL-Yun.d.ts} +2 -2
- package/dist/{area-4eRs3c0K.cjs → area-D_N8b4Ng.cjs} +4 -3
- package/dist/area-D_N8b4Ng.cjs.map +1 -0
- package/dist/area.cjs +1 -1
- package/dist/area.d.cts +1 -1
- package/dist/area.d.ts +1 -1
- package/dist/area.js +1 -1
- package/dist/axis-BzBkkC5X.cjs +305 -0
- package/dist/axis-BzBkkC5X.cjs.map +1 -0
- package/dist/axis-C5obgdJt.js +240 -0
- package/dist/axis-C5obgdJt.js.map +1 -0
- package/dist/{bar-Da6dE_nI.cjs → bar-BrmfXugT.cjs} +77 -58
- package/dist/bar-BrmfXugT.cjs.map +1 -0
- package/dist/{bar-XwzM6Pb0.d.ts → bar-Bs_rPqgR.d.ts} +1 -1
- package/dist/{bar-BDLR4p9c.d.cts → bar-CEt8YRxf.d.cts} +2 -2
- package/dist/{bar-B5n2oq9-.js → bar-CgpC2EpX.js} +2 -2
- package/dist/{bar-B5n2oq9-.js.map → bar-CgpC2EpX.js.map} +1 -1
- package/dist/{bar-BNZ3GhIw.js → bar-D_KKd2fL.js} +75 -56
- package/dist/bar-D_KKd2fL.js.map +1 -0
- package/dist/{bar-LYIF8MEz.cjs → bar-wVykm1us.cjs} +2 -2
- package/dist/{bar-LYIF8MEz.cjs.map → bar-wVykm1us.cjs.map} +1 -1
- package/dist/bar.cjs +1 -1
- package/dist/bar.d.cts +1 -1
- package/dist/bar.d.ts +1 -1
- package/dist/bar.js +1 -1
- package/dist/calendar-B7843sQu.d.cts +106 -0
- package/dist/calendar-BG_q_NC_.cjs +507 -0
- package/dist/calendar-BG_q_NC_.cjs.map +1 -0
- package/dist/calendar-CF3gfDQk.js +502 -0
- package/dist/calendar-CF3gfDQk.js.map +1 -0
- package/dist/calendar-D10_ki1S.d.ts +106 -0
- package/dist/calendar.cjs +3 -0
- package/dist/calendar.d.cts +3 -0
- package/dist/calendar.d.ts +3 -0
- package/dist/calendar.js +1 -0
- package/dist/{candlestick-BHQkQfxH.js → candlestick-B1onjo1o.js} +17 -14
- package/dist/candlestick-B1onjo1o.js.map +1 -0
- package/dist/{candlestick-Dq7qp-F0.d.cts → candlestick-B7YXUVVh.d.cts} +4 -3
- package/dist/{candlestick-CYCQXgky.cjs → candlestick-BwrFKak_.cjs} +17 -14
- package/dist/candlestick-BwrFKak_.cjs.map +1 -0
- package/dist/{candlestick-D0xKkdqd.d.ts → candlestick-XpqJvarq.d.ts} +4 -3
- package/dist/candlestick.cjs +3 -3
- package/dist/candlestick.d.cts +1 -1
- package/dist/candlestick.d.ts +1 -1
- package/dist/candlestick.js +3 -3
- package/dist/{cartesian-DV02PsBe.cjs → cartesian-B9CrasFJ.cjs} +190 -310
- package/dist/cartesian-B9CrasFJ.cjs.map +1 -0
- package/dist/{cartesian-CI2x6N7N.js → cartesian-COglz544.js} +161 -251
- package/dist/cartesian-COglz544.js.map +1 -0
- package/dist/{chart-DWn9v6qw.js → chart-B97FBRCd.js} +114 -72
- package/dist/chart-B97FBRCd.js.map +1 -0
- package/dist/{chart-QilhWP8Z.d.ts → chart-CE9EVbfV.d.ts} +427 -112
- package/dist/{chart-kqFMEwDo.d.cts → chart-Dz4geQZy.d.cts} +427 -112
- package/dist/{chart-e2VqomCI.cjs → chart-GUmmjJ7S.cjs} +132 -78
- package/dist/chart-GUmmjJ7S.cjs.map +1 -0
- package/dist/{core-BKRQvPAT.js → core-7fgM3su0.js} +188 -73
- package/dist/core-7fgM3su0.js.map +1 -0
- package/dist/{core-DRUCk67j.d.ts → core-BUQzLsRJ.d.ts} +26 -10
- package/dist/{core-DIOC61up.cjs → core-BZTrsPxc.cjs} +200 -73
- package/dist/core-BZTrsPxc.cjs.map +1 -0
- package/dist/{core-PAX5ogLk.d.cts → core-Ck5uHcW8.d.cts} +45 -24
- package/dist/core.cjs +45 -31
- package/dist/core.d.cts +23 -18
- package/dist/core.d.ts +23 -18
- package/dist/core.js +28 -23
- package/dist/{dates-DurEr9WT.cjs → dates-0YNY49KQ.cjs} +2 -2
- package/dist/{dates-DurEr9WT.cjs.map → dates-0YNY49KQ.cjs.map} +1 -1
- package/dist/{dates-C2RzY3rE.js → dates-CKDRgpin.js} +2 -2
- package/dist/{dates-C2RzY3rE.js.map → dates-CKDRgpin.js.map} +1 -1
- package/dist/decimate.cjs +1 -1
- package/dist/decimate.js +1 -1
- package/dist/{dom-D_g13XWY.cjs → dom-C33zvtPo.cjs} +3 -7
- package/dist/dom-C33zvtPo.cjs.map +1 -0
- package/dist/{dom-CuceR8gt.js → dom-CTse6Rvd.js} +3 -7
- package/dist/dom-CTse6Rvd.js.map +1 -0
- package/dist/end-labels-B3oRvjxw.js +114 -0
- package/dist/end-labels-B3oRvjxw.js.map +1 -0
- package/dist/end-labels-CS-fnpp-.cjs +119 -0
- package/dist/end-labels-CS-fnpp-.cjs.map +1 -0
- package/dist/end-labels.cjs +11 -0
- package/dist/end-labels.cjs.map +1 -0
- package/dist/end-labels.d.cts +6 -0
- package/dist/end-labels.d.ts +6 -0
- package/dist/end-labels.js +11 -0
- package/dist/end-labels.js.map +1 -0
- package/dist/{export-chart-83UYH48t.js → export-chart-BOH_nfcH.js} +92 -15
- package/dist/export-chart-BOH_nfcH.js.map +1 -0
- package/dist/{export-chart-mYgEfK-L.cjs → export-chart-Be4T9J3m.cjs} +97 -14
- package/dist/export-chart-Be4T9J3m.cjs.map +1 -0
- package/dist/export.cjs +5 -3
- package/dist/export.cjs.map +1 -1
- package/dist/export.d.cts +4 -3
- package/dist/export.d.ts +4 -3
- package/dist/export.js +5 -4
- package/dist/export.js.map +1 -1
- package/dist/{fade-GGxcBdss.js → fade-CDrQjnDz.js} +56 -78
- package/dist/fade-CDrQjnDz.js.map +1 -0
- package/dist/{fade-DVTkhrFU.cjs → fade-CRqcKMWY.cjs} +56 -78
- package/dist/fade-CRqcKMWY.cjs.map +1 -0
- package/dist/{features-BMxkqCyS.js → features-B55rwpQC.js} +4 -2
- package/dist/features-B55rwpQC.js.map +1 -0
- package/dist/{features-DCXEvoya.cjs → features-DEDP5CEQ.cjs} +9 -1
- package/dist/features-DEDP5CEQ.cjs.map +1 -0
- package/dist/fit-BPyPRnsK.js +16 -0
- package/dist/fit-BPyPRnsK.js.map +1 -0
- package/dist/fit-D4MIIQQz.cjs +21 -0
- package/dist/fit-D4MIIQQz.cjs.map +1 -0
- package/dist/funnel-B9ridzNx.d.cts +50 -0
- package/dist/funnel-CFEEulw_.cjs +244 -0
- package/dist/funnel-CFEEulw_.cjs.map +1 -0
- package/dist/funnel-CYCv8cq2.js +239 -0
- package/dist/funnel-CYCv8cq2.js.map +1 -0
- package/dist/funnel-FogM8flk.d.ts +50 -0
- package/dist/funnel.cjs +3 -0
- package/dist/funnel.d.cts +3 -0
- package/dist/funnel.d.ts +3 -0
- package/dist/funnel.js +1 -0
- package/dist/{gauge-DXkjXNCD.cjs → gauge-6HfDcLMJ.cjs} +28 -28
- package/dist/gauge-6HfDcLMJ.cjs.map +1 -0
- package/dist/{gauge-BSist7My.d.cts → gauge-BScJ7U6O.d.cts} +2 -2
- package/dist/{gauge-0VJuAHWF.d.ts → gauge-D78oq1Lx.d.ts} +2 -2
- package/dist/{gauge-ts0kqN1-.js → gauge-DiTk5aWO.js} +28 -28
- package/dist/gauge-DiTk5aWO.js.map +1 -0
- package/dist/gauge.cjs +1 -1
- package/dist/gauge.d.cts +1 -1
- package/dist/gauge.d.ts +1 -1
- package/dist/gauge.js +1 -1
- package/dist/heat-Bsqq4zw9.js +38 -0
- package/dist/heat-Bsqq4zw9.js.map +1 -0
- package/dist/heat-DYsivvDq.cjs +49 -0
- package/dist/heat-DYsivvDq.cjs.map +1 -0
- package/dist/{heatmap-CXhlrLTl.cjs → heatmap-Dyzrd4Fd.cjs} +39 -37
- package/dist/heatmap-Dyzrd4Fd.cjs.map +1 -0
- package/dist/{heatmap-19BGJTKF.js → heatmap-J7fxG7MM.js} +35 -33
- package/dist/heatmap-J7fxG7MM.js.map +1 -0
- package/dist/{heatmap-Dp_oyEe0.d.cts → heatmap-Jvwo7iFW.d.cts} +2 -2
- package/dist/{heatmap-59lmClj9.d.ts → heatmap-mFCnP6aB.d.ts} +2 -2
- package/dist/heatmap.cjs +1 -1
- package/dist/heatmap.d.cts +1 -1
- package/dist/heatmap.d.ts +1 -1
- package/dist/heatmap.js +1 -1
- package/dist/{hydrate-OA6R2_Pn.js → hydrate-BB3MlR36.js} +2 -2
- package/dist/{hydrate-OA6R2_Pn.js.map → hydrate-BB3MlR36.js.map} +1 -1
- package/dist/{hydrate-CmN1k8Mo.cjs → hydrate-m0I5m6ue.cjs} +2 -2
- package/dist/{hydrate-CmN1k8Mo.cjs.map → hydrate-m0I5m6ue.cjs.map} +1 -1
- package/dist/hydrate.cjs +2 -2
- package/dist/hydrate.js +2 -2
- package/dist/index.cjs +69 -45
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +24 -19
- package/dist/index.d.ts +24 -19
- package/dist/index.js +51 -37
- package/dist/index.js.map +1 -1
- package/dist/interaction-DXYSjgnP.cjs +32 -0
- package/dist/interaction-DXYSjgnP.cjs.map +1 -0
- package/dist/interaction-En1KlwFO.js +21 -0
- package/dist/interaction-En1KlwFO.js.map +1 -0
- package/dist/layout-CYerDebD.d.cts +29 -0
- package/dist/layout-CYerDebD.d.ts +29 -0
- package/dist/{layout-JY2aR-yE.cjs → layout-Cfg9x1k2.cjs} +32 -1
- package/dist/layout-Cfg9x1k2.cjs.map +1 -0
- package/dist/{layout-DmrrLjwN.js → layout-DqAte3H8.js} +27 -2
- package/dist/layout-DqAte3H8.js.map +1 -0
- package/dist/{line-DO66LtwH.js → line-CXH0L10d.js} +84 -37
- package/dist/line-CXH0L10d.js.map +1 -0
- package/dist/{line-_rNdeKmS.d.cts → line-Cu9ctpbv.d.cts} +9 -3
- package/dist/{line-Dbt6KFRK.cjs → line-DHbYCQy4.cjs} +84 -37
- package/dist/line-DHbYCQy4.cjs.map +1 -0
- package/dist/{line-DtSh7HQU.d.ts → line-TkzA7wMK.d.ts} +8 -1
- package/dist/line.cjs +3 -3
- package/dist/line.d.cts +1 -1
- package/dist/line.d.ts +1 -1
- package/dist/line.js +3 -3
- package/dist/log.cjs +1 -1
- package/dist/log.js +1 -1
- package/dist/map-BirylCmT.d.cts +156 -0
- package/dist/map-CYp6x-uS.js +784 -0
- package/dist/map-CYp6x-uS.js.map +1 -0
- package/dist/map-ChwSgooH.cjs +795 -0
- package/dist/map-ChwSgooH.cjs.map +1 -0
- package/dist/map-DNqog2Xs.d.ts +156 -0
- package/dist/map.cjs +4 -0
- package/dist/map.d.cts +3 -0
- package/dist/map.d.ts +3 -0
- package/dist/map.js +1 -0
- package/dist/maps/world.cjs +875 -0
- package/dist/maps/world.cjs.map +1 -0
- package/dist/maps/world.d.cts +2 -0
- package/dist/maps/world.d.ts +2 -0
- package/dist/maps/world.js +874 -0
- package/dist/maps/world.js.map +1 -0
- package/dist/{morph-9_LJL0ra.cjs → morph-3I1Nf_tR.cjs} +2 -2
- package/dist/{morph-9_LJL0ra.cjs.map → morph-3I1Nf_tR.cjs.map} +1 -1
- package/dist/{morph-DnRxuwR-.js → morph-GfBab-b3.js} +2 -2
- package/dist/{morph-DnRxuwR-.js.map → morph-GfBab-b3.js.map} +1 -1
- package/dist/morph.cjs +2 -2
- package/dist/morph.js +2 -2
- package/dist/others-CuNdpvjd.d.cts +31 -0
- package/dist/{others-J7NCAMA0.js → others-DBIGE6jr.js} +11 -3
- package/dist/others-DBIGE6jr.js.map +1 -0
- package/dist/others-DBO4Kjwl.d.ts +29 -0
- package/dist/{others-DWdK7vKp.cjs → others-WfjCsjqT.cjs} +14 -6
- package/dist/others-WfjCsjqT.cjs.map +1 -0
- package/dist/{parliament-Cru4IcuM.js → parliament-BKN6ikBJ.js} +30 -29
- package/dist/parliament-BKN6ikBJ.js.map +1 -0
- package/dist/{parliament-CLCI7tUO.d.ts → parliament-CHdf13XU.d.ts} +2 -2
- package/dist/{parliament-CgsVnWEe.d.cts → parliament-CsYgh4N2.d.cts} +2 -2
- package/dist/{parliament-x5hcFaQ3.cjs → parliament-DhxAaIZ3.cjs} +30 -29
- package/dist/parliament-DhxAaIZ3.cjs.map +1 -0
- package/dist/parliament.cjs +1 -1
- package/dist/parliament.d.cts +1 -1
- package/dist/parliament.d.ts +1 -1
- package/dist/parliament.js +1 -1
- package/dist/{patterns-D3-wQagb.cjs → patterns-BPN1c9qe.cjs} +2 -2
- package/dist/{patterns-D3-wQagb.cjs.map → patterns-BPN1c9qe.cjs.map} +1 -1
- package/dist/{patterns-CufKZYhm.js → patterns-CVrLrJXg.js} +2 -2
- package/dist/{patterns-CufKZYhm.js.map → patterns-CVrLrJXg.js.map} +1 -1
- package/dist/patterns.cjs +2 -2
- package/dist/patterns.d.cts +1 -1
- package/dist/patterns.d.ts +1 -1
- package/dist/patterns.js +2 -2
- package/dist/{percentage-bar-ybNS3goo.cjs → percentage-bar-BChkTRoz.cjs} +37 -35
- package/dist/percentage-bar-BChkTRoz.cjs.map +1 -0
- package/dist/{percentage-bar-nhTeakD_.d.ts → percentage-bar-CSAbzDOn.d.ts} +11 -15
- package/dist/{percentage-bar-B6tNOqNn.js → percentage-bar-CaInxrL8.js} +37 -35
- package/dist/percentage-bar-CaInxrL8.js.map +1 -0
- package/dist/{percentage-bar-tepMr7Hd.d.cts → percentage-bar-UZHCRvlK.d.cts} +11 -15
- package/dist/percentage-bar.cjs +1 -1
- package/dist/percentage-bar.d.cts +1 -1
- package/dist/percentage-bar.d.ts +1 -1
- package/dist/percentage-bar.js +1 -1
- package/dist/{pie-BXg2gNpb.d.cts → pie-AFedsDcF.d.cts} +17 -14
- package/dist/{pie-CVsc-6qD.js → pie-Ch6Bx0ih.js} +68 -52
- package/dist/pie-Ch6Bx0ih.js.map +1 -0
- package/dist/{pie-BpjvSPnz.cjs → pie-Cll1OrVZ.cjs} +68 -52
- package/dist/pie-Cll1OrVZ.cjs.map +1 -0
- package/dist/{pie-CFptILSm.d.ts → pie-Cn2H3pz8.d.ts} +17 -14
- package/dist/pie.cjs +1 -1
- package/dist/pie.d.cts +1 -1
- package/dist/pie.d.ts +1 -1
- package/dist/pie.js +1 -1
- package/dist/{point-shapes--_gmdTyK.cjs → point-shapes-BRawRM78.cjs} +23 -22
- package/dist/point-shapes-BRawRM78.cjs.map +1 -0
- package/dist/{point-shapes-DD2Ektzm.js → point-shapes-DI6GhcI7.js} +18 -23
- package/dist/point-shapes-DI6GhcI7.js.map +1 -0
- package/dist/point-shapes.cjs +6 -4
- package/dist/point-shapes.cjs.map +1 -1
- package/dist/point-shapes.d.cts +2 -2
- package/dist/point-shapes.d.ts +2 -2
- package/dist/point-shapes.js +7 -5
- package/dist/point-shapes.js.map +1 -1
- package/dist/{radar-BR-mumDd.js → radar-Bg-IiIWB.js} +21 -22
- package/dist/radar-Bg-IiIWB.js.map +1 -0
- package/dist/{radar-BC9Skgpj.d.ts → radar-DEer2jjd.d.ts} +2 -2
- package/dist/{radar-D1-lItDy.d.cts → radar-DxmjXhMc.d.cts} +2 -2
- package/dist/{radar-HPDrIdzc.cjs → radar-wDyX17S3.cjs} +22 -23
- package/dist/radar-wDyX17S3.cjs.map +1 -0
- package/dist/radar.cjs +1 -1
- package/dist/radar.d.cts +1 -1
- package/dist/radar.d.ts +1 -1
- package/dist/radar.js +1 -1
- package/dist/range-bar-BnKjJP89.cjs +348 -0
- package/dist/range-bar-BnKjJP89.cjs.map +1 -0
- package/dist/range-bar-C4cRaaQE.d.ts +123 -0
- package/dist/range-bar-D32dIQOY.d.cts +123 -0
- package/dist/range-bar-Dx6ce0J1.js +343 -0
- package/dist/range-bar-Dx6ce0J1.js.map +1 -0
- package/dist/range-bar.cjs +3 -0
- package/dist/range-bar.d.cts +3 -0
- package/dist/range-bar.d.ts +3 -0
- package/dist/range-bar.js +1 -0
- package/dist/{rect-DSVmUZrD.js → rect-CZTNvMlf.js} +2 -2
- package/dist/{rect-DSVmUZrD.js.map → rect-CZTNvMlf.js.map} +1 -1
- package/dist/{rect-D6VhynBM.cjs → rect-DPr9QRxl.cjs} +2 -2
- package/dist/{rect-D6VhynBM.cjs.map → rect-DPr9QRxl.cjs.map} +1 -1
- package/dist/{sankey-fCoo1cpz.cjs → sankey-0CSp_Er9.cjs} +72 -71
- package/dist/sankey-0CSp_Er9.cjs.map +1 -0
- package/dist/{sankey-Dk7jUt8x.d.cts → sankey-D-8ATwBT.d.cts} +2 -2
- package/dist/{sankey-D6JeZfK5.js → sankey-Dp4CuLVe.js} +72 -71
- package/dist/sankey-Dp4CuLVe.js.map +1 -0
- package/dist/{sankey-D_v7KxnJ.d.ts → sankey-DpYJsOI4.d.ts} +2 -2
- package/dist/sankey.cjs +1 -1
- package/dist/sankey.d.cts +1 -1
- package/dist/sankey.d.ts +1 -1
- package/dist/sankey.js +1 -1
- package/dist/{scatter-C0TWjFpW.js → scatter-0Z7K_YUz.js} +94 -46
- package/dist/scatter-0Z7K_YUz.js.map +1 -0
- package/dist/{scatter-CXEsioOJ.d.ts → scatter-BAL5K9_4.d.ts} +28 -9
- package/dist/{scatter-DZeEIfyo.d.cts → scatter-BUGbnRzM.d.cts} +28 -9
- package/dist/{scatter-DVqB_fP9.cjs → scatter-CZ8do3Up.cjs} +95 -47
- package/dist/scatter-CZ8do3Up.cjs.map +1 -0
- package/dist/scatter.cjs +1 -1
- package/dist/scatter.d.cts +2 -2
- package/dist/scatter.d.ts +2 -2
- package/dist/scatter.js +1 -1
- package/dist/slice-labels-1TBq7p3q.d.cts +28 -0
- package/dist/slice-labels-C9ucsBVW.js +88 -0
- package/dist/slice-labels-C9ucsBVW.js.map +1 -0
- package/dist/slice-labels-CbFiy46l.cjs +93 -0
- package/dist/slice-labels-CbFiy46l.cjs.map +1 -0
- package/dist/slice-labels-Cm5CyV7B.d.ts +28 -0
- package/dist/slice-labels.cjs +11 -0
- package/dist/slice-labels.cjs.map +1 -0
- package/dist/slice-labels.d.cts +6 -0
- package/dist/slice-labels.d.ts +6 -0
- package/dist/slice-labels.js +11 -0
- package/dist/slice-labels.js.map +1 -0
- package/dist/{sparkline-cbvRkWqS.d.ts → sparkline-CtoBJe-a.d.ts} +2 -2
- package/dist/{sparkline-B39NA0Mi.cjs → sparkline-DjR-V6BI.cjs} +13 -15
- package/dist/sparkline-DjR-V6BI.cjs.map +1 -0
- package/dist/{sparkline-DAP6jtzw.d.cts → sparkline-DwHJfeZz.d.cts} +2 -2
- package/dist/{sparkline-XO_TqCNP.js → sparkline-_dxwtdli.js} +13 -15
- package/dist/sparkline-_dxwtdli.js.map +1 -0
- package/dist/sparkline.cjs +1 -1
- package/dist/sparkline.d.cts +1 -1
- package/dist/sparkline.d.ts +1 -1
- package/dist/sparkline.js +1 -1
- package/dist/{stack-Dagxq7l2.d.cts → stack-CcmyALx0.d.cts} +1 -1
- package/dist/{stack-2H2Gfs1Q.js → stack-CyVlS7Fr.js} +2 -2
- package/dist/{stack-2H2Gfs1Q.js.map → stack-CyVlS7Fr.js.map} +1 -1
- package/dist/{stack-BgPzoQmv.cjs → stack-DBhmYNat.cjs} +2 -2
- package/dist/{stack-BgPzoQmv.cjs.map → stack-DBhmYNat.cjs.map} +1 -1
- package/dist/style.css +1 -1
- package/dist/{time-axis-BjZ1bYTK.cjs → time-axis-CVKjQKSS.cjs} +4 -3
- package/dist/{time-axis-BjZ1bYTK.cjs.map → time-axis-CVKjQKSS.cjs.map} +1 -1
- package/dist/{time-axis-FLONo54E.js → time-axis-CkmbAw4Z.js} +3 -2
- package/dist/{time-axis-FLONo54E.js.map → time-axis-CkmbAw4Z.js.map} +1 -1
- package/dist/time.cjs +3 -3
- package/dist/time.js +3 -3
- package/dist/{treemap-BAkhmVQc.d.cts → treemap-C2maqerU.d.cts} +37 -5
- package/dist/{treemap-BNpxFBao.d.ts → treemap-D_zbubo3.d.ts} +37 -5
- package/dist/{treemap-BWpEUlDh.cjs → treemap-PulGXZv0.cjs} +58 -33
- package/dist/treemap-PulGXZv0.cjs.map +1 -0
- package/dist/{treemap-CQdavQ9u.js → treemap-lbYxb-7h.js} +57 -32
- package/dist/treemap-lbYxb-7h.js.map +1 -0
- package/dist/treemap.cjs +1 -1
- package/dist/treemap.d.cts +1 -1
- package/dist/treemap.d.ts +1 -1
- package/dist/treemap.js +1 -1
- package/dist/{value-labels-BBuSi4i0.js → value-labels-B0VeheyE.js} +29 -8
- package/dist/value-labels-B0VeheyE.js.map +1 -0
- package/dist/{value-labels-BV9keAuL.cjs → value-labels-Dcyk3GIY.cjs} +29 -8
- package/dist/value-labels-Dcyk3GIY.cjs.map +1 -0
- package/dist/value-labels.cjs +2 -2
- package/dist/value-labels.d.cts +1 -1
- package/dist/value-labels.d.ts +1 -1
- package/dist/value-labels.js +2 -2
- package/dist/zoom.cjs +810 -0
- package/dist/zoom.cjs.map +1 -0
- package/dist/zoom.d.cts +34 -0
- package/dist/zoom.d.ts +34 -0
- package/dist/zoom.js +806 -0
- package/dist/zoom.js.map +1 -0
- package/package.json +120 -235
- package/dist/annotations-D0YQ0IoA.js.map +0 -1
- package/dist/annotations-DdRdeBUB.cjs.map +0 -1
- package/dist/area-0-L1bG9B.js.map +0 -1
- package/dist/area-4eRs3c0K.cjs.map +0 -1
- package/dist/bar-BNZ3GhIw.js.map +0 -1
- package/dist/bar-Da6dE_nI.cjs.map +0 -1
- package/dist/candlestick-BHQkQfxH.js.map +0 -1
- package/dist/candlestick-CYCQXgky.cjs.map +0 -1
- package/dist/cartesian-CI2x6N7N.js.map +0 -1
- package/dist/cartesian-DV02PsBe.cjs.map +0 -1
- package/dist/chart-DWn9v6qw.js.map +0 -1
- package/dist/chart-e2VqomCI.cjs.map +0 -1
- package/dist/core-BKRQvPAT.js.map +0 -1
- package/dist/core-DIOC61up.cjs.map +0 -1
- package/dist/dom-CuceR8gt.js.map +0 -1
- package/dist/dom-D_g13XWY.cjs.map +0 -1
- package/dist/export-chart-83UYH48t.js.map +0 -1
- package/dist/export-chart-mYgEfK-L.cjs.map +0 -1
- package/dist/fade-DVTkhrFU.cjs.map +0 -1
- package/dist/fade-GGxcBdss.js.map +0 -1
- package/dist/features-BMxkqCyS.js.map +0 -1
- package/dist/features-DCXEvoya.cjs.map +0 -1
- package/dist/gauge-DXkjXNCD.cjs.map +0 -1
- package/dist/gauge-ts0kqN1-.js.map +0 -1
- package/dist/heatmap-19BGJTKF.js.map +0 -1
- package/dist/heatmap-CXhlrLTl.cjs.map +0 -1
- package/dist/layout-DmrrLjwN.js.map +0 -1
- package/dist/layout-JY2aR-yE.cjs.map +0 -1
- package/dist/line-DO66LtwH.js.map +0 -1
- package/dist/line-Dbt6KFRK.cjs.map +0 -1
- package/dist/others-DWdK7vKp.cjs.map +0 -1
- package/dist/others-J7NCAMA0.js.map +0 -1
- package/dist/parliament-Cru4IcuM.js.map +0 -1
- package/dist/parliament-x5hcFaQ3.cjs.map +0 -1
- package/dist/percentage-bar-B6tNOqNn.js.map +0 -1
- package/dist/percentage-bar-ybNS3goo.cjs.map +0 -1
- package/dist/pie-BpjvSPnz.cjs.map +0 -1
- package/dist/pie-CVsc-6qD.js.map +0 -1
- package/dist/point-shapes--_gmdTyK.cjs.map +0 -1
- package/dist/point-shapes-DD2Ektzm.js.map +0 -1
- package/dist/radar-BR-mumDd.js.map +0 -1
- package/dist/radar-HPDrIdzc.cjs.map +0 -1
- package/dist/sankey-D6JeZfK5.js.map +0 -1
- package/dist/sankey-fCoo1cpz.cjs.map +0 -1
- package/dist/scatter-C0TWjFpW.js.map +0 -1
- package/dist/scatter-DVqB_fP9.cjs.map +0 -1
- package/dist/sparkline-B39NA0Mi.cjs.map +0 -1
- package/dist/sparkline-XO_TqCNP.js.map +0 -1
- package/dist/treemap-BWpEUlDh.cjs.map +0 -1
- package/dist/treemap-CQdavQ9u.js.map +0 -1
- package/dist/value-labels-BBuSi4i0.js.map +0 -1
- package/dist/value-labels-BV9keAuL.cjs.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sankey-D6JeZfK5.js","names":[],"sources":["../src/charts/sankey.ts"],"sourcesContent":["import type { DataTable } from '../a11y.ts'\nimport type { ChartType, RenderContext } from '../chart.ts'\nimport { formatDetail, type NumberFormat } from '../format.ts'\nimport type { Hit, HitItem, Interaction } from '../interaction.ts'\nimport {\n estimateTextWidth,\n type InsetsInput,\n innerRect,\n insets,\n LINE_HEIGHT,\n mirrorSides,\n type Rect,\n round,\n} from '../layout.ts'\nimport type { LegendItem } from '../legend.ts'\nimport { type ChildInput, h } from '../vnode.ts'\nimport { cleanData, finite, isRecord, named, records, text } from './clean.ts'\n\n/** A node of the flow; nodes left out are made from the links. */\nexport interface SankeyNode {\n name: string\n /**\n * Custom color; overrides the palette slot via `--tc-series-color`. Nodes\n * sharing a color form one legend entry, named after the first of them.\n * Values that could inject CSS (`;`, quotes, `url()` …) are ignored, so colors from user data are safe.\n */\n color?: string\n /** Start hidden (toggle it back from the legend, with every node of its color). */\n hidden?: boolean\n}\n\n/** A flow between two nodes, by name. */\nexport interface SankeyLink {\n from: string\n to: string\n /** Non-negative value; negative values count as zero. */\n value: number\n}\n\nexport interface SankeyData {\n /** Optional: sets the stacking order within a column, and colors. */\n nodes?: readonly SankeyNode[]\n links: readonly SankeyLink[]\n}\n\nexport interface SankeyOptions {\n data: SankeyData\n /** Width of the node bars in pixels. Defaults to `12`. */\n nodeWidth?: number\n /** Vertical gap between the nodes of a column in pixels. Defaults to `16`. */\n nodePadding?: number\n /** Format of the values (labels, tooltips and the table). */\n format?: NumberFormat\n /**\n * `'justify'` (default) puts every node without outgoing flows in the last\n * column; `'left'` leaves it in the column after its sources.\n */\n align?: 'justify' | 'left'\n /** Extra space around the diagram, in pixels. */\n padding?: InsetsInput\n}\n\ninterface Node {\n data: SankeyNode\n index: number\n /** Palette slot, 1-based: the node's position in its column. */\n slot: number\n column: number\n value: number\n x: number\n y: number\n height: number\n ins: Link[]\n outs: Link[]\n}\n\ninterface Link {\n data: SankeyLink\n index: number\n source: Node\n target: Node\n /** Top of the slice at the source and at the target. */\n sy: number\n ty: number\n width: number\n}\n\ninterface Layout {\n nodes: Node[]\n links: Link[]\n /** The columns' extent, between the label margins. */\n plot: Rect\n nodeWidth: number\n labels: NodeLabel[]\n}\n\n/** A node's label: the name and the value under it, cut to fit (empty when hidden). */\ninterface NodeLabel {\n side: 'left' | 'right'\n name: string\n value: string\n}\n\n/** Space between a node and its label. */\nconst LABEL_GAP = 8\n/** Largest share of the width one side's labels may take. */\nconst MAX_LABEL_SHARE = 0.3\n/** Pixels around a node that still count as hovering it. */\nconst HOVER_SLOP = 2\n\n/** `text`, cut short with an ellipsis to fit `width` pixels. */\nfunction truncate(text: string, width: number, fontSize: number): string {\n if (estimateTextWidth(text, fontSize) <= width) return text\n let end = text.length\n while (end > 0 && estimateTextWidth(`${text.slice(0, end)}…`, fontSize) > width) end--\n return end > 0 ? `${text.slice(0, end).trimEnd()}…` : ''\n}\n\n/** The color of a node for hover and tooltip swatches. */\nconst colorOf = (node: Node): string => node.data.color ?? `var(--tc-color-${node.slot})`\n\n/** The visible nodes and links, in data order, with their columns. */\nfunction graph(data: SankeyData, hidden: ReadonlySet<string>, justify: boolean) {\n const byName = new Map<string, Node>()\n const nodes: Node[] = []\n const node = (name: string, data?: SankeyNode): Node => {\n let found = byName.get(name)\n if (!found) {\n found = {\n data: data ?? { name },\n index: nodes.length,\n slot: 1,\n column: 0,\n value: 0,\n x: 0,\n y: 0,\n height: 0,\n ins: [],\n outs: [],\n }\n byName.set(name, found)\n nodes.push(found)\n }\n return found\n }\n const declared = new Map((data.nodes ?? []).map((n) => [n.name, n]))\n /** A legend key hides every node of its color, see `sankeyLegend`. */\n const isHidden = (name: string) => {\n const n = declared.get(name)\n return hidden.has(name) || (n?.color !== undefined && hidden.has(legendKey(data, n.color)))\n }\n const links: Link[] = []\n data.links.forEach((link, index) => {\n if (link.from === link.to || isHidden(link.from) || isHidden(link.to)) return\n const source = node(link.from, declared.get(link.from))\n const target = node(link.to, declared.get(link.to))\n const out: Link = { data: link, index, source, target, sy: 0, ty: 0, width: 0 }\n links.push(out)\n if (link.value <= 0) return\n source.outs.push(out)\n target.ins.push(out)\n })\n for (const n of nodes) {\n n.value = Math.max(\n n.outs.reduce((sum, l) => sum + l.data.value, 0),\n n.ins.reduce((sum, l) => sum + l.data.value, 0),\n )\n }\n // Column: the longest path from a source, passes bounded so cycles end.\n for (let pass = 0; pass < nodes.length; pass++) {\n let changed = false\n for (const link of links) {\n if (link.data.value > 0 && link.target.column <= link.source.column) {\n link.target.column = link.source.column + 1\n changed = true\n }\n }\n if (!changed) break\n }\n const last = nodes.reduce((max, n) => Math.max(max, n.column), 0)\n if (justify) for (const n of nodes) if (n.outs.length === 0) n.column = last\n // Stack order within a column: declared nodes first, then first appearance.\n const order = [...declared.keys()]\n nodes.sort((a, b) => {\n if (a.column !== b.column) return a.column - b.column\n const ia = order.indexOf(a.data.name)\n const ib = order.indexOf(b.data.name)\n if (ia !== -1 && ib !== -1) return ia - ib\n if (ia !== ib) return ia === -1 ? 1 : -1\n return a.index - b.index\n })\n const slots = new Map<number, number>()\n nodes.forEach((n, index) => {\n n.index = index\n const slot = (slots.get(n.column) ?? 0) + 1\n slots.set(n.column, slot)\n n.slot = ((slot - 1) % 8) + 1\n })\n return { nodes, links, columns: last + 1 }\n}\n\n/** Key of the legend entry of `color`: the first node that wears it. */\nconst legendKey = (data: SankeyData, color: string): string =>\n (data.nodes ?? []).find((n) => n.color === color)?.name ?? color\n\nfunction layout(options: SankeyOptions, ctx: RenderContext): Layout {\n const { width, height, fontSize, locale } = ctx\n const nodeWidth = Math.max(1, options.nodeWidth ?? 12)\n const nodePadding = Math.max(0, options.nodePadding ?? 16)\n // Right to left, the layout is worked out as its mirror image, then flipped.\n const { rtl } = ctx\n const area = innerRect(width, height, mirrorSides(insets(options.padding), rtl))\n const { nodes, links, columns } = graph(options.data, ctx.hidden, options.align !== 'left')\n const format = formatDetail(options.format, locale)\n\n // Labels take their room from the sides: the first column's to its left,\n // the last column's to its right, the rest to the right of their node.\n const texts = nodes.map((n) => [n.data.name, format(n.value)] as const)\n const widest = (match: (n: Node) => boolean) =>\n nodes.reduce((max, n, i) => {\n if (!match(n)) return max\n const [name, value] = texts[i] as readonly [string, string]\n return Math.max(max, estimateTextWidth(name, fontSize), estimateTextWidth(value, fontSize))\n }, 0)\n const cap = area.width * MAX_LABEL_SHARE\n const left =\n columns > 1\n ? Math.min(\n cap,\n widest((n) => n.column === 0),\n )\n : 0\n const right = Math.min(\n cap,\n widest((n) => n.column === columns - 1),\n )\n const plot: Rect = {\n x: area.x + (left ? left + LABEL_GAP : 0),\n y: area.y,\n width: Math.max(\n 0,\n area.width - (left ? left + LABEL_GAP : 0) - (right ? right + LABEL_GAP : 0),\n ),\n height: area.height,\n }\n const step = columns > 1 ? (plot.width - nodeWidth) / (columns - 1) : 0\n\n // Heights: one scale for every column, so values compare across them.\n const byColumn: Node[][] = Array.from({ length: columns }, () => [])\n for (const n of nodes) byColumn[n.column]?.push(n)\n const pad = byColumn.reduce(\n (min, col) => (col.length > 1 ? Math.min(min, plot.height / 2 / (col.length - 1)) : min),\n nodePadding,\n )\n let k = Number.POSITIVE_INFINITY\n for (const col of byColumn) {\n const sum = col.reduce((s, n) => s + n.value, 0)\n if (sum > 0) k = Math.min(k, (plot.height - (col.length - 1) * pad) / sum)\n }\n if (!Number.isFinite(k) || k < 0) k = 0\n byColumn.forEach((col, c) => {\n const total = col.reduce((s, n) => s + n.value * k, 0) + (col.length - 1) * pad\n let y = plot.y + (plot.height - total) / 2\n for (const n of col) {\n const x = plot.x + (columns > 1 ? c * step : (plot.width - nodeWidth) / 2)\n n.x = rtl ? width - x - nodeWidth : x\n n.y = y\n n.height = n.value * k\n y += n.height + pad\n }\n })\n // Slices: flows leave and enter in the order of the node at the other end.\n for (const n of nodes) {\n let y = n.y\n for (const link of [...n.outs].sort((a, b) => a.target.y - b.target.y)) {\n link.sy = y\n link.width = link.data.value * k\n y += link.width\n }\n y = n.y\n for (const link of [...n.ins].sort((a, b) => a.source.y - b.source.y)) {\n link.ty = y\n y += link.data.value * k\n }\n }\n\n const labels = nodes.map((n, i): NodeLabel => {\n const [name, value] = texts[i] as readonly [string, string]\n const side: 'left' | 'right' = n.column === 0 && columns > 1 ? 'left' : 'right'\n const room =\n side === 'left' ? left : n.column === columns - 1 ? right : step - nodeWidth - LABEL_GAP * 2\n // Crowded columns keep only the names: the value line would run into the next label.\n const col = byColumn[n.column] as Node[]\n const at = col.indexOf(n)\n const neighbours = [col[at - 1], col[at + 1]].filter((o): o is Node => !!o)\n const spacing = neighbours.reduce(\n (min, o) => Math.min(min, (n.height + o.height) / 2 + pad),\n Number.POSITIVE_INFINITY,\n )\n const showValue = spacing >= fontSize * (1 + LINE_HEIGHT)\n return {\n side,\n name: truncate(name, room, fontSize),\n value: showValue ? truncate(value, room, fontSize) : '',\n }\n })\n if (rtl) plot.x = width - plot.x - plot.width\n return { nodes, links, plot, nodeWidth, labels }\n}\n\n/** The x of a link's ends: the facing edges of its source and its target. */\nconst linkEnds = (link: Link, nodeWidth: number): [number, number] =>\n link.source.x > link.target.x\n ? [link.source.x, link.target.x + nodeWidth]\n : [link.source.x + nodeWidth, link.target.x]\n\n/** Path of a link: two cubic Béziers between the slices at its ends. */\nfunction linkPath(link: Link, nodeWidth: number): string {\n const [x0, x1] = linkEnds(link, nodeWidth)\n const xm = (x0 + x1) / 2\n const { sy, ty, width } = link\n const p = (...v: number[]) => v.map(round).join(',')\n return `M${p(x0, sy)}C${p(xm, sy, xm, ty, x1, ty)}L${p(x1, ty + width)}C${p(xm, ty + width, xm, sy + width, x0, sy + width)}Z`\n}\n\n/** A point on a cubic Bézier with control points `a`, `b`, `c`, `d`. */\nconst cubic = (a: number, b: number, c: number, d: number, t: number): number => {\n const u = 1 - t\n return u * u * u * a + 3 * u * u * t * b + 3 * u * t * t * c + t * t * t * d\n}\n\n/** Whether `(px, py)` lies inside the ribbon of `link`. */\nfunction inLink(link: Link, nodeWidth: number, px: number, py: number): boolean {\n const [x0, x1] = linkEnds(link, nodeWidth)\n if (px < Math.min(x0, x1) || px > Math.max(x0, x1) || x0 === x1) return false\n const xm = (x0 + x1) / 2\n // x(t) is monotone, so bisection finds the t under the pointer.\n let lo = 0\n let hi = 1\n for (let i = 0; i < 20; i++) {\n const mid = (lo + hi) / 2\n if (cubic(x0, xm, xm, x1, mid) < px === x1 > x0) lo = mid\n else hi = mid\n }\n const top = cubic(link.sy, link.sy, link.ty, link.ty, (lo + hi) / 2)\n return py >= top && py <= top + link.width\n}\n\nfunction renderSankey(options: SankeyOptions, ctx: RenderContext): ChildInput {\n const { nodes, links, plot, nodeWidth, labels } = layout(options, ctx)\n const drawn = links.filter((link) => link.data.value > 0)\n const formatValue = formatDetail(options.format, ctx.locale)\n\n const nodeMark = (n: Node) => ({\n d: `M0,0h${round(nodeWidth)}v${round(n.height)}h${round(-nodeWidth)}Z`,\n x: n.x,\n y: n.y,\n })\n const linkItem = (link: Link): HitItem => ({\n name: `${link.source.data.name} ${ctx.rtl ? '←' : '→'} ${link.target.data.name}`,\n seriesIndex: link.index,\n color: colorOf(link.source),\n value: link.data.value,\n text: formatValue(link.data.value),\n x: (link.source.x + nodeWidth + link.target.x) / 2,\n y: cubic(link.sy, link.sy, link.ty, link.ty, 0.5) + link.width / 2,\n })\n const hitNode = (n: Node, linkIndex?: number): Hit => {\n const own: HitItem = {\n name: n.data.name,\n seriesIndex: links.length + n.index,\n color: colorOf(n),\n value: n.value,\n text: formatValue(n.value),\n x: n.x + nodeWidth / 2,\n y: n.y + n.height / 2,\n }\n const flows = [...n.ins, ...n.outs].map(linkItem)\n const focused = flows.find((item) => item.seriesIndex === linkIndex)\n const link = focused && drawn.find((l) => l.index === linkIndex)\n return {\n index: n.index,\n label: n.data.name,\n title: '',\n x: own.x,\n area: plot,\n items: [own, ...flows],\n seriesIndex: focused ? linkIndex : own.seriesIndex,\n mark: link ? { d: linkPath(link, nodeWidth), x: 0, y: 0 } : nodeMark(n),\n }\n }\n const hitLink = (link: Link): Hit => {\n const item = linkItem(link)\n return {\n index: link.source.index,\n label: link.source.data.name,\n title: '',\n x: item.x,\n area: plot,\n items: [item],\n seriesIndex: link.index,\n mark: { d: linkPath(link, nodeWidth), x: 0, y: 0 },\n }\n }\n\n const interaction: Interaction = {\n count: nodes.length,\n hitTest(px, py) {\n const n = nodes.find(\n (n) =>\n px >= n.x - HOVER_SLOP &&\n px <= n.x + nodeWidth + HOVER_SLOP &&\n py >= n.y - HOVER_SLOP &&\n py <= n.y + n.height + HOVER_SLOP,\n )\n if (n) return hitNode(n)\n const link = drawn.find((l) => inLink(l, nodeWidth, px, py))\n return link ? hitLink(link) : null\n },\n hitIndex(index, seriesIndex) {\n const n = nodes[index]\n return n ? hitNode(n, seriesIndex) : null\n },\n }\n ctx.onHitTest(interaction)\n\n return [\n h(\n 'g',\n { key: 'links', class: 'tc-sankey-links' },\n drawn.map((link) =>\n h('path', {\n key: `${link.source.data.name}→${link.target.data.name}#${link.index}`,\n class: ['tc-series', `tc-series-${link.source.slot}`, 'tc-sankey-link'],\n style: { '--tc-series-color': link.source.data.color },\n d: linkPath(link, nodeWidth),\n }),\n ),\n ),\n h(\n 'g',\n { key: 'nodes', class: 'tc-sankey-nodes' },\n nodes.map((n) =>\n h(\n 'g',\n {\n key: n.data.name,\n class: ['tc-series', `tc-series-${n.slot}`],\n 'data-series': n.data.name,\n style: { '--tc-series-color': n.data.color },\n },\n h('rect', {\n class: 'tc-sankey-node',\n x: round(n.x),\n y: round(n.y),\n width: round(nodeWidth),\n height: round(n.height),\n }),\n ),\n ),\n ),\n h(\n 'g',\n { key: 'labels', class: 'tc-sankey-labels', 'aria-hidden': 'true' },\n nodes.map((n, i) => {\n const label = labels[i] as NodeLabel\n if (!label.name && !label.value) return null\n // The label's side is the one of the left-to-right layout: mirrored with it.\n const before = (label.side === 'left') !== (ctx.rtl === true)\n const x = round(before ? n.x - LABEL_GAP : n.x + nodeWidth + LABEL_GAP)\n const y = round(n.y + n.height / 2)\n const anchor = before ? 'end' : 'start'\n return h(\n 'g',\n { key: n.data.name, class: 'tc-sankey-label' },\n h(\n 'text',\n {\n class: 'tc-value-label tc-sankey-name',\n x,\n y,\n dy: label.value ? '-0.25em' : '0.35em',\n 'text-anchor': anchor,\n },\n label.name,\n ),\n label.value &&\n h(\n 'text',\n {\n class: 'tc-tick-label tc-sankey-value',\n x,\n y,\n dy: '0.95em',\n 'text-anchor': anchor,\n },\n label.value,\n ),\n )\n }),\n ),\n ]\n}\n\n/** One legend entry per custom color, named after the first node wearing it. */\nfunction sankeyLegend(options: SankeyOptions): LegendItem[] {\n const seen = new Map<string, LegendItem>()\n for (const n of options.data.nodes ?? []) {\n if (n.color && !seen.has(n.color)) {\n const item: LegendItem = { key: n.name, name: n.name, index: seen.size, color: n.color }\n if (n.hidden) item.hidden = true\n seen.set(n.color, item)\n }\n }\n return [...seen.values()]\n}\n\nfunction sankeyTable(options: SankeyOptions, ctx: RenderContext): DataTable {\n const { links } = graph(options.data, ctx.hidden, true)\n const value = formatDetail(options.format, ctx.locale)\n return {\n columns: ['From', 'To', 'Value'],\n rows: links.map((link) => [link.data.from, link.data.to, value(link.data.value)]),\n }\n}\n\n/** Nodes and links from users, APIs and JSON, in the shape the layout expects. */\nconst cleanSankey = (data: unknown): unknown => {\n const d = isRecord(data) ? data : {}\n return {\n ...d,\n nodes: Array.isArray(d.nodes) ? records(d.nodes, (r) => named(r)) : undefined,\n links: records(d.links, (r) => ({\n from: text(r.from),\n to: text(r.to),\n value: Math.max(0, finite(r.value) ?? 0),\n })),\n }\n}\n\n/**\n * Sankey diagram: flows between nodes, as ribbons whose width is their\n * value. Nodes are made from the links (or declared, to set their order and\n * colors) and placed in columns by the longest path from a source.\n *\n * ```ts\n * new Chart('#el', {\n * type: sankey,\n * data: {\n * links: [\n * { from: 'Wages', to: 'Income', value: 60 },\n * { from: 'Dividends', to: 'Income', value: 15 },\n * { from: 'Income', to: 'Rent', value: 30 },\n * { from: 'Income', to: 'Savings', value: 45 },\n * ],\n * },\n * })\n * ```\n */\nexport const sankey: ChartType<SankeyOptions> = {\n name: 'sankey',\n clean: cleanData(cleanSankey),\n render: renderSankey,\n legend: sankeyLegend,\n table: sankeyTable,\n}\n"],"mappings":";;;;;;AAwGA,MAAM,YAAY;;AAElB,MAAM,kBAAkB;;AAExB,MAAM,aAAa;;AAGnB,SAAS,SAAS,MAAc,OAAe,UAA0B;CACvE,IAAI,kBAAkB,MAAM,QAAQ,KAAK,OAAO,OAAO;CACvD,IAAI,MAAM,KAAK;CACf,OAAO,MAAM,KAAK,kBAAkB,GAAG,KAAK,MAAM,GAAG,GAAG,EAAE,IAAI,QAAQ,IAAI,OAAO;CACjF,OAAO,MAAM,IAAI,GAAG,KAAK,MAAM,GAAG,GAAG,CAAC,CAAC,QAAQ,EAAE,KAAK;AACxD;;AAGA,MAAM,WAAW,SAAuB,KAAK,KAAK,SAAS,kBAAkB,KAAK,KAAK;;AAGvF,SAAS,MAAM,MAAkB,QAA6B,SAAkB;CAC9E,MAAM,yBAAS,IAAI,IAAkB;CACrC,MAAM,QAAgB,CAAC;CACv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,EAAE;GAAM,MAAM,EAAE;GAAM,OAAO,KAAK;GAAM,OAAO,EAAE;EAAM;EACvF,IAAI,EAAE,QAAQ,KAAK,SAAS;EAC5B,KAAK,IAAI,EAAE,OAAO,IAAI;CACxB;CAEF,OAAO,CAAC,GAAG,KAAK,OAAO,CAAC;AAC1B;AAEA,SAAS,YAAY,SAAwB,KAA+B;CAC1E,MAAM,EAAE,UAAU,MAAM,QAAQ,MAAM,IAAI,QAAQ,IAAI;CACtD,MAAM,QAAQ,aAAa,QAAQ,QAAQ,IAAI,MAAM;CACrD,OAAO;EACL,SAAS;GAAC;GAAQ;GAAM;EAAO;EAC/B,MAAM,MAAM,KAAK,SAAS;GAAC,KAAK,KAAK;GAAM,KAAK,KAAK;GAAI,MAAM,KAAK,KAAK,KAAK;EAAC,CAAC;CAClF;AACF;;AAGA,MAAM,eAAe,SAA2B;CAC9C,MAAM,IAAI,SAAS,IAAI,IAAI,OAAO,CAAC;CACnC,OAAO;EACL,GAAG;EACH,OAAO,MAAM,QAAQ,EAAE,KAAK,IAAI,QAAQ,EAAE,QAAQ,MAAM,MAAM,CAAC,CAAC,IAAI,KAAA;EACpE,OAAO,QAAQ,EAAE,QAAQ,OAAO;GAC9B,MAAM,KAAK,EAAE,IAAI;GACjB,IAAI,KAAK,EAAE,EAAE;GACb,OAAO,KAAK,IAAI,GAAG,OAAO,EAAE,KAAK,KAAK,CAAC;EACzC,EAAE;CACJ;AACF;;;;;;;;;;;;;;;;;;;;AAqBA,MAAa,SAAmC;CAC9C,MAAM;CACN,OAAO,UAAU,WAAW;CAC5B,QAAQ;CACR,QAAQ;CACR,OAAO;AACT"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sankey-fCoo1cpz.cjs","names":["estimateTextWidth","innerRect","mirrorSides","insets","formatDetail","LINE_HEIGHT","round","h","isRecord","records","named","text","finite","cleanData"],"sources":["../src/charts/sankey.ts"],"sourcesContent":["import type { DataTable } from '../a11y.ts'\nimport type { ChartType, RenderContext } from '../chart.ts'\nimport { formatDetail, type NumberFormat } from '../format.ts'\nimport type { Hit, HitItem, Interaction } from '../interaction.ts'\nimport {\n estimateTextWidth,\n type InsetsInput,\n innerRect,\n insets,\n LINE_HEIGHT,\n mirrorSides,\n type Rect,\n round,\n} from '../layout.ts'\nimport type { LegendItem } from '../legend.ts'\nimport { type ChildInput, h } from '../vnode.ts'\nimport { cleanData, finite, isRecord, named, records, text } from './clean.ts'\n\n/** A node of the flow; nodes left out are made from the links. */\nexport interface SankeyNode {\n name: string\n /**\n * Custom color; overrides the palette slot via `--tc-series-color`. Nodes\n * sharing a color form one legend entry, named after the first of them.\n * Values that could inject CSS (`;`, quotes, `url()` …) are ignored, so colors from user data are safe.\n */\n color?: string\n /** Start hidden (toggle it back from the legend, with every node of its color). */\n hidden?: boolean\n}\n\n/** A flow between two nodes, by name. */\nexport interface SankeyLink {\n from: string\n to: string\n /** Non-negative value; negative values count as zero. */\n value: number\n}\n\nexport interface SankeyData {\n /** Optional: sets the stacking order within a column, and colors. */\n nodes?: readonly SankeyNode[]\n links: readonly SankeyLink[]\n}\n\nexport interface SankeyOptions {\n data: SankeyData\n /** Width of the node bars in pixels. Defaults to `12`. */\n nodeWidth?: number\n /** Vertical gap between the nodes of a column in pixels. Defaults to `16`. */\n nodePadding?: number\n /** Format of the values (labels, tooltips and the table). */\n format?: NumberFormat\n /**\n * `'justify'` (default) puts every node without outgoing flows in the last\n * column; `'left'` leaves it in the column after its sources.\n */\n align?: 'justify' | 'left'\n /** Extra space around the diagram, in pixels. */\n padding?: InsetsInput\n}\n\ninterface Node {\n data: SankeyNode\n index: number\n /** Palette slot, 1-based: the node's position in its column. */\n slot: number\n column: number\n value: number\n x: number\n y: number\n height: number\n ins: Link[]\n outs: Link[]\n}\n\ninterface Link {\n data: SankeyLink\n index: number\n source: Node\n target: Node\n /** Top of the slice at the source and at the target. */\n sy: number\n ty: number\n width: number\n}\n\ninterface Layout {\n nodes: Node[]\n links: Link[]\n /** The columns' extent, between the label margins. */\n plot: Rect\n nodeWidth: number\n labels: NodeLabel[]\n}\n\n/** A node's label: the name and the value under it, cut to fit (empty when hidden). */\ninterface NodeLabel {\n side: 'left' | 'right'\n name: string\n value: string\n}\n\n/** Space between a node and its label. */\nconst LABEL_GAP = 8\n/** Largest share of the width one side's labels may take. */\nconst MAX_LABEL_SHARE = 0.3\n/** Pixels around a node that still count as hovering it. */\nconst HOVER_SLOP = 2\n\n/** `text`, cut short with an ellipsis to fit `width` pixels. */\nfunction truncate(text: string, width: number, fontSize: number): string {\n if (estimateTextWidth(text, fontSize) <= width) return text\n let end = text.length\n while (end > 0 && estimateTextWidth(`${text.slice(0, end)}…`, fontSize) > width) end--\n return end > 0 ? `${text.slice(0, end).trimEnd()}…` : ''\n}\n\n/** The color of a node for hover and tooltip swatches. */\nconst colorOf = (node: Node): string => node.data.color ?? `var(--tc-color-${node.slot})`\n\n/** The visible nodes and links, in data order, with their columns. */\nfunction graph(data: SankeyData, hidden: ReadonlySet<string>, justify: boolean) {\n const byName = new Map<string, Node>()\n const nodes: Node[] = []\n const node = (name: string, data?: SankeyNode): Node => {\n let found = byName.get(name)\n if (!found) {\n found = {\n data: data ?? { name },\n index: nodes.length,\n slot: 1,\n column: 0,\n value: 0,\n x: 0,\n y: 0,\n height: 0,\n ins: [],\n outs: [],\n }\n byName.set(name, found)\n nodes.push(found)\n }\n return found\n }\n const declared = new Map((data.nodes ?? []).map((n) => [n.name, n]))\n /** A legend key hides every node of its color, see `sankeyLegend`. */\n const isHidden = (name: string) => {\n const n = declared.get(name)\n return hidden.has(name) || (n?.color !== undefined && hidden.has(legendKey(data, n.color)))\n }\n const links: Link[] = []\n data.links.forEach((link, index) => {\n if (link.from === link.to || isHidden(link.from) || isHidden(link.to)) return\n const source = node(link.from, declared.get(link.from))\n const target = node(link.to, declared.get(link.to))\n const out: Link = { data: link, index, source, target, sy: 0, ty: 0, width: 0 }\n links.push(out)\n if (link.value <= 0) return\n source.outs.push(out)\n target.ins.push(out)\n })\n for (const n of nodes) {\n n.value = Math.max(\n n.outs.reduce((sum, l) => sum + l.data.value, 0),\n n.ins.reduce((sum, l) => sum + l.data.value, 0),\n )\n }\n // Column: the longest path from a source, passes bounded so cycles end.\n for (let pass = 0; pass < nodes.length; pass++) {\n let changed = false\n for (const link of links) {\n if (link.data.value > 0 && link.target.column <= link.source.column) {\n link.target.column = link.source.column + 1\n changed = true\n }\n }\n if (!changed) break\n }\n const last = nodes.reduce((max, n) => Math.max(max, n.column), 0)\n if (justify) for (const n of nodes) if (n.outs.length === 0) n.column = last\n // Stack order within a column: declared nodes first, then first appearance.\n const order = [...declared.keys()]\n nodes.sort((a, b) => {\n if (a.column !== b.column) return a.column - b.column\n const ia = order.indexOf(a.data.name)\n const ib = order.indexOf(b.data.name)\n if (ia !== -1 && ib !== -1) return ia - ib\n if (ia !== ib) return ia === -1 ? 1 : -1\n return a.index - b.index\n })\n const slots = new Map<number, number>()\n nodes.forEach((n, index) => {\n n.index = index\n const slot = (slots.get(n.column) ?? 0) + 1\n slots.set(n.column, slot)\n n.slot = ((slot - 1) % 8) + 1\n })\n return { nodes, links, columns: last + 1 }\n}\n\n/** Key of the legend entry of `color`: the first node that wears it. */\nconst legendKey = (data: SankeyData, color: string): string =>\n (data.nodes ?? []).find((n) => n.color === color)?.name ?? color\n\nfunction layout(options: SankeyOptions, ctx: RenderContext): Layout {\n const { width, height, fontSize, locale } = ctx\n const nodeWidth = Math.max(1, options.nodeWidth ?? 12)\n const nodePadding = Math.max(0, options.nodePadding ?? 16)\n // Right to left, the layout is worked out as its mirror image, then flipped.\n const { rtl } = ctx\n const area = innerRect(width, height, mirrorSides(insets(options.padding), rtl))\n const { nodes, links, columns } = graph(options.data, ctx.hidden, options.align !== 'left')\n const format = formatDetail(options.format, locale)\n\n // Labels take their room from the sides: the first column's to its left,\n // the last column's to its right, the rest to the right of their node.\n const texts = nodes.map((n) => [n.data.name, format(n.value)] as const)\n const widest = (match: (n: Node) => boolean) =>\n nodes.reduce((max, n, i) => {\n if (!match(n)) return max\n const [name, value] = texts[i] as readonly [string, string]\n return Math.max(max, estimateTextWidth(name, fontSize), estimateTextWidth(value, fontSize))\n }, 0)\n const cap = area.width * MAX_LABEL_SHARE\n const left =\n columns > 1\n ? Math.min(\n cap,\n widest((n) => n.column === 0),\n )\n : 0\n const right = Math.min(\n cap,\n widest((n) => n.column === columns - 1),\n )\n const plot: Rect = {\n x: area.x + (left ? left + LABEL_GAP : 0),\n y: area.y,\n width: Math.max(\n 0,\n area.width - (left ? left + LABEL_GAP : 0) - (right ? right + LABEL_GAP : 0),\n ),\n height: area.height,\n }\n const step = columns > 1 ? (plot.width - nodeWidth) / (columns - 1) : 0\n\n // Heights: one scale for every column, so values compare across them.\n const byColumn: Node[][] = Array.from({ length: columns }, () => [])\n for (const n of nodes) byColumn[n.column]?.push(n)\n const pad = byColumn.reduce(\n (min, col) => (col.length > 1 ? Math.min(min, plot.height / 2 / (col.length - 1)) : min),\n nodePadding,\n )\n let k = Number.POSITIVE_INFINITY\n for (const col of byColumn) {\n const sum = col.reduce((s, n) => s + n.value, 0)\n if (sum > 0) k = Math.min(k, (plot.height - (col.length - 1) * pad) / sum)\n }\n if (!Number.isFinite(k) || k < 0) k = 0\n byColumn.forEach((col, c) => {\n const total = col.reduce((s, n) => s + n.value * k, 0) + (col.length - 1) * pad\n let y = plot.y + (plot.height - total) / 2\n for (const n of col) {\n const x = plot.x + (columns > 1 ? c * step : (plot.width - nodeWidth) / 2)\n n.x = rtl ? width - x - nodeWidth : x\n n.y = y\n n.height = n.value * k\n y += n.height + pad\n }\n })\n // Slices: flows leave and enter in the order of the node at the other end.\n for (const n of nodes) {\n let y = n.y\n for (const link of [...n.outs].sort((a, b) => a.target.y - b.target.y)) {\n link.sy = y\n link.width = link.data.value * k\n y += link.width\n }\n y = n.y\n for (const link of [...n.ins].sort((a, b) => a.source.y - b.source.y)) {\n link.ty = y\n y += link.data.value * k\n }\n }\n\n const labels = nodes.map((n, i): NodeLabel => {\n const [name, value] = texts[i] as readonly [string, string]\n const side: 'left' | 'right' = n.column === 0 && columns > 1 ? 'left' : 'right'\n const room =\n side === 'left' ? left : n.column === columns - 1 ? right : step - nodeWidth - LABEL_GAP * 2\n // Crowded columns keep only the names: the value line would run into the next label.\n const col = byColumn[n.column] as Node[]\n const at = col.indexOf(n)\n const neighbours = [col[at - 1], col[at + 1]].filter((o): o is Node => !!o)\n const spacing = neighbours.reduce(\n (min, o) => Math.min(min, (n.height + o.height) / 2 + pad),\n Number.POSITIVE_INFINITY,\n )\n const showValue = spacing >= fontSize * (1 + LINE_HEIGHT)\n return {\n side,\n name: truncate(name, room, fontSize),\n value: showValue ? truncate(value, room, fontSize) : '',\n }\n })\n if (rtl) plot.x = width - plot.x - plot.width\n return { nodes, links, plot, nodeWidth, labels }\n}\n\n/** The x of a link's ends: the facing edges of its source and its target. */\nconst linkEnds = (link: Link, nodeWidth: number): [number, number] =>\n link.source.x > link.target.x\n ? [link.source.x, link.target.x + nodeWidth]\n : [link.source.x + nodeWidth, link.target.x]\n\n/** Path of a link: two cubic Béziers between the slices at its ends. */\nfunction linkPath(link: Link, nodeWidth: number): string {\n const [x0, x1] = linkEnds(link, nodeWidth)\n const xm = (x0 + x1) / 2\n const { sy, ty, width } = link\n const p = (...v: number[]) => v.map(round).join(',')\n return `M${p(x0, sy)}C${p(xm, sy, xm, ty, x1, ty)}L${p(x1, ty + width)}C${p(xm, ty + width, xm, sy + width, x0, sy + width)}Z`\n}\n\n/** A point on a cubic Bézier with control points `a`, `b`, `c`, `d`. */\nconst cubic = (a: number, b: number, c: number, d: number, t: number): number => {\n const u = 1 - t\n return u * u * u * a + 3 * u * u * t * b + 3 * u * t * t * c + t * t * t * d\n}\n\n/** Whether `(px, py)` lies inside the ribbon of `link`. */\nfunction inLink(link: Link, nodeWidth: number, px: number, py: number): boolean {\n const [x0, x1] = linkEnds(link, nodeWidth)\n if (px < Math.min(x0, x1) || px > Math.max(x0, x1) || x0 === x1) return false\n const xm = (x0 + x1) / 2\n // x(t) is monotone, so bisection finds the t under the pointer.\n let lo = 0\n let hi = 1\n for (let i = 0; i < 20; i++) {\n const mid = (lo + hi) / 2\n if (cubic(x0, xm, xm, x1, mid) < px === x1 > x0) lo = mid\n else hi = mid\n }\n const top = cubic(link.sy, link.sy, link.ty, link.ty, (lo + hi) / 2)\n return py >= top && py <= top + link.width\n}\n\nfunction renderSankey(options: SankeyOptions, ctx: RenderContext): ChildInput {\n const { nodes, links, plot, nodeWidth, labels } = layout(options, ctx)\n const drawn = links.filter((link) => link.data.value > 0)\n const formatValue = formatDetail(options.format, ctx.locale)\n\n const nodeMark = (n: Node) => ({\n d: `M0,0h${round(nodeWidth)}v${round(n.height)}h${round(-nodeWidth)}Z`,\n x: n.x,\n y: n.y,\n })\n const linkItem = (link: Link): HitItem => ({\n name: `${link.source.data.name} ${ctx.rtl ? '←' : '→'} ${link.target.data.name}`,\n seriesIndex: link.index,\n color: colorOf(link.source),\n value: link.data.value,\n text: formatValue(link.data.value),\n x: (link.source.x + nodeWidth + link.target.x) / 2,\n y: cubic(link.sy, link.sy, link.ty, link.ty, 0.5) + link.width / 2,\n })\n const hitNode = (n: Node, linkIndex?: number): Hit => {\n const own: HitItem = {\n name: n.data.name,\n seriesIndex: links.length + n.index,\n color: colorOf(n),\n value: n.value,\n text: formatValue(n.value),\n x: n.x + nodeWidth / 2,\n y: n.y + n.height / 2,\n }\n const flows = [...n.ins, ...n.outs].map(linkItem)\n const focused = flows.find((item) => item.seriesIndex === linkIndex)\n const link = focused && drawn.find((l) => l.index === linkIndex)\n return {\n index: n.index,\n label: n.data.name,\n title: '',\n x: own.x,\n area: plot,\n items: [own, ...flows],\n seriesIndex: focused ? linkIndex : own.seriesIndex,\n mark: link ? { d: linkPath(link, nodeWidth), x: 0, y: 0 } : nodeMark(n),\n }\n }\n const hitLink = (link: Link): Hit => {\n const item = linkItem(link)\n return {\n index: link.source.index,\n label: link.source.data.name,\n title: '',\n x: item.x,\n area: plot,\n items: [item],\n seriesIndex: link.index,\n mark: { d: linkPath(link, nodeWidth), x: 0, y: 0 },\n }\n }\n\n const interaction: Interaction = {\n count: nodes.length,\n hitTest(px, py) {\n const n = nodes.find(\n (n) =>\n px >= n.x - HOVER_SLOP &&\n px <= n.x + nodeWidth + HOVER_SLOP &&\n py >= n.y - HOVER_SLOP &&\n py <= n.y + n.height + HOVER_SLOP,\n )\n if (n) return hitNode(n)\n const link = drawn.find((l) => inLink(l, nodeWidth, px, py))\n return link ? hitLink(link) : null\n },\n hitIndex(index, seriesIndex) {\n const n = nodes[index]\n return n ? hitNode(n, seriesIndex) : null\n },\n }\n ctx.onHitTest(interaction)\n\n return [\n h(\n 'g',\n { key: 'links', class: 'tc-sankey-links' },\n drawn.map((link) =>\n h('path', {\n key: `${link.source.data.name}→${link.target.data.name}#${link.index}`,\n class: ['tc-series', `tc-series-${link.source.slot}`, 'tc-sankey-link'],\n style: { '--tc-series-color': link.source.data.color },\n d: linkPath(link, nodeWidth),\n }),\n ),\n ),\n h(\n 'g',\n { key: 'nodes', class: 'tc-sankey-nodes' },\n nodes.map((n) =>\n h(\n 'g',\n {\n key: n.data.name,\n class: ['tc-series', `tc-series-${n.slot}`],\n 'data-series': n.data.name,\n style: { '--tc-series-color': n.data.color },\n },\n h('rect', {\n class: 'tc-sankey-node',\n x: round(n.x),\n y: round(n.y),\n width: round(nodeWidth),\n height: round(n.height),\n }),\n ),\n ),\n ),\n h(\n 'g',\n { key: 'labels', class: 'tc-sankey-labels', 'aria-hidden': 'true' },\n nodes.map((n, i) => {\n const label = labels[i] as NodeLabel\n if (!label.name && !label.value) return null\n // The label's side is the one of the left-to-right layout: mirrored with it.\n const before = (label.side === 'left') !== (ctx.rtl === true)\n const x = round(before ? n.x - LABEL_GAP : n.x + nodeWidth + LABEL_GAP)\n const y = round(n.y + n.height / 2)\n const anchor = before ? 'end' : 'start'\n return h(\n 'g',\n { key: n.data.name, class: 'tc-sankey-label' },\n h(\n 'text',\n {\n class: 'tc-value-label tc-sankey-name',\n x,\n y,\n dy: label.value ? '-0.25em' : '0.35em',\n 'text-anchor': anchor,\n },\n label.name,\n ),\n label.value &&\n h(\n 'text',\n {\n class: 'tc-tick-label tc-sankey-value',\n x,\n y,\n dy: '0.95em',\n 'text-anchor': anchor,\n },\n label.value,\n ),\n )\n }),\n ),\n ]\n}\n\n/** One legend entry per custom color, named after the first node wearing it. */\nfunction sankeyLegend(options: SankeyOptions): LegendItem[] {\n const seen = new Map<string, LegendItem>()\n for (const n of options.data.nodes ?? []) {\n if (n.color && !seen.has(n.color)) {\n const item: LegendItem = { key: n.name, name: n.name, index: seen.size, color: n.color }\n if (n.hidden) item.hidden = true\n seen.set(n.color, item)\n }\n }\n return [...seen.values()]\n}\n\nfunction sankeyTable(options: SankeyOptions, ctx: RenderContext): DataTable {\n const { links } = graph(options.data, ctx.hidden, true)\n const value = formatDetail(options.format, ctx.locale)\n return {\n columns: ['From', 'To', 'Value'],\n rows: links.map((link) => [link.data.from, link.data.to, value(link.data.value)]),\n }\n}\n\n/** Nodes and links from users, APIs and JSON, in the shape the layout expects. */\nconst cleanSankey = (data: unknown): unknown => {\n const d = isRecord(data) ? data : {}\n return {\n ...d,\n nodes: Array.isArray(d.nodes) ? records(d.nodes, (r) => named(r)) : undefined,\n links: records(d.links, (r) => ({\n from: text(r.from),\n to: text(r.to),\n value: Math.max(0, finite(r.value) ?? 0),\n })),\n }\n}\n\n/**\n * Sankey diagram: flows between nodes, as ribbons whose width is their\n * value. Nodes are made from the links (or declared, to set their order and\n * colors) and placed in columns by the longest path from a source.\n *\n * ```ts\n * new Chart('#el', {\n * type: sankey,\n * data: {\n * links: [\n * { from: 'Wages', to: 'Income', value: 60 },\n * { from: 'Dividends', to: 'Income', value: 15 },\n * { from: 'Income', to: 'Rent', value: 30 },\n * { from: 'Income', to: 'Savings', value: 45 },\n * ],\n * },\n * })\n * ```\n */\nexport const sankey: ChartType<SankeyOptions> = {\n name: 'sankey',\n clean: cleanData(cle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AAO;EAC/B,MAAM,MAAM,KAAK,SAAS;GAAC,KAAK,KAAK;GAAM,KAAK,KAAK;GAAI,MAAM,KAAK,KAAK,KAAK;EAAC,CAAC;CAClF;AACF;;AAGA,MAAM,eAAe,SAA2B;CAC9C,MAAM,IAAII,cAAAA,SAAS,IAAI,IAAI,OAAO,CAAC;CACnC,OAAO;EACL,GAAG;EACH,OAAO,MAAM,QAAQ,EAAE,KAAK,IAAIC,cAAAA,QAAQ,EAAE,QAAQ,MAAMC,cAAAA,MAAM,CAAC,CAAC,IAAI,KAAA;EACpE,OAAOD,cAAAA,QAAQ,EAAE,QAAQ,OAAO;GAC9B,MAAME,cAAAA,KAAK,EAAE,IAAI;GACjB,IAAIA,cAAAA,KAAK,EAAE,EAAE;GACb,OAAO,KAAK,IAAI,GAAGC,cAAAA,OAAO,EAAE,KAAK,KAAK,CAAC;EACzC,EAAE;CACJ;AACF;;;;;;;;;;;;;;;;;;;;AAqBA,MAAa,SAAmC;CAC9C,MAAM;CACN,OAAOC,cAAAA,UAAU,WAAW;CAC5B,QAAQ;CACR,QAAQ;CACR,OAAO;AACT"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"scatter-C0TWjFpW.js","names":[],"sources":["../src/charts/scatter.ts"],"sourcesContent":["import type { DataTable } from '../a11y.ts'\nimport type { ChartType, RenderContext } from '../chart.ts'\nimport { axis, axisSize, type Tick, thinTicks } from '../components/axis.ts'\nimport { grid } from '../components/grid.ts'\nimport { formatDetail, formatNumber } from '../format.ts'\nimport type { Hit, HitItem, Interaction } from '../interaction.ts'\nimport {\n estimateTextWidth,\n type InsetsInput,\n innerRect,\n insets,\n LINE_HEIGHT,\n mirrorSides,\n round,\n} from '../layout.ts'\nimport { extent } from '../scales/extent.ts'\nimport type { LinearScale } from '../scales/linear.ts'\nimport { circlePath } from '../shapes/circle.ts'\nimport { type ClassValue, h } from '../vnode.ts'\nimport {\n domainOf,\n markerShape,\n plotClip,\n plottable,\n tickCount,\n type ValueAxisOptions,\n valueScale,\n valueTicks,\n} from './cartesian.ts'\nimport { cleanData, finite, isRecord, named, records, text } from './clean.ts'\nimport { groupAttrs, keyOf, legendItems } from './named.ts'\n\n/** A point of a scatter or bubble chart. */\nexport interface ScatterPoint {\n x: number\n y: number\n /** Bubble size; the circle area is proportional to it. */\n size?: number\n /** Name shown in the tooltip and table (e.g. a country). */\n label?: string\n}\n\nexport interface ScatterSeries {\n name: string\n points: readonly ScatterPoint[]\n /** Stable identity for keyed updates and legend toggles. Defaults to `name`. */\n id?: string\n /**\n * Custom color; overrides the palette slot via `--tc-series-color`.\n * Values that could inject CSS (`;`, quotes, `url()` …) are ignored, so colors from user data are safe.\n */\n color?: string\n /** Extra classes on the series group. */\n class?: ClassValue\n /** Start hidden (toggle it back from the legend). */\n hidden?: boolean\n}\n\nexport interface ScatterOptions {\n data: { series: readonly ScatterSeries[] }\n /** Horizontal value axis; `reverse` runs it from the right (the default with `rtl`). */\n x?: ValueAxisOptions & { reverse?: boolean }\n /** Vertical value axis. */\n y?: ValueAxisOptions\n /** Radius of points without a size, in pixels. Defaults to `4`. */\n radius?: number\n /** Radius range for bubbles (points with `size`). Defaults to `{ min: 4, max: 24 }`. */\n size?: { min?: number; max?: number }\n /** Extra space around the plot area, in pixels. */\n padding?: InsetsInput\n}\n\n/** Pointer distance (in pixels, beyond the radius) that still hits a point. */\nconst HIT_RADIUS = 24\nconst EDGE = 8\n\ninterface Placed {\n seriesIndex: number\n pointIndex: number\n point: ScatterPoint\n cx: number\n cy: number\n r: number\n}\n\n/** A point's bubble size, or `undefined` when it has none (or an invalid one). */\nconst sizeOf = (p: ScatterPoint): number | undefined =>\n p.size != null && Number.isFinite(p.size) && p.size > 0 ? p.size : undefined\n\nfunction renderScatter(options: ScatterOptions, ctx: RenderContext) {\n const { width, height, fontSize, locale } = ctx\n const xOptions = options.x ?? {}\n const yOptions = options.y ?? {}\n const radius = options.radius ?? 4\n const visible = options.data.series.filter((s) => !ctx.hidden.has(keyOf(s)))\n const points = visible.flatMap((s) => s.points)\n const sizes = points.map(sizeOf).filter((v): v is number => v !== undefined)\n const maxSize = extent(sizes)?.[1] ?? 0\n const rMin = options.size?.min ?? 4\n const rMax = options.size?.max ?? 24\n // Area-proportional bubbles: the radius grows with the square root of the size.\n const bubble = (size: number | undefined) =>\n size != null && size > 0 && maxSize > 0\n ? rMin + (rMax - rMin) * Math.sqrt(size / maxSize)\n : radius\n const overhang = Math.max(radius, sizes.length ? rMax : 0) + 2\n\n const countY = tickCount(yOptions, Math.max(2, Math.round(height / 60)))\n const countX = tickCount(xOptions, Math.max(2, Math.round(width / 80)))\n // Only points that can be plotted on both axes take part.\n const usable = (p: ScatterPoint) => plottable(p.x, xOptions) && plottable(p.y, yOptions)\n const shown = points.filter(usable)\n const xDomain = domainOf(\n shown.map((p) => p.x),\n xOptions,\n false,\n countX,\n )\n const yDomain = domainOf(\n shown.map((p) => p.y),\n yOptions,\n false,\n countY,\n )\n\n const showX = xOptions.show !== false\n const showY = yOptions.show !== false\n // Linear or logarithmic, as each axis asks (see valueScale).\n const ticksOf = (scale: LinearScale, axis: ValueAxisOptions, count: number) =>\n valueTicks(scale, axis, count, axis.format, locale)\n const probeY = ticksOf(valueScale(yDomain, [1, 0], yOptions), yOptions, countY)\n const probeX = ticksOf(valueScale(xDomain, [0, 1], xOptions), xOptions, countX)\n const half = (tick: Tick | undefined) =>\n showX && tick ? Math.ceil(estimateTextWidth(tick.label, fontSize) / 2) : 0\n // Right to left, the sides are worked out as their mirror image, then swapped.\n const { rtl } = ctx\n const reverse = xOptions.reverse ?? rtl === true\n // The x tick at the value axis' end of the plot, and the one at the other end.\n const near = reverse === (rtl === true) ? 0 : probeX.length - 1\n const pad = mirrorSides(insets(options.padding), rtl)\n const margins = mirrorSides(\n {\n top:\n pad.top + Math.max(showY ? Math.ceil((fontSize * LINE_HEIGHT) / 2) : 0, overhang, EDGE / 2),\n right: pad.right + Math.max(half(probeX[probeX.length - 1 - near]), overhang, EDGE),\n bottom:\n pad.bottom + Math.max(showX ? axisSize('bottom', probeX, fontSize) : 0, overhang, EDGE / 2),\n left:\n pad.left +\n Math.max(showY ? axisSize('left', probeY, fontSize) : 0, half(probeX[near]), overhang),\n },\n rtl,\n )\n const area = innerRect(width, height, margins)\n const end = area.x + area.width\n const x = valueScale(xDomain, reverse ? [end, area.x] : [area.x, end], xOptions)\n const y = valueScale(yDomain, [area.y + area.height, area.y], yOptions)\n // Thinned like the ticks of the other charts: on a log axis they crowd at the end of each decade.\n const xTicks = thinTicks(ticksOf(x, xOptions, countX), 'bottom', fontSize)\n const yTicks = thinTicks(ticksOf(y, yOptions, countY), 'left', fontSize, 4)\n\n // Every visible point in pixels, sorted by x for fast nearest-point lookups.\n const placed: Placed[] = []\n options.data.series.forEach((series, seriesIndex) => {\n if (ctx.hidden.has(keyOf(series))) return\n series.points.forEach((point, pointIndex) => {\n if (!usable(point)) return\n placed.push({\n seriesIndex,\n pointIndex,\n point,\n cx: x(point.x),\n cy: y(point.y),\n r: bubble(sizeOf(point)),\n })\n })\n })\n placed.sort((a, b) => a.cx - b.cx)\n\n const fx = formatDetail(xOptions.format, locale)\n const fy = formatDetail(yOptions.format, locale)\n const fs = formatNumber(undefined, locale)\n const hitFor = (p: Placed, index: number): Hit => {\n const series = options.data.series[p.seriesIndex] as ScatterSeries\n const sz = sizeOf(p.point)\n const size = sz === undefined ? '' : ` · ${fs(sz)}`\n const item: HitItem = {\n name: series.name,\n seriesIndex: p.seriesIndex,\n value: p.point.y,\n text: `${fx(p.point.x)}, ${fy(p.point.y)}${size}`,\n x: p.cx,\n y: p.cy,\n }\n if (series.color) item.color = series.color\n return {\n index,\n label: p.point.label ?? series.name,\n title: p.point.label ?? '',\n x: p.cx,\n area,\n items: [item],\n seriesIndex: p.seriesIndex,\n mark: { d: circlePath(round(p.r + 4)), x: p.cx, y: p.cy },\n }\n }\n\n const interaction: Interaction = {\n count: placed.length,\n hitIndex: (index) => {\n const p = placed[index]\n return p ? hitFor(p, index) : null\n },\n hitTest(px, py) {\n // Binary search the first point within reach on x, then scan the window.\n let lo = 0\n let hi = placed.length\n const reach = HIT_RADIUS + rMax\n while (lo < hi) {\n const mid = (lo + hi) >> 1\n if ((placed[mid] as Placed).cx < px - reach) lo = mid + 1\n else hi = mid\n }\n let best = -1\n let bestDistance = Number.POSITIVE_INFINITY\n for (let i = lo; i < placed.length; i++) {\n const p = placed[i] as Placed\n if (p.cx > px + reach) break\n const distance = Math.hypot(p.cx - px, p.cy - py) - p.r\n if (distance < bestDistance && distance <= HIT_RADIUS) {\n best = i\n bestDistance = distance\n }\n }\n return best === -1 ? null : hitFor(placed[best] as Placed, best)\n },\n }\n ctx.onHitTest(interaction)\n\n /** One path drawing a dot of `radius` at every point (two arcs each, or the series' shape). */\n const shape = markerShape(options)\n const dotsPath = (dots: readonly ScatterPoint[], slot: number) => {\n if (!dots.length) return null\n const r = round(radius)\n let d = ''\n for (const p of dots) {\n d += shape\n ? shape(slot, x(p.x), y(p.y), r)\n : `M${round(x(p.x) - radius)},${round(y(p.y))}a${r},${r},0,1,0,${2 * r},0a${r},${r},0,1,0,${-2 * r},0`\n }\n return h('path', { key: 'dots', class: ['tc-point tc-dots', shape && 'tc-marker'], d })\n }\n\n const background = []\n if (yOptions.grid !== false) background.push(grid({ direction: 'y', ticks: yTicks, area }))\n if (xOptions.grid) background.push(grid({ direction: 'x', ticks: xTicks, area }))\n\n // Dots may reach a little past the plot edges; bubbles are cut at them (like\n // Chart.js), as a big one there would cover the axis labels.\n const clip = plotClip(ctx, area, sizes.length ? 0 : overhang)\n const groups = options.data.series.map(\n (series, seriesIndex) =>\n !ctx.hidden.has(keyOf(series)) &&\n h(\n 'g',\n groupAttrs(series, seriesIndex),\n // Plain points share one path per series: thousands of circles would\n // each cost the browser style and layout work. The path keeps its\n // commands while the point count does, so new data morphs. Bubbles\n // stay circles: each is see-through over the others.\n dotsPath(\n series.points.filter((p) => usable(p) && sizeOf(p) === undefined),\n seriesIndex,\n ),\n series.points.map(\n (point, i) =>\n usable(point) &&\n sizeOf(point) !== undefined &&\n h('circle', {\n key: i,\n class: 'tc-point tc-bubble',\n cx: round(x(point.x)),\n cy: round(y(point.y)),\n r: round(bubble(sizeOf(point))),\n }),\n ),\n ),\n )\n\n return [\n h('defs', null, clip.def),\n background,\n h('g', { key: 'series', class: 'tc-series-list', 'clip-path': clip.url }, groups),\n showY && axis({ position: rtl ? 'right' : 'left', ticks: yTicks, area }),\n showX && axis({ position: 'bottom', ticks: xTicks, area }),\n ]\n}\n\nfunction scatterTable(\n options: ScatterOptions,\n ctx: RenderContext,\n limit: number = Number.POSITIVE_INFINITY,\n): DataTable {\n const fx = formatDetail(options.x?.format, ctx.locale)\n const fy = formatDetail(options.y?.format, ctx.locale)\n const fs = formatNumber(undefined, ctx.locale)\n const series = options.data.series.filter((s) => !ctx.hidden.has(keyOf(s)))\n const withSize = series.some((s) => s.points.some((p) => p.size != null))\n const withLabel = series.some((s) => s.points.some((p) => p.label != null))\n const total = series.reduce((sum, s) => sum + s.points.length, 0)\n let left = limit\n return {\n columns: ['', ...(withLabel ? ['Label'] : []), 'x', 'y', ...(withSize ? ['Size'] : [])],\n total,\n rows: series.flatMap((s) => {\n const take = s.points.slice(0, Math.max(0, left))\n left -= take.length\n return take.map((p) => [\n s.name,\n ...(withLabel ? [p.label ?? ''] : []),\n fx(p.x),\n fy(p.y),\n ...(withSize ? [sizeOf(p) === undefined ? '–' : fs(sizeOf(p) as number)] : []),\n ])\n }),\n }\n}\n\n/**\n * Scatter chart: points on two value axes; give points a `size` for a\n * bubble chart (area-proportional radii).\n *\n * ```ts\n * new Chart('#el', {\n * type: scatter,\n * data: { series: [{ name: 'Cities', points: [{ x: 12, y: 3.4 }, { x: 18, y: 5.1 }] }] },\n * })\n * ```\n */\nexport const scatter: ChartType<ScatterOptions> = {\n name: 'scatter',\n clean: cleanData((data) => ({\n ...(isRecord(data) ? data : {}),\n series: records(isRecord(data) && data.series, (s) => ({\n ...named(s),\n points: records(s.points, (p) => ({\n ...p,\n x: finite(p.x),\n y: finite(p.y),\n size: finite(p.size) ?? undefined,\n label: p.label == null ? undefined : text(p.label),\n })).filter((p) => p.x !== null && p.y !== null),\n })),\n })),\n render: renderScatter,\n legend: (options) => legendItems(options.data.series),\n table: scatterTable,\n valueLabels: { format: (options) => options.y?.format },\n}\n"],"mappings":";;;;;;;;;;AAyEA,MAAM,aAAa;AACnB,MAAM,OAAO;;AAYb,MAAM,UAAU,MACd,EAAE,QAAQ,QAAQ,OAAO,SAAS,EAAE,IAAI,KAAK,EAAE,OAAO,IAAI,EAAE,OAAO,KAAA;AAErE,SAAS,cAAc,SAAyB,KAAoB;CAClE,MAAM,EAAE,OAAO,QAAQ,UAAU,WAAW;CAC5C,MAAM,WAAW,QAAQ,KAAK,CAAC;CAC/B,MAAM,WAAW,QAAQ,KAAK,CAAC;CAC/B,MAAM,SAAS,QAAQ,UAAU;CAEjC,MAAM,SADU,QAAQ,KAAK,OAAO,QAAQ,MAAM,CAAC,IAAI,OAAO,IAAI,MAAM,CAAC,CAAC,CACrD,CAAC,CAAC,SAAS,MAAM,EAAE,MAAM;CAC9C,MAAM,QAAQ,OAAO,IAAI,MAAM,CAAC,CAAC,QAAQ,MAAmB,MAAM,KAAA,CAAS;CAC3E,MAAM,UAAU,OAAO,KAAK,CAAC,GAAG,MAAM;CACtC,MAAM,OAAO,QAAQ,MAAM,OAAO;CAClC,MAAM,OAAO,QAAQ,MAAM,OAAO;CAElC,MAAM,UAAU,SACd,QAAQ,QAAQ,OAAO,KAAK,UAAU,IAClC,QAAQ,OAAO,QAAQ,KAAK,KAAK,OAAO,OAAO,IAC/C;CACN,MAAM,WAAW,KAAK,IAAI,QAAQ,MAAM,SAAS,OAAO,CAAC,IAAI;CAE7D,MAAM,SAAS,UAAU,UAAU,KAAK,IAAI,GAAG,KAAK,MAAM,SAAS,EAAE,CAAC,CAAC;CACvE,MAAM,SAAS,UAAU,UAAU,KAAK,IAAI,GAAG,KAAK,MAAM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AK,KAAK,MAAM;IACrB,EAAE;IACF,GAAI,YAAY,CAAC,EAAE,SAAS,EAAE,IAAI,CAAC;IACnC,GAAG,EAAE,CAAC;IACN,GAAG,EAAE,CAAC;IACN,GAAI,WAAW,CAAC,OAAO,CAAC,MAAM,KAAA,IAAY,MAAM,GAAG,OAAO,CAAC,CAAW,CAAC,IAAI,CAAC;GAC9E,CAAC;EACH,CAAC;CACH;AACF;;;;;;;;;;;;AAaA,MAAa,UAAqC;CAChD,MAAM;CACN,OAAO,WAAW,UAAU;EAC1B,GAAI,SAAS,IAAI,IAAI,OAAO,CAAC;EAC7B,QAAQ,QAAQ,SAAS,IAAI,KAAK,KAAK,SAAS,OAAO;GACrD,GAAG,MAAM,CAAC;GACV,QAAQ,QAAQ,EAAE,SAAS,OAAO;IAChC,GAAG;IACH,GAAG,OAAO,EAAE,CAAC;IACb,GAAG,OAAO,EAAE,CAAC;IACb,MAAM,OAAO,EAAE,IAAI,KAAK,KAAA;IACxB,OAAO,EAAE,SAAS,OAAO,KAAA,IAAY,KAAK,EAAE,KAAK;GACnD,EAAE,CAAC,CAAC,QAAQ,MAAM,EAAE,MAAM,QAAQ,EAAE,MAAM,IAAI;EAChD,EAAE;CACJ,EAAE;CACF,QAAQ;CACR,SAAS,YAAY,YAAY,QAAQ,KAAK,MAAM;CACpD,OAAO;CACP,aAAa,EAAE,SAAS,YAAY,QAAQ,GAAG,OAAO;AACxD"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"scatter-DVqB_fP9.cjs","names":["keyOf","extent","tickCount","plottable","domainOf","valueTicks","valueScale","estimateTextWidth","mirrorSides","insets","LINE_HEIGHT","axisSize","innerRect","thinTicks","formatDetail","formatNumber","circlePath","round","markerShape","h","grid","plotClip","groupAttrs","axis","cleanData","isRecord","records","named","finite","text","legendItems"],"sources":["../src/charts/scatter.ts"],"sourcesContent":["import type { DataTable } from '../a11y.ts'\nimport type { ChartType, RenderContext } from '../chart.ts'\nimport { axis, axisSize, type Tick, thinTicks } from '../components/axis.ts'\nimport { grid } from '../components/grid.ts'\nimport { formatDetail, formatNumber } from '../format.ts'\nimport type { Hit, HitItem, Interaction } from '../interaction.ts'\nimport {\n estimateTextWidth,\n type InsetsInput,\n innerRect,\n insets,\n LINE_HEIGHT,\n mirrorSides,\n round,\n} from '../layout.ts'\nimport { extent } from '../scales/extent.ts'\nimport type { LinearScale } from '../scales/linear.ts'\nimport { circlePath } from '../shapes/circle.ts'\nimport { type ClassValue, h } from '../vnode.ts'\nimport {\n domainOf,\n markerShape,\n plotClip,\n plottable,\n tickCount,\n type ValueAxisOptions,\n valueScale,\n valueTicks,\n} from './cartesian.ts'\nimport { cleanData, finite, isRecord, named, records, text } from './clean.ts'\nimport { groupAttrs, keyOf, legendItems } from './named.ts'\n\n/** A point of a scatter or bubble chart. */\nexport interface ScatterPoint {\n x: number\n y: number\n /** Bubble size; the circle area is proportional to it. */\n size?: number\n /** Name shown in the tooltip and table (e.g. a country). */\n label?: string\n}\n\nexport interface ScatterSeries {\n name: string\n points: readonly ScatterPoint[]\n /** Stable identity for keyed updates and legend toggles. Defaults to `name`. */\n id?: string\n /**\n * Custom color; overrides the palette slot via `--tc-series-color`.\n * Values that could inject CSS (`;`, quotes, `url()` …) are ignored, so colors from user data are safe.\n */\n color?: string\n /** Extra classes on the series group. */\n class?: ClassValue\n /** Start hidden (toggle it back from the legend). */\n hidden?: boolean\n}\n\nexport interface ScatterOptions {\n data: { series: readonly ScatterSeries[] }\n /** Horizontal value axis; `reverse` runs it from the right (the default with `rtl`). */\n x?: ValueAxisOptions & { reverse?: boolean }\n /** Vertical value axis. */\n y?: ValueAxisOptions\n /** Radius of points without a size, in pixels. Defaults to `4`. */\n radius?: number\n /** Radius range for bubbles (points with `size`). Defaults to `{ min: 4, max: 24 }`. */\n size?: { min?: number; max?: number }\n /** Extra space around the plot area, in pixels. */\n padding?: InsetsInput\n}\n\n/** Pointer distance (in pixels, beyond the radius) that still hits a point. */\nconst HIT_RADIUS = 24\nconst EDGE = 8\n\ninterface Placed {\n seriesIndex: number\n pointIndex: number\n point: ScatterPoint\n cx: number\n cy: number\n r: number\n}\n\n/** A point's bubble size, or `undefined` when it has none (or an invalid one). */\nconst sizeOf = (p: ScatterPoint): number | undefined =>\n p.size != null && Number.isFinite(p.size) && p.size > 0 ? p.size : undefined\n\nfunction renderScatter(options: ScatterOptions, ctx: RenderContext) {\n const { width, height, fontSize, locale } = ctx\n const xOptions = options.x ?? {}\n const yOptions = options.y ?? {}\n const radius = options.radius ?? 4\n const visible = options.data.series.filter((s) => !ctx.hidden.has(keyOf(s)))\n const points = visible.flatMap((s) => s.points)\n const sizes = points.map(sizeOf).filter((v): v is number => v !== undefined)\n const maxSize = extent(sizes)?.[1] ?? 0\n const rMin = options.size?.min ?? 4\n const rMax = options.size?.max ?? 24\n // Area-proportional bubbles: the radius grows with the square root of the size.\n const bubble = (size: number | undefined) =>\n size != null && size > 0 && maxSize > 0\n ? rMin + (rMax - rMin) * Math.sqrt(size / maxSize)\n : radius\n const overhang = Math.max(radius, sizes.length ? rMax : 0) + 2\n\n const countY = tickCount(yOptions, Math.max(2, Math.round(height / 60)))\n const countX = tickCount(xOptions, Math.max(2, Math.round(width / 80)))\n // Only points that can be plotted on both axes take part.\n const usable = (p: ScatterPoint) => plottable(p.x, xOptions) && plottable(p.y, yOptions)\n const shown = points.filter(usable)\n const xDomain = domainOf(\n shown.map((p) => p.x),\n xOptions,\n false,\n countX,\n )\n const yDomain = domainOf(\n shown.map((p) => p.y),\n yOptions,\n false,\n countY,\n )\n\n const showX = xOptions.show !== false\n const showY = yOptions.show !== false\n // Linear or logarithmic, as each axis asks (see valueScale).\n const ticksOf = (scale: LinearScale, axis: ValueAxisOptions, count: number) =>\n valueTicks(scale, axis, count, axis.format, locale)\n const probeY = ticksOf(valueScale(yDomain, [1, 0], yOptions), yOptions, countY)\n const probeX = ticksOf(valueScale(xDomain, [0, 1], xOptions), xOptions, countX)\n const half = (tick: Tick | undefined) =>\n showX && tick ? Math.ceil(estimateTextWidth(tick.label, fontSize) / 2) : 0\n // Right to left, the sides are worked out as their mirror image, then swapped.\n const { rtl } = ctx\n const reverse = xOptions.reverse ?? rtl === true\n // The x tick at the value axis' end of the plot, and the one at the other end.\n const near = reverse === (rtl === true) ? 0 : probeX.length - 1\n const pad = mirrorSides(insets(options.padding), rtl)\n const margins = mirrorSides(\n {\n top:\n pad.top + Math.max(showY ? Math.ceil((fontSize * LINE_HEIGHT) / 2) : 0, overhang, EDGE / 2),\n right: pad.right + Math.max(half(probeX[probeX.length - 1 - near]), overhang, EDGE),\n bottom:\n pad.bottom + Math.max(showX ? axisSize('bottom', probeX, fontSize) : 0, overhang, EDGE / 2),\n left:\n pad.left +\n Math.max(showY ? axisSize('left', probeY, fontSize) : 0, half(probeX[near]), overhang),\n },\n rtl,\n )\n const area = innerRect(width, height, margins)\n const end = area.x + area.width\n const x = valueScale(xDomain, reverse ? [end, area.x] : [area.x, end], xOptions)\n const y = valueScale(yDomain, [area.y + area.height, area.y], yOptions)\n // Thinned like the ticks of the other charts: on a log axis they crowd at the end of each decade.\n const xTicks = thinTicks(ticksOf(x, xOptions, countX), 'bottom', fontSize)\n const yTicks = thinTicks(ticksOf(y, yOptions, countY), 'left', fontSize, 4)\n\n // Every visible point in pixels, sorted by x for fast nearest-point lookups.\n const placed: Placed[] = []\n options.data.series.forEach((series, seriesIndex) => {\n if (ctx.hidden.has(keyOf(series))) return\n series.points.forEach((point, pointIndex) => {\n if (!usable(point)) return\n placed.push({\n seriesIndex,\n pointIndex,\n point,\n cx: x(point.x),\n cy: y(point.y),\n r: bubble(sizeOf(point)),\n })\n })\n })\n placed.sort((a, b) => a.cx - b.cx)\n\n const fx = formatDetail(xOptions.format, locale)\n const fy = formatDetail(yOptions.format, locale)\n const fs = formatNumber(undefined, locale)\n const hitFor = (p: Placed, index: number): Hit => {\n const series = options.data.series[p.seriesIndex] as ScatterSeries\n const sz = sizeOf(p.point)\n const size = sz === undefined ? '' : ` · ${fs(sz)}`\n const item: HitItem = {\n name: series.name,\n seriesIndex: p.seriesIndex,\n value: p.point.y,\n text: `${fx(p.point.x)}, ${fy(p.point.y)}${size}`,\n x: p.cx,\n y: p.cy,\n }\n if (series.color) item.color = series.color\n return {\n index,\n label: p.point.label ?? series.name,\n title: p.point.label ?? '',\n x: p.cx,\n area,\n items: [item],\n seriesIndex: p.seriesIndex,\n mark: { d: circlePath(round(p.r + 4)), x: p.cx, y: p.cy },\n }\n }\n\n const interaction: Interaction = {\n count: placed.length,\n hitIndex: (index) => {\n const p = placed[index]\n return p ? hitFor(p, index) : null\n },\n hitTest(px, py) {\n // Binary search the first point within reach on x, then scan the window.\n let lo = 0\n let hi = placed.length\n const reach = HIT_RADIUS + rMax\n while (lo < hi) {\n const mid = (lo + hi) >> 1\n if ((placed[mid] as Placed).cx < px - reach) lo = mid + 1\n else hi = mid\n }\n let best = -1\n let bestDistance = Number.POSITIVE_INFINITY\n for (let i = lo; i < placed.length; i++) {\n const p = placed[i] as Placed\n if (p.cx > px + reach) break\n const distance = Math.hypot(p.cx - px, p.cy - py) - p.r\n if (distance < bestDistance && distance <= HIT_RADIUS) {\n best = i\n bestDistance = distance\n }\n }\n return best === -1 ? null : hitFor(placed[best] as Placed, best)\n },\n }\n ctx.onHitTest(interaction)\n\n /** One path drawing a dot of `radius` at every point (two arcs each, or the series' shape). */\n const shape = markerShape(options)\n const dotsPath = (dots: readonly ScatterPoint[], slot: number) => {\n if (!dots.length) return null\n const r = round(radius)\n let d = ''\n for (const p of dots) {\n d += shape\n ? shape(slot, x(p.x), y(p.y), r)\n : `M${round(x(p.x) - radius)},${round(y(p.y))}a${r},${r},0,1,0,${2 * r},0a${r},${r},0,1,0,${-2 * r},0`\n }\n return h('path', { key: 'dots', class: ['tc-point tc-dots', shape && 'tc-marker'], d })\n }\n\n const background = []\n if (yOptions.grid !== false) background.push(grid({ direction: 'y', ticks: yTicks, area }))\n if (xOptions.grid) background.push(grid({ direction: 'x', ticks: xTicks, area }))\n\n // Dots may reach a little past the plot edges; bubbles are cut at them (like\n // Chart.js), as a big one there would cover the axis labels.\n const clip = plotClip(ctx, area, sizes.length ? 0 : overhang)\n const groups = options.data.series.map(\n (series, seriesIndex) =>\n !ctx.hidden.has(keyOf(series)) &&\n h(\n 'g',\n groupAttrs(series, seriesIndex),\n // Plain points share one path per series: thousands of circles would\n // each cost the browser style and layout work. The path keeps its\n // commands while the point count does, so new data morphs. Bubbles\n // stay circles: each is see-through over the others.\n dotsPath(\n series.points.filter((p) => usable(p) && sizeOf(p) === undefined),\n seriesIndex,\n ),\n series.points.map(\n (point, i) =>\n usable(point) &&\n sizeOf(point) !== undefined &&\n h('circle', {\n key: i,\n class: 'tc-point tc-bubble',\n cx: round(x(point.x)),\n cy: round(y(point.y)),\n r: round(bubble(sizeOf(point))),\n }),\n ),\n ),\n )\n\n return [\n h('defs', null, clip.def),\n background,\n h('g', { key: 'series', class: 'tc-series-list', 'clip-path': clip.url }, groups),\n showY && axis({ position: rtl ? 'right' : 'left', ticks: yTicks, area }),\n showX && axis({ position: 'bottom', ticks: xTicks, area }),\n ]\n}\n\nfunction scatterTable(\n options: ScatterOptions,\n ctx: RenderContext,\n limit: number = Number.POSITIVE_INFINITY,\n): DataTable {\n const fx = formatDetail(options.x?.format, ctx.locale)\n const fy = formatDetail(options.y?.format, ctx.locale)\n const fs = formatNumber(undefined, ctx.locale)\n const series = options.data.series.filter((s) => !ctx.hidden.has(keyOf(s)))\n const withSize = series.some((s) => s.points.some((p) => p.size != null))\n const withLabel = series.some((s) => s.points.some((p) => p.label != null))\n const total = series.reduce((sum, s) => sum + s.points.length, 0)\n let left = limit\n return {\n columns: ['', ...(withLabel ? ['Label'] : []), 'x', 'y', ...(withSize ? ['Size'] : [])],\n total,\n rows: series.flatMap((s) => {\n const take = s.points.slice(0, Math.max(0, left))\n left -= take.length\n return take.map((p) => [\n s.name,\n ...(withLabel ? [p.label ?? ''] : []),\n fx(p.x),\n fy(p.y),\n ...(withSize ? [sizeOf(p) === undefined ? '–' : fs(sizeOf(p) as number)] : []),\n ])\n }),\n }\n}\n\n/**\n * Scatter chart: points on two value axes; give points a `size` for a\n * bubble chart (area-proportional radii).\n *\n * ```ts\n * new Chart('#el', {\n * type: scatter,\n * data: { series: [{ name: 'Cities', points: [{ x: 12, y: 3.4 }, { x: 18, y: 5.1 }] }] },\n * })\n * ```\n */\nexport const scatter: ChartType<ScatterOptions> = {\n name: 'scatter',\n clean: cleanData((data) => ({\n ...(isRecord(data) ? data : {}),\n series: records(isRecord(data) && data.series, (s) => ({\n ...named(s),\n points: records(s.points, (p) => ({\n ...p,\n x: finite(p.x),\n y: finite(p.y),\n size: finite(p.size) ?? undefined,\n label: p.label == null ? undefined : text(p.label),\n })).filter((p) => p.x !== null && p.y !== null),\n })),\n })),\n render: renderScatter,\n legend: (options) => legendItems(options.data.series),\n table: scatterTable,\n valueLabels: { format: (options) => options.y?.format },\n}\n"],"mappings":";;;;;;;;;;AAyEA,MAAM,aAAa;AACnB,MAAM,OAAO;;AAYb,MAAM,UAAU,MACd,EAAE,QAAQ,QAAQ,OAAO,SAAS,EAAE,IAAI,KAAK,EAAE,OAAO,IAAI,EAAE,OAAO,KAAA;AAErE,SAAS,cAAc,SAAyB,KAAoB;CAClE,MAAM,EAAE,OAAO,QAAQ,UAAU,WAAW;CAC5C,MAAM,WAAW,QAAQ,KAAK,CAAC;CAC/B,MAAM,WAAW,QAAQ,KAAK,CAAC;CAC/B,MAAM,SAAS,QAAQ,UAAU;CAEjC,MAAM,SADU,QAAQ,KAAK,OAAO,QAAQ,MAAM,CAAC,IAAI,OAAO,IAAIA,cAAAA,MAAM,CAAC,CAAC,CACrD,CAAC,CAAC,SAAS,MAAM,EAAE,MAAM;CAC9C,MAAM,QAAQ,OAAO,IAAI,MAAM,CAAC,CAAC,QAAQ,MAAmB,MAAM,KAAA,CAAS;CAC3E,MAAM,UAAUC,eAAAA,OAAO,KAAK,CAAC,GAAG,MAAM;CACtC,MAAM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A,QAAQD,cAAAA,SAAS,IAAI,KAAK,KAAK,SAAS,OAAO;GACrD,GAAGE,cAAAA,MAAM,CAAC;GACV,QAAQD,cAAAA,QAAQ,EAAE,SAAS,OAAO;IAChC,GAAG;IACH,GAAGE,cAAAA,OAAO,EAAE,CAAC;IACb,GAAGA,cAAAA,OAAO,EAAE,CAAC;IACb,MAAMA,cAAAA,OAAO,EAAE,IAAI,KAAK,KAAA;IACxB,OAAO,EAAE,SAAS,OAAO,KAAA,IAAYC,cAAAA,KAAK,EAAE,KAAK;GACnD,EAAE,CAAC,CAAC,QAAQ,MAAM,EAAE,MAAM,QAAQ,EAAE,MAAM,IAAI;EAChD,EAAE;CACJ,EAAE;CACF,QAAQ;CACR,SAAS,YAAYC,cAAAA,YAAY,QAAQ,KAAK,MAAM;CACpD,OAAO;CACP,aAAa,EAAE,SAAS,YAAY,QAAQ,GAAG,OAAO;AACxD"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sparkline-B39NA0Mi.cjs","names":["insets","innerRect","domainOf","linear","formatNumber","labelKey","circlePath","h","round","barPath","areaPath","linePath","fadeMask","cleanData","numbers","label"],"sources":["../src/charts/sparkline.ts"],"sourcesContent":["import type { ChartType, RenderContext } from '../chart.ts'\nimport { fadeMask } from '../components/fade.ts'\nimport { formatNumber, type NumberFormat } from '../format.ts'\nimport type { Hit, HitItem, Interaction } from '../interaction.ts'\nimport { type InsetsInput, innerRect, insets, round } from '../layout.ts'\nimport { linear } from '../scales/linear.ts'\nimport { barPath } from '../shapes/bar.ts'\nimport { circlePath } from '../shapes/circle.ts'\nimport { areaPath, type Curve, linePath, type Point } from '../shapes/path.ts'\nimport { h } from '../vnode.ts'\nimport { domainOf, type Label, labelKey } from './cartesian.ts'\nimport { cleanData, label, numbers } from './clean.ts'\n\nexport interface SparklineOptions {\n /** The values; `null` leaves a gap. */\n data: readonly (number | null | undefined)[]\n /** Labels for the tooltip, one per value (e.g. dates). */\n labels?: readonly Label[]\n /** Name shown in the tooltip. Defaults to `'Value'`. */\n name?: string\n /**\n * `'line'` (default), `'area'`, `'bar'`, or `'tristate'`: only the sign\n * counts, as a full bar up (win), down (loss) or a tick on the middle (draw).\n */\n variant?: 'line' | 'area' | 'bar' | 'tristate'\n /** Interpolation for lines and areas. Defaults to `'monotone'`. */\n curve?: Curve\n /** Dot on the last value. Defaults to `'last'`. */\n point?: 'last' | 'none'\n /** Mark the minimum and maximum values. */\n markers?: 'minmax' | 'none'\n /** Dot radius in pixels. Defaults to `3`. */\n pointRadius?: number\n /** Include zero in the value range. Defaults to `true` for areas and bars, `false` for lines. */\n zero?: boolean\n /** Format of values in the tooltip. */\n format?: NumberFormat\n /** Extra space around the plot, in pixels. */\n padding?: InsetsInput\n}\n\nfunction renderSparkline(options: SparklineOptions, ctx: RenderContext) {\n const {\n variant = 'line',\n curve = 'monotone',\n point = 'last',\n markers = 'none',\n pointRadius = 3,\n name = 'Value',\n } = options\n const values = options.data.map((v) => (v == null || !Number.isFinite(v) ? null : v))\n // (No log option on sparklines, so finite is all that matters here.)\n const count = values.length\n const dots = point === 'last' || markers === 'minmax'\n // Room for the stroke and dots so nothing is clipped at the edges.\n const overhang = dots ? pointRadius + 2 : 2\n const pad = insets(options.padding, 0)\n const area = innerRect(ctx.width, ctx.height, {\n top: pad.top + overhang,\n right: pad.right + overhang,\n bottom: pad.bottom + overhang,\n left: pad.left + overhang,\n })\n const tristate = variant === 'tristate'\n const zero = options.zero ?? variant !== 'line'\n // Tristate bars span half the height each way, whatever the magnitude.\n const domain: [number, number] = tristate ? [-1, 1] : domainOf(values, { nice: false }, zero, 2)\n\n const bars = variant === 'bar' || tristate\n const gap = 1\n const slot = count > 0 ? area.width / count : 0\n // Right to left, the values run from the right: value `i` takes the place of its mirror.\n const place = (i: number) => (ctx.rtl ? count - 1 - i : i)\n const xAt = (i: number) =>\n bars\n ? area.x + slot * place(i) + slot / 2\n : area.x + (count > 1 ? (area.width * place(i)) / (count - 1) : area.width / 2)\n const y = linear(domain, [area.y + area.height, area.y])\n const baseline = y(Math.min(Math.max(0, domain[0]), domain[1]))\n const points: Point[] = values.map((v, i) => (v === null ? null : [xAt(i), y(v)]))\n\n const format = formatNumber(options.format, ctx.locale)\n const labelOf = (i: number) => {\n const label = options.labels?.[i]\n return label === undefined ? '' : String(label)\n }\n // Where a value is drawn: a tristate bar ends at its sign, not its magnitude.\n const yOf = (v: number) => y(tristate ? Math.sign(v) : v)\n const hitFor = (i: number): Hit | null => {\n const value = values[i]\n if (value === undefined) return null\n const px = xAt(i)\n const item: HitItem = {\n name,\n seriesIndex: 0,\n value,\n text: value === null ? '–' : format(value),\n x: px,\n y: value === null ? null : yOf(value),\n }\n const hit: Hit = {\n index: i,\n label: labelKey(options.labels?.[i] ?? i + 1),\n title: labelOf(i),\n x: px,\n area,\n items: [item],\n }\n if (value !== null) hit.mark = { d: circlePath(pointRadius + 3), x: px, y: yOf(value) }\n return hit\n }\n const interaction: Interaction = {\n count,\n reversed: ctx.rtl === true,\n hitIndex: (i) => hitFor(i),\n hitTest(px, py) {\n if (count === 0 || py < area.y - overhang || py > area.y + area.height + overhang) return null\n const i = bars\n ? Math.floor((px - area.x) / slot)\n : Math.round(((px - area.x) / Math.max(1, area.width)) * (count - 1))\n return hitFor(place(Math.max(0, Math.min(count - 1, i))))\n },\n }\n ctx.onHitTest(interaction)\n\n const marks = []\n if (tristate) {\n const width = Math.max(1, slot - gap)\n marks.push(\n h('line', {\n class: 'tc-sparkline-zero',\n x1: area.x,\n x2: area.x + area.width,\n y1: round(baseline),\n y2: round(baseline),\n }),\n )\n values.forEach((v, i) => {\n if (v === null) return\n const sign = Math.sign(v)\n // A draw is a short tick centered on the middle line.\n const tick = Math.min(2, area.height / 2)\n const [from, to] =\n sign === 0 ? [baseline + tick / 2, baseline - tick / 2] : [baseline, y(sign)]\n marks.push(\n h('path', {\n key: i,\n class: [\n 'tc-bar',\n sign < 0 && 'tc-bar-negative',\n sign < 0 ? 'tc-tristate-loss' : sign > 0 ? 'tc-tristate-win' : 'tc-tristate-draw',\n ],\n d: barPath(xAt(i) - width / 2, width, from, to, sign === 0 ? 0 : Math.min(2, width / 2)),\n }),\n )\n })\n } else if (bars) {\n const width = Math.max(1, slot - gap)\n values.forEach((v, i) => {\n if (v === null) return\n marks.push(\n h('path', {\n key: i,\n class: ['tc-bar', v < 0 && 'tc-bar-negative'],\n d: barPath(xAt(i) - width / 2, width, baseline, y(v), Math.min(2, width / 2)),\n }),\n )\n })\n } else {\n if (variant === 'area') {\n marks.push(\n h('path', {\n class: 'tc-area tc-area-gradient',\n d: areaPath(points, baseline, { curve }),\n mask: `url(#${ctx.id}-fade)`,\n }),\n )\n }\n marks.push(h('path', { class: 'tc-line', d: linePath(points, { curve }) }))\n }\n\n const dotAt = (i: number, cls: string) => {\n const v = values[i]\n return v == null\n ? null\n : h('circle', {\n key: `${cls}-${i}`,\n class: ['tc-point', cls],\n cx: round(xAt(i)),\n cy: round(y(v)),\n r: pointRadius,\n })\n }\n const extremes = []\n if (markers === 'minmax') {\n let min = -1\n let max = -1\n values.forEach((v, i) => {\n if (v === null) return\n if (min === -1 || v < (values[min] as number)) min = i\n if (max === -1 || v > (values[max] as number)) max = i\n })\n if (min !== -1) extremes.push(dotAt(min, 'tc-point-min'))\n if (max !== -1 && max !== min) extremes.push(dotAt(max, 'tc-point-max'))\n }\n let last = -1\n if (point === 'last') {\n for (let i = count - 1; i >= 0; i--) {\n if (values[i] !== null) {\n last = i\n break\n }\n }\n }\n\n return [\n variant === 'area' && h('defs', null, fadeMask(`${ctx.id}-fade`)),\n h(\n 'g',\n { class: 'tc-series tc-series-1 tc-sparkline' },\n marks,\n extremes,\n last !== -1 && !bars && dotAt(last, 'tc-point-last'),\n ),\n ]\n}\n\n/**\n * Sparkline: a tiny line, area or bar chart without axes, for stat tiles.\n *\n * ```ts\n * new Chart('#el', { type: sparkline, data: [3, 5, 4, 7, 6], height: 40 })\n * ```\n */\nexport const sparkline: ChartType<SparklineOptions> = {\n name: 'sparkline',\n // The labels too: they come from outside like the values.\n clean: (options) => ({\n ...cleanData(numbers)(options),\n labels: Array.isArray(options.labels) ? options.labels.map(label) : undefined,\n }),\n render: renderSparkline,\n // Decorative by default: opt in with `keyboard: true`.\n keyboard: false,\n}\n"],"mappings":";;;;;;;;;AAyCA,SAAS,gBAAgB,SAA2B,KAAoB;CACtE,MAAM,EACJ,UAAU,QACV,QAAQ,YACR,QAAQ,QACR,UAAU,QACV,cAAc,GACd,OAAO,YACL;CACJ,MAAM,SAAS,QAAQ,KAAK,KAAK,MAAO,KAAK,QAAQ,CAAC,OAAO,SAAS,CAAC,IAAI,OAAO,CAAE;CAEpF,MAAM,QAAQ,OAAO;CAGrB,MAAM,WAFO,UAAU,UAAU,YAAY,WAErB,cAAc,IAAI;CAC1C,MAAM,MAAMA,eAAAA,OAAO,QAAQ,SAAS,CAAC;CACrC,MAAM,OAAOC,eAAAA,UAAU,IAAI,OAAO,IAAI,QAAQ;EAC5C,KAAK,IAAI,MAAM;EACf,OAAO,IAAI,QAAQ;EACnB,QAAQ,IAAI,SAAS;EACrB,MAAM,IAAI,OAAO;CACnB,CAAC;CACD,MAAM,WAAW,YAAY;CAC7B,MAAM,OAAO,QAAQ,QAAQ,YAAY;CAEzC,MAAM,SAA2B,WAAW,CAAC,IAAI,CAAC,IAAIC,kBAAAA,SAAS,QAAQ,EAAE,MAAM,MAAM,GAAG,MAAM,CAAC;CAE/F,MAAM,OAAO,YAAY,SAAS;CAClC,MAAM,MAAM;CACZ,MAAM,OAAO,QAAQ,IAAI,KAAK,QAAQ,QAAQ;CAE9C,MAAM,SAAS,MAAe,IAAI,MAAM,QAAQ,IAAI,IAAI;CACxD,MAAM,OAAO,MACX,OACI,KAAK,IAAI,OAAO,MAAM,CAAC,IAAI,OAAO,IAClC,KAAK,KAAK,QAAQ,IAAK,KAAK,QAAQ,MAAM,CAAC,KAAM,QAAQ,KAAK,KAAK,QAAQ;CACjF,MAAM,IAAIC,kBAAAA,OAAO,QA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,OAAO;CACX,IAAI,UAAU,QACP;OAAA,IAAI,IAAI,QAAQ,GAAG,KAAK,GAAG,KAC9B,IAAI,OAAO,OAAO,MAAM;GACtB,OAAO;GACP;EACF;;CAIJ,OAAO,CACL,YAAY,UAAUD,cAAAA,EAAE,QAAQ,MAAMK,aAAAA,SAAS,GAAG,IAAI,GAAG,MAAM,CAAC,GAChEL,cAAAA,EACE,KACA,EAAE,OAAO,qCAAqC,GAC9C,OACA,UACA,SAAS,MAAM,CAAC,QAAQ,MAAM,MAAM,eAAe,CACrD,CACF;AACF;;;;;;;;AASA,MAAa,YAAyC;CACpD,MAAM;CAEN,QAAQ,aAAa;EACnB,GAAGM,cAAAA,UAAUC,cAAAA,OAAO,CAAC,CAAC,OAAO;EAC7B,QAAQ,MAAM,QAAQ,QAAQ,MAAM,IAAI,QAAQ,OAAO,IAAIC,cAAAA,KAAK,IAAI,KAAA;CACtE;CACA,QAAQ;CAER,UAAU;AACZ"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sparkline-XO_TqCNP.js","names":[],"sources":["../src/charts/sparkline.ts"],"sourcesContent":["import type { ChartType, RenderContext } from '../chart.ts'\nimport { fadeMask } from '../components/fade.ts'\nimport { formatNumber, type NumberFormat } from '../format.ts'\nimport type { Hit, HitItem, Interaction } from '../interaction.ts'\nimport { type InsetsInput, innerRect, insets, round } from '../layout.ts'\nimport { linear } from '../scales/linear.ts'\nimport { barPath } from '../shapes/bar.ts'\nimport { circlePath } from '../shapes/circle.ts'\nimport { areaPath, type Curve, linePath, type Point } from '../shapes/path.ts'\nimport { h } from '../vnode.ts'\nimport { domainOf, type Label, labelKey } from './cartesian.ts'\nimport { cleanData, label, numbers } from './clean.ts'\n\nexport interface SparklineOptions {\n /** The values; `null` leaves a gap. */\n data: readonly (number | null | undefined)[]\n /** Labels for the tooltip, one per value (e.g. dates). */\n labels?: readonly Label[]\n /** Name shown in the tooltip. Defaults to `'Value'`. */\n name?: string\n /**\n * `'line'` (default), `'area'`, `'bar'`, or `'tristate'`: only the sign\n * counts, as a full bar up (win), down (loss) or a tick on the middle (draw).\n */\n variant?: 'line' | 'area' | 'bar' | 'tristate'\n /** Interpolation for lines and areas. Defaults to `'monotone'`. */\n curve?: Curve\n /** Dot on the last value. Defaults to `'last'`. */\n point?: 'last' | 'none'\n /** Mark the minimum and maximum values. */\n markers?: 'minmax' | 'none'\n /** Dot radius in pixels. Defaults to `3`. */\n pointRadius?: number\n /** Include zero in the value range. Defaults to `true` for areas and bars, `false` for lines. */\n zero?: boolean\n /** Format of values in the tooltip. */\n format?: NumberFormat\n /** Extra space around the plot, in pixels. */\n padding?: InsetsInput\n}\n\nfunction renderSparkline(options: SparklineOptions, ctx: RenderContext) {\n const {\n variant = 'line',\n curve = 'monotone',\n point = 'last',\n markers = 'none',\n pointRadius = 3,\n name = 'Value',\n } = options\n const values = options.data.map((v) => (v == null || !Number.isFinite(v) ? null : v))\n // (No log option on sparklines, so finite is all that matters here.)\n const count = values.length\n const dots = point === 'last' || markers === 'minmax'\n // Room for the stroke and dots so nothing is clipped at the edges.\n const overhang = dots ? pointRadius + 2 : 2\n const pad = insets(options.padding, 0)\n const area = innerRect(ctx.width, ctx.height, {\n top: pad.top + overhang,\n right: pad.right + overhang,\n bottom: pad.bottom + overhang,\n left: pad.left + overhang,\n })\n const tristate = variant === 'tristate'\n const zero = options.zero ?? variant !== 'line'\n // Tristate bars span half the height each way, whatever the magnitude.\n const domain: [number, number] = tristate ? [-1, 1] : domainOf(values, { nice: false }, zero, 2)\n\n const bars = variant === 'bar' || tristate\n const gap = 1\n const slot = count > 0 ? area.width / count : 0\n // Right to left, the values run from the right: value `i` takes the place of its mirror.\n const place = (i: number) => (ctx.rtl ? count - 1 - i : i)\n const xAt = (i: number) =>\n bars\n ? area.x + slot * place(i) + slot / 2\n : area.x + (count > 1 ? (area.width * place(i)) / (count - 1) : area.width / 2)\n const y = linear(domain, [area.y + area.height, area.y])\n const baseline = y(Math.min(Math.max(0, domain[0]), domain[1]))\n const points: Point[] = values.map((v, i) => (v === null ? null : [xAt(i), y(v)]))\n\n const format = formatNumber(options.format, ctx.locale)\n const labelOf = (i: number) => {\n const label = options.labels?.[i]\n return label === undefined ? '' : String(label)\n }\n // Where a value is drawn: a tristate bar ends at its sign, not its magnitude.\n const yOf = (v: number) => y(tristate ? Math.sign(v) : v)\n const hitFor = (i: number): Hit | null => {\n const value = values[i]\n if (value === undefined) return null\n const px = xAt(i)\n const item: HitItem = {\n name,\n seriesIndex: 0,\n value,\n text: value === null ? '–' : format(value),\n x: px,\n y: value === null ? null : yOf(value),\n }\n const hit: Hit = {\n index: i,\n label: labelKey(options.labels?.[i] ?? i + 1),\n title: labelOf(i),\n x: px,\n area,\n items: [item],\n }\n if (value !== null) hit.mark = { d: circlePath(pointRadius + 3), x: px, y: yOf(value) }\n return hit\n }\n const interaction: Interaction = {\n count,\n reversed: ctx.rtl === true,\n hitIndex: (i) => hitFor(i),\n hitTest(px, py) {\n if (count === 0 || py < area.y - overhang || py > area.y + area.height + overhang) return null\n const i = bars\n ? Math.floor((px - area.x) / slot)\n : Math.round(((px - area.x) / Math.max(1, area.width)) * (count - 1))\n return hitFor(place(Math.max(0, Math.min(count - 1, i))))\n },\n }\n ctx.onHitTest(interaction)\n\n const marks = []\n if (tristate) {\n const width = Math.max(1, slot - gap)\n marks.push(\n h('line', {\n class: 'tc-sparkline-zero',\n x1: area.x,\n x2: area.x + area.width,\n y1: round(baseline),\n y2: round(baseline),\n }),\n )\n values.forEach((v, i) => {\n if (v === null) return\n const sign = Math.sign(v)\n // A draw is a short tick centered on the middle line.\n const tick = Math.min(2, area.height / 2)\n const [from, to] =\n sign === 0 ? [baseline + tick / 2, baseline - tick / 2] : [baseline, y(sign)]\n marks.push(\n h('path', {\n key: i,\n class: [\n 'tc-bar',\n sign < 0 && 'tc-bar-negative',\n sign < 0 ? 'tc-tristate-loss' : sign > 0 ? 'tc-tristate-win' : 'tc-tristate-draw',\n ],\n d: barPath(xAt(i) - width / 2, width, from, to, sign === 0 ? 0 : Math.min(2, width / 2)),\n }),\n )\n })\n } else if (bars) {\n const width = Math.max(1, slot - gap)\n values.forEach((v, i) => {\n if (v === null) return\n marks.push(\n h('path', {\n key: i,\n class: ['tc-bar', v < 0 && 'tc-bar-negative'],\n d: barPath(xAt(i) - width / 2, width, baseline, y(v), Math.min(2, width / 2)),\n }),\n )\n })\n } else {\n if (variant === 'area') {\n marks.push(\n h('path', {\n class: 'tc-area tc-area-gradient',\n d: areaPath(points, baseline, { curve }),\n mask: `url(#${ctx.id}-fade)`,\n }),\n )\n }\n marks.push(h('path', { class: 'tc-line', d: linePath(points, { curve }) }))\n }\n\n const dotAt = (i: number, cls: string) => {\n const v = values[i]\n return v == null\n ? null\n : h('circle', {\n key: `${cls}-${i}`,\n class: ['tc-point', cls],\n cx: round(xAt(i)),\n cy: round(y(v)),\n r: pointRadius,\n })\n }\n const extremes = []\n if (markers === 'minmax') {\n let min = -1\n let max = -1\n values.forEach((v, i) => {\n if (v === null) return\n if (min === -1 || v < (values[min] as number)) min = i\n if (max === -1 || v > (values[max] as number)) max = i\n })\n if (min !== -1) extremes.push(dotAt(min, 'tc-point-min'))\n if (max !== -1 && max !== min) extremes.push(dotAt(max, 'tc-point-max'))\n }\n let last = -1\n if (point === 'last') {\n for (let i = count - 1; i >= 0; i--) {\n if (values[i] !== null) {\n last = i\n break\n }\n }\n }\n\n return [\n variant === 'area' && h('defs', null, fadeMask(`${ctx.id}-fade`)),\n h(\n 'g',\n { class: 'tc-series tc-series-1 tc-sparkline' },\n marks,\n extremes,\n last !== -1 && !bars && dotAt(last, 'tc-point-last'),\n ),\n ]\n}\n\n/**\n * Sparkline: a tiny line, area or bar chart without axes, for stat tiles.\n *\n * ```ts\n * new Chart('#el', { type: sparkline, data: [3, 5, 4, 7, 6], height: 40 })\n * ```\n */\nexport const sparkline: ChartType<SparklineOptions> = {\n name: 'sparkline',\n // The labels too: they come from outside like the values.\n clean: (options) => ({\n ...cleanData(numbers)(options),\n labels: Array.isArray(options.labels) ? options.labels.map(label) : undefined,\n }),\n render: renderSparkline,\n // Decorative by default: opt in with `keyboard: true`.\n keyboard: false,\n}\n"],"mappings":";;;;;;;;;AAyCA,SAAS,gBAAgB,SAA2B,KAAoB;CACtE,MAAM,EACJ,UAAU,QACV,QAAQ,YACR,QAAQ,QACR,UAAU,QACV,cAAc,GACd,OAAO,YACL;CACJ,MAAM,SAAS,QAAQ,KAAK,KAAK,MAAO,KAAK,QAAQ,CAAC,OAAO,SAAS,CAAC,IAAI,OAAO,CAAE;CAEpF,MAAM,QAAQ,OAAO;CAGrB,MAAM,WAFO,UAAU,UAAU,YAAY,WAErB,cAAc,IAAI;CAC1C,MAAM,MAAM,OAAO,QAAQ,SAAS,CAAC;CACrC,MAAM,OAAO,UAAU,IAAI,OAAO,IAAI,QAAQ;EAC5C,KAAK,IAAI,MAAM;EACf,OAAO,IAAI,QAAQ;EACnB,QAAQ,IAAI,SAAS;EACrB,MAAM,IAAI,OAAO;CACnB,CAAC;CACD,MAAM,WAAW,YAAY;CAC7B,MAAM,OAAO,QAAQ,QAAQ,YAAY;CAEzC,MAAM,SAA2B,WAAW,CAAC,IAAI,CAAC,IAAI,SAAS,QAAQ,EAAE,MAAM,MAAM,GAAG,MAAM,CAAC;CAE/F,MAAM,OAAO,YAAY,SAAS;CAClC,MAAM,MAAM;CACZ,MAAM,OAAO,QAAQ,IAAI,KAAK,QAAQ,QAAQ;CAE9C,MAAM,SAAS,MAAe,IAAI,MAAM,QAAQ,IAAI,IAAI;CACxD,MAAM,OAAO,MACX,OACI,KAAK,IAAI,OAAO,MAAM,CAAC,IAAI,OAAO,IAClC,KAAK,KAAK,QAAQ,IAAK,KAAK,QAAQ,MAAM,CAAC,KAAM,QAAQ,KAAK,KAAK,QAAQ;CACjF,MAAM,IAAI,OAAO,QAAQ,CAAC,KAAK,IAAI,KAAK,QAAQ,KAAK,CAAC,CAAC;CACvD,MAAM,WAAW,EAAE,KAAK,IA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,EAAE,OAAO,qCAAqC,GAC9C,OACA,UACA,SAAS,MAAM,CAAC,QAAQ,MAAM,MAAM,eAAe,CACrD,CACF;AACF;;;;;;;;AASA,MAAa,YAAyC;CACpD,MAAM;CAEN,QAAQ,aAAa;EACnB,GAAG,UAAU,OAAO,CAAC,CAAC,OAAO;EAC7B,QAAQ,MAAM,QAAQ,QAAQ,MAAM,IAAI,QAAQ,OAAO,IAAI,KAAK,IAAI,KAAA;CACtE;CACA,QAAQ;CAER,UAAU;AACZ"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"treemap-BWpEUlDh.cjs","names":["keyOf","estimateTextWidth","innerRect","insets","formatNumber","getNumberFormat","rectPath","h","groupAttrs","round","list","isRecord","named","finite","cleanData","legendItems"],"sources":["../src/charts/treemap.ts"],"sourcesContent":["import type { DataTable } from '../a11y.ts'\nimport type { ChartType, RenderContext } from '../chart.ts'\nimport { formatNumber, getNumberFormat, type NumberFormat } from '../format.ts'\nimport type { Hit, HitItem, Interaction } from '../interaction.ts'\nimport { estimateTextWidth, type InsetsInput, innerRect, insets, round } from '../layout.ts'\nimport { rectPath } from '../shapes/rect.ts'\nimport { type ChildInput, type ClassValue, h } from '../vnode.ts'\nimport { cleanData, finite, isRecord, list, named } from './clean.ts'\nimport { groupAttrs, keyOf, legendItems } from './named.ts'\n\n/** A tile of a treemap, or a group of them. */\nexport interface TreemapNode {\n name: string\n /** Size of the tile; a negative value is zero. A group is as large as its `children`. */\n value?: number\n /** Tiles (or groups) inside this one; they share its color. */\n children?: readonly TreemapNode[]\n /** Stable identity for keyed updates and legend toggles. Defaults to `name`. */\n id?: string\n /**\n * Custom color; overrides the palette slot via `--tc-series-color`.\n * Values that could inject CSS (`;`, quotes, `url()` …) are ignored, so colors from user data are safe.\n */\n color?: string\n /** Extra classes on the group (top level) or the tile. */\n class?: ClassValue\n /** Start hidden (top level; toggle it back from the legend). */\n hidden?: boolean\n}\n\nexport interface TreemapOptions {\n /** Tiles, or groups of tiles; each top-level entry takes a palette color and a legend entry. */\n data: readonly TreemapNode[]\n /** Space between tiles in pixels. Defaults to `2`. */\n gap?: number\n /** Corner radius of the tiles. Defaults to `3`. */\n radius?: number\n /** Names (and values, where they fit) written in the tiles. Defaults to `true`. */\n labels?: boolean\n /** Format of the values (tiles, tooltip, table). */\n format?: NumberFormat\n /** Extra space around the chart, in pixels. */\n padding?: InsetsInput\n}\n\n/** Levels of nesting read from the data, and the most nodes: enough for any chart, few enough to draw. */\nconst MAX_DEPTH = 8\nconst MAX_NODES = 5000\n\n/** Space between a tile's edge and its text. */\nconst INSET = 6\n\n/** A node with its size worked out. */\ninterface Sized {\n node: TreemapNode\n value: number\n children?: Sized[]\n}\n\ninterface Tile {\n node: TreemapNode\n key: string\n /** Position of the top-level ancestor in `data` (the color slot). */\n top: number\n /** Names of the ancestors, outermost first. */\n trail: readonly string[]\n value: number\n x: number\n y: number\n width: number\n height: number\n}\n\nfunction sized(nodes: readonly TreemapNode[]): Sized[] {\n return nodes.map((node) => {\n if (node.children?.length) {\n const children = sized(node.children)\n return { node, children, value: children.reduce((sum, child) => sum + child.value, 0) }\n }\n return { node, value: Math.max(0, node.value ?? 0) }\n })\n}\n\n/** The top-level entries with their sizes and color slots, without the hidden ones. */\nfunction visible(options: TreemapOptions, hidden: ReadonlySet<string>) {\n return sized(options.data)\n .map((entry, index) => ({ entry, index }))\n .filter(({ entry }) => !hidden.has(keyOf(entry.node)))\n}\n\n/**\n * Squarified layout (Bruls, Huizing, van Wijk): `items`, largest first, fill\n * the rectangle in rows along its shorter side, each row closed as soon as\n * another item would make its tiles less square.\n */\nfunction squarify(\n items: readonly Sized[],\n x: number,\n y: number,\n w: number,\n hgt: number,\n place: (item: Sized, x: number, y: number, w: number, hgt: number) => void,\n): void {\n const sorted = items.filter((item) => item.value > 0).sort((a, b) => b.value - a.value)\n let left = sorted.reduce((sum, item) => sum + item.value, 0)\n let i = 0\n while (i < sorted.length && w > 0 && hgt > 0) {\n const short = Math.min(w, hgt)\n // Pixels of area per unit of value in what is left of the rectangle.\n const k = (w * hgt) / left\n const largest = (sorted[i] as Sized).value\n let sum = 0\n let best = Number.POSITIVE_INFINITY\n let j = i\n for (; j < sorted.length; j++) {\n const next = sum + (sorted[j] as Sized).value\n // Thickness of the row squared: its worst tile is the largest or the smallest.\n const t2 = ((next * k) / short) ** 2\n const worst = Math.max(t2 / ((sorted[j] as Sized).value * k), (largest * k) / t2)\n if (worst > best) break\n best = worst\n sum = next\n }\n const thickness = (sum * k) / short\n let offset = 0\n for (; i < j; i++) {\n const item = sorted[i] as Sized\n const length = (item.value * k) / thickness\n if (w >= hgt) place(item, x, y + offset, thickness, length)\n else place(item, x + offset, y, length, thickness)\n offset += length\n }\n if (w >= hgt) {\n x += thickness\n w -= thickness\n } else {\n y += thickness\n hgt -= thickness\n }\n left -= sum\n }\n}\n\n/** Half gaps left around a tile on its left, top, right and bottom side. */\ntype Edges = readonly [number, number, number, number]\n\n/**\n * The tiles of `items` in a rectangle, groups laid out inside their own.\n * The gap is cut from the tiles after they are placed, so it does not change\n * their arrangement: half of it on every side (a whole one between any two\n * neighbors), none at the edge of the chart. `edges` are the half gaps of\n * the rectangle itself.\n */\nfunction layout(\n items: readonly Sized[],\n x: number,\n y: number,\n w: number,\n hgt: number,\n gap: number,\n out: Tile[],\n edges: Edges,\n top?: { index: number; key: string; trail: readonly string[] },\n slots?: readonly number[],\n): void {\n squarify(items, x, y, w, hgt, (item, tx, ty, tw, th) => {\n const index = top?.index ?? (slots?.[items.indexOf(item)] as number)\n const key = top ? `${top.key}/${keyOf(item.node)}` : keyOf(item.node)\n const trail = top?.trail ?? []\n // A side on the border of the rectangle takes its half gap (none at the chart's edge), the others one.\n const near = 0.01\n const sides: Edges = [\n tx - x < near ? edges[0] : 1,\n ty - y < near ? edges[1] : 1,\n x + w - tx - tw < near ? edges[2] : 1,\n y + hgt - ty - th < near ? edges[3] : 1,\n ]\n if (item.children) {\n layout(item.children, tx, ty, tw, th, gap, out, sides, {\n index,\n key,\n trail: [...trail, item.node.name],\n })\n } else {\n const half = gap / 2\n out.push({\n node: item.node,\n key,\n top: index,\n trail,\n value: item.value,\n x: tx + sides[0] * half,\n y: ty + sides[1] * half,\n width: Math.max(0, tw - (sides[0] + sides[2]) * half),\n height: Math.max(0, th - (sides[1] + sides[3]) * half),\n })\n }\n })\n}\n\n/** `text` cut to `width` pixels with an ellipsis, or `''` when not even a few letters fit. */\nfunction fit(text: string, width: number, fontSize: number): string {\n if (estimateTextWidth(text, fontSize) <= width) return text\n const chars = [...text]\n while (chars.length > 2) {\n chars.pop()\n const cut = `${chars.join('').trimEnd()}…`\n if (estimateTextWidth(cut, fontSize) <= width) return cut\n }\n return ''\n}\n\nfunction renderTreemap(options: TreemapOptions, ctx: RenderContext): ChildInput {\n const { width, height, fontSize, locale } = ctx\n const gap = Math.max(0, options.gap ?? 2)\n const radius = Math.max(0, options.radius ?? 3)\n const area = innerRect(width, height, insets(options.padding, 0))\n const entries = visible(options, ctx.hidden)\n const total = entries.reduce((sum, { entry }) => sum + entry.value, 0)\n\n const tiles: Tile[] = []\n layout(\n entries.map(({ entry }) => entry),\n area.x,\n area.y,\n area.width,\n area.height,\n gap,\n tiles,\n [0, 0, 0, 0],\n undefined,\n entries.map(({ index }) => index),\n )\n\n const value = formatNumber(options.format, locale)\n const share = getNumberFormat(locale, { style: 'percent', maximumFractionDigits: 1 })\n const hitFor = (tile: Tile, index: number): Hit => {\n const x = tile.x + tile.width / 2\n const item: HitItem = {\n name: tile.node.name,\n seriesIndex: tile.top,\n value: tile.value,\n text: `${value(tile.value)} (${share.format(total > 0 ? tile.value / total : 0)})`,\n x,\n y: tile.y + tile.height / 2,\n }\n const color = tile.node.color ?? options.data[tile.top]?.color\n if (color) item.color = color\n return {\n index,\n label: [...tile.trail, tile.node.name].join(' › '),\n title: tile.trail.join(' › '),\n x,\n area,\n items: [item],\n seriesIndex: tile.top,\n // A ring just inside the hovered tile.\n mark: {\n d: rectPath(tile.x + 1, tile.y + 1, tile.width - 2, tile.height - 2, radius - 1),\n x: 0,\n y: 0,\n },\n }\n }\n\n const interaction: Interaction = {\n count: tiles.length,\n hitIndex: (index) => {\n const tile = tiles[index]\n return tile ? hitFor(tile, index) : null\n },\n hitTest(px, py) {\n const index = tiles.findIndex(\n (tile) =>\n px >= tile.x - gap / 2 &&\n px <= tile.x + tile.width + gap / 2 &&\n py >= tile.y - gap / 2 &&\n py <= tile.y + tile.height + gap / 2,\n )\n return index < 0 ? null : hitFor(tiles[index] as Tile, index)\n },\n }\n ctx.onHitTest(interaction)\n\n const groups = entries.map(({ entry, index }) =>\n h(\n 'g',\n groupAttrs(entry.node, index),\n tiles\n .filter((tile) => tile.top === index)\n .map((tile) =>\n h('rect', {\n key: tile.key,\n class: ['tc-tile', tile.trail.length > 0 && tile.node.class],\n x: round(tile.x),\n y: round(tile.y),\n width: round(tile.width),\n height: round(tile.height),\n rx: round(Math.min(radius, tile.width / 2, tile.height / 2)),\n // A tile inside a group may have a color of its own.\n style: tile.trail.length > 0 ? { '--tc-series-color': tile.node.color } : undefined,\n }),\n ),\n ),\n )\n\n // Names where a few letters fit, values below where there is a second line.\n const line = fontSize * 1.3\n const labels =\n options.labels !== false &&\n tiles.flatMap((tile) => {\n const room = tile.width - INSET * 2\n const name = tile.height >= line + INSET ? fit(tile.node.name, room, fontSize) : ''\n if (!name) return []\n const text = value(tile.value)\n const x = round(tile.x + INSET)\n const y = tile.y + INSET + fontSize * 0.85\n return [\n h('text', { key: tile.key, class: 'tc-treemap-label', x, y: round(y) }, name),\n tile.height >= line * 2 + INSET * 1.5 &&\n estimateTextWidth(text, fontSize) <= room &&\n h(\n 'text',\n {\n key: `${tile.key}/value`,\n class: 'tc-treemap-label tc-treemap-value',\n x,\n y: round(y + line),\n },\n text,\n ),\n ]\n })\n\n return [\n h('g', { class: 'tc-treemap-tiles' }, groups),\n labels && h('g', { class: 'tc-treemap-labels', 'aria-hidden': 'true' }, labels),\n ]\n}\n\nfunction treemapTable(options: TreemapOptions, ctx: RenderContext, limit: number): DataTable {\n const entries = visible(options, ctx.hidden)\n const total = entries.reduce((sum, { entry }) => sum + entry.value, 0)\n const value = formatNumber(options.format, ctx.locale)\n const share = getNumberFormat(ctx.locale, { style: 'percent', maximumFractionDigits: 1 })\n const rows: string[][] = []\n const walk = (items: readonly Sized[], trail: readonly string[]) => {\n for (const item of items) {\n const path = [...trail, item.node.name]\n if (item.children) walk(item.children, path)\n else {\n rows.push([\n path.join(' › '),\n value(item.value),\n share.format(total > 0 ? item.value / total : 0),\n ])\n }\n }\n }\n walk(\n entries.map(({ entry }) => entry),\n [],\n )\n const table: DataTable = { columns: ['', 'Value', 'Share'], rows }\n if (rows.length > limit) {\n table.rows = rows.slice(0, limit)\n table.total = rows.length\n }\n return table\n}\n\n/** Nodes with text for names and finite values, at most `MAX_DEPTH` deep and `MAX_NODES` in all. */\nfunction cleanNodes(data: unknown, depth = 0, budget = { left: MAX_NODES }): TreemapNode[] {\n const nodes: TreemapNode[] = []\n for (const r of list(data)) {\n if (!isRecord(r) || budget.left <= 0) continue\n budget.left--\n const children =\n depth < MAX_DEPTH && Array.isArray(r.children)\n ? cleanNodes(r.children, depth + 1, budget)\n : undefined\n nodes.push({ ...named(r), value: finite(r.value) ?? 0, children } as unknown as TreemapNode)\n }\n return nodes\n}\n\n/**\n * Treemap: parts of a whole as tiles, each as large as its value, laid out\n * as close to squares as they go with the largest in the top left corner.\n * Entries with `children` are groups: their tiles stay together and share\n * the group's color.\n *\n * ```ts\n * new Chart('#el', {\n * type: treemap,\n * data: [\n * { name: 'Search', value: 42 },\n * { name: 'Social', children: [{ name: 'Video', value: 18 }, { name: 'Posts', value: 9 }] },\n * ],\n * })\n * ```\n */\nexport const treemap: ChartType<TreemapOptions> = {\n name: 'treemap',\n clean: cleanData((data) => cleanNodes(data)),\n render: renderTreemap,\n legend: (options) => legendItems(options.data),\n table: treemapTable,\n}\n"],"mappings":";;;;;;;;AA8CA,MAAM,YAAY;AAClB,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,GAAkB;CACzF,MAAM,QAAuB,CAAC;CAC9B,KAAK,MAAM,KAAKK,cAAAA,KAAK,IAAI,GAAG;EAC1B,IAAI,CAACC,cAAAA,SAAS,CAAC,KAAK,OAAO,QAAQ,GAAG;EACtC,OAAO;EACP,MAAM,WACJ,QAAQ,aAAa,MAAM,QAAQ,EAAE,QAAQ,IACzC,WAAW,EAAE,UAAU,QAAQ,GAAG,MAAM,IACxC,KAAA;EACN,MAAM,KAAK;GAAE,GAAGC,cAAAA,MAAM,CAAC;GAAG,OAAOC,cAAAA,OAAO,EAAE,KAAK,KAAK;GAAG;EAAS,CAA2B;CAC7F;CACA,OAAO;AACT;;;;;;;;;;;;;;;;;AAkBA,MAAa,UAAqC;CAChD,MAAM;CACN,OAAOC,cAAAA,WAAW,SAAS,WAAW,IAAI,CAAC;CAC3C,QAAQ;CACR,SAAS,YAAYC,cAAAA,YAAY,QAAQ,IAAI;CAC7C,OAAO;AACT"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"treemap-CQdavQ9u.js","names":[],"sources":["../src/charts/treemap.ts"],"sourcesContent":["import type { DataTable } from '../a11y.ts'\nimport type { ChartType, RenderContext } from '../chart.ts'\nimport { formatNumber, getNumberFormat, type NumberFormat } from '../format.ts'\nimport type { Hit, HitItem, Interaction } from '../interaction.ts'\nimport { estimateTextWidth, type InsetsInput, innerRect, insets, round } from '../layout.ts'\nimport { rectPath } from '../shapes/rect.ts'\nimport { type ChildInput, type ClassValue, h } from '../vnode.ts'\nimport { cleanData, finite, isRecord, list, named } from './clean.ts'\nimport { groupAttrs, keyOf, legendItems } from './named.ts'\n\n/** A tile of a treemap, or a group of them. */\nexport interface TreemapNode {\n name: string\n /** Size of the tile; a negative value is zero. A group is as large as its `children`. */\n value?: number\n /** Tiles (or groups) inside this one; they share its color. */\n children?: readonly TreemapNode[]\n /** Stable identity for keyed updates and legend toggles. Defaults to `name`. */\n id?: string\n /**\n * Custom color; overrides the palette slot via `--tc-series-color`.\n * Values that could inject CSS (`;`, quotes, `url()` …) are ignored, so colors from user data are safe.\n */\n color?: string\n /** Extra classes on the group (top level) or the tile. */\n class?: ClassValue\n /** Start hidden (top level; toggle it back from the legend). */\n hidden?: boolean\n}\n\nexport interface TreemapOptions {\n /** Tiles, or groups of tiles; each top-level entry takes a palette color and a legend entry. */\n data: readonly TreemapNode[]\n /** Space between tiles in pixels. Defaults to `2`. */\n gap?: number\n /** Corner radius of the tiles. Defaults to `3`. */\n radius?: number\n /** Names (and values, where they fit) written in the tiles. Defaults to `true`. */\n labels?: boolean\n /** Format of the values (tiles, tooltip, table). */\n format?: NumberFormat\n /** Extra space around the chart, in pixels. */\n padding?: InsetsInput\n}\n\n/** Levels of nesting read from the data, and the most nodes: enough for any chart, few enough to draw. */\nconst MAX_DEPTH = 8\nconst MAX_NODES = 5000\n\n/** Space between a tile's edge and its text. */\nconst INSET = 6\n\n/** A node with its size worked out. */\ninterface Sized {\n node: TreemapNode\n value: number\n children?: Sized[]\n}\n\ninterface Tile {\n node: TreemapNode\n key: string\n /** Position of the top-level ancestor in `data` (the color slot). */\n top: number\n /** Names of the ancestors, outermost first. */\n trail: readonly string[]\n value: number\n x: number\n y: number\n width: number\n height: number\n}\n\nfunction sized(nodes: readonly TreemapNode[]): Sized[] {\n return nodes.map((node) => {\n if (node.children?.length) {\n const children = sized(node.children)\n return { node, children, value: children.reduce((sum, child) => sum + child.value, 0) }\n }\n return { node, value: Math.max(0, node.value ?? 0) }\n })\n}\n\n/** The top-level entries with their sizes and color slots, without the hidden ones. */\nfunction visible(options: TreemapOptions, hidden: ReadonlySet<string>) {\n return sized(options.data)\n .map((entry, index) => ({ entry, index }))\n .filter(({ entry }) => !hidden.has(keyOf(entry.node)))\n}\n\n/**\n * Squarified layout (Bruls, Huizing, van Wijk): `items`, largest first, fill\n * the rectangle in rows along its shorter side, each row closed as soon as\n * another item would make its tiles less square.\n */\nfunction squarify(\n items: readonly Sized[],\n x: number,\n y: number,\n w: number,\n hgt: number,\n place: (item: Sized, x: number, y: number, w: number, hgt: number) => void,\n): void {\n const sorted = items.filter((item) => item.value > 0).sort((a, b) => b.value - a.value)\n let left = sorted.reduce((sum, item) => sum + item.value, 0)\n let i = 0\n while (i < sorted.length && w > 0 && hgt > 0) {\n const short = Math.min(w, hgt)\n // Pixels of area per unit of value in what is left of the rectangle.\n const k = (w * hgt) / left\n const largest = (sorted[i] as Sized).value\n let sum = 0\n let best = Number.POSITIVE_INFINITY\n let j = i\n for (; j < sorted.length; j++) {\n const next = sum + (sorted[j] as Sized).value\n // Thickness of the row squared: its worst tile is the largest or the smallest.\n const t2 = ((next * k) / short) ** 2\n const worst = Math.max(t2 / ((sorted[j] as Sized).value * k), (largest * k) / t2)\n if (worst > best) break\n best = worst\n sum = next\n }\n const thickness = (sum * k) / short\n let offset = 0\n for (; i < j; i++) {\n const item = sorted[i] as Sized\n const length = (item.value * k) / thickness\n if (w >= hgt) place(item, x, y + offset, thickness, length)\n else place(item, x + offset, y, length, thickness)\n offset += length\n }\n if (w >= hgt) {\n x += thickness\n w -= thickness\n } else {\n y += thickness\n hgt -= thickness\n }\n left -= sum\n }\n}\n\n/** Half gaps left around a tile on its left, top, right and bottom side. */\ntype Edges = readonly [number, number, number, number]\n\n/**\n * The tiles of `items` in a rectangle, groups laid out inside their own.\n * The gap is cut from the tiles after they are placed, so it does not change\n * their arrangement: half of it on every side (a whole one between any two\n * neighbors), none at the edge of the chart. `edges` are the half gaps of\n * the rectangle itself.\n */\nfunction layout(\n items: readonly Sized[],\n x: number,\n y: number,\n w: number,\n hgt: number,\n gap: number,\n out: Tile[],\n edges: Edges,\n top?: { index: number; key: string; trail: readonly string[] },\n slots?: readonly number[],\n): void {\n squarify(items, x, y, w, hgt, (item, tx, ty, tw, th) => {\n const index = top?.index ?? (slots?.[items.indexOf(item)] as number)\n const key = top ? `${top.key}/${keyOf(item.node)}` : keyOf(item.node)\n const trail = top?.trail ?? []\n // A side on the border of the rectangle takes its half gap (none at the chart's edge), the others one.\n const near = 0.01\n const sides: Edges = [\n tx - x < near ? edges[0] : 1,\n ty - y < near ? edges[1] : 1,\n x + w - tx - tw < near ? edges[2] : 1,\n y + hgt - ty - th < near ? edges[3] : 1,\n ]\n if (item.children) {\n layout(item.children, tx, ty, tw, th, gap, out, sides, {\n index,\n key,\n trail: [...trail, item.node.name],\n })\n } else {\n const half = gap / 2\n out.push({\n node: item.node,\n key,\n top: index,\n trail,\n value: item.value,\n x: tx + sides[0] * half,\n y: ty + sides[1] * half,\n width: Math.max(0, tw - (sides[0] + sides[2]) * half),\n height: Math.max(0, th - (sides[1] + sides[3]) * half),\n })\n }\n })\n}\n\n/** `text` cut to `width` pixels with an ellipsis, or `''` when not even a few letters fit. */\nfunction fit(text: string, width: number, fontSize: number): string {\n if (estimateTextWidth(text, fontSize) <= width) return text\n const chars = [...text]\n while (chars.length > 2) {\n chars.pop()\n const cut = `${chars.join('').trimEnd()}…`\n if (estimateTextWidth(cut, fontSize) <= width) return cut\n }\n return ''\n}\n\nfunction renderTreemap(options: TreemapOptions, ctx: RenderContext): ChildInput {\n const { width, height, fontSize, locale } = ctx\n const gap = Math.max(0, options.gap ?? 2)\n const radius = Math.max(0, options.radius ?? 3)\n const area = innerRect(width, height, insets(options.padding, 0))\n const entries = visible(options, ctx.hidden)\n const total = entries.reduce((sum, { entry }) => sum + entry.value, 0)\n\n const tiles: Tile[] = []\n layout(\n entries.map(({ entry }) => entry),\n area.x,\n area.y,\n area.width,\n area.height,\n gap,\n tiles,\n [0, 0, 0, 0],\n undefined,\n entries.map(({ index }) => index),\n )\n\n const value = formatNumber(options.format, locale)\n const share = getNumberFormat(locale, { style: 'percent', maximumFractionDigits: 1 })\n const hitFor = (tile: Tile, index: number): Hit => {\n const x = tile.x + tile.width / 2\n const item: HitItem = {\n name: tile.node.name,\n seriesIndex: tile.top,\n value: tile.value,\n text: `${value(tile.value)} (${share.format(total > 0 ? tile.value / total : 0)})`,\n x,\n y: tile.y + tile.height / 2,\n }\n const color = tile.node.color ?? options.data[tile.top]?.color\n if (color) item.color = color\n return {\n index,\n label: [...tile.trail, tile.node.name].join(' › '),\n title: tile.trail.join(' › '),\n x,\n area,\n items: [item],\n seriesIndex: tile.top,\n // A ring just inside the hovered tile.\n mark: {\n d: rectPath(tile.x + 1, tile.y + 1, tile.width - 2, tile.height - 2, radius - 1),\n x: 0,\n y: 0,\n },\n }\n }\n\n const interaction: Interaction = {\n count: tiles.length,\n hitIndex: (index) => {\n const tile = tiles[index]\n return tile ? hitFor(tile, index) : null\n },\n hitTest(px, py) {\n const index = tiles.findIndex(\n (tile) =>\n px >= tile.x - gap / 2 &&\n px <= tile.x + tile.width + gap / 2 &&\n py >= tile.y - gap / 2 &&\n py <= tile.y + tile.height + gap / 2,\n )\n return index < 0 ? null : hitFor(tiles[index] as Tile, index)\n },\n }\n ctx.onHitTest(interaction)\n\n const groups = entries.map(({ entry, index }) =>\n h(\n 'g',\n groupAttrs(entry.node, index),\n tiles\n .filter((tile) => tile.top === index)\n .map((tile) =>\n h('rect', {\n key: tile.key,\n class: ['tc-tile', tile.trail.length > 0 && tile.node.class],\n x: round(tile.x),\n y: round(tile.y),\n width: round(tile.width),\n height: round(tile.height),\n rx: round(Math.min(radius, tile.width / 2, tile.height / 2)),\n // A tile inside a group may have a color of its own.\n style: tile.trail.length > 0 ? { '--tc-series-color': tile.node.color } : undefined,\n }),\n ),\n ),\n )\n\n // Names where a few letters fit, values below where there is a second line.\n const line = fontSize * 1.3\n const labels =\n options.labels !== false &&\n tiles.flatMap((tile) => {\n const room = tile.width - INSET * 2\n const name = tile.height >= line + INSET ? fit(tile.node.name, room, fontSize) : ''\n if (!name) return []\n const text = value(tile.value)\n const x = round(tile.x + INSET)\n const y = tile.y + INSET + fontSize * 0.85\n return [\n h('text', { key: tile.key, class: 'tc-treemap-label', x, y: round(y) }, name),\n tile.height >= line * 2 + INSET * 1.5 &&\n estimateTextWidth(text, fontSize) <= room &&\n h(\n 'text',\n {\n key: `${tile.key}/value`,\n class: 'tc-treemap-label tc-treemap-value',\n x,\n y: round(y + line),\n },\n text,\n ),\n ]\n })\n\n return [\n h('g', { class: 'tc-treemap-tiles' }, groups),\n labels && h('g', { class: 'tc-treemap-labels', 'aria-hidden': 'true' }, labels),\n ]\n}\n\nfunction treemapTable(options: TreemapOptions, ctx: RenderContext, limit: number): DataTable {\n const entries = visible(options, ctx.hidden)\n const total = entries.reduce((sum, { entry }) => sum + entry.value, 0)\n const value = formatNumber(options.format, ctx.locale)\n const share = getNumberFormat(ctx.locale, { style: 'percent', maximumFractionDigits: 1 })\n const rows: string[][] = []\n const walk = (items: readonly Sized[], trail: readonly string[]) => {\n for (const item of items) {\n const path = [...trail, item.node.name]\n if (item.children) walk(item.children, path)\n else {\n rows.push([\n path.join(' › '),\n value(item.value),\n share.format(total > 0 ? item.value / total : 0),\n ])\n }\n }\n }\n walk(\n entries.map(({ entry }) => entry),\n [],\n )\n const table: DataTable = { columns: ['', 'Value', 'Share'], rows }\n if (rows.length > limit) {\n table.rows = rows.slice(0, limit)\n table.total = rows.length\n }\n return table\n}\n\n/** Nodes with text for names and finite values, at most `MAX_DEPTH` deep and `MAX_NODES` in all. */\nfunction cleanNodes(data: unknown, depth = 0, budget = { left: MAX_NODES }): TreemapNode[] {\n const nodes: TreemapNode[] = []\n for (const r of list(data)) {\n if (!isRecord(r) || budget.left <= 0) continue\n budget.left--\n const children =\n depth < MAX_DEPTH && Array.isArray(r.children)\n ? cleanNodes(r.children, depth + 1, budget)\n : undefined\n nodes.push({ ...named(r), value: finite(r.value) ?? 0, children } as unknown as TreemapNode)\n }\n return nodes\n}\n\n/**\n * Treemap: parts of a whole as tiles, each as large as its value, laid out\n * as close to squares as they go with the largest in the top left corner.\n * Entries with `children` are groups: their tiles stay together and share\n * the group's color.\n *\n * ```ts\n * new Chart('#el', {\n * type: treemap,\n * data: [\n * { name: 'Search', value: 42 },\n * { name: 'Social', children: [{ name: 'Video', value: 18 }, { name: 'Posts', value: 9 }] },\n * ],\n * })\n * ```\n */\nexport const treemap: ChartType<TreemapOptions> = {\n name: 'treemap',\n clean: cleanData((data) => cleanNodes(data)),\n render: renderTreemap,\n legend: (options) => legendItems(options.data),\n table: treemapTable,\n}\n"],"mappings":";;;;;;;;AA8CA,MAAM,YAAY;AAClB,MAAM,YAAY;;AAGlB,MAAM,QAAQ;AAuBd,SAAS,MAAM,OAAwC;CACrD,OAAO,MAAM,KAAK,SAAS;EACzB,IAAI,KAAK,UAAU,QAAQ;GACzB,MAAM,WAAW,MAAM,KAAK,QAAQ;GACpC,OAAO;IAAE;IAAM;IAAU,OAAO,SAAS,QAAQ,KAAK,UAAU,MAAM,MAAM,OAAO,CAAC;GAAE;EACxF;EACA,OAAO;GAAE;GAAM,OAAO,KAAK,IAAI,GAAG,KAAK,SAAS,CAAC;EAAE;CACrD,CAAC;AACH;;AAGA,SAAS,QAAQ,SAAyB,QAA6B;CACrE,OAAO,MAAM,QAAQ,IAAI,CAAC,CACvB,KAAK,OAAO,WAAW;EAAE;EAAO;CAAM,EAAE,CAAC,CACzC,QAAQ,EAAE,YAAY,CAAC,OAAO,IAAI,MAAM,MAAM,IAAI,CAAC,CAAC;AACzD;;;;;;AAOA,SAAS,SACP,OACA,GACA,GACA,GACA,KACA,OACM;CACN,MAAM,SAAS,MAAM,QAAQ,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,GAAG,MAAM,EAAE,QAAQ,EAAE,KAAK;CACtF,IAAI,OAAO,OAAO,QAAQ,KAAK,SAAS,MAAM,KAAK,OAAO,CAAC;CAC3D,IAAI,IAAI;CACR,OAAO,IAAI,OAAO,UAAU,IAAI,KAAK,MAAM,GAAG;EAC5C,MAAM,QAAQ,KAAK,IAAI,GAAG,GAAG;EAE7B,MAAM,IAAK,IAAI,MAAO;EACtB,MAAM,UAAW,OAAO,EAAE,CAAW;EACrC,IAAI,MAAM;EACV,IAAI,OAAO,OAAO;EAClB,IAAI,IAAI;EACR,OAAO,IAAI,OAAO,QAAQ,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AAM,KAAK,KAAK,IAAI,GAAG;EAC1B,IAAI,CAAC,SAAS,CAAC,KAAK,OAAO,QAAQ,GAAG;EACtC,OAAO;EACP,MAAM,WACJ,QAAQ,aAAa,MAAM,QAAQ,EAAE,QAAQ,IACzC,WAAW,EAAE,UAAU,QAAQ,GAAG,MAAM,IACxC,KAAA;EACN,MAAM,KAAK;GAAE,GAAG,MAAM,CAAC;GAAG,OAAO,OAAO,EAAE,KAAK,KAAK;GAAG;EAAS,CAA2B;CAC7F;CACA,OAAO;AACT;;;;;;;;;;;;;;;;;AAkBA,MAAa,UAAqC;CAChD,MAAM;CACN,OAAO,WAAW,SAAS,WAAW,IAAI,CAAC;CAC3C,QAAQ;CACR,SAAS,YAAY,YAAY,QAAQ,IAAI;CAC7C,OAAO;AACT"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"value-labels-BBuSi4i0.js","names":[],"sources":["../src/charts/value-labels.ts"],"sourcesContent":["/**\n * Value labels: the value written on each mark, for charts read at a\n * glance. They are worked out from the chart's interaction, so every type\n * gets them the same way: bars at their end (inside when there is no room\n * outside), stacked segments and heatmap cells in their middle, lines and\n * points above their point (the last one by default), slices in their\n * middle with their share. A label that does not fit its mark or the plot,\n * or that would cover another one, is left out: labels never overlap.\n */\nimport type { ChartConfig, RenderContext } from '../chart.ts'\nimport type { PostStep } from '../features.ts'\nimport { formatNumber, getNumberFormat, type NumberFormat } from '../format.ts'\nimport type { Hit, HitItem, Interaction } from '../interaction.ts'\nimport { estimateTextWidth, type Rect, round } from '../layout.ts'\nimport { h, type VNode } from '../vnode.ts'\n\nexport interface ValueLabelOptions {\n /** Format of the values. Defaults to the value axis format (slices: their share in percent). */\n format?: NumberFormat\n /** Which points of lines, areas and scatters get a label. Defaults to `'last'`. */\n points?: 'last' | 'all'\n}\n\n/** Space between a mark and its label, and around labels. */\nconst GAP = 4\n\ninterface Placed {\n key: string\n text: string\n x: number\n y: number\n inside: boolean\n box: Rect\n}\n\nconst overlaps = (a: Rect, b: Rect): boolean =>\n a.x < b.x + b.width && b.x < a.x + a.width && a.y < b.y + b.height && b.y < a.y + a.height\n\nconst contains = (outer: Rect, inner: Rect): boolean =>\n inner.x >= outer.x - 1 &&\n inner.y >= outer.y - 1 &&\n inner.x + inner.width <= outer.x + outer.width + 1 &&\n inner.y + inner.height <= outer.y + outer.height + 1\n\n/** The labels layer of a chart, or `null` when nothing gets one. */\nexport function valueLabels(\n config: ChartConfig<object>,\n interaction: Interaction,\n ctx: RenderContext,\n): VNode | null {\n const option = config.valueLabels\n const options: ValueLabelOptions = typeof option === 'object' ? option : {}\n const { fontSize, locale } = ctx\n // What the chart type says about its marks (slices, cells) and its number format.\n const spec = config.type.valueLabels\n const pie = spec?.marks === 'slice'\n const cell = spec?.marks === 'cell'\n const stacked = !!(config as { stacked?: unknown }).stacked\n const format = options.format\n ? formatNumber(options.format, locale)\n : pie\n ? (v: number) =>\n getNumberFormat(locale, { style: 'percent', maximumFractionDigits: 1 }).format(v)\n : spec?.format\n ? formatNumber(spec.format(config), locale)\n : undefined\n // Numbers have no descenders: one em is their height, with room to spare.\n const height = fontSize\n\n // Candidates in order of priority: every hit's items, and for points only the\n // last one of each series unless all are asked for.\n const items: [string, HitItem, Hit][] = []\n const last = new Map<number, number>()\n let total = 0\n for (let i = 0; i < interaction.count; i++) {\n const hit = interaction.hitIndex(i)\n for (const item of hit?.items ?? []) {\n if (item.value === null || item.y === null || !hit) continue\n total += Math.abs(item.value)\n if (!pie && !item.box && options.points !== 'all') last.set(item.seriesIndex, items.length)\n items.push([`${i}-${item.seriesIndex}`, item, hit])\n }\n }\n\n // Marks a label must not cover: every bar and cell but its own.\n const marks = items.flatMap(([, item]) => (item.box ? [item.box] : []))\n const placed: Placed[] = []\n items.forEach(([key, item, hit], n) => {\n const { area } = hit\n if (!pie && !item.box && options.points !== 'all' && last.get(item.seriesIndex) !== n) return\n const value = item.value as number\n const share = value / (total || 1)\n const text = format ? format(pie ? share : value) : item.text\n const width = estimateTextWidth(text, fontSize)\n const at = (x: number, y: number, inside: boolean): Placed => {\n // A point's label at the plot's edge (the last point) moves in.\n if (!item.box && !pie) {\n x = Math.max(area.x + width / 2 + 2, Math.min(x, area.x + area.width - width / 2 - 2))\n }\n return {\n key,\n text,\n x,\n y,\n inside,\n box: { x: x - width / 2 - 2, y: y - height / 2, width: width + 4, height },\n }\n }\n const y = item.y as number\n const candidates: Placed[] = []\n const { box } = item\n if (pie) {\n candidates.push(at(item.x, y, true))\n } else if (box) {\n const horizontal = hit.axis === 'y'\n const down = value < 0\n if (!stacked && !cell) {\n // Beyond the bar's end, then just inside it.\n const reach = (horizontal ? width / 2 : height / 2) + GAP\n const sign = down ? 1 : -1\n const along = y + sign * reach\n // Sideways, bars grow to the right, or to the left in a right-to-left chart.\n const side = ctx.rtl ? -sign : sign\n candidates.push(\n horizontal ? at(item.x - side * reach, y, false) : at(item.x, along, false),\n // A label wider than its bar may lean off a taller neighbour.\n ...(horizontal\n ? []\n : [\n at(box.x + width / 2 - 3, along, false),\n at(box.x + box.width - width / 2 + 3, along, false),\n ]),\n horizontal ? at(item.x + side * reach, y, true) : at(item.x, y - sign * reach, true),\n )\n } else {\n candidates.push(at(box.x + box.width / 2, box.y + box.height / 2, true))\n }\n } else {\n // Above the point, below it, or beside it (the end of a line, at the plot's edge).\n const side = width / 2 + GAP + 4\n candidates.push(\n at(item.x, y - height / 2 - GAP - 2, false),\n at(item.x, y + height / 2 + GAP + 2, false),\n at(item.x - side, y, false),\n at(item.x + side, y, false),\n )\n }\n // Labels may rise into the margin above the plot, not over the axes.\n const room = { ...area, y: 0, height: area.y + area.height }\n // Glyphs leave a little room at their sides (`slim`): a label may brush a neighbour.\n const fits = (p: Placed, slim = { ...p.box, x: p.box.x + 5, width: p.box.width - 10 }) =>\n contains(pie ? area : room, p.box) &&\n (!p.inside || !box || contains(box, p.box)) &&\n (!pie || sliceFits(item, area, share, p.box)) &&\n !placed.some((other) => overlaps(other.box, p.box)) &&\n !marks.some((mark) => mark !== box && overlaps(mark, slim))\n const spot = candidates.find((p) => fits(p))\n if (spot) placed.push(spot)\n })\n\n if (!placed.length) return null\n return h(\n 'g',\n { key: 'value-labels', class: 'tc-value-labels', 'aria-hidden': 'true' },\n placed.map((p) =>\n h(\n 'text',\n {\n key: p.key,\n class: ['tc-value-label', p.inside && 'tc-value-label-inside'],\n style: `transform:translate(${round(p.x)}px,${round(p.y)}px)`,\n 'text-anchor': 'middle',\n dy: '0.35em',\n },\n p.text,\n ),\n ),\n )\n}\n\n/**\n * Whether a label fits its slice: it sits at the slice's centroid, where the\n * slice is about its share of the circle wide and twice the distance to the\n * outer edge deep.\n */\nfunction sliceFits(item: HitItem, area: Rect, share: number, label: Rect): boolean {\n const outer = area.width / 2\n const radius = Math.hypot(item.x - area.x - outer, (item.y as number) - area.y - outer)\n const depth = 2 * (outer - radius)\n return label.width <= share * 2 * Math.PI * radius && label.height <= depth\n}\n\n/** The step that adds the labels over the content of charts with `valueLabels`. */\nexport const labelsStep: PostStep = (config, content, interaction, ctx) =>\n config.valueLabels && interaction ? [content, valueLabels(config, interaction, ctx)] : content\n"],"mappings":";;;;;AAwBA,MAAM,MAAM;AAWZ,MAAM,YAAY,GAAS,MACzB,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,IAAI,EAAE;AAEtF,MAAM,YAAY,OAAa,UAC7B,MAAM,KAAK,MAAM,IAAI,KACrB,MAAM,KAAK,MAAM,IAAI,KACrB,MAAM,IAAI,MAAM,SAAS,MAAM,IAAI,MAAM,QAAQ,KACjD,MAAM,IAAI,MAAM,UAAU,MAAM,IAAI,MAAM,SAAS;;AAGrD,SAAgB,YACd,QACA,aACA,KACc;CACd,MAAM,SAAS,OAAO;CACtB,MAAM,UAA6B,OAAO,WAAW,WAAW,SAAS,CAAC;CAC1E,MAAM,EAAE,UAAU,WAAW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,IAAI;CACN,GACA,EAAE,IACJ,CACF,CACF;AACF;;;;;;AAOA,SAAS,UAAU,MAAe,MAAY,OAAe,OAAsB;CACjF,MAAM,QAAQ,KAAK,QAAQ;CAC3B,MAAM,SAAS,KAAK,MAAM,KAAK,IAAI,KAAK,IAAI,OAAQ,KAAK,IAAe,KAAK,IAAI,KAAK;CACtF,MAAM,QAAQ,KAAK,QAAQ;CAC3B,OAAO,MAAM,SAAS,QAAQ,IAAI,KAAK,KAAK,UAAU,MAAM,UAAU;AACxE;;AAGA,MAAa,cAAwB,QAAQ,SAAS,aAAa,QACjE,OAAO,eAAe,cAAc,CAAC,SAAS,YAAY,QAAQ,aAAa,GAAG,CAAC,IAAI"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"value-labels-BV9keAuL.cjs","names":["formatNumber","getNumberFormat","estimateTextWidth","h","round"],"sources":["../src/charts/value-labels.ts"],"sourcesContent":["/**\n * Value labels: the value written on each mark, for charts read at a\n * glance. They are worked out from the chart's interaction, so every type\n * gets them the same way: bars at their end (inside when there is no room\n * outside), stacked segments and heatmap cells in their middle, lines and\n * points above their point (the last one by default), slices in their\n * middle with their share. A label that does not fit its mark or the plot,\n * or that would cover another one, is left out: labels never overlap.\n */\nimport type { ChartConfig, RenderContext } from '../chart.ts'\nimport type { PostStep } from '../features.ts'\nimport { formatNumber, getNumberFormat, type NumberFormat } from '../format.ts'\nimport type { Hit, HitItem, Interaction } from '../interaction.ts'\nimport { estimateTextWidth, type Rect, round } from '../layout.ts'\nimport { h, type VNode } from '../vnode.ts'\n\nexport interface ValueLabelOptions {\n /** Format of the values. Defaults to the value axis format (slices: their share in percent). */\n format?: NumberFormat\n /** Which points of lines, areas and scatters get a label. Defaults to `'last'`. */\n points?: 'last' | 'all'\n}\n\n/** Space between a mark and its label, and around labels. */\nconst GAP = 4\n\ninterface Placed {\n key: string\n text: string\n x: number\n y: number\n inside: boolean\n box: Rect\n}\n\nconst overlaps = (a: Rect, b: Rect): boolean =>\n a.x < b.x + b.width && b.x < a.x + a.width && a.y < b.y + b.height && b.y < a.y + a.height\n\nconst contains = (outer: Rect, inner: Rect): boolean =>\n inner.x >= outer.x - 1 &&\n inner.y >= outer.y - 1 &&\n inner.x + inner.width <= outer.x + outer.width + 1 &&\n inner.y + inner.height <= outer.y + outer.height + 1\n\n/** The labels layer of a chart, or `null` when nothing gets one. */\nexport function valueLabels(\n config: ChartConfig<object>,\n interaction: Interaction,\n ctx: RenderContext,\n): VNode | null {\n const option = config.valueLabels\n const options: ValueLabelOptions = typeof option === 'object' ? option : {}\n const { fontSize, locale } = ctx\n // What the chart type says about its marks (slices, cells) and its number format.\n const spec = config.type.valueLabels\n const pie = spec?.marks === 'slice'\n const cell = spec?.marks === 'cell'\n const stacked = !!(config as { stacked?: unknown }).stacked\n const format = options.format\n ? formatNumber(options.format, locale)\n : pie\n ? (v: number) =>\n getNumberFormat(locale, { style: 'percent', maximumFractionDigits: 1 }).format(v)\n : spec?.format\n ? formatNumber(spec.format(config), locale)\n : undefined\n // Numbers have no descenders: one em is their height, with room to spare.\n const height = fontSize\n\n // Candidates in order of priority: every hit's items, and for points only the\n // last one of each series unless all are asked for.\n const items: [string, HitItem, Hit][] = []\n const last = new Map<number, number>()\n let total = 0\n for (let i = 0; i < interaction.count; i++) {\n const hit = interaction.hitIndex(i)\n for (const item of hit?.items ?? []) {\n if (item.value === null || item.y === null || !hit) continue\n total += Math.abs(item.value)\n if (!pie && !item.box && options.points !== 'all') last.set(item.seriesIndex, items.length)\n items.push([`${i}-${item.seriesIndex}`, item, hit])\n }\n }\n\n // Marks a label must not cover: every bar and cell but its own.\n const marks = items.flatMap(([, item]) => (item.box ? [item.box] : []))\n const placed: Placed[] = []\n items.forEach(([key, item, hit], n) => {\n const { area } = hit\n if (!pie && !item.box && options.points !== 'all' && last.get(item.seriesIndex) !== n) return\n const value = item.value as number\n const share = value / (total || 1)\n const text = format ? format(pie ? share : value) : item.text\n const width = estimateTextWidth(text, fontSize)\n const at = (x: number, y: number, inside: boolean): Placed => {\n // A point's label at the plot's edge (the last point) moves in.\n if (!item.box && !pie) {\n x = Math.max(area.x + width / 2 + 2, Math.min(x, area.x + area.width - width / 2 - 2))\n }\n return {\n key,\n text,\n x,\n y,\n inside,\n box: { x: x - width / 2 - 2, y: y - height / 2, width: width + 4, height },\n }\n }\n const y = item.y as number\n const candidates: Placed[] = []\n const { box } = item\n if (pie) {\n candidates.push(at(item.x, y, true))\n } else if (box) {\n const horizontal = hit.axis === 'y'\n const down = value < 0\n if (!stacked && !cell) {\n // Beyond the bar's end, then just inside it.\n const reach = (horizontal ? width / 2 : height / 2) + GAP\n const sign = down ? 1 : -1\n const along = y + sign * reach\n // Sideways, bars grow to the right, or to the left in a right-to-left chart.\n const side = ctx.rtl ? -sign : sign\n candidates.push(\n horizontal ? at(item.x - side * reach, y, false) : at(item.x, along, false),\n // A label wider than its bar may lean off a taller neighbour.\n ...(horizontal\n ? []\n : [\n at(box.x + width / 2 - 3, along, false),\n at(box.x + box.width - width / 2 + 3, along, false),\n ]),\n horizontal ? at(item.x + side * reach, y, true) : at(item.x, y - sign * reach, true),\n )\n } else {\n candidates.push(at(box.x + box.width / 2, box.y + box.height / 2, true))\n }\n } else {\n // Above the point, below it, or beside it (the end of a line, at the plot's edge).\n const side = width / 2 + GAP + 4\n candidates.push(\n at(item.x, y - height / 2 - GAP - 2, false),\n at(item.x, y + height / 2 + GAP + 2, false),\n at(item.x - side, y, false),\n at(item.x + side, y, false),\n )\n }\n // Labels may rise into the margin above the plot, not over the axes.\n const room = { ...area, y: 0, height: area.y + area.height }\n // Glyphs leave a little room at their sides (`slim`): a label may brush a neighbour.\n const fits = (p: Placed, slim = { ...p.box, x: p.box.x + 5, width: p.box.width - 10 }) =>\n contains(pie ? area : room, p.box) &&\n (!p.inside || !box || contains(box, p.box)) &&\n (!pie || sliceFits(item, area, share, p.box)) &&\n !placed.some((other) => overlaps(other.box, p.box)) &&\n !marks.some((mark) => mark !== box && overlaps(mark, slim))\n const spot = candidates.find((p) => fits(p))\n if (spot) placed.push(spot)\n })\n\n if (!placed.length) return null\n return h(\n 'g',\n { key: 'value-labels', class: 'tc-value-labels', 'aria-hidden': 'true' },\n placed.map((p) =>\n h(\n 'text',\n {\n key: p.key,\n class: ['tc-value-label', p.inside && 'tc-value-label-inside'],\n style: `transform:translate(${round(p.x)}px,${round(p.y)}px)`,\n 'text-anchor': 'middle',\n dy: '0.35em',\n },\n p.text,\n ),\n ),\n )\n}\n\n/**\n * Whether a label fits its slice: it sits at the slice's centroid, where the\n * slice is about its share of the circle wide and twice the distance to the\n * outer edge deep.\n */\nfunction sliceFits(item: HitItem, area: Rect, share: number, label: Rect): boolean {\n const outer = area.width / 2\n const radius = Math.hypot(item.x - area.x - outer, (item.y as number) - area.y - outer)\n const depth = 2 * (outer - radius)\n return label.width <= share * 2 * Math.PI * radius && label.height <= depth\n}\n\n/** The step that adds the labels over the content of charts with `valueLabels`. */\nexport const labelsStep: PostStep = (config, content, interaction, ctx) =>\n config.valueLabels && interaction ? [content, valueLabels(config, interaction, ctx)] : content\n"],"mappings":";;;;;AAwBA,MAAM,MAAM;AAWZ,MAAM,YAAY,GAAS,MACzB,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,IAAI,EAAE;AAEtF,MAAM,YAAY,OAAa,UAC7B,MAAM,KAAK,MAAM,IAAI,KACrB,MAAM,KAAK,MAAM,IAAI,KACrB,MAAM,IAAI,MAAM,SAAS,MAAM,IAAI,MAAM,QAAQ,KACjD,MAAM,IAAI,MAAM,UAAU,MAAM,IAAI,MAAM,SAAS;;AAGrD,SAAgB,YACd,QACA,aACA,KACc;CACd,MAAM,SAAS,OAAO;CACtB,MAAM,UAA6B,OAAO,WAAW,WAAW,SAAS,CAAC;CAC1E,MAAM,EAAE,UAAU,WAAW;CAE7B,MAAM,OAA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