@mui/x-charts 9.11.1 → 9.13.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 (124) hide show
  1. package/BarChart/BarChart.js +8 -1
  2. package/BarChart/BarChart.mjs +8 -1
  3. package/CHANGELOG.md +278 -0
  4. package/ChartsContainer/ChartsContainer.js +8 -1
  5. package/ChartsContainer/ChartsContainer.mjs +8 -1
  6. package/ChartsContainer/useChartsContainerProps.js +3 -1
  7. package/ChartsContainer/useChartsContainerProps.mjs +3 -1
  8. package/ChartsTooltip/ChartsAxisTooltipContent.js +2 -9
  9. package/ChartsTooltip/ChartsAxisTooltipContent.mjs +2 -9
  10. package/ChartsTooltip/ChartsItemTooltipContent.js +2 -2
  11. package/ChartsTooltip/ChartsItemTooltipContent.mjs +2 -2
  12. package/ChartsTooltip/ChartsTooltipContainer.js +6 -2
  13. package/ChartsTooltip/ChartsTooltipContainer.mjs +6 -2
  14. package/ChartsXAxis/useAxisTicksProps.js +2 -1
  15. package/ChartsXAxis/useAxisTicksProps.mjs +2 -1
  16. package/ChartsYAxis/shortenLabels.js +16 -26
  17. package/ChartsYAxis/shortenLabels.mjs +17 -27
  18. package/ChartsYAxis/useAxisTicksProps.js +2 -1
  19. package/ChartsYAxis/useAxisTicksProps.mjs +2 -1
  20. package/LineChart/CircleMarkElement.js +0 -4
  21. package/LineChart/CircleMarkElement.mjs +0 -4
  22. package/LineChart/LineChart.js +8 -1
  23. package/LineChart/LineChart.mjs +8 -1
  24. package/LineChart/MarkElement.js +13 -6
  25. package/LineChart/MarkElement.mjs +13 -6
  26. package/PieChart/PieChart.js +7 -0
  27. package/PieChart/PieChart.mjs +7 -0
  28. package/RadarChart/RadarChart.js +8 -1
  29. package/RadarChart/RadarChart.mjs +8 -1
  30. package/RadarChart/RadarSeriesPlot/RadarSeriesMarks.js +6 -2
  31. package/RadarChart/RadarSeriesPlot/RadarSeriesMarks.mjs +6 -2
  32. package/RadarChart/RadarSeriesPlot/RadarSeriesPlot.js +2 -1
  33. package/RadarChart/RadarSeriesPlot/RadarSeriesPlot.mjs +2 -1
  34. package/RadarChart/useRadarChartProps.js +3 -1
  35. package/RadarChart/useRadarChartProps.mjs +3 -1
  36. package/ScatterChart/ScatterChart.js +8 -1
  37. package/ScatterChart/ScatterChart.mjs +8 -1
  38. package/SparkLineChart/SparkLineChart.js +8 -1
  39. package/SparkLineChart/SparkLineChart.mjs +8 -1
  40. package/constants/index.d.mts +3 -1
  41. package/constants/index.d.ts +3 -1
  42. package/constants/index.js +5 -2
  43. package/constants/index.mjs +4 -1
  44. package/hooks/animation/index.d.mts +1 -0
  45. package/hooks/animation/index.d.ts +1 -0
  46. package/hooks/animation/index.js +11 -0
  47. package/hooks/animation/index.mjs +1 -0
  48. package/hooks/animation/useAnimateMark.d.mts +25 -0
  49. package/hooks/animation/useAnimateMark.d.ts +25 -0
  50. package/hooks/animation/useAnimateMark.js +45 -0
  51. package/hooks/animation/useAnimateMark.mjs +39 -0
  52. package/hooks/useInteractionItemProps.js +4 -0
  53. package/hooks/useInteractionItemProps.mjs +4 -0
  54. package/index.js +1 -1
  55. package/index.mjs +1 -1
  56. package/internals/components/ChartsAccessibilityProxy/ChartsAccessibilityProxy.js +13 -3
  57. package/internals/components/ChartsAccessibilityProxy/ChartsAccessibilityProxy.mjs +12 -3
  58. package/internals/components/ChartsAccessibilityProxy/focusAccessibilityProxy.d.mts +8 -0
  59. package/internals/components/ChartsAccessibilityProxy/focusAccessibilityProxy.d.ts +8 -0
  60. package/internals/components/ChartsAccessibilityProxy/focusAccessibilityProxy.js +25 -0
  61. package/internals/components/ChartsAccessibilityProxy/focusAccessibilityProxy.mjs +19 -0
  62. package/internals/components/ChartsAccessibilityProxy/index.d.mts +2 -1
  63. package/internals/components/ChartsAccessibilityProxy/index.d.ts +2 -1
  64. package/internals/components/ChartsAccessibilityProxy/index.js +11 -0
  65. package/internals/components/ChartsAccessibilityProxy/index.mjs +2 -1
  66. package/internals/domUtils.js +17 -16
  67. package/internals/domUtils.mjs +17 -15
  68. package/internals/ellipsize.d.mts +30 -0
  69. package/internals/ellipsize.d.ts +30 -0
  70. package/internals/ellipsize.js +60 -0
  71. package/internals/ellipsize.mjs +59 -0
  72. package/internals/index.d.mts +1 -0
  73. package/internals/index.d.ts +1 -0
  74. package/internals/index.js +8 -0
  75. package/internals/index.mjs +1 -0
  76. package/internals/plugins/corePlugins/useChartElementRef/useChartElementRef.js +3 -1
  77. package/internals/plugins/corePlugins/useChartElementRef/useChartElementRef.mjs +3 -1
  78. package/internals/plugins/corePlugins/useChartElementRef/useChartElementRef.types.d.mts +5 -0
  79. package/internals/plugins/corePlugins/useChartElementRef/useChartElementRef.types.d.ts +5 -0
  80. package/internals/plugins/featurePlugins/shared/useRegisterPointerInteractions.js +10 -0
  81. package/internals/plugins/featurePlugins/shared/useRegisterPointerInteractions.mjs +10 -0
  82. package/internals/plugins/featurePlugins/useChartCartesianAxis/computeAxisAutoSize.d.mts +3 -0
  83. package/internals/plugins/featurePlugins/useChartCartesianAxis/computeAxisAutoSize.d.ts +3 -0
  84. package/internals/plugins/featurePlugins/useChartCartesianAxis/computeAxisAutoSize.js +9 -5
  85. package/internals/plugins/featurePlugins/useChartCartesianAxis/computeAxisAutoSize.mjs +9 -5
  86. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartAxisAutoSize.selectors.js +9 -4
  87. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartAxisAutoSize.selectors.mjs +9 -4
  88. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxis.js +75 -3
  89. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxis.mjs +76 -3
  90. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxis.types.d.mts +6 -2
  91. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxis.types.d.ts +6 -2
  92. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisLayout.selectors.d.mts +1 -0
  93. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisLayout.selectors.d.ts +1 -0
  94. package/internals/plugins/featurePlugins/useChartClosestPoint/useChartClosestPoint.js +22 -0
  95. package/internals/plugins/featurePlugins/useChartClosestPoint/useChartClosestPoint.mjs +22 -0
  96. package/internals/plugins/featurePlugins/useChartInteraction/useChartInteraction.js +27 -1
  97. package/internals/plugins/featurePlugins/useChartInteraction/useChartInteraction.mjs +27 -1
  98. package/internals/plugins/featurePlugins/useChartInteraction/useChartInteraction.types.d.mts +20 -0
  99. package/internals/plugins/featurePlugins/useChartInteraction/useChartInteraction.types.d.ts +20 -0
  100. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.js +242 -35
  101. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.mjs +244 -36
  102. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.selectors.d.mts +3 -0
  103. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.selectors.d.ts +3 -0
  104. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.selectors.js +12 -5
  105. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.selectors.mjs +11 -4
  106. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.types.d.mts +29 -0
  107. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.types.d.ts +29 -0
  108. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/utils/getItemAtAxisPosition.d.mts +28 -0
  109. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/utils/getItemAtAxisPosition.d.ts +28 -0
  110. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/utils/getItemAtAxisPosition.js +81 -0
  111. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/utils/getItemAtAxisPosition.mjs +76 -0
  112. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/utils/getItemAtRotationIndex.d.mts +18 -0
  113. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/utils/getItemAtRotationIndex.d.ts +18 -0
  114. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/utils/getItemAtRotationIndex.js +65 -0
  115. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/utils/getItemAtRotationIndex.mjs +60 -0
  116. package/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarAxis.js +43 -1
  117. package/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarAxis.mjs +43 -1
  118. package/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarAxis.types.d.mts +3 -2
  119. package/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarAxis.types.d.ts +3 -2
  120. package/internals/useDefaultTickLabelStyle.d.mts +7 -0
  121. package/internals/useDefaultTickLabelStyle.d.ts +7 -0
  122. package/internals/useDefaultTickLabelStyle.js +34 -0
  123. package/internals/useDefaultTickLabelStyle.mjs +28 -0
  124. package/package.json +6 -6
