@automattic/charts 4.7.0 → 4.8.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 (61) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/TOKENS.md +6 -3
  3. package/dist/index.cjs +212 -95
  4. package/dist/index.cjs.map +1 -1
  5. package/dist/index.css +10 -9
  6. package/dist/index.d.cts +60 -20
  7. package/dist/index.d.ts +60 -20
  8. package/dist/index.js +212 -97
  9. package/dist/index.js.map +1 -1
  10. package/package.json +1 -1
  11. package/src/charts/area-chart/area-chart.tsx +2 -2
  12. package/src/charts/area-chart/test/area-chart.test.tsx +1 -1
  13. package/src/charts/area-chart/test/tooltip-resolution-branches.test.tsx +1 -1
  14. package/src/charts/bar-chart/bar-chart.module.scss +7 -0
  15. package/src/charts/bar-chart/bar-chart.tsx +20 -14
  16. package/src/charts/bar-chart/private/comparison-bars.tsx +1 -0
  17. package/src/charts/bar-chart/test/bar-chart.test.tsx +25 -0
  18. package/src/charts/conversion-funnel-chart/conversion-funnel-chart.tsx +1 -1
  19. package/src/charts/conversion-funnel-chart/test/conversion-funnel-chart.test.tsx +9 -0
  20. package/src/charts/heatmap-chart/heatmap-chart.module.scss +6 -4
  21. package/src/charts/heatmap-chart/heatmap-chart.tsx +39 -29
  22. package/src/charts/heatmap-chart/private/heatmap-context.ts +2 -2
  23. package/src/charts/heatmap-chart/private/heatmap-legend.tsx +2 -2
  24. package/src/charts/heatmap-chart/private/heatmap-scale.ts +74 -0
  25. package/src/charts/heatmap-chart/private/index.ts +2 -1
  26. package/src/charts/heatmap-chart/private/use-heatmap-colors.ts +24 -6
  27. package/src/charts/heatmap-chart/test/heatmap-chart.test.tsx +99 -7
  28. package/src/charts/heatmap-chart/test/heatmap-scale.test.ts +78 -0
  29. package/src/charts/heatmap-chart/test/use-heatmap-colors.test.ts +18 -6
  30. package/src/charts/heatmap-chart/types.ts +4 -3
  31. package/src/charts/line-chart/line-chart.tsx +2 -2
  32. package/src/charts/pie-chart/pie-chart.tsx +4 -4
  33. package/src/charts/pie-semi-circle-chart/pie-semi-circle-chart.tsx +4 -4
  34. package/src/charts/pie-semi-circle-chart/test/pie-semi-circle-chart.test.tsx +1 -1
  35. package/src/charts/private/test/label-text-color.test.ts +6 -8
  36. package/src/components/tooltip/base-tooltip.tsx +31 -32
  37. package/src/components/tooltip/index.ts +3 -1
  38. package/src/components/tooltip/private/bounded-tooltip.tsx +15 -15
  39. package/src/components/tooltip/private/label-value-content.tsx +8 -0
  40. package/src/components/tooltip/private/xy-chart-tooltip-overlay.tsx +336 -0
  41. package/src/components/tooltip/test/tool-tip.test.tsx +8 -6
  42. package/src/components/tooltip/test/tooltip-box.test.tsx +53 -0
  43. package/src/components/tooltip/test/xy-chart-tooltip-overlay.test.tsx +445 -0
  44. package/src/components/tooltip/test/xy-chart-tooltip.test.tsx +282 -365
  45. package/src/components/tooltip/{base-tooltip.module.scss → tooltip-box.module.scss} +5 -8
  46. package/src/components/tooltip/tooltip-box.tsx +43 -0
  47. package/src/components/tooltip/types.ts +7 -1
  48. package/src/components/tooltip/xy-chart-tooltip.tsx +410 -300
  49. package/src/hooks/test/use-chart-margin.test.tsx +8 -4
  50. package/src/hooks/use-chart-margin.tsx +21 -18
  51. package/src/index.ts +8 -3
  52. package/src/providers/chart-context/global-charts-provider.tsx +5 -14
  53. package/src/providers/chart-context/hooks/use-default-hidden-series.ts +1 -1
  54. package/src/providers/chart-context/private/catalog-pointers.ts +1 -0
  55. package/src/providers/chart-context/private/resolve-opaque-hex.ts +16 -0
  56. package/src/providers/chart-context/test/use-default-hidden-series.test.tsx +1 -1
  57. package/src/styles/chart-scope.scss +1 -0
  58. package/src/test-utils/zoned-parsing-suite.ts +0 -10
  59. package/src/utils/test/date-formatting.test.ts +0 -10
  60. package/src/components/tooltip/accessible-tooltip.tsx +0 -433
  61. package/src/components/tooltip/test/accessible-tooltip.test.tsx +0 -331
