@mui/x-charts 7.2.0 → 7.3.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 +32 -2
- package/BarChart/BarPlot.js +12 -5
- package/BarChart/getColor.d.ts +3 -0
- package/BarChart/getColor.js +33 -0
- package/CHANGELOG.md +125 -0
- package/ChartContainer/ChartContainer.js +35 -4
- package/ChartsAxis/ChartsAxis.js +4 -4
- package/ChartsClipPath/ChartsClipPath.js +2 -2
- package/ChartsLegend/ChartsLegend.js +2 -2
- package/ChartsTooltip/ChartsAxisTooltipContent.d.ts +4 -1
- package/ChartsTooltip/ChartsAxisTooltipContent.js +7 -2
- package/ChartsTooltip/ChartsItemTooltipContent.d.ts +6 -0
- package/ChartsTooltip/ChartsItemTooltipContent.js +15 -1
- package/ChartsTooltip/DefaultChartsAxisTooltipContent.js +6 -3
- package/ChartsTooltip/DefaultChartsItemTooltipContent.js +13 -4
- package/ChartsTooltip/utils.d.ts +5 -1
- package/ChartsVoronoiHandler/ChartsVoronoiHandler.js +6 -6
- package/ChartsXAxis/ChartsXAxis.js +2 -2
- package/ChartsYAxis/ChartsYAxis.js +2 -2
- package/Gauge/GaugeProvider.js +5 -5
- package/LineChart/AnimatedArea.js +6 -5
- package/LineChart/AnimatedLine.js +7 -5
- package/LineChart/AreaElement.d.ts +1 -0
- package/LineChart/AreaElement.js +4 -1
- package/LineChart/AreaPlot.js +7 -1
- package/LineChart/LineChart.js +32 -2
- package/LineChart/LineElement.d.ts +1 -0
- package/LineChart/LineElement.js +4 -1
- package/LineChart/LineHighlightPlot.js +4 -1
- package/LineChart/LinePlot.js +7 -1
- package/LineChart/MarkPlot.js +5 -5
- package/LineChart/getColor.d.ts +3 -0
- package/LineChart/getColor.js +31 -0
- package/PieChart/PieChart.js +32 -2
- package/PieChart/PiePlot.js +26 -6
- 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 +32 -2
- package/ScatterChart/Scatter.d.ts +1 -0
- package/ScatterChart/Scatter.js +6 -3
- package/ScatterChart/ScatterChart.js +32 -2
- package/ScatterChart/ScatterPlot.js +3 -0
- package/ScatterChart/getColor.d.ts +3 -0
- package/ScatterChart/getColor.js +31 -0
- package/SparkLineChart/SparkLineChart.js +15 -0
- package/context/CartesianContextProvider.d.ts +2 -2
- package/context/CartesianContextProvider.js +23 -8
- package/esm/BarChart/BarChart.js +32 -2
- package/esm/BarChart/BarPlot.js +13 -5
- package/esm/BarChart/getColor.js +27 -0
- package/esm/ChartContainer/ChartContainer.js +36 -4
- package/esm/ChartsAxis/ChartsAxis.js +4 -4
- package/esm/ChartsClipPath/ChartsClipPath.js +2 -2
- package/esm/ChartsLegend/ChartsLegend.js +2 -2
- package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +7 -2
- package/esm/ChartsTooltip/ChartsItemTooltipContent.js +15 -1
- package/esm/ChartsTooltip/DefaultChartsAxisTooltipContent.js +6 -3
- package/esm/ChartsTooltip/DefaultChartsItemTooltipContent.js +13 -4
- package/esm/ChartsVoronoiHandler/ChartsVoronoiHandler.js +6 -6
- package/esm/ChartsXAxis/ChartsXAxis.js +2 -2
- package/esm/ChartsYAxis/ChartsYAxis.js +2 -2
- package/esm/Gauge/GaugeProvider.js +5 -5
- package/esm/LineChart/AnimatedArea.js +6 -5
- package/esm/LineChart/AnimatedLine.js +7 -5
- package/esm/LineChart/AreaElement.js +4 -1
- package/esm/LineChart/AreaPlot.js +7 -1
- package/esm/LineChart/LineChart.js +32 -2
- 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 +32 -2
- package/esm/PieChart/PiePlot.js +26 -6
- 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 +32 -2
- package/esm/ScatterChart/Scatter.js +6 -3
- package/esm/ScatterChart/ScatterChart.js +32 -2
- package/esm/ScatterChart/ScatterPlot.js +3 -0
- package/esm/ScatterChart/getColor.js +25 -0
- package/esm/SparkLineChart/SparkLineChart.js +15 -0
- package/esm/context/CartesianContextProvider.js +23 -8
- 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 +96 -0
- package/esm/internals/components/ChartsAxesGradients/ChartsContinuousGradient.js +55 -0
- package/esm/internals/components/ChartsAxesGradients/ChartsPiecewiseGradient.js +41 -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/hooks/index.d.ts +3 -0
- package/hooks/index.js +65 -1
- package/hooks/useAxisEvents.js +7 -6
- package/hooks/useChartId.d.ts +1 -0
- package/hooks/useChartId.js +16 -0
- 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/index.js +1 -1
- package/internals/colorGetter.d.ts +5 -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 +4 -4
- package/internals/defaultizeValueFormatter.d.ts +5 -5
- package/internals/getScale.d.ts +2 -2
- package/models/axis.d.ts +44 -4
- package/models/colorMapping.d.ts +45 -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/modern/BarChart/BarChart.js +32 -2
- package/modern/BarChart/BarPlot.js +13 -5
- package/modern/BarChart/getColor.js +27 -0
- package/modern/ChartContainer/ChartContainer.js +36 -4
- package/modern/ChartsAxis/ChartsAxis.js +4 -4
- package/modern/ChartsClipPath/ChartsClipPath.js +2 -2
- package/modern/ChartsLegend/ChartsLegend.js +2 -2
- package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +7 -2
- package/modern/ChartsTooltip/ChartsItemTooltipContent.js +15 -1
- package/modern/ChartsTooltip/DefaultChartsAxisTooltipContent.js +6 -3
- package/modern/ChartsTooltip/DefaultChartsItemTooltipContent.js +13 -4
- package/modern/ChartsVoronoiHandler/ChartsVoronoiHandler.js +6 -6
- package/modern/ChartsXAxis/ChartsXAxis.js +2 -2
- package/modern/ChartsYAxis/ChartsYAxis.js +2 -2
- package/modern/Gauge/GaugeProvider.js +5 -5
- package/modern/LineChart/AnimatedArea.js +6 -5
- package/modern/LineChart/AnimatedLine.js +7 -5
- package/modern/LineChart/AreaElement.js +4 -1
- package/modern/LineChart/AreaPlot.js +7 -1
- package/modern/LineChart/LineChart.js +32 -2
- 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 +32 -2
- package/modern/PieChart/PiePlot.js +26 -6
- 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 +32 -2
- package/modern/ScatterChart/Scatter.js +6 -3
- package/modern/ScatterChart/ScatterChart.js +32 -2
- package/modern/ScatterChart/ScatterPlot.js +3 -0
- package/modern/ScatterChart/getColor.js +25 -0
- package/modern/SparkLineChart/SparkLineChart.js +15 -0
- package/modern/context/CartesianContextProvider.js +23 -8
- 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 +96 -0
- package/modern/internals/components/ChartsAxesGradients/ChartsContinuousGradient.js +55 -0
- package/modern/internals/components/ChartsAxesGradients/ChartsPiecewiseGradient.js +41 -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/package.json +1 -1
|
@@ -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,
|
|
@@ -379,11 +379,26 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
|
|
|
379
379
|
width: PropTypes.number,
|
|
380
380
|
/**
|
|
381
381
|
* The configuration of the x-axes.
|
|
382
|
-
* If not provided, a default axis config is used
|
|
382
|
+
* If not provided, a default axis config is used.
|
|
383
383
|
*/
|
|
384
384
|
xAxis: PropTypes.arrayOf(PropTypes.shape({
|
|
385
385
|
axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
386
386
|
classes: PropTypes.object,
|
|
387
|
+
colorMap: PropTypes.oneOfType([PropTypes.shape({
|
|
388
|
+
color: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string.isRequired), PropTypes.func]).isRequired,
|
|
389
|
+
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
390
|
+
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
391
|
+
type: PropTypes.oneOf(['continuous']).isRequired
|
|
392
|
+
}), PropTypes.shape({
|
|
393
|
+
colors: PropTypes.arrayOf(PropTypes.string).isRequired,
|
|
394
|
+
thresholds: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired).isRequired,
|
|
395
|
+
type: PropTypes.oneOf(['piecewise']).isRequired
|
|
396
|
+
}), PropTypes.shape({
|
|
397
|
+
colors: PropTypes.arrayOf(PropTypes.string).isRequired,
|
|
398
|
+
type: PropTypes.oneOf(['ordinal']).isRequired,
|
|
399
|
+
unknownColor: PropTypes.string,
|
|
400
|
+
values: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired)
|
|
401
|
+
})]),
|
|
387
402
|
data: PropTypes.array,
|
|
388
403
|
dataKey: PropTypes.string,
|
|
389
404
|
disableLine: PropTypes.bool,
|
|
@@ -416,11 +431,26 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
|
|
|
416
431
|
})),
|
|
417
432
|
/**
|
|
418
433
|
* The configuration of the y-axes.
|
|
419
|
-
* If not provided, a default axis config is used
|
|
434
|
+
* If not provided, a default axis config is used.
|
|
420
435
|
*/
|
|
421
436
|
yAxis: PropTypes.arrayOf(PropTypes.shape({
|
|
422
437
|
axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
423
438
|
classes: PropTypes.object,
|
|
439
|
+
colorMap: PropTypes.oneOfType([PropTypes.shape({
|
|
440
|
+
color: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string.isRequired), PropTypes.func]).isRequired,
|
|
441
|
+
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
442
|
+
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
443
|
+
type: PropTypes.oneOf(['continuous']).isRequired
|
|
444
|
+
}), PropTypes.shape({
|
|
445
|
+
colors: PropTypes.arrayOf(PropTypes.string).isRequired,
|
|
446
|
+
thresholds: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired).isRequired,
|
|
447
|
+
type: PropTypes.oneOf(['piecewise']).isRequired
|
|
448
|
+
}), PropTypes.shape({
|
|
449
|
+
colors: PropTypes.arrayOf(PropTypes.string).isRequired,
|
|
450
|
+
type: PropTypes.oneOf(['ordinal']).isRequired,
|
|
451
|
+
unknownColor: PropTypes.string,
|
|
452
|
+
values: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired)
|
|
453
|
+
})]),
|
|
424
454
|
data: PropTypes.array,
|
|
425
455
|
dataKey: PropTypes.string,
|
|
426
456
|
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
|
+
}
|
|
@@ -335,11 +335,26 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
|
|
|
335
335
|
width: PropTypes.number,
|
|
336
336
|
/**
|
|
337
337
|
* The configuration of the x-axes.
|
|
338
|
-
* If not provided, a default axis config is used
|
|
338
|
+
* If not provided, a default axis config is used.
|
|
339
339
|
*/
|
|
340
340
|
xAxis: PropTypes.arrayOf(PropTypes.shape({
|
|
341
341
|
axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
342
342
|
classes: PropTypes.object,
|
|
343
|
+
colorMap: PropTypes.oneOfType([PropTypes.shape({
|
|
344
|
+
color: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string.isRequired), PropTypes.func]).isRequired,
|
|
345
|
+
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
346
|
+
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
347
|
+
type: PropTypes.oneOf(['continuous']).isRequired
|
|
348
|
+
}), PropTypes.shape({
|
|
349
|
+
colors: PropTypes.arrayOf(PropTypes.string).isRequired,
|
|
350
|
+
thresholds: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired).isRequired,
|
|
351
|
+
type: PropTypes.oneOf(['piecewise']).isRequired
|
|
352
|
+
}), PropTypes.shape({
|
|
353
|
+
colors: PropTypes.arrayOf(PropTypes.string).isRequired,
|
|
354
|
+
type: PropTypes.oneOf(['ordinal']).isRequired,
|
|
355
|
+
unknownColor: PropTypes.string,
|
|
356
|
+
values: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired)
|
|
357
|
+
})]),
|
|
343
358
|
data: PropTypes.array,
|
|
344
359
|
dataKey: PropTypes.string,
|
|
345
360
|
disableLine: PropTypes.bool,
|
|
@@ -372,11 +387,26 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
|
|
|
372
387
|
})),
|
|
373
388
|
/**
|
|
374
389
|
* The configuration of the y-axes.
|
|
375
|
-
* If not provided, a default axis config is used
|
|
390
|
+
* If not provided, a default axis config is used.
|
|
376
391
|
*/
|
|
377
392
|
yAxis: PropTypes.arrayOf(PropTypes.shape({
|
|
378
393
|
axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
379
394
|
classes: PropTypes.object,
|
|
395
|
+
colorMap: PropTypes.oneOfType([PropTypes.shape({
|
|
396
|
+
color: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string.isRequired), PropTypes.func]).isRequired,
|
|
397
|
+
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
398
|
+
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
399
|
+
type: PropTypes.oneOf(['continuous']).isRequired
|
|
400
|
+
}), PropTypes.shape({
|
|
401
|
+
colors: PropTypes.arrayOf(PropTypes.string).isRequired,
|
|
402
|
+
thresholds: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired).isRequired,
|
|
403
|
+
type: PropTypes.oneOf(['piecewise']).isRequired
|
|
404
|
+
}), PropTypes.shape({
|
|
405
|
+
colors: PropTypes.arrayOf(PropTypes.string).isRequired,
|
|
406
|
+
type: PropTypes.oneOf(['ordinal']).isRequired,
|
|
407
|
+
unknownColor: PropTypes.string,
|
|
408
|
+
values: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired)
|
|
409
|
+
})]),
|
|
380
410
|
data: PropTypes.array,
|
|
381
411
|
dataKey: PropTypes.string,
|
|
382
412
|
disableLine: PropTypes.bool,
|
|
@@ -5,6 +5,7 @@ import { DrawingContext } from '../context/DrawingProvider';
|
|
|
5
5
|
import { PieArcPlot } from './PieArcPlot';
|
|
6
6
|
import { PieArcLabelPlot } from './PieArcLabelPlot';
|
|
7
7
|
import { getPercentageValue } from '../internals/utils';
|
|
8
|
+
import { getPieCoordinates } from './getPieCoordinates';
|
|
8
9
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
9
10
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
10
11
|
/**
|
|
@@ -34,7 +35,6 @@ function PiePlot(props) {
|
|
|
34
35
|
if (seriesData === undefined) {
|
|
35
36
|
return null;
|
|
36
37
|
}
|
|
37
|
-
const availableRadius = Math.min(width, height) / 2;
|
|
38
38
|
const {
|
|
39
39
|
series,
|
|
40
40
|
seriesOrder
|
|
@@ -53,10 +53,19 @@ function PiePlot(props) {
|
|
|
53
53
|
faded,
|
|
54
54
|
highlightScope
|
|
55
55
|
} = series[seriesId];
|
|
56
|
+
const {
|
|
57
|
+
cx,
|
|
58
|
+
cy,
|
|
59
|
+
availableRadius
|
|
60
|
+
} = getPieCoordinates({
|
|
61
|
+
cx: cxParam,
|
|
62
|
+
cy: cyParam
|
|
63
|
+
}, {
|
|
64
|
+
width,
|
|
65
|
+
height
|
|
66
|
+
});
|
|
56
67
|
const outerRadius = getPercentageValue(outerRadiusParam ?? availableRadius, availableRadius);
|
|
57
68
|
const innerRadius = getPercentageValue(innerRadiusParam ?? 0, availableRadius);
|
|
58
|
-
const cx = getPercentageValue(cxParam ?? '50%', width);
|
|
59
|
-
const cy = getPercentageValue(cyParam ?? '50%', height);
|
|
60
69
|
return /*#__PURE__*/_jsx("g", {
|
|
61
70
|
transform: `translate(${left + cx}, ${top + cy})`,
|
|
62
71
|
children: /*#__PURE__*/_jsx(PieArcPlot, {
|
|
@@ -89,11 +98,20 @@ function PiePlot(props) {
|
|
|
89
98
|
cy: cyParam,
|
|
90
99
|
highlightScope
|
|
91
100
|
} = series[seriesId];
|
|
101
|
+
const {
|
|
102
|
+
cx,
|
|
103
|
+
cy,
|
|
104
|
+
availableRadius
|
|
105
|
+
} = getPieCoordinates({
|
|
106
|
+
cx: cxParam,
|
|
107
|
+
cy: cyParam
|
|
108
|
+
}, {
|
|
109
|
+
width,
|
|
110
|
+
height
|
|
111
|
+
});
|
|
92
112
|
const outerRadius = getPercentageValue(outerRadiusParam ?? availableRadius, availableRadius);
|
|
93
113
|
const innerRadius = getPercentageValue(innerRadiusParam ?? 0, availableRadius);
|
|
94
114
|
const arcLabelRadius = arcLabelRadiusParam === undefined ? (outerRadius + innerRadius) / 2 : getPercentageValue(arcLabelRadiusParam, availableRadius);
|
|
95
|
-
const cx = getPercentageValue(cxParam ?? '50%', width);
|
|
96
|
-
const cy = getPercentageValue(cyParam ?? '50%', height);
|
|
97
115
|
return /*#__PURE__*/_jsx("g", {
|
|
98
116
|
transform: `translate(${left + cx}, ${top + cy})`,
|
|
99
117
|
children: /*#__PURE__*/_jsx(PieArcLabelPlot, {
|
|
@@ -107,7 +125,9 @@ function PiePlot(props) {
|
|
|
107
125
|
skipAnimation: skipAnimation,
|
|
108
126
|
arcLabel: arcLabel,
|
|
109
127
|
arcLabelMinAngle: arcLabelMinAngle,
|
|
110
|
-
highlightScope: highlightScope
|
|
128
|
+
highlightScope: highlightScope,
|
|
129
|
+
slots: slots,
|
|
130
|
+
slotProps: slotProps
|
|
111
131
|
})
|
|
112
132
|
}, seriesId);
|
|
113
133
|
})]
|
|
@@ -28,8 +28,10 @@ const formatter = params => {
|
|
|
28
28
|
}, series[seriesId], {
|
|
29
29
|
data: series[seriesId].data.map((item, index) => _extends({}, item, {
|
|
30
30
|
id: item.id ?? `auto-generated-pie-id-${seriesId}-${index}`
|
|
31
|
-
}, arcs[index])).map(item => _extends({}, item, {
|
|
32
|
-
formattedValue: series[seriesId].valueFormatter?.(item
|
|
31
|
+
}, arcs[index])).map((item, index) => _extends({}, item, {
|
|
32
|
+
formattedValue: series[seriesId].valueFormatter?.(item, {
|
|
33
|
+
dataIndex: index
|
|
34
|
+
}) ?? item.value.toLocaleString()
|
|
33
35
|
}))
|
|
34
36
|
});
|
|
35
37
|
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { getPercentageValue } from '../internals/utils';
|
|
2
|
+
export function getPieCoordinates(series, drawing) {
|
|
3
|
+
const {
|
|
4
|
+
height,
|
|
5
|
+
width
|
|
6
|
+
} = drawing;
|
|
7
|
+
const {
|
|
8
|
+
cx: cxParam,
|
|
9
|
+
cy: cyParam
|
|
10
|
+
} = series;
|
|
11
|
+
const availableRadius = Math.min(width, height) / 2;
|
|
12
|
+
const cx = getPercentageValue(cxParam ?? '50%', width);
|
|
13
|
+
const cy = getPercentageValue(cyParam ?? '50%', height);
|
|
14
|
+
return {
|
|
15
|
+
cx,
|
|
16
|
+
cy,
|
|
17
|
+
availableRadius
|
|
18
|
+
};
|
|
19
|
+
}
|
package/modern/PieChart/index.js
CHANGED
|
@@ -106,11 +106,26 @@ process.env.NODE_ENV !== "production" ? ResponsiveChartContainer.propTypes = {
|
|
|
106
106
|
width: PropTypes.number,
|
|
107
107
|
/**
|
|
108
108
|
* The configuration of the x-axes.
|
|
109
|
-
* If not provided, a default axis config is used
|
|
109
|
+
* If not provided, a default axis config is used.
|
|
110
110
|
*/
|
|
111
111
|
xAxis: PropTypes.arrayOf(PropTypes.shape({
|
|
112
112
|
axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
113
113
|
classes: PropTypes.object,
|
|
114
|
+
colorMap: PropTypes.oneOfType([PropTypes.shape({
|
|
115
|
+
color: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string.isRequired), PropTypes.func]).isRequired,
|
|
116
|
+
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
117
|
+
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
118
|
+
type: PropTypes.oneOf(['continuous']).isRequired
|
|
119
|
+
}), PropTypes.shape({
|
|
120
|
+
colors: PropTypes.arrayOf(PropTypes.string).isRequired,
|
|
121
|
+
thresholds: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired).isRequired,
|
|
122
|
+
type: PropTypes.oneOf(['piecewise']).isRequired
|
|
123
|
+
}), PropTypes.shape({
|
|
124
|
+
colors: PropTypes.arrayOf(PropTypes.string).isRequired,
|
|
125
|
+
type: PropTypes.oneOf(['ordinal']).isRequired,
|
|
126
|
+
unknownColor: PropTypes.string,
|
|
127
|
+
values: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired)
|
|
128
|
+
})]),
|
|
114
129
|
data: PropTypes.array,
|
|
115
130
|
dataKey: PropTypes.string,
|
|
116
131
|
disableLine: PropTypes.bool,
|
|
@@ -143,11 +158,26 @@ process.env.NODE_ENV !== "production" ? ResponsiveChartContainer.propTypes = {
|
|
|
143
158
|
})),
|
|
144
159
|
/**
|
|
145
160
|
* The configuration of the y-axes.
|
|
146
|
-
* If not provided, a default axis config is used
|
|
161
|
+
* If not provided, a default axis config is used.
|
|
147
162
|
*/
|
|
148
163
|
yAxis: PropTypes.arrayOf(PropTypes.shape({
|
|
149
164
|
axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
150
165
|
classes: PropTypes.object,
|
|
166
|
+
colorMap: PropTypes.oneOfType([PropTypes.shape({
|
|
167
|
+
color: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string.isRequired), PropTypes.func]).isRequired,
|
|
168
|
+
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
169
|
+
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
170
|
+
type: PropTypes.oneOf(['continuous']).isRequired
|
|
171
|
+
}), PropTypes.shape({
|
|
172
|
+
colors: PropTypes.arrayOf(PropTypes.string).isRequired,
|
|
173
|
+
thresholds: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired).isRequired,
|
|
174
|
+
type: PropTypes.oneOf(['piecewise']).isRequired
|
|
175
|
+
}), PropTypes.shape({
|
|
176
|
+
colors: PropTypes.arrayOf(PropTypes.string).isRequired,
|
|
177
|
+
type: PropTypes.oneOf(['ordinal']).isRequired,
|
|
178
|
+
unknownColor: PropTypes.string,
|
|
179
|
+
values: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired)
|
|
180
|
+
})]),
|
|
151
181
|
data: PropTypes.array,
|
|
152
182
|
dataKey: PropTypes.string,
|
|
153
183
|
disableLine: PropTypes.bool,
|
|
@@ -21,6 +21,7 @@ function Scatter(props) {
|
|
|
21
21
|
xScale,
|
|
22
22
|
yScale,
|
|
23
23
|
color,
|
|
24
|
+
colorGetter,
|
|
24
25
|
markerSize,
|
|
25
26
|
onItemClick
|
|
26
27
|
} = props;
|
|
@@ -63,19 +64,20 @@ function Scatter(props) {
|
|
|
63
64
|
isFaded: !isHighlighted && getIsFaded(item, pointCtx, highlightScope),
|
|
64
65
|
interactionProps: getInteractionItemProps(pointCtx),
|
|
65
66
|
id: scatterPoint.id,
|
|
66
|
-
dataIndex: i
|
|
67
|
+
dataIndex: i,
|
|
68
|
+
color: colorGetter ? colorGetter(i) : color
|
|
67
69
|
});
|
|
68
70
|
}
|
|
69
71
|
}
|
|
70
72
|
return temp;
|
|
71
|
-
}, [xScale, yScale, series.data, series.id, item, highlightScope, getInteractionItemProps]);
|
|
73
|
+
}, [xScale, yScale, series.data, series.id, item, highlightScope, getInteractionItemProps, color, colorGetter]);
|
|
72
74
|
return /*#__PURE__*/_jsx("g", {
|
|
73
75
|
children: cleanData.map(dataPoint => /*#__PURE__*/_jsx("circle", _extends({
|
|
74
76
|
cx: 0,
|
|
75
77
|
cy: 0,
|
|
76
78
|
r: (dataPoint.isHighlighted ? 1.2 : 1) * markerSize,
|
|
77
79
|
transform: `translate(${dataPoint.x}, ${dataPoint.y})`,
|
|
78
|
-
fill: color,
|
|
80
|
+
fill: dataPoint.color,
|
|
79
81
|
opacity: dataPoint.isFaded && 0.3 || 1,
|
|
80
82
|
onClick: onItemClick && (event => onItemClick(event, {
|
|
81
83
|
type: 'scatter',
|
|
@@ -92,6 +94,7 @@ process.env.NODE_ENV !== "production" ? Scatter.propTypes = {
|
|
|
92
94
|
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
93
95
|
// ----------------------------------------------------------------------
|
|
94
96
|
color: PropTypes.string.isRequired,
|
|
97
|
+
colorGetter: PropTypes.func,
|
|
95
98
|
markerSize: PropTypes.number.isRequired,
|
|
96
99
|
/**
|
|
97
100
|
* Callback fired when clicking on a scatter item.
|
|
@@ -328,11 +328,26 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
|
|
|
328
328
|
width: PropTypes.number,
|
|
329
329
|
/**
|
|
330
330
|
* The configuration of the x-axes.
|
|
331
|
-
* If not provided, a default axis config is used
|
|
331
|
+
* If not provided, a default axis config is used.
|
|
332
332
|
*/
|
|
333
333
|
xAxis: PropTypes.arrayOf(PropTypes.shape({
|
|
334
334
|
axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
335
335
|
classes: PropTypes.object,
|
|
336
|
+
colorMap: PropTypes.oneOfType([PropTypes.shape({
|
|
337
|
+
color: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string.isRequired), PropTypes.func]).isRequired,
|
|
338
|
+
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
339
|
+
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
340
|
+
type: PropTypes.oneOf(['continuous']).isRequired
|
|
341
|
+
}), PropTypes.shape({
|
|
342
|
+
colors: PropTypes.arrayOf(PropTypes.string).isRequired,
|
|
343
|
+
thresholds: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired).isRequired,
|
|
344
|
+
type: PropTypes.oneOf(['piecewise']).isRequired
|
|
345
|
+
}), PropTypes.shape({
|
|
346
|
+
colors: PropTypes.arrayOf(PropTypes.string).isRequired,
|
|
347
|
+
type: PropTypes.oneOf(['ordinal']).isRequired,
|
|
348
|
+
unknownColor: PropTypes.string,
|
|
349
|
+
values: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired)
|
|
350
|
+
})]),
|
|
336
351
|
data: PropTypes.array,
|
|
337
352
|
dataKey: PropTypes.string,
|
|
338
353
|
disableLine: PropTypes.bool,
|
|
@@ -365,11 +380,26 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
|
|
|
365
380
|
})),
|
|
366
381
|
/**
|
|
367
382
|
* The configuration of the y-axes.
|
|
368
|
-
* If not provided, a default axis config is used
|
|
383
|
+
* If not provided, a default axis config is used.
|
|
369
384
|
*/
|
|
370
385
|
yAxis: PropTypes.arrayOf(PropTypes.shape({
|
|
371
386
|
axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
372
387
|
classes: PropTypes.object,
|
|
388
|
+
colorMap: PropTypes.oneOfType([PropTypes.shape({
|
|
389
|
+
color: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string.isRequired), PropTypes.func]).isRequired,
|
|
390
|
+
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
391
|
+
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
392
|
+
type: PropTypes.oneOf(['continuous']).isRequired
|
|
393
|
+
}), PropTypes.shape({
|
|
394
|
+
colors: PropTypes.arrayOf(PropTypes.string).isRequired,
|
|
395
|
+
thresholds: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired).isRequired,
|
|
396
|
+
type: PropTypes.oneOf(['piecewise']).isRequired
|
|
397
|
+
}), PropTypes.shape({
|
|
398
|
+
colors: PropTypes.arrayOf(PropTypes.string).isRequired,
|
|
399
|
+
type: PropTypes.oneOf(['ordinal']).isRequired,
|
|
400
|
+
unknownColor: PropTypes.string,
|
|
401
|
+
values: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired)
|
|
402
|
+
})]),
|
|
373
403
|
data: PropTypes.array,
|
|
374
404
|
dataKey: PropTypes.string,
|
|
375
405
|
disableLine: PropTypes.bool,
|
|
@@ -4,6 +4,7 @@ import PropTypes from 'prop-types';
|
|
|
4
4
|
import { Scatter } from './Scatter';
|
|
5
5
|
import { SeriesContext } from '../context/SeriesContextProvider';
|
|
6
6
|
import { CartesianContext } from '../context/CartesianContextProvider';
|
|
7
|
+
import getColor from './getColor';
|
|
7
8
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
9
|
/**
|
|
9
10
|
* Demos:
|
|
@@ -48,12 +49,14 @@ function ScatterPlot(props) {
|
|
|
48
49
|
markerSize,
|
|
49
50
|
color
|
|
50
51
|
} = series[seriesId];
|
|
52
|
+
const colorGetter = getColor(series[seriesId], xAxis[xAxisKey ?? defaultXAxisId], yAxis[yAxisKey ?? defaultYAxisId]);
|
|
51
53
|
const xScale = xAxis[xAxisKey ?? defaultXAxisId].scale;
|
|
52
54
|
const yScale = yAxis[yAxisKey ?? defaultYAxisId].scale;
|
|
53
55
|
return /*#__PURE__*/_jsx(ScatterItems, _extends({
|
|
54
56
|
xScale: xScale,
|
|
55
57
|
yScale: yScale,
|
|
56
58
|
color: color,
|
|
59
|
+
colorGetter: colorGetter,
|
|
57
60
|
markerSize: markerSize ?? 4,
|
|
58
61
|
series: series[seriesId],
|
|
59
62
|
onItemClick: onItemClick
|
|
@@ -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.y);
|
|
8
|
+
if (color === null) {
|
|
9
|
+
return series.color;
|
|
10
|
+
}
|
|
11
|
+
return color;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
if (xColorScale) {
|
|
15
|
+
return dataIndex => {
|
|
16
|
+
const value = series.data[dataIndex];
|
|
17
|
+
const color = value === null ? series.color : xColorScale(value.x);
|
|
18
|
+
if (color === null) {
|
|
19
|
+
return series.color;
|
|
20
|
+
}
|
|
21
|
+
return color;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
return () => series.color;
|
|
25
|
+
}
|