@automattic/charts 1.6.0 → 1.7.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.
Files changed (33) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/README.md +2 -2
  3. package/dist/index.cjs +22 -9
  4. package/dist/index.cjs.map +1 -1
  5. package/dist/index.css +6 -3
  6. package/dist/index.d.cts +103 -30
  7. package/dist/index.d.ts +106 -33
  8. package/dist/index.js +22 -9
  9. package/dist/index.js.map +1 -1
  10. package/package.json +22 -21
  11. package/src/charts/area-chart/types.ts +1 -1
  12. package/src/charts/bar-chart/bar-chart.tsx +1 -1
  13. package/src/charts/geo-chart/geo-chart.tsx +3 -1
  14. package/src/charts/leaderboard-chart/leaderboard-chart.module.scss +27 -14
  15. package/src/charts/leaderboard-chart/leaderboard-chart.tsx +7 -4
  16. package/src/charts/leaderboard-chart/test/leaderboard-chart.test.tsx +51 -4
  17. package/src/charts/line-chart/line-chart.tsx +1 -1
  18. package/src/charts/line-chart/private/line-chart-annotation-label-popover.tsx +18 -2
  19. package/src/charts/line-chart/private/line-chart-annotation.tsx +1 -1
  20. package/src/charts/line-chart/types.ts +1 -1
  21. package/src/charts/pie-semi-circle-chart/pie-semi-circle-chart.tsx +2 -2
  22. package/src/charts/private/chart-layout/chart-layout.tsx +1 -2
  23. package/src/charts/private/x-zoom.tsx +2 -2
  24. package/src/components/legend/hooks/use-chart-legend-items.ts +6 -2
  25. package/src/components/legend/legend.tsx +1 -2
  26. package/src/components/legend/utils/label-transform-factory.ts +1 -1
  27. package/src/components/tooltip/accessible-tooltip.tsx +2 -6
  28. package/src/index.ts +6 -5
  29. package/src/providers/chart-context/themes.ts +1 -1
  30. package/src/providers/chart-context/types.ts +7 -2
  31. package/src/types.ts +104 -11
  32. package/src/utils/get-styles.ts +1 -2
  33. package/src/visx/types.ts +30 -1
package/dist/index.js CHANGED
@@ -17,7 +17,6 @@ import { LinearGradient } from "@visx/gradient";
17
17
  import { curveCatmullRom, curveLinear, curveMonotoneX } from "@visx/curve";
18
18
  import { useParentSize } from "@visx/responsive";
19
19
  import { Annotation, CircleSubject, Connector, HtmlLabel, Label, LineSubject } from "@visx/annotation";
20
- import { Icon, chevronRight, close } from "@wordpress/icons";
21
20
  import { PatternCircles, PatternHexagons, PatternLines, PatternWaves } from "@visx/pattern";
22
21
  import { useTooltip, useTooltipInPortal } from "@visx/tooltip";
23
22
  import { Chart } from "react-google-charts";
@@ -25,6 +24,7 @@ import DOMPurify from "dompurify";
25
24
  import { __assign } from "tslib";
26
25
  import _extends from "@babel/runtime/helpers/esm/extends";
27
26
  import "@babel/runtime/helpers/extends";
27
+ import { Icon, chevronRight } from "@wordpress/icons";
28
28
  import { Pie } from "@visx/shape";
29
29
  //#region \0rolldown/runtime.js
30
30
  var __create = Object.create;
@@ -709,7 +709,7 @@ const defaultTheme = {
709
709
  leaderboardChart: {
710
710
  rowGap: 12,
711
711
  columnGap: 4,
712
- labelSpacing: 1.5,
712
+ labelSpacing: "xs",
713
713
  deltaColors: [
714
714
  "#FF8C8F",
715
715
  "#757575",
@@ -3059,6 +3059,19 @@ const LineChartAnnotationsOverlay = ({ children }) => {
3059
3059
  })
3060
3060
  });
3061
3061
  };
3062
+ const CloseIcon = () => /* @__PURE__ */ jsx("svg", {
3063
+ width: "16",
3064
+ height: "16",
3065
+ viewBox: "0 0 24 24",
3066
+ fill: "none",
3067
+ stroke: "currentColor",
3068
+ strokeWidth: "2",
3069
+ strokeLinecap: "round",
3070
+ strokeLinejoin: "round",
3071
+ "aria-hidden": "true",
3072
+ focusable: "false",
3073
+ children: /* @__PURE__ */ jsx("path", { d: "M6 6l12 12M18 6L6 18" })
3074
+ });
3062
3075
  const LineChartAnnotationLabelWithPopover = ({ title, subtitle, renderLabel, renderLabelPopover }) => {
3063
3076
  const popoverId = useId();
3064
3077
  const buttonRef = useRef(null);
@@ -3120,10 +3133,7 @@ const LineChartAnnotationLabelWithPopover = ({ title, subtitle, renderLabel, ren
3120
3133
  popovertargetaction: "hide",
3121
3134
  className: line_chart_module_default["line-chart__annotation-label-popover-close-button"],
3122
3135
  "aria-label": __("Close", "jetpack-charts"),
3123
- children: /* @__PURE__ */ jsx(Icon, {
3124
- icon: close,
3125
- size: 16
3126
- })
3136
+ children: /* @__PURE__ */ jsx(CloseIcon, {})
3127
3137
  })]
3128
3138
  })
3129
3139
  })]
@@ -7763,13 +7773,15 @@ const defaultDeltaFormatter = (value) => {
7763
7773
  };
7764
7774
  /**
7765
7775
  * Build a bar's width. A hover-inset CSS variable (0 by default) is subtracted
7766
- * so interactive rows can pull the bar's right edge back by a fixed pixel amount
7767
- * on hover instead of a percentage scale keeping the bar↔value gap constant.
7776
+ * on hover, scaled by the bar's share so the pull-back is proportional to its
7777
+ * length: the full-length (100%) bar the one that reaches the value pulls
7778
+ * back the whole inset to keep its gap with the value, while shorter bars pull
7779
+ * back proportionally less, down to ~0 for a very short bar.
7768
7780
  *
7769
7781
  * @param share - The bar's share of the row width, as a percentage.
7770
7782
  * @return A CSS width value.
7771
7783
  */
7772
- const getBarWidth = (share) => `calc(${share}% - var(--a8c--charts--leaderboard--bar--hover-inset, 0px))`;
7784
+ const getBarWidth = (share) => `calc(${share}% - var(--a8c--charts--leaderboard--bar--hover-inset, 0px) * ${share} / 100)`;
7773
7785
  const BarLabel = ({ label }) => /* @__PURE__ */ jsx(Fragment$1, { children: typeof label === "string" ? /* @__PURE__ */ jsx(Text$1, {
7774
7786
  className: leaderboard_chart_module_default.label,
7775
7787
  children: label
@@ -7978,6 +7990,7 @@ const LeaderboardChartInternal = ({ data, chartId: providedChartId, width: propW
7978
7990
  type: "button",
7979
7991
  className: leaderboard_chart_module_default.interactiveRow,
7980
7992
  onClick: entry.onClick,
7993
+ "aria-label": entry.ariaLabel,
7981
7994
  children: [rowCells, /* @__PURE__ */ jsx(Icon, {
7982
7995
  className: leaderboard_chart_module_default.chevron,
7983
7996
  icon: chevronRight,