@@ -1,3 +1,4 @@
1
+ import type { ChartsTextAnchor, ChartsTextBaseline } from "./getWordsByLines.js";
1
2
  interface EllipsizeConfig {
2
3
  width: number;
3
4
  height: number;
@@ -9,6 +10,35 @@ interface EllipsizeConfig {
9
10
  };
10
11
  }
11
12
  export declare function doesTextFitInRect(text: string, config: EllipsizeConfig): boolean;
13
+ export interface RotatedTextBoundsConfig {
14
+ /** Angle, in degrees, in which the text is displayed. */
15
+ angle: number;
16
+ textAnchor?: ChartsTextAnchor;
17
+ dominantBaseline?: ChartsTextBaseline;
18
+ isRtl?: boolean;
19
+ }
20
+ export interface RotatedTextBounds {
21
+ /** Width of the text bounding box once rotated. */
22
+ width: number;
23
+ /** How far the text extends above its anchor point. */
24
+ above: number;
25
+ /** How far the text extends below its anchor point. */
26
+ below: number;
27
+ }
28
+ /**
29
+ * Returns the size of a rotated text, and how far it extends on each side of its anchor point.
30
+ *
31
+ * Which side of the anchor the text is drawn on depends on both the text anchoring and the rotation,
32
+ * so `above` and `below` are not necessarily equal. Either of them is negative when the whole text
33
+ * sits on the other side of the anchor point.
34
+ *
35
+ * @param textSize The size of the text before rotation.
36
+ * @param config How the text is anchored and rotated.
37
+ */
38
+ export declare function getRotatedTextBounds(textSize: {
39
+ width: number;
40
+ height: number;
41
+ }, config: RotatedTextBoundsConfig): RotatedTextBounds;
12
42
  /** This function finds the best place to clip the text to add an ellipsis.
13
43
  * This function assumes that the {@link doesTextFit} never returns true for longer text after returning false for
14
44
  * shorter text.
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.doesTextFitInRect = doesTextFitInRect;
7
7
  exports.ellipsize = ellipsize;
8
+ exports.getRotatedTextBounds = getRotatedTextBounds;
8
9
  var _getGraphemeCount = require("./getGraphemeCount");
9
10
  var _degToRad = require("./degToRad");
10
11
  var _sliceUntil = require("./sliceUntil");
@@ -22,6 +23,65 @@ function doesTextFitInRect(text, config) {
22
23
  return angledWidth <= width && angledHeight <= height;
23
24
  }
24
25
 
26
+ /**
27
+ * Position of the text bounding box relative to its anchor point, as a fraction of the text width.
28
+ * `0` means the box starts at the anchor, `-1` that it ends there.
29
+ */
30
+ function getHorizontalAnchorOffset(textAnchor, isRtl) {
31
+ const anchor = textAnchor ?? 'middle';
32
+ if (anchor === 'middle') {
33
+ return -1 / 2;
34
+ }
35
+ const startsAtAnchor = isRtl ? anchor === 'end' : anchor === 'start';
36
+ return startsAtAnchor ? 0 : -1;
37
+ }
38
+
39
+ /**
40
+ * Position of the text bounding box relative to its anchor point, as a fraction of the text height.
41
+ * `0` means the box starts at the anchor, `-1` that it ends there.
42
+ */
43
+ function getVerticalAnchorOffset(dominantBaseline) {
44
+ switch (dominantBaseline ?? 'central') {
45
+ case 'hanging':
46
+ case 'text-before-edge':
47
+ return 0;
48
+ case 'central':
49
+ return -1 / 2;
50
+ default:
51
+ return -1;
52
+ }
53
+ }
54
+ /**
55
+ * Returns the size of a rotated text, and how far it extends on each side of its anchor point.
56
+ *
57
+ * Which side of the anchor the text is drawn on depends on both the text anchoring and the rotation,
58
+ * so `above` and `below` are not necessarily equal. Either of them is negative when the whole text
59
+ * sits on the other side of the anchor point.
60
+ *
61
+ * @param textSize The size of the text before rotation.
62
+ * @param config How the text is anchored and rotated.
63
+ */
64
+ function getRotatedTextBounds(textSize, config) {
65
+ const angle = (0, _degToRad.degToRad)(config.angle);
66
+ const sin = Math.sin(angle);
67
+ const cos = Math.cos(angle);
68
+ const left = getHorizontalAnchorOffset(config.textAnchor, config.isRtl ?? false) * textSize.width;
69
+ const right = left + textSize.width;
70
+ const top = getVerticalAnchorOffset(config.dominantBaseline) * textSize.height;
71
+ const bottom = top + textSize.height;
72
+
73
+ /* A rotation by `angle` maps a point to `(x * cos - y * sin, x * sin + y * cos)`. Both terms of
74
+ * the vertical coordinate are independent, so the extrema of their sum are the sums of their
75
+ * extrema. */
76
+ const fromWidth = [left * sin, right * sin];
77
+ const fromHeight = [top * cos, bottom * cos];
78
+ return {
79
+ width: Math.abs(textSize.width * cos) + Math.abs(textSize.height * sin),
80
+ above: -(Math.min(...fromWidth) + Math.min(...fromHeight)),
81
+ below: Math.max(...fromWidth) + Math.max(...fromHeight)
82
+ };
83
+ }
84
+
25
85
  /** This function finds the best place to clip the text to add an ellipsis.
26
86
  * This function assumes that the {@link doesTextFit} never returns true for longer text after returning false for
27
87
  * shorter text.
@@ -15,6 +15,65 @@ export function doesTextFitInRect(text, config) {
15
15
  return angledWidth <= width && angledHeight <= height;
16
16
  }
17
17
 
18
+ /**
19
+ * Position of the text bounding box relative to its anchor point, as a fraction of the text width.
20
+ * `0` means the box starts at the anchor, `-1` that it ends there.
21
+ */
22
+ function getHorizontalAnchorOffset(textAnchor, isRtl) {
23
+ const anchor = textAnchor ?? 'middle';
24
+ if (anchor === 'middle') {
25
+ return -1 / 2;
26
+ }
27
+ const startsAtAnchor = isRtl ? anchor === 'end' : anchor === 'start';
28
+ return startsAtAnchor ? 0 : -1;
29
+ }
30
+
31
+ /**
32
+ * Position of the text bounding box relative to its anchor point, as a fraction of the text height.
33
+ * `0` means the box starts at the anchor, `-1` that it ends there.
34
+ */
35
+ function getVerticalAnchorOffset(dominantBaseline) {
36
+ switch (dominantBaseline ?? 'central') {
37
+ case 'hanging':
38
+ case 'text-before-edge':
39
+ return 0;
40
+ case 'central':
41
+ return -1 / 2;
42
+ default:
43
+ return -1;
44
+ }
45
+ }
46
+ /**
47
+ * Returns the size of a rotated text, and how far it extends on each side of its anchor point.
48
+ *
49
+ * Which side of the anchor the text is drawn on depends on both the text anchoring and the rotation,
50
+ * so `above` and `below` are not necessarily equal. Either of them is negative when the whole text
51
+ * sits on the other side of the anchor point.
52
+ *
53
+ * @param textSize The size of the text before rotation.
54
+ * @param config How the text is anchored and rotated.
55
+ */
56
+ export function getRotatedTextBounds(textSize, config) {
57
+ const angle = degToRad(config.angle);
58
+ const sin = Math.sin(angle);
59
+ const cos = Math.cos(angle);
60
+ const left = getHorizontalAnchorOffset(config.textAnchor, config.isRtl ?? false) * textSize.width;
61
+ const right = left + textSize.width;
62
+ const top = getVerticalAnchorOffset(config.dominantBaseline) * textSize.height;
63
+ const bottom = top + textSize.height;
64
+
65
+ /* A rotation by `angle` maps a point to `(x * cos - y * sin, x * sin + y * cos)`. Both terms of
66
+ * the vertical coordinate are independent, so the extrema of their sum are the sums of their
67
+ * extrema. */
68
+ const fromWidth = [left * sin, right * sin];
69
+ const fromHeight = [top * cos, bottom * cos];
70
+ return {
71
+ width: Math.abs(textSize.width * cos) + Math.abs(textSize.height * sin),
72
+ above: -(Math.min(...fromWidth) + Math.min(...fromHeight)),
73
+ below: Math.max(...fromWidth) + Math.max(...fromHeight)
74
+ };
75
+ }
76
+
18
77
  /** This function finds the best place to clip the text to add an ellipsis.
19
78
  * This function assumes that the {@link doesTextFit} never returns true for longer text after returning false for
20
79
  * shorter text.
@@ -83,6 +83,7 @@ export { processLineLikeSeries } from "./processLineLikeSeries.mjs";
83
83
  export { getLineLikeTooltip } from "./getLineLikeTooltip.mjs";
84
84
  export { checkBarChartScaleErrors } from "../BarChart/checkBarChartScaleErrors.mjs";
85
85
  export { getBandSize } from "./getBandSize.mjs";
86
+ export { useDefaultTickLabelStyle } from "./useDefaultTickLabelStyle.mjs";
86
87
  export * from "./plugins/utils/defaultSeriesConfig.mjs";
87
88
  export { EPSILON } from "../utils/epsilon.mjs";
88
89
  export { useUtilityClasses as useChartsTooltipUtilityClasses, getChartsTooltipUtilityClass } from "../ChartsTooltip/chartsTooltipClasses.mjs";
@@ -83,6 +83,7 @@ export { processLineLikeSeries } from "./processLineLikeSeries.js";
83
83
  export { getLineLikeTooltip } from "./getLineLikeTooltip.js";
84
84
  export { checkBarChartScaleErrors } from "../BarChart/checkBarChartScaleErrors.js";
85
85
  export { getBandSize } from "./getBandSize.js";
86
+ export { useDefaultTickLabelStyle } from "./useDefaultTickLabelStyle.js";
86
87
  export * from "./plugins/utils/defaultSeriesConfig.js";
87
88
  export { EPSILON } from "../utils/epsilon.js";
88
89
  export { useUtilityClasses as useChartsTooltipUtilityClasses, getChartsTooltipUtilityClass } from "../ChartsTooltip/chartsTooltipClasses.js";
@@ -30,6 +30,7 @@ var _exportNames = {
30
30
  getLineLikeTooltip: true,
31
31
  checkBarChartScaleErrors: true,
32
32
  getBandSize: true,
33
+ useDefaultTickLabelStyle: true,
33
34
  EPSILON: true,
34
35
  useChartsTooltipUtilityClasses: true,
35
36
  getChartsTooltipUtilityClass: true,
@@ -157,6 +158,12 @@ Object.defineProperty(exports, "useChartsTooltipUtilityClasses", {
157
158
  return _chartsTooltipClasses.useUtilityClasses;
158
159
  }
159
160
  });
161
+ Object.defineProperty(exports, "useDefaultTickLabelStyle", {
162
+ enumerable: true,
163
+ get: function () {
164
+ return _useDefaultTickLabelStyle.useDefaultTickLabelStyle;
165
+ }
166
+ });
160
167
  Object.defineProperty(exports, "useDrawingArea", {
161
168
  enumerable: true,
162
169
  get: function () {
@@ -967,6 +974,7 @@ var _processLineLikeSeries = require("./processLineLikeSeries");
967
974
  var _getLineLikeTooltip = require("./getLineLikeTooltip");
968
975
  var _checkBarChartScaleErrors = require("../BarChart/checkBarChartScaleErrors");
969
976
  var _getBandSize = require("./getBandSize");
977
+ var _useDefaultTickLabelStyle = require("./useDefaultTickLabelStyle");
970
978
  var _defaultSeriesConfig = require("./plugins/utils/defaultSeriesConfig");
971
979
  Object.keys(_defaultSeriesConfig).forEach(function (key) {
972
980
  if (key === "default" || key === "__esModule") return;
@@ -91,6 +91,7 @@ export { processLineLikeSeries } from "./processLineLikeSeries.mjs";
91
91
  export { getLineLikeTooltip } from "./getLineLikeTooltip.mjs";
92
92
  export { checkBarChartScaleErrors } from "../BarChart/checkBarChartScaleErrors.mjs";
93
93
  export { getBandSize } from "./getBandSize.mjs";
94
+ export { useDefaultTickLabelStyle } from "./useDefaultTickLabelStyle.mjs";
94
95
  export * from "./plugins/utils/defaultSeriesConfig.mjs";
95
96
  export { EPSILON } from "../utils/epsilon.mjs";
96
97
  export { useUtilityClasses as useChartsTooltipUtilityClasses, getChartsTooltipUtilityClass } from "../ChartsTooltip/chartsTooltipClasses.mjs";
@@ -10,10 +10,12 @@ var React = _interopRequireWildcard(require("react"));
10
10
  const useChartElementRef = () => {
11
11
  const chartsLayerContainerRef = React.useRef(null);
12
12
  const chartRootRef = React.useRef(null);
13
+ const chartsAccessibilityProxyRef = React.useRef(null);
13
14
  return {
14
15
  instance: {
15
16
  chartsLayerContainerRef,
16
- chartRootRef
17
+ chartRootRef,
18
+ chartsAccessibilityProxyRef
17
19
  }
18
20
  };
19
21
  };
@@ -4,10 +4,12 @@ import * as React from 'react';
4
4
  export const useChartElementRef = () => {
5
5
  const chartsLayerContainerRef = React.useRef(null);
6
6
  const chartRootRef = React.useRef(null);
7
+ const chartsAccessibilityProxyRef = React.useRef(null);
7
8
  return {
8
9
  instance: {
9
10
  chartsLayerContainerRef,
10
- chartRootRef
11
+ chartRootRef,
12
+ chartsAccessibilityProxyRef
11
13
  }
12
14
  };
13
15
  };
@@ -9,6 +9,11 @@ export interface UseChartElementRefInstance {
9
9
  * Reference to the chart root element.
10
10
  */
