@automattic/charts 3.1.0 → 3.1.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.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [3.1.1] - 2026-08-26
9
+ ### Fixed
10
+ - LineChart, AreaChart, BarChart: Keep the derived date tick labels when a consumer passes an undefined tickFormat. [#51531]
11
+
8
12
  ## [3.1.0] - 2026-08-25
9
13
  ### Added
10
14
  - Add `defaultHiddenSeries` to seed a series hidden on load, plus absolute visibility setters. Keep the keyboard tooltip open when the chart re-renders under it. [#51458]
@@ -1003,6 +1007,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1003
1007
  - Fixed lints following ESLint rule changes for TS [#40584]
1004
1008
  - Fixing a bug in Chart storybook data. [#40640]
1005
1009
 
1010
+ [3.1.1]: https://github.com/Automattic/charts/compare/v3.1.0...v3.1.1
1006
1011
  [3.1.0]: https://github.com/Automattic/charts/compare/v3.0.0...v3.1.0
1007
1012
  [3.0.0]: https://github.com/Automattic/charts/compare/v2.0.1...v3.0.0
1008
1013
  [2.0.1]: https://github.com/Automattic/charts/compare/v2.0.0...v2.0.1
package/dist/index.cjs CHANGED
@@ -3493,8 +3493,8 @@ const LineChartInternal = (0, react.forwardRef)(({ data, chartId: providedChartI
3493
3493
  totalPoints: dataSorted[0]?.data.length || 0
3494
3494
  });
3495
3495
  const chartOptions = (0, react.useMemo)(() => {
3496
- const { tickResolution, ...xAxisOptions } = options?.axis?.x ?? {};
3497
- const formatter = xAxisOptions.tickFormat || getFormatter(dataSorted, tickResolution);
3496
+ const { tickResolution, tickFormat, ...xAxisOptions } = options?.axis?.x ?? {};
3497
+ const formatter = tickFormat || getFormatter(dataSorted, tickResolution);
3498
3498
  return {
3499
3499
  axis: {
3500
3500
  x: {
@@ -3960,8 +3960,8 @@ const AreaChartInternal = (0, react.forwardRef)(({ data, chartId: providedChartI
3960
3960
  rescaleYOnVisibility
3961
3961
  ]);
3962
3962
  const chartOptions = (0, react.useMemo)(() => {
3963
- const { tickResolution, ...xAxisOptions } = options?.axis?.x ?? {};
3964
- const formatter = xAxisOptions.tickFormat || getFormatter(dataSorted, tickResolution);
3963
+ const { tickResolution, tickFormat, ...xAxisOptions } = options?.axis?.x ?? {};
3964
+ const formatter = tickFormat || getFormatter(dataSorted, tickResolution);
3965
3965
  return {
3966
3966
  axis: {
3967
3967
  x: {
@@ -4430,11 +4430,13 @@ const getGroupPadding = (scale) => {
4430
4430
  function useBarChartOptions(data, horizontal, options = {}, isSeriesRendered = ALL_RENDERED) {
4431
4431
  const stableOptions = useDeepMemo(options);
4432
4432
  const axisConfig = (0, react.useMemo)(() => {
4433
- const { labelOverflow: xLabelOverflow, tickResolution: xTickResolution, ...xAxisOptions } = stableOptions.axis?.x || {};
4434
- const { labelOverflow: yLabelOverflow, tickResolution: yTickResolution, ...yAxisOptions } = stableOptions.axis?.y || {};
4433
+ const { labelOverflow: xLabelOverflow, tickResolution: xTickResolution, tickFormat: xTickFormat, ...xAxisOptions } = stableOptions.axis?.x || {};
4434
+ const { labelOverflow: yLabelOverflow, tickResolution: yTickResolution, tickFormat: yTickFormat, ...yAxisOptions } = stableOptions.axis?.y || {};
4435
4435
  return {
4436
4436
  xLabelOverflow,
4437
4437
  yLabelOverflow,
4438
+ xTickFormat,
4439
+ yTickFormat,
4438
4440
  xAxisOptions,
4439
4441
  yAxisOptions,
4440
4442
  tickResolution: horizontal ? yTickResolution : xTickResolution
@@ -4494,7 +4496,7 @@ function useBarChartOptions(data, horizontal, options = {}, isSeriesRendered = A
4494
4496
  isSeriesRendered
4495
4497
  ]);
4496
4498
  return (0, react.useMemo)(() => {
4497
- const { xTickFormat, yTickFormat, tooltipLabelFormatter: defaultTooltipLabelFormatter, xAccessor, yAccessor, gridVisibility, xScale: baseXScale, yScale: baseYScale } = defaultOptions[horizontal ? "horizontal" : "vertical"];
4499
+ const { xTickFormat: defaultXTickFormat, yTickFormat: defaultYTickFormat, tooltipLabelFormatter: defaultTooltipLabelFormatter, xAccessor, yAccessor, gridVisibility, xScale: baseXScale, yScale: baseYScale } = defaultOptions[horizontal ? "horizontal" : "vertical"];
4498
4500
  let valueScaleDomainOverride = {};
4499
4501
  if (data.some((s) => s.options?.type === "comparison")) {
4500
4502
  if (!(!horizontal ? stableOptions.yScale?.domain : stableOptions.xScale?.domain)) {
@@ -4519,11 +4521,11 @@ function useBarChartOptions(data, horizontal, options = {}, isSeriesRendered = A
4519
4521
  ...stableOptions.yScale || {},
4520
4522
  ...!horizontal ? valueScaleDomainOverride : {}
4521
4523
  };
4522
- const { xLabelOverflow, yLabelOverflow, xAxisOptions, yAxisOptions } = axisConfig;
4523
- const providedToolTipLabelFormatter = horizontal ? yAxisOptions.tickFormat : xAxisOptions.tickFormat;
4524
+ const { xLabelOverflow, yLabelOverflow, xTickFormat, yTickFormat, xAxisOptions, yAxisOptions } = axisConfig;
4525
+ const dateAxisTickFormat = horizontal ? yTickFormat : xTickFormat;
4524
4526
  const { timeAxis } = defaultOptions;
4525
4527
  const dateAxisOptions = horizontal ? yAxisOptions : xAxisOptions;
4526
- const bandTickValues = timeAxis && !dateAxisOptions.tickFormat ? getBandTickValues(timeAxis.domain, timeAxis.tickFormatter, dateAxisOptions.numTicks ?? DEFAULT_NUM_TICKS) : null;
4528
+ const bandTickValues = timeAxis && !dateAxisTickFormat ? getBandTickValues(timeAxis.domain, timeAxis.tickFormatter, dateAxisOptions.numTicks ?? DEFAULT_NUM_TICKS) : null;
4527
4529
  const dateAxisTickValues = bandTickValues ? { tickValues: bandTickValues } : {};
4528
4530
  return {
4529
4531
  gridVisibility,
@@ -4537,7 +4539,7 @@ function useBarChartOptions(data, horizontal, options = {}, isSeriesRendered = A
4537
4539
  x: {
4538
4540
  orientation: "bottom",
4539
4541
  numTicks: DEFAULT_NUM_TICKS,
4540
- tickFormat: xTickFormat,
4542
+ tickFormat: xTickFormat || defaultXTickFormat,
4541
4543
  ...horizontal ? {} : dateAxisTickValues,
4542
4544
  ...xLabelOverflow === "ellipsis" ? { tickComponent: TruncatedXTickComponent } : {},
4543
4545
  ...xAxisOptions
@@ -4545,14 +4547,14 @@ function useBarChartOptions(data, horizontal, options = {}, isSeriesRendered = A
4545
4547
  y: {
4546
4548
  orientation: "left",
4547
4549
  numTicks: DEFAULT_NUM_TICKS,
4548
- tickFormat: yTickFormat,
4550
+ tickFormat: yTickFormat || defaultYTickFormat,
4549
4551
  ...horizontal ? dateAxisTickValues : {},
4550
4552
  ...yLabelOverflow === "ellipsis" ? { tickComponent: TruncatedYTickComponent } : {},
4551
4553
  ...yAxisOptions
4552
4554
  }
4553
4555
  },
4554
4556
  barGroup: { padding: getGroupPadding(horizontal ? yScale : xScale) },
4555
- tooltip: { labelFormatter: providedToolTipLabelFormatter || defaultTooltipLabelFormatter }
4557
+ tooltip: { labelFormatter: dateAxisTickFormat || defaultTooltipLabelFormatter }
4556
4558
  };
4557
4559
  }, [
4558
4560
  defaultOptions,