@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
package/PieChart/PiePlot.js
CHANGED
|
@@ -12,6 +12,7 @@ var _DrawingProvider = require("../context/DrawingProvider");
|
|
|
12
12
|
var _PieArcPlot = require("./PieArcPlot");
|
|
13
13
|
var _PieArcLabelPlot = require("./PieArcLabelPlot");
|
|
14
14
|
var _utils = require("../internals/utils");
|
|
15
|
+
var _getPieCoordinates = require("./getPieCoordinates");
|
|
15
16
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
16
17
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
17
18
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
@@ -42,7 +43,6 @@ function PiePlot(props) {
|
|
|
42
43
|
if (seriesData === undefined) {
|
|
43
44
|
return null;
|
|
44
45
|
}
|
|
45
|
-
const availableRadius = Math.min(width, height) / 2;
|
|
46
46
|
const {
|
|
47
47
|
series,
|
|
48
48
|
seriesOrder
|
|
@@ -61,10 +61,19 @@ function PiePlot(props) {
|
|
|
61
61
|
faded,
|
|
62
62
|
highlightScope
|
|
63
63
|
} = series[seriesId];
|
|
64
|
+
const {
|
|
65
|
+
cx,
|
|
66
|
+
cy,
|
|
67
|
+
availableRadius
|
|
68
|
+
} = (0, _getPieCoordinates.getPieCoordinates)({
|
|
69
|
+
cx: cxParam,
|
|
70
|
+
cy: cyParam
|
|
71
|
+
}, {
|
|
72
|
+
width,
|
|
73
|
+
height
|
|
74
|
+
});
|
|
64
75
|
const outerRadius = (0, _utils.getPercentageValue)(outerRadiusParam ?? availableRadius, availableRadius);
|
|
65
76
|
const innerRadius = (0, _utils.getPercentageValue)(innerRadiusParam ?? 0, availableRadius);
|
|
66
|
-
const cx = (0, _utils.getPercentageValue)(cxParam ?? '50%', width);
|
|
67
|
-
const cy = (0, _utils.getPercentageValue)(cyParam ?? '50%', height);
|
|
68
77
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("g", {
|
|
69
78
|
transform: `translate(${left + cx}, ${top + cy})`,
|
|
70
79
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_PieArcPlot.PieArcPlot, {
|
|
@@ -97,11 +106,20 @@ function PiePlot(props) {
|
|
|
97
106
|
cy: cyParam,
|
|
98
107
|
highlightScope
|
|
99
108
|
} = series[seriesId];
|
|
109
|
+
const {
|
|
110
|
+
cx,
|
|
111
|
+
cy,
|
|
112
|
+
availableRadius
|
|
113
|
+
} = (0, _getPieCoordinates.getPieCoordinates)({
|
|
114
|
+
cx: cxParam,
|
|
115
|
+
cy: cyParam
|
|
116
|
+
}, {
|
|
117
|
+
width,
|
|
118
|
+
height
|
|
119
|
+
});
|
|
100
120
|
const outerRadius = (0, _utils.getPercentageValue)(outerRadiusParam ?? availableRadius, availableRadius);
|
|
101
121
|
const innerRadius = (0, _utils.getPercentageValue)(innerRadiusParam ?? 0, availableRadius);
|
|
102
122
|
const arcLabelRadius = arcLabelRadiusParam === undefined ? (outerRadius + innerRadius) / 2 : (0, _utils.getPercentageValue)(arcLabelRadiusParam, availableRadius);
|
|
103
|
-
const cx = (0, _utils.getPercentageValue)(cxParam ?? '50%', width);
|
|
104
|
-
const cy = (0, _utils.getPercentageValue)(cyParam ?? '50%', height);
|
|
105
123
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("g", {
|
|
106
124
|
transform: `translate(${left + cx}, ${top + cy})`,
|
|
107
125
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_PieArcLabelPlot.PieArcLabelPlot, {
|
|
@@ -115,7 +133,9 @@ function PiePlot(props) {
|
|
|
115
133
|
skipAnimation: skipAnimation,
|
|
116
134
|
arcLabel: arcLabel,
|
|
117
135
|
arcLabelMinAngle: arcLabelMinAngle,
|
|
118
|
-
highlightScope: highlightScope
|
|
136
|
+
highlightScope: highlightScope,
|
|
137
|
+
slots: slots,
|
|
138
|
+
slotProps: slotProps
|
|
119
139
|
})
|
|
120
140
|
}, seriesId);
|
|
121
141
|
})]
|
package/PieChart/formatter.js
CHANGED
|
@@ -35,8 +35,10 @@ const formatter = params => {
|
|
|
35
35
|
}, series[seriesId], {
|
|
36
36
|
data: series[seriesId].data.map((item, index) => (0, _extends2.default)({}, item, {
|
|
37
37
|
id: item.id ?? `auto-generated-pie-id-${seriesId}-${index}`
|
|
38
|
-
}, arcs[index])).map(item => (0, _extends2.default)({}, item, {
|
|
39
|
-
formattedValue: series[seriesId].valueFormatter?.(item
|
|
38
|
+
}, arcs[index])).map((item, index) => (0, _extends2.default)({}, item, {
|
|
39
|
+
formattedValue: series[seriesId].valueFormatter?.(item, {
|
|
40
|
+
dataIndex: index
|
|
41
|
+
}) ?? item.value.toLocaleString()
|
|
40
42
|
}))
|
|
41
43
|
});
|
|
42
44
|
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { DrawingArea } from '../context/DrawingProvider';
|
|
2
|
+
import { DefaultizedPieSeriesType } from '../models/seriesType/pie';
|
|
3
|
+
export declare function getPieCoordinates(series: Pick<DefaultizedPieSeriesType, 'cx' | 'cy'>, drawing: Pick<DrawingArea, 'width' | 'height'>): {
|
|
4
|
+
cx: number;
|
|
5
|
+
cy: number;
|
|
6
|
+
availableRadius: number;
|
|
7
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getPieCoordinates = getPieCoordinates;
|
|
7
|
+
var _utils = require("../internals/utils");
|
|
8
|
+
function getPieCoordinates(series, drawing) {
|
|
9
|
+
const {
|
|
10
|
+
height,
|
|
11
|
+
width
|
|
12
|
+
} = drawing;
|
|
13
|
+
const {
|
|
14
|
+
cx: cxParam,
|
|
15
|
+
cy: cyParam
|
|
16
|
+
} = series;
|
|
17
|
+
const availableRadius = Math.min(width, height) / 2;
|
|
18
|
+
const cx = (0, _utils.getPercentageValue)(cxParam ?? '50%', width);
|
|
19
|
+
const cy = (0, _utils.getPercentageValue)(cyParam ?? '50%', height);
|
|
20
|
+
return {
|
|
21
|
+
cx,
|
|
22
|
+
cy,
|
|
23
|
+
availableRadius
|
|
24
|
+
};
|
|
25
|
+
}
|
package/PieChart/index.d.ts
CHANGED
package/PieChart/index.js
CHANGED
|
@@ -68,4 +68,15 @@ Object.keys(_PieArcLabel).forEach(function (key) {
|
|
|
68
68
|
return _PieArcLabel[key];
|
|
69
69
|
}
|
|
70
70
|
});
|
|
71
|
+
});
|
|
72
|
+
var _getPieCoordinates = require("./getPieCoordinates");
|
|
73
|
+
Object.keys(_getPieCoordinates).forEach(function (key) {
|
|
74
|
+
if (key === "default" || key === "__esModule") return;
|
|
75
|
+
if (key in exports && exports[key] === _getPieCoordinates[key]) return;
|
|
76
|
+
Object.defineProperty(exports, key, {
|
|
77
|
+
enumerable: true,
|
|
78
|
+
get: function () {
|
|
79
|
+
return _getPieCoordinates[key];
|
|
80
|
+
}
|
|
81
|
+
});
|
|
71
82
|
});
|
|
@@ -115,11 +115,26 @@ process.env.NODE_ENV !== "production" ? ResponsiveChartContainer.propTypes = {
|
|
|
115
115
|
width: _propTypes.default.number,
|
|
116
116
|
/**
|
|
117
117
|
* The configuration of the x-axes.
|
|
118
|
-
* If not provided, a default axis config is used
|
|
118
|
+
* If not provided, a default axis config is used.
|
|
119
119
|
*/
|
|
120
120
|
xAxis: _propTypes.default.arrayOf(_propTypes.default.shape({
|
|
121
121
|
axisId: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]),
|
|
122
122
|
classes: _propTypes.default.object,
|
|
123
|
+
colorMap: _propTypes.default.oneOfType([_propTypes.default.shape({
|
|
124
|
+
color: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.string.isRequired), _propTypes.default.func]).isRequired,
|
|
125
|
+
max: _propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.number]),
|
|
126
|
+
min: _propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.number]),
|
|
127
|
+
type: _propTypes.default.oneOf(['continuous']).isRequired
|
|
128
|
+
}), _propTypes.default.shape({
|
|
129
|
+
colors: _propTypes.default.arrayOf(_propTypes.default.string).isRequired,
|
|
130
|
+
thresholds: _propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.number]).isRequired).isRequired,
|
|
131
|
+
type: _propTypes.default.oneOf(['piecewise']).isRequired
|
|
132
|
+
}), _propTypes.default.shape({
|
|
133
|
+
colors: _propTypes.default.arrayOf(_propTypes.default.string).isRequired,
|
|
134
|
+
type: _propTypes.default.oneOf(['ordinal']).isRequired,
|
|
135
|
+
unknownColor: _propTypes.default.string,
|
|
136
|
+
values: _propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.number, _propTypes.default.string]).isRequired)
|
|
137
|
+
})]),
|
|
123
138
|
data: _propTypes.default.array,
|
|
124
139
|
dataKey: _propTypes.default.string,
|
|
125
140
|
disableLine: _propTypes.default.bool,
|
|
@@ -152,11 +167,26 @@ process.env.NODE_ENV !== "production" ? ResponsiveChartContainer.propTypes = {
|
|
|
152
167
|
})),
|
|
153
168
|
/**
|
|
154
169
|
* The configuration of the y-axes.
|
|
155
|
-
* If not provided, a default axis config is used
|
|
170
|
+
* If not provided, a default axis config is used.
|
|
156
171
|
*/
|
|
157
172
|
yAxis: _propTypes.default.arrayOf(_propTypes.default.shape({
|
|
158
173
|
axisId: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]),
|
|
159
174
|
classes: _propTypes.default.object,
|
|
175
|
+
colorMap: _propTypes.default.oneOfType([_propTypes.default.shape({
|
|
176
|
+
color: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.string.isRequired), _propTypes.default.func]).isRequired,
|
|
177
|
+
max: _propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.number]),
|
|
178
|
+
min: _propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.number]),
|
|
179
|
+
type: _propTypes.default.oneOf(['continuous']).isRequired
|
|
180
|
+
}), _propTypes.default.shape({
|
|
181
|
+
colors: _propTypes.default.arrayOf(_propTypes.default.string).isRequired,
|
|
182
|
+
thresholds: _propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.number]).isRequired).isRequired,
|
|
183
|
+
type: _propTypes.default.oneOf(['piecewise']).isRequired
|
|
184
|
+
}), _propTypes.default.shape({
|
|
185
|
+
colors: _propTypes.default.arrayOf(_propTypes.default.string).isRequired,
|
|
186
|
+
type: _propTypes.default.oneOf(['ordinal']).isRequired,
|
|
187
|
+
unknownColor: _propTypes.default.string,
|
|
188
|
+
values: _propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.number, _propTypes.default.string]).isRequired)
|
|
189
|
+
})]),
|
|
160
190
|
data: _propTypes.default.array,
|
|
161
191
|
dataKey: _propTypes.default.string,
|
|
162
192
|
disableLine: _propTypes.default.bool,
|
|
@@ -7,6 +7,7 @@ export interface ScatterProps {
|
|
|
7
7
|
yScale: D3Scale;
|
|
8
8
|
markerSize: number;
|
|
9
9
|
color: string;
|
|
10
|
+
colorGetter?: (dataIndex: number) => string;
|
|
10
11
|
/**
|
|
11
12
|
* Callback fired when clicking on a scatter item.
|
|
12
13
|
* @param {MouseEvent} event Mouse event recorded on the `<svg/>` element.
|
package/ScatterChart/Scatter.js
CHANGED
|
@@ -30,6 +30,7 @@ function Scatter(props) {
|
|
|
30
30
|
xScale,
|
|
31
31
|
yScale,
|
|
32
32
|
color,
|
|
33
|
+
colorGetter,
|
|
33
34
|
markerSize,
|
|
34
35
|
onItemClick
|
|
35
36
|
} = props;
|
|
@@ -72,19 +73,20 @@ function Scatter(props) {
|
|
|
72
73
|
isFaded: !isHighlighted && (0, _useInteractionItemProps.getIsFaded)(item, pointCtx, highlightScope),
|
|
73
74
|
interactionProps: getInteractionItemProps(pointCtx),
|
|
74
75
|
id: scatterPoint.id,
|
|
75
|
-
dataIndex: i
|
|
76
|
+
dataIndex: i,
|
|
77
|
+
color: colorGetter ? colorGetter(i) : color
|
|
76
78
|
});
|
|
77
79
|
}
|
|
78
80
|
}
|
|
79
81
|
return temp;
|
|
80
|
-
}, [xScale, yScale, series.data, series.id, item, highlightScope, getInteractionItemProps]);
|
|
82
|
+
}, [xScale, yScale, series.data, series.id, item, highlightScope, getInteractionItemProps, color, colorGetter]);
|
|
81
83
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("g", {
|
|
82
84
|
children: cleanData.map(dataPoint => /*#__PURE__*/(0, _jsxRuntime.jsx)("circle", (0, _extends2.default)({
|
|
83
85
|
cx: 0,
|
|
84
86
|
cy: 0,
|
|
85
87
|
r: (dataPoint.isHighlighted ? 1.2 : 1) * markerSize,
|
|
86
88
|
transform: `translate(${dataPoint.x}, ${dataPoint.y})`,
|
|
87
|
-
fill: color,
|
|
89
|
+
fill: dataPoint.color,
|
|
88
90
|
opacity: dataPoint.isFaded && 0.3 || 1,
|
|
89
91
|
onClick: onItemClick && (event => onItemClick(event, {
|
|
90
92
|
type: 'scatter',
|
|
@@ -101,6 +103,7 @@ process.env.NODE_ENV !== "production" ? Scatter.propTypes = {
|
|
|
101
103
|
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
102
104
|
// ----------------------------------------------------------------------
|
|
103
105
|
color: _propTypes.default.string.isRequired,
|
|
106
|
+
colorGetter: _propTypes.default.func,
|
|
104
107
|
markerSize: _propTypes.default.number.isRequired,
|
|
105
108
|
/**
|
|
106
109
|
* Callback fired when clicking on a scatter item.
|
|
@@ -336,11 +336,26 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
|
|
|
336
336
|
width: _propTypes.default.number,
|
|
337
337
|
/**
|
|
338
338
|
* The configuration of the x-axes.
|
|
339
|
-
* If not provided, a default axis config is used
|
|
339
|
+
* If not provided, a default axis config is used.
|
|
340
340
|
*/
|
|
341
341
|
xAxis: _propTypes.default.arrayOf(_propTypes.default.shape({
|
|
342
342
|
axisId: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]),
|
|
343
343
|
classes: _propTypes.default.object,
|
|
344
|
+
colorMap: _propTypes.default.oneOfType([_propTypes.default.shape({
|
|
345
|
+
color: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.string.isRequired), _propTypes.default.func]).isRequired,
|
|
346
|
+
max: _propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.number]),
|
|
347
|
+
min: _propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.number]),
|
|
348
|
+
type: _propTypes.default.oneOf(['continuous']).isRequired
|
|
349
|
+
}), _propTypes.default.shape({
|
|
350
|
+
colors: _propTypes.default.arrayOf(_propTypes.default.string).isRequired,
|
|
351
|
+
thresholds: _propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.number]).isRequired).isRequired,
|
|
352
|
+
type: _propTypes.default.oneOf(['piecewise']).isRequired
|
|
353
|
+
}), _propTypes.default.shape({
|
|
354
|
+
colors: _propTypes.default.arrayOf(_propTypes.default.string).isRequired,
|
|
355
|
+
type: _propTypes.default.oneOf(['ordinal']).isRequired,
|
|
356
|
+
unknownColor: _propTypes.default.string,
|
|
357
|
+
values: _propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.number, _propTypes.default.string]).isRequired)
|
|
358
|
+
})]),
|
|
344
359
|
data: _propTypes.default.array,
|
|
345
360
|
dataKey: _propTypes.default.string,
|
|
346
361
|
disableLine: _propTypes.default.bool,
|
|
@@ -373,11 +388,26 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
|
|
|
373
388
|
})),
|
|
374
389
|
/**
|
|
375
390
|
* The configuration of the y-axes.
|
|
376
|
-
* If not provided, a default axis config is used
|
|
391
|
+
* If not provided, a default axis config is used.
|
|
377
392
|
*/
|
|
378
393
|
yAxis: _propTypes.default.arrayOf(_propTypes.default.shape({
|
|
379
394
|
axisId: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]),
|
|
380
395
|
classes: _propTypes.default.object,
|
|
396
|
+
colorMap: _propTypes.default.oneOfType([_propTypes.default.shape({
|
|
397
|
+
color: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.string.isRequired), _propTypes.default.func]).isRequired,
|
|
398
|
+
max: _propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.number]),
|
|
399
|
+
min: _propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.number]),
|
|
400
|
+
type: _propTypes.default.oneOf(['continuous']).isRequired
|
|
401
|
+
}), _propTypes.default.shape({
|
|
402
|
+
colors: _propTypes.default.arrayOf(_propTypes.default.string).isRequired,
|
|
403
|
+
thresholds: _propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.number]).isRequired).isRequired,
|
|
404
|
+
type: _propTypes.default.oneOf(['piecewise']).isRequired
|
|
405
|
+
}), _propTypes.default.shape({
|
|
406
|
+
colors: _propTypes.default.arrayOf(_propTypes.default.string).isRequired,
|
|
407
|
+
type: _propTypes.default.oneOf(['ordinal']).isRequired,
|
|
408
|
+
unknownColor: _propTypes.default.string,
|
|
409
|
+
values: _propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.number, _propTypes.default.string]).isRequired)
|
|
410
|
+
})]),
|
|
381
411
|
data: _propTypes.default.array,
|
|
382
412
|
dataKey: _propTypes.default.string,
|
|
383
413
|
disableLine: _propTypes.default.bool,
|
|
@@ -11,6 +11,7 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
|
11
11
|
var _Scatter = require("./Scatter");
|
|
12
12
|
var _SeriesContextProvider = require("../context/SeriesContextProvider");
|
|
13
13
|
var _CartesianContextProvider = require("../context/CartesianContextProvider");
|
|
14
|
+
var _getColor = _interopRequireDefault(require("./getColor"));
|
|
14
15
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
15
16
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
16
17
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
@@ -57,12 +58,14 @@ function ScatterPlot(props) {
|
|
|
57
58
|
markerSize,
|
|
58
59
|
color
|
|
59
60
|
} = series[seriesId];
|
|
61
|
+
const colorGetter = (0, _getColor.default)(series[seriesId], xAxis[xAxisKey ?? defaultXAxisId], yAxis[yAxisKey ?? defaultYAxisId]);
|
|
60
62
|
const xScale = xAxis[xAxisKey ?? defaultXAxisId].scale;
|
|
61
63
|
const yScale = yAxis[yAxisKey ?? defaultYAxisId].scale;
|
|
62
64
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(ScatterItems, (0, _extends2.default)({
|
|
63
65
|
xScale: xScale,
|
|
64
66
|
yScale: yScale,
|
|
65
67
|
color: color,
|
|
68
|
+
colorGetter: colorGetter,
|
|
66
69
|
markerSize: markerSize ?? 4,
|
|
67
70
|
series: series[seriesId],
|
|
68
71
|
onItemClick: onItemClick
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { AxisDefaultized } from '../models/axis';
|
|
2
|
+
import { DefaultizedScatterSeriesType } from '../models/seriesType/scatter';
|
|
3
|
+
export default function getColor(series: DefaultizedScatterSeriesType, xAxis: AxisDefaultized, yAxis: AxisDefaultized): (dataIndex: number) => string;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = getColor;
|
|
7
|
+
function getColor(series, xAxis, yAxis) {
|
|
8
|
+
const yColorScale = yAxis.colorScale;
|
|
9
|
+
const xColorScale = xAxis.colorScale;
|
|
10
|
+
if (yColorScale) {
|
|
11
|
+
return dataIndex => {
|
|
12
|
+
const value = series.data[dataIndex];
|
|
13
|
+
const color = value === null ? series.color : yColorScale(value.y);
|
|
14
|
+
if (color === null) {
|
|
15
|
+
return series.color;
|
|
16
|
+
}
|
|
17
|
+
return color;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
if (xColorScale) {
|
|
21
|
+
return dataIndex => {
|
|
22
|
+
const value = series.data[dataIndex];
|
|
23
|
+
const color = value === null ? series.color : xColorScale(value.x);
|
|
24
|
+
if (color === null) {
|
|
25
|
+
return series.color;
|
|
26
|
+
}
|
|
27
|
+
return color;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
return () => series.color;
|
|
31
|
+
}
|
|
@@ -234,6 +234,21 @@ process.env.NODE_ENV !== "production" ? SparkLineChart.propTypes = {
|
|
|
234
234
|
xAxis: _propTypes.default.shape({
|
|
235
235
|
axisId: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]),
|
|
236
236
|
classes: _propTypes.default.object,
|
|
237
|
+
colorMap: _propTypes.default.oneOfType([_propTypes.default.shape({
|
|
238
|
+
color: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.string.isRequired), _propTypes.default.func]).isRequired,
|
|
239
|
+
max: _propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.number]),
|
|
240
|
+
min: _propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.number]),
|
|
241
|
+
type: _propTypes.default.oneOf(['continuous']).isRequired
|
|
242
|
+
}), _propTypes.default.shape({
|
|
243
|
+
colors: _propTypes.default.arrayOf(_propTypes.default.string).isRequired,
|
|
244
|
+
thresholds: _propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.number]).isRequired).isRequired,
|
|
245
|
+
type: _propTypes.default.oneOf(['piecewise']).isRequired
|
|
246
|
+
}), _propTypes.default.shape({
|
|
247
|
+
colors: _propTypes.default.arrayOf(_propTypes.default.string).isRequired,
|
|
248
|
+
type: _propTypes.default.oneOf(['ordinal']).isRequired,
|
|
249
|
+
unknownColor: _propTypes.default.string,
|
|
250
|
+
values: _propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.number, _propTypes.default.string]).isRequired)
|
|
251
|
+
})]),
|
|
237
252
|
data: _propTypes.default.array,
|
|
238
253
|
dataKey: _propTypes.default.string,
|
|
239
254
|
disableLine: _propTypes.default.bool,
|
|
@@ -6,12 +6,12 @@ import { MakeOptional } from '../models/helpers';
|
|
|
6
6
|
export type CartesianContextProviderProps = {
|
|
7
7
|
/**
|
|
8
8
|
* The configuration of the x-axes.
|
|
9
|
-
* If not provided, a default axis config is used
|
|
9
|
+
* If not provided, a default axis config is used.
|
|
10
10
|
*/
|
|
11
11
|
xAxis?: MakeOptional<AxisConfig, 'id'>[];
|
|
12
12
|
/**
|
|
13
13
|
* The configuration of the y-axes.
|
|
14
|
-
* If not provided, a default axis config is used
|
|
14
|
+
* If not provided, a default axis config is used.
|
|
15
15
|
*/
|
|
16
16
|
yAxis?: MakeOptional<AxisConfig, 'id'>[];
|
|
17
17
|
/**
|
|
@@ -14,10 +14,11 @@ var _extremums2 = require("../ScatterChart/extremums");
|
|
|
14
14
|
var _extremums3 = require("../LineChart/extremums");
|
|
15
15
|
var _axis = require("../models/axis");
|
|
16
16
|
var _getScale = require("../internals/getScale");
|
|
17
|
-
var _DrawingProvider = require("./DrawingProvider");
|
|
18
17
|
var _SeriesContextProvider = require("./SeriesContextProvider");
|
|
19
18
|
var _constants = require("../constants");
|
|
20
19
|
var _useTicks = require("../hooks/useTicks");
|
|
20
|
+
var _useDrawingArea = require("../hooks/useDrawingArea");
|
|
21
|
+
var _colorScale = require("../internals/colorScale");
|
|
21
22
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
22
23
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
23
24
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
@@ -52,7 +53,7 @@ function CartesianContextProvider(props) {
|
|
|
52
53
|
children
|
|
53
54
|
} = props;
|
|
54
55
|
const formattedSeries = React.useContext(_SeriesContextProvider.SeriesContext);
|
|
55
|
-
const drawingArea =
|
|
56
|
+
const drawingArea = (0, _useDrawingArea.useDrawingArea)();
|
|
56
57
|
const xAxis = React.useMemo(() => inXAxis?.map(axisConfig => {
|
|
57
58
|
const dataKey = axisConfig.dataKey;
|
|
58
59
|
if (dataKey === undefined || axisConfig.data !== undefined) {
|
|
@@ -122,13 +123,19 @@ function CartesianContextProvider(props) {
|
|
|
122
123
|
barGapRatio
|
|
123
124
|
}, axis, {
|
|
124
125
|
scale: (0, _d3Scale.scaleBand)(axis.data, range).paddingInner(categoryGapRatio).paddingOuter(categoryGapRatio / 2),
|
|
125
|
-
tickNumber: axis.data.length
|
|
126
|
+
tickNumber: axis.data.length,
|
|
127
|
+
colorScale: axis.colorMap && (axis.colorMap.type === 'ordinal' ? (0, _colorScale.getOrdinalColorScale)((0, _extends2.default)({
|
|
128
|
+
values: axis.data
|
|
129
|
+
}, axis.colorMap)) : (0, _colorScale.getColorScale)(axis.colorMap))
|
|
126
130
|
});
|
|
127
131
|
}
|
|
128
132
|
if ((0, _axis.isPointScaleConfig)(axis)) {
|
|
129
133
|
completedXAxis[axis.id] = (0, _extends2.default)({}, axis, {
|
|
130
134
|
scale: (0, _d3Scale.scalePoint)(axis.data, range),
|
|
131
|
-
tickNumber: axis.data.length
|
|
135
|
+
tickNumber: axis.data.length,
|
|
136
|
+
colorScale: axis.colorMap && (axis.colorMap.type === 'ordinal' ? (0, _colorScale.getOrdinalColorScale)((0, _extends2.default)({
|
|
137
|
+
values: axis.data
|
|
138
|
+
}, axis.colorMap)) : (0, _colorScale.getColorScale)(axis.colorMap))
|
|
132
139
|
});
|
|
133
140
|
}
|
|
134
141
|
if (axis.scaleType === 'band' || axis.scaleType === 'point') {
|
|
@@ -147,7 +154,8 @@ function CartesianContextProvider(props) {
|
|
|
147
154
|
completedXAxis[axis.id] = (0, _extends2.default)({}, axis, {
|
|
148
155
|
scaleType,
|
|
149
156
|
scale: niceScale.domain(domain),
|
|
150
|
-
tickNumber
|
|
157
|
+
tickNumber,
|
|
158
|
+
colorScale: axis.colorMap && (0, _colorScale.getColorScale)(axis.colorMap)
|
|
151
159
|
});
|
|
152
160
|
});
|
|
153
161
|
const allYAxis = [...(yAxis?.map((axis, index) => (0, _extends2.default)({
|
|
@@ -170,13 +178,19 @@ function CartesianContextProvider(props) {
|
|
|
170
178
|
barGapRatio: 0
|
|
171
179
|
}, axis, {
|
|
172
180
|
scale: (0, _d3Scale.scaleBand)(axis.data, [range[1], range[0]]).paddingInner(categoryGapRatio).paddingOuter(categoryGapRatio / 2),
|
|
173
|
-
tickNumber: axis.data.length
|
|
181
|
+
tickNumber: axis.data.length,
|
|
182
|
+
colorScale: axis.colorMap && (axis.colorMap.type === 'ordinal' ? (0, _colorScale.getOrdinalColorScale)((0, _extends2.default)({
|
|
183
|
+
values: axis.data
|
|
184
|
+
}, axis.colorMap)) : (0, _colorScale.getColorScale)(axis.colorMap))
|
|
174
185
|
});
|
|
175
186
|
}
|
|
176
187
|
if ((0, _axis.isPointScaleConfig)(axis)) {
|
|
177
188
|
completedYAxis[axis.id] = (0, _extends2.default)({}, axis, {
|
|
178
189
|
scale: (0, _d3Scale.scalePoint)(axis.data, [range[1], range[0]]),
|
|
179
|
-
tickNumber: axis.data.length
|
|
190
|
+
tickNumber: axis.data.length,
|
|
191
|
+
colorScale: axis.colorMap && (axis.colorMap.type === 'ordinal' ? (0, _colorScale.getOrdinalColorScale)((0, _extends2.default)({
|
|
192
|
+
values: axis.data
|
|
193
|
+
}, axis.colorMap)) : (0, _colorScale.getColorScale)(axis.colorMap))
|
|
180
194
|
});
|
|
181
195
|
}
|
|
182
196
|
if (axis.scaleType === 'band' || axis.scaleType === 'point') {
|
|
@@ -195,7 +209,8 @@ function CartesianContextProvider(props) {
|
|
|
195
209
|
completedYAxis[axis.id] = (0, _extends2.default)({}, axis, {
|
|
196
210
|
scaleType,
|
|
197
211
|
scale: niceScale.domain(domain),
|
|
198
|
-
tickNumber
|
|
212
|
+
tickNumber,
|
|
213
|
+
colorScale: axis.colorMap && (0, _colorScale.getColorScale)(axis.colorMap)
|
|
199
214
|
});
|
|
200
215
|
});
|
|
201
216
|
return {
|
package/esm/BarChart/BarChart.js
CHANGED
|
@@ -366,11 +366,26 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
366
366
|
width: PropTypes.number,
|
|
367
367
|
/**
|
|
368
368
|
* The configuration of the x-axes.
|
|
369
|
-
* If not provided, a default axis config is used
|
|
369
|
+
* If not provided, a default axis config is used.
|
|
370
370
|
*/
|
|
371
371
|
xAxis: PropTypes.arrayOf(PropTypes.shape({
|
|
372
372
|
axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
373
373
|
classes: PropTypes.object,
|
|
374
|
+
colorMap: PropTypes.oneOfType([PropTypes.shape({
|
|
375
|
+
color: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string.isRequired), PropTypes.func]).isRequired,
|
|
376
|
+
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
377
|
+
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
378
|
+
type: PropTypes.oneOf(['continuous']).isRequired
|
|
379
|
+
}), PropTypes.shape({
|
|
380
|
+
colors: PropTypes.arrayOf(PropTypes.string).isRequired,
|
|
381
|
+
thresholds: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired).isRequired,
|
|
382
|
+
type: PropTypes.oneOf(['piecewise']).isRequired
|
|
383
|
+
}), PropTypes.shape({
|
|
384
|
+
colors: PropTypes.arrayOf(PropTypes.string).isRequired,
|
|
385
|
+
type: PropTypes.oneOf(['ordinal']).isRequired,
|
|
386
|
+
unknownColor: PropTypes.string,
|
|
387
|
+
values: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired)
|
|
388
|
+
})]),
|
|
374
389
|
data: PropTypes.array,
|
|
375
390
|
dataKey: PropTypes.string,
|
|
376
391
|
disableLine: PropTypes.bool,
|
|
@@ -403,11 +418,26 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
403
418
|
})),
|
|
404
419
|
/**
|
|
405
420
|
* The configuration of the y-axes.
|
|
406
|
-
* If not provided, a default axis config is used
|
|
421
|
+
* If not provided, a default axis config is used.
|
|
407
422
|
*/
|
|
408
423
|
yAxis: PropTypes.arrayOf(PropTypes.shape({
|
|
409
424
|
axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
410
425
|
classes: PropTypes.object,
|
|
426
|
+
colorMap: PropTypes.oneOfType([PropTypes.shape({
|
|
427
|
+
color: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string.isRequired), PropTypes.func]).isRequired,
|
|
428
|
+
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
429
|
+
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
430
|
+
type: PropTypes.oneOf(['continuous']).isRequired
|
|
431
|
+
}), PropTypes.shape({
|
|
432
|
+
colors: PropTypes.arrayOf(PropTypes.string).isRequired,
|
|
433
|
+
thresholds: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired).isRequired,
|
|
434
|
+
type: PropTypes.oneOf(['piecewise']).isRequired
|
|
435
|
+
}), PropTypes.shape({
|
|
436
|
+
colors: PropTypes.arrayOf(PropTypes.string).isRequired,
|
|
437
|
+
type: PropTypes.oneOf(['ordinal']).isRequired,
|
|
438
|
+
unknownColor: PropTypes.string,
|
|
439
|
+
values: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired)
|
|
440
|
+
})]),
|
|
411
441
|
data: PropTypes.array,
|
|
412
442
|
dataKey: PropTypes.string,
|
|
413
443
|
disableLine: PropTypes.bool,
|
package/esm/BarChart/BarPlot.js
CHANGED
|
@@ -7,9 +7,10 @@ import { useTransition } from '@react-spring/web';
|
|
|
7
7
|
import { SeriesContext } from '../context/SeriesContextProvider';
|
|
8
8
|
import { CartesianContext } from '../context/CartesianContextProvider';
|
|
9
9
|
import { BarElement } from './BarElement';
|
|
10
|
-
import { isBandScaleConfig } from '../models/axis';
|
|
10
|
+
import { isBandScaleConfig, isPointScaleConfig } from '../models/axis';
|
|
11
11
|
import { DEFAULT_X_AXIS_KEY, DEFAULT_Y_AXIS_KEY } from '../constants';
|
|
12
|
-
import
|
|
12
|
+
import getColor from './getColor';
|
|
13
|
+
|
|
13
14
|
/**
|
|
14
15
|
* Solution of the equations
|
|
15
16
|
* W = barWidth * N + offset * (N-1)
|
|
@@ -19,6 +20,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
19
20
|
* @param gapRatio The ratio of the gap between bars over the bar width.
|
|
20
21
|
* @returns The bar width and the offset between bars.
|
|
21
22
|
*/
|
|
23
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
22
24
|
function getBandSize({
|
|
23
25
|
bandWidth: W,
|
|
24
26
|
numberOfGroups: N,
|
|
@@ -74,6 +76,9 @@ const useAggregatedData = () => {
|
|
|
74
76
|
throw new Error(`MUI X Charts: ${xAxisKey === DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : `The x-axis with id "${xAxisKey}"`} shoud have data property.`);
|
|
75
77
|
}
|
|
76
78
|
baseScaleConfig = xAxisConfig;
|
|
79
|
+
if (isBandScaleConfig(yAxisConfig) || isPointScaleConfig(yAxisConfig)) {
|
|
80
|
+
throw new Error(`MUI X Charts: ${yAxisKey === DEFAULT_Y_AXIS_KEY ? 'The first `yAxis`' : `The y-axis with id "${yAxisKey}"`} shoud be a continuous type to display the bar series of id "${seriesId}".`);
|
|
81
|
+
}
|
|
77
82
|
} else {
|
|
78
83
|
if (!isBandScaleConfig(yAxisConfig)) {
|
|
79
84
|
throw new Error(`MUI X Charts: ${yAxisKey === DEFAULT_Y_AXIS_KEY ? 'The first `yAxis`' : `The y-axis with id "${yAxisKey}"`} shoud be of type "band" to display the bar series of id "${seriesId}".`);
|
|
@@ -82,9 +87,13 @@ const useAggregatedData = () => {
|
|
|
82
87
|
throw new Error(`MUI X Charts: ${yAxisKey === DEFAULT_Y_AXIS_KEY ? 'The first `yAxis`' : `The y-axis with id "${yAxisKey}"`} shoud have data property.`);
|
|
83
88
|
}
|
|
84
89
|
baseScaleConfig = yAxisConfig;
|
|
90
|
+
if (isBandScaleConfig(xAxisConfig) || isPointScaleConfig(xAxisConfig)) {
|
|
91
|
+
throw new Error(`MUI X Charts: ${xAxisKey === DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : `The x-axis with id "${xAxisKey}"`} shoud be a continuous type to display the bar series of id "${seriesId}".`);
|
|
92
|
+
}
|
|
85
93
|
}
|
|
86
94
|
const xScale = xAxisConfig.scale;
|
|
87
95
|
const yScale = yAxisConfig.scale;
|
|
96
|
+
const colorGetter = getColor(series[seriesId], xAxis[xAxisKey], yAxis[yAxisKey]);
|
|
88
97
|
const bandWidth = baseScaleConfig.scale.bandwidth();
|
|
89
98
|
const {
|
|
90
99
|
barWidth,
|
|
@@ -96,8 +105,7 @@ const useAggregatedData = () => {
|
|
|
96
105
|
});
|
|
97
106
|
const barOffset = groupIndex * (barWidth + offset);
|
|
98
107
|
const {
|
|
99
|
-
stackedData
|
|
100
|
-
color
|
|
108
|
+
stackedData
|
|
101
109
|
} = series[seriesId];
|
|
102
110
|
return stackedData.map((values, dataIndex) => {
|
|
103
111
|
const valueCoordinates = values.map(v => verticalLayout ? yScale(v) : xScale(v));
|
|
@@ -113,7 +121,7 @@ const useAggregatedData = () => {
|
|
|
113
121
|
yOrigin: yScale(0),
|
|
114
122
|
height: verticalLayout ? maxValueCoord - minValueCoord : barWidth,
|
|
115
123
|
width: verticalLayout ? barWidth : maxValueCoord - minValueCoord,
|
|
116
|
-
color,
|
|
124
|
+
color: colorGetter(dataIndex),
|
|
117
125
|
highlightScope: series[seriesId].highlightScope
|
|
118
126
|
};
|
|
119
127
|
});
|