@mui/x-charts 6.0.0-alpha.1 → 6.0.0-alpha.3

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 (179) hide show
  1. package/BarChart/BarChart.d.ts +1 -4
  2. package/BarChart/BarChart.js +6 -3
  3. package/BarChart/BarPlot.js +42 -8
  4. package/BarChart/legend.d.ts +3 -0
  5. package/BarChart/legend.js +20 -0
  6. package/CHANGELOG.md +287 -107
  7. package/ChartContainer/index.d.ts +3 -1
  8. package/ChartContainer/index.js +10 -6
  9. package/ChartsAxisHighlight/ChartsAxisHighlight.js +3 -2
  10. package/ChartsLegend/ChartsLegend.d.ts +5 -1
  11. package/ChartsLegend/ChartsLegend.js +5 -1
  12. package/ChartsLegend/utils.d.ts +1 -1
  13. package/ChartsLegend/utils.js +12 -1
  14. package/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
  15. package/ChartsTooltip/ChartsItemTooltipContent.js +11 -2
  16. package/LineChart/LineChart.d.ts +1 -4
  17. package/LineChart/LineChart.js +6 -3
  18. package/LineChart/legend.d.ts +3 -0
  19. package/LineChart/legend.js +20 -0
  20. package/PieChart/PieArc.d.ts +36 -0
  21. package/PieChart/PieArc.js +128 -0
  22. package/PieChart/PieArcLabel.d.ts +36 -0
  23. package/PieChart/PieArcLabel.js +113 -0
  24. package/PieChart/PieChart.d.ts +20 -0
  25. package/PieChart/PieChart.js +292 -0
  26. package/PieChart/PiePlot.d.ts +2 -0
  27. package/PieChart/PiePlot.js +98 -0
  28. package/PieChart/formatter.d.ts +3 -0
  29. package/PieChart/formatter.js +49 -0
  30. package/PieChart/index.d.ts +4 -0
  31. package/PieChart/index.js +47 -0
  32. package/PieChart/legend.d.ts +3 -0
  33. package/PieChart/legend.js +19 -0
  34. package/PieChart/package.json +6 -0
  35. package/README.md +2 -2
  36. package/ResponsiveChartContainer/index.d.ts +1 -1
  37. package/ResponsiveChartContainer/index.js +22 -9
  38. package/ScatterChart/Scatter.d.ts +1 -1
  39. package/ScatterChart/Scatter.js +1 -1
  40. package/ScatterChart/ScatterChart.d.ts +1 -4
  41. package/ScatterChart/ScatterChart.js +6 -3
  42. package/ScatterChart/legend.d.ts +3 -0
  43. package/ScatterChart/legend.js +20 -0
  44. package/context/CartesianContextProvider.js +31 -20
  45. package/context/SeriesContextProvider.js +11 -1
  46. package/esm/BarChart/BarChart.js +4 -2
  47. package/esm/BarChart/BarPlot.js +44 -8
  48. package/esm/BarChart/legend.js +13 -0
  49. package/esm/ChartContainer/index.js +7 -5
  50. package/esm/ChartsAxisHighlight/ChartsAxisHighlight.js +3 -2
  51. package/esm/ChartsLegend/ChartsLegend.js +5 -1
  52. package/esm/ChartsLegend/utils.js +11 -1
  53. package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
  54. package/esm/ChartsTooltip/ChartsItemTooltipContent.js +11 -3
  55. package/esm/LineChart/LineChart.js +4 -2
  56. package/esm/LineChart/legend.js +13 -0
  57. package/esm/PieChart/PieArc.js +117 -0
  58. package/esm/PieChart/PieArcLabel.js +101 -0
  59. package/esm/PieChart/PieChart.js +285 -0
  60. package/esm/PieChart/PiePlot.js +92 -0
  61. package/esm/PieChart/formatter.js +48 -0
  62. package/esm/PieChart/index.js +4 -0
  63. package/esm/PieChart/legend.js +12 -0
  64. package/esm/ResponsiveChartContainer/index.js +20 -8
  65. package/esm/ScatterChart/Scatter.js +1 -1
  66. package/esm/ScatterChart/ScatterChart.js +4 -2
  67. package/esm/ScatterChart/legend.js +13 -0
  68. package/esm/context/CartesianContextProvider.js +31 -18
  69. package/esm/context/SeriesContextProvider.js +11 -1
  70. package/esm/hooks/index.js +2 -0
  71. package/esm/hooks/useAxisEvents.js +12 -7
  72. package/esm/hooks/useDrawingArea.js +16 -0
  73. package/esm/hooks/useScale.js +19 -21
  74. package/esm/hooks/useTicks.js +26 -13
  75. package/esm/index.js +2 -0
  76. package/esm/internals/defaultizeColor.js +7 -0
  77. package/esm/internals/getScale.js +17 -0
  78. package/esm/internals/isBandScale.js +3 -0
  79. package/esm/models/axis.js +6 -1
  80. package/esm/models/seriesType/index.js +1 -8
  81. package/hooks/index.d.ts +2 -0
  82. package/hooks/index.js +27 -0
  83. package/hooks/package.json +6 -0
  84. package/hooks/useAxisEvents.js +14 -9
  85. package/hooks/useDrawingArea.d.ts +6 -0
  86. package/hooks/useDrawingArea.js +24 -0
  87. package/hooks/useScale.d.ts +3 -6
  88. package/hooks/useScale.js +24 -24
  89. package/hooks/useTicks.d.ts +1 -1
  90. package/hooks/useTicks.js +19 -9
  91. package/index.d.ts +2 -0
  92. package/index.js +23 -1
  93. package/internals/defaultizeColor.d.ts +35 -0
  94. package/internals/defaultizeColor.js +7 -0
  95. package/internals/getScale.d.ts +2 -0
  96. package/internals/getScale.js +23 -0
  97. package/internals/isBandScale.d.ts +3 -0
  98. package/internals/isBandScale.js +9 -0
  99. package/legacy/BarChart/BarChart.js +4 -2
  100. package/legacy/BarChart/BarPlot.js +44 -10
  101. package/legacy/BarChart/legend.js +15 -0
  102. package/legacy/ChartContainer/index.js +7 -5
  103. package/legacy/ChartsAxisHighlight/ChartsAxisHighlight.js +3 -2
  104. package/legacy/ChartsLegend/ChartsLegend.js +5 -1
  105. package/legacy/ChartsLegend/utils.js +12 -6
  106. package/legacy/ChartsTooltip/ChartsAxisTooltipContent.js +3 -1
  107. package/legacy/ChartsTooltip/ChartsItemTooltipContent.js +10 -3
  108. package/legacy/LineChart/LineChart.js +4 -2
  109. package/legacy/LineChart/legend.js +15 -0
  110. package/legacy/PieChart/PieArc.js +118 -0
  111. package/legacy/PieChart/PieArcLabel.js +101 -0
  112. package/legacy/PieChart/PieChart.js +297 -0
  113. package/legacy/PieChart/PiePlot.js +89 -0
  114. package/legacy/PieChart/formatter.js +55 -0
  115. package/legacy/PieChart/index.js +4 -0
  116. package/legacy/PieChart/legend.js +16 -0
  117. package/legacy/ResponsiveChartContainer/index.js +18 -8
  118. package/legacy/ScatterChart/Scatter.js +1 -1
  119. package/legacy/ScatterChart/ScatterChart.js +4 -2
  120. package/legacy/ScatterChart/legend.js +15 -0
  121. package/legacy/context/CartesianContextProvider.js +31 -18
  122. package/legacy/context/SeriesContextProvider.js +11 -1
  123. package/legacy/hooks/index.js +2 -0
  124. package/legacy/hooks/useAxisEvents.js +12 -7
  125. package/legacy/hooks/useDrawingArea.js +17 -0
  126. package/legacy/hooks/useScale.js +17 -21
  127. package/legacy/hooks/useTicks.js +26 -13
  128. package/legacy/index.js +3 -1
  129. package/legacy/internals/defaultizeColor.js +9 -0
  130. package/legacy/internals/getScale.js +17 -0
  131. package/legacy/internals/isBandScale.js +3 -0
  132. package/legacy/models/axis.js +6 -1
  133. package/legacy/models/seriesType/index.js +1 -8
  134. package/models/axis.d.ts +25 -12
  135. package/models/axis.js +9 -1
  136. package/models/seriesType/bar.d.ts +1 -1
  137. package/models/seriesType/common.d.ts +1 -1
  138. package/models/seriesType/config.d.ts +29 -2
  139. package/models/seriesType/index.d.ts +7 -3
  140. package/models/seriesType/index.js +11 -0
  141. package/models/seriesType/line.d.ts +1 -1
  142. package/models/seriesType/pie.d.ts +103 -3
  143. package/models/seriesType/scatter.d.ts +1 -1
  144. package/modern/BarChart/BarChart.js +4 -2
  145. package/modern/BarChart/BarPlot.js +44 -8
  146. package/modern/BarChart/legend.js +13 -0
  147. package/modern/ChartContainer/index.js +7 -5
  148. package/modern/ChartsAxisHighlight/ChartsAxisHighlight.js +3 -2
  149. package/modern/ChartsLegend/ChartsLegend.js +5 -1
  150. package/modern/ChartsLegend/utils.js +11 -1
  151. package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
  152. package/modern/ChartsTooltip/ChartsItemTooltipContent.js +11 -2
  153. package/modern/LineChart/LineChart.js +4 -2
  154. package/modern/LineChart/legend.js +13 -0
  155. package/modern/PieChart/PieArc.js +116 -0
  156. package/modern/PieChart/PieArcLabel.js +101 -0
  157. package/modern/PieChart/PieChart.js +285 -0
  158. package/modern/PieChart/PiePlot.js +91 -0
  159. package/modern/PieChart/formatter.js +41 -0
  160. package/modern/PieChart/index.js +4 -0
  161. package/modern/PieChart/legend.js +12 -0
  162. package/modern/ResponsiveChartContainer/index.js +20 -8
  163. package/modern/ScatterChart/Scatter.js +1 -1
  164. package/modern/ScatterChart/ScatterChart.js +4 -2
  165. package/modern/ScatterChart/legend.js +13 -0
  166. package/modern/context/CartesianContextProvider.js +29 -18
  167. package/modern/context/SeriesContextProvider.js +11 -1
  168. package/modern/hooks/index.js +2 -0
  169. package/modern/hooks/useAxisEvents.js +12 -7
  170. package/modern/hooks/useDrawingArea.js +16 -0
  171. package/modern/hooks/useScale.js +19 -21
  172. package/modern/hooks/useTicks.js +18 -8
  173. package/modern/index.js +3 -1
  174. package/modern/internals/defaultizeColor.js +7 -0
  175. package/modern/internals/getScale.js +17 -0
  176. package/modern/internals/isBandScale.js +3 -0
  177. package/modern/models/axis.js +6 -1
  178. package/modern/models/seriesType/index.js +1 -8
  179. package/package.json +1 -1
@@ -0,0 +1,285 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import * as React from 'react';
3
+ import PropTypes from 'prop-types';
4
+ import { ResponsiveChartContainer } from '../ResponsiveChartContainer';
5
+ import { ChartsAxis } from '../ChartsAxis/ChartsAxis';
6
+ import { DEFAULT_X_AXIS_KEY } from '../constants';
7
+ import { ChartsTooltip } from '../ChartsTooltip';
8
+ import { ChartsLegend } from '../ChartsLegend';
9
+ import { ChartsAxisHighlight } from '../ChartsAxisHighlight';
10
+ import { PiePlot } from './PiePlot';
11
+ import { jsx as _jsx } from "react/jsx-runtime";
12
+ import { jsxs as _jsxs } from "react/jsx-runtime";
13
+ const defaultMargin = {
14
+ top: 5,
15
+ bottom: 5,
16
+ left: 5,
17
+ right: 100
18
+ };
19
+ function PieChart(props) {
20
+ const {
21
+ xAxis,
22
+ yAxis,
23
+ series,
24
+ width,
25
+ height,
26
+ margin: marginProps,
27
+ colors,
28
+ sx,
29
+ tooltip = {
30
+ trigger: 'item'
31
+ },
32
+ axisHighlight = {
33
+ x: 'none',
34
+ y: 'none'
35
+ },
36
+ legend = {
37
+ direction: 'column',
38
+ position: {
39
+ vertical: 'middle',
40
+ horizontal: 'right'
41
+ }
42
+ },
43
+ topAxis = null,
44
+ leftAxis = null,
45
+ rightAxis = null,
46
+ bottomAxis = null,
47
+ children
48
+ } = props;
49
+ const margin = _extends({}, defaultMargin, marginProps);
50
+ return /*#__PURE__*/_jsxs(ResponsiveChartContainer, {
51
+ series: series.map(s => _extends({
52
+ type: 'pie'
53
+ }, s)),
54
+ width: width,
55
+ height: height,
56
+ margin: margin,
57
+ xAxis: xAxis ?? [{
58
+ id: DEFAULT_X_AXIS_KEY,
59
+ scaleType: 'point',
60
+ data: [...new Array(Math.max(...series.map(s => s.data.length)))].map((_, index) => index)
61
+ }],
62
+ yAxis: yAxis,
63
+ colors: colors,
64
+ sx: sx,
65
+ disableAxisListener: tooltip?.trigger !== 'axis' && axisHighlight?.x === 'none' && axisHighlight?.y === 'none',
66
+ children: [/*#__PURE__*/_jsx(ChartsAxis, {
67
+ topAxis: topAxis,
68
+ leftAxis: leftAxis,
69
+ rightAxis: rightAxis,
70
+ bottomAxis: bottomAxis
71
+ }), /*#__PURE__*/_jsx(PiePlot, {}), /*#__PURE__*/_jsx(ChartsLegend, _extends({}, legend)), /*#__PURE__*/_jsx(ChartsAxisHighlight, _extends({}, axisHighlight)), /*#__PURE__*/_jsx(ChartsTooltip, _extends({}, tooltip)), children]
72
+ });
73
+ }
74
+ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
75
+ // ----------------------------- Warning --------------------------------
76
+ // | These PropTypes are generated from the TypeScript type definitions |
77
+ // | To update them edit the TypeScript types and run "yarn proptypes" |
78
+ // ----------------------------------------------------------------------
79
+ axisHighlight: PropTypes.shape({
80
+ x: PropTypes.oneOf(['band', 'line', 'none']),
81
+ y: PropTypes.oneOf(['line', 'none'])
82
+ }),
83
+ /**
84
+ * Indicate which axis to display the bottom of the charts.
85
+ * Can be a string (the id of the axis) or an object `ChartsXAxisProps`
86
+ * @default xAxisIds[0] The id of the first provided axis
87
+ */
88
+ bottomAxis: PropTypes.oneOfType([PropTypes.shape({
89
+ axisId: PropTypes.string.isRequired,
90
+ classes: PropTypes.object,
91
+ disableLine: PropTypes.bool,
92
+ disableTicks: PropTypes.bool,
93
+ fill: PropTypes.string,
94
+ label: PropTypes.string,
95
+ labelFontSize: PropTypes.number,
96
+ position: PropTypes.oneOf(['bottom', 'top']),
97
+ stroke: PropTypes.string,
98
+ tickFontSize: PropTypes.number,
99
+ tickSize: PropTypes.number
100
+ }), PropTypes.string]),
101
+ children: PropTypes.node,
102
+ className: PropTypes.string,
103
+ /**
104
+ * Color palette used to colorize multiple series.
105
+ */
106
+ colors: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string), PropTypes.func]),
107
+ desc: PropTypes.string,
108
+ disableAxisListener: PropTypes.bool,
109
+ height: PropTypes.number,
110
+ /**
111
+ * Indicate which axis to display the left of the charts.
112
+ * Can be a string (the id of the axis) or an object `ChartsYAxisProps`
113
+ * @default yAxisIds[0] The id of the first provided axis
114
+ */
115
+ leftAxis: PropTypes.oneOfType([PropTypes.shape({
116
+ axisId: PropTypes.string.isRequired,
117
+ classes: PropTypes.object,
118
+ disableLine: PropTypes.bool,
119
+ disableTicks: PropTypes.bool,
120
+ fill: PropTypes.string,
121
+ label: PropTypes.string,
122
+ labelFontSize: PropTypes.number,
123
+ position: PropTypes.oneOf(['left', 'right']),
124
+ stroke: PropTypes.string,
125
+ tickFontSize: PropTypes.number,
126
+ tickSize: PropTypes.number
127
+ }), PropTypes.string]),
128
+ legend: PropTypes.shape({
129
+ classes: PropTypes.object,
130
+ direction: PropTypes.oneOf(['column', 'row']),
131
+ hidden: PropTypes.bool,
132
+ itemWidth: PropTypes.number,
133
+ markSize: PropTypes.number,
134
+ offset: PropTypes.shape({
135
+ x: PropTypes.number,
136
+ y: PropTypes.number
137
+ }),
138
+ position: PropTypes.shape({
139
+ horizontal: PropTypes.oneOf(['left', 'middle', 'right']).isRequired,
140
+ vertical: PropTypes.oneOf(['bottom', 'middle', 'top']).isRequired
141
+ }),
142
+ spacing: PropTypes.number
143
+ }),
144
+ margin: PropTypes.shape({
145
+ bottom: PropTypes.number,
146
+ left: PropTypes.number,
147
+ right: PropTypes.number,
148
+ top: PropTypes.number
149
+ }),
150
+ /**
151
+ * Indicate which axis to display the right of the charts.
152
+ * Can be a string (the id of the axis) or an object `ChartsYAxisProps`
153
+ * @default null
154
+ */
155
+ rightAxis: PropTypes.oneOfType([PropTypes.shape({
156
+ axisId: PropTypes.string.isRequired,
157
+ classes: PropTypes.object,
158
+ disableLine: PropTypes.bool,
159
+ disableTicks: PropTypes.bool,
160
+ fill: PropTypes.string,
161
+ label: PropTypes.string,
162
+ labelFontSize: PropTypes.number,
163
+ position: PropTypes.oneOf(['left', 'right']),
164
+ stroke: PropTypes.string,
165
+ tickFontSize: PropTypes.number,
166
+ tickSize: PropTypes.number
167
+ }), PropTypes.string]),
168
+ series: PropTypes.arrayOf(PropTypes.shape({
169
+ arcLabel: PropTypes.oneOfType([PropTypes.oneOf(['formattedValue', 'label', 'value']), PropTypes.func]),
170
+ arcLabelMinAngle: PropTypes.number,
171
+ color: PropTypes.string,
172
+ cornerRadius: PropTypes.number,
173
+ cx: PropTypes.number,
174
+ cy: PropTypes.number,
175
+ data: PropTypes.arrayOf(PropTypes.shape({
176
+ color: PropTypes.string,
177
+ id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
178
+ label: PropTypes.string,
179
+ value: PropTypes.number.isRequired
180
+ })).isRequired,
181
+ endAngle: PropTypes.number,
182
+ faded: PropTypes.shape({
183
+ additionalRadius: PropTypes.number,
184
+ cornerRadius: PropTypes.number,
185
+ innerRadius: PropTypes.number,
186
+ outerRadius: PropTypes.number
187
+ }),
188
+ highlighted: PropTypes.shape({
189
+ additionalRadius: PropTypes.number,
190
+ cornerRadius: PropTypes.number,
191
+ innerRadius: PropTypes.number,
192
+ outerRadius: PropTypes.number
193
+ }),
194
+ highlightScope: PropTypes.shape({
195
+ faded: PropTypes.oneOf(['global', 'none', 'series']),
196
+ highlighted: PropTypes.oneOf(['item', 'none', 'series'])
197
+ }),
198
+ id: PropTypes.string,
199
+ innerRadius: PropTypes.number,
200
+ outerRadius: PropTypes.number,
201
+ paddingAngle: PropTypes.number,
202
+ sortingValues: PropTypes.oneOfType([PropTypes.oneOf(['asc', 'desc', 'none']), PropTypes.func]),
203
+ startAngle: PropTypes.number,
204
+ type: PropTypes.oneOf(['pie']),
205
+ valueFormatter: PropTypes.func
206
+ })).isRequired,
207
+ sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
208
+ title: PropTypes.string,
209
+ tooltip: PropTypes.shape({
210
+ axisContent: PropTypes.elementType,
211
+ classes: PropTypes.object,
212
+ itemContent: PropTypes.elementType,
213
+ trigger: PropTypes.oneOf(['axis', 'item', 'none'])
214
+ }),
215
+ /**
216
+ * Indicate which axis to display the top of the charts.
217
+ * Can be a string (the id of the axis) or an object `ChartsXAxisProps`
218
+ * @default null
219
+ */
220
+ topAxis: PropTypes.oneOfType([PropTypes.shape({
221
+ axisId: PropTypes.string.isRequired,
222
+ classes: PropTypes.object,
223
+ disableLine: PropTypes.bool,
224
+ disableTicks: PropTypes.bool,
225
+ fill: PropTypes.string,
226
+ label: PropTypes.string,
227
+ labelFontSize: PropTypes.number,
228
+ position: PropTypes.oneOf(['bottom', 'top']),
229
+ stroke: PropTypes.string,
230
+ tickFontSize: PropTypes.number,
231
+ tickSize: PropTypes.number
232
+ }), PropTypes.string]),
233
+ viewBox: PropTypes.shape({
234
+ height: PropTypes.number,
235
+ width: PropTypes.number,
236
+ x: PropTypes.number,
237
+ y: PropTypes.number
238
+ }),
239
+ width: PropTypes.number,
240
+ xAxis: PropTypes.arrayOf(PropTypes.shape({
241
+ axisId: PropTypes.string,
242
+ classes: PropTypes.object,
243
+ data: PropTypes.array,
244
+ disableLine: PropTypes.bool,
245
+ disableTicks: PropTypes.bool,
246
+ fill: PropTypes.string,
247
+ id: PropTypes.string,
248
+ label: PropTypes.string,
249
+ labelFontSize: PropTypes.number,
250
+ max: PropTypes.number,
251
+ maxTicks: PropTypes.number,
252
+ min: PropTypes.number,
253
+ minTicks: PropTypes.number,
254
+ position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
255
+ scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
256
+ stroke: PropTypes.string,
257
+ tickFontSize: PropTypes.number,
258
+ tickSize: PropTypes.number,
259
+ tickSpacing: PropTypes.number,
260
+ valueFormatter: PropTypes.func
261
+ })),
262
+ yAxis: PropTypes.arrayOf(PropTypes.shape({
263
+ axisId: PropTypes.string,
264
+ classes: PropTypes.object,
265
+ data: PropTypes.array,
266
+ disableLine: PropTypes.bool,
267
+ disableTicks: PropTypes.bool,
268
+ fill: PropTypes.string,
269
+ id: PropTypes.string,
270
+ label: PropTypes.string,
271
+ labelFontSize: PropTypes.number,
272
+ max: PropTypes.number,
273
+ maxTicks: PropTypes.number,
274
+ min: PropTypes.number,
275
+ minTicks: PropTypes.number,
276
+ position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
277
+ scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
278
+ stroke: PropTypes.string,
279
+ tickFontSize: PropTypes.number,
280
+ tickSize: PropTypes.number,
281
+ tickSpacing: PropTypes.number,
282
+ valueFormatter: PropTypes.func
283
+ }))
284
+ } : void 0;
285
+ export { PieChart };
@@ -0,0 +1,91 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import * as React from 'react';
3
+ import { SeriesContext } from '../context/SeriesContextProvider';
4
+ import PieArc from './PieArc';
5
+ import PieArcLabel from './PieArcLabel';
6
+ import { DrawingContext } from '../context/DrawingProvider';
7
+ import { createElement as _createElement } from "react";
8
+ import { jsxs as _jsxs } from "react/jsx-runtime";
9
+ import { jsx as _jsx } from "react/jsx-runtime";
10
+ const RATIO = 180 / Math.PI;
11
+ function getItemLabel(arcLabel, arcLabelMinAngle, item) {
12
+ if (!arcLabel) {
13
+ return null;
14
+ }
15
+ const angle = (item.endAngle - item.startAngle) * RATIO;
16
+ if (angle < arcLabelMinAngle) {
17
+ return null;
18
+ }
19
+ if (typeof arcLabel === 'string') {
20
+ return item[arcLabel]?.toString();
21
+ }
22
+ return arcLabel(item);
23
+ }
24
+ export function PiePlot() {
25
+ const seriesData = React.useContext(SeriesContext).pie;
26
+ const {
27
+ left,
28
+ top,
29
+ width,
30
+ height
31
+ } = React.useContext(DrawingContext);
32
+ if (seriesData === undefined) {
33
+ return null;
34
+ }
35
+ const availableRadius = Math.min(width, height) / 2;
36
+ const center = {
37
+ x: left + width / 2,
38
+ y: top + height / 2
39
+ };
40
+ const {
41
+ series,
42
+ seriesOrder
43
+ } = seriesData;
44
+ return /*#__PURE__*/_jsx("g", {
45
+ children: seriesOrder.map(seriesId => {
46
+ const {
47
+ innerRadius,
48
+ outerRadius,
49
+ cornerRadius,
50
+ arcLabel,
51
+ arcLabelMinAngle = 0,
52
+ data,
53
+ cx,
54
+ cy,
55
+ highlighted,
56
+ faded
57
+ } = series[seriesId];
58
+ return /*#__PURE__*/_jsx("g", {
59
+ transform: `translate(${cx === undefined ? center.x : left + cx}, ${cy === undefined ? center.y : top + cy})`,
60
+ children: /*#__PURE__*/_jsxs("g", {
61
+ children: [data.map((item, index) => {
62
+ return /*#__PURE__*/_createElement(PieArc, _extends({}, item, {
63
+ key: item.id,
64
+ innerRadius: innerRadius,
65
+ outerRadius: outerRadius ?? availableRadius,
66
+ cornerRadius: cornerRadius,
67
+ id: seriesId,
68
+ color: item.color,
69
+ dataIndex: index,
70
+ highlightScope: series[seriesId].highlightScope,
71
+ highlighted: highlighted,
72
+ faded: faded
73
+ }));
74
+ }), data.map((item, index) => {
75
+ return /*#__PURE__*/_createElement(PieArcLabel, _extends({}, item, {
76
+ key: item.id,
77
+ innerRadius: innerRadius,
78
+ outerRadius: outerRadius ?? availableRadius,
79
+ cornerRadius: cornerRadius,
80
+ id: seriesId,
81
+ color: item.color,
82
+ dataIndex: index,
83
+ highlightScope: series[seriesId].highlightScope,
84
+ formattedArcLabel: getItemLabel(arcLabel, arcLabelMinAngle, item)
85
+ }));
86
+ })]
87
+ })
88
+ }, seriesId);
89
+ })
90
+ });
91
+ }
@@ -0,0 +1,41 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import { pie as d3Pie } from 'd3-shape';
3
+ const getSortingComparator = (comparator = 'none') => {
4
+ if (typeof comparator === 'function') {
5
+ return comparator;
6
+ }
7
+ switch (comparator) {
8
+ case 'none':
9
+ return null;
10
+ case 'desc':
11
+ return (a, b) => b - a;
12
+ case 'asc':
13
+ return (a, b) => a - b;
14
+ default:
15
+ return null;
16
+ }
17
+ };
18
+ const formatter = params => {
19
+ const {
20
+ seriesOrder,
21
+ series
22
+ } = params;
23
+ const defaultizedSeries = {};
24
+ seriesOrder.forEach(seriesId => {
25
+ const arcs = d3Pie().startAngle(2 * Math.PI * (series[seriesId].startAngle ?? 0) / 360).endAngle(2 * Math.PI * (series[seriesId].endAngle ?? 360) / 360).padAngle(2 * Math.PI * (series[seriesId].paddingAngle ?? 0) / 360).sortValues(getSortingComparator(series[seriesId].sortingValues ?? 'none'))(series[seriesId].data.map(piePoint => piePoint.value));
26
+ defaultizedSeries[seriesId] = _extends({
27
+ valueFormatter: item => item.value.toLocaleString()
28
+ }, series[seriesId], {
29
+ data: series[seriesId].data.map((item, index) => _extends({}, item, {
30
+ id: item.id ?? `auto-generated-pie-id-${seriesId}-${index}`
31
+ }, arcs[index])).map(item => _extends({}, item, {
32
+ formattedValue: series[seriesId].valueFormatter?.(item) ?? item.value.toLocaleString()
33
+ }))
34
+ });
35
+ });
36
+ return {
37
+ seriesOrder,
38
+ series: defaultizedSeries
39
+ };
40
+ };
41
+ export default formatter;
@@ -0,0 +1,4 @@
1
+ export { PiePlot } from './PiePlot';
2
+ export { PieChart } from './PieChart';
3
+ export * from './PieArc';
4
+ export * from './PieArcLabel';
@@ -0,0 +1,12 @@
1
+ const legendGetter = params => {
2
+ const {
3
+ seriesOrder,
4
+ series
5
+ } = params;
6
+ return seriesOrder.flatMap(seriesId => series[seriesId].data.map(item => ({
7
+ color: item.color,
8
+ label: item.label,
9
+ id: item.id
10
+ })).filter(item => item.label !== undefined));
11
+ };
12
+ export default legendGetter;
@@ -1,4 +1,6 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
+ const _excluded = ["width", "height"];
2
4
  import * as React from 'react';
3
5
  import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
4
6
  import ownerWindow from '@mui/utils/ownerWindow';
@@ -82,19 +84,29 @@ const ResizableContainer = styled('div', {
82
84
  flexDirection: 'column',
83
85
  alignItems: 'center',
84
86
  justifyContent: 'center',
85
- overflow: 'hidden'
87
+ overflow: 'hidden',
88
+ '&>svg': {
89
+ width: '100%',
90
+ height: '100%'
91
+ }
86
92
  }));
87
- export function ResponsiveChartContainer(props) {
88
- const [containerRef, width, height] = useChartDimensions(props.width, props.height);
93
+ export const ResponsiveChartContainer = /*#__PURE__*/React.forwardRef(function ResponsiveChartContainer(props, ref) {
94
+ const {
95
+ width: inWidth,
96
+ height: inHeight
97
+ } = props,
98
+ other = _objectWithoutPropertiesLoose(props, _excluded);
99
+ const [containerRef, width, height] = useChartDimensions(inWidth, inHeight);
89
100
  return /*#__PURE__*/_jsx(ResizableContainer, {
90
101
  ref: containerRef,
91
102
  ownerState: {
92
- width: props.width,
93
- height: props.height
103
+ width: inWidth,
104
+ height: inHeight
94
105
  },
95
- children: /*#__PURE__*/_jsx(ChartContainer, _extends({}, props, {
106
+ children: /*#__PURE__*/_jsx(ChartContainer, _extends({}, other, {
96
107
  width: width,
97
- height: height
108
+ height: height,
109
+ ref: ref
98
110
  }))
99
111
  });
100
- }
112
+ });
@@ -82,7 +82,7 @@ process.env.NODE_ENV !== "production" ? Scatter.propTypes = {
82
82
  color: PropTypes.string.isRequired,
83
83
  markerSize: PropTypes.number.isRequired,
84
84
  series: PropTypes.shape({
85
- color: PropTypes.string.isRequired,
85
+ color: PropTypes.string,
86
86
  data: PropTypes.arrayOf(PropTypes.shape({
87
87
  id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
88
88
  x: PropTypes.number.isRequired,
@@ -9,7 +9,7 @@ import { ChartsLegend } from '../ChartsLegend';
9
9
  import { ChartsAxisHighlight } from '../ChartsAxisHighlight';
10
10
  import { jsx as _jsx } from "react/jsx-runtime";
11
11
  import { jsxs as _jsxs } from "react/jsx-runtime";
12
- function ScatterChart(props) {
12
+ const ScatterChart = /*#__PURE__*/React.forwardRef(function ScatterChart(props, ref) {
13
13
  const {
14
14
  xAxis,
15
15
  yAxis,
@@ -29,6 +29,7 @@ function ScatterChart(props) {
29
29
  children
30
30
  } = props;
31
31
  return /*#__PURE__*/_jsxs(ResponsiveChartContainer, {
32
+ ref: ref,
32
33
  series: series.map(s => _extends({
33
34
  type: 'scatter'
34
35
  }, s)),
@@ -51,7 +52,7 @@ function ScatterChart(props) {
51
52
  trigger: "item"
52
53
  }, tooltip)), children]
53
54
  });
54
- }
55
+ });
55
56
  process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
56
57
  // ----------------------------- Warning --------------------------------
57
58
  // | These PropTypes are generated from the TypeScript type definitions |
@@ -109,6 +110,7 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
109
110
  legend: PropTypes.shape({
110
111
  classes: PropTypes.object,
111
112
  direction: PropTypes.oneOf(['column', 'row']),
113
+ hidden: PropTypes.bool,
112
114
  itemWidth: PropTypes.number,
113
115
  markSize: PropTypes.number,
114
116
  offset: PropTypes.shape({
@@ -0,0 +1,13 @@
1
+ const legendGetter = params => {
2
+ const {
3
+ seriesOrder,
4
+ series
5
+ } = params;
6
+ const data = seriesOrder.map(seriesId => ({
7
+ color: series[seriesId].color,
8
+ label: series[seriesId].label,
9
+ id: seriesId
10
+ }));
11
+ return data.filter(item => item.label !== undefined);
12
+ };
13
+ export default legendGetter;
@@ -5,12 +5,15 @@ import PropTypes from 'prop-types';
5
5
  import { getExtremumX as getBarExtremumX, getExtremumY as getBarExtremumY } from '../BarChart/extremums';
6
6
  import { getExtremumX as getScatterExtremumX, getExtremumY as getScatterExtremumY } from '../ScatterChart/extremums';
7
7
  import { getExtremumX as getLineExtremumX, getExtremumY as getLineExtremumY } from '../LineChart/extremums';
8
- import { getScale } from '../hooks/useScale';
8
+ import { isBandScaleConfig, isPointScaleConfig } from '../models/axis';
9
+ import { getScale } from '../internals/getScale';
9
10
  import { DrawingContext } from './DrawingProvider';
10
11
  import { SeriesContext } from './SeriesContextProvider';
11
12
  import { DEFAULT_X_AXIS_KEY, DEFAULT_Y_AXIS_KEY } from '../constants';
12
13
  import { getTicksNumber } from '../hooks/useTicks';
13
14
  import { jsx as _jsx } from "react/jsx-runtime";
15
+ const DEFAULT_CATEGORY_GAP_RATIO = 0.1;
16
+
14
17
  // TODO: those might be better placed in a distinct file
15
18
  const xExtremumGetters = {
16
19
  bar: getBarExtremumX,
@@ -71,24 +74,28 @@ function CartesianContextProvider({
71
74
  allXAxis.forEach((axis, axisIndex) => {
72
75
  const isDefaultAxis = axisIndex === 0;
73
76
  const [minData, maxData] = getAxisExtremum(axis, xExtremumGetters, isDefaultAxis);
74
- const scaleType = axis.scaleType ?? 'linear';
75
77
  const range = [drawingArea.left, drawingArea.left + drawingArea.width];
76
- if (scaleType === 'band') {
77
- completedXAxis[axis.id] = _extends({}, axis, {
78
- scaleType,
79
- scale: scaleBand(axis.data, range),
78
+ if (isBandScaleConfig(axis)) {
79
+ const categoryGapRatio = axis.categoryGapRatio ?? DEFAULT_CATEGORY_GAP_RATIO;
80
+ completedXAxis[axis.id] = _extends({
81
+ categoryGapRatio,
82
+ barGapRatio: 0
83
+ }, axis, {
84
+ scale: scaleBand(axis.data, range).paddingInner(categoryGapRatio).paddingOuter(categoryGapRatio / 2),
80
85
  ticksNumber: axis.data.length
81
86
  });
82
- return;
83
87
  }
84
- if (scaleType === 'point') {
88
+ if (isPointScaleConfig(axis)) {
85
89
  completedXAxis[axis.id] = _extends({}, axis, {
86
- scaleType,
87
90
  scale: scalePoint(axis.data, range),
88
91
  ticksNumber: axis.data.length
89
92
  });
93
+ }
94
+ if (axis.scaleType === 'band' || axis.scaleType === 'point') {
95
+ // Could be merged with the two previous "if conditions" but then TS does not get that `axis.scaleType` can't be `band` or `point`.
90
96
  return;
91
97
  }
98
+ const scaleType = axis.scaleType ?? 'linear';
92
99
  const extremums = [axis.min ?? minData, axis.max ?? maxData];
93
100
  const ticksNumber = getTicksNumber(_extends({}, axis, {
94
101
  range
@@ -115,23 +122,27 @@ function CartesianContextProvider({
115
122
  const isDefaultAxis = axisIndex === 0;
116
123
  const [minData, maxData] = getAxisExtremum(axis, yExtremumGetters, isDefaultAxis);
117
124
  const range = [drawingArea.top + drawingArea.height, drawingArea.top];
118
- const scaleType = axis.scaleType ?? 'linear';
119
- if (scaleType === 'band') {
120
- completedYAxis[axis.id] = _extends({}, axis, {
121
- scaleType,
122
- scale: scaleBand(axis.data, range),
125
+ if (isBandScaleConfig(axis)) {
126
+ const categoryGapRatio = axis.categoryGapRatio ?? DEFAULT_CATEGORY_GAP_RATIO;
127
+ completedXAxis[axis.id] = _extends({
128
+ categoryGapRatio,
129
+ barGapRatio: 0
130
+ }, axis, {
131
+ scale: scaleBand(axis.data, range).paddingInner(categoryGapRatio).paddingOuter(categoryGapRatio / 2),
123
132
  ticksNumber: axis.data.length
124
133
  });
125
- return;
126
134
  }
127
- if (scaleType === 'point') {
128
- completedYAxis[axis.id] = _extends({}, axis, {
129
- scaleType,
135
+ if (isPointScaleConfig(axis)) {
136
+ completedXAxis[axis.id] = _extends({}, axis, {
130
137
  scale: scalePoint(axis.data, range),
131
138
  ticksNumber: axis.data.length
132
139
  });
140
+ }
141
+ if (axis.scaleType === 'band' || axis.scaleType === 'point') {
142
+ // Could be merged with the two previous "if conditions" but then TS does not get that `axis.scaleType` can't be `band` or `point`.
133
143
  return;
134
144
  }
145
+ const scaleType = axis.scaleType ?? 'linear';
135
146
  const extremums = [axis.min ?? minData, axis.max ?? maxData];
136
147
  const ticksNumber = getTicksNumber(_extends({}, axis, {
137
148
  range
@@ -4,6 +4,7 @@ import { useTheme } from '@mui/material/styles';
4
4
  import barSeriesFormatter from '../BarChart/formatter';
5
5
  import scatterSeriesFormatter from '../ScatterChart/formatter';
6
6
  import lineSeriesFormatter from '../LineChart/formatter';
7
+ import pieSeriesFormatter from '../PieChart/formatter';
7
8
  import { defaultizeColor } from '../internals/defaultizeColor';
8
9
  import { blueberryTwilightPalette } from '../colorPalettes';
9
10
  import { jsx as _jsx } from "react/jsx-runtime";
@@ -11,8 +12,17 @@ export const SeriesContext = /*#__PURE__*/React.createContext({});
11
12
  const seriesTypeFormatter = {
12
13
  bar: barSeriesFormatter,
13
14
  scatter: scatterSeriesFormatter,
14
- line: lineSeriesFormatter
15
+ line: lineSeriesFormatter,
16
+ pie: pieSeriesFormatter
15
17
  };
18
+ /**
19
+ * This methods is the interface between what the developer is providing and what components receives
20
+ * To simplify the components behaviors, it groups series by type, such that LinePlots props are not updated if some line data are modified
21
+ * It also add defaultized values such as the ids, colors
22
+ * @param series The array of series provided by devs
23
+ * @param colors The color palette used to defaultize series colors
24
+ * @returns An object structuring all the series by type.
25
+ */
16
26
  const formatSeries = (series, colors) => {
17
27
  // Group series by type
18
28
  const seriesGroups = {};
@@ -0,0 +1,2 @@
1
+ export * from './useDrawingArea';
2
+ export * from './useScale';