@mui/x-charts 7.0.0-beta.3 → 7.0.0-beta.5

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 (221) hide show
  1. package/BarChart/BarChart.js +0 -2
  2. package/CHANGELOG.md +357 -22
  3. package/ChartsGrid/ChartsGrid.js +2 -2
  4. package/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +1 -1
  5. package/ChartsTooltip/utils.js +1 -1
  6. package/ChartsVoronoiHandler/ChartsVoronoiHandler.d.ts +0 -1
  7. package/ChartsVoronoiHandler/ChartsVoronoiHandler.js +1 -2
  8. package/ChartsXAxis/ChartsXAxis.js +1 -1
  9. package/ChartsYAxis/ChartsYAxis.js +1 -1
  10. package/Gauge/Gauge.js +0 -2
  11. package/Gauge/GaugeContainer.d.ts +0 -2
  12. package/Gauge/GaugeContainer.js +0 -2
  13. package/Gauge/GaugeProvider.js +3 -0
  14. package/Gauge/GaugeValueText.js +1 -1
  15. package/LineChart/LineChart.js +0 -2
  16. package/PieChart/PieChart.js +0 -2
  17. package/ResponsiveChartContainer/ResponsiveChartContainer.d.ts +0 -2
  18. package/ResponsiveChartContainer/ResponsiveChartContainer.js +0 -2
  19. package/ScatterChart/ScatterChart.js +0 -3
  20. package/SparkLineChart/SparkLineChart.js +0 -2
  21. package/context/CartesianContextProvider.d.ts +0 -8
  22. package/context/CartesianContextProvider.js +4 -89
  23. package/context/DrawingProvider.d.ts +2 -11
  24. package/context/DrawingProvider.js +10 -35
  25. package/context/HighlightProvider.js +3 -0
  26. package/context/InteractionProvider.js +3 -0
  27. package/context/SeriesContextProvider.js +3 -0
  28. package/context/index.d.ts +0 -2
  29. package/context/index.js +1 -15
  30. package/esm/BarChart/BarChart.js +0 -2
  31. package/esm/ChartsGrid/ChartsGrid.js +2 -2
  32. package/esm/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +2 -2
  33. package/esm/ChartsTooltip/utils.js +2 -2
  34. package/esm/ChartsVoronoiHandler/ChartsVoronoiHandler.js +2 -3
  35. package/esm/ChartsXAxis/ChartsXAxis.js +1 -1
  36. package/esm/ChartsYAxis/ChartsYAxis.js +1 -1
  37. package/esm/Gauge/Gauge.js +0 -2
  38. package/esm/Gauge/GaugeContainer.js +0 -2
  39. package/esm/Gauge/GaugeProvider.js +3 -0
  40. package/esm/Gauge/GaugeValueText.js +1 -1
  41. package/esm/LineChart/LineChart.js +0 -2
  42. package/esm/PieChart/PieChart.js +0 -2
  43. package/esm/ResponsiveChartContainer/ResponsiveChartContainer.js +0 -2
  44. package/esm/ScatterChart/ScatterChart.js +0 -3
  45. package/esm/SparkLineChart/SparkLineChart.js +0 -2
  46. package/esm/context/CartesianContextProvider.js +3 -88
  47. package/esm/context/DrawingProvider.js +10 -36
  48. package/esm/context/HighlightProvider.js +3 -0
  49. package/esm/context/InteractionProvider.js +3 -0
  50. package/esm/context/SeriesContextProvider.js +3 -0
  51. package/esm/context/index.js +1 -2
  52. package/esm/hooks/useAxisEvents.js +2 -2
  53. package/hooks/useAxisEvents.js +1 -1
  54. package/hooks/useTicks.d.ts +1 -1
  55. package/index.js +1 -1
  56. package/modern/BarChart/BarChart.js +0 -2
  57. package/modern/ChartsGrid/ChartsGrid.js +2 -2
  58. package/modern/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +2 -2
  59. package/modern/ChartsTooltip/utils.js +2 -2
  60. package/modern/ChartsVoronoiHandler/ChartsVoronoiHandler.js +2 -3
  61. package/modern/ChartsXAxis/ChartsXAxis.js +1 -1
  62. package/modern/ChartsYAxis/ChartsYAxis.js +1 -1
  63. package/modern/Gauge/Gauge.js +0 -2
  64. package/modern/Gauge/GaugeContainer.js +0 -2
  65. package/modern/Gauge/GaugeProvider.js +3 -0
  66. package/modern/Gauge/GaugeValueText.js +1 -1
  67. package/modern/LineChart/LineChart.js +0 -2
  68. package/modern/PieChart/PieChart.js +0 -2
  69. package/modern/ResponsiveChartContainer/ResponsiveChartContainer.js +0 -2
  70. package/modern/ScatterChart/ScatterChart.js +0 -3
  71. package/modern/SparkLineChart/SparkLineChart.js +0 -2
  72. package/modern/context/CartesianContextProvider.js +3 -88
  73. package/modern/context/DrawingProvider.js +10 -36
  74. package/modern/context/HighlightProvider.js +3 -0
  75. package/modern/context/InteractionProvider.js +3 -0
  76. package/modern/context/SeriesContextProvider.js +3 -0
  77. package/modern/context/index.js +1 -2
  78. package/modern/hooks/useAxisEvents.js +2 -2
  79. package/modern/index.js +1 -1
  80. package/package.json +1 -1
  81. package/legacy/BarChart/BarChart.js +0 -440
  82. package/legacy/BarChart/BarElement.js +0 -119
  83. package/legacy/BarChart/BarPlot.js +0 -232
  84. package/legacy/BarChart/extremums.js +0 -45
  85. package/legacy/BarChart/formatter.js +0 -78
  86. package/legacy/BarChart/index.js +0 -3
  87. package/legacy/BarChart/legend.js +0 -15
  88. package/legacy/ChartContainer/ChartContainer.js +0 -189
  89. package/legacy/ChartContainer/index.js +0 -1
  90. package/legacy/ChartsAxis/ChartsAxis.js +0 -215
  91. package/legacy/ChartsAxis/axisClasses.js +0 -5
  92. package/legacy/ChartsAxis/index.js +0 -2
  93. package/legacy/ChartsAxisHighlight/ChartsAxisHighlight.js +0 -105
  94. package/legacy/ChartsAxisHighlight/index.js +0 -1
  95. package/legacy/ChartsClipPath/ChartsClipPath.js +0 -48
  96. package/legacy/ChartsClipPath/index.js +0 -1
  97. package/legacy/ChartsGrid/ChartsGrid.js +0 -119
  98. package/legacy/ChartsGrid/chartsGridClasses.js +0 -6
  99. package/legacy/ChartsGrid/index.js +0 -2
  100. package/legacy/ChartsLegend/ChartsLegend.js +0 -100
  101. package/legacy/ChartsLegend/DefaultChartsLegend.js +0 -302
  102. package/legacy/ChartsLegend/chartsLegendClasses.js +0 -5
  103. package/legacy/ChartsLegend/index.js +0 -4
  104. package/legacy/ChartsLegend/utils.js +0 -15
  105. package/legacy/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +0 -75
  106. package/legacy/ChartsOnAxisClickHandler/index.js +0 -1
  107. package/legacy/ChartsReferenceLine/ChartsReferenceLine.js +0 -72
  108. package/legacy/ChartsReferenceLine/ChartsXReferenceLine.js +0 -105
  109. package/legacy/ChartsReferenceLine/ChartsYReferenceLine.js +0 -105
  110. package/legacy/ChartsReferenceLine/chartsReferenceLineClasses.js +0 -6
  111. package/legacy/ChartsReferenceLine/common.js +0 -19
  112. package/legacy/ChartsReferenceLine/index.js +0 -2
  113. package/legacy/ChartsSurface.js +0 -78
  114. package/legacy/ChartsText/ChartsText.js +0 -95
  115. package/legacy/ChartsText/index.js +0 -1
  116. package/legacy/ChartsTooltip/ChartsAxisTooltipContent.js +0 -96
  117. package/legacy/ChartsTooltip/ChartsItemTooltipContent.js +0 -53
  118. package/legacy/ChartsTooltip/ChartsTooltip.js +0 -148
  119. package/legacy/ChartsTooltip/ChartsTooltipTable.js +0 -80
  120. package/legacy/ChartsTooltip/DefaultChartsAxisTooltipContent.js +0 -118
  121. package/legacy/ChartsTooltip/DefaultChartsItemTooltipContent.js +0 -78
  122. package/legacy/ChartsTooltip/chartsTooltipClasses.js +0 -5
  123. package/legacy/ChartsTooltip/index.js +0 -6
  124. package/legacy/ChartsTooltip/utils.js +0 -103
  125. package/legacy/ChartsVoronoiHandler/ChartsVoronoiHandler.js +0 -206
  126. package/legacy/ChartsVoronoiHandler/index.js +0 -1
  127. package/legacy/ChartsXAxis/ChartsXAxis.js +0 -339
  128. package/legacy/ChartsXAxis/index.js +0 -1
  129. package/legacy/ChartsYAxis/ChartsYAxis.js +0 -267
  130. package/legacy/ChartsYAxis/index.js +0 -1
  131. package/legacy/Gauge/Gauge.js +0 -146
  132. package/legacy/Gauge/GaugeContainer.js +0 -215
  133. package/legacy/Gauge/GaugeProvider.js +0 -87
  134. package/legacy/Gauge/GaugeReferenceArc.js +0 -37
  135. package/legacy/Gauge/GaugeValueArc.js +0 -44
  136. package/legacy/Gauge/GaugeValueText.js +0 -66
  137. package/legacy/Gauge/gaugeClasses.js +0 -7
  138. package/legacy/Gauge/index.js +0 -7
  139. package/legacy/Gauge/utils.js +0 -84
  140. package/legacy/LineChart/AnimatedArea.js +0 -102
  141. package/legacy/LineChart/AnimatedLine.js +0 -104
  142. package/legacy/LineChart/AreaElement.js +0 -112
  143. package/legacy/LineChart/AreaPlot.js +0 -149
  144. package/legacy/LineChart/LineChart.js +0 -452
  145. package/legacy/LineChart/LineElement.js +0 -112
  146. package/legacy/LineChart/LineHighlightElement.js +0 -79
  147. package/legacy/LineChart/LineHighlightPlot.js +0 -97
  148. package/legacy/LineChart/LinePlot.js +0 -144
  149. package/legacy/LineChart/MarkElement.js +0 -153
  150. package/legacy/LineChart/MarkPlot.js +0 -178
  151. package/legacy/LineChart/extremums.js +0 -54
  152. package/legacy/LineChart/formatter.js +0 -82
  153. package/legacy/LineChart/index.js +0 -11
  154. package/legacy/LineChart/legend.js +0 -15
  155. package/legacy/PieChart/PieArc.js +0 -103
  156. package/legacy/PieChart/PieArcLabel.js +0 -112
  157. package/legacy/PieChart/PieArcLabelPlot.js +0 -193
  158. package/legacy/PieChart/PieArcPlot.js +0 -180
  159. package/legacy/PieChart/PieChart.js +0 -404
  160. package/legacy/PieChart/PiePlot.js +0 -137
  161. package/legacy/PieChart/dataTransform/transition.js +0 -149
  162. package/legacy/PieChart/dataTransform/useTransformData.js +0 -63
  163. package/legacy/PieChart/formatter.js +0 -55
  164. package/legacy/PieChart/index.js +0 -6
  165. package/legacy/PieChart/legend.js +0 -16
  166. package/legacy/ResponsiveChartContainer/ResponsiveChartContainer.js +0 -185
  167. package/legacy/ResponsiveChartContainer/index.js +0 -1
  168. package/legacy/ResponsiveChartContainer/useChartContainerDimensions.js +0 -73
  169. package/legacy/ScatterChart/Scatter.js +0 -110
  170. package/legacy/ScatterChart/ScatterChart.js +0 -395
  171. package/legacy/ScatterChart/ScatterPlot.js +0 -80
  172. package/legacy/ScatterChart/extremums.js +0 -39
  173. package/legacy/ScatterChart/formatter.js +0 -12
  174. package/legacy/ScatterChart/index.js +0 -3
  175. package/legacy/ScatterChart/legend.js +0 -15
  176. package/legacy/SparkLineChart/SparkLineChart.js +0 -266
  177. package/legacy/SparkLineChart/index.js +0 -1
  178. package/legacy/colorPalettes/colorPalettes.js +0 -15
  179. package/legacy/colorPalettes/index.js +0 -1
  180. package/legacy/constants.js +0 -8
  181. package/legacy/context/CartesianContextProvider.js +0 -327
  182. package/legacy/context/DrawingProvider.js +0 -74
  183. package/legacy/context/HighlightProvider.js +0 -56
  184. package/legacy/context/InteractionProvider.js +0 -81
  185. package/legacy/context/SeriesContextProvider.js +0 -74
  186. package/legacy/context/index.js +0 -2
  187. package/legacy/hooks/index.js +0 -2
  188. package/legacy/hooks/useAxisEvents.js +0 -120
  189. package/legacy/hooks/useChartDimensions.js +0 -18
  190. package/legacy/hooks/useDrawingArea.js +0 -21
  191. package/legacy/hooks/useInteractionItemProps.js +0 -71
  192. package/legacy/hooks/useMounted.js +0 -21
  193. package/legacy/hooks/useReducedMotion.js +0 -27
  194. package/legacy/hooks/useScale.js +0 -33
  195. package/legacy/hooks/useTicks.js +0 -65
  196. package/legacy/index.js +0 -33
  197. package/legacy/internals/components/AxisSharedComponents.js +0 -25
  198. package/legacy/internals/defaultizeColor.js +0 -17
  199. package/legacy/internals/defaultizeValueFormatter.js +0 -12
  200. package/legacy/internals/domUtils.js +0 -121
  201. package/legacy/internals/geometry.js +0 -37
  202. package/legacy/internals/getCurve.js +0 -39
  203. package/legacy/internals/getScale.js +0 -17
  204. package/legacy/internals/getWordsByLines.js +0 -15
  205. package/legacy/internals/isBandScale.js +0 -3
  206. package/legacy/internals/stackSeries.js +0 -92
  207. package/legacy/internals/useAnimatedPath.js +0 -32
  208. package/legacy/internals/utils.js +0 -52
  209. package/legacy/models/axis.js +0 -6
  210. package/legacy/models/helpers.js +0 -1
  211. package/legacy/models/index.js +0 -4
  212. package/legacy/models/layout.js +0 -1
  213. package/legacy/models/seriesType/bar.js +0 -1
  214. package/legacy/models/seriesType/common.js +0 -1
  215. package/legacy/models/seriesType/config.js +0 -1
  216. package/legacy/models/seriesType/index.js +0 -5
  217. package/legacy/models/seriesType/line.js +0 -1
  218. package/legacy/models/seriesType/pie.js +0 -1
  219. package/legacy/models/seriesType/scatter.js +0 -1
  220. package/legacy/models/stacking.js +0 -1
  221. package/legacy/themeAugmentation/index.js +0 -3
@@ -1,327 +0,0 @@
1
- import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
- import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
- import _extends from "@babel/runtime/helpers/esm/extends";
4
- import * as React from 'react';
5
- import { scaleBand, scalePoint } from 'd3-scale';
6
- import PropTypes from 'prop-types';
7
- import { getExtremumX as getBarExtremumX, getExtremumY as getBarExtremumY } from '../BarChart/extremums';
8
- import { getExtremumX as getScatterExtremumX, getExtremumY as getScatterExtremumY } from '../ScatterChart/extremums';
9
- import { getExtremumX as getLineExtremumX, getExtremumY as getLineExtremumY } from '../LineChart/extremums';
10
- import { isBandScaleConfig, isPointScaleConfig } from '../models/axis';
11
- import { getScale } from '../internals/getScale';
12
- import { DrawingContext } from './DrawingProvider';
13
- import { SeriesContext } from './SeriesContextProvider';
14
- import { DEFAULT_X_AXIS_KEY, DEFAULT_Y_AXIS_KEY } from '../constants';
15
- import { getTickNumber } from '../hooks/useTicks';
16
- import { jsx as _jsx } from "react/jsx-runtime";
17
- var DEFAULT_CATEGORY_GAP_RATIO = 0.2;
18
- var DEFAULT_BAR_GAP_RATIO = 0.1;
19
-
20
- // TODO: those might be better placed in a distinct file
21
- var xExtremumGetters = {
22
- bar: getBarExtremumX,
23
- scatter: getScatterExtremumX,
24
- line: getLineExtremumX
25
- };
26
- var yExtremumGetters = {
27
- bar: getBarExtremumY,
28
- scatter: getScatterExtremumY,
29
- line: getLineExtremumY
30
- };
31
- export var CartesianContext = /*#__PURE__*/React.createContext({
32
- xAxis: {},
33
- yAxis: {},
34
- xAxisIds: [],
35
- yAxisIds: []
36
- });
37
-
38
- /**
39
- * API:
40
- *
41
- * - [CartesianContextProvider API](https://mui.com/x/api/charts/cartesian-context-provider/)
42
- */
43
- function CartesianContextProvider(props) {
44
- var inXAxis = props.xAxis,
45
- inYAxis = props.yAxis,
46
- dataset = props.dataset,
47
- children = props.children;
48
- var formattedSeries = React.useContext(SeriesContext);
49
- var drawingArea = React.useContext(DrawingContext);
50
- var xAxis = React.useMemo(function () {
51
- return inXAxis == null ? void 0 : inXAxis.map(function (axisConfig) {
52
- var dataKey = axisConfig.dataKey;
53
- if (dataKey === undefined || axisConfig.data !== undefined) {
54
- return axisConfig;
55
- }
56
- if (dataset === undefined) {
57
- throw Error('MUI X Charts: x-axis uses `dataKey` but no `dataset` is provided.');
58
- }
59
- return _extends({}, axisConfig, {
60
- data: dataset.map(function (d) {
61
- return d[dataKey];
62
- })
63
- });
64
- });
65
- }, [inXAxis, dataset]);
66
- var yAxis = React.useMemo(function () {
67
- return inYAxis == null ? void 0 : inYAxis.map(function (axisConfig) {
68
- var dataKey = axisConfig.dataKey;
69
- if (dataKey === undefined || axisConfig.data !== undefined) {
70
- return axisConfig;
71
- }
72
- if (dataset === undefined) {
73
- throw Error('MUI X Charts: y-axis uses `dataKey` but no `dataset` is provided.');
74
- }
75
- return _extends({}, axisConfig, {
76
- data: dataset.map(function (d) {
77
- return d[dataKey];
78
- })
79
- });
80
- });
81
- }, [inYAxis, dataset]);
82
- var value = React.useMemo(function () {
83
- var _xAxis$map, _yAxis$map;
84
- var axisExtremumCallback = function axisExtremumCallback(acc, chartType, axis, getters, isDefaultAxis) {
85
- var _ref, _formattedSeries$char;
86
- var getter = getters[chartType];
87
- var series = (_ref = (_formattedSeries$char = formattedSeries[chartType]) == null ? void 0 : _formattedSeries$char.series) != null ? _ref : {};
88
- var _getter = getter({
89
- series: series,
90
- axis: axis,
91
- isDefaultAxis: isDefaultAxis
92
- }),
93
- _getter2 = _slicedToArray(_getter, 2),
94
- minChartTypeData = _getter2[0],
95
- maxChartTypeData = _getter2[1];
96
- var _acc = _slicedToArray(acc, 2),
97
- minData = _acc[0],
98
- maxData = _acc[1];
99
- if (minData === null || maxData === null) {
100
- return [minChartTypeData, maxChartTypeData];
101
- }
102
- if (minChartTypeData === null || maxChartTypeData === null) {
103
- return [minData, maxData];
104
- }
105
- return [Math.min(minChartTypeData, minData), Math.max(maxChartTypeData, maxData)];
106
- };
107
- var getAxisExtremum = function getAxisExtremum(axis, getters, isDefaultAxis) {
108
- var charTypes = Object.keys(getters);
109
- return charTypes.reduce(function (acc, charType) {
110
- return axisExtremumCallback(acc, charType, axis, getters, isDefaultAxis);
111
- }, [null, null]);
112
- };
113
- var allXAxis = [].concat(_toConsumableArray((_xAxis$map = xAxis == null ? void 0 : xAxis.map(function (axis, index) {
114
- return _extends({
115
- id: "deaultized-x-axis-".concat(index)
116
- }, axis);
117
- })) != null ? _xAxis$map : []), _toConsumableArray(xAxis === undefined || xAxis.findIndex(function (_ref2) {
118
- var id = _ref2.id;
119
- return id === DEFAULT_X_AXIS_KEY;
120
- }) === -1 ? [{
121
- id: DEFAULT_X_AXIS_KEY,
122
- scaleType: 'linear'
123
- }] : []));
124
- var completedXAxis = {};
125
- allXAxis.forEach(function (axis, axisIndex) {
126
- var _axis$scaleType, _axis$min, _axis$max, _axis$min2, _axis$max2;
127
- var isDefaultAxis = axisIndex === 0;
128
- var _getAxisExtremum = getAxisExtremum(axis, xExtremumGetters, isDefaultAxis),
129
- _getAxisExtremum2 = _slicedToArray(_getAxisExtremum, 2),
130
- minData = _getAxisExtremum2[0],
131
- maxData = _getAxisExtremum2[1];
132
- var range = axis.reverse ? [drawingArea.left + drawingArea.width, drawingArea.left] : [drawingArea.left, drawingArea.left + drawingArea.width];
133
- if (isBandScaleConfig(axis)) {
134
- var _axis$categoryGapRati, _axis$barGapRatio;
135
- var categoryGapRatio = (_axis$categoryGapRati = axis.categoryGapRatio) != null ? _axis$categoryGapRati : DEFAULT_CATEGORY_GAP_RATIO;
136
- var barGapRatio = (_axis$barGapRatio = axis.barGapRatio) != null ? _axis$barGapRatio : DEFAULT_BAR_GAP_RATIO;
137
- completedXAxis[axis.id] = _extends({
138
- categoryGapRatio: categoryGapRatio,
139
- barGapRatio: barGapRatio
140
- }, axis, {
141
- scale: scaleBand(axis.data, range).paddingInner(categoryGapRatio).paddingOuter(categoryGapRatio / 2),
142
- tickNumber: axis.data.length
143
- });
144
- }
145
- if (isPointScaleConfig(axis)) {
146
- completedXAxis[axis.id] = _extends({}, axis, {
147
- scale: scalePoint(axis.data, range),
148
- tickNumber: axis.data.length
149
- });
150
- }
151
- if (axis.scaleType === 'band' || axis.scaleType === 'point') {
152
- // Could be merged with the two previous "if conditions" but then TS does not get that `axis.scaleType` can't be `band` or `point`.
153
- return;
154
- }
155
- var scaleType = (_axis$scaleType = axis.scaleType) != null ? _axis$scaleType : 'linear';
156
- var extremums = [(_axis$min = axis.min) != null ? _axis$min : minData, (_axis$max = axis.max) != null ? _axis$max : maxData];
157
- var tickNumber = getTickNumber(_extends({}, axis, {
158
- range: range,
159
- domain: extremums
160
- }));
161
- var niceScale = getScale(scaleType, extremums, range).nice(tickNumber);
162
- var niceDomain = niceScale.domain();
163
- var domain = [(_axis$min2 = axis.min) != null ? _axis$min2 : niceDomain[0], (_axis$max2 = axis.max) != null ? _axis$max2 : niceDomain[1]];
164
- completedXAxis[axis.id] = _extends({}, axis, {
165
- scaleType: scaleType,
166
- scale: niceScale.domain(domain),
167
- tickNumber: tickNumber
168
- });
169
- });
170
- var allYAxis = [].concat(_toConsumableArray((_yAxis$map = yAxis == null ? void 0 : yAxis.map(function (axis, index) {
171
- return _extends({
172
- id: "deaultized-y-axis-".concat(index)
173
- }, axis);
174
- })) != null ? _yAxis$map : []), _toConsumableArray(yAxis === undefined || yAxis.findIndex(function (_ref3) {
175
- var id = _ref3.id;
176
- return id === DEFAULT_Y_AXIS_KEY;
177
- }) === -1 ? [{
178
- id: DEFAULT_Y_AXIS_KEY,
179
- scaleType: 'linear'
180
- }] : []));
181
- var completedYAxis = {};
182
- allYAxis.forEach(function (axis, axisIndex) {
183
- var _axis$scaleType2, _axis$min3, _axis$max3, _axis$min4, _axis$max4;
184
- var isDefaultAxis = axisIndex === 0;
185
- var _getAxisExtremum3 = getAxisExtremum(axis, yExtremumGetters, isDefaultAxis),
186
- _getAxisExtremum4 = _slicedToArray(_getAxisExtremum3, 2),
187
- minData = _getAxisExtremum4[0],
188
- maxData = _getAxisExtremum4[1];
189
- var range = axis.reverse ? [drawingArea.top, drawingArea.top + drawingArea.height] : [drawingArea.top + drawingArea.height, drawingArea.top];
190
- if (isBandScaleConfig(axis)) {
191
- var _axis$categoryGapRati2;
192
- var categoryGapRatio = (_axis$categoryGapRati2 = axis.categoryGapRatio) != null ? _axis$categoryGapRati2 : DEFAULT_CATEGORY_GAP_RATIO;
193
- completedYAxis[axis.id] = _extends({
194
- categoryGapRatio: categoryGapRatio,
195
- barGapRatio: 0
196
- }, axis, {
197
- scale: scaleBand(axis.data, [range[1], range[0]]).paddingInner(categoryGapRatio).paddingOuter(categoryGapRatio / 2),
198
- tickNumber: axis.data.length
199
- });
200
- }
201
- if (isPointScaleConfig(axis)) {
202
- completedYAxis[axis.id] = _extends({}, axis, {
203
- scale: scalePoint(axis.data, [range[1], range[0]]),
204
- tickNumber: axis.data.length
205
- });
206
- }
207
- if (axis.scaleType === 'band' || axis.scaleType === 'point') {
208
- // Could be merged with the two previous "if conditions" but then TS does not get that `axis.scaleType` can't be `band` or `point`.
209
- return;
210
- }
211
- var scaleType = (_axis$scaleType2 = axis.scaleType) != null ? _axis$scaleType2 : 'linear';
212
- var extremums = [(_axis$min3 = axis.min) != null ? _axis$min3 : minData, (_axis$max3 = axis.max) != null ? _axis$max3 : maxData];
213
- var tickNumber = getTickNumber(_extends({}, axis, {
214
- range: range,
215
- domain: extremums
216
- }));
217
- var niceScale = getScale(scaleType, extremums, range).nice(tickNumber);
218
- var niceDomain = niceScale.domain();
219
- var domain = [(_axis$min4 = axis.min) != null ? _axis$min4 : niceDomain[0], (_axis$max4 = axis.max) != null ? _axis$max4 : niceDomain[1]];
220
- completedYAxis[axis.id] = _extends({}, axis, {
221
- scaleType: scaleType,
222
- scale: niceScale.domain(domain),
223
- tickNumber: tickNumber
224
- });
225
- });
226
- return {
227
- xAxis: completedXAxis,
228
- yAxis: completedYAxis,
229
- xAxisIds: allXAxis.map(function (_ref4) {
230
- var id = _ref4.id;
231
- return id;
232
- }),
233
- yAxisIds: allYAxis.map(function (_ref5) {
234
- var id = _ref5.id;
235
- return id;
236
- })
237
- };
238
- }, [drawingArea.height, drawingArea.left, drawingArea.top, drawingArea.width, formattedSeries, xAxis, yAxis]);
239
-
240
- // @ts-ignore
241
- return /*#__PURE__*/_jsx(CartesianContext.Provider, {
242
- value: value,
243
- children: children
244
- });
245
- }
246
- process.env.NODE_ENV !== "production" ? CartesianContextProvider.propTypes = {
247
- // ----------------------------- Warning --------------------------------
248
- // | These PropTypes are generated from the TypeScript type definitions |
249
- // | To update them edit the TypeScript types and run "yarn proptypes" |
250
- // ----------------------------------------------------------------------
251
- children: PropTypes.node,
252
- /**
253
- * An array of objects that can be used to populate series and axes data using their `dataKey` property.
254
- */
255
- dataset: PropTypes.arrayOf(PropTypes.object),
256
- /**
257
- * The configuration of the x-axes.
258
- * If not provided, a default axis config is used with id set to `DEFAULT_X_AXIS_KEY`.
259
- */
260
- xAxis: PropTypes.arrayOf(PropTypes.shape({
261
- axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
262
- classes: PropTypes.object,
263
- data: PropTypes.array,
264
- dataKey: PropTypes.string,
265
- disableLine: PropTypes.bool,
266
- disableTicks: PropTypes.bool,
267
- fill: PropTypes.string,
268
- hideTooltip: PropTypes.bool,
269
- id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
270
- label: PropTypes.string,
271
- labelFontSize: PropTypes.number,
272
- labelStyle: PropTypes.object,
273
- max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
274
- min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
275
- position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
276
- reverse: PropTypes.bool,
277
- scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
278
- slotProps: PropTypes.object,
279
- slots: PropTypes.object,
280
- stroke: PropTypes.string,
281
- tickFontSize: PropTypes.number,
282
- tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
283
- tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
284
- tickLabelStyle: PropTypes.object,
285
- tickMaxStep: PropTypes.number,
286
- tickMinStep: PropTypes.number,
287
- tickNumber: PropTypes.number,
288
- tickSize: PropTypes.number,
289
- valueFormatter: PropTypes.func
290
- })),
291
- /**
292
- * The configuration of the y-axes.
293
- * If not provided, a default axis config is used with id set to `DEFAULT_Y_AXIS_KEY`.
294
- */
295
- yAxis: PropTypes.arrayOf(PropTypes.shape({
296
- axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
297
- classes: PropTypes.object,
298
- data: PropTypes.array,
299
- dataKey: PropTypes.string,
300
- disableLine: PropTypes.bool,
301
- disableTicks: PropTypes.bool,
302
- fill: PropTypes.string,
303
- hideTooltip: PropTypes.bool,
304
- id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
305
- label: PropTypes.string,
306
- labelFontSize: PropTypes.number,
307
- labelStyle: PropTypes.object,
308
- max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
309
- min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
310
- position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
311
- reverse: PropTypes.bool,
312
- scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
313
- slotProps: PropTypes.object,
314
- slots: PropTypes.object,
315
- stroke: PropTypes.string,
316
- tickFontSize: PropTypes.number,
317
- tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
318
- tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
319
- tickLabelStyle: PropTypes.object,
320
- tickMaxStep: PropTypes.number,
321
- tickMinStep: PropTypes.number,
322
- tickNumber: PropTypes.number,
323
- tickSize: PropTypes.number,
324
- valueFormatter: PropTypes.func
325
- }))
326
- } : void 0;
327
- export { CartesianContextProvider };
@@ -1,74 +0,0 @@
1
- import _extends from "@babel/runtime/helpers/esm/extends";
2
- import * as React from 'react';
3
- import PropTypes from 'prop-types';
4
- import useId from '@mui/utils/useId';
5
- import useChartDimensions from '../hooks/useChartDimensions';
6
-
7
- /**
8
- * Defines the area in which it is possible to draw the charts.
9
- */
10
- import { jsx as _jsx } from "react/jsx-runtime";
11
- export var DrawingContext = /*#__PURE__*/React.createContext({
12
- top: 0,
13
- left: 0,
14
- bottom: 0,
15
- right: 0,
16
- height: 300,
17
- width: 400,
18
- chartId: ''
19
- });
20
- export var SVGContext = /*#__PURE__*/React.createContext({
21
- current: null
22
- });
23
-
24
- /**
25
- * API:
26
- *
27
- * - [DrawingProvider API](https://mui.com/x/api/charts/drawing-provider/)
28
- */
29
- function DrawingProvider(props) {
30
- var width = props.width,
31
- height = props.height,
32
- margin = props.margin,
33
- svgRef = props.svgRef,
34
- children = props.children;
35
- var drawingArea = useChartDimensions(width, height, margin);
36
- var chartId = useId();
37
- var value = React.useMemo(function () {
38
- return _extends({
39
- chartId: chartId != null ? chartId : ''
40
- }, drawingArea);
41
- }, [chartId, drawingArea]);
42
- return /*#__PURE__*/_jsx(SVGContext.Provider, {
43
- value: svgRef,
44
- children: /*#__PURE__*/_jsx(DrawingContext.Provider, {
45
- value: value,
46
- children: children
47
- })
48
- });
49
- }
50
- process.env.NODE_ENV !== "production" ? DrawingProvider.propTypes = {
51
- // ----------------------------- Warning --------------------------------
52
- // | These PropTypes are generated from the TypeScript type definitions |
53
- // | To update them edit the TypeScript types and run "yarn proptypes" |
54
- // ----------------------------------------------------------------------
55
- children: PropTypes.node,
56
- height: PropTypes.number.isRequired,
57
- /**
58
- * The margin between the SVG and the drawing area.
59
- * It's used for leaving some space for extra information such as the x- and y-axis or legend.
60
- * Accepts an object with the optional properties: `top`, `bottom`, `left`, and `right`.
61
- * @default object Depends on the charts type.
62
- */
63
- margin: PropTypes.shape({
64
- bottom: PropTypes.number,
65
- left: PropTypes.number,
66
- right: PropTypes.number,
67
- top: PropTypes.number
68
- }),
69
- svgRef: PropTypes.shape({
70
- current: PropTypes.object
71
- }).isRequired,
72
- width: PropTypes.number.isRequired
73
- } : void 0;
74
- export { DrawingProvider };
@@ -1,56 +0,0 @@
1
- import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
- import _extends from "@babel/runtime/helpers/esm/extends";
3
- import * as React from 'react';
4
- import { jsx as _jsx } from "react/jsx-runtime";
5
- var defaultScope = {
6
- highlighted: 'none',
7
- faded: 'none'
8
- };
9
- export var HighlighContext = /*#__PURE__*/React.createContext({
10
- item: null,
11
- scope: defaultScope,
12
- dispatch: function dispatch() {
13
- return null;
14
- }
15
- });
16
- var dataReducer = function dataReducer(prevState, action) {
17
- switch (action.type) {
18
- case 'enterItem':
19
- return _extends({}, prevState, {
20
- item: action.item,
21
- scope: _extends({}, defaultScope, action.scope)
22
- });
23
- case 'leaveItem':
24
- if (prevState.item === null || Object.keys(action.item).some(function (key) {
25
- return action.item[key] !== prevState.item[key];
26
- })) {
27
- // The item is already something else
28
- return prevState;
29
- }
30
- return _extends({}, prevState, {
31
- item: null
32
- });
33
- default:
34
- return prevState;
35
- }
36
- };
37
- function HighlightProvider(props) {
38
- var children = props.children;
39
- var _React$useReducer = React.useReducer(dataReducer, {
40
- item: null,
41
- scope: defaultScope
42
- }),
43
- _React$useReducer2 = _slicedToArray(_React$useReducer, 2),
44
- data = _React$useReducer2[0],
45
- dispatch = _React$useReducer2[1];
46
- var value = React.useMemo(function () {
47
- return _extends({}, data, {
48
- dispatch: dispatch
49
- });
50
- }, [data]);
51
- return /*#__PURE__*/_jsx(HighlighContext.Provider, {
52
- value: value,
53
- children: children
54
- });
55
- }
56
- export { HighlightProvider };
@@ -1,81 +0,0 @@
1
- import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
- import _extends from "@babel/runtime/helpers/esm/extends";
3
- import * as React from 'react';
4
- import { jsx as _jsx } from "react/jsx-runtime";
5
- export var InteractionContext = /*#__PURE__*/React.createContext({
6
- item: null,
7
- axis: {
8
- x: null,
9
- y: null
10
- },
11
- useVoronoiInteraction: false,
12
- dispatch: function dispatch() {
13
- return null;
14
- }
15
- });
16
- var dataReducer = function dataReducer(prevState, action) {
17
- switch (action.type) {
18
- case 'enterItem':
19
- return _extends({}, prevState, {
20
- item: action.data
21
- });
22
- case 'exitChart':
23
- if (prevState.item === null && prevState.axis.x === null && prevState.axis.y === null) {
24
- return prevState;
25
- }
26
- return _extends({}, prevState, {
27
- axis: {
28
- x: null,
29
- y: null
30
- },
31
- item: null
32
- });
33
- case 'updateVoronoiUsage':
34
- return _extends({}, prevState, {
35
- useVoronoiInteraction: action.useVoronoiInteraction
36
- });
37
- case 'leaveItem':
38
- if (prevState.item === null || Object.keys(action.data).some(function (key) {
39
- return action.data[key] !== prevState.item[key];
40
- })) {
41
- // The item is already something else
42
- return prevState;
43
- }
44
- return _extends({}, prevState, {
45
- item: null
46
- });
47
- case 'updateAxis':
48
- if (action.data.x === prevState.axis.x && action.data.y === prevState.axis.y) {
49
- return prevState;
50
- }
51
- return _extends({}, prevState, {
52
- axis: action.data
53
- });
54
- default:
55
- return prevState;
56
- }
57
- };
58
- function InteractionProvider(props) {
59
- var children = props.children;
60
- var _React$useReducer = React.useReducer(dataReducer, {
61
- item: null,
62
- axis: {
63
- x: null,
64
- y: null
65
- },
66
- useVoronoiInteraction: false
67
- }),
68
- _React$useReducer2 = _slicedToArray(_React$useReducer, 2),
69
- data = _React$useReducer2[0],
70
- dispatch = _React$useReducer2[1];
71
- var value = React.useMemo(function () {
72
- return _extends({}, data, {
73
- dispatch: dispatch
74
- });
75
- }, [data]);
76
- return /*#__PURE__*/_jsx(InteractionContext.Provider, {
77
- value: value,
78
- children: children
79
- });
80
- }
81
- export { InteractionProvider };
@@ -1,74 +0,0 @@
1
- import _extends from "@babel/runtime/helpers/esm/extends";
2
- import * as React from 'react';
3
- import { useTheme } from '@mui/material/styles';
4
- import barSeriesFormatter from '../BarChart/formatter';
5
- import scatterSeriesFormatter from '../ScatterChart/formatter';
6
- import lineSeriesFormatter from '../LineChart/formatter';
7
- import pieSeriesFormatter from '../PieChart/formatter';
8
- import { defaultizeColor } from '../internals/defaultizeColor';
9
- import { blueberryTwilightPalette } from '../colorPalettes';
10
- import { jsx as _jsx } from "react/jsx-runtime";
11
- export var SeriesContext = /*#__PURE__*/React.createContext({});
12
- var seriesTypeFormatter = {
13
- bar: barSeriesFormatter,
14
- scatter: scatterSeriesFormatter,
15
- line: lineSeriesFormatter,
16
- pie: pieSeriesFormatter
17
- };
18
-
19
- /**
20
- * This methods is the interface between what the developer is providing and what components receives
21
- * To simplify the components behaviors, it groups series by type, such that LinePlots props are not updated if some line data are modified
22
- * It also add defaultized values such as the ids, colors
23
- * @param series The array of series provided by devs
24
- * @param colors The color palette used to defaultize series colors
25
- * @returns An object structuring all the series by type.
26
- */
27
- var formatSeries = function formatSeries(series, colors, dataset) {
28
- // Group series by type
29
- var seriesGroups = {};
30
- series.forEach(function (seriesData, seriesIndex) {
31
- var _seriesGroups$type;
32
- var _seriesData$id = seriesData.id,
33
- id = _seriesData$id === void 0 ? "auto-generated-id-".concat(seriesIndex) : _seriesData$id,
34
- type = seriesData.type;
35
- if (seriesGroups[type] === undefined) {
36
- seriesGroups[type] = {
37
- series: {},
38
- seriesOrder: []
39
- };
40
- }
41
- if (((_seriesGroups$type = seriesGroups[type]) == null ? void 0 : _seriesGroups$type.series[id]) !== undefined) {
42
- throw new Error("MUI X Charts: series' id \"".concat(id, "\" is not unique."));
43
- }
44
- seriesGroups[type].series[id] = _extends({
45
- id: id
46
- }, defaultizeColor(seriesData, seriesIndex, colors));
47
- seriesGroups[type].seriesOrder.push(id);
48
- });
49
- var formattedSeries = {};
50
- // Apply formater on a type group
51
- Object.keys(seriesTypeFormatter).forEach(function (type) {
52
- if (seriesGroups[type] !== undefined) {
53
- var _seriesTypeFormatter$, _seriesTypeFormatter$2;
54
- formattedSeries[type] = (_seriesTypeFormatter$ = (_seriesTypeFormatter$2 = seriesTypeFormatter[type]) == null ? void 0 : _seriesTypeFormatter$2.call(seriesTypeFormatter, seriesGroups[type], dataset)) != null ? _seriesTypeFormatter$ : seriesGroups[type];
55
- }
56
- });
57
- return formattedSeries;
58
- };
59
- function SeriesContextProvider(props) {
60
- var series = props.series,
61
- dataset = props.dataset,
62
- _props$colors = props.colors,
63
- colors = _props$colors === void 0 ? blueberryTwilightPalette : _props$colors,
64
- children = props.children;
65
- var theme = useTheme();
66
- var formattedSeries = React.useMemo(function () {
67
- return formatSeries(series, typeof colors === 'function' ? colors(theme.palette.mode) : colors, dataset);
68
- }, [series, colors, theme.palette.mode, dataset]);
69
- return /*#__PURE__*/_jsx(SeriesContext.Provider, {
70
- value: formattedSeries,
71
- children: children
72
- });
73
- }
74
- export { SeriesContextProvider };
@@ -1,2 +0,0 @@
1
- export { CartesianContextProvider } from './CartesianContextProvider';
2
- export { DrawingProvider } from './DrawingProvider';
@@ -1,2 +0,0 @@
1
- export * from './useDrawingArea';
2
- export * from './useScale';