@automattic/charts 0.45.0 → 0.46.0

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,13 @@ 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
+ ## [0.46.0] - 2025-10-28
9
+ ### Added
10
+ - Charts: Add interactive legend support to LeaderboardChart [#45581]
11
+
12
+ ### Changed
13
+ - Update package dependencies. [#45652]
14
+
8
15
  ## [0.45.0] - 2025-10-27
9
16
  ### Added
10
17
  - Add interactive legend support to BarChart. [#45561]
@@ -528,6 +535,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
528
535
  - Fixed lints following ESLint rule changes for TS [#40584]
529
536
  - Fixing a bug in Chart storybook data. [#40640]
530
537
 
538
+ [0.46.0]: https://github.com/Automattic/charts/compare/v0.45.0...v0.46.0
531
539
  [0.45.0]: https://github.com/Automattic/charts/compare/v0.44.0...v0.45.0
532
540
  [0.44.0]: https://github.com/Automattic/charts/compare/v0.43.0...v0.44.0
533
541
  [0.43.0]: https://github.com/Automattic/charts/compare/v0.42.0...v0.43.0
@@ -4257,7 +4257,9 @@ var BarWithLabel = ({
4257
4257
  withComparison,
4258
4258
  withOverlayLabel,
4259
4259
  primaryColor,
4260
- secondaryColor
4260
+ secondaryColor,
4261
+ isPrimaryVisible = true,
4262
+ isComparisonVisible = true
4261
4263
  }) => /* @__PURE__ */ jsxs(
4262
4264
  "div",
4263
4265
  {
@@ -4266,7 +4268,7 @@ var BarWithLabel = ({
4266
4268
  }),
4267
4269
  children: [
4268
4270
  /* @__PURE__ */ jsx3(BarLabel, { label: entry.label }),
4269
- /* @__PURE__ */ jsx3(
4271
+ isPrimaryVisible && /* @__PURE__ */ jsx3(
4270
4272
  "div",
4271
4273
  {
4272
4274
  className: leaderboard_chart_module_default.bar,
@@ -4276,7 +4278,7 @@ var BarWithLabel = ({
4276
4278
  }
4277
4279
  }
4278
4280
  ),
4279
- withComparison && !withOverlayLabel && /* @__PURE__ */ jsx3(
4281
+ withComparison && !withOverlayLabel && isComparisonVisible && /* @__PURE__ */ jsx3(
4280
4282
  "div",
4281
4283
  {
4282
4284
  className: leaderboard_chart_module_default.bar,
@@ -4307,6 +4309,7 @@ var LeaderboardChartInternal = ({
4307
4309
  legendShapeWidth = 8,
4308
4310
  legendShapeHeight = 8,
4309
4311
  legendLabels,
4312
+ legendInteractive = false,
4310
4313
  className,
4311
4314
  style,
4312
4315
  children
@@ -4322,7 +4325,7 @@ var LeaderboardChartInternal = ({
4322
4325
  secondaryColor: settingsSecondaryColor,
4323
4326
  deltaColors
4324
4327
  } = leaderboardChartSettings;
4325
- const { getElementStyles } = useGlobalChartsContext();
4328
+ const { getElementStyles, isSeriesVisible } = useGlobalChartsContext();
4326
4329
  const { color: resolvedPrimaryColor } = getElementStyles({
4327
4330
  index: 0,
4328
4331
  overrideColor: primaryColor || settingsPrimaryColor
@@ -4339,6 +4342,31 @@ var LeaderboardChartInternal = ({
4339
4342
  withOverlayLabel,
4340
4343
  legendLabels
4341
4344
  });
4345
+ const isPrimaryVisible = useMemo3(() => {
4346
+ if (!chartId || !legendInteractive || legendItems.length === 0) {
4347
+ return true;
4348
+ }
4349
+ return isSeriesVisible(chartId, legendItems[0].label);
4350
+ }, [chartId, legendInteractive, legendItems, isSeriesVisible]);
4351
+ const isComparisonVisible = useMemo3(() => {
4352
+ if (!chartId || !legendInteractive || legendItems.length < 2) {
4353
+ return true;
4354
+ }
4355
+ return isSeriesVisible(chartId, legendItems[1].label);
4356
+ }, [chartId, legendInteractive, legendItems, isSeriesVisible]);
4357
+ const allSeriesHidden = useMemo3(() => {
4358
+ if (!legendInteractive) return false;
4359
+ if (withComparison && !withOverlayLabel) {
4360
+ return !isPrimaryVisible && !isComparisonVisible;
4361
+ }
4362
+ return !isPrimaryVisible;
4363
+ }, [
4364
+ legendInteractive,
4365
+ isPrimaryVisible,
4366
+ isComparisonVisible,
4367
+ withComparison,
4368
+ withOverlayLabel
4369
+ ]);
4342
4370
  const isDataValid = Boolean(data && data.length > 0);
4343
4371
  const chartMetadata = useMemo3(
4344
4372
  () => ({
@@ -4398,7 +4426,7 @@ var LeaderboardChartInternal = ({
4398
4426
  gap: showLegend ? "16px" : "0"
4399
4427
  },
4400
4428
  children: [
4401
- /* @__PURE__ */ jsx3(component_default6, { templateColumns: "minmax(0, 1fr) auto", rowGap, columnGap, children: data.map((entry) => {
4429
+ allSeriesHidden ? /* @__PURE__ */ jsx3("div", { className: leaderboard_chart_module_default.emptyState, children: __2("All series are hidden. Click legend items to show data.", "jetpack-charts") }) : /* @__PURE__ */ jsx3(component_default6, { templateColumns: "minmax(0, 1fr) auto", rowGap, columnGap, children: data.map((entry) => {
4402
4430
  const colorIndex = Math.sign(entry.delta) + 1;
4403
4431
  const deltaColor = deltaColors[colorIndex];
4404
4432
  return /* @__PURE__ */ jsxs(Fragment, { children: [
@@ -4409,7 +4437,9 @@ var LeaderboardChartInternal = ({
4409
4437
  withComparison,
4410
4438
  withOverlayLabel,
4411
4439
  primaryColor: resolvedPrimaryColor,
4412
- secondaryColor: resolvedSecondaryColor
4440
+ secondaryColor: resolvedSecondaryColor,
4441
+ isPrimaryVisible,
4442
+ isComparisonVisible
4413
4443
  }
4414
4444
  ) }),
4415
4445
  /* @__PURE__ */ jsxs(
@@ -4419,8 +4449,8 @@ var LeaderboardChartInternal = ({
4419
4449
  [leaderboard_chart_module_default.overlayLabel]: withOverlayLabel
4420
4450
  }),
4421
4451
  children: [
4422
- /* @__PURE__ */ jsx3(component_default4, { children: valueFormatter(entry.currentValue) }),
4423
- withComparison && /* @__PURE__ */ jsx3(component_default4, { style: { color: deltaColor }, children: deltaFormatter(entry.delta) })
4452
+ isPrimaryVisible && /* @__PURE__ */ jsx3(component_default4, { children: valueFormatter(entry.currentValue) }),
4453
+ withComparison && isComparisonVisible && /* @__PURE__ */ jsx3(component_default4, { style: { color: deltaColor }, children: deltaFormatter(entry.delta) })
4424
4454
  ]
4425
4455
  }
4426
4456
  )
@@ -4435,7 +4465,8 @@ var LeaderboardChartInternal = ({
4435
4465
  shape: legendShape,
4436
4466
  shapeWidth: legendShapeWidth,
4437
4467
  shapeHeight: legendShapeHeight,
4438
- chartId
4468
+ chartId,
4469
+ interactive: legendInteractive
4439
4470
  }
4440
4471
  ),
4441
4472
  otherChildren
@@ -4498,4 +4529,4 @@ is-plain-object/dist/is-plain-object.mjs:
4498
4529
  * Released under the MIT License.
4499
4530
  *)
4500
4531
  */
4501
- //# sourceMappingURL=chunk-VM3CHO3G.js.map
4532
+ //# sourceMappingURL=chunk-4H3J2HCD.js.map