@automattic/charts 1.8.0 → 1.8.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
@@ -1,7 +1,7 @@
1
1
  import { getStringWidth as getStringWidth$1 } from "./visx/text/index.js";
2
2
  import { formatNumber, formatNumberCompact } from "@automattic/number-formatters";
3
3
  import { AnimatedAreaSeries, AnimatedAreaStack, AreaSeries, Axis, BarGroup, BarSeries, DataContext, Grid, Tooltip, TooltipContext, XYChart, buildChartTheme } from "@visx/xychart";
4
- import { __ } from "@wordpress/i18n";
4
+ import { __, sprintf } from "@wordpress/i18n";
5
5
  import clsx from "clsx";
6
6
  import * as React from "react";
7
7
  import { Children, Fragment, Fragment as Fragment$2, createContext, createContext as createContext$1, createElement, forwardRef, forwardRef as forwardRef$1, forwardRef as forwardRef$2, isValidElement, memo, useCallback, useCallback as useCallback$1, 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 } from "react";
@@ -4470,7 +4470,7 @@ function useBarChartOptions(data, horizontal, options = {}) {
4470
4470
  if (typeof v === "number" && Number.isFinite(v)) allValues.push(v);
4471
4471
  });
4472
4472
  });
4473
- if (allValues.length > 0) valueScaleDomainOverride = { domain: [Math.min(...allValues), Math.max(...allValues)] };
4473
+ if (allValues.length > 0) valueScaleDomainOverride = { domain: [Math.min(0, ...allValues), Math.max(0, ...allValues)] };
4474
4474
  }
4475
4475
  }
4476
4476
  const xScale = {
@@ -4649,6 +4649,7 @@ const ComparisonBars = ({ comparisonEntries, primaryKeys, groupPadding, horizont
4649
4649
  return /* @__PURE__ */ jsx("g", {
4650
4650
  className: "bar-chart__comparison-bars",
4651
4651
  pointerEvents: "none",
4652
+ "aria-hidden": "true",
4652
4653
  children: rects
4653
4654
  });
4654
4655
  };
@@ -4660,6 +4661,10 @@ const validateData$2 = (data) => {
4660
4661
  return null;
4661
4662
  };
4662
4663
  const getPatternId = (chartId, index) => `bar-pattern-${chartId}-${index}`;
4664
+ const renderTooltipRow = (label, value) => /* @__PURE__ */ jsx("div", {
4665
+ className: bar_chart_module_default["bar-chart__tooltip-row"],
4666
+ children: sprintf(__("%1$s: %2$s", "jetpack-charts"), label, value)
4667
+ });
4663
4668
  const BarChartInternal = ({ data, chartId: providedChartId, width, height, className, margin, withTooltips = false, showLegend = false, legend = {}, gridVisibility: gridVisibilityProp, renderTooltip, options = {}, orientation = "vertical", withPatterns = false, showZeroValues = false, animation, children, gap = "md" }) => {
4664
4669
  const legendInteractive = legend.interactive ?? false;
4665
4670
  const horizontal = orientation === "horizontal";
@@ -4713,6 +4718,7 @@ const BarChartInternal = ({ data, chartId: providedChartId, width, height, class
4713
4718
  }, [seriesWithVisibility]);
4714
4719
  const primaryEntries = useMemo(() => seriesWithVisibility.filter(({ isVisible, series }) => isVisible && series.options?.type !== "comparison"), [seriesWithVisibility]);
4715
4720
  const primaryKeys = useMemo(() => primaryEntries.map(({ series }) => series.label), [primaryEntries]);
4721
+ const primarySeries = useMemo(() => primaryEntries.map(({ series }) => series), [primaryEntries]);
4716
4722
  const comparisonEntries = useMemo(() => {
4717
4723
  const primaryByGroup = new Map(primaryEntries.map(({ series, index }) => [series.group, {
4718
4724
  label: series.label,
@@ -4808,26 +4814,8 @@ const BarChartInternal = ({ data, chartId: providedChartId, width, height, class
4808
4814
  className: bar_chart_module_default["bar-chart__tooltip-header"],
4809
4815
  children: categoryLabel
4810
4816
  }),
4811
- /* @__PURE__ */ jsxs("div", {
4812
- className: bar_chart_module_default["bar-chart__tooltip-row"],
4813
- children: [/* @__PURE__ */ jsxs("span", {
4814
- className: bar_chart_module_default["bar-chart__tooltip-label"],
4815
- children: [primaryKey, ":"]
4816
- }), /* @__PURE__ */ jsx("span", {
4817
- className: bar_chart_module_default["bar-chart__tooltip-value"],
4818
- children: formatNumber(nearestDatum.value)
4819
- })]
4820
- }),
4821
- /* @__PURE__ */ jsxs("div", {
4822
- className: bar_chart_module_default["bar-chart__tooltip-row"],
4823
- children: [/* @__PURE__ */ jsxs("span", {
4824
- className: bar_chart_module_default["bar-chart__tooltip-label"],
4825
- children: [comparisonEntry.series.label, ":"]
4826
- }), /* @__PURE__ */ jsx("span", {
4827
- className: bar_chart_module_default["bar-chart__tooltip-value"],
4828
- children: formatNumber(comparisonDatum.value)
4829
- })]
4830
- })
4817
+ renderTooltipRow(primaryKey, formatNumber(nearestDatum.value)),
4818
+ renderTooltipRow(comparisonEntry.series.label, formatNumber(comparisonDatum.value))
4831
4819
  ]
4832
4820
  });
4833
4821
  return /* @__PURE__ */ jsxs("div", {
@@ -4835,16 +4823,7 @@ const BarChartInternal = ({ data, chartId: providedChartId, width, height, class
4835
4823
  children: [/* @__PURE__ */ jsx("div", {
4836
4824
  className: bar_chart_module_default["bar-chart__tooltip-header"],
4837
4825
  children: primaryKey
4838
- }), /* @__PURE__ */ jsxs("div", {
4839
- className: bar_chart_module_default["bar-chart__tooltip-row"],
4840
- children: [/* @__PURE__ */ jsxs("span", {
4841
- className: bar_chart_module_default["bar-chart__tooltip-label"],
4842
- children: [categoryLabel, ":"]
4843
- }), /* @__PURE__ */ jsx("span", {
4844
- className: bar_chart_module_default["bar-chart__tooltip-value"],
4845
- children: formatNumber(nearestDatum.value)
4846
- })]
4847
- })]
4826
+ }), renderTooltipRow(categoryLabel, formatNumber(nearestDatum.value))]
4848
4827
  });
4849
4828
  }, [chartOptions.tooltip, comparisonEntries]);
4850
4829
  const renderPattern = useCallback((index, color) => {
@@ -5037,7 +5016,7 @@ const BarChartInternal = ({ data, chartId: providedChartId, width, height, class
5037
5016
  selectedIndex,
5038
5017
  tooltipRef,
5039
5018
  keyboardFocusedClassName: bar_chart_module_default["bar-chart__tooltip--keyboard-focused"],
5040
- series: data,
5019
+ series: primarySeries,
5041
5020
  mode: "individual"
5042
5021
  })
5043
5022
  ]