@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
@@ -1,60 +1,58 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
- // DOM utils taken from
2
+ // DOM utils adapted from
3
3
  // https://github.com/recharts/recharts/blob/master/src/util/DOMUtils.ts
4
4
 
5
5
  function isSsr() {
6
6
  return typeof window === 'undefined';
7
7
  }
8
8
  const stringCache = new Map();
9
+ export function clearStringMeasurementCache() {
10
+ stringCache.clear();
11
+ }
9
12
  const MAX_CACHE_NUM = 2000;
10
- const SPAN_STYLE = {
11
- position: 'absolute',
12
- top: '-20000px',
13
- left: 0,
14
- padding: 0,
15
- margin: 0,
16
- border: 'none',
17
- whiteSpace: 'pre'
18
- };
19
- const STYLE_LIST = ['minWidth', 'maxWidth', 'width', 'minHeight', 'maxHeight', 'height', 'top', 'left', 'fontSize', 'padding', 'margin', 'paddingLeft', 'paddingRight', 'paddingTop', 'paddingBottom', 'marginLeft', 'marginRight', 'marginTop', 'marginBottom'];
20
- export const MEASUREMENT_SPAN_ID = 'mui_measurement_span';
13
+ const PIXEL_STYLES = new Set(['minWidth', 'maxWidth', 'width', 'minHeight', 'maxHeight', 'height', 'top', 'left', 'fontSize', 'padding', 'margin', 'paddingLeft', 'paddingRight', 'paddingTop', 'paddingBottom', 'marginLeft', 'marginRight', 'marginTop', 'marginBottom']);
21
14
 
22
15
  /**
23
- *
16
+ * Convert number value to pixel value for certain CSS properties
24
17
  * @param name CSS property name
25
18
  * @param value
26
19
  * @returns add 'px' for distance properties
27
20
  */
28
- function autoCompleteStyle(name, value) {
29
- if (STYLE_LIST.indexOf(name) >= 0 && value === +value) {
21
+ function convertPixelValue(name, value) {
22
+ if (PIXEL_STYLES.has(name) && value === +value) {
30
23
  return `${value}px`;
31
24
  }
32
25
  return value;
33
26
  }
34
27
 
35
28
  /**
36
- *
29
+ * Converts camelcase to dash-case
37
30
  * @param text camelcase css property
38
- * @returns css property
39
31
  */
40
- function camelToMiddleLine(text) {
41
- const strs = text.split('');
42
- const formatStrs = strs.reduce((result, entry) => {
43
- if (entry === entry.toUpperCase()) {
44
- return [...result, '-', entry.toLowerCase()];
45
- }
46
- return [...result, entry];
47
- }, []);
48
- return formatStrs.join('');
32
+ const AZ = /([A-Z])/g;
33
+ function camelCaseToDashCase(text) {
34
+ return String(text).replace(AZ, match => `-${match.toLowerCase()}`);
49
35
  }
50
36
 
51
37
  /**
52
- *
38
+ * Converts a style object into a string to be used as a cache key
53
39
  * @param style React style object
54
40
  * @returns CSS styling string
55
41
  */
56
- export const getStyleString = style => Object.keys(style).sort().reduce((result, s) => `${result}${camelToMiddleLine(s)}:${autoCompleteStyle(s, style[s])};`, '');
57
- let domCleanTimeout;
42
+ export function getStyleString(style) {
43
+ let result = '';
44
+ for (const key in style) {
45
+ if (Object.hasOwn(style, key)) {
46
+ const k = key;
47
+ const value = style[k];
48
+ if (value === undefined) {
49
+ continue;
50
+ }
51
+ result += `${camelCaseToDashCase(k)}:${convertPixelValue(k, value)};`;
52
+ }
53
+ }
54
+ return result;
55
+ }
58
56
 
59
57
  /**
60
58
  *
@@ -69,7 +67,7 @@ export const getStringSize = (text, style = {}) => {
69
67
  height: 0
70
68
  };
71
69
  }
72
- const str = `${text}`;
70
+ const str = String(text);
73
71
  const styleString = getStyleString(style);
74
72
  const cacheKey = `${str}-${styleString}`;
75
73
  const size = stringCache.get(cacheKey);
@@ -77,22 +75,18 @@ export const getStringSize = (text, style = {}) => {
77
75
  return size;
78
76
  }
79
77
  try {
80
- let measurementSpan = document.getElementById(MEASUREMENT_SPAN_ID);
81
- if (measurementSpan === null) {
82
- measurementSpan = document.createElement('span');
83
- measurementSpan.setAttribute('id', MEASUREMENT_SPAN_ID);
84
- measurementSpan.setAttribute('aria-hidden', 'true');
85
- document.body.appendChild(measurementSpan);
86
- }
78
+ const measurementSpanContainer = getMeasurementContainer();
79
+ const measurementElem = document.createElementNS('http://www.w3.org/2000/svg', 'text');
80
+
87
81
  // Need to use CSS Object Model (CSSOM) to be able to comply with Content Security Policy (CSP)
88
82
  // https://en.wikipedia.org/wiki/Content_Security_Policy
89
- const measurementSpanStyle = _extends({}, SPAN_STYLE, style);
90
- Object.keys(measurementSpanStyle).map(styleKey => {
91
- measurementSpan.style[camelToMiddleLine(styleKey)] = autoCompleteStyle(styleKey, measurementSpanStyle[styleKey]);
83
+ Object.keys(style).map(styleKey => {
84
+ measurementElem.style[camelCaseToDashCase(styleKey)] = convertPixelValue(styleKey, style[styleKey]);
92
85
  return styleKey;
93
86
  });
94
- measurementSpan.textContent = str;
95
- const rect = measurementSpan.getBoundingClientRect();
87
+ measurementElem.textContent = str;
88
+ measurementSpanContainer.replaceChildren(measurementElem);
89
+ const rect = measurementElem.getBoundingClientRect();
96
90
  const result = {
97
91
  width: rect.width,
98
92
  height: rect.height
@@ -103,15 +97,7 @@ export const getStringSize = (text, style = {}) => {
103
97
  }
104
98
  if (process.env.NODE_ENV === 'test') {
105
99
  // In test environment, we clean the measurement span immediately
106
- measurementSpan.textContent = '';
107
- } else {
108
- if (domCleanTimeout) {
109
- clearTimeout(domCleanTimeout);
110
- }
111
- domCleanTimeout = setTimeout(() => {
112
- // Limit node cleaning to once per render cycle
113
- measurementSpan.textContent = '';
114
- }, 0);
100
+ measurementSpanContainer.replaceChildren();
115
101
  }
116
102
  return result;
117
103
  } catch {
@@ -120,4 +106,81 @@ export const getStringSize = (text, style = {}) => {
120
106
  height: 0
121
107
  };
122
108
  }
123
- };
109
+ };
110
+ export function batchMeasureStrings(texts, style = {}) {
111
+ if (isSsr()) {
112
+ return new Map(Array.from(texts).map(text => [text, {
113
+ width: 0,
114
+ height: 0
115
+ }]));
116
+ }
117
+ const sizeMap = new Map();
118
+ const textToMeasure = [];
119
+ const styleString = getStyleString(style);
120
+ for (const text of texts) {
121
+ const cacheKey = `${text}-${styleString}`;
122
+ const size = stringCache.get(cacheKey);
123
+ if (size) {
124
+ sizeMap.set(text, size);
125
+ } else {
126
+ textToMeasure.push(text);
127
+ }
128
+ }
129
+ const measurementContainer = getMeasurementContainer();
130
+ // Need to use CSS Object Model (CSSOM) to be able to comply with Content Security Policy (CSP)
131
+ // https://en.wikipedia.org/wiki/Content_Security_Policy
132
+ const measurementSpanStyle = _extends({}, style);
133
+ Object.keys(measurementSpanStyle).map(styleKey => {
134
+ measurementContainer.style[camelCaseToDashCase(styleKey)] = convertPixelValue(styleKey, measurementSpanStyle[styleKey]);
135
+ return styleKey;
136
+ });
137
+ const measurementElems = [];
138
+ for (const string of textToMeasure) {
139
+ const measurementElem = document.createElementNS('http://www.w3.org/2000/svg', 'text');
140
+ measurementElem.textContent = `${string}`;
141
+ measurementElems.push(measurementElem);
142
+ }
143
+ measurementContainer.replaceChildren(...measurementElems);
144
+ for (let i = 0; i < textToMeasure.length; i += 1) {
145
+ const text = textToMeasure[i];
146
+ const measurementSpan = measurementContainer.children[i];
147
+ const rect = measurementSpan.getBoundingClientRect();
148
+ const result = {
149
+ width: rect.width,
150
+ height: rect.height
151
+ };
152
+ const cacheKey = `${text}-${styleString}`;
153
+ stringCache.set(cacheKey, result);
154
+ sizeMap.set(text, result);
155
+ }
156
+ if (stringCache.size + 1 > MAX_CACHE_NUM) {
157
+ stringCache.clear();
158
+ }
159
+ if (process.env.NODE_ENV === 'test') {
160
+ // In test environment, we clean the measurement span immediately
161
+ measurementContainer.replaceChildren();
162
+ }
163
+ return sizeMap;
164
+ }
165
+ let measurementContainer = null;
166
+
167
+ /**
168
+ * Get (or create) a hidden span element to measure text size.
169
+ */
170
+ function getMeasurementContainer() {
171
+ if (measurementContainer === null) {
172
+ measurementContainer = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
173
+ measurementContainer.setAttribute('aria-hidden', 'true');
174
+ measurementContainer.style.position = 'absolute';
175
+ measurementContainer.style.top = '-20000px';
176
+ measurementContainer.style.left = '0';
177
+ measurementContainer.style.padding = '0';
178
+ measurementContainer.style.margin = '0';
179
+ measurementContainer.style.border = 'none';
180
+ measurementContainer.style.pointerEvents = 'none';
181
+ measurementContainer.style.visibility = 'hidden';
182
+ measurementContainer.style.contain = 'strict';
183
+ document.body.appendChild(measurementContainer);
184
+ }
185
+ return measurementContainer;
186
+ }
@@ -27,6 +27,7 @@ export * from "./plugins/featurePlugins/useChartInteraction/index.js";
27
27
  export * from "./plugins/featurePlugins/useChartHighlight/index.js";
28
28
  export * from "./plugins/featurePlugins/useChartKeyboardNavigation/index.js";
29
29
  export * from "./plugins/featurePlugins/useChartClosestPoint/index.js";
30
+ export * from "./plugins/featurePlugins/useChartBrush/index.js";
30
31
  export * from "./plugins/utils/selectors.js";
31
32
  export { getAxisTriggerTooltip as getCartesianAxisTriggerTooltip } from "./plugins/featurePlugins/useChartCartesianAxis/getAxisTriggerTooltip.js";
32
33
  export { getAxisIndex as getCartesianAxisIndex } from "./plugins/featurePlugins/useChartCartesianAxis/getAxisValue.js";
@@ -32,6 +32,7 @@ export * from "./plugins/featurePlugins/useChartInteraction/index.js";
32
32
  export * from "./plugins/featurePlugins/useChartHighlight/index.js";
33
33
  export * from "./plugins/featurePlugins/useChartKeyboardNavigation/index.js";
34
34
  export * from "./plugins/featurePlugins/useChartClosestPoint/index.js";
35
+ export * from "./plugins/featurePlugins/useChartBrush/index.js";
35
36
  export * from "./plugins/utils/selectors.js";
36
37
  export { getAxisTriggerTooltip as getCartesianAxisTriggerTooltip } from "./plugins/featurePlugins/useChartCartesianAxis/getAxisTriggerTooltip.js";
37
38
  export { getAxisIndex as getCartesianAxisIndex } from "./plugins/featurePlugins/useChartCartesianAxis/getAxisValue.js";
@@ -6,6 +6,7 @@ import { UseChartKeyboardNavigationSignature } from "./featurePlugins/useChartKe
6
6
  import { UseChartPolarAxisSignature } from "./featurePlugins/useChartPolarAxis/index.js";
7
7
  import { UseChartClosestPointSignature } from "./featurePlugins/useChartClosestPoint/index.js";
8
8
  import { UseChartZAxisSignature } from "./featurePlugins/useChartZAxis/index.js";
9
- export type AllPluginSignatures<TSeries extends ChartSeriesType = ChartSeriesType> = [UseChartZAxisSignature, UseChartCartesianAxisSignature<TSeries>, UseChartPolarAxisSignature, UseChartInteractionSignature, UseChartHighlightSignature, UseChartClosestPointSignature, UseChartKeyboardNavigationSignature];
10
- export type DefaultPluginSignatures<TSeries extends ChartSeriesType = ChartSeriesType> = [UseChartZAxisSignature, UseChartCartesianAxisSignature<TSeries>, UseChartInteractionSignature, UseChartHighlightSignature, UseChartClosestPointSignature, UseChartKeyboardNavigationSignature];
11
- export declare const DEFAULT_PLUGINS: readonly [import("./models/index.js").ChartPlugin<UseChartZAxisSignature>, import("./models/index.js").ChartPlugin<UseChartCartesianAxisSignature<any>>, import("./models/index.js").ChartPlugin<UseChartInteractionSignature>, import("./models/index.js").ChartPlugin<UseChartHighlightSignature>, import("./models/index.js").ChartPlugin<UseChartClosestPointSignature>, import("./models/index.js").ChartPlugin<UseChartKeyboardNavigationSignature>];
9
+ import { UseChartBrushSignature } from "./featurePlugins/useChartBrush/index.js";
10
+ export type AllPluginSignatures<TSeries extends ChartSeriesType = ChartSeriesType> = [UseChartZAxisSignature, UseChartBrushSignature, UseChartCartesianAxisSignature<TSeries>, UseChartPolarAxisSignature, UseChartInteractionSignature, UseChartHighlightSignature, UseChartClosestPointSignature, UseChartKeyboardNavigationSignature];
11
+ export type DefaultPluginSignatures<TSeries extends ChartSeriesType = ChartSeriesType> = [UseChartZAxisSignature, UseChartBrushSignature, UseChartCartesianAxisSignature<TSeries>, UseChartInteractionSignature, UseChartHighlightSignature, UseChartClosestPointSignature, UseChartKeyboardNavigationSignature];
12
+ export declare const DEFAULT_PLUGINS: readonly [import("./models/index.js").ChartPlugin<UseChartZAxisSignature>, import("./models/index.js").ChartPlugin<UseChartBrushSignature>, import("./models/index.js").ChartPlugin<UseChartCartesianAxisSignature<any>>, import("./models/index.js").ChartPlugin<UseChartInteractionSignature>, import("./models/index.js").ChartPlugin<UseChartHighlightSignature>, import("./models/index.js").ChartPlugin<UseChartClosestPointSignature>, import("./models/index.js").ChartPlugin<UseChartKeyboardNavigationSignature>];
@@ -6,4 +6,5 @@ import { useChartInteraction } from "./featurePlugins/useChartInteraction/index.
6
6
  import { useChartKeyboardNavigation } from "./featurePlugins/useChartKeyboardNavigation/index.js";
7
7
  import { useChartClosestPoint } from "./featurePlugins/useChartClosestPoint/index.js";
8
8
  import { useChartZAxis } from "./featurePlugins/useChartZAxis/index.js";
9
- export const DEFAULT_PLUGINS = [useChartZAxis, useChartCartesianAxis, useChartInteraction, useChartHighlight, useChartClosestPoint, useChartKeyboardNavigation];
9
+ import { useChartBrush } from "./featurePlugins/useChartBrush/index.js";
10
+ export const DEFAULT_PLUGINS = [useChartZAxis, useChartBrush, useChartCartesianAxis, useChartInteraction, useChartHighlight, useChartClosestPoint, useChartKeyboardNavigation];
@@ -18,14 +18,26 @@ export const useChartInteractionListener = ({
18
18
  name: 'pan',
19
19
  threshold: 0,
20
20
  maxPointers: 1
21
+ }), new MoveGesture({
22
+ name: 'move',
23
+ preventIf: ['pan', 'zoomPinch', 'zoomPan']
24
+ }), new TapGesture({
25
+ name: 'tap',
26
+ preventIf: ['pan', 'zoomPinch', 'zoomPan']
27
+ }), new PressGesture({
28
+ name: 'quickPress',
29
+ duration: 50
21
30
  }), new PanGesture({
31
+ name: 'brush',
32
+ threshold: 0,
33
+ maxPointers: 1
34
+ }),
35
+ // Zoom gestures
36
+ new PanGesture({
22
37
  name: 'zoomPan',
23
38
  threshold: 0,
24
39
  maxPointers: 1,
25
40
  preventIf: ['zoomTapAndDrag', 'zoomPressAndDrag']
26
- }), new MoveGesture({
27
- name: 'move',
28
- preventIf: ['pan', 'zoomPinch', 'zoomPan'] // Prevent move gesture when pan is active
29
41
  }), new PinchGesture({
30
42
  name: 'zoomPinch',
31
43
  threshold: 5,
@@ -34,12 +46,6 @@ export const useChartInteractionListener = ({
34
46
  name: 'zoomTurnWheel',
35
47
  sensitivity: 0.01,
36
48
  initialDelta: 1
37
- }), new TapGesture({
38
- name: 'tap',
39
- preventIf: ['pan', 'zoomPan', 'zoomPinch']
40
- }), new PressGesture({
41
- name: 'quickPress',
42
- duration: 50
43
49
  }), new TapAndDragGesture({
44
50
  name: 'zoomTapAndDrag',
45
51
  dragThreshold: 10
@@ -56,7 +62,7 @@ export const useChartInteractionListener = ({
56
62
  if (!svg || !gestureManager) {
57
63
  return undefined;
58
64
  }
59
- gestureManager.registerElement(['pan', 'move', 'zoomPinch', 'zoomPan', 'zoomTurnWheel', 'tap', 'quickPress', 'zoomTapAndDrag', 'zoomPressAndDrag'], svg);
65
+ gestureManager.registerElement(['pan', 'move', 'zoomPinch', 'zoomPan', 'zoomTurnWheel', 'tap', 'quickPress', 'zoomTapAndDrag', 'zoomPressAndDrag', 'brush'], svg);
60
66
  return () => {
61
67
  // Cleanup gesture manager
62
68
  gestureManager.unregisterAllGestures(svg);
@@ -1,11 +1,11 @@
1
1
  import { MoveEvent, PanEvent, PanGestureOptions, PinchEvent, PinchGestureOptions, PressEvent, TapEvent, TurnWheelEvent, type PressAndDragEvent, type PressAndDragGestureOptions, type TapAndDragEvent, type TapAndDragGestureOptions, type TurnWheelGestureOptions } from '@mui/x-internal-gestures/core';
2
2
  import { ChartPluginSignature } from "../../models/index.js";
3
- export type ChartInteraction = 'pan' | 'panStart' | 'panEnd' | 'zoomPan' | 'zoomPanStart' | 'zoomPanEnd' | 'zoomPinch' | 'zoomPinchStart' | 'zoomPinchEnd' | 'zoomTurnWheel' | 'zoomTapAndDrag' | 'zoomTapAndDragStart' | 'zoomTapAndDragEnd' | 'zoomPressAndDrag' | 'zoomPressAndDragStart' | 'zoomPressAndDragEnd' | 'move' | 'moveStart' | 'moveEnd' | 'tap' | 'quickPress' | 'quickPressEnd';
3
+ export type ChartInteraction = 'pan' | 'panStart' | 'panEnd' | 'zoomPan' | 'zoomPanStart' | 'zoomPanEnd' | 'zoomPinch' | 'zoomPinchStart' | 'zoomPinchEnd' | 'zoomTurnWheel' | 'zoomTapAndDrag' | 'zoomTapAndDragStart' | 'zoomTapAndDragEnd' | 'zoomPressAndDrag' | 'zoomPressAndDragStart' | 'zoomPressAndDragEnd' | 'move' | 'moveStart' | 'moveEnd' | 'tap' | 'quickPress' | 'quickPressEnd' | 'brush' | 'brushStart' | 'brushCancel' | 'brushEnd';
4
4
  export type InteractionListenerResult = {
5
5
  cleanup: () => void;
6
6
  };
7
7
  export type AddInteractionListener = {
8
- <CustomData extends Record<string, unknown> = Record<string, unknown>>(interaction: 'pan' | 'panStart' | 'panEnd' | 'zoomPan' | 'zoomPanStart' | 'zoomPanEnd', callback: (event: PanEvent<CustomData>) => void, options?: boolean | AddEventListenerOptions): InteractionListenerResult;
8
+ <CustomData extends Record<string, unknown> = Record<string, unknown>>(interaction: 'pan' | 'panStart' | 'panEnd' | 'zoomPan' | 'zoomPanStart' | 'zoomPanEnd' | 'brush' | 'brushStart' | 'brushCancel' | 'brushEnd', callback: (event: PanEvent<CustomData>) => void, options?: boolean | AddEventListenerOptions): InteractionListenerResult;
9
9
  <CustomData extends Record<string, unknown> = Record<string, unknown>>(interaction: 'zoomPinch' | 'zoomPinchStart' | 'zoomPinchEnd', callback: (event: PinchEvent<CustomData>) => void, options?: boolean | AddEventListenerOptions): InteractionListenerResult;
10
10
  <CustomData extends Record<string, unknown> = Record<string, unknown>>(interaction: 'zoomTurnWheel', callback: (event: TurnWheelEvent<CustomData>) => void, options?: boolean | AddEventListenerOptions): InteractionListenerResult;
11
11
  <CustomData extends Record<string, unknown> = Record<string, unknown>>(interaction: 'move' | 'moveStart' | 'moveEnd', callback: (event: MoveEvent<CustomData>) => void, options?: boolean | AddEventListenerOptions): InteractionListenerResult;
@@ -0,0 +1,3 @@
1
+ export * from "./useChartBrush.js";
2
+ export * from "./useChartBrush.types.js";
3
+ export * from "./useChartBrush.selectors.js";
@@ -0,0 +1,3 @@
1
+ export * from "./useChartBrush.js";
2
+ export * from "./useChartBrush.types.js";
3
+ export * from "./useChartBrush.selectors.js";
@@ -0,0 +1,3 @@
1
+ import { ChartPlugin } from "../../models/index.js";
2
+ import { UseChartBrushSignature } from "./useChartBrush.types.js";
3
+ export declare const useChartBrush: ChartPlugin<UseChartBrushSignature>;
@@ -0,0 +1,109 @@
1
+ 'use client';
2
+
3
+ import _extends from "@babel/runtime/helpers/esm/extends";
4
+ import useEventCallback from '@mui/utils/useEventCallback';
5
+ import * as React from 'react';
6
+ import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
7
+ import { getSVGPoint } from "../../../getSVGPoint.js";
8
+ export const useChartBrush = ({
9
+ store,
10
+ svgRef,
11
+ instance,
12
+ params
13
+ }) => {
14
+ useEnhancedEffect(() => {
15
+ store.update(prev => {
16
+ return _extends({}, prev, {
17
+ brush: _extends({}, prev.brush, {
18
+ enabled: params.brushConfig.enabled,
19
+ preventTooltip: params.brushConfig.preventTooltip,
20
+ preventHighlight: params.brushConfig.preventHighlight
21
+ })
22
+ });
23
+ });
24
+ }, [store, params.brushConfig.enabled, params.brushConfig.preventTooltip, params.brushConfig.preventHighlight]);
25
+ const setBrushCoordinates = useEventCallback(function setBrushCoordinates(point) {
26
+ store.update(prev => {
27
+ return _extends({}, prev, {
28
+ brush: _extends({}, prev.brush, {
29
+ start: prev.brush.start ?? point,
30
+ current: point
31
+ })
32
+ });
33
+ });
34
+ });
35
+ const clearBrush = useEventCallback(function clearBrush() {
36
+ store.update(prev => {
37
+ return _extends({}, prev, {
38
+ brush: _extends({}, prev.brush, {
39
+ start: null,
40
+ current: null
41
+ })
42
+ });
43
+ });
44
+ });
45
+ React.useEffect(() => {
46
+ const element = svgRef.current;
47
+ if (element === null || !store.getSnapshot().brush.enabled) {
48
+ return () => {};
49
+ }
50
+ const handleBrushStart = event => {
51
+ if (event.detail.target?.closest('[data-charts-zoom-slider]')) {
52
+ return;
53
+ }
54
+ const point = getSVGPoint(element, {
55
+ clientX: event.detail.initialCentroid.x,
56
+ clientY: event.detail.initialCentroid.y
57
+ });
58
+ setBrushCoordinates(point);
59
+ };
60
+ const handleBrush = event => {
61
+ const currentPoint = getSVGPoint(element, {
62
+ clientX: event.detail.centroid.x,
63
+ clientY: event.detail.centroid.y
64
+ });
65
+ setBrushCoordinates(currentPoint);
66
+ };
67
+ const brushStartHandler = instance.addInteractionListener('brushStart', handleBrushStart);
68
+ const brushHandler = instance.addInteractionListener('brush', handleBrush);
69
+ const brushCancelHandler = instance.addInteractionListener('brushCancel', clearBrush);
70
+ const brushEndHandler = instance.addInteractionListener('brushEnd', clearBrush);
71
+ return () => {
72
+ brushStartHandler.cleanup();
73
+ brushHandler.cleanup();
74
+ brushEndHandler.cleanup();
75
+ brushCancelHandler.cleanup();
76
+ };
77
+ }, [svgRef, instance, store, clearBrush, setBrushCoordinates]);
78
+ return {
79
+ instance: {
80
+ setBrushCoordinates,
81
+ clearBrush
82
+ }
83
+ };
84
+ };
85
+ useChartBrush.params = {
86
+ brushConfig: true
87
+ };
88
+ useChartBrush.getDefaultizedParams = ({
89
+ params
90
+ }) => {
91
+ return _extends({}, params, {
92
+ brushConfig: {
93
+ enabled: params?.brushConfig?.enabled ?? false,
94
+ preventTooltip: params?.brushConfig?.preventTooltip ?? true,
95
+ preventHighlight: params?.brushConfig?.preventHighlight ?? true
96
+ }
97
+ });
98
+ };
99
+ useChartBrush.getInitialState = params => {
100
+ return {
101
+ brush: {
102
+ enabled: params.brushConfig.enabled,
103
+ preventTooltip: params.brushConfig.preventTooltip,
104
+ preventHighlight: params.brushConfig.preventHighlight,
105
+ start: null,
106
+ current: null
107
+ }
108
+ };
109
+ };
@@ -0,0 +1,82 @@
1
+ import { type ChartOptionalRootSelector } from "../../utils/selectors.js";
2
+ import type { UseChartBrushSignature } from "./useChartBrush.types.js";
3
+ export declare const selectorBrush: ChartOptionalRootSelector<UseChartBrushSignature>;
4
+ export declare const selectorBrushStart: 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("./useChartBrush.types.js").UseChartBrushState> & {
5
+ cacheKey: import("../../models/index.js").ChartStateCacheKey;
6
+ } & {
7
+ cacheKey: import("../../models/index.js").ChartStateCacheKey;
8
+ }, import("./useChartBrush.types.js").Point | null | undefined, any[]>;
9
+ export declare const selectorBrushCurrent: 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("./useChartBrush.types.js").UseChartBrushState> & {
10
+ cacheKey: import("../../models/index.js").ChartStateCacheKey;
11
+ } & {
12
+ cacheKey: import("../../models/index.js").ChartStateCacheKey;
13
+ }, import("./useChartBrush.types.js").Point | null | undefined, any[]>;
14
+ export declare const selectorBrushStartX: 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("./useChartBrush.types.js").UseChartBrushState> & {
15
+ cacheKey: import("../../models/index.js").ChartStateCacheKey;
16
+ } & {
17
+ cacheKey: import("../../models/index.js").ChartStateCacheKey;
18
+ }, number | null, any[]>;
19
+ export declare const selectorBrushStartY: 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("./useChartBrush.types.js").UseChartBrushState> & {
20
+ cacheKey: import("../../models/index.js").ChartStateCacheKey;
21
+ } & {
22
+ cacheKey: import("../../models/index.js").ChartStateCacheKey;
23
+ }, number | null, any[]>;
24
+ export declare const selectorBrushCurrentX: 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("./useChartBrush.types.js").UseChartBrushState> & {
25
+ cacheKey: import("../../models/index.js").ChartStateCacheKey;
26
+ } & {
27
+ cacheKey: import("../../models/index.js").ChartStateCacheKey;
28
+ }, number | null, any[]>;
29
+ export declare const selectorBrushCurrentY: 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("./useChartBrush.types.js").UseChartBrushState> & {
30
+ cacheKey: import("../../models/index.js").ChartStateCacheKey;
31
+ } & {
32
+ cacheKey: import("../../models/index.js").ChartStateCacheKey;
33
+ }, number | null, any[]>;
34
+ export declare const selectorBrushState: 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("./useChartBrush.types.js").UseChartBrushState> & {
35
+ cacheKey: import("../../models/index.js").ChartStateCacheKey;
36
+ } & {
37
+ cacheKey: import("../../models/index.js").ChartStateCacheKey;
38
+ }, {
39
+ start: {
40
+ x: number;
41
+ y: number;
42
+ };
43
+ current: {
44
+ x: number;
45
+ y: number;
46
+ };
47
+ } | null, any[]>;
48
+ export declare const selectorBrushConfigNoZoom: 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<{}> & {
49
+ cacheKey: import("../../models/index.js").ChartStateCacheKey;
50
+ } & {
51
+ cacheKey: import("../../models/index.js").ChartStateCacheKey;
52
+ }, "x" | "y" | "xy", any[]>;
53
+ export declare const selectorBrushConfigZoom: 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/index.js").UseChartCartesianAxisState> & {
54
+ cacheKey: import("../../models/index.js").ChartStateCacheKey;
55
+ } & {
56
+ cacheKey: import("../../models/index.js").ChartStateCacheKey;
57
+ }, "x" | "y" | "xy" | null, []>;
58
+ export declare const selectorBrushConfig: 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<{}> & {
59
+ cacheKey: import("../../models/index.js").ChartStateCacheKey;
60
+ } & {
61
+ cacheKey: import("../../models/index.js").ChartStateCacheKey;
62
+ } & Partial<import("../useChartCartesianAxis/index.js").UseChartCartesianAxisState>, "x" | "y" | "xy", any[]>;
63
+ export declare const selectorIsBrushEnabled: 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("./useChartBrush.types.js").UseChartBrushState> & {
64
+ cacheKey: import("../../models/index.js").ChartStateCacheKey;
65
+ } & {
66
+ cacheKey: import("../../models/index.js").ChartStateCacheKey;
67
+ }, boolean | undefined, any[]>;
68
+ export declare const selectorIsBrushSelectionActive: 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("./useChartBrush.types.js").UseChartBrushState> & {
69
+ cacheKey: import("../../models/index.js").ChartStateCacheKey;
70
+ } & {
71
+ cacheKey: import("../../models/index.js").ChartStateCacheKey;
72
+ }, boolean | undefined, any[]>;
73
+ export declare const selectorBrushShouldPreventAxisHighlight: 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("./useChartBrush.types.js").UseChartBrushState> & {
74
+ cacheKey: import("../../models/index.js").ChartStateCacheKey;
75
+ } & {
76
+ cacheKey: import("../../models/index.js").ChartStateCacheKey;
77
+ }, boolean | undefined, any[]>;
78
+ export declare const selectorBrushShouldPreventTooltip: 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("./useChartBrush.types.js").UseChartBrushState> & {
79
+ cacheKey: import("../../models/index.js").ChartStateCacheKey;
80
+ } & {
81
+ cacheKey: import("../../models/index.js").ChartStateCacheKey;
82
+ }, boolean | undefined, any[]>;
@@ -0,0 +1,75 @@
1
+ import { createSelector } from "../../utils/selectors.js";
2
+ import { selectorChartZoomOptionsLookup } from "../useChartCartesianAxis/index.js";
3
+ import { selectorChartSeriesProcessed } from "../../corePlugins/useChartSeries/index.js";
4
+ export const selectorBrush = state => state.brush;
5
+ export const selectorBrushStart = createSelector([selectorBrush], brush => brush?.start);
6
+ export const selectorBrushCurrent = createSelector([selectorBrush], brush => brush?.current);
7
+ export const selectorBrushStartX = createSelector([selectorBrush], brush => brush?.start?.x ?? null);
8
+ export const selectorBrushStartY = createSelector([selectorBrush], brush => brush?.start?.y ?? null);
9
+ export const selectorBrushCurrentX = createSelector([selectorBrush], brush => brush?.current?.x ?? null);
10
+ export const selectorBrushCurrentY = createSelector([selectorBrush], brush => brush?.current?.y ?? null);
11
+ export const selectorBrushState = createSelector([selectorBrushStartX, selectorBrushStartY, selectorBrushCurrentX, selectorBrushCurrentY], (startX, startY, currentX, currentY) => {
12
+ if (startX === null || startY === null || currentX === null || currentY === null) {
13
+ return null;
14
+ }
15
+ return {
16
+ start: {
17
+ x: startX,
18
+ y: startY
19
+ },
20
+ current: {
21
+ x: currentX,
22
+ y: currentY
23
+ }
24
+ };
25
+ });
26
+ export const selectorBrushConfigNoZoom = createSelector([selectorChartSeriesProcessed], series => {
27
+ let hasHorizontal = false;
28
+ let isBothDirections = false;
29
+ if (series) {
30
+ Object.entries(series).forEach(([seriesType, seriesData]) => {
31
+ if (Object.values(seriesData.series).some(s => s.layout === 'horizontal')) {
32
+ hasHorizontal = true;
33
+ }
34
+ if (seriesType === 'scatter' && seriesData.seriesOrder.length > 0) {
35
+ isBothDirections = true;
36
+ }
37
+ });
38
+ }
39
+ if (isBothDirections) {
40
+ return 'xy';
41
+ }
42
+ if (hasHorizontal) {
43
+ return 'y';
44
+ }
45
+ return 'x';
46
+ });
47
+ export const selectorBrushConfigZoom = createSelector([selectorChartZoomOptionsLookup], optionsLookup => {
48
+ let hasX = false;
49
+ let hasY = false;
50
+ Object.values(optionsLookup).forEach(options => {
51
+ if (options.axisDirection === 'y') {
52
+ hasY = true;
53
+ }
54
+ if (options.axisDirection === 'x') {
55
+ hasX = true;
56
+ }
57
+ });
58
+ if (hasX && hasY) {
59
+ return 'xy';
60
+ }
61
+ if (hasY) {
62
+ return 'y';
63
+ }
64
+ if (hasX) {
65
+ return 'x';
66
+ }
67
+ return null;
68
+ });
69
+ export const selectorBrushConfig = createSelector([selectorBrushConfigNoZoom, selectorBrushConfigZoom], (configNoZoom, configZoom) => configZoom ?? configNoZoom);
70
+ export const selectorIsBrushEnabled = createSelector([selectorBrush], brush => brush?.enabled);
71
+ export const selectorIsBrushSelectionActive = createSelector([selectorBrush], brush => {
72
+ return brush?.enabled && brush?.start !== null && brush?.current !== null;
73
+ });
74
+ export const selectorBrushShouldPreventAxisHighlight = createSelector([selectorBrush, selectorIsBrushSelectionActive], (brush, isBrushSelectionActive) => isBrushSelectionActive && brush?.preventHighlight);
75
+ export const selectorBrushShouldPreventTooltip = createSelector([selectorBrush, selectorIsBrushSelectionActive], (brush, isBrushSelectionActive) => isBrushSelectionActive && brush?.preventTooltip);