@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.
- package/BarChart/BarChart.js +44 -36
- package/BarChart/useBarPlotData.js +20 -33
- package/CHANGELOG.md +204 -1
- package/ChartContainer/ChartContainer.js +68 -56
- package/ChartsTooltip/ChartsTooltipContainer.js +2 -0
- package/ChartsXAxis/useAxisTicksProps.d.ts +197 -355
- package/ChartsYAxis/useAxisTicksProps.d.ts +197 -355
- 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 +44 -36
- package/PieChart/PieArc.d.ts +18 -4
- package/PieChart/PieArc.js +11 -5
- package/PieChart/PieArcPlot.js +3 -1
- package/ScatterChart/ScatterChart.js +44 -36
- package/ScatterChart/seriesConfig/seriesProcessor.js +1 -1
- package/SparkLineChart/SparkLineChart.js +44 -36
- package/esm/BarChart/BarChart.js +44 -36
- package/esm/BarChart/useBarPlotData.js +20 -33
- package/esm/ChartContainer/ChartContainer.js +68 -56
- package/esm/ChartsTooltip/ChartsTooltipContainer.js +2 -0
- package/esm/ChartsXAxis/useAxisTicksProps.d.ts +197 -355
- package/esm/ChartsYAxis/useAxisTicksProps.d.ts +197 -355
- 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 +44 -36
- package/esm/PieChart/PieArc.d.ts +18 -4
- package/esm/PieChart/PieArc.js +11 -5
- package/esm/PieChart/PieArcPlot.js +3 -1
- package/esm/ScatterChart/ScatterChart.js +44 -36
- package/esm/ScatterChart/seriesConfig/seriesProcessor.js +1 -1
- package/esm/SparkLineChart/SparkLineChart.js +44 -36
- package/esm/hooks/animation/useAnimate.js +5 -3
- package/esm/hooks/useScale.d.ts +5 -1
- package/esm/index.js +1 -1
- package/esm/internals/Flatbush.bench.d.ts +1 -0
- package/esm/internals/Flatbush.bench.js +42 -0
- package/esm/internals/Flatbush.d.ts +63 -0
- package/esm/internals/Flatbush.js +468 -0
- package/esm/internals/animation/useAnimateInternal.d.ts +1 -1
- package/esm/internals/animation/useAnimateInternal.js +1 -1
- package/esm/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.js +8 -8
- package/esm/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.types.d.ts +4 -2
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/computeAxisValue.d.ts +9 -11
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/computeAxisValue.js +4 -28
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/createAxisFilterMapper.d.ts +4 -5
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/createAxisFilterMapper.js +3 -24
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/domain.d.ts +20 -0
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/domain.js +77 -0
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisScale.d.ts +4 -65
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisScale.js +7 -104
- 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/useChartCartesianAxisPreview.selectors.d.ts +3 -3
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisPreview.selectors.js +31 -39
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisRendering.selectors.d.ts +185 -6
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisRendering.selectors.js +199 -47
- 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/featurePlugins/useChartHighlight/useChartHighlight.js +10 -3
- package/esm/internals/plugins/featurePlugins/useChartHighlight/useChartHighlight.selectors.d.ts +4 -4
- package/esm/internals/plugins/featurePlugins/useChartHighlight/useChartHighlight.selectors.js +3 -2
- package/esm/internals/plugins/featurePlugins/useChartHighlight/useChartHighlight.types.d.ts +6 -0
- package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.js +5 -1
- package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.selectors.d.ts +9 -1
- package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.selectors.js +10 -1
- package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.types.d.ts +2 -1
- package/esm/internals/plugins/featurePlugins/useChartPolarAxis/computeAxisValue.js +2 -2
- package/esm/internals/scaleGuards.d.ts +12 -6
- package/esm/internals/symlogScale.js +5 -0
- package/esm/locales/enUS.js +4 -4
- package/esm/locales/ptBR.js +97 -99
- package/esm/models/axis.d.ts +39 -17
- package/esm/models/axis.js +3 -0
- package/esm/models/seriesType/scatter.d.ts +2 -0
- package/esm/themeAugmentation/components.d.ts +3 -0
- package/esm/themeAugmentation/overrides.d.ts +2 -0
- package/hooks/animation/useAnimate.js +4 -3
- package/hooks/useScale.d.ts +5 -1
- package/index.js +1 -1
- package/internals/Flatbush.bench.d.ts +1 -0
- package/internals/Flatbush.bench.js +44 -0
- package/internals/Flatbush.d.ts +63 -0
- package/internals/Flatbush.js +477 -0
- package/internals/animation/useAnimateInternal.d.ts +1 -1
- package/internals/animation/useAnimateInternal.js +1 -1
- package/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.js +7 -7
- package/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.types.d.ts +4 -2
- package/internals/plugins/featurePlugins/useChartCartesianAxis/computeAxisValue.d.ts +9 -11
- package/internals/plugins/featurePlugins/useChartCartesianAxis/computeAxisValue.js +4 -28
- package/internals/plugins/featurePlugins/useChartCartesianAxis/createAxisFilterMapper.d.ts +4 -5
- package/internals/plugins/featurePlugins/useChartCartesianAxis/createAxisFilterMapper.js +3 -25
- package/internals/plugins/featurePlugins/useChartCartesianAxis/domain.d.ts +20 -0
- package/internals/plugins/featurePlugins/useChartCartesianAxis/domain.js +84 -0
- package/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisScale.d.ts +4 -65
- package/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisScale.js +8 -108
- package/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisValue.d.ts +6 -2
- package/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisValue.js +3 -6
- package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisPreview.selectors.d.ts +3 -3
- package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisPreview.selectors.js +29 -37
- package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisRendering.selectors.d.ts +185 -6
- package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisRendering.selectors.js +200 -47
- 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/featurePlugins/useChartHighlight/useChartHighlight.js +10 -3
- package/internals/plugins/featurePlugins/useChartHighlight/useChartHighlight.selectors.d.ts +4 -4
- package/internals/plugins/featurePlugins/useChartHighlight/useChartHighlight.selectors.js +3 -2
- package/internals/plugins/featurePlugins/useChartHighlight/useChartHighlight.types.d.ts +6 -0
- package/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.js +5 -1
- package/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.selectors.d.ts +9 -1
- package/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.selectors.js +11 -2
- package/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.types.d.ts +2 -1
- package/internals/plugins/featurePlugins/useChartPolarAxis/computeAxisValue.js +1 -1
- package/internals/scaleGuards.d.ts +12 -6
- package/internals/symlogScale.js +5 -0
- package/locales/enUS.js +4 -4
- package/locales/ptBR.js +97 -99
- package/models/axis.d.ts +39 -17
- package/models/axis.js +4 -0
- package/models/seriesType/scatter.d.ts +2 -0
- package/package.json +7 -6
- package/themeAugmentation/components.d.ts +3 -0
- 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
|
+
}
|
|
@@ -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];
|
package/esm/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import * as React from 'react';
|
|
4
|
-
import { GestureManager, MoveGesture, PanGesture, PinchGesture, PressGesture, TapAndDragGesture, TapGesture, TurnWheelGesture } from '@mui/x-internal-gestures/core';
|
|
4
|
+
import { GestureManager, MoveGesture, PanGesture, PinchGesture, PressAndDragGesture, PressGesture, TapAndDragGesture, TapGesture, TurnWheelGesture } from '@mui/x-internal-gestures/core';
|
|
5
5
|
const preventDefault = event => event.preventDefault();
|
|
6
6
|
export const useChartInteractionListener = ({
|
|
7
7
|
svgRef
|
|
@@ -22,7 +22,7 @@ export const useChartInteractionListener = ({
|
|
|
22
22
|
name: 'zoomPan',
|
|
23
23
|
threshold: 0,
|
|
24
24
|
maxPointers: 1,
|
|
25
|
-
preventIf: ['zoomTapAndDrag']
|
|
25
|
+
preventIf: ['zoomTapAndDrag', 'zoomPressAndDrag']
|
|
26
26
|
}), new MoveGesture({
|
|
27
27
|
name: 'move',
|
|
28
28
|
preventIf: ['pan', 'zoomPinch', 'zoomPan'] // Prevent move gesture when pan is active
|
|
@@ -36,17 +36,17 @@ export const useChartInteractionListener = ({
|
|
|
36
36
|
initialDelta: 1
|
|
37
37
|
}), new TapGesture({
|
|
38
38
|
name: 'tap',
|
|
39
|
-
maxDistance: 10,
|
|
40
39
|
preventIf: ['pan', 'zoomPan', 'zoomPinch']
|
|
41
40
|
}), new PressGesture({
|
|
42
41
|
name: 'quickPress',
|
|
43
|
-
duration: 50
|
|
44
|
-
maxDistance: 10
|
|
42
|
+
duration: 50
|
|
45
43
|
}), new TapAndDragGesture({
|
|
46
44
|
name: 'zoomTapAndDrag',
|
|
47
|
-
|
|
45
|
+
dragThreshold: 10
|
|
46
|
+
}), new PressAndDragGesture({
|
|
47
|
+
name: 'zoomPressAndDrag',
|
|
48
48
|
dragThreshold: 10,
|
|
49
|
-
|
|
49
|
+
preventIf: ['zoomPinch']
|
|
50
50
|
})]
|
|
51
51
|
});
|
|
52
52
|
}
|
|
@@ -56,7 +56,7 @@ export const useChartInteractionListener = ({
|
|
|
56
56
|
if (!svg || !gestureManager) {
|
|
57
57
|
return undefined;
|
|
58
58
|
}
|
|
59
|
-
gestureManager.registerElement(['pan', 'move', 'zoomPinch', 'zoomPan', 'zoomTurnWheel', 'tap', 'quickPress', 'zoomTapAndDrag'], svg);
|
|
59
|
+
gestureManager.registerElement(['pan', 'move', 'zoomPinch', 'zoomPan', 'zoomTurnWheel', 'tap', 'quickPress', 'zoomTapAndDrag', 'zoomPressAndDrag'], svg);
|
|
60
60
|
return () => {
|
|
61
61
|
// Cleanup gesture manager
|
|
62
62
|
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' | '
|
|
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 {
|
|
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
|
|
6
|
+
import { ComputedAxisConfig } from "./useChartCartesianAxis.types.js";
|
|
6
7
|
import { ProcessedSeries } from "../../corePlugins/useChartSeries/useChartSeries.types.js";
|
|
7
|
-
import {
|
|
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,
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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[];
|
|
@@ -5,9 +5,7 @@ import { getColorScale, getOrdinalColorScale, getSequentialColorScale } from "..
|
|
|
5
5
|
import { scaleTickNumberByRange } from "../../../ticks.js";
|
|
6
6
|
import { getScale } from "../../../getScale.js";
|
|
7
7
|
import { isDateData, createDateFormatter } from "../../../dateHelpers.js";
|
|
8
|
-
import { getAxisExtrema } from "./getAxisExtrema.js";
|
|
9
8
|
import { getAxisTriggerTooltip } from "./getAxisTriggerTooltip.js";
|
|
10
|
-
import { applyDomainLimit, getActualAxisExtrema, getDomainLimit } from "./getAxisScale.js";
|
|
11
9
|
import { isBandScale, isOrdinalScale } from "../../../scaleGuards.js";
|
|
12
10
|
function getRange(drawingArea, axisDirection,
|
|
13
11
|
// | 'rotation' | 'radius',
|
|
@@ -25,9 +23,7 @@ export function computeAxisValue({
|
|
|
25
23
|
seriesConfig,
|
|
26
24
|
axisDirection,
|
|
27
25
|
zoomMap,
|
|
28
|
-
|
|
29
|
-
getFilters,
|
|
30
|
-
preferStrictDomainInLineCharts
|
|
26
|
+
domains
|
|
31
27
|
}) {
|
|
32
28
|
if (allAxis === undefined) {
|
|
33
29
|
return {
|
|
@@ -37,11 +33,9 @@ export function computeAxisValue({
|
|
|
37
33
|
}
|
|
38
34
|
const axisIdsTriggeringTooltip = getAxisTriggerTooltip(axisDirection, seriesConfig, formattedSeries, allAxis[0].id);
|
|
39
35
|
const completeAxis = {};
|
|
40
|
-
allAxis.forEach(
|
|
36
|
+
allAxis.forEach(eachAxis => {
|
|
41
37
|
const axis = eachAxis;
|
|
42
|
-
const
|
|
43
|
-
let scale = scaleDefinition.scale;
|
|
44
|
-
const zoomOption = zoomOptions?.[axis.id];
|
|
38
|
+
const scale = scales[axis.id];
|
|
45
39
|
const zoom = zoomMap?.get(axis.id);
|
|
46
40
|
const zoomRange = zoom ? [zoom.start, zoom.end] : [0, 100];
|
|
47
41
|
const range = getRange(drawingArea, axisDirection, axis.reverse ?? false);
|
|
@@ -92,28 +86,10 @@ export function computeAxisValue({
|
|
|
92
86
|
// Could be merged with the two previous "if conditions" but then TS does not get that `axis.scaleType` can't be `band` or `point`.
|
|
93
87
|
return;
|
|
94
88
|
}
|
|
95
|
-
const rawTickNumber =
|
|
89
|
+
const rawTickNumber = domains[axis.id].tickNumber;
|
|
96
90
|
const continuousAxis = axis;
|
|
97
91
|
const scaleType = continuousAxis.scaleType ?? 'linear';
|
|
98
92
|
const tickNumber = scaleTickNumberByRange(rawTickNumber, zoomRange);
|
|
99
|
-
const filter = zoom === undefined && !zoomOption ? getFilters : undefined; // Do not apply filtering if zoom is already defined.
|
|
100
|
-
if (filter) {
|
|
101
|
-
const [minData, maxData] = getAxisExtrema(axis, axisDirection, seriesConfig, axisIndex, formattedSeries, filter);
|
|
102
|
-
scale = scale.copy();
|
|
103
|
-
scale.domain([minData, maxData]);
|
|
104
|
-
const domainLimit = getDomainLimit(axis, axisDirection, axisIndex, formattedSeries, preferStrictDomainInLineCharts);
|
|
105
|
-
const axisExtrema = getActualAxisExtrema(axis, minData, maxData);
|
|
106
|
-
if (typeof domainLimit === 'function') {
|
|
107
|
-
const {
|
|
108
|
-
min,
|
|
109
|
-
max
|
|
110
|
-
} = domainLimit(minData, maxData);
|
|
111
|
-
axisExtrema[0] = min;
|
|
112
|
-
axisExtrema[1] = max;
|
|
113
|
-
}
|
|
114
|
-
scale.domain(axisExtrema);
|
|
115
|
-
applyDomainLimit(scale, axis, domainLimit, rawTickNumber);
|
|
116
|
-
}
|
|
117
93
|
completeAxis[axis.id] = _extends({
|
|
118
94
|
offset: 0,
|
|
119
95
|
height: 0,
|
package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/createAxisFilterMapper.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { NumberValue } from '@mui/x-charts-vendor/d3-scale';
|
|
2
2
|
import { AxisConfig } from "../../../../models/index.js";
|
|
3
|
-
import {
|
|
4
|
-
import { GetZoomAxisFilters, ZoomAxisFilters
|
|
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(
|
|
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;
|