@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/CHANGELOG.md +5 -0
- package/dist/index.cjs +11 -32
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +12 -33
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/charts/bar-chart/bar-chart.tsx +29 -22
- package/src/charts/bar-chart/private/comparison-bars.tsx +1 -0
- package/src/charts/bar-chart/private/use-bar-chart-options.ts +4 -1
- package/src/charts/bar-chart/test/bar-chart.test.tsx +141 -3
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
|
+
## [1.8.1] - 2026-06-26
|
|
9
|
+
### Fixed
|
|
10
|
+
- Fix Bar Chart comparison mode — pair the keyboard tooltip with the focused bar, keep the value axis zero-based, and make the tooltip label/value separator translatable. [#49959]
|
|
11
|
+
|
|
8
12
|
## [1.8.0] - 2026-06-24
|
|
9
13
|
### Added
|
|
10
14
|
- Add comparison mode to the Bar Chart — a translucent shadow bar (standard slot width, 50% opacity) rendered behind each primary bar, paired by group. Primary bars are narrowed to 1/widthFactor of the slot (default widthFactor 1.5 → ~67% width, centered), with widthFactor as the single control. [#49676]
|
|
@@ -885,6 +889,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
885
889
|
- Fixed lints following ESLint rule changes for TS [#40584]
|
|
886
890
|
- Fixing a bug in Chart storybook data. [#40640]
|
|
887
891
|
|
|
892
|
+
[1.8.1]: https://github.com/Automattic/charts/compare/v1.8.0...v1.8.1
|
|
888
893
|
[1.8.0]: https://github.com/Automattic/charts/compare/v1.7.0...v1.8.0
|
|
889
894
|
[1.7.0]: https://github.com/Automattic/charts/compare/v1.6.0...v1.7.0
|
|
890
895
|
[1.6.0]: https://github.com/Automattic/charts/compare/v1.5.3...v1.6.0
|
package/dist/index.cjs
CHANGED
|
@@ -4474,7 +4474,7 @@ function useBarChartOptions(data, horizontal, options = {}) {
|
|
|
4474
4474
|
if (typeof v === "number" && Number.isFinite(v)) allValues.push(v);
|
|
4475
4475
|
});
|
|
4476
4476
|
});
|
|
4477
|
-
if (allValues.length > 0) valueScaleDomainOverride = { domain: [Math.min(...allValues), Math.max(...allValues)] };
|
|
4477
|
+
if (allValues.length > 0) valueScaleDomainOverride = { domain: [Math.min(0, ...allValues), Math.max(0, ...allValues)] };
|
|
4478
4478
|
}
|
|
4479
4479
|
}
|
|
4480
4480
|
const xScale = {
|
|
@@ -4653,6 +4653,7 @@ const ComparisonBars = ({ comparisonEntries, primaryKeys, groupPadding, horizont
|
|
|
4653
4653
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("g", {
|
|
4654
4654
|
className: "bar-chart__comparison-bars",
|
|
4655
4655
|
pointerEvents: "none",
|
|
4656
|
+
"aria-hidden": "true",
|
|
4656
4657
|
children: rects
|
|
4657
4658
|
});
|
|
4658
4659
|
};
|
|
@@ -4664,6 +4665,10 @@ const validateData$2 = (data) => {
|
|
|
4664
4665
|
return null;
|
|
4665
4666
|
};
|
|
4666
4667
|
const getPatternId = (chartId, index) => `bar-pattern-${chartId}-${index}`;
|
|
4668
|
+
const renderTooltipRow = (label, value) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
4669
|
+
className: bar_chart_module_default["bar-chart__tooltip-row"],
|
|
4670
|
+
children: (0, _wordpress_i18n.sprintf)((0, _wordpress_i18n.__)("%1$s: %2$s", "jetpack-charts"), label, value)
|
|
4671
|
+
});
|
|
4667
4672
|
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" }) => {
|
|
4668
4673
|
const legendInteractive = legend.interactive ?? false;
|
|
4669
4674
|
const horizontal = orientation === "horizontal";
|
|
@@ -4717,6 +4722,7 @@ const BarChartInternal = ({ data, chartId: providedChartId, width, height, class
|
|
|
4717
4722
|
}, [seriesWithVisibility]);
|
|
4718
4723
|
const primaryEntries = (0, react$1.useMemo)(() => seriesWithVisibility.filter(({ isVisible, series }) => isVisible && series.options?.type !== "comparison"), [seriesWithVisibility]);
|
|
4719
4724
|
const primaryKeys = (0, react$1.useMemo)(() => primaryEntries.map(({ series }) => series.label), [primaryEntries]);
|
|
4725
|
+
const primarySeries = (0, react$1.useMemo)(() => primaryEntries.map(({ series }) => series), [primaryEntries]);
|
|
4720
4726
|
const comparisonEntries = (0, react$1.useMemo)(() => {
|
|
4721
4727
|
const primaryByGroup = new Map(primaryEntries.map(({ series, index }) => [series.group, {
|
|
4722
4728
|
label: series.label,
|
|
@@ -4812,26 +4818,8 @@ const BarChartInternal = ({ data, chartId: providedChartId, width, height, class
|
|
|
4812
4818
|
className: bar_chart_module_default["bar-chart__tooltip-header"],
|
|
4813
4819
|
children: categoryLabel
|
|
4814
4820
|
}),
|
|
4815
|
-
|
|
4816
|
-
|
|
4817
|
-
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
4818
|
-
className: bar_chart_module_default["bar-chart__tooltip-label"],
|
|
4819
|
-
children: [primaryKey, ":"]
|
|
4820
|
-
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
4821
|
-
className: bar_chart_module_default["bar-chart__tooltip-value"],
|
|
4822
|
-
children: (0, _automattic_number_formatters.formatNumber)(nearestDatum.value)
|
|
4823
|
-
})]
|
|
4824
|
-
}),
|
|
4825
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
4826
|
-
className: bar_chart_module_default["bar-chart__tooltip-row"],
|
|
4827
|
-
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
4828
|
-
className: bar_chart_module_default["bar-chart__tooltip-label"],
|
|
4829
|
-
children: [comparisonEntry.series.label, ":"]
|
|
4830
|
-
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
4831
|
-
className: bar_chart_module_default["bar-chart__tooltip-value"],
|
|
4832
|
-
children: (0, _automattic_number_formatters.formatNumber)(comparisonDatum.value)
|
|
4833
|
-
})]
|
|
4834
|
-
})
|
|
4821
|
+
renderTooltipRow(primaryKey, (0, _automattic_number_formatters.formatNumber)(nearestDatum.value)),
|
|
4822
|
+
renderTooltipRow(comparisonEntry.series.label, (0, _automattic_number_formatters.formatNumber)(comparisonDatum.value))
|
|
4835
4823
|
]
|
|
4836
4824
|
});
|
|
4837
4825
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
@@ -4839,16 +4827,7 @@ const BarChartInternal = ({ data, chartId: providedChartId, width, height, class
|
|
|
4839
4827
|
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
4840
4828
|
className: bar_chart_module_default["bar-chart__tooltip-header"],
|
|
4841
4829
|
children: primaryKey
|
|
4842
|
-
}),
|
|
4843
|
-
className: bar_chart_module_default["bar-chart__tooltip-row"],
|
|
4844
|
-
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
4845
|
-
className: bar_chart_module_default["bar-chart__tooltip-label"],
|
|
4846
|
-
children: [categoryLabel, ":"]
|
|
4847
|
-
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
4848
|
-
className: bar_chart_module_default["bar-chart__tooltip-value"],
|
|
4849
|
-
children: (0, _automattic_number_formatters.formatNumber)(nearestDatum.value)
|
|
4850
|
-
})]
|
|
4851
|
-
})]
|
|
4830
|
+
}), renderTooltipRow(categoryLabel, (0, _automattic_number_formatters.formatNumber)(nearestDatum.value))]
|
|
4852
4831
|
});
|
|
4853
4832
|
}, [chartOptions.tooltip, comparisonEntries]);
|
|
4854
4833
|
const renderPattern = (0, react$1.useCallback)((index, color) => {
|
|
@@ -5041,7 +5020,7 @@ const BarChartInternal = ({ data, chartId: providedChartId, width, height, class
|
|
|
5041
5020
|
selectedIndex,
|
|
5042
5021
|
tooltipRef,
|
|
5043
5022
|
keyboardFocusedClassName: bar_chart_module_default["bar-chart__tooltip--keyboard-focused"],
|
|
5044
|
-
series:
|
|
5023
|
+
series: primarySeries,
|
|
5045
5024
|
mode: "individual"
|
|
5046
5025
|
})
|
|
5047
5026
|
]
|