@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/dist/index.js CHANGED
@@ -3491,8 +3491,8 @@ const LineChartInternal = forwardRef(({ data, chartId: providedChartId, width, h
3491
3491
  totalPoints: dataSorted[0]?.data.length || 0
3492
3492
  });
3493
3493
  const chartOptions = useMemo(() => {
3494
- const { tickResolution, ...xAxisOptions } = options?.axis?.x ?? {};
3495
- const formatter = xAxisOptions.tickFormat || getFormatter(dataSorted, tickResolution);
3494
+ const { tickResolution, tickFormat, ...xAxisOptions } = options?.axis?.x ?? {};
3495
+ const formatter = tickFormat || getFormatter(dataSorted, tickResolution);
3496
3496
  return {
3497
3497
  axis: {
3498
3498
  x: {
@@ -3958,8 +3958,8 @@ const AreaChartInternal = forwardRef(({ data, chartId: providedChartId, width, h
3958
3958
  rescaleYOnVisibility
3959
3959
  ]);
3960
3960
  const chartOptions = useMemo(() => {
3961
- const { tickResolution, ...xAxisOptions } = options?.axis?.x ?? {};
3962
- const formatter = xAxisOptions.tickFormat || getFormatter(dataSorted, tickResolution);
3961
+ const { tickResolution, tickFormat, ...xAxisOptions } = options?.axis?.x ?? {};
3962
+ const formatter = tickFormat || getFormatter(dataSorted, tickResolution);
3963
3963
  return {
3964
3964
  axis: {
3965
3965
  x: {
@@ -4428,11 +4428,13 @@ const getGroupPadding = (scale) => {
4428
4428
  function useBarChartOptions(data, horizontal, options = {}, isSeriesRendered = ALL_RENDERED) {
4429
4429
  const stableOptions = useDeepMemo(options);
4430
4430
  const axisConfig = useMemo(() => {
4431
- const { labelOverflow: xLabelOverflow, tickResolution: xTickResolution, ...xAxisOptions } = stableOptions.axis?.x || {};
4432
- const { labelOverflow: yLabelOverflow, tickResolution: yTickResolution, ...yAxisOptions } = stableOptions.axis?.y || {};
4431
+ const { labelOverflow: xLabelOverflow, tickResolution: xTickResolution, tickFormat: xTickFormat, ...xAxisOptions } = stableOptions.axis?.x || {};
4432
+ const { labelOverflow: yLabelOverflow, tickResolution: yTickResolution, tickFormat: yTickFormat, ...yAxisOptions } = stableOptions.axis?.y || {};
4433
4433
  return {
4434
4434
  xLabelOverflow,
4435
4435
  yLabelOverflow,
4436
+ xTickFormat,
4437
+ yTickFormat,
4436
4438
  xAxisOptions,
4437
4439
  yAxisOptions,
4438
4440
  tickResolution: horizontal ? yTickResolution : xTickResolution
@@ -4492,7 +4494,7 @@ function useBarChartOptions(data, horizontal, options = {}, isSeriesRendered = A
4492
4494
  isSeriesRendered
4493
4495
  ]);
4494
4496
  return useMemo(() => {
4495
- const { xTickFormat, yTickFormat, tooltipLabelFormatter: defaultTooltipLabelFormatter, xAccessor, yAccessor, gridVisibility, xScale: baseXScale, yScale: baseYScale } = defaultOptions[horizontal ? "horizontal" : "vertical"];
4497
+ const { xTickFormat: defaultXTickFormat, yTickFormat: defaultYTickFormat, tooltipLabelFormatter: defaultTooltipLabelFormatter, xAccessor, yAccessor, gridVisibility, xScale: baseXScale, yScale: baseYScale } = defaultOptions[horizontal ? "horizontal" : "vertical"];
4496
4498
  let valueScaleDomainOverride = {};
4497
4499
  if (data.some((s) => s.options?.type === "comparison")) {
4498
4500
  if (!(!horizontal ? stableOptions.yScale?.domain : stableOptions.xScale?.domain)) {
@@ -4517,11 +4519,11 @@ function useBarChartOptions(data, horizontal, options = {}, isSeriesRendered = A
4517
4519
  ...stableOptions.yScale || {},
4518
4520
  ...!horizontal ? valueScaleDomainOverride : {}
4519
4521
  };
4520
- const { xLabelOverflow, yLabelOverflow, xAxisOptions, yAxisOptions } = axisConfig;
4521
- const providedToolTipLabelFormatter = horizontal ? yAxisOptions.tickFormat : xAxisOptions.tickFormat;
4522
+ const { xLabelOverflow, yLabelOverflow, xTickFormat, yTickFormat, xAxisOptions, yAxisOptions } = axisConfig;
4523
+ const dateAxisTickFormat = horizontal ? yTickFormat : xTickFormat;
4522
4524
  const { timeAxis } = defaultOptions;
4523
4525
  const dateAxisOptions = horizontal ? yAxisOptions : xAxisOptions;
4524
- const bandTickValues = timeAxis && !dateAxisOptions.tickFormat ? getBandTickValues(timeAxis.domain, timeAxis.tickFormatter, dateAxisOptions.numTicks ?? DEFAULT_NUM_TICKS) : null;
4526
+ const bandTickValues = timeAxis && !dateAxisTickFormat ? getBandTickValues(timeAxis.domain, timeAxis.tickFormatter, dateAxisOptions.numTicks ?? DEFAULT_NUM_TICKS) : null;
4525
4527
  const dateAxisTickValues = bandTickValues ? { tickValues: bandTickValues } : {};
4526
4528
  return {
4527
4529
  gridVisibility,
@@ -4535,7 +4537,7 @@ function useBarChartOptions(data, horizontal, options = {}, isSeriesRendered = A
4535
4537
  x: {
4536
4538
  orientation: "bottom",
4537
4539
  numTicks: DEFAULT_NUM_TICKS,
4538
- tickFormat: xTickFormat,
4540
+ tickFormat: xTickFormat || defaultXTickFormat,
4539
4541
  ...horizontal ? {} : dateAxisTickValues,
4540
4542
  ...xLabelOverflow === "ellipsis" ? { tickComponent: TruncatedXTickComponent } : {},
4541
4543
  ...xAxisOptions
@@ -4543,14 +4545,14 @@ function useBarChartOptions(data, horizontal, options = {}, isSeriesRendered = A
4543
4545
  y: {
4544
4546
  orientation: "left",
4545
4547
  numTicks: DEFAULT_NUM_TICKS,
4546
- tickFormat: yTickFormat,
4548
+ tickFormat: yTickFormat || defaultYTickFormat,
4547
4549
  ...horizontal ? dateAxisTickValues : {},
4548
4550
  ...yLabelOverflow === "ellipsis" ? { tickComponent: TruncatedYTickComponent } : {},
4549
4551
  ...yAxisOptions
4550
4552
  }
4551
4553
  },
4552
4554
  barGroup: { padding: getGroupPadding(horizontal ? yScale : xScale) },
4553
- tooltip: { labelFormatter: providedToolTipLabelFormatter || defaultTooltipLabelFormatter }
4555
+ tooltip: { labelFormatter: dateAxisTickFormat || defaultTooltipLabelFormatter }
4554
4556
  };
4555
4557
  }, [
4556
4558
  defaultOptions,