@mui/x-charts 8.14.0 → 8.15.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 (164) hide show
  1. package/BarChart/BarChart.js +8 -0
  2. package/BarChart/BarChart.plugins.d.ts +2 -1
  3. package/BarChart/BarChart.plugins.js +2 -1
  4. package/BarChart/useBarChartProps.js +4 -2
  5. package/BarChart/useBarPlotData.js +20 -33
  6. package/CHANGELOG.md +202 -0
  7. package/ChartContainer/ChartContainer.js +8 -0
  8. package/ChartContainer/useChartContainerProps.js +4 -2
  9. package/ChartsBrushOverlay/ChartsBrushOverlay.classes.d.ts +12 -0
  10. package/ChartsBrushOverlay/ChartsBrushOverlay.classes.js +9 -0
  11. package/ChartsBrushOverlay/ChartsBrushOverlay.d.ts +6 -0
  12. package/ChartsBrushOverlay/ChartsBrushOverlay.js +102 -0
  13. package/ChartsBrushOverlay/index.d.ts +4 -0
  14. package/ChartsBrushOverlay/index.js +19 -0
  15. package/ChartsReferenceLine/ChartsReferenceLine.js +1 -1
  16. package/ChartsReferenceLine/ChartsXReferenceLine.js +13 -8
  17. package/ChartsReferenceLine/ChartsYReferenceLine.js +13 -8
  18. package/ChartsReferenceLine/common.d.ts +3 -1
  19. package/ChartsReferenceLine/common.js +3 -1
  20. package/ChartsTooltip/ChartsTooltipContainer.js +20 -2
  21. package/ChartsXAxis/getVisibleLabels.js +45 -25
  22. package/Gauge/Gauge.js +2 -9
  23. package/Gauge/GaugeReferenceArc.d.ts +4 -1
  24. package/Gauge/GaugeReferenceArc.js +12 -3
  25. package/Gauge/GaugeValueArc.d.ts +4 -1
  26. package/Gauge/GaugeValueArc.js +16 -8
  27. package/Gauge/GaugeValueText.js +3 -1
  28. package/LineChart/LineChart.js +8 -0
  29. package/LineChart/LineChart.plugins.d.ts +2 -1
  30. package/LineChart/LineChart.plugins.js +2 -1
  31. package/LineChart/useLineChartProps.js +4 -2
  32. package/ScatterChart/ScatterChart.js +8 -0
  33. package/ScatterChart/ScatterChart.plugins.d.ts +2 -1
  34. package/ScatterChart/ScatterChart.plugins.js +2 -1
  35. package/ScatterChart/seriesConfig/seriesProcessor.js +1 -1
  36. package/ScatterChart/useScatterChartProps.js +5 -3
  37. package/SparkLineChart/SparkLineChart.js +8 -0
  38. package/esm/BarChart/BarChart.js +8 -0
  39. package/esm/BarChart/BarChart.plugins.d.ts +2 -1
  40. package/esm/BarChart/BarChart.plugins.js +2 -1
  41. package/esm/BarChart/useBarChartProps.js +4 -2
  42. package/esm/BarChart/useBarPlotData.js +20 -33
  43. package/esm/ChartContainer/ChartContainer.js +8 -0
  44. package/esm/ChartContainer/useChartContainerProps.js +4 -2
  45. package/esm/ChartsBrushOverlay/ChartsBrushOverlay.classes.d.ts +12 -0
  46. package/esm/ChartsBrushOverlay/ChartsBrushOverlay.classes.js +2 -0
  47. package/esm/ChartsBrushOverlay/ChartsBrushOverlay.d.ts +6 -0
  48. package/esm/ChartsBrushOverlay/ChartsBrushOverlay.js +95 -0
  49. package/esm/ChartsBrushOverlay/index.d.ts +4 -0
  50. package/esm/ChartsBrushOverlay/index.js +2 -0
  51. package/esm/ChartsReferenceLine/ChartsReferenceLine.js +1 -1
  52. package/esm/ChartsReferenceLine/ChartsXReferenceLine.js +14 -9
  53. package/esm/ChartsReferenceLine/ChartsYReferenceLine.js +14 -9
  54. package/esm/ChartsReferenceLine/common.d.ts +3 -1
  55. package/esm/ChartsReferenceLine/common.js +2 -0
  56. package/esm/ChartsTooltip/ChartsTooltipContainer.js +20 -2
  57. package/esm/ChartsXAxis/getVisibleLabels.js +45 -25
  58. package/esm/Gauge/Gauge.js +2 -9
  59. package/esm/Gauge/GaugeReferenceArc.d.ts +4 -1
  60. package/esm/Gauge/GaugeReferenceArc.js +11 -2
  61. package/esm/Gauge/GaugeValueArc.d.ts +4 -1
  62. package/esm/Gauge/GaugeValueArc.js +16 -8
  63. package/esm/Gauge/GaugeValueText.js +3 -1
  64. package/esm/LineChart/LineChart.js +8 -0
  65. package/esm/LineChart/LineChart.plugins.d.ts +2 -1
  66. package/esm/LineChart/LineChart.plugins.js +2 -1
  67. package/esm/LineChart/useLineChartProps.js +4 -2
  68. package/esm/ScatterChart/ScatterChart.js +8 -0
  69. package/esm/ScatterChart/ScatterChart.plugins.d.ts +2 -1
  70. package/esm/ScatterChart/ScatterChart.plugins.js +2 -1
  71. package/esm/ScatterChart/seriesConfig/seriesProcessor.js +1 -1
  72. package/esm/ScatterChart/useScatterChartProps.js +5 -3
  73. package/esm/SparkLineChart/SparkLineChart.js +8 -0
  74. package/esm/hooks/index.d.ts +2 -1
  75. package/esm/hooks/index.js +2 -1
  76. package/esm/hooks/useBrush.d.ts +18 -0
  77. package/esm/hooks/useBrush.js +16 -0
  78. package/esm/index.d.ts +2 -1
  79. package/esm/index.js +2 -1
  80. package/esm/internals/Flatbush.d.ts +63 -0
  81. package/esm/internals/Flatbush.js +468 -0
  82. package/esm/internals/domUtils.d.ts +9 -4
  83. package/esm/internals/domUtils.js +115 -52
  84. package/esm/internals/index.d.ts +1 -0
  85. package/esm/internals/index.js +1 -0
  86. package/esm/internals/plugins/allPlugins.d.ts +4 -3
  87. package/esm/internals/plugins/allPlugins.js +2 -1
  88. package/esm/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.js +16 -10
  89. package/esm/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.types.d.ts +2 -2
  90. package/esm/internals/plugins/featurePlugins/useChartBrush/index.d.ts +3 -0
  91. package/esm/internals/plugins/featurePlugins/useChartBrush/index.js +3 -0
  92. package/esm/internals/plugins/featurePlugins/useChartBrush/useChartBrush.d.ts +3 -0
  93. package/esm/internals/plugins/featurePlugins/useChartBrush/useChartBrush.js +109 -0
  94. package/esm/internals/plugins/featurePlugins/useChartBrush/useChartBrush.selectors.d.ts +82 -0
  95. package/esm/internals/plugins/featurePlugins/useChartBrush/useChartBrush.selectors.js +75 -0
  96. package/esm/internals/plugins/featurePlugins/useChartBrush/useChartBrush.types.d.ts +72 -0
  97. package/esm/internals/plugins/featurePlugins/useChartBrush/useChartBrush.types.js +1 -0
  98. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/createZoomLookup.js +3 -2
  99. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/defaultizeAxis.js +2 -2
  100. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/defaultizeZoom.d.ts +2 -1
  101. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/defaultizeZoom.js +8 -3
  102. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisValue.d.ts +6 -2
  103. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisValue.js +3 -6
  104. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxis.types.d.ts +3 -1
  105. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisRendering.selectors.d.ts +19 -0
  106. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisRendering.selectors.js +41 -0
  107. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianHighlight.selectors.d.ts +4 -4
  108. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianHighlight.selectors.js +13 -6
  109. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianInteraction.selectors.js +4 -1
  110. package/esm/internals/plugins/featurePlugins/useChartClosestPoint/findClosestPoints.d.ts +5 -0
  111. package/esm/internals/plugins/featurePlugins/useChartClosestPoint/findClosestPoints.js +33 -0
  112. package/esm/internals/plugins/featurePlugins/useChartClosestPoint/useChartClosestPoint.js +40 -81
  113. package/esm/internals/plugins/utils/selectors.d.ts +1 -1
  114. package/esm/locales/elGR.js +97 -99
  115. package/esm/models/seriesType/scatter.d.ts +2 -0
  116. package/esm/tests/constants.js +1 -0
  117. package/esm/themeAugmentation/components.d.ts +3 -0
  118. package/esm/themeAugmentation/overrides.d.ts +2 -0
  119. package/hooks/index.d.ts +2 -1
  120. package/hooks/index.js +12 -0
  121. package/hooks/useBrush.d.ts +18 -0
  122. package/hooks/useBrush.js +21 -0
  123. package/index.d.ts +2 -1
  124. package/index.js +13 -1
  125. package/internals/Flatbush.d.ts +63 -0
  126. package/internals/Flatbush.js +477 -0
  127. package/internals/domUtils.d.ts +9 -4
  128. package/internals/domUtils.js +119 -54
  129. package/internals/index.d.ts +1 -0
  130. package/internals/index.js +12 -0
  131. package/internals/plugins/allPlugins.d.ts +4 -3
  132. package/internals/plugins/allPlugins.js +2 -1
  133. package/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.js +16 -10
  134. package/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.types.d.ts +2 -2
  135. package/internals/plugins/featurePlugins/useChartBrush/index.d.ts +3 -0
  136. package/internals/plugins/featurePlugins/useChartBrush/index.js +38 -0
  137. package/internals/plugins/featurePlugins/useChartBrush/useChartBrush.d.ts +3 -0
  138. package/internals/plugins/featurePlugins/useChartBrush/useChartBrush.js +117 -0
  139. package/internals/plugins/featurePlugins/useChartBrush/useChartBrush.selectors.d.ts +82 -0
  140. package/internals/plugins/featurePlugins/useChartBrush/useChartBrush.selectors.js +82 -0
  141. package/internals/plugins/featurePlugins/useChartBrush/useChartBrush.types.d.ts +72 -0
  142. package/internals/plugins/featurePlugins/useChartBrush/useChartBrush.types.js +5 -0
  143. package/internals/plugins/featurePlugins/useChartCartesianAxis/createZoomLookup.js +3 -2
  144. package/internals/plugins/featurePlugins/useChartCartesianAxis/defaultizeAxis.js +2 -2
  145. package/internals/plugins/featurePlugins/useChartCartesianAxis/defaultizeZoom.d.ts +2 -1
  146. package/internals/plugins/featurePlugins/useChartCartesianAxis/defaultizeZoom.js +8 -3
  147. package/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisValue.d.ts +6 -2
  148. package/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisValue.js +3 -6
  149. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxis.types.d.ts +3 -1
  150. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisRendering.selectors.d.ts +19 -0
  151. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisRendering.selectors.js +43 -1
  152. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianHighlight.selectors.d.ts +4 -4
  153. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianHighlight.selectors.js +13 -6
  154. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianInteraction.selectors.js +4 -1
  155. package/internals/plugins/featurePlugins/useChartClosestPoint/findClosestPoints.d.ts +5 -0
  156. package/internals/plugins/featurePlugins/useChartClosestPoint/findClosestPoints.js +39 -0
  157. package/internals/plugins/featurePlugins/useChartClosestPoint/useChartClosestPoint.js +39 -80
  158. package/internals/plugins/utils/selectors.d.ts +1 -1
  159. package/locales/elGR.js +97 -99
  160. package/models/seriesType/scatter.d.ts +2 -0
  161. package/package.json +5 -4
  162. package/tests/constants.js +7 -0
  163. package/themeAugmentation/components.d.ts +3 -0
  164. package/themeAugmentation/overrides.d.ts +2 -0
