@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.
Files changed (132) hide show
  1. package/BarChart/BarChart.js +10 -10
  2. package/BarChart/BarChart.mjs +10 -10
  3. package/BarChart/seriesConfig/bar/getColor.js +7 -53
  4. package/BarChart/seriesConfig/bar/getColor.mjs +7 -53
  5. package/BarChart/seriesConfig/bar/seriesProcessor.js +3 -1
  6. package/BarChart/seriesConfig/bar/seriesProcessor.mjs +3 -1
  7. package/BarChart/seriesConfig/bar/tooltip.js +4 -27
  8. package/BarChart/seriesConfig/bar/tooltip.mjs +4 -27
  9. package/CHANGELOG.md +221 -0
  10. package/ChartsContainer/ChartsContainer.js +9 -9
  11. package/ChartsContainer/ChartsContainer.mjs +9 -9
  12. package/ChartsLabel/ChartsLabelMark.js +0 -2
  13. package/ChartsLabel/ChartsLabelMark.mjs +0 -2
  14. package/ChartsLabel/labelMarkClasses.d.mts +0 -1
  15. package/ChartsLabel/labelMarkClasses.d.ts +0 -1
  16. package/ChartsLabel/labelMarkClasses.js +1 -2
  17. package/ChartsLabel/labelMarkClasses.mjs +2 -2
  18. package/ChartsLayerContainer/ChartsLayerContainer.js +36 -30
  19. package/ChartsLayerContainer/ChartsLayerContainer.mjs +36 -30
  20. package/ChartsRadialAxisHighlight/ChartsRadialAxisHighlight.types.d.mts +1 -1
  21. package/ChartsRadialAxisHighlight/ChartsRadialAxisHighlight.types.d.ts +1 -1
  22. package/ChartsRadialAxisHighlight/ChartsRadiusAxisHighlight.js +31 -14
  23. package/ChartsRadialAxisHighlight/ChartsRadiusAxisHighlight.mjs +32 -15
  24. package/ChartsRadiusAxis/ChartsRadiusAxis.d.mts +1 -47
  25. package/ChartsRadiusAxis/ChartsRadiusAxis.d.ts +1 -47
  26. package/ChartsRadiusAxis/ChartsRadiusAxis.js +20 -16
  27. package/ChartsRadiusAxis/ChartsRadiusAxis.mjs +21 -15
  28. package/ChartsRotationAxis/ChartsRotationAxis.d.mts +1 -47
  29. package/ChartsRotationAxis/ChartsRotationAxis.d.ts +1 -47
  30. package/ChartsRotationAxis/ChartsRotationAxis.js +16 -19
  31. package/ChartsRotationAxis/ChartsRotationAxis.mjs +17 -18
  32. package/ChartsTooltip/useAxesTooltip.d.mts +1 -1
  33. package/ChartsTooltip/useAxesTooltip.d.ts +1 -1
  34. package/ChartsTooltip/useAxesTooltip.js +11 -2
  35. package/ChartsTooltip/useAxesTooltip.mjs +12 -3
  36. package/ChartsXAxis/ChartsXAxis.js +3 -1
  37. package/ChartsXAxis/ChartsXAxis.mjs +3 -1
  38. package/ChartsYAxis/ChartsYAxis.js +3 -1
  39. package/ChartsYAxis/ChartsYAxis.mjs +3 -1
  40. package/LineChart/LineChart.js +6 -6
  41. package/LineChart/LineChart.mjs +6 -6
  42. package/LineChart/seriesConfig/curveEvaluation.js +12 -1
  43. package/LineChart/seriesConfig/curveEvaluation.mjs +12 -1
  44. package/LineChart/seriesConfig/getColor.js +7 -54
  45. package/LineChart/seriesConfig/getColor.mjs +7 -54
  46. package/LineChart/seriesConfig/seriesProcessor.d.mts +2 -4
  47. package/LineChart/seriesConfig/seriesProcessor.d.ts +2 -4
  48. package/LineChart/seriesConfig/seriesProcessor.js +2 -139
  49. package/LineChart/seriesConfig/seriesProcessor.mjs +2 -138
  50. package/LineChart/seriesConfig/tooltip.js +4 -25
  51. package/LineChart/seriesConfig/tooltip.mjs +4 -25
  52. package/PieChart/PieChart.js +6 -6
  53. package/PieChart/PieChart.mjs +6 -6
  54. package/RadarChart/RadarAxis/useRadarAxis.js +1 -1
  55. package/RadarChart/RadarAxis/useRadarAxis.mjs +1 -1
  56. package/RadarChart/RadarChart.js +8 -8
  57. package/RadarChart/RadarChart.mjs +8 -8
  58. package/RadarChart/RadarGrid/CircularRadarStripes.js +2 -3
  59. package/RadarChart/RadarGrid/CircularRadarStripes.mjs +2 -3
  60. package/RadarChart/RadarSeriesPlot/RadarSeriesArea.js +3 -1
  61. package/RadarChart/RadarSeriesPlot/RadarSeriesArea.mjs +3 -1
  62. package/RadarChart/RadarSeriesPlot/RadarSeriesMarks.js +1 -0
  63. package/RadarChart/RadarSeriesPlot/RadarSeriesMarks.mjs +1 -0
  64. package/RadarChart/RadarSeriesPlot/RadarSeriesPlot.js +1 -0
  65. package/RadarChart/RadarSeriesPlot/RadarSeriesPlot.mjs +1 -0
  66. package/RadarChart/RadarSeriesPlot/useRadarRotationIndex.js +1 -1
  67. package/RadarChart/RadarSeriesPlot/useRadarRotationIndex.mjs +2 -2
  68. package/ScatterChart/ScatterChart.js +11 -11
  69. package/ScatterChart/ScatterChart.mjs +11 -11
  70. package/ScatterChart/seriesConfig/tooltip.js +2 -24
  71. package/ScatterChart/seriesConfig/tooltip.mjs +2 -24
  72. package/SparkLineChart/SparkLineChart.js +27 -27
  73. package/SparkLineChart/SparkLineChart.mjs +27 -27
  74. package/index.js +1 -1
  75. package/index.mjs +1 -1
  76. package/internals/components/ChartsAccessibilityProxy/ChartsAccessibilityProxy.js +1 -1
  77. package/internals/components/ChartsAccessibilityProxy/ChartsAccessibilityProxy.mjs +1 -1
  78. package/internals/getLineLikeTooltip.d.mts +9 -0
  79. package/internals/getLineLikeTooltip.d.ts +9 -0
  80. package/internals/getLineLikeTooltip.js +38 -0
  81. package/internals/getLineLikeTooltip.mjs +31 -0
  82. package/internals/getRingPath.d.mts +16 -0
  83. package/internals/getRingPath.d.ts +16 -0
  84. package/internals/getRingPath.js +39 -0
  85. package/internals/getRingPath.mjs +33 -0
  86. package/internals/index.d.mts +7 -2
  87. package/internals/index.d.ts +7 -2
  88. package/internals/index.js +46 -3
  89. package/internals/index.mjs +6 -2
  90. package/internals/plugins/corePlugins/useChartSeriesConfig/types/tooltipGetter.types.d.mts +4 -2
  91. package/internals/plugins/corePlugins/useChartSeriesConfig/types/tooltipGetter.types.d.ts +4 -2
  92. package/internals/plugins/featurePlugins/useChartCartesianAxis/createZoomLookup.d.mts +3 -3
  93. package/internals/plugins/featurePlugins/useChartCartesianAxis/createZoomLookup.d.ts +3 -3
  94. package/internals/plugins/featurePlugins/useChartCartesianAxis/index.d.mts +1 -0
  95. package/internals/plugins/featurePlugins/useChartCartesianAxis/index.d.ts +1 -0
  96. package/internals/plugins/featurePlugins/useChartCartesianAxis/index.js +8 -0
  97. package/internals/plugins/featurePlugins/useChartCartesianAxis/index.mjs +1 -0
  98. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisPosition.selectors.d.mts +6 -1
  99. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisPosition.selectors.d.ts +6 -1
  100. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisPosition.selectors.js +48 -36
  101. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisPosition.selectors.mjs +47 -36
  102. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisRendering.selectors.d.mts +74 -1
  103. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisRendering.selectors.d.ts +74 -1
  104. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianHighlight.selectors.d.mts +152 -2
  105. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianHighlight.selectors.d.ts +152 -2
  106. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianInteraction.selectors.d.mts +2 -2
  107. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianInteraction.selectors.d.ts +2 -2
  108. package/internals/plugins/featurePlugins/useChartHighlight/useChartHighlight.js +3 -0
  109. package/internals/plugins/featurePlugins/useChartHighlight/useChartHighlight.mjs +3 -0
  110. package/internals/plugins/featurePlugins/useChartPolarAxis/getAxisExtremum.d.mts +2 -2
  111. package/internals/plugins/featurePlugins/useChartPolarAxis/getAxisExtremum.d.ts +2 -2
  112. package/internals/plugins/featurePlugins/useChartPolarAxis/getAxisIndex.d.mts +6 -1
  113. package/internals/plugins/featurePlugins/useChartPolarAxis/getAxisIndex.d.ts +6 -1
  114. package/internals/plugins/featurePlugins/useChartPolarAxis/getAxisIndex.js +36 -2
  115. package/internals/plugins/featurePlugins/useChartPolarAxis/getAxisIndex.mjs +34 -1
  116. package/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarAxis.js +1 -1
  117. package/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarAxis.mjs +2 -2
  118. package/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarInteraction.selectors.d.mts +22 -2
  119. package/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarInteraction.selectors.d.ts +22 -2
  120. package/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarInteraction.selectors.js +73 -12
  121. package/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarInteraction.selectors.mjs +74 -12
  122. package/internals/processLineLikeSeries.d.mts +6 -0
  123. package/internals/processLineLikeSeries.d.ts +6 -0
  124. package/internals/processLineLikeSeries.js +145 -0
  125. package/internals/processLineLikeSeries.mjs +138 -0
  126. package/internals/resolveColorProcessor.d.mts +11 -0
  127. package/internals/resolveColorProcessor.d.ts +11 -0
  128. package/internals/resolveColorProcessor.js +62 -0
  129. package/internals/resolveColorProcessor.mjs +56 -0
  130. package/models/axis.d.mts +55 -7
  131. package/models/axis.d.ts +55 -7
  132. package/package.json +3 -3
@@ -155,14 +155,25 @@ export function evaluateCurveY(points, targetX, curveType) {
155
155
  const capture = new SegmentCapture();
156
156
  const factory = getCurveFactory(curveType);
157
157
  const curveInstance = factory(capture);
158
+
159
+ // Track which side of targetX the first point is on, so we detect the
160
+ // crossing regardless of whether x is increasing or decreasing.
161
+ const initialSide = points[0].x > targetX;
162
+ let searchStartIndex = 0;
163
+ let crossingDetected = false;
158
164
  curveInstance.lineStart();
159
165
  for (const p of points) {
166
+ if (!crossingDetected && p.x > targetX !== initialSide) {
167
+ searchStartIndex = Math.max(0, capture.segments.length - 1);
168
+ crossingDetected = true;
169
+ }
160
170
  curveInstance.point(p.x, p.y);
161
171
  }
162
172
  curveInstance.lineEnd();
163
173
 
164
174
  // Find the segment containing targetX.
165
- for (const segment of capture.segments) {
175
+ for (let i = searchStartIndex; i < capture.segments.length; i += 1) {
176
+ const segment = capture.segments[i];
166
177
  if (targetX < segment.x0 + 0.5 && targetX > segment.x0 - 0.5) {
167
178
  return segment.y0;
168
179
  }
@@ -4,58 +4,11 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _getSeriesColorFn = require("../../internals/getSeriesColorFn");
8
- const getColor = (series, xAxis, yAxis) => {
9
- const yColorScale = yAxis?.colorScale;
10
- const xColorScale = xAxis?.colorScale;
11
- const getSeriesColor = (0, _getSeriesColorFn.getSeriesColorFn)(series);
12
- if (yColorScale) {
13
- return dataIndex => {
14
- if (dataIndex === undefined) {
15
- return series.color;
16
- }
17
- const value = series.data[dataIndex];
18
- const color = value === null ? getSeriesColor({
19
- value,
20
- dataIndex
21
- }) : yColorScale(value);
22
- if (color === null) {
23
- return getSeriesColor({
24
- value,
25
- dataIndex
26
- });
27
- }
28
- return color;
29
- };
30
- }
31
- if (xColorScale) {
32
- return dataIndex => {
33
- if (dataIndex === undefined) {
34
- return series.color;
35
- }
36
- const value = xAxis.data?.[dataIndex];
37
- const color = value === null ? getSeriesColor({
38
- value,
39
- dataIndex
40
- }) : xColorScale(value);
41
- if (color === null) {
42
- return getSeriesColor({
43
- value,
44
- dataIndex
45
- });
46
- }
47
- return color;
48
- };
49
- }
50
- return dataIndex => {
51
- if (dataIndex === undefined) {
52
- return series.color;
53
- }
54
- const value = series.data[dataIndex];
55
- return getSeriesColor({
56
- value,
57
- dataIndex
58
- });
59
- };
60
- };
7
+ var _resolveColorProcessor = require("../../internals/resolveColorProcessor");
8
+ const getColor = (series, xAxis, yAxis) => (0, _resolveColorProcessor.resolveColorProcessor)({
9
+ series,
10
+ valueColorScale: yAxis?.colorScale,
11
+ categoryColorScale: xAxis?.colorScale,
12
+ categoryValues: xAxis?.data
13
+ });
61
14
  var _default = exports.default = getColor;
@@ -1,55 +1,8 @@
1
- import { getSeriesColorFn } from "../../internals/getSeriesColorFn.mjs";
2
- const getColor = (series, xAxis, yAxis) => {
3
- const yColorScale = yAxis?.colorScale;
4
- const xColorScale = xAxis?.colorScale;
5
- const getSeriesColor = getSeriesColorFn(series);
6
- if (yColorScale) {
7
- return dataIndex => {
8
- if (dataIndex === undefined) {
9
- return series.color;
10
- }
11
- const value = series.data[dataIndex];
12
- const color = value === null ? getSeriesColor({
13
- value,
14
- dataIndex
15
- }) : yColorScale(value);
16
- if (color === null) {
17
- return getSeriesColor({
18
- value,
19
- dataIndex
20
- });
21
- }
22
- return color;
23
- };
24
- }
25
- if (xColorScale) {
26
- return dataIndex => {
27
- if (dataIndex === undefined) {
28
- return series.color;
29
- }
30
- const value = xAxis.data?.[dataIndex];
31
- const color = value === null ? getSeriesColor({
32
- value,
33
- dataIndex
34
- }) : xColorScale(value);
35
- if (color === null) {
36
- return getSeriesColor({
37
- value,
38
- dataIndex
39
- });
40
- }
41
- return color;
42
- };
43
- }
44
- return dataIndex => {
45
- if (dataIndex === undefined) {
46
- return series.color;
47
- }
48
- const value = series.data[dataIndex];
49
- return getSeriesColor({
50
- value,
51
- dataIndex
52
- });
53
- };
54
- };
1
+ import { resolveColorProcessor } from "../../internals/resolveColorProcessor.mjs";
2
+ const getColor = (series, xAxis, yAxis) => resolveColorProcessor({
3
+ series,
4
+ valueColorScale: yAxis?.colorScale,
5
+ categoryColorScale: xAxis?.colorScale,
6
+ categoryValues: xAxis?.data
7
+ });
55
8
  export default getColor;
@@ -1,5 +1,3 @@
1
- import { type DatasetType } from "../../models/seriesType/config.mjs";
2
- import type { SeriesProcessorParams, SeriesProcessorResult } from "../../internals/plugins/corePlugins/useChartSeriesConfig/index.mjs";
3
- import type { IsItemVisibleFunction } from "../../internals/plugins/featurePlugins/useChartVisibilityManager/index.mjs";
4
- declare function seriesProcessor(params: SeriesProcessorParams<'line'>, dataset?: Readonly<DatasetType>, isItemVisible?: IsItemVisibleFunction): SeriesProcessorResult<'line'>;
1
+ import type { SeriesProcessor } from "../../internals/plugins/corePlugins/useChartSeriesConfig/index.mjs";
2
+ declare const seriesProcessor: SeriesProcessor<'line'>;
5
3
  export default seriesProcessor;
@@ -1,5 +1,3 @@
1
- import { type DatasetType } from "../../models/seriesType/config.js";
2
- import type { SeriesProcessorParams, SeriesProcessorResult } from "../../internals/plugins/corePlugins/useChartSeriesConfig/index.js";
3
- import type { IsItemVisibleFunction } from "../../internals/plugins/featurePlugins/useChartVisibilityManager/index.js";
4
- declare function seriesProcessor(params: SeriesProcessorParams<'line'>, dataset?: Readonly<DatasetType>, isItemVisible?: IsItemVisibleFunction): SeriesProcessorResult<'line'>;
1
+ import type { SeriesProcessor } from "../../internals/plugins/corePlugins/useChartSeriesConfig/index.js";
2
+ declare const seriesProcessor: SeriesProcessor<'line'>;
5
3
  export default seriesProcessor;
@@ -1,146 +1,9 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
6
5
  });
7
6
  exports.default = void 0;
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("../../internals/stacking");
13
- const defaultShapes = ['circle', 'square', 'diamond', 'cross', 'star', 'triangle', 'wye'];
14
- const lineValueFormatter = v => v == null ? '' : v.toLocaleString();
15
- function seriesProcessor(params, dataset, isItemVisible) {
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
- // Create a data set with format adapted to d3
27
- const d3Dataset = dataset ?? [];
28
- seriesOrder.forEach((id, seriesIndex) => {
29
- idToIndex.set(id, seriesIndex);
30
- const data = series[id].data;
31
- if (data !== undefined) {
32
- data.forEach((value, dataIndex) => {
33
- if (d3Dataset.length <= dataIndex) {
34
- d3Dataset.push({
35
- [id]: value
36
- });
37
- } else {
38
- d3Dataset[dataIndex][id] = value;
39
- }
40
- });
41
- } else if (series[id].valueGetter && dataset) {
42
- // When valueGetter is used without dataKey, populate d3Dataset with the series id as key
43
- dataset.forEach((entry, dataIndex) => {
44
- const value = series[id].valueGetter(entry);
45
- if (d3Dataset.length <= dataIndex) {
46
- d3Dataset.push({
47
- [id]: value
48
- });
49
- } else {
50
- d3Dataset[dataIndex][id] = value;
51
- }
52
- });
53
- } else if (dataset === undefined && process.env.NODE_ENV !== 'production') {
54
- // TODO: fix mui/no-guarded-throw
55
- // eslint-disable-next-line mui/no-guarded-throw
56
- throw new Error(process.env.NODE_ENV !== "production" ? `MUI X Charts: Line 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)(27, id));
57
- }
58
- if (process.env.NODE_ENV !== 'production') {
59
- if (!data && dataset) {
60
- const dataKey = series[id].dataKey;
61
- if (!dataKey && !series[id].valueGetter) {
62
- // TODO: fix mui/no-guarded-throw
63
- // eslint-disable-next-line mui/no-guarded-throw
64
- throw new Error(`MUI X Charts: Line 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
- dataset.forEach((entry, index) => {
68
- const value = entry[dataKey];
69
- if (value != null && typeof value !== 'number') {
70
- (0, _warning.warnOnce)(`MUI X Charts: your dataset key "${dataKey}" is used for plotting lines, but the dataset contains the non-null non-numerical element "${value}" at index ${index}.
71
- Line plots only support numeric and null values.`);
72
- }
73
- });
74
- }
75
- }
76
- }
77
- });
78
- const completedSeries = {};
79
- stackingGroups.forEach(stackingGroup => {
80
- const {
81
- ids,
82
- stackingOffset,
83
- stackingOrder
84
- } = stackingGroup;
85
- const keys = ids.map(id => {
86
- // Use dataKey if needed and available
87
- const dataKey = series[id].dataKey;
88
- return series[id].data === undefined && dataKey !== undefined ? dataKey : id;
89
- });
90
- const stackedData = (0, _d3Shape.stack)().keys(keys).value((d, key) => d[key] ?? 0) // defaultize null value to 0
91
- .order(stackingOrder).offset(stackingOffset)(d3Dataset);
92
- const idOrder = stackedData.map(s => s.index);
93
- const fixedOrder = () => idOrder;
94
-
95
- // Compute visible stacked data
96
- const visibleStackedData = (0, _d3Shape.stack)().keys(keys).value((d, key) => {
97
- const keyIndex = keys.indexOf(key);
98
- const seriesId = ids[keyIndex];
99
- if (!isItemVisible?.({
100
- type: 'line',
101
- seriesId
102
- })) {
103
- // For hidden series, return 0 so they don't contribute to the stack
104
- return 0;
105
- }
106
- return d[key] ?? 0;
107
- }).order(fixedOrder).offset(stackingOffset)(d3Dataset);
108
- ids.forEach((id, index) => {
109
- const {
110
- dataKey,
111
- valueGetter
112
- } = series[id];
113
- let data;
114
- if (valueGetter) {
115
- data = dataset.map(d => valueGetter(d));
116
- } else if (dataKey) {
117
- data = dataset.map(d => {
118
- const value = d[dataKey];
119
- return typeof value === 'number' ? value : null;
120
- });
121
- } else {
122
- data = series[id].data;
123
- }
124
- const hidden = !isItemVisible?.({
125
- type: 'line',
126
- seriesId: id
127
- });
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
- }
7
+ var _processLineLikeSeries = require("../../internals/processLineLikeSeries");
8
+ const seriesProcessor = (params, dataset, isItemVisible) => (0, _processLineLikeSeries.processLineLikeSeries)(params, dataset, isItemVisible, 'line');
146
9
  var _default = exports.default = seriesProcessor;
@@ -1,139 +1,3 @@
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 "../../internals/stacking/index.mjs";
6
- const defaultShapes = ['circle', 'square', 'diamond', 'cross', 'star', 'triangle', 'wye'];
7
- const lineValueFormatter = v => v == null ? '' : v.toLocaleString();
8
- function seriesProcessor(params, dataset, isItemVisible) {
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
- // Create a data set with format adapted to d3
20
- const d3Dataset = dataset ?? [];
21
- seriesOrder.forEach((id, seriesIndex) => {
22
- idToIndex.set(id, seriesIndex);
23
- const data = series[id].data;
24
- if (data !== undefined) {
25
- data.forEach((value, dataIndex) => {
26
- if (d3Dataset.length <= dataIndex) {
27
- d3Dataset.push({
28
- [id]: value
29
- });
30
- } else {
31
- d3Dataset[dataIndex][id] = value;
32
- }
33
- });
34
- } else if (series[id].valueGetter && dataset) {
35
- // When valueGetter is used without dataKey, populate d3Dataset with the series id as key
36
- dataset.forEach((entry, dataIndex) => {
37
- const value = series[id].valueGetter(entry);
38
- if (d3Dataset.length <= dataIndex) {
39
- d3Dataset.push({
40
- [id]: value
41
- });
42
- } else {
43
- d3Dataset[dataIndex][id] = value;
44
- }
45
- });
46
- } else if (dataset === undefined && process.env.NODE_ENV !== 'production') {
47
- // TODO: fix mui/no-guarded-throw
48
- // eslint-disable-next-line mui/no-guarded-throw
49
- throw new Error(process.env.NODE_ENV !== "production" ? `MUI X Charts: Line 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(27, id));
50
- }
51
- if (process.env.NODE_ENV !== 'production') {
52
- if (!data && dataset) {
53
- const dataKey = series[id].dataKey;
54
- if (!dataKey && !series[id].valueGetter) {
55
- // TODO: fix mui/no-guarded-throw
56
- // eslint-disable-next-line mui/no-guarded-throw
57
- throw new Error(`MUI X Charts: Line 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
- dataset.forEach((entry, index) => {
61
- const value = entry[dataKey];
62
- if (value != null && typeof value !== 'number') {
63
- warnOnce(`MUI X Charts: your dataset key "${dataKey}" is used for plotting lines, but the dataset contains the non-null non-numerical element "${value}" at index ${index}.
64
- Line plots only support numeric and null values.`);
65
- }
66
- });
67
- }
68
- }
69
- }
70
- });
71
- const completedSeries = {};
72
- stackingGroups.forEach(stackingGroup => {
73
- const {
74
- ids,
75
- stackingOffset,
76
- stackingOrder
77
- } = stackingGroup;
78
- const keys = ids.map(id => {
79
- // Use dataKey if needed and available
80
- const dataKey = series[id].dataKey;
81
- return series[id].data === undefined && dataKey !== undefined ? dataKey : id;
82
- });
83
- const stackedData = d3Stack().keys(keys).value((d, key) => d[key] ?? 0) // defaultize null value to 0
84
- .order(stackingOrder).offset(stackingOffset)(d3Dataset);
85
- const idOrder = stackedData.map(s => s.index);
86
- const fixedOrder = () => idOrder;
87
-
88
- // Compute visible stacked data
89
- const visibleStackedData = d3Stack().keys(keys).value((d, key) => {
90
- const keyIndex = keys.indexOf(key);
91
- const seriesId = ids[keyIndex];
92
- if (!isItemVisible?.({
93
- type: 'line',
94
- seriesId
95
- })) {
96
- // For hidden series, return 0 so they don't contribute to the stack
97
- return 0;
98
- }
99
- return d[key] ?? 0;
100
- }).order(fixedOrder).offset(stackingOffset)(d3Dataset);
101
- ids.forEach((id, index) => {
102
- const {
103
- dataKey,
104
- valueGetter
105
- } = series[id];
106
- let data;
107
- if (valueGetter) {
108
- data = dataset.map(d => valueGetter(d));
109
- } else if (dataKey) {
110
- data = dataset.map(d => {
111
- const value = d[dataKey];
112
- return typeof value === 'number' ? value : null;
113
- });
114
- } else {
115
- data = series[id].data;
116
- }
117
- const hidden = !isItemVisible?.({
118
- type: 'line',
119
- seriesId: id
120
- });
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
- }
1
+ import { processLineLikeSeries } from "../../internals/processLineLikeSeries.mjs";
2
+ const seriesProcessor = (params, dataset, isItemVisible) => processLineLikeSeries(params, dataset, isItemVisible, 'line');
139
3
  export default seriesProcessor;
@@ -4,31 +4,10 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = exports.axisTooltipGetter = void 0;
7
- var _getLabel = require("../../internals/getLabel");
8
- const tooltipGetter = params => {
9
- const {
10
- series,
11
- getColor,
12
- identifier
13
- } = params;
14
- if (!identifier || identifier.dataIndex === undefined) {
15
- return null;
16
- }
17
- const label = (0, _getLabel.getLabel)(series.label, 'tooltip');
18
- const value = series.data[identifier.dataIndex];
19
- const formattedValue = series.valueFormatter(value, {
20
- dataIndex: identifier.dataIndex
21
- });
22
- return {
23
- identifier,
24
- color: getColor(identifier.dataIndex),
25
- label,
26
- value,
27
- formattedValue,
28
- markType: series.labelMarkType,
29
- markShape: series.showMark ? series.shape : undefined
30
- };
31
- };
7
+ var _getLineLikeTooltip = require("../../internals/getLineLikeTooltip");
8
+ const tooltipGetter = params => (0, _getLineLikeTooltip.getLineLikeTooltip)(params, {
9
+ includeMarkShape: true
10
+ });
32
11
  const axisTooltipGetter = series => {
33
12
  return Object.values(series).map(s => ({
34
13
  direction: 'x',
@@ -1,28 +1,7 @@
1
- import { getLabel } from "../../internals/getLabel.mjs";
2
- const tooltipGetter = params => {
3
- const {
4
- series,
5
- getColor,
6
- identifier
7
- } = params;
8
- if (!identifier || identifier.dataIndex === undefined) {
9
- return null;
10
- }
11
- const label = getLabel(series.label, 'tooltip');
12
- const value = series.data[identifier.dataIndex];
13
- const formattedValue = series.valueFormatter(value, {
14
- dataIndex: identifier.dataIndex
15
- });
16
- return {
17
- identifier,
18
- color: getColor(identifier.dataIndex),
19
- label,
20
- value,
21
- formattedValue,
22
- markType: series.labelMarkType,
23
- markShape: series.showMark ? series.shape : undefined
24
- };
25
- };
1
+ import { getLineLikeTooltip } from "../../internals/getLineLikeTooltip.mjs";
2
+ const tooltipGetter = params => getLineLikeTooltip(params, {
3
+ includeMarkShape: true
4
+ });
26
5
  export const axisTooltipGetter = series => {
27
6
  return Object.values(series).map(s => ({
28
7
  direction: 'x',
@@ -184,11 +184,11 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
184
184
  */
185
185
  highlightedItem: _propTypes.default.oneOfType([_propTypes.default.shape({
186
186
  dataIndex: _propTypes.default.number,
187
- seriesId: _propTypes.default.string.isRequired,
188
- type: _propTypes.default.oneOf(['pie']).isRequired
187
+ seriesId: _propTypes.default.string.isRequired
189
188
  }), _propTypes.default.shape({
190
189
  dataIndex: _propTypes.default.number,
191
- seriesId: _propTypes.default.string.isRequired
190
+ seriesId: _propTypes.default.string.isRequired,
191
+ type: _propTypes.default.oneOf(['pie']).isRequired
192
192
  })]),
193
193
  /**
194
194
  * This prop is used to help implement the accessibility logic.
@@ -305,11 +305,11 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
305
305
  */
306
306
  tooltipItem: _propTypes.default.oneOfType([_propTypes.default.shape({
307
307
  dataIndex: _propTypes.default.number.isRequired,
308
- seriesId: _propTypes.default.string.isRequired,
309
- type: _propTypes.default.oneOf(['pie']).isRequired
308
+ seriesId: _propTypes.default.string.isRequired
310
309
  }), _propTypes.default.shape({
311
310
  dataIndex: _propTypes.default.number.isRequired,
312
- seriesId: _propTypes.default.string.isRequired
311
+ seriesId: _propTypes.default.string.isRequired,
312
+ type: _propTypes.default.oneOf(['pie']).isRequired
313
313
  })]),
314
314
  /**
315
315
  * The width of the chart in px. If not defined, it takes the width of the parent element.
@@ -177,11 +177,11 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
177
177
  */
178
178
  highlightedItem: PropTypes.oneOfType([PropTypes.shape({
179
179
  dataIndex: PropTypes.number,
180
- seriesId: PropTypes.string.isRequired,
181
- type: PropTypes.oneOf(['pie']).isRequired
180
+ seriesId: PropTypes.string.isRequired
182
181
  }), PropTypes.shape({
183
182
  dataIndex: PropTypes.number,
184
- seriesId: PropTypes.string.isRequired
183
+ seriesId: PropTypes.string.isRequired,
184
+ type: PropTypes.oneOf(['pie']).isRequired
185
185
  })]),
186
186
  /**
187
187
  * This prop is used to help implement the accessibility logic.
@@ -298,11 +298,11 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
298
298
  */
299
299
  tooltipItem: PropTypes.oneOfType([PropTypes.shape({
300
300
  dataIndex: PropTypes.number.isRequired,
301
- seriesId: PropTypes.string.isRequired,
302
- type: PropTypes.oneOf(['pie']).isRequired
301
+ seriesId: PropTypes.string.isRequired
303
302
  }), PropTypes.shape({
304
303
  dataIndex: PropTypes.number.isRequired,
305
- seriesId: PropTypes.string.isRequired
304
+ seriesId: PropTypes.string.isRequired,
305
+ type: PropTypes.oneOf(['pie']).isRequired
306
306
  })]),
307
307
  /**
308
308
  * The width of the chart in px. If not defined, it takes the width of the parent element.
@@ -38,7 +38,7 @@ function useRadarAxis(params) {
38
38
  return null;
39
39
  }
40
40
  const existingMetrics = rotationScale.domain();
41
- if (!existingMetrics.includes(metric)) {
41
+ if (process.env.NODE_ENV !== 'production' && !existingMetrics.includes(metric)) {
42
42
  (0, _warning.warnOnce)([`MUI X Charts: Your radar axis tries to display values for the metric "${metric}" which does not exist.`, `Either add this metric to your radar, or pick one from the existing metrics: ${existingMetrics.join(', ')}`]);
43
43
  }
44
44
  const anglesWithDefault = angle !== undefined ? (0, _degToRad.degToRad)(angle) : rotationScale(metric) ?? 0;
@@ -32,7 +32,7 @@ export function useRadarAxis(params) {
32
32
  return null;
33
33
  }
34
34
  const existingMetrics = rotationScale.domain();
35
- if (!existingMetrics.includes(metric)) {
35
+ if (process.env.NODE_ENV !== 'production' && !existingMetrics.includes(metric)) {
36
36
  warnOnce([`MUI X Charts: Your radar axis tries to display values for the metric "${metric}" which does not exist.`, `Either add this metric to your radar, or pick one from the existing metrics: ${existingMetrics.join(', ')}`]);
37
37
  }
38
38
  const anglesWithDefault = angle !== undefined ? degToRad(angle) : rotationScale(metric) ?? 0;
@@ -151,11 +151,11 @@ process.env.NODE_ENV !== "production" ? RadarChart.propTypes = {
151
151
  */
152
152
  highlightedItem: _propTypes.default.oneOfType([_propTypes.default.shape({
153
153
  dataIndex: _propTypes.default.number,
154
- seriesId: _propTypes.default.string.isRequired,
155
- type: _propTypes.default.oneOf(['radar']).isRequired
154
+ seriesId: _propTypes.default.string.isRequired
156
155
  }), _propTypes.default.shape({
157
156
  dataIndex: _propTypes.default.number,
158
- seriesId: _propTypes.default.string.isRequired
157
+ seriesId: _propTypes.default.string.isRequired,
158
+ type: _propTypes.default.oneOf(['radar']).isRequired
159
159
  })]),
160
160
  /**
161
161
  * This prop is used to help implement the accessibility logic.
@@ -256,11 +256,11 @@ process.env.NODE_ENV !== "production" ? RadarChart.propTypes = {
256
256
  labelFormatter: _propTypes.default.func,
257
257
  labelGap: _propTypes.default.number,
258
258
  max: _propTypes.default.number,
259
- metrics: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.string), _propTypes.default.arrayOf(_propTypes.default.shape({
259
+ metrics: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.shape({
260
260
  max: _propTypes.default.number,
261
261
  min: _propTypes.default.number,
262
262
  name: _propTypes.default.string.isRequired
263
- }))]).isRequired,
263
+ })), _propTypes.default.arrayOf(_propTypes.default.string)]).isRequired,
264
264
  startAngle: _propTypes.default.number
265
265
  }).isRequired,
266
266
  /**
@@ -313,11 +313,11 @@ process.env.NODE_ENV !== "production" ? RadarChart.propTypes = {
313
313
  */
314
314
  tooltipItem: _propTypes.default.oneOfType([_propTypes.default.shape({
315
315
  dataIndex: _propTypes.default.number,
316
- seriesId: _propTypes.default.string.isRequired,
317
- type: _propTypes.default.oneOf(['radar']).isRequired
316
+ seriesId: _propTypes.default.string.isRequired
318
317
  }), _propTypes.default.shape({
319
318
  dataIndex: _propTypes.default.number,
320
- seriesId: _propTypes.default.string.isRequired
319
+ seriesId: _propTypes.default.string.isRequired,
320
+ type: _propTypes.default.oneOf(['radar']).isRequired
321
321
  })]),
322
322
  /**
323
323
  * The width of the chart in px. If not defined, it takes the width of the parent element.