@automattic/charts 4.14.0 → 4.15.1

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.
Files changed (49) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/TOKENS.md +1 -1
  3. package/dist/index.cjs +649 -882
  4. package/dist/index.cjs.map +1 -1
  5. package/dist/index.css +58 -1
  6. package/dist/index.d.cts +41 -7
  7. package/dist/index.d.ts +41 -7
  8. package/dist/index.js +650 -883
  9. package/dist/index.js.map +1 -1
  10. package/package.json +8 -8
  11. package/src/charts/area-chart/area-chart.tsx +29 -20
  12. package/src/charts/area-chart/types.ts +3 -1
  13. package/src/charts/bar-chart/bar-chart.module.scss +38 -0
  14. package/src/charts/bar-chart/bar-chart.tsx +159 -56
  15. package/src/charts/bar-chart/private/band-tooltip.tsx +40 -5
  16. package/src/charts/bar-chart/private/bar-layer.tsx +66 -13
  17. package/src/charts/bar-chart/private/category.ts +25 -0
  18. package/src/charts/bar-chart/private/comparison-bars-geometry.ts +13 -1
  19. package/src/charts/bar-chart/private/index.ts +3 -1
  20. package/src/charts/bar-chart/private/selected-bar-ring.tsx +17 -6
  21. package/src/charts/bar-chart/private/stack-layout.ts +99 -0
  22. package/src/charts/bar-chart/private/stacked-bar-series.tsx +145 -0
  23. package/src/charts/bar-chart/private/test/stack-layout.test.ts +81 -0
  24. package/src/charts/bar-chart/private/test/value-domain.test.ts +10 -0
  25. package/src/charts/bar-chart/private/use-bar-chart-options.ts +35 -11
  26. package/src/charts/bar-chart/private/{use-overlap-slots.ts → use-bar-slots.ts} +36 -38
  27. package/src/charts/bar-chart/private/use-bar-stops.ts +19 -19
  28. package/src/charts/bar-chart/private/value-domain.ts +10 -8
  29. package/src/charts/bar-chart/test/bar-chart-stacked.test.tsx +546 -0
  30. package/src/charts/bar-chart/test/bar-chart.test.tsx +75 -0
  31. package/src/charts/bar-chart/test/use-bar-legend-items.test.tsx +18 -0
  32. package/src/charts/bar-chart/types.ts +3 -1
  33. package/src/charts/bar-chart/use-bar-colors.ts +12 -0
  34. package/src/charts/bar-chart/use-bar-legend-items.ts +4 -2
  35. package/src/charts/bar-list-chart/bar-list-chart.tsx +2 -0
  36. package/src/charts/leaderboard-chart/leaderboard-chart.module.scss +43 -1
  37. package/src/charts/leaderboard-chart/leaderboard-chart.tsx +25 -20
  38. package/src/charts/leaderboard-chart/test/leaderboard-chart.test.tsx +15 -20
  39. package/src/charts/line-chart/line-chart.tsx +55 -26
  40. package/src/charts/line-chart/test/line-chart.test.tsx +86 -0
  41. package/src/charts/line-chart/types.ts +3 -1
  42. package/src/charts/private/test/compact-when-short.test.tsx +170 -0
  43. package/src/charts/private/test/tick-decimals.test.tsx +95 -0
  44. package/src/charts/private/tick-decimals.tsx +132 -0
  45. package/src/charts/private/use-compact-when-short.ts +18 -0
  46. package/src/providers/chart-context/themes.ts +4 -0
  47. package/src/types.ts +35 -2
  48. package/src/charts/private/test/whole-number-ticks.test.tsx +0 -57
  49. package/src/charts/private/whole-number-ticks.tsx +0 -79
package/dist/index.cjs CHANGED
@@ -1283,6 +1283,15 @@ const defaultTheme = {
1283
1283
  },
1284
1284
  strokeWidth: 1.5
1285
1285
  },
1286
+ compactWhenShort: {
1287
+ below: 140,
1288
+ margin: {
1289
+ top: 2,
1290
+ right: 2,
1291
+ bottom: 2,
1292
+ left: 2
1293
+ }
1294
+ },
1286
1295
  heatmapChart: {
1287
1296
  compactCellGap: 2,
1288
1297
  compactCellSize: 11,
@@ -3558,6 +3567,89 @@ const getAllHiddenMessage = (interactive, itemType) => {
3558
3567
  if (interactive) return (0, _wordpress_i18n._x)("All series are hidden. Click legend items to show data.", "chart empty state: interactive series", "jetpack-charts");
3559
3568
  return (0, _wordpress_i18n._x)("All series are hidden.", "chart empty state: series", "jetpack-charts");
3560
3569
  };
3570
+ // src/charts/private/tick-decimals.tsx
3571
+ /**
3572
+ * Whether every reading in the series is a whole number.
3573
+ *
3574
+ * @param series - The series visx renders.
3575
+ * @return True when at least one reading exists and none has a fraction.
3576
+ */
3577
+ const hasOnlyWholeNumbers = (series) => {
3578
+ let sawReading = false;
3579
+ for (const { data } of series) for (const point of data) {
3580
+ const value = point?.value;
3581
+ if (!isReading(value)) continue;
3582
+ if (!Number.isInteger(value)) return false;
3583
+ sawReading = true;
3584
+ }
3585
+ return sawReading;
3586
+ };
3587
+ const EPSILON = 1e-12;
3588
+ const tolerance = (scaled) => EPSILON * Math.max(1, Math.abs(scaled));
3589
+ const isValidDecimals = (decimals) => Number.isInteger(decimals) && decimals >= 0;
3590
+ const isOnDecimals = (value, decimals) => {
3591
+ const scaled = value * 10 ** decimals;
3592
+ return Math.abs(scaled - Math.round(scaled)) < tolerance(scaled);
3593
+ };
3594
+ /**
3595
+ * The scale's ticks with those finer than `decimals` places dropped.
3596
+ *
3597
+ * d3 steps by 1, 2 or 5 times a power of ten, so every multiple of 10^-decimals inside the domain is one of its ticks.
3598
+ *
3599
+ * @param scale - The value scale visx built.
3600
+ * @param count - Ticks to ask the scale for; undefined uses the scale's own default, as visx does.
3601
+ * @param decimals - Decimal places a tick may carry; 0 keeps whole numbers.
3602
+ * @return The kept ticks, or undefined when visx's own ticks need no change.
3603
+ */
3604
+ const getTickDecimalValues = (scale, count, decimals = 0) => {
3605
+ const ticks = scale?.ticks?.(count);
3606
+ if (!ticks?.every((tick) => typeof tick === "number")) return;
3607
+ const kept = ticks.filter((tick) => isOnDecimals(tick, decimals));
3608
+ return kept.length > 1 && kept.length < ticks.length ? kept : void 0;
3609
+ };
3610
+ /**
3611
+ * A value domain widened to the nearest `decimals` steps when fewer than two fit inside it, so the axis shows at least two ticks.
3612
+ *
3613
+ * @param domain - The domain the chart would scale to.
3614
+ * @param decimals - The axis's `tickDecimals`.
3615
+ * @return The widened domain, or undefined when `domain` needs no change.
3616
+ */
3617
+ const getTickDecimalsDomain = (domain, decimals) => {
3618
+ if (!domain || !isValidDecimals(decimals)) return;
3619
+ const scale = 10 ** decimals;
3620
+ const low = domain[0] * scale;
3621
+ const high = domain[1] * scale;
3622
+ if (Math.floor(high + tolerance(high)) - Math.ceil(low - tolerance(low)) >= 1) return;
3623
+ const floor = Math.floor(low + tolerance(low));
3624
+ const ceil = Math.max(Math.ceil(high - tolerance(high)), floor + 1);
3625
+ return [floor / scale, ceil / scale];
3626
+ };
3627
+ /**
3628
+ * The decimals a value axis's ticks are held to: 0 for whole-number data, else the caller's `tickDecimals`.
3629
+ *
3630
+ * @param hasWholeNumberValues - Whether every plotted value is a whole number.
3631
+ * @param tickDecimals - The axis's `tickDecimals`.
3632
+ * @return Decimal places, or undefined to keep visx's ticks.
3633
+ */
3634
+ const getTickDecimals = (hasWholeNumberValues, tickDecimals) => {
3635
+ if (hasWholeNumberValues) return 0;
3636
+ return isValidDecimals(tickDecimals) ? tickDecimals : void 0;
3637
+ };
3638
+ /**
3639
+ * Hands its children the chart's value-scale ticks, held to `decimals` places.
3640
+ *
3641
+ * @param props - Component props.
3642
+ * @param props.axis - Which scale carries the values.
3643
+ * @param props.numTicks - Ticks to ask the scale for.
3644
+ * @param props.decimals - Decimal places a tick may carry, or undefined to keep visx's ticks.
3645
+ * @param props.children - Renders the axis and grid with the tick values.
3646
+ * @return The rendered children.
3647
+ */
3648
+ const TickDecimals = ({ axis, numTicks, decimals, children }) => {
3649
+ const { xScale, yScale } = (0, react.useContext)(_visx_xychart.DataContext);
3650
+ const tickValues = decimals === void 0 ? void 0 : getTickDecimalValues(axis === "x" ? xScale : yScale, numTicks, decimals);
3651
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: children(tickValues) });
3652
+ };
3561
3653
  // src/charts/private/time-axis.ts
3562
3654
  const X_TICK_WIDTH = 60;
3563
3655
  const getCurveType = (type, smoothing) => {
@@ -3850,52 +3942,24 @@ const buildTimeAxisOptions = ({ dataSorted, width, axisOptions, scaleDomain, zoo
3850
3942
  ...numTicks === void 0 ? {} : { numTicks }
3851
3943
  };
3852
3944
  };
3853
- // src/charts/private/whole-number-ticks.tsx
3854
- /**
3855
- * Whether every reading in the series is a whole number.
3856
- *
3857
- * @param series - The series visx renders.
3858
- * @return True when at least one reading exists and none has a fraction.
3859
- */
3860
- const hasOnlyWholeNumbers = (series) => {
3861
- let sawReading = false;
3862
- for (const { data } of series) for (const point of data) {
3863
- const value = point?.value;
3864
- if (!isReading(value)) continue;
3865
- if (!Number.isInteger(value)) return false;
3866
- sawReading = true;
3867
- }
3868
- return sawReading;
3869
- };
3945
+ // src/charts/private/use-compact-when-short.ts
3870
3946
  /**
3871
- * The scale's ticks with the fractional ones dropped.
3947
+ * Whether a `compactWhenShort` chart is compact, and the margin it then defaults to.
3872
3948
  *
3873
- * d3 steps by 1, 2 or 5 times a power of ten, so every whole number inside the domain is one of its ticks.
3874
- *
3875
- * @param scale - The value scale visx built.
3876
- * @param count - Ticks to ask the scale for; undefined uses the scale's own default, as visx does.
3877
- * @return Whole-number ticks, or undefined when visx's own ticks need no change.
3878
- */
3879
- const getWholeNumberTickValues = (scale, count) => {
3880
- const ticks = scale?.ticks?.(count);
3881
- if (!ticks?.every((tick) => typeof tick === "number")) return;
3882
- const whole = ticks.filter((tick) => Number.isInteger(tick));
3883
- return whole.length > 1 && whole.length < ticks.length ? whole : void 0;
3884
- };
3885
- /**
3886
- * Hands its children the whole-number ticks of the chart's value scale.
3949
+ * Reads the height the chart was given, not the measured plot area: that grows once the legend
3950
+ * is hidden and would flip the chart straight back. A zero height is unmeasured, not short.
3887
3951
  *
3888
- * @param props - Component props.
3889
- * @param props.axis - Which scale carries the values.
3890
- * @param props.numTicks - Ticks to ask the scale for.
3891
- * @param props.enabled - Whether the plotted values are all whole numbers and the caller pinned neither the ticks nor the value domain.
3892
- * @param props.children - Renders the axis and grid with the tick values.
3893
- * @return The rendered children.
3952
+ * @param enabled - The chart's `compactWhenShort` prop.
3953
+ * @param height - The height the chart was given.
3954
+ * @return Whether the chart is compact, and the compact margin when it is.
3894
3955
  */
3895
- const WholeNumberTicks = ({ axis, numTicks, enabled, children }) => {
3896
- const { xScale, yScale } = (0, react.useContext)(_visx_xychart.DataContext);
3897
- const tickValues = enabled ? getWholeNumberTickValues(axis === "x" ? xScale : yScale, numTicks) : void 0;
3898
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: children(tickValues) });
3956
+ const useCompactWhenShort = (enabled, height) => {
3957
+ const { compactWhenShort } = useGlobalChartsTheme();
3958
+ const isCompact = enabled && (height ?? 0) > 0 && height < compactWhenShort.below;
3959
+ return {
3960
+ isCompact,
3961
+ compactMargin: isCompact ? compactWhenShort.margin : void 0
3962
+ };
3899
3963
  };
3900
3964
  // src/charts/private/with-responsive/with-responsive.module.scss
3901
3965
  var with_responsive_module_default = {
@@ -4782,7 +4846,7 @@ const LineChartScalesRef = ({ chartRef, width, height, margin }) => {
4782
4846
  ]);
4783
4847
  return null;
4784
4848
  };
4785
- const LineChartInternal = (0, react.forwardRef)(({ data, ariaLabel, chartId: providedChartId, width, height, className, margin, withTooltips = true, withTooltipCrosshairs, showLegend = false, legend = {}, renderGlyph = defaultRenderGlyph, glyphStyle = {}, withLegendGlyph = false, withGradientFill = false, smoothing = true, curveType, renderTooltip = renderDefaultTooltip, tooltipPlacement, tooltipStyle, withStartGlyphs = false, withEndGlyphs = false, animation, options = {}, onPointerDown = void 0, onPointerUp = void 0, onPointerMove = void 0, onPointerOut = void 0, onDatumActivate = void 0, zoomable = false, rescaleYOnVisibilityChange = true, defaultHiddenSeries, children, gridVisibility, gap = "md" }, ref) => {
4849
+ const LineChartInternal = (0, react.forwardRef)(({ data, ariaLabel, chartId: providedChartId, width, height, className, margin, withTooltips = true, withTooltipCrosshairs, showLegend = false, legend = {}, renderGlyph = defaultRenderGlyph, glyphStyle = {}, withLegendGlyph = false, withGradientFill = false, smoothing = true, curveType, renderTooltip = renderDefaultTooltip, tooltipPlacement, tooltipStyle, withStartGlyphs = false, withEndGlyphs = false, animation, options = {}, onPointerDown = void 0, onPointerUp = void 0, onPointerMove = void 0, onPointerOut = void 0, onDatumActivate = void 0, zoomable = false, rescaleYOnVisibilityChange = true, defaultHiddenSeries, children, gridVisibility, gap = "md", compactWhenShort = false }, ref) => {
4786
4850
  const legendInteractive = legend.interactive ?? false;
4787
4851
  const legendCollapseGroups = legend.collapseGroups ?? false;
4788
4852
  const legendComparisonItem = legend.comparisonItem ?? false;
@@ -4809,6 +4873,7 @@ const LineChartInternal = (0, react.forwardRef)(({ data, ariaLabel, chartId: pro
4809
4873
  }
4810
4874
  });
4811
4875
  const { legendChildren, nonLegendChildren } = useChartChildren(children, "LineChart");
4876
+ const { isCompact, compactMargin } = useCompactWhenShort(compactWhenShort, height);
4812
4877
  const [measuredChartHeight, setMeasuredChartHeight] = (0, react.useState)();
4813
4878
  const handleContentHeightChange = (0, react.useCallback)((contentHeight) => {
4814
4879
  setMeasuredChartHeight(contentHeight > 0 ? contentHeight : height);
@@ -4897,25 +4962,34 @@ const LineChartInternal = (0, react.forwardRef)(({ data, ariaLabel, chartId: pro
4897
4962
  return min <= max ? [min, max] : void 0;
4898
4963
  }, [dataSorted, isSeriesVisible]);
4899
4964
  const hasWholeNumberValues = (0, react.useMemo)(() => hasOnlyWholeNumbers(visibleSeries), [visibleSeries]);
4965
+ const isLogScale = options?.yScale?.type === "log";
4966
+ const callerTickDecimals = isLogScale ? void 0 : options?.axis?.y?.tickDecimals;
4967
+ const yTickDecimals = getTickDecimals(hasWholeNumberValues, callerTickDecimals);
4900
4968
  const chartOptions = (0, react.useMemo)(() => {
4901
- const fallbackYDomain = getFallbackYDomain(visibleReadingExtent, options?.yScale?.type === "log");
4969
+ const fallbackYDomain = getFallbackYDomain(visibleReadingExtent, isLogScale);
4970
+ const { tickDecimals, ...yAxisOptions } = options?.axis?.y ?? {};
4971
+ const tickDecimalsDomain = isLogScale || tickDecimals === void 0 || options?.yScale?.domain || yAxisOptions.tickValues ? void 0 : getTickDecimalsDomain(yDomain ?? fallbackYDomain ?? visibleReadingExtent, yTickDecimals);
4902
4972
  return {
4903
4973
  axis: {
4904
- x: buildTimeAxisOptions({
4905
- dataSorted,
4906
- width,
4907
- axisOptions: options?.axis?.x,
4908
- scaleDomain: options?.xScale?.domain,
4909
- zoomDomain: zoom.domain,
4910
- formatting,
4911
- isSeriesRendered: (series) => isSeriesVisible(series.label)
4912
- }),
4974
+ x: {
4975
+ ...buildTimeAxisOptions({
4976
+ dataSorted,
4977
+ width,
4978
+ axisOptions: options?.axis?.x,
4979
+ scaleDomain: options?.xScale?.domain,
4980
+ zoomDomain: zoom.domain,
4981
+ formatting,
4982
+ isSeriesRendered: (series) => isSeriesVisible(series.label)
4983
+ }),
4984
+ ...isCompact && { display: false }
4985
+ },
4913
4986
  y: {
4914
4987
  orientation: "left",
4915
4988
  numTicks: 4,
4916
4989
  tickFormat: _automattic_number_formatters.formatNumberCompact,
4917
4990
  display: true,
4918
- ...options?.axis?.y
4991
+ ...yAxisOptions,
4992
+ ...isCompact && { display: false }
4919
4993
  }
4920
4994
  },
4921
4995
  xScale: {
@@ -4929,6 +5003,7 @@ const LineChartInternal = (0, react.forwardRef)(({ data, ariaLabel, chartId: pro
4929
5003
  zero: false,
4930
5004
  ...fallbackYDomain ? { domain: fallbackYDomain } : {},
4931
5005
  ...yDomain ? { domain: yDomain } : {},
5006
+ ...tickDecimalsDomain ? { domain: tickDecimalsDomain } : {},
4932
5007
  ...options?.yScale
4933
5008
  }
4934
5009
  };
@@ -4939,8 +5014,11 @@ const LineChartInternal = (0, react.forwardRef)(({ data, ariaLabel, chartId: pro
4939
5014
  zoom.domain,
4940
5015
  yDomain,
4941
5016
  visibleReadingExtent,
5017
+ isLogScale,
5018
+ yTickDecimals,
4942
5019
  formatting,
4943
- isSeriesVisible
5020
+ isSeriesVisible,
5021
+ isCompact
4944
5022
  ]);
4945
5023
  const bucketInfo = (0, react.useMemo)(() => getBucketInfo(visibleSeries, options?.axis?.x?.tickResolution), [visibleSeries, options?.axis?.x?.tickResolution]);
4946
5024
  const tooltipRenderGlyph = (0, react.useMemo)(() => {
@@ -5015,7 +5093,7 @@ const LineChartInternal = (0, react.forwardRef)(({ data, ariaLabel, chartId: pro
5015
5093
  className: (0, clsx.default)("line-chart", line_chart_module_default["line-chart"]),
5016
5094
  children: error
5017
5095
  });
5018
- const legendElement = showLegend && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Legend, {
5096
+ const legendElement = showLegend && !isCompact && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Legend, {
5019
5097
  orientation: legend.orientation ?? "horizontal",
5020
5098
  alignment: legend.alignment ?? "center",
5021
5099
  position: legendPosition,
@@ -5039,7 +5117,7 @@ const LineChartInternal = (0, react.forwardRef)(({ data, ariaLabel, chartId: pro
5039
5117
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ChartLayout, {
5040
5118
  legendPosition,
5041
5119
  legendElement,
5042
- legendChildren,
5120
+ legendChildren: isCompact ? [] : legendChildren,
5043
5121
  gap,
5044
5122
  className: (0, clsx.default)("line-chart", line_chart_module_default["line-chart"], { [line_chart_module_default["line-chart--animated"]]: animation && !prefersReducedMotion }, className),
5045
5123
  style: {
@@ -5067,6 +5145,7 @@ const LineChartInternal = (0, react.forwardRef)(({ data, ariaLabel, chartId: pro
5067
5145
  height: chartHeight,
5068
5146
  margin: {
5069
5147
  ...defaultMargin,
5148
+ ...compactMargin,
5070
5149
  ...margin
5071
5150
  },
5072
5151
  xScale: chartOptions.xScale,
@@ -5074,12 +5153,12 @@ const LineChartInternal = (0, react.forwardRef)(({ data, ariaLabel, chartId: pro
5074
5153
  onPointerOut,
5075
5154
  children: [
5076
5155
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)(NearestPointerEvents, { ...zoom.handlers }),
5077
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(WholeNumberTicks, {
5156
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TickDecimals, {
5078
5157
  axis: "y",
5079
5158
  numTicks: chartOptions.axis.y.numTicks,
5080
- enabled: hasWholeNumberValues && !chartOptions.axis.y.tickValues && !options?.yScale?.domain,
5159
+ decimals: !chartOptions.axis.y.tickValues && !options?.yScale?.domain ? yTickDecimals : void 0,
5081
5160
  children: (tickValues) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
5082
- !allSeriesHidden && gridVisibility !== "none" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_visx_xychart.Grid, {
5161
+ !allSeriesHidden && gridVisibility !== "none" && !isCompact && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_visx_xychart.Grid, {
5083
5162
  columns: false,
5084
5163
  numTicks: chartOptions.axis.y.numTicks,
5085
5164
  tickValues: tickValues ?? chartOptions.axis.y.tickValues
@@ -5096,7 +5175,7 @@ const LineChartInternal = (0, react.forwardRef)(({ data, ariaLabel, chartId: pro
5096
5175
  y: chartHeight / 2,
5097
5176
  width,
5098
5177
  height: chartHeight,
5099
- children: getAllHiddenMessage(legendInteractive, "series")
5178
+ children: getAllHiddenMessage(legendInteractive && !isCompact, "series")
5100
5179
  }) : null,
5101
5180
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ZoomClip, {
5102
5181
  active: zoomable && !!zoom.domain,
@@ -5298,7 +5377,7 @@ const HoverGlyphs = ({ visibleSeries, stacked, stackOffset, getElementStyles, st
5298
5377
  });
5299
5378
  };
5300
5379
  // src/charts/area-chart/area-chart.tsx
5301
- const AreaChartInternal = (0, react.forwardRef)(({ data, ariaLabel, chartId: providedChartId, width, height, className, margin, withTooltips = true, withTooltipCrosshairs, showLegend = false, legend = {}, stacked = true, stackOffset = "none", smoothing = true, curveType, fillOpacity, withStroke, renderTooltip = renderDefaultTooltip, animation, options = {}, onPointerDown, onPointerUp, onPointerMove, onPointerOut, zoomable = false, rescaleYOnVisibilityChange = true, defaultHiddenSeries, children, gridVisibility, gap = "md" }, ref) => {
5380
+ const AreaChartInternal = (0, react.forwardRef)(({ data, ariaLabel, chartId: providedChartId, width, height, className, margin, withTooltips = true, withTooltipCrosshairs, showLegend = false, legend = {}, stacked = true, stackOffset = "none", smoothing = true, curveType, fillOpacity, withStroke, renderTooltip = renderDefaultTooltip, animation, options = {}, onPointerDown, onPointerUp, onPointerMove, onPointerOut, zoomable = false, rescaleYOnVisibilityChange = true, defaultHiddenSeries, children, gridVisibility, gap = "md", compactWhenShort = false }, ref) => {
5302
5381
  const legendInteractive = legend.interactive ?? false;
5303
5382
  const legendShape = legend.shape ?? "rect";
5304
5383
  const legendPosition = legend.position ?? "bottom";
@@ -5321,6 +5400,7 @@ const AreaChartInternal = (0, react.forwardRef)(({ data, ariaLabel, chartId: pro
5321
5400
  }
5322
5401
  });
5323
5402
  const { legendChildren, nonLegendChildren } = useChartChildren(children, "AreaChart");
5403
+ const { isCompact, compactMargin } = useCompactWhenShort(compactWhenShort, height);
5324
5404
  const [measuredChartHeight, setMeasuredChartHeight] = (0, react.useState)();
5325
5405
  const handleContentHeightChange = (0, react.useCallback)((contentHeight) => {
5326
5406
  setMeasuredChartHeight(contentHeight > 0 ? contentHeight : height);
@@ -5400,20 +5480,24 @@ const AreaChartInternal = (0, react.forwardRef)(({ data, ariaLabel, chartId: pro
5400
5480
  const chartOptions = (0, react.useMemo)(() => {
5401
5481
  return {
5402
5482
  axis: {
5403
- x: buildTimeAxisOptions({
5404
- dataSorted,
5405
- width,
5406
- axisOptions: options?.axis?.x,
5407
- scaleDomain: options?.xScale?.domain,
5408
- zoomDomain: zoom.domain,
5409
- formatting
5410
- }),
5483
+ x: {
5484
+ ...buildTimeAxisOptions({
5485
+ dataSorted,
5486
+ width,
5487
+ axisOptions: options?.axis?.x,
5488
+ scaleDomain: options?.xScale?.domain,
5489
+ zoomDomain: zoom.domain,
5490
+ formatting
5491
+ }),
5492
+ ...isCompact && { display: false }
5493
+ },
5411
5494
  y: {
5412
5495
  orientation: "left",
5413
5496
  numTicks: 4,
5414
5497
  tickFormat: _automattic_number_formatters.formatNumberCompact,
5415
5498
  display: true,
5416
- ...options?.axis?.y
5499
+ ...options?.axis?.y,
5500
+ ...isCompact && { display: false }
5417
5501
  }
5418
5502
  },
5419
5503
  xScale: {
@@ -5436,7 +5520,8 @@ const AreaChartInternal = (0, react.forwardRef)(({ data, ariaLabel, chartId: pro
5436
5520
  stacked,
5437
5521
  fixedYDomain,
5438
5522
  zoom.domain,
5439
- formatting
5523
+ formatting,
5524
+ isCompact
5440
5525
  ]);
5441
5526
  const defaultMargin = useChartMargin(height, chartOptions, dataSorted, theme);
5442
5527
  const error = validateData$3(dataSorted);
@@ -5516,7 +5601,7 @@ const AreaChartInternal = (0, react.forwardRef)(({ data, ariaLabel, chartId: pro
5516
5601
  className: (0, clsx.default)("area-chart", area_chart_module_default["area-chart"]),
5517
5602
  children: error
5518
5603
  });
5519
- const legendElement = showLegend && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Legend, {
5604
+ const legendElement = showLegend && !isCompact && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Legend, {
5520
5605
  orientation: legend.orientation ?? "horizontal",
5521
5606
  alignment: legend.alignment ?? "center",
5522
5607
  position: legendPosition,
@@ -5564,7 +5649,7 @@ const AreaChartInternal = (0, react.forwardRef)(({ data, ariaLabel, chartId: pro
5564
5649
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ChartLayout, {
5565
5650
  legendPosition,
5566
5651
  legendElement,
5567
- legendChildren,
5652
+ legendChildren: isCompact ? [] : legendChildren,
5568
5653
  gap,
5569
5654
  className: (0, clsx.default)("area-chart", area_chart_module_default["area-chart"], { [area_chart_module_default["area-chart--animated"]]: animationEnabled }, className),
5570
5655
  style: {
@@ -5592,6 +5677,7 @@ const AreaChartInternal = (0, react.forwardRef)(({ data, ariaLabel, chartId: pro
5592
5677
  height: chartHeight,
5593
5678
  margin: {
5594
5679
  ...defaultMargin,
5680
+ ...compactMargin,
5595
5681
  ...margin
5596
5682
  },
5597
5683
  xScale: chartOptions.xScale,
@@ -5602,12 +5688,12 @@ const AreaChartInternal = (0, react.forwardRef)(({ data, ariaLabel, chartId: pro
5602
5688
  onPointerOut,
5603
5689
  pointerEventsDataKey: "nearest",
5604
5690
  children: [
5605
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(WholeNumberTicks, {
5691
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TickDecimals, {
5606
5692
  axis: "y",
5607
5693
  numTicks: chartOptions.axis.y.numTicks,
5608
- enabled: hasWholeNumberValues && !chartOptions.axis.y.tickValues && !options?.yScale?.domain,
5694
+ decimals: hasWholeNumberValues && !chartOptions.axis.y.tickValues && !options?.yScale?.domain ? 0 : void 0,
5609
5695
  children: (tickValues) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
5610
- !allSeriesHidden && gridVisibility !== "none" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_visx_xychart.Grid, {
5696
+ !allSeriesHidden && gridVisibility !== "none" && !isCompact && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_visx_xychart.Grid, {
5611
5697
  columns: false,
5612
5698
  numTicks: chartOptions.axis.y.numTicks,
5613
5699
  tickValues: tickValues ?? chartOptions.axis.y.tickValues
@@ -5624,7 +5710,7 @@ const AreaChartInternal = (0, react.forwardRef)(({ data, ariaLabel, chartId: pro
5624
5710
  y: chartHeight / 2,
5625
5711
  width,
5626
5712
  height: chartHeight,
5627
- children: getAllHiddenMessage(legendInteractive, "series")
5713
+ children: getAllHiddenMessage(legendInteractive && !isCompact, "series")
5628
5714
  }) : null,
5629
5715
  /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(ZoomClip, {
5630
5716
  active: zoomable,
@@ -5687,9 +5773,145 @@ var bar_chart_module_default = {
5687
5773
  "bar-chart": "a8ccharts-97yN9W-bar-chart",
5688
5774
  "bar-chart--animated": "a8ccharts-97yN9W-bar-chart--animated",
5689
5775
  "bar-chart--animated-horizontal": "a8ccharts-97yN9W-bar-chart--animated-horizontal",
5776
+ "bar-chart--stacked": "a8ccharts-97yN9W-bar-chart--stacked",
5690
5777
  "rise": "a8ccharts-97yN9W-rise",
5691
5778
  "stretch": "a8ccharts-97yN9W-stretch"
5692
5779
  };
5780
+ // src/charts/bar-chart/private/category.ts
5781
+ /**
5782
+ * Whether two data points sit at the same category: the same label, or the same date.
5783
+ *
5784
+ * @param point - A data point.
5785
+ * @param category - The data point naming the category.
5786
+ * @return Whether `point` is at `category`.
5787
+ */
5788
+ function isSameCategory(point, category) {
5789
+ return category.label ? point.label === category.label : !!category.date && !!point.date && point.date.getTime() === category.date.getTime();
5790
+ }
5791
+ /**
5792
+ * The category a data point sits at, as a key two points share when `isSameCategory` holds.
5793
+ *
5794
+ * @param point - A data point.
5795
+ * @return The category key.
5796
+ */
5797
+ function categoryKey(point) {
5798
+ return point.label ? `label:${point.label}` : `date:${point.date?.getTime()}`;
5799
+ }
5800
+ // src/charts/bar-chart/private/value-domain.ts
5801
+ /** Domain for a value axis that has nothing to scale, so its ticks still read 0 to 1. */
5802
+ const EMPTY_DOMAIN = [0, 1];
5803
+ /**
5804
+ * The value a bar is drawn at, preferring `visualValue` so a zero still shows a sliver.
5805
+ *
5806
+ * A missing reading is NaN, not null: `ComparisonBars` coerces the value with `Number()`,
5807
+ * which turns null into 0 and would draw a comparison shadow at the baseline.
5808
+ *
5809
+ * @param point - A data point handed to visx.
5810
+ * @return The bar value, or NaN when the bucket has no reading.
5811
+ */
5812
+ const getBarValue = (point) => {
5813
+ const enhanced = point;
5814
+ return (enhanced?.visualValue !== void 0 ? enhanced.visualValue : point?.value) ?? NaN;
5815
+ };
5816
+ /**
5817
+ * Whether visx renders a bar for a point.
5818
+ *
5819
+ * @param point - A data point handed to visx.
5820
+ * @return True when the point has a finite bar value.
5821
+ */
5822
+ const isBarRendered = (point) => Number.isFinite(getBarValue(point));
5823
+ /**
5824
+ * An explicit domain for the value scale, or null to let visx fit one to the data.
5825
+ *
5826
+ * Zero goes into the domain here rather than through the scale's `zero` flag: visx applies
5827
+ * `nice` before `zero`, which would leave the axis topping out at a raw maximum.
5828
+ *
5829
+ * @param data - Every series handed to the chart.
5830
+ * @param includeZero - Whether the domain must span zero.
5831
+ * @param isSeriesRendered - Whether visx mounts a series, i.e. the legend shows it.
5832
+ * @param tickDecimals - The value axis's `tickDecimals`.
5833
+ * @return Value domain, or null when visx should fit its own.
5834
+ */
5835
+ const getValueScaleDomain = (data, includeZero, isSeriesRendered, tickDecimals) => {
5836
+ let min = Infinity;
5837
+ let max = -Infinity;
5838
+ for (const series of data) {
5839
+ if (!isSeriesRendered(series)) continue;
5840
+ for (const point of series.data) {
5841
+ const value = getBarValue(point);
5842
+ if (!Number.isFinite(value)) continue;
5843
+ min = Math.min(min, value);
5844
+ max = Math.max(max, value);
5845
+ }
5846
+ }
5847
+ if (min === Infinity) return [...EMPTY_DOMAIN];
5848
+ let domain = null;
5849
+ if (min === max) domain = min === 0 ? [...EMPTY_DOMAIN] : [Math.min(0, min), Math.max(0, max)];
5850
+ else if (includeZero) domain = [Math.min(0, min), Math.max(0, max)];
5851
+ return getTickDecimalsDomain(domain ?? [min, max], tickDecimals) ?? domain;
5852
+ };
5853
+ // src/charts/bar-chart/private/stack-layout.ts
5854
+ /**
5855
+ * The series a layout draws: a stacked layout leaves comparison series out for now.
5856
+ *
5857
+ * @param series - The chart's series.
5858
+ * @param layout - The layout the bars are drawn in.
5859
+ * @return The drawn series.
5860
+ */
5861
+ function getDrawnSeries(series, layout) {
5862
+ return layout === "stacked" ? series.filter((item) => item.options?.type !== "comparison") : series;
5863
+ }
5864
+ /**
5865
+ * Stacks the series in order at each category: positives upward and negatives downward from zero.
5866
+ *
5867
+ * @param series - The series to stack, bottom first.
5868
+ * @return The stack layout.
5869
+ */
5870
+ function getStackLayout(series) {
5871
+ const segments = /* @__PURE__ */ new Map();
5872
+ const extents = /* @__PURE__ */ new Map();
5873
+ for (const { label, data } of series) {
5874
+ const byCategory = /* @__PURE__ */ new Map();
5875
+ segments.set(label, byCategory);
5876
+ for (const point of data) {
5877
+ const value = getBarValue(point);
5878
+ if (!Number.isFinite(value)) continue;
5879
+ const key = categoryKey(point);
5880
+ if (byCategory.has(key)) continue;
5881
+ const extent = extents.get(key) ?? [0, 0];
5882
+ const side = value < 0 ? 0 : 1;
5883
+ const start = extent[side];
5884
+ extent[side] = start + value;
5885
+ extents.set(key, extent);
5886
+ byCategory.set(key, {
5887
+ start,
5888
+ end: start + value
5889
+ });
5890
+ }
5891
+ }
5892
+ let extent = null;
5893
+ for (const [low, high] of extents.values()) extent = extent ? [Math.min(extent[0], low), Math.max(extent[1], high)] : [low, high];
5894
+ return {
5895
+ segmentOf: (key, datum) => segments.get(key)?.get(categoryKey(datum)),
5896
+ extentAt: (category) => {
5897
+ const [low, high] = extents.get(categoryKey(category)) ?? [0, 0];
5898
+ return [low, high];
5899
+ },
5900
+ extent
5901
+ };
5902
+ }
5903
+ /**
5904
+ * The value domain of a computed stack, falling back to an empty chart's domain.
5905
+ *
5906
+ * @param stack - The precomputed stack.
5907
+ * @param tickDecimals - The value axis precision, when set.
5908
+ * @return The extent widened for tick precision, or the empty chart domain.
5909
+ */
5910
+ function getStackedValueDomain(stack, tickDecimals) {
5911
+ const { extent } = stack;
5912
+ const domain = !extent || extent[0] === extent[1] ? [...EMPTY_DOMAIN] : extent;
5913
+ return getTickDecimalsDomain(domain, tickDecimals) ?? domain;
5914
+ }
5693
5915
  // src/charts/bar-chart/private/truncated-tick-component.tsx
5694
5916
  /**
5695
5917
  * Get the bandwidth of a scale
@@ -5804,57 +6026,6 @@ const createTruncatedTickComponent = (axis) => (props) => {
5804
6026
  */
5805
6027
  const TruncatedXTickComponent = createTruncatedTickComponent("x");
5806
6028
  const TruncatedYTickComponent = createTruncatedTickComponent("y");
5807
- // src/charts/bar-chart/private/value-domain.ts
5808
- /** Domain for a value axis that has nothing to scale, so its ticks still read 0 to 1. */
5809
- const EMPTY_DOMAIN = [0, 1];
5810
- /**
5811
- * The value a bar is drawn at, preferring `visualValue` so a zero still shows a sliver.
5812
- *
5813
- * A missing reading is NaN, not null: `ComparisonBars` coerces the value with `Number()`,
5814
- * which turns null into 0 and would draw a comparison shadow at the baseline.
5815
- *
5816
- * @param point - A data point handed to visx.
5817
- * @return The bar value, or NaN when the bucket has no reading.
5818
- */
5819
- const getBarValue = (point) => {
5820
- const enhanced = point;
5821
- return (enhanced?.visualValue !== void 0 ? enhanced.visualValue : point?.value) ?? NaN;
5822
- };
5823
- /**
5824
- * Whether visx renders a bar for a point.
5825
- *
5826
- * @param point - A data point handed to visx.
5827
- * @return True when the point has a finite bar value.
5828
- */
5829
- const isBarRendered = (point) => Number.isFinite(getBarValue(point));
5830
- /**
5831
- * An explicit domain for the value scale, or null to let visx fit one to the data.
5832
- *
5833
- * Zero goes into the domain here rather than through the scale's `zero` flag: visx applies
5834
- * `nice` before `zero`, which would leave the axis topping out at a raw maximum.
5835
- *
5836
- * @param data - Every series handed to the chart.
5837
- * @param includeZero - Whether the domain must span zero.
5838
- * @param isSeriesRendered - Whether visx mounts a series, i.e. the legend shows it.
5839
- * @return Value domain, or null when visx should fit its own.
5840
- */
5841
- const getValueScaleDomain = (data, includeZero, isSeriesRendered) => {
5842
- let min = Infinity;
5843
- let max = -Infinity;
5844
- for (const series of data) {
5845
- if (!isSeriesRendered(series)) continue;
5846
- for (const point of series.data) {
5847
- const value = getBarValue(point);
5848
- if (!Number.isFinite(value)) continue;
5849
- min = Math.min(min, value);
5850
- max = Math.max(max, value);
5851
- }
5852
- }
5853
- if (min === Infinity) return [...EMPTY_DOMAIN];
5854
- if (min === max) return min === 0 ? [...EMPTY_DOMAIN] : [Math.min(0, min), Math.max(0, max)];
5855
- if (includeZero) return [Math.min(0, min), Math.max(0, max)];
5856
- return null;
5857
- };
5858
6029
  // src/charts/bar-chart/private/use-bar-chart-options.ts
5859
6030
  /** Outer padding of the category band scale (space at the chart edges). */
5860
6031
  const BASE_BAND_PADDING = .2;
@@ -5943,14 +6114,18 @@ const getGroupPadding = (scale) => {
5943
6114
  * @param horizontal - Whether the chart is horizontal or vertical.
5944
6115
  * @param options - The options for the chart.
5945
6116
  * @param isSeriesRendered - Whether visx mounts a series, i.e. the legend shows it.
6117
+ * @param stack - The precomputed stack, when series share one bar.
5946
6118
  * @return The merged options for the chart.
5947
6119
  */
5948
- function useBarChartOptions(data, horizontal, options = {}, isSeriesRendered = ALL_RENDERED) {
6120
+ function useBarChartOptions(data, horizontal, options = {}, isSeriesRendered = ALL_RENDERED, stack) {
5949
6121
  const stableOptions = useDeepMemo(options);
5950
6122
  const formatting = useChartFormatting();
6123
+ const isStacked = !!stack;
5951
6124
  const axisConfig = (0, react.useMemo)(() => {
5952
- const { labelOverflow: xLabelOverflow, tickResolution: xTickResolution, tickFormat: xTickFormat, ...xAxisOptions } = stableOptions.axis?.x || {};
5953
- const { labelOverflow: yLabelOverflow, tickResolution: yTickResolution, tickFormat: yTickFormat, ...yAxisOptions } = stableOptions.axis?.y || {};
6125
+ const { labelOverflow: xLabelOverflow, tickResolution: xTickResolution, tickFormat: xTickFormat, tickDecimals: xTickDecimals, ...xAxisOptions } = stableOptions.axis?.x || {};
6126
+ const { labelOverflow: yLabelOverflow, tickResolution: yTickResolution, tickFormat: yTickFormat, tickDecimals: yTickDecimals, ...yAxisOptions } = stableOptions.axis?.y || {};
6127
+ const [valueAxisOptions, valueTickDecimals] = horizontal ? [xAxisOptions, xTickDecimals] : [yAxisOptions, yTickDecimals];
6128
+ const valueScaleType = isStacked ? "linear" : (horizontal ? stableOptions.xScale : stableOptions.yScale)?.type;
5954
6129
  return {
5955
6130
  xLabelOverflow,
5956
6131
  yLabelOverflow,
@@ -5958,9 +6133,14 @@ function useBarChartOptions(data, horizontal, options = {}, isSeriesRendered = A
5958
6133
  yTickFormat,
5959
6134
  xAxisOptions,
5960
6135
  yAxisOptions,
5961
- tickResolution: horizontal ? yTickResolution : xTickResolution
6136
+ tickResolution: horizontal ? yTickResolution : xTickResolution,
6137
+ valueTickDecimals: valueAxisOptions.tickValues || valueScaleType === "log" ? void 0 : valueTickDecimals
5962
6138
  };
5963
- }, [stableOptions, horizontal]);
6139
+ }, [
6140
+ stableOptions,
6141
+ horizontal,
6142
+ isStacked
6143
+ ]);
5964
6144
  const { tickResolution } = axisConfig;
5965
6145
  const defaultOptions = (0, react.useMemo)(() => {
5966
6146
  const bandScale = {
@@ -6015,17 +6195,21 @@ function useBarChartOptions(data, horizontal, options = {}, isSeriesRendered = A
6015
6195
  const { xTickFormat: defaultXTickFormat, yTickFormat: defaultYTickFormat, tooltipLabelFormatter: defaultTooltipLabelFormatter, xAccessor, yAccessor, gridVisibility, xScale: baseXScale, yScale: baseYScale } = defaultOptions[horizontal ? "horizontal" : "vertical"];
6016
6196
  const valueScaleOptions = horizontal ? stableOptions.xScale : stableOptions.yScale;
6017
6197
  const includeZero = data.some((s) => s.options?.type === "comparison") || valueScaleOptions?.zero !== false;
6018
- const domain = valueScaleOptions?.domain ? null : getValueScaleDomain(data, includeZero, isSeriesRendered);
6019
- const valueScaleDomainOverride = domain ? { domain } : {};
6198
+ let domain = null;
6199
+ if (!valueScaleOptions?.domain) domain = stack ? getStackedValueDomain(stack, axisConfig.valueTickDecimals) : getValueScaleDomain(data, includeZero, isSeriesRendered, axisConfig.valueTickDecimals);
6200
+ const valueScaleOverride = {
6201
+ ...domain && { domain },
6202
+ ...stack && { type: "linear" }
6203
+ };
6020
6204
  const xScale = {
6021
6205
  ...baseXScale,
6022
6206
  ...stableOptions.xScale || {},
6023
- ...horizontal ? valueScaleDomainOverride : {}
6207
+ ...horizontal ? valueScaleOverride : {}
6024
6208
  };
6025
6209
  const yScale = {
6026
6210
  ...baseYScale,
6027
6211
  ...stableOptions.yScale || {},
6028
- ...!horizontal ? valueScaleDomainOverride : {}
6212
+ ...!horizontal ? valueScaleOverride : {}
6029
6213
  };
6030
6214
  const { xLabelOverflow, yLabelOverflow, xTickFormat, yTickFormat, xAxisOptions, yAxisOptions } = axisConfig;
6031
6215
  const dateAxisTickFormat = horizontal ? yTickFormat : xTickFormat;
@@ -6060,7 +6244,8 @@ function useBarChartOptions(data, horizontal, options = {}, isSeriesRendered = A
6060
6244
  }
6061
6245
  },
6062
6246
  barGroup: { padding: getGroupPadding(horizontal ? yScale : xScale) },
6063
- tooltip: { labelFormatter: dateAxisTickFormat || defaultTooltipLabelFormatter }
6247
+ tooltip: { labelFormatter: dateAxisTickFormat || defaultTooltipLabelFormatter },
6248
+ valueTickDecimals: axisConfig.valueTickDecimals
6064
6249
  };
6065
6250
  }, [
6066
6251
  defaultOptions,
@@ -6068,7 +6253,8 @@ function useBarChartOptions(data, horizontal, options = {}, isSeriesRendered = A
6068
6253
  stableOptions,
6069
6254
  horizontal,
6070
6255
  data,
6071
- isSeriesRendered
6256
+ isSeriesRendered,
6257
+ stack
6072
6258
  ]);
6073
6259
  }
6074
6260
  // src/charts/bar-chart/private/band-scale.ts
@@ -6100,6 +6286,17 @@ function getValueScaleBaseline(scale) {
6100
6286
  return Number.isFinite(maybeZero) ? Math.max(maybeZero, minOutput) : minOutput;
6101
6287
  }
6102
6288
  /**
6289
+ * A value's position on a continuous scale, held inside its range so a domain that leaves the value out cannot push a bar off the plot.
6290
+ *
6291
+ * @param {ValueScale} scale - The continuous value scale.
6292
+ * @param {number} value - The value to place.
6293
+ * @return {number} The position in pixels.
6294
+ */
6295
+ function getValueScalePosition(scale, value) {
6296
+ const [a, b] = scale.range().map((r) => Number(r) || 0);
6297
+ return Math.min(Math.max(scale(value), Math.min(a, b)), Math.max(a, b));
6298
+ }
6299
+ /**
6103
6300
  * Compute the rect that spans `valuePositions` along the value axis, centered on a slot and scaled by `widthFactor` across it.
6104
6301
  *
6105
6302
  * @param {object} params - Geometry inputs.
@@ -6296,13 +6493,13 @@ const SelectedBarRing = ({ chartId, selected, slotKeys, groupPadding, horizontal
6296
6493
  const slotOffset = groupScale(selected.slotKey);
6297
6494
  const bandPosition = Number(bandScale((horizontal ? yAccessor : xAccessor)(category)));
6298
6495
  if (slotOffset == null || !Number.isFinite(bandPosition)) return null;
6299
- const valuePositions = selected.data.map((datum) => Number(valueScale(Number((horizontal ? xAccessor : yAccessor)(datum)))));
6496
+ const valuePositions = selected.valueExtent ? selected.valueExtent.map((value) => getValueScalePosition(valueScale, value)) : [getValueScaleBaseline(valueScale), ...selected.data.map((datum) => Number(valueScale(Number((horizontal ? xAccessor : yAccessor)(datum)))))];
6300
6497
  const rect = computeSlotRect({
6301
6498
  horizontal,
6302
6499
  bandPosition,
6303
6500
  slotOffset,
6304
6501
  slotThickness: groupScale.bandwidth(),
6305
- valuePositions: [getValueScaleBaseline(valueScale), ...valuePositions],
6502
+ valuePositions,
6306
6503
  widthFactor: selected.thickness
6307
6504
  });
6308
6505
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SelectedRing, {
@@ -6312,38 +6509,147 @@ const SelectedBarRing = ({ chartId, selected, slotKeys, groupPadding, horizontal
6312
6509
  testId: "bar-chart-selected-ring"
6313
6510
  });
6314
6511
  };
6315
- // src/charts/bar-chart/private/bar-layer.tsx
6512
+ // src/charts/bar-chart/private/stacked-bar-series.tsx
6316
6513
  /**
6317
- * Draws the bars in front of any comparison shadows, slotted for an overlap layout and grouped by visx otherwise, then the selected bar's ring.
6514
+ * The side a segment rounds when it ends its drawn stack: the far end of the positives or of the negatives.
6318
6515
  *
6319
- * @param props - Component props.
6320
- * @param props.chartId - The chart's id, which keeps the ring's clip path unique on a page with several charts.
6321
- * @param props.overlapSlots - The overlap layout, or undefined for a grouped one.
6322
- * @param props.selectedBar - The bar or slot the keyboard has selected.
6323
- * @param props.primaryEntries - The visible primary series, for a grouped layout.
6324
- * @param props.primaryKeys - Their labels, in group order.
6325
- * @param props.getBarBackground - Reads a series' bar fill.
6326
- * @param props.barClassName - Adds classes to a bar.
6327
- * @param props.groupPadding - The padding between the bars of a category.
6516
+ * @param stack - The stack layout.
6517
+ * @param segment - The segment.
6518
+ * @param category - A datum at the segment's category.
6519
+ * @param horizontal - Whether the bars run horizontally.
6520
+ * @param clamp - Holds a value inside the value domain, where the bars are cut off.
6521
+ * @return The side to round, or undefined for a segment inside its stack or drawn with no length.
6522
+ */
6523
+ function getStackEnd(stack, segment, category, horizontal, clamp) {
6524
+ const [start, end] = [segment.start, segment.end].map(clamp);
6525
+ if (start === end) return;
6526
+ const extent = stack.extentAt(category).map(clamp);
6527
+ if (segment.end > 0 && end === extent[1]) return horizontal ? "right" : "top";
6528
+ if (segment.end < 0 && end === extent[0]) return horizontal ? "left" : "bottom";
6529
+ }
6530
+ const StackedBarSeries = ({ barClassName, slotKeys, slotKey, groupPadding, stack, ...props }) => {
6531
+ const { xScale, yScale, horizontal } = (0, react.useContext)(_visx_xychart.DataContext);
6532
+ const bandScale = horizontal ? yScale : xScale;
6533
+ const valueScale = horizontal ? xScale : yScale;
6534
+ const groupScale = (0, react.useMemo)(() => createGroupScale(slotKeys, bandScale?.bandwidth?.() ?? 0, groupPadding), [
6535
+ slotKeys,
6536
+ bandScale,
6537
+ groupPadding
6538
+ ]);
6539
+ const { dataKey, xAccessor, yAccessor } = props;
6540
+ const [domainStart, domainEnd] = (horizontal ? xScale : yScale)?.domain() ?? [-Infinity, Infinity];
6541
+ const domainMin = Math.min(Number(domainStart), Number(domainEnd));
6542
+ const domainMax = Math.max(Number(domainStart), Number(domainEnd));
6543
+ const clamp = (0, react.useCallback)((value) => Math.min(domainMax, Math.max(domainMin, value)), [domainMin, domainMax]);
6544
+ const stackEnd = (0, react.useCallback)((datum) => {
6545
+ const [low, high] = stack.extentAt(datum);
6546
+ return clamp(high > 0 ? high : low);
6547
+ }, [stack, clamp]);
6548
+ const renderGlyph = (0, react.useCallback)(({ datum, color }) => {
6549
+ const segment = stack.segmentOf(dataKey, datum);
6550
+ if (!segment || !bandScale?.bandwidth || !valueScale) return null;
6551
+ const rect = computeSlotRect({
6552
+ horizontal: !!horizontal,
6553
+ bandPosition: Number(bandScale((horizontal ? yAccessor : xAccessor)(datum))),
6554
+ slotOffset: groupScale(slotKey) ?? 0,
6555
+ slotThickness: groupScale.bandwidth(),
6556
+ valuePositions: [segment.start, segment.end].map((value) => getValueScalePosition(valueScale, value)),
6557
+ widthFactor: 1
6558
+ });
6559
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("rect", {
6560
+ ...rect,
6561
+ "data-stack-end": getStackEnd(stack, segment, datum, !!horizontal, clamp),
6562
+ className: (0, clsx.default)("visx-bar", barClassName?.(datum)),
6563
+ fill: color
6564
+ });
6565
+ }, [
6566
+ stack,
6567
+ clamp,
6568
+ dataKey,
6569
+ bandScale,
6570
+ valueScale,
6571
+ horizontal,
6572
+ groupScale,
6573
+ slotKey,
6574
+ xAccessor,
6575
+ yAccessor,
6576
+ barClassName
6577
+ ]);
6578
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_visx_xychart.GlyphSeries, {
6579
+ ...props,
6580
+ xAccessor: horizontal ? stackEnd : xAccessor,
6581
+ yAccessor: horizontal ? yAccessor : stackEnd,
6582
+ enableEvents: false,
6583
+ renderGlyph
6584
+ });
6585
+ };
6586
+ // src/charts/bar-chart/private/bar-layer.tsx
6587
+ /**
6588
+ * Wraps the stacked bars so the entrance animation grows them from the zero line.
6589
+ *
6590
+ * Reading the scales here, not in `BarLayer`, keeps the series' own data registration from re-rendering it in a loop.
6591
+ *
6592
+ * @param props - Component props.
6593
+ * @param props.horizontal - Whether the bars run horizontally.
6594
+ * @param props.children - The stacked series.
6595
+ * @return The group.
6596
+ */
6597
+ const StackedBarGroup = ({ horizontal, children }) => {
6598
+ const { xScale, yScale } = (0, react.useContext)(_visx_xychart.DataContext);
6599
+ const valueScale = horizontal ? xScale : yScale;
6600
+ const zero = valueScale ? getValueScalePosition(valueScale, 0) : 0;
6601
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("g", {
6602
+ className: "visx-bar-group",
6603
+ style: { transformOrigin: horizontal ? `${zero}px 0` : `0 ${zero}px` },
6604
+ children
6605
+ });
6606
+ };
6607
+ /**
6608
+ * Draws the bars in front of any comparison shadows, stacked or slotted in the layout's slots and grouped by visx otherwise, then the selected bar's ring.
6609
+ *
6610
+ * @param props - Component props.
6611
+ * @param props.chartId - The chart's id, which keeps the ring's clip path unique on a page with several charts.
6612
+ * @param props.barSlots - The overlap or stacked slots, or undefined for a grouped layout.
6613
+ * @param props.selectedBar - The bar or slot the keyboard has selected.
6614
+ * @param props.primaryEntries - The visible primary series, for a grouped layout.
6615
+ * @param props.primaryKeys - Their labels, in group order.
6616
+ * @param props.getBarBackground - Reads a series' bar fill.
6617
+ * @param props.barClassName - Adds classes to a bar.
6618
+ * @param props.groupPadding - The padding between the bars of a category.
6328
6619
  * @param props.horizontal - Whether the bars run horizontally.
6329
6620
  * @param props.xAccessor - Reads a datum's x value.
6330
6621
  * @param props.yAccessor - Reads a datum's y value.
6331
6622
  * @return The bars.
6332
6623
  */
6333
- const BarLayer = ({ chartId, overlapSlots, selectedBar, primaryEntries, primaryKeys, getBarBackground, barClassName, groupPadding, horizontal, xAccessor, yAccessor }) => {
6624
+ const BarLayer = ({ chartId, barSlots, selectedBar, primaryEntries, primaryKeys, getBarBackground, barClassName, groupPadding, horizontal, xAccessor, yAccessor }) => {
6334
6625
  let bars;
6335
- if (overlapSlots) bars = /* @__PURE__ */ (0, react_jsx_runtime.jsx)("g", {
6626
+ if (barSlots?.kind === "stacked") bars = /* @__PURE__ */ (0, react_jsx_runtime.jsx)(StackedBarGroup, {
6627
+ horizontal,
6628
+ children: barSlots.entries.map(({ series, index }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(StackedBarSeries, {
6629
+ dataKey: series.label,
6630
+ data: series.data,
6631
+ xAccessor,
6632
+ yAccessor,
6633
+ colorAccessor: getBarBackground(index),
6634
+ barClassName,
6635
+ slotKeys: barSlots.slotKeys,
6636
+ slotKey: barSlots.slotOf(series.label),
6637
+ groupPadding,
6638
+ stack: barSlots.stack
6639
+ }, series.label))
6640
+ });
6641
+ else if (barSlots) bars = /* @__PURE__ */ (0, react_jsx_runtime.jsx)("g", {
6336
6642
  className: "visx-bar-group",
6337
- children: overlapSlots.entries.map(({ series, index }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SlottedBarSeries, {
6643
+ children: barSlots.entries.map(({ series, index }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SlottedBarSeries, {
6338
6644
  dataKey: series.label,
6339
6645
  data: series.data,
6340
6646
  xAccessor,
6341
6647
  yAccessor,
6342
6648
  colorAccessor: getBarBackground(index),
6343
6649
  barClassName,
6344
- slotKeys: overlapSlots.slotKeys,
6345
- slotKey: overlapSlots.slotOf(series.label),
6346
- thickness: overlapSlots.thicknessOf(series.label),
6650
+ slotKeys: barSlots.slotKeys,
6651
+ slotKey: barSlots.slotOf(series.label),
6652
+ thickness: barSlots.thicknessOf(series.label),
6347
6653
  groupPadding
6348
6654
  }, series.label))
6349
6655
  });
@@ -6373,7 +6679,7 @@ const BarLayer = ({ chartId, overlapSlots, selectedBar, primaryEntries, primaryK
6373
6679
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [bars, selectedBar && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SelectedBarRing, {
6374
6680
  chartId,
6375
6681
  selected: selectedBar,
6376
- slotKeys: overlapSlots?.slotKeys ?? primaryKeys,
6682
+ slotKeys: barSlots?.slotKeys ?? primaryKeys,
6377
6683
  groupPadding,
6378
6684
  horizontal,
6379
6685
  xAccessor,
@@ -6509,28 +6815,36 @@ function getOverlapBarColors(series, colors, slotColors, background) {
6509
6815
  });
6510
6816
  return barColors;
6511
6817
  }
6512
- // src/charts/bar-chart/private/use-overlap-slots.ts
6818
+ // src/charts/bar-chart/private/use-bar-slots.ts
6513
6819
  /**
6514
- * Whether two data points sit at the same category: the same label, or the same date.
6820
+ * Lays out the visible series in slots: overlap layers primaries and comparisons in two, stacked puts every primary in one.
6515
6821
  *
6516
- * @param point - A data point.
6517
- * @param category - The data point naming the category.
6518
- * @return Whether `point` is at `category`.
6519
- */
6520
- function isSameCategory(point, category) {
6521
- return category.label ? point.label === category.label : !!category.date && !!point.date && point.date.getTime() === category.date.getTime();
6522
- }
6523
- /**
6524
- * Lays out the visible series of an overlap layout in slots and layers.
6525
- *
6526
- * @param enabled - Whether the chart draws an overlap layout.
6822
+ * @param layout - How the chart places its series in a category.
6527
6823
  * @param seriesWithVisibility - Every series, with its index and whether it is visible.
6528
- * @return The layout, or undefined when the chart is not an overlap layout.
6824
+ * @return The slots, or undefined for a grouped layout.
6529
6825
  */
6530
- function useOverlapSlots(enabled, seriesWithVisibility) {
6826
+ function useBarSlots(layout, seriesWithVisibility) {
6531
6827
  return (0, react.useMemo)(() => {
6532
- if (!enabled) return;
6828
+ if (layout === "grouped") return;
6533
6829
  const visible = seriesWithVisibility.filter(({ isVisible }) => isVisible);
6830
+ if (layout === "stacked") {
6831
+ const entries = visible.map(({ series, index }) => ({
6832
+ series,
6833
+ index
6834
+ }));
6835
+ const slotKeys = [PRIMARY_SLOT];
6836
+ const slotOf = () => PRIMARY_SLOT;
6837
+ return {
6838
+ kind: "stacked",
6839
+ stack: getStackLayout(entries.map(({ series }) => series)),
6840
+ entries,
6841
+ keys: entries.map(({ series }) => series.label),
6842
+ slotKeys,
6843
+ slotOf,
6844
+ thicknessOf: () => 1,
6845
+ positions: getStopPositions(entries, slotKeys, slotOf)
6846
+ };
6847
+ }
6534
6848
  const placements = getOverlapPlacements(visible.map(({ series }) => series));
6535
6849
  const placed = visible.map(({ series, index }, position) => ({
6536
6850
  entry: {
@@ -6547,6 +6861,7 @@ function useOverlapSlots(enabled, seriesWithVisibility) {
6547
6861
  const showsComparisons = entries.some(({ series }) => slotOf(series.label) === COMPARISON_SLOT);
6548
6862
  const slotKeys = [...hasPrimaries ? [PRIMARY_SLOT] : [], ...showsComparisons ? [COMPARISON_SLOT] : []];
6549
6863
  return {
6864
+ kind: "overlap",
6550
6865
  entries,
6551
6866
  keys: entries.map(({ series }) => series.label),
6552
6867
  slotKeys,
@@ -6554,16 +6869,7 @@ function useOverlapSlots(enabled, seriesWithVisibility) {
6554
6869
  thicknessOf,
6555
6870
  positions: getStopPositions(entries, slotKeys, slotOf)
6556
6871
  };
6557
- }, [enabled, seriesWithVisibility]);
6558
- }
6559
- /**
6560
- * The category a data point sits at, as a key two points share when `isSameCategory` holds.
6561
- *
6562
- * @param point - A data point.
6563
- * @return The category key.
6564
- */
6565
- function categoryKey(point) {
6566
- return point.label ? `label:${point.label}` : `date:${point.date?.getTime()}`;
6872
+ }, [layout, seriesWithVisibility]);
6567
6873
  }
6568
6874
  /**
6569
6875
  * Lists a stop for every slot at every category that slot draws a bar at, category by category.
@@ -6622,7 +6928,7 @@ function membersAt(entries, category, stopKey) {
6622
6928
  /**
6623
6929
  * The slot a keyboard index selects, and every bar at its category.
6624
6930
  *
6625
- * @param slots - The overlap layout.
6931
+ * @param slots - The overlap or stacked slots.
6626
6932
  * @param selectedIndex - The keyboard index into `slots.positions`.
6627
6933
  * @return The selected slot, or undefined when nothing is selected or drawn there.
6628
6934
  */
@@ -6636,25 +6942,26 @@ function getSelectedSlot(slots, selectedIndex) {
6636
6942
  data: slotBars.map(({ datum }) => datum),
6637
6943
  slotKey,
6638
6944
  thickness: Math.max(...slotBars.map(({ key }) => slots.thicknessOf(key))),
6639
- members
6945
+ members,
6946
+ ...slots.kind === "stacked" && { valueExtent: slots.stack.extentAt(category) }
6640
6947
  };
6641
6948
  }
6642
6949
  // src/charts/bar-chart/private/use-bar-stops.ts
6643
6950
  /**
6644
- * Lays out the keyboard stops: one per slot and category in an overlap layout, else one per primary bar, series-major within each category.
6951
+ * Lays out the keyboard stops: one per slot and category in a slotted layout, else one per primary bar, series-major within each category.
6645
6952
  *
6646
- * @param overlapSlots - The overlap layout, or undefined for a grouped one.
6953
+ * @param barSlots - The overlap or stacked slots, or undefined for a grouped layout.
6647
6954
  * @param primaryEntries - The visible primary series.
6648
6955
  * @return The stops.
6649
6956
  */
6650
- function useBarStops(overlapSlots, primaryEntries) {
6651
- const series = (0, react.useMemo)(() => overlapSlots ? [] : primaryEntries.map((entry) => entry.series), [overlapSlots, primaryEntries]);
6957
+ function useBarStops(barSlots, primaryEntries) {
6958
+ const series = (0, react.useMemo)(() => barSlots ? [] : primaryEntries.map((entry) => entry.series), [barSlots, primaryEntries]);
6652
6959
  return {
6653
- count: overlapSlots?.positions.length ?? Math.max(0, ...series.map((item) => item.data.length)) * series.length,
6654
- key: (0, react.useMemo)(() => JSON.stringify(overlapSlots?.keys ?? series.map((item) => item.label)), [overlapSlots, series]),
6960
+ count: barSlots?.positions.length ?? Math.max(0, ...series.map((item) => item.data.length)) * series.length,
6961
+ key: (0, react.useMemo)(() => JSON.stringify(barSlots?.keys ?? series.map((item) => item.label)), [barSlots, series]),
6655
6962
  barAt: (0, react.useCallback)((stop) => {
6656
- if (overlapSlots) {
6657
- const position = overlapSlots.positions[stop];
6963
+ if (barSlots) {
6964
+ const position = barSlots.positions[stop];
6658
6965
  return position && {
6659
6966
  datum: position.datum,
6660
6967
  index: position.dataPointIndex,
@@ -6670,17 +6977,17 @@ function useBarStops(overlapSlots, primaryEntries) {
6670
6977
  index,
6671
6978
  key: item.label
6672
6979
  } : void 0;
6673
- }, [overlapSlots, series]),
6980
+ }, [barSlots, series]),
6674
6981
  stopOf: (0, react.useCallback)((seriesKey, dataPointIndex) => {
6675
- if (overlapSlots) {
6676
- const hovered = overlapSlots.entries.find((entry) => entry.series.label === seriesKey)?.series.data[dataPointIndex];
6677
- const slotKey = overlapSlots.slotOf(seriesKey);
6678
- const stop = hovered ? overlapSlots.positions.findIndex((position) => position.slotKey === slotKey && isSameCategory(position.datum, hovered)) : -1;
6982
+ if (barSlots) {
6983
+ const hovered = barSlots.entries.find((entry) => entry.series.label === seriesKey)?.series.data[dataPointIndex];
6984
+ const slotKey = barSlots.slotOf(seriesKey);
6985
+ const stop = hovered ? barSlots.positions.findIndex((position) => position.slotKey === slotKey && isSameCategory(position.datum, hovered)) : -1;
6679
6986
  return stop >= 0 ? stop : void 0;
6680
6987
  }
6681
6988
  const seriesIndex = series.findIndex((item) => item.label === seriesKey);
6682
6989
  return seriesIndex >= 0 ? dataPointIndex * series.length + seriesIndex : void 0;
6683
- }, [overlapSlots, series])
6990
+ }, [barSlots, series])
6684
6991
  };
6685
6992
  }
6686
6993
  /**
@@ -6835,10 +7142,23 @@ function nearestBandIndex(data, accessor, scale, position) {
6835
7142
  return nearest;
6836
7143
  }
6837
7144
  /**
7145
+ * How far a pointer sits from a stacked segment along the value axis.
7146
+ *
7147
+ * @param segment - The segment, or undefined when its series has no reading there.
7148
+ * @param scale - The value scale.
7149
+ * @param position - Pointer coordinate on the value axis.
7150
+ * @return 0 inside the segment, Infinity without one, otherwise the gap to its nearer end.
7151
+ */
7152
+ function distanceToSegment(segment, scale, position) {
7153
+ if (!segment) return Infinity;
7154
+ const [low, high] = [segment.start, segment.end].map((value) => getValueScalePosition(scale, value)).sort((a, b) => a - b);
7155
+ return Math.max(low - position, 0, position - high);
7156
+ }
7157
+ /**
6838
7158
  * Correct visx's range-based band inversion, which omits outer padding.
6839
7159
  * @param root0 - Registered series selection.
6840
7160
  * @param root0.keys - Visible series keys, back to front where bars overlap.
6841
- * @param root0.slots - Where series share slots: the slots of a category, in the order the band lays them out, and the slot each series sits in.
7161
+ * @param root0.slots - Where series share slots: the slots of a category, in the order the band lays them out, the slot each series sits in, and for a stack where each segment runs.
6842
7162
  * @param root0.groupPadding - Padding between grouped bars.
6843
7163
  * @param root0.withTooltips - Whether pointer events update the tooltip.
6844
7164
  * @param root0.onPointerDown - Receives the corrected pointer-down datum.
@@ -6850,6 +7170,7 @@ function BandTooltip({ keys, slots, groupPadding, withTooltips, onPointerDown, o
6850
7170
  const { xScale, yScale, dataRegistry, horizontal } = (0, react.useContext)(_visx_xychart.DataContext);
6851
7171
  const { showTooltip, hideTooltip, updateTooltip } = (0, react.useContext)(_visx_xychart.TooltipContext);
6852
7172
  const scale = horizontal ? yScale : xScale;
7173
+ const valueScale = horizontal ? xScale : yScale;
6853
7174
  const bandwidth = scale?.bandwidth?.() ?? 0;
6854
7175
  const groupScale = (0, react.useMemo)(() => createGroupScale(slots?.keys ?? keys, bandwidth, groupPadding), [
6855
7176
  slots,
@@ -6874,6 +7195,7 @@ function BandTooltip({ keys, slots, groupPadding, withTooltips, onPointerDown, o
6874
7195
  const start = band + Number(groupScale(slots ? slots.slotOf(key) : key));
6875
7196
  const end = start + groupScale.step();
6876
7197
  const distance = position >= start && position <= end ? 0 : Math.abs(position - (start + end) / 2);
7198
+ const valueDistance = slots?.stack && valueScale ? distanceToSegment(slots.stack.segmentOf(key, datum), valueScale, horizontal ? point.x : point.y) : 0;
6877
7199
  bands.push(band);
6878
7200
  selections.push({
6879
7201
  event: params.event,
@@ -6881,8 +7203,8 @@ function BandTooltip({ keys, slots, groupPadding, withTooltips, onPointerDown, o
6881
7203
  datum,
6882
7204
  index,
6883
7205
  svgPoint: point,
6884
- distanceX: horizontal ? 0 : distance,
6885
- distanceY: horizontal ? distance : 0
7206
+ distanceX: horizontal ? valueDistance : distance,
7207
+ distanceY: horizontal ? distance : valueDistance
6886
7208
  });
6887
7209
  }
6888
7210
  if (!slots) return selections;
@@ -6891,6 +7213,7 @@ function BandTooltip({ keys, slots, groupPadding, withTooltips, onPointerDown, o
6891
7213
  return selections.filter((_, index) => bands[index] === hoveredBand);
6892
7214
  }, [
6893
7215
  scale,
7216
+ valueScale,
6894
7217
  dataRegistry,
6895
7218
  horizontal,
6896
7219
  keys,
@@ -6984,6 +7307,16 @@ function useBarColors() {
6984
7307
  data,
6985
7308
  index
6986
7309
  }).color);
7310
+ if (layout === "stacked") {
7311
+ const drawn = getDrawnSeries(series, layout);
7312
+ return series.map((data, index) => {
7313
+ const drawnIndex = drawn.indexOf(data);
7314
+ return drawnIndex === -1 ? colors[index] : getElementStyles({
7315
+ data,
7316
+ index: drawnIndex
7317
+ }).color;
7318
+ });
7319
+ }
6987
7320
  if (layout !== "overlap") return comparisonOpacity === void 0 ? getGroupedBarColors(series, colors, backgroundColor) : colors;
6988
7321
  return getOverlapBarColors(series, colors, [getElementStyles({ index: 0 }).color, getElementStyles({ index: 1 }).color], backgroundColor);
6989
7322
  }, [
@@ -7032,13 +7365,14 @@ function forBarLayout(data, items, layout, seriesColors) {
7032
7365
  /**
7033
7366
  * Builds legend items that match `BarChart`'s bars in a layout, for a custom legend or a chart's own.
7034
7367
  *
7035
- * @param data - The series the chart draws.
7368
+ * @param allData - The chart's series; those the layout does not draw get no item.
7036
7369
  * @param options - The legend options, and the layout the bars are drawn in.
7037
7370
  * @param legendShape - The shape of the legend swatches.
7038
7371
  * @return The legend items.
7039
7372
  */
7040
- function useBarLegendItems(data, options = {}, legendShape) {
7373
+ function useBarLegendItems(allData, options = {}, legendShape) {
7041
7374
  const { layout } = options;
7375
+ const data = (0, react.useMemo)(() => getDrawnSeries(allData, layout), [allData, layout]);
7042
7376
  const getBarColors = useBarColors();
7043
7377
  const seriesColors = (0, react.useMemo)(() => layout ? getBarColors(data, { layout }) : void 0, [
7044
7378
  data,
@@ -7067,7 +7401,12 @@ const renderTooltipRow = (label, value) => /* @__PURE__ */ (0, react_jsx_runtime
7067
7401
  className: bar_chart_module_default["bar-chart__tooltip-row"],
7068
7402
  children: (0, _wordpress_i18n.sprintf)((0, _wordpress_i18n.__)("%1$s: %2$s", "jetpack-charts"), label, value)
7069
7403
  });
7070
- const BarChartInternal = ({ data, ariaLabel, chartId: providedChartId, width, height, className, margin, withTooltips = false, showLegend = false, legend = {}, gridVisibility: gridVisibilityProp, renderTooltip, tooltipPlacement, tooltipAnchorTop, tooltipStyle, barClassName, options = {}, orientation = "vertical", layout = "grouped", withPatterns = false, showZeroValues = false, withBandHighlight = false, onBandHighlightChange, defaultHiddenSeries, animation, children, gap = "md", onPointerDown, onPointerUp, onDatumActivate }) => {
7404
+ const BarChartInternal = ({ data, ariaLabel, chartId: providedChartId, width, height, className, margin, withTooltips = false, showLegend = false, legend = {}, gridVisibility: gridVisibilityProp, renderTooltip, tooltipPlacement, tooltipAnchorTop, tooltipStyle, barClassName, options = {}, orientation = "vertical", layout = "grouped", withPatterns = false, showZeroValues = false, withBandHighlight = false, onBandHighlightChange, defaultHiddenSeries, animation, children, gap = "md", compactWhenShort = false, onPointerDown, onPointerUp, onDatumActivate }) => {
7405
+ if (layout === "stacked" && showZeroValues) warnOnce("bar-chart-stacked-zero-values", "BarChart: showZeroValues has no effect in a stacked layout.");
7406
+ if (layout === "stacked" && data?.some((series) => series.options?.type === "comparison")) warnOnce("bar-chart-stacked-comparison", "BarChart: a stacked layout does not draw comparison series yet.");
7407
+ const valueScaleOptions = orientation === "horizontal" ? options.xScale : options.yScale;
7408
+ if (layout === "stacked" && valueScaleOptions?.type && valueScaleOptions.type !== "linear") warnOnce(`bar-chart-stacked-${valueScaleOptions.type}-scale`, `BarChart: a stacked layout draws on a linear value scale, so the ${valueScaleOptions.type} scale is ignored.`);
7409
+ if (layout === "stacked" && valueScaleOptions?.zero === false && !valueScaleOptions.domain) warnOnce("bar-chart-stacked-zero", "BarChart: every stack starts at zero, so zero: false has no effect in a stacked layout.");
7071
7410
  if (!withTooltips && (withBandHighlight || onBandHighlightChange)) warnOnce("bar-chart-band-highlight-without-tooltips", "BarChart: withBandHighlight and onBandHighlightChange require withTooltips.");
7072
7411
  const legendInteractive = legend.interactive ?? false;
7073
7412
  const legendCollapseGroups = legend.collapseGroups ?? false;
@@ -7075,13 +7414,15 @@ const BarChartInternal = ({ data, ariaLabel, chartId: providedChartId, width, he
7075
7414
  const legendComparisonSeriesItems = legend.comparisonSeriesItems;
7076
7415
  const horizontal = orientation === "horizontal";
7077
7416
  const isOverlap = layout === "overlap";
7417
+ const isStacked = layout === "stacked";
7078
7418
  const chartId = useChartId(providedChartId);
7079
7419
  const hiddenSeries = useDefaultHiddenSeries(chartId, defaultHiddenSeries);
7080
7420
  const isSeriesVisible = (0, react.useCallback)((seriesLabel) => !hiddenSeries.has(seriesLabel), [hiddenSeries]);
7081
7421
  const theme = useXYChartTheme(data);
7082
- const dataSorted = useChartDataTransform(data);
7422
+ const transformedData = useChartDataTransform(data);
7423
+ const dataSorted = (0, react.useMemo)(() => getDrawnSeries(transformedData, layout), [layout, transformedData]);
7083
7424
  const dataWithVisibleZeros = useZeroValueDisplay(dataSorted, {
7084
- enabled: showZeroValues,
7425
+ enabled: showZeroValues && !isStacked,
7085
7426
  valueAxisLength: horizontal ? width : height
7086
7427
  });
7087
7428
  const legendItems = useBarLegendItems(dataSorted, (0, react.useMemo)(() => ({
@@ -7105,13 +7446,39 @@ const BarChartInternal = ({ data, ariaLabel, chartId: providedChartId, width, he
7105
7446
  if (providerTheme.barChart?.barStyles?.comparison?.opacity !== void 0) warnOnce("bar-chart-comparison-opacity", "BarChart: theme.barChart.barStyles.comparison.opacity is deprecated. Comparison bars are opaque; leave it unset.");
7106
7447
  const isSeriesRendered = (0, react.useCallback)((series) => isSeriesVisible(series.label), [isSeriesVisible]);
7107
7448
  const hasWholeNumberValues = (0, react.useMemo)(() => hasOnlyWholeNumbers(dataSorted.filter(isSeriesRendered)), [dataSorted, isSeriesRendered]);
7108
- const chartOptions = useBarChartOptions(dataWithVisibleZeros, horizontal, options, isSeriesRendered);
7449
+ const { isCompact, compactMargin } = useCompactWhenShort(compactWhenShort && !horizontal, height);
7450
+ const resolvedOptions = (0, react.useMemo)(() => isCompact ? {
7451
+ ...options,
7452
+ axis: {
7453
+ ...options.axis,
7454
+ x: {
7455
+ ...options.axis?.x,
7456
+ display: false
7457
+ },
7458
+ y: {
7459
+ ...options.axis?.y,
7460
+ display: false
7461
+ }
7462
+ }
7463
+ } : options, [isCompact, options]);
7464
+ const seriesWithVisibility = (0, react.useMemo)(() => dataWithVisibleZeros.map((series, index) => ({
7465
+ series,
7466
+ index,
7467
+ isVisible: isSeriesRendered(series)
7468
+ })), [dataWithVisibleZeros, isSeriesRendered]);
7469
+ const allSeriesHidden = (0, react.useMemo)(() => {
7470
+ return seriesWithVisibility.every(({ isVisible }) => !isVisible);
7471
+ }, [seriesWithVisibility]);
7472
+ const primaryEntries = (0, react.useMemo)(() => seriesWithVisibility.filter(({ isVisible, series }) => isVisible && series.options?.type !== "comparison"), [seriesWithVisibility]);
7473
+ const barSlots = useBarSlots(layout, seriesWithVisibility);
7474
+ const chartOptions = useBarChartOptions(dataWithVisibleZeros, horizontal, resolvedOptions, isSeriesRendered, barSlots?.kind === "stacked" ? barSlots.stack : void 0);
7109
7475
  const valueAxis = horizontal ? chartOptions.axis.x : chartOptions.axis.y;
7110
7476
  const callerValueDomain = horizontal ? options.xScale?.domain : options.yScale?.domain;
7111
- const wholeNumberTicksProps = {
7477
+ const valueTickDecimals = getTickDecimals(hasWholeNumberValues, chartOptions.valueTickDecimals);
7478
+ const tickDecimalsProps = {
7112
7479
  axis: horizontal ? "x" : "y",
7113
7480
  numTicks: valueAxis.numTicks,
7114
- enabled: hasWholeNumberValues && !valueAxis.tickValues && !callerValueDomain
7481
+ decimals: !valueAxis.tickValues && !callerValueDomain ? valueTickDecimals : void 0
7115
7482
  };
7116
7483
  const defaultMargin = useChartMargin(height, chartOptions, dataSorted, theme, horizontal);
7117
7484
  const chartRef = (0, react.useRef)(null);
@@ -7122,18 +7489,8 @@ const BarChartInternal = ({ data, ariaLabel, chartId: providedChartId, width, he
7122
7489
  }, [height]);
7123
7490
  const [selectedIndex, setSelectedIndex] = (0, react.useState)(void 0);
7124
7491
  const [isNavigating, setIsNavigating] = (0, react.useState)(false);
7125
- const seriesWithVisibility = (0, react.useMemo)(() => dataWithVisibleZeros.map((series, index) => ({
7126
- series,
7127
- index,
7128
- isVisible: isSeriesRendered(series)
7129
- })), [dataWithVisibleZeros, isSeriesRendered]);
7130
- const allSeriesHidden = (0, react.useMemo)(() => {
7131
- return seriesWithVisibility.every(({ isVisible }) => !isVisible);
7132
- }, [seriesWithVisibility]);
7133
- const primaryEntries = (0, react.useMemo)(() => seriesWithVisibility.filter(({ isVisible, series }) => isVisible && series.options?.type !== "comparison"), [seriesWithVisibility]);
7134
- const overlapSlots = useOverlapSlots(isOverlap, seriesWithVisibility);
7135
7492
  const primaryKeys = (0, react.useMemo)(() => primaryEntries.map(({ series }) => series.label), [primaryEntries]);
7136
- const stops = useBarStops(overlapSlots, primaryEntries);
7493
+ const stops = useBarStops(barSlots, primaryEntries);
7137
7494
  const { barAt, stopOf } = stops;
7138
7495
  const activateSelectedBar = (0, react.useCallback)((stop) => {
7139
7496
  const bar = barAt(stop);
@@ -7154,7 +7511,7 @@ const BarChartInternal = ({ data, ariaLabel, chartId: providedChartId, width, he
7154
7511
  if (stop !== void 0) onChartPointerMove(stop);
7155
7512
  }, [stopOf, onChartPointerMove]);
7156
7513
  const comparisonEntries = (0, react.useMemo)(() => {
7157
- if (isOverlap) return [];
7514
+ if (barSlots) return [];
7158
7515
  const primaryByGroup = new Map(primaryEntries.map(({ series, index }) => [series.group, {
7159
7516
  label: series.label,
7160
7517
  index
@@ -7175,7 +7532,7 @@ const BarChartInternal = ({ data, ariaLabel, chartId: providedChartId, width, he
7175
7532
  });
7176
7533
  return entries;
7177
7534
  }, [
7178
- isOverlap,
7535
+ barSlots,
7179
7536
  seriesWithVisibility,
7180
7537
  primaryEntries,
7181
7538
  primaryKeys
@@ -7241,6 +7598,32 @@ const BarChartInternal = ({ data, ariaLabel, chartId: providedChartId, width, he
7241
7598
  })]
7242
7599
  });
7243
7600
  }, [chartOptions.tooltip, dataSorted]);
7601
+ const renderStackedTooltip = (0, react.useCallback)(({ tooltipData }) => {
7602
+ const nearestDatum = tooltipData?.nearestDatum?.datum;
7603
+ if (!nearestDatum || barSlots?.kind !== "stacked") return null;
7604
+ const datumByKey = tooltipData?.datumByKey ?? {};
7605
+ const categoryLabel = chartOptions.tooltip.labelFormatter(nearestDatum.label || (nearestDatum.date ? nearestDatum.date.getTime() : 0), 0, []);
7606
+ const rows = [...barSlots.entries].reverse().flatMap(({ series }) => {
7607
+ const datum = datumByKey[series.label]?.datum;
7608
+ return datum ? [{
7609
+ label: series.label,
7610
+ datum
7611
+ }] : [];
7612
+ });
7613
+ const readings = rows.filter(({ datum }) => isBarRendered(datum)).length;
7614
+ const [negative, positive] = barSlots.stack.extentAt(nearestDatum);
7615
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
7616
+ className: bar_chart_module_default["bar-chart__tooltip"],
7617
+ children: [
7618
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
7619
+ className: bar_chart_module_default["bar-chart__tooltip-header"],
7620
+ children: categoryLabel
7621
+ }),
7622
+ rows.map(({ label, datum }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react.Fragment, { children: renderTooltipRow(label, formatReading(datum.value)) }, label)),
7623
+ readings > 1 && renderTooltipRow((0, _wordpress_i18n.__)("Total", "jetpack-charts"), formatReading(negative + positive))
7624
+ ]
7625
+ });
7626
+ }, [chartOptions.tooltip, barSlots]);
7244
7627
  const renderDefaultTooltip = (0, react.useCallback)(({ tooltipData }) => {
7245
7628
  const nearestDatum = tooltipData?.nearestDatum?.datum;
7246
7629
  if (!nearestDatum) return null;
@@ -7312,24 +7695,25 @@ const BarChartInternal = ({ data, ariaLabel, chartId: providedChartId, width, he
7312
7695
  }
7313
7696
  `;
7314
7697
  }, [chartId]);
7315
- const overlapBandSlots = (0, react.useMemo)(() => overlapSlots && {
7316
- keys: overlapSlots.slotKeys,
7317
- slotOf: overlapSlots.slotOf
7318
- }, [overlapSlots]);
7319
- const selectedSlot = (0, react.useMemo)(() => getSelectedSlot(overlapSlots, selectedIndex), [overlapSlots, selectedIndex]);
7698
+ const barBandSlots = (0, react.useMemo)(() => barSlots && {
7699
+ keys: barSlots.slotKeys,
7700
+ slotOf: barSlots.slotOf,
7701
+ stack: barSlots.kind === "stacked" ? barSlots.stack : void 0
7702
+ }, [barSlots]);
7703
+ const selectedSlot = (0, react.useMemo)(() => getSelectedSlot(barSlots, selectedIndex), [barSlots, selectedIndex]);
7320
7704
  const selectedGroup = (0, react.useMemo)(() => {
7321
- const stop = overlapSlots || selectedIndex === void 0 ? void 0 : barAt(selectedIndex);
7705
+ const stop = barSlots || selectedIndex === void 0 ? void 0 : barAt(selectedIndex);
7322
7706
  if (!stop) return;
7323
7707
  return membersAt(primaryEntries, stop.datum, stop.key);
7324
7708
  }, [
7325
- overlapSlots,
7709
+ barSlots,
7326
7710
  selectedIndex,
7327
7711
  barAt,
7328
7712
  primaryEntries
7329
7713
  ]);
7330
7714
  const selectedMembers = selectedSlot?.members ?? selectedGroup;
7331
7715
  const selectedBar = (0, react.useMemo)(() => {
7332
- if (overlapSlots) return selectedSlot;
7716
+ if (barSlots) return selectedSlot;
7333
7717
  const bar = selectedIndex === void 0 ? void 0 : barAt(selectedIndex);
7334
7718
  return bar && isBarRendered(bar.datum) ? {
7335
7719
  data: [bar.datum],
@@ -7337,7 +7721,7 @@ const BarChartInternal = ({ data, ariaLabel, chartId: providedChartId, width, he
7337
7721
  thickness: 1
7338
7722
  } : void 0;
7339
7723
  }, [
7340
- overlapSlots,
7724
+ barSlots,
7341
7725
  selectedSlot,
7342
7726
  selectedIndex,
7343
7727
  barAt
@@ -7360,9 +7744,9 @@ const BarChartInternal = ({ data, ariaLabel, chartId: providedChartId, width, he
7360
7744
  className: (0, clsx.default)("bar-chart", bar_chart_module_default["bar-chart"]),
7361
7745
  children: error
7362
7746
  });
7363
- const gridVisibility = gridVisibilityProp ?? chartOptions.gridVisibility;
7747
+ const gridVisibility = isCompact ? "none" : gridVisibilityProp ?? chartOptions.gridVisibility;
7364
7748
  const legendPosition = legend.position ?? "bottom";
7365
- const legendElement = showLegend && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Legend, {
7749
+ const legendElement = showLegend && !isCompact && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Legend, {
7366
7750
  orientation: legend.orientation ?? "horizontal",
7367
7751
  position: legendPosition,
7368
7752
  alignment: legend.alignment ?? "center",
@@ -7385,9 +7769,12 @@ const BarChartInternal = ({ data, ariaLabel, chartId: providedChartId, width, he
7385
7769
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ChartLayout, {
7386
7770
  legendPosition,
7387
7771
  legendElement,
7388
- legendChildren,
7772
+ legendChildren: isCompact ? [] : legendChildren,
7389
7773
  gap,
7390
- className: (0, clsx.default)("bar-chart", bar_chart_module_default["bar-chart"], { [bar_chart_module_default[`bar-chart--animated${horizontal ? "-horizontal" : ""}`]]: animation && !prefersReducedMotion }, className),
7774
+ className: (0, clsx.default)("bar-chart", bar_chart_module_default["bar-chart"], {
7775
+ [bar_chart_module_default["bar-chart--stacked"]]: isStacked,
7776
+ [bar_chart_module_default[`bar-chart--animated${horizontal ? "-horizontal" : ""}`]]: animation && !prefersReducedMotion
7777
+ }, className),
7391
7778
  style: {
7392
7779
  width,
7393
7780
  height
@@ -7414,6 +7801,7 @@ const BarChartInternal = ({ data, ariaLabel, chartId: providedChartId, width, he
7414
7801
  height: chartHeight,
7415
7802
  margin: {
7416
7803
  ...defaultMargin,
7804
+ ...compactMargin,
7417
7805
  ...margin
7418
7806
  },
7419
7807
  xScale,
@@ -7426,8 +7814,8 @@ const BarChartInternal = ({ data, ariaLabel, chartId: providedChartId, width, he
7426
7814
  horizontal,
7427
7815
  onChange: onBandHighlightChange
7428
7816
  }),
7429
- !allSeriesHidden && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(WholeNumberTicks, {
7430
- ...wholeNumberTicksProps,
7817
+ !allSeriesHidden && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TickDecimals, {
7818
+ ...tickDecimalsProps,
7431
7819
  children: (valueTicks) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_visx_xychart.Grid, {
7432
7820
  columns: gridVisibility.includes("y"),
7433
7821
  rows: false,
@@ -7446,7 +7834,7 @@ const BarChartInternal = ({ data, ariaLabel, chartId: providedChartId, width, he
7446
7834
  y: chartHeight / 2,
7447
7835
  width,
7448
7836
  height: chartHeight,
7449
- children: getAllHiddenMessage(legendInteractive, "series")
7837
+ children: getAllHiddenMessage(legendInteractive && !isCompact, "series")
7450
7838
  }) : null,
7451
7839
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ComparisonBars, {
7452
7840
  comparisonEntries,
@@ -7460,7 +7848,7 @@ const BarChartInternal = ({ data, ariaLabel, chartId: providedChartId, width, he
7460
7848
  }),
7461
7849
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)(BarLayer, {
7462
7850
  chartId,
7463
- overlapSlots,
7851
+ barSlots,
7464
7852
  selectedBar,
7465
7853
  primaryEntries,
7466
7854
  primaryKeys,
@@ -7472,16 +7860,16 @@ const BarChartInternal = ({ data, ariaLabel, chartId: providedChartId, width, he
7472
7860
  yAccessor: chartOptions.accessors.yAccessor
7473
7861
  }),
7474
7862
  (withTooltips || onPointerDown || onPointerUp) && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(BandTooltip, {
7475
- keys: overlapSlots?.keys ?? primaryKeys,
7476
- slots: overlapBandSlots,
7863
+ keys: barSlots?.keys ?? primaryKeys,
7864
+ slots: barBandSlots,
7477
7865
  groupPadding,
7478
7866
  withTooltips,
7479
7867
  onPointerDown,
7480
7868
  onPointerUp,
7481
7869
  onPointerMove: handlePointerMove
7482
7870
  }),
7483
- !allSeriesHidden && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(WholeNumberTicks, {
7484
- ...wholeNumberTicksProps,
7871
+ !allSeriesHidden && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TickDecimals, {
7872
+ ...tickDecimalsProps,
7485
7873
  children: (valueTicks) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [chartOptions.axis.x.display !== false && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_visx_xychart.Axis, {
7486
7874
  ...chartOptions.axis.x,
7487
7875
  ...horizontal && valueTicks ? { tickValues: valueTicks } : {}
@@ -7498,7 +7886,7 @@ const BarChartInternal = ({ data, ariaLabel, chartId: providedChartId, width, he
7498
7886
  detectBounds: true,
7499
7887
  snapTooltipToDatumX: true,
7500
7888
  snapTooltipToDatumY: true,
7501
- renderTooltip: renderTooltip || (isOverlap ? renderOverlapTooltip : renderDefaultTooltip),
7889
+ renderTooltip: renderTooltip || isStacked && renderStackedTooltip || (isOverlap ? renderOverlapTooltip : renderDefaultTooltip),
7502
7890
  selectedIndex,
7503
7891
  tooltipRef,
7504
7892
  keyboardFocusedClassName: bar_chart_module_default["bar-chart__tooltip--keyboard-focused"],
@@ -9833,629 +10221,6 @@ const useMonthCalendarHeatmapData = (valueByDay, range, options = {}) => {
9833
10221
  weekStartsOn
9834
10222
  ]);
9835
10223
  };
9836
- // ../../../node_modules/.pnpm/is-plain-object@5.1.0/node_modules/is-plain-object/dist/is-plain-object.mjs
9837
- /*!
9838
- * is-plain-object <https://github.com/jonschlinkert/is-plain-object>
9839
- *
9840
- * Copyright (c) 2014-2017, Jon Schlinkert.
9841
- * Released under the MIT License.
9842
- */
9843
- function isObject(o) {
9844
- return Object.prototype.toString.call(o) === "[object Object]";
9845
- }
9846
- function isPlainObject(o) {
9847
- var ctor, prot;
9848
- if (isObject(o) === false) return false;
9849
- ctor = o.constructor;
9850
- if (ctor === void 0) return true;
9851
- prot = ctor.prototype;
9852
- if (isObject(prot) === false) return false;
9853
- if (prot.hasOwnProperty("isPrototypeOf") === false) return false;
9854
- return true;
9855
- }
9856
- // ../../../node_modules/.pnpm/@wordpress+warning@4.0.0/node_modules/@wordpress/warning/build-module/utils.mjs
9857
- var logged = /* @__PURE__ */ new Set();
9858
- // ../../../node_modules/.pnpm/@wordpress+warning@4.0.0/node_modules/@wordpress/warning/build-module/index.mjs
9859
- function isDev() {
9860
- return globalThis.SCRIPT_DEBUG === true;
9861
- }
9862
- function warning(message) {
9863
- if (!isDev()) return;
9864
- if (logged.has(message)) return;
9865
- console.warn(message);
9866
- try {
9867
- throw Error(message);
9868
- } catch {}
9869
- logged.add(message);
9870
- }
9871
- // ../../../node_modules/.pnpm/fast-deep-equal@3.1.3/node_modules/fast-deep-equal/es6/index.js
9872
- var require_es6 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
9873
- module.exports = function equal(a, b) {
9874
- if (a === b) return true;
9875
- if (a && b && typeof a == "object" && typeof b == "object") {
9876
- if (a.constructor !== b.constructor) return false;
9877
- var length, i, keys;
9878
- if (Array.isArray(a)) {
9879
- length = a.length;
9880
- if (length != b.length) return false;
9881
- for (i = length; i-- !== 0;) if (!equal(a[i], b[i])) return false;
9882
- return true;
9883
- }
9884
- if (a instanceof Map && b instanceof Map) {
9885
- if (a.size !== b.size) return false;
9886
- for (i of a.entries()) if (!b.has(i[0])) return false;
9887
- for (i of a.entries()) if (!equal(i[1], b.get(i[0]))) return false;
9888
- return true;
9889
- }
9890
- if (a instanceof Set && b instanceof Set) {
9891
- if (a.size !== b.size) return false;
9892
- for (i of a.entries()) if (!b.has(i[0])) return false;
9893
- return true;
9894
- }
9895
- if (ArrayBuffer.isView(a) && ArrayBuffer.isView(b)) {
9896
- length = a.length;
9897
- if (length != b.length) return false;
9898
- for (i = length; i-- !== 0;) if (a[i] !== b[i]) return false;
9899
- return true;
9900
- }
9901
- if (a.constructor === RegExp) return a.source === b.source && a.flags === b.flags;
9902
- if (a.valueOf !== Object.prototype.valueOf) return a.valueOf() === b.valueOf();
9903
- if (a.toString !== Object.prototype.toString) return a.toString() === b.toString();
9904
- keys = Object.keys(a);
9905
- length = keys.length;
9906
- if (length !== Object.keys(b).length) return false;
9907
- for (i = length; i-- !== 0;) if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false;
9908
- for (i = length; i-- !== 0;) {
9909
- var key = keys[i];
9910
- if (!equal(a[key], b[key])) return false;
9911
- }
9912
- return true;
9913
- }
9914
- return a !== a && b !== b;
9915
- };
9916
- }));
9917
- // ../../../node_modules/.pnpm/@wordpress+components@43.0.0_@date-fns+tz@1.5.0_@types+react-dom@19.3.0_@types+react@19_401cb4bad47bd1f7b56615ff574f0485/node_modules/@wordpress/components/build-module/utils/hooks/use-update-effect.mjs
9918
- function useUpdateEffect(effect, deps) {
9919
- const mountedRef = (0, react.useRef)(false);
9920
- (0, react.useEffect)(() => {
9921
- if (mountedRef.current) return effect();
9922
- mountedRef.current = true;
9923
- }, deps);
9924
- (0, react.useEffect)(() => () => {
9925
- mountedRef.current = false;
9926
- }, []);
9927
- }
9928
- var use_update_effect_default = useUpdateEffect;
9929
- // ../../../node_modules/.pnpm/@wordpress+components@43.0.0_@date-fns+tz@1.5.0_@types+react-dom@19.3.0_@types+react@19_401cb4bad47bd1f7b56615ff574f0485/node_modules/@wordpress/components/build-module/context/context-system-provider.mjs
9930
- var import_es6 = /* @__PURE__ */ __toESM(require_es6(), 1);
9931
- var ComponentsContext = (0, react.createContext)({});
9932
- ComponentsContext.displayName = "ComponentsContext";
9933
- var useComponentsContext = () => (0, react.useContext)(ComponentsContext);
9934
- function useContextSystemBridge({ value }) {
9935
- const parentContext = useComponentsContext();
9936
- const valueRef = (0, react.useRef)(value);
9937
- use_update_effect_default(() => {
9938
- if ((0, import_es6.default)(valueRef.current, value) && valueRef.current !== value) warning(`Please memoize your context: ${JSON.stringify(value)}`);
9939
- }, [value]);
9940
- return (0, react.useMemo)(() => {
9941
- return (0, deepmerge.default)(parentContext ?? {}, value ?? {}, { isMergeableObject: isPlainObject });
9942
- }, [parentContext, value]);
9943
- }
9944
- var BaseContextSystemProvider = ({ children, value }) => {
9945
- const contextValue = useContextSystemBridge({ value });
9946
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ComponentsContext.Provider, {
9947
- value: contextValue,
9948
- children
9949
- });
9950
- };
9951
- (0, react.memo)(BaseContextSystemProvider);
9952
- // ../../../node_modules/.pnpm/@wordpress+components@43.0.0_@date-fns+tz@1.5.0_@types+react-dom@19.3.0_@types+react@19_401cb4bad47bd1f7b56615ff574f0485/node_modules/@wordpress/components/build-module/context/constants.mjs
9953
- var COMPONENT_NAMESPACE = "data-wp-component";
9954
- var CONNECTED_NAMESPACE = "data-wp-c16t";
9955
- var CONNECT_STATIC_NAMESPACE = "__contextSystemKey__";
9956
- // ../../../node_modules/.pnpm/memize@2.1.1/node_modules/memize/dist/index.js
9957
- /**
9958
- * Memize options object.
9959
- *
9960
- * @typedef MemizeOptions
9961
- *
9962
- * @property {number} [maxSize] Maximum size of the cache.
9963
- */
9964
- /**
9965
- * Internal cache entry.
9966
- *
9967
- * @typedef MemizeCacheNode
9968
- *
9969
- * @property {?MemizeCacheNode|undefined} [prev] Previous node.
9970
- * @property {?MemizeCacheNode|undefined} [next] Next node.
9971
- * @property {Array<*>} args Function arguments for cache
9972
- * entry.
9973
- * @property {*} val Function result.
9974
- */
9975
- /**
9976
- * Properties of the enhanced function for controlling cache.
9977
- *
9978
- * @typedef MemizeMemoizedFunction
9979
- *
9980
- * @property {()=>void} clear Clear the cache.
9981
- */
9982
- /**
9983
- * Accepts a function to be memoized, and returns a new memoized function, with
9984
- * optional options.
9985
- *
9986
- * @template {(...args: any[]) => any} F
9987
- *
9988
- * @param {F} fn Function to memoize.
9989
- * @param {MemizeOptions} [options] Options object.
9990
- *
9991
- * @return {((...args: Parameters<F>) => ReturnType<F>) & MemizeMemoizedFunction} Memoized function.
9992
- */
9993
- function memize(fn, options) {
9994
- var size = 0;
9995
- /** @type {?MemizeCacheNode|undefined} */
9996
- var head;
9997
- /** @type {?MemizeCacheNode|undefined} */
9998
- var tail;
9999
- options = options || {};
10000
- function memoized() {
10001
- var node = head, len = arguments.length, args, i;
10002
- searchCache: while (node) {
10003
- if (node.args.length !== arguments.length) {
10004
- node = node.next;
10005
- continue;
10006
- }
10007
- for (i = 0; i < len; i++) if (node.args[i] !== arguments[i]) {
10008
- node = node.next;
10009
- continue searchCache;
10010
- }
10011
- if (node !== head) {
10012
- if (node === tail) tail = node.prev;
10013
- /** @type {MemizeCacheNode} */ node.prev.next = node.next;
10014
- if (node.next) node.next.prev = node.prev;
10015
- node.next = head;
10016
- node.prev = null;
10017
- /** @type {MemizeCacheNode} */ head.prev = node;
10018
- head = node;
10019
- }
10020
- return node.val;
10021
- }
10022
- args = new Array(len);
10023
- for (i = 0; i < len; i++) args[i] = arguments[i];
10024
- node = {
10025
- args,
10026
- val: fn.apply(null, args)
10027
- };
10028
- if (head) {
10029
- head.prev = node;
10030
- node.next = head;
10031
- } else tail = node;
10032
- if (size === options.maxSize) {
10033
- tail = tail.prev;
10034
- /** @type {MemizeCacheNode} */ tail.next = null;
10035
- } else size++;
10036
- head = node;
10037
- return node.val;
10038
- }
10039
- memoized.clear = function() {
10040
- head = null;
10041
- tail = null;
10042
- size = 0;
10043
- };
10044
- return memoized;
10045
- }
10046
- // ../../../node_modules/.pnpm/@wordpress+components@43.0.0_@date-fns+tz@1.5.0_@types+react-dom@19.3.0_@types+react@19_401cb4bad47bd1f7b56615ff574f0485/node_modules/@wordpress/components/build-module/context/get-styled-class-name-from-key.mjs
10047
- function getStyledClassName(namespace) {
10048
- return `components-${namespace.replace(/([a-z0-9])([A-Z])/g, "$1-$2").replace(/([A-Z])([A-Z][a-z])/g, "$1-$2").replace(/[^A-Z0-9]+/gi, "-").replace(/^-|-$/g, "").toLowerCase()}`;
10049
- }
10050
- var getStyledClassNameFromKey = memize(getStyledClassName);
10051
- // ../../../node_modules/.pnpm/@wordpress+components@43.0.0_@date-fns+tz@1.5.0_@types+react-dom@19.3.0_@types+react@19_401cb4bad47bd1f7b56615ff574f0485/node_modules/@wordpress/components/build-module/context/context-connect.mjs
10052
- function contextConnect(Component, namespace) {
10053
- return _contextConnect(Component, namespace, { forwardsRef: true });
10054
- }
10055
- function _contextConnect(Component, namespace, options) {
10056
- const WrappedComponent = options?.forwardsRef ? (0, react.forwardRef)(Component) : Component;
10057
- if (typeof namespace === "undefined") warning("contextConnect: Please provide a namespace");
10058
- let mergedNamespace = WrappedComponent["__contextSystemKey__"] || [namespace];
10059
- if (Array.isArray(namespace)) mergedNamespace = [...mergedNamespace, ...namespace];
10060
- if (typeof namespace === "string") mergedNamespace = [...mergedNamespace, namespace];
10061
- return Object.assign(WrappedComponent, {
10062
- [CONNECT_STATIC_NAMESPACE]: [...new Set(mergedNamespace)],
10063
- displayName: namespace,
10064
- selector: `.${getStyledClassNameFromKey(namespace)}`
10065
- });
10066
- }
10067
- // ../../../node_modules/.pnpm/@wordpress+components@43.0.0_@date-fns+tz@1.5.0_@types+react-dom@19.3.0_@types+react@19_401cb4bad47bd1f7b56615ff574f0485/node_modules/@wordpress/components/build-module/context/utils.mjs
10068
- function getNamespace(componentName) {
10069
- return { [COMPONENT_NAMESPACE]: componentName };
10070
- }
10071
- function getConnectedNamespace() {
10072
- return { [CONNECTED_NAMESPACE]: true };
10073
- }
10074
- // ../../../node_modules/.pnpm/@wordpress+components@43.0.0_@date-fns+tz@1.5.0_@types+react-dom@19.3.0_@types+react@19_401cb4bad47bd1f7b56615ff574f0485/node_modules/@wordpress/components/build-module/context/use-context-system.mjs
10075
- function useContextSystem(props, namespace) {
10076
- const contextSystemProps = useComponentsContext();
10077
- if (typeof namespace === "undefined") warning("useContextSystem: Please provide a namespace");
10078
- const contextProps = contextSystemProps?.[namespace] || {};
10079
- const finalComponentProps = {
10080
- ...getConnectedNamespace(),
10081
- ...getNamespace(namespace)
10082
- };
10083
- const { _overrides, ...otherContextProps } = contextProps;
10084
- const overrideProps = _overrides;
10085
- const initialMergedProps = Object.entries(otherContextProps).length ? Object.assign({}, otherContextProps, props) : props;
10086
- const propsWithChildren = initialMergedProps;
10087
- const classes = (0, clsx.default)(getStyledClassNameFromKey(namespace), props.className);
10088
- const rendered = typeof propsWithChildren.renderChildren === "function" ? propsWithChildren.renderChildren(initialMergedProps) : propsWithChildren.children;
10089
- for (const key in initialMergedProps) finalComponentProps[key] = initialMergedProps[key];
10090
- for (const key in overrideProps) finalComponentProps[key] = overrideProps[key];
10091
- if (rendered !== void 0) finalComponentProps.children = rendered;
10092
- finalComponentProps.className = classes;
10093
- return finalComponentProps;
10094
- }
10095
- // ../../../node_modules/.pnpm/@wordpress+components@43.0.0_@date-fns+tz@1.5.0_@types+react-dom@19.3.0_@types+react@19_401cb4bad47bd1f7b56615ff574f0485/node_modules/@wordpress/components/build-module/visually-hidden/styles.mjs
10096
- var visuallyHidden = {
10097
- border: 0,
10098
- clip: "rect(1px, 1px, 1px, 1px)",
10099
- WebkitClipPath: "inset( 50% )",
10100
- clipPath: "inset( 50% )",
10101
- height: "1px",
10102
- margin: "-1px",
10103
- overflow: "hidden",
10104
- padding: 0,
10105
- position: "absolute",
10106
- width: "1px",
10107
- wordWrap: "normal",
10108
- wordBreak: "normal"
10109
- };
10110
- // ../../../node_modules/.pnpm/@wordpress+components@43.0.0_@date-fns+tz@1.5.0_@types+react-dom@19.3.0_@types+react@19_401cb4bad47bd1f7b56615ff574f0485/node_modules/@wordpress/components/build-module/utils/polymorphic-element.mjs
10111
- var customAttributeRegExp = /^(data|aria|x)-/i;
10112
- var eventHandlerRegExp = /^on[A-Z]/;
10113
- var svgElementNames = new Set(`animate animateMotion animateTransform circle clipPath defs desc ellipse
10114
- feBlend feColorMatrix feComponentTransfer feComposite feConvolveMatrix
10115
- feDiffuseLighting feDisplacementMap feDistantLight feDropShadow feFlood
10116
- feFuncA feFuncB feFuncG feFuncR feGaussianBlur feImage feMerge feMergeNode
10117
- feMorphology feOffset fePointLight feSpecularLighting feSpotLight feTile
10118
- feTurbulence filter foreignObject g image line linearGradient marker mask
10119
- metadata mpath path pattern polygon polyline radialGradient rect set stop svg
10120
- switch symbol text textPath tspan use view`.split(/\s+/));
10121
- var baseElementProps = new Set(`children dangerouslySetInnerHTML key autoFocus defaultValue defaultChecked
10122
- innerHTML suppressContentEditableWarning suppressHydrationWarning valueLink
10123
- abbr accept acceptCharset accessKey action allow allowUserMedia
10124
- allowPaymentRequest allowFullScreen allowTransparency alt async autoComplete
10125
- autoPlay capture cellPadding cellSpacing challenge charSet checked cite classID
10126
- className cols colSpan content contentEditable contextMenu controls controlsList
10127
- coords crossOrigin data dateTime decoding default defer dir disabled
10128
- disablePictureInPicture disableRemotePlayback download draggable encType
10129
- enterKeyHint fetchpriority fetchPriority form formAction formEncType formMethod
10130
- formNoValidate formTarget frameBorder headers height hidden high href hrefLang
10131
- htmlFor httpEquiv id inputMode integrity is keyParams keyType kind label lang
10132
- list loading loop low marginHeight marginWidth max maxLength media mediaGroup
10133
- method min minLength multiple muted name nonce noValidate open optimum pattern
10134
- placeholder playsInline popover popoverTarget popoverTargetAction poster
10135
- preload profile radioGroup readOnly referrerPolicy rel required reversed role
10136
- rows rowSpan sandbox scope scoped scrolling seamless selected shape size sizes
10137
- slot span spellCheck src srcDoc srcLang srcSet start step style summary
10138
- tabIndex target title translate type useMap value width wmode wrap about
10139
- datatype inlist prefix property resource typeof vocab autoCapitalize
10140
- autoCorrect autoSave color incremental fallback inert itemProp itemScope
10141
- itemType itemID itemRef on option results security unselectable`.split(/\s+/));
10142
- var svgElementProps = new Set(`accentHeight accumulate additive alignmentBaseline allowReorder alphabetic
10143
- amplitude arabicForm ascent attributeName attributeType autoReverse azimuth
10144
- baseFrequency baselineShift baseProfile bbox begin bias by calcMode capHeight
10145
- clip clipPathUnits clipPath clipRule colorInterpolation
10146
- colorInterpolationFilters colorProfile colorRendering contentScriptType
10147
- contentStyleType cursor cx cy d decelerate descent diffuseConstant direction
10148
- display divisor dominantBaseline dur dx dy edgeMode elevation enableBackground
10149
- end exponent externalResourcesRequired fill fillOpacity fillRule filter
10150
- filterRes filterUnits floodColor floodOpacity focusable fontFamily fontSize
10151
- fontSizeAdjust fontStretch fontStyle fontVariant fontWeight format from fr fx
10152
- fy g1 g2 glyphName glyphOrientationHorizontal glyphOrientationVertical
10153
- glyphRef gradientTransform gradientUnits hanging horizAdvX horizOriginX
10154
- ideographic imageRendering in in2 intercept k k1 k2 k3 k4 kernelMatrix
10155
- kernelUnitLength kerning keyPoints keySplines keyTimes lengthAdjust
10156
- letterSpacing lightingColor limitingConeAngle local markerEnd markerMid
10157
- markerStart markerHeight markerUnits markerWidth mask maskContentUnits
10158
- maskUnits mathematical mode numOctaves offset opacity operator order orient
10159
- orientation origin overflow overlinePosition overlineThickness panose1
10160
- paintOrder pathLength patternContentUnits patternTransform patternUnits
10161
- pointerEvents points pointsAtX pointsAtY pointsAtZ preserveAlpha
10162
- preserveAspectRatio primitiveUnits r radius refX refY renderingIntent
10163
- repeatCount repeatDur requiredExtensions requiredFeatures restart result rotate
10164
- rx ry scale seed shapeRendering slope spacing specularConstant
10165
- specularExponent speed spreadMethod startOffset stdDeviation stemh stemv
10166
- stitchTiles stopColor stopOpacity strikethroughPosition strikethroughThickness
10167
- string stroke strokeDasharray strokeDashoffset strokeLinecap strokeLinejoin
10168
- strokeMiterlimit strokeOpacity strokeWidth surfaceScale systemLanguage
10169
- tableValues targetX targetY textAnchor textDecoration textRendering textLength
10170
- to transform u1 u2 underlinePosition underlineThickness unicode unicodeBidi
10171
- unicodeRange unitsPerEm vAlphabetic vHanging vIdeographic vMathematical values
10172
- vectorEffect version vertAdvY vertOriginX vertOriginY viewBox viewTarget
10173
- visibility widths wordSpacing writingMode x xHeight x1 x2 xChannelSelector
10174
- xlinkActuate xlinkArcrole xlinkHref xlinkRole xlinkShow xlinkTitle xlinkType
10175
- xmlBase xmlns xmlnsXlink xmlLang xmlSpace y y1 y2 yChannelSelector z
10176
- zoomAndPan`.split(/\s+/));
10177
- var compatElementProps = /* @__PURE__ */ new Set([
10178
- "autofocus",
10179
- "class",
10180
- "for"
10181
- ]);
10182
- function isValidIntrinsicElementProp(prop, element) {
10183
- if (customAttributeRegExp.test(prop) || eventHandlerRegExp.test(prop)) return true;
10184
- if (baseElementProps.has(prop) || compatElementProps.has(prop)) return true;
10185
- return svgElementNames.has(element) && svgElementProps.has(prop);
10186
- }
10187
- function filterIntrinsicElementProps(props, element) {
10188
- return Object.fromEntries(Object.entries(props).filter(([prop]) => isValidIntrinsicElementProp(prop, element)));
10189
- }
10190
- function UnforwardedPolymorphicElement({ as, ...props }, ref) {
10191
- const Element = as || "div";
10192
- const forwardedProps = typeof Element === "string" ? filterIntrinsicElementProps(props, Element) : props;
10193
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Element, {
10194
- ref,
10195
- ...forwardedProps
10196
- });
10197
- }
10198
- var PolymorphicElement = (0, react.forwardRef)(UnforwardedPolymorphicElement);
10199
- // ../../../node_modules/.pnpm/@wordpress+components@43.0.0_@date-fns+tz@1.5.0_@types+react-dom@19.3.0_@types+react@19_401cb4bad47bd1f7b56615ff574f0485/node_modules/@wordpress/components/build-module/view/component.mjs
10200
- function UnforwardedView({ css, ...restProps }, ref) {
10201
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(PolymorphicElement, {
10202
- ref,
10203
- ...restProps
10204
- });
10205
- }
10206
- var component_default$2 = Object.assign((0, react.forwardRef)(UnforwardedView), { selector: ".components-view" });
10207
- // ../../../node_modules/.pnpm/@wordpress+components@43.0.0_@date-fns+tz@1.5.0_@types+react-dom@19.3.0_@types+react@19_401cb4bad47bd1f7b56615ff574f0485/node_modules/@wordpress/components/build-module/visually-hidden/component.mjs
10208
- function UnconnectedVisuallyHidden(props, forwardedRef) {
10209
- const { style: styleProp, ...contextProps } = useContextSystem(props, "VisuallyHidden");
10210
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(component_default$2, {
10211
- ref: forwardedRef,
10212
- ...contextProps,
10213
- "data-visually-hidden": "",
10214
- style: {
10215
- ...visuallyHidden,
10216
- ...styleProp || {}
10217
- }
10218
- });
10219
- }
10220
- var component_default$1 = contextConnect(UnconnectedVisuallyHidden, "VisuallyHidden");
10221
- // ../../../node_modules/.pnpm/@wordpress+components@43.0.0_@date-fns+tz@1.5.0_@types+react-dom@19.3.0_@types+react@19_401cb4bad47bd1f7b56615ff574f0485/node_modules/@wordpress/components/build-module/utils/use-responsive-value.mjs
10222
- var breakpoints = [
10223
- "40em",
10224
- "52em",
10225
- "64em"
10226
- ];
10227
- var useBreakpointIndex = (options = {}) => {
10228
- const { defaultIndex = 0, enabled = true } = options;
10229
- if (typeof defaultIndex !== "number") throw new TypeError(`Default breakpoint index should be a number. Got: ${defaultIndex}, ${typeof defaultIndex}`);
10230
- else if (defaultIndex < 0 || defaultIndex > breakpoints.length - 1) throw new RangeError(`Default breakpoint index out of range. Theme has ${breakpoints.length} breakpoints, got index ${defaultIndex}`);
10231
- const [value, setValue] = (0, react.useState)(defaultIndex);
10232
- (0, react.useEffect)(() => {
10233
- if (!enabled) return;
10234
- const getIndex = () => breakpoints.filter((bp) => {
10235
- return typeof window !== "undefined" ? window.matchMedia(`screen and (min-width: ${bp})`).matches : false;
10236
- }).length;
10237
- const onResize = () => {
10238
- const newValue = getIndex();
10239
- if (value !== newValue) setValue(newValue);
10240
- };
10241
- onResize();
10242
- if (typeof window !== "undefined") window.addEventListener("resize", onResize);
10243
- return () => {
10244
- if (typeof window !== "undefined") window.removeEventListener("resize", onResize);
10245
- };
10246
- }, [value, enabled]);
10247
- return value;
10248
- };
10249
- function useResponsiveValue(values, options = {}) {
10250
- const isResponsive = Array.isArray(values) && values.length > 1;
10251
- const index = useBreakpointIndex({
10252
- ...options,
10253
- enabled: isResponsive
10254
- });
10255
- if (!Array.isArray(values) && typeof values !== "function") return values;
10256
- const array = values || [];
10257
- return array[index >= array.length ? array.length - 1 : index];
10258
- }
10259
- // ../../../node_modules/.pnpm/@wordpress+components@43.0.0_@date-fns+tz@1.5.0_@types+react-dom@19.3.0_@types+react@19_401cb4bad47bd1f7b56615ff574f0485/node_modules/@wordpress/components/build-module/grid/utils.mjs
10260
- var ALIGNMENTS = {
10261
- bottom: {
10262
- alignItems: "flex-end",
10263
- justifyContent: "center"
10264
- },
10265
- bottomLeft: {
10266
- alignItems: "flex-end",
10267
- justifyContent: "flex-start"
10268
- },
10269
- bottomRight: {
10270
- alignItems: "flex-end",
10271
- justifyContent: "flex-end"
10272
- },
10273
- center: {
10274
- alignItems: "center",
10275
- justifyContent: "center"
10276
- },
10277
- spaced: {
10278
- alignItems: "center",
10279
- justifyContent: "space-between"
10280
- },
10281
- left: {
10282
- alignItems: "center",
10283
- justifyContent: "flex-start"
10284
- },
10285
- right: {
10286
- alignItems: "center",
10287
- justifyContent: "flex-end"
10288
- },
10289
- stretch: { alignItems: "stretch" },
10290
- top: {
10291
- alignItems: "flex-start",
10292
- justifyContent: "center"
10293
- },
10294
- topLeft: {
10295
- alignItems: "flex-start",
10296
- justifyContent: "flex-start"
10297
- },
10298
- topRight: {
10299
- alignItems: "flex-start",
10300
- justifyContent: "flex-end"
10301
- }
10302
- };
10303
- function getAlignmentProps(alignment) {
10304
- return alignment ? ALIGNMENTS[alignment] ?? {} : {};
10305
- }
10306
- // ../../../node_modules/.pnpm/@wordpress+components@43.0.0_@date-fns+tz@1.5.0_@types+react-dom@19.3.0_@types+react@19_401cb4bad47bd1f7b56615ff574f0485/node_modules/@wordpress/components/build-module/grid/hook.mjs
10307
- var STYLE_HASH_ATTRIBUTE = "data-wp-hash";
10308
- function getRuntime() {
10309
- const globalScope = globalThis;
10310
- if (globalScope.__wpStyleRuntime) return globalScope.__wpStyleRuntime;
10311
- globalScope.__wpStyleRuntime = {
10312
- documents: /* @__PURE__ */ new Map(),
10313
- styles: /* @__PURE__ */ new Map(),
10314
- injectedStyles: /* @__PURE__ */ new WeakMap()
10315
- };
10316
- if (typeof document !== "undefined") registerDocument(document);
10317
- return globalScope.__wpStyleRuntime;
10318
- }
10319
- function documentContainsStyleHash(targetDocument, hash) {
10320
- if (!targetDocument.head) return false;
10321
- for (const style of targetDocument.head.querySelectorAll(`style[${STYLE_HASH_ATTRIBUTE}]`)) if (style.getAttribute(STYLE_HASH_ATTRIBUTE) === hash) return true;
10322
- return false;
10323
- }
10324
- function injectStyle(targetDocument, hash, css) {
10325
- if (!targetDocument.head) return;
10326
- const runtime = getRuntime();
10327
- let injectedStyles = runtime.injectedStyles.get(targetDocument);
10328
- if (!injectedStyles) {
10329
- injectedStyles = /* @__PURE__ */ new Set();
10330
- runtime.injectedStyles.set(targetDocument, injectedStyles);
10331
- }
10332
- if (injectedStyles.has(hash)) return;
10333
- if (documentContainsStyleHash(targetDocument, hash)) {
10334
- injectedStyles.add(hash);
10335
- return;
10336
- }
10337
- const style = targetDocument.createElement("style");
10338
- style.setAttribute(STYLE_HASH_ATTRIBUTE, hash);
10339
- style.appendChild(targetDocument.createTextNode(css));
10340
- targetDocument.head.appendChild(style);
10341
- injectedStyles.add(hash);
10342
- }
10343
- function registerDocument(targetDocument) {
10344
- const runtime = getRuntime();
10345
- runtime.documents.set(targetDocument, (runtime.documents.get(targetDocument) ?? 0) + 1);
10346
- for (const [hash, css] of runtime.styles) injectStyle(targetDocument, hash, css);
10347
- return () => {
10348
- const count = runtime.documents.get(targetDocument);
10349
- if (count === void 0) return;
10350
- if (count <= 1) {
10351
- runtime.documents.delete(targetDocument);
10352
- return;
10353
- }
10354
- runtime.documents.set(targetDocument, count - 1);
10355
- };
10356
- }
10357
- function registerStyle(hash, css) {
10358
- const runtime = getRuntime();
10359
- runtime.styles.set(hash, css);
10360
- for (const targetDocument of runtime.documents.keys()) injectStyle(targetDocument, hash, css);
10361
- }
10362
- if (typeof process === "undefined" || process.env.NODE_ENV !== "test") registerStyle("79bac25858", "._631b7063b4047c89__grid{--wp-components-grid-align:initial;--wp-components-grid-justify:initial;--wp-components-grid-gap:initial;--wp-components-grid-template-columns:initial;--wp-components-grid-template-rows:initial;--wp-components-grid-row-gap:initial;--wp-components-grid-column-gap:initial;display:grid}._631b7063b4047c89__grid:not(:where(._51fa5e5688d538e7__row-gap-inherit,._3940112538797bb2__row-gap-initial,._9dc0e80dad95eb11__row-gap-unset,._964ec4132d3d0776__row-gap-revert,._9219888d7c4749d5__row-gap-revert-layer)){row-gap:var(--wp-components-grid-row-gap,calc(4px*var(--wp-components-grid-gap)))}._631b7063b4047c89__grid:not(:where(._149fd947497e8690__column-gap-inherit,.a018e74b0f04c517__column-gap-initial,.b1e45f9587eb70e5__column-gap-unset,._4da312511f64af94__column-gap-revert,.b51ead67217c210a__column-gap-revert-layer)){column-gap:var(--wp-components-grid-column-gap,calc(4px*var(--wp-components-grid-gap)))}._4cae76607d36422b__has-align:not(:where(._2c693b642b24e0d9__align-inherit,.fd4c5676ad7e83d4__align-initial,.c4c0cde44ab0ed21__align-unset,._8c23efb61db2f04e__align-revert,.c3adc4c41efa56d1__align-revert-layer)){align-items:var(--wp-components-grid-align)}._9bcd99517d001b4b__has-justify:not(:where(.a72d35ee0eda5e6b__justify-inherit,.d386403fd02ebc45__justify-initial,._7d60510a69e8ddf9__justify-unset,._857dfb6521d0cae3__justify-revert,._1537fff8402f1ca1__justify-revert-layer)){justify-content:var(--wp-components-grid-justify)}._983f7df07cd35a72__has-template-columns:not(:where(.df2216db1a717825__template-columns-inherit,._9016934ed273a0b8__template-columns-initial,._74966333f352d829__template-columns-unset,.b3ce45d005011688__template-columns-revert,._9ff0250b9bed5764__template-columns-revert-layer)){grid-template-columns:var(--wp-components-grid-template-columns)}._7e0fa0c081c20f6e__has-template-rows:not(:where(._10cfd24f62672d27__template-rows-inherit,.da1333be6b2af8c3__template-rows-initial,._919938d55c0cf234__template-rows-unset,.db40efe5796b7ffb__template-rows-revert,._1080cc5b99823c58__template-rows-revert-layer)){grid-template-rows:var(--wp-components-grid-template-rows)}.f4729d54fca65af1__is-inline{display:inline-grid;vertical-align:middle}._2c693b642b24e0d9__align-inherit{align-items:inherit}.fd4c5676ad7e83d4__align-initial{align-items:normal}.c4c0cde44ab0ed21__align-unset{align-items:unset}._8c23efb61db2f04e__align-revert{align-items:revert}.c3adc4c41efa56d1__align-revert-layer{align-items:revert-layer}.a72d35ee0eda5e6b__justify-inherit{justify-content:inherit}.d386403fd02ebc45__justify-initial{justify-content:normal}._7d60510a69e8ddf9__justify-unset{justify-content:unset}._857dfb6521d0cae3__justify-revert{justify-content:revert}._1537fff8402f1ca1__justify-revert-layer{justify-content:revert-layer}.df2216db1a717825__template-columns-inherit{grid-template-columns:inherit}._9016934ed273a0b8__template-columns-initial{grid-template-columns:none}._74966333f352d829__template-columns-unset{grid-template-columns:unset}.b3ce45d005011688__template-columns-revert{grid-template-columns:revert}._9ff0250b9bed5764__template-columns-revert-layer{grid-template-columns:revert-layer}._10cfd24f62672d27__template-rows-inherit{grid-template-rows:inherit}.da1333be6b2af8c3__template-rows-initial{grid-template-rows:none}._919938d55c0cf234__template-rows-unset{grid-template-rows:unset}.db40efe5796b7ffb__template-rows-revert{grid-template-rows:revert}._1080cc5b99823c58__template-rows-revert-layer{grid-template-rows:revert-layer}._51fa5e5688d538e7__row-gap-inherit{row-gap:inherit}._3940112538797bb2__row-gap-initial{row-gap:normal}._9dc0e80dad95eb11__row-gap-unset{row-gap:unset}._964ec4132d3d0776__row-gap-revert{row-gap:revert}._9219888d7c4749d5__row-gap-revert-layer{row-gap:revert-layer}._149fd947497e8690__column-gap-inherit{column-gap:inherit}.a018e74b0f04c517__column-gap-initial{column-gap:normal}.b1e45f9587eb70e5__column-gap-unset{column-gap:unset}._4da312511f64af94__column-gap-revert{column-gap:revert}.b51ead67217c210a__column-gap-revert-layer{column-gap:revert-layer}");
10363
- var style_module_default = {
10364
- "grid": "_631b7063b4047c89__grid",
10365
- "row-gap-inherit": "_51fa5e5688d538e7__row-gap-inherit",
10366
- "row-gap-initial": "_3940112538797bb2__row-gap-initial",
10367
- "row-gap-unset": "_9dc0e80dad95eb11__row-gap-unset",
10368
- "row-gap-revert": "_964ec4132d3d0776__row-gap-revert",
10369
- "row-gap-revert-layer": "_9219888d7c4749d5__row-gap-revert-layer",
10370
- "column-gap-inherit": "_149fd947497e8690__column-gap-inherit",
10371
- "column-gap-initial": "a018e74b0f04c517__column-gap-initial",
10372
- "column-gap-unset": "b1e45f9587eb70e5__column-gap-unset",
10373
- "column-gap-revert": "_4da312511f64af94__column-gap-revert",
10374
- "column-gap-revert-layer": "b51ead67217c210a__column-gap-revert-layer",
10375
- "has-align": "_4cae76607d36422b__has-align",
10376
- "align-inherit": "_2c693b642b24e0d9__align-inherit",
10377
- "align-initial": "fd4c5676ad7e83d4__align-initial",
10378
- "align-unset": "c4c0cde44ab0ed21__align-unset",
10379
- "align-revert": "_8c23efb61db2f04e__align-revert",
10380
- "align-revert-layer": "c3adc4c41efa56d1__align-revert-layer",
10381
- "has-justify": "_9bcd99517d001b4b__has-justify",
10382
- "justify-inherit": "a72d35ee0eda5e6b__justify-inherit",
10383
- "justify-initial": "d386403fd02ebc45__justify-initial",
10384
- "justify-unset": "_7d60510a69e8ddf9__justify-unset",
10385
- "justify-revert": "_857dfb6521d0cae3__justify-revert",
10386
- "justify-revert-layer": "_1537fff8402f1ca1__justify-revert-layer",
10387
- "has-template-columns": "_983f7df07cd35a72__has-template-columns",
10388
- "template-columns-inherit": "df2216db1a717825__template-columns-inherit",
10389
- "template-columns-initial": "_9016934ed273a0b8__template-columns-initial",
10390
- "template-columns-unset": "_74966333f352d829__template-columns-unset",
10391
- "template-columns-revert": "b3ce45d005011688__template-columns-revert",
10392
- "template-columns-revert-layer": "_9ff0250b9bed5764__template-columns-revert-layer",
10393
- "has-template-rows": "_7e0fa0c081c20f6e__has-template-rows",
10394
- "template-rows-inherit": "_10cfd24f62672d27__template-rows-inherit",
10395
- "template-rows-initial": "da1333be6b2af8c3__template-rows-initial",
10396
- "template-rows-unset": "_919938d55c0cf234__template-rows-unset",
10397
- "template-rows-revert": "db40efe5796b7ffb__template-rows-revert",
10398
- "template-rows-revert-layer": "_1080cc5b99823c58__template-rows-revert-layer",
10399
- "is-inline": "f4729d54fca65af1__is-inline"
10400
- };
10401
- var CSS_WIDE_KEYWORDS = /* @__PURE__ */ new Set([
10402
- "inherit",
10403
- "initial",
10404
- "unset",
10405
- "revert",
10406
- "revert-layer"
10407
- ]);
10408
- function toCSSValue(value) {
10409
- return typeof value === "number" ? `${value}px` : value?.trim() || void 0;
10410
- }
10411
- function useGrid(props) {
10412
- const { align, alignment, className, columnGap, columns = 2, gap = 3, isInline = false, justify, rowGap, rows, style, templateColumns, templateRows, ...otherProps } = useContextSystem(props, "Grid");
10413
- const column = useResponsiveValue(Array.isArray(columns) ? columns : [columns]);
10414
- const row = useResponsiveValue(Array.isArray(rows) ? rows : [rows]);
10415
- const gridTemplateColumns = templateColumns || !!column && `repeat( ${column}, 1fr )`;
10416
- const gridTemplateRows = templateRows || !!row && `repeat( ${row}, 1fr )`;
10417
- const alignmentProps = getAlignmentProps(alignment);
10418
- const values = {
10419
- align: alignmentProps.alignItems ?? align,
10420
- justify: alignmentProps.justifyContent ?? justify,
10421
- "template-columns": gridTemplateColumns || void 0,
10422
- "template-rows": gridTemplateRows || void 0,
10423
- "row-gap": rowGap,
10424
- "column-gap": columnGap
10425
- };
10426
- return {
10427
- ...otherProps,
10428
- className: (0, clsx.default)(style_module_default.grid, {
10429
- [style_module_default["is-inline"]]: isInline,
10430
- [style_module_default["has-align"]]: !!values.align?.trim(),
10431
- [style_module_default["has-justify"]]: !!values.justify?.trim(),
10432
- [style_module_default["has-template-columns"]]: !!toCSSValue(values["template-columns"]),
10433
- [style_module_default["has-template-rows"]]: !!toCSSValue(values["template-rows"])
10434
- }, Object.entries(values).map(([property, value]) => {
10435
- const keyword = typeof value === "string" ? value.trim().toLowerCase() : "";
10436
- return CSS_WIDE_KEYWORDS.has(keyword) && style_module_default[`${property}-${keyword}`];
10437
- }), className),
10438
- style: {
10439
- "--wp-components-grid-align": values.align,
10440
- "--wp-components-grid-justify": values.justify,
10441
- "--wp-components-grid-gap": gap,
10442
- "--wp-components-grid-template-columns": toCSSValue(values["template-columns"]),
10443
- "--wp-components-grid-template-rows": toCSSValue(values["template-rows"]),
10444
- "--wp-components-grid-row-gap": toCSSValue(rowGap),
10445
- "--wp-components-grid-column-gap": toCSSValue(columnGap),
10446
- ...style
10447
- }
10448
- };
10449
- }
10450
- // ../../../node_modules/.pnpm/@wordpress+components@43.0.0_@date-fns+tz@1.5.0_@types+react-dom@19.3.0_@types+react@19_401cb4bad47bd1f7b56615ff574f0485/node_modules/@wordpress/components/build-module/grid/component.mjs
10451
- function UnconnectedGrid(props, forwardedRef) {
10452
- const gridProps = useGrid(props);
10453
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(component_default$2, {
10454
- ...gridProps,
10455
- ref: forwardedRef
10456
- });
10457
- }
10458
- var component_default = contextConnect(UnconnectedGrid, "Grid");
10459
10224
  // src/charts/leaderboard-chart/hooks/use-fitted-row-count.ts
10460
10225
  /**
10461
10226
  * Fractional layout rounding can put a row's bottom a hair past the container's
@@ -10602,6 +10367,8 @@ var leaderboard_chart_module_default = {
10602
10367
  "deltaValue--up": "a8ccharts-GovfoW-deltaValue--up",
10603
10368
  "emptyState": "a8ccharts-GovfoW-emptyState",
10604
10369
  "fitEmptyState": "a8ccharts-GovfoW-fitEmptyState",
10370
+ "grid": "a8ccharts-GovfoW-grid",
10371
+ "grid--comparison": "a8ccharts-GovfoW-grid--comparison",
10605
10372
  "interactiveRow": "a8ccharts-GovfoW-interactiveRow",
10606
10373
  "is-overlay": "a8ccharts-GovfoW-is-overlay",
10607
10374
  "label": "a8ccharts-GovfoW-label",
@@ -10655,8 +10422,6 @@ function resolveLeaderboardEntries(data, { includePrevious, clampNegative = fals
10655
10422
  });
10656
10423
  }
10657
10424
  // src/charts/leaderboard-chart/leaderboard-chart.tsx
10658
- const ROW_GAP = "var(--a8c-charts-dimension-leaderboard-row-gap, 12px)";
10659
- const COLUMN_GAP = "var(--a8c-charts-dimension-leaderboard-column-gap, 4px)";
10660
10425
  /** Indexed by `Math.sign( delta ) + 1`, so [negative, neutral, positive]. */
10661
10426
  const DELTA_TREND_CLASS = [
10662
10427
  "deltaValue--down",
@@ -10710,8 +10475,9 @@ function forwardCellClickToRowButton(event) {
10710
10475
  if (event.target.closest("a, button")) return;
10711
10476
  event.currentTarget.querySelector(":scope > button")?.click();
10712
10477
  }
10713
- const BarLabel = ({ label }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: typeof label === "string" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_ui.Text, {
10478
+ const BarLabel = ({ label, isInteractiveRow }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: typeof label === "string" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_ui.Text, {
10714
10479
  className: leaderboard_chart_module_default.label,
10480
+ title: isInteractiveRow ? label : void 0,
10715
10481
  children: label
10716
10482
  }) : label });
10717
10483
  const Bar = ({ share, color, animation, divergingScale }) => {
@@ -10750,7 +10516,10 @@ const BarWithLabel = ({ entry, withComparison, withOverlayLabel, primaryColor, s
10750
10516
  })] });
10751
10517
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
10752
10518
  className: (0, clsx.default)(leaderboard_chart_module_default.barWithLabelContainer, { [leaderboard_chart_module_default["is-overlay"]]: withOverlayLabel }),
10753
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(BarLabel, { label: entry.label }), bars]
10519
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(BarLabel, {
10520
+ label: entry.label,
10521
+ isInteractiveRow: Boolean(entry.onClick)
10522
+ }), bars]
10754
10523
  });
10755
10524
  };
10756
10525
  /**
@@ -10876,7 +10645,7 @@ const LeaderboardChartInternal = ({ data, chartId: providedChartId, width: propW
10876
10645
  const { contentRef, fittedCount, isMeasurable } = useFittedRowCount(fitRows && !allSeriesHidden, data?.length ?? 0, data);
10877
10646
  const shouldFitRows = fitRows && isMeasurable;
10878
10647
  const showComparisonColumn = withComparison && isComparisonVisible;
10879
- const templateColumns = showComparisonColumn && isPrimaryVisible ? "minmax(0, 1fr) auto auto" : "minmax(0, 1fr) auto";
10648
+ const hasDeltaColumn = showComparisonColumn && isPrimaryVisible;
10880
10649
  if (!data || data.length === 0) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ChartInstanceContext.Provider, {
10881
10650
  value: { chartId },
10882
10651
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ChartLayout, {
@@ -10938,13 +10707,11 @@ const LeaderboardChartInternal = ({ data, chartId: providedChartId, width: propW
10938
10707
  }), allSeriesHidden ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
10939
10708
  className: leaderboard_chart_module_default.emptyState,
10940
10709
  children: getAllHiddenMessage(legendInteractive, "series")
10941
- }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(component_default, {
10710
+ }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
10942
10711
  role: "list",
10943
10712
  "aria-label": ariaLabel ?? (0, _wordpress_i18n.__)("Leaderboard chart", "jetpack-charts"),
10944
- templateColumns,
10945
- rowGap: ROW_GAP,
10946
- columnGap: COLUMN_GAP,
10947
10713
  "data-leaderboard-grid": true,
10714
+ className: (0, clsx.default)(leaderboard_chart_module_default.grid, { [leaderboard_chart_module_default["grid--comparison"]]: hasDeltaColumn }),
10948
10715
  children: resolvedData.map((entry, rowIndex) => {
10949
10716
  const rowStyle = shouldFitRows && rowIndex >= fittedCount ? { visibility: "hidden" } : void 0;
10950
10717
  const hasPreviousPeriodValue = hasPreviousValue(entry);
@@ -10979,8 +10746,8 @@ const LeaderboardChartInternal = ({ data, chartId: providedChartId, width: propW
10979
10746
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
10980
10747
  "aria-hidden": "true",
10981
10748
  children: "—"
10982
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(component_default$1, {
10983
- as: "span",
10749
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_ui.VisuallyHidden, {
10750
+ render: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {}),
10984
10751
  children: hasPreviousPeriodValue ? (0, _wordpress_i18n.__)("Percentage change unavailable", "jetpack-charts") : (0, _wordpress_i18n.__)("No comparison data", "jetpack-charts")
10985
10752
  })]
10986
10753
  })