@@ -0,0 +1,72 @@
1
+ import { ChartPluginSignature } from "../../models/index.js";
2
+ export type Point = {
3
+ x: number;
4
+ y: number;
5
+ };
6
+ export interface UseChartBrushState {
7
+ brush: {
8
+ /**
9
+ * Whether the brush interaction is enabled.
10
+ */
11
+ enabled: boolean;
12
+ /**
13
+ * Whether to prevent tooltip from showing during brush interaction.
14
+ */
15
+ preventTooltip: boolean;
16
+ /**
17
+ * Whether to prevent highlighting during brush interaction.
18
+ */
19
+ preventHighlight: boolean;
20
+ /**
21
+ * The starting coordinate of the brush interaction.
22
+ */
23
+ start: Point | null;
24
+ /**
25
+ * The current coordinate of the brush interaction.
26
+ */
27
+ current: Point | null;
28
+ };
29
+ }
30
+ export interface UseChartBrushInstance {
31
+ /**
32
+ * Set the brush coordinates.
33
+ * @param {Point | null} point The point coordinate, if start value is null, it will set both start and current to this value.
34
+ */
35
+ setBrushCoordinates: (point: Point | null) => void;
36
+ /**
37
+ * Clear the brush coordinates.
38
+ */
39
+ clearBrush: () => void;
40
+ }
41
+ export interface BrushConfig {
42
+ /**
43
+ * Whether the brush interaction is enabled.
44
+ * @default false
45
+ */
46
+ enabled?: boolean;
47
+ /**
48
+ * Whether to prevent tooltip from showing during brush interaction.
49
+ * @default false
50
+ */
51
+ preventTooltip?: boolean;
52
+ /**
53
+ * Whether to prevent highlighting during brush interaction.
54
+ * @default false
55
+ */
56
+ preventHighlight?: boolean;
57
+ }
58
+ export interface UseChartBrushParameters {
59
+ /**
60
+ * Configuration for the brush interaction.
61
+ */
62
+ brushConfig?: BrushConfig;
63
+ }
64
+ export type UseChartBrushDefaultizedParameters = {
65
+ brushConfig: Required<BrushConfig>;
66
+ };
67
+ export type UseChartBrushSignature = ChartPluginSignature<{
68
+ params: UseChartBrushParameters;
69
+ defaultizedParams: UseChartBrushDefaultizedParameters;
70
+ state: UseChartBrushState;
71
+ instance: UseChartBrushInstance;
72
+ }>;
@@ -3,9 +3,10 @@ export const createZoomLookup = axisDirection => (axes = []) => axes.reduce((acc
3
3
  // @ts-ignore
4
4
  const {
5
5
  zoom,
6
- id: axisId
6
+ id: axisId,
7
+ reverse
7
8
  } = v;
8
- const defaultizedZoom = defaultizeZoom(zoom, axisId, axisDirection);
9
+ const defaultizedZoom = defaultizeZoom(zoom, axisId, axisDirection, reverse);
9
10
  if (defaultizedZoom) {
10
11
  acc[axisId] = defaultizedZoom;
11
12
  }
@@ -25,7 +25,7 @@ export function defaultizeXAxis(inAxes, dataset) {
25
25
  id,
26
26
  position,
27
27
  height: axisConfig.height ?? defaultHeight,
28
- zoom: defaultizeZoom(axisConfig.zoom, id, 'x')
28
+ zoom: defaultizeZoom(axisConfig.zoom, id, 'x', axisConfig.reverse)
29
29
  });
30
30
 
31
31
  // Increment the offset for the next axis
@@ -75,7 +75,7 @@ export function defaultizeYAxis(inAxes, dataset) {
75
75
  id,
76
76
  position,
77
77
  width: axisConfig.width ?? defaultWidth,
78
- zoom: defaultizeZoom(axisConfig.zoom, id, 'y')
78
+ zoom: defaultizeZoom(axisConfig.zoom, id, 'y', axisConfig.reverse)
79
79
  });
