@mui/x-charts 8.13.1 → 8.14.1

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 (134) hide show
  1. package/BarChart/BarChart.js +44 -36
  2. package/BarChart/useBarPlotData.js +20 -33
  3. package/CHANGELOG.md +204 -1
  4. package/ChartContainer/ChartContainer.js +68 -56
  5. package/ChartsTooltip/ChartsTooltipContainer.js +2 -0
  6. package/ChartsXAxis/useAxisTicksProps.d.ts +197 -355
  7. package/ChartsYAxis/useAxisTicksProps.d.ts +197 -355
  8. package/Gauge/Gauge.js +2 -9
  9. package/Gauge/GaugeReferenceArc.d.ts +4 -1
  10. package/Gauge/GaugeReferenceArc.js +12 -3
  11. package/Gauge/GaugeValueArc.d.ts +4 -1
  12. package/Gauge/GaugeValueArc.js +16 -8
  13. package/Gauge/GaugeValueText.js +3 -1
  14. package/LineChart/LineChart.js +44 -36
  15. package/PieChart/PieArc.d.ts +18 -4
  16. package/PieChart/PieArc.js +11 -5
  17. package/PieChart/PieArcPlot.js +3 -1
  18. package/ScatterChart/ScatterChart.js +44 -36
  19. package/ScatterChart/seriesConfig/seriesProcessor.js +1 -1
  20. package/SparkLineChart/SparkLineChart.js +44 -36
  21. package/esm/BarChart/BarChart.js +44 -36
  22. package/esm/BarChart/useBarPlotData.js +20 -33
  23. package/esm/ChartContainer/ChartContainer.js +68 -56
  24. package/esm/ChartsTooltip/ChartsTooltipContainer.js +2 -0
  25. package/esm/ChartsXAxis/useAxisTicksProps.d.ts +197 -355
  26. package/esm/ChartsYAxis/useAxisTicksProps.d.ts +197 -355
  27. package/esm/Gauge/Gauge.js +2 -9
  28. package/esm/Gauge/GaugeReferenceArc.d.ts +4 -1
  29. package/esm/Gauge/GaugeReferenceArc.js +11 -2
  30. package/esm/Gauge/GaugeValueArc.d.ts +4 -1
  31. package/esm/Gauge/GaugeValueArc.js +16 -8
  32. package/esm/Gauge/GaugeValueText.js +3 -1
  33. package/esm/LineChart/LineChart.js +44 -36
  34. package/esm/PieChart/PieArc.d.ts +18 -4
  35. package/esm/PieChart/PieArc.js +11 -5
  36. package/esm/PieChart/PieArcPlot.js +3 -1
  37. package/esm/ScatterChart/ScatterChart.js +44 -36
  38. package/esm/ScatterChart/seriesConfig/seriesProcessor.js +1 -1
  39. package/esm/SparkLineChart/SparkLineChart.js +44 -36
  40. package/esm/hooks/animation/useAnimate.js +5 -3
  41. package/esm/hooks/useScale.d.ts +5 -1
  42. package/esm/index.js +1 -1
  43. package/esm/internals/Flatbush.bench.d.ts +1 -0
  44. package/esm/internals/Flatbush.bench.js +42 -0
  45. package/esm/internals/Flatbush.d.ts +63 -0
  46. package/esm/internals/Flatbush.js +468 -0
  47. package/esm/internals/animation/useAnimateInternal.d.ts +1 -1
  48. package/esm/internals/animation/useAnimateInternal.js +1 -1
  49. package/esm/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.js +8 -8
  50. package/esm/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.types.d.ts +4 -2
  51. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/computeAxisValue.d.ts +9 -11
  52. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/computeAxisValue.js +4 -28
  53. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/createAxisFilterMapper.d.ts +4 -5
  54. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/createAxisFilterMapper.js +3 -24
  55. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/domain.d.ts +20 -0
  56. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/domain.js +77 -0
  57. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisScale.d.ts +4 -65
  58. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisScale.js +7 -104
  59. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisValue.d.ts +6 -2
  60. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisValue.js +3 -6
  61. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisPreview.selectors.d.ts +3 -3
  62. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisPreview.selectors.js +31 -39
  63. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisRendering.selectors.d.ts +185 -6
  64. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisRendering.selectors.js +199 -47
  65. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianInteraction.selectors.js +4 -1
  66. package/esm/internals/plugins/featurePlugins/useChartClosestPoint/findClosestPoints.d.ts +5 -0
  67. package/esm/internals/plugins/featurePlugins/useChartClosestPoint/findClosestPoints.js +33 -0
  68. package/esm/internals/plugins/featurePlugins/useChartClosestPoint/useChartClosestPoint.js +40 -81
  69. package/esm/internals/plugins/featurePlugins/useChartHighlight/useChartHighlight.js +10 -3
  70. package/esm/internals/plugins/featurePlugins/useChartHighlight/useChartHighlight.selectors.d.ts +4 -4
  71. package/esm/internals/plugins/featurePlugins/useChartHighlight/useChartHighlight.selectors.js +3 -2
  72. package/esm/internals/plugins/featurePlugins/useChartHighlight/useChartHighlight.types.d.ts +6 -0
  73. package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.js +5 -1
  74. package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.selectors.d.ts +9 -1
  75. package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.selectors.js +10 -1
  76. package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.types.d.ts +2 -1
  77. package/esm/internals/plugins/featurePlugins/useChartPolarAxis/computeAxisValue.js +2 -2
  78. package/esm/internals/scaleGuards.d.ts +12 -6
  79. package/esm/internals/symlogScale.js +5 -0
  80. package/esm/locales/enUS.js +4 -4
  81. package/esm/locales/ptBR.js +97 -99
  82. package/esm/models/axis.d.ts +39 -17
  83. package/esm/models/axis.js +3 -0
  84. package/esm/models/seriesType/scatter.d.ts +2 -0
  85. package/esm/themeAugmentation/components.d.ts +3 -0
  86. package/esm/themeAugmentation/overrides.d.ts +2 -0
  87. package/hooks/animation/useAnimate.js +4 -3
  88. package/hooks/useScale.d.ts +5 -1
  89. package/index.js +1 -1
  90. package/internals/Flatbush.bench.d.ts +1 -0
  91. package/internals/Flatbush.bench.js +44 -0
  92. package/internals/Flatbush.d.ts +63 -0
  93. package/internals/Flatbush.js +477 -0
  94. package/internals/animation/useAnimateInternal.d.ts +1 -1
  95. package/internals/animation/useAnimateInternal.js +1 -1
  96. package/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.js +7 -7
  97. package/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.types.d.ts +4 -2
  98. package/internals/plugins/featurePlugins/useChartCartesianAxis/computeAxisValue.d.ts +9 -11
  99. package/internals/plugins/featurePlugins/useChartCartesianAxis/computeAxisValue.js +4 -28
  100. package/internals/plugins/featurePlugins/useChartCartesianAxis/createAxisFilterMapper.d.ts +4 -5
  101. package/internals/plugins/featurePlugins/useChartCartesianAxis/createAxisFilterMapper.js +3 -25
  102. package/internals/plugins/featurePlugins/useChartCartesianAxis/domain.d.ts +20 -0
  103. package/internals/plugins/featurePlugins/useChartCartesianAxis/domain.js +84 -0
  104. package/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisScale.d.ts +4 -65
  105. package/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisScale.js +8 -108
  106. package/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisValue.d.ts +6 -2
  107. package/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisValue.js +3 -6
  108. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisPreview.selectors.d.ts +3 -3
  109. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisPreview.selectors.js +29 -37
  110. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisRendering.selectors.d.ts +185 -6
  111. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisRendering.selectors.js +200 -47
  112. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianInteraction.selectors.js +4 -1
  113. package/internals/plugins/featurePlugins/useChartClosestPoint/findClosestPoints.d.ts +5 -0
  114. package/internals/plugins/featurePlugins/useChartClosestPoint/findClosestPoints.js +39 -0
  115. package/internals/plugins/featurePlugins/useChartClosestPoint/useChartClosestPoint.js +39 -80
  116. package/internals/plugins/featurePlugins/useChartHighlight/useChartHighlight.js +10 -3
  117. package/internals/plugins/featurePlugins/useChartHighlight/useChartHighlight.selectors.d.ts +4 -4
  118. package/internals/plugins/featurePlugins/useChartHighlight/useChartHighlight.selectors.js +3 -2
  119. package/internals/plugins/featurePlugins/useChartHighlight/useChartHighlight.types.d.ts +6 -0
  120. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.js +5 -1
  121. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.selectors.d.ts +9 -1
  122. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.selectors.js +11 -2
  123. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.types.d.ts +2 -1
  124. package/internals/plugins/featurePlugins/useChartPolarAxis/computeAxisValue.js +1 -1
  125. package/internals/scaleGuards.d.ts +12 -6
  126. package/internals/symlogScale.js +5 -0
  127. package/locales/enUS.js +4 -4
  128. package/locales/ptBR.js +97 -99
  129. package/models/axis.d.ts +39 -17
  130. package/models/axis.js +4 -0
  131. package/models/seriesType/scatter.d.ts +2 -0
  132. package/package.json +7 -6
  133. package/themeAugmentation/components.d.ts +3 -0
  134. package/themeAugmentation/overrides.d.ts +2 -0
@@ -0,0 +1,477 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.Flatbush = void 0;
8
+ var _flatqueue = _interopRequireDefault(require("flatqueue"));
9
+ // @ts-nocheck
10
+ /* eslint-disable */
11
+
12
+ const ARRAY_TYPES = [Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array];
13
+ const VERSION = 3; // serialized format version
14
+
15
+ class Flatbush {
16
+ /**
17
+ * Recreate a Flatbush index from raw `ArrayBuffer` or `SharedArrayBuffer` data.
18
+ * @param {ArrayBufferLike} data
19
+ * @param {number} [byteOffset=0] byte offset to the start of the Flatbush buffer in the referenced ArrayBuffer.
20
+ * @returns {Flatbush} index
21
+ */
22
+ static from(data, byteOffset = 0) {
23
+ if (byteOffset % 8 !== 0) {
24
+ throw new Error('byteOffset must be 8-byte aligned.');
25
+ }
26
+
27
+ // @ts-expect-error duck typing array buffers
28
+ if (!data || data.byteLength === undefined || data.buffer) {
29
+ throw new Error('Data must be an instance of ArrayBuffer or SharedArrayBuffer.');
30
+ }
31
+ const [magic, versionAndType] = new Uint8Array(data, byteOffset + 0, 2);
32
+ if (magic !== 0xfb) {
33
+ throw new Error('Data does not appear to be in a Flatbush format.');
34
+ }
35
+ const version = versionAndType >> 4;
36
+ if (version !== VERSION) {
37
+ throw new Error(`Got v${version} data when expected v${VERSION}.`);
38
+ }
39
+ const ArrayType = ARRAY_TYPES[versionAndType & 0x0f];
40
+ if (!ArrayType) {
41
+ throw new Error('Unrecognized array type.');
42
+ }
43
+ const [nodeSize] = new Uint16Array(data, byteOffset + 2, 1);
44
+ const [numItems] = new Uint32Array(data, byteOffset + 4, 1);
45
+ return new Flatbush(numItems, nodeSize, ArrayType, undefined, data, byteOffset);
46
+ }
47
+
48
+ /**
49
+ * Create a Flatbush index that will hold a given number of items.
50
+ * @param {number} numItems
51
+ * @param {number} [nodeSize=16] Size of the tree node (16 by default).
52
+ * @param {TypedArrayConstructor} [ArrayType=Float64Array] The array type used for coordinates storage (`Float64Array` by default).
53
+ * @param {ArrayBufferConstructor | SharedArrayBufferConstructor} [ArrayBufferType=ArrayBuffer] The array buffer type used to store data (`ArrayBuffer` by default).
54
+ * @param {ArrayBufferLike} [data] (Only used internally)
55
+ * @param {number} [byteOffset=0] (Only used internally)
56
+ */
57
+ constructor(numItems, nodeSize = 16, ArrayType = Float64Array, ArrayBufferType = ArrayBuffer, data, byteOffset = 0) {
58
+ if (numItems === undefined) {
59
+ throw new Error('Missing required argument: numItems.');
60
+ }
61
+ if (isNaN(numItems) || numItems <= 0) {
62
+ throw new Error(`Unexpected numItems value: ${numItems}.`);
63
+ }
64
+ this.numItems = +numItems;
65
+ this.nodeSize = Math.min(Math.max(+nodeSize, 2), 65535);
66
+ this.byteOffset = byteOffset;
67
+
68
+ // calculate the total number of nodes in the R-tree to allocate space for
69
+ // and the index of each tree level (used in search later)
70
+ let n = numItems;
71
+ let numNodes = n;
72
+ this._levelBounds = [n * 4];
73
+ do {
74
+ n = Math.ceil(n / this.nodeSize);
75
+ numNodes += n;
76
+ this._levelBounds.push(numNodes * 4);
77
+ } while (n !== 1);
78
+ this.ArrayType = ArrayType;
79
+ this.IndexArrayType = numNodes < 16384 ? Uint16Array : Uint32Array;
80
+ const arrayTypeIndex = ARRAY_TYPES.indexOf(ArrayType);
81
+ const nodesByteSize = numNodes * 4 * ArrayType.BYTES_PER_ELEMENT;
82
+ if (arrayTypeIndex < 0) {
83
+ throw new Error(`Unexpected typed array class: ${ArrayType}.`);
84
+ }
85
+ if (data) {
86
+ this.data = data;
87
+ this._boxes = new ArrayType(data, byteOffset + 8, numNodes * 4);
88
+ this._indices = new this.IndexArrayType(data, byteOffset + 8 + nodesByteSize, numNodes);
89
+ this._pos = numNodes * 4;
90
+ this.minX = this._boxes[this._pos - 4];
91
+ this.minY = this._boxes[this._pos - 3];
92
+ this.maxX = this._boxes[this._pos - 2];
93
+ this.maxY = this._boxes[this._pos - 1];
94
+ } else {
95
+ const data = this.data = new ArrayBufferType(8 + nodesByteSize + numNodes * this.IndexArrayType.BYTES_PER_ELEMENT);
96
+ this._boxes = new ArrayType(data, 8, numNodes * 4);
97
+ this._indices = new this.IndexArrayType(data, 8 + nodesByteSize, numNodes);
98
+ this._pos = 0;
99
+ this.minX = Infinity;
100
+ this.minY = Infinity;
101
+ this.maxX = -Infinity;
102
+ this.maxY = -Infinity;
103
+ new Uint8Array(data, 0, 2).set([0xfb, (VERSION << 4) + arrayTypeIndex]);
104
+ new Uint16Array(data, 2, 1)[0] = nodeSize;
105
+ new Uint32Array(data, 4, 1)[0] = numItems;
106
+ }
107
+
108
+ // a priority queue for k-nearest-neighbors queries
109
+ /** @type FlatQueue<number> */
110
+ this._queue = new _flatqueue.default();
111
+ }
112
+
113
+ /**
114
+ * Add a given rectangle to the index.
115
+ * @param {number} minX
116
+ * @param {number} minY
117
+ * @param {number} maxX
118
+ * @param {number} maxY
119
+ * @returns {number} A zero-based, incremental number that represents the newly added rectangle.
120
+ */
121
+ add(minX, minY, maxX = minX, maxY = minY) {
122
+ const index = this._pos >> 2;
123
+ const boxes = this._boxes;
124
+ this._indices[index] = index;
125
+ boxes[this._pos++] = minX;
126
+ boxes[this._pos++] = minY;
127
+ boxes[this._pos++] = maxX;
128
+ boxes[this._pos++] = maxY;
129
+ if (minX < this.minX) {
130
+ this.minX = minX;
131
+ }
132
+ if (minY < this.minY) {
133
+ this.minY = minY;
134
+ }
135
+ if (maxX > this.maxX) {
136
+ this.maxX = maxX;
137
+ }
138
+ if (maxY > this.maxY) {
139
+ this.maxY = maxY;
140
+ }
141
+ return index;
142
+ }
143
+
144
+ /** Perform indexing of the added rectangles. */
145
+ finish() {
146
+ if (this._pos >> 2 !== this.numItems) {
147
+ throw new Error(`Added ${this._pos >> 2} items when expected ${this.numItems}.`);
148
+ }
149
+ const boxes = this._boxes;
150
+ if (this.numItems <= this.nodeSize) {
151
+ // only one node, skip sorting and just fill the root box
152
+ boxes[this._pos++] = this.minX;
153
+ boxes[this._pos++] = this.minY;
154
+ boxes[this._pos++] = this.maxX;
155
+ boxes[this._pos++] = this.maxY;
156
+ return;
157
+ }
158
+ const width = this.maxX - this.minX || 1;
159
+ const height = this.maxY - this.minY || 1;
160
+ const hilbertValues = new Uint32Array(this.numItems);
161
+ const hilbertMax = (1 << 16) - 1;
162
+
163
+ // map item centers into Hilbert coordinate space and calculate Hilbert values
164
+ for (let i = 0, pos = 0; i < this.numItems; i++) {
165
+ const minX = boxes[pos++];
166
+ const minY = boxes[pos++];
167
+ const maxX = boxes[pos++];
168
+ const maxY = boxes[pos++];
169
+ const x = Math.floor(hilbertMax * ((minX + maxX) / 2 - this.minX) / width);
170
+ const y = Math.floor(hilbertMax * ((minY + maxY) / 2 - this.minY) / height);
171
+ hilbertValues[i] = hilbert(x, y);
172
+ }
173
+
174
+ // sort items by their Hilbert value (for packing later)
175
+ sort(hilbertValues, boxes, this._indices, 0, this.numItems - 1, this.nodeSize);
176
+
177
+ // generate nodes at each tree level, bottom-up
178
+ for (let i = 0, pos = 0; i < this._levelBounds.length - 1; i++) {
179
+ const end = this._levelBounds[i];
180
+
181
+ // generate a parent node for each block of consecutive <nodeSize> nodes
182
+ while (pos < end) {
183
+ const nodeIndex = pos;
184
+
185
+ // calculate bbox for the new node
186
+ let nodeMinX = boxes[pos++];
187
+ let nodeMinY = boxes[pos++];
188
+ let nodeMaxX = boxes[pos++];
189
+ let nodeMaxY = boxes[pos++];
190
+ for (let j = 1; j < this.nodeSize && pos < end; j++) {
191
+ nodeMinX = Math.min(nodeMinX, boxes[pos++]);
192
+ nodeMinY = Math.min(nodeMinY, boxes[pos++]);
193
+ nodeMaxX = Math.max(nodeMaxX, boxes[pos++]);
194
+ nodeMaxY = Math.max(nodeMaxY, boxes[pos++]);
195
+ }
196
+
197
+ // add the new node to the tree data
198
+ this._indices[this._pos >> 2] = nodeIndex;
199
+ boxes[this._pos++] = nodeMinX;
200
+ boxes[this._pos++] = nodeMinY;
201
+ boxes[this._pos++] = nodeMaxX;
202
+ boxes[this._pos++] = nodeMaxY;
203
+ }
204
+ }
205
+ }
206
+
207
+ /**
208
+ * Search the index by a bounding box.
209
+ * @param {number} minX
210
+ * @param {number} minY
211
+ * @param {number} maxX
212
+ * @param {number} maxY
213
+ * @param {(index: number) => boolean} [filterFn] An optional function for filtering the results.
214
+ * @returns {number[]} An array containing the index, the x coordinate and the y coordinate of the points intersecting or touching the given bounding box.
215
+ */
216
+ search(minX, minY, maxX, maxY, filterFn) {
217
+ if (this._pos !== this._boxes.length) {
218
+ throw new Error('Data not yet indexed - call index.finish().');
219
+ }
220
+
221
+ /** @type number | undefined */
222
+ let nodeIndex = this._boxes.length - 4;
223
+ const queue = [];
224
+ const results = [];
225
+ while (nodeIndex !== undefined) {
226
+ // find the end index of the node
227
+ const end = Math.min(nodeIndex + this.nodeSize * 4, upperBound(nodeIndex, this._levelBounds));
228
+
229
+ // search through child nodes
230
+ for (let /** @type number */pos = nodeIndex; pos < end; pos += 4) {
231
+ // check if node bbox intersects with query bbox
232
+ if (maxX < this._boxes[pos]) {
233
+ continue;
234
+ } // maxX < nodeMinX
235
+ if (maxY < this._boxes[pos + 1]) {
236
+ continue;
237
+ } // maxY < nodeMinY
238
+ if (minX > this._boxes[pos + 2]) {
239
+ continue;
240
+ } // minX > nodeMaxX
241
+ if (minY > this._boxes[pos + 3]) {
242
+ continue;
243
+ } // minY > nodeMaxY
244
+
245
+ const index = this._indices[pos >> 2] | 0;
246
+ if (nodeIndex >= this.numItems * 4) {
247
+ queue.push(index); // node; add it to the search queue
248
+ } else if (filterFn === undefined || filterFn(index)) {
249
+ results.push(index);
250
+ results.push(this._boxes[pos]); // leaf item
251
+ results.push(this._boxes[pos + 1]);
252
+ }
253
+ }
254
+ nodeIndex = queue.pop();
255
+ }
256
+ return results;
257
+ }
258
+
259
+ /**
260
+ * Search items in order of distance from the given point.
261
+ * @param x
262
+ * @param y
263
+ * @param [maxResults=Infinity]
264
+ * @param maxDistSq
265
+ * @param [filterFn] An optional function for filtering the results.
266
+ * @param [sqDistFn] An optional function to calculate squared distance from the point to the item.
267
+ * @returns {number[]} An array of indices of items found.
268
+ */
269
+ neighbors(x, y, maxResults = Infinity, maxDistSq = Infinity, filterFn, sqDistFn = sqDist) {
270
+ if (this._pos !== this._boxes.length) {
271
+ throw new Error('Data not yet indexed - call index.finish().');
272
+ }
273
+
274
+ /** @type number | undefined */
275
+ let nodeIndex = this._boxes.length - 4;
276
+ const q = this._queue;
277
+ const results = [];
278
+
279
+ /* eslint-disable no-labels */
280
+ outer: while (nodeIndex !== undefined) {
281
+ // find the end index of the node
282
+ const end = Math.min(nodeIndex + this.nodeSize * 4, upperBound(nodeIndex, this._levelBounds));
283
+
284
+ // add child nodes to the queue
285
+ for (let pos = nodeIndex; pos < end; pos += 4) {
286
+ const index = this._indices[pos >> 2] | 0;
287
+ const minX = this._boxes[pos];
288
+ const minY = this._boxes[pos + 1];
289
+ const maxX = this._boxes[pos + 2];
290
+ const maxY = this._boxes[pos + 3];
291
+ const dx = x < minX ? minX - x : x > maxX ? x - maxX : 0;
292
+ const dy = y < minY ? minY - y : y > maxY ? y - maxY : 0;
293
+ const dist = sqDistFn(dx, dy);
294
+ if (dist > maxDistSq) {
295
+ continue;
296
+ }
297
+ if (nodeIndex >= this.numItems * 4) {
298
+ q.push(index << 1, dist); // node (use even id)
299
+ } else if (filterFn === undefined || filterFn(index)) {
300
+ q.push((index << 1) + 1, dist); // leaf item (use odd id)
301
+ }
302
+ }
303
+
304
+ // pop items from the queue
305
+ // @ts-expect-error q.length check eliminates undefined values
306
+ while (q.length && q.peek() & 1) {
307
+ const dist = q.peekValue();
308
+
309
+ // @ts-expect-error
310
+ if (dist > maxDistSq) {
311
+ break outer;
312
+ }
313
+ // @ts-expect-error
314
+ results.push(q.pop() >> 1);
315
+ if (results.length === maxResults) {
316
+ break outer;
317
+ }
318
+ }
319
+
320
+ // @ts-expect-error
321
+ nodeIndex = q.length ? q.pop() >> 1 : undefined;
322
+ }
323
+ q.clear();
324
+ return results;
325
+ }
326
+ }
327
+ exports.Flatbush = Flatbush;
328
+ function sqDist(dx, dy) {
329
+ return dx * dx + dy * dy;
330
+ }
331
+
332
+ /**
333
+ * Binary search for the first value in the array bigger than the given.
334
+ * @param {number} value
335
+ * @param {number[]} arr
336
+ */
337
+ function upperBound(value, arr) {
338
+ let i = 0;
339
+ let j = arr.length - 1;
340
+ while (i < j) {
341
+ const m = i + j >> 1;
342
+ if (arr[m] > value) {
343
+ j = m;
344
+ } else {
345
+ i = m + 1;
346
+ }
347
+ }
348
+ return arr[i];
349
+ }
350
+
351
+ /**
352
+ * Custom quicksort that partially sorts bbox data alongside the hilbert values.
353
+ * @param {Uint32Array} values
354
+ * @param {InstanceType<TypedArrayConstructor>} boxes
355
+ * @param {Uint16Array | Uint32Array} indices
356
+ * @param {number} left
357
+ * @param {number} right
358
+ * @param {number} nodeSize
359
+ */
360
+ function sort(values, boxes, indices, left, right, nodeSize) {
361
+ if (Math.floor(left / nodeSize) >= Math.floor(right / nodeSize)) {
362
+ return;
363
+ }
364
+
365
+ // apply median of three method
366
+ const start = values[left];
367
+ const mid = values[left + right >> 1];
368
+ const end = values[right];
369
+ let pivot = end;
370
+ const x = Math.max(start, mid);
371
+ if (end > x) {
372
+ pivot = x;
373
+ } else if (x === start) {
374
+ pivot = Math.max(mid, end);
375
+ } else if (x === mid) {
376
+ pivot = Math.max(start, end);
377
+ }
378
+ let i = left - 1;
379
+ let j = right + 1;
380
+ while (true) {
381
+ do {
382
+ i++;
383
+ } while (values[i] < pivot);
384
+ do {
385
+ j--;
386
+ } while (values[j] > pivot);
387
+ if (i >= j) {
388
+ break;
389
+ }
390
+ swap(values, boxes, indices, i, j);
391
+ }
392
+ sort(values, boxes, indices, left, j, nodeSize);
393
+ sort(values, boxes, indices, j + 1, right, nodeSize);
394
+ }
395
+
396
+ /**
397
+ * Swap two values and two corresponding boxes.
398
+ * @param {Uint32Array} values
399
+ * @param {InstanceType<TypedArrayConstructor>} boxes
400
+ * @param {Uint16Array | Uint32Array} indices
401
+ * @param {number} i
402
+ * @param {number} j
403
+ */
404
+ function swap(values, boxes, indices, i, j) {
405
+ const temp = values[i];
406
+ values[i] = values[j];
407
+ values[j] = temp;
408
+ const k = 4 * i;
409
+ const m = 4 * j;
410
+ const a = boxes[k];
411
+ const b = boxes[k + 1];
412
+ const c = boxes[k + 2];
413
+ const d = boxes[k + 3];
414
+ boxes[k] = boxes[m];
415
+ boxes[k + 1] = boxes[m + 1];
416
+ boxes[k + 2] = boxes[m + 2];
417
+ boxes[k + 3] = boxes[m + 3];
418
+ boxes[m] = a;
419
+ boxes[m + 1] = b;
420
+ boxes[m + 2] = c;
421
+ boxes[m + 3] = d;
422
+ const e = indices[i];
423
+ indices[i] = indices[j];
424
+ indices[j] = e;
425
+ }
426
+
427
+ /**
428
+ * Fast Hilbert curve algorithm by http://threadlocalmutex.com/
429
+ * Ported from C++ https://github.com/rawrunprotected/hilbert_curves (public domain)
430
+ * @param {number} x
431
+ * @param {number} y
432
+ */
433
+ function hilbert(x, y) {
434
+ let a = x ^ y;
435
+ let b = 0xffff ^ a;
436
+ let c = 0xffff ^ (x | y);
437
+ let d = x & (y ^ 0xffff);
438
+ let A = a | b >> 1;
439
+ let B = a >> 1 ^ a;
440
+ let C = c >> 1 ^ b & d >> 1 ^ c;
441
+ let D = a & c >> 1 ^ d >> 1 ^ d;
442
+ a = A;
443
+ b = B;
444
+ c = C;
445
+ d = D;
446
+ A = a & a >> 2 ^ b & b >> 2;
447
+ B = a & b >> 2 ^ b & (a ^ b) >> 2;
448
+ C ^= a & c >> 2 ^ b & d >> 2;
449
+ D ^= b & c >> 2 ^ (a ^ b) & d >> 2;
450
+ a = A;
451
+ b = B;
452
+ c = C;
453
+ d = D;
454
+ A = a & a >> 4 ^ b & b >> 4;
455
+ B = a & b >> 4 ^ b & (a ^ b) >> 4;
456
+ C ^= a & c >> 4 ^ b & d >> 4;
457
+ D ^= b & c >> 4 ^ (a ^ b) & d >> 4;
458
+ a = A;
459
+ b = B;
460
+ c = C;
461
+ d = D;
462
+ C ^= a & c >> 8 ^ b & d >> 8;
463
+ D ^= b & c >> 8 ^ (a ^ b) & d >> 8;
464
+ a = C ^ C >> 1;
465
+ b = D ^ D >> 1;
466
+ let i0 = x ^ y;
467
+ let i1 = b | 0xffff ^ (i0 | a);
468
+ i0 = (i0 | i0 << 8) & 0x00ff00ff;
469
+ i0 = (i0 | i0 << 4) & 0x0f0f0f0f;
470
+ i0 = (i0 | i0 << 2) & 0x33333333;
471
+ i0 = (i0 | i0 << 1) & 0x55555555;
472
+ i1 = (i1 | i1 << 8) & 0x00ff00ff;
473
+ i1 = (i1 | i1 << 4) & 0x0f0f0f0f;
474
+ i1 = (i1 | i1 << 2) & 0x33333333;
475
+ i1 = (i1 | i1 << 1) & 0x55555555;
476
+ return (i1 << 1 | i0) >>> 0;
477
+ }
@@ -18,4 +18,4 @@ export declare function useAnimateInternal<Props extends {}, Elem extends Elemen
18
18
  applyProps: (element: Elem, props: Props) => void;
19
19
  skip?: boolean;
20
20
  initialProps?: Props;
21
- }): (element: Elem | null) => void;
21
+ }): readonly [(element: Elem | null) => void, Props];
@@ -78,5 +78,5 @@ function useAnimateInternal(props, {
78
78
  animate(element);
79
79
  }
80
80
  }, [animate, props, skip]);
81
- return setRef;
81
+ return [setRef, lastInterpolatedPropsRef.current];
82
82
  }
@@ -28,7 +28,7 @@ const useChartInteractionListener = ({
28
28
  name: 'zoomPan',
29
29
  threshold: 0,
30
30
  maxPointers: 1,
31
- preventIf: ['zoomTapAndDrag']
31
+ preventIf: ['zoomTapAndDrag', 'zoomPressAndDrag']
32
32
  }), new _core.MoveGesture({
33
33
  name: 'move',
34
34
  preventIf: ['pan', 'zoomPinch', 'zoomPan'] // Prevent move gesture when pan is active
@@ -42,17 +42,17 @@ const useChartInteractionListener = ({
42
42
  initialDelta: 1
43
43
  }), new _core.TapGesture({
44
44
  name: 'tap',
45
- maxDistance: 10,
46
45
  preventIf: ['pan', 'zoomPan', 'zoomPinch']
47
46
  }), new _core.PressGesture({
48
47
  name: 'quickPress',
49
- duration: 50,
50
- maxDistance: 10
48
+ duration: 50
51
49
  }), new _core.TapAndDragGesture({
52
50
  name: 'zoomTapAndDrag',
53
- tapMaxDistance: 10,
51
+ dragThreshold: 10
52
+ }), new _core.PressAndDragGesture({
53
+ name: 'zoomPressAndDrag',
54
54
  dragThreshold: 10,
55
- dragTimeout: 1000
55
+ preventIf: ['zoomPinch']
56
56
  })]
57
57
  });
58
58
  }
@@ -62,7 +62,7 @@ const useChartInteractionListener = ({
62
62
  if (!svg || !gestureManager) {
63
63
  return undefined;
64
64
  }
65
- gestureManager.registerElement(['pan', 'move', 'zoomPinch', 'zoomPan', 'zoomTurnWheel', 'tap', 'quickPress', 'zoomTapAndDrag'], svg);
65
+ gestureManager.registerElement(['pan', 'move', 'zoomPinch', 'zoomPan', 'zoomTurnWheel', 'tap', 'quickPress', 'zoomTapAndDrag', 'zoomPressAndDrag'], svg);
66
66
  return () => {
67
67
  // Cleanup gesture manager
68
68
  gestureManager.unregisterAllGestures(svg);
@@ -1,6 +1,6 @@
1
- import { MoveEvent, PanEvent, PanGestureOptions, PinchEvent, PinchGestureOptions, PressEvent, TapEvent, TurnWheelEvent, type TapAndDragEvent, type TapAndDragGestureOptions, type TurnWheelGestureOptions } from '@mui/x-internal-gestures/core';
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' | 'move' | 'moveStart' | 'moveEnd' | 'quickPress' | 'quickPressEnd' | 'zoomTurnWheel' | 'tap';
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';
4
4
  export type InteractionListenerResult = {
5
5
  cleanup: () => void;
6
6
  };
@@ -12,12 +12,14 @@ export type AddInteractionListener = {
12
12
  <CustomData extends Record<string, unknown> = Record<string, unknown>>(interaction: 'tap', callback: (event: TapEvent<CustomData>) => void, options?: boolean | AddEventListenerOptions): InteractionListenerResult;
13
13
  <CustomData extends Record<string, unknown> = Record<string, unknown>>(interaction: 'quickPress' | 'quickPressEnd', callback: (event: PressEvent<CustomData>) => void, options?: boolean | AddEventListenerOptions): InteractionListenerResult;
14
14
  <CustomData extends Record<string, unknown> = Record<string, unknown>>(interaction: 'zoomTapAndDrag' | 'zoomTapAndDragStart' | 'zoomTapAndDragEnd', callback: (event: TapAndDragEvent<CustomData>) => void, options?: boolean | AddEventListenerOptions): InteractionListenerResult;
15
+ <CustomData extends Record<string, unknown> = Record<string, unknown>>(interaction: 'zoomPressAndDrag' | 'zoomPressAndDragStart' | 'zoomPressAndDragEnd', callback: (event: PressAndDragEvent<CustomData>) => void, options?: boolean | AddEventListenerOptions): InteractionListenerResult;
15
16
  };
16
17
  export type UpdateZoomInteractionListeners = {
17
18
  (interaction: 'zoomPan', options?: Omit<PanGestureOptions<'zoomPan'>, 'name'>): void;
18
19
  (interaction: 'zoomPinch', options?: Omit<PinchGestureOptions<'zoomPinch'>, 'name'>): void;
19
20
  (interaction: 'zoomTurnWheel', options?: Omit<TurnWheelGestureOptions<'zoomTurnWheel'>, 'name'>): void;
20
21
  (interaction: 'zoomTapAndDrag', options?: Omit<TapAndDragGestureOptions<'zoomTapAndDrag'>, 'name'>): void;
22
+ (interaction: 'zoomPressAndDrag', options?: Omit<PressAndDragGestureOptions<'zoomPressAndDrag'>, 'name'>): void;
21
23
  };
22
24
  export interface UseChartInteractionListenerParameters {}
23
25
  export interface UseChartInteractionListenerState {}
@@ -1,27 +1,25 @@
1
- import { ChartsXAxisProps, ChartsAxisProps, ChartsYAxisProps, AxisId, DefaultedXAxis, DefaultedYAxis } from "../../../../models/axis.js";
1
+ import { NumberValue } from '@mui/x-charts-vendor/d3-scale';
2
+ import { ChartsXAxisProps, ChartsAxisProps, ChartsYAxisProps, AxisId, DefaultedXAxis, DefaultedYAxis, D3Scale } from "../../../../models/axis.js";
2
3
  import { ChartSeriesType } from "../../../../models/seriesType/config.js";
3
4
  import type { ChartDrawingArea } from "../../../../hooks/index.js";
4
5
  import { ChartSeriesConfig } from "../../models/seriesConfig/index.js";
5
- import { ComputedAxisConfig, DefaultizedZoomOptions } from "./useChartCartesianAxis.types.js";
6
+ import { ComputedAxisConfig } from "./useChartCartesianAxis.types.js";
6
7
  import { ProcessedSeries } from "../../corePlugins/useChartSeries/useChartSeries.types.js";
7
- import { GetZoomAxisFilters, ZoomData } from "./zoom.types.js";
8
- import { ScaleDefinition } from "./getAxisScale.js";
8
+ import { ZoomData } from "./zoom.types.js";
9
9
  export type ComputeResult<T extends ChartsAxisProps> = {
10
10
  axis: ComputedAxisConfig<T>;
11
11
  axisIds: AxisId[];
12
12
  };
13
13
  type ComputeCommonParams<T extends ChartSeriesType = ChartSeriesType> = {
14
- scales: Record<AxisId, ScaleDefinition>;
14
+ scales: Record<AxisId, D3Scale>;
15
15
  drawingArea: ChartDrawingArea;
16
16
  formattedSeries: ProcessedSeries<T>;
17
17
  seriesConfig: ChartSeriesConfig<T>;
18
18
  zoomMap?: Map<AxisId, ZoomData>;
19
- zoomOptions?: Record<AxisId, DefaultizedZoomOptions>;
20
- getFilters?: GetZoomAxisFilters;
21
- /**
22
- * @deprecated To remove in v9. This is an experimental feature to avoid breaking change.
23
- */
24
- preferStrictDomainInLineCharts?: boolean;
19
+ domains: Record<AxisId, {
20
+ domain: ReadonlyArray<string | NumberValue>;
21
+ tickNumber?: number;
22
+ }>;
25
23
  };
26
24
  export declare function computeAxisValue<T extends ChartSeriesType>(options: ComputeCommonParams<T> & {
27
25
  axis?: DefaultedYAxis[];
@@ -12,9 +12,7 @@ var _colorScale = require("../../../colorScale");
12
12
  var _ticks = require("../../../ticks");
13
13
  var _getScale = require("../../../getScale");
14
14
  var _dateHelpers = require("../../../dateHelpers");
15
- var _getAxisExtrema = require("./getAxisExtrema");
16
15
  var _getAxisTriggerTooltip = require("./getAxisTriggerTooltip");
17
- var _getAxisScale = require("./getAxisScale");
18
16
  var _scaleGuards = require("../../../scaleGuards");
19
17
  function getRange(drawingArea, axisDirection,
20
18
  // | 'rotation' | 'radius',
@@ -32,9 +30,7 @@ function computeAxisValue({
32
30
  seriesConfig,
33
31
  axisDirection,
34
32
  zoomMap,
35
- zoomOptions,
36
- getFilters,
37
- preferStrictDomainInLineCharts
33
+ domains
38
34
  }) {
39
35
  if (allAxis === undefined) {
40
36
  return {
@@ -44,11 +40,9 @@ function computeAxisValue({
44
40
  }
45
41
  const axisIdsTriggeringTooltip = (0, _getAxisTriggerTooltip.getAxisTriggerTooltip)(axisDirection, seriesConfig, formattedSeries, allAxis[0].id);
46
42
  const completeAxis = {};
47
- allAxis.forEach((eachAxis, axisIndex) => {
43
+ allAxis.forEach(eachAxis => {
48
44
  const axis = eachAxis;
49
- const scaleDefinition = scales[axis.id];
50
- let scale = scaleDefinition.scale;
51
- const zoomOption = zoomOptions?.[axis.id];
45
+ const scale = scales[axis.id];
52
46
  const zoom = zoomMap?.get(axis.id);
53
47
  const zoomRange = zoom ? [zoom.start, zoom.end] : [0, 100];
54
48
  const range = getRange(drawingArea, axisDirection, axis.reverse ?? false);
@@ -99,28 +93,10 @@ function computeAxisValue({
99
93
  // Could be merged with the two previous "if conditions" but then TS does not get that `axis.scaleType` can't be `band` or `point`.
100
94
  return;
101
95
  }
102
- const rawTickNumber = scaleDefinition.tickNumber;
96
+ const rawTickNumber = domains[axis.id].tickNumber;
103
97
  const continuousAxis = axis;
104
98
  const scaleType = continuousAxis.scaleType ?? 'linear';
105
99
  const tickNumber = (0, _ticks.scaleTickNumberByRange)(rawTickNumber, zoomRange);
106
- const filter = zoom === undefined && !zoomOption ? getFilters : undefined; // Do not apply filtering if zoom is already defined.
107
- if (filter) {
108
- const [minData, maxData] = (0, _getAxisExtrema.getAxisExtrema)(axis, axisDirection, seriesConfig, axisIndex, formattedSeries, filter);
109
- scale = scale.copy();
110
- scale.domain([minData, maxData]);
111
- const domainLimit = (0, _getAxisScale.getDomainLimit)(axis, axisDirection, axisIndex, formattedSeries, preferStrictDomainInLineCharts);
112
- const axisExtrema = (0, _getAxisScale.getActualAxisExtrema)(axis, minData, maxData);
113
- if (typeof domainLimit === 'function') {
114
- const {
115
- min,
116
- max
117
- } = domainLimit(minData, maxData);
118
- axisExtrema[0] = min;
119
- axisExtrema[1] = max;
120
- }
121
- scale.domain(axisExtrema);
122
- (0, _getAxisScale.applyDomainLimit)(scale, axis, domainLimit, rawTickNumber);
123
- }
124
100
  completeAxis[axis.id] = (0, _extends2.default)({
125
101
  offset: 0,
126
102
  height: 0,
@@ -1,8 +1,7 @@
1
- import { AxisId, D3ContinuousScale, D3Scale } from "../../../../models/axis.js";
1
+ import { NumberValue } from '@mui/x-charts-vendor/d3-scale';
2
2
  import { AxisConfig } from "../../../../models/index.js";
3
- import { DefaultizedZoomOptions, ExtremumFilter } from "./useChartCartesianAxis.types.js";
4
- import { GetZoomAxisFilters, ZoomAxisFilters, ZoomData } from "./zoom.types.js";
5
- export declare function createAxisFilterMapper(zoomMap: Map<AxisId, ZoomData>, zoomOptions: Record<AxisId, DefaultizedZoomOptions>, direction: 'x' | 'y'): (axisId: AxisId, axisData: AxisConfig['data'], scale: D3Scale) => ExtremumFilter | null;
3
+ import { ExtremumFilter } from "./useChartCartesianAxis.types.js";
4
+ import { GetZoomAxisFilters, ZoomAxisFilters } from "./zoom.types.js";
6
5
  export declare function createDiscreteScaleGetAxisFilter(axisData: AxisConfig['data'], zoomStart: number, zoomEnd: number, direction: 'x' | 'y'): ExtremumFilter;
7
- export declare function createContinuousScaleGetAxisFilter(scale: D3ContinuousScale, zoomStart: number, zoomEnd: number, direction: 'x' | 'y', axisData: AxisConfig['data']): ExtremumFilter;
6
+ export declare function createContinuousScaleGetAxisFilter(domain: readonly NumberValue[], zoomStart: number, zoomEnd: number, direction: 'x' | 'y', axisData: AxisConfig['data']): ExtremumFilter;
8
7
  export declare const createGetAxisFilters: (filters: ZoomAxisFilters) => GetZoomAxisFilters;