@mui/x-charts 7.2.0 → 7.3.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.d.ts +1 -0
- package/BarChart/BarChart.js +40 -99
- package/BarChart/BarElement.d.ts +63 -62
- package/BarChart/BarElement.js +1 -2
- package/BarChart/BarPlot.js +14 -7
- package/BarChart/getColor.d.ts +3 -0
- package/BarChart/getColor.js +33 -0
- package/CHANGELOG.md +204 -2
- package/ChartContainer/ChartContainer.js +38 -5
- package/ChartsAxis/ChartsAxis.js +11 -103
- package/ChartsAxisHighlight/ChartsAxisHighlight.js +1 -1
- package/ChartsClipPath/ChartsClipPath.js +3 -3
- package/ChartsGrid/ChartsGrid.js +1 -1
- package/ChartsLegend/ChartsLegend.js +3 -3
- package/ChartsLegend/DefaultChartsLegend.js +1 -1
- package/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +1 -1
- package/ChartsReferenceLine/ChartsReferenceLine.js +1 -1
- package/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
- package/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
- package/ChartsSurface.js +1 -1
- package/ChartsText/ChartsText.js +1 -1
- package/ChartsTooltip/ChartsAxisTooltipContent.d.ts +4 -1
- package/ChartsTooltip/ChartsAxisTooltipContent.js +21 -3
- package/ChartsTooltip/ChartsItemTooltipContent.d.ts +6 -0
- package/ChartsTooltip/ChartsItemTooltipContent.js +32 -2
- package/ChartsTooltip/ChartsTooltip.js +1 -1
- package/ChartsTooltip/ChartsTooltipTable.d.ts +3 -7
- package/ChartsTooltip/ChartsTooltipTable.js +8 -9
- package/ChartsTooltip/DefaultChartsAxisTooltipContent.js +7 -7
- package/ChartsTooltip/DefaultChartsItemTooltipContent.js +15 -8
- package/ChartsTooltip/utils.d.ts +5 -1
- package/ChartsTooltip/utils.js +1 -1
- package/ChartsVoronoiHandler/ChartsVoronoiHandler.js +7 -7
- package/ChartsXAxis/ChartsXAxis.js +3 -3
- package/ChartsYAxis/ChartsYAxis.js +3 -3
- package/Gauge/Gauge.js +1 -1
- package/Gauge/GaugeContainer.js +1 -1
- package/Gauge/GaugeProvider.js +6 -6
- package/Gauge/GaugeReferenceArc.js +1 -1
- package/Gauge/GaugeValueArc.js +1 -1
- package/Gauge/GaugeValueText.js +1 -1
- package/LineChart/AnimatedArea.d.ts +63 -62
- package/LineChart/AnimatedArea.js +7 -6
- package/LineChart/AnimatedLine.d.ts +63 -62
- package/LineChart/AnimatedLine.js +8 -6
- package/LineChart/AreaElement.d.ts +1 -0
- package/LineChart/AreaElement.js +5 -2
- package/LineChart/AreaPlot.js +8 -2
- package/LineChart/LineChart.d.ts +1 -0
- package/LineChart/LineChart.js +40 -99
- package/LineChart/LineElement.d.ts +1 -0
- package/LineChart/LineElement.js +5 -2
- package/LineChart/LineHighlightElement.js +1 -1
- package/LineChart/LineHighlightPlot.js +5 -2
- package/LineChart/LinePlot.js +8 -2
- package/LineChart/MarkElement.js +1 -1
- package/LineChart/MarkPlot.js +6 -6
- package/LineChart/getColor.d.ts +3 -0
- package/LineChart/getColor.js +31 -0
- package/PieChart/PieArc.d.ts +1 -0
- package/PieChart/PieArc.js +1 -1
- package/PieChart/PieArcLabel.d.ts +1 -0
- package/PieChart/PieArcLabel.js +1 -1
- package/PieChart/PieArcLabelPlot.js +1 -1
- package/PieChart/PieArcPlot.js +1 -1
- package/PieChart/PieChart.d.ts +1 -0
- package/PieChart/PieChart.js +40 -99
- package/PieChart/PiePlot.js +27 -7
- package/PieChart/dataTransform/transition.d.ts +1 -0
- package/PieChart/dataTransform/useTransformData.js +1 -1
- package/PieChart/formatter.js +4 -2
- package/PieChart/getColor.d.ts +2 -0
- package/PieChart/getColor.js +11 -0
- package/PieChart/getPieCoordinates.d.ts +7 -0
- package/PieChart/getPieCoordinates.js +25 -0
- package/PieChart/index.d.ts +1 -0
- package/PieChart/index.js +11 -0
- package/ResponsiveChartContainer/ResponsiveChartContainer.js +35 -3
- package/ResponsiveChartContainer/useChartContainerDimensions.js +1 -1
- package/ScatterChart/Scatter.d.ts +1 -0
- package/ScatterChart/Scatter.js +7 -4
- package/ScatterChart/ScatterChart.d.ts +3 -1
- package/ScatterChart/ScatterChart.js +95 -126
- package/ScatterChart/ScatterPlot.js +11 -1
- package/ScatterChart/getColor.d.ts +4 -0
- package/ScatterChart/getColor.js +48 -0
- package/SparkLineChart/SparkLineChart.js +16 -1
- package/context/CartesianContextProvider.d.ts +4 -3
- package/context/CartesianContextProvider.js +24 -9
- package/context/DrawingProvider.js +1 -1
- package/context/HighlightProvider.js +1 -1
- package/context/InteractionProvider.js +1 -1
- package/context/SeriesContextProvider.js +1 -1
- package/context/ZAxisContextProvider.d.ts +33 -0
- package/context/ZAxisContextProvider.js +98 -0
- package/context/index.d.ts +2 -0
- package/context/index.js +8 -1
- package/esm/BarChart/BarChart.js +40 -100
- package/esm/BarChart/BarElement.js +0 -1
- package/esm/BarChart/BarPlot.js +15 -7
- package/esm/BarChart/getColor.js +27 -0
- package/esm/ChartContainer/ChartContainer.js +38 -5
- package/esm/ChartsAxis/ChartsAxis.js +11 -104
- package/esm/ChartsAxisHighlight/ChartsAxisHighlight.js +1 -2
- package/esm/ChartsClipPath/ChartsClipPath.js +2 -2
- package/esm/ChartsGrid/ChartsGrid.js +1 -2
- package/esm/ChartsLegend/ChartsLegend.js +2 -2
- package/esm/ChartsLegend/DefaultChartsLegend.js +1 -2
- package/esm/ChartsReferenceLine/ChartsXReferenceLine.js +1 -2
- package/esm/ChartsReferenceLine/ChartsYReferenceLine.js +1 -2
- package/esm/ChartsSurface.js +1 -2
- package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +20 -2
- package/esm/ChartsTooltip/ChartsItemTooltipContent.js +31 -1
- package/esm/ChartsTooltip/ChartsTooltipTable.js +8 -8
- package/esm/ChartsTooltip/DefaultChartsAxisTooltipContent.js +7 -8
- package/esm/ChartsTooltip/DefaultChartsItemTooltipContent.js +15 -9
- package/esm/ChartsVoronoiHandler/ChartsVoronoiHandler.js +6 -6
- package/esm/ChartsXAxis/ChartsXAxis.js +3 -4
- package/esm/ChartsYAxis/ChartsYAxis.js +3 -4
- package/esm/Gauge/Gauge.js +1 -2
- package/esm/Gauge/GaugeProvider.js +5 -5
- package/esm/LineChart/AnimatedArea.js +7 -7
- package/esm/LineChart/AnimatedLine.js +8 -7
- package/esm/LineChart/AreaElement.js +4 -1
- package/esm/LineChart/AreaPlot.js +7 -1
- package/esm/LineChart/LineChart.js +40 -100
- package/esm/LineChart/LineElement.js +4 -1
- package/esm/LineChart/LineHighlightPlot.js +4 -1
- package/esm/LineChart/LinePlot.js +7 -1
- package/esm/LineChart/MarkPlot.js +5 -5
- package/esm/LineChart/getColor.js +25 -0
- package/esm/PieChart/PieChart.js +40 -100
- package/esm/PieChart/PiePlot.js +27 -8
- package/esm/PieChart/formatter.js +4 -2
- package/esm/PieChart/getColor.js +5 -0
- package/esm/PieChart/getPieCoordinates.js +19 -0
- package/esm/PieChart/index.js +2 -1
- package/esm/ResponsiveChartContainer/ResponsiveChartContainer.js +34 -2
- package/esm/ScatterChart/Scatter.js +6 -3
- package/esm/ScatterChart/ScatterChart.js +95 -127
- package/esm/ScatterChart/ScatterPlot.js +10 -0
- package/esm/ScatterChart/getColor.js +42 -0
- package/esm/SparkLineChart/SparkLineChart.js +16 -2
- package/esm/context/CartesianContextProvider.js +23 -8
- package/esm/context/ZAxisContextProvider.js +89 -0
- package/esm/context/index.js +1 -1
- package/esm/hooks/index.js +4 -1
- package/esm/hooks/useAxisEvents.js +7 -6
- package/esm/hooks/useChartId.js +8 -0
- package/esm/hooks/useSeries.js +64 -0
- package/esm/hooks/useSvgRef.js +9 -0
- package/esm/internals/colorGetter.js +22 -0
- package/esm/internals/colorScale.js +16 -0
- package/esm/internals/components/ChartsAxesGradients/ChartsAxesGradients.js +95 -0
- package/esm/internals/components/ChartsAxesGradients/ChartsContinuousGradient.js +55 -0
- package/esm/internals/components/ChartsAxesGradients/ChartsPiecewiseGradient.js +40 -0
- package/esm/internals/components/ChartsAxesGradients/index.js +1 -0
- package/esm/models/colorMapping.js +1 -0
- package/esm/models/seriesType/index.js +6 -1
- package/esm/models/z-axis.js +1 -0
- package/hooks/index.d.ts +3 -0
- package/hooks/index.js +65 -1
- package/hooks/useAxisEvents.js +8 -7
- package/hooks/useChartDimensions.js +1 -1
- package/hooks/useChartId.d.ts +1 -0
- package/hooks/useChartId.js +16 -0
- package/hooks/useDrawingArea.js +1 -1
- package/hooks/useInteractionItemProps.js +1 -1
- package/hooks/useMounted.js +1 -1
- package/hooks/useScale.js +1 -1
- package/hooks/useSeries.d.ts +45 -0
- package/hooks/useSeries.js +75 -0
- package/hooks/useSvgRef.d.ts +2 -0
- package/hooks/useSvgRef.js +17 -0
- package/hooks/useTicks.js +1 -1
- package/index.js +1 -1
- package/internals/colorGetter.d.ts +7 -0
- package/internals/colorGetter.js +29 -0
- package/internals/colorScale.d.ts +5 -0
- package/internals/colorScale.js +24 -0
- package/internals/components/ChartsAxesGradients/ChartsAxesGradients.d.ts +3 -0
- package/internals/components/ChartsAxesGradients/ChartsAxesGradients.js +105 -0
- package/internals/components/ChartsAxesGradients/ChartsContinuousGradient.d.ts +13 -0
- package/internals/components/ChartsAxesGradients/ChartsContinuousGradient.js +63 -0
- package/internals/components/ChartsAxesGradients/ChartsPiecewiseGradient.d.ts +12 -0
- package/internals/components/ChartsAxesGradients/ChartsPiecewiseGradient.js +48 -0
- package/internals/components/ChartsAxesGradients/index.d.ts +1 -0
- package/internals/components/ChartsAxesGradients/index.js +16 -0
- package/internals/defaultizeColor.d.ts +5 -4
- package/internals/defaultizeValueFormatter.d.ts +5 -5
- package/internals/getScale.d.ts +2 -2
- package/internals/useAnimatedPath.d.ts +1 -0
- package/internals/useAnimatedPath.js +1 -1
- package/models/axis.d.ts +44 -4
- package/models/colorMapping.d.ts +46 -0
- package/models/colorMapping.js +5 -0
- package/models/index.d.ts +1 -1
- package/models/seriesType/common.d.ts +10 -2
- package/models/seriesType/index.d.ts +2 -0
- package/models/seriesType/index.js +17 -1
- package/models/seriesType/pie.d.ts +5 -0
- package/models/seriesType/scatter.d.ts +5 -0
- package/models/z-axis.d.ts +14 -0
- package/models/z-axis.js +5 -0
- package/modern/BarChart/BarChart.js +40 -100
- package/modern/BarChart/BarElement.js +0 -1
- package/modern/BarChart/BarPlot.js +15 -7
- package/modern/BarChart/getColor.js +27 -0
- package/modern/ChartContainer/ChartContainer.js +38 -5
- package/modern/ChartsAxis/ChartsAxis.js +11 -104
- package/modern/ChartsAxisHighlight/ChartsAxisHighlight.js +1 -2
- package/modern/ChartsClipPath/ChartsClipPath.js +2 -2
- package/modern/ChartsGrid/ChartsGrid.js +1 -2
- package/modern/ChartsLegend/ChartsLegend.js +2 -2
- package/modern/ChartsLegend/DefaultChartsLegend.js +1 -2
- package/modern/ChartsReferenceLine/ChartsXReferenceLine.js +1 -2
- package/modern/ChartsReferenceLine/ChartsYReferenceLine.js +1 -2
- package/modern/ChartsSurface.js +1 -2
- package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +20 -2
- package/modern/ChartsTooltip/ChartsItemTooltipContent.js +31 -1
- package/modern/ChartsTooltip/ChartsTooltipTable.js +8 -8
- package/modern/ChartsTooltip/DefaultChartsAxisTooltipContent.js +7 -8
- package/modern/ChartsTooltip/DefaultChartsItemTooltipContent.js +15 -9
- package/modern/ChartsVoronoiHandler/ChartsVoronoiHandler.js +6 -6
- package/modern/ChartsXAxis/ChartsXAxis.js +3 -4
- package/modern/ChartsYAxis/ChartsYAxis.js +3 -4
- package/modern/Gauge/Gauge.js +1 -2
- package/modern/Gauge/GaugeProvider.js +5 -5
- package/modern/LineChart/AnimatedArea.js +7 -7
- package/modern/LineChart/AnimatedLine.js +8 -7
- package/modern/LineChart/AreaElement.js +4 -1
- package/modern/LineChart/AreaPlot.js +7 -1
- package/modern/LineChart/LineChart.js +40 -100
- package/modern/LineChart/LineElement.js +4 -1
- package/modern/LineChart/LineHighlightPlot.js +4 -1
- package/modern/LineChart/LinePlot.js +7 -1
- package/modern/LineChart/MarkPlot.js +5 -5
- package/modern/LineChart/getColor.js +25 -0
- package/modern/PieChart/PieChart.js +40 -100
- package/modern/PieChart/PiePlot.js +27 -8
- package/modern/PieChart/formatter.js +4 -2
- package/modern/PieChart/getColor.js +5 -0
- package/modern/PieChart/getPieCoordinates.js +19 -0
- package/modern/PieChart/index.js +2 -1
- package/modern/ResponsiveChartContainer/ResponsiveChartContainer.js +34 -2
- package/modern/ScatterChart/Scatter.js +6 -3
- package/modern/ScatterChart/ScatterChart.js +95 -127
- package/modern/ScatterChart/ScatterPlot.js +10 -0
- package/modern/ScatterChart/getColor.js +42 -0
- package/modern/SparkLineChart/SparkLineChart.js +16 -2
- package/modern/context/CartesianContextProvider.js +23 -8
- package/modern/context/ZAxisContextProvider.js +89 -0
- package/modern/context/index.js +1 -1
- package/modern/hooks/index.js +4 -1
- package/modern/hooks/useAxisEvents.js +7 -6
- package/modern/hooks/useChartId.js +8 -0
- package/modern/hooks/useSeries.js +64 -0
- package/modern/hooks/useSvgRef.js +9 -0
- package/modern/index.js +1 -1
- package/modern/internals/colorGetter.js +22 -0
- package/modern/internals/colorScale.js +16 -0
- package/modern/internals/components/ChartsAxesGradients/ChartsAxesGradients.js +95 -0
- package/modern/internals/components/ChartsAxesGradients/ChartsContinuousGradient.js +55 -0
- package/modern/internals/components/ChartsAxesGradients/ChartsPiecewiseGradient.js +40 -0
- package/modern/internals/components/ChartsAxesGradients/index.js +1 -0
- package/modern/models/colorMapping.js +1 -0
- package/modern/models/seriesType/index.js +6 -1
- package/modern/models/z-axis.js +1 -0
- package/package.json +3 -5
|
@@ -7,13 +7,12 @@ import { useSlotProps } from '@mui/base/utils';
|
|
|
7
7
|
import { unstable_composeClasses as composeClasses } from '@mui/utils';
|
|
8
8
|
import { useThemeProps, useTheme } from '@mui/material/styles';
|
|
9
9
|
import { CartesianContext } from '../context/CartesianContextProvider';
|
|
10
|
-
import { DrawingContext } from '../context/DrawingProvider';
|
|
11
10
|
import { useTicks } from '../hooks/useTicks';
|
|
11
|
+
import { useDrawingArea } from '../hooks/useDrawingArea';
|
|
12
12
|
import { AxisRoot } from '../internals/components/AxisSharedComponents';
|
|
13
13
|
import { ChartsText } from '../ChartsText';
|
|
14
14
|
import { getAxisUtilityClass } from '../ChartsAxis/axisClasses';
|
|
15
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
16
|
-
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
15
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
17
16
|
const useUtilityClasses = ownerState => {
|
|
18
17
|
const {
|
|
19
18
|
classes,
|
|
@@ -94,7 +93,7 @@ function ChartsYAxis(inProps) {
|
|
|
94
93
|
top,
|
|
95
94
|
width,
|
|
96
95
|
height
|
|
97
|
-
} =
|
|
96
|
+
} = useDrawingArea();
|
|
98
97
|
const tickSize = disableTicks ? 4 : tickSizeProp;
|
|
99
98
|
const yTicks = useTicks({
|
|
100
99
|
scale: yScale,
|
package/modern/Gauge/Gauge.js
CHANGED
|
@@ -9,8 +9,7 @@ import { GaugeValueArc } from './GaugeValueArc';
|
|
|
9
9
|
import { GaugeReferenceArc } from './GaugeReferenceArc';
|
|
10
10
|
import { getGaugeUtilityClass } from './gaugeClasses';
|
|
11
11
|
import { GaugeValueText } from './GaugeValueText';
|
|
12
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
-
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
12
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
13
|
const useUtilityClasses = props => {
|
|
15
14
|
const {
|
|
16
15
|
classes
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// @ignore - do not document.
|
|
2
2
|
import * as React from 'react';
|
|
3
|
-
import { DrawingContext } from '../context/DrawingProvider';
|
|
4
3
|
import { getPercentageValue } from '../internals/utils';
|
|
5
4
|
import { getArcRatios, getAvailableRadius } from './utils';
|
|
5
|
+
import { useDrawingArea } from '../hooks/useDrawingArea';
|
|
6
6
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
7
|
export const GaugeContext = /*#__PURE__*/React.createContext({
|
|
8
8
|
value: null,
|
|
@@ -36,11 +36,11 @@ export function GaugeProvider(props) {
|
|
|
36
36
|
children
|
|
37
37
|
} = props;
|
|
38
38
|
const {
|
|
39
|
-
|
|
40
|
-
height,
|
|
39
|
+
left,
|
|
41
40
|
top,
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
width,
|
|
42
|
+
height
|
|
43
|
+
} = useDrawingArea();
|
|
44
44
|
const ratios = getArcRatios(startAngle, endAngle);
|
|
45
45
|
const innerCx = cxParam ? getPercentageValue(cxParam, width) : ratios.cx * width;
|
|
46
46
|
const innerCy = cyParam ? getPercentageValue(cyParam, height) : ratios.cy * height;
|
|
@@ -7,10 +7,9 @@ import { styled } from '@mui/material/styles';
|
|
|
7
7
|
import { color as d3Color } from 'd3-color';
|
|
8
8
|
import { animated, useSpring } from '@react-spring/web';
|
|
9
9
|
import { useAnimatedPath } from '../internals/useAnimatedPath';
|
|
10
|
-
import { DrawingContext } from '../context/DrawingProvider';
|
|
11
10
|
import { cleanId } from '../internals/utils';
|
|
12
|
-
import {
|
|
13
|
-
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
11
|
+
import { useChartId, useDrawingArea } from '../hooks';
|
|
12
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
13
|
export const AreaElementPath = styled(animated.path, {
|
|
15
14
|
name: 'MuiAreaElement',
|
|
16
15
|
slot: 'Root',
|
|
@@ -19,7 +18,7 @@ export const AreaElementPath = styled(animated.path, {
|
|
|
19
18
|
ownerState
|
|
20
19
|
}) => ({
|
|
21
20
|
stroke: 'none',
|
|
22
|
-
fill: ownerState.isHighlighted
|
|
21
|
+
fill: ownerState.gradientId && `url(#${ownerState.gradientId})` || ownerState.isHighlighted && d3Color(ownerState.color).brighter(1).formatHex() || d3Color(ownerState.color).brighter(0.5).formatHex(),
|
|
23
22
|
transition: 'opacity 0.2s ease-in, fill 0.2s ease-in',
|
|
24
23
|
opacity: ownerState.isFaded ? 0.3 : 1
|
|
25
24
|
}));
|
|
@@ -46,9 +45,9 @@ function AnimatedArea(props) {
|
|
|
46
45
|
right,
|
|
47
46
|
bottom,
|
|
48
47
|
width,
|
|
49
|
-
height
|
|
50
|
-
|
|
51
|
-
|
|
48
|
+
height
|
|
49
|
+
} = useDrawingArea();
|
|
50
|
+
const chartId = useChartId();
|
|
52
51
|
const path = useAnimatedPath(d, skipAnimation);
|
|
53
52
|
const {
|
|
54
53
|
animatedWidth
|
|
@@ -90,6 +89,7 @@ process.env.NODE_ENV !== "production" ? AnimatedArea.propTypes = {
|
|
|
90
89
|
ownerState: PropTypes.shape({
|
|
91
90
|
classes: PropTypes.object,
|
|
92
91
|
color: PropTypes.string.isRequired,
|
|
92
|
+
gradientId: PropTypes.string,
|
|
93
93
|
id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
|
|
94
94
|
isFaded: PropTypes.bool.isRequired,
|
|
95
95
|
isHighlighted: PropTypes.bool.isRequired
|
|
@@ -7,10 +7,10 @@ import { animated, useSpring } from '@react-spring/web';
|
|
|
7
7
|
import { color as d3Color } from 'd3-color';
|
|
8
8
|
import { styled } from '@mui/material/styles';
|
|
9
9
|
import { useAnimatedPath } from '../internals/useAnimatedPath';
|
|
10
|
-
import { DrawingContext } from '../context/DrawingProvider';
|
|
11
10
|
import { cleanId } from '../internals/utils';
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
11
|
+
import { useChartId } from '../hooks/useChartId';
|
|
12
|
+
import { useDrawingArea } from '../hooks/useDrawingArea';
|
|
13
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
14
|
export const LineElementPath = styled(animated.path, {
|
|
15
15
|
name: 'MuiLineElement',
|
|
16
16
|
slot: 'Root',
|
|
@@ -21,7 +21,7 @@ export const LineElementPath = styled(animated.path, {
|
|
|
21
21
|
strokeWidth: 2,
|
|
22
22
|
strokeLinejoin: 'round',
|
|
23
23
|
fill: 'none',
|
|
24
|
-
stroke: ownerState.isHighlighted
|
|
24
|
+
stroke: ownerState.gradientId && `url(#${ownerState.gradientId})` || ownerState.isHighlighted && d3Color(ownerState.color).brighter(0.5).formatHex() || ownerState.color,
|
|
25
25
|
transition: 'opacity 0.2s ease-in, stroke 0.2s ease-in',
|
|
26
26
|
opacity: ownerState.isFaded ? 0.3 : 1
|
|
27
27
|
}));
|
|
@@ -48,9 +48,9 @@ function AnimatedLine(props) {
|
|
|
48
48
|
bottom,
|
|
49
49
|
width,
|
|
50
50
|
height,
|
|
51
|
-
right
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
right
|
|
52
|
+
} = useDrawingArea();
|
|
53
|
+
const chartId = useChartId();
|
|
54
54
|
const path = useAnimatedPath(d, skipAnimation);
|
|
55
55
|
const {
|
|
56
56
|
animatedWidth
|
|
@@ -92,6 +92,7 @@ process.env.NODE_ENV !== "production" ? AnimatedLine.propTypes = {
|
|
|
92
92
|
ownerState: PropTypes.shape({
|
|
93
93
|
classes: PropTypes.object,
|
|
94
94
|
color: PropTypes.string.isRequired,
|
|
95
|
+
gradientId: PropTypes.string,
|
|
95
96
|
id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
|
|
96
97
|
isFaded: PropTypes.bool.isRequired,
|
|
97
98
|
isHighlighted: PropTypes.bool.isRequired
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
|
-
const _excluded = ["id", "classes", "color", "highlightScope", "slots", "slotProps", "onClick"];
|
|
3
|
+
const _excluded = ["id", "classes", "color", "gradientId", "highlightScope", "slots", "slotProps", "onClick"];
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import PropTypes from 'prop-types';
|
|
6
6
|
import composeClasses from '@mui/utils/composeClasses';
|
|
@@ -42,6 +42,7 @@ function AreaElement(props) {
|
|
|
42
42
|
id,
|
|
43
43
|
classes: innerClasses,
|
|
44
44
|
color,
|
|
45
|
+
gradientId,
|
|
45
46
|
highlightScope,
|
|
46
47
|
slots,
|
|
47
48
|
slotProps,
|
|
@@ -64,6 +65,7 @@ function AreaElement(props) {
|
|
|
64
65
|
id,
|
|
65
66
|
classes: innerClasses,
|
|
66
67
|
color,
|
|
68
|
+
gradientId,
|
|
67
69
|
isFaded,
|
|
68
70
|
isHighlighted
|
|
69
71
|
};
|
|
@@ -92,6 +94,7 @@ process.env.NODE_ENV !== "production" ? AreaElement.propTypes = {
|
|
|
92
94
|
classes: PropTypes.object,
|
|
93
95
|
color: PropTypes.string.isRequired,
|
|
94
96
|
d: PropTypes.string.isRequired,
|
|
97
|
+
gradientId: PropTypes.string,
|
|
95
98
|
highlightScope: PropTypes.shape({
|
|
96
99
|
faded: PropTypes.oneOf(['global', 'none', 'series']),
|
|
97
100
|
highlighted: PropTypes.oneOf(['item', 'none', 'series'])
|
|
@@ -10,6 +10,7 @@ import { AreaElement } from './AreaElement';
|
|
|
10
10
|
import { getValueToPositionMapper } from '../hooks/useScale';
|
|
11
11
|
import getCurveFactory from '../internals/getCurve';
|
|
12
12
|
import { DEFAULT_X_AXIS_KEY } from '../constants';
|
|
13
|
+
import { useChartGradient } from '../internals/components/ChartsAxesGradients';
|
|
13
14
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
15
|
const useAggregatedData = () => {
|
|
15
16
|
const seriesData = React.useContext(SeriesContext).line;
|
|
@@ -43,6 +44,7 @@ const useAggregatedData = () => {
|
|
|
43
44
|
const xScale = getValueToPositionMapper(xAxis[xAxisKey].scale);
|
|
44
45
|
const yScale = yAxis[yAxisKey].scale;
|
|
45
46
|
const xData = xAxis[xAxisKey].data;
|
|
47
|
+
const gradientUsed = yAxis[yAxisKey].colorScale && [yAxisKey, 'y'] || xAxis[xAxisKey].colorScale && [xAxisKey, 'x'] || undefined;
|
|
46
48
|
if (process.env.NODE_ENV !== 'production') {
|
|
47
49
|
if (xData === undefined) {
|
|
48
50
|
throw new Error(`MUI X Charts: ${xAxisKey === DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : `The x-axis with id "${xAxisKey}"`} should have data property to be able to display a line plot.`);
|
|
@@ -60,6 +62,7 @@ const useAggregatedData = () => {
|
|
|
60
62
|
const d3Data = connectNulls ? formattedData.filter((_, i) => data[i] != null) : formattedData;
|
|
61
63
|
const d = areaPath.curve(curve)(d3Data) || '';
|
|
62
64
|
return _extends({}, series[seriesId], {
|
|
65
|
+
gradientUsed,
|
|
63
66
|
d,
|
|
64
67
|
seriesId
|
|
65
68
|
});
|
|
@@ -86,6 +89,7 @@ function AreaPlot(props) {
|
|
|
86
89
|
skipAnimation
|
|
87
90
|
} = props,
|
|
88
91
|
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
92
|
+
const getGradientId = useChartGradient();
|
|
89
93
|
const completedData = useAggregatedData();
|
|
90
94
|
return /*#__PURE__*/_jsx("g", _extends({}, other, {
|
|
91
95
|
children: completedData.reverse().map(({
|
|
@@ -93,11 +97,13 @@ function AreaPlot(props) {
|
|
|
93
97
|
seriesId,
|
|
94
98
|
color,
|
|
95
99
|
highlightScope,
|
|
96
|
-
area
|
|
100
|
+
area,
|
|
101
|
+
gradientUsed
|
|
97
102
|
}) => !!area && /*#__PURE__*/_jsx(AreaElement, {
|
|
98
103
|
id: seriesId,
|
|
99
104
|
d: d,
|
|
100
105
|
color: color,
|
|
106
|
+
gradientId: gradientUsed && getGradientId(...gradientUsed),
|
|
101
107
|
highlightScope: highlightScope,
|
|
102
108
|
slots: slots,
|
|
103
109
|
slotProps: slotProps,
|
|
@@ -15,8 +15,7 @@ import { ChartsClipPath } from '../ChartsClipPath';
|
|
|
15
15
|
import { LineHighlightPlot } from './LineHighlightPlot';
|
|
16
16
|
import { ChartsGrid } from '../ChartsGrid';
|
|
17
17
|
import { ChartsOnAxisClickHandler } from '../ChartsOnAxisClickHandler';
|
|
18
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
19
|
-
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
18
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
20
19
|
/**
|
|
21
20
|
* Demos:
|
|
22
21
|
*
|
|
@@ -144,30 +143,7 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
|
|
|
144
143
|
* Can be a string (the id of the axis) or an object `ChartsXAxisProps`.
|
|
145
144
|
* @default xAxisIds[0] The id of the first provided axis
|
|
146
145
|
*/
|
|
147
|
-
bottomAxis: PropTypes.oneOfType([PropTypes.
|
|
148
|
-
axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
149
|
-
classes: PropTypes.object,
|
|
150
|
-
disableLine: PropTypes.bool,
|
|
151
|
-
disableTicks: PropTypes.bool,
|
|
152
|
-
fill: PropTypes.string,
|
|
153
|
-
label: PropTypes.string,
|
|
154
|
-
labelFontSize: PropTypes.number,
|
|
155
|
-
labelStyle: PropTypes.object,
|
|
156
|
-
position: PropTypes.oneOf(['bottom', 'top']),
|
|
157
|
-
slotProps: PropTypes.object,
|
|
158
|
-
slots: PropTypes.object,
|
|
159
|
-
stroke: PropTypes.string,
|
|
160
|
-
tickFontSize: PropTypes.number,
|
|
161
|
-
tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
|
|
162
|
-
tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
|
|
163
|
-
tickLabelPlacement: PropTypes.oneOf(['middle', 'tick']),
|
|
164
|
-
tickLabelStyle: PropTypes.object,
|
|
165
|
-
tickMaxStep: PropTypes.number,
|
|
166
|
-
tickMinStep: PropTypes.number,
|
|
167
|
-
tickNumber: PropTypes.number,
|
|
168
|
-
tickPlacement: PropTypes.oneOf(['end', 'extremities', 'middle', 'start']),
|
|
169
|
-
tickSize: PropTypes.number
|
|
170
|
-
}), PropTypes.string]),
|
|
146
|
+
bottomAxis: PropTypes.oneOfType([PropTypes.object, PropTypes.string]),
|
|
171
147
|
children: PropTypes.node,
|
|
172
148
|
className: PropTypes.string,
|
|
173
149
|
/**
|
|
@@ -206,30 +182,7 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
|
|
|
206
182
|
* Can be a string (the id of the axis) or an object `ChartsYAxisProps`.
|
|
207
183
|
* @default yAxisIds[0] The id of the first provided axis
|
|
208
184
|
*/
|
|
209
|
-
leftAxis: PropTypes.oneOfType([PropTypes.
|
|
210
|
-
axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
211
|
-
classes: PropTypes.object,
|
|
212
|
-
disableLine: PropTypes.bool,
|
|
213
|
-
disableTicks: PropTypes.bool,
|
|
214
|
-
fill: PropTypes.string,
|
|
215
|
-
label: PropTypes.string,
|
|
216
|
-
labelFontSize: PropTypes.number,
|
|
217
|
-
labelStyle: PropTypes.object,
|
|
218
|
-
position: PropTypes.oneOf(['left', 'right']),
|
|
219
|
-
slotProps: PropTypes.object,
|
|
220
|
-
slots: PropTypes.object,
|
|
221
|
-
stroke: PropTypes.string,
|
|
222
|
-
tickFontSize: PropTypes.number,
|
|
223
|
-
tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
|
|
224
|
-
tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
|
|
225
|
-
tickLabelPlacement: PropTypes.oneOf(['middle', 'tick']),
|
|
226
|
-
tickLabelStyle: PropTypes.object,
|
|
227
|
-
tickMaxStep: PropTypes.number,
|
|
228
|
-
tickMinStep: PropTypes.number,
|
|
229
|
-
tickNumber: PropTypes.number,
|
|
230
|
-
tickPlacement: PropTypes.oneOf(['end', 'extremities', 'middle', 'start']),
|
|
231
|
-
tickSize: PropTypes.number
|
|
232
|
-
}), PropTypes.string]),
|
|
185
|
+
leftAxis: PropTypes.oneOfType([PropTypes.object, PropTypes.string]),
|
|
233
186
|
/**
|
|
234
187
|
* @deprecated Consider using `slotProps.legend` instead.
|
|
235
188
|
*/
|
|
@@ -280,32 +233,10 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
|
|
|
280
233
|
* Can be a string (the id of the axis) or an object `ChartsYAxisProps`.
|
|
281
234
|
* @default null
|
|
282
235
|
*/
|
|
283
|
-
rightAxis: PropTypes.oneOfType([PropTypes.
|
|
284
|
-
axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
285
|
-
classes: PropTypes.object,
|
|
286
|
-
disableLine: PropTypes.bool,
|
|
287
|
-
disableTicks: PropTypes.bool,
|
|
288
|
-
fill: PropTypes.string,
|
|
289
|
-
label: PropTypes.string,
|
|
290
|
-
labelFontSize: PropTypes.number,
|
|
291
|
-
labelStyle: PropTypes.object,
|
|
292
|
-
position: PropTypes.oneOf(['left', 'right']),
|
|
293
|
-
slotProps: PropTypes.object,
|
|
294
|
-
slots: PropTypes.object,
|
|
295
|
-
stroke: PropTypes.string,
|
|
296
|
-
tickFontSize: PropTypes.number,
|
|
297
|
-
tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
|
|
298
|
-
tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
|
|
299
|
-
tickLabelPlacement: PropTypes.oneOf(['middle', 'tick']),
|
|
300
|
-
tickLabelStyle: PropTypes.object,
|
|
301
|
-
tickMaxStep: PropTypes.number,
|
|
302
|
-
tickMinStep: PropTypes.number,
|
|
303
|
-
tickNumber: PropTypes.number,
|
|
304
|
-
tickPlacement: PropTypes.oneOf(['end', 'extremities', 'middle', 'start']),
|
|
305
|
-
tickSize: PropTypes.number
|
|
306
|
-
}), PropTypes.string]),
|
|
236
|
+
rightAxis: PropTypes.oneOfType([PropTypes.object, PropTypes.string]),
|
|
307
237
|
/**
|
|
308
238
|
* The series to display in the line chart.
|
|
239
|
+
* An array of [[LineSeriesType]] objects.
|
|
309
240
|
*/
|
|
310
241
|
series: PropTypes.arrayOf(PropTypes.object).isRequired,
|
|
311
242
|
/**
|
|
@@ -343,30 +274,7 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
|
|
|
343
274
|
* Can be a string (the id of the axis) or an object `ChartsXAxisProps`.
|
|
344
275
|
* @default null
|
|
345
276
|
*/
|
|
346
|
-
topAxis: PropTypes.oneOfType([PropTypes.
|
|
347
|
-
axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
348
|
-
classes: PropTypes.object,
|
|
349
|
-
disableLine: PropTypes.bool,
|
|
350
|
-
disableTicks: PropTypes.bool,
|
|
351
|
-
fill: PropTypes.string,
|
|
352
|
-
label: PropTypes.string,
|
|
353
|
-
labelFontSize: PropTypes.number,
|
|
354
|
-
labelStyle: PropTypes.object,
|
|
355
|
-
position: PropTypes.oneOf(['bottom', 'top']),
|
|
356
|
-
slotProps: PropTypes.object,
|
|
357
|
-
slots: PropTypes.object,
|
|
358
|
-
stroke: PropTypes.string,
|
|
359
|
-
tickFontSize: PropTypes.number,
|
|
360
|
-
tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
|
|
361
|
-
tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
|
|
362
|
-
tickLabelPlacement: PropTypes.oneOf(['middle', 'tick']),
|
|
363
|
-
tickLabelStyle: PropTypes.object,
|
|
364
|
-
tickMaxStep: PropTypes.number,
|
|
365
|
-
tickMinStep: PropTypes.number,
|
|
366
|
-
tickNumber: PropTypes.number,
|
|
367
|
-
tickPlacement: PropTypes.oneOf(['end', 'extremities', 'middle', 'start']),
|
|
368
|
-
tickSize: PropTypes.number
|
|
369
|
-
}), PropTypes.string]),
|
|
277
|
+
topAxis: PropTypes.oneOfType([PropTypes.object, PropTypes.string]),
|
|
370
278
|
viewBox: PropTypes.shape({
|
|
371
279
|
height: PropTypes.number,
|
|
372
280
|
width: PropTypes.number,
|
|
@@ -379,11 +287,27 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
|
|
|
379
287
|
width: PropTypes.number,
|
|
380
288
|
/**
|
|
381
289
|
* The configuration of the x-axes.
|
|
382
|
-
* If not provided, a default axis config is used
|
|
290
|
+
* If not provided, a default axis config is used.
|
|
291
|
+
* An array of [[AxisConfig]] objects.
|
|
383
292
|
*/
|
|
384
293
|
xAxis: PropTypes.arrayOf(PropTypes.shape({
|
|
385
294
|
axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
386
295
|
classes: PropTypes.object,
|
|
296
|
+
colorMap: PropTypes.oneOfType([PropTypes.shape({
|
|
297
|
+
color: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string.isRequired), PropTypes.func]).isRequired,
|
|
298
|
+
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
299
|
+
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
300
|
+
type: PropTypes.oneOf(['continuous']).isRequired
|
|
301
|
+
}), PropTypes.shape({
|
|
302
|
+
colors: PropTypes.arrayOf(PropTypes.string).isRequired,
|
|
303
|
+
thresholds: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired).isRequired,
|
|
304
|
+
type: PropTypes.oneOf(['piecewise']).isRequired
|
|
305
|
+
}), PropTypes.shape({
|
|
306
|
+
colors: PropTypes.arrayOf(PropTypes.string).isRequired,
|
|
307
|
+
type: PropTypes.oneOf(['ordinal']).isRequired,
|
|
308
|
+
unknownColor: PropTypes.string,
|
|
309
|
+
values: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired)
|
|
310
|
+
})]),
|
|
387
311
|
data: PropTypes.array,
|
|
388
312
|
dataKey: PropTypes.string,
|
|
389
313
|
disableLine: PropTypes.bool,
|
|
@@ -416,11 +340,27 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
|
|
|
416
340
|
})),
|
|
417
341
|
/**
|
|
418
342
|
* The configuration of the y-axes.
|
|
419
|
-
* If not provided, a default axis config is used
|
|
343
|
+
* If not provided, a default axis config is used.
|
|
344
|
+
* An array of [[AxisConfig]] objects.
|
|
420
345
|
*/
|
|
421
346
|
yAxis: PropTypes.arrayOf(PropTypes.shape({
|
|
422
347
|
axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
423
348
|
classes: PropTypes.object,
|
|
349
|
+
colorMap: PropTypes.oneOfType([PropTypes.shape({
|
|
350
|
+
color: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string.isRequired), PropTypes.func]).isRequired,
|
|
351
|
+
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
352
|
+
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
353
|
+
type: PropTypes.oneOf(['continuous']).isRequired
|
|
354
|
+
}), PropTypes.shape({
|
|
355
|
+
colors: PropTypes.arrayOf(PropTypes.string).isRequired,
|
|
356
|
+
thresholds: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired).isRequired,
|
|
357
|
+
type: PropTypes.oneOf(['piecewise']).isRequired
|
|
358
|
+
}), PropTypes.shape({
|
|
359
|
+
colors: PropTypes.arrayOf(PropTypes.string).isRequired,
|
|
360
|
+
type: PropTypes.oneOf(['ordinal']).isRequired,
|
|
361
|
+
unknownColor: PropTypes.string,
|
|
362
|
+
values: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired)
|
|
363
|
+
})]),
|
|
424
364
|
data: PropTypes.array,
|
|
425
365
|
dataKey: PropTypes.string,
|
|
426
366
|
disableLine: PropTypes.bool,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
|
-
const _excluded = ["id", "classes", "color", "highlightScope", "slots", "slotProps", "onClick"];
|
|
3
|
+
const _excluded = ["id", "classes", "color", "gradientId", "highlightScope", "slots", "slotProps", "onClick"];
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import PropTypes from 'prop-types';
|
|
6
6
|
import composeClasses from '@mui/utils/composeClasses';
|
|
@@ -42,6 +42,7 @@ function LineElement(props) {
|
|
|
42
42
|
id,
|
|
43
43
|
classes: innerClasses,
|
|
44
44
|
color,
|
|
45
|
+
gradientId,
|
|
45
46
|
highlightScope,
|
|
46
47
|
slots,
|
|
47
48
|
slotProps,
|
|
@@ -64,6 +65,7 @@ function LineElement(props) {
|
|
|
64
65
|
id,
|
|
65
66
|
classes: innerClasses,
|
|
66
67
|
color,
|
|
68
|
+
gradientId,
|
|
67
69
|
isFaded,
|
|
68
70
|
isHighlighted
|
|
69
71
|
};
|
|
@@ -92,6 +94,7 @@ process.env.NODE_ENV !== "production" ? LineElement.propTypes = {
|
|
|
92
94
|
classes: PropTypes.object,
|
|
93
95
|
color: PropTypes.string.isRequired,
|
|
94
96
|
d: PropTypes.string.isRequired,
|
|
97
|
+
gradientId: PropTypes.string,
|
|
95
98
|
highlightScope: PropTypes.shape({
|
|
96
99
|
faded: PropTypes.oneOf(['global', 'none', 'series']),
|
|
97
100
|
highlighted: PropTypes.oneOf(['item', 'none', 'series'])
|
|
@@ -9,6 +9,7 @@ import { LineHighlightElement } from './LineHighlightElement';
|
|
|
9
9
|
import { getValueToPositionMapper } from '../hooks/useScale';
|
|
10
10
|
import { InteractionContext } from '../context/InteractionProvider';
|
|
11
11
|
import { DEFAULT_X_AXIS_KEY } from '../constants';
|
|
12
|
+
import getColor from './getColor';
|
|
12
13
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
14
|
/**
|
|
14
15
|
* Demos:
|
|
@@ -74,9 +75,11 @@ function LineHighlightPlot(props) {
|
|
|
74
75
|
}
|
|
75
76
|
const x = xScale(xData[highlightedIndex]);
|
|
76
77
|
const y = yScale(stackedData[highlightedIndex][1]); // This should not be undefined since y should not be a band scale
|
|
78
|
+
|
|
79
|
+
const colorGetter = getColor(series[seriesId], xAxis[xAxisKey], yAxis[yAxisKey]);
|
|
77
80
|
return /*#__PURE__*/_jsx(Element, _extends({
|
|
78
81
|
id: seriesId,
|
|
79
|
-
color:
|
|
82
|
+
color: colorGetter(highlightedIndex),
|
|
80
83
|
x: x,
|
|
81
84
|
y: y
|
|
82
85
|
}, slotProps?.lineHighlight), `${seriesId}`);
|
|
@@ -10,6 +10,7 @@ import { LineElement } from './LineElement';
|
|
|
10
10
|
import { getValueToPositionMapper } from '../hooks/useScale';
|
|
11
11
|
import getCurveFactory from '../internals/getCurve';
|
|
12
12
|
import { DEFAULT_X_AXIS_KEY } from '../constants';
|
|
13
|
+
import { useChartGradient } from '../internals/components/ChartsAxesGradients';
|
|
13
14
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
15
|
const useAggregatedData = () => {
|
|
15
16
|
const seriesData = React.useContext(SeriesContext).line;
|
|
@@ -43,6 +44,7 @@ const useAggregatedData = () => {
|
|
|
43
44
|
const xScale = getValueToPositionMapper(xAxis[xAxisKey].scale);
|
|
44
45
|
const yScale = yAxis[yAxisKey].scale;
|
|
45
46
|
const xData = xAxis[xAxisKey].data;
|
|
47
|
+
const gradientUsed = yAxis[yAxisKey].colorScale && [yAxisKey, 'y'] || xAxis[xAxisKey].colorScale && [xAxisKey, 'x'] || undefined;
|
|
46
48
|
if (process.env.NODE_ENV !== 'production') {
|
|
47
49
|
if (xData === undefined) {
|
|
48
50
|
throw new Error(`MUI X Charts: ${xAxisKey === DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : `The x-axis with id "${xAxisKey}"`} should have data property to be able to display a line plot.`);
|
|
@@ -59,6 +61,7 @@ const useAggregatedData = () => {
|
|
|
59
61
|
const d3Data = connectNulls ? formattedData.filter((_, i) => data[i] != null) : formattedData;
|
|
60
62
|
const d = linePath.curve(getCurveFactory(series[seriesId].curve))(d3Data) || '';
|
|
61
63
|
return _extends({}, series[seriesId], {
|
|
64
|
+
gradientUsed,
|
|
62
65
|
d,
|
|
63
66
|
seriesId
|
|
64
67
|
});
|
|
@@ -84,18 +87,21 @@ function LinePlot(props) {
|
|
|
84
87
|
onItemClick
|
|
85
88
|
} = props,
|
|
86
89
|
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
90
|
+
const getGradientId = useChartGradient();
|
|
87
91
|
const completedData = useAggregatedData();
|
|
88
92
|
return /*#__PURE__*/_jsx("g", _extends({}, other, {
|
|
89
93
|
children: completedData.map(({
|
|
90
94
|
d,
|
|
91
95
|
seriesId,
|
|
92
96
|
color,
|
|
93
|
-
highlightScope
|
|
97
|
+
highlightScope,
|
|
98
|
+
gradientUsed
|
|
94
99
|
}) => {
|
|
95
100
|
return /*#__PURE__*/_jsx(LineElement, {
|
|
96
101
|
id: seriesId,
|
|
97
102
|
d: d,
|
|
98
103
|
color: color,
|
|
104
|
+
gradientId: gradientUsed && getGradientId(...gradientUsed),
|
|
99
105
|
highlightScope: highlightScope,
|
|
100
106
|
skipAnimation: skipAnimation,
|
|
101
107
|
slots: slots,
|
|
@@ -7,9 +7,10 @@ import { SeriesContext } from '../context/SeriesContextProvider';
|
|
|
7
7
|
import { CartesianContext } from '../context/CartesianContextProvider';
|
|
8
8
|
import { MarkElement } from './MarkElement';
|
|
9
9
|
import { getValueToPositionMapper } from '../hooks/useScale';
|
|
10
|
+
import { useChartId } from '../hooks/useChartId';
|
|
10
11
|
import { DEFAULT_X_AXIS_KEY } from '../constants';
|
|
11
|
-
import { DrawingContext } from '../context/DrawingProvider';
|
|
12
12
|
import { cleanId } from '../internals/utils';
|
|
13
|
+
import getColor from './getColor';
|
|
13
14
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
15
|
/**
|
|
15
16
|
* Demos:
|
|
@@ -31,9 +32,7 @@ function MarkPlot(props) {
|
|
|
31
32
|
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
32
33
|
const seriesData = React.useContext(SeriesContext).line;
|
|
33
34
|
const axisData = React.useContext(CartesianContext);
|
|
34
|
-
const
|
|
35
|
-
chartId
|
|
36
|
-
} = React.useContext(DrawingContext);
|
|
35
|
+
const chartId = useChartId();
|
|
37
36
|
const Mark = slots?.mark ?? MarkElement;
|
|
38
37
|
if (seriesData === undefined) {
|
|
39
38
|
return null;
|
|
@@ -87,6 +86,7 @@ function MarkPlot(props) {
|
|
|
87
86
|
}
|
|
88
87
|
const clipId = cleanId(`${chartId}-${seriesId}-line-clip`); // We assume that if displaying line mark, the line will also be rendered
|
|
89
88
|
|
|
89
|
+
const colorGetter = getColor(series[seriesId], xAxis[xAxisKey], yAxis[yAxisKey]);
|
|
90
90
|
return /*#__PURE__*/_jsx("g", {
|
|
91
91
|
clipPath: `url(#${clipId})`,
|
|
92
92
|
children: xData?.map((x, index) => {
|
|
@@ -135,7 +135,7 @@ function MarkPlot(props) {
|
|
|
135
135
|
id: seriesId,
|
|
136
136
|
dataIndex: index,
|
|
137
137
|
shape: "circle",
|
|
138
|
-
color:
|
|
138
|
+
color: colorGetter(index),
|
|
139
139
|
x: x,
|
|
140
140
|
y: y // Don't know why TS doesn't get from the filter that y can't be null
|
|
141
141
|
,
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export default function getColor(series, xAxis, yAxis) {
|
|
2
|
+
const yColorScale = yAxis.colorScale;
|
|
3
|
+
const xColorScale = xAxis.colorScale;
|
|
4
|
+
if (yColorScale) {
|
|
5
|
+
return dataIndex => {
|
|
6
|
+
const value = series.data[dataIndex];
|
|
7
|
+
const color = value === null ? series.color : yColorScale(value);
|
|
8
|
+
if (color === null) {
|
|
9
|
+
return series.color;
|
|
10
|
+
}
|
|
11
|
+
return color;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
if (xColorScale) {
|
|
15
|
+
return dataIndex => {
|
|
16
|
+
const value = xAxis.data?.[dataIndex];
|
|
17
|
+
const color = value === null ? series.color : xColorScale(value);
|
|
18
|
+
if (color === null) {
|
|
19
|
+
return series.color;
|
|
20
|
+
}
|
|
21
|
+
return color;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
return () => series.color;
|
|
25
|
+
}
|