@automattic/charts 0.32.0 → 0.33.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/CHANGELOG.md +19 -6
- package/dist/bar-chart.module-BGQPECGS.scss +12 -0
- package/dist/base-legend.module-YZJXJR45.scss +76 -0
- package/dist/{types/components/tooltip/base-tooltip.d.ts → base-tooltip-Dlq8KmQA.d.cts} +1 -1
- package/dist/base-tooltip-Dlq8KmQA.d.ts +32 -0
- package/dist/base-tooltip.module-NILZYBVJ.scss +11 -0
- package/dist/chunk-253F4WJT.cjs +2 -0
- package/dist/chunk-253F4WJT.cjs.map +1 -0
- package/dist/chunk-2CEQF5RH.cjs +2 -0
- package/dist/chunk-2CEQF5RH.cjs.map +1 -0
- package/dist/chunk-2O5XXOKH.cjs +32 -0
- package/dist/chunk-2O5XXOKH.cjs.map +1 -0
- package/dist/chunk-4CPALWEX.cjs +2 -0
- package/dist/chunk-4CPALWEX.cjs.map +1 -0
- package/dist/chunk-6HERQ6UJ.js +2 -0
- package/dist/chunk-6HERQ6UJ.js.map +1 -0
- package/dist/chunk-76MUGFRK.cjs +2 -0
- package/dist/chunk-76MUGFRK.cjs.map +1 -0
- package/dist/chunk-7C6PJGWI.js +2 -0
- package/dist/chunk-7C6PJGWI.js.map +1 -0
- package/dist/chunk-7TRU7Z3V.cjs +2 -0
- package/dist/chunk-7TRU7Z3V.cjs.map +1 -0
- package/dist/chunk-A6B522YL.js +2 -0
- package/dist/chunk-A6B522YL.js.map +1 -0
- package/dist/chunk-ALC6I6HA.js +2 -0
- package/dist/chunk-ALC6I6HA.js.map +1 -0
- package/dist/chunk-BNAXWJSF.cjs +2 -0
- package/dist/chunk-BNAXWJSF.cjs.map +1 -0
- package/dist/chunk-DBGSHU4Q.js +2 -0
- package/dist/chunk-DBGSHU4Q.js.map +1 -0
- package/dist/chunk-GRHWUZHQ.js +2 -0
- package/dist/chunk-GRHWUZHQ.js.map +1 -0
- package/dist/chunk-HJYSGVCM.cjs +2 -0
- package/dist/chunk-HJYSGVCM.cjs.map +1 -0
- package/dist/chunk-JNA2WFY7.cjs +12 -0
- package/dist/chunk-JNA2WFY7.cjs.map +1 -0
- package/dist/chunk-MPWOYZHH.js +12 -0
- package/dist/chunk-MPWOYZHH.js.map +1 -0
- package/dist/chunk-QAF44M37.cjs +2 -0
- package/dist/chunk-QAF44M37.cjs.map +1 -0
- package/dist/chunk-QZBB6KI3.js +2 -0
- package/dist/chunk-QZBB6KI3.js.map +1 -0
- package/dist/chunk-RFBBAUMM.js +2 -0
- package/dist/chunk-RFBBAUMM.js.map +1 -0
- package/dist/chunk-RS3D7LRG.cjs +2 -0
- package/dist/chunk-RS3D7LRG.cjs.map +1 -0
- package/dist/chunk-SJSVNSI5.cjs +2 -0
- package/dist/chunk-SJSVNSI5.cjs.map +1 -0
- package/dist/chunk-UMO3DIW3.js +2 -0
- package/dist/chunk-UMO3DIW3.js.map +1 -0
- package/dist/chunk-UPZWVSQA.cjs +2 -0
- package/dist/chunk-UPZWVSQA.cjs.map +1 -0
- package/dist/chunk-VFET7YXL.js +2 -0
- package/dist/chunk-VFET7YXL.js.map +1 -0
- package/dist/chunk-WH6WPZPG.cjs +2 -0
- package/dist/chunk-WH6WPZPG.cjs.map +1 -0
- package/dist/chunk-WRNE6E3B.js +2 -0
- package/dist/chunk-WRNE6E3B.js.map +1 -0
- package/dist/chunk-XTK36YFB.js +32 -0
- package/dist/chunk-XTK36YFB.js.map +1 -0
- package/dist/chunk-Z7T2M5EL.js +2 -0
- package/dist/chunk-Z7T2M5EL.js.map +1 -0
- package/dist/components/bar-chart/index.cjs +2 -0
- package/dist/components/bar-chart/index.cjs.map +1 -0
- package/dist/components/bar-chart/index.d.cts +31 -0
- package/dist/components/bar-chart/index.d.ts +31 -0
- package/dist/components/bar-chart/index.js +2 -0
- package/dist/components/bar-chart/index.js.map +1 -0
- package/dist/components/bar-list-chart/index.cjs +2 -0
- package/dist/components/bar-list-chart/index.cjs.map +1 -0
- package/dist/components/bar-list-chart/index.d.cts +84 -0
- package/dist/{types/components/bar-list-chart/bar-list-chart.d.ts → components/bar-list-chart/index.d.ts} +17 -5
- package/dist/components/bar-list-chart/index.js +2 -0
- package/dist/components/bar-list-chart/index.js.map +1 -0
- package/dist/components/conversion-funnel-chart/index.cjs +2 -0
- package/dist/components/conversion-funnel-chart/index.cjs.map +1 -0
- package/dist/{types/components/conversion-funnel-chart/conversion-funnel-chart.d.ts → components/conversion-funnel-chart/index.d.cts} +1 -1
- package/dist/components/conversion-funnel-chart/index.d.ts +94 -0
- package/dist/components/conversion-funnel-chart/index.js +2 -0
- package/dist/components/conversion-funnel-chart/index.js.map +1 -0
- package/dist/components/leaderboard-chart/index.cjs +2 -0
- package/dist/components/leaderboard-chart/index.cjs.map +1 -0
- package/dist/components/leaderboard-chart/index.d.cts +27 -0
- package/dist/{types/utils/format-metric-value.d.ts → components/leaderboard-chart/index.d.ts} +3 -0
- package/dist/components/leaderboard-chart/index.js +2 -0
- package/dist/components/leaderboard-chart/index.js.map +1 -0
- package/dist/components/legend/index.cjs +2 -0
- package/dist/components/legend/index.cjs.map +1 -0
- package/dist/components/legend/index.d.cts +33 -0
- package/dist/{types/components/legend/hooks/use-chart-legend-items.d.ts → components/legend/index.d.ts} +14 -3
- package/dist/components/legend/index.js +2 -0
- package/dist/components/legend/index.js.map +1 -0
- package/dist/components/line-chart/index.cjs +2 -0
- package/dist/components/line-chart/index.cjs.map +1 -0
- package/dist/components/line-chart/index.d.cts +91 -0
- package/dist/components/line-chart/index.d.ts +91 -0
- package/dist/components/line-chart/index.js +2 -0
- package/dist/components/line-chart/index.js.map +1 -0
- package/dist/components/pie-chart/index.cjs +2 -0
- package/dist/components/pie-chart/index.cjs.map +1 -0
- package/dist/components/pie-chart/index.d.cts +66 -0
- package/dist/{types/components/pie-chart/pie-chart.d.ts → components/pie-chart/index.d.ts} +24 -4
- package/dist/components/pie-chart/index.js +2 -0
- package/dist/components/pie-chart/index.js.map +1 -0
- package/dist/components/pie-semi-circle-chart/index.cjs +2 -0
- package/dist/components/pie-semi-circle-chart/index.cjs.map +1 -0
- package/dist/components/pie-semi-circle-chart/index.d.cts +50 -0
- package/dist/{types/components/pie-semi-circle-chart/pie-semi-circle-chart.d.ts → components/pie-semi-circle-chart/index.d.ts} +15 -4
- package/dist/components/pie-semi-circle-chart/index.js +2 -0
- package/dist/components/pie-semi-circle-chart/index.js.map +1 -0
- package/dist/components/tooltip/index.cjs +2 -0
- package/dist/components/tooltip/index.cjs.map +1 -0
- package/dist/components/tooltip/index.d.cts +68 -0
- package/dist/{types/components/tooltip/accessible-tooltip.d.ts → components/tooltip/index.d.ts} +21 -5
- package/dist/components/tooltip/index.js +2 -0
- package/dist/components/tooltip/index.js.map +1 -0
- package/dist/conversion-funnel-chart.module-5ZPZQXF3.scss +165 -0
- package/dist/hooks/index.cjs +2 -0
- package/dist/hooks/index.cjs.map +1 -0
- package/dist/hooks/index.d.cts +116 -0
- package/dist/hooks/index.d.ts +116 -0
- package/dist/hooks/index.js +2 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +29 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/{types/components/leaderboard-chart/leaderboard-chart.d.ts → leaderboard-chart-D8KNIPOq.d.cts} +2 -21
- package/dist/leaderboard-chart-D8KNIPOq.d.ts +83 -0
- package/dist/leaderboard-chart.module-AZFQ7TAT.scss +55 -0
- package/dist/legend-CGLLcxnk.d.cts +9 -0
- package/dist/{types/components/legend/legend.d.ts → legend-iXnk1-uq.d.ts} +2 -2
- package/dist/line-chart.module-NRZUHHPY.scss +106 -0
- package/dist/pie-chart.module-LOP3Y52M.scss +5 -0
- package/dist/pie-semi-circle-chart.module-7NJL5QNB.scss +17 -0
- package/dist/providers/index.cjs +2 -0
- package/dist/providers/index.cjs.map +1 -0
- package/dist/providers/index.d.cts +25 -0
- package/dist/providers/index.d.ts +25 -0
- package/dist/providers/index.js +2 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/{types/components/legend/types.d.ts → types-4lieC41v.d.cts} +2 -2
- package/dist/types-4lieC41v.d.ts +31 -0
- package/dist/{types/components/private/chart-composition/types.d.ts → types-CqnQHiIy.d.cts} +3 -3
- package/dist/{types/types.d.ts → types-DdYRE7ga.d.cts} +30 -5
- package/dist/types-DdYRE7ga.d.ts +353 -0
- package/dist/types-UkvpmJXU.d.ts +19 -0
- package/dist/use-global-charts-theme-D3LjTUGh.d.ts +81 -0
- package/dist/use-global-charts-theme-mXcouoeC.d.cts +81 -0
- package/dist/visx/group/index.cjs +2 -0
- package/dist/visx/group/index.cjs.map +1 -0
- package/dist/visx/group/index.d.cts +3 -0
- package/dist/visx/group/index.d.ts +3 -0
- package/dist/visx/group/index.js +2 -0
- package/dist/visx/group/index.js.map +1 -0
- package/dist/visx/legend/index.cjs +2 -0
- package/dist/visx/legend/index.cjs.map +1 -0
- package/dist/visx/legend/index.js +2 -0
- package/dist/visx/legend/index.js.map +1 -0
- package/dist/visx/text/index.cjs +2 -0
- package/dist/visx/text/index.cjs.map +1 -0
- package/dist/visx/text/index.js +2 -0
- package/dist/visx/text/index.js.map +1 -0
- package/dist/{types/components/private/with-responsive/with-responsive.d.ts → with-responsive-Cp2qnQPo.d.cts} +1 -1
- package/dist/with-responsive-Cp2qnQPo.d.ts +16 -0
- package/package.json +115 -42
- package/src/components/bar-chart/bar-chart.module.scss +12 -0
- package/src/components/bar-chart/bar-chart.tsx +435 -0
- package/src/components/bar-chart/index.ts +2 -0
- package/src/components/bar-chart/private/index.ts +1 -0
- package/src/components/bar-chart/private/use-bar-chart-options.ts +135 -0
- package/src/components/bar-chart/test/bar-chart.test.tsx +566 -0
- package/src/components/bar-list-chart/bar-list-chart.tsx +316 -0
- package/src/components/bar-list-chart/index.ts +2 -0
- package/src/components/bar-list-chart/test/bar-list-chart.test.tsx +73 -0
- package/src/components/conversion-funnel-chart/conversion-funnel-chart.module.scss +165 -0
- package/src/components/conversion-funnel-chart/conversion-funnel-chart.tsx +462 -0
- package/src/components/conversion-funnel-chart/index.ts +9 -0
- package/src/components/conversion-funnel-chart/private/index.ts +1 -0
- package/src/components/conversion-funnel-chart/private/use-funnel-selection.ts +68 -0
- package/src/components/conversion-funnel-chart/test/conversion-funnel-chart.test.tsx +431 -0
- package/src/components/conversion-funnel-chart/test/use-funnel-selection.test.ts +206 -0
- package/src/components/leaderboard-chart/README.md +199 -0
- package/src/components/leaderboard-chart/index.ts +4 -0
- package/src/components/leaderboard-chart/leaderboard-chart.module.scss +55 -0
- package/src/components/leaderboard-chart/leaderboard-chart.tsx +303 -0
- package/src/components/leaderboard-chart/test/leaderboard-chart.test.tsx +123 -0
- package/src/components/legend/hooks/use-chart-legend-items.ts +212 -0
- package/src/components/legend/index.ts +4 -0
- package/src/components/legend/legend.tsx +33 -0
- package/src/components/legend/private/base-legend.module.scss +76 -0
- package/src/components/legend/private/base-legend.tsx +179 -0
- package/src/components/legend/private/index.ts +1 -0
- package/src/components/legend/test/legend.test.tsx +85 -0
- package/src/components/legend/types.ts +34 -0
- package/src/components/legend/utils/index.ts +3 -0
- package/{dist/cjs/components/legend/utils/label-transform-factory.js → src/components/legend/utils/label-transform-factory.ts} +15 -10
- package/{dist/cjs/components/legend/utils/value-or-identity.js → src/components/legend/utils/value-or-identity.ts} +8 -10
- package/src/components/line-chart/index.ts +9 -0
- package/src/components/line-chart/line-chart.module.scss +106 -0
- package/src/components/line-chart/line-chart.tsx +576 -0
- package/src/components/line-chart/private/index.ts +3 -0
- package/src/components/line-chart/private/line-chart-annotation-label-popover.tsx +111 -0
- package/src/components/line-chart/private/line-chart-annotation.tsx +321 -0
- package/src/components/line-chart/private/line-chart-annotations-overlay.tsx +135 -0
- package/src/components/line-chart/test/line-chart-annotation-label-popover.test.tsx +81 -0
- package/src/components/line-chart/test/line-chart-annotation.test.tsx +306 -0
- package/src/components/line-chart/test/line-chart.test.tsx +725 -0
- package/src/components/line-chart/types.ts +42 -0
- package/{dist/mjs/components/pie-chart/index.js → src/components/pie-chart/index.ts} +2 -1
- package/src/components/pie-chart/pie-chart.module.scss +5 -0
- package/src/components/pie-chart/pie-chart.tsx +384 -0
- package/src/components/pie-chart/test/composition-api.test.tsx +151 -0
- package/src/components/pie-chart/test/pie-chart.test.tsx +226 -0
- package/src/components/pie-semi-circle-chart/index.ts +2 -0
- package/src/components/pie-semi-circle-chart/pie-semi-circle-chart.module.scss +17 -0
- package/src/components/pie-semi-circle-chart/pie-semi-circle-chart.tsx +375 -0
- package/src/components/pie-semi-circle-chart/test/pie-semi-circle-chart.test.tsx +181 -0
- package/{dist/mjs/components/private/chart-composition/chart-html.js → src/components/private/chart-composition/chart-html.tsx} +6 -7
- package/{dist/mjs/components/private/chart-composition/chart-svg.js → src/components/private/chart-composition/chart-svg.tsx} +6 -7
- package/src/components/private/chart-composition/index.ts +4 -0
- package/src/components/private/chart-composition/test/use-chart-children.test.tsx +131 -0
- package/src/components/private/chart-composition/types.ts +21 -0
- package/src/components/private/chart-composition/use-chart-children.ts +58 -0
- package/src/components/private/default-glyph/default-glyph.tsx +23 -0
- package/src/components/private/default-glyph/index.ts +1 -0
- package/src/components/private/grid-control/grid-control.module.scss +11 -0
- package/src/components/private/grid-control/grid-control.tsx +26 -0
- package/src/components/private/grid-control/index.ts +1 -0
- package/src/components/private/grid-control/test/grid-control.test.tsx +56 -0
- package/src/components/private/single-chart-context/index.ts +8 -0
- package/src/components/private/single-chart-context/single-chart-context.tsx +25 -0
- package/src/components/private/single-chart-context/use-single-chart-context.ts +12 -0
- package/src/components/private/with-responsive/index.ts +2 -0
- package/src/components/private/with-responsive/test/with-responsive.test.tsx +57 -0
- package/src/components/private/with-responsive/with-responsive.tsx +79 -0
- package/src/components/tooltip/accessible-tooltip.tsx +245 -0
- package/src/components/tooltip/base-tooltip.module.scss +11 -0
- package/src/components/tooltip/base-tooltip.tsx +57 -0
- package/src/components/tooltip/index.ts +4 -0
- package/src/components/tooltip/test/tool-tip.test.tsx +50 -0
- package/src/components/tooltip/types.ts +8 -0
- package/src/declarations.d.ts +5 -0
- package/src/hooks/index.ts +7 -0
- package/src/hooks/test/use-chart-data-transform.test.ts +135 -0
- package/src/hooks/test/use-chart-margin.test.tsx +119 -0
- package/src/hooks/test/use-chart-mouse-handler.test.tsx +53 -0
- package/src/hooks/test/use-element-height.test.tsx +270 -0
- package/src/hooks/use-chart-data-transform.ts +52 -0
- package/src/hooks/use-chart-margin.tsx +64 -0
- package/src/hooks/use-chart-mouse-handler.ts +88 -0
- package/{dist/mjs/hooks/use-deep-memo.js → src/hooks/use-deep-memo.ts} +8 -8
- package/src/hooks/use-element-height.ts +37 -0
- package/src/hooks/use-xychart-theme.ts +19 -0
- package/src/hooks/use-zero-value-display.ts +67 -0
- package/src/index.ts +32 -0
- package/src/providers/chart-context/global-charts-provider.tsx +96 -0
- package/src/providers/chart-context/hooks/use-chart-id.ts +6 -0
- package/src/providers/chart-context/hooks/use-chart-registration.ts +50 -0
- package/src/providers/chart-context/hooks/use-global-charts-context.ts +11 -0
- package/src/providers/chart-context/hooks/use-global-charts-theme.ts +30 -0
- package/src/providers/chart-context/index.ts +6 -0
- package/src/providers/chart-context/test/chart-context.test.tsx +584 -0
- package/src/providers/chart-context/test/use-global-charts-theme.test.tsx +206 -0
- package/src/providers/chart-context/types.ts +28 -0
- package/src/providers/index.ts +2 -0
- package/src/providers/theme/index.ts +2 -0
- package/src/providers/theme/theme-provider.tsx +35 -0
- package/src/providers/theme/themes.ts +193 -0
- package/src/types.ts +368 -0
- package/src/utils/color-utils.ts +40 -0
- package/{dist/mjs/utils/create-composition.js → src/utils/create-composition.ts} +5 -4
- package/{dist/mjs/utils/date-parsing.js → src/utils/date-parsing.ts} +40 -34
- package/src/utils/format-metric-value.ts +92 -0
- package/{dist/mjs/utils/format-percentage.js → src/utils/format-percentage.ts} +9 -11
- package/src/utils/get-longest-tick-width.ts +25 -0
- package/src/utils/get-styles.ts +84 -0
- package/src/utils/index.ts +25 -0
- package/src/utils/is-safari.ts +6 -0
- package/src/utils/merge-themes.ts +29 -0
- package/src/utils/test/color-utils.test.ts +232 -0
- package/src/utils/test/date-parsing.test.ts +306 -0
- package/src/utils/test/format-metric-value.test.ts +78 -0
- package/src/utils/test/get-longest-tick-width.test.ts +43 -0
- package/src/utils/test/get-styles.test.ts +334 -0
- package/src/utils/test/is-safari.test.ts +100 -0
- package/src/utils/test/merge-themes.test.ts +100 -0
- package/src/visx/README.md +43 -0
- package/src/visx/group/index.ts +2 -0
- package/src/visx/legend/index.ts +2 -0
- package/src/visx/text/index.ts +2 -0
- package/src/visx/types.ts +2 -0
- package/tsup.config.ts +23 -0
- package/agents.md +0 -155
- package/dist/cjs/components/bar-chart/bar-chart.js +0 -210
- package/dist/cjs/components/bar-chart/bar-chart.module.scss.js +0 -7
- package/dist/cjs/components/bar-chart/index.js +0 -7
- package/dist/cjs/components/bar-chart/private/use-bar-chart-options.js +0 -115
- package/dist/cjs/components/bar-list-chart/bar-list-chart.js +0 -144
- package/dist/cjs/components/bar-list-chart/index.js +0 -7
- package/dist/cjs/components/conversion-funnel-chart/conversion-funnel-chart.js +0 -246
- package/dist/cjs/components/conversion-funnel-chart/conversion-funnel-chart.module.scss.js +0 -7
- package/dist/cjs/components/conversion-funnel-chart/private/use-funnel-selection.js +0 -61
- package/dist/cjs/components/leaderboard-chart/index.js +0 -13
- package/dist/cjs/components/leaderboard-chart/leaderboard-chart.js +0 -113
- package/dist/cjs/components/leaderboard-chart/leaderboard-chart.module.scss.js +0 -7
- package/dist/cjs/components/legend/hooks/use-chart-legend-items.js +0 -125
- package/dist/cjs/components/legend/index.js +0 -9
- package/dist/cjs/components/legend/legend.js +0 -30
- package/dist/cjs/components/legend/private/base-legend.js +0 -78
- package/dist/cjs/components/legend/private/base-legend.module.scss.js +0 -7
- package/dist/cjs/components/line-chart/index.js +0 -7
- package/dist/cjs/components/line-chart/line-chart.js +0 -312
- package/dist/cjs/components/line-chart/line-chart.module.scss.js +0 -7
- package/dist/cjs/components/line-chart/private/line-chart-annotation-label-popover.js +0 -65
- package/dist/cjs/components/line-chart/private/line-chart-annotation.js +0 -197
- package/dist/cjs/components/line-chart/private/line-chart-annotations-overlay.js +0 -97
- package/dist/cjs/components/pie-chart/index.js +0 -8
- package/dist/cjs/components/pie-chart/pie-chart.js +0 -175
- package/dist/cjs/components/pie-chart/pie-chart.module.scss.js +0 -7
- package/dist/cjs/components/pie-semi-circle-chart/index.js +0 -7
- package/dist/cjs/components/pie-semi-circle-chart/pie-semi-circle-chart.js +0 -162
- package/dist/cjs/components/pie-semi-circle-chart/pie-semi-circle-chart.module.scss.js +0 -7
- package/dist/cjs/components/private/chart-composition/chart-html.js +0 -22
- package/dist/cjs/components/private/chart-composition/chart-svg.js +0 -22
- package/dist/cjs/components/private/chart-composition/use-chart-children.js +0 -55
- package/dist/cjs/components/private/default-glyph/default-glyph.js +0 -12
- package/dist/cjs/components/private/single-chart-context/single-chart-context.js +0 -10
- package/dist/cjs/components/private/single-chart-context/use-single-chart-context.js +0 -16
- package/dist/cjs/components/private/with-responsive/with-responsive.js +0 -37
- package/dist/cjs/components/tooltip/accessible-tooltip.js +0 -141
- package/dist/cjs/components/tooltip/base-tooltip.js +0 -11
- package/dist/cjs/components/tooltip/base-tooltip.module.scss.js +0 -7
- package/dist/cjs/components/tooltip/index.js +0 -10
- package/dist/cjs/hooks/use-chart-data-transform.js +0 -56
- package/dist/cjs/hooks/use-chart-margin.js +0 -49
- package/dist/cjs/hooks/use-chart-mouse-handler.js +0 -46
- package/dist/cjs/hooks/use-deep-memo.js +0 -21
- package/dist/cjs/hooks/use-element-height.js +0 -35
- package/dist/cjs/hooks/use-xychart-theme.js +0 -29
- package/dist/cjs/hooks/use-zero-value-display.js +0 -43
- package/dist/cjs/index.js +0 -68
- package/dist/cjs/providers/chart-context/global-charts-provider.js +0 -63
- package/dist/cjs/providers/chart-context/hooks/use-chart-id.js +0 -10
- package/dist/cjs/providers/chart-context/hooks/use-chart-registration.js +0 -47
- package/dist/cjs/providers/chart-context/hooks/use-global-charts-context.js +0 -14
- package/dist/cjs/providers/chart-context/hooks/use-global-charts-theme.js +0 -31
- package/dist/cjs/providers/chart-context/index.js +0 -16
- package/dist/cjs/providers/theme/index.js +0 -12
- package/dist/cjs/providers/theme/theme-provider.js +0 -25
- package/dist/cjs/providers/theme/themes.js +0 -183
- package/dist/cjs/style.css +0 -1
- package/dist/cjs/utils/color-utils.js +0 -39
- package/dist/cjs/utils/create-composition.js +0 -17
- package/dist/cjs/utils/date-parsing.js +0 -99
- package/dist/cjs/utils/format-metric-value.js +0 -76
- package/dist/cjs/utils/format-percentage.js +0 -24
- package/dist/cjs/utils/get-longest-tick-width.js +0 -19
- package/dist/cjs/utils/get-styles.js +0 -58
- package/dist/cjs/utils/is-safari.js +0 -10
- package/dist/cjs/utils/merge-themes.js +0 -21
- package/dist/cjs/visx/group/index.js +0 -10
- package/dist/cjs/visx/legend/index.js +0 -18
- package/dist/cjs/visx/text/index.js +0 -18
- package/dist/mjs/components/bar-chart/bar-chart.js +0 -206
- package/dist/mjs/components/bar-chart/bar-chart.module.scss.js +0 -3
- package/dist/mjs/components/bar-chart/index.js +0 -1
- package/dist/mjs/components/bar-chart/private/use-bar-chart-options.js +0 -113
- package/dist/mjs/components/bar-list-chart/bar-list-chart.js +0 -139
- package/dist/mjs/components/bar-list-chart/index.js +0 -1
- package/dist/mjs/components/conversion-funnel-chart/conversion-funnel-chart.js +0 -241
- package/dist/mjs/components/conversion-funnel-chart/conversion-funnel-chart.module.scss.js +0 -3
- package/dist/mjs/components/conversion-funnel-chart/private/use-funnel-selection.js +0 -59
- package/dist/mjs/components/leaderboard-chart/index.js +0 -6
- package/dist/mjs/components/leaderboard-chart/leaderboard-chart.js +0 -108
- package/dist/mjs/components/leaderboard-chart/leaderboard-chart.module.scss.js +0 -3
- package/dist/mjs/components/legend/hooks/use-chart-legend-items.js +0 -123
- package/dist/mjs/components/legend/index.js +0 -2
- package/dist/mjs/components/legend/legend.js +0 -28
- package/dist/mjs/components/legend/private/base-legend.js +0 -76
- package/dist/mjs/components/legend/private/base-legend.module.scss.js +0 -3
- package/dist/mjs/components/legend/utils/label-transform-factory.js +0 -17
- package/dist/mjs/components/legend/utils/value-or-identity.js +0 -20
- package/dist/mjs/components/line-chart/index.js +0 -1
- package/dist/mjs/components/line-chart/line-chart.js +0 -308
- package/dist/mjs/components/line-chart/line-chart.module.scss.js +0 -3
- package/dist/mjs/components/line-chart/private/line-chart-annotation-label-popover.js +0 -60
- package/dist/mjs/components/line-chart/private/line-chart-annotation.js +0 -192
- package/dist/mjs/components/line-chart/private/line-chart-annotations-overlay.js +0 -93
- package/dist/mjs/components/pie-chart/pie-chart.js +0 -170
- package/dist/mjs/components/pie-chart/pie-chart.module.scss.js +0 -3
- package/dist/mjs/components/pie-semi-circle-chart/index.js +0 -1
- package/dist/mjs/components/pie-semi-circle-chart/pie-semi-circle-chart.js +0 -158
- package/dist/mjs/components/pie-semi-circle-chart/pie-semi-circle-chart.module.scss.js +0 -3
- package/dist/mjs/components/private/chart-composition/use-chart-children.js +0 -53
- package/dist/mjs/components/private/default-glyph/default-glyph.js +0 -10
- package/dist/mjs/components/private/single-chart-context/single-chart-context.js +0 -7
- package/dist/mjs/components/private/single-chart-context/use-single-chart-context.js +0 -13
- package/dist/mjs/components/private/with-responsive/with-responsive.js +0 -35
- package/dist/mjs/components/tooltip/accessible-tooltip.js +0 -135
- package/dist/mjs/components/tooltip/base-tooltip.js +0 -9
- package/dist/mjs/components/tooltip/base-tooltip.module.scss.js +0 -3
- package/dist/mjs/components/tooltip/index.js +0 -2
- package/dist/mjs/hooks/use-chart-data-transform.js +0 -54
- package/dist/mjs/hooks/use-chart-margin.js +0 -47
- package/dist/mjs/hooks/use-chart-mouse-handler.js +0 -44
- package/dist/mjs/hooks/use-element-height.js +0 -33
- package/dist/mjs/hooks/use-xychart-theme.js +0 -27
- package/dist/mjs/hooks/use-zero-value-display.js +0 -41
- package/dist/mjs/index.js +0 -21
- package/dist/mjs/providers/chart-context/global-charts-provider.js +0 -60
- package/dist/mjs/providers/chart-context/hooks/use-chart-id.js +0 -8
- package/dist/mjs/providers/chart-context/hooks/use-chart-registration.js +0 -45
- package/dist/mjs/providers/chart-context/hooks/use-global-charts-context.js +0 -12
- package/dist/mjs/providers/chart-context/hooks/use-global-charts-theme.js +0 -29
- package/dist/mjs/providers/chart-context/index.js +0 -5
- package/dist/mjs/providers/theme/index.js +0 -2
- package/dist/mjs/providers/theme/theme-provider.js +0 -22
- package/dist/mjs/providers/theme/themes.js +0 -179
- package/dist/mjs/style.css +0 -1
- package/dist/mjs/utils/color-utils.js +0 -37
- package/dist/mjs/utils/format-metric-value.js +0 -74
- package/dist/mjs/utils/get-longest-tick-width.js +0 -17
- package/dist/mjs/utils/get-styles.js +0 -54
- package/dist/mjs/utils/is-safari.js +0 -8
- package/dist/mjs/utils/merge-themes.js +0 -19
- package/dist/mjs/visx/group/index.js +0 -1
- package/dist/types/components/bar-chart/bar-chart.d.ts +0 -21
- package/dist/types/components/bar-chart/index.d.ts +0 -1
- package/dist/types/components/bar-list-chart/index.d.ts +0 -1
- package/dist/types/components/leaderboard-chart/index.d.ts +0 -2
- package/dist/types/components/legend/index.d.ts +0 -3
- package/dist/types/components/line-chart/index.d.ts +0 -2
- package/dist/types/components/line-chart/line-chart.d.ts +0 -18
- package/dist/types/components/line-chart/private/line-chart-annotation.d.ts +0 -6
- package/dist/types/components/line-chart/private/line-chart-annotations-overlay.d.ts +0 -8
- package/dist/types/components/line-chart/types.d.ts +0 -61
- package/dist/types/components/pie-chart/index.d.ts +0 -1
- package/dist/types/components/pie-semi-circle-chart/index.d.ts +0 -1
- package/dist/types/components/private/single-chart-context/single-chart-context.d.ts +0 -19
- package/dist/types/components/tooltip/index.d.ts +0 -3
- package/dist/types/components/tooltip/types.d.ts +0 -8
- package/dist/types/index.d.ts +0 -18
- package/dist/types/providers/chart-context/global-charts-provider.d.ts +0 -14
- package/dist/types/providers/chart-context/hooks/use-chart-id.d.ts +0 -3
- package/dist/types/providers/chart-context/hooks/use-chart-registration.d.ts +0 -11
- package/dist/types/providers/chart-context/hooks/use-global-charts-context.d.ts +0 -5
- package/dist/types/providers/chart-context/hooks/use-global-charts-theme.d.ts +0 -14
- package/dist/types/providers/chart-context/index.d.ts +0 -6
- package/dist/types/providers/chart-context/types.d.ts +0 -29
- package/dist/types/providers/theme/index.d.ts +0 -2
- package/dist/types/providers/theme/theme-provider.d.ts +0 -20
- package/dist/types/providers/theme/themes.d.ts +0 -16
- package/dist/types/visx/group/index.d.ts +0 -1
- package/rollup.config.mjs +0 -109
- package/webpack.config.cjs +0 -144
- /package/dist/{mjs/visx/legend/index.js → visx/legend/index.d.cts} +0 -0
- /package/dist/{types/visx → visx}/legend/index.d.ts +0 -0
- /package/dist/{mjs/visx/text/index.js → visx/text/index.d.cts} +0 -0
- /package/dist/{types/visx → visx}/text/index.d.ts +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -5,18 +5,30 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [0.33.0] - 2025-09-08
|
|
9
|
+
### Added
|
|
10
|
+
- Add ability to control percentage vs. value display. [#45052]
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
- LeaderboardChart: Use GlobalContextProvider theme for colors. [#45067]
|
|
14
|
+
- Update package dependencies. [#45027] [#45097]
|
|
15
|
+
- Use `tsup` for builds. [#45051]
|
|
16
|
+
|
|
17
|
+
### Fixed
|
|
18
|
+
- Allow type-checking of tests and stories. [#45082]
|
|
19
|
+
|
|
8
20
|
## [0.32.0] - 2025-09-02
|
|
9
21
|
### Added
|
|
10
|
-
-
|
|
22
|
+
- Add controls for label visibility. [#45040]
|
|
11
23
|
|
|
12
24
|
### Changed
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
-
|
|
16
|
-
-
|
|
25
|
+
- Fix the conversion-funnel-chart component export. [#45033]
|
|
26
|
+
- Format percentage values to be prettier. [#45032]
|
|
27
|
+
- Use a global context provider for theme configuration in all stories. [#45028]
|
|
28
|
+
- Use `getStringWidth` for label size calculations. [#45030]
|
|
17
29
|
|
|
18
30
|
### Fixed
|
|
19
|
-
-
|
|
31
|
+
- Prevent z-index issue across all charts. [#45043]
|
|
20
32
|
|
|
21
33
|
## [0.31.0] - 2025-09-01
|
|
22
34
|
### Added
|
|
@@ -418,6 +430,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
418
430
|
- Fixed lints following ESLint rule changes for TS [#40584]
|
|
419
431
|
- Fixing a bug in Chart storybook data. [#40640]
|
|
420
432
|
|
|
433
|
+
[0.33.0]: https://github.com/Automattic/charts/compare/v0.32.0...v0.33.0
|
|
421
434
|
[0.32.0]: https://github.com/Automattic/charts/compare/v0.31.0...v0.32.0
|
|
422
435
|
[0.31.0]: https://github.com/Automattic/charts/compare/v0.30.0...v0.31.0
|
|
423
436
|
[0.30.0]: https://github.com/Automattic/charts/compare/v0.29.0...v0.30.0
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
.legend {
|
|
2
|
+
|
|
3
|
+
&--horizontal {
|
|
4
|
+
display: flex;
|
|
5
|
+
flex-direction: row;
|
|
6
|
+
flex-wrap: wrap;
|
|
7
|
+
gap: 16px;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
&--vertical {
|
|
11
|
+
display: flex;
|
|
12
|
+
flex-direction: column;
|
|
13
|
+
gap: 8px;
|
|
14
|
+
|
|
15
|
+
&.legend--alignment-start {
|
|
16
|
+
align-items: flex-start;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
&.legend--alignment-center {
|
|
20
|
+
align-items: center;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
&.legend--alignment-end {
|
|
24
|
+
align-items: flex-end;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Position-based styles
|
|
29
|
+
&--position-top {
|
|
30
|
+
position: relative;
|
|
31
|
+
|
|
32
|
+
&.legend--alignment-start {
|
|
33
|
+
justify-content: flex-start;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
&.legend--alignment-center {
|
|
37
|
+
justify-content: center;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
&.legend--alignment-end {
|
|
41
|
+
justify-content: flex-end;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
&--position-bottom {
|
|
46
|
+
position: relative;
|
|
47
|
+
|
|
48
|
+
&.legend--alignment-start {
|
|
49
|
+
justify-content: flex-start;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
&.legend--alignment-center {
|
|
53
|
+
justify-content: center;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
&.legend--alignment-end {
|
|
57
|
+
justify-content: flex-end;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.legend-item {
|
|
63
|
+
display: flex;
|
|
64
|
+
align-items: center;
|
|
65
|
+
font-size: 0.875rem;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
.legend-item-label {
|
|
69
|
+
display: flex;
|
|
70
|
+
align-items: center;
|
|
71
|
+
gap: 0.5rem;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.legend-item-value {
|
|
75
|
+
font-weight: 500;
|
|
76
|
+
}
|
|
@@ -29,4 +29,4 @@ type CustomTooltip = {
|
|
|
29
29
|
type BaseTooltipProps = TooltipCommonProps & (DefaultDataTooltip | CustomTooltip);
|
|
30
30
|
declare const BaseTooltip: ({ data, top, left, component: Component, children, className, }: BaseTooltipProps) => react_jsx_runtime.JSX.Element;
|
|
31
31
|
|
|
32
|
-
export { BaseTooltip, type
|
|
32
|
+
export { BaseTooltip as B, type TooltipData as T, type BaseTooltipProps as a };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { CSSProperties, ComponentType, ReactNode } from 'react';
|
|
3
|
+
|
|
4
|
+
type TooltipData = {
|
|
5
|
+
label: string;
|
|
6
|
+
value: number;
|
|
7
|
+
valueDisplay?: string;
|
|
8
|
+
};
|
|
9
|
+
type TooltipComponentProps = {
|
|
10
|
+
data: TooltipData;
|
|
11
|
+
className?: string;
|
|
12
|
+
};
|
|
13
|
+
type TooltipCommonProps = {
|
|
14
|
+
top: number;
|
|
15
|
+
left: number;
|
|
16
|
+
style?: CSSProperties;
|
|
17
|
+
className?: string;
|
|
18
|
+
};
|
|
19
|
+
type DefaultDataTooltip = {
|
|
20
|
+
data: TooltipData;
|
|
21
|
+
component?: ComponentType<TooltipComponentProps>;
|
|
22
|
+
children?: never;
|
|
23
|
+
};
|
|
24
|
+
type CustomTooltip = {
|
|
25
|
+
children: ReactNode;
|
|
26
|
+
data?: never;
|
|
27
|
+
component?: never;
|
|
28
|
+
};
|
|
29
|
+
type BaseTooltipProps = TooltipCommonProps & (DefaultDataTooltip | CustomTooltip);
|
|
30
|
+
declare const BaseTooltip: ({ data, top, left, component: Component, children, className, }: BaseTooltipProps) => react_jsx_runtime.JSX.Element;
|
|
31
|
+
|
|
32
|
+
export { BaseTooltip as B, type TooltipData as T, type BaseTooltipProps as a };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
.tooltip {
|
|
2
|
+
padding: 0.5rem;
|
|
3
|
+
background-color: rgba(0, 0, 0, 0.85);
|
|
4
|
+
color: #fff;
|
|
5
|
+
border-radius: 4px;
|
|
6
|
+
font-size: 14px;
|
|
7
|
+
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
|
|
8
|
+
position: absolute;
|
|
9
|
+
pointer-events: none;
|
|
10
|
+
transform: translate(-50%, -100%);
|
|
11
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var _chunkBNAXWJSFcjs = require('./chunk-BNAXWJSF.cjs');var _chunkRS3D7LRGcjs = require('./chunk-RS3D7LRG.cjs');var _chunk4CPALWEXcjs = require('./chunk-4CPALWEX.cjs');var _chunkHJYSGVCMcjs = require('./chunk-HJYSGVCM.cjs');var _chunk76MUGFRKcjs = require('./chunk-76MUGFRK.cjs');var _chunkSJSVNSI5cjs = require('./chunk-SJSVNSI5.cjs');var _group = require('@visx/group');var _shape = require('@visx/shape');var _clsx = require('clsx'); var _clsx2 = _interopRequireDefault(_clsx);var _react = require('react');var p="./pie-chart.module-LOP3Y52M.scss";var _jsxruntime = require('react/jsx-runtime');var we=o=>{if(!o.length)return{isValid:!1,message:"No data available"};if(o.some(r=>r.percentage<0||r.value<0))return{isValid:!1,message:"Invalid data: Negative values are not allowed"};let n=o.reduce((r,i)=>r+i.percentage,0);return Math.abs(n-100)>.01?{isValid:!1,message:"Invalid percentage total: Must equal 100"}:{isValid:!0,message:""}},te=({data:o,chartId:C,withTooltips:n=!1,className:r,showLegend:i=!1,legendOrientation:oe="horizontal",legendPosition:g="bottom",legendAlignment:ae="center",legendShape:re="circle",size:D,thickness:h=1,padding:ne=20,gapScale:P=0,cornerScale:d=0,showLabels:ie=!0,legendValueDisplay:L="percentage",children:se=null})=>{let f=_chunkSJSVNSI5cjs.u.call(void 0, ),v=_chunkSJSVNSI5cjs.q.call(void 0, C),[le,pe]=_chunkSJSVNSI5cjs.y.call(void 0, ),{onMouseMove:he,onMouseLeave:de,tooltipOpen:me,tooltipData:I,tooltipLeft:ce,tooltipTop:ue}=_chunkSJSVNSI5cjs.b.call(void 0, {withTooltips:n}),Ce=_react.useMemo.call(void 0, ()=>({showValues:!0,legendValueDisplay:L}),[L]),ge=_chunk76MUGFRKcjs.d.call(void 0, o,Ce),{isValid:S,message:Pe}=we(o),{svgChildren:fe,htmlChildren:ve,otherChildren:xe}=_chunkBNAXWJSFcjs.c.call(void 0, se,"PieChart"),be=_react.useMemo.call(void 0, ()=>({thickness:h,gapScale:P,cornerScale:d}),[h,P,d]);_chunkSJSVNSI5cjs.r.call(void 0, {chartId:v,legendItems:ge,chartType:"pie",isDataValid:S,metadata:be});let{resolveGroupColor:Me}=_chunkSJSVNSI5cjs.p.call(void 0, );if(!S)return _jsxruntime.jsx.call(void 0, "div",{className:_clsx2.default.call(void 0, "pie-chart",p["pie-chart"],r),children:_jsxruntime.jsx.call(void 0, "div",{className:p["error-message"],children:Pe})});let s=D,H=D,l=i&&g==="top"?H-pe:H,ye=Math.min(s,l)/2,Re=s/2,Ve=l/2,Ge=P*(2*Math.PI/o.length),m=ye-ne,N=h===0?0:m*(1-h),De=(m-N)/2,Le=d?Math.min(d*m,De):0,Ie=o.map((a,t)=>({...a,index:t})),B={value:a=>a.value,fill:({group:a,index:t,color:x})=>Me({group:a,index:t,overrideColor:x})};return _jsxruntime.jsx.call(void 0, _chunk76MUGFRKcjs.a.Provider,{value:{chartId:v,chartWidth:s,chartHeight:l},children:_jsxruntime.jsxs.call(void 0, "div",{className:_clsx2.default.call(void 0, "pie-chart",p["pie-chart"],r),style:{display:"flex",flexDirection:i&&g==="top"?"column-reverse":"column"},children:[_jsxruntime.jsx.call(void 0, "svg",{viewBox:`0 0 ${s} ${l}`,preserveAspectRatio:"xMidYMid meet",width:s,height:l,children:_jsxruntime.jsxs.call(void 0, _group.Group,{top:Ve,left:Re,children:[_jsxruntime.jsx.call(void 0, _shape.Pie,{data:Ie,pieValue:B.value,outerRadius:m,innerRadius:N,padAngle:Ge,cornerRadius:Le,children:a=>a.arcs.map((t,x)=>{let[T,W]=a.path.centroid(t),Se=t.endAngle-t.startAngle>=.25,He=Be=>he(Be,t.data),b={d:a.path(t)||"",fill:B.fill(t.data)};n&&(b.onMouseMove=He,b.onMouseLeave=de);let M=12,Ne=_chunkRS3D7LRGcjs.c.call(void 0, t.data.label,{fontSize:M}),E=6,A=Ne+E*2,w=M+E*2;return _jsxruntime.jsxs.call(void 0, "g",{children:[_jsxruntime.jsx.call(void 0, "path",{...b}),ie&&Se&&_jsxruntime.jsxs.call(void 0, "g",{children:[f.labelBackgroundColor&&_jsxruntime.jsx.call(void 0, "rect",{x:T-A/2,y:W-w/2,width:A,height:w,fill:f.labelBackgroundColor,rx:4,ry:4,pointerEvents:"none"}),_jsxruntime.jsx.call(void 0, "text",{x:T,y:W,dy:".33em",fill:f.labelTextColor||"#333",fontSize:M,textAnchor:"middle",pointerEvents:"none",children:t.data.label})]})]},`arc-${x}`)})}),fe]})}),i&&_jsxruntime.jsx.call(void 0, _chunk76MUGFRKcjs.c,{orientation:oe,position:g,alignment:ae,className:p["pie-chart-legend"],shape:re,ref:le,chartId:v}),n&&me&&I&&_jsxruntime.jsx.call(void 0, _chunkHJYSGVCMcjs.a,{data:I,top:ue||0,left:ce||0,style:{transform:"translate(-50%, -100%)"}}),ve,xe]})})},G=o=>_react.useContext.call(void 0, _chunkSJSVNSI5cjs.n)?_jsxruntime.jsx.call(void 0, te,{...o}):_jsxruntime.jsx.call(void 0, _chunkSJSVNSI5cjs.o,{children:_jsxruntime.jsx.call(void 0, te,{...o})});G.displayName="PieChart";var Oe=_chunkSJSVNSI5cjs.c.call(void 0, G,{Legend:_chunk76MUGFRKcjs.c,SVG:_chunkBNAXWJSFcjs.a,HTML:_chunkBNAXWJSFcjs.b}),ke= exports.b =_chunkSJSVNSI5cjs.c.call(void 0, _chunk4CPALWEXcjs.a.call(void 0, G),{Legend:_chunk76MUGFRKcjs.c,SVG:_chunkBNAXWJSFcjs.a,HTML:_chunkBNAXWJSFcjs.b});exports.a = Oe; exports.b = ke;
|
|
2
|
+
//# sourceMappingURL=chunk-253F4WJT.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/jetpack/jetpack/projects/js-packages/charts/dist/chunk-253F4WJT.cjs","../src/components/pie-chart/pie-chart.tsx"],"names":["validateData","data","item","totalPercentage","sum","PieChartInternal","providedChartId","withTooltips","className","showLegend","legendOrientation","legendPosition","legendAlignment","legendShape","size","thickness","padding","gapScale","cornerScale","showLabels","legendValueDisplay","children","providerTheme","useGlobalChartsTheme","chartId","useChartId","legendRef","legendHeight","useElementHeight","onMouseMove","onMouseLeave","tooltipOpen","tooltipData","tooltipLeft","tooltipTop","useChartMouseHandler","legendOptions","useMemo","legendItems","useChartLegendItems","isValid","message","svgChildren","htmlChildren","otherChildren","useChartChildren","chartMetadata","useChartRegistration","resolveGroupColor","useGlobalChartsContext","jsx","clsx","pie_chart_module_default","width","height","adjustedHeight","radius","centerX","centerY","padAngle","outerRadius","innerRadius","maxCornerRadius","cornerRadius","dataWithIndex","d","index","accessors","group","overrideColor","SingleChartContext","jsxs"],"mappings":"AAAA,iOAAsD,wDAAyC,wDAAyC,wDAAyC,wDAAkD,wDAAiG,oCCA9S,oCACF,wEACH,8BACmB,IDHmb,CAAC,CAAC,kCAAkC,CCsLvf,+CAAA,IA5FEA,EAAAA,CAAiBC,CAAAA,EAAiC,CACvD,EAAA,CAAK,CAAEA,CAAAA,CAAK,MAAA,CACX,MAAO,CAAE,OAAA,CAAS,CAAA,CAAA,CAAO,OAAA,CAAS,mBAAoB,CAAA,CAKvD,EAAA,CAD0BA,CAAAA,CAAK,IAAA,CAAMC,CAAAA,EAAQA,CAAAA,CAAK,UAAA,CAAa,CAAA,EAAKA,CAAAA,CAAK,KAAA,CAAQ,CAAE,CAAA,CAElF,MAAO,CAAE,OAAA,CAAS,CAAA,CAAA,CAAO,OAAA,CAAS,+CAAgD,CAAA,CAInF,IAAMC,CAAAA,CAAkBF,CAAAA,CAAK,MAAA,CAAQ,CAAEG,CAAAA,CAAKF,CAAAA,CAAAA,EAAUE,CAAAA,CAAMF,CAAAA,CAAK,UAAA,CAAY,CAAE,CAAA,CAC/E,OAAK,IAAA,CAAK,GAAA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AA,mBAACoB,CAAmB,QAAA,CAAnB,CACA,KAAA,CAAQ,CACP,OAAA,CAAA9C,CAAAA,CACA,UAAA,CAAY6B,CAAAA,CACZ,WAAA,CAAaE,CACd,CAAA,CAEA,QAAA,CAAAgB,8BAAAA,KAAC,CAAA,CACA,SAAA,CAAYpB,4BAAAA,WAAM,CAAaC,CAAAA,CAAQ,WAAY,CAAA,CAAG5C,CAAU,CAAA,CAChE,KAAA,CAAQ,CACP,OAAA,CAAS,MAAA,CACT,aAAA,CAAeC,CAAAA,EAAcE,CAAAA,GAAmB,KAAA,CAAQ,gBAAA,CAAmB,QAC5E,CAAA,CAEA,QAAA,CAAA,CAAAuC,6BAAAA,KAAC,CAAA,CACA,OAAA,CAAU,CAAA,IAAA,EAAQG,CAAM,CAAA,CAAA,EAAKE,CAAe,CAAA,CAAA","file":"/home/runner/work/jetpack/jetpack/projects/js-packages/charts/dist/chunk-253F4WJT.cjs","sourcesContent":[null,"import { Group } from '@visx/group';\nimport { Pie } from '@visx/shape';\nimport clsx from 'clsx';\nimport { useContext, useMemo } from 'react';\nimport { useChartMouseHandler, useElementHeight } from '../../hooks';\nimport {\n\tGlobalChartsProvider,\n\tuseChartId,\n\tuseChartRegistration,\n\tuseGlobalChartsContext,\n\tuseGlobalChartsTheme,\n} from '../../providers/chart-context';\nimport { GlobalChartsContext } from '../../providers/chart-context/global-charts-provider';\nimport { attachSubComponents } from '../../utils';\nimport { getStringWidth } from '../../visx/text';\nimport { Legend, useChartLegendItems } from '../legend';\nimport { ChartSVG, ChartHTML, useChartChildren } from '../private/chart-composition';\nimport { SingleChartContext } from '../private/single-chart-context';\nimport { withResponsive, ResponsiveConfig } from '../private/with-responsive';\nimport { BaseTooltip } from '../tooltip';\nimport styles from './pie-chart.module.scss';\nimport type { BaseChartProps, DataPointPercentage, Optional } from '../../types';\nimport type { LegendValueDisplay } from '../legend';\nimport type { ChartComponentWithComposition } from '../private/chart-composition';\nimport type { SVGProps, MouseEvent, ReactNode, FC } from 'react';\n\nexport interface PieChartProps extends BaseChartProps< DataPointPercentage[] > {\n\t/**\n\t * Inner radius in pixels. If > 0, creates a donut chart. Defaults to 0.\n\t */\n\tinnerRadius?: number;\n\n\t/**\n\t * Add padding to the chart\n\t */\n\tpadding?: number;\n\n\t/**\n\t * Thickness of the pie chart.\n\t * A value between 0 and 1, where 0 means no thickness\n\t * and 1 means the maximum thickness.\n\t */\n\tthickness?: number;\n\n\t/**\n\t * Scale of the gap between groups in the pie chart\n\t * A value between 0 and 1, where 0 means no gap.\n\t */\n\tgapScale?: number;\n\n\t/**\n\t * Scale of the corner radius for the pie chart segments.\n\t * A value between 0 and 1, where 0 means no corner radius.\n\t */\n\tcornerScale?: number;\n\n\t/**\n\t * Whether to show labels on pie segments. Defaults to true.\n\t */\n\tshowLabels?: boolean;\n\n\t/**\n\t * What type of value to display in the legend when showValues is true.\n\t * - 'percentage': Shows percentage values (e.g., \"23%\") [default]\n\t * - 'value': Shows raw numeric values (e.g., \"30000\")\n\t * - 'valueDisplay': Shows formatted values (e.g., \"30K\")\n\t * - 'none': Shows no values, only labels\n\t */\n\tlegendValueDisplay?: LegendValueDisplay;\n\n\t/**\n\t * Use the children prop to render additional elements on the chart.\n\t */\n\tchildren?: ReactNode;\n}\n\n// Base props type with optional responsive properties\ntype PieChartBaseProps = Optional< PieChartProps, 'size' >;\n\n// Composition API types\ntype PieChartComponent = ChartComponentWithComposition< PieChartBaseProps >;\ntype PieChartResponsiveComponent = ChartComponentWithComposition<\n\tPieChartBaseProps & ResponsiveConfig\n>;\n\n/**\n * Validates the pie chart data\n * @param data - The data to validate\n * @return Object containing validation result and error message\n */\nconst validateData = ( data: DataPointPercentage[] ) => {\n\tif ( ! data.length ) {\n\t\treturn { isValid: false, message: 'No data available' };\n\t}\n\n\t// Check for negative values\n\tconst hasNegativeValues = data.some( item => item.percentage < 0 || item.value < 0 );\n\tif ( hasNegativeValues ) {\n\t\treturn { isValid: false, message: 'Invalid data: Negative values are not allowed' };\n\t}\n\n\t// Validate total percentage\n\tconst totalPercentage = data.reduce( ( sum, item ) => sum + item.percentage, 0 );\n\tif ( Math.abs( totalPercentage - 100 ) > 0.01 ) {\n\t\t// Using small epsilon for floating point comparison\n\t\treturn { isValid: false, message: 'Invalid percentage total: Must equal 100' };\n\t}\n\n\treturn { isValid: true, message: '' };\n};\n\n/**\n * Renders a pie or donut chart using the provided data.\n *\n * @param {PieChartProps} props - Component props\n * @return {JSX.Element} The rendered chart component\n */\nconst PieChartInternal = ( {\n\tdata,\n\tchartId: providedChartId,\n\twithTooltips = false,\n\tclassName,\n\tshowLegend = false,\n\tlegendOrientation = 'horizontal',\n\tlegendPosition = 'bottom',\n\tlegendAlignment = 'center',\n\tlegendShape = 'circle',\n\tsize,\n\tthickness = 1,\n\tpadding = 20,\n\tgapScale = 0,\n\tcornerScale = 0,\n\tshowLabels = true,\n\tlegendValueDisplay = 'percentage',\n\tchildren = null,\n}: PieChartProps ) => {\n\tconst providerTheme = useGlobalChartsTheme();\n\tconst chartId = useChartId( providedChartId );\n\tconst [ legendRef, legendHeight ] = useElementHeight< HTMLDivElement >();\n\tconst { onMouseMove, onMouseLeave, tooltipOpen, tooltipData, tooltipLeft, tooltipTop } =\n\t\tuseChartMouseHandler( {\n\t\t\twithTooltips,\n\t\t} );\n\n\t// Memoize legend options to prevent unnecessary re-calculations\n\tconst legendOptions = useMemo(\n\t\t() => ( { showValues: true, legendValueDisplay } ),\n\t\t[ legendValueDisplay ]\n\t);\n\n\t// Create legend items using the reusable hook\n\tconst legendItems = useChartLegendItems( data, legendOptions );\n\n\tconst { isValid, message } = validateData( data );\n\n\t// Process children to extract compound components\n\tconst { svgChildren, htmlChildren, otherChildren } = useChartChildren( children, 'PieChart' );\n\n\t// Memoize metadata to prevent unnecessary re-registration\n\tconst chartMetadata = useMemo(\n\t\t() => ( {\n\t\t\tthickness,\n\t\t\tgapScale,\n\t\t\tcornerScale,\n\t\t} ),\n\t\t[ thickness, gapScale, cornerScale ]\n\t);\n\n\t// Register chart with context only if data is valid\n\tuseChartRegistration( {\n\t\tchartId,\n\t\tlegendItems,\n\t\tchartType: 'pie',\n\t\tisDataValid: isValid,\n\t\tmetadata: chartMetadata,\n\t} );\n\n\tconst { resolveGroupColor } = useGlobalChartsContext();\n\n\tif ( ! isValid ) {\n\t\treturn (\n\t\t\t<div className={ clsx( 'pie-chart', styles[ 'pie-chart' ], className ) }>\n\t\t\t\t<div className={ styles[ 'error-message' ] }>{ message }</div>\n\t\t\t</div>\n\t\t);\n\t}\n\n\tconst width = size;\n\tconst height = size;\n\tconst adjustedHeight = showLegend && legendPosition === 'top' ? height - legendHeight : height;\n\n\t// Calculate radius based on width/height\n\tconst radius = Math.min( width, adjustedHeight ) / 2;\n\n\t// Center the chart in the available space\n\tconst centerX = width / 2;\n\tconst centerY = adjustedHeight / 2;\n\n\t// Calculate the angle between each\n\tconst padAngle = gapScale * ( ( 2 * Math.PI ) / data.length );\n\n\tconst outerRadius = radius - padding;\n\tconst innerRadius = thickness === 0 ? 0 : outerRadius * ( 1 - thickness );\n\n\tconst maxCornerRadius = ( outerRadius - innerRadius ) / 2;\n\tconst cornerRadius = cornerScale ? Math.min( cornerScale * outerRadius, maxCornerRadius ) : 0;\n\n\t// Map the data to include index for color assignment\n\tconst dataWithIndex = data.map( ( d, index ) => ( {\n\t\t...d,\n\t\tindex,\n\t} ) );\n\n\tconst accessors = {\n\t\tvalue: ( d: DataPointPercentage ) => d.value,\n\t\t// Use the color property from the data object as a last resort. The theme provides colours by default.\n\t\tfill: ( { group, index, color: overrideColor }: DataPointPercentage & { index: number } ) =>\n\t\t\tresolveGroupColor( { group, index, overrideColor } ),\n\t};\n\n\treturn (\n\t\t<SingleChartContext.Provider\n\t\t\tvalue={ {\n\t\t\t\tchartId,\n\t\t\t\tchartWidth: width,\n\t\t\t\tchartHeight: adjustedHeight,\n\t\t\t} }\n\t\t>\n\t\t\t<div\n\t\t\t\tclassName={ clsx( 'pie-chart', styles[ 'pie-chart' ], className ) }\n\t\t\t\tstyle={ {\n\t\t\t\t\tdisplay: 'flex',\n\t\t\t\t\tflexDirection: showLegend && legendPosition === 'top' ? 'column-reverse' : 'column',\n\t\t\t\t} }\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\tviewBox={ `0 0 ${ width } ${ adjustedHeight }` }\n\t\t\t\t\tpreserveAspectRatio=\"xMidYMid meet\"\n\t\t\t\t\twidth={ width }\n\t\t\t\t\theight={ adjustedHeight }\n\t\t\t\t>\n\t\t\t\t\t<Group top={ centerY } left={ centerX }>\n\t\t\t\t\t\t<Pie< DataPointPercentage & { index: number } >\n\t\t\t\t\t\t\tdata={ dataWithIndex }\n\t\t\t\t\t\t\tpieValue={ accessors.value }\n\t\t\t\t\t\t\touterRadius={ outerRadius }\n\t\t\t\t\t\t\tinnerRadius={ innerRadius }\n\t\t\t\t\t\t\tpadAngle={ padAngle }\n\t\t\t\t\t\t\tcornerRadius={ cornerRadius }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ pie => {\n\t\t\t\t\t\t\t\treturn pie.arcs.map( ( arc, index ) => {\n\t\t\t\t\t\t\t\t\tconst [ centroidX, centroidY ] = pie.path.centroid( arc );\n\t\t\t\t\t\t\t\t\tconst hasSpaceForLabel = arc.endAngle - arc.startAngle >= 0.25;\n\t\t\t\t\t\t\t\t\tconst handleMouseMove = ( event: MouseEvent< SVGElement > ) =>\n\t\t\t\t\t\t\t\t\t\tonMouseMove( event, arc.data );\n\n\t\t\t\t\t\t\t\t\tconst pathProps: SVGProps< SVGPathElement > = {\n\t\t\t\t\t\t\t\t\t\td: pie.path( arc ) || '',\n\t\t\t\t\t\t\t\t\t\tfill: accessors.fill( arc.data ),\n\t\t\t\t\t\t\t\t\t};\n\n\t\t\t\t\t\t\t\t\tif ( withTooltips ) {\n\t\t\t\t\t\t\t\t\t\tpathProps.onMouseMove = handleMouseMove;\n\t\t\t\t\t\t\t\t\t\tpathProps.onMouseLeave = onMouseLeave;\n\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t// Estimate text width more accurately for background sizing\n\t\t\t\t\t\t\t\t\tconst fontSize = 12;\n\t\t\t\t\t\t\t\t\tconst estimatedTextWidth = getStringWidth( arc.data.label, { fontSize } );\n\t\t\t\t\t\t\t\t\tconst labelPadding = 6;\n\t\t\t\t\t\t\t\t\tconst backgroundWidth = estimatedTextWidth + labelPadding * 2;\n\t\t\t\t\t\t\t\t\tconst backgroundHeight = fontSize + labelPadding * 2;\n\n\t\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t\t<g key={ `arc-${ index }` }>\n\t\t\t\t\t\t\t\t\t\t\t<path { ...pathProps } />\n\t\t\t\t\t\t\t\t\t\t\t{ showLabels && hasSpaceForLabel && (\n\t\t\t\t\t\t\t\t\t\t\t\t<g>\n\t\t\t\t\t\t\t\t\t\t\t\t\t{ providerTheme.labelBackgroundColor && (\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<rect\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tx={ centroidX - backgroundWidth / 2 }\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\ty={ centroidY - backgroundHeight / 2 }\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\twidth={ backgroundWidth }\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\theight={ backgroundHeight }\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tfill={ providerTheme.labelBackgroundColor }\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\trx={ 4 }\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\try={ 4 }\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tpointerEvents=\"none\"\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t\t\t\t\t<text\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tx={ centroidX }\n\t\t\t\t\t\t\t\t\t\t\t\t\t\ty={ centroidY }\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tdy=\".33em\"\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tfill={ providerTheme.labelTextColor || '#333' }\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tfontSize={ fontSize }\n\t\t\t\t\t\t\t\t\t\t\t\t\t\ttextAnchor=\"middle\"\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tpointerEvents=\"none\"\n\t\t\t\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t{ arc.data.label }\n\t\t\t\t\t\t\t\t\t\t\t\t\t</text>\n\t\t\t\t\t\t\t\t\t\t\t\t</g>\n\t\t\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t\t</g>\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t</Pie>\n\n\t\t\t\t\t\t{ /* Render SVG children (like Group, Text) inside the SVG */ }\n\t\t\t\t\t\t{ svgChildren }\n\t\t\t\t\t</Group>\n\t\t\t\t</svg>\n\n\t\t\t\t{ showLegend && (\n\t\t\t\t\t<Legend\n\t\t\t\t\t\torientation={ legendOrientation }\n\t\t\t\t\t\tposition={ legendPosition }\n\t\t\t\t\t\talignment={ legendAlignment }\n\t\t\t\t\t\tclassName={ styles[ 'pie-chart-legend' ] }\n\t\t\t\t\t\tshape={ legendShape }\n\t\t\t\t\t\tref={ legendRef }\n\t\t\t\t\t\tchartId={ chartId }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\n\t\t\t\t{ withTooltips && tooltipOpen && tooltipData && (\n\t\t\t\t\t<BaseTooltip\n\t\t\t\t\t\tdata={ tooltipData }\n\t\t\t\t\t\ttop={ tooltipTop || 0 }\n\t\t\t\t\t\tleft={ tooltipLeft || 0 }\n\t\t\t\t\t\tstyle={ {\n\t\t\t\t\t\t\ttransform: 'translate(-50%, -100%)',\n\t\t\t\t\t\t} }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\n\t\t\t\t{ /* Render HTML component children from PieChart.HTML */ }\n\t\t\t\t{ htmlChildren }\n\n\t\t\t\t{ /* Render other React children for backward compatibility */ }\n\t\t\t\t{ otherChildren }\n\t\t\t</div>\n\t\t</SingleChartContext.Provider>\n\t);\n};\n\nconst PieChartWithProvider: FC< PieChartProps > = props => {\n\tconst existingContext = useContext( GlobalChartsContext );\n\n\t// If we're already in a GlobalChartsProvider context, don't create a new one\n\tif ( existingContext ) {\n\t\treturn <PieChartInternal { ...props } />;\n\t}\n\n\t// Otherwise, create our own GlobalChartsProvider\n\treturn (\n\t\t<GlobalChartsProvider>\n\t\t\t<PieChartInternal { ...props } />\n\t\t</GlobalChartsProvider>\n\t);\n};\n\nPieChartWithProvider.displayName = 'PieChart';\n\n// Create PieChart with composition API\nconst PieChart = attachSubComponents( PieChartWithProvider, {\n\tLegend: Legend,\n\tSVG: ChartSVG,\n\tHTML: ChartHTML,\n} ) as PieChartComponent;\n\n// Create responsive PieChart with composition API\nconst PieChartResponsive = attachSubComponents(\n\twithResponsive< PieChartProps >( PieChartWithProvider ),\n\t{\n\t\tLegend: Legend,\n\t\tSVG: ChartSVG,\n\t\tHTML: ChartHTML,\n\t}\n) as PieChartResponsiveComponent;\n\nexport { PieChartResponsive as default, PieChart as PieChartUnresponsive };\n"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _chunkJNA2WFY7cjs = require('./chunk-JNA2WFY7.cjs');var _chunk4CPALWEXcjs = require('./chunk-4CPALWEX.cjs');var _chunkSJSVNSI5cjs = require('./chunk-SJSVNSI5.cjs');var _numberformatters = require('@automattic/number-formatters');var _group = require('@visx/group');var _scale = require('@visx/scale');var _text = require('@visx/text');var _react = require('react');var _jsxruntime = require('react/jsx-runtime');var h=e=>{let t=e;return t&&"bandwidth"in t?_nullishCoalesce(_optionalChain([t, 'optionalAccess', _2 => _2.bandwidth, 'call', _3 => _3()]), () => (0)):0},G=({textProps:e,x:t,y:a,label:r,formatter:n})=>_jsxruntime.jsx.call(void 0, _text.Text,{...e,textAnchor:"start",x:t,y:a,children:n(r)}),N=({textProps:e,x:t,y:a,value:r,formatter:n})=>_jsxruntime.jsx.call(void 0, _text.Text,{...e,textAnchor:"end",x:t,y:a,fontWeight:500,children:n(r)}),_=({ticks:e,tickLabelProps:t,yOffset:a,labelPosition:r,valuePosition:n,data:p,labelFormatter:o,valueFormatter:s,LabelComponent:c=G,ValueComponent:m=N})=>{if(e.length===0)return null;let b=e.map(({value:u,index:i})=>typeof t=="function"?t(u,i,e):{});return e.map(({from:u,formattedValue:i},f)=>{let x=_nullishCoalesce(b[f], () => ({}));delete x.textAnchor,delete x.dx;let L=p.reduce((A,{data:R})=>A+(_nullishCoalesce(_optionalChain([R, 'access', _4 => _4[f], 'optionalAccess', _5 => _5.value]), () => (0))),0),d=u.y+a;return _jsxruntime.jsxs.call(void 0, _group.Group,{children:[_jsxruntime.jsx.call(void 0, c,{textProps:x,x:r,y:d,label:i,formatter:o}),_jsxruntime.jsx.call(void 0, m,{textProps:x,x:n,y:d,value:L,formatter:s,data:p,index:f})]},f)})},w=(e,t,a,r)=>{if(!r)return 0;let n=e.map(({label:m})=>m),p=_scale.createScale.call(void 0, {type:"band",range:[0,a],domain:n,...t}),o=_scale.scaleBand.call(void 0, {domain:n,range:[0,h(p)],padding:t.paddingInner});return-(h(o)+6)},v=({data:e,width:t,height:a,options:r={},margin:n={left:0,right:20,bottom:0,top:0},...p})=>{let o=_react.useMemo.call(void 0, ()=>{let s=e.length>1,c={paddingInner:s?.3:.1,padding:s?.3:.1},m={zero:!0},b={...c,..._nullishCoalesce(r.yScale, () => ({}))},u={...m,..._nullishCoalesce(r.xScale, () => ({}))};return{yScale:b,xScale:u,labelPosition:_nullishCoalesce(r.labelPosition, () => ((s?0:10))),valueFormatter:_nullishCoalesce(r.valueFormatter, () => ((i=>_numberformatters.formatNumberCompact.call(void 0, i)))),labelFormatter:_nullishCoalesce(r.labelFormatter, () => ((i=>String(i)))),valuePosition:_nullishCoalesce(r.valuePosition, () => (t)),yOffset:_nullishCoalesce(r.yOffset, () => (w(e,b,a,s)))}},[r,t,e,a]);return _jsxruntime.jsx.call(void 0, _chunkJNA2WFY7cjs.a,{orientation:"horizontal",gridVisibility:"none",data:e,width:t,height:a,margin:n,options:{axis:{y:{children:s=>_jsxruntime.jsx.call(void 0, _,{...s,data:e,yOffset:o.yOffset,labelPosition:o.labelPosition,valuePosition:o.valuePosition,labelFormatter:o.labelFormatter,valueFormatter:o.valueFormatter,LabelComponent:r.labelComponent,ValueComponent:r.valueComponent})},x:{children:()=>null}},xScale:o.xScale,yScale:o.yScale},...p})},B=e=>_react.useContext.call(void 0, _chunkSJSVNSI5cjs.n)?_jsxruntime.jsx.call(void 0, v,{...e}):_jsxruntime.jsx.call(void 0, _chunkSJSVNSI5cjs.o,{children:_jsxruntime.jsx.call(void 0, v,{...e})});B.displayName="BarListChart";var z=_chunk4CPALWEXcjs.a.call(void 0, B);exports.a = z;
|
|
2
|
+
//# sourceMappingURL=chunk-2CEQF5RH.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/jetpack/jetpack/projects/js-packages/charts/dist/chunk-2CEQF5RH.cjs","../src/components/bar-list-chart/bar-list-chart.tsx"],"names":["getScaleBandwidth","scale","s","DefaultLabelComponent","textProps","x","y","label","formatter","jsx","Text","DefaultValueComponent","value","AxisRenderer","ticks","tickLabelProps","yOffset","labelPosition","valuePosition","data","labelFormatter","valueFormatter","LabelComponent","ValueComponent","allTickLabelProps","index","from","formattedValue","sum","acc","seriesData","jsxs","Group","getDefaultYOffset","yScaleConfig","height","isMultiSeries","dataKeys","yScale","createScale","groupScale","scaleBand","BarListChartInternal","width","options","margin","rest","chartOptions","useMemo","defaultYScale","defaultXScale","xScale","formatNumberCompact","BarChartResponsive","renderProps","BarListChart","props","useContext","GlobalChartsProvider","BarListChartResponsive","withResponsive"],"mappings":"AAAA,yuBAAwC,wDAAyC,wDAAgD,iECA7F,oCACd,oCACiB,kCACF,8BACD,+CA0FlC,IARIA,CAAAA,CAAiDC,CAAAA,EAAmB,CAEzE,IAAMC,CAAAA,CAAID,CAAAA,CACV,OAAOC,CAAAA,EAAK,WAAA,GAAeA,CAAAA,kCAAIA,CAAAA,6BAAG,SAAA,mBAAU,GAAA,SAAK,GAAA,CAAI,CACtD,CAAA,CAEMC,CAAAA,CAAwB,CAAE,CAAE,SAAA,CAAAC,CAAAA,CAAW,CAAA,CAAAC,CAAAA,CAAG,CAAA,CAAAC,CAAAA,CAAG,KAAA,CAAAC,CAAAA,CAAO,SAAA,CAAAC,CAAU,CAAA,CAAA,EAElEC,6BAAAA,UAACC,CAAA,CAAO,GAAGN,CAAAA,CAAY,UAAA,CAAW,OAAA,CAAQ,CAAA,CAAIC,CAAAA,CAAI,CAAA,CAAIC,CAAAA,CACnD,QAAA,CAAAE,CAAAA,CAAWD,CAAM,CAAA,CACpB,CAAA,CAIII,CAAAA,CAAwB,CAAE,CAAE,SAAA,CAAAP,CAAAA,CAAW,CAAA,CAAAC,CAAAA,CAAG,CAAA,CAAAC,CAAAA,CAAG,KAAA,CAAAM,CAAAA,CAAO,SAAA,CAAAJ,CAAU,CAAA,CAAA,EAElEC,6BAAAA,UAACC,CAAA,CAAO,GAAGN,CAAAA,CAAY,UAAA,CAAW,KAAA,CAAM,CAAA,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jD,6BAAAA,CAACiC,CAAA,CAAuB,GAAGc,CAAAA,CAAQ,CAAA,CACpC,CAAA,CAIFD,CAAAA,CAAa,WAAA,CAAc,cAAA,CAE3B,IAAMI,CAAAA,CAAyBC,iCAAAA,CAAkD,CAAA,CAAA,cAAA","file":"/home/runner/work/jetpack/jetpack/projects/js-packages/charts/dist/chunk-2CEQF5RH.cjs","sourcesContent":[null,"import { formatNumberCompact } from '@automattic/number-formatters';\nimport { Group } from '@visx/group';\nimport { createScale, scaleBand } from '@visx/scale';\nimport { Text, type TextProps } from '@visx/text';\nimport { useContext, useMemo } from 'react';\nimport { GlobalChartsContext, GlobalChartsProvider } from '../../providers/chart-context';\nimport { BarChart } from '../bar-chart';\nimport { withResponsive } from '../private/with-responsive';\nimport type { SeriesData } from '../..';\nimport type { ScaleOptions } from '../../types';\nimport type { BarChartProps } from '../bar-chart/bar-chart';\nimport type { AxisRendererProps, AxisScale } from '@visx/axis';\nimport type { AnyD3Scale } from '@visx/scale';\nimport type { ComponentType, FC } from 'react';\n\nexport interface BarListChartProps\n\textends Exclude< BarChartProps, 'orientation' | 'size' | 'gridVisibility' > {\n\toptions?: {\n\t\t/**\n\t\t * Scale for the y axis. Exclude the type property.\n\t\t */\n\t\tyScale: Omit< ScaleOptions, 'type' >;\n\t\t/**\n\t\t * Scale for the x axis. Exclude the type property.\n\t\t */\n\t\txScale: Omit< ScaleOptions, 'type' >;\n\t\t/**\n\t\t * Formatter for the label.\n\t\t */\n\t\tlabelFormatter?: ( value: string ) => string;\n\t\t/**\n\t\t * Formatter for the value.\n\t\t */\n\t\tvalueFormatter?: ( value: number ) => string;\n\t\t/**\n\t\t * y offset of the label and value. Default is based on the number of series, automatically computed.\n\t\t */\n\t\tyOffset?: number;\n\t\t/**\n\t\t * x position of the label.\n\t\t */\n\t\tlabelPosition?: number;\n\t\t/**\n\t\t * x position of the value.\n\t\t */\n\t\tvaluePosition?: number;\n\t\t/**\n\t\t * Custom render function for the label.\n\t\t */\n\t\tlabelComponent?: ComponentType< RenderLabelProps >;\n\t\t/**\n\t\t * Custom render function for the value.\n\t\t */\n\t\tvalueComponent?: ComponentType< RenderValueProps >;\n\t};\n}\n\nexport interface RenderLabelProps {\n\ttextProps: TextProps;\n\tx: number;\n\ty: number;\n\tlabel: string;\n\tformatter: ( value: string ) => string;\n}\n\nexport interface RenderValueProps {\n\ttextProps: TextProps;\n\tx: number;\n\ty: number;\n\tvalue: number;\n\t/**\n\t * Original data\n\t */\n\tdata: SeriesData[];\n\t/**\n\t * Index of the data point\n\t */\n\tindex: number;\n\tformatter: ( value: number ) => string;\n}\n\n/**\n * Get the bandwidth of a scale\n * @param scale - The scale to get the bandwidth of\n * @return The bandwidth of the scale\n */\nconst getScaleBandwidth = < Scale extends AxisScale >( scale?: Scale ) => {\n\t// Broaden type before using 'xxx' in s as typeguard.\n\tconst s = scale as AxisScale;\n\treturn s && 'bandwidth' in s ? s?.bandwidth() ?? 0 : 0;\n};\n\nconst DefaultLabelComponent = ( { textProps, x, y, label, formatter } ) => {\n\treturn (\n\t\t<Text { ...textProps } textAnchor=\"start\" x={ x } y={ y }>\n\t\t\t{ formatter( label ) }\n\t\t</Text>\n\t);\n};\n\nconst DefaultValueComponent = ( { textProps, x, y, value, formatter }: RenderValueProps ) => {\n\treturn (\n\t\t<Text { ...textProps } textAnchor=\"end\" x={ x } y={ y } fontWeight={ 500 }>\n\t\t\t{ formatter( value ) }\n\t\t</Text>\n\t);\n};\n\nconst AxisRenderer = ( {\n\tticks,\n\ttickLabelProps,\n\tyOffset,\n\tlabelPosition,\n\tvaluePosition,\n\tdata,\n\tlabelFormatter,\n\tvalueFormatter,\n\tLabelComponent = DefaultLabelComponent,\n\tValueComponent = DefaultValueComponent,\n}: AxisRendererProps< AnyD3Scale > & {\n\tyOffset: number;\n\tlabelPosition: number;\n\tvaluePosition: number;\n\tdata: SeriesData[];\n\tlabelFormatter?: ( value: string ) => string;\n\tvalueFormatter?: ( value: number ) => string;\n\tLabelComponent?: ComponentType< RenderLabelProps >;\n\tValueComponent?: ComponentType< RenderValueProps >;\n} ) => {\n\tif ( ticks.length === 0 ) {\n\t\treturn null;\n\t}\n\n\t// compute the max tick label size to compute label offset\n\tconst allTickLabelProps = ticks.map( ( { value, index } ) =>\n\t\ttypeof tickLabelProps === 'function' ? tickLabelProps( value, index, ticks ) : {}\n\t);\n\n\treturn ticks.map( ( { from, formattedValue }, index ) => {\n\t\tconst textProps = allTickLabelProps[ index ] ?? {};\n\t\t// No need to pass textAnchor and dx. It will be handled by the component.\n\t\tdelete textProps.textAnchor;\n\t\tdelete textProps.dx;\n\n\t\tconst sum = data.reduce(\n\t\t\t( acc, { data: seriesData } ) => acc + ( seriesData[ index ]?.value ?? 0 ),\n\t\t\t0\n\t\t);\n\t\tconst y = from.y + yOffset;\n\n\t\treturn (\n\t\t\t<Group key={ index }>\n\t\t\t\t<LabelComponent\n\t\t\t\t\ttextProps={ textProps }\n\t\t\t\t\tx={ labelPosition }\n\t\t\t\t\ty={ y }\n\t\t\t\t\tlabel={ formattedValue }\n\t\t\t\t\tformatter={ labelFormatter }\n\t\t\t\t/>\n\t\t\t\t<ValueComponent\n\t\t\t\t\ttextProps={ textProps }\n\t\t\t\t\tx={ valuePosition }\n\t\t\t\t\ty={ y }\n\t\t\t\t\tvalue={ sum }\n\t\t\t\t\tformatter={ valueFormatter }\n\t\t\t\t\tdata={ data }\n\t\t\t\t\tindex={ index }\n\t\t\t\t/>\n\t\t\t</Group>\n\t\t);\n\t} );\n};\n\n/**\n * Calculate the default y offset for the bar list chart.\n * @param data - The data to calculate the default y offset for.\n * @param yScaleConfig - The y scale configuration.\n * @param height - The height of the chart.\n * @param isMultiSeries - Whether the chart is a multi series chart.\n * @return The default y offset.\n */\nconst getDefaultYOffset = (\n\tdata: SeriesData[],\n\tyScaleConfig: Omit< ScaleOptions, 'type' >,\n\theight: number,\n\tisMultiSeries: boolean\n) => {\n\tif ( ! isMultiSeries ) {\n\t\treturn 0;\n\t}\n\n\tconst dataKeys = data.map( ( { label } ) => label );\n\n\tconst yScale = createScale< string >( {\n\t\ttype: 'band' as const,\n\t\trange: [ 0, height ],\n\t\tdomain: dataKeys,\n\t\t...yScaleConfig,\n\t} );\n\n\tconst groupScale = scaleBand< string >( {\n\t\tdomain: dataKeys,\n\t\trange: [ 0, getScaleBandwidth( yScale ) ],\n\t\tpadding: yScaleConfig.paddingInner,\n\t} );\n\n\tconst GAP_BETWEEN_BARS = 6;\n\tconst barThickness = getScaleBandwidth( groupScale );\n\n\t// Use negative value to move the label up.\n\treturn -( barThickness + GAP_BETWEEN_BARS );\n};\n\nconst BarListChartInternal: FC< BarListChartProps > = ( {\n\tdata,\n\twidth,\n\theight,\n\toptions = {},\n\tmargin = {\n\t\tleft: 0,\n\t\tright: 20,\n\t\tbottom: 0,\n\t\ttop: 0,\n\t},\n\t...rest\n} ) => {\n\tconst chartOptions = useMemo( () => {\n\t\tconst isMultiSeries = data.length > 1;\n\n\t\tconst defaultYScale = {\n\t\t\t// For multi series, set default padding larger to look better.\n\t\t\tpaddingInner: isMultiSeries ? 0.3 : 0.1,\n\t\t\tpadding: isMultiSeries ? 0.3 : 0.1,\n\t\t};\n\t\tconst defaultXScale = {\n\t\t\t// Always begin at zero since the x axis is hidden.\n\t\t\tzero: true,\n\t\t};\n\t\tconst yScale = {\n\t\t\t...defaultYScale,\n\t\t\t...( options.yScale ?? {} ),\n\t\t};\n\t\tconst xScale = {\n\t\t\t...defaultXScale,\n\t\t\t...( options.xScale ?? {} ),\n\t\t};\n\n\t\treturn {\n\t\t\tyScale,\n\t\t\txScale,\n\t\t\tlabelPosition: options.labelPosition ?? ( isMultiSeries ? 0 : 10 ),\n\t\t\tvalueFormatter: options.valueFormatter ?? ( value => formatNumberCompact( value ) ),\n\t\t\tlabelFormatter: options.labelFormatter ?? ( value => String( value ) ),\n\t\t\tvaluePosition: options.valuePosition ?? width,\n\t\t\tyOffset: options.yOffset ?? getDefaultYOffset( data, yScale, height, isMultiSeries ),\n\t\t};\n\t}, [ options, width, data, height ] );\n\n\treturn (\n\t\t<BarChart\n\t\t\torientation=\"horizontal\"\n\t\t\tgridVisibility={ 'none' }\n\t\t\tdata={ data }\n\t\t\twidth={ width }\n\t\t\theight={ height }\n\t\t\tmargin={ margin }\n\t\t\toptions={ {\n\t\t\t\taxis: {\n\t\t\t\t\ty: {\n\t\t\t\t\t\tchildren: ( renderProps: AxisRendererProps< AnyD3Scale > ) => (\n\t\t\t\t\t\t\t<AxisRenderer\n\t\t\t\t\t\t\t\t{ ...renderProps }\n\t\t\t\t\t\t\t\tdata={ data }\n\t\t\t\t\t\t\t\tyOffset={ chartOptions.yOffset }\n\t\t\t\t\t\t\t\tlabelPosition={ chartOptions.labelPosition }\n\t\t\t\t\t\t\t\tvaluePosition={ chartOptions.valuePosition }\n\t\t\t\t\t\t\t\tlabelFormatter={ chartOptions.labelFormatter }\n\t\t\t\t\t\t\t\tvalueFormatter={ chartOptions.valueFormatter }\n\t\t\t\t\t\t\t\tLabelComponent={ options.labelComponent }\n\t\t\t\t\t\t\t\tValueComponent={ options.valueComponent }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t),\n\t\t\t\t\t},\n\t\t\t\t\tx: {\n\t\t\t\t\t\tchildren: () => null,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\txScale: chartOptions.xScale,\n\t\t\t\tyScale: chartOptions.yScale,\n\t\t\t} }\n\t\t\t{ ...rest }\n\t\t/>\n\t);\n};\n\nconst BarListChart: FC< BarListChartProps > = props => {\n\tconst existingContext = useContext( GlobalChartsContext );\n\n\t// If we're already in a GlobalChartsProvider context, render the core component directly\n\tif ( existingContext ) {\n\t\treturn <BarListChartInternal { ...props } />;\n\t}\n\n\t// Otherwise, wrap with our own GlobalChartsProvider\n\treturn (\n\t\t<GlobalChartsProvider>\n\t\t\t<BarListChartInternal { ...props } />\n\t\t</GlobalChartsProvider>\n\t);\n};\n\nBarListChart.displayName = 'BarListChart';\n\nconst BarListChartResponsive = withResponsive< BarListChartProps >( BarListChart );\n\nexport { BarListChartResponsive as default, BarListChart as BarListChartUnresponsive };\n"]}
|