@mui/x-charts 8.0.0-alpha.10 → 8.0.0-alpha.11
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.d.ts +1 -2
- package/BarChart/BarChart.js +2 -4
- package/BarChart/BarChart.plugins.d.ts +12 -0
- package/BarChart/BarChart.plugins.js +5 -0
- package/BarChart/useBarChartProps.d.ts +2 -3
- package/BarChart/useBarChartProps.js +5 -8
- package/CHANGELOG.md +107 -2
- package/ChartContainer/ChartContainer.d.ts +2 -2
- package/ChartContainer/ChartContainer.js +8 -1
- package/ChartContainer/useChartContainerProps.d.ts +4 -3
- package/ChartContainer/useChartContainerProps.js +11 -7
- package/ChartDataProvider/ChartDataProvider.js +4 -1
- package/ChartsSurface/ChartsSurface.d.ts +0 -6
- package/ChartsSurface/ChartsSurface.js +1 -10
- package/ChartsTooltip/ChartsTooltipContainer.js +2 -2
- package/Gauge/Gauge.js +0 -6
- package/Gauge/GaugeContainer.js +0 -6
- package/LineChart/LineChart.d.ts +1 -2
- package/LineChart/LineChart.js +2 -4
- package/LineChart/LineChart.plugins.d.ts +12 -0
- package/LineChart/LineChart.plugins.js +5 -0
- package/LineChart/useLineChartProps.d.ts +2 -3
- package/LineChart/useLineChartProps.js +5 -8
- package/PieChart/PieChart.d.ts +3 -1
- package/PieChart/PieChart.js +8 -115
- package/PieChart/PieChart.plugins.d.ts +5 -0
- package/PieChart/PieChart.plugins.js +3 -0
- package/ScatterChart/ScatterChart.js +8 -1
- package/ScatterChart/ScatterChart.plugins.d.ts +12 -0
- package/ScatterChart/ScatterChart.plugins.js +5 -0
- package/ScatterChart/useScatterChartProps.d.ts +2 -1
- package/ScatterChart/useScatterChartProps.js +3 -1
- package/SparkLineChart/SparkLineChart.d.ts +12 -0
- package/SparkLineChart/SparkLineChart.js +24 -4
- package/colorPalettes/colorPalettes.d.ts +2 -0
- package/context/ChartProvider/ChartProvider.types.d.ts +2 -1
- package/hooks/useAxisEvents.d.ts +0 -1
- package/hooks/useAxisEvents.js +0 -165
- package/index.d.ts +0 -1
- package/index.js +1 -2
- package/internals/plugins/allPlugins.d.ts +1 -1
- package/internals/plugins/corePlugins/useChartSeries/useChartSeries.types.d.ts +5 -2
- package/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisValue.d.ts +9 -0
- package/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisValue.js +59 -0
- package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxis.d.ts +1 -2
- package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxis.js +142 -5
- package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxis.types.d.ts +19 -2
- package/models/axis.d.ts +17 -0
- package/models/axis.js +5 -1
- package/models/index.d.ts +1 -1
- package/modern/BarChart/BarChart.js +2 -4
- package/modern/BarChart/BarChart.plugins.js +5 -0
- package/modern/BarChart/useBarChartProps.js +5 -8
- package/modern/ChartContainer/ChartContainer.js +8 -1
- package/modern/ChartContainer/useChartContainerProps.js +11 -7
- package/modern/ChartDataProvider/ChartDataProvider.js +4 -1
- package/modern/ChartsSurface/ChartsSurface.js +1 -10
- package/modern/ChartsTooltip/ChartsTooltipContainer.js +2 -2
- package/modern/Gauge/Gauge.js +0 -6
- package/modern/Gauge/GaugeContainer.js +0 -6
- package/modern/LineChart/LineChart.js +2 -4
- package/modern/LineChart/LineChart.plugins.js +5 -0
- package/modern/LineChart/useLineChartProps.js +5 -8
- package/modern/PieChart/PieChart.js +8 -115
- package/modern/PieChart/PieChart.plugins.js +3 -0
- package/modern/ScatterChart/ScatterChart.js +8 -1
- package/modern/ScatterChart/ScatterChart.plugins.js +5 -0
- package/modern/ScatterChart/useScatterChartProps.js +3 -1
- package/modern/SparkLineChart/SparkLineChart.js +24 -4
- package/modern/hooks/useAxisEvents.js +0 -165
- package/modern/index.js +1 -2
- package/modern/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisValue.js +59 -0
- package/modern/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxis.js +142 -5
- package/modern/models/axis.js +5 -1
- package/node/BarChart/BarChart.js +2 -4
- package/node/BarChart/BarChart.plugins.js +11 -0
- package/node/BarChart/useBarChartProps.js +5 -8
- package/node/ChartContainer/ChartContainer.js +8 -1
- package/node/ChartContainer/useChartContainerProps.js +11 -7
- package/node/ChartDataProvider/ChartDataProvider.js +4 -1
- package/node/ChartsSurface/ChartsSurface.js +1 -10
- package/node/ChartsTooltip/ChartsTooltipContainer.js +2 -2
- package/node/Gauge/Gauge.js +0 -6
- package/node/Gauge/GaugeContainer.js +0 -6
- package/node/LineChart/LineChart.js +2 -4
- package/node/LineChart/LineChart.plugins.js +11 -0
- package/node/LineChart/useLineChartProps.js +5 -8
- package/node/PieChart/PieChart.js +8 -115
- package/node/PieChart/PieChart.plugins.js +9 -0
- package/node/ScatterChart/ScatterChart.js +8 -1
- package/node/ScatterChart/ScatterChart.plugins.js +11 -0
- package/node/ScatterChart/useScatterChartProps.js +3 -1
- package/node/SparkLineChart/SparkLineChart.js +24 -4
- package/node/hooks/useAxisEvents.js +1 -173
- package/node/index.js +1 -12
- package/node/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisValue.js +65 -0
- package/node/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxis.js +141 -4
- package/node/models/axis.js +5 -1
- package/package.json +2 -2
- package/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.d.ts +0 -20
- package/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +0 -82
- package/ChartsOnAxisClickHandler/index.d.ts +0 -1
- package/ChartsOnAxisClickHandler/index.js +0 -1
- package/ChartsOnAxisClickHandler/package.json +0 -6
- package/modern/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +0 -82
- package/modern/ChartsOnAxisClickHandler/index.js +0 -1
- package/node/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +0 -88
- package/node/ChartsOnAxisClickHandler/index.js +0 -16
|
@@ -4,6 +4,9 @@ import { ChartPluginSignature, ChartSeriesConfig } from '../../models';
|
|
|
4
4
|
import { ChartSeriesType, DatasetType } from '../../../../models/seriesType/config';
|
|
5
5
|
import { SeriesProcessorResult } from '../../models/seriesConfig/seriesProcessor.types';
|
|
6
6
|
export interface UseChartSeriesParameters<T extends ChartSeriesType = ChartSeriesType> {
|
|
7
|
+
/**
|
|
8
|
+
* An array of objects that can be used to populate series and axes data using their `dataKey` property.
|
|
9
|
+
*/
|
|
7
10
|
dataset?: DatasetType;
|
|
8
11
|
/**
|
|
9
12
|
* The array of series to display.
|
|
@@ -13,7 +16,7 @@ export interface UseChartSeriesParameters<T extends ChartSeriesType = ChartSerie
|
|
|
13
16
|
series?: AllSeriesType<T>[];
|
|
14
17
|
/**
|
|
15
18
|
* Color palette used to colorize multiple series.
|
|
16
|
-
* @default
|
|
19
|
+
* @default rainbowSurgePalette
|
|
17
20
|
*/
|
|
18
21
|
colors?: ChartsColorPalette;
|
|
19
22
|
theme?: 'light' | 'dark';
|
|
@@ -27,7 +30,7 @@ export type UseChartSeriesDefaultizedParameters<T extends ChartSeriesType = Char
|
|
|
27
30
|
series: AllSeriesType<T>[];
|
|
28
31
|
/**
|
|
29
32
|
* Color palette used to colorize multiple series.
|
|
30
|
-
* @default
|
|
33
|
+
* @default rainbowSurgePalette
|
|
31
34
|
*/
|
|
32
35
|
colors: ChartsColorPalette;
|
|
33
36
|
theme: 'light' | 'dark';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AxisDefaultized } from '../../../../models/axis';
|
|
2
|
+
/**
|
|
3
|
+
* For a pointer coordinate, this function returns the value and dataIndex associated.
|
|
4
|
+
* Returns `null` if the coordinate is outside of values.
|
|
5
|
+
*/
|
|
6
|
+
export declare function getAxisValue(axisConfig: AxisDefaultized, pointerValue: number): {
|
|
7
|
+
value: any;
|
|
8
|
+
index: number;
|
|
9
|
+
} | null;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { isBandScale } from "../../../isBandScale.js";
|
|
2
|
+
function getAsANumber(value) {
|
|
3
|
+
return value instanceof Date ? value.getTime() : value;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* For a pointer coordinate, this function returns the value and dataIndex associated.
|
|
8
|
+
* Returns `null` if the coordinate is outside of values.
|
|
9
|
+
*/
|
|
10
|
+
export function getAxisValue(axisConfig, pointerValue) {
|
|
11
|
+
const {
|
|
12
|
+
scale,
|
|
13
|
+
data: axisData,
|
|
14
|
+
reverse
|
|
15
|
+
} = axisConfig;
|
|
16
|
+
if (!isBandScale(scale)) {
|
|
17
|
+
const value = scale.invert(pointerValue);
|
|
18
|
+
if (axisData === undefined) {
|
|
19
|
+
return {
|
|
20
|
+
value,
|
|
21
|
+
index: -1
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
const valueAsNumber = getAsANumber(value);
|
|
25
|
+
const closestIndex = axisData?.findIndex((pointValue, index) => {
|
|
26
|
+
const v = getAsANumber(pointValue);
|
|
27
|
+
if (v > valueAsNumber) {
|
|
28
|
+
if (index === 0 || Math.abs(valueAsNumber - v) <= Math.abs(valueAsNumber - getAsANumber(axisData[index - 1]))) {
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (v <= valueAsNumber) {
|
|
33
|
+
if (index === axisData.length - 1 || Math.abs(getAsANumber(value) - v) < Math.abs(getAsANumber(value) - getAsANumber(axisData[index + 1]))) {
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return false;
|
|
38
|
+
});
|
|
39
|
+
return {
|
|
40
|
+
value: closestIndex !== undefined && closestIndex >= 0 ? axisData[closestIndex] : value,
|
|
41
|
+
index: closestIndex
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
const dataIndex = scale.bandwidth() === 0 ? Math.floor((pointerValue - Math.min(...scale.range()) + scale.step() / 2) / scale.step()) : Math.floor((pointerValue - Math.min(...scale.range())) / scale.step());
|
|
45
|
+
if (dataIndex < 0 || dataIndex >= axisData.length) {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
if (reverse) {
|
|
49
|
+
const reverseIndex = axisData.length - 1 - dataIndex;
|
|
50
|
+
return {
|
|
51
|
+
index: reverseIndex,
|
|
52
|
+
value: axisData[reverseIndex]
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
index: dataIndex,
|
|
57
|
+
value: axisData[dataIndex]
|
|
58
|
+
};
|
|
59
|
+
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import { ChartPlugin } from '../../models';
|
|
2
|
-
import { ChartSeriesType } from '../../../../models/seriesType/config';
|
|
3
2
|
import { UseChartCartesianAxisSignature } from './useChartCartesianAxis.types';
|
|
4
|
-
export declare const useChartCartesianAxis: ChartPlugin<UseChartCartesianAxisSignature<
|
|
3
|
+
export declare const useChartCartesianAxis: ChartPlugin<UseChartCartesianAxisSignature<any>>;
|
|
@@ -6,12 +6,18 @@ import { warnOnce } from '@mui/x-internals/warning';
|
|
|
6
6
|
import { rainbowSurgePalette } from "../../../../colorPalettes/index.js";
|
|
7
7
|
import { useSelector } from "../../../store/useSelector.js";
|
|
8
8
|
import { selectorChartDrawingArea } from "../../corePlugins/useChartDimensions/useChartDimensions.selectors.js";
|
|
9
|
-
import {
|
|
9
|
+
import { selectorChartSeriesProcessed } from "../../corePlugins/useChartSeries/useChartSeries.selectors.js";
|
|
10
10
|
import { defaultizeAxis } from "./defaultizeAxis.js";
|
|
11
|
+
import { selectorChartXAxis, selectorChartYAxis } from "./useChartCartesianAxis.selectors.js";
|
|
12
|
+
import { getAxisValue } from "./getAxisValue.js";
|
|
13
|
+
import { getSVGPoint } from "../../../getSVGPoint.js";
|
|
14
|
+
import { selectorChartsInteractionAxis } from "../useChartInteraction/index.js";
|
|
11
15
|
export const useChartCartesianAxis = ({
|
|
12
16
|
params,
|
|
13
17
|
store,
|
|
14
|
-
seriesConfig
|
|
18
|
+
seriesConfig,
|
|
19
|
+
svgRef,
|
|
20
|
+
instance
|
|
15
21
|
}) => {
|
|
16
22
|
const {
|
|
17
23
|
xAxis,
|
|
@@ -26,7 +32,16 @@ export const useChartCartesianAxis = ({
|
|
|
26
32
|
}
|
|
27
33
|
}
|
|
28
34
|
const drawingArea = useSelector(store, selectorChartDrawingArea);
|
|
29
|
-
const
|
|
35
|
+
const processedSeries = useSelector(store, selectorChartSeriesProcessed);
|
|
36
|
+
const interactionAxis = useSelector(store, selectorChartsInteractionAxis);
|
|
37
|
+
const {
|
|
38
|
+
axis: xAxisWithScale,
|
|
39
|
+
axisIds: xAxisIds
|
|
40
|
+
} = useSelector(store, selectorChartXAxis);
|
|
41
|
+
const {
|
|
42
|
+
axis: yAxisWithScale,
|
|
43
|
+
axisIds: yAxisIds
|
|
44
|
+
} = useSelector(store, selectorChartYAxis);
|
|
30
45
|
|
|
31
46
|
// The effect do not track any value defined synchronously during the 1st render by hooks called after `useChartCartesianAxis`
|
|
32
47
|
// As a consequence, the state generated by the 1st run of this useEffect will always be equal to the initialization one
|
|
@@ -42,13 +57,135 @@ export const useChartCartesianAxis = ({
|
|
|
42
57
|
y: defaultizeAxis(yAxis, dataset, 'y')
|
|
43
58
|
})
|
|
44
59
|
}));
|
|
45
|
-
}, [seriesConfig, drawingArea,
|
|
60
|
+
}, [seriesConfig, drawingArea, xAxis, yAxis, dataset, store]);
|
|
61
|
+
const usedXAxis = xAxisIds[0];
|
|
62
|
+
const usedYAxis = yAxisIds[0];
|
|
63
|
+
|
|
64
|
+
// Use a ref to avoid rerendering on every mousemove event.
|
|
65
|
+
const mousePosition = React.useRef({
|
|
66
|
+
isInChart: false,
|
|
67
|
+
x: -1,
|
|
68
|
+
y: -1
|
|
69
|
+
});
|
|
70
|
+
React.useEffect(() => {
|
|
71
|
+
const element = svgRef.current;
|
|
72
|
+
if (element === null || params.disableAxisListener) {
|
|
73
|
+
return () => {};
|
|
74
|
+
}
|
|
75
|
+
const handleOut = () => {
|
|
76
|
+
mousePosition.current = {
|
|
77
|
+
isInChart: false,
|
|
78
|
+
x: -1,
|
|
79
|
+
y: -1
|
|
80
|
+
};
|
|
81
|
+
instance.cleanInteraction();
|
|
82
|
+
};
|
|
83
|
+
const handleMove = event => {
|
|
84
|
+
const target = 'targetTouches' in event ? event.targetTouches[0] : event;
|
|
85
|
+
const svgPoint = getSVGPoint(element, target);
|
|
86
|
+
mousePosition.current.x = svgPoint.x;
|
|
87
|
+
mousePosition.current.y = svgPoint.y;
|
|
88
|
+
if (!instance.isPointInside(svgPoint, {
|
|
89
|
+
targetElement: event.target
|
|
90
|
+
})) {
|
|
91
|
+
if (mousePosition.current.isInChart) {
|
|
92
|
+
store.update(prev => _extends({}, prev, {
|
|
93
|
+
interaction: {
|
|
94
|
+
item: null,
|
|
95
|
+
axis: {
|
|
96
|
+
x: null,
|
|
97
|
+
y: null
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}));
|
|
101
|
+
mousePosition.current.isInChart = false;
|
|
102
|
+
}
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
mousePosition.current.isInChart = true;
|
|
106
|
+
instance.setAxisInteraction({
|
|
107
|
+
x: getAxisValue(xAxisWithScale[usedXAxis], svgPoint.x),
|
|
108
|
+
y: getAxisValue(yAxisWithScale[usedYAxis], svgPoint.y)
|
|
109
|
+
});
|
|
110
|
+
};
|
|
111
|
+
const handleDown = event => {
|
|
112
|
+
const target = event.currentTarget;
|
|
113
|
+
if (!target) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
if (target.hasPointerCapture(event.pointerId)) {
|
|
117
|
+
target.releasePointerCapture(event.pointerId);
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
element.addEventListener('pointerdown', handleDown);
|
|
121
|
+
element.addEventListener('pointermove', handleMove);
|
|
122
|
+
element.addEventListener('pointerout', handleOut);
|
|
123
|
+
element.addEventListener('pointercancel', handleOut);
|
|
124
|
+
element.addEventListener('pointerleave', handleOut);
|
|
125
|
+
return () => {
|
|
126
|
+
element.removeEventListener('pointerdown', handleDown);
|
|
127
|
+
element.removeEventListener('pointermove', handleMove);
|
|
128
|
+
element.removeEventListener('pointerout', handleOut);
|
|
129
|
+
element.removeEventListener('pointercancel', handleOut);
|
|
130
|
+
element.removeEventListener('pointerleave', handleOut);
|
|
131
|
+
};
|
|
132
|
+
}, [svgRef, store, xAxisWithScale, usedXAxis, yAxisWithScale, usedYAxis, instance, params.disableAxisListener]);
|
|
133
|
+
React.useEffect(() => {
|
|
134
|
+
const element = svgRef.current;
|
|
135
|
+
if (element === null || !params.onAxisClick) {
|
|
136
|
+
return () => {};
|
|
137
|
+
}
|
|
138
|
+
const handleMouseClick = event => {
|
|
139
|
+
event.preventDefault();
|
|
140
|
+
let dataIndex = null;
|
|
141
|
+
let isXaxis = false;
|
|
142
|
+
if (interactionAxis.x === null && interactionAxis.y === null) {
|
|
143
|
+
const svgPoint = getSVGPoint(element, event);
|
|
144
|
+
const xIndex = getAxisValue(xAxisWithScale[usedXAxis], svgPoint.x)?.index ?? null;
|
|
145
|
+
isXaxis = xIndex !== null && xIndex !== -1;
|
|
146
|
+
dataIndex = isXaxis ? xIndex : getAxisValue(yAxisWithScale[usedYAxis], svgPoint.y)?.index ?? null;
|
|
147
|
+
} else {
|
|
148
|
+
isXaxis = interactionAxis.x !== null && interactionAxis.x.index !== -1;
|
|
149
|
+
dataIndex = isXaxis ? interactionAxis.x && interactionAxis.x.index : interactionAxis.y && interactionAxis.y.index;
|
|
150
|
+
}
|
|
151
|
+
const USED_AXIS_ID = isXaxis ? xAxisIds[0] : yAxisIds[0];
|
|
152
|
+
if (dataIndex == null || dataIndex === -1) {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// The .data exist because otherwise the dataIndex would be null or -1.
|
|
157
|
+
const axisValue = (isXaxis ? xAxisWithScale : yAxisWithScale)[USED_AXIS_ID].data[dataIndex];
|
|
158
|
+
const seriesValues = {};
|
|
159
|
+
Object.keys(processedSeries).filter(seriesType => ['bar', 'line'].includes(seriesType)).forEach(seriesType => {
|
|
160
|
+
processedSeries[seriesType]?.seriesOrder.forEach(seriesId => {
|
|
161
|
+
const seriesItem = processedSeries[seriesType].series[seriesId];
|
|
162
|
+
const providedXAxisId = seriesItem.xAxisId;
|
|
163
|
+
const providedYAxisId = seriesItem.yAxisId;
|
|
164
|
+
const axisKey = isXaxis ? providedXAxisId : providedYAxisId;
|
|
165
|
+
if (axisKey === undefined || axisKey === USED_AXIS_ID) {
|
|
166
|
+
seriesValues[seriesId] = seriesItem.data[dataIndex];
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
params.onAxisClick?.(event, {
|
|
171
|
+
dataIndex,
|
|
172
|
+
axisValue,
|
|
173
|
+
seriesValues
|
|
174
|
+
});
|
|
175
|
+
};
|
|
176
|
+
element.addEventListener('click', handleMouseClick);
|
|
177
|
+
return () => {
|
|
178
|
+
element.removeEventListener('click', handleMouseClick);
|
|
179
|
+
};
|
|
180
|
+
}, [params.onAxisClick, processedSeries, svgRef, xAxisWithScale, xAxisIds, yAxisWithScale, yAxisIds, params, interactionAxis, usedXAxis, usedYAxis]);
|
|
46
181
|
return {};
|
|
47
182
|
};
|
|
48
183
|
useChartCartesianAxis.params = {
|
|
49
184
|
xAxis: true,
|
|
50
185
|
yAxis: true,
|
|
51
|
-
dataset: true
|
|
186
|
+
dataset: true,
|
|
187
|
+
onAxisClick: true,
|
|
188
|
+
disableAxisListener: true
|
|
52
189
|
};
|
|
53
190
|
useChartCartesianAxis.getDefaultizedParams = ({
|
|
54
191
|
params
|
package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxis.types.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { MakeOptional } from '@mui/x-internals/types';
|
|
2
2
|
import { ChartPluginSignature } from '../../models';
|
|
3
3
|
import { ChartSeriesType, DatasetType } from '../../../../models/seriesType/config';
|
|
4
|
-
import { AxisDefaultized, ScaleName, ChartsXAxisProps, ChartsYAxisProps, AxisId, AxisConfig } from '../../../../models/axis';
|
|
4
|
+
import { AxisDefaultized, ScaleName, ChartsXAxisProps, ChartsYAxisProps, AxisId, AxisConfig, ChartsAxisData } from '../../../../models/axis';
|
|
5
5
|
import { UseChartSeriesSignature } from '../../corePlugins/useChartSeries';
|
|
6
6
|
import { ZoomData, ZoomOptions } from './zoom.types';
|
|
7
|
+
import { UseChartInteractionSignature } from '../useChartInteraction';
|
|
7
8
|
export type DefaultizedAxisConfig<AxisProps> = {
|
|
8
9
|
[axisId: AxisId]: AxisDefaultized<ScaleName, any, AxisProps>;
|
|
9
10
|
};
|
|
@@ -38,7 +39,23 @@ export interface UseChartCartesianAxisParameters {
|
|
|
38
39
|
* An array of [[AxisConfig]] objects.
|
|
39
40
|
*/
|
|
40
41
|
yAxis?: MakeOptional<AxisConfig<ScaleName, any, ChartsYAxisProps>, 'id'>[];
|
|
42
|
+
/**
|
|
43
|
+
* An array of objects that can be used to populate series and axes data using their `dataKey` property.
|
|
44
|
+
*/
|
|
41
45
|
dataset?: DatasetType;
|
|
46
|
+
/**
|
|
47
|
+
* The function called for onClick events.
|
|
48
|
+
* The second argument contains information about all line/bar elements at the current mouse position.
|
|
49
|
+
* @param {MouseEvent} event The mouse event recorded on the `<svg/>` element.
|
|
50
|
+
* @param {null | AxisData} data The data about the clicked axis and items associated with it.
|
|
51
|
+
*/
|
|
52
|
+
onAxisClick?: (event: MouseEvent, data: null | ChartsAxisData) => void;
|
|
53
|
+
/**
|
|
54
|
+
* If `true`, the charts will not listen to the mouse move event.
|
|
55
|
+
* It might break interactive features, but will improve performance.
|
|
56
|
+
* @default false
|
|
57
|
+
*/
|
|
58
|
+
disableAxisListener?: boolean;
|
|
42
59
|
}
|
|
43
60
|
export type UseChartCartesianAxisDefaultizedParameters = UseChartCartesianAxisParameters & {
|
|
44
61
|
defaultizedXAxis: AxisConfig<ScaleName, any, ChartsXAxisProps>[];
|
|
@@ -71,5 +88,5 @@ export type UseChartCartesianAxisSignature<SeriesType extends ChartSeriesType =
|
|
|
71
88
|
params: UseChartCartesianAxisParameters;
|
|
72
89
|
defaultizedParams: UseChartCartesianAxisDefaultizedParameters;
|
|
73
90
|
state: UseChartCartesianAxisState;
|
|
74
|
-
dependencies: [UseChartSeriesSignature<SeriesType>];
|
|
91
|
+
dependencies: [UseChartInteractionSignature, UseChartSeriesSignature<SeriesType>];
|
|
75
92
|
}>;
|
package/models/axis.d.ts
CHANGED
|
@@ -293,3 +293,20 @@ export declare function isBandScaleConfig(scaleConfig: AxisConfig<ScaleName>): s
|
|
|
293
293
|
export declare function isPointScaleConfig(scaleConfig: AxisConfig<ScaleName>): scaleConfig is AxisConfig<'point'> & {
|
|
294
294
|
scaleType: 'point';
|
|
295
295
|
};
|
|
296
|
+
/**
|
|
297
|
+
* The data format returned by onAxisClick.
|
|
298
|
+
*/
|
|
299
|
+
export interface ChartsAxisData {
|
|
300
|
+
/**
|
|
301
|
+
* The index in the axis' data property.
|
|
302
|
+
*/
|
|
303
|
+
dataIndex: number;
|
|
304
|
+
/**
|
|
305
|
+
* Tha value associated to the axis item.
|
|
306
|
+
*/
|
|
307
|
+
axisValue: number | Date | string;
|
|
308
|
+
/**
|
|
309
|
+
* The mapping of series ids to their value for this particular axis index.
|
|
310
|
+
*/
|
|
311
|
+
seriesValues: Record<string, number | null | undefined>;
|
|
312
|
+
}
|
package/models/axis.js
CHANGED
package/models/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export * from './seriesType';
|
|
2
2
|
export * from './layout';
|
|
3
3
|
export * from './stacking';
|
|
4
|
-
export type { AxisConfig, ChartsYAxisProps, ChartsXAxisProps, ScaleName, ContinuousScaleName, } from './axis';
|
|
4
|
+
export type { AxisConfig, ChartsYAxisProps, ChartsXAxisProps, ScaleName, ContinuousScaleName, ChartsAxisData, } from './axis';
|
|
5
5
|
export type { PropsFromSlot } from '@mui/x-internals/slots';
|
|
6
6
|
export type { Position } from './position';
|
|
7
7
|
export type { CurveType } from './curve';
|
|
@@ -11,7 +11,6 @@ import { ChartsLegend } from "../ChartsLegend/index.js";
|
|
|
11
11
|
import { ChartsAxisHighlight } from "../ChartsAxisHighlight/index.js";
|
|
12
12
|
import { ChartsClipPath } from "../ChartsClipPath/index.js";
|
|
13
13
|
import { ChartsGrid } from "../ChartsGrid/index.js";
|
|
14
|
-
import { ChartsOnAxisClickHandler } from "../ChartsOnAxisClickHandler/index.js";
|
|
15
14
|
import { ChartsOverlay } from "../ChartsOverlay/ChartsOverlay.js";
|
|
16
15
|
import { useBarChartProps } from "./useBarChartProps.js";
|
|
17
16
|
import { ChartDataProvider } from "../ChartDataProvider/index.js";
|
|
@@ -39,7 +38,6 @@ const BarChart = /*#__PURE__*/React.forwardRef(function BarChart(inProps, ref) {
|
|
|
39
38
|
chartsWrapperProps,
|
|
40
39
|
chartContainerProps,
|
|
41
40
|
barPlotProps,
|
|
42
|
-
axisClickHandlerProps,
|
|
43
41
|
gridProps,
|
|
44
42
|
clipPathProps,
|
|
45
43
|
clipPathGroupProps,
|
|
@@ -57,7 +55,7 @@ const BarChart = /*#__PURE__*/React.forwardRef(function BarChart(inProps, ref) {
|
|
|
57
55
|
return /*#__PURE__*/_jsx(ChartDataProvider, _extends({}, chartDataProviderProps, {
|
|
58
56
|
children: /*#__PURE__*/_jsxs(ChartsWrapper, _extends({}, chartsWrapperProps, {
|
|
59
57
|
children: [!props.hideLegend && /*#__PURE__*/_jsx(ChartsLegend, _extends({}, legendProps)), /*#__PURE__*/_jsxs(ChartsSurface, _extends({}, chartsSurfaceProps, {
|
|
60
|
-
children: [
|
|
58
|
+
children: [/*#__PURE__*/_jsx(ChartsGrid, _extends({}, gridProps)), /*#__PURE__*/_jsxs("g", _extends({}, clipPathGroupProps, {
|
|
61
59
|
children: [/*#__PURE__*/_jsx(BarPlot, _extends({}, barPlotProps)), /*#__PURE__*/_jsx(ChartsOverlay, _extends({}, overlayProps)), /*#__PURE__*/_jsx(ChartsAxisHighlight, _extends({}, axisHighlightProps))]
|
|
62
60
|
})), /*#__PURE__*/_jsx(ChartsAxis, _extends({}, chartsAxisProps)), !props.loading && /*#__PURE__*/_jsx(Tooltip, _extends({}, props.slotProps?.tooltip)), /*#__PURE__*/_jsx(ChartsClipPath, _extends({}, clipPathProps)), children]
|
|
63
61
|
}))]
|
|
@@ -104,7 +102,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
104
102
|
className: PropTypes.string,
|
|
105
103
|
/**
|
|
106
104
|
* Color palette used to colorize multiple series.
|
|
107
|
-
* @default
|
|
105
|
+
* @default rainbowSurgePalette
|
|
108
106
|
*/
|
|
109
107
|
colors: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string), PropTypes.func]),
|
|
110
108
|
/**
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { useChartZAxis } from "../internals/plugins/featurePlugins/useChartZAxis/index.js";
|
|
2
|
+
import { useChartCartesianAxis } from "../internals/plugins/featurePlugins/useChartCartesianAxis/index.js";
|
|
3
|
+
import { useChartInteraction } from "../internals/plugins/featurePlugins/useChartInteraction/index.js";
|
|
4
|
+
import { useChartHighlight } from "../internals/plugins/featurePlugins/useChartHighlight/index.js";
|
|
5
|
+
export const BAR_CHART_PLUGINS = [useChartZAxis, useChartCartesianAxis, useChartInteraction, useChartHighlight];
|
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
4
4
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
5
|
-
const _excluded = ["xAxis", "yAxis", "series", "width", "height", "margin", "colors", "dataset", "sx", "
|
|
5
|
+
const _excluded = ["xAxis", "yAxis", "series", "width", "height", "margin", "colors", "dataset", "sx", "axisHighlight", "grid", "topAxis", "leftAxis", "rightAxis", "bottomAxis", "children", "slots", "slotProps", "skipAnimation", "loading", "layout", "onItemClick", "highlightedItem", "onHighlightChange", "borderRadius", "barLabel", "className", "hideLegend"];
|
|
6
6
|
import useId from '@mui/utils/useId';
|
|
7
7
|
import { DEFAULT_X_AXIS_KEY, DEFAULT_Y_AXIS_KEY } from "../constants/index.js";
|
|
8
8
|
import { calculateMargins } from "../internals/calculateMargins.js";
|
|
9
|
+
import { BAR_CHART_PLUGINS } from "./BarChart.plugins.js";
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* A helper function that extracts BarChartProps from the input props
|
|
@@ -25,7 +26,6 @@ export const useBarChartProps = props => {
|
|
|
25
26
|
colors,
|
|
26
27
|
dataset,
|
|
27
28
|
sx,
|
|
28
|
-
onAxisClick,
|
|
29
29
|
axisHighlight,
|
|
30
30
|
grid,
|
|
31
31
|
topAxis,
|
|
@@ -80,9 +80,10 @@ export const useBarChartProps = props => {
|
|
|
80
80
|
}, defaultAxisConfig)] : undefined),
|
|
81
81
|
highlightedItem,
|
|
82
82
|
onHighlightChange,
|
|
83
|
-
disableAxisListener: slotProps?.tooltip?.trigger !== 'axis' && axisHighlight?.x === 'none' && axisHighlight?.y === 'none'
|
|
83
|
+
disableAxisListener: slotProps?.tooltip?.trigger !== 'axis' && axisHighlight?.x === 'none' && axisHighlight?.y === 'none',
|
|
84
84
|
className,
|
|
85
|
-
skipAnimation
|
|
85
|
+
skipAnimation,
|
|
86
|
+
plugins: BAR_CHART_PLUGINS
|
|
86
87
|
});
|
|
87
88
|
const barPlotProps = {
|
|
88
89
|
onItemClick,
|
|
@@ -91,9 +92,6 @@ export const useBarChartProps = props => {
|
|
|
91
92
|
borderRadius,
|
|
92
93
|
barLabel
|
|
93
94
|
};
|
|
94
|
-
const axisClickHandlerProps = {
|
|
95
|
-
onAxisClick
|
|
96
|
-
};
|
|
97
95
|
const gridProps = {
|
|
98
96
|
vertical: grid?.vertical,
|
|
99
97
|
horizontal: grid?.horizontal
|
|
@@ -135,7 +133,6 @@ export const useBarChartProps = props => {
|
|
|
135
133
|
chartsWrapperProps,
|
|
136
134
|
chartContainerProps,
|
|
137
135
|
barPlotProps,
|
|
138
|
-
axisClickHandlerProps,
|
|
139
136
|
gridProps,
|
|
140
137
|
clipPathProps,
|
|
141
138
|
clipPathGroupProps,
|
|
@@ -58,7 +58,7 @@ process.env.NODE_ENV !== "production" ? ChartContainer.propTypes = {
|
|
|
58
58
|
className: PropTypes.string,
|
|
59
59
|
/**
|
|
60
60
|
* Color palette used to colorize multiple series.
|
|
61
|
-
* @default
|
|
61
|
+
* @default rainbowSurgePalette
|
|
62
62
|
*/
|
|
63
63
|
colors: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string), PropTypes.func]),
|
|
64
64
|
/**
|
|
@@ -100,6 +100,13 @@ process.env.NODE_ENV !== "production" ? ChartContainer.propTypes = {
|
|
|
100
100
|
right: PropTypes.number,
|
|
101
101
|
top: PropTypes.number
|
|
102
102
|
}),
|
|
103
|
+
/**
|
|
104
|
+
* The function called for onClick events.
|
|
105
|
+
* The second argument contains information about all line/bar elements at the current mouse position.
|
|
106
|
+
* @param {MouseEvent} event The mouse event recorded on the `<svg/>` element.
|
|
107
|
+
* @param {null | AxisData} data The data about the clicked axis and items associated with it.
|
|
108
|
+
*/
|
|
109
|
+
onAxisClick: PropTypes.func,
|
|
103
110
|
/**
|
|
104
111
|
* The callback fired when the highlighted item changes.
|
|
105
112
|
*
|
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
4
4
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
5
|
-
const _excluded = ["width", "height", "margin", "children", "series", "colors", "dataset", "desc", "disableAxisListener", "highlightedItem", "onHighlightChange", "sx", "title", "xAxis", "yAxis", "zAxis", "skipAnimation", "seriesConfig"];
|
|
5
|
+
const _excluded = ["width", "height", "margin", "children", "series", "colors", "dataset", "desc", "onAxisClick", "disableAxisListener", "highlightedItem", "onHighlightChange", "sx", "title", "xAxis", "yAxis", "zAxis", "skipAnimation", "seriesConfig", "plugins"];
|
|
6
6
|
import { ALL_PLUGINS } from "../internals/plugins/allPlugins.js";
|
|
7
7
|
export const useChartContainerProps = (props, ref) => {
|
|
8
|
-
const
|
|
8
|
+
const _ref = props,
|
|
9
|
+
{
|
|
9
10
|
width,
|
|
10
11
|
height,
|
|
11
12
|
margin,
|
|
@@ -14,6 +15,7 @@ export const useChartContainerProps = (props, ref) => {
|
|
|
14
15
|
colors,
|
|
15
16
|
dataset,
|
|
16
17
|
desc,
|
|
18
|
+
onAxisClick,
|
|
17
19
|
disableAxisListener,
|
|
18
20
|
highlightedItem,
|
|
19
21
|
onHighlightChange,
|
|
@@ -23,14 +25,14 @@ export const useChartContainerProps = (props, ref) => {
|
|
|
23
25
|
yAxis,
|
|
24
26
|
zAxis,
|
|
25
27
|
skipAnimation,
|
|
26
|
-
seriesConfig
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
seriesConfig,
|
|
29
|
+
plugins
|
|
30
|
+
} = _ref,
|
|
31
|
+
other = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
29
32
|
const chartsSurfaceProps = _extends({
|
|
30
33
|
title,
|
|
31
34
|
desc,
|
|
32
35
|
sx,
|
|
33
|
-
disableAxisListener,
|
|
34
36
|
ref
|
|
35
37
|
}, other);
|
|
36
38
|
const chartDataProviderProps = {
|
|
@@ -40,14 +42,16 @@ export const useChartContainerProps = (props, ref) => {
|
|
|
40
42
|
dataset,
|
|
41
43
|
highlightedItem,
|
|
42
44
|
onHighlightChange,
|
|
45
|
+
onAxisClick,
|
|
43
46
|
xAxis,
|
|
44
47
|
yAxis,
|
|
45
48
|
zAxis,
|
|
46
49
|
skipAnimation,
|
|
47
50
|
width,
|
|
48
51
|
height,
|
|
52
|
+
disableAxisListener,
|
|
49
53
|
seriesConfig,
|
|
50
|
-
plugins: ALL_PLUGINS
|
|
54
|
+
plugins: plugins ?? ALL_PLUGINS
|
|
51
55
|
};
|
|
52
56
|
return {
|
|
53
57
|
chartDataProviderProps,
|
|
@@ -55,9 +55,12 @@ process.env.NODE_ENV !== "production" ? ChartDataProvider.propTypes = {
|
|
|
55
55
|
children: PropTypes.node,
|
|
56
56
|
/**
|
|
57
57
|
* Color palette used to colorize multiple series.
|
|
58
|
-
* @default
|
|
58
|
+
* @default rainbowSurgePalette
|
|
59
59
|
*/
|
|
60
60
|
colors: PropTypes.any,
|
|
61
|
+
/**
|
|
62
|
+
* An array of objects that can be used to populate series and axes data using their `dataKey` property.
|
|
63
|
+
*/
|
|
61
64
|
dataset: PropTypes.any,
|
|
62
65
|
/**
|
|
63
66
|
* The height of the chart in px. If not defined, it takes the height of the parent element.
|
|
@@ -2,12 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
4
4
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
5
|
-
const _excluded = ["children", "
|
|
5
|
+
const _excluded = ["children", "className", "title", "desc"];
|
|
6
6
|
import { styled, useThemeProps } from '@mui/material/styles';
|
|
7
7
|
import PropTypes from 'prop-types';
|
|
8
8
|
import * as React from 'react';
|
|
9
9
|
import useForkRef from '@mui/utils/useForkRef';
|
|
10
|
-
import { useAxisEvents } from "../hooks/useAxisEvents.js";
|
|
11
10
|
import { ChartsAxesGradients } from "../internals/components/ChartsAxesGradients/index.js";
|
|
12
11
|
import { useSvgRef } from "../hooks/useSvgRef.js";
|
|
13
12
|
import { useSelector } from "../internals/store/useSelector.js";
|
|
@@ -65,14 +64,12 @@ const ChartsSurface = /*#__PURE__*/React.forwardRef(function ChartsSurface(inPro
|
|
|
65
64
|
});
|
|
66
65
|
const {
|
|
67
66
|
children,
|
|
68
|
-
disableAxisListener = false,
|
|
69
67
|
className,
|
|
70
68
|
title,
|
|
71
69
|
desc
|
|
72
70
|
} = themeProps,
|
|
73
71
|
other = _objectWithoutPropertiesLoose(themeProps, _excluded);
|
|
74
72
|
const hasIntrinsicSize = svgHeight > 0 && svgWidth > 0;
|
|
75
|
-
useAxisEvents(disableAxisListener);
|
|
76
73
|
return /*#__PURE__*/_jsxs(ChartsSurfaceStyles, _extends({
|
|
77
74
|
ownerState: {
|
|
78
75
|
width: propsWidth,
|
|
@@ -97,12 +94,6 @@ process.env.NODE_ENV !== "production" ? ChartsSurface.propTypes = {
|
|
|
97
94
|
children: PropTypes.node,
|
|
98
95
|
className: PropTypes.string,
|
|
99
96
|
desc: PropTypes.string,
|
|
100
|
-
/**
|
|
101
|
-
* If `true`, the charts will not listen to the mouse move event.
|
|
102
|
-
* It might break interactive features, but will improve performance.
|
|
103
|
-
* @default false
|
|
104
|
-
*/
|
|
105
|
-
disableAxisListener: PropTypes.bool,
|
|
106
97
|
sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
|
|
107
98
|
title: PropTypes.string
|
|
108
99
|
} : void 0;
|
|
@@ -27,6 +27,7 @@ const ChartsTooltipRoot = styled(Popper, {
|
|
|
27
27
|
pointerEvents: 'none',
|
|
28
28
|
zIndex: theme.zIndex.modal
|
|
29
29
|
}));
|
|
30
|
+
const axisHasData = axis => axis?.data !== undefined && axis.data.length !== 0;
|
|
30
31
|
|
|
31
32
|
/**
|
|
32
33
|
* Demos:
|
|
@@ -51,7 +52,6 @@ function ChartsTooltipContainer(inProps) {
|
|
|
51
52
|
const svgRef = useSvgRef();
|
|
52
53
|
const pointerType = usePointerType();
|
|
53
54
|
const xAxis = useXAxis();
|
|
54
|
-
const xAxisHasData = xAxis.data !== undefined && xAxis.data.length !== 0;
|
|
55
55
|
const popperRef = React.useRef(null);
|
|
56
56
|
const positionRef = useLazyRef(() => ({
|
|
57
57
|
x: 0,
|
|
@@ -60,7 +60,7 @@ function ChartsTooltipContainer(inProps) {
|
|
|
60
60
|
const store = useStore();
|
|
61
61
|
const isOpen = useSelector(store,
|
|
62
62
|
// eslint-disable-next-line no-nested-ternary
|
|
63
|
-
trigger === 'axis' ?
|
|
63
|
+
trigger === 'axis' ? axisHasData(xAxis) ? selectorChartsInteractionXAxisIsDefined : selectorChartsInteractionYAxisIsDefined : selectorChartsInteractionItemIsDefined);
|
|
64
64
|
const popperOpen = pointerType !== null && isOpen; // tooltipHasData;
|
|
65
65
|
|
|
66
66
|
React.useEffect(() => {
|
package/modern/Gauge/Gauge.js
CHANGED
|
@@ -73,12 +73,6 @@ process.env.NODE_ENV !== "production" ? Gauge.propTypes = {
|
|
|
73
73
|
*/
|
|
74
74
|
cy: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
75
75
|
desc: PropTypes.string,
|
|
76
|
-
/**
|
|
77
|
-
* If `true`, the charts will not listen to the mouse move event.
|
|
78
|
-
* It might break interactive features, but will improve performance.
|
|
79
|
-
* @default false
|
|
80
|
-
*/
|
|
81
|
-
disableAxisListener: PropTypes.bool,
|
|
82
76
|
/**
|
|
83
77
|
* The end angle (deg).
|
|
84
78
|
* @default 360
|
|
@@ -103,12 +103,6 @@ process.env.NODE_ENV !== "production" ? GaugeContainer.propTypes = {
|
|
|
103
103
|
*/
|
|
104
104
|
cy: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
105
105
|
desc: PropTypes.string,
|
|
106
|
-
/**
|
|
107
|
-
* If `true`, the charts will not listen to the mouse move event.
|
|
108
|
-
* It might break interactive features, but will improve performance.
|
|
109
|
-
* @default false
|
|
110
|
-
*/
|
|
111
|
-
disableAxisListener: PropTypes.bool,
|
|
112
106
|
/**
|
|
113
107
|
* The end angle (deg).
|
|
114
108
|
* @default 360
|