@automattic/charts 1.5.0 → 1.5.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
@@ -3243,7 +3243,7 @@ var x_zoom_module_default = {
3243
3243
  };
3244
3244
 
3245
3245
  // src/charts/private/x-zoom.tsx
3246
- import { jsx as _jsx12, jsxs as _jsxs4 } from "react/jsx-runtime";
3246
+ import { jsx as _jsx12, Fragment as _Fragment4, jsxs as _jsxs4 } from "react/jsx-runtime";
3247
3247
  var MIN_DRAG_PIXELS = 6;
3248
3248
  function useXZoom({
3249
3249
  enabled,
@@ -3311,6 +3311,35 @@ function ZoomSelectionRect({
3311
3311
  height: innerHeight ?? 0
3312
3312
  });
3313
3313
  }
3314
+ function ZoomClip({
3315
+ active,
3316
+ chartId,
3317
+ children
3318
+ }) {
3319
+ const {
3320
+ margin,
3321
+ innerWidth,
3322
+ innerHeight
3323
+ } = useContext9(DataContext2);
3324
+ const id = `chart-zoom-clip-${String(chartId ?? "").replace(/[^A-Za-z0-9_-]/g, "")}`;
3325
+ const clip = active && (innerWidth ?? 0) > 0 && (innerHeight ?? 0) > 0;
3326
+ return /* @__PURE__ */ _jsxs4(_Fragment4, {
3327
+ children: [clip && /* @__PURE__ */ _jsx12("defs", {
3328
+ children: /* @__PURE__ */ _jsx12("clipPath", {
3329
+ id,
3330
+ children: /* @__PURE__ */ _jsx12("rect", {
3331
+ x: margin?.left ?? 0,
3332
+ y: margin?.top ?? 0,
3333
+ width: innerWidth,
3334
+ height: innerHeight
3335
+ })
3336
+ })
3337
+ }), /* @__PURE__ */ _jsx12("g", {
3338
+ clipPath: clip ? `url(#${id})` : void 0,
3339
+ children
3340
+ })]
3341
+ });
3342
+ }
3314
3343
  function ZoomResetButton({
3315
3344
  onClick
3316
3345
  }) {
@@ -4179,65 +4208,69 @@ var LineChartInternal = /* @__PURE__ */ forwardRef4(({
4179
4208
  width,
4180
4209
  height: chartHeight,
4181
4210
  children: __3("All series are hidden. Click legend items to show data.", "jetpack-charts")
4182
- }) : null, seriesWithVisibility.map(({
4183
- series: seriesData,
4184
- index,
4185
- isVisible
4186
- }) => {
4187
- if (!isVisible) {
4188
- return null;
4189
- }
4190
- const {
4191
- color,
4192
- lineStyles,
4193
- glyph
4194
- } = getElementStyles({
4195
- data: seriesData,
4196
- index
4197
- });
4198
- const lineProps = {
4199
- stroke: color,
4200
- ...lineStyles
4201
- };
4202
- return /* @__PURE__ */ _jsxs7("g", {
4203
- children: [withGradientFill && /* @__PURE__ */ _jsx16(LinearGradient, {
4204
- id: `area-gradient-${chartId}-${index + 1}`,
4205
- from: color,
4206
- fromOpacity: 0.4,
4207
- toOpacity: 0.1,
4208
- to: providerTheme.backgroundColor,
4209
- ...seriesData.options?.gradient,
4210
- children: seriesData.options?.gradient?.stops?.map((stop, stopIndex) => /* @__PURE__ */ _jsx16("stop", {
4211
- offset: stop.offset,
4212
- stopColor: stop.color || color,
4213
- stopOpacity: stop.opacity ?? 1
4214
- }, `${stop.offset}-${stop.color || color}`))
4215
- }), /* @__PURE__ */ _jsx16(AreaSeries, {
4216
- dataKey: seriesData?.label,
4217
- data: seriesData.data,
4218
- ...accessors,
4219
- fill: withGradientFill ? `url(#area-gradient-${chartId}-${index + 1})` : "transparent",
4220
- renderLine: true,
4221
- curve: getCurveType(curveType, smoothing),
4222
- lineProps
4223
- }, seriesData?.label), withStartGlyphs && /* @__PURE__ */ _jsx16(line_chart_glyph_default, {
4224
- index,
4225
- data: seriesData,
4211
+ }) : null, /* @__PURE__ */ _jsx16(ZoomClip, {
4212
+ active: zoomable && !!zoom.domain,
4213
+ chartId,
4214
+ children: seriesWithVisibility.map(({
4215
+ series: seriesData,
4216
+ index,
4217
+ isVisible
4218
+ }) => {
4219
+ if (!isVisible) {
4220
+ return null;
4221
+ }
4222
+ const {
4226
4223
  color,
4227
- renderGlyph: glyph ?? renderGlyph,
4228
- accessors,
4229
- glyphStyle,
4230
- position: "start"
4231
- }), withEndGlyphs && /* @__PURE__ */ _jsx16(line_chart_glyph_default, {
4232
- index,
4224
+ lineStyles,
4225
+ glyph
4226
+ } = getElementStyles({
4233
4227
  data: seriesData,
4234
- color,
4235
- renderGlyph: glyph ?? renderGlyph,
4236
- accessors,
4237
- glyphStyle,
4238
- position: "end"
4239
- })]
4240
- }, seriesData?.label || index);
4228
+ index
4229
+ });
4230
+ const lineProps = {
4231
+ stroke: color,
4232
+ ...lineStyles
4233
+ };
4234
+ return /* @__PURE__ */ _jsxs7("g", {
4235
+ children: [withGradientFill && /* @__PURE__ */ _jsx16(LinearGradient, {
4236
+ id: `area-gradient-${chartId}-${index + 1}`,
4237
+ from: color,
4238
+ fromOpacity: 0.4,
4239
+ toOpacity: 0.1,
4240
+ to: providerTheme.backgroundColor,
4241
+ ...seriesData.options?.gradient,
4242
+ children: seriesData.options?.gradient?.stops?.map((stop, stopIndex) => /* @__PURE__ */ _jsx16("stop", {
4243
+ offset: stop.offset,
4244
+ stopColor: stop.color || color,
4245
+ stopOpacity: stop.opacity ?? 1
4246
+ }, `${stop.offset}-${stop.color || color}`))
4247
+ }), /* @__PURE__ */ _jsx16(AreaSeries, {
4248
+ dataKey: seriesData?.label,
4249
+ data: seriesData.data,
4250
+ ...accessors,
4251
+ fill: withGradientFill ? `url(#area-gradient-${chartId}-${index + 1})` : "transparent",
4252
+ renderLine: true,
4253
+ curve: getCurveType(curveType, smoothing),
4254
+ lineProps
4255
+ }, seriesData?.label), withStartGlyphs && /* @__PURE__ */ _jsx16(line_chart_glyph_default, {
4256
+ index,
4257
+ data: seriesData,
4258
+ color,
4259
+ renderGlyph: glyph ?? renderGlyph,
4260
+ accessors,
4261
+ glyphStyle,
4262
+ position: "start"
4263
+ }), withEndGlyphs && /* @__PURE__ */ _jsx16(line_chart_glyph_default, {
4264
+ index,
4265
+ data: seriesData,
4266
+ color,
4267
+ renderGlyph: glyph ?? renderGlyph,
4268
+ accessors,
4269
+ glyphStyle,
4270
+ position: "end"
4271
+ })]
4272
+ }, seriesData?.label || index);
4273
+ })
4241
4274
  }), withTooltips && /* @__PURE__ */ _jsx16(AccessibleTooltip, {
4242
4275
  detectBounds: true,
4243
4276
  snapTooltipToDatumX: true,
@@ -4403,7 +4436,7 @@ var HoverGlyphs = ({
4403
4436
  };
4404
4437
 
4405
4438
  // src/charts/area-chart/area-chart.tsx
4406
- import { jsx as _jsx18, Fragment as _Fragment4, jsxs as _jsxs8 } from "react/jsx-runtime";
4439
+ import { jsx as _jsx18, jsxs as _jsxs8, Fragment as _Fragment5 } from "react/jsx-runtime";
4407
4440
  var AreaChartInternal = /* @__PURE__ */ forwardRef5(({
4408
4441
  data,
4409
4442
  chartId: providedChartId,
@@ -4749,12 +4782,16 @@ var AreaChartInternal = /* @__PURE__ */ forwardRef5(({
4749
4782
  width,
4750
4783
  height: chartHeight,
4751
4784
  children: __5("All series are hidden. Click legend items to show data.", "jetpack-charts")
4752
- }) : null, !allSeriesHidden && stacked && /* @__PURE__ */ _jsx18(AnimatedAreaStack, {
4753
- curve,
4754
- offset: stackOffset,
4755
- renderLine: resolvedWithStroke,
4756
- children: seriesWithVisibility.map(renderSeries)
4757
- }), !allSeriesHidden && !stacked && seriesWithVisibility.map(renderSeries), withTooltips && /* @__PURE__ */ _jsxs8(_Fragment4, {
4785
+ }) : null, /* @__PURE__ */ _jsxs8(ZoomClip, {
4786
+ active: zoomable,
4787
+ chartId,
4788
+ children: [!allSeriesHidden && stacked && /* @__PURE__ */ _jsx18(AnimatedAreaStack, {
4789
+ curve,
4790
+ offset: stackOffset,
4791
+ renderLine: resolvedWithStroke,
4792
+ children: seriesWithVisibility.map(renderSeries)
4793
+ }), !allSeriesHidden && !stacked && seriesWithVisibility.map(renderSeries)]
4794
+ }), withTooltips && /* @__PURE__ */ _jsxs8(_Fragment5, {
4758
4795
  children: [/* @__PURE__ */ _jsx18(AccessibleTooltip, {
4759
4796
  detectBounds: true,
4760
4797
  snapTooltipToDatumX: true,
@@ -5036,7 +5073,7 @@ function useBarChartOptions(data, horizontal, options = {}) {
5036
5073
  }
5037
5074
 
5038
5075
  // src/charts/bar-chart/bar-chart.tsx
5039
- import { jsx as _jsx20, jsxs as _jsxs9, Fragment as _Fragment5 } from "react/jsx-runtime";
5076
+ import { jsx as _jsx20, jsxs as _jsxs9, Fragment as _Fragment6 } from "react/jsx-runtime";
5040
5077
  var validateData3 = (data) => {
5041
5078
  if (!data?.length) return "No data available";
5042
5079
  const hasInvalidData = data.some((series) => series.data.some((point) => isNaN(point.value) || point.value === null || point.value === void 0 || !point.label && (!("date" in point && point.date) || isNaN(point.date.getTime()))));
@@ -5306,7 +5343,7 @@ var BarChartInternal = ({
5306
5343
  columns: gridVisibility.includes("y"),
5307
5344
  rows: gridVisibility.includes("x"),
5308
5345
  numTicks: 4
5309
- }), withPatterns && /* @__PURE__ */ _jsxs9(_Fragment5, {
5346
+ }), withPatterns && /* @__PURE__ */ _jsxs9(_Fragment6, {
5310
5347
  children: [/* @__PURE__ */ _jsx20("defs", {
5311
5348
  children: dataSorted.map((seriesData, index) => renderPattern(index, getElementStyles({
5312
5349
  data: seriesData,
@@ -5671,7 +5708,7 @@ var useFunnelSelection = (hideTooltip) => {
5671
5708
  };
5672
5709
 
5673
5710
  // src/charts/conversion-funnel-chart/conversion-funnel-chart.tsx
5674
- import { jsx as _jsx22, Fragment as _Fragment6, jsxs as _jsxs11 } from "react/jsx-runtime";
5711
+ import { jsx as _jsx22, Fragment as _Fragment7, jsxs as _jsxs11 } from "react/jsx-runtime";
5675
5712
  var ConversionFunnelChartInternal = ({
5676
5713
  mainRate,
5677
5714
  changeIndicator,
@@ -5832,7 +5869,7 @@ var ConversionFunnelChartInternal = ({
5832
5869
  const isPositiveChange = changeIndicator?.startsWith("+");
5833
5870
  const changeColor = isPositiveChange ? positiveChangeColor : negativeChangeColor;
5834
5871
  const barBackgroundColor = backgroundColor || hexToRgba(barColor, 0.08) || "rgba(0, 0, 0, 0.08)";
5835
- const renderDefaultMainMetric = () => /* @__PURE__ */ _jsxs11(_Fragment6, {
5872
+ const renderDefaultMainMetric = () => /* @__PURE__ */ _jsxs11(_Fragment7, {
5836
5873
  children: [/* @__PURE__ */ _jsx22("span", {
5837
5874
  className: conversion_funnel_chart_module_default["main-rate"],
5838
5875
  children: formatPercentage(mainRate)
@@ -5887,7 +5924,7 @@ var ConversionFunnelChartInternal = ({
5887
5924
  });
5888
5925
  }
5889
5926
  const maxRate = Math.max(...steps.map((step) => step.rate));
5890
- return /* @__PURE__ */ _jsxs11(_Fragment6, {
5927
+ return /* @__PURE__ */ _jsxs11(_Fragment7, {
5891
5928
  children: [/* @__PURE__ */ _jsxs11(Stack, {
5892
5929
  direction: "column",
5893
5930
  gap: "xl",
@@ -8422,7 +8459,7 @@ var leaderboard_chart_module_default = {
8422
8459
  };
8423
8460
 
8424
8461
  // src/charts/leaderboard-chart/leaderboard-chart.tsx
8425
- import { jsx as _jsx27, Fragment as _Fragment7, jsxs as _jsxs12 } from "react/jsx-runtime";
8462
+ import { jsx as _jsx27, Fragment as _Fragment8, jsxs as _jsxs12 } from "react/jsx-runtime";
8426
8463
  var defaultValueFormatter = (value) => {
8427
8464
  return formatMetricValue(value, "number", {
8428
8465
  useMultipliers: true,
@@ -8437,7 +8474,7 @@ var defaultDeltaFormatter = (value) => {
8437
8474
  };
8438
8475
  var BarLabel = ({
8439
8476
  label
8440
- }) => /* @__PURE__ */ _jsx27(_Fragment7, {
8477
+ }) => /* @__PURE__ */ _jsx27(_Fragment8, {
8441
8478
  children: typeof label === "string" ? /* @__PURE__ */ _jsx27(Text, {
8442
8479
  className: leaderboard_chart_module_default.label,
8443
8480
  children: label
@@ -8766,7 +8803,7 @@ var pie_chart_module_default = {
8766
8803
  };
8767
8804
 
8768
8805
  // src/charts/pie-chart/pie-chart.tsx
8769
- import { jsx as _jsx29, Fragment as _Fragment8, jsxs as _jsxs13 } from "react/jsx-runtime";
8806
+ import { jsx as _jsx29, Fragment as _Fragment9, jsxs as _jsxs13 } from "react/jsx-runtime";
8770
8807
  var renderDefaultPieTooltip = ({
8771
8808
  tooltipData
8772
8809
  }) => {
@@ -8956,7 +8993,7 @@ var PieChartInternal = ({
8956
8993
  width: propWidth || void 0,
8957
8994
  height: propHeight || void 0
8958
8995
  },
8959
- trailingContent: /* @__PURE__ */ _jsxs13(_Fragment8, {
8996
+ trailingContent: /* @__PURE__ */ _jsxs13(_Fragment9, {
8960
8997
  children: [withTooltips && tooltipOpen && tooltipData && /* @__PURE__ */ _jsx29(TooltipInPortal, {
8961
8998
  top: tooltipTop || 0,
8962
8999
  left: tooltipLeft || 0,
@@ -9135,7 +9172,7 @@ var pie_semi_circle_chart_module_default = {
9135
9172
  };
9136
9173
 
9137
9174
  // src/charts/pie-semi-circle-chart/pie-semi-circle-chart.tsx
9138
- import { jsx as _jsx30, Fragment as _Fragment9, jsxs as _jsxs14 } from "react/jsx-runtime";
9175
+ import { jsx as _jsx30, Fragment as _Fragment10, jsxs as _jsxs14 } from "react/jsx-runtime";
9139
9176
  var renderDefaultPieSemiCircleTooltip = ({
9140
9177
  tooltipData
9141
9178
  }) => {
@@ -9337,7 +9374,7 @@ var PieSemiCircleChartInternal = ({
9337
9374
  width: propWidth || void 0,
9338
9375
  height: propHeight || void 0
9339
9376
  },
9340
- trailingContent: /* @__PURE__ */ _jsxs14(_Fragment9, {
9377
+ trailingContent: /* @__PURE__ */ _jsxs14(_Fragment10, {
9341
9378
  children: [withTooltips && tooltipOpen && tooltipData && /* @__PURE__ */ _jsx30(TooltipInPortal, {
9342
9379
  top: tooltipTop || 0,
9343
9380
  left: tooltipLeft || 0,
@@ -9386,7 +9423,7 @@ var PieSemiCircleChartInternal = ({
9386
9423
  width,
9387
9424
  height,
9388
9425
  children: __11("All segments are hidden. Click legend items to show data.", "jetpack-charts")
9389
- }) : /* @__PURE__ */ _jsxs14(_Fragment9, {
9426
+ }) : /* @__PURE__ */ _jsxs14(_Fragment10, {
9390
9427
  children: [/* @__PURE__ */ _jsx30(Pie2, {
9391
9428
  data: dataWithIndex,
9392
9429
  pieValue: accessors.value,