11
11
  chartRootRef: React.RefObject<Element | null>;
12
+ /**
13
+ * Reference to the root of the accessibility proxy, the element owning the chart tab stop.
14
+ * It is `null` when keyboard navigation is disabled.
15
+ */
16
+ chartsAccessibilityProxyRef: React.RefObject<HTMLDivElement | null>;
12
17
  }
13
18
  export type UseChartElementRefSignature = ChartPluginSignature<{
14
19
  instance: UseChartElementRefInstance;
@@ -9,6 +9,11 @@ export interface UseChartElementRefInstance {
9
9
  * Reference to the chart root element.
10
10
  */
11
11
  chartRootRef: React.RefObject<Element | null>;
12
+ /**
13
+ * Reference to the root of the accessibility proxy, the element owning the chart tab stop.
14
+ * It is `null` when keyboard navigation is disabled.
15
+ */
16
+ chartsAccessibilityProxyRef: React.RefObject<HTMLDivElement | null>;
12
17
  }
13
18
  export type UseChartElementRefSignature = ChartPluginSignature<{
14
19
  instance: UseChartElementRefInstance;
@@ -40,6 +40,7 @@ function useRegisterPointerInteractions() {
40
40
  const lastItem = lastItemRef.current;
41
41
  if (lastItem) {
42
42
  lastItemRef.current = undefined;
43
+ instance.clearHoveredItem(lastItem);
43
44
  instance.removeTooltipItem(lastItem);
44
45
  instance.clearHighlight();
45
46
  }
@@ -66,6 +67,7 @@ function useRegisterPointerInteractions() {
66
67
  }
67
68
  if (item) {
68
69
  instance.setLastUpdateSource('pointer');
70
+ instance.setHoveredItem(item);
69
71
  instance.setTooltipItem(item);
70
72
  instance.setHighlight(item);
71
73
  lastItemRef.current = item;
@@ -73,10 +75,18 @@ function useRegisterPointerInteractions() {
73
75
  reset();
74
76
  }
75
77
  };
78
+
79
+ // Touch has no hover phase, so a tap may never produce a `pointermove`. Resolving on
80
+ // `pointerdown` too is what makes the pointer item known for a stationary tap.
81
+ const onPointerDown = function onPointerDown(event) {
82
+ onPointerMove(event);
83
+ };
84
+ element.addEventListener('pointerdown', onPointerDown);
76
85
  element.addEventListener('pointerleave', onPointerLeave);
77
86
  element.addEventListener('pointermove', onPointerMove);
78
87
  element.addEventListener('pointerenter', onPointerEnter);
79
88
  return () => {
89
+ element.removeEventListener('pointerdown', onPointerDown);
80
90
  element.removeEventListener('pointerenter', onPointerEnter);
81
91
  element.removeEventListener('pointermove', onPointerMove);
82
92
  element.removeEventListener('pointerleave', onPointerLeave);
@@ -34,6 +34,7 @@ export function useRegisterPointerInteractions() {
34
34
  const lastItem = lastItemRef.current;
35
35
  if (lastItem) {
36
36
  lastItemRef.current = undefined;
37
+ instance.clearHoveredItem(lastItem);
37
38
  instance.removeTooltipItem(lastItem);
38
39
  instance.clearHighlight();
39
40
  }
@@ -60,6 +61,7 @@ export function useRegisterPointerInteractions() {
60
61
  }
61
62
  if (item) {
62
63
  instance.setLastUpdateSource('pointer');
64
+ instance.setHoveredItem(item);
63
65
  instance.setTooltipItem(item);
64
66
  instance.setHighlight(item);
65
67
  lastItemRef.current = item;
@@ -67,10 +69,18 @@ export function useRegisterPointerInteractions() {
67
69
  reset();
68
70
  }
69
71
  };
72
+
73
+ // Touch has no hover phase, so a tap may never produce a `pointermove`. Resolving on
74
+ // `pointerdown` too is what makes the pointer item known for a stationary tap.
75
+ const onPointerDown = function onPointerDown(event) {
76
+ onPointerMove(event);
77
+ };
78
+ element.addEventListener('pointerdown', onPointerDown);
70
79
  element.addEventListener('pointerleave', onPointerLeave);
71
80
  element.addEventListener('pointermove', onPointerMove);
72
81
  element.addEventListener('pointerenter', onPointerEnter);
73
82
  return () => {
83
+ element.removeEventListener('pointerdown', onPointerDown);
74
84
  element.removeEventListener('pointerenter', onPointerEnter);
75
85
  element.removeEventListener('pointermove', onPointerMove);
76
86
  element.removeEventListener('pointerleave', onPointerLeave);
@@ -1,4 +1,5 @@
1
1
  import type { DefaultedXAxis, DefaultedYAxis } from "../../../../models/axis.mjs";
2
+ import type { ChartsTextStyle } from "../../../getWordsByLines.mjs";
2
3
  import type { DomainDefinition } from "./domain.mjs";
3
4
  interface ComputeAxisAutoSizeOptions {
4
5
  axis: DefaultedXAxis | DefaultedYAxis;
@@ -9,6 +10,8 @@ interface ComputeAxisAutoSizeOptions {
9
10
  * so tick labels measured from them match what the chart renders.
10
11
  */
11
12
  domain?: DomainDefinition;
13
+ /** Font the ticks render with, used only for measuring. */
14
+ defaultTickLabelStyle?: ChartsTextStyle;
12
15
  }
13
16
  /**
14
17
  * Result of auto-size computation for axes.
@@ -1,4 +1,5 @@
1
1
  import type { DefaultedXAxis, DefaultedYAxis } from "../../../../models/axis.js";
2
+ import type { ChartsTextStyle } from "../../../getWordsByLines.js";
2
3
  import type { DomainDefinition } from "./domain.js";
3
4
  interface ComputeAxisAutoSizeOptions {
4
5
  axis: DefaultedXAxis | DefaultedYAxis;
@@ -9,6 +10,8 @@ interface ComputeAxisAutoSizeOptions {
9
10
  * so tick labels measured from them match what the chart renders.
10
11
  */
11
12
  domain?: DomainDefinition;
13
+ /** Font the ticks render with, used only for measuring. */
14
+ defaultTickLabelStyle?: ChartsTextStyle;
12
15
  }
13
16
  /**
14
17
  * Result of auto-size computation for axes.
@@ -219,7 +219,7 @@ function getRotatedDimension(width, height, angle, direction) {
219
219
  *
220
220
  * Returns both the total size and the computed tick sizes for each group level.
221
221
  */
222
- function computeGroupedAxisAutoSize(axis, direction) {
222
+ function computeGroupedAxisAutoSize(axis, direction, defaultTickLabelStyle) {
223
223
  const {
224
224
  groups,
225
225
  data,
@@ -238,7 +238,7 @@ function computeGroupedAxisAutoSize(axis, direction) {
238
238
  for (let groupIndex = 0; groupIndex < groups.length; groupIndex += 1) {
239
239
  const group = groups[groupIndex];
240
240
  const groupLabels = selectLargestCandidates(getGroupLabels(data, group));
241
- const groupTickLabelStyle = (0, _extends2.default)({}, axisTickLabelStyle, group.tickLabelStyle);
241
+ const groupTickLabelStyle = (0, _extends2.default)({}, defaultTickLabelStyle, axisTickLabelStyle, group.tickLabelStyle);
242
242
  const angle = groupTickLabelStyle?.angle;
243
243
  const {
244
244
  maxWidth,
@@ -284,12 +284,16 @@ function computeAxisAutoSize(options) {
284
284
  const {
285
285
  axis,
286
286
  direction,
287
- domain
287
+ domain,
288
+ defaultTickLabelStyle
288
289
  } = options;
289
290
  if (hasGroups(axis)) {
290
- return computeGroupedAxisAutoSize(axis, direction);
291
+ return computeGroupedAxisAutoSize(axis, direction, defaultTickLabelStyle);
291
292
  }
292
- const tickLabelStyle = axis.tickLabelStyle;
293
+
294
+ // Measure with the font the ticks render with. `axis.tickLabelStyle` only holds what the user set,
295
+ // so on its own the measurement element would inherit the document font instead.
296
+ const tickLabelStyle = (0, _extends2.default)({}, defaultTickLabelStyle, axis.tickLabelStyle);
293
297
  const tickSize = axis.tickSize ?? _autoSizeConstants.AXIS_AUTO_SIZE_TICK_SIZE;
294
298
  const hasLabel = Boolean(axis.label);
295
299
  const angle = tickLabelStyle?.angle;
@@ -212,7 +212,7 @@ function getRotatedDimension(width, height, angle, direction) {
212
212
  *
213
213
  * Returns both the total size and the computed tick sizes for each group level.
214
214
  */
215
- function computeGroupedAxisAutoSize(axis, direction) {
215
+ function computeGroupedAxisAutoSize(axis, direction, defaultTickLabelStyle) {
216
216
  const {
217
217
  groups,
218
218
  data,
@@ -231,7 +231,7 @@ function computeGroupedAxisAutoSize(axis, direction) {
231
231
  for (let groupIndex = 0; groupIndex < groups.length; groupIndex += 1) {
232
232
  const group = groups[groupIndex];
233
233
  const groupLabels = selectLargestCandidates(getGroupLabels(data, group));
234
- const groupTickLabelStyle = _extends({}, axisTickLabelStyle, group.tickLabelStyle);
234
+ const groupTickLabelStyle = _extends({}, defaultTickLabelStyle, axisTickLabelStyle, group.tickLabelStyle);
235
235
  const angle = groupTickLabelStyle?.angle;
236
236
  const {
237
237
  maxWidth,
@@ -277,12 +277,16 @@ export function computeAxisAutoSize(options) {
277
277
  const {
278
278
  axis,
279
279
  direction,
280
- domain
280
+ domain,
281
+ defaultTickLabelStyle
281
282
  } = options;
282
283
  if (hasGroups(axis)) {
283
- return computeGroupedAxisAutoSize(axis, direction);
284
+ return computeGroupedAxisAutoSize(axis, direction, defaultTickLabelStyle);
284
285
  }
285
- const tickLabelStyle = axis.tickLabelStyle;
286
+
287
+ // Measure with the font the ticks render with. `axis.tickLabelStyle` only holds what the user set,
288
+ // so on its own the measurement element would inherit the document font instead.
289
+ const tickLabelStyle = _extends({}, defaultTickLabelStyle, axis.tickLabelStyle);
286
290
  const tickSize = axis.tickSize ?? AXIS_AUTO_SIZE_TICK_SIZE;
287
291
  const hasLabel = Boolean(axis.label);
288
292
  const angle = tickLabelStyle?.angle;
@@ -10,6 +10,9 @@ var _computeAxisAutoSize = require("./computeAxisAutoSize");
10
10
  var _useChartAxisDomains = require("./useChartAxisDomains.selectors");
11
11
  // Direct state access to avoid circular dependency
12
12
  const selectorIsHydrated = state => state.dimensions.width && state.dimensions.height;
13
+
14
+ // Direct state access to avoid circular dependency
15
+ const selectorDefaultTickLabelStyle = state => state.cartesianAxis?.defaultTickLabelStyle;
13
16
  const EMPTY_SIZES = {};
14
17
  const EMPTY_RESULTS = {};
15
18
 
@@ -17,7 +20,7 @@ const EMPTY_RESULTS = {};
17
20
  * Selector that computes full auto-size results for X axes that have `height: 'auto'`.
18
21
  * Returns a map of axis ID to full result (including group tick sizes for grouped axes).
19
22
  */
20
- const selectorChartXAxisAutoSizeResults = exports.selectorChartXAxisAutoSizeResults = (0, _store.createSelectorMemoized)(_useChartCartesianAxisLayout.selectorChartRawXAxis, selectorIsHydrated, _useChartAxisDomains.selectorChartXAxisDomainsForAutoSize, function selectorChartXAxisAutoSizeResults(xAxes, isHydrated, domainsMap) {
23
+ const selectorChartXAxisAutoSizeResults = exports.selectorChartXAxisAutoSizeResults = (0, _store.createSelectorMemoized)(_useChartCartesianAxisLayout.selectorChartRawXAxis, selectorIsHydrated, _useChartAxisDomains.selectorChartXAxisDomainsForAutoSize, selectorDefaultTickLabelStyle, function selectorChartXAxisAutoSizeResults(xAxes, isHydrated, domainsMap, defaultTickLabelStyle) {
21
24
  const hasAutoAxis = xAxes?.some(axis => axis.height === 'auto');
22
25
  if (!hasAutoAxis || !isHydrated) {
23
26
  return EMPTY_RESULTS;
@@ -29,7 +32,8 @@ const selectorChartXAxisAutoSizeResults = exports.selectorChartXAxisAutoSizeResu
29
32
  const computed = (0, _computeAxisAutoSize.computeAxisAutoSize)({
30
33
  axis,
31
34
  direction: 'x',
32
- domain: domainsMap[axis.id]
35
+ domain: domainsMap[axis.id],
36
+ defaultTickLabelStyle
33
37
  });
34
38
  if (computed !== undefined) {
35
39
  results[axis.id] = computed;
@@ -58,7 +62,7 @@ const selectorChartXAxisAutoSizes = exports.selectorChartXAxisAutoSizes = (0, _s
58
62
  * Selector that computes full auto-size results for Y axes that have `width: 'auto'`.
59
63
  * Returns a map of axis ID to full result (including group tick sizes for grouped axes).
60
64
  */
61
- const selectorChartYAxisAutoSizeResults = exports.selectorChartYAxisAutoSizeResults = (0, _store.createSelectorMemoized)(_useChartCartesianAxisLayout.selectorChartRawYAxis, selectorIsHydrated, _useChartAxisDomains.selectorChartYAxisDomainsForAutoSize, function selectorChartYAxisAutoSizeResults(yAxes, isHydrated, domainsMap) {
65
+ const selectorChartYAxisAutoSizeResults = exports.selectorChartYAxisAutoSizeResults = (0, _store.createSelectorMemoized)(_useChartCartesianAxisLayout.selectorChartRawYAxis, selectorIsHydrated, _useChartAxisDomains.selectorChartYAxisDomainsForAutoSize, selectorDefaultTickLabelStyle, function selectorChartYAxisAutoSizeResults(yAxes, isHydrated, domainsMap, defaultTickLabelStyle) {
62
66
  const hasAutoAxis = yAxes?.some(axis => axis.width === 'auto');
63
67
  if (!hasAutoAxis || !isHydrated) {
64
68
  return EMPTY_RESULTS;
@@ -70,7 +74,8 @@ const selectorChartYAxisAutoSizeResults = exports.selectorChartYAxisAutoSizeResu
70
74
  const computed = (0, _computeAxisAutoSize.computeAxisAutoSize)({
71
75
  axis,
72
76
  direction: 'y',
73
- domain: domainsMap[axis.id]
77
+ domain: domainsMap[axis.id],
78
+ defaultTickLabelStyle
74
79
  });
75
80
  if (computed !== undefined) {
76
81
  results[axis.id] = computed;
@@ -5,6 +5,9 @@ import { selectorChartXAxisDomainsForAutoSize, selectorChartYAxisDomainsForAutoS
5
5
 
6
6
  // Direct state access to avoid circular dependency
7
7
  const selectorIsHydrated = state => state.dimensions.width && state.dimensions.height;
8
+
9
+ // Direct state access to avoid circular dependency
10
+ const selectorDefaultTickLabelStyle = state => state.cartesianAxis?.defaultTickLabelStyle;
8
11
  const EMPTY_SIZES = {};
9
12
  const EMPTY_RESULTS = {};
10
13
 
@@ -12,7 +15,7 @@ const EMPTY_RESULTS = {};
12
15
  * Selector that computes full auto-size results for X axes that have `height: 'auto'`.
13
16
  * Returns a map of axis ID to full result (including group tick sizes for grouped axes).
14
17
  */
15
- export const selectorChartXAxisAutoSizeResults = createSelectorMemoized(selectorChartRawXAxis, selectorIsHydrated, selectorChartXAxisDomainsForAutoSize, function selectorChartXAxisAutoSizeResults(xAxes, isHydrated, domainsMap) {
18
+ export const selectorChartXAxisAutoSizeResults = createSelectorMemoized(selectorChartRawXAxis, selectorIsHydrated, selectorChartXAxisDomainsForAutoSize, selectorDefaultTickLabelStyle, function selectorChartXAxisAutoSizeResults(xAxes, isHydrated, domainsMap, defaultTickLabelStyle) {
16
19
  const hasAutoAxis = xAxes?.some(axis => axis.height === 'auto');
17
20
  if (!hasAutoAxis || !isHydrated) {
18
21
  return EMPTY_RESULTS;
@@ -24,7 +27,8 @@ export const selectorChartXAxisAutoSizeResults = createSelectorMemoized(selector
24
27
  const computed = computeAxisAutoSize({
25
28
  axis,
26
29
  direction: 'x',
27
- domain: domainsMap[axis.id]
30
+ domain: domainsMap[axis.id],
31
+ defaultTickLabelStyle
28
32
  });
29
33
  if (computed !== undefined) {
30
34
  results[axis.id] = computed;
@@ -53,7 +57,7 @@ export const selectorChartXAxisAutoSizes = createSelectorMemoized(selectorChartX
53
57
  * Selector that computes full auto-size results for Y axes that have `width: 'auto'`.
54
58
  * Returns a map of axis ID to full result (including group tick sizes for grouped axes).
55
59
  */
56
- export const selectorChartYAxisAutoSizeResults = createSelectorMemoized(selectorChartRawYAxis, selectorIsHydrated, selectorChartYAxisDomainsForAutoSize, function selectorChartYAxisAutoSizeResults(yAxes, isHydrated, domainsMap) {
60
+ export const selectorChartYAxisAutoSizeResults = createSelectorMemoized(selectorChartRawYAxis, selectorIsHydrated, selectorChartYAxisDomainsForAutoSize, selectorDefaultTickLabelStyle, function selectorChartYAxisAutoSizeResults(yAxes, isHydrated, domainsMap, defaultTickLabelStyle) {
57
61
  const hasAutoAxis = yAxes?.some(axis => axis.width === 'auto');
58
62
  if (!hasAutoAxis || !isHydrated) {
59
63
  return EMPTY_RESULTS;
@@ -65,7 +69,8 @@ export const selectorChartYAxisAutoSizeResults = createSelectorMemoized(selector
65
69
  const computed = computeAxisAutoSize({
66
70
  axis,
67
71
  direction: 'y',
68
- domain: domainsMap[axis.id]
72
+ domain: domainsMap[axis.id],
73
+ defaultTickLabelStyle
69
74
  });
70
75
  if (computed !== undefined) {
71
76
  results[axis.id] = computed;