@mui/x-charts 7.9.0 → 7.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/BarChart/BarChart.js +2 -2
- package/BarChart/formatter.js +1 -1
- package/BarChart/useBarChartProps.js +38 -33
- package/CHANGELOG.md +159 -0
- package/ChartContainer/ChartContainer.d.ts +28 -2
- package/ChartContainer/ChartContainer.js +25 -66
- package/ChartContainer/useChartContainerHooks.d.ts +1 -1
- package/ChartContainer/useChartContainerHooks.js +2 -2
- package/ChartContainer/useChartContainerProps.d.ts +86 -0
- package/ChartContainer/useChartContainerProps.js +95 -0
- package/ChartContainer/useDefaultizeAxis.d.ts +36 -0
- package/ChartContainer/useDefaultizeAxis.js +29 -0
- package/ChartsLegend/ChartsLegend.d.ts +3 -12
- package/ChartsLegend/ContinuousColorLegend.d.ts +65 -0
- package/ChartsLegend/ContinuousColorLegend.js +398 -0
- package/ChartsLegend/DefaultChartsLegend.d.ts +7 -50
- package/ChartsLegend/DefaultChartsLegend.js +13 -198
- package/ChartsLegend/LegendPerItem.d.ts +61 -0
- package/ChartsLegend/LegendPerItem.js +151 -0
- package/ChartsLegend/PiecewiseColorLegend.d.ts +26 -0
- package/ChartsLegend/PiecewiseColorLegend.js +169 -0
- package/ChartsLegend/chartsLegend.types.d.ts +31 -0
- package/ChartsLegend/chartsLegend.types.js +5 -0
- package/ChartsLegend/index.d.ts +2 -0
- package/ChartsLegend/index.js +22 -0
- package/ChartsLegend/legend.types.d.ts +62 -0
- package/ChartsLegend/legend.types.js +5 -0
- package/ChartsLegend/legendItemsPlacement.d.ts +3 -0
- package/ChartsLegend/legendItemsPlacement.js +79 -0
- package/ChartsLegend/useAxis.d.ts +7 -0
- package/ChartsLegend/useAxis.js +47 -0
- package/ChartsLegend/utils.d.ts +1 -8
- package/ChartsReferenceLine/ChartsReferenceLine.d.ts +1 -1
- package/ChartsSurface.js +3 -1
- package/ChartsVoronoiHandler/ChartsVoronoiHandler.js +26 -18
- package/ChartsXAxis/ChartsXAxis.js +1 -1
- package/ChartsYAxis/ChartsYAxis.js +15 -3
- package/Gauge/Gauge.d.ts +1 -4
- package/Gauge/Gauge.js +9 -6
- package/Gauge/GaugeContainer.js +8 -4
- package/Gauge/GaugeProvider.js +9 -9
- package/LineChart/AnimatedArea.js +2 -2
- package/LineChart/AnimatedLine.js +2 -2
- package/LineChart/AreaPlot.js +7 -1
- package/LineChart/LineChart.js +2 -2
- package/LineChart/LineHighlightPlot.js +8 -0
- package/LineChart/MarkElement.js +2 -2
- package/LineChart/MarkPlot.js +4 -20
- package/LineChart/extremums.js +1 -1
- package/LineChart/formatter.js +1 -1
- package/LineChart/useLineChartProps.js +38 -33
- package/PieChart/PieChart.d.ts +1 -4
- package/PieChart/PieChart.js +40 -34
- package/PieChart/PiePlot.js +6 -6
- package/PieChart/getPieCoordinates.js +3 -3
- package/ResponsiveChartContainer/ResponsiveChartContainer.js +8 -20
- package/ResponsiveChartContainer/useChartContainerDimensions.d.ts +5 -1
- package/ResponsiveChartContainer/useChartContainerDimensions.js +6 -2
- package/ResponsiveChartContainer/useResponsiveChartContainerProps.d.ts +20 -0
- package/ResponsiveChartContainer/useResponsiveChartContainerProps.js +73 -0
- package/ScatterChart/Scatter.js +6 -9
- package/ScatterChart/useScatterChartProps.js +35 -30
- package/SparkLineChart/SparkLineChart.js +27 -22
- package/context/CartesianProvider/CartesianProvider.d.ts +2 -3
- package/context/CartesianProvider/CartesianProvider.js +18 -7
- package/context/CartesianProvider/computeValue.d.ts +32 -9
- package/context/CartesianProvider/computeValue.js +20 -16
- package/context/CartesianProvider/defaultizeAxis.d.ts +36 -0
- package/context/CartesianProvider/defaultizeAxis.js +21 -0
- package/context/CartesianProvider/index.d.ts +0 -1
- package/context/CartesianProvider/index.js +1 -3
- package/context/CartesianProvider/normalizeAxis.d.ts +1 -1
- package/context/CartesianProvider/normalizeAxis.js +1 -1
- package/context/DrawingProvider.d.ts +11 -0
- package/context/DrawingProvider.js +9 -2
- package/context/HighlightedProvider/HighlightedProvider.js +2 -2
- package/esm/BarChart/BarChart.js +2 -2
- package/esm/BarChart/formatter.js +1 -1
- package/esm/BarChart/useBarChartProps.js +38 -33
- package/esm/ChartContainer/ChartContainer.js +25 -66
- package/esm/ChartContainer/useChartContainerHooks.js +2 -2
- package/esm/ChartContainer/useChartContainerProps.js +87 -0
- package/esm/ChartContainer/useDefaultizeAxis.js +19 -0
- package/esm/ChartsLegend/ContinuousColorLegend.js +390 -0
- package/esm/ChartsLegend/DefaultChartsLegend.js +14 -198
- package/esm/ChartsLegend/LegendPerItem.js +141 -0
- package/esm/ChartsLegend/PiecewiseColorLegend.js +161 -0
- package/esm/ChartsLegend/chartsLegend.types.js +1 -0
- package/esm/ChartsLegend/index.js +2 -0
- package/esm/ChartsLegend/legend.types.js +1 -0
- package/esm/ChartsLegend/legendItemsPlacement.js +72 -0
- package/esm/ChartsLegend/useAxis.js +39 -0
- package/esm/ChartsSurface.js +3 -1
- package/esm/ChartsVoronoiHandler/ChartsVoronoiHandler.js +26 -18
- package/esm/ChartsXAxis/ChartsXAxis.js +1 -1
- package/esm/ChartsYAxis/ChartsYAxis.js +15 -3
- package/esm/Gauge/Gauge.js +8 -5
- package/esm/Gauge/GaugeContainer.js +8 -4
- package/esm/Gauge/GaugeProvider.js +1 -1
- package/esm/LineChart/AnimatedArea.js +1 -1
- package/esm/LineChart/AnimatedLine.js +1 -1
- package/esm/LineChart/AreaPlot.js +7 -1
- package/esm/LineChart/LineChart.js +2 -2
- package/esm/LineChart/LineHighlightPlot.js +8 -0
- package/esm/LineChart/MarkElement.js +1 -1
- package/esm/LineChart/MarkPlot.js +3 -19
- package/esm/LineChart/extremums.js +1 -1
- package/esm/LineChart/formatter.js +1 -1
- package/esm/LineChart/useLineChartProps.js +38 -33
- package/esm/PieChart/PieChart.js +39 -33
- package/esm/PieChart/PiePlot.js +1 -1
- package/esm/PieChart/getPieCoordinates.js +1 -1
- package/esm/ResponsiveChartContainer/ResponsiveChartContainer.js +8 -20
- package/esm/ResponsiveChartContainer/useChartContainerDimensions.js +6 -2
- package/esm/ResponsiveChartContainer/useResponsiveChartContainerProps.js +65 -0
- package/esm/ScatterChart/Scatter.js +6 -9
- package/esm/ScatterChart/useScatterChartProps.js +35 -30
- package/esm/SparkLineChart/SparkLineChart.js +27 -22
- package/esm/context/CartesianProvider/CartesianProvider.js +18 -7
- package/esm/context/CartesianProvider/computeValue.js +20 -16
- package/esm/context/CartesianProvider/defaultizeAxis.js +13 -0
- package/esm/context/CartesianProvider/index.js +1 -3
- package/esm/context/CartesianProvider/normalizeAxis.js +1 -1
- package/esm/context/DrawingProvider.js +9 -2
- package/esm/context/HighlightedProvider/HighlightedProvider.js +2 -2
- package/esm/hooks/useAxisEvents.js +3 -10
- package/esm/hooks/useDrawingArea.js +5 -3
- package/esm/hooks/useReducedMotion.js +4 -2
- package/esm/internals/cleanId.js +6 -0
- package/esm/internals/components/ChartsAxesGradients/ChartsContinuousGradient.js +3 -2
- package/esm/internals/{utils.js → getPercentageValue.js} +1 -13
- package/esm/internals/getSymbol.js +5 -0
- package/esm/internals/index.js +3 -1
- package/esm/internals/isDefined.js +3 -0
- package/esm/internals/notNull.js +3 -0
- package/esm/internals/ts-generic.js +1 -0
- package/hooks/useAxisEvents.js +3 -10
- package/hooks/useDrawingArea.js +5 -3
- package/hooks/useReducedMotion.js +4 -2
- package/index.js +1 -1
- package/internals/cleanId.d.ts +4 -0
- package/internals/cleanId.js +12 -0
- package/internals/components/ChartsAxesGradients/ChartsContinuousGradient.d.ts +6 -0
- package/internals/components/ChartsAxesGradients/ChartsContinuousGradient.js +3 -2
- package/internals/getPercentageValue.d.ts +7 -0
- package/internals/{utils.js → getPercentageValue.js} +1 -15
- package/internals/getSymbol.d.ts +2 -0
- package/internals/getSymbol.js +11 -0
- package/internals/index.d.ts +3 -1
- package/internals/index.js +25 -5
- package/internals/isDefined.d.ts +1 -0
- package/internals/isDefined.js +9 -0
- package/internals/notNull.d.ts +1 -0
- package/internals/notNull.js +9 -0
- package/internals/ts-generic.d.ts +5 -0
- package/internals/ts-generic.js +5 -0
- package/models/axis.d.ts +5 -2
- package/models/helpers.d.ts +1 -0
- package/models/seriesType/config.d.ts +2 -16
- package/modern/BarChart/BarChart.js +2 -2
- package/modern/BarChart/formatter.js +1 -1
- package/modern/BarChart/useBarChartProps.js +38 -33
- package/modern/ChartContainer/ChartContainer.js +25 -66
- package/modern/ChartContainer/useChartContainerHooks.js +2 -2
- package/modern/ChartContainer/useChartContainerProps.js +87 -0
- package/modern/ChartContainer/useDefaultizeAxis.js +19 -0
- package/modern/ChartsLegend/ContinuousColorLegend.js +390 -0
- package/modern/ChartsLegend/DefaultChartsLegend.js +14 -198
- package/modern/ChartsLegend/LegendPerItem.js +141 -0
- package/modern/ChartsLegend/PiecewiseColorLegend.js +161 -0
- package/modern/ChartsLegend/chartsLegend.types.js +1 -0
- package/modern/ChartsLegend/index.js +2 -0
- package/modern/ChartsLegend/legend.types.js +1 -0
- package/modern/ChartsLegend/legendItemsPlacement.js +72 -0
- package/modern/ChartsLegend/useAxis.js +39 -0
- package/modern/ChartsSurface.js +3 -1
- package/modern/ChartsVoronoiHandler/ChartsVoronoiHandler.js +26 -18
- package/modern/ChartsXAxis/ChartsXAxis.js +1 -1
- package/modern/ChartsYAxis/ChartsYAxis.js +15 -3
- package/modern/Gauge/Gauge.js +8 -5
- package/modern/Gauge/GaugeContainer.js +8 -4
- package/modern/Gauge/GaugeProvider.js +1 -1
- package/modern/LineChart/AnimatedArea.js +1 -1
- package/modern/LineChart/AnimatedLine.js +1 -1
- package/modern/LineChart/AreaPlot.js +7 -1
- package/modern/LineChart/LineChart.js +2 -2
- package/modern/LineChart/LineHighlightPlot.js +8 -0
- package/modern/LineChart/MarkElement.js +1 -1
- package/modern/LineChart/MarkPlot.js +3 -19
- package/modern/LineChart/extremums.js +1 -1
- package/modern/LineChart/formatter.js +1 -1
- package/modern/LineChart/useLineChartProps.js +38 -33
- package/modern/PieChart/PieChart.js +39 -33
- package/modern/PieChart/PiePlot.js +1 -1
- package/modern/PieChart/getPieCoordinates.js +1 -1
- package/modern/ResponsiveChartContainer/ResponsiveChartContainer.js +8 -20
- package/modern/ResponsiveChartContainer/useChartContainerDimensions.js +6 -2
- package/modern/ResponsiveChartContainer/useResponsiveChartContainerProps.js +65 -0
- package/modern/ScatterChart/Scatter.js +6 -9
- package/modern/ScatterChart/useScatterChartProps.js +35 -30
- package/modern/SparkLineChart/SparkLineChart.js +27 -22
- package/modern/context/CartesianProvider/CartesianProvider.js +18 -7
- package/modern/context/CartesianProvider/computeValue.js +20 -16
- package/modern/context/CartesianProvider/defaultizeAxis.js +13 -0
- package/modern/context/CartesianProvider/index.js +1 -3
- package/modern/context/CartesianProvider/normalizeAxis.js +1 -1
- package/modern/context/DrawingProvider.js +9 -2
- package/modern/context/HighlightedProvider/HighlightedProvider.js +2 -2
- package/modern/hooks/useAxisEvents.js +3 -10
- package/modern/hooks/useDrawingArea.js +5 -3
- package/modern/hooks/useReducedMotion.js +4 -2
- package/modern/index.js +1 -1
- package/modern/internals/cleanId.js +6 -0
- package/modern/internals/components/ChartsAxesGradients/ChartsContinuousGradient.js +3 -2
- package/modern/internals/{utils.js → getPercentageValue.js} +1 -13
- package/modern/internals/getSymbol.js +5 -0
- package/modern/internals/index.js +3 -1
- package/modern/internals/isDefined.js +3 -0
- package/modern/internals/notNull.js +3 -0
- package/modern/internals/ts-generic.js +1 -0
- package/package.json +4 -4
- package/internals/utils.d.ts +0 -18
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
|
+
const _excluded = ["xAxis", "yAxis", "width", "height", "margin", "colors", "sx", "showTooltip", "tooltip", "showHighlight", "axisHighlight", "children", "slots", "slotProps", "data", "plotType", "valueFormatter", "area", "curve", "className"];
|
|
2
4
|
import * as React from 'react';
|
|
3
5
|
import PropTypes from 'prop-types';
|
|
4
6
|
import { BarPlot } from '../BarChart';
|
|
@@ -26,33 +28,35 @@ const SPARKLINE_DEFAULT_MARGIN = {
|
|
|
26
28
|
*/
|
|
27
29
|
const SparkLineChart = /*#__PURE__*/React.forwardRef(function SparkLineChart(props, ref) {
|
|
28
30
|
const {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
31
|
+
xAxis,
|
|
32
|
+
yAxis,
|
|
33
|
+
width,
|
|
34
|
+
height,
|
|
35
|
+
margin = SPARKLINE_DEFAULT_MARGIN,
|
|
36
|
+
colors,
|
|
37
|
+
sx,
|
|
38
|
+
showTooltip,
|
|
39
|
+
tooltip,
|
|
40
|
+
showHighlight,
|
|
41
|
+
axisHighlight: inAxisHighlight,
|
|
42
|
+
children,
|
|
43
|
+
slots,
|
|
44
|
+
slotProps,
|
|
45
|
+
data,
|
|
46
|
+
plotType = 'line',
|
|
47
|
+
valueFormatter = value => value === null ? '' : value.toString(),
|
|
48
|
+
area,
|
|
49
|
+
curve = 'linear',
|
|
50
|
+
className
|
|
51
|
+
} = props,
|
|
52
|
+
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
49
53
|
const defaultXHighlight = showHighlight && plotType === 'bar' ? {
|
|
50
54
|
x: 'band'
|
|
51
55
|
} : {
|
|
52
56
|
x: 'none'
|
|
53
57
|
};
|
|
54
58
|
const axisHighlight = _extends({}, defaultXHighlight, inAxisHighlight);
|
|
55
|
-
return /*#__PURE__*/_jsxs(ResponsiveChartContainer, {
|
|
59
|
+
return /*#__PURE__*/_jsxs(ResponsiveChartContainer, _extends({}, other, {
|
|
56
60
|
ref: ref,
|
|
57
61
|
series: [_extends({
|
|
58
62
|
type: plotType,
|
|
@@ -66,6 +70,7 @@ const SparkLineChart = /*#__PURE__*/React.forwardRef(function SparkLineChart(pro
|
|
|
66
70
|
width: width,
|
|
67
71
|
height: height,
|
|
68
72
|
margin: margin,
|
|
73
|
+
className: className,
|
|
69
74
|
xAxis: [_extends({
|
|
70
75
|
id: DEFAULT_X_AXIS_KEY,
|
|
71
76
|
scaleType: plotType === 'bar' ? 'band' : 'point',
|
|
@@ -104,7 +109,7 @@ const SparkLineChart = /*#__PURE__*/React.forwardRef(function SparkLineChart(pro
|
|
|
104
109
|
slotProps: slotProps,
|
|
105
110
|
slots: slots
|
|
106
111
|
})), children]
|
|
107
|
-
});
|
|
112
|
+
}));
|
|
108
113
|
});
|
|
109
114
|
process.env.NODE_ENV !== "production" ? SparkLineChart.propTypes = {
|
|
110
115
|
// ----------------------------- Warning --------------------------------
|
|
@@ -2,13 +2,12 @@ import * as React from 'react';
|
|
|
2
2
|
import { useDrawingArea } from '../../hooks/useDrawingArea';
|
|
3
3
|
import { useSeries } from '../../hooks/useSeries';
|
|
4
4
|
import { CartesianContext } from './CartesianContext';
|
|
5
|
-
import { normalizeAxis } from './normalizeAxis';
|
|
6
5
|
import { computeValue } from './computeValue';
|
|
7
6
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
7
|
function CartesianContextProvider(props) {
|
|
9
8
|
const {
|
|
10
|
-
xAxis
|
|
11
|
-
yAxis
|
|
9
|
+
xAxis,
|
|
10
|
+
yAxis,
|
|
12
11
|
dataset,
|
|
13
12
|
xExtremumGetters,
|
|
14
13
|
yExtremumGetters,
|
|
@@ -16,10 +15,22 @@ function CartesianContextProvider(props) {
|
|
|
16
15
|
} = props;
|
|
17
16
|
const formattedSeries = useSeries();
|
|
18
17
|
const drawingArea = useDrawingArea();
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
const xValues = React.useMemo(() => computeValue({
|
|
19
|
+
drawingArea,
|
|
20
|
+
formattedSeries,
|
|
21
|
+
axis: xAxis,
|
|
22
|
+
extremumGetters: xExtremumGetters,
|
|
23
|
+
dataset,
|
|
24
|
+
axisDirection: 'x'
|
|
25
|
+
}), [drawingArea, formattedSeries, xAxis, xExtremumGetters, dataset]);
|
|
26
|
+
const yValues = React.useMemo(() => computeValue({
|
|
27
|
+
drawingArea,
|
|
28
|
+
formattedSeries,
|
|
29
|
+
axis: yAxis,
|
|
30
|
+
extremumGetters: yExtremumGetters,
|
|
31
|
+
dataset,
|
|
32
|
+
axisDirection: 'y'
|
|
33
|
+
}), [drawingArea, formattedSeries, yAxis, yExtremumGetters, dataset]);
|
|
23
34
|
const value = React.useMemo(() => ({
|
|
24
35
|
isInitialized: true,
|
|
25
36
|
data: {
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import { scaleBand, scalePoint, scaleTime } from 'd3-scale';
|
|
3
|
-
import { DEFAULT_X_AXIS_KEY, DEFAULT_Y_AXIS_KEY } from '../../constants';
|
|
4
3
|
import { isBandScaleConfig, isPointScaleConfig } from '../../models/axis';
|
|
5
4
|
import { getColorScale, getOrdinalColorScale } from '../../internals/colorScale';
|
|
6
5
|
import { getTickNumber } from '../../hooks/useTicks';
|
|
7
6
|
import { getScale } from '../../internals/getScale';
|
|
8
7
|
import { getAxisExtremum } from './getAxisExtremum';
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
import { normalizeAxis } from './normalizeAxis';
|
|
9
|
+
const getRange = (drawingArea, axisDirection, isReverse) => {
|
|
10
|
+
const range = axisDirection === 'x' ? [drawingArea.left, drawingArea.left + drawingArea.width] : [drawingArea.top + drawingArea.height, drawingArea.top];
|
|
11
11
|
return isReverse ? range.reverse() : range;
|
|
12
12
|
};
|
|
13
13
|
const zoomedScaleRange = (scaleRange, zoomRange) => {
|
|
@@ -29,26 +29,30 @@ function createDateFormatter(axis, range) {
|
|
|
29
29
|
}
|
|
30
30
|
const DEFAULT_CATEGORY_GAP_RATIO = 0.2;
|
|
31
31
|
const DEFAULT_BAR_GAP_RATIO = 0.1;
|
|
32
|
-
export function computeValue(
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
32
|
+
export function computeValue({
|
|
33
|
+
drawingArea,
|
|
34
|
+
formattedSeries,
|
|
35
|
+
axis: inAxis,
|
|
36
|
+
extremumGetters,
|
|
37
|
+
dataset,
|
|
38
|
+
axisDirection,
|
|
39
|
+
zoomData
|
|
40
|
+
}) {
|
|
41
|
+
const allAxis = normalizeAxis(inAxis, dataset, axisDirection);
|
|
42
42
|
const completeAxis = {};
|
|
43
43
|
allAxis.forEach((axis, axisIndex) => {
|
|
44
44
|
const isDefaultAxis = axisIndex === 0;
|
|
45
45
|
const [minData, maxData] = getAxisExtremum(axis, extremumGetters, isDefaultAxis, formattedSeries);
|
|
46
|
-
const
|
|
46
|
+
const zoom = zoomData?.find(({
|
|
47
|
+
axisId
|
|
48
|
+
}) => axisId === axis.id);
|
|
49
|
+
const zoomRange = zoom ? [zoom.start, zoom.end] : [0, 100];
|
|
50
|
+
const range = getRange(drawingArea, axisDirection, axis.reverse);
|
|
47
51
|
if (isBandScaleConfig(axis)) {
|
|
48
52
|
const categoryGapRatio = axis.categoryGapRatio ?? DEFAULT_CATEGORY_GAP_RATIO;
|
|
49
53
|
const barGapRatio = axis.barGapRatio ?? DEFAULT_BAR_GAP_RATIO;
|
|
50
54
|
// Reverse range because ordinal scales are presented from top to bottom on y-axis
|
|
51
|
-
const scaleRange =
|
|
55
|
+
const scaleRange = axisDirection === 'x' ? range : [range[1], range[0]];
|
|
52
56
|
const zoomedRange = zoomedScaleRange(scaleRange, zoomRange);
|
|
53
57
|
completeAxis[axis.id] = _extends({
|
|
54
58
|
categoryGapRatio,
|
|
@@ -66,7 +70,7 @@ export function computeValue(drawingArea, formattedSeries, inAxis, extremumGette
|
|
|
66
70
|
}
|
|
67
71
|
}
|
|
68
72
|
if (isPointScaleConfig(axis)) {
|
|
69
|
-
const scaleRange =
|
|
73
|
+
const scaleRange = axisDirection === 'x' ? range : [...range].reverse();
|
|
70
74
|
const zoomedRange = zoomedScaleRange(scaleRange, zoomRange);
|
|
71
75
|
completeAxis[axis.id] = _extends({}, axis, {
|
|
72
76
|
scale: scalePoint(axis.data, zoomedRange),
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import { DEFAULT_X_AXIS_KEY, DEFAULT_Y_AXIS_KEY } from '../../constants';
|
|
3
|
+
export const defaultizeAxis = (inAxis, axisName) => {
|
|
4
|
+
const DEFAULT_AXIS_KEY = axisName === 'x' ? DEFAULT_X_AXIS_KEY : DEFAULT_Y_AXIS_KEY;
|
|
5
|
+
return [...(inAxis?.map((axis, index) => _extends({
|
|
6
|
+
id: `defaultized-${axisName}-axis-${index}`
|
|
7
|
+
}, axis)) ?? []), ...(inAxis === undefined || inAxis.findIndex(({
|
|
8
|
+
id
|
|
9
|
+
}) => id === DEFAULT_AXIS_KEY) === -1 ? [{
|
|
10
|
+
id: DEFAULT_AXIS_KEY,
|
|
11
|
+
scaleType: 'linear'
|
|
12
|
+
}] : [])];
|
|
13
|
+
};
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { computeValue } from './computeValue';
|
|
2
|
-
import { normalizeAxis } from './normalizeAxis';
|
|
3
2
|
export * from './CartesianProvider';
|
|
4
3
|
export * from './CartesianContext';
|
|
5
4
|
export * from './useCartesianContext';
|
|
6
5
|
const cartesianProviderUtils = {
|
|
7
|
-
computeValue
|
|
8
|
-
normalizeAxis
|
|
6
|
+
computeValue
|
|
9
7
|
};
|
|
10
8
|
export { cartesianProviderUtils };
|
|
@@ -14,7 +14,8 @@ export const DrawingContext = /*#__PURE__*/React.createContext({
|
|
|
14
14
|
right: 0,
|
|
15
15
|
height: 300,
|
|
16
16
|
width: 400,
|
|
17
|
-
chartId: ''
|
|
17
|
+
chartId: '',
|
|
18
|
+
isPointInside: () => false
|
|
18
19
|
});
|
|
19
20
|
if (process.env.NODE_ENV !== 'production') {
|
|
20
21
|
DrawingContext.displayName = 'DrawingContext';
|
|
@@ -38,9 +39,15 @@ export function DrawingProvider(props) {
|
|
|
38
39
|
} = props;
|
|
39
40
|
const drawingArea = useChartDimensions(width, height, margin);
|
|
40
41
|
const chartId = useId();
|
|
42
|
+
const isPointInside = React.useCallback(({
|
|
43
|
+
x,
|
|
44
|
+
y
|
|
45
|
+
}) => x >= drawingArea.left && x <= drawingArea.left + drawingArea.width && y >= drawingArea.top && y <= drawingArea.top + drawingArea.height, [drawingArea]);
|
|
41
46
|
const value = React.useMemo(() => _extends({
|
|
42
47
|
chartId: chartId ?? ''
|
|
43
|
-
}, drawingArea
|
|
48
|
+
}, drawingArea, {
|
|
49
|
+
isPointInside
|
|
50
|
+
}), [chartId, drawingArea, isPointInside]);
|
|
44
51
|
const refValue = React.useMemo(() => ({
|
|
45
52
|
isInitialized: true,
|
|
46
53
|
data: svgRef
|
|
@@ -15,11 +15,11 @@ const mergeDeprecatedOptions = options => {
|
|
|
15
15
|
highlighted,
|
|
16
16
|
faded
|
|
17
17
|
} = _ref,
|
|
18
|
-
|
|
18
|
+
other = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
19
19
|
return _extends({
|
|
20
20
|
highlight: highlighted,
|
|
21
21
|
fade: faded
|
|
22
|
-
},
|
|
22
|
+
}, other);
|
|
23
23
|
};
|
|
24
24
|
function HighlightedProvider({
|
|
25
25
|
children,
|
|
@@ -10,12 +10,7 @@ function getAsANumber(value) {
|
|
|
10
10
|
}
|
|
11
11
|
export const useAxisEvents = disableAxisListener => {
|
|
12
12
|
const svgRef = useSvgRef();
|
|
13
|
-
const
|
|
14
|
-
left,
|
|
15
|
-
top,
|
|
16
|
-
width,
|
|
17
|
-
height
|
|
18
|
-
} = useDrawingArea();
|
|
13
|
+
const drawingArea = useDrawingArea();
|
|
19
14
|
const {
|
|
20
15
|
xAxis,
|
|
21
16
|
yAxis,
|
|
@@ -103,9 +98,7 @@ export const useAxisEvents = disableAxisListener => {
|
|
|
103
98
|
x: svgPoint.x,
|
|
104
99
|
y: svgPoint.y
|
|
105
100
|
};
|
|
106
|
-
|
|
107
|
-
const outsideY = svgPoint.y < top || svgPoint.y > top + height;
|
|
108
|
-
if (outsideX || outsideY) {
|
|
101
|
+
if (!drawingArea.isPointInside(svgPoint)) {
|
|
109
102
|
dispatch({
|
|
110
103
|
type: 'exitChart'
|
|
111
104
|
});
|
|
@@ -142,5 +135,5 @@ export const useAxisEvents = disableAxisListener => {
|
|
|
142
135
|
element.removeEventListener('pointercancel', handleOut);
|
|
143
136
|
element.removeEventListener('pointerleave', handleOut);
|
|
144
137
|
};
|
|
145
|
-
}, [svgRef, dispatch,
|
|
138
|
+
}, [svgRef, dispatch, usedYAxis, yAxis, usedXAxis, xAxis, disableAxisListener, drawingArea]);
|
|
146
139
|
};
|
|
@@ -7,7 +7,8 @@ export function useDrawingArea() {
|
|
|
7
7
|
width,
|
|
8
8
|
height,
|
|
9
9
|
bottom,
|
|
10
|
-
right
|
|
10
|
+
right,
|
|
11
|
+
isPointInside
|
|
11
12
|
} = React.useContext(DrawingContext);
|
|
12
13
|
return React.useMemo(() => ({
|
|
13
14
|
left,
|
|
@@ -15,6 +16,7 @@ export function useDrawingArea() {
|
|
|
15
16
|
width,
|
|
16
17
|
height,
|
|
17
18
|
bottom,
|
|
18
|
-
right
|
|
19
|
-
|
|
19
|
+
right,
|
|
20
|
+
isPointInside
|
|
21
|
+
}), [height, left, top, width, bottom, right, isPointInside]);
|
|
20
22
|
}
|
|
@@ -26,9 +26,11 @@ export const useReducedMotion = () => {
|
|
|
26
26
|
});
|
|
27
27
|
};
|
|
28
28
|
handleMediaChange(mql);
|
|
29
|
-
|
|
29
|
+
|
|
30
|
+
// MatchMedia is not fully supported in all environments, so we need to check if it exists before calling addEventListener
|
|
31
|
+
mql.addEventListener?.('change', handleMediaChange);
|
|
30
32
|
return () => {
|
|
31
|
-
mql.removeEventListener('change', handleMediaChange);
|
|
33
|
+
mql.removeEventListener?.('change', handleMediaChange);
|
|
32
34
|
};
|
|
33
35
|
}, []);
|
|
34
36
|
};
|
|
@@ -4,6 +4,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
4
4
|
const PX_PRECISION = 10;
|
|
5
5
|
export default function ChartsContinuousGradient(props) {
|
|
6
6
|
const {
|
|
7
|
+
gradientUnits,
|
|
7
8
|
isReversed,
|
|
8
9
|
gradientId,
|
|
9
10
|
size,
|
|
@@ -26,8 +27,8 @@ export default function ChartsContinuousGradient(props) {
|
|
|
26
27
|
x2: "0",
|
|
27
28
|
y1: "0",
|
|
28
29
|
y2: "0",
|
|
29
|
-
[`${direction}${isReversed ? 1 : 2}`]: `${size}px`,
|
|
30
|
-
gradientUnits:
|
|
30
|
+
[`${direction}${isReversed ? 1 : 2}`]: gradientUnits === 'objectBoundingBox' ? 1 : `${size}px`,
|
|
31
|
+
gradientUnits: gradientUnits ?? 'userSpaceOnUse' // Use the SVG coordinate instead of the component ones.
|
|
31
32
|
,
|
|
32
33
|
children: Array.from({
|
|
33
34
|
length: numberOfPoints + 1
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
// Returns the index of a defined shape
|
|
2
|
-
export function getSymbol(shape) {
|
|
3
|
-
const symbolNames = 'circle cross diamond square star triangle wye'.split(/ /);
|
|
4
|
-
return symbolNames.indexOf(shape) || 0;
|
|
5
|
-
}
|
|
6
1
|
/**
|
|
7
2
|
* Helper that converts values and percentages into values.
|
|
8
3
|
* @param value The value provided by the developer. Can either be a number or a string with '%' or 'px'.
|
|
@@ -29,12 +24,5 @@ export function getPercentageValue(value, refValue) {
|
|
|
29
24
|
return val;
|
|
30
25
|
}
|
|
31
26
|
}
|
|
32
|
-
throw Error(`MUI
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Remove spaces to have viable ids
|
|
37
|
-
*/
|
|
38
|
-
export function cleanId(id) {
|
|
39
|
-
return id.replace(' ', '_');
|
|
27
|
+
throw Error(`MUI X Charts: Received an unknown value "${value}". It should be a number, or a string with a percentage value.`);
|
|
40
28
|
}
|
package/esm/internals/index.js
CHANGED
|
@@ -8,16 +8,18 @@ export { useReducedMotion } from '../hooks/useReducedMotion';
|
|
|
8
8
|
export { useSeries } from '../hooks/useSeries';
|
|
9
9
|
export { useInteractionItemProps } from '../hooks/useInteractionItemProps';
|
|
10
10
|
export { useDrawingArea } from '../hooks/useDrawingArea';
|
|
11
|
-
export { useChartContainerHooks } from '../ChartContainer/useChartContainerHooks';
|
|
12
11
|
export { useScatterChartProps } from '../ScatterChart/useScatterChartProps';
|
|
13
12
|
export { useLineChartProps } from '../LineChart/useLineChartProps';
|
|
14
13
|
export { useBarChartProps } from '../BarChart/useBarChartProps';
|
|
14
|
+
export { useResponsiveChartContainerProps } from '../ResponsiveChartContainer/useResponsiveChartContainerProps';
|
|
15
|
+
export { useChartContainerProps } from '../ChartContainer/useChartContainerProps';
|
|
15
16
|
|
|
16
17
|
// utils
|
|
17
18
|
export * from './defaultizeValueFormatter';
|
|
18
19
|
export * from './configInit';
|
|
19
20
|
export * from './getLabel';
|
|
20
21
|
export * from './getSVGPoint';
|
|
22
|
+
export * from './isDefined';
|
|
21
23
|
|
|
22
24
|
// contexts
|
|
23
25
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/hooks/useAxisEvents.js
CHANGED
|
@@ -18,12 +18,7 @@ function getAsANumber(value) {
|
|
|
18
18
|
}
|
|
19
19
|
const useAxisEvents = disableAxisListener => {
|
|
20
20
|
const svgRef = (0, _useSvgRef.useSvgRef)();
|
|
21
|
-
const
|
|
22
|
-
left,
|
|
23
|
-
top,
|
|
24
|
-
width,
|
|
25
|
-
height
|
|
26
|
-
} = (0, _useDrawingArea.useDrawingArea)();
|
|
21
|
+
const drawingArea = (0, _useDrawingArea.useDrawingArea)();
|
|
27
22
|
const {
|
|
28
23
|
xAxis,
|
|
29
24
|
yAxis,
|
|
@@ -111,9 +106,7 @@ const useAxisEvents = disableAxisListener => {
|
|
|
111
106
|
x: svgPoint.x,
|
|
112
107
|
y: svgPoint.y
|
|
113
108
|
};
|
|
114
|
-
|
|
115
|
-
const outsideY = svgPoint.y < top || svgPoint.y > top + height;
|
|
116
|
-
if (outsideX || outsideY) {
|
|
109
|
+
if (!drawingArea.isPointInside(svgPoint)) {
|
|
117
110
|
dispatch({
|
|
118
111
|
type: 'exitChart'
|
|
119
112
|
});
|
|
@@ -150,6 +143,6 @@ const useAxisEvents = disableAxisListener => {
|
|
|
150
143
|
element.removeEventListener('pointercancel', handleOut);
|
|
151
144
|
element.removeEventListener('pointerleave', handleOut);
|
|
152
145
|
};
|
|
153
|
-
}, [svgRef, dispatch,
|
|
146
|
+
}, [svgRef, dispatch, usedYAxis, yAxis, usedXAxis, xAxis, disableAxisListener, drawingArea]);
|
|
154
147
|
};
|
|
155
148
|
exports.useAxisEvents = useAxisEvents;
|
package/hooks/useDrawingArea.js
CHANGED
|
@@ -15,7 +15,8 @@ function useDrawingArea() {
|
|
|
15
15
|
width,
|
|
16
16
|
height,
|
|
17
17
|
bottom,
|
|
18
|
-
right
|
|
18
|
+
right,
|
|
19
|
+
isPointInside
|
|
19
20
|
} = React.useContext(_DrawingProvider.DrawingContext);
|
|
20
21
|
return React.useMemo(() => ({
|
|
21
22
|
left,
|
|
@@ -23,6 +24,7 @@ function useDrawingArea() {
|
|
|
23
24
|
width,
|
|
24
25
|
height,
|
|
25
26
|
bottom,
|
|
26
|
-
right
|
|
27
|
-
|
|
27
|
+
right,
|
|
28
|
+
isPointInside
|
|
29
|
+
}), [height, left, top, width, bottom, right, isPointInside]);
|
|
28
30
|
}
|
|
@@ -31,9 +31,11 @@ const useReducedMotion = () => {
|
|
|
31
31
|
});
|
|
32
32
|
};
|
|
33
33
|
handleMediaChange(mql);
|
|
34
|
-
|
|
34
|
+
|
|
35
|
+
// MatchMedia is not fully supported in all environments, so we need to check if it exists before calling addEventListener
|
|
36
|
+
mql.addEventListener?.('change', handleMediaChange);
|
|
35
37
|
return () => {
|
|
36
|
-
mql.removeEventListener('change', handleMediaChange);
|
|
38
|
+
mql.removeEventListener?.('change', handleMediaChange);
|
|
37
39
|
};
|
|
38
40
|
}, []);
|
|
39
41
|
};
|
package/index.js
CHANGED
|
@@ -8,6 +8,12 @@ type ChartsContinuousGradientProps = {
|
|
|
8
8
|
scale: (value: any) => number | undefined;
|
|
9
9
|
colorMap: ContinuousColorConfig;
|
|
10
10
|
colorScale: (value: any) => string | null;
|
|
11
|
+
/**
|
|
12
|
+
* Defines the coordinate base to use:
|
|
13
|
+
* - 'userSpaceOnUse': uses the coordinate of the SVG (values in px).
|
|
14
|
+
* - 'objectBoundingBox': uses the coordinate ot the object on which gradient is applied (values from 0 to 1).
|
|
15
|
+
*/
|
|
16
|
+
gradientUnits?: 'objectBoundingBox' | 'userSpaceOnUse';
|
|
11
17
|
};
|
|
12
18
|
export default function ChartsContinuousGradient(props: ChartsContinuousGradientProps): React.JSX.Element | null;
|
|
13
19
|
export {};
|
|
@@ -12,6 +12,7 @@ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e;
|
|
|
12
12
|
const PX_PRECISION = 10;
|
|
13
13
|
function ChartsContinuousGradient(props) {
|
|
14
14
|
const {
|
|
15
|
+
gradientUnits,
|
|
15
16
|
isReversed,
|
|
16
17
|
gradientId,
|
|
17
18
|
size,
|
|
@@ -34,8 +35,8 @@ function ChartsContinuousGradient(props) {
|
|
|
34
35
|
x2: "0",
|
|
35
36
|
y1: "0",
|
|
36
37
|
y2: "0",
|
|
37
|
-
[`${direction}${isReversed ? 1 : 2}`]: `${size}px`,
|
|
38
|
-
gradientUnits:
|
|
38
|
+
[`${direction}${isReversed ? 1 : 2}`]: gradientUnits === 'objectBoundingBox' ? 1 : `${size}px`,
|
|
39
|
+
gradientUnits: gradientUnits ?? 'userSpaceOnUse' // Use the SVG coordinate instead of the component ones.
|
|
39
40
|
,
|
|
40
41
|
children: Array.from({
|
|
41
42
|
length: numberOfPoints + 1
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helper that converts values and percentages into values.
|
|
3
|
+
* @param value The value provided by the developer. Can either be a number or a string with '%' or 'px'.
|
|
4
|
+
* @param refValue The numerical value associated to 100%.
|
|
5
|
+
* @returns The numerical value associated to the provided value.
|
|
6
|
+
*/
|
|
7
|
+
export declare function getPercentageValue(value: number | string, refValue: number): number;
|
|
@@ -3,14 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.cleanId = cleanId;
|
|
7
6
|
exports.getPercentageValue = getPercentageValue;
|
|
8
|
-
exports.getSymbol = getSymbol;
|
|
9
|
-
// Returns the index of a defined shape
|
|
10
|
-
function getSymbol(shape) {
|
|
11
|
-
const symbolNames = 'circle cross diamond square star triangle wye'.split(/ /);
|
|
12
|
-
return symbolNames.indexOf(shape) || 0;
|
|
13
|
-
}
|
|
14
7
|
/**
|
|
15
8
|
* Helper that converts values and percentages into values.
|
|
16
9
|
* @param value The value provided by the developer. Can either be a number or a string with '%' or 'px'.
|
|
@@ -37,12 +30,5 @@ function getPercentageValue(value, refValue) {
|
|
|
37
30
|
return val;
|
|
38
31
|
}
|
|
39
32
|
}
|
|
40
|
-
throw Error(`MUI
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Remove spaces to have viable ids
|
|
45
|
-
*/
|
|
46
|
-
function cleanId(id) {
|
|
47
|
-
return id.replace(' ', '_');
|
|
33
|
+
throw Error(`MUI X Charts: Received an unknown value "${value}". It should be a number, or a string with a percentage value.`);
|
|
48
34
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getSymbol = getSymbol;
|
|
7
|
+
// Returns the index of a defined shape
|
|
8
|
+
function getSymbol(shape) {
|
|
9
|
+
const symbolNames = 'circle cross diamond square star triangle wye'.split(/ /);
|
|
10
|
+
return symbolNames.indexOf(shape) || 0;
|
|
11
|
+
}
|
package/internals/index.d.ts
CHANGED
|
@@ -5,14 +5,16 @@ export { useReducedMotion } from '../hooks/useReducedMotion';
|
|
|
5
5
|
export { useSeries } from '../hooks/useSeries';
|
|
6
6
|
export { useInteractionItemProps } from '../hooks/useInteractionItemProps';
|
|
7
7
|
export { useDrawingArea } from '../hooks/useDrawingArea';
|
|
8
|
-
export { useChartContainerHooks } from '../ChartContainer/useChartContainerHooks';
|
|
9
8
|
export { useScatterChartProps } from '../ScatterChart/useScatterChartProps';
|
|
10
9
|
export { useLineChartProps } from '../LineChart/useLineChartProps';
|
|
11
10
|
export { useBarChartProps } from '../BarChart/useBarChartProps';
|
|
11
|
+
export { useResponsiveChartContainerProps } from '../ResponsiveChartContainer/useResponsiveChartContainerProps';
|
|
12
|
+
export { useChartContainerProps } from '../ChartContainer/useChartContainerProps';
|
|
12
13
|
export * from './defaultizeValueFormatter';
|
|
13
14
|
export * from './configInit';
|
|
14
15
|
export * from './getLabel';
|
|
15
16
|
export * from './getSVGPoint';
|
|
17
|
+
export * from './isDefined';
|
|
16
18
|
export * from '../context/CartesianProvider';
|
|
17
19
|
export * from '../context/DrawingProvider';
|
|
18
20
|
export * from '../context/ColorProvider';
|