@mui/x-charts 9.1.0 → 9.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 +10 -10
- package/BarChart/BarChart.mjs +10 -10
- package/BarChart/seriesConfig/bar/getColor.js +7 -53
- package/BarChart/seriesConfig/bar/getColor.mjs +7 -53
- package/BarChart/seriesConfig/bar/seriesProcessor.js +3 -1
- package/BarChart/seriesConfig/bar/seriesProcessor.mjs +3 -1
- package/BarChart/seriesConfig/bar/tooltip.js +4 -27
- package/BarChart/seriesConfig/bar/tooltip.mjs +4 -27
- package/CHANGELOG.md +221 -0
- package/ChartsContainer/ChartsContainer.js +9 -9
- package/ChartsContainer/ChartsContainer.mjs +9 -9
- package/ChartsLabel/ChartsLabelMark.js +0 -2
- package/ChartsLabel/ChartsLabelMark.mjs +0 -2
- package/ChartsLabel/labelMarkClasses.d.mts +0 -1
- package/ChartsLabel/labelMarkClasses.d.ts +0 -1
- package/ChartsLabel/labelMarkClasses.js +1 -2
- package/ChartsLabel/labelMarkClasses.mjs +2 -2
- package/ChartsLayerContainer/ChartsLayerContainer.js +36 -30
- package/ChartsLayerContainer/ChartsLayerContainer.mjs +36 -30
- package/ChartsRadialAxisHighlight/ChartsRadialAxisHighlight.types.d.mts +1 -1
- package/ChartsRadialAxisHighlight/ChartsRadialAxisHighlight.types.d.ts +1 -1
- package/ChartsRadialAxisHighlight/ChartsRadiusAxisHighlight.js +31 -14
- package/ChartsRadialAxisHighlight/ChartsRadiusAxisHighlight.mjs +32 -15
- package/ChartsRadiusAxis/ChartsRadiusAxis.d.mts +1 -47
- package/ChartsRadiusAxis/ChartsRadiusAxis.d.ts +1 -47
- package/ChartsRadiusAxis/ChartsRadiusAxis.js +20 -16
- package/ChartsRadiusAxis/ChartsRadiusAxis.mjs +21 -15
- package/ChartsRotationAxis/ChartsRotationAxis.d.mts +1 -47
- package/ChartsRotationAxis/ChartsRotationAxis.d.ts +1 -47
- package/ChartsRotationAxis/ChartsRotationAxis.js +16 -19
- package/ChartsRotationAxis/ChartsRotationAxis.mjs +17 -18
- package/ChartsTooltip/useAxesTooltip.d.mts +1 -1
- package/ChartsTooltip/useAxesTooltip.d.ts +1 -1
- package/ChartsTooltip/useAxesTooltip.js +11 -2
- package/ChartsTooltip/useAxesTooltip.mjs +12 -3
- package/ChartsXAxis/ChartsXAxis.js +3 -1
- package/ChartsXAxis/ChartsXAxis.mjs +3 -1
- package/ChartsYAxis/ChartsYAxis.js +3 -1
- package/ChartsYAxis/ChartsYAxis.mjs +3 -1
- package/LineChart/LineChart.js +6 -6
- package/LineChart/LineChart.mjs +6 -6
- package/LineChart/seriesConfig/curveEvaluation.js +12 -1
- package/LineChart/seriesConfig/curveEvaluation.mjs +12 -1
- package/LineChart/seriesConfig/getColor.js +7 -54
- package/LineChart/seriesConfig/getColor.mjs +7 -54
- package/LineChart/seriesConfig/seriesProcessor.d.mts +2 -4
- package/LineChart/seriesConfig/seriesProcessor.d.ts +2 -4
- package/LineChart/seriesConfig/seriesProcessor.js +2 -139
- package/LineChart/seriesConfig/seriesProcessor.mjs +2 -138
- package/LineChart/seriesConfig/tooltip.js +4 -25
- package/LineChart/seriesConfig/tooltip.mjs +4 -25
- package/PieChart/PieChart.js +6 -6
- package/PieChart/PieChart.mjs +6 -6
- package/RadarChart/RadarAxis/useRadarAxis.js +1 -1
- package/RadarChart/RadarAxis/useRadarAxis.mjs +1 -1
- package/RadarChart/RadarChart.js +8 -8
- package/RadarChart/RadarChart.mjs +8 -8
- package/RadarChart/RadarGrid/CircularRadarStripes.js +2 -3
- package/RadarChart/RadarGrid/CircularRadarStripes.mjs +2 -3
- package/RadarChart/RadarSeriesPlot/RadarSeriesArea.js +3 -1
- package/RadarChart/RadarSeriesPlot/RadarSeriesArea.mjs +3 -1
- package/RadarChart/RadarSeriesPlot/RadarSeriesMarks.js +1 -0
- package/RadarChart/RadarSeriesPlot/RadarSeriesMarks.mjs +1 -0
- package/RadarChart/RadarSeriesPlot/RadarSeriesPlot.js +1 -0
- package/RadarChart/RadarSeriesPlot/RadarSeriesPlot.mjs +1 -0
- package/RadarChart/RadarSeriesPlot/useRadarRotationIndex.js +1 -1
- package/RadarChart/RadarSeriesPlot/useRadarRotationIndex.mjs +2 -2
- package/ScatterChart/ScatterChart.js +11 -11
- package/ScatterChart/ScatterChart.mjs +11 -11
- package/ScatterChart/seriesConfig/tooltip.js +2 -24
- package/ScatterChart/seriesConfig/tooltip.mjs +2 -24
- package/SparkLineChart/SparkLineChart.js +27 -27
- package/SparkLineChart/SparkLineChart.mjs +27 -27
- package/index.js +1 -1
- package/index.mjs +1 -1
- package/internals/components/ChartsAccessibilityProxy/ChartsAccessibilityProxy.js +1 -1
- package/internals/components/ChartsAccessibilityProxy/ChartsAccessibilityProxy.mjs +1 -1
- package/internals/getLineLikeTooltip.d.mts +9 -0
- package/internals/getLineLikeTooltip.d.ts +9 -0
- package/internals/getLineLikeTooltip.js +38 -0
- package/internals/getLineLikeTooltip.mjs +31 -0
- package/internals/getRingPath.d.mts +16 -0
- package/internals/getRingPath.d.ts +16 -0
- package/internals/getRingPath.js +39 -0
- package/internals/getRingPath.mjs +33 -0
- package/internals/index.d.mts +7 -2
- package/internals/index.d.ts +7 -2
- package/internals/index.js +46 -3
- package/internals/index.mjs +6 -2
- package/internals/plugins/corePlugins/useChartSeriesConfig/types/tooltipGetter.types.d.mts +4 -2
- package/internals/plugins/corePlugins/useChartSeriesConfig/types/tooltipGetter.types.d.ts +4 -2
- package/internals/plugins/featurePlugins/useChartCartesianAxis/createZoomLookup.d.mts +3 -3
- package/internals/plugins/featurePlugins/useChartCartesianAxis/createZoomLookup.d.ts +3 -3
- package/internals/plugins/featurePlugins/useChartCartesianAxis/index.d.mts +1 -0
- package/internals/plugins/featurePlugins/useChartCartesianAxis/index.d.ts +1 -0
- package/internals/plugins/featurePlugins/useChartCartesianAxis/index.js +8 -0
- package/internals/plugins/featurePlugins/useChartCartesianAxis/index.mjs +1 -0
- package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisPosition.selectors.d.mts +6 -1
- package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisPosition.selectors.d.ts +6 -1
- package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisPosition.selectors.js +48 -36
- package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisPosition.selectors.mjs +47 -36
- package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisRendering.selectors.d.mts +74 -1
- package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisRendering.selectors.d.ts +74 -1
- package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianHighlight.selectors.d.mts +152 -2
- package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianHighlight.selectors.d.ts +152 -2
- package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianInteraction.selectors.d.mts +2 -2
- package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianInteraction.selectors.d.ts +2 -2
- package/internals/plugins/featurePlugins/useChartHighlight/useChartHighlight.js +3 -0
- package/internals/plugins/featurePlugins/useChartHighlight/useChartHighlight.mjs +3 -0
- package/internals/plugins/featurePlugins/useChartPolarAxis/getAxisExtremum.d.mts +2 -2
- package/internals/plugins/featurePlugins/useChartPolarAxis/getAxisExtremum.d.ts +2 -2
- package/internals/plugins/featurePlugins/useChartPolarAxis/getAxisIndex.d.mts +6 -1
- package/internals/plugins/featurePlugins/useChartPolarAxis/getAxisIndex.d.ts +6 -1
- package/internals/plugins/featurePlugins/useChartPolarAxis/getAxisIndex.js +36 -2
- package/internals/plugins/featurePlugins/useChartPolarAxis/getAxisIndex.mjs +34 -1
- package/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarAxis.js +1 -1
- package/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarAxis.mjs +2 -2
- package/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarInteraction.selectors.d.mts +22 -2
- package/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarInteraction.selectors.d.ts +22 -2
- package/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarInteraction.selectors.js +73 -12
- package/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarInteraction.selectors.mjs +74 -12
- package/internals/processLineLikeSeries.d.mts +6 -0
- package/internals/processLineLikeSeries.d.ts +6 -0
- package/internals/processLineLikeSeries.js +145 -0
- package/internals/processLineLikeSeries.mjs +138 -0
- package/internals/resolveColorProcessor.d.mts +11 -0
- package/internals/resolveColorProcessor.d.ts +11 -0
- package/internals/resolveColorProcessor.js +62 -0
- package/internals/resolveColorProcessor.mjs +56 -0
- package/models/axis.d.mts +55 -7
- package/models/axis.d.ts +55 -7
- package/package.json +3 -3
package/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarInteraction.selectors.mjs
CHANGED
|
@@ -2,8 +2,8 @@ import { isDeepEqual } from '@mui/x-internals/isDeepEqual';
|
|
|
2
2
|
import { createSelector, createSelectorMemoizedWithOptions } from '@mui/x-internals/store';
|
|
3
3
|
import { selectorChartsInteractionPointerX, selectorChartsInteractionPointerY } from "../useChartInteraction/useChartInteraction.selectors.mjs";
|
|
4
4
|
import { generateSvg2rotation } from "./coordinateTransformation.mjs";
|
|
5
|
-
import {
|
|
6
|
-
import { selectorChartPolarCenter, selectorChartRotationAxis } from "./useChartPolarAxis.selectors.mjs";
|
|
5
|
+
import { getRotationAxisIndex, getRadiusAxisIndex } from "./getAxisIndex.mjs";
|
|
6
|
+
import { selectorChartPolarCenter, selectorChartRadiusAxis, selectorChartRotationAxis } from "./useChartPolarAxis.selectors.mjs";
|
|
7
7
|
const optionalGetAxisId = (_, id) => id;
|
|
8
8
|
const optionalGetAxisIds = (_, ids) => ids;
|
|
9
9
|
|
|
@@ -11,10 +11,17 @@ const optionalGetAxisIds = (_, ids) => ids;
|
|
|
11
11
|
* Get interaction indexes
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
function indexGetter(value, axes, ids) {
|
|
15
|
-
|
|
14
|
+
function indexGetter(value, axes, ids, type) {
|
|
15
|
+
if (type === 'rotation') {
|
|
16
|
+
const rotationAxes = axes;
|
|
17
|
+
return Array.isArray(ids) ? ids.map(id => getRotationAxisIndex(rotationAxes.axis[id], value)) : getRotationAxisIndex(rotationAxes.axis[ids], value);
|
|
18
|
+
}
|
|
19
|
+
const radiusAxes = axes;
|
|
20
|
+
return Array.isArray(ids) ? ids.map(id => getRadiusAxisIndex(radiusAxes.axis[id], value)) : getRadiusAxisIndex(radiusAxes.axis[ids], value);
|
|
16
21
|
}
|
|
17
22
|
|
|
23
|
+
// ============================= Rotation axis =============================
|
|
24
|
+
|
|
18
25
|
/**
|
|
19
26
|
* Helper to get the rotation associated to the interaction coordinate.
|
|
20
27
|
*/
|
|
@@ -24,8 +31,8 @@ const selectorChartsInteractionRotationAngle = createSelector(selectorChartsInte
|
|
|
24
31
|
}
|
|
25
32
|
return generateSvg2rotation(center)(x, y);
|
|
26
33
|
});
|
|
27
|
-
export const selectorChartsInteractionRotationAxisIndex = createSelector(selectorChartsInteractionRotationAngle, selectorChartRotationAxis, optionalGetAxisId, (rotation, rotationAxis, id) => rotation === null ? null : indexGetter(rotation, rotationAxis, id ?? rotationAxis.axisIds[0]));
|
|
28
|
-
export const selectorChartsInteractionRotationAxisIndexes = createSelector(selectorChartsInteractionRotationAngle, selectorChartRotationAxis, optionalGetAxisIds, (rotation, rotationAxis, ids) => rotation === null ? null : indexGetter(rotation, rotationAxis, ids ?? rotationAxis.axisIds));
|
|
34
|
+
export const selectorChartsInteractionRotationAxisIndex = createSelector(selectorChartsInteractionRotationAngle, selectorChartRotationAxis, optionalGetAxisId, (rotation, rotationAxis, id) => rotation === null ? null : indexGetter(rotation, rotationAxis, id ?? rotationAxis.axisIds[0], 'rotation'));
|
|
35
|
+
export const selectorChartsInteractionRotationAxisIndexes = createSelector(selectorChartsInteractionRotationAngle, selectorChartRotationAxis, optionalGetAxisIds, (rotation, rotationAxis, ids) => rotation === null ? null : indexGetter(rotation, rotationAxis, ids ?? rotationAxis.axisIds, 'rotation'));
|
|
29
36
|
export const selectorChartsInteractionRotationAxisValue = createSelector(selectorChartRotationAxis, selectorChartsInteractionRotationAxisIndex, optionalGetAxisId, (rotationAxis, rotationIndex, id) => {
|
|
30
37
|
id = id ?? rotationAxis.axisIds[0];
|
|
31
38
|
if (rotationIndex === null || rotationIndex === -1 || rotationAxis.axisIds.length === 0) {
|
|
@@ -74,15 +81,70 @@ export const selectorChartsInteractionTooltipRotationAxes = createSelectorMemoiz
|
|
|
74
81
|
}) => axes.axis[axisId].triggerTooltip && dataIndex >= 0);
|
|
75
82
|
});
|
|
76
83
|
|
|
84
|
+
// ============================= Radius axis =============================
|
|
85
|
+
|
|
77
86
|
/**
|
|
78
|
-
*
|
|
87
|
+
* Helper to get the radius associated to the interaction coordinate.
|
|
79
88
|
*/
|
|
80
|
-
export const
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
89
|
+
export const selectorChartsInteractionRadius = createSelector(selectorChartsInteractionPointerX, selectorChartsInteractionPointerY, selectorChartPolarCenter, (x, y, center) => {
|
|
90
|
+
if (x === null || y === null) {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
return Math.sqrt((x - center.cx) ** 2 + (y - center.cy) ** 2);
|
|
94
|
+
});
|
|
95
|
+
export const selectorChartsInteractionRadiusAxisIndex = createSelector(selectorChartsInteractionRadius, selectorChartRadiusAxis, optionalGetAxisId, (radius, radiusAxis, id) => radius === null ? null : indexGetter(radius, radiusAxis, id ?? radiusAxis.axisIds[0], 'radius'));
|
|
96
|
+
export const selectorChartsInteractionRadiusAxisIndexes = createSelector(selectorChartsInteractionRadius, selectorChartRadiusAxis, optionalGetAxisIds, (radius, radiusAxis, ids) => radius === null ? null : indexGetter(radius, radiusAxis, ids ?? radiusAxis.axisIds, 'radius'));
|
|
97
|
+
export const selectorChartsInteractionRadiusAxisValue = createSelector(selectorChartRadiusAxis, selectorChartsInteractionRadiusAxisIndex, optionalGetAxisId, (radiusAxis, radiusIndex, id) => {
|
|
98
|
+
id = id ?? radiusAxis.axisIds[0];
|
|
99
|
+
if (radiusIndex === null || radiusIndex === -1 || radiusAxis.axisIds.length === 0) {
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
const data = radiusAxis.axis[id]?.data;
|
|
103
|
+
if (!data) {
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
return data[radiusIndex];
|
|
107
|
+
});
|
|
108
|
+
export const selectorChartsInteractionRadiusAxisValues = createSelector(selectorChartRadiusAxis, selectorChartsInteractionRadiusAxisIndexes, optionalGetAxisIds, (radiusAxis, radiusIndexes, ids) => {
|
|
109
|
+
ids = ids ?? radiusAxis.axisIds;
|
|
110
|
+
if (radiusIndexes === null) {
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
return ids.map((id, axisIndex) => {
|
|
114
|
+
const radiusIndex = radiusIndexes[axisIndex];
|
|
115
|
+
if (radiusIndex === -1) {
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
return radiusAxis.axis[id].data?.[radiusIndex];
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Get radius-axis ids and corresponding data index that should be display in the tooltip.
|
|
124
|
+
*/
|
|
125
|
+
export const selectorChartsInteractionTooltipRadiusAxes = createSelectorMemoizedWithOptions({
|
|
126
|
+
memoizeOptions: {
|
|
127
|
+
// Keep the same reference if array content is the same.
|
|
128
|
+
// If possible, avoid this pattern by creating selectors that
|
|
129
|
+
// uses string/number as arguments.
|
|
130
|
+
resultEqualityCheck: isDeepEqual
|
|
131
|
+
}
|
|
132
|
+
})(selectorChartsInteractionRadiusAxisIndexes, selectorChartRadiusAxis, (indexes, axes) => {
|
|
133
|
+
if (indexes === null) {
|
|
134
|
+
return [];
|
|
135
|
+
}
|
|
136
|
+
return axes.axisIds.map((axisId, axisIndex) => ({
|
|
137
|
+
axisId,
|
|
138
|
+
dataIndex: indexes[axisIndex]
|
|
139
|
+
})).filter(({
|
|
140
|
+
axisId,
|
|
141
|
+
dataIndex
|
|
142
|
+
}) => axes.axis[axisId].triggerTooltip && dataIndex >= 0);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
// ============================= Cross axes selectors =============================
|
|
84
146
|
|
|
85
147
|
/**
|
|
86
148
|
* Return `true` if the axis tooltip has something to display.
|
|
87
149
|
*/
|
|
88
|
-
export const selectorChartsInteractionPolarAxisTooltip = createSelector(selectorChartsInteractionTooltipRotationAxes, rotationTooltip => rotationTooltip.length > 0);
|
|
150
|
+
export const selectorChartsInteractionPolarAxisTooltip = createSelector(selectorChartsInteractionTooltipRotationAxes, selectorChartsInteractionTooltipRadiusAxes, (rotationTooltip, radiusTooltip) => rotationTooltip.length > 0 || radiusTooltip.length > 0);
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type ChartSeriesType, type DatasetType } from "../models/seriesType/config.mjs";
|
|
2
|
+
import type { SeriesProcessorParams, SeriesProcessorResult } from "./plugins/corePlugins/useChartSeriesConfig/index.mjs";
|
|
3
|
+
import type { IsItemVisibleFunction } from "./plugins/featurePlugins/useChartVisibilityManager/index.mjs";
|
|
4
|
+
type LineLikeChartType = Extract<ChartSeriesType, 'line' | 'radialLine'>;
|
|
5
|
+
export declare function processLineLikeSeries<SeriesType extends LineLikeChartType>(params: SeriesProcessorParams<SeriesType>, dataset: Readonly<DatasetType> | undefined, isItemVisible: IsItemVisibleFunction | undefined, seriesType: SeriesType): SeriesProcessorResult<SeriesType>;
|
|
6
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type ChartSeriesType, type DatasetType } from "../models/seriesType/config.js";
|
|
2
|
+
import type { SeriesProcessorParams, SeriesProcessorResult } from "./plugins/corePlugins/useChartSeriesConfig/index.js";
|
|
3
|
+
import type { IsItemVisibleFunction } from "./plugins/featurePlugins/useChartVisibilityManager/index.js";
|
|
4
|
+
type LineLikeChartType = Extract<ChartSeriesType, 'line' | 'radialLine'>;
|
|
5
|
+
export declare function processLineLikeSeries<SeriesType extends LineLikeChartType>(params: SeriesProcessorParams<SeriesType>, dataset: Readonly<DatasetType> | undefined, isItemVisible: IsItemVisibleFunction | undefined, seriesType: SeriesType): SeriesProcessorResult<SeriesType>;
|
|
6
|
+
export {};
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.processLineLikeSeries = processLineLikeSeries;
|
|
8
|
+
var _formatErrorMessage2 = _interopRequireDefault(require("@mui/x-internals/formatErrorMessage"));
|
|
9
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
10
|
+
var _d3Shape = require("@mui/x-charts-vendor/d3-shape");
|
|
11
|
+
var _warning = require("@mui/x-internals/warning");
|
|
12
|
+
var _stacking = require("./stacking");
|
|
13
|
+
const defaultShapes = ['circle', 'square', 'diamond', 'cross', 'star', 'triangle', 'wye'];
|
|
14
|
+
const lineValueFormatter = v => v == null ? '' : v.toLocaleString();
|
|
15
|
+
function processLineLikeSeries(params, dataset, isItemVisible, seriesType) {
|
|
16
|
+
const {
|
|
17
|
+
seriesOrder,
|
|
18
|
+
series
|
|
19
|
+
} = params;
|
|
20
|
+
const stackingGroups = (0, _stacking.getStackingGroups)((0, _extends2.default)({}, params, {
|
|
21
|
+
defaultStrategy: {
|
|
22
|
+
stackOffset: 'none'
|
|
23
|
+
}
|
|
24
|
+
}));
|
|
25
|
+
const idToIndex = new Map();
|
|
26
|
+
const d3Dataset = dataset ?? [];
|
|
27
|
+
seriesOrder.forEach((id, seriesIndex) => {
|
|
28
|
+
idToIndex.set(id, seriesIndex);
|
|
29
|
+
const data = series[id].data;
|
|
30
|
+
if (data !== undefined) {
|
|
31
|
+
data.forEach((value, dataIndex) => {
|
|
32
|
+
if (d3Dataset.length <= dataIndex) {
|
|
33
|
+
d3Dataset.push({
|
|
34
|
+
[id]: value
|
|
35
|
+
});
|
|
36
|
+
} else {
|
|
37
|
+
d3Dataset[dataIndex][id] = value;
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
} else if (series[id].valueGetter && dataset) {
|
|
41
|
+
dataset.forEach((entry, dataIndex) => {
|
|
42
|
+
const value = series[id].valueGetter(entry);
|
|
43
|
+
if (d3Dataset.length <= dataIndex) {
|
|
44
|
+
d3Dataset.push({
|
|
45
|
+
[id]: value
|
|
46
|
+
});
|
|
47
|
+
} else {
|
|
48
|
+
d3Dataset[dataIndex][id] = value;
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
} else if (dataset === undefined && process.env.NODE_ENV !== 'production') {
|
|
52
|
+
const titleCase = seriesType === 'line' ? 'Line' : 'Radial line';
|
|
53
|
+
// TODO: fix mui/no-guarded-throw
|
|
54
|
+
// eslint-disable-next-line mui/no-guarded-throw
|
|
55
|
+
throw new Error(process.env.NODE_ENV !== "production" ? `MUI X Charts: ${titleCase} series with id="${id}" has no data. ` + 'The chart cannot render this series without data. ' + 'Provide a data property to the series or use the dataset prop.' : (0, _formatErrorMessage2.default)(276, titleCase, id));
|
|
56
|
+
}
|
|
57
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
58
|
+
if (!data && dataset) {
|
|
59
|
+
const dataKey = series[id].dataKey;
|
|
60
|
+
if (!dataKey && !series[id].valueGetter) {
|
|
61
|
+
const titleCase = seriesType === 'line' ? 'Line' : 'Radial line';
|
|
62
|
+
// TODO: fix mui/no-guarded-throw
|
|
63
|
+
// eslint-disable-next-line mui/no-guarded-throw
|
|
64
|
+
throw new Error(`MUI X Charts: ${titleCase} series with id="${id}" has no data, no dataKey, and no valueGetter. ` + 'When using the dataset prop, each series must have a dataKey or valueGetter to identify which dataset values to use. ' + 'Add a dataKey or valueGetter property to the series configuration.');
|
|
65
|
+
}
|
|
66
|
+
if (dataKey) {
|
|
67
|
+
const titleCase = seriesType === 'line' ? 'Line' : 'Radial line';
|
|
68
|
+
const lowerCase = seriesType === 'line' ? 'lines' : 'radial lines';
|
|
69
|
+
dataset.forEach((entry, index) => {
|
|
70
|
+
const value = entry[dataKey];
|
|
71
|
+
if (value != null && typeof value !== 'number') {
|
|
72
|
+
(0, _warning.warnOnce)(`MUI X Charts: your dataset key "${dataKey}" is used for plotting ${lowerCase}, but the dataset contains the non-null non-numerical element "${value}" at index ${index}.
|
|
73
|
+
${titleCase} plots only support numeric and null values.`);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
const completedSeries = {};
|
|
81
|
+
stackingGroups.forEach(stackingGroup => {
|
|
82
|
+
const {
|
|
83
|
+
ids,
|
|
84
|
+
stackingOffset,
|
|
85
|
+
stackingOrder
|
|
86
|
+
} = stackingGroup;
|
|
87
|
+
const keys = ids.map(id => {
|
|
88
|
+
const dataKey = series[id].dataKey;
|
|
89
|
+
return series[id].data === undefined && dataKey !== undefined ? dataKey : id;
|
|
90
|
+
});
|
|
91
|
+
const stackedData = (0, _d3Shape.stack)().keys(keys).value((d, key) => d[key] ?? 0).order(stackingOrder).offset(stackingOffset)(d3Dataset);
|
|
92
|
+
const idOrder = stackedData.map(s => s.index);
|
|
93
|
+
const fixedOrder = () => idOrder;
|
|
94
|
+
const visibleStackedData = (0, _d3Shape.stack)().keys(keys).value((d, key) => {
|
|
95
|
+
const keyIndex = keys.indexOf(key);
|
|
96
|
+
const seriesId = ids[keyIndex];
|
|
97
|
+
if (!isItemVisible?.({
|
|
98
|
+
type: seriesType,
|
|
99
|
+
seriesId
|
|
100
|
+
})) {
|
|
101
|
+
return 0;
|
|
102
|
+
}
|
|
103
|
+
return d[key] ?? 0;
|
|
104
|
+
}).order(fixedOrder).offset(stackingOffset)(d3Dataset);
|
|
105
|
+
ids.forEach((id, index) => {
|
|
106
|
+
const {
|
|
107
|
+
dataKey,
|
|
108
|
+
valueGetter
|
|
109
|
+
} = series[id];
|
|
110
|
+
let data;
|
|
111
|
+
if (valueGetter) {
|
|
112
|
+
data = dataset.map(d => valueGetter(d));
|
|
113
|
+
} else if (dataKey) {
|
|
114
|
+
data = dataset.map(d => {
|
|
115
|
+
const value = d[dataKey];
|
|
116
|
+
return typeof value === 'number' ? value : null;
|
|
117
|
+
});
|
|
118
|
+
} else {
|
|
119
|
+
data = series[id].data;
|
|
120
|
+
}
|
|
121
|
+
const hidden = !isItemVisible?.({
|
|
122
|
+
type: seriesType,
|
|
123
|
+
seriesId: id
|
|
124
|
+
});
|
|
125
|
+
// SAFETY: 'line' and 'radialLine' series inputs are structurally identical for the
|
|
126
|
+
// fields needed to build the defaultized series result. The differing axis-ID fields
|
|
127
|
+
// are passed through via spread without being read.
|
|
128
|
+
completedSeries[id] = (0, _extends2.default)({
|
|
129
|
+
labelMarkType: 'line+mark'
|
|
130
|
+
}, series[id], {
|
|
131
|
+
shape: series[id].shape ?? defaultShapes[(idToIndex.get(id) ?? 0) % defaultShapes.length],
|
|
132
|
+
data,
|
|
133
|
+
valueFormatter: series[id].valueFormatter ?? lineValueFormatter,
|
|
134
|
+
hidden,
|
|
135
|
+
stackedData: stackedData[index],
|
|
136
|
+
visibleStackedData: visibleStackedData[index]
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
return {
|
|
141
|
+
seriesOrder,
|
|
142
|
+
stackingGroups,
|
|
143
|
+
series: completedSeries
|
|
144
|
+
};
|
|
145
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import _formatErrorMessage from "@mui/x-internals/formatErrorMessage";
|
|
2
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
3
|
+
import { stack as d3Stack } from '@mui/x-charts-vendor/d3-shape';
|
|
4
|
+
import { warnOnce } from '@mui/x-internals/warning';
|
|
5
|
+
import { getStackingGroups } from "./stacking/index.mjs";
|
|
6
|
+
const defaultShapes = ['circle', 'square', 'diamond', 'cross', 'star', 'triangle', 'wye'];
|
|
7
|
+
const lineValueFormatter = v => v == null ? '' : v.toLocaleString();
|
|
8
|
+
export function processLineLikeSeries(params, dataset, isItemVisible, seriesType) {
|
|
9
|
+
const {
|
|
10
|
+
seriesOrder,
|
|
11
|
+
series
|
|
12
|
+
} = params;
|
|
13
|
+
const stackingGroups = getStackingGroups(_extends({}, params, {
|
|
14
|
+
defaultStrategy: {
|
|
15
|
+
stackOffset: 'none'
|
|
16
|
+
}
|
|
17
|
+
}));
|
|
18
|
+
const idToIndex = new Map();
|
|
19
|
+
const d3Dataset = dataset ?? [];
|
|
20
|
+
seriesOrder.forEach((id, seriesIndex) => {
|
|
21
|
+
idToIndex.set(id, seriesIndex);
|
|
22
|
+
const data = series[id].data;
|
|
23
|
+
if (data !== undefined) {
|
|
24
|
+
data.forEach((value, dataIndex) => {
|
|
25
|
+
if (d3Dataset.length <= dataIndex) {
|
|
26
|
+
d3Dataset.push({
|
|
27
|
+
[id]: value
|
|
28
|
+
});
|
|
29
|
+
} else {
|
|
30
|
+
d3Dataset[dataIndex][id] = value;
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
} else if (series[id].valueGetter && dataset) {
|
|
34
|
+
dataset.forEach((entry, dataIndex) => {
|
|
35
|
+
const value = series[id].valueGetter(entry);
|
|
36
|
+
if (d3Dataset.length <= dataIndex) {
|
|
37
|
+
d3Dataset.push({
|
|
38
|
+
[id]: value
|
|
39
|
+
});
|
|
40
|
+
} else {
|
|
41
|
+
d3Dataset[dataIndex][id] = value;
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
} else if (dataset === undefined && process.env.NODE_ENV !== 'production') {
|
|
45
|
+
const titleCase = seriesType === 'line' ? 'Line' : 'Radial line';
|
|
46
|
+
// TODO: fix mui/no-guarded-throw
|
|
47
|
+
// eslint-disable-next-line mui/no-guarded-throw
|
|
48
|
+
throw new Error(process.env.NODE_ENV !== "production" ? `MUI X Charts: ${titleCase} series with id="${id}" has no data. ` + 'The chart cannot render this series without data. ' + 'Provide a data property to the series or use the dataset prop.' : _formatErrorMessage(276, titleCase, id));
|
|
49
|
+
}
|
|
50
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
51
|
+
if (!data && dataset) {
|
|
52
|
+
const dataKey = series[id].dataKey;
|
|
53
|
+
if (!dataKey && !series[id].valueGetter) {
|
|
54
|
+
const titleCase = seriesType === 'line' ? 'Line' : 'Radial line';
|
|
55
|
+
// TODO: fix mui/no-guarded-throw
|
|
56
|
+
// eslint-disable-next-line mui/no-guarded-throw
|
|
57
|
+
throw new Error(`MUI X Charts: ${titleCase} series with id="${id}" has no data, no dataKey, and no valueGetter. ` + 'When using the dataset prop, each series must have a dataKey or valueGetter to identify which dataset values to use. ' + 'Add a dataKey or valueGetter property to the series configuration.');
|
|
58
|
+
}
|
|
59
|
+
if (dataKey) {
|
|
60
|
+
const titleCase = seriesType === 'line' ? 'Line' : 'Radial line';
|
|
61
|
+
const lowerCase = seriesType === 'line' ? 'lines' : 'radial lines';
|
|
62
|
+
dataset.forEach((entry, index) => {
|
|
63
|
+
const value = entry[dataKey];
|
|
64
|
+
if (value != null && typeof value !== 'number') {
|
|
65
|
+
warnOnce(`MUI X Charts: your dataset key "${dataKey}" is used for plotting ${lowerCase}, but the dataset contains the non-null non-numerical element "${value}" at index ${index}.
|
|
66
|
+
${titleCase} plots only support numeric and null values.`);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
const completedSeries = {};
|
|
74
|
+
stackingGroups.forEach(stackingGroup => {
|
|
75
|
+
const {
|
|
76
|
+
ids,
|
|
77
|
+
stackingOffset,
|
|
78
|
+
stackingOrder
|
|
79
|
+
} = stackingGroup;
|
|
80
|
+
const keys = ids.map(id => {
|
|
81
|
+
const dataKey = series[id].dataKey;
|
|
82
|
+
return series[id].data === undefined && dataKey !== undefined ? dataKey : id;
|
|
83
|
+
});
|
|
84
|
+
const stackedData = d3Stack().keys(keys).value((d, key) => d[key] ?? 0).order(stackingOrder).offset(stackingOffset)(d3Dataset);
|
|
85
|
+
const idOrder = stackedData.map(s => s.index);
|
|
86
|
+
const fixedOrder = () => idOrder;
|
|
87
|
+
const visibleStackedData = d3Stack().keys(keys).value((d, key) => {
|
|
88
|
+
const keyIndex = keys.indexOf(key);
|
|
89
|
+
const seriesId = ids[keyIndex];
|
|
90
|
+
if (!isItemVisible?.({
|
|
91
|
+
type: seriesType,
|
|
92
|
+
seriesId
|
|
93
|
+
})) {
|
|
94
|
+
return 0;
|
|
95
|
+
}
|
|
96
|
+
return d[key] ?? 0;
|
|
97
|
+
}).order(fixedOrder).offset(stackingOffset)(d3Dataset);
|
|
98
|
+
ids.forEach((id, index) => {
|
|
99
|
+
const {
|
|
100
|
+
dataKey,
|
|
101
|
+
valueGetter
|
|
102
|
+
} = series[id];
|
|
103
|
+
let data;
|
|
104
|
+
if (valueGetter) {
|
|
105
|
+
data = dataset.map(d => valueGetter(d));
|
|
106
|
+
} else if (dataKey) {
|
|
107
|
+
data = dataset.map(d => {
|
|
108
|
+
const value = d[dataKey];
|
|
109
|
+
return typeof value === 'number' ? value : null;
|
|
110
|
+
});
|
|
111
|
+
} else {
|
|
112
|
+
data = series[id].data;
|
|
113
|
+
}
|
|
114
|
+
const hidden = !isItemVisible?.({
|
|
115
|
+
type: seriesType,
|
|
116
|
+
seriesId: id
|
|
117
|
+
});
|
|
118
|
+
// SAFETY: 'line' and 'radialLine' series inputs are structurally identical for the
|
|
119
|
+
// fields needed to build the defaultized series result. The differing axis-ID fields
|
|
120
|
+
// are passed through via spread without being read.
|
|
121
|
+
completedSeries[id] = _extends({
|
|
122
|
+
labelMarkType: 'line+mark'
|
|
123
|
+
}, series[id], {
|
|
124
|
+
shape: series[id].shape ?? defaultShapes[(idToIndex.get(id) ?? 0) % defaultShapes.length],
|
|
125
|
+
data,
|
|
126
|
+
valueFormatter: series[id].valueFormatter ?? lineValueFormatter,
|
|
127
|
+
hidden,
|
|
128
|
+
stackedData: stackedData[index],
|
|
129
|
+
visibleStackedData: visibleStackedData[index]
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
return {
|
|
134
|
+
seriesOrder,
|
|
135
|
+
stackingGroups,
|
|
136
|
+
series: completedSeries
|
|
137
|
+
};
|
|
138
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { DefaultizedSeriesType } from "../models/seriesType/index.mjs";
|
|
2
|
+
import type { ChartSeriesType } from "../models/seriesType/config.mjs";
|
|
3
|
+
type LineOrBarSeriesType = Extract<ChartSeriesType, 'line' | 'bar' | 'radialLine' | 'radialBar'>;
|
|
4
|
+
export interface ResolveColorProcessorParams<SeriesType extends LineOrBarSeriesType, V> {
|
|
5
|
+
series: Pick<DefaultizedSeriesType<SeriesType>, 'color' | 'data' | 'colorGetter'>;
|
|
6
|
+
valueColorScale?: (value: number) => string | null;
|
|
7
|
+
categoryColorScale?: (value: V) => string | null;
|
|
8
|
+
categoryValues?: readonly V[];
|
|
9
|
+
}
|
|
10
|
+
export declare function resolveColorProcessor<SeriesType extends LineOrBarSeriesType, V>(params: ResolveColorProcessorParams<SeriesType, V>): (dataIndex?: number) => string;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { DefaultizedSeriesType } from "../models/seriesType/index.js";
|
|
2
|
+
import type { ChartSeriesType } from "../models/seriesType/config.js";
|
|
3
|
+
type LineOrBarSeriesType = Extract<ChartSeriesType, 'line' | 'bar' | 'radialLine' | 'radialBar'>;
|
|
4
|
+
export interface ResolveColorProcessorParams<SeriesType extends LineOrBarSeriesType, V> {
|
|
5
|
+
series: Pick<DefaultizedSeriesType<SeriesType>, 'color' | 'data' | 'colorGetter'>;
|
|
6
|
+
valueColorScale?: (value: number) => string | null;
|
|
7
|
+
categoryColorScale?: (value: V) => string | null;
|
|
8
|
+
categoryValues?: readonly V[];
|
|
9
|
+
}
|
|
10
|
+
export declare function resolveColorProcessor<SeriesType extends LineOrBarSeriesType, V>(params: ResolveColorProcessorParams<SeriesType, V>): (dataIndex?: number) => string;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.resolveColorProcessor = resolveColorProcessor;
|
|
7
|
+
var _getSeriesColorFn = require("./getSeriesColorFn");
|
|
8
|
+
function resolveColorProcessor(params) {
|
|
9
|
+
const {
|
|
10
|
+
series,
|
|
11
|
+
valueColorScale,
|
|
12
|
+
categoryColorScale,
|
|
13
|
+
categoryValues
|
|
14
|
+
} = params;
|
|
15
|
+
const getSeriesColor = (0, _getSeriesColorFn.getSeriesColorFn)(series);
|
|
16
|
+
if (valueColorScale) {
|
|
17
|
+
return dataIndex => {
|
|
18
|
+
if (dataIndex === undefined) {
|
|
19
|
+
return series.color;
|
|
20
|
+
}
|
|
21
|
+
const value = series.data[dataIndex];
|
|
22
|
+
const color = value === null ? getSeriesColor({
|
|
23
|
+
value,
|
|
24
|
+
dataIndex
|
|
25
|
+
}) : valueColorScale(value);
|
|
26
|
+
if (color === null) {
|
|
27
|
+
return getSeriesColor({
|
|
28
|
+
value,
|
|
29
|
+
dataIndex
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
return color;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
if (categoryColorScale && categoryValues) {
|
|
36
|
+
return dataIndex => {
|
|
37
|
+
if (dataIndex === undefined) {
|
|
38
|
+
return series.color;
|
|
39
|
+
}
|
|
40
|
+
const value = categoryValues[dataIndex];
|
|
41
|
+
const fallbackValue = {
|
|
42
|
+
value: series.data[dataIndex],
|
|
43
|
+
dataIndex
|
|
44
|
+
};
|
|
45
|
+
const color = value === null ? getSeriesColor(fallbackValue) : categoryColorScale(value);
|
|
46
|
+
if (color === null) {
|
|
47
|
+
return getSeriesColor(fallbackValue);
|
|
48
|
+
}
|
|
49
|
+
return color;
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
return dataIndex => {
|
|
53
|
+
if (dataIndex === undefined) {
|
|
54
|
+
return series.color;
|
|
55
|
+
}
|
|
56
|
+
const value = series.data[dataIndex];
|
|
57
|
+
return getSeriesColor({
|
|
58
|
+
value,
|
|
59
|
+
dataIndex
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { getSeriesColorFn } from "./getSeriesColorFn.mjs";
|
|
2
|
+
export function resolveColorProcessor(params) {
|
|
3
|
+
const {
|
|
4
|
+
series,
|
|
5
|
+
valueColorScale,
|
|
6
|
+
categoryColorScale,
|
|
7
|
+
categoryValues
|
|
8
|
+
} = params;
|
|
9
|
+
const getSeriesColor = getSeriesColorFn(series);
|
|
10
|
+
if (valueColorScale) {
|
|
11
|
+
return dataIndex => {
|
|
12
|
+
if (dataIndex === undefined) {
|
|
13
|
+
return series.color;
|
|
14
|
+
}
|
|
15
|
+
const value = series.data[dataIndex];
|
|
16
|
+
const color = value === null ? getSeriesColor({
|
|
17
|
+
value,
|
|
18
|
+
dataIndex
|
|
19
|
+
}) : valueColorScale(value);
|
|
20
|
+
if (color === null) {
|
|
21
|
+
return getSeriesColor({
|
|
22
|
+
value,
|
|
23
|
+
dataIndex
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
return color;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
if (categoryColorScale && categoryValues) {
|
|
30
|
+
return dataIndex => {
|
|
31
|
+
if (dataIndex === undefined) {
|
|
32
|
+
return series.color;
|
|
33
|
+
}
|
|
34
|
+
const value = categoryValues[dataIndex];
|
|
35
|
+
const fallbackValue = {
|
|
36
|
+
value: series.data[dataIndex],
|
|
37
|
+
dataIndex
|
|
38
|
+
};
|
|
39
|
+
const color = value === null ? getSeriesColor(fallbackValue) : categoryColorScale(value);
|
|
40
|
+
if (color === null) {
|
|
41
|
+
return getSeriesColor(fallbackValue);
|
|
42
|
+
}
|
|
43
|
+
return color;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
return dataIndex => {
|
|
47
|
+
if (dataIndex === undefined) {
|
|
48
|
+
return series.color;
|
|
49
|
+
}
|
|
50
|
+
const value = series.data[dataIndex];
|
|
51
|
+
return getSeriesColor({
|
|
52
|
+
value,
|
|
53
|
+
dataIndex
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
}
|