@mui/x-charts 7.1.1 → 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/extremums.js +1 -1
- package/BarChart/getColor.d.ts +3 -0
- package/BarChart/getColor.js +33 -0
- package/CHANGELOG.md +211 -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 +7 -7
- package/ChartsYAxis/ChartsYAxis.js +9 -6
- 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/extremums.js +1 -1
- 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 +7 -7
- package/esm/ChartsYAxis/ChartsYAxis.js +9 -6
- 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/hooks/useTicks.d.ts +1 -1
- 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/extremums.js +1 -1
- 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 +7 -7
- package/modern/ChartsYAxis/ChartsYAxis.js +9 -6
- 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
|
@@ -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
|
+
}
|
|
@@ -226,6 +226,21 @@ process.env.NODE_ENV !== "production" ? SparkLineChart.propTypes = {
|
|
|
226
226
|
xAxis: PropTypes.shape({
|
|
227
227
|
axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
228
228
|
classes: PropTypes.object,
|
|
229
|
+
colorMap: PropTypes.oneOfType([PropTypes.shape({
|
|
230
|
+
color: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string.isRequired), PropTypes.func]).isRequired,
|
|
231
|
+
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
232
|
+
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
233
|
+
type: PropTypes.oneOf(['continuous']).isRequired
|
|
234
|
+
}), PropTypes.shape({
|
|
235
|
+
colors: PropTypes.arrayOf(PropTypes.string).isRequired,
|
|
236
|
+
thresholds: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired).isRequired,
|
|
237
|
+
type: PropTypes.oneOf(['piecewise']).isRequired
|
|
238
|
+
}), PropTypes.shape({
|
|
239
|
+
colors: PropTypes.arrayOf(PropTypes.string).isRequired,
|
|
240
|
+
type: PropTypes.oneOf(['ordinal']).isRequired,
|
|
241
|
+
unknownColor: PropTypes.string,
|
|
242
|
+
values: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired)
|
|
243
|
+
})]),
|
|
229
244
|
data: PropTypes.array,
|
|
230
245
|
dataKey: PropTypes.string,
|
|
231
246
|
disableLine: PropTypes.bool,
|
|
@@ -6,10 +6,11 @@ import { getExtremumX as getScatterExtremumX, getExtremumY as getScatterExtremum
|
|
|
6
6
|
import { getExtremumX as getLineExtremumX, getExtremumY as getLineExtremumY } from '../LineChart/extremums';
|
|
7
7
|
import { isBandScaleConfig, isPointScaleConfig } from '../models/axis';
|
|
8
8
|
import { getScale } from '../internals/getScale';
|
|
9
|
-
import { DrawingContext } from './DrawingProvider';
|
|
10
9
|
import { SeriesContext } from './SeriesContextProvider';
|
|
11
10
|
import { DEFAULT_X_AXIS_KEY, DEFAULT_Y_AXIS_KEY } from '../constants';
|
|
12
11
|
import { getTickNumber } from '../hooks/useTicks';
|
|
12
|
+
import { useDrawingArea } from '../hooks/useDrawingArea';
|
|
13
|
+
import { getColorScale, getOrdinalColorScale } from '../internals/colorScale';
|
|
13
14
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
15
|
const DEFAULT_CATEGORY_GAP_RATIO = 0.2;
|
|
15
16
|
const DEFAULT_BAR_GAP_RATIO = 0.1;
|
|
@@ -42,7 +43,7 @@ function CartesianContextProvider(props) {
|
|
|
42
43
|
children
|
|
43
44
|
} = props;
|
|
44
45
|
const formattedSeries = React.useContext(SeriesContext);
|
|
45
|
-
const drawingArea =
|
|
46
|
+
const drawingArea = useDrawingArea();
|
|
46
47
|
const xAxis = React.useMemo(() => inXAxis?.map(axisConfig => {
|
|
47
48
|
const dataKey = axisConfig.dataKey;
|
|
48
49
|
if (dataKey === undefined || axisConfig.data !== undefined) {
|
|
@@ -112,13 +113,19 @@ function CartesianContextProvider(props) {
|
|
|
112
113
|
barGapRatio
|
|
113
114
|
}, axis, {
|
|
114
115
|
scale: scaleBand(axis.data, range).paddingInner(categoryGapRatio).paddingOuter(categoryGapRatio / 2),
|
|
115
|
-
tickNumber: axis.data.length
|
|
116
|
+
tickNumber: axis.data.length,
|
|
117
|
+
colorScale: axis.colorMap && (axis.colorMap.type === 'ordinal' ? getOrdinalColorScale(_extends({
|
|
118
|
+
values: axis.data
|
|
119
|
+
}, axis.colorMap)) : getColorScale(axis.colorMap))
|
|
116
120
|
});
|
|
117
121
|
}
|
|
118
122
|
if (isPointScaleConfig(axis)) {
|
|
119
123
|
completedXAxis[axis.id] = _extends({}, axis, {
|
|
120
124
|
scale: scalePoint(axis.data, range),
|
|
121
|
-
tickNumber: axis.data.length
|
|
125
|
+
tickNumber: axis.data.length,
|
|
126
|
+
colorScale: axis.colorMap && (axis.colorMap.type === 'ordinal' ? getOrdinalColorScale(_extends({
|
|
127
|
+
values: axis.data
|
|
128
|
+
}, axis.colorMap)) : getColorScale(axis.colorMap))
|
|
122
129
|
});
|
|
123
130
|
}
|
|
124
131
|
if (axis.scaleType === 'band' || axis.scaleType === 'point') {
|
|
@@ -137,7 +144,8 @@ function CartesianContextProvider(props) {
|
|
|
137
144
|
completedXAxis[axis.id] = _extends({}, axis, {
|
|
138
145
|
scaleType,
|
|
139
146
|
scale: niceScale.domain(domain),
|
|
140
|
-
tickNumber
|
|
147
|
+
tickNumber,
|
|
148
|
+
colorScale: axis.colorMap && getColorScale(axis.colorMap)
|
|
141
149
|
});
|
|
142
150
|
});
|
|
143
151
|
const allYAxis = [...(yAxis?.map((axis, index) => _extends({
|
|
@@ -160,13 +168,19 @@ function CartesianContextProvider(props) {
|
|
|
160
168
|
barGapRatio: 0
|
|
161
169
|
}, axis, {
|
|
162
170
|
scale: scaleBand(axis.data, [range[1], range[0]]).paddingInner(categoryGapRatio).paddingOuter(categoryGapRatio / 2),
|
|
163
|
-
tickNumber: axis.data.length
|
|
171
|
+
tickNumber: axis.data.length,
|
|
172
|
+
colorScale: axis.colorMap && (axis.colorMap.type === 'ordinal' ? getOrdinalColorScale(_extends({
|
|
173
|
+
values: axis.data
|
|
174
|
+
}, axis.colorMap)) : getColorScale(axis.colorMap))
|
|
164
175
|
});
|
|
165
176
|
}
|
|
166
177
|
if (isPointScaleConfig(axis)) {
|
|
167
178
|
completedYAxis[axis.id] = _extends({}, axis, {
|
|
168
179
|
scale: scalePoint(axis.data, [range[1], range[0]]),
|
|
169
|
-
tickNumber: axis.data.length
|
|
180
|
+
tickNumber: axis.data.length,
|
|
181
|
+
colorScale: axis.colorMap && (axis.colorMap.type === 'ordinal' ? getOrdinalColorScale(_extends({
|
|
182
|
+
values: axis.data
|
|
183
|
+
}, axis.colorMap)) : getColorScale(axis.colorMap))
|
|
170
184
|
});
|
|
171
185
|
}
|
|
172
186
|
if (axis.scaleType === 'band' || axis.scaleType === 'point') {
|
|
@@ -185,7 +199,8 @@ function CartesianContextProvider(props) {
|
|
|
185
199
|
completedYAxis[axis.id] = _extends({}, axis, {
|
|
186
200
|
scaleType,
|
|
187
201
|
scale: niceScale.domain(domain),
|
|
188
|
-
tickNumber
|
|
202
|
+
tickNumber,
|
|
203
|
+
colorScale: axis.colorMap && getColorScale(axis.colorMap)
|
|
189
204
|
});
|
|
190
205
|
});
|
|
191
206
|
return {
|
package/modern/hooks/index.js
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
export * from './useDrawingArea';
|
|
2
|
-
export * from './
|
|
2
|
+
export * from './useChartId';
|
|
3
|
+
export * from './useScale';
|
|
4
|
+
export * from './useSvgRef';
|
|
5
|
+
export { useSeries as unstable_useSeries, usePieSeries as unstable_usePieSeries, useLineSeries as unstable_useLineSeries, useBarSeries as unstable_useBarSeries, useScatterSeries as unstable_useScatterSeries } from './useSeries';
|
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { InteractionContext } from '../context/InteractionProvider';
|
|
3
3
|
import { CartesianContext } from '../context/CartesianContextProvider';
|
|
4
|
-
import { SvgContext, DrawingContext } from '../context/DrawingProvider';
|
|
5
4
|
import { isBandScale } from '../internals/isBandScale';
|
|
6
5
|
import { getSVGPoint } from '../internals/utils';
|
|
6
|
+
import { useSvgRef } from './useSvgRef';
|
|
7
|
+
import { useDrawingArea } from './useDrawingArea';
|
|
7
8
|
function getAsANumber(value) {
|
|
8
9
|
return value instanceof Date ? value.getTime() : value;
|
|
9
10
|
}
|
|
10
11
|
export const useAxisEvents = disableAxisListener => {
|
|
11
|
-
const svgRef =
|
|
12
|
+
const svgRef = useSvgRef();
|
|
12
13
|
const {
|
|
13
|
-
|
|
14
|
-
height,
|
|
14
|
+
left,
|
|
15
15
|
top,
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
width,
|
|
17
|
+
height
|
|
18
|
+
} = useDrawingArea();
|
|
18
19
|
const {
|
|
19
20
|
xAxis,
|
|
20
21
|
yAxis,
|
|
@@ -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