@mui/x-charts 7.1.1 → 7.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (192) hide show
  1. package/BarChart/BarChart.js +32 -2
  2. package/BarChart/BarPlot.js +12 -5
  3. package/BarChart/extremums.js +1 -1
  4. package/BarChart/getColor.d.ts +3 -0
  5. package/BarChart/getColor.js +33 -0
  6. package/CHANGELOG.md +211 -0
  7. package/ChartContainer/ChartContainer.js +35 -4
  8. package/ChartsAxis/ChartsAxis.js +4 -4
  9. package/ChartsClipPath/ChartsClipPath.js +2 -2
  10. package/ChartsLegend/ChartsLegend.js +2 -2
  11. package/ChartsTooltip/ChartsAxisTooltipContent.d.ts +4 -1
  12. package/ChartsTooltip/ChartsAxisTooltipContent.js +7 -2
  13. package/ChartsTooltip/ChartsItemTooltipContent.d.ts +6 -0
  14. package/ChartsTooltip/ChartsItemTooltipContent.js +15 -1
  15. package/ChartsTooltip/DefaultChartsAxisTooltipContent.js +6 -3
  16. package/ChartsTooltip/DefaultChartsItemTooltipContent.js +13 -4
  17. package/ChartsTooltip/utils.d.ts +5 -1
  18. package/ChartsVoronoiHandler/ChartsVoronoiHandler.js +6 -6
  19. package/ChartsXAxis/ChartsXAxis.js +7 -7
  20. package/ChartsYAxis/ChartsYAxis.js +9 -6
  21. package/Gauge/GaugeProvider.js +5 -5
  22. package/LineChart/AnimatedArea.js +6 -5
  23. package/LineChart/AnimatedLine.js +7 -5
  24. package/LineChart/AreaElement.d.ts +1 -0
  25. package/LineChart/AreaElement.js +4 -1
  26. package/LineChart/AreaPlot.js +7 -1
  27. package/LineChart/LineChart.js +32 -2
  28. package/LineChart/LineElement.d.ts +1 -0
  29. package/LineChart/LineElement.js +4 -1
  30. package/LineChart/LineHighlightPlot.js +4 -1
  31. package/LineChart/LinePlot.js +7 -1
  32. package/LineChart/MarkPlot.js +5 -5
  33. package/LineChart/getColor.d.ts +3 -0
  34. package/LineChart/getColor.js +31 -0
  35. package/PieChart/PieChart.js +32 -2
  36. package/PieChart/PiePlot.js +26 -6
  37. package/PieChart/formatter.js +4 -2
  38. package/PieChart/getColor.d.ts +2 -0
  39. package/PieChart/getColor.js +11 -0
  40. package/PieChart/getPieCoordinates.d.ts +7 -0
  41. package/PieChart/getPieCoordinates.js +25 -0
  42. package/PieChart/index.d.ts +1 -0
  43. package/PieChart/index.js +11 -0
  44. package/ResponsiveChartContainer/ResponsiveChartContainer.js +32 -2
  45. package/ScatterChart/Scatter.d.ts +1 -0
  46. package/ScatterChart/Scatter.js +6 -3
  47. package/ScatterChart/ScatterChart.js +32 -2
  48. package/ScatterChart/ScatterPlot.js +3 -0
  49. package/ScatterChart/getColor.d.ts +3 -0
  50. package/ScatterChart/getColor.js +31 -0
  51. package/SparkLineChart/SparkLineChart.js +15 -0
  52. package/context/CartesianContextProvider.d.ts +2 -2
  53. package/context/CartesianContextProvider.js +23 -8
  54. package/esm/BarChart/BarChart.js +32 -2
  55. package/esm/BarChart/BarPlot.js +13 -5
  56. package/esm/BarChart/extremums.js +1 -1
  57. package/esm/BarChart/getColor.js +27 -0
  58. package/esm/ChartContainer/ChartContainer.js +36 -4
  59. package/esm/ChartsAxis/ChartsAxis.js +4 -4
  60. package/esm/ChartsClipPath/ChartsClipPath.js +2 -2
  61. package/esm/ChartsLegend/ChartsLegend.js +2 -2
  62. package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +7 -2
  63. package/esm/ChartsTooltip/ChartsItemTooltipContent.js +15 -1
  64. package/esm/ChartsTooltip/DefaultChartsAxisTooltipContent.js +6 -3
  65. package/esm/ChartsTooltip/DefaultChartsItemTooltipContent.js +13 -4
  66. package/esm/ChartsVoronoiHandler/ChartsVoronoiHandler.js +6 -6
  67. package/esm/ChartsXAxis/ChartsXAxis.js +7 -7
  68. package/esm/ChartsYAxis/ChartsYAxis.js +9 -6
  69. package/esm/Gauge/GaugeProvider.js +5 -5
  70. package/esm/LineChart/AnimatedArea.js +6 -5
  71. package/esm/LineChart/AnimatedLine.js +7 -5
  72. package/esm/LineChart/AreaElement.js +4 -1
  73. package/esm/LineChart/AreaPlot.js +7 -1
  74. package/esm/LineChart/LineChart.js +32 -2
  75. package/esm/LineChart/LineElement.js +4 -1
  76. package/esm/LineChart/LineHighlightPlot.js +4 -1
  77. package/esm/LineChart/LinePlot.js +7 -1
  78. package/esm/LineChart/MarkPlot.js +5 -5
  79. package/esm/LineChart/getColor.js +25 -0
  80. package/esm/PieChart/PieChart.js +32 -2
  81. package/esm/PieChart/PiePlot.js +26 -6
  82. package/esm/PieChart/formatter.js +4 -2
  83. package/esm/PieChart/getColor.js +5 -0
  84. package/esm/PieChart/getPieCoordinates.js +19 -0
  85. package/esm/PieChart/index.js +2 -1
  86. package/esm/ResponsiveChartContainer/ResponsiveChartContainer.js +32 -2
  87. package/esm/ScatterChart/Scatter.js +6 -3
  88. package/esm/ScatterChart/ScatterChart.js +32 -2
  89. package/esm/ScatterChart/ScatterPlot.js +3 -0
  90. package/esm/ScatterChart/getColor.js +25 -0
  91. package/esm/SparkLineChart/SparkLineChart.js +15 -0
  92. package/esm/context/CartesianContextProvider.js +23 -8
  93. package/esm/hooks/index.js +4 -1
  94. package/esm/hooks/useAxisEvents.js +7 -6
  95. package/esm/hooks/useChartId.js +8 -0
  96. package/esm/hooks/useSeries.js +64 -0
  97. package/esm/hooks/useSvgRef.js +9 -0
  98. package/esm/internals/colorGetter.js +22 -0
  99. package/esm/internals/colorScale.js +16 -0
  100. package/esm/internals/components/ChartsAxesGradients/ChartsAxesGradients.js +96 -0
  101. package/esm/internals/components/ChartsAxesGradients/ChartsContinuousGradient.js +55 -0
  102. package/esm/internals/components/ChartsAxesGradients/ChartsPiecewiseGradient.js +41 -0
  103. package/esm/internals/components/ChartsAxesGradients/index.js +1 -0
  104. package/esm/models/colorMapping.js +1 -0
  105. package/esm/models/seriesType/index.js +6 -1
  106. package/hooks/index.d.ts +3 -0
  107. package/hooks/index.js +65 -1
  108. package/hooks/useAxisEvents.js +7 -6
  109. package/hooks/useChartId.d.ts +1 -0
  110. package/hooks/useChartId.js +16 -0
  111. package/hooks/useSeries.d.ts +45 -0
  112. package/hooks/useSeries.js +75 -0
  113. package/hooks/useSvgRef.d.ts +2 -0
  114. package/hooks/useSvgRef.js +17 -0
  115. package/hooks/useTicks.d.ts +1 -1
  116. package/index.js +1 -1
  117. package/internals/colorGetter.d.ts +5 -0
  118. package/internals/colorGetter.js +29 -0
  119. package/internals/colorScale.d.ts +5 -0
  120. package/internals/colorScale.js +24 -0
  121. package/internals/components/ChartsAxesGradients/ChartsAxesGradients.d.ts +3 -0
  122. package/internals/components/ChartsAxesGradients/ChartsAxesGradients.js +105 -0
  123. package/internals/components/ChartsAxesGradients/ChartsContinuousGradient.d.ts +13 -0
  124. package/internals/components/ChartsAxesGradients/ChartsContinuousGradient.js +63 -0
  125. package/internals/components/ChartsAxesGradients/ChartsPiecewiseGradient.d.ts +12 -0
  126. package/internals/components/ChartsAxesGradients/ChartsPiecewiseGradient.js +48 -0
  127. package/internals/components/ChartsAxesGradients/index.d.ts +1 -0
  128. package/internals/components/ChartsAxesGradients/index.js +16 -0
  129. package/internals/defaultizeColor.d.ts +4 -4
  130. package/internals/defaultizeValueFormatter.d.ts +5 -5
  131. package/internals/getScale.d.ts +2 -2
  132. package/models/axis.d.ts +44 -4
  133. package/models/colorMapping.d.ts +45 -0
  134. package/models/colorMapping.js +5 -0
  135. package/models/index.d.ts +1 -1
  136. package/models/seriesType/common.d.ts +10 -2
  137. package/models/seriesType/index.d.ts +2 -0
  138. package/models/seriesType/index.js +17 -1
  139. package/modern/BarChart/BarChart.js +32 -2
  140. package/modern/BarChart/BarPlot.js +13 -5
  141. package/modern/BarChart/extremums.js +1 -1
  142. package/modern/BarChart/getColor.js +27 -0
  143. package/modern/ChartContainer/ChartContainer.js +36 -4
  144. package/modern/ChartsAxis/ChartsAxis.js +4 -4
  145. package/modern/ChartsClipPath/ChartsClipPath.js +2 -2
  146. package/modern/ChartsLegend/ChartsLegend.js +2 -2
  147. package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +7 -2
  148. package/modern/ChartsTooltip/ChartsItemTooltipContent.js +15 -1
  149. package/modern/ChartsTooltip/DefaultChartsAxisTooltipContent.js +6 -3
  150. package/modern/ChartsTooltip/DefaultChartsItemTooltipContent.js +13 -4
  151. package/modern/ChartsVoronoiHandler/ChartsVoronoiHandler.js +6 -6
  152. package/modern/ChartsXAxis/ChartsXAxis.js +7 -7
  153. package/modern/ChartsYAxis/ChartsYAxis.js +9 -6
  154. package/modern/Gauge/GaugeProvider.js +5 -5
  155. package/modern/LineChart/AnimatedArea.js +6 -5
  156. package/modern/LineChart/AnimatedLine.js +7 -5
  157. package/modern/LineChart/AreaElement.js +4 -1
  158. package/modern/LineChart/AreaPlot.js +7 -1
  159. package/modern/LineChart/LineChart.js +32 -2
  160. package/modern/LineChart/LineElement.js +4 -1
  161. package/modern/LineChart/LineHighlightPlot.js +4 -1
  162. package/modern/LineChart/LinePlot.js +7 -1
  163. package/modern/LineChart/MarkPlot.js +5 -5
  164. package/modern/LineChart/getColor.js +25 -0
  165. package/modern/PieChart/PieChart.js +32 -2
  166. package/modern/PieChart/PiePlot.js +26 -6
  167. package/modern/PieChart/formatter.js +4 -2
  168. package/modern/PieChart/getColor.js +5 -0
  169. package/modern/PieChart/getPieCoordinates.js +19 -0
  170. package/modern/PieChart/index.js +2 -1
  171. package/modern/ResponsiveChartContainer/ResponsiveChartContainer.js +32 -2
  172. package/modern/ScatterChart/Scatter.js +6 -3
  173. package/modern/ScatterChart/ScatterChart.js +32 -2
  174. package/modern/ScatterChart/ScatterPlot.js +3 -0
  175. package/modern/ScatterChart/getColor.js +25 -0
  176. package/modern/SparkLineChart/SparkLineChart.js +15 -0
  177. package/modern/context/CartesianContextProvider.js +23 -8
  178. package/modern/hooks/index.js +4 -1
  179. package/modern/hooks/useAxisEvents.js +7 -6
  180. package/modern/hooks/useChartId.js +8 -0
  181. package/modern/hooks/useSeries.js +64 -0
  182. package/modern/hooks/useSvgRef.js +9 -0
  183. package/modern/index.js +1 -1
  184. package/modern/internals/colorGetter.js +22 -0
  185. package/modern/internals/colorScale.js +16 -0
  186. package/modern/internals/components/ChartsAxesGradients/ChartsAxesGradients.js +96 -0
  187. package/modern/internals/components/ChartsAxesGradients/ChartsContinuousGradient.js +55 -0
  188. package/modern/internals/components/ChartsAxesGradients/ChartsPiecewiseGradient.js +41 -0
  189. package/modern/internals/components/ChartsAxesGradients/index.js +1 -0
  190. package/modern/models/colorMapping.js +1 -0
  191. package/modern/models/seriesType/index.js +6 -1
  192. package/package.json +1 -1
@@ -0,0 +1,22 @@
1
+ import getBarColor from '../BarChart/getColor';
2
+ import getLineColor from '../LineChart/getColor';
3
+ import getScatterColor from '../ScatterChart/getColor';
4
+ import getPieColor from '../PieChart/getColor';
5
+ function getColor(series, xAxis, yAxis) {
6
+ if (xAxis !== undefined && yAxis !== undefined) {
7
+ if (series.type === 'bar') {
8
+ return getBarColor(series, xAxis, yAxis);
9
+ }
10
+ if (series.type === 'line') {
11
+ return getLineColor(series, xAxis, yAxis);
12
+ }
13
+ if (series.type === 'scatter') {
14
+ return getScatterColor(series, xAxis, yAxis);
15
+ }
16
+ }
17
+ if (series.type === 'pie') {
18
+ return getPieColor(series);
19
+ }
20
+ throw Error(`MUI X Charts: getColor called with unexpected arguments for series with id "${series.id}"`);
21
+ }
22
+ export default getColor;
@@ -0,0 +1,16 @@
1
+ import { scaleOrdinal, scaleThreshold, scaleSequential } from 'd3-scale';
2
+ export function getSequentialColorScale(config) {
3
+ if (config.type === 'piecewise') {
4
+ return scaleThreshold(config.thresholds, config.colors);
5
+ }
6
+ return scaleSequential([config.min ?? 0, config.max ?? 100], config.color);
7
+ }
8
+ export function getOrdinalColorScale(config) {
9
+ if (config.values) {
10
+ return scaleOrdinal(config.values, config.colors).unknown(config.unknownColor ?? null);
11
+ }
12
+ return scaleOrdinal(config.colors.map((_, index) => index), config.colors).unknown(config.unknownColor ?? null);
13
+ }
14
+ export function getColorScale(config) {
15
+ return config.type === 'ordinal' ? getOrdinalColorScale(config) : getSequentialColorScale(config);
16
+ }
@@ -0,0 +1,96 @@
1
+ import * as React from 'react';
2
+ import { CartesianContext } from '../../../context/CartesianContextProvider';
3
+ import { DrawingContext } from '../../../context/DrawingProvider';
4
+ import { useDrawingArea } from '../../../hooks';
5
+ import ChartsPiecewiseGradient from './ChartsPiecewiseGradient';
6
+ import ChartsContinuousGradient from './ChartsContinuousGradient';
7
+ import { jsx as _jsx } from "react/jsx-runtime";
8
+ import { jsxs as _jsxs } from "react/jsx-runtime";
9
+ export function useChartGradient() {
10
+ const {
11
+ chartId
12
+ } = React.useContext(DrawingContext);
13
+ return React.useCallback((axisId, direction) => `${chartId}-graient-${direction}-${axisId}`, [chartId]);
14
+ }
15
+ export function ChartsAxesGradients() {
16
+ const {
17
+ top,
18
+ height,
19
+ bottom,
20
+ left,
21
+ width,
22
+ right
23
+ } = useDrawingArea();
24
+ const svgHeight = top + height + bottom;
25
+ const svgWidth = left + width + right;
26
+ const getGradientId = useChartGradient();
27
+ const {
28
+ xAxisIds,
29
+ xAxis,
30
+ yAxisIds,
31
+ yAxis
32
+ } = React.useContext(CartesianContext);
33
+ return /*#__PURE__*/_jsxs("defs", {
34
+ children: [yAxisIds.filter(axisId => yAxis[axisId].colorMap !== undefined).map(axisId => {
35
+ const gradientId = getGradientId(axisId, 'y');
36
+ const {
37
+ colorMap,
38
+ scale,
39
+ colorScale,
40
+ reverse
41
+ } = yAxis[axisId];
42
+ if (colorMap?.type === 'piecewise') {
43
+ return /*#__PURE__*/_jsx(ChartsPiecewiseGradient, {
44
+ isReveresed: !reverse,
45
+ scale: scale,
46
+ colorMap: colorMap,
47
+ size: svgHeight,
48
+ gradientId: gradientId,
49
+ direction: "y"
50
+ }, gradientId);
51
+ }
52
+ if (colorMap?.type === 'continuous') {
53
+ return /*#__PURE__*/_jsx(ChartsContinuousGradient, {
54
+ isReveresed: !reverse,
55
+ scale: scale,
56
+ colorScale: colorScale,
57
+ colorMap: colorMap,
58
+ size: svgHeight,
59
+ gradientId: gradientId,
60
+ direction: "y"
61
+ }, gradientId);
62
+ }
63
+ return null;
64
+ }), xAxisIds.filter(axisId => xAxis[axisId].colorMap !== undefined).map(axisId => {
65
+ const gradientId = getGradientId(axisId, 'x');
66
+ const {
67
+ colorMap,
68
+ scale,
69
+ reverse,
70
+ colorScale
71
+ } = xAxis[axisId];
72
+ if (colorMap?.type === 'piecewise') {
73
+ return /*#__PURE__*/_jsx(ChartsPiecewiseGradient, {
74
+ isReveresed: reverse,
75
+ scale: scale,
76
+ colorMap: colorMap,
77
+ size: svgWidth,
78
+ gradientId: gradientId,
79
+ direction: "x"
80
+ }, gradientId);
81
+ }
82
+ if (colorMap?.type === 'continuous') {
83
+ return /*#__PURE__*/_jsx(ChartsContinuousGradient, {
84
+ isReveresed: reverse,
85
+ scale: scale,
86
+ colorScale: colorScale,
87
+ colorMap: colorMap,
88
+ size: svgWidth,
89
+ gradientId: gradientId,
90
+ direction: "x"
91
+ }, gradientId);
92
+ }
93
+ return null;
94
+ })]
95
+ });
96
+ }
@@ -0,0 +1,55 @@
1
+ import * as React from 'react';
2
+ import { interpolateDate, interpolateNumber } from 'd3-interpolate';
3
+ import { jsx as _jsx } from "react/jsx-runtime";
4
+ const PX_PRECISION = 10;
5
+ export default function ChartsContinuousGradient(props) {
6
+ const {
7
+ isReveresed,
8
+ gradientId,
9
+ size,
10
+ direction,
11
+ scale,
12
+ colorScale,
13
+ colorMap
14
+ } = props;
15
+ const extremValues = [colorMap.min ?? 0, colorMap.max ?? 100];
16
+ const extremPositions = extremValues.map(scale).filter(p => p !== undefined);
17
+ if (extremPositions.length !== 2) {
18
+ return null;
19
+ }
20
+ const interpolator = typeof extremValues[0] === 'number' ? interpolateNumber(extremValues[0], extremValues[1]) : interpolateDate(extremValues[0], extremValues[1]);
21
+ const numberOfPoints = Math.round((Math.max(...extremPositions) - Math.min(...extremPositions)) / PX_PRECISION);
22
+ const keyPrefix = `${extremValues[0]}-${extremValues[1]}-`;
23
+ return /*#__PURE__*/_jsx("linearGradient", {
24
+ id: gradientId,
25
+ x1: "0",
26
+ x2: "0",
27
+ y1: "0",
28
+ y2: "0",
29
+ [`${direction}${isReveresed ? 1 : 2}`]: `${size}px`,
30
+ gradientUnits: "userSpaceOnUse" // Use the SVG coordinate instead of the component ones.
31
+ ,
32
+ children: Array.from({
33
+ length: numberOfPoints + 1
34
+ }, (_, index) => {
35
+ const value = interpolator(index / numberOfPoints);
36
+ if (value === undefined) {
37
+ return null;
38
+ }
39
+ const x = scale(value);
40
+ if (x === undefined) {
41
+ return null;
42
+ }
43
+ const offset = isReveresed ? 1 - x / size : x / size;
44
+ const color = colorScale(value);
45
+ if (color === null) {
46
+ return null;
47
+ }
48
+ return /*#__PURE__*/_jsx("stop", {
49
+ offset: offset,
50
+ stopColor: color,
51
+ stopOpacity: 1
52
+ }, keyPrefix + index);
53
+ })
54
+ });
55
+ }
@@ -0,0 +1,41 @@
1
+ import * as React from 'react';
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { jsxs as _jsxs } from "react/jsx-runtime";
4
+ export default function ChartsPiecewiseGradient(props) {
5
+ const {
6
+ isReveresed,
7
+ gradientId,
8
+ size,
9
+ direction,
10
+ scale,
11
+ colorMap
12
+ } = props;
13
+ return /*#__PURE__*/_jsx("linearGradient", {
14
+ id: gradientId,
15
+ x1: "0",
16
+ x2: "0",
17
+ y1: "0",
18
+ y2: "0",
19
+ [`${direction}${isReveresed ? 1 : 2}`]: `${size}px`,
20
+ gradientUnits: "userSpaceOnUse" // Use the SVG coordinate instead of the component ones.
21
+ ,
22
+ children: colorMap.thresholds.map((threshold, index) => {
23
+ const x = scale(threshold);
24
+ if (x === undefined) {
25
+ return null;
26
+ }
27
+ const offset = isReveresed ? 1 - x / size : x / size;
28
+ return /*#__PURE__*/_jsxs(React.Fragment, {
29
+ children: [/*#__PURE__*/_jsx("stop", {
30
+ offset: offset,
31
+ stopColor: colorMap.colors[index],
32
+ stopOpacity: 1
33
+ }), /*#__PURE__*/_jsx("stop", {
34
+ offset: offset,
35
+ stopColor: colorMap.colors[index + 1],
36
+ stopOpacity: 1
37
+ })]
38
+ }, threshold.toString() + index);
39
+ })
40
+ });
41
+ }
@@ -0,0 +1 @@
1
+ export * from './ChartsAxesGradients';
@@ -0,0 +1 @@
1
+ export {};
@@ -2,4 +2,9 @@ export * from './line';
2
2
  export * from './bar';
3
3
  export * from './scatter';
4
4
  export * from './pie';
5
- export {};
5
+ export function isDefaultizedBarSeries(series) {
6
+ return series.type === 'bar';
7
+ }
8
+ export function isBarSeries(series) {
9
+ return series.type === 'bar';
10
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/x-charts",
3
- "version": "7.1.1",
3
+ "version": "7.3.0",
4
4
  "description": "The community edition of the Charts components (MUI X).",
5
5
  "author": "MUI Team",
6
6
  "main": "./index.js",