@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.
- package/BarChart/BarChart.js +8 -0
- package/BarChart/BarChart.plugins.d.ts +2 -1
- package/BarChart/BarChart.plugins.js +2 -1
- package/BarChart/useBarChartProps.js +4 -2
- package/BarChart/useBarPlotData.js +20 -33
- package/CHANGELOG.md +202 -0
- package/ChartContainer/ChartContainer.js +8 -0
- package/ChartContainer/useChartContainerProps.js +4 -2
- package/ChartsBrushOverlay/ChartsBrushOverlay.classes.d.ts +12 -0
- package/ChartsBrushOverlay/ChartsBrushOverlay.classes.js +9 -0
- package/ChartsBrushOverlay/ChartsBrushOverlay.d.ts +6 -0
- package/ChartsBrushOverlay/ChartsBrushOverlay.js +102 -0
- package/ChartsBrushOverlay/index.d.ts +4 -0
- package/ChartsBrushOverlay/index.js +19 -0
- package/ChartsReferenceLine/ChartsReferenceLine.js +1 -1
- package/ChartsReferenceLine/ChartsXReferenceLine.js +13 -8
- package/ChartsReferenceLine/ChartsYReferenceLine.js +13 -8
- package/ChartsReferenceLine/common.d.ts +3 -1
- package/ChartsReferenceLine/common.js +3 -1
- package/ChartsTooltip/ChartsTooltipContainer.js +20 -2
- package/ChartsXAxis/getVisibleLabels.js +45 -25
- package/Gauge/Gauge.js +2 -9
- package/Gauge/GaugeReferenceArc.d.ts +4 -1
- package/Gauge/GaugeReferenceArc.js +12 -3
- package/Gauge/GaugeValueArc.d.ts +4 -1
- package/Gauge/GaugeValueArc.js +16 -8
- package/Gauge/GaugeValueText.js +3 -1
- package/LineChart/LineChart.js +8 -0
- package/LineChart/LineChart.plugins.d.ts +2 -1
- package/LineChart/LineChart.plugins.js +2 -1
- package/LineChart/useLineChartProps.js +4 -2
- package/ScatterChart/ScatterChart.js +8 -0
- package/ScatterChart/ScatterChart.plugins.d.ts +2 -1
- package/ScatterChart/ScatterChart.plugins.js +2 -1
- package/ScatterChart/seriesConfig/seriesProcessor.js +1 -1
- package/ScatterChart/useScatterChartProps.js +5 -3
- package/SparkLineChart/SparkLineChart.js +8 -0
- package/esm/BarChart/BarChart.js +8 -0
- package/esm/BarChart/BarChart.plugins.d.ts +2 -1
- package/esm/BarChart/BarChart.plugins.js +2 -1
- package/esm/BarChart/useBarChartProps.js +4 -2
- package/esm/BarChart/useBarPlotData.js +20 -33
- package/esm/ChartContainer/ChartContainer.js +8 -0
- package/esm/ChartContainer/useChartContainerProps.js +4 -2
- package/esm/ChartsBrushOverlay/ChartsBrushOverlay.classes.d.ts +12 -0
- package/esm/ChartsBrushOverlay/ChartsBrushOverlay.classes.js +2 -0
- package/esm/ChartsBrushOverlay/ChartsBrushOverlay.d.ts +6 -0
- package/esm/ChartsBrushOverlay/ChartsBrushOverlay.js +95 -0
- package/esm/ChartsBrushOverlay/index.d.ts +4 -0
- package/esm/ChartsBrushOverlay/index.js +2 -0
- package/esm/ChartsReferenceLine/ChartsReferenceLine.js +1 -1
- package/esm/ChartsReferenceLine/ChartsXReferenceLine.js +14 -9
- package/esm/ChartsReferenceLine/ChartsYReferenceLine.js +14 -9
- package/esm/ChartsReferenceLine/common.d.ts +3 -1
- package/esm/ChartsReferenceLine/common.js +2 -0
- package/esm/ChartsTooltip/ChartsTooltipContainer.js +20 -2
- package/esm/ChartsXAxis/getVisibleLabels.js +45 -25
- package/esm/Gauge/Gauge.js +2 -9
- package/esm/Gauge/GaugeReferenceArc.d.ts +4 -1
- package/esm/Gauge/GaugeReferenceArc.js +11 -2
- package/esm/Gauge/GaugeValueArc.d.ts +4 -1
- package/esm/Gauge/GaugeValueArc.js +16 -8
- package/esm/Gauge/GaugeValueText.js +3 -1
- package/esm/LineChart/LineChart.js +8 -0
- package/esm/LineChart/LineChart.plugins.d.ts +2 -1
- package/esm/LineChart/LineChart.plugins.js +2 -1
- package/esm/LineChart/useLineChartProps.js +4 -2
- package/esm/ScatterChart/ScatterChart.js +8 -0
- package/esm/ScatterChart/ScatterChart.plugins.d.ts +2 -1
- package/esm/ScatterChart/ScatterChart.plugins.js +2 -1
- package/esm/ScatterChart/seriesConfig/seriesProcessor.js +1 -1
- package/esm/ScatterChart/useScatterChartProps.js +5 -3
- package/esm/SparkLineChart/SparkLineChart.js +8 -0
- package/esm/hooks/index.d.ts +2 -1
- package/esm/hooks/index.js +2 -1
- package/esm/hooks/useBrush.d.ts +18 -0
- package/esm/hooks/useBrush.js +16 -0
- package/esm/index.d.ts +2 -1
- package/esm/index.js +2 -1
- package/esm/internals/Flatbush.d.ts +63 -0
- package/esm/internals/Flatbush.js +468 -0
- package/esm/internals/domUtils.d.ts +9 -4
- package/esm/internals/domUtils.js +115 -52
- package/esm/internals/index.d.ts +1 -0
- package/esm/internals/index.js +1 -0
- package/esm/internals/plugins/allPlugins.d.ts +4 -3
- package/esm/internals/plugins/allPlugins.js +2 -1
- package/esm/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.js +16 -10
- package/esm/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.types.d.ts +2 -2
- package/esm/internals/plugins/featurePlugins/useChartBrush/index.d.ts +3 -0
- package/esm/internals/plugins/featurePlugins/useChartBrush/index.js +3 -0
- package/esm/internals/plugins/featurePlugins/useChartBrush/useChartBrush.d.ts +3 -0
- package/esm/internals/plugins/featurePlugins/useChartBrush/useChartBrush.js +109 -0
- package/esm/internals/plugins/featurePlugins/useChartBrush/useChartBrush.selectors.d.ts +82 -0
- package/esm/internals/plugins/featurePlugins/useChartBrush/useChartBrush.selectors.js +75 -0
- package/esm/internals/plugins/featurePlugins/useChartBrush/useChartBrush.types.d.ts +72 -0
- package/esm/internals/plugins/featurePlugins/useChartBrush/useChartBrush.types.js +1 -0
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/createZoomLookup.js +3 -2
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/defaultizeAxis.js +2 -2
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/defaultizeZoom.d.ts +2 -1
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/defaultizeZoom.js +8 -3
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisValue.d.ts +6 -2
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisValue.js +3 -6
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxis.types.d.ts +3 -1
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisRendering.selectors.d.ts +19 -0
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisRendering.selectors.js +41 -0
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianHighlight.selectors.d.ts +4 -4
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianHighlight.selectors.js +13 -6
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianInteraction.selectors.js +4 -1
- package/esm/internals/plugins/featurePlugins/useChartClosestPoint/findClosestPoints.d.ts +5 -0
- package/esm/internals/plugins/featurePlugins/useChartClosestPoint/findClosestPoints.js +33 -0
- package/esm/internals/plugins/featurePlugins/useChartClosestPoint/useChartClosestPoint.js +40 -81
- package/esm/internals/plugins/utils/selectors.d.ts +1 -1
- package/esm/locales/elGR.js +97 -99
- package/esm/models/seriesType/scatter.d.ts +2 -0
- package/esm/tests/constants.js +1 -0
- package/esm/themeAugmentation/components.d.ts +3 -0
- package/esm/themeAugmentation/overrides.d.ts +2 -0
- package/hooks/index.d.ts +2 -1
- package/hooks/index.js +12 -0
- package/hooks/useBrush.d.ts +18 -0
- package/hooks/useBrush.js +21 -0
- package/index.d.ts +2 -1
- package/index.js +13 -1
- package/internals/Flatbush.d.ts +63 -0
- package/internals/Flatbush.js +477 -0
- package/internals/domUtils.d.ts +9 -4
- package/internals/domUtils.js +119 -54
- package/internals/index.d.ts +1 -0
- package/internals/index.js +12 -0
- package/internals/plugins/allPlugins.d.ts +4 -3
- package/internals/plugins/allPlugins.js +2 -1
- package/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.js +16 -10
- package/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.types.d.ts +2 -2
- package/internals/plugins/featurePlugins/useChartBrush/index.d.ts +3 -0
- package/internals/plugins/featurePlugins/useChartBrush/index.js +38 -0
- package/internals/plugins/featurePlugins/useChartBrush/useChartBrush.d.ts +3 -0
- package/internals/plugins/featurePlugins/useChartBrush/useChartBrush.js +117 -0
- package/internals/plugins/featurePlugins/useChartBrush/useChartBrush.selectors.d.ts +82 -0
- package/internals/plugins/featurePlugins/useChartBrush/useChartBrush.selectors.js +82 -0
- package/internals/plugins/featurePlugins/useChartBrush/useChartBrush.types.d.ts +72 -0
- package/internals/plugins/featurePlugins/useChartBrush/useChartBrush.types.js +5 -0
- package/internals/plugins/featurePlugins/useChartCartesianAxis/createZoomLookup.js +3 -2
- package/internals/plugins/featurePlugins/useChartCartesianAxis/defaultizeAxis.js +2 -2
- package/internals/plugins/featurePlugins/useChartCartesianAxis/defaultizeZoom.d.ts +2 -1
- package/internals/plugins/featurePlugins/useChartCartesianAxis/defaultizeZoom.js +8 -3
- package/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisValue.d.ts +6 -2
- package/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisValue.js +3 -6
- package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxis.types.d.ts +3 -1
- package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisRendering.selectors.d.ts +19 -0
- package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisRendering.selectors.js +43 -1
- package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianHighlight.selectors.d.ts +4 -4
- package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianHighlight.selectors.js +13 -6
- package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianInteraction.selectors.js +4 -1
- package/internals/plugins/featurePlugins/useChartClosestPoint/findClosestPoints.d.ts +5 -0
- package/internals/plugins/featurePlugins/useChartClosestPoint/findClosestPoints.js +39 -0
- package/internals/plugins/featurePlugins/useChartClosestPoint/useChartClosestPoint.js +39 -80
- package/internals/plugins/utils/selectors.d.ts +1 -1
- package/locales/elGR.js +97 -99
- package/models/seriesType/scatter.d.ts +2 -0
- package/package.json +5 -4
- package/tests/constants.js +7 -0
- package/themeAugmentation/components.d.ts +3 -0
- 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
|
+
}
|
package/internals/domUtils.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
|
|
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
|
|
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
|
+
}>;
|