@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
package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/createAxisFilterMapper.js
CHANGED
|
@@ -1,22 +1,4 @@
|
|
|
1
1
|
import { isDefined } from "../../../isDefined.js";
|
|
2
|
-
import { isOrdinalScale } from "../../../scaleGuards.js";
|
|
3
|
-
export function createAxisFilterMapper(zoomMap, zoomOptions, direction) {
|
|
4
|
-
return (axisId, axisData, scale) => {
|
|
5
|
-
const zoomOption = zoomOptions[axisId];
|
|
6
|
-
if (!zoomOption || zoomOption.filterMode !== 'discard') {
|
|
7
|
-
return null;
|
|
8
|
-
}
|
|
9
|
-
const zoom = zoomMap?.get(axisId);
|
|
10
|
-
if (zoom === undefined || zoom.start <= 0 && zoom.end >= 100) {
|
|
11
|
-
// No zoom, or zoom with all data visible
|
|
12
|
-
return null;
|
|
13
|
-
}
|
|
14
|
-
if (isOrdinalScale(scale)) {
|
|
15
|
-
return createDiscreteScaleGetAxisFilter(axisData, zoom.start, zoom.end, direction);
|
|
16
|
-
}
|
|
17
|
-
return createContinuousScaleGetAxisFilter(scale, zoom.start, zoom.end, direction, axisData);
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
2
|
export function createDiscreteScaleGetAxisFilter(axisData, zoomStart, zoomEnd, direction) {
|
|
21
3
|
const maxIndex = axisData?.length ?? 0;
|
|
22
4
|
const minVal = Math.floor(zoomStart * maxIndex / 100);
|
|
@@ -30,12 +12,9 @@ export function createDiscreteScaleGetAxisFilter(axisData, zoomStart, zoomEnd, d
|
|
|
30
12
|
return dataIndex >= minVal && dataIndex < maxVal;
|
|
31
13
|
};
|
|
32
14
|
}
|
|
33
|
-
export function createContinuousScaleGetAxisFilter(
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
[min, max] = scale.domain();
|
|
37
|
-
min = min instanceof Date ? min.getTime() : min;
|
|
38
|
-
max = max instanceof Date ? max.getTime() : max;
|
|
15
|
+
export function createContinuousScaleGetAxisFilter(domain, zoomStart, zoomEnd, direction, axisData) {
|
|
16
|
+
const min = domain[0].valueOf();
|
|
17
|
+
const max = domain[1].valueOf();
|
|
39
18
|
const minVal = min + zoomStart * (max - min) / 100;
|
|
40
19
|
const maxVal = min + zoomEnd * (max - min) / 100;
|
|
41
20
|
return function filterAxis(value, dataIndex) {
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { NumberValue } from '@mui/x-charts-vendor/d3-scale';
|
|
2
|
+
import { ContinuousScaleName, DefaultedAxis } from "../../../../models/axis.js";
|
|
3
|
+
import { ProcessedSeries } from "../../corePlugins/useChartSeries/index.js";
|
|
4
|
+
import { TickParams } from "../../../../hooks/useTicks.js";
|
|
5
|
+
/**
|
|
6
|
+
* Calculates the initial domain and tick number for a given axis.
|
|
7
|
+
* The domain should still run through the zoom filterMode after this step.
|
|
8
|
+
*/
|
|
9
|
+
export declare function calculateInitialDomainAndTickNumber(axis: DefaultedAxis<ContinuousScaleName>, axisDirection: 'x' | 'y', axisIndex: number, formattedSeries: ProcessedSeries, [minData, maxData]: [number | Date, number | Date], defaultTickNumber: number, preferStrictDomainInLineCharts: boolean | undefined): {
|
|
10
|
+
domain: [NumberValue, NumberValue];
|
|
11
|
+
tickNumber: number;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Calculates the final domain for an axis.
|
|
15
|
+
* After this step, the domain can be used to create the axis scale.
|
|
16
|
+
*/
|
|
17
|
+
export declare function calculateFinalDomain(axis: Pick<DefaultedAxis<ContinuousScaleName>, 'id' | 'domainLimit' | 'scaleType'> & TickParams & {
|
|
18
|
+
min?: NumberValue;
|
|
19
|
+
max?: NumberValue;
|
|
20
|
+
}, axisDirection: 'x' | 'y', axisIndex: number, formattedSeries: ProcessedSeries, [minData, maxData]: [number | Date, number | Date], tickNumber: number, preferStrictDomainInLineCharts: boolean | undefined): NumberValue[];
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { getScale } from "../../../getScale.js";
|
|
2
|
+
import { getAxisDomainLimit } from "./getAxisDomainLimit.js";
|
|
3
|
+
import { getTickNumber } from "../../../ticks.js";
|
|
4
|
+
function niceDomain(scaleType, domain, tickNumber) {
|
|
5
|
+
return getScale(scaleType ?? 'linear', domain, [0, 1]).nice(tickNumber).domain();
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Calculates the initial domain and tick number for a given axis.
|
|
10
|
+
* The domain should still run through the zoom filterMode after this step.
|
|
11
|
+
*/
|
|
12
|
+
export function calculateInitialDomainAndTickNumber(axis, axisDirection, axisIndex, formattedSeries, [minData, maxData], defaultTickNumber, preferStrictDomainInLineCharts) {
|
|
13
|
+
const domainLimit = getDomainLimit(axis, axisDirection, axisIndex, formattedSeries, preferStrictDomainInLineCharts);
|
|
14
|
+
let axisExtrema = getActualAxisExtrema(axis, minData, maxData);
|
|
15
|
+
if (typeof domainLimit === 'function') {
|
|
16
|
+
const {
|
|
17
|
+
min,
|
|
18
|
+
max
|
|
19
|
+
} = domainLimit(minData.valueOf(), maxData.valueOf());
|
|
20
|
+
axisExtrema[0] = min;
|
|
21
|
+
axisExtrema[1] = max;
|
|
22
|
+
}
|
|
23
|
+
const tickNumber = getTickNumber(axis, axisExtrema, defaultTickNumber);
|
|
24
|
+
if (domainLimit === 'nice') {
|
|
25
|
+
axisExtrema = niceDomain(axis.scaleType, axisExtrema, tickNumber);
|
|
26
|
+
}
|
|
27
|
+
axisExtrema = ['min' in axis ? axis.min ?? axisExtrema[0] : axisExtrema[0], 'max' in axis ? axis.max ?? axisExtrema[1] : axisExtrema[1]];
|
|
28
|
+
return {
|
|
29
|
+
domain: axisExtrema,
|
|
30
|
+
tickNumber
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Calculates the final domain for an axis.
|
|
36
|
+
* After this step, the domain can be used to create the axis scale.
|
|
37
|
+
*/
|
|
38
|
+
export function calculateFinalDomain(axis, axisDirection, axisIndex, formattedSeries, [minData, maxData], tickNumber, preferStrictDomainInLineCharts) {
|
|
39
|
+
const domainLimit = getDomainLimit(axis, axisDirection, axisIndex, formattedSeries, preferStrictDomainInLineCharts);
|
|
40
|
+
let axisExtrema = getActualAxisExtrema(axis, minData, maxData);
|
|
41
|
+
if (typeof domainLimit === 'function') {
|
|
42
|
+
const {
|
|
43
|
+
min,
|
|
44
|
+
max
|
|
45
|
+
} = domainLimit(minData.valueOf(), maxData.valueOf());
|
|
46
|
+
axisExtrema[0] = min;
|
|
47
|
+
axisExtrema[1] = max;
|
|
48
|
+
}
|
|
49
|
+
if (domainLimit === 'nice') {
|
|
50
|
+
axisExtrema = niceDomain(axis.scaleType, axisExtrema, tickNumber);
|
|
51
|
+
}
|
|
52
|
+
return [axis.min ?? axisExtrema[0], axis.max ?? axisExtrema[1]];
|
|
53
|
+
}
|
|
54
|
+
function getDomainLimit(axis, axisDirection, axisIndex, formattedSeries, preferStrictDomainInLineCharts) {
|
|
55
|
+
return preferStrictDomainInLineCharts ? getAxisDomainLimit(axis, axisDirection, axisIndex, formattedSeries) : axis.domainLimit ?? 'nice';
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Get the actual axis extrema considering the user defined min and max values.
|
|
60
|
+
* @param axisExtrema User defined axis extrema.
|
|
61
|
+
* @param minData Minimum value from the data.
|
|
62
|
+
* @param maxData Maximum value from the data.
|
|
63
|
+
*/
|
|
64
|
+
function getActualAxisExtrema(axisExtrema, minData, maxData) {
|
|
65
|
+
let min = minData;
|
|
66
|
+
let max = maxData;
|
|
67
|
+
if ('max' in axisExtrema && axisExtrema.max != null && axisExtrema.max < minData) {
|
|
68
|
+
min = axisExtrema.max;
|
|
69
|
+
}
|
|
70
|
+
if ('min' in axisExtrema && axisExtrema.min != null && axisExtrema.min > minData) {
|
|
71
|
+
max = axisExtrema.min;
|
|
72
|
+
}
|
|
73
|
+
if (!('min' in axisExtrema) && !('max' in axisExtrema)) {
|
|
74
|
+
return [min, max];
|
|
75
|
+
}
|
|
76
|
+
return [axisExtrema.min ?? min, axisExtrema.max ?? max];
|
|
77
|
+
}
|
|
@@ -1,66 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { ProcessedSeries } from "../../corePlugins/useChartSeries/index.js";
|
|
4
|
-
import { ChartSeriesConfig } from "../../models/index.js";
|
|
5
|
-
import { ZoomData } from "./zoom.types.js";
|
|
1
|
+
import { NumberValue } from '@mui/x-charts-vendor/d3-scale';
|
|
2
|
+
import { AxisConfig, ChartsAxisProps, D3Scale, DefaultedAxis, ScaleName } from "../../../../models/axis.js";
|
|
6
3
|
import { ChartDrawingArea } from "../../../../hooks/useDrawingArea.js";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
formattedSeries: ProcessedSeries<T>;
|
|
10
|
-
seriesConfig: ChartSeriesConfig<T>;
|
|
11
|
-
zoomMap?: Map<AxisId, ZoomData>;
|
|
12
|
-
/**
|
|
13
|
-
* @deprecated To remove in v9. This is an experimental feature to avoid breaking change.
|
|
14
|
-
*/
|
|
15
|
-
preferStrictDomainInLineCharts?: boolean;
|
|
16
|
-
defaultTickNumber: number;
|
|
17
|
-
};
|
|
18
|
-
export declare function getXAxesScales<T extends ChartSeriesType>({
|
|
19
|
-
drawingArea,
|
|
20
|
-
formattedSeries,
|
|
21
|
-
axis: axes,
|
|
22
|
-
seriesConfig,
|
|
23
|
-
zoomMap,
|
|
24
|
-
preferStrictDomainInLineCharts,
|
|
25
|
-
defaultTickNumber
|
|
26
|
-
}: GetAxesScalesParams<T> & {
|
|
27
|
-
axis?: DefaultedAxis[];
|
|
28
|
-
}): Record<AxisId, ScaleDefinition>;
|
|
29
|
-
export declare function getYAxesScales<T extends ChartSeriesType>({
|
|
30
|
-
drawingArea,
|
|
31
|
-
formattedSeries,
|
|
32
|
-
axis: axes,
|
|
33
|
-
seriesConfig,
|
|
34
|
-
zoomMap,
|
|
35
|
-
preferStrictDomainInLineCharts,
|
|
36
|
-
defaultTickNumber
|
|
37
|
-
}: GetAxesScalesParams<T> & {
|
|
38
|
-
axis?: DefaultedAxis[];
|
|
39
|
-
}): Record<AxisId, ScaleDefinition>;
|
|
40
|
-
export type ScaleDefinition = {
|
|
41
|
-
scale: D3ContinuousScale;
|
|
42
|
-
tickNumber: number;
|
|
43
|
-
} | {
|
|
44
|
-
scale: D3OrdinalScale;
|
|
45
|
-
tickNumber?: never;
|
|
46
|
-
};
|
|
47
|
-
type DomainLimit = 'nice' | 'strict' | ((min: number, max: number) => {
|
|
48
|
-
min: number;
|
|
49
|
-
max: number;
|
|
50
|
-
});
|
|
51
|
-
export declare function getDomainLimit(axis: Pick<DefaultedAxis, 'id' | 'domainLimit'>, axisDirection: 'x' | 'y', axisIndex: number, formattedSeries: ProcessedSeries, preferStrictDomainInLineCharts: boolean | undefined): "nice" | "strict" | ((min: number, max: number) => {
|
|
52
|
-
min: number;
|
|
53
|
-
max: number;
|
|
54
|
-
});
|
|
55
|
-
export declare function applyDomainLimit(scale: D3ContinuousScale, axis: {
|
|
56
|
-
min?: number | Date;
|
|
57
|
-
max?: number | Date;
|
|
58
|
-
}, domainLimit: DomainLimit, rawTickNumber: number): void;
|
|
59
|
-
/**
|
|
60
|
-
* Get the actual axis extrema considering the user defined min and max values.
|
|
61
|
-
* @param axisExtrema User defined axis extrema.
|
|
62
|
-
* @param minData Minimum value from the data.
|
|
63
|
-
* @param maxData Maximum value from the data.
|
|
64
|
-
*/
|
|
65
|
-
export declare function getActualAxisExtrema(axisExtrema: Pick<AxisConfig, 'min' | 'max'>, minData: number, maxData: number): [number | Date, number | Date];
|
|
66
|
-
export {};
|
|
4
|
+
export declare function getRange(drawingArea: ChartDrawingArea, axisDirection: 'x' | 'y', axis: AxisConfig<ScaleName, any, ChartsAxisProps>): [number, number];
|
|
5
|
+
export declare function getNormalizedAxisScale(axis: Readonly<DefaultedAxis<ScaleName, any, Readonly<ChartsAxisProps>>>, domain: ReadonlyArray<NumberValue | string>): D3Scale;
|
|
@@ -1,121 +1,24 @@
|
|
|
1
1
|
import { scaleBand, scalePoint } from '@mui/x-charts-vendor/d3-scale';
|
|
2
2
|
import { isBandScaleConfig, isPointScaleConfig, isSymlogScaleConfig } from "../../../../models/axis.js";
|
|
3
|
-
import { zoomScaleRange } from "./zoom.js";
|
|
4
|
-
import { getAxisDomainLimit } from "./getAxisDomainLimit.js";
|
|
5
|
-
import { getTickNumber } from "../../../ticks.js";
|
|
6
3
|
import { getScale } from "../../../getScale.js";
|
|
7
|
-
import { getAxisExtrema } from "./getAxisExtrema.js";
|
|
8
4
|
const DEFAULT_CATEGORY_GAP_RATIO = 0.2;
|
|
9
|
-
function getRange(drawingArea, axisDirection, axis) {
|
|
5
|
+
export function getRange(drawingArea, axisDirection, axis) {
|
|
10
6
|
const range = axisDirection === 'x' ? [drawingArea.left, drawingArea.left + drawingArea.width] : [drawingArea.top + drawingArea.height, drawingArea.top];
|
|
11
7
|
return axis.reverse ? [range[1], range[0]] : range;
|
|
12
8
|
}
|
|
13
|
-
export function
|
|
14
|
-
|
|
15
|
-
formattedSeries,
|
|
16
|
-
axis: axes = [],
|
|
17
|
-
seriesConfig,
|
|
18
|
-
zoomMap,
|
|
19
|
-
preferStrictDomainInLineCharts,
|
|
20
|
-
defaultTickNumber
|
|
21
|
-
}) {
|
|
22
|
-
const scales = {};
|
|
23
|
-
axes.forEach((eachAxis, axisIndex) => {
|
|
24
|
-
const axis = eachAxis;
|
|
25
|
-
const zoom = zoomMap?.get(axis.id);
|
|
26
|
-
scales[axis.id] = getAxisScale(axis, 'x', zoom, drawingArea, seriesConfig, axisIndex, formattedSeries, preferStrictDomainInLineCharts, defaultTickNumber);
|
|
27
|
-
});
|
|
28
|
-
return scales;
|
|
29
|
-
}
|
|
30
|
-
export function getYAxesScales({
|
|
31
|
-
drawingArea,
|
|
32
|
-
formattedSeries,
|
|
33
|
-
axis: axes = [],
|
|
34
|
-
seriesConfig,
|
|
35
|
-
zoomMap,
|
|
36
|
-
preferStrictDomainInLineCharts,
|
|
37
|
-
defaultTickNumber
|
|
38
|
-
}) {
|
|
39
|
-
const scales = {};
|
|
40
|
-
axes.forEach((eachAxis, axisIndex) => {
|
|
41
|
-
const axis = eachAxis;
|
|
42
|
-
const zoom = zoomMap?.get(axis.id);
|
|
43
|
-
scales[axis.id] = getAxisScale(axis, 'y', zoom, drawingArea, seriesConfig, axisIndex, formattedSeries, preferStrictDomainInLineCharts, defaultTickNumber);
|
|
44
|
-
});
|
|
45
|
-
return scales;
|
|
46
|
-
}
|
|
47
|
-
function getAxisScale(axis, axisDirection, zoom, drawingArea, seriesConfig, axisIndex, formattedSeries,
|
|
48
|
-
/**
|
|
49
|
-
* @deprecated To remove in v9. This is an experimental feature to avoid breaking change.
|
|
50
|
-
*/
|
|
51
|
-
preferStrictDomainInLineCharts, defaultTickNumber) {
|
|
52
|
-
const zoomRange = zoom ? [zoom.start, zoom.end] : [0, 100];
|
|
53
|
-
const range = getRange(drawingArea, axisDirection, axis);
|
|
9
|
+
export function getNormalizedAxisScale(axis, domain) {
|
|
10
|
+
const range = [0, 1];
|
|
54
11
|
if (isBandScaleConfig(axis)) {
|
|
55
12
|
const categoryGapRatio = axis.categoryGapRatio ?? DEFAULT_CATEGORY_GAP_RATIO;
|
|
56
|
-
|
|
57
|
-
const scaleRange = axisDirection === 'y' ? [range[1], range[0]] : range;
|
|
58
|
-
const zoomedRange = zoomScaleRange(scaleRange, zoomRange);
|
|
59
|
-
return {
|
|
60
|
-
scale: scaleBand(axis.data, zoomedRange).paddingInner(categoryGapRatio).paddingOuter(categoryGapRatio / 2)
|
|
61
|
-
};
|
|
13
|
+
return scaleBand(domain, range).paddingInner(categoryGapRatio).paddingOuter(categoryGapRatio / 2);
|
|
62
14
|
}
|
|
63
15
|
if (isPointScaleConfig(axis)) {
|
|
64
|
-
|
|
65
|
-
const zoomedRange = zoomScaleRange(scaleRange, zoomRange);
|
|
66
|
-
return {
|
|
67
|
-
scale: scalePoint(axis.data, zoomedRange)
|
|
68
|
-
};
|
|
16
|
+
return scalePoint(domain, range);
|
|
69
17
|
}
|
|
70
18
|
const scaleType = axis.scaleType ?? 'linear';
|
|
71
|
-
const
|
|
72
|
-
const [minData, maxData] = getAxisExtrema(axis, axisDirection, seriesConfig, axisIndex, formattedSeries);
|
|
73
|
-
const axisExtrema = getActualAxisExtrema(axis, minData, maxData);
|
|
74
|
-
if (typeof domainLimit === 'function') {
|
|
75
|
-
const {
|
|
76
|
-
min,
|
|
77
|
-
max
|
|
78
|
-
} = domainLimit(minData, maxData);
|
|
79
|
-
axisExtrema[0] = min;
|
|
80
|
-
axisExtrema[1] = max;
|
|
81
|
-
}
|
|
82
|
-
const rawTickNumber = getTickNumber(axis, axisExtrema, defaultTickNumber);
|
|
83
|
-
const zoomedRange = zoomScaleRange(range, zoomRange);
|
|
84
|
-
const scale = getScale(scaleType, axisExtrema, zoomedRange);
|
|
19
|
+
const scale = getScale(scaleType, domain, range);
|
|
85
20
|
if (isSymlogScaleConfig(axis) && axis.constant != null) {
|
|
86
21
|
scale.constant(axis.constant);
|
|
87
22
|
}
|
|
88
|
-
|
|
89
|
-
return {
|
|
90
|
-
scale,
|
|
91
|
-
tickNumber: rawTickNumber
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
export function getDomainLimit(axis, axisDirection, axisIndex, formattedSeries, preferStrictDomainInLineCharts) {
|
|
95
|
-
return preferStrictDomainInLineCharts ? getAxisDomainLimit(axis, axisDirection, axisIndex, formattedSeries) : axis.domainLimit ?? 'nice';
|
|
96
|
-
}
|
|
97
|
-
export function applyDomainLimit(scale, axis, domainLimit, rawTickNumber) {
|
|
98
|
-
if (domainLimit === 'nice') {
|
|
99
|
-
scale.nice(rawTickNumber);
|
|
100
|
-
}
|
|
101
|
-
const [minDomain, maxDomain] = scale.domain();
|
|
102
|
-
scale.domain([axis.min ?? minDomain, axis.max ?? maxDomain]);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Get the actual axis extrema considering the user defined min and max values.
|
|
107
|
-
* @param axisExtrema User defined axis extrema.
|
|
108
|
-
* @param minData Minimum value from the data.
|
|
109
|
-
* @param maxData Maximum value from the data.
|
|
110
|
-
*/
|
|
111
|
-
export function getActualAxisExtrema(axisExtrema, minData, maxData) {
|
|
112
|
-
let min = minData;
|
|
113
|
-
let max = maxData;
|
|
114
|
-
if (axisExtrema.max != null && axisExtrema.max.valueOf() < minData) {
|
|
115
|
-
min = axisExtrema.max;
|
|
116
|
-
}
|
|
117
|
-
if (axisExtrema.min != null && axisExtrema.min.valueOf() > minData) {
|
|
118
|
-
max = axisExtrema.min;
|
|
119
|
-
}
|
|
120
|
-
return [axisExtrema.min ?? min, axisExtrema.max ?? max];
|
|
23
|
+
return scale;
|
|
121
24
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ComputedAxis } from "../../../../models/axis.js";
|
|
1
|
+
import { ComputedAxis, D3Scale } from "../../../../models/axis.js";
|
|
2
2
|
/**
|
|
3
3
|
* For a pointer coordinate, this function returns the dataIndex associated.
|
|
4
4
|
* Returns `-1` if no dataIndex matches.
|
|
@@ -8,4 +8,8 @@ export declare function getAxisIndex(axisConfig: ComputedAxis, pointerValue: num
|
|
|
8
8
|
* For a pointer coordinate, this function returns the value associated.
|
|
9
9
|
* Returns `null` if the coordinate has no value associated.
|
|
10
10
|
*/
|
|
11
|
-
export declare function getAxisValue
|
|
11
|
+
export declare function getAxisValue<Domain extends {
|
|
12
|
+
toString(): string;
|
|
13
|
+
} = {
|
|
14
|
+
toString(): string;
|
|
15
|
+
}, Range = number, Output = number>(scale: D3Scale<Domain, Range, Output>, axisData: readonly any[] | undefined, pointerValue: number, dataIndex: number | null): number | Date | null;
|
|
@@ -46,14 +46,11 @@ export function getAxisIndex(axisConfig, pointerValue) {
|
|
|
46
46
|
* For a pointer coordinate, this function returns the value associated.
|
|
47
47
|
* Returns `null` if the coordinate has no value associated.
|
|
48
48
|
*/
|
|
49
|
-
export function getAxisValue(
|
|
50
|
-
const {
|
|
51
|
-
scale,
|
|
52
|
-
data: axisData
|
|
53
|
-
} = axisConfig;
|
|
49
|
+
export function getAxisValue(scale, axisData, pointerValue, dataIndex) {
|
|
54
50
|
if (!isOrdinalScale(scale)) {
|
|
55
51
|
if (dataIndex === null) {
|
|
56
|
-
|
|
52
|
+
const invertedValue = scale.invert(pointerValue);
|
|
53
|
+
return Number.isNaN(invertedValue) ? null : invertedValue;
|
|
57
54
|
}
|
|
58
55
|
return axisData[dataIndex];
|
|
59
56
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AxisId } from "../../../../models/axis.js";
|
|
2
|
-
export declare const selectorChartPreviewXScales: import("reselect").Selector<any, Record<AxisId,
|
|
1
|
+
import { AxisId, D3Scale } from "../../../../models/axis.js";
|
|
2
|
+
export declare const selectorChartPreviewXScales: import("reselect").Selector<any, Record<AxisId, D3Scale>, [axisId: AxisId]>;
|
|
3
3
|
export declare const selectorChartPreviewComputedXAxis: import("reselect").Selector<any, import("./useChartCartesianAxis.types.js").ComputedAxisConfig<import("../../../index.js").ChartsXAxisProps>, [axisId: AxisId]>;
|
|
4
|
-
export declare const selectorChartPreviewYScales: import("reselect").Selector<any, Record<AxisId,
|
|
4
|
+
export declare const selectorChartPreviewYScales: import("reselect").Selector<any, Record<AxisId, D3Scale>, [axisId: AxisId]>;
|
|
5
5
|
export declare const selectorChartPreviewComputedYAxis: import("reselect").Selector<any, import("./useChartCartesianAxis.types.js").ComputedAxisConfig<import("../../../index.js").ChartsYAxisProps>, [axisId: AxisId]>;
|
|
@@ -2,11 +2,12 @@ import { createSelector } from "../../utils/selectors.js";
|
|
|
2
2
|
import { selectorChartRawXAxis, selectorChartRawYAxis } from "./useChartCartesianAxisLayout.selectors.js";
|
|
3
3
|
import { selectorChartSeriesConfig, selectorChartSeriesProcessed } from "../../corePlugins/useChartSeries/index.js";
|
|
4
4
|
import { computeAxisValue } from "./computeAxisValue.js";
|
|
5
|
-
import {
|
|
5
|
+
import { selectorChartNormalizedXScales, selectorChartNormalizedYScales, selectorChartXDomains, selectorChartYDomains, selectorChartZoomOptionsLookup } from "./useChartCartesianAxisRendering.selectors.js";
|
|
6
6
|
import { selectorChartDrawingArea } from "../../corePlugins/useChartDimensions/index.js";
|
|
7
7
|
import { ZOOM_SLIDER_PREVIEW_SIZE } from "../../../constants.js";
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
8
|
+
import { getRange } from "./getAxisScale.js";
|
|
9
|
+
import { zoomScaleRange } from "./zoom.js";
|
|
10
|
+
import { isOrdinalScale } from "../../../scaleGuards.js";
|
|
10
11
|
function createPreviewDrawingArea(axisDirection, mainChartDrawingArea) {
|
|
11
12
|
return axisDirection === 'x' ? {
|
|
12
13
|
left: 0,
|
|
@@ -24,26 +25,22 @@ function createPreviewDrawingArea(axisDirection, mainChartDrawingArea) {
|
|
|
24
25
|
bottom: mainChartDrawingArea.height
|
|
25
26
|
};
|
|
26
27
|
}
|
|
27
|
-
export const selectorChartPreviewXScales = createSelector([selectorChartRawXAxis, selectorChartDrawingArea,
|
|
28
|
+
export const selectorChartPreviewXScales = createSelector([selectorChartRawXAxis, selectorChartDrawingArea, selectorChartZoomOptionsLookup, selectorChartNormalizedXScales, (_, axisId) => axisId], function selectorChartPreviewXScales(xAxes, chartDrawingArea, zoomOptions, normalizedXScales, axisId) {
|
|
28
29
|
const hasAxis = xAxes?.some(axis => axis.id === axisId);
|
|
29
30
|
const drawingArea = createPreviewDrawingArea(hasAxis ? 'x' : 'y', chartDrawingArea);
|
|
30
31
|
const options = zoomOptions[axisId];
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
axis: xAxes,
|
|
40
|
-
seriesConfig,
|
|
41
|
-
zoomMap,
|
|
42
|
-
preferStrictDomainInLineCharts,
|
|
43
|
-
defaultTickNumber
|
|
32
|
+
const scales = {};
|
|
33
|
+
xAxes?.forEach(eachAxis => {
|
|
34
|
+
const axis = eachAxis;
|
|
35
|
+
const scale = normalizedXScales[axis.id].copy();
|
|
36
|
+
const range = getRange(drawingArea, 'x', axis);
|
|
37
|
+
const zoomedRange = zoomScaleRange(range, [options.minStart, options.maxEnd]);
|
|
38
|
+
scale.range(zoomedRange);
|
|
39
|
+
scales[axis.id] = scale;
|
|
44
40
|
});
|
|
41
|
+
return scales;
|
|
45
42
|
});
|
|
46
|
-
export const selectorChartPreviewComputedXAxis = createSelector([selectorChartRawXAxis, selectorChartSeriesProcessed, selectorChartSeriesConfig, selectorChartZoomOptionsLookup,
|
|
43
|
+
export const selectorChartPreviewComputedXAxis = createSelector([selectorChartRawXAxis, selectorChartSeriesProcessed, selectorChartSeriesConfig, selectorChartZoomOptionsLookup, selectorChartDrawingArea, selectorChartPreviewXScales, selectorChartXDomains, (_, axisId) => axisId], (xAxes, formattedSeries, seriesConfig, zoomOptions, chartDrawingArea, scales, domains, axisId) => {
|
|
47
44
|
const hasAxis = xAxes?.some(axis => axis.id === axisId);
|
|
48
45
|
const drawingArea = createPreviewDrawingArea(hasAxis ? 'x' : 'y', chartDrawingArea);
|
|
49
46
|
const options = zoomOptions[axisId];
|
|
@@ -60,9 +57,7 @@ export const selectorChartPreviewComputedXAxis = createSelector([selectorChartRa
|
|
|
60
57
|
seriesConfig,
|
|
61
58
|
axisDirection: 'x',
|
|
62
59
|
zoomMap,
|
|
63
|
-
|
|
64
|
-
getFilters,
|
|
65
|
-
preferStrictDomainInLineCharts
|
|
60
|
+
domains
|
|
66
61
|
});
|
|
67
62
|
if (computedAxes.axis[axisId]) {
|
|
68
63
|
return {
|
|
@@ -71,26 +66,25 @@ export const selectorChartPreviewComputedXAxis = createSelector([selectorChartRa
|
|
|
71
66
|
}
|
|
72
67
|
return computedAxes.axis;
|
|
73
68
|
});
|
|
74
|
-
export const selectorChartPreviewYScales = createSelector([selectorChartRawYAxis, selectorChartDrawingArea,
|
|
69
|
+
export const selectorChartPreviewYScales = createSelector([selectorChartRawYAxis, selectorChartDrawingArea, selectorChartZoomOptionsLookup, selectorChartNormalizedYScales, (_, axisId) => axisId], function selectorChartPreviewYScales(yAxes, chartDrawingArea, zoomOptions, normalizedYScales, axisId) {
|
|
75
70
|
const hasAxis = yAxes?.some(axis => axis.id === axisId);
|
|
76
71
|
const drawingArea = createPreviewDrawingArea(hasAxis ? 'y' : 'x', chartDrawingArea);
|
|
77
72
|
const options = zoomOptions[axisId];
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
preferStrictDomainInLineCharts,
|
|
90
|
-
defaultTickNumber
|
|
73
|
+
const scales = {};
|
|
74
|
+
yAxes?.forEach(eachAxis => {
|
|
75
|
+
const axis = eachAxis;
|
|
76
|
+
const scale = normalizedYScales[axis.id].copy();
|
|
77
|
+
let range = getRange(drawingArea, 'y', axis);
|
|
78
|
+
if (isOrdinalScale(scale)) {
|
|
79
|
+
range = range.reverse();
|
|
80
|
+
}
|
|
81
|
+
const zoomedRange = zoomScaleRange(range, [options.minStart, options.maxEnd]);
|
|
82
|
+
scale.range(zoomedRange);
|
|
83
|
+
scales[axis.id] = scale;
|
|
91
84
|
});
|
|
85
|
+
return scales;
|
|
92
86
|
});
|
|
93
|
-
export const selectorChartPreviewComputedYAxis = createSelector([selectorChartRawYAxis, selectorChartSeriesProcessed, selectorChartSeriesConfig, selectorChartZoomOptionsLookup,
|
|
87
|
+
export const selectorChartPreviewComputedYAxis = createSelector([selectorChartRawYAxis, selectorChartSeriesProcessed, selectorChartSeriesConfig, selectorChartZoomOptionsLookup, selectorChartDrawingArea, selectorChartPreviewYScales, selectorChartYDomains, (_, axisId) => axisId], (yAxes, formattedSeries, seriesConfig, zoomOptions, chartDrawingArea, scales, domains, axisId) => {
|
|
94
88
|
const hasAxis = yAxes?.some(axis => axis.id === axisId);
|
|
95
89
|
const drawingArea = createPreviewDrawingArea(hasAxis ? 'y' : 'x', chartDrawingArea);
|
|
96
90
|
const options = zoomOptions[axisId];
|
|
@@ -107,9 +101,7 @@ export const selectorChartPreviewComputedYAxis = createSelector([selectorChartRa
|
|
|
107
101
|
seriesConfig,
|
|
108
102
|
axisDirection: 'y',
|
|
109
103
|
zoomMap,
|
|
110
|
-
|
|
111
|
-
getFilters,
|
|
112
|
-
preferStrictDomainInLineCharts
|
|
104
|
+
domains
|
|
113
105
|
});
|
|
114
106
|
if (computedAxes.axis[axisId]) {
|
|
115
107
|
return {
|