80
80
 
81
81
  // Increment the offset for the next axis
@@ -9,6 +9,7 @@ export declare const defaultZoomOptions: {
9
9
  maxSpan: number;
10
10
  panning: true;
11
11
  filterMode: "keep";
12
+ reverse: false;
12
13
  slider: {
13
14
  enabled: false;
14
15
  preview: false;
@@ -16,4 +17,4 @@ export declare const defaultZoomOptions: {
16
17
  showTooltip: import("./zoom.types.js").ZoomSliderShowTooltip;
17
18
  };
18
19
  };
19
- export declare const defaultizeZoom: (zoom: boolean | ZoomOptions | undefined, axisId: AxisId, axisDirection: "x" | "y") => DefaultizedZoomOptions | undefined;
20
+ export declare const defaultizeZoom: (zoom: boolean | ZoomOptions | undefined, axisId: AxisId, axisDirection: "x" | "y", reverse?: boolean) => DefaultizedZoomOptions | undefined;
@@ -8,6 +8,7 @@ export const defaultZoomOptions = {
8
8
  maxSpan: 100,
9
9
  panning: true,
10
10
  filterMode: 'keep',
11
+ reverse: false,
11
12
  slider: {
12
13
  enabled: false,
13
14
  preview: false,
@@ -15,7 +16,7 @@ export const defaultZoomOptions = {
15
16
  showTooltip: DEFAULT_ZOOM_SLIDER_SHOW_TOOLTIP
16
17
  }
17
18
  };
18
- export const defaultizeZoom = (zoom, axisId, axisDirection) => {
19
+ export const defaultizeZoom = (zoom, axisId, axisDirection, reverse) => {
19
20
  if (!zoom) {
20
21
  return undefined;
21
22
  }
@@ -23,12 +24,16 @@ export const defaultizeZoom = (zoom, axisId, axisDirection) => {
23
24
  return _extends({
24
25
  axisId,
25
26
  axisDirection
26
- }, defaultZoomOptions);
27
+ }, defaultZoomOptions, {
28
+ reverse: reverse ?? false
29
+ });
27
30
  }
28
31
  return _extends({
29
32
  axisId,
30
33
  axisDirection
31
- }, defaultZoomOptions, zoom, {
34
+ }, defaultZoomOptions, {
35
+ reverse: reverse ?? false
36
+ }, zoom, {
32
37
  slider: _extends({}, defaultZoomOptions.slider, {
33
38
  size: zoom.slider?.preview ?? defaultZoomOptions.slider.preview ? DEFAULT_ZOOM_SLIDER_PREVIEW_SIZE : DEFAULT_ZOOM_SLIDER_SIZE
34
39
  }, zoom.slider)
@@ -1,4 +1,4 @@
1
- import { ComputedAxis } from "../../../../models/axis.js";
1
+ import { ComputedAxis, D3Scale } from "../../../../models/axis.js";
2
2
  /**
3
3
  * For a pointer coordinate, this function returns the dataIndex associated.
4
4
  * Returns `-1` if no dataIndex matches.
@@ -8,4 +8,8 @@ export declare function getAxisIndex(axisConfig: ComputedAxis, pointerValue: num
8
8
  * For a pointer coordinate, this function returns the value associated.
9
9
  * Returns `null` if the coordinate has no value associated.
10
10
  */
11
- export declare function getAxisValue(axisConfig: ComputedAxis, pointerValue: number, dataIndex: number | null): number | Date | null;
11
+ export declare function getAxisValue<Domain extends {
12
+ toString(): string;
13
+ } = {
14
+ toString(): string;
15
+ }, Range = number, Output = number>(scale: D3Scale<Domain, Range, Output>, axisData: readonly any[] | undefined, pointerValue: number, dataIndex: number | null): number | Date | null;
@@ -46,14 +46,11 @@ export function getAxisIndex(axisConfig, pointerValue) {
46
46
  * For a pointer coordinate, this function returns the value associated.
47
47
  * Returns `null` if the coordinate has no value associated.
48
48
  */
49
- export function getAxisValue(axisConfig, pointerValue, dataIndex) {
50
- const {
51
- scale,
52
- data: axisData
53
- } = axisConfig;
49
+ export function getAxisValue(scale, axisData, pointerValue, dataIndex) {
54
50
  if (!isOrdinalScale(scale)) {
55
51
  if (dataIndex === null) {
56
- return scale.invert(pointerValue);
52
+ const invertedValue = scale.invert(pointerValue);
53
+ return Number.isNaN(invertedValue) ? null : invertedValue;
57
54
  }
58
55
  return axisData[dataIndex];
59
56
  }
@@ -5,6 +5,7 @@ import type { UseChartSeriesSignature } from "../../corePlugins/useChartSeries/i
5
5
  import type { ZoomData, ZoomOptions, ZoomSliderShowTooltip } from "./zoom.types.js";
6
6
  import type { UseChartInteractionSignature } from "../useChartInteraction/index.js";
7
7
  import type { ChartsAxisProps } from "../../../../ChartsAxis/index.js";
8
+ import type { UseChartBrushSignature } from "../useChartBrush/index.js";
8
9
  /**
9
10
  * The axes' configuration after computing.
10
11
  * An axis in this state already contains a scale function and all the necessary properties to be rendered.
@@ -67,6 +68,7 @@ export interface DefaultizedZoomOptions extends Required<Omit<ZoomOptions, 'slid
67
68
  axisId: AxisId;
68
69
  axisDirection: 'x' | 'y';
69
70
  slider: DefaultedZoomSliderOptions;
71
+ reverse: boolean;
70
72
  }
71
73
  export interface UseChartCartesianAxisState {
72
74
  /**
@@ -94,5 +96,5 @@ export type UseChartCartesianAxisSignature<SeriesType extends ChartSeriesType =
94
96
  defaultizedParams: UseChartCartesianAxisDefaultizedParameters;
95
97
  state: UseChartCartesianAxisState;
96
98
  dependencies: [UseChartSeriesSignature<SeriesType>];
97
- optionalDependencies: [UseChartInteractionSignature];
99
+ optionalDependencies: [UseChartInteractionSignature, UseChartBrushSignature];
98
100
  }>;
@@ -1,6 +1,8 @@
1
1
  import { NumberValue } from '@mui/x-charts-vendor/d3-scale';
2
2
  import { ZoomData } from "./zoom.types.js";
3
3
  import { AxisId, D3Scale } from "../../../../models/axis.js";
4
+ import { SeriesId } from "../../../../models/seriesType/common.js";
5
+ import { Flatbush } from "../../../Flatbush.js";
4
6
  export declare const createZoomMap: (zoom: readonly ZoomData[]) => Map<AxisId, ZoomData>;
5
7
  /**
6
8
  * Following selectors are not exported because they exist in the MIT chart only to ba able to reuse the Zoom state from the pro.
@@ -15,6 +17,7 @@ export declare const selectorChartZoomMap: import("reselect").Selector<import(".
15
17
  } & {
16
18
  cacheKey: import("../../models/index.js").ChartStateCacheKey;
17
19
  }, Map<AxisId, ZoomData> | undefined, []>;
20
+ export declare const selectorChartAxisZoomData: import("reselect").Selector<any, ZoomData | undefined, [axisId: AxisId]>;
18
21
  export declare const selectorChartZoomOptionsLookup: import("reselect").Selector<import("../../corePlugins/useChartId/useChartId.types.js").UseChartIdState & import("../../corePlugins/useChartExperimentalFeature/useChartExperimentalFeature.types.js").UseChartExperimentalFeaturesState & import("../../corePlugins/useChartDimensions/useChartDimensions.types.js").UseChartDimensionsState & import("../../corePlugins/useChartSeries/useChartSeries.types.js").UseChartSeriesState<keyof import("../../../index.js").ChartsSeriesConfig> & import("../../corePlugins/useChartAnimation/useChartAnimation.types.js").UseChartAnimationState & import("../../../index.js").UseChartInteractionListenerState & Partial<import("./useChartCartesianAxis.types.js").UseChartCartesianAxisState> & {
19
22
  cacheKey: import("../../models/index.js").ChartStateCacheKey;
20
23
  } & {
@@ -222,4 +225,20 @@ export declare const selectorChartRawAxis: import("reselect").Selector<any, ({
222
225
  } & import("../../../../hooks/useTicks.js").TickParams & import("../../../index.js").AxisConfigExtension & {
223
226
  zoom: import("./useChartCartesianAxis.types.js").DefaultizedZoomOptions | undefined;
224
227
  }) | undefined, [axisId: AxisId]>;
228
+ export declare const selectorChartDefaultXAxisId: import("reselect").Selector<import("../../corePlugins/useChartId/useChartId.types.js").UseChartIdState & import("../../corePlugins/useChartExperimentalFeature/useChartExperimentalFeature.types.js").UseChartExperimentalFeaturesState & import("../../corePlugins/useChartDimensions/useChartDimensions.types.js").UseChartDimensionsState & import("../../corePlugins/useChartSeries/useChartSeries.types.js").UseChartSeriesState<keyof import("../../../index.js").ChartsSeriesConfig> & import("../../corePlugins/useChartAnimation/useChartAnimation.types.js").UseChartAnimationState & import("../../../index.js").UseChartInteractionListenerState & Partial<import("./useChartCartesianAxis.types.js").UseChartCartesianAxisState> & {
229
+ cacheKey: import("../../models/index.js").ChartStateCacheKey;
230
+ } & {
231
+ cacheKey: import("../../models/index.js").ChartStateCacheKey;
232
+ }, AxisId, []>;
233
+ export declare const selectorChartDefaultYAxisId: import("reselect").Selector<import("../../corePlugins/useChartId/useChartId.types.js").UseChartIdState & import("../../corePlugins/useChartExperimentalFeature/useChartExperimentalFeature.types.js").UseChartExperimentalFeaturesState & import("../../corePlugins/useChartDimensions/useChartDimensions.types.js").UseChartDimensionsState & import("../../corePlugins/useChartSeries/useChartSeries.types.js").UseChartSeriesState<keyof import("../../../index.js").ChartsSeriesConfig> & import("../../corePlugins/useChartAnimation/useChartAnimation.types.js").UseChartAnimationState & import("../../../index.js").UseChartInteractionListenerState & Partial<import("./useChartCartesianAxis.types.js").UseChartCartesianAxisState> & {
234
+ cacheKey: import("../../models/index.js").ChartStateCacheKey;
235
+ } & {
236
+ cacheKey: import("../../models/index.js").ChartStateCacheKey;
237
+ }, AxisId, []>;
238
+ export declare const selectorChartSeriesEmptyFlatbushMap: () => Map<SeriesId, Flatbush>;
239
+ export declare const selectorChartSeriesFlatbushMap: import("reselect").Selector<import("../../corePlugins/useChartId/useChartId.types.js").UseChartIdState & import("../../corePlugins/useChartExperimentalFeature/useChartExperimentalFeature.types.js").UseChartExperimentalFeaturesState & import("../../corePlugins/useChartDimensions/useChartDimensions.types.js").UseChartDimensionsState & import("../../corePlugins/useChartSeries/useChartSeries.types.js").UseChartSeriesState<keyof import("../../../index.js").ChartsSeriesConfig> & import("../../corePlugins/useChartAnimation/useChartAnimation.types.js").UseChartAnimationState & import("../../../index.js").UseChartInteractionListenerState & Partial<{}> & {
240
+ cacheKey: import("../../models/index.js").ChartStateCacheKey;
241
+ } & {
242
+ cacheKey: import("../../models/index.js").ChartStateCacheKey;
243
+ } & Partial<import("./useChartCartesianAxis.types.js").UseChartCartesianAxisState>, Map<SeriesId, Flatbush>, any[]>;
225
244
  export {};
@@ -1,4 +1,5 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import { isDeepEqual } from '@mui/x-internals/isDeepEqual';
2
3
  import { selectorChartDrawingArea } from "../../corePlugins/useChartDimensions/index.js";
3
4
  import { selectorChartSeriesConfig, selectorChartSeriesProcessed } from "../../corePlugins/useChartSeries/index.js";
4
5
  import { createSelector } from "../../utils/selectors.js";
@@ -14,6 +15,7 @@ import { isOrdinalScale } from "../../../scaleGuards.js";
14
15
  import { zoomScaleRange } from "./zoom.js";
15
16
  import { getAxisExtrema } from "./getAxisExtrema.js";
16
17
  import { calculateFinalDomain, calculateInitialDomainAndTickNumber } from "./domain.js";
18
+ import { Flatbush } from "../../../Flatbush.js";
17
19
  export const createZoomMap = zoom => {
18
20
  const zoomItemMap = new Map();
19
21
  zoom.forEach(zoomItem => {
@@ -29,6 +31,7 @@ const selectorChartZoomState = state => state.zoom;
29
31
 
30
32
  export const selectorChartZoomIsInteracting = createSelector([selectorChartZoomState], zoom => zoom?.isInteracting);
31
33
  export const selectorChartZoomMap = createSelector([selectorChartZoomState], zoom => zoom?.zoomData && createZoomMap(zoom?.zoomData));
34
+ export const selectorChartAxisZoomData = createSelector([selectorChartZoomMap, (_, axisId) => axisId], (zoomMap, axisId) => zoomMap?.get(axisId));
32
35
  export const selectorChartZoomOptionsLookup = createSelector([selectorChartRawXAxis, selectorChartRawYAxis], (xAxis, yAxis) => _extends({}, createZoomLookup('x')(xAxis), createZoomLookup('y')(yAxis)));
33
36
  export const selectorChartAxisZoomOptionsLookup = createSelector([selectorChartZoomOptionsLookup, (_, axisId) => axisId], (axisLookup, axisId) => axisLookup[axisId]);
34
37
  export const selectorDefaultXAxisTickNumber = createSelector([selectorChartDrawingArea], function selectorDefaultXAxisTickNumber(drawingArea) {
@@ -125,6 +128,10 @@ export const selectorChartFilteredXDomains = createSelector([selectorChartRawXAx
125
128
  filteredDomains[axis.id] = calculateFinalDomain(axis, 'x', axisIndex, formattedSeries, axisExtrema, rawTickNumber, preferStrictDomainInLineCharts);
126
129
  });
127
130
  return filteredDomains;
131
+ }, {
132
+ memoizeOptions: {
133
+ resultEqualityCheck: (a, b) => isDeepEqual(a, b)
134
+ }
128
135
  });
129
136
  export const selectorChartFilteredYDomains = createSelector([selectorChartRawYAxis, selectorChartSeriesProcessed, selectorChartSeriesConfig, selectorChartZoomMap, selectorChartZoomOptionsLookup, selectorChartZoomAxisFilters, selectorPreferStrictDomainInLineCharts, selectorChartYDomains], (axes, formattedSeries, seriesConfig, zoomMap, zoomOptions, getFilters, preferStrictDomainInLineCharts, domains) => {
130
137
  const filteredDomains = {};
@@ -147,6 +154,10 @@ export const selectorChartFilteredYDomains = createSelector([selectorChartRawYAx
147
154
  filteredDomains[axis.id] = calculateFinalDomain(axis, 'y', axisIndex, formattedSeries, axisExtrema, rawTickNumber, preferStrictDomainInLineCharts);
148
155
  });
149
156
  return filteredDomains;
157
+ }, {
158
+ memoizeOptions: {
159
+ resultEqualityCheck: (a, b) => isDeepEqual(a, b)
160
+ }
150
161
  });
151
162
  export const selectorChartNormalizedXScales = createSelector([selectorChartRawXAxis, selectorChartFilteredXDomains], function selectorChartNormalizedXScales(axes, filteredDomains) {
152
163
  const scales = {};
@@ -227,4 +238,34 @@ export const selectorChartRawAxis = createSelector([selectorChartRawXAxis, selec
227
238
  return undefined;
228
239
  }
229
240
  return axis;
241
+ });
242
+ export const selectorChartDefaultXAxisId = createSelector([selectorChartRawXAxis], xAxes => xAxes[0].id);
243
+ export const selectorChartDefaultYAxisId = createSelector([selectorChartRawYAxis], yAxes => yAxes[0].id);
244
+ const EMPTY_MAP = new Map();
245
+ export const selectorChartSeriesEmptyFlatbushMap = () => EMPTY_MAP;
246
+ export const selectorChartSeriesFlatbushMap = createSelector([selectorChartSeriesProcessed, selectorChartNormalizedXScales, selectorChartNormalizedYScales, selectorChartDefaultXAxisId, selectorChartDefaultYAxisId], function selectChartSeriesFlatbushMap(allSeries, xAxesScaleMap, yAxesScaleMap, defaultXAxisId, defaultYAxisId) {
247
+ // FIXME: Do we want to support non-scatter series here?
248
+ const validSeries = allSeries.scatter;
249
+ const flatbushMap = new Map();
250
+ if (!validSeries) {
251
+ return flatbushMap;
252
+ }
253
+ validSeries.seriesOrder.forEach(seriesId => {
254
+ const {
255
+ data,
256
+ xAxisId = defaultXAxisId,
257
+ yAxisId = defaultYAxisId
258
+ } = validSeries.series[seriesId];
259
+ const flatbush = new Flatbush(data.length);
260
+ const originalXScale = xAxesScaleMap[xAxisId];
261
+ const originalYScale = yAxesScaleMap[yAxisId];
262
+ for (const datum of data) {
263
+ // Add the points using a [0, 1] range so that we don't need to recreate the Flatbush structure when zooming.
264
+ // This doesn't happen in practice, though, because currently the scales depend on the drawing area.
265
+ flatbush.add(originalXScale(datum.x), originalYScale(datum.y));
266
+ }
267
+ flatbush.finish();
268
+ flatbushMap.set(seriesId, flatbush);
269
+ });
270
+ return flatbushMap;
230
271
  });
@@ -3,17 +3,17 @@ export declare const selectorChartsHighlightXAxisIndex: import("reselect").Selec
3
3
  cacheKey: import("../../models/index.js").ChartStateCacheKey;
4
4
  } & {
5
5
  cacheKey: import("../../models/index.js").ChartStateCacheKey;
6
- } & Partial<import("./useChartCartesianAxis.types.js").UseChartCartesianAxisState> & Partial<{}>, AxisItemIdentifier[], [id?: import("../../../index.js").AxisId | undefined]>;
6
+ } & Partial<import("./useChartCartesianAxis.types.js").UseChartCartesianAxisState> & Partial<{}> & Partial<import("../useChartBrush/index.js").UseChartBrushState>, AxisItemIdentifier[], [id?: import("../../../index.js").AxisId | undefined]>;
7
7
  export declare const selectorChartsHighlightYAxisIndex: import("reselect").Selector<import("../../corePlugins/useChartId/useChartId.types.js").UseChartIdState & import("../../corePlugins/useChartExperimentalFeature/useChartExperimentalFeature.types.js").UseChartExperimentalFeaturesState & import("../../corePlugins/useChartDimensions/useChartDimensions.types.js").UseChartDimensionsState & import("../../corePlugins/useChartSeries/useChartSeries.types.js").UseChartSeriesState<keyof import("../../../index.js").ChartsSeriesConfig> & import("../../corePlugins/useChartAnimation/useChartAnimation.types.js").UseChartAnimationState & import("../../../index.js").UseChartInteractionListenerState & Partial<import("../useChartInteraction/useChartInteraction.types.js").UseChartInteractionState> & {
8
8
  cacheKey: import("../../models/index.js").ChartStateCacheKey;
9
9
  } & {
10
10
  cacheKey: import("../../models/index.js").ChartStateCacheKey;
11
- } & Partial<import("./useChartCartesianAxis.types.js").UseChartCartesianAxisState> & Partial<{}>, AxisItemIdentifier[], [id?: import("../../../index.js").AxisId | undefined]>;
11
+ } & Partial<import("./useChartCartesianAxis.types.js").UseChartCartesianAxisState> & Partial<{}> & Partial<import("../useChartBrush/index.js").UseChartBrushState>, AxisItemIdentifier[], [id?: import("../../../index.js").AxisId | undefined]>;
12
12
  export declare const selectorChartsHighlightXAxisValue: import("reselect").Selector<import("../../corePlugins/useChartId/useChartId.types.js").UseChartIdState & import("../../corePlugins/useChartExperimentalFeature/useChartExperimentalFeature.types.js").UseChartExperimentalFeaturesState & import("../../corePlugins/useChartDimensions/useChartDimensions.types.js").UseChartDimensionsState & import("../../corePlugins/useChartSeries/useChartSeries.types.js").UseChartSeriesState<keyof import("../../../index.js").ChartsSeriesConfig> & import("../../corePlugins/useChartAnimation/useChartAnimation.types.js").UseChartAnimationState & import("../../../index.js").UseChartInteractionListenerState & Partial<import("../useChartInteraction/useChartInteraction.types.js").UseChartInteractionState> & {
13
13
  cacheKey: import("../../models/index.js").ChartStateCacheKey;
14
14
  } & {
15
15
  cacheKey: import("../../models/index.js").ChartStateCacheKey;
16
- } & Partial<import("./useChartCartesianAxis.types.js").UseChartCartesianAxisState> & Partial<{}> & Partial<import("../useChartKeyboardNavigation/useChartKeyboardNavigation.types.js").UseChartKeyboardNavigationState>, {
16
+ } & Partial<import("./useChartCartesianAxis.types.js").UseChartCartesianAxisState> & Partial<{}> & Partial<import("../useChartKeyboardNavigation/useChartKeyboardNavigation.types.js").UseChartKeyboardNavigationState> & Partial<import("../useChartBrush/index.js").UseChartBrushState>, {
17
17
  value: any;
18
18
  axisId: import("../../../index.js").AxisId;
19
19
  dataIndex: number;
@@ -26,7 +26,7 @@ export declare const selectorChartsHighlightYAxisValue: import("reselect").Selec
26
26
  cacheKey: import("../../models/index.js").ChartStateCacheKey;
27
27
  } & {
28
28
  cacheKey: import("../../models/index.js").ChartStateCacheKey;
29
- } & Partial<import("./useChartCartesianAxis.types.js").UseChartCartesianAxisState> & Partial<{}> & Partial<import("../useChartKeyboardNavigation/useChartKeyboardNavigation.types.js").UseChartKeyboardNavigationState>, {
29
+ } & Partial<import("./useChartCartesianAxis.types.js").UseChartCartesianAxisState> & Partial<{}> & Partial<import("../useChartKeyboardNavigation/useChartKeyboardNavigation.types.js").UseChartKeyboardNavigationState> & Partial<import("../useChartBrush/index.js").UseChartBrushState>, {
30
30
  value: any;
31
31
  axisId: import("../../../index.js").AxisId;
32
32
  dataIndex: number;
@@ -4,8 +4,12 @@ import { selectorChartXAxis, selectorChartYAxis } from "./useChartCartesianAxisR
4
4
  import { selectorChartsInteractionXAxisIndex, selectorChartsInteractionXAxisValue, selectorChartsInteractionYAxisIndex, selectorChartsInteractionYAxisValue } from "./useChartCartesianInteraction.selectors.js";
5
5
  import { selectorChartsKeyboardXAxisIndex, selectorChartsKeyboardYAxisIndex } from "../useChartKeyboardNavigation/useChartKeyboardNavigation.selectors.js";
6
6
  import { selectorChartsLastInteraction } from "../useChartInteraction/useChartInteraction.selectors.js";
7
+ import { selectorBrushShouldPreventAxisHighlight } from "../useChartBrush/index.js";
7
8
  const selectorChartControlledCartesianAxisHighlight = state => state.controlledCartesianAxisHighlight;
8
- const selectAxisHighlight = (computedIndex, axis, axisItems) => {
9
+ const selectAxisHighlight = (computedIndex, axis, axisItems, isBrushSelectionActive) => {
10
+ if (isBrushSelectionActive) {
11
+ return [];
12
+ }
9
13
  if (axisItems !== undefined) {
10
14
  return axisItems.filter(item => axis.axis[item.axisId] !== undefined).map(item => item);
11
15
  }
@@ -14,9 +18,12 @@ const selectAxisHighlight = (computedIndex, axis, axisItems) => {
14
18
  dataIndex: computedIndex
15
19
  }];
16
20
  };
17
- export const selectorChartsHighlightXAxisIndex = createSelector([selectorChartsInteractionXAxisIndex, selectorChartXAxis, selectorChartControlledCartesianAxisHighlight], selectAxisHighlight);
18
- export const selectorChartsHighlightYAxisIndex = createSelector([selectorChartsInteractionYAxisIndex, selectorChartYAxis, selectorChartControlledCartesianAxisHighlight], selectAxisHighlight);
19
- const selectAxisHighlightWithValue = (computedIndex, computedValue, axis, controlledAxisItems, keyboardAxisItem, lastInteractionUpdate) => {
21
+ export const selectorChartsHighlightXAxisIndex = createSelector([selectorChartsInteractionXAxisIndex, selectorChartXAxis, selectorChartControlledCartesianAxisHighlight, selectorBrushShouldPreventAxisHighlight], selectAxisHighlight);
22
+ export const selectorChartsHighlightYAxisIndex = createSelector([selectorChartsInteractionYAxisIndex, selectorChartYAxis, selectorChartControlledCartesianAxisHighlight, selectorBrushShouldPreventAxisHighlight], selectAxisHighlight);
23
+ const selectAxisHighlightWithValue = (computedIndex, computedValue, axis, controlledAxisItems, keyboardAxisItem, lastInteractionUpdate, isBrushSelectionActive) => {
24
+ if (isBrushSelectionActive) {
25
+ return [];
26
+ }
20
27
  if (controlledAxisItems !== undefined) {
21
28
  return controlledAxisItems.map(item => _extends({}, item, {
22
29
  value: axis.axis[item.axisId]?.data?.[item.dataIndex]
@@ -51,8 +58,8 @@ const selectAxisHighlightWithValue = (computedIndex, computedValue, axis, contro
51
58
  }
52
59
  return [];
53
60
  };
54
- export const selectorChartsHighlightXAxisValue = createSelector([selectorChartsInteractionXAxisIndex, selectorChartsInteractionXAxisValue, selectorChartXAxis, selectorChartControlledCartesianAxisHighlight, selectorChartsKeyboardXAxisIndex, selectorChartsLastInteraction], selectAxisHighlightWithValue);
55
- export const selectorChartsHighlightYAxisValue = createSelector([selectorChartsInteractionYAxisIndex, selectorChartsInteractionYAxisValue, selectorChartYAxis, selectorChartControlledCartesianAxisHighlight, selectorChartsKeyboardYAxisIndex, selectorChartsLastInteraction], selectAxisHighlightWithValue);
61
+ export const selectorChartsHighlightXAxisValue = createSelector([selectorChartsInteractionXAxisIndex, selectorChartsInteractionXAxisValue, selectorChartXAxis, selectorChartControlledCartesianAxisHighlight, selectorChartsKeyboardXAxisIndex, selectorChartsLastInteraction, selectorBrushShouldPreventAxisHighlight], selectAxisHighlightWithValue);
62
+ export const selectorChartsHighlightYAxisValue = createSelector([selectorChartsInteractionYAxisIndex, selectorChartsInteractionYAxisValue, selectorChartYAxis, selectorChartControlledCartesianAxisHighlight, selectorChartsKeyboardYAxisIndex, selectorChartsLastInteraction, selectorBrushShouldPreventAxisHighlight], selectAxisHighlightWithValue);
56
63
 
57
64
  /**
58
65
  * Get the scale of the axis with highlight if controlled. The default axis otherwise.
@@ -34,7 +34,10 @@ export const selectorChartAxisInteraction = createSelector([selectorChartsIntera
34
34
  */
35
35
 
36
36
  function valueGetter(value, axes, indexes, ids = axes.axisIds[0]) {
37
- return Array.isArray(ids) ? ids.map((id, axisIndex) => getAxisValue(axes.axis[id], value, indexes[axisIndex])) : getAxisValue(axes.axis[ids], value, indexes);
37
+ return Array.isArray(ids) ? ids.map((id, axisIndex) => {
38
+ const axis = axes.axis[id];
39
+ return getAxisValue(axis.scale, axis.data, value, indexes[axisIndex]);
40
+ }) : getAxisValue(axes.axis[ids].scale, axes.axis[ids].data, value, indexes);
38
41
  }
39
42
  export const selectorChartsInteractionXAxisValue = createSelector([selectorChartsInteractionPointerX, selectorChartXAxis, selectorChartsInteractionXAxisIndex, optionalGetAxisId], (x, xAxes, xIndex, id) => {
40
43
  if (x === null || xAxes.axisIds.length === 0) {
@@ -0,0 +1,5 @@
1
+ import { ChartDrawingArea } from "../../../../hooks/useDrawingArea.js";
2
+ import { ScatterValueType } from "../../../../models/seriesType/scatter.js";
3
+ import { Flatbush } from "../../../Flatbush.js";
4
+ import { D3Scale } from "../../../../models/axis.js";
5
+ export declare function findClosestPoints(flatbush: Flatbush, drawingArea: Pick<ChartDrawingArea, 'top' | 'left' | 'width' | 'height'>, seriesData: readonly ScatterValueType[], xScale: D3Scale, yScale: D3Scale, xZoomStart: number, xZoomEnd: number, yZoomStart: number, yZoomEnd: number, svgPointX: number, svgPointY: number, maxRadius?: number, maxResults?: number): number[];
@@ -0,0 +1,33 @@
1
+ import { isOrdinalScale } from "../../../scaleGuards.js";
2
+ export function findClosestPoints(flatbush, drawingArea, seriesData, xScale, yScale, xZoomStart, xZoomEnd, yZoomStart, yZoomEnd, svgPointX, svgPointY, maxRadius = Infinity, maxResults = 1) {
3
+ const originalXScale = xScale.copy();
4
+ const originalYScale = yScale.copy();
5
+ originalXScale.range([0, 1]);
6
+ originalYScale.range([0, 1]);
7
+ const excludeIfOutsideDrawingArea = function excludeIfOutsideDrawingArea(index) {
8
+ const x = originalXScale(seriesData[index].x);
9
+ const y = originalYScale(seriesData[index].y);
10
+ return x >= xZoomStart && x <= xZoomEnd && y >= yZoomStart && y <= yZoomEnd;
11
+ };
12
+
13
+ // We need to convert the distance from the original range [0, 1] to the current drawing area
14
+ // so the comparison is done on pixels instead of normalized values.
15
+ // fx and fy are the factors to convert the distance from [0, 1] to the current drawing area.
16
+ const fx = xScale.range()[1] - xScale.range()[0];
17
+ const fy = yScale.range()[1] - yScale.range()[0];
18
+ const fxSq = fx * fx;
19
+ const fySq = fy * fy;
20
+ function sqDistFn(dx, dy) {
21
+ return fxSq * dx * dx + fySq * dy * dy;
22
+ }
23
+ const pointX = originalXScale(invertScale(xScale, svgPointX, dataIndex => seriesData[dataIndex].x));
24
+ const pointY = originalYScale(invertScale(yScale, svgPointY, dataIndex => seriesData[dataIndex].y));
25
+ return flatbush.neighbors(pointX, pointY, maxResults, maxRadius != null ? maxRadius * maxRadius : Infinity, excludeIfOutsideDrawingArea, sqDistFn);
26
+ }
27
+ function invertScale(scale, value, getDataPoint) {
28
+ if (isOrdinalScale(scale)) {
29
+ const dataIndex = scale.bandwidth() === 0 ? Math.floor((value - Math.min(...scale.range()) + scale.step() / 2) / scale.step()) : Math.floor((value - Math.min(...scale.range())) / scale.step());
30
+ return getDataPoint(dataIndex);
31
+ }
32
+ return scale.invert(value);
33
+ }
@@ -4,13 +4,12 @@ import _extends from "@babel/runtime/helpers/esm/extends";
4
4
  import * as React from 'react';
5
5
  import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
6
6
  import useEventCallback from '@mui/utils/useEventCallback';
7
- import { Delaunay } from '@mui/x-charts-vendor/d3-delaunay';
8
- import { getValueToPositionMapper } from "../../../../hooks/useScale.js";
9
7
  import { getSVGPoint } from "../../../getSVGPoint.js";
10
8
  import { useSelector } from "../../../store/useSelector.js";
11
- import { selectorChartXAxis, selectorChartYAxis, selectorChartZoomIsInteracting } from "../useChartCartesianAxis/index.js";
9
+ import { selectorChartAxisZoomData, selectorChartSeriesEmptyFlatbushMap, selectorChartSeriesFlatbushMap, selectorChartXAxis, selectorChartYAxis, selectorChartZoomIsInteracting } from "../useChartCartesianAxis/index.js";
12
10
  import { selectorChartSeriesProcessed } from "../../corePlugins/useChartSeries/useChartSeries.selectors.js";
13
11
  import { selectorChartDrawingArea } from "../../corePlugins/useChartDimensions/index.js";
12
+ import { findClosestPoints } from "./findClosestPoints.js";
14
13
  export const useChartClosestPoint = ({
15
14
  svgRef,
16
15
  params,
@@ -36,9 +35,7 @@ export const useChartClosestPoint = ({
36
35
  series,
37
36
  seriesOrder
38
37
  } = useSelector(store, selectorChartSeriesProcessed)?.scatter ?? {};
39
- const voronoiRef = React.useRef({});
40
- const delauneyRef = React.useRef(undefined);
41
- const lastFind = React.useRef(undefined);
38
+ const flatbushMap = useSelector(store, zoomIsInteracting ? selectorChartSeriesEmptyFlatbushMap : selectorChartSeriesFlatbushMap);
42
39
  const defaultXAxisId = xAxisIds[0];
43
40
  const defaultYAxisId = yAxisIds[0];
44
41
  useEnhancedEffect(() => {
@@ -48,52 +45,6 @@ export const useChartClosestPoint = ({
48
45
  }
49
46
  }));
50
47
  }, [store, disableVoronoi]);
51
- useEnhancedEffect(() => {
52
- // This effect generate and store the Delaunay object that's used to map coordinate to closest point.
53
-
54
- if (zoomIsInteracting || seriesOrder === undefined || series === undefined || disableVoronoi) {
55
- // If there is no scatter chart series
56
- return;
57
- }
58
- voronoiRef.current = {};
59
- let points = [];
60
- seriesOrder.forEach(seriesId => {
61
- const {
62
- data,
63
- xAxisId,
64
- yAxisId
65
- } = series[seriesId];
66
- const xScale = xAxis[xAxisId ?? defaultXAxisId].scale;
67
- const yScale = yAxis[yAxisId ?? defaultYAxisId].scale;
68
- const getXPosition = getValueToPositionMapper(xScale);
69
- const getYPosition = getValueToPositionMapper(yScale);
70
- const seriesPoints = [];
71
- const seriesIndexes = [];
72
- for (let dataIndex = 0; dataIndex < data.length; dataIndex += 1) {
73
- const {
74
- x,
75
- y
76
- } = data[dataIndex];
77
- const pointX = getXPosition(x);
78
- const pointY = getYPosition(y);
79
- if (instance.isPointInside(pointX, pointY)) {
80
- seriesPoints.push(pointX);
81
- seriesPoints.push(pointY);
82
- seriesIndexes.push(dataIndex);
83
- }
84
- }
85
- voronoiRef.current[seriesId] = {
86
- seriesId,
87
- seriesIndexes,
88
- startIndex: points.length,
89
- endIndex: points.length + seriesPoints.length,
90
- markerSize: series[seriesId].markerSize
91
- };
92
- points = points.concat(seriesPoints);
93
- });
94
- delauneyRef.current = new Delaunay(points);
95
- lastFind.current = undefined;
96
- }, [zoomIsInteracting, defaultXAxisId, defaultYAxisId, series, seriesOrder, xAxis, yAxis, drawingArea, instance, disableVoronoi]);
97
48
  React.useEffect(() => {
98
49
  if (svgRef.current === null || disableVoronoi) {
99
50
  return undefined;
@@ -103,40 +54,48 @@ export const useChartClosestPoint = ({
103
54
  // Get mouse coordinate in global SVG space
104
55
  const svgPoint = getSVGPoint(element, event);
105
56
  if (!instance.isPointInside(svgPoint.x, svgPoint.y)) {
106
- lastFind.current = undefined;
107
57
  return 'outside-chart';
108
58
  }
109
- if (!delauneyRef.current) {
110
- return 'no-point-found';
111
- }
112
- const closestPointIndex = delauneyRef.current.find(svgPoint.x, svgPoint.y, lastFind.current);
113
- if (closestPointIndex === undefined) {
114
- return 'no-point-found';
59
+ let closestPoint = undefined;
60
+ for (const seriesId of seriesOrder ?? []) {
61
+ const aSeries = (series ?? {})[seriesId];
62
+ const flatbush = flatbushMap.get(seriesId);
63
+ if (!flatbush) {
64
+ continue;
65
+ }
66
+ const xAxisId = aSeries.xAxisId ?? defaultXAxisId;
67
+ const yAxisId = aSeries.yAxisId ?? defaultYAxisId;
68
+ const xAxisZoom = selectorChartAxisZoomData(store.getSnapshot(), xAxisId);
69
+ const yAxisZoom = selectorChartAxisZoomData(store.getSnapshot(), yAxisId);
70
+ const maxRadius = voronoiMaxRadius === 'item' ? aSeries.markerSize : voronoiMaxRadius;
71
+ const xZoomStart = (xAxisZoom?.start ?? 0) / 100;
72
+ const xZoomEnd = (xAxisZoom?.end ?? 100) / 100;
73
+ const yZoomStart = (yAxisZoom?.start ?? 0) / 100;
74
+ const yZoomEnd = (yAxisZoom?.end ?? 100) / 100;
75
+ const xScale = xAxis[xAxisId].scale;
76
+ const yScale = yAxis[yAxisId].scale;
77
+ const closestPointIndex = findClosestPoints(flatbush, drawingArea, aSeries.data, xScale, yScale, xZoomStart, xZoomEnd, yZoomStart, yZoomEnd, svgPoint.x, svgPoint.y, maxRadius)[0];
78
+ if (closestPointIndex === undefined) {
79
+ continue;
80
+ }
81
+ const point = aSeries.data[closestPointIndex];
82
+ const scaledX = xScale(point.x);
83
+ const scaledY = yScale(point.y);
84
+ const distSq = (scaledX - svgPoint.x) ** 2 + (scaledY - svgPoint.y) ** 2;
85
+ if (closestPoint === undefined || distSq < closestPoint.distanceSq) {
86
+ closestPoint = {
87
+ dataIndex: closestPointIndex,
88
+ seriesId,
89
+ distanceSq: distSq
90
+ };
91
+ }
115
92
  }
116
- lastFind.current = closestPointIndex;
117
- const closestSeries = Object.values(voronoiRef.current).find(value => {
118
- return 2 * closestPointIndex >= value.startIndex && 2 * closestPointIndex < value.endIndex;
119
- });
120
- if (closestSeries === undefined) {
93
+ if (closestPoint === undefined) {
121
94
  return 'no-point-found';
122
95
  }
123
-
124
- // The point index in the series with id=closestSeries.seriesId.
125
- const seriesPointIndex = (2 * closestPointIndex - voronoiRef.current[closestSeries.seriesId].startIndex) / 2;
126
- const dataIndex = voronoiRef.current[closestSeries.seriesId].seriesIndexes[seriesPointIndex];
127
- const maxRadius = voronoiMaxRadius === 'item' ? closestSeries.markerSize : voronoiMaxRadius;
128
- if (maxRadius !== undefined) {
129
- const pointX = delauneyRef.current.points[2 * closestPointIndex];
130
- const pointY = delauneyRef.current.points[2 * closestPointIndex + 1];
131
- const dist2 = (pointX - svgPoint.x) ** 2 + (pointY - svgPoint.y) ** 2;
132
- if (dist2 > maxRadius ** 2) {
133
- // The closest point is too far to be considered.
134
- return 'outside-voronoi-max-radius';
135
- }
136
- }
137
96
  return {
138
- seriesId: closestSeries.seriesId,
139
- dataIndex
97
+ seriesId: closestPoint.seriesId,
98
+ dataIndex: closestPoint.dataIndex
140
99
  };
141
100
  }
142
101
 
@@ -211,7 +170,7 @@ export const useChartClosestPoint = ({
211
170
  pressHandler.cleanup();
212
171
  pressEndHandler.cleanup();
213
172
  };
214
- }, [svgRef, yAxis, xAxis, voronoiMaxRadius, onItemClick, disableVoronoi, drawingArea, instance]);
173
+ }, [svgRef, yAxis, xAxis, voronoiMaxRadius, onItemClick, disableVoronoi, drawingArea, instance, seriesOrder, series, flatbushMap, defaultXAxisId, defaultYAxisId, store]);
215
174
 
216
175
  // Instance implementation
217
176
  const enableVoronoiCallback = useEventCallback(() => {