@tabler/charts 0.1.0 → 0.3.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 +92 -4
- package/dist/{annotations-Bp7HwtF5.d.ts → annotations-B02GR_KU.d.ts} +3 -8
- package/dist/{annotations-BszTTjf9.js → annotations-BQ8l-qHs.js} +6 -7
- package/dist/{annotations-BszTTjf9.js.map → annotations-BQ8l-qHs.js.map} +1 -1
- package/dist/{annotations-lyt0I3HU.d.cts → annotations-CHafaGd4.d.cts} +3 -8
- package/dist/{annotations-DpETO8dE.cjs → annotations-CpCWA29b.cjs} +6 -7
- package/dist/{annotations-DpETO8dE.cjs.map → annotations-CpCWA29b.cjs.map} +1 -1
- package/dist/annotations.cjs +3 -5
- package/dist/annotations.cjs.map +1 -1
- package/dist/annotations.d.cts +2 -1
- package/dist/annotations.d.ts +2 -1
- package/dist/annotations.js +3 -4
- package/dist/{arc-a1tRTEw7.js → arc-B3V5IR0w.js} +2 -3
- package/dist/{arc-a1tRTEw7.js.map → arc-B3V5IR0w.js.map} +1 -1
- package/dist/{arc-BXpLrt9b.cjs → arc-CYhI62kO.cjs} +2 -3
- package/dist/{arc-BXpLrt9b.cjs.map → arc-CYhI62kO.cjs.map} +1 -1
- package/dist/{area-CF__HOwL.d.ts → area-DEFQm_SQ.d.ts} +3 -6
- package/dist/{area-sHCE3pg5.cjs → area-DYdQ_sMV.cjs} +5 -6
- package/dist/{area-sHCE3pg5.cjs.map → area-DYdQ_sMV.cjs.map} +1 -1
- package/dist/{area-DQsLERhx.js → area-WdtfqvhX.js} +5 -6
- package/dist/{area-DQsLERhx.js.map → area-WdtfqvhX.js.map} +1 -1
- package/dist/{area-DIxaAbYZ.d.cts → area-h_FvieFb.d.cts} +3 -6
- package/dist/area.cjs +1 -1
- package/dist/area.d.cts +2 -1
- package/dist/area.d.ts +2 -1
- package/dist/area.js +1 -2
- package/dist/axis-MMaVoSWB.js +235 -0
- package/dist/axis-MMaVoSWB.js.map +1 -0
- package/dist/axis-YfAerNBA.cjs +300 -0
- package/dist/axis-YfAerNBA.cjs.map +1 -0
- package/dist/{band-DTcNDAFO.d.ts → band-CNKvdnTC.d.cts} +1 -4
- package/dist/{band-DTcNDAFO.d.cts → band-CNKvdnTC.d.ts} +1 -4
- package/dist/{bar-jZEoao74.js → bar-BOcRcArc.js} +80 -62
- package/dist/bar-BOcRcArc.js.map +1 -0
- package/dist/{bar-C-7zR2qp.cjs → bar-CVkOJ7WA.cjs} +82 -64
- package/dist/bar-CVkOJ7WA.cjs.map +1 -0
- package/dist/{bar-DM16NUvV.js → bar-CgpC2EpX.js} +3 -4
- package/dist/{bar-DM16NUvV.js.map → bar-CgpC2EpX.js.map} +1 -1
- package/dist/{bar-BBM8RhoL.d.ts → bar-D9B_arKf.d.ts} +4 -7
- package/dist/{bar-CRKLDg98.d.cts → bar-DZCQ-kyf.d.cts} +4 -7
- package/dist/{bar-DGuUN3nc.cjs → bar-wVykm1us.cjs} +3 -4
- package/dist/{bar-DGuUN3nc.cjs.map → bar-wVykm1us.cjs.map} +1 -1
- package/dist/bar.cjs +1 -1
- package/dist/bar.d.cts +2 -1
- package/dist/bar.d.ts +2 -1
- package/dist/bar.js +1 -2
- package/dist/calendar-BSvO8nRb.d.cts +106 -0
- package/dist/calendar-BXgIX5H1.js +502 -0
- package/dist/calendar-BXgIX5H1.js.map +1 -0
- package/dist/calendar-Bq3vFzPl.d.ts +106 -0
- package/dist/calendar-DAFXjV99.cjs +507 -0
- package/dist/calendar-DAFXjV99.cjs.map +1 -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-D_vV0_XZ.d.ts → candlestick-B3WcLzph.d.ts} +3 -6
- package/dist/{candlestick-__pXl_pV.d.cts → candlestick-BcomxeVG.d.cts} +3 -6
- package/dist/{candlestick-DuXwAFID.js → candlestick-BtT9glp9.js} +19 -18
- package/dist/{candlestick-DuXwAFID.js.map → candlestick-BtT9glp9.js.map} +1 -1
- package/dist/{candlestick-B5r1w3kc.cjs → candlestick-CSmRuZ4v.cjs} +19 -18
- package/dist/{candlestick-B5r1w3kc.cjs.map → candlestick-CSmRuZ4v.cjs.map} +1 -1
- package/dist/candlestick.cjs +4 -5
- package/dist/candlestick.d.cts +1 -1
- package/dist/candlestick.d.ts +1 -1
- package/dist/candlestick.js +4 -6
- package/dist/{cartesian-Cr0AF0nG.js → cartesian-BrPqb5Qn.js} +138 -264
- package/dist/cartesian-BrPqb5Qn.js.map +1 -0
- package/dist/{cartesian-BoDfgBCV.cjs → cartesian-DRSXHxWe.cjs} +162 -324
- package/dist/cartesian-DRSXHxWe.cjs.map +1 -0
- package/dist/{chart-BF2CK9I_.js → chart-B6TTY4Kr.js} +120 -77
- package/dist/chart-B6TTY4Kr.js.map +1 -0
- package/dist/{chart-DyN7bcx8.d.ts → chart-CYrrUCi3.d.ts} +222 -102
- package/dist/{chart-D7ooEFnk.d.cts → chart-CbPzP5Dp.d.cts} +248 -102
- package/dist/{chart-CowF_lWY.cjs → chart-D_lyOy-M.cjs} +132 -83
- package/dist/chart-D_lyOy-M.cjs.map +1 -0
- package/dist/{circle-BQMuAfls.cjs → circle-Bwxy5j7B.cjs} +2 -3
- package/dist/{circle-BQMuAfls.cjs.map → circle-Bwxy5j7B.cjs.map} +1 -1
- package/dist/{circle-Z7YfCoCM.js → circle-YRDaOBpk.js} +2 -3
- package/dist/{circle-Z7YfCoCM.js.map → circle-YRDaOBpk.js.map} +1 -1
- package/dist/{clean-o1vDEhFV.js → clean-CkoQobGv.js} +3 -4
- package/dist/{clean-o1vDEhFV.js.map → clean-CkoQobGv.js.map} +1 -1
- package/dist/{clean-Byl6kzf0.cjs → clean-Die2iCNc.cjs} +8 -3
- package/dist/{clean-Byl6kzf0.cjs.map → clean-Die2iCNc.cjs.map} +1 -1
- package/dist/{core-D1vO1LrC.d.cts → core-9BnLEW4K.d.cts} +31 -72
- package/dist/{core-DcbemzGf.d.ts → core-C3qEppSm.d.ts} +10 -46
- package/dist/{core-CegR_j55.js → core-CQ0FaJ4G.js} +138 -99
- package/dist/core-CQ0FaJ4G.js.map +1 -0
- package/dist/{core-RzS9IQO5.cjs → core-D2PSked3.cjs} +139 -100
- package/dist/core-D2PSked3.cjs.map +1 -0
- package/dist/core.cjs +47 -33
- package/dist/core.d.cts +26 -21
- package/dist/core.d.ts +26 -21
- package/dist/core.js +31 -25
- package/dist/{dates-CG-FvioW.js → dates-DLe2Ww64.js} +4 -5
- package/dist/{dates-CG-FvioW.js.map → dates-DLe2Ww64.js.map} +1 -1
- package/dist/{dates-Btm7Zm6W.cjs → dates-DerXTb1J.cjs} +4 -5
- package/dist/{dates-Btm7Zm6W.cjs.map → dates-DerXTb1J.cjs.map} +1 -1
- package/dist/{decimate-tLhDk1ys.cjs → decimate-BS3x8g-f.cjs} +2 -3
- package/dist/{decimate-tLhDk1ys.cjs.map → decimate-BS3x8g-f.cjs.map} +1 -1
- package/dist/{decimate-BGg9XgF0.d.ts → decimate-BxxYBJJk.d.cts} +2 -5
- package/dist/{decimate-C87cl_Sp.js → decimate-CapfgiDY.js} +2 -3
- package/dist/{decimate-C87cl_Sp.js.map → decimate-CapfgiDY.js.map} +1 -1
- package/dist/{decimate-CNSpgGa5.d.cts → decimate-Du87fMLG.d.ts} +2 -5
- package/dist/decimate.cjs +3 -4
- package/dist/decimate.d.cts +1 -1
- package/dist/decimate.d.ts +1 -1
- package/dist/decimate.js +3 -4
- package/dist/{dom-CLF868Qs.cjs → dom-C33zvtPo.cjs} +5 -11
- package/dist/dom-C33zvtPo.cjs.map +1 -0
- package/dist/{dom-vP3IcMak.js → dom-CTse6Rvd.js} +5 -11
- package/dist/dom-CTse6Rvd.js.map +1 -0
- package/dist/{export-chart-BhhYgksr.cjs → export-chart-CPtXmZvi.cjs} +18 -14
- package/dist/export-chart-CPtXmZvi.cjs.map +1 -0
- package/dist/{export-chart-9w8t3rjZ.js → export-chart-DoeiAyR2.js} +18 -14
- package/dist/export-chart-DoeiAyR2.js.map +1 -0
- package/dist/export.cjs +3 -5
- package/dist/export.cjs.map +1 -1
- package/dist/export.d.cts +8 -1
- package/dist/export.d.ts +8 -1
- package/dist/export.js +3 -4
- package/dist/{extent-BAMZo0Nq.js → extent-DOV8rs-6.js} +2 -3
- package/dist/{extent-BAMZo0Nq.js.map → extent-DOV8rs-6.js.map} +1 -1
- package/dist/{extent-DsFWvAHJ.cjs → extent-DuYDcvM9.cjs} +2 -3
- package/dist/{extent-DsFWvAHJ.cjs.map → extent-DuYDcvM9.cjs.map} +1 -1
- package/dist/{fade-D3NxH5Qg.js → fade-CDrQjnDz.js} +59 -83
- package/dist/fade-CDrQjnDz.js.map +1 -0
- package/dist/{fade-Cs74puQS.cjs → fade-CRqcKMWY.cjs} +59 -83
- package/dist/fade-CRqcKMWY.cjs.map +1 -0
- package/dist/{features-wASyHGic.js → features-B55rwpQC.js} +5 -4
- package/dist/features-B55rwpQC.js.map +1 -0
- package/dist/{features-BclHgg2W.cjs → features-DEDP5CEQ.cjs} +10 -3
- 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/{format-B0yKXBTH.cjs → format-CAE5ruy6.cjs} +2 -3
- package/dist/{format-B0yKXBTH.cjs.map → format-CAE5ruy6.cjs.map} +1 -1
- package/dist/{format-lStwuc1L.js → format-it1kepFG.js} +2 -3
- package/dist/{format-lStwuc1L.js.map → format-it1kepFG.js.map} +1 -1
- package/dist/funnel-BdcfUkb5.d.ts +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-CarOh8w_.d.cts +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-D-FYhuds.cjs → gauge-6HfDcLMJ.cjs} +35 -36
- package/dist/gauge-6HfDcLMJ.cjs.map +1 -0
- package/dist/{gauge-Dh423FHh.js → gauge-DiTk5aWO.js} +35 -36
- package/dist/gauge-DiTk5aWO.js.map +1 -0
- package/dist/{gauge-zpia05t2.d.ts → gauge-Ds9k1UV2.d.cts} +5 -8
- package/dist/{gauge-DP_EB2z3.d.cts → gauge-Zy25jfps.d.ts} +5 -8
- package/dist/gauge.cjs +1 -1
- package/dist/gauge.d.cts +2 -1
- package/dist/gauge.d.ts +2 -1
- package/dist/gauge.js +1 -2
- package/dist/{heatmap-DSZ2bVIa.js → heatmap-C1v8bwpq.js} +43 -43
- package/dist/heatmap-C1v8bwpq.js.map +1 -0
- package/dist/{heatmap-BectCEeE.d.ts → heatmap-CJ-0dfhJ.d.cts} +4 -7
- package/dist/{heatmap-BK18EBgJ.cjs → heatmap-Dcc_bsoQ.cjs} +47 -47
- package/dist/heatmap-Dcc_bsoQ.cjs.map +1 -0
- package/dist/{heatmap-CCso6m61.d.cts → heatmap-Jp5sHRTo.d.ts} +4 -7
- package/dist/heatmap.cjs +1 -1
- package/dist/heatmap.d.cts +2 -1
- package/dist/heatmap.d.ts +2 -1
- package/dist/heatmap.js +1 -2
- package/dist/{hydrate-DDNIHYv_.js → hydrate-BB3MlR36.js} +3 -4
- package/dist/{hydrate-DDNIHYv_.js.map → hydrate-BB3MlR36.js.map} +1 -1
- package/dist/{hydrate-CzfxLfTv.d.ts → hydrate-BtAZf_5K.d.cts} +2 -5
- package/dist/{hydrate-CTTmQy0x.d.cts → hydrate-OjM1pIUG.d.ts} +2 -5
- package/dist/{hydrate-CxwTXDqO.cjs → hydrate-m0I5m6ue.cjs} +3 -4
- package/dist/hydrate-m0I5m6ue.cjs.map +1 -0
- package/dist/hydrate.cjs +3 -4
- package/dist/hydrate.cjs.map +1 -1
- package/dist/hydrate.d.cts +1 -1
- package/dist/hydrate.d.ts +1 -1
- package/dist/hydrate.js +3 -4
- package/dist/index.cjs +72 -56
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +28 -28
- package/dist/index.d.ts +28 -28
- package/dist/index.js +52 -44
- 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-CtMBhNd9.cjs → layout-Cfg9x1k2.cjs} +45 -3
- package/dist/layout-Cfg9x1k2.cjs.map +1 -0
- package/dist/{layout-B3hiqVEw.js → layout-DqAte3H8.js} +34 -4
- package/dist/layout-DqAte3H8.js.map +1 -0
- package/dist/{line-CN4uZ9ZX.d.ts → line-Bpr5uVLQ.d.ts} +4 -7
- package/dist/{line-B3Ed6u7j.js → line-CxR4tg1Q.js} +49 -38
- package/dist/line-CxR4tg1Q.js.map +1 -0
- package/dist/{line-fQbtP_jL.cjs → line-YiCuhVMI.cjs} +49 -38
- package/dist/line-YiCuhVMI.cjs.map +1 -0
- package/dist/{line-W7VD_qs1.d.cts → line-vyWO030v.d.cts} +4 -7
- package/dist/line.cjs +4 -5
- package/dist/line.cjs.map +1 -1
- package/dist/line.d.cts +1 -1
- package/dist/line.d.ts +1 -1
- package/dist/line.js +4 -6
- package/dist/{log-CaofN3-n.d.ts → log-CI41TmcU.d.cts} +1 -6
- package/dist/{log-CaofN3-n.d.cts → log-CI41TmcU.d.ts} +1 -6
- package/dist/{log-axis-83rSpvL5.cjs → log-axis-DdRNyAq8.cjs} +6 -8
- package/dist/{log-axis-83rSpvL5.cjs.map → log-axis-DdRNyAq8.cjs.map} +1 -1
- package/dist/{log-axis-B_uvvOFc.js → log-axis-DhthtHFk.js} +6 -8
- package/dist/{log-axis-B_uvvOFc.js.map → log-axis-DhthtHFk.js.map} +1 -1
- package/dist/log.cjs +3 -5
- package/dist/log.cjs.map +1 -1
- package/dist/log.d.cts +1 -1
- package/dist/log.d.ts +1 -1
- package/dist/log.js +3 -4
- package/dist/map-49FcfdmJ.d.cts +156 -0
- package/dist/map-BMC61J-P.d.ts +156 -0
- package/dist/map-BqrZ80vT.cjs +818 -0
- package/dist/map-BqrZ80vT.cjs.map +1 -0
- package/dist/map-C15NC7kW.js +807 -0
- package/dist/map-C15NC7kW.js.map +1 -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-CqYDu1bY.cjs → morph-3I1Nf_tR.cjs} +4 -5
- package/dist/morph-3I1Nf_tR.cjs.map +1 -0
- package/dist/{morph-BMxz3X2b.d.ts → morph-Dh7gJkV4.d.cts} +1 -4
- package/dist/{morph-BMxz3X2b.d.cts → morph-Dh7gJkV4.d.ts} +1 -4
- package/dist/{morph-Bgg-24l8.js → morph-GfBab-b3.js} +4 -5
- package/dist/{morph-Bgg-24l8.js.map → morph-GfBab-b3.js.map} +1 -1
- package/dist/morph.cjs +3 -4
- package/dist/morph.cjs.map +1 -1
- package/dist/morph.d.cts +1 -1
- package/dist/morph.d.ts +1 -1
- package/dist/morph.js +3 -4
- package/dist/{named-BWWb5LQJ.cjs → named-BBASc8dW.cjs} +2 -3
- package/dist/{named-BWWb5LQJ.cjs.map → named-BBASc8dW.cjs.map} +1 -1
- package/dist/{named-DE15TOgh.js → named-BOiBah6I.js} +2 -3
- package/dist/{named-DE15TOgh.js.map → named-BOiBah6I.js.map} +1 -1
- package/dist/others-DBIGE6jr.js +57 -0
- package/dist/others-DBIGE6jr.js.map +1 -0
- package/dist/others-DBO4Kjwl.d.ts +29 -0
- package/dist/others-WfjCsjqT.cjs +68 -0
- package/dist/others-WfjCsjqT.cjs.map +1 -0
- package/dist/others-ls5eKtZ4.d.cts +31 -0
- package/dist/{parliament-Dw0sOERi.js → parliament-BKN6ikBJ.js} +36 -36
- package/dist/parliament-BKN6ikBJ.js.map +1 -0
- package/dist/{parliament-1Zv2Xh0D.d.ts → parliament-C7V8UJj1.d.cts} +5 -8
- package/dist/{parliament-DdrLVZwt.d.cts → parliament-Cz9n_DoK.d.ts} +5 -8
- package/dist/{parliament-CpWnoEvG.cjs → parliament-DhxAaIZ3.cjs} +36 -36
- package/dist/parliament-DhxAaIZ3.cjs.map +1 -0
- package/dist/parliament.cjs +1 -1
- package/dist/parliament.d.cts +2 -1
- package/dist/parliament.d.ts +2 -1
- package/dist/parliament.js +1 -2
- package/dist/{path-CwB28da0.d.ts → path-YeUiOfG8.d.cts} +1 -4
- package/dist/{path-CwB28da0.d.cts → path-YeUiOfG8.d.ts} +1 -4
- package/dist/{patterns-DtgcnA8o.js → patterns-BMUINoka.js} +4 -5
- package/dist/{patterns-DtgcnA8o.js.map → patterns-BMUINoka.js.map} +1 -1
- package/dist/{patterns-LfcQAWCy.cjs → patterns-Dw7OMD_2.cjs} +4 -5
- package/dist/{patterns-LfcQAWCy.cjs.map → patterns-Dw7OMD_2.cjs.map} +1 -1
- package/dist/patterns.cjs +3 -5
- package/dist/patterns.cjs.map +1 -1
- package/dist/patterns.d.cts +5 -1
- package/dist/patterns.d.ts +5 -1
- package/dist/patterns.js +3 -4
- package/dist/percentage-bar-BChkTRoz.cjs +164 -0
- package/dist/percentage-bar-BChkTRoz.cjs.map +1 -0
- package/dist/percentage-bar-CaInxrL8.js +159 -0
- package/dist/percentage-bar-CaInxrL8.js.map +1 -0
- package/dist/percentage-bar-R1--2grK.d.cts +58 -0
- package/dist/percentage-bar-cSeiLdwU.d.ts +58 -0
- package/dist/percentage-bar.cjs +3 -0
- package/dist/percentage-bar.d.cts +3 -0
- package/dist/percentage-bar.d.ts +3 -0
- package/dist/percentage-bar.js +1 -0
- package/dist/{pie-BF9yI5mE.d.cts → pie-BQQkvy1N.d.ts} +11 -11
- package/dist/{pie-DzUXDTcn.js → pie-Bd8wyrtY.js} +52 -55
- package/dist/pie-Bd8wyrtY.js.map +1 -0
- package/dist/{pie-BxTZt6Go.cjs → pie-BseZlCgP.cjs} +52 -55
- package/dist/pie-BseZlCgP.cjs.map +1 -0
- package/dist/{pie-5z1fDdKO.d.ts → pie-vD5-g8je.d.cts} +11 -11
- package/dist/pie.cjs +1 -1
- package/dist/pie.d.cts +2 -1
- package/dist/pie.d.ts +2 -1
- package/dist/pie.js +1 -2
- package/dist/{point-shapes-CGl4dugc.cjs → point-shapes-BRawRM78.cjs} +24 -24
- package/dist/point-shapes-BRawRM78.cjs.map +1 -0
- package/dist/{point-shapes-DI84NNpI.js → point-shapes-DI6GhcI7.js} +19 -25
- package/dist/point-shapes-DI6GhcI7.js.map +1 -0
- package/dist/point-shapes.cjs +7 -6
- package/dist/point-shapes.cjs.map +1 -1
- package/dist/point-shapes.d.cts +6 -2
- package/dist/point-shapes.d.ts +6 -2
- package/dist/point-shapes.js +8 -7
- package/dist/point-shapes.js.map +1 -1
- package/dist/{radar-1-EryihA.d.ts → radar-7I6hsY_h.d.cts} +4 -7
- package/dist/{radar-CYPab_I4.js → radar-D6XqkFWQ.js} +25 -27
- package/dist/radar-D6XqkFWQ.js.map +1 -0
- package/dist/{radar-CoGUNNSb.cjs → radar-DjISDnSf.cjs} +26 -28
- package/dist/radar-DjISDnSf.cjs.map +1 -0
- package/dist/{radar-DBW4O0Vt.d.cts → radar-vLxilcr4.d.ts} +4 -7
- package/dist/radar.cjs +1 -1
- package/dist/radar.d.cts +2 -1
- package/dist/radar.d.ts +2 -1
- package/dist/radar.js +1 -2
- package/dist/rect-CZTNvMlf.js +11 -0
- package/dist/rect-CZTNvMlf.js.map +1 -0
- package/dist/rect-DPr9QRxl.cjs +16 -0
- package/dist/rect-DPr9QRxl.cjs.map +1 -0
- package/dist/{sankey-Bacx4fVe.cjs → sankey-0CSp_Er9.cjs} +100 -95
- package/dist/sankey-0CSp_Er9.cjs.map +1 -0
- package/dist/{sankey-OV_WoPrl.d.ts → sankey-7As41Fo4.d.ts} +4 -7
- package/dist/{sankey-B4PNKusJ.js → sankey-Dp4CuLVe.js} +100 -95
- package/dist/sankey-Dp4CuLVe.js.map +1 -0
- package/dist/{sankey-DuGI3Qc5.d.cts → sankey-DqiuxUx7.d.cts} +4 -7
- package/dist/sankey.cjs +1 -1
- package/dist/sankey.d.cts +2 -1
- package/dist/sankey.d.ts +2 -1
- package/dist/sankey.js +1 -2
- package/dist/{scatter-DbxLyZX0.d.cts → scatter-BXkXGgM_.d.ts} +14 -9
- package/dist/{scatter-DgMN9zRy.cjs → scatter-Bwkblr4L.cjs} +47 -42
- package/dist/scatter-Bwkblr4L.cjs.map +1 -0
- package/dist/{scatter-kgtgR318.js → scatter-DCMAtt5L.js} +45 -40
- package/dist/scatter-DCMAtt5L.js.map +1 -0
- package/dist/{scatter-BqzgJqdX.d.ts → scatter-DL0zAV09.d.cts} +14 -9
- package/dist/scatter.cjs +1 -1
- package/dist/scatter.d.cts +2 -1
- package/dist/scatter.d.ts +2 -1
- package/dist/scatter.js +1 -2
- package/dist/{sparkline-BfyO_oNM.d.ts → sparkline-BElUSd0r.d.ts} +5 -8
- package/dist/{sparkline-BS9-hltA.cjs → sparkline-BMSuEPHP.cjs} +22 -23
- package/dist/sparkline-BMSuEPHP.cjs.map +1 -0
- package/dist/{sparkline-BQzt27Fr.js → sparkline-NDmq90kP.js} +22 -23
- package/dist/sparkline-NDmq90kP.js.map +1 -0
- package/dist/{sparkline-CWlJDKyh.d.cts → sparkline-RYly7bR0.d.cts} +5 -8
- package/dist/sparkline.cjs +1 -1
- package/dist/sparkline.d.cts +2 -1
- package/dist/sparkline.d.ts +2 -1
- package/dist/sparkline.js +1 -2
- package/dist/{stack-DVhJWaki.cjs → stack-BO4624CY.cjs} +3 -4
- package/dist/{stack-DVhJWaki.cjs.map → stack-BO4624CY.cjs.map} +1 -1
- package/dist/{stack-CpR6RGKd.d.ts → stack-BTWYIwLO.d.cts} +2 -4
- package/dist/{stack-CpR6RGKd.d.cts → stack-DR0eQTsB.d.ts} +1 -4
- package/dist/{stack-DRbwTeF3.js → stack-jVKvg2x_.js} +3 -4
- package/dist/{stack-DRbwTeF3.js.map → stack-jVKvg2x_.js.map} +1 -1
- package/dist/style.css +1 -1
- package/dist/{sweep-CbfR7--d.js → sweep-BpRPlhs6.js} +5 -6
- package/dist/{sweep-CbfR7--d.js.map → sweep-BpRPlhs6.js.map} +1 -1
- package/dist/{sweep-DaTEDDuC.cjs → sweep-Dnp6LDBz.cjs} +5 -6
- package/dist/sweep-Dnp6LDBz.cjs.map +1 -0
- package/dist/{time-CNVnt-B2.d.cts → time-B4oxWHQI.d.cts} +2 -7
- package/dist/{time-CHjiY9Q4.d.ts → time-DRIDgv2a.d.ts} +2 -7
- package/dist/{time-axis-VSX34_Tb.cjs → time-axis-B3VekUfX.cjs} +11 -11
- package/dist/{time-axis-VSX34_Tb.cjs.map → time-axis-B3VekUfX.cjs.map} +1 -1
- package/dist/{time-axis-Bc9eHX1r.js → time-axis-CLjqOakA.js} +10 -10
- package/dist/{time-axis-Bc9eHX1r.js.map → time-axis-CLjqOakA.js.map} +1 -1
- package/dist/time.cjs +4 -6
- package/dist/time.cjs.map +1 -1
- package/dist/time.d.cts +1 -1
- package/dist/time.d.ts +1 -1
- package/dist/time.js +4 -5
- package/dist/treemap-25vHO_UK.d.cts +65 -0
- package/dist/treemap-BCXUbixd.d.ts +65 -0
- package/dist/treemap-C4glsx-g.js +293 -0
- package/dist/treemap-C4glsx-g.js.map +1 -0
- package/dist/treemap-CZk8kKFD.cjs +298 -0
- package/dist/treemap-CZk8kKFD.cjs.map +1 -0
- package/dist/treemap.cjs +3 -0
- package/dist/treemap.d.cts +3 -0
- package/dist/treemap.d.ts +3 -0
- package/dist/treemap.js +1 -0
- package/dist/{tween-BCYd0RTY.js → tween-BdQqUmmv.js} +2 -3
- package/dist/{tween-BCYd0RTY.js.map → tween-BdQqUmmv.js.map} +1 -1
- package/dist/{tween-CIGBlryn.cjs → tween-c3aOmfKE.cjs} +2 -3
- package/dist/{tween-CIGBlryn.cjs.map → tween-c3aOmfKE.cjs.map} +1 -1
- package/dist/{value-labels-IZIQPhfk.js → value-labels-C7GrhOXJ.js} +30 -10
- package/dist/value-labels-C7GrhOXJ.js.map +1 -0
- package/dist/{value-labels-B0WJoJ7x.cjs → value-labels-DzaKIWKp.cjs} +30 -10
- package/dist/value-labels-DzaKIWKp.cjs.map +1 -0
- package/dist/value-labels.cjs +3 -5
- package/dist/value-labels.cjs.map +1 -1
- package/dist/value-labels.d.cts +5 -1
- package/dist/value-labels.d.ts +5 -1
- package/dist/value-labels.js +3 -4
- package/dist/{vnode-CkQ27Cxe.cjs → vnode-ClAiw28x.cjs} +2 -3
- package/dist/{vnode-CkQ27Cxe.cjs.map → vnode-ClAiw28x.cjs.map} +1 -1
- package/dist/{vnode-BUflsBsa.d.ts → vnode-Du2cC8Fm.d.cts} +1 -4
- package/dist/{vnode-BUflsBsa.d.cts → vnode-Du2cC8Fm.d.ts} +1 -4
- package/dist/{vnode-tCWItoUH.js → vnode-_EMUqysL.js} +2 -3
- package/dist/{vnode-tCWItoUH.js.map → vnode-_EMUqysL.js.map} +1 -1
- package/package.json +94 -214
- package/dist/bar-C-7zR2qp.cjs.map +0 -1
- package/dist/bar-jZEoao74.js.map +0 -1
- package/dist/cartesian-BoDfgBCV.cjs.map +0 -1
- package/dist/cartesian-Cr0AF0nG.js.map +0 -1
- package/dist/chart-BF2CK9I_.js.map +0 -1
- package/dist/chart-CowF_lWY.cjs.map +0 -1
- package/dist/core-CegR_j55.js.map +0 -1
- package/dist/core-RzS9IQO5.cjs.map +0 -1
- package/dist/dom-CLF868Qs.cjs.map +0 -1
- package/dist/dom-vP3IcMak.js.map +0 -1
- package/dist/export-chart-9w8t3rjZ.js.map +0 -1
- package/dist/export-chart-BhhYgksr.cjs.map +0 -1
- package/dist/fade-Cs74puQS.cjs.map +0 -1
- package/dist/fade-D3NxH5Qg.js.map +0 -1
- package/dist/features-BclHgg2W.cjs.map +0 -1
- package/dist/features-wASyHGic.js.map +0 -1
- package/dist/gauge-D-FYhuds.cjs.map +0 -1
- package/dist/gauge-Dh423FHh.js.map +0 -1
- package/dist/heatmap-BK18EBgJ.cjs.map +0 -1
- package/dist/heatmap-DSZ2bVIa.js.map +0 -1
- package/dist/hydrate-CxwTXDqO.cjs.map +0 -1
- package/dist/layout-B3hiqVEw.js.map +0 -1
- package/dist/layout-CtMBhNd9.cjs.map +0 -1
- package/dist/line-B3Ed6u7j.js.map +0 -1
- package/dist/line-fQbtP_jL.cjs.map +0 -1
- package/dist/morph-CqYDu1bY.cjs.map +0 -1
- package/dist/parliament-CpWnoEvG.cjs.map +0 -1
- package/dist/parliament-Dw0sOERi.js.map +0 -1
- package/dist/pie-BxTZt6Go.cjs.map +0 -1
- package/dist/pie-DzUXDTcn.js.map +0 -1
- package/dist/point-shapes-CGl4dugc.cjs.map +0 -1
- package/dist/point-shapes-DI84NNpI.js.map +0 -1
- package/dist/radar-CYPab_I4.js.map +0 -1
- package/dist/radar-CoGUNNSb.cjs.map +0 -1
- package/dist/sankey-B4PNKusJ.js.map +0 -1
- package/dist/sankey-Bacx4fVe.cjs.map +0 -1
- package/dist/scatter-DgMN9zRy.cjs.map +0 -1
- package/dist/scatter-kgtgR318.js.map +0 -1
- package/dist/sparkline-BQzt27Fr.js.map +0 -1
- package/dist/sparkline-BS9-hltA.cjs.map +0 -1
- package/dist/sweep-DaTEDDuC.cjs.map +0 -1
- package/dist/value-labels-B0WJoJ7x.cjs.map +0 -1
- package/dist/value-labels-IZIQPhfk.js.map +0 -1
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { n as estimateTextWidth } from "./layout-DqAte3H8.js";
|
|
2
|
+
// src/charts/fit.ts
|
|
3
|
+
/** `text` cut to `width` pixels with an ellipsis, or `''` when not even a few letters fit. */
|
|
4
|
+
function fit(text, width, fontSize) {
|
|
5
|
+
if (estimateTextWidth(text, fontSize) <= width) return text;
|
|
6
|
+
const chars = [...text];
|
|
7
|
+
while (chars.length > 2) {
|
|
8
|
+
chars.pop();
|
|
9
|
+
const cut = `${chars.join("").trimEnd()}…`;
|
|
10
|
+
if (estimateTextWidth(cut, fontSize) <= width) return cut;
|
|
11
|
+
}
|
|
12
|
+
return "";
|
|
13
|
+
}
|
|
14
|
+
export { fit as t };
|
|
15
|
+
|
|
16
|
+
//# sourceMappingURL=fit-BPyPRnsK.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fit-BPyPRnsK.js","names":[],"sources":["../src/charts/fit.ts"],"sourcesContent":["import { estimateTextWidth } from '../layout.ts'\n\n/** `text` cut to `width` pixels with an ellipsis, or `''` when not even a few letters fit. */\nexport function 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"],"mappings":";;;AAGA,SAAgB,IAAI,MAAc,OAAe,UAA0B;CACzE,IAAI,kBAAkB,MAAM,QAAQ,KAAK,OAAO,OAAO;CACvD,MAAM,QAAQ,CAAC,GAAG,IAAI;CACtB,OAAO,MAAM,SAAS,GAAG;EACvB,MAAM,IAAI;EACV,MAAM,MAAM,GAAG,MAAM,KAAK,EAAE,CAAC,CAAC,QAAQ,EAAE;EACxC,IAAI,kBAAkB,KAAK,QAAQ,KAAK,OAAO,OAAO;CACxD;CACA,OAAO;AACT"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const require_layout = require("./layout-Cfg9x1k2.cjs");
|
|
2
|
+
// src/charts/fit.ts
|
|
3
|
+
/** `text` cut to `width` pixels with an ellipsis, or `''` when not even a few letters fit. */
|
|
4
|
+
function fit(text, width, fontSize) {
|
|
5
|
+
if (require_layout.estimateTextWidth(text, fontSize) <= width) return text;
|
|
6
|
+
const chars = [...text];
|
|
7
|
+
while (chars.length > 2) {
|
|
8
|
+
chars.pop();
|
|
9
|
+
const cut = `${chars.join("").trimEnd()}…`;
|
|
10
|
+
if (require_layout.estimateTextWidth(cut, fontSize) <= width) return cut;
|
|
11
|
+
}
|
|
12
|
+
return "";
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(exports, "fit", {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: function() {
|
|
17
|
+
return fit;
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=fit-D4MIIQQz.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fit-D4MIIQQz.cjs","names":["estimateTextWidth"],"sources":["../src/charts/fit.ts"],"sourcesContent":["import { estimateTextWidth } from '../layout.ts'\n\n/** `text` cut to `width` pixels with an ellipsis, or `''` when not even a few letters fit. */\nexport function 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"],"mappings":";;;AAGA,SAAgB,IAAI,MAAc,OAAe,UAA0B;CACzE,IAAIA,eAAAA,kBAAkB,MAAM,QAAQ,KAAK,OAAO,OAAO;CACvD,MAAM,QAAQ,CAAC,GAAG,IAAI;CACtB,OAAO,MAAM,SAAS,GAAG;EACvB,MAAM,IAAI;EACV,MAAM,MAAM,GAAG,MAAM,KAAK,EAAE,CAAC,CAAC,QAAQ,EAAE;EACxC,IAAIA,eAAAA,kBAAkB,KAAK,QAAQ,KAAK,OAAO,OAAO;CACxD;CACA,OAAO;AACT"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/format.ts
|
|
2
2
|
const MAX_CACHE = 64;
|
|
3
3
|
const numberCache = /* @__PURE__ */ new Map();
|
|
4
4
|
const dateCache = /* @__PURE__ */ new Map();
|
|
@@ -136,7 +136,6 @@ function formatDate(format, locale) {
|
|
|
136
136
|
const df = getDateFormat(locale, format);
|
|
137
137
|
return (value) => df.format(value);
|
|
138
138
|
}
|
|
139
|
-
//#endregion
|
|
140
139
|
Object.defineProperty(exports, "formatDate", {
|
|
141
140
|
enumerable: true,
|
|
142
141
|
get: function() {
|
|
@@ -180,4 +179,4 @@ Object.defineProperty(exports, "stepPrecision", {
|
|
|
180
179
|
}
|
|
181
180
|
});
|
|
182
181
|
|
|
183
|
-
//# sourceMappingURL=format-
|
|
182
|
+
//# sourceMappingURL=format-CAE5ruy6.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format-B0yKXBTH.cjs","names":[],"sources":["../src/format.ts"],"sourcesContent":["/**\n * Number and date formatting built on `Intl` — locale aware, zero bytes of\n * locale data shipped.\n *\n * Formats are plain data (`Intl` options) or functions, so chart configs stay\n * serializable (JSON attributes, SSR). Pass an explicit `locale` when\n * rendering on the server, otherwise server and browser may disagree.\n */\n\n/** Locale(s) passed to `Intl`; `undefined` uses the runtime default. */\nexport type Locale = string | readonly string[] | undefined\n\n/** `Intl.NumberFormat` options, plus suffixes of our own for compact notation. */\nexport interface NumberFormatOptions extends Intl.NumberFormatOptions {\n /**\n * Compact notation with these suffixes for thousands, millions, billions…\n * instead of the locale's words: `['k', 'M', 'G']` writes 1500 as \"1.5k\",\n * or \"1,5k\" in Polish, where the locale itself writes \"1,5 tys.\". `true`\n * stands for `['K', 'M', 'B', 'T']`. Larger numbers keep the last suffix.\n */\n compactSymbols?: boolean | readonly string[]\n}\n\n/** Number format options or a custom formatter. */\nexport type NumberFormat = NumberFormatOptions | ((value: number) => string)\n\n/** `Intl.DateTimeFormat` options or a custom formatter. */\nexport type DateFormat = Intl.DateTimeFormatOptions | ((value: Date) => string)\n\nconst MAX_CACHE = 64\nconst numberCache = /* @__PURE__ */ new Map<string, Intl.NumberFormat>()\nconst dateCache = /* @__PURE__ */ new Map<string, Intl.DateTimeFormat>()\n\nfunction cached<T>(cache: Map<string, T>, key: string, create: () => T): T {\n let value = cache.get(key)\n if (value === undefined) {\n if (cache.size >= MAX_CACHE) cache.clear()\n value = create()\n cache.set(key, value)\n }\n return value\n}\n\nfunction cacheKey(locale: Locale, options: object): string {\n return `${JSON.stringify(locale ?? null)}|${JSON.stringify(options)}`\n}\n\n/** Shared, cached `Intl.NumberFormat` instance. */\nexport function getNumberFormat(\n locale?: Locale,\n options: Intl.NumberFormatOptions = {},\n): Intl.NumberFormat {\n return cached(\n numberCache,\n cacheKey(locale, options),\n () => new Intl.NumberFormat(locale as string | string[] | undefined, options),\n )\n}\n\n/** Shared, cached `Intl.DateTimeFormat` instance. */\nexport function getDateFormat(\n locale?: Locale,\n options: Intl.DateTimeFormatOptions = {},\n): Intl.DateTimeFormat {\n return cached(\n dateCache,\n cacheKey(locale, options),\n () => new Intl.DateTimeFormat(locale as string | string[] | undefined, options),\n )\n}\n\n/** Avoid `-0` rendering as \"-0\". */\nconst unsignedZero = (value: number): number => (value === 0 ? 0 : value)\n\n/**\n * Create a number formatter.\n *\n * ```ts\n * formatNumber({ style: 'currency', currency: 'PLN' }, 'pl-PL')(1234.5) // \"1234,50 zł\"\n * ```\n */\nexport function formatNumber(format?: NumberFormat, locale?: Locale): (value: number) => string {\n if (typeof format === 'function') return format\n const { compactSymbols, ...options } = format ?? {}\n if (compactSymbols) {\n return formatCompact(compactSymbols === true ? SYMBOLS : compactSymbols, options, locale)\n }\n const nf = getNumberFormat(locale, options)\n return (value) => nf.format(unsignedZero(value))\n}\n\nconst SYMBOLS = ['K', 'M', 'B', 'T']\n\n/**\n * Compact notation with the given suffixes: the value divided by its power\n * of a thousand, formatted by `Intl` (separators, currency, sign) with the\n * suffix after the digits. Without digits of its own it rounds like `Intl`'s\n * compact notation: two significant digits below 10, whole numbers above.\n */\nfunction formatCompact(\n symbols: readonly string[],\n // `notation` and `compactDisplay` are taken out: the suffixes replace them.\n { notation, compactDisplay, ...options }: Intl.NumberFormatOptions,\n locale: Locale,\n): (value: number) => string {\n const own = digitsOf(options)\n const small = getNumberFormat(locale, own ? options : { ...options, maximumSignificantDigits: 2 })\n const large = own ? small : getNumberFormat(locale, { ...options, maximumFractionDigits: 0 })\n return (value) => {\n for (let exp = 0; ; exp++) {\n const scaled = unsignedZero(value / 1000 ** exp)\n const parts = (Math.abs(scaled) < 10 ? small : large).formatToParts(scaled)\n let digits = ''\n let last: Intl.NumberFormatPart | undefined\n for (const part of parts) {\n if (part.type === 'integer') digits += part.value\n if (part.type === 'integer' || part.type === 'fraction') last = part\n }\n // Four digits or more: a thousand times smaller, with the next suffix\n // (so 999 950 rounds up to \"1M\", not \"1000K\").\n if (digits.length < 4 || exp >= symbols.length) {\n if (exp && last) last.value += symbols[exp - 1]\n return parts.map((part) => part.value).join('')\n }\n }\n }\n}\n\n/** Whether number options write compact numbers (\"25K\"). */\nconst compactOf = (o: NumberFormatOptions): boolean =>\n o.notation === 'compact' || !!o.compactSymbols\n\n/** Whether number options set their digits (fraction or significant). */\nconst digitsOf = (o: Intl.NumberFormatOptions): boolean =>\n (o.minimumFractionDigits ??\n o.maximumFractionDigits ??\n o.minimumSignificantDigits ??\n o.maximumSignificantDigits) !== undefined\n\n/**\n * A formatter for values read one at a time (tooltips, data tables) in an\n * axis format. Compact notation suits ticks (\"$25K\") but hides the\n * difference between values: unless the format sets its own precision, it\n * keeps three significant digits (\"$24.8K\").\n */\nexport function formatDetail(format?: NumberFormat, locale?: Locale): (value: number) => string {\n return formatNumber(\n typeof format === 'object' && compactOf(format) && !digitsOf(format)\n ? { ...format, maximumSignificantDigits: 3 }\n : format,\n locale,\n )\n}\n/**\n * Number of fraction digits needed to tell apart ticks `step` apart,\n * e.g. `1 → 0`, `0.2 → 1`, `0.05 → 2`.\n */\nexport function stepPrecision(step: number): number {\n const abs = Math.abs(step)\n if (!Number.isFinite(abs) || abs === 0) return 0\n return Math.max(0, -Math.floor(Math.log10(abs) + 1e-9))\n}\n\nfunction hasPrecision(options: NumberFormatOptions): boolean {\n return (\n digitsOf(options) || !!options.compactSymbols || (options.notation ?? 'standard') !== 'standard'\n )\n}\n/**\n * Create a formatter for axis ticks `step` apart. Unless `format` sets its\n * own precision, every tick gets the same number of fraction digits, derived\n * from the step (`0, 0.5, 1` → `0.0, 0.5, 1.0`).\n */\nexport function formatTicks(\n step: number,\n format?: NumberFormat,\n locale?: Locale,\n): (value: number) => string {\n if (typeof format === 'function') return format\n const options = format ?? {}\n if (hasPrecision(options)) return formatNumber(options, locale)\n\n let digits = stepPrecision(step)\n if (options.style === 'percent') digits = Math.max(0, digits - 2)\n const fmt = formatNumber(\n { ...options, minimumFractionDigits: digits, maximumFractionDigits: digits },\n locale,\n )\n // Values within floating point noise of zero (e.g. 1e-17) print as zero.\n const epsilon = Math.abs(step) * 1e-9\n return (value) => fmt(Math.abs(value) < epsilon ? 0 : value)\n}\n\n/**\n * Create a date formatter accepting `Date` objects or timestamps.\n *\n * ```ts\n * formatDate({ month: 'short', day: 'numeric' }, 'en-US')(new Date(2026, 0, 5)) // \"Jan 5\"\n * ```\n */\nexport function formatDate(format?: DateFormat, locale?: Locale): (value: Date | number) => string {\n if (typeof format === 'function') {\n return (value) => format(typeof value === 'number' ? new Date(value) : value)\n }\n const df = getDateFormat(locale, format)\n return (value) => df.format(value)\n}\n"],"mappings":";AA6BA,MAAM,YAAY;AAClB,MAAM,8BAA8B,IAAI,IAA+B;AACvE,MAAM,4BAA4B,IAAI,IAAiC;AAEvE,SAAS,OAAU,OAAuB,KAAa,QAAoB;CACzE,IAAI,QAAQ,MAAM,IAAI,GAAG;CACzB,IAAI,UAAU,KAAA,GAAW;EACvB,IAAI,MAAM,QAAQ,WAAW,MAAM,MAAM;EACzC,QAAQ,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AAI,SAAS,cAAc,IAAI;CAC/B,IAAI,QAAQ,UAAU,WAAW,SAAS,KAAK,IAAI,GAAG,SAAS,CAAC;CAChE,MAAM,MAAM,aACV;EAAE,GAAG;EAAS,uBAAuB;EAAQ,uBAAuB;CAAO,GAC3E,MACF;CAEA,MAAM,UAAU,KAAK,IAAI,IAAI,IAAI;CACjC,QAAQ,UAAU,IAAI,KAAK,IAAI,KAAK,IAAI,UAAU,IAAI,KAAK;AAC7D;;;;;;;;AASA,SAAgB,WAAW,QAAqB,QAAmD;CACjG,IAAI,OAAO,WAAW,YACpB,QAAQ,UAAU,OAAO,OAAO,UAAU,WAAW,IAAI,KAAK,KAAK,IAAI,KAAK;CAE9E,MAAM,KAAK,cAAc,QAAQ,MAAM;CACvC,QAAQ,UAAU,GAAG,OAAO,KAAK;AACnC"}
|
|
1
|
+
{"version":3,"file":"format-CAE5ruy6.cjs","names":[],"sources":["../src/format.ts"],"sourcesContent":["/**\n * Number and date formatting built on `Intl` — locale aware, zero bytes of\n * locale data shipped.\n *\n * Formats are plain data (`Intl` options) or functions, so chart configs stay\n * serializable (JSON attributes, SSR). Pass an explicit `locale` when\n * rendering on the server, otherwise server and browser may disagree.\n */\n\n/** Locale(s) passed to `Intl`; `undefined` uses the runtime default. */\nexport type Locale = string | readonly string[] | undefined\n\n/** `Intl.NumberFormat` options, plus suffixes of our own for compact notation. */\nexport interface NumberFormatOptions extends Intl.NumberFormatOptions {\n /**\n * Compact notation with these suffixes for thousands, millions, billions…\n * instead of the locale's words: `['k', 'M', 'G']` writes 1500 as \"1.5k\",\n * or \"1,5k\" in Polish, where the locale itself writes \"1,5 tys.\". `true`\n * stands for `['K', 'M', 'B', 'T']`. Larger numbers keep the last suffix.\n */\n compactSymbols?: boolean | readonly string[]\n}\n\n/** Number format options or a custom formatter. */\nexport type NumberFormat = NumberFormatOptions | ((value: number) => string)\n\n/** `Intl.DateTimeFormat` options or a custom formatter. */\nexport type DateFormat = Intl.DateTimeFormatOptions | ((value: Date) => string)\n\nconst MAX_CACHE = 64\nconst numberCache = /* @__PURE__ */ new Map<string, Intl.NumberFormat>()\nconst dateCache = /* @__PURE__ */ new Map<string, Intl.DateTimeFormat>()\n\nfunction cached<T>(cache: Map<string, T>, key: string, create: () => T): T {\n let value = cache.get(key)\n if (value === undefined) {\n if (cache.size >= MAX_CACHE) cache.clear()\n value = create()\n cache.set(key, value)\n }\n return value\n}\n\nfunction cacheKey(locale: Locale, options: object): string {\n return `${JSON.stringify(locale ?? null)}|${JSON.stringify(options)}`\n}\n\n/** Shared, cached `Intl.NumberFormat` instance. */\nexport function getNumberFormat(\n locale?: Locale,\n options: Intl.NumberFormatOptions = {},\n): Intl.NumberFormat {\n return cached(\n numberCache,\n cacheKey(locale, options),\n () => new Intl.NumberFormat(locale as string | string[] | undefined, options),\n )\n}\n\n/** Shared, cached `Intl.DateTimeFormat` instance. */\nexport function getDateFormat(\n locale?: Locale,\n options: Intl.DateTimeFormatOptions = {},\n): Intl.DateTimeFormat {\n return cached(\n dateCache,\n cacheKey(locale, options),\n () => new Intl.DateTimeFormat(locale as string | string[] | undefined, options),\n )\n}\n\n/** Avoid `-0` rendering as \"-0\". */\nconst unsignedZero = (value: number): number => (value === 0 ? 0 : value)\n\n/**\n * Create a number formatter.\n *\n * ```ts\n * formatNumber({ style: 'currency', currency: 'PLN' }, 'pl-PL')(1234.5) // \"1234,50 zł\"\n * ```\n */\nexport function formatNumber(format?: NumberFormat, locale?: Locale): (value: number) => string {\n if (typeof format === 'function') return format\n const { compactSymbols, ...options } = format ?? {}\n if (compactSymbols) {\n return formatCompact(compactSymbols === true ? SYMBOLS : compactSymbols, options, locale)\n }\n const nf = getNumberFormat(locale, options)\n return (value) => nf.format(unsignedZero(value))\n}\n\nconst SYMBOLS = ['K', 'M', 'B', 'T']\n\n/**\n * Compact notation with the given suffixes: the value divided by its power\n * of a thousand, formatted by `Intl` (separators, currency, sign) with the\n * suffix after the digits. Without digits of its own it rounds like `Intl`'s\n * compact notation: two significant digits below 10, whole numbers above.\n */\nfunction formatCompact(\n symbols: readonly string[],\n // `notation` and `compactDisplay` are taken out: the suffixes replace them.\n { notation, compactDisplay, ...options }: Intl.NumberFormatOptions,\n locale: Locale,\n): (value: number) => string {\n const own = digitsOf(options)\n const small = getNumberFormat(locale, own ? options : { ...options, maximumSignificantDigits: 2 })\n const large = own ? small : getNumberFormat(locale, { ...options, maximumFractionDigits: 0 })\n return (value) => {\n for (let exp = 0; ; exp++) {\n const scaled = unsignedZero(value / 1000 ** exp)\n const parts = (Math.abs(scaled) < 10 ? small : large).formatToParts(scaled)\n let digits = ''\n let last: Intl.NumberFormatPart | undefined\n for (const part of parts) {\n if (part.type === 'integer') digits += part.value\n if (part.type === 'integer' || part.type === 'fraction') last = part\n }\n // Four digits or more: a thousand times smaller, with the next suffix\n // (so 999 950 rounds up to \"1M\", not \"1000K\").\n if (digits.length < 4 || exp >= symbols.length) {\n if (exp && last) last.value += symbols[exp - 1]\n return parts.map((part) => part.value).join('')\n }\n }\n }\n}\n\n/** Whether number options write compact numbers (\"25K\"). */\nconst compactOf = (o: NumberFormatOptions): boolean =>\n o.notation === 'compact' || !!o.compactSymbols\n\n/** Whether number options set their digits (fraction or significant). */\nconst digitsOf = (o: Intl.NumberFormatOptions): boolean =>\n (o.minimumFractionDigits ??\n o.maximumFractionDigits ??\n o.minimumSignificantDigits ??\n o.maximumSignificantDigits) !== undefined\n\n/**\n * A formatter for values read one at a time (tooltips, data tables) in an\n * axis format. Compact notation suits ticks (\"$25K\") but hides the\n * difference between values: unless the format sets its own precision, it\n * keeps three significant digits (\"$24.8K\").\n */\nexport function formatDetail(format?: NumberFormat, locale?: Locale): (value: number) => string {\n return formatNumber(\n typeof format === 'object' && compactOf(format) && !digitsOf(format)\n ? { ...format, maximumSignificantDigits: 3 }\n : format,\n locale,\n )\n}\n/**\n * Number of fraction digits needed to tell apart ticks `step` apart,\n * e.g. `1 → 0`, `0.2 → 1`, `0.05 → 2`.\n */\nexport function stepPrecision(step: number): number {\n const abs = Math.abs(step)\n if (!Number.isFinite(abs) || abs === 0) return 0\n return Math.max(0, -Math.floor(Math.log10(abs) + 1e-9))\n}\n\nfunction hasPrecision(options: NumberFormatOptions): boolean {\n return (\n digitsOf(options) || !!options.compactSymbols || (options.notation ?? 'standard') !== 'standard'\n )\n}\n/**\n * Create a formatter for axis ticks `step` apart. Unless `format` sets its\n * own precision, every tick gets the same number of fraction digits, derived\n * from the step (`0, 0.5, 1` → `0.0, 0.5, 1.0`).\n */\nexport function formatTicks(\n step: number,\n format?: NumberFormat,\n locale?: Locale,\n): (value: number) => string {\n if (typeof format === 'function') return format\n const options = format ?? {}\n if (hasPrecision(options)) return formatNumber(options, locale)\n\n let digits = stepPrecision(step)\n if (options.style === 'percent') digits = Math.max(0, digits - 2)\n const fmt = formatNumber(\n { ...options, minimumFractionDigits: digits, maximumFractionDigits: digits },\n locale,\n )\n // Values within floating point noise of zero (e.g. 1e-17) print as zero.\n const epsilon = Math.abs(step) * 1e-9\n return (value) => fmt(Math.abs(value) < epsilon ? 0 : value)\n}\n\n/**\n * Create a date formatter accepting `Date` objects or timestamps.\n *\n * ```ts\n * formatDate({ month: 'short', day: 'numeric' }, 'en-US')(new Date(2026, 0, 5)) // \"Jan 5\"\n * ```\n */\nexport function formatDate(format?: DateFormat, locale?: Locale): (value: Date | number) => string {\n if (typeof format === 'function') {\n return (value) => format(typeof value === 'number' ? new Date(value) : value)\n }\n const df = getDateFormat(locale, format)\n return (value) => df.format(value)\n}\n"],"mappings":";AA6BA,MAAM,YAAY;AAClB,MAAM,8BAA8B,IAAI,IAA+B;AACvE,MAAM,4BAA4B,IAAI,IAAiC;AAEvE,SAAS,OAAU,OAAuB,KAAa,QAAoB;CACzE,IAAI,QAAQ,MAAM,IAAI,GAAG;CACzB,IAAI,UAAU,KAAA,GAAW;EACvB,IAAI,MAAM,QAAQ,WAAW,MAAM,MAAM;EACzC,QAAQ,OAAO;EACf,MAAM,IAAI,KAAK,KAAK;CACtB;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,UAAU,WAAW,SAAS,KAAK,IAAI,GAAG,SAAS,CAAC;CAChE,MAAM,MAAM,aACV;EAAE,GAAG;EAAS,uBAAuB;EAAQ,uBAAuB;CAAO,GAC3E,MACF;CAEA,MAAM,UAAU,KAAK,IAAI,IAAI,IAAI;CACjC,QAAQ,UAAU,IAAI,KAAK,IAAI,KAAK,IAAI,UAAU,IAAI,KAAK;AAC7D;;;;;;;;AASA,SAAgB,WAAW,QAAqB,QAAmD;CACjG,IAAI,OAAO,WAAW,YACpB,QAAQ,UAAU,OAAO,OAAO,UAAU,WAAW,IAAI,KAAK,KAAK,IAAI,KAAK;CAE9E,MAAM,KAAK,cAAc,QAAQ,MAAM;CACvC,QAAQ,UAAU,GAAG,OAAO,KAAK;AACnC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/format.ts
|
|
2
2
|
const MAX_CACHE = 64;
|
|
3
3
|
const numberCache = /* @__PURE__ */ new Map();
|
|
4
4
|
const dateCache = /* @__PURE__ */ new Map();
|
|
@@ -136,7 +136,6 @@ function formatDate(format, locale) {
|
|
|
136
136
|
const df = getDateFormat(locale, format);
|
|
137
137
|
return (value) => df.format(value);
|
|
138
138
|
}
|
|
139
|
-
//#endregion
|
|
140
139
|
export { getDateFormat as a, formatTicks as i, formatDetail as n, getNumberFormat as o, formatNumber as r, stepPrecision as s, formatDate as t };
|
|
141
140
|
|
|
142
|
-
//# sourceMappingURL=format-
|
|
141
|
+
//# sourceMappingURL=format-it1kepFG.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format-lStwuc1L.js","names":[],"sources":["../src/format.ts"],"sourcesContent":["/**\n * Number and date formatting built on `Intl` — locale aware, zero bytes of\n * locale data shipped.\n *\n * Formats are plain data (`Intl` options) or functions, so chart configs stay\n * serializable (JSON attributes, SSR). Pass an explicit `locale` when\n * rendering on the server, otherwise server and browser may disagree.\n */\n\n/** Locale(s) passed to `Intl`; `undefined` uses the runtime default. */\nexport type Locale = string | readonly string[] | undefined\n\n/** `Intl.NumberFormat` options, plus suffixes of our own for compact notation. */\nexport interface NumberFormatOptions extends Intl.NumberFormatOptions {\n /**\n * Compact notation with these suffixes for thousands, millions, billions…\n * instead of the locale's words: `['k', 'M', 'G']` writes 1500 as \"1.5k\",\n * or \"1,5k\" in Polish, where the locale itself writes \"1,5 tys.\". `true`\n * stands for `['K', 'M', 'B', 'T']`. Larger numbers keep the last suffix.\n */\n compactSymbols?: boolean | readonly string[]\n}\n\n/** Number format options or a custom formatter. */\nexport type NumberFormat = NumberFormatOptions | ((value: number) => string)\n\n/** `Intl.DateTimeFormat` options or a custom formatter. */\nexport type DateFormat = Intl.DateTimeFormatOptions | ((value: Date) => string)\n\nconst MAX_CACHE = 64\nconst numberCache = /* @__PURE__ */ new Map<string, Intl.NumberFormat>()\nconst dateCache = /* @__PURE__ */ new Map<string, Intl.DateTimeFormat>()\n\nfunction cached<T>(cache: Map<string, T>, key: string, create: () => T): T {\n let value = cache.get(key)\n if (value === undefined) {\n if (cache.size >= MAX_CACHE) cache.clear()\n value = create()\n cache.set(key, value)\n }\n return value\n}\n\nfunction cacheKey(locale: Locale, options: object): string {\n return `${JSON.stringify(locale ?? null)}|${JSON.stringify(options)}`\n}\n\n/** Shared, cached `Intl.NumberFormat` instance. */\nexport function getNumberFormat(\n locale?: Locale,\n options: Intl.NumberFormatOptions = {},\n): Intl.NumberFormat {\n return cached(\n numberCache,\n cacheKey(locale, options),\n () => new Intl.NumberFormat(locale as string | string[] | undefined, options),\n )\n}\n\n/** Shared, cached `Intl.DateTimeFormat` instance. */\nexport function getDateFormat(\n locale?: Locale,\n options: Intl.DateTimeFormatOptions = {},\n): Intl.DateTimeFormat {\n return cached(\n dateCache,\n cacheKey(locale, options),\n () => new Intl.DateTimeFormat(locale as string | string[] | undefined, options),\n )\n}\n\n/** Avoid `-0` rendering as \"-0\". */\nconst unsignedZero = (value: number): number => (value === 0 ? 0 : value)\n\n/**\n * Create a number formatter.\n *\n * ```ts\n * formatNumber({ style: 'currency', currency: 'PLN' }, 'pl-PL')(1234.5) // \"1234,50 zł\"\n * ```\n */\nexport function formatNumber(format?: NumberFormat, locale?: Locale): (value: number) => string {\n if (typeof format === 'function') return format\n const { compactSymbols, ...options } = format ?? {}\n if (compactSymbols) {\n return formatCompact(compactSymbols === true ? SYMBOLS : compactSymbols, options, locale)\n }\n const nf = getNumberFormat(locale, options)\n return (value) => nf.format(unsignedZero(value))\n}\n\nconst SYMBOLS = ['K', 'M', 'B', 'T']\n\n/**\n * Compact notation with the given suffixes: the value divided by its power\n * of a thousand, formatted by `Intl` (separators, currency, sign) with the\n * suffix after the digits. Without digits of its own it rounds like `Intl`'s\n * compact notation: two significant digits below 10, whole numbers above.\n */\nfunction formatCompact(\n symbols: readonly string[],\n // `notation` and `compactDisplay` are taken out: the suffixes replace them.\n { notation, compactDisplay, ...options }: Intl.NumberFormatOptions,\n locale: Locale,\n): (value: number) => string {\n const own = digitsOf(options)\n const small = getNumberFormat(locale, own ? options : { ...options, maximumSignificantDigits: 2 })\n const large = own ? small : getNumberFormat(locale, { ...options, maximumFractionDigits: 0 })\n return (value) => {\n for (let exp = 0; ; exp++) {\n const scaled = unsignedZero(value / 1000 ** exp)\n const parts = (Math.abs(scaled) < 10 ? small : large).formatToParts(scaled)\n let digits = ''\n let last: Intl.NumberFormatPart | undefined\n for (const part of parts) {\n if (part.type === 'integer') digits += part.value\n if (part.type === 'integer' || part.type === 'fraction') last = part\n }\n // Four digits or more: a thousand times smaller, with the next suffix\n // (so 999 950 rounds up to \"1M\", not \"1000K\").\n if (digits.length < 4 || exp >= symbols.length) {\n if (exp && last) last.value += symbols[exp - 1]\n return parts.map((part) => part.value).join('')\n }\n }\n }\n}\n\n/** Whether number options write compact numbers (\"25K\"). */\nconst compactOf = (o: NumberFormatOptions): boolean =>\n o.notation === 'compact' || !!o.compactSymbols\n\n/** Whether number options set their digits (fraction or significant). */\nconst digitsOf = (o: Intl.NumberFormatOptions): boolean =>\n (o.minimumFractionDigits ??\n o.maximumFractionDigits ??\n o.minimumSignificantDigits ??\n o.maximumSignificantDigits) !== undefined\n\n/**\n * A formatter for values read one at a time (tooltips, data tables) in an\n * axis format. Compact notation suits ticks (\"$25K\") but hides the\n * difference between values: unless the format sets its own precision, it\n * keeps three significant digits (\"$24.8K\").\n */\nexport function formatDetail(format?: NumberFormat, locale?: Locale): (value: number) => string {\n return formatNumber(\n typeof format === 'object' && compactOf(format) && !digitsOf(format)\n ? { ...format, maximumSignificantDigits: 3 }\n : format,\n locale,\n )\n}\n/**\n * Number of fraction digits needed to tell apart ticks `step` apart,\n * e.g. `1 → 0`, `0.2 → 1`, `0.05 → 2`.\n */\nexport function stepPrecision(step: number): number {\n const abs = Math.abs(step)\n if (!Number.isFinite(abs) || abs === 0) return 0\n return Math.max(0, -Math.floor(Math.log10(abs) + 1e-9))\n}\n\nfunction hasPrecision(options: NumberFormatOptions): boolean {\n return (\n digitsOf(options) || !!options.compactSymbols || (options.notation ?? 'standard') !== 'standard'\n )\n}\n/**\n * Create a formatter for axis ticks `step` apart. Unless `format` sets its\n * own precision, every tick gets the same number of fraction digits, derived\n * from the step (`0, 0.5, 1` → `0.0, 0.5, 1.0`).\n */\nexport function formatTicks(\n step: number,\n format?: NumberFormat,\n locale?: Locale,\n): (value: number) => string {\n if (typeof format === 'function') return format\n const options = format ?? {}\n if (hasPrecision(options)) return formatNumber(options, locale)\n\n let digits = stepPrecision(step)\n if (options.style === 'percent') digits = Math.max(0, digits - 2)\n const fmt = formatNumber(\n { ...options, minimumFractionDigits: digits, maximumFractionDigits: digits },\n locale,\n )\n // Values within floating point noise of zero (e.g. 1e-17) print as zero.\n const epsilon = Math.abs(step) * 1e-9\n return (value) => fmt(Math.abs(value) < epsilon ? 0 : value)\n}\n\n/**\n * Create a date formatter accepting `Date` objects or timestamps.\n *\n * ```ts\n * formatDate({ month: 'short', day: 'numeric' }, 'en-US')(new Date(2026, 0, 5)) // \"Jan 5\"\n * ```\n */\nexport function formatDate(format?: DateFormat, locale?: Locale): (value: Date | number) => string {\n if (typeof format === 'function') {\n return (value) => format(typeof value === 'number' ? new Date(value) : value)\n }\n const df = getDateFormat(locale, format)\n return (value) => df.format(value)\n}\n"],"mappings":";AA6BA,MAAM,YAAY;AAClB,MAAM,8BAA8B,IAAI,IAA+B;AACvE,MAAM,4BAA4B,IAAI,IAAiC;AAEvE,SAAS,OAAU,OAAuB,KAAa,QAAoB;CACzE,IAAI,QAAQ,MAAM,IAAI,GAAG;CACzB,IAAI,UAAU,KAAA,GAAW;EACvB,IAAI,MAAM,QAAQ,WAAW,MAAM,MAAM;EACzC,QAAQ,OAAO;EACf,MAAM,IAAI,KAAK,KAAK;CACtB;CACA,OAAO;AACT;AAEA,SAAS,SAAS,QAAgB,SAAyB;CACzD,OAAO,GAAG,KAAK,UAAU,UAAU,IAAI,EAAE,GAAG,KAAK,UAAU,OAAO;AACpE;;AAGA,SAAgB,gBACd,QACA,UAAoC,CAAC,GAClB;CACnB,OAAO,OACL,aACA,SAAS,QAAQ,OAAO,SAClB,IAAI,KAAK,aAAa,QAAyC,OAAO,CAC9E;AACF;;AAGA,SAAgB,cACd,QACA,UAAsC,CAAC,GAClB;CACrB,OAAO,OACL,WACA,SAAS,QAAQ,OAAO,SAClB,IAAI,KAAK,eAAe,QAAyC,OAAO,CAChF;AACF;;AAGA,MAAM,gBAAgB,UAA2B,UAAU,IAAI,IAAI;;;;;;;;AASnE,SAAgB,aAAa,QAAuB,QAA4C;CAC9F,IAAI,OAAO,WAAW,YAAY,OAAO;CACzC,MAAM,EAAE,gBAAgB,GAAG,YAAY,UAAU,CAAC;CAClD,IAAI,gBACF,OAAO,cAAc,mBAAmB,OAAO,UAAU,gBAAgB,SAAS,MAAM;CAE1F,MAAM,KAAK,gBAAgB,QAAQ,OAAO;CAC1C,QAAQ,UAAU,GAAG,OAAO,aAAa,KAAK,CAAC;AACjD;AAEA,MAAM,UAAU;CAAC;CAAK;CAAK;CAAK;AAAG;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AG,KAAK,QAAQ,GAAG,OAAO;CAC/C,OAAO,KAAK,IAAI,GAAG,CAAC,KAAK,MAAM,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC;AACxD;AAEA,SAAS,aAAa,SAAuC;CAC3D,OACE,SAAS,OAAO,KAAK,CAAC,CAAC,QAAQ,mBAAmB,QAAQ,YAAY,gBAAgB;AAE1F;;;;;;AAMA,SAAgB,YACd,MACA,QACA,QAC2B;CAC3B,IAAI,OAAO,WAAW,YAAY,OAAO;CACzC,MAAM,UAAU,UAAU,CAAC;CAC3B,IAAI,aAAa,OAAO,GAAG,OAAO,aAAa,SAAS,MAAM;CAE9D,IAAI,SAAS,cAAc,IAAI;CAC/B,IAAI,QAAQ,UAAU,WAAW,SAAS,KAAK,IAAI,GAAG,SAAS,CAAC;CAChE,MAAM,MAAM,aACV;EAAE,GAAG;EAAS,uBAAuB;EAAQ,uBAAuB;CAAO,GAC3E,MACF;CAEA,MAAM,UAAU,KAAK,IAAI,IAAI,IAAI;CACjC,QAAQ,UAAU,IAAI,KAAK,IAAI,KAAK,IAAI,UAAU,IAAI,KAAK;AAC7D;;;;;;;;AASA,SAAgB,WAAW,QAAqB,QAAmD;CACjG,IAAI,OAAO,WAAW,YACpB,QAAQ,UAAU,OAAO,OAAO,UAAU,WAAW,IAAI,KAAK,KAAK,IAAI,KAAK;CAE9E,MAAM,KAAK,cAAc,QAAQ,MAAM;CACvC,QAAQ,UAAU,GAAG,OAAO,KAAK;AACnC"}
|
|
1
|
+
{"version":3,"file":"format-it1kepFG.js","names":[],"sources":["../src/format.ts"],"sourcesContent":["/**\n * Number and date formatting built on `Intl` — locale aware, zero bytes of\n * locale data shipped.\n *\n * Formats are plain data (`Intl` options) or functions, so chart configs stay\n * serializable (JSON attributes, SSR). Pass an explicit `locale` when\n * rendering on the server, otherwise server and browser may disagree.\n */\n\n/** Locale(s) passed to `Intl`; `undefined` uses the runtime default. */\nexport type Locale = string | readonly string[] | undefined\n\n/** `Intl.NumberFormat` options, plus suffixes of our own for compact notation. */\nexport interface NumberFormatOptions extends Intl.NumberFormatOptions {\n /**\n * Compact notation with these suffixes for thousands, millions, billions…\n * instead of the locale's words: `['k', 'M', 'G']` writes 1500 as \"1.5k\",\n * or \"1,5k\" in Polish, where the locale itself writes \"1,5 tys.\". `true`\n * stands for `['K', 'M', 'B', 'T']`. Larger numbers keep the last suffix.\n */\n compactSymbols?: boolean | readonly string[]\n}\n\n/** Number format options or a custom formatter. */\nexport type NumberFormat = NumberFormatOptions | ((value: number) => string)\n\n/** `Intl.DateTimeFormat` options or a custom formatter. */\nexport type DateFormat = Intl.DateTimeFormatOptions | ((value: Date) => string)\n\nconst MAX_CACHE = 64\nconst numberCache = /* @__PURE__ */ new Map<string, Intl.NumberFormat>()\nconst dateCache = /* @__PURE__ */ new Map<string, Intl.DateTimeFormat>()\n\nfunction cached<T>(cache: Map<string, T>, key: string, create: () => T): T {\n let value = cache.get(key)\n if (value === undefined) {\n if (cache.size >= MAX_CACHE) cache.clear()\n value = create()\n cache.set(key, value)\n }\n return value\n}\n\nfunction cacheKey(locale: Locale, options: object): string {\n return `${JSON.stringify(locale ?? null)}|${JSON.stringify(options)}`\n}\n\n/** Shared, cached `Intl.NumberFormat` instance. */\nexport function getNumberFormat(\n locale?: Locale,\n options: Intl.NumberFormatOptions = {},\n): Intl.NumberFormat {\n return cached(\n numberCache,\n cacheKey(locale, options),\n () => new Intl.NumberFormat(locale as string | string[] | undefined, options),\n )\n}\n\n/** Shared, cached `Intl.DateTimeFormat` instance. */\nexport function getDateFormat(\n locale?: Locale,\n options: Intl.DateTimeFormatOptions = {},\n): Intl.DateTimeFormat {\n return cached(\n dateCache,\n cacheKey(locale, options),\n () => new Intl.DateTimeFormat(locale as string | string[] | undefined, options),\n )\n}\n\n/** Avoid `-0` rendering as \"-0\". */\nconst unsignedZero = (value: number): number => (value === 0 ? 0 : value)\n\n/**\n * Create a number formatter.\n *\n * ```ts\n * formatNumber({ style: 'currency', currency: 'PLN' }, 'pl-PL')(1234.5) // \"1234,50 zł\"\n * ```\n */\nexport function formatNumber(format?: NumberFormat, locale?: Locale): (value: number) => string {\n if (typeof format === 'function') return format\n const { compactSymbols, ...options } = format ?? {}\n if (compactSymbols) {\n return formatCompact(compactSymbols === true ? SYMBOLS : compactSymbols, options, locale)\n }\n const nf = getNumberFormat(locale, options)\n return (value) => nf.format(unsignedZero(value))\n}\n\nconst SYMBOLS = ['K', 'M', 'B', 'T']\n\n/**\n * Compact notation with the given suffixes: the value divided by its power\n * of a thousand, formatted by `Intl` (separators, currency, sign) with the\n * suffix after the digits. Without digits of its own it rounds like `Intl`'s\n * compact notation: two significant digits below 10, whole numbers above.\n */\nfunction formatCompact(\n symbols: readonly string[],\n // `notation` and `compactDisplay` are taken out: the suffixes replace them.\n { notation, compactDisplay, ...options }: Intl.NumberFormatOptions,\n locale: Locale,\n): (value: number) => string {\n const own = digitsOf(options)\n const small = getNumberFormat(locale, own ? options : { ...options, maximumSignificantDigits: 2 })\n const large = own ? small : getNumberFormat(locale, { ...options, maximumFractionDigits: 0 })\n return (value) => {\n for (let exp = 0; ; exp++) {\n const scaled = unsignedZero(value / 1000 ** exp)\n const parts = (Math.abs(scaled) < 10 ? small : large).formatToParts(scaled)\n let digits = ''\n let last: Intl.NumberFormatPart | undefined\n for (const part of parts) {\n if (part.type === 'integer') digits += part.value\n if (part.type === 'integer' || part.type === 'fraction') last = part\n }\n // Four digits or more: a thousand times smaller, with the next suffix\n // (so 999 950 rounds up to \"1M\", not \"1000K\").\n if (digits.length < 4 || exp >= symbols.length) {\n if (exp && last) last.value += symbols[exp - 1]\n return parts.map((part) => part.value).join('')\n }\n }\n }\n}\n\n/** Whether number options write compact numbers (\"25K\"). */\nconst compactOf = (o: NumberFormatOptions): boolean =>\n o.notation === 'compact' || !!o.compactSymbols\n\n/** Whether number options set their digits (fraction or significant). */\nconst digitsOf = (o: Intl.NumberFormatOptions): boolean =>\n (o.minimumFractionDigits ??\n o.maximumFractionDigits ??\n o.minimumSignificantDigits ??\n o.maximumSignificantDigits) !== undefined\n\n/**\n * A formatter for values read one at a time (tooltips, data tables) in an\n * axis format. Compact notation suits ticks (\"$25K\") but hides the\n * difference between values: unless the format sets its own precision, it\n * keeps three significant digits (\"$24.8K\").\n */\nexport function formatDetail(format?: NumberFormat, locale?: Locale): (value: number) => string {\n return formatNumber(\n typeof format === 'object' && compactOf(format) && !digitsOf(format)\n ? { ...format, maximumSignificantDigits: 3 }\n : format,\n locale,\n )\n}\n/**\n * Number of fraction digits needed to tell apart ticks `step` apart,\n * e.g. `1 → 0`, `0.2 → 1`, `0.05 → 2`.\n */\nexport function stepPrecision(step: number): number {\n const abs = Math.abs(step)\n if (!Number.isFinite(abs) || abs === 0) return 0\n return Math.max(0, -Math.floor(Math.log10(abs) + 1e-9))\n}\n\nfunction hasPrecision(options: NumberFormatOptions): boolean {\n return (\n digitsOf(options) || !!options.compactSymbols || (options.notation ?? 'standard') !== 'standard'\n )\n}\n/**\n * Create a formatter for axis ticks `step` apart. Unless `format` sets its\n * own precision, every tick gets the same number of fraction digits, derived\n * from the step (`0, 0.5, 1` → `0.0, 0.5, 1.0`).\n */\nexport function formatTicks(\n step: number,\n format?: NumberFormat,\n locale?: Locale,\n): (value: number) => string {\n if (typeof format === 'function') return format\n const options = format ?? {}\n if (hasPrecision(options)) return formatNumber(options, locale)\n\n let digits = stepPrecision(step)\n if (options.style === 'percent') digits = Math.max(0, digits - 2)\n const fmt = formatNumber(\n { ...options, minimumFractionDigits: digits, maximumFractionDigits: digits },\n locale,\n )\n // Values within floating point noise of zero (e.g. 1e-17) print as zero.\n const epsilon = Math.abs(step) * 1e-9\n return (value) => fmt(Math.abs(value) < epsilon ? 0 : value)\n}\n\n/**\n * Create a date formatter accepting `Date` objects or timestamps.\n *\n * ```ts\n * formatDate({ month: 'short', day: 'numeric' }, 'en-US')(new Date(2026, 0, 5)) // \"Jan 5\"\n * ```\n */\nexport function formatDate(format?: DateFormat, locale?: Locale): (value: Date | number) => string {\n if (typeof format === 'function') {\n return (value) => format(typeof value === 'number' ? new Date(value) : value)\n }\n const df = getDateFormat(locale, format)\n return (value) => df.format(value)\n}\n"],"mappings":";AA6BA,MAAM,YAAY;AAClB,MAAM,8BAA8B,IAAI,IAA+B;AACvE,MAAM,4BAA4B,IAAI,IAAiC;AAEvE,SAAS,OAAU,OAAuB,KAAa,QAAoB;CACzE,IAAI,QAAQ,MAAM,IAAI,GAAG;CACzB,IAAI,UAAU,KAAA,GAAW;EACvB,IAAI,MAAM,QAAQ,WAAW,MAAM,MAAM;EACzC,QAAQ,OAAO;EACf,MAAM,IAAI,KAAK,KAAK;CACtB;CACA,OAAO;AACT;AAEA,SAAS,SAAS,QAAgB,SAAyB;CACzD,OAAO,GAAG,KAAK,UAAU,UAAU,IAAI,EAAE,GAAG,KAAK,UAAU,OAAO;AACpE;;AAGA,SAAgB,gBACd,QACA,UAAoC,CAAC,GAClB;CACnB,OAAO,OACL,aACA,SAAS,QAAQ,OAAO,SAClB,IAAI,KAAK,aAAa,QAAyC,OAAO,CAC9E;AACF;;AAGA,SAAgB,cACd,QACA,UAAsC,CAAC,GAClB;CACrB,OAAO,OACL,WACA,SAAS,QAAQ,OAAO,SAClB,IAAI,KAAK,eAAe,QAAyC,OAAO,CAChF;AACF;;AAGA,MAAM,gBAAgB,UAA2B,UAAU,IAAI,IAAI;;;;;;;;AASnE,SAAgB,aAAa,QAAuB,QAA4C;CAC9F,IAAI,OAAO,WAAW,YAAY,OAAO;CACzC,MAAM,EAAE,gBAAgB,GAAG,YAAY,UAAU,CAAC;CAClD,IAAI,gBACF,OAAO,cAAc,mBAAmB,OAAO,UAAU,gBAAgB,SAAS,MAAM;CAE1F,MAAM,KAAK,gBAAgB,QAAQ,OAAO;CAC1C,QAAQ,UAAU,GAAG,OAAO,aAAa,KAAK,CAAC;AACjD;AAEA,MAAM,UAAU;CAAC;CAAK;CAAK;CAAK;AAAG;;;;;;;AAQnC,SAAS,cACP,SAEA,EAAE,UAAU,gB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K,IAAI,GAAG,CAAC,KAAK,MAAM,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC;AACxD;AAEA,SAAS,aAAa,SAAuC;CAC3D,OACE,SAAS,OAAO,KAAK,CAAC,CAAC,QAAQ,mBAAmB,QAAQ,YAAY,gBAAgB;AAE1F;;;;;;AAMA,SAAgB,YACd,MACA,QACA,QAC2B;CAC3B,IAAI,OAAO,WAAW,YAAY,OAAO;CACzC,MAAM,UAAU,UAAU,CAAC;CAC3B,IAAI,aAAa,OAAO,GAAG,OAAO,aAAa,SAAS,MAAM;CAE9D,IAAI,SAAS,cAAc,IAAI;CAC/B,IAAI,QAAQ,UAAU,WAAW,SAAS,KAAK,IAAI,GAAG,SAAS,CAAC;CAChE,MAAM,MAAM,aACV;EAAE,GAAG;EAAS,uBAAuB;EAAQ,uBAAuB;CAAO,GAC3E,MACF;CAEA,MAAM,UAAU,KAAK,IAAI,IAAI,IAAI;CACjC,QAAQ,UAAU,IAAI,KAAK,IAAI,KAAK,IAAI,UAAU,IAAI,KAAK;AAC7D;;;;;;;;AASA,SAAgB,WAAW,QAAqB,QAAmD;CACjG,IAAI,OAAO,WAAW,YACpB,QAAQ,UAAU,OAAO,OAAO,UAAU,WAAW,IAAI,KAAK,KAAK,IAAI,KAAK;CAE9E,MAAM,KAAK,cAAc,QAAQ,MAAM;CACvC,QAAQ,UAAU,GAAG,OAAO,KAAK;AACnC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { o as ChartType } from "./chart-CYrrUCi3.js";
|
|
2
|
+
import { c as NumberFormat } from "./time-DRIDgv2a.js";
|
|
3
|
+
import { a as InsetsInput } from "./annotations-B02GR_KU.js";
|
|
4
|
+
import { a as ClassValue } from "./vnode-Du2cC8Fm.js";
|
|
5
|
+
/** One stage of a funnel. */
|
|
6
|
+
interface FunnelStage {
|
|
7
|
+
name: string;
|
|
8
|
+
/** How many reached the stage. Stages without a number, or with a negative one, are left out. */
|
|
9
|
+
value: number;
|
|
10
|
+
/** Stable identity for keyed updates. Defaults to `name`. */
|
|
11
|
+
id?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Custom color, drawn as it is instead of the stage's shade of `--tc-funnel-color`.
|
|
14
|
+
* Values that could inject CSS (`;`, quotes, `url()` …) are ignored, so colors from user data are safe.
|
|
15
|
+
*/
|
|
16
|
+
color?: string;
|
|
17
|
+
/** Extra classes on the stage's shape. */
|
|
18
|
+
class?: ClassValue;
|
|
19
|
+
}
|
|
20
|
+
interface FunnelOptions {
|
|
21
|
+
/** Stages in the order of the process; they are drawn as they come, not sorted. */
|
|
22
|
+
data: readonly FunnelStage[];
|
|
23
|
+
/** Name, value and share of the first stage written above every stage. Defaults to `true`. */
|
|
24
|
+
labels?: boolean;
|
|
25
|
+
/** Radius of the top corners of the stages. Defaults to `4`. */
|
|
26
|
+
radius?: number;
|
|
27
|
+
/** Format of the values (labels, tooltip, table). */
|
|
28
|
+
format?: NumberFormat;
|
|
29
|
+
/** Extra space around the chart, in pixels. */
|
|
30
|
+
padding?: InsetsInput;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Funnel: how many get from one stage of a process to the next. Every stage
|
|
34
|
+
* is a column with its name, its value and its share of the first stage on
|
|
35
|
+
* top; the shapes below step down from each stage's height to the next, in
|
|
36
|
+
* one color that deepens as the funnel narrows (`--tc-funnel-color`).
|
|
37
|
+
*
|
|
38
|
+
* ```ts
|
|
39
|
+
* new Chart('#el', {
|
|
40
|
+
* type: funnel,
|
|
41
|
+
* data: [
|
|
42
|
+
* { name: 'Visits', value: 12400 },
|
|
43
|
+
* { name: 'Signups', value: 3100 },
|
|
44
|
+
* { name: 'Purchases', value: 620 },
|
|
45
|
+
* ],
|
|
46
|
+
* })
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
declare const funnel: ChartType<FunnelOptions>;
|
|
50
|
+
export { FunnelStage as n, funnel as r, FunnelOptions as t };
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
const require_format = require("./format-CAE5ruy6.cjs");
|
|
2
|
+
const require_layout = require("./layout-Cfg9x1k2.cjs");
|
|
3
|
+
const require_vnode = require("./vnode-ClAiw28x.cjs");
|
|
4
|
+
const require_clean = require("./clean-Die2iCNc.cjs");
|
|
5
|
+
const require_fit = require("./fit-D4MIIQQz.cjs");
|
|
6
|
+
const require_named = require("./named-BBASc8dW.cjs");
|
|
7
|
+
// src/charts/funnel.ts
|
|
8
|
+
/** Space between a column's left edge and its text (none in the first column). */
|
|
9
|
+
const INSET = 10;
|
|
10
|
+
/** Share of the full color in the first stage; the last one takes all of it. */
|
|
11
|
+
const PALEST = .3;
|
|
12
|
+
const COLOR = "var(--tc-funnel-color,var(--tc-color-1))";
|
|
13
|
+
const share = (value, of) => of > 0 ? value / of : 0;
|
|
14
|
+
function stagesOf(options) {
|
|
15
|
+
const first = options.data[0]?.value ?? 0;
|
|
16
|
+
return options.data.map((data, i) => ({
|
|
17
|
+
data,
|
|
18
|
+
value: data.value,
|
|
19
|
+
ofFirst: i === 0 ? 1 : share(data.value, first),
|
|
20
|
+
ofPrevious: i === 0 ? 1 : share(data.value, options.data[i - 1].value)
|
|
21
|
+
}));
|
|
22
|
+
}
|
|
23
|
+
/** Share of the full color in stage `i` of `count`: paler where the funnel is wide. */
|
|
24
|
+
const shadeOf = (i, count) => require_layout.round((count > 1 ? PALEST + .7 * i / (count - 1) : 1) * 100);
|
|
25
|
+
/** Corner of radius `r` that takes at most half of either edge it sits on. */
|
|
26
|
+
const corner = (r, edgeX, edgeY) => Math.max(0, Math.min(r, edgeX / 2, edgeY / 2));
|
|
27
|
+
/**
|
|
28
|
+
* A stage from `x0` to `x1`, standing on `floor`: its top runs from its own
|
|
29
|
+
* height `y0` to the next stage's `y1`, with both top corners rounded.
|
|
30
|
+
*/
|
|
31
|
+
function stagePath(x0, x1, y0, y1, floor, radius) {
|
|
32
|
+
const dx = x1 - x0;
|
|
33
|
+
const dy = y1 - y0;
|
|
34
|
+
const near = corner(radius, dx, floor - y0);
|
|
35
|
+
const far = corner(radius, dx, floor - y1);
|
|
36
|
+
const tn = dx > 0 ? near / dx : 0;
|
|
37
|
+
const tf = dx > 0 ? far / dx : 0;
|
|
38
|
+
const n = require_layout.round;
|
|
39
|
+
return `M${n(x0)},${n(y0 + near)}Q${n(x0)},${n(y0)},${n(x0 + dx * tn)},${n(y0 + dy * tn)}L${n(x1 - dx * tf)},${n(y1 - dy * tf)}Q${n(x1)},${n(y1)},${n(x1)},${n(y1 + far)}L${n(x1)},${n(floor)}L${n(x0)},${n(floor)}Z`;
|
|
40
|
+
}
|
|
41
|
+
function renderFunnel(options, ctx) {
|
|
42
|
+
const { width, height, fontSize, locale } = ctx;
|
|
43
|
+
const radius = Math.max(0, options.radius ?? 4);
|
|
44
|
+
const area = require_layout.innerRect(width, height, require_layout.insets(options.padding, 0));
|
|
45
|
+
const stages = stagesOf(options);
|
|
46
|
+
const count = stages.length;
|
|
47
|
+
if (count === 0) return { content: null };
|
|
48
|
+
const value = require_format.formatNumber(options.format, locale);
|
|
49
|
+
const percent = require_format.getNumberFormat(locale, {
|
|
50
|
+
style: "percent",
|
|
51
|
+
maximumFractionDigits: 1
|
|
52
|
+
});
|
|
53
|
+
const short = typeof options.format === "function" ? value : require_format.formatNumber({
|
|
54
|
+
...options.format,
|
|
55
|
+
notation: "compact"
|
|
56
|
+
}, locale);
|
|
57
|
+
const line = fontSize * 1.3;
|
|
58
|
+
const header = options.labels === false ? 0 : Math.min(area.height, line * 3 + 8);
|
|
59
|
+
const floor = area.y + area.height;
|
|
60
|
+
const plot = area.height - header;
|
|
61
|
+
const column = area.width / count;
|
|
62
|
+
const columnX = (i) => area.x + i * column;
|
|
63
|
+
const max = Math.max(0, ...stages.map((stage) => stage.value));
|
|
64
|
+
const top = (v) => floor - (max > 0 ? v / max * plot : 0);
|
|
65
|
+
const colorOf = (i) => stages[i].data.color ?? `color-mix(in oklab,${COLOR} ${shadeOf(i, count)}%,var(--tc-surface))`;
|
|
66
|
+
const hitFor = (i) => {
|
|
67
|
+
const stage = stages[i];
|
|
68
|
+
const x = columnX(i) + column / 2;
|
|
69
|
+
const items = [{
|
|
70
|
+
name: stage.data.name,
|
|
71
|
+
seriesIndex: 0,
|
|
72
|
+
value: stage.value,
|
|
73
|
+
text: value(stage.value),
|
|
74
|
+
x,
|
|
75
|
+
y: top(stage.value),
|
|
76
|
+
color: colorOf(i)
|
|
77
|
+
}];
|
|
78
|
+
const rate = (seriesIndex, of, v) => items.push({
|
|
79
|
+
name: `of ${of.data.name}`,
|
|
80
|
+
seriesIndex,
|
|
81
|
+
value: v,
|
|
82
|
+
text: percent.format(v),
|
|
83
|
+
x,
|
|
84
|
+
y: null,
|
|
85
|
+
color: "transparent"
|
|
86
|
+
});
|
|
87
|
+
if (i > 0) rate(1, stages[0], stage.ofFirst);
|
|
88
|
+
if (i > 1) rate(2, stages[i - 1], stage.ofPrevious);
|
|
89
|
+
return {
|
|
90
|
+
index: i,
|
|
91
|
+
label: stage.data.name,
|
|
92
|
+
title: "",
|
|
93
|
+
x,
|
|
94
|
+
area,
|
|
95
|
+
highlight: {
|
|
96
|
+
kind: "band",
|
|
97
|
+
x: columnX(i),
|
|
98
|
+
y: area.y,
|
|
99
|
+
width: column,
|
|
100
|
+
height: area.height
|
|
101
|
+
},
|
|
102
|
+
items
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
const interaction = {
|
|
106
|
+
count,
|
|
107
|
+
hitIndex: (i) => i >= 0 && i < count ? hitFor(i) : null,
|
|
108
|
+
hitTest(px, py) {
|
|
109
|
+
if (px < area.x || px > area.x + area.width || py < area.y || py > floor) return null;
|
|
110
|
+
return hitFor(Math.min(count - 1, Math.floor((px - area.x) / (column || 1))));
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
const dividers = stages.slice(1).map((stage, i) => require_vnode.h("line", {
|
|
114
|
+
key: require_named.keyOf(stage.data),
|
|
115
|
+
class: "tc-grid-line tc-funnel-divider",
|
|
116
|
+
x1: require_layout.round(columnX(i + 1)),
|
|
117
|
+
x2: require_layout.round(columnX(i + 1)),
|
|
118
|
+
y1: require_layout.round(area.y),
|
|
119
|
+
y2: require_layout.round(floor)
|
|
120
|
+
}));
|
|
121
|
+
const shapes = stages.map((stage, i) => require_vnode.h("path", {
|
|
122
|
+
key: require_named.keyOf(stage.data),
|
|
123
|
+
class: ["tc-funnel-stage", stage.data.class],
|
|
124
|
+
"data-series": stage.data.name,
|
|
125
|
+
d: stagePath(columnX(i), columnX(i + 1), top(stage.value), top((stages[i + 1] ?? stage).value), floor, radius),
|
|
126
|
+
style: {
|
|
127
|
+
"--tc-funnel-color": stage.data.color,
|
|
128
|
+
"--tc-funnel-shade": `${stage.data.color ? 100 : shadeOf(i, count)}%`
|
|
129
|
+
}
|
|
130
|
+
}));
|
|
131
|
+
const labels = header >= line * 3 && stages.flatMap((stage, i) => {
|
|
132
|
+
const inset = i === 0 ? 0 : INSET;
|
|
133
|
+
const room = column - inset - INSET;
|
|
134
|
+
const x = require_layout.round(columnX(i) + inset);
|
|
135
|
+
const y = area.y + fontSize * .85;
|
|
136
|
+
const key = require_named.keyOf(stage.data);
|
|
137
|
+
const fits = (text) => require_layout.estimateTextWidth(text, fontSize) <= room;
|
|
138
|
+
const name = require_fit.fit(stage.data.name, room, fontSize);
|
|
139
|
+
const whole = value(stage.value);
|
|
140
|
+
const amount = fits(whole) ? whole : short(stage.value);
|
|
141
|
+
const rate = i > 0 ? percent.format(stage.ofFirst) : "";
|
|
142
|
+
return [
|
|
143
|
+
name && require_vnode.h("text", {
|
|
144
|
+
key,
|
|
145
|
+
class: "tc-funnel-name",
|
|
146
|
+
x,
|
|
147
|
+
y: require_layout.round(y)
|
|
148
|
+
}, name),
|
|
149
|
+
fits(amount) && require_vnode.h("text", {
|
|
150
|
+
key: `${key}/value`,
|
|
151
|
+
class: "tc-funnel-value",
|
|
152
|
+
x,
|
|
153
|
+
y: require_layout.round(y + line)
|
|
154
|
+
}, amount),
|
|
155
|
+
rate && fits(rate) && require_vnode.h("text", {
|
|
156
|
+
key: `${key}/share`,
|
|
157
|
+
class: "tc-funnel-share",
|
|
158
|
+
x,
|
|
159
|
+
y: require_layout.round(y + line * 2)
|
|
160
|
+
}, rate)
|
|
161
|
+
];
|
|
162
|
+
});
|
|
163
|
+
return {
|
|
164
|
+
content: [
|
|
165
|
+
require_vnode.h("g", {
|
|
166
|
+
class: "tc-funnel-dividers",
|
|
167
|
+
"aria-hidden": "true"
|
|
168
|
+
}, dividers),
|
|
169
|
+
require_vnode.h("g", { class: "tc-funnel-stages" }, shapes),
|
|
170
|
+
labels && require_vnode.h("g", {
|
|
171
|
+
class: "tc-funnel-labels",
|
|
172
|
+
"aria-hidden": "true"
|
|
173
|
+
}, labels)
|
|
174
|
+
],
|
|
175
|
+
interaction
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
function funnelTable(options, ctx, limit) {
|
|
179
|
+
const value = require_format.formatNumber(options.format, ctx.locale);
|
|
180
|
+
const percent = require_format.getNumberFormat(ctx.locale, {
|
|
181
|
+
style: "percent",
|
|
182
|
+
maximumFractionDigits: 1
|
|
183
|
+
});
|
|
184
|
+
const rows = stagesOf(options).map((stage) => [
|
|
185
|
+
stage.data.name,
|
|
186
|
+
value(stage.value),
|
|
187
|
+
percent.format(stage.ofFirst),
|
|
188
|
+
percent.format(stage.ofPrevious)
|
|
189
|
+
]);
|
|
190
|
+
const table = {
|
|
191
|
+
columns: [
|
|
192
|
+
"",
|
|
193
|
+
"Value",
|
|
194
|
+
"Of first",
|
|
195
|
+
"Of previous"
|
|
196
|
+
],
|
|
197
|
+
rows
|
|
198
|
+
};
|
|
199
|
+
if (rows.length > limit) {
|
|
200
|
+
table.rows = rows.slice(0, limit);
|
|
201
|
+
table.total = rows.length;
|
|
202
|
+
}
|
|
203
|
+
return table;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Stages with text for names. A stage that reports no number did not report
|
|
207
|
+
* a zero, and the stage after it would be measured against it: such stages
|
|
208
|
+
* are left out, as are negative counts.
|
|
209
|
+
*/
|
|
210
|
+
const cleanStages = (data) => require_clean.records(data, (r) => ({
|
|
211
|
+
...require_clean.named(r),
|
|
212
|
+
value: require_clean.finite(r.value)
|
|
213
|
+
})).filter((stage) => stage.value !== null && stage.value >= 0);
|
|
214
|
+
/**
|
|
215
|
+
* Funnel: how many get from one stage of a process to the next. Every stage
|
|
216
|
+
* is a column with its name, its value and its share of the first stage on
|
|
217
|
+
* top; the shapes below step down from each stage's height to the next, in
|
|
218
|
+
* one color that deepens as the funnel narrows (`--tc-funnel-color`).
|
|
219
|
+
*
|
|
220
|
+
* ```ts
|
|
221
|
+
* new Chart('#el', {
|
|
222
|
+
* type: funnel,
|
|
223
|
+
* data: [
|
|
224
|
+
* { name: 'Visits', value: 12400 },
|
|
225
|
+
* { name: 'Signups', value: 3100 },
|
|
226
|
+
* { name: 'Purchases', value: 620 },
|
|
227
|
+
* ],
|
|
228
|
+
* })
|
|
229
|
+
* ```
|
|
230
|
+
*/
|
|
231
|
+
const funnel = {
|
|
232
|
+
name: "funnel",
|
|
233
|
+
clean: require_clean.cleanData(cleanStages),
|
|
234
|
+
render: renderFunnel,
|
|
235
|
+
table: funnelTable
|
|
236
|
+
};
|
|
237
|
+
Object.defineProperty(exports, "funnel", {
|
|
238
|
+
enumerable: true,
|
|
239
|
+
get: function() {
|
|
240
|
+
return funnel;
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
//# sourceMappingURL=funnel-CFEEulw_.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"funnel-CFEEulw_.cjs","names":["round","innerRect","insets","formatNumber","getNumberFormat","h","keyOf","estimateTextWidth","fit","records","named","finite","cleanData"],"sources":["../src/charts/funnel.ts"],"sourcesContent":["import type { DataTable } from '../a11y.ts'\nimport type { ChartType, RenderContext, RenderResult } 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 { type ClassValue, h } from '../vnode.ts'\nimport { cleanData, finite, named, records } from './clean.ts'\nimport { fit } from './fit.ts'\nimport { keyOf } from './named.ts'\n\n/** One stage of a funnel. */\nexport interface FunnelStage {\n name: string\n /** How many reached the stage. Stages without a number, or with a negative one, are left out. */\n value: number\n /** Stable identity for keyed updates. Defaults to `name`. */\n id?: string\n /**\n * Custom color, drawn as it is instead of the stage's shade of `--tc-funnel-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 stage's shape. */\n class?: ClassValue\n}\n\nexport interface FunnelOptions {\n /** Stages in the order of the process; they are drawn as they come, not sorted. */\n data: readonly FunnelStage[]\n /** Name, value and share of the first stage written above every stage. Defaults to `true`. */\n labels?: boolean\n /** Radius of the top corners of the stages. Defaults to `4`. */\n radius?: number\n /** Format of the values (labels, tooltip, table). */\n format?: NumberFormat\n /** Extra space around the chart, in pixels. */\n padding?: InsetsInput\n}\n\n/** Space between a column's left edge and its text (none in the first column). */\nconst INSET = 10\n\n/** Share of the full color in the first stage; the last one takes all of it. */\nconst PALEST = 0.3\n\nconst COLOR = 'var(--tc-funnel-color,var(--tc-color-1))'\n\n/** A stage with its conversion rates, `0…1` (`1` for the first stage). */\ninterface Stage {\n data: FunnelStage\n value: number\n ofFirst: number\n ofPrevious: number\n}\n\nconst share = (value: number, of: number): number => (of > 0 ? value / of : 0)\n\nfunction stagesOf(options: FunnelOptions): Stage[] {\n const first = options.data[0]?.value ?? 0\n return options.data.map((data, i) => ({\n data,\n value: data.value,\n ofFirst: i === 0 ? 1 : share(data.value, first),\n ofPrevious: i === 0 ? 1 : share(data.value, (options.data[i - 1] as FunnelStage).value),\n }))\n}\n\n/** Share of the full color in stage `i` of `count`: paler where the funnel is wide. */\nconst shadeOf = (i: number, count: number): number =>\n round((count > 1 ? PALEST + ((1 - PALEST) * i) / (count - 1) : 1) * 100)\n\n/** Corner of radius `r` that takes at most half of either edge it sits on. */\nconst corner = (r: number, edgeX: number, edgeY: number): number =>\n Math.max(0, Math.min(r, edgeX / 2, edgeY / 2))\n\n/**\n * A stage from `x0` to `x1`, standing on `floor`: its top runs from its own\n * height `y0` to the next stage's `y1`, with both top corners rounded.\n */\nfunction stagePath(\n x0: number,\n x1: number,\n y0: number,\n y1: number,\n floor: number,\n radius: number,\n): string {\n const dx = x1 - x0\n const dy = y1 - y0\n const near = corner(radius, dx, floor - y0)\n const far = corner(radius, dx, floor - y1)\n // How far along the sloped top each corner reaches.\n const tn = dx > 0 ? near / dx : 0\n const tf = dx > 0 ? far / dx : 0\n const n = round\n return (\n `M${n(x0)},${n(y0 + near)}Q${n(x0)},${n(y0)},${n(x0 + dx * tn)},${n(y0 + dy * tn)}` +\n `L${n(x1 - dx * tf)},${n(y1 - dy * tf)}Q${n(x1)},${n(y1)},${n(x1)},${n(y1 + far)}` +\n `L${n(x1)},${n(floor)}L${n(x0)},${n(floor)}Z`\n )\n}\n\nfunction renderFunnel(options: FunnelOptions, ctx: RenderContext): RenderResult {\n const { width, height, fontSize, locale } = ctx\n const radius = Math.max(0, options.radius ?? 4)\n const area = innerRect(width, height, insets(options.padding, 0))\n const stages = stagesOf(options)\n const count = stages.length\n if (count === 0) return { content: null }\n\n const value = formatNumber(options.format, locale)\n const percent = getNumberFormat(locale, { style: 'percent', maximumFractionDigits: 1 })\n // For columns too narrow for the whole value: \"31K\" says more than nothing.\n const short =\n typeof options.format === 'function'\n ? value\n : formatNumber({ ...options.format, notation: 'compact' }, locale)\n\n // Three lines of text above the shapes: name, value, share of the first stage.\n const line = fontSize * 1.3\n const header = options.labels === false ? 0 : Math.min(area.height, line * 3 + 8)\n const floor = area.y + area.height\n const plot = area.height - header\n const column = area.width / count\n const columnX = (i: number) => area.x + i * column\n // Every stage is measured against the largest, so a funnel that only loses fills the plot.\n const max = Math.max(0, ...stages.map((stage) => stage.value))\n const top = (v: number) => floor - (max > 0 ? (v / max) * plot : 0)\n\n const colorOf = (i: number): string =>\n (stages[i] as Stage).data.color ??\n `color-mix(in oklab,${COLOR} ${shadeOf(i, count)}%,var(--tc-surface))`\n\n const hitFor = (i: number): Hit => {\n const stage = stages[i] as Stage\n const x = columnX(i) + column / 2\n const items: HitItem[] = [\n {\n name: stage.data.name,\n seriesIndex: 0,\n value: stage.value,\n text: value(stage.value),\n x,\n y: top(stage.value),\n color: colorOf(i),\n },\n ]\n // Conversion rates as notes below the value: no swatch, no value label.\n const rate = (seriesIndex: number, of: Stage, v: number) =>\n items.push({\n name: `of ${of.data.name}`,\n seriesIndex,\n value: v,\n text: percent.format(v),\n x,\n y: null,\n color: 'transparent',\n })\n if (i > 0) rate(1, stages[0] as Stage, stage.ofFirst)\n // The second stage's previous one is the first: the same rate again.\n if (i > 1) rate(2, stages[i - 1] as Stage, stage.ofPrevious)\n return {\n index: i,\n label: stage.data.name,\n title: '',\n x,\n area,\n // The whole column is highlighted, as it is the whole hit area.\n highlight: { kind: 'band', x: columnX(i), y: area.y, width: column, height: area.height },\n items,\n }\n }\n\n const interaction: Interaction = {\n count,\n hitIndex: (i) => (i >= 0 && i < count ? hitFor(i) : null),\n hitTest(px, py) {\n if (px < area.x || px > area.x + area.width || py < area.y || py > floor) return null\n return hitFor(Math.min(count - 1, Math.floor((px - area.x) / (column || 1))))\n },\n }\n\n const dividers = stages.slice(1).map((stage, i) =>\n h('line', {\n key: keyOf(stage.data),\n class: 'tc-grid-line tc-funnel-divider',\n x1: round(columnX(i + 1)),\n x2: round(columnX(i + 1)),\n y1: round(area.y),\n y2: round(floor),\n }),\n )\n\n const shapes = stages.map((stage, i) =>\n h('path', {\n key: keyOf(stage.data),\n class: ['tc-funnel-stage', stage.data.class],\n 'data-series': stage.data.name,\n // The last stage stays level: a slope would draw a loss the data does not report.\n d: stagePath(\n columnX(i),\n columnX(i + 1),\n top(stage.value),\n top((stages[i + 1] ?? stage).value),\n floor,\n radius,\n ),\n // A map, so values from data cannot inject CSS (see normalizeStyle).\n style: {\n '--tc-funnel-color': stage.data.color,\n '--tc-funnel-shade': `${stage.data.color ? 100 : shadeOf(i, count)}%`,\n },\n }),\n )\n\n const labels =\n header >= line * 3 &&\n stages.flatMap((stage, i) => {\n const inset = i === 0 ? 0 : INSET\n const room = column - inset - INSET\n const x = round(columnX(i) + inset)\n const y = area.y + fontSize * 0.85\n const key = keyOf(stage.data)\n const fits = (text: string) => estimateTextWidth(text, fontSize) <= room\n const name = fit(stage.data.name, room, fontSize)\n const whole = value(stage.value)\n const amount = fits(whole) ? whole : short(stage.value)\n // Nothing to convert from at the top of the funnel.\n const rate = i > 0 ? percent.format(stage.ofFirst) : ''\n return [\n name && h('text', { key, class: 'tc-funnel-name', x, y: round(y) }, name),\n fits(amount) &&\n h(\n 'text',\n { key: `${key}/value`, class: 'tc-funnel-value', x, y: round(y + line) },\n amount,\n ),\n rate &&\n fits(rate) &&\n h(\n 'text',\n { key: `${key}/share`, class: 'tc-funnel-share', x, y: round(y + line * 2) },\n rate,\n ),\n ]\n })\n\n const content = [\n h('g', { class: 'tc-funnel-dividers', 'aria-hidden': 'true' }, dividers),\n h('g', { class: 'tc-funnel-stages' }, shapes),\n labels && h('g', { class: 'tc-funnel-labels', 'aria-hidden': 'true' }, labels),\n ]\n return { content, interaction }\n}\n\nfunction funnelTable(options: FunnelOptions, ctx: RenderContext, limit: number): DataTable {\n const value = formatNumber(options.format, ctx.locale)\n const percent = getNumberFormat(ctx.locale, { style: 'percent', maximumFractionDigits: 1 })\n const rows = stagesOf(options).map((stage) => [\n stage.data.name,\n value(stage.value),\n percent.format(stage.ofFirst),\n percent.format(stage.ofPrevious),\n ])\n const table: DataTable = { columns: ['', 'Value', 'Of first', 'Of previous'], 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/**\n * Stages with text for names. A stage that reports no number did not report\n * a zero, and the stage after it would be measured against it: such stages\n * are left out, as are negative counts.\n */\nconst cleanStages = (data: unknown): unknown =>\n records(data, (r) => ({ ...named(r), value: finite(r.value) })).filter(\n (stage) => stage.value !== null && stage.value >= 0,\n )\n\n/**\n * Funnel: how many get from one stage of a process to the next. Every stage\n * is a column with its name, its value and its share of the first stage on\n * top; the shapes below step down from each stage's height to the next, in\n * one color that deepens as the funnel narrows (`--tc-funnel-color`).\n *\n * ```ts\n * new Chart('#el', {\n * type: funnel,\n * data: [\n * { name: 'Visits', value: 12400 },\n * { name: 'Signups', value: 3100 },\n * { name: 'Purchases', value: 620 },\n * ],\n * })\n * ```\n */\nexport const funnel: ChartType<FunnelOptions> = {\n name: 'funnel',\n clean: cleanData(cleanStages),\n render: renderFunnel,\n table: funnelTable,\n}\n"],"mappings":";;;;;;;;AAwCA,MAAM,QAAQ;;AAGd,MAAM,SAAS;AAEf,MAAM,QAAQ;AAUd,MAAM,SAAS,OAAe,OAAwB,KAAK,IAAI,QAAQ,KAAK;AAE5E,SAAS,SAAS,SAAiC;CACjD,MAAM,QAAQ,QAAQ,KAAK,EAAE,EAAE,SAAS;CACxC,OAAO,QAAQ,KAAK,KAAK,MAAM,OAAO;EACpC;EACA,OAAO,KAAK;EACZ,SAAS,MAAM,IAAI,IAAI,MAAM,KAAK,OAAO,KAAK;EAC9C,YAAY,MAAM,IAAI,IAAI,MAAM,KAAK,OAAQ,QAAQ,KAAK,IAAI,EAAE,CAAiB,KAAK;CACxF,EAAE;AACJ;;AAGA,MAAM,WAAW,GAAW,UAC1BA,eAAAA,OAAO,QAAQ,IAAI,SAAW,KAAc,KAAM,QAAQ,KAAK,KAAK,GAAG;;AAGzE,MAAM,UAAU,GAAW,OAAe,UACxC,KAAK,IAAI,GAAG,KAAK,IAAI,GAAG,QAAQ,GAAG,QAAQ,CAAC,CAAC;;;;;AAM/C,SAAS,UACP,IACA,IACA,IACA,IACA,OACA,QACQ;CACR,MAAM,KAAK,KAAK;CAChB,MAAM,KAAK,KAAK;CAChB,M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