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