@@ -1,8 +1,7 @@
1
1
  // `.surface` is the look alone, for a chart that positions the box itself.
2
- // The box carries the chart scope class inside TooltipTheme, so these roles
2
+ // The box carries the tooltip scope class inside TooltipTheme, so these roles
3
3
  // resolve for the dark tooltip theme, as in @wordpress/ui's Tooltip popup.
4
- .surface,
5
- .tooltip {
4
+ .surface {
6
5
  padding: var(--wpds-dimension-padding-xs) var(--wpds-dimension-padding-sm);
7
6
  background-color: var(--a8c-charts-color-surface);
8
7
  color: var(--a8c-charts-color-label);
@@ -12,13 +11,11 @@
12
11
  line-height: 1.4;
13
12
  box-shadow: var(--a8c-charts-elevation-sm, 0 1px 2px 0 #0000000d, 0 2px 3px 0 #0000000a, 0 6px 6px 0 #00000008, 0 8px 8px 0 #00000005);
14
13
  pointer-events: none;
14
+ // Beats a host `max-width` on `.visx-tooltip`, even an `!important`
15
+ // one: WordPress.com's Help Center caps it at 150px.
16
+ min-width: fit-content;
15
17
 
16
18
  @media (forced-colors: active) {
17
19
  border: var(--wpds-border-width-xs) solid CanvasText;
18
20
  }
19
21
  }
20
-
21
- .tooltip {
22
- position: absolute;
23
- transform: translate(-50%, -100%);
24
- }
@@ -0,0 +1,43 @@
1
+ import clsx from 'clsx';
2
+ import { forwardRef } from 'react';
3
+ import { TOOLTIP_SCOPE_CLASS } from '../../styles/chart-scope-class';
4
+ import { TooltipTheme } from './private/tooltip-theme';
5
+ import styles from './tooltip-box.module.scss';
6
+ import type { HTMLAttributes } from 'react';
7
+
8
+ type TooltipBoxProps = HTMLAttributes< HTMLDivElement > & {
9
+ /** Drop the chart surface, scope class and dark theme, leaving a bare box. */
10
+ unstyled?: boolean;
11
+ };
12
+
13
+ /**
14
+ * The chart tooltip box: the dark surface every chart tooltip draws. It does not position itself; place it with `style` or a wrapper.
15
+ *
16
+ * @param props - Div attributes, plus `unstyled`.
17
+ * @param props.unstyled - Drop the surface, scope class and theme.
18
+ * @param ref - Forwarded to the box element.
19
+ * @return The tooltip box.
20
+ */
21
+ export const TooltipBox = forwardRef< HTMLDivElement, TooltipBoxProps >(
22
+ ( { unstyled = false, role = 'tooltip', className, children, ...rest }, ref ) => {
23
+ const box = (
24
+ <div
25
+ ref={ ref }
26
+ role={ role }
27
+ className={ clsx(
28
+ 'visx-tooltip',
29
+ ! unstyled && [ TOOLTIP_SCOPE_CLASS, styles.surface ],
30
+ className
31
+ ) }
32
+ { ...rest }
33
+ >
34
+ { children }
35
+ </div>
36
+ );
37
+ return unstyled ? box : <TooltipTheme>{ box }</TooltipTheme>;
38
+ }
39
+ );
40
+
41
+ TooltipBox.displayName = 'TooltipBox';
42
+
43
+ export type { TooltipBoxProps };
@@ -5,4 +5,10 @@ type TooltipProps = {
5
5
  };
6
6
  };
7
7
 
8
- export type { TooltipProps };
8
+ type TooltipData = {
9
+ label: string;
10
+ value: number;
11
+ valueDisplay?: string;
12
+ };
13
+
14
+ export type { TooltipProps, TooltipData };