@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
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { SeriesContext } from '../context/SeriesContextProvider';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Get access to the internal state of series.
|
|
6
|
+
* Structured by type of series:
|
|
7
|
+
* { seriesType?: { series: { id1: precessedValue, ... }, seriesOrder: [id1, ...] } }
|
|
8
|
+
* @returns FormattedSeries series
|
|
9
|
+
*/
|
|
10
|
+
export function useSeries() {
|
|
11
|
+
const series = React.useContext(SeriesContext);
|
|
12
|
+
if (series === undefined) {
|
|
13
|
+
throw new Error(['MUI X: Could not find the series ref context.', 'It looks like you rendered your component outside of a ChartsContainer parent component.'].join('\n'));
|
|
14
|
+
}
|
|
15
|
+
return series;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Get access to the internal state of pie series.
|
|
20
|
+
* The returned object contains:
|
|
21
|
+
* - series: a mapping from ids to series attributes.
|
|
22
|
+
* - seriesOrder: the array of series ids.
|
|
23
|
+
* @returns { series: Record<SeriesId, DefaultizedPieSeriesType>; seriesOrder: SeriesId[]; } | undefined pieSeries
|
|
24
|
+
*/
|
|
25
|
+
export function usePieSeries() {
|
|
26
|
+
const series = useSeries();
|
|
27
|
+
return React.useMemo(() => series.pie, [series.pie]);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Get access to the internal state of line series.
|
|
32
|
+
* The returned object contains:
|
|
33
|
+
* - series: a mapping from ids to series attributes.
|
|
34
|
+
* - seriesOrder: the array of series ids.
|
|
35
|
+
* @returns { series: Record<SeriesId, DefaultizedLineSeriesType>; seriesOrder: SeriesId[]; } | undefined lineSeries
|
|
36
|
+
*/
|
|
37
|
+
export function useLineSeries() {
|
|
38
|
+
const series = useSeries();
|
|
39
|
+
return React.useMemo(() => series.line, [series.line]);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Get access to the internal state of bar series.
|
|
44
|
+
* The returned object contains:
|
|
45
|
+
* - series: a mapping from ids to series attributes.
|
|
46
|
+
* - seriesOrder: the array of series ids.
|
|
47
|
+
* @returns { series: Record<SeriesId, DefaultizedBarSeriesType>; seriesOrder: SeriesId[]; } | undefined barSeries
|
|
48
|
+
*/
|
|
49
|
+
export function useBarSeries() {
|
|
50
|
+
const series = useSeries();
|
|
51
|
+
return React.useMemo(() => series.bar, [series.bar]);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Get access to the internal state of scatter series.
|
|
56
|
+
* The returned object contains:
|
|
57
|
+
* - series: a mapping from ids to series attributes.
|
|
58
|
+
* - seriesOrder: the array of series ids.
|
|
59
|
+
* @returns { series: Record<SeriesId, DefaultizedScatterSeriesType>; seriesOrder: SeriesId[]; } | undefined scatterSeries
|
|
60
|
+
*/
|
|
61
|
+
export function useScatterSeries() {
|
|
62
|
+
const series = useSeries();
|
|
63
|
+
return React.useMemo(() => series.scatter, [series.scatter]);
|
|
64
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { SvgContext } from '../context/DrawingProvider';
|
|
3
|
+
export function useSvgRef() {
|
|
4
|
+
const svgRef = React.useContext(SvgContext);
|
|
5
|
+
if (svgRef === undefined) {
|
|
6
|
+
throw new Error(['MUI X: Could not find the svg ref context.', 'It looks like you rendered your component outside of a ChartsContainer parent component.'].join('\n'));
|
|
7
|
+
}
|
|
8
|
+
return svgRef;
|
|
9
|
+
}
|
package/modern/index.js
CHANGED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import getBarColor from '../BarChart/getColor';
|
|
2
|
+
import getLineColor from '../LineChart/getColor';
|
|
3
|
+
import getScatterColor from '../ScatterChart/getColor';
|
|
4
|
+
import getPieColor from '../PieChart/getColor';
|
|
5
|
+
function getColor(series, xAxis, yAxis, zAxis) {
|
|
6
|
+
if (xAxis !== undefined && yAxis !== undefined) {
|
|
7
|
+
if (series.type === 'bar') {
|
|
8
|
+
return getBarColor(series, xAxis, yAxis);
|
|
9
|
+
}
|
|
10
|
+
if (series.type === 'line') {
|
|
11
|
+
return getLineColor(series, xAxis, yAxis);
|
|
12
|
+
}
|
|
13
|
+
if (series.type === 'scatter') {
|
|
14
|
+
return getScatterColor(series, xAxis, yAxis, zAxis);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
if (series.type === 'pie') {
|
|
18
|
+
return getPieColor(series);
|
|
19
|
+
}
|
|
20
|
+
throw Error(`MUI X Charts: getColor called with unexpected arguments for series with id "${series.id}"`);
|
|
21
|
+
}
|
|
22
|
+
export default getColor;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { scaleOrdinal, scaleThreshold, scaleSequential } from 'd3-scale';
|
|
2
|
+
export function getSequentialColorScale(config) {
|
|
3
|
+
if (config.type === 'piecewise') {
|
|
4
|
+
return scaleThreshold(config.thresholds, config.colors);
|
|
5
|
+
}
|
|
6
|
+
return scaleSequential([config.min ?? 0, config.max ?? 100], config.color);
|
|
7
|
+
}
|
|
8
|
+
export function getOrdinalColorScale(config) {
|
|
9
|
+
if (config.values) {
|
|
10
|
+
return scaleOrdinal(config.values, config.colors).unknown(config.unknownColor ?? null);
|
|
11
|
+
}
|
|
12
|
+
return scaleOrdinal(config.colors.map((_, index) => index), config.colors).unknown(config.unknownColor ?? null);
|
|
13
|
+
}
|
|
14
|
+
export function getColorScale(config) {
|
|
15
|
+
return config.type === 'ordinal' ? getOrdinalColorScale(config) : getSequentialColorScale(config);
|
|
16
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { CartesianContext } from '../../../context/CartesianContextProvider';
|
|
3
|
+
import { DrawingContext } from '../../../context/DrawingProvider';
|
|
4
|
+
import { useDrawingArea } from '../../../hooks';
|
|
5
|
+
import ChartsPiecewiseGradient from './ChartsPiecewiseGradient';
|
|
6
|
+
import ChartsContinuousGradient from './ChartsContinuousGradient';
|
|
7
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
8
|
+
export function useChartGradient() {
|
|
9
|
+
const {
|
|
10
|
+
chartId
|
|
11
|
+
} = React.useContext(DrawingContext);
|
|
12
|
+
return React.useCallback((axisId, direction) => `${chartId}-graient-${direction}-${axisId}`, [chartId]);
|
|
13
|
+
}
|
|
14
|
+
export function ChartsAxesGradients() {
|
|
15
|
+
const {
|
|
16
|
+
top,
|
|
17
|
+
height,
|
|
18
|
+
bottom,
|
|
19
|
+
left,
|
|
20
|
+
width,
|
|
21
|
+
right
|
|
22
|
+
} = useDrawingArea();
|
|
23
|
+
const svgHeight = top + height + bottom;
|
|
24
|
+
const svgWidth = left + width + right;
|
|
25
|
+
const getGradientId = useChartGradient();
|
|
26
|
+
const {
|
|
27
|
+
xAxisIds,
|
|
28
|
+
xAxis,
|
|
29
|
+
yAxisIds,
|
|
30
|
+
yAxis
|
|
31
|
+
} = React.useContext(CartesianContext);
|
|
32
|
+
return /*#__PURE__*/_jsxs("defs", {
|
|
33
|
+
children: [yAxisIds.filter(axisId => yAxis[axisId].colorMap !== undefined).map(axisId => {
|
|
34
|
+
const gradientId = getGradientId(axisId, 'y');
|
|
35
|
+
const {
|
|
36
|
+
colorMap,
|
|
37
|
+
scale,
|
|
38
|
+
colorScale,
|
|
39
|
+
reverse
|
|
40
|
+
} = yAxis[axisId];
|
|
41
|
+
if (colorMap?.type === 'piecewise') {
|
|
42
|
+
return /*#__PURE__*/_jsx(ChartsPiecewiseGradient, {
|
|
43
|
+
isReveresed: !reverse,
|
|
44
|
+
scale: scale,
|
|
45
|
+
colorMap: colorMap,
|
|
46
|
+
size: svgHeight,
|
|
47
|
+
gradientId: gradientId,
|
|
48
|
+
direction: "y"
|
|
49
|
+
}, gradientId);
|
|
50
|
+
}
|
|
51
|
+
if (colorMap?.type === 'continuous') {
|
|
52
|
+
return /*#__PURE__*/_jsx(ChartsContinuousGradient, {
|
|
53
|
+
isReveresed: !reverse,
|
|
54
|
+
scale: scale,
|
|
55
|
+
colorScale: colorScale,
|
|
56
|
+
colorMap: colorMap,
|
|
57
|
+
size: svgHeight,
|
|
58
|
+
gradientId: gradientId,
|
|
59
|
+
direction: "y"
|
|
60
|
+
}, gradientId);
|
|
61
|
+
}
|
|
62
|
+
return null;
|
|
63
|
+
}), xAxisIds.filter(axisId => xAxis[axisId].colorMap !== undefined).map(axisId => {
|
|
64
|
+
const gradientId = getGradientId(axisId, 'x');
|
|
65
|
+
const {
|
|
66
|
+
colorMap,
|
|
67
|
+
scale,
|
|
68
|
+
reverse,
|
|
69
|
+
colorScale
|
|
70
|
+
} = xAxis[axisId];
|
|
71
|
+
if (colorMap?.type === 'piecewise') {
|
|
72
|
+
return /*#__PURE__*/_jsx(ChartsPiecewiseGradient, {
|
|
73
|
+
isReveresed: reverse,
|
|
74
|
+
scale: scale,
|
|
75
|
+
colorMap: colorMap,
|
|
76
|
+
size: svgWidth,
|
|
77
|
+
gradientId: gradientId,
|
|
78
|
+
direction: "x"
|
|
79
|
+
}, gradientId);
|
|
80
|
+
}
|
|
81
|
+
if (colorMap?.type === 'continuous') {
|
|
82
|
+
return /*#__PURE__*/_jsx(ChartsContinuousGradient, {
|
|
83
|
+
isReveresed: reverse,
|
|
84
|
+
scale: scale,
|
|
85
|
+
colorScale: colorScale,
|
|
86
|
+
colorMap: colorMap,
|
|
87
|
+
size: svgWidth,
|
|
88
|
+
gradientId: gradientId,
|
|
89
|
+
direction: "x"
|
|
90
|
+
}, gradientId);
|
|
91
|
+
}
|
|
92
|
+
return null;
|
|
93
|
+
})]
|
|
94
|
+
});
|
|
95
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { interpolateDate, interpolateNumber } from 'd3-interpolate';
|
|
3
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
4
|
+
const PX_PRECISION = 10;
|
|
5
|
+
export default function ChartsContinuousGradient(props) {
|
|
6
|
+
const {
|
|
7
|
+
isReveresed,
|
|
8
|
+
gradientId,
|
|
9
|
+
size,
|
|
10
|
+
direction,
|
|
11
|
+
scale,
|
|
12
|
+
colorScale,
|
|
13
|
+
colorMap
|
|
14
|
+
} = props;
|
|
15
|
+
const extremValues = [colorMap.min ?? 0, colorMap.max ?? 100];
|
|
16
|
+
const extremPositions = extremValues.map(scale).filter(p => p !== undefined);
|
|
17
|
+
if (extremPositions.length !== 2) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
const interpolator = typeof extremValues[0] === 'number' ? interpolateNumber(extremValues[0], extremValues[1]) : interpolateDate(extremValues[0], extremValues[1]);
|
|
21
|
+
const numberOfPoints = Math.round((Math.max(...extremPositions) - Math.min(...extremPositions)) / PX_PRECISION);
|
|
22
|
+
const keyPrefix = `${extremValues[0]}-${extremValues[1]}-`;
|
|
23
|
+
return /*#__PURE__*/_jsx("linearGradient", {
|
|
24
|
+
id: gradientId,
|
|
25
|
+
x1: "0",
|
|
26
|
+
x2: "0",
|
|
27
|
+
y1: "0",
|
|
28
|
+
y2: "0",
|
|
29
|
+
[`${direction}${isReveresed ? 1 : 2}`]: `${size}px`,
|
|
30
|
+
gradientUnits: "userSpaceOnUse" // Use the SVG coordinate instead of the component ones.
|
|
31
|
+
,
|
|
32
|
+
children: Array.from({
|
|
33
|
+
length: numberOfPoints + 1
|
|
34
|
+
}, (_, index) => {
|
|
35
|
+
const value = interpolator(index / numberOfPoints);
|
|
36
|
+
if (value === undefined) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
const x = scale(value);
|
|
40
|
+
if (x === undefined) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
const offset = isReveresed ? 1 - x / size : x / size;
|
|
44
|
+
const color = colorScale(value);
|
|
45
|
+
if (color === null) {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
return /*#__PURE__*/_jsx("stop", {
|
|
49
|
+
offset: offset,
|
|
50
|
+
stopColor: color,
|
|
51
|
+
stopOpacity: 1
|
|
52
|
+
}, keyPrefix + index);
|
|
53
|
+
})
|
|
54
|
+
});
|
|
55
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
export default function ChartsPiecewiseGradient(props) {
|
|
4
|
+
const {
|
|
5
|
+
isReveresed,
|
|
6
|
+
gradientId,
|
|
7
|
+
size,
|
|
8
|
+
direction,
|
|
9
|
+
scale,
|
|
10
|
+
colorMap
|
|
11
|
+
} = props;
|
|
12
|
+
return /*#__PURE__*/_jsx("linearGradient", {
|
|
13
|
+
id: gradientId,
|
|
14
|
+
x1: "0",
|
|
15
|
+
x2: "0",
|
|
16
|
+
y1: "0",
|
|
17
|
+
y2: "0",
|
|
18
|
+
[`${direction}${isReveresed ? 1 : 2}`]: `${size}px`,
|
|
19
|
+
gradientUnits: "userSpaceOnUse" // Use the SVG coordinate instead of the component ones.
|
|
20
|
+
,
|
|
21
|
+
children: colorMap.thresholds.map((threshold, index) => {
|
|
22
|
+
const x = scale(threshold);
|
|
23
|
+
if (x === undefined) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
const offset = isReveresed ? 1 - x / size : x / size;
|
|
27
|
+
return /*#__PURE__*/_jsxs(React.Fragment, {
|
|
28
|
+
children: [/*#__PURE__*/_jsx("stop", {
|
|
29
|
+
offset: offset,
|
|
30
|
+
stopColor: colorMap.colors[index],
|
|
31
|
+
stopOpacity: 1
|
|
32
|
+
}), /*#__PURE__*/_jsx("stop", {
|
|
33
|
+
offset: offset,
|
|
34
|
+
stopColor: colorMap.colors[index + 1],
|
|
35
|
+
stopOpacity: 1
|
|
36
|
+
})]
|
|
37
|
+
}, threshold.toString() + index);
|
|
38
|
+
})
|
|
39
|
+
});
|
|
40
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ChartsAxesGradients';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -2,4 +2,9 @@ export * from './line';
|
|
|
2
2
|
export * from './bar';
|
|
3
3
|
export * from './scatter';
|
|
4
4
|
export * from './pie';
|
|
5
|
-
export {
|
|
5
|
+
export function isDefaultizedBarSeries(series) {
|
|
6
|
+
return series.type === 'bar';
|
|
7
|
+
}
|
|
8
|
+
export function isBarSeries(series) {
|
|
9
|
+
return series.type === 'bar';
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mui/x-charts",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.3.1",
|
|
4
4
|
"description": "The community edition of the Charts components (MUI X).",
|
|
5
5
|
"author": "MUI Team",
|
|
6
6
|
"main": "./index.js",
|
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
"homepage": "https://mui.com/x/react-charts/",
|
|
12
12
|
"sideEffects": false,
|
|
13
13
|
"publishConfig": {
|
|
14
|
-
"access": "public"
|
|
14
|
+
"access": "public",
|
|
15
|
+
"directory": "build"
|
|
15
16
|
},
|
|
16
17
|
"keywords": [
|
|
17
18
|
"react",
|
|
@@ -69,9 +70,6 @@
|
|
|
69
70
|
"default": "./esm/*/index.js"
|
|
70
71
|
}
|
|
71
72
|
},
|
|
72
|
-
"setupFiles": [
|
|
73
|
-
"<rootDir>/src/setupTests.js"
|
|
74
|
-
],
|
|
75
73
|
"engines": {
|
|
76
74
|
"node": ">=14.0.0"
|
|
77
75
|
},
|