@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,468 @@
1
+ // @ts-nocheck
2
+ /* eslint-disable */
3
+ import FlatQueue from 'flatqueue';
4
+ const ARRAY_TYPES = [Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array];
5
+ const VERSION = 3; // serialized format version
6
+
7
+ export class Flatbush {
8
+ /**
9
+ * Recreate a Flatbush index from raw `ArrayBuffer` or `SharedArrayBuffer` data.
10
+ * @param {ArrayBufferLike} data
11
+ * @param {number} [byteOffset=0] byte offset to the start of the Flatbush buffer in the referenced ArrayBuffer.
12
+ * @returns {Flatbush} index
13
+ */
14
+ static from(data, byteOffset = 0) {
15
+ if (byteOffset % 8 !== 0) {
16
+ throw new Error('byteOffset must be 8-byte aligned.');
17
+ }
18
+
19
+ // @ts-expect-error duck typing array buffers
20
+ if (!data || data.byteLength === undefined || data.buffer) {
21
+ throw new Error('Data must be an instance of ArrayBuffer or SharedArrayBuffer.');
22
+ }
23
+ const [magic, versionAndType] = new Uint8Array(data, byteOffset + 0, 2);
24
+ if (magic !== 0xfb) {
25
+ throw new Error('Data does not appear to be in a Flatbush format.');
26
+ }
27
+ const version = versionAndType >> 4;
28
+ if (version !== VERSION) {
29
+ throw new Error(`Got v${version} data when expected v${VERSION}.`);
30
+ }
31
+ const ArrayType = ARRAY_TYPES[versionAndType & 0x0f];
32
+ if (!ArrayType) {
33
+ throw new Error('Unrecognized array type.');
34
+ }
35
+ const [nodeSize] = new Uint16Array(data, byteOffset + 2, 1);
36
+ const [numItems] = new Uint32Array(data, byteOffset + 4, 1);
37
+ return new Flatbush(numItems, nodeSize, ArrayType, undefined, data, byteOffset);
38
+ }
39
+
40
+ /**
41
+ * Create a Flatbush index that will hold a given number of items.
42
+ * @param {number} numItems
43
+ * @param {number} [nodeSize=16] Size of the tree node (16 by default).
44
+ * @param {TypedArrayConstructor} [ArrayType=Float64Array] The array type used for coordinates storage (`Float64Array` by default).
45
+ * @param {ArrayBufferConstructor | SharedArrayBufferConstructor} [ArrayBufferType=ArrayBuffer] The array buffer type used to store data (`ArrayBuffer` by default).
46
+ * @param {ArrayBufferLike} [data] (Only used internally)
47
+ * @param {number} [byteOffset=0] (Only used internally)
48
+ */
49
+ constructor(numItems, nodeSize = 16, ArrayType = Float64Array, ArrayBufferType = ArrayBuffer, data, byteOffset = 0) {
50
+ if (numItems === undefined) {
51
+ throw new Error('Missing required argument: numItems.');
52
+ }
53
+ if (isNaN(numItems) || numItems <= 0) {
54
+ throw new Error(`Unexpected numItems value: ${numItems}.`);
55
+ }
56
+ this.numItems = +numItems;
57
+ this.nodeSize = Math.min(Math.max(+nodeSize, 2), 65535);
58
+ this.byteOffset = byteOffset;
59
+
60
+ // calculate the total number of nodes in the R-tree to allocate space for
61
+ // and the index of each tree level (used in search later)
62
+ let n = numItems;
63
+ let numNodes = n;
64
+ this._levelBounds = [n * 4];
65
+ do {
66
+ n = Math.ceil(n / this.nodeSize);
67
+ numNodes += n;
68
+ this._levelBounds.push(numNodes * 4);
69
+ } while (n !== 1);
70
+ this.ArrayType = ArrayType;
71
+ this.IndexArrayType = numNodes < 16384 ? Uint16Array : Uint32Array;
72
+ const arrayTypeIndex = ARRAY_TYPES.indexOf(ArrayType);
73
+ const nodesByteSize = numNodes * 4 * ArrayType.BYTES_PER_ELEMENT;
74
+ if (arrayTypeIndex < 0) {
75
+ throw new Error(`Unexpected typed array class: ${ArrayType}.`);
76
+ }
77
+ if (data) {
78
+ this.data = data;
79
+ this._boxes = new ArrayType(data, byteOffset + 8, numNodes * 4);
80
+ this._indices = new this.IndexArrayType(data, byteOffset + 8 + nodesByteSize, numNodes);
81
+ this._pos = numNodes * 4;
82
+ this.minX = this._boxes[this._pos - 4];
83
+ this.minY = this._boxes[this._pos - 3];
84
+ this.maxX = this._boxes[this._pos - 2];
85
+ this.maxY = this._boxes[this._pos - 1];
86
+ } else {
87
+ const data = this.data = new ArrayBufferType(8 + nodesByteSize + numNodes * this.IndexArrayType.BYTES_PER_ELEMENT);
88
+ this._boxes = new ArrayType(data, 8, numNodes * 4);
89
+ this._indices = new this.IndexArrayType(data, 8 + nodesByteSize, numNodes);
90
+ this._pos = 0;
91
+ this.minX = Infinity;
92
+ this.minY = Infinity;
93
+ this.maxX = -Infinity;
94
+ this.maxY = -Infinity;
95
+ new Uint8Array(data, 0, 2).set([0xfb, (VERSION << 4) + arrayTypeIndex]);
96
+ new Uint16Array(data, 2, 1)[0] = nodeSize;
97
+ new Uint32Array(data, 4, 1)[0] = numItems;
98
+ }
99
+
100
+ // a priority queue for k-nearest-neighbors queries
101
+ /** @type FlatQueue<number> */
102
+ this._queue = new FlatQueue();
103
+ }
104
+
105
+ /**
106
+ * Add a given rectangle to the index.
107
+ * @param {number} minX
108
+ * @param {number} minY
109
+ * @param {number} maxX
110
+ * @param {number} maxY
111
+ * @returns {number} A zero-based, incremental number that represents the newly added rectangle.
112
+ */
113
+ add(minX, minY, maxX = minX, maxY = minY) {
114
+ const index = this._pos >> 2;
115
+ const boxes = this._boxes;
116
+ this._indices[index] = index;
117
+ boxes[this._pos++] = minX;
118
+ boxes[this._pos++] = minY;
119
+ boxes[this._pos++] = maxX;
120
+ boxes[this._pos++] = maxY;
121
+ if (minX < this.minX) {
122
+ this.minX = minX;
123
+ }
124
+ if (minY < this.minY) {
125
+ this.minY = minY;
126
+ }
127
+ if (maxX > this.maxX) {
128
+ this.maxX = maxX;
129
+ }
130
+ if (maxY > this.maxY) {
131
+ this.maxY = maxY;
132
+ }
133
+ return index;
134
+ }
135
+
136
+ /** Perform indexing of the added rectangles. */
137
+ finish() {
138
+ if (this._pos >> 2 !== this.numItems) {
139
+ throw new Error(`Added ${this._pos >> 2} items when expected ${this.numItems}.`);
140
+ }
141
+ const boxes = this._boxes;
142
+ if (this.numItems <= this.nodeSize) {
143
+ // only one node, skip sorting and just fill the root box
144
+ boxes[this._pos++] = this.minX;
145
+ boxes[this._pos++] = this.minY;
146
+ boxes[this._pos++] = this.maxX;
147
+ boxes[this._pos++] = this.maxY;
148
+ return;
149
+ }
150
+ const width = this.maxX - this.minX || 1;
151
+ const height = this.maxY - this.minY || 1;
152
+ const hilbertValues = new Uint32Array(this.numItems);
153
+ const hilbertMax = (1 << 16) - 1;
154
+
155
+ // map item centers into Hilbert coordinate space and calculate Hilbert values
156
+ for (let i = 0, pos = 0; i < this.numItems; i++) {
157
+ const minX = boxes[pos++];
158
+ const minY = boxes[pos++];
159
+ const maxX = boxes[pos++];
160
+ const maxY = boxes[pos++];
161
+ const x = Math.floor(hilbertMax * ((minX + maxX) / 2 - this.minX) / width);
162
+ const y = Math.floor(hilbertMax * ((minY + maxY) / 2 - this.minY) / height);
163
+ hilbertValues[i] = hilbert(x, y);
164
+ }
165
+
166
+ // sort items by their Hilbert value (for packing later)
167
+ sort(hilbertValues, boxes, this._indices, 0, this.numItems - 1, this.nodeSize);
168
+
169
+ // generate nodes at each tree level, bottom-up
170
+ for (let i = 0, pos = 0; i < this._levelBounds.length - 1; i++) {
171
+ const end = this._levelBounds[i];
172
+
173
+ // generate a parent node for each block of consecutive <nodeSize> nodes
174
+ while (pos < end) {
175
+ const nodeIndex = pos;
176
+
177
+ // calculate bbox for the new node
178
+ let nodeMinX = boxes[pos++];
179
+ let nodeMinY = boxes[pos++];
180
+ let nodeMaxX = boxes[pos++];
181
+ let nodeMaxY = boxes[pos++];
182
+ for (let j = 1; j < this.nodeSize && pos < end; j++) {
183
+ nodeMinX = Math.min(nodeMinX, boxes[pos++]);
184
+ nodeMinY = Math.min(nodeMinY, boxes[pos++]);
185
+ nodeMaxX = Math.max(nodeMaxX, boxes[pos++]);
186
+ nodeMaxY = Math.max(nodeMaxY, boxes[pos++]);
187
+ }
188
+
189
+ // add the new node to the tree data
190
+ this._indices[this._pos >> 2] = nodeIndex;
191
+ boxes[this._pos++] = nodeMinX;
192
+ boxes[this._pos++] = nodeMinY;
193
+ boxes[this._pos++] = nodeMaxX;
194
+ boxes[this._pos++] = nodeMaxY;
195
+ }
196
+ }
197
+ }
198
+
199
+ /**
200
+ * Search the index by a bounding box.
201
+ * @param {number} minX
202
+ * @param {number} minY
203
+ * @param {number} maxX
204
+ * @param {number} maxY
205
+ * @param {(index: number) => boolean} [filterFn] An optional function for filtering the results.
206
+ * @returns {number[]} An array containing the index, the x coordinate and the y coordinate of the points intersecting or touching the given bounding box.
207
+ */
208
+ search(minX, minY, maxX, maxY, filterFn) {
209
+ if (this._pos !== this._boxes.length) {
210
+ throw new Error('Data not yet indexed - call index.finish().');
211
+ }
212
+
213
+ /** @type number | undefined */
214
+ let nodeIndex = this._boxes.length - 4;
215
+ const queue = [];
216
+ const results = [];
217
+ while (nodeIndex !== undefined) {
218
+ // find the end index of the node
219
+ const end = Math.min(nodeIndex + this.nodeSize * 4, upperBound(nodeIndex, this._levelBounds));
220
+
221
+ // search through child nodes
222
+ for (let /** @type number */pos = nodeIndex; pos < end; pos += 4) {
223
+ // check if node bbox intersects with query bbox
224
+ if (maxX < this._boxes[pos]) {
225
+ continue;
226
+ } // maxX < nodeMinX
227
+ if (maxY < this._boxes[pos + 1]) {
228
+ continue;
229
+ } // maxY < nodeMinY
230
+ if (minX > this._boxes[pos + 2]) {
231
+ continue;
232
+ } // minX > nodeMaxX
233
+ if (minY > this._boxes[pos + 3]) {
234
+ continue;
235
+ } // minY > nodeMaxY
236
+
237
+ const index = this._indices[pos >> 2] | 0;
238
+ if (nodeIndex >= this.numItems * 4) {
239
+ queue.push(index); // node; add it to the search queue
240
+ } else if (filterFn === undefined || filterFn(index)) {
241
+ results.push(index);
242
+ results.push(this._boxes[pos]); // leaf item
243
+ results.push(this._boxes[pos + 1]);
244
+ }
245
+ }
246
+ nodeIndex = queue.pop();
247
+ }
248
+ return results;
249
+ }
250
+
251
+ /**
252
+ * Search items in order of distance from the given point.
253
+ * @param x
254
+ * @param y
255
+ * @param [maxResults=Infinity]
256
+ * @param maxDistSq
257
+ * @param [filterFn] An optional function for filtering the results.
258
+ * @param [sqDistFn] An optional function to calculate squared distance from the point to the item.
259
+ * @returns {number[]} An array of indices of items found.
260
+ */
261
+ neighbors(x, y, maxResults = Infinity, maxDistSq = Infinity, filterFn, sqDistFn = sqDist) {
262
+ if (this._pos !== this._boxes.length) {
263
+ throw new Error('Data not yet indexed - call index.finish().');
264
+ }
265
+
266
+ /** @type number | undefined */
267
+ let nodeIndex = this._boxes.length - 4;
268
+ const q = this._queue;
269
+ const results = [];
270
+
271
+ /* eslint-disable no-labels */
272
+ outer: while (nodeIndex !== undefined) {
273
+ // find the end index of the node
274
+ const end = Math.min(nodeIndex + this.nodeSize * 4, upperBound(nodeIndex, this._levelBounds));
275
+
276
+ // add child nodes to the queue
277
+ for (let pos = nodeIndex; pos < end; pos += 4) {
278
+ const index = this._indices[pos >> 2] | 0;
279
+ const minX = this._boxes[pos];
280
+ const minY = this._boxes[pos + 1];
281
+ const maxX = this._boxes[pos + 2];
282
+ const maxY = this._boxes[pos + 3];
283
+ const dx = x < minX ? minX - x : x > maxX ? x - maxX : 0;
284
+ const dy = y < minY ? minY - y : y > maxY ? y - maxY : 0;
285
+ const dist = sqDistFn(dx, dy);
286
+ if (dist > maxDistSq) {
287
+ continue;
288
+ }
289
+ if (nodeIndex >= this.numItems * 4) {
290
+ q.push(index << 1, dist); // node (use even id)
291
+ } else if (filterFn === undefined || filterFn(index)) {
292
+ q.push((index << 1) + 1, dist); // leaf item (use odd id)
293
+ }
294
+ }
295
+
296
+ // pop items from the queue
297
+ // @ts-expect-error q.length check eliminates undefined values
298
+ while (q.length && q.peek() & 1) {
299
+ const dist = q.peekValue();
300
+
301
+ // @ts-expect-error
302
+ if (dist > maxDistSq) {
303
+ break outer;
304
+ }
305
+ // @ts-expect-error
306
+ results.push(q.pop() >> 1);
307
+ if (results.length === maxResults) {
308
+ break outer;
309
+ }
310
+ }
311
+
312
+ // @ts-expect-error
313
+ nodeIndex = q.length ? q.pop() >> 1 : undefined;
314
+ }
315
+ q.clear();
316
+ return results;
317
+ }
318
+ }
319
+ function sqDist(dx, dy) {
320
+ return dx * dx + dy * dy;
321
+ }
322
+
323
+ /**
324
+ * Binary search for the first value in the array bigger than the given.
325
+ * @param {number} value
326
+ * @param {number[]} arr
327
+ */
328
+ function upperBound(value, arr) {
329
+ let i = 0;
330
+ let j = arr.length - 1;
331
+ while (i < j) {
332
+ const m = i + j >> 1;
333
+ if (arr[m] > value) {
334
+ j = m;
335
+ } else {
336
+ i = m + 1;
337
+ }
338
+ }
339
+ return arr[i];
340
+ }
341
+
342
+ /**
343
+ * Custom quicksort that partially sorts bbox data alongside the hilbert values.
344
+ * @param {Uint32Array} values
345
+ * @param {InstanceType<TypedArrayConstructor>} boxes
346
+ * @param {Uint16Array | Uint32Array} indices
347
+ * @param {number} left
348
+ * @param {number} right
349
+ * @param {number} nodeSize
350
+ */
351
+ function sort(values, boxes, indices, left, right, nodeSize) {
352
+ if (Math.floor(left / nodeSize) >= Math.floor(right / nodeSize)) {
353
+ return;
354
+ }
355
+
356
+ // apply median of three method
357
+ const start = values[left];
358
+ const mid = values[left + right >> 1];
359
+ const end = values[right];
360
+ let pivot = end;
361
+ const x = Math.max(start, mid);
362
+ if (end > x) {
363
+ pivot = x;
364
+ } else if (x === start) {
365
+ pivot = Math.max(mid, end);
366
+ } else if (x === mid) {
367
+ pivot = Math.max(start, end);
368
+ }
369
+ let i = left - 1;
370
+ let j = right + 1;
371
+ while (true) {
372
+ do {
373
+ i++;
374
+ } while (values[i] < pivot);
375
+ do {
376
+ j--;
377
+ } while (values[j] > pivot);
378
+ if (i >= j) {
379
+ break;
380
+ }
381
+ swap(values, boxes, indices, i, j);
382
+ }
383
+ sort(values, boxes, indices, left, j, nodeSize);
384
+ sort(values, boxes, indices, j + 1, right, nodeSize);
385
+ }
386
+
387
+ /**
388
+ * Swap two values and two corresponding boxes.
389
+ * @param {Uint32Array} values
390
+ * @param {InstanceType<TypedArrayConstructor>} boxes
391
+ * @param {Uint16Array | Uint32Array} indices
392
+ * @param {number} i
393
+ * @param {number} j
394
+ */
395
+ function swap(values, boxes, indices, i, j) {
396
+ const temp = values[i];
397
+ values[i] = values[j];
398
+ values[j] = temp;
399
+ const k = 4 * i;
400
+ const m = 4 * j;
401
+ const a = boxes[k];
402
+ const b = boxes[k + 1];
403
+ const c = boxes[k + 2];
404
+ const d = boxes[k + 3];
405
+ boxes[k] = boxes[m];
406
+ boxes[k + 1] = boxes[m + 1];
407
+ boxes[k + 2] = boxes[m + 2];
408
+ boxes[k + 3] = boxes[m + 3];
409
+ boxes[m] = a;
410
+ boxes[m + 1] = b;
411
+ boxes[m + 2] = c;
412
+ boxes[m + 3] = d;
413
+ const e = indices[i];
414
+ indices[i] = indices[j];
415
+ indices[j] = e;
416
+ }
417
+
418
+ /**
419
+ * Fast Hilbert curve algorithm by http://threadlocalmutex.com/
420
+ * Ported from C++ https://github.com/rawrunprotected/hilbert_curves (public domain)
421
+ * @param {number} x
422
+ * @param {number} y
423
+ */
424
+ function hilbert(x, y) {
425
+ let a = x ^ y;
426
+ let b = 0xffff ^ a;
427
+ let c = 0xffff ^ (x | y);
428
+ let d = x & (y ^ 0xffff);
429
+ let A = a | b >> 1;
430
+ let B = a >> 1 ^ a;
431
+ let C = c >> 1 ^ b & d >> 1 ^ c;
432
+ let D = a & c >> 1 ^ d >> 1 ^ d;
433
+ a = A;
434
+ b = B;
435
+ c = C;
436
+ d = D;
437
+ A = a & a >> 2 ^ b & b >> 2;
438
+ B = a & b >> 2 ^ b & (a ^ b) >> 2;
439
+ C ^= a & c >> 2 ^ b & d >> 2;
440
+ D ^= b & c >> 2 ^ (a ^ b) & d >> 2;
441
+ a = A;
442
+ b = B;
443
+ c = C;
444
+ d = D;
445
+ A = a & a >> 4 ^ b & b >> 4;
446
+ B = a & b >> 4 ^ b & (a ^ b) >> 4;
447
+ C ^= a & c >> 4 ^ b & d >> 4;
448
+ D ^= b & c >> 4 ^ (a ^ b) & d >> 4;
449
+ a = A;
450
+ b = B;
451
+ c = C;
452
+ d = D;
453
+ C ^= a & c >> 8 ^ b & d >> 8;
454
+ D ^= b & c >> 8 ^ (a ^ b) & d >> 8;
455
+ a = C ^ C >> 1;
456
+ b = D ^ D >> 1;
457
+ let i0 = x ^ y;
458
+ let i1 = b | 0xffff ^ (i0 | a);
459
+ i0 = (i0 | i0 << 8) & 0x00ff00ff;
460
+ i0 = (i0 | i0 << 4) & 0x0f0f0f0f;
461
+ i0 = (i0 | i0 << 2) & 0x33333333;
462
+ i0 = (i0 | i0 << 1) & 0x55555555;
463
+ i1 = (i1 | i1 << 8) & 0x00ff00ff;
464
+ i1 = (i1 | i1 << 4) & 0x0f0f0f0f;
465
+ i1 = (i1 | i1 << 2) & 0x33333333;
466
+ i1 = (i1 | i1 << 1) & 0x55555555;
467
+ return (i1 << 1 | i0) >>> 0;
468
+ }
@@ -1,10 +1,11 @@
1
- export declare const MEASUREMENT_SPAN_ID = "mui_measurement_span";
1
+ import * as React from 'react';
2
+ export declare function clearStringMeasurementCache(): void;
2
3
  /**
3
- *
4
+ * Converts a style object into a string to be used as a cache key
4
5
  * @param style React style object
5
6
  * @returns CSS styling string
6
7
  */
7
- export declare const getStyleString: (style: React.CSSProperties) => string;
8
+ export declare function getStyleString(style: React.CSSProperties): string;
8
9
  /**
9
10
  *
10
11
  * @param text The string to estimate
@@ -14,4 +15,8 @@ export declare const getStyleString: (style: React.CSSProperties) => string;
14
15
  export declare const getStringSize: (text: string | number, style?: React.CSSProperties) => {
15
16
  width: number;
16
17
  height: number;
17
- };
18
+ };
19
+ export declare function batchMeasureStrings(texts: Iterable<string | number>, style?: React.CSSProperties): Map<string | number, {
20
+ width: number;
21
+ height: number;
22
+ }>;