@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,101 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
3
+ var _excluded = ["id", "dataIndex", "classes", "color", "highlightScope", "innerRadius", "outerRadius", "cornerRadius", "formattedArcLabel"];
4
+ import * as React from 'react';
5
+ import { arc as d3Arc } from 'd3-shape';
6
+ import PropTypes from 'prop-types';
7
+ import composeClasses from '@mui/utils/composeClasses';
8
+ import generateUtilityClass from '@mui/utils/generateUtilityClass';
9
+ import { styled } from '@mui/material/styles';
10
+ import generateUtilityClasses from '@mui/utils/generateUtilityClasses';
11
+ import { InteractionContext } from '../context/InteractionProvider';
12
+ import { getIsFaded, getIsHighlighted } from '../hooks/useInteractionItemProps';
13
+ import { jsx as _jsx } from "react/jsx-runtime";
14
+ export function getPieArcLabelUtilityClass(slot) {
15
+ return generateUtilityClass('MuiPieArcLabel', slot);
16
+ }
17
+ export var pieArcLabelClasses = generateUtilityClasses('MuiPieArcLabel', ['root', 'highlighted', 'faded']);
18
+ var useUtilityClasses = function useUtilityClasses(ownerState) {
19
+ var classes = ownerState.classes,
20
+ id = ownerState.id,
21
+ isFaded = ownerState.isFaded,
22
+ isHighlighted = ownerState.isHighlighted;
23
+ var slots = {
24
+ root: ['root', "series-".concat(id), isHighlighted && 'highlighted', isFaded && 'faded']
25
+ };
26
+ return composeClasses(slots, getPieArcLabelUtilityClass, classes);
27
+ };
28
+ var PieArcLabelRoot = styled('text', {
29
+ name: 'MuiPieArcLabel',
30
+ slot: 'Root',
31
+ overridesResolver: function overridesResolver(_, styles) {
32
+ return styles.root;
33
+ }
34
+ })(function (_ref) {
35
+ var theme = _ref.theme;
36
+ return {
37
+ fill: theme.palette.text.primary,
38
+ alignmentBaseline: 'baseline',
39
+ textAnchor: 'middle'
40
+ };
41
+ });
42
+ export default function PieArcLabel(props) {
43
+ var id = props.id,
44
+ dataIndex = props.dataIndex,
45
+ innerClasses = props.classes,
46
+ color = props.color,
47
+ highlightScope = props.highlightScope,
48
+ _props$innerRadius = props.innerRadius,
49
+ innerRadius = _props$innerRadius === void 0 ? 0 : _props$innerRadius,
50
+ outerRadius = props.outerRadius,
51
+ _props$cornerRadius = props.cornerRadius,
52
+ cornerRadius = _props$cornerRadius === void 0 ? 0 : _props$cornerRadius,
53
+ formattedArcLabel = props.formattedArcLabel,
54
+ other = _objectWithoutProperties(props, _excluded);
55
+ var _React$useContext = React.useContext(InteractionContext),
56
+ item = _React$useContext.item;
57
+ var isHighlighted = getIsHighlighted(item, {
58
+ type: 'pie',
59
+ seriesId: id,
60
+ dataIndex: dataIndex
61
+ }, highlightScope);
62
+ var isFaded = !isHighlighted && getIsFaded(item, {
63
+ type: 'pie',
64
+ seriesId: id,
65
+ dataIndex: dataIndex
66
+ }, highlightScope);
67
+ var ownerState = {
68
+ id: id,
69
+ dataIndex: dataIndex,
70
+ classes: innerClasses,
71
+ color: color,
72
+ isFaded: isFaded,
73
+ isHighlighted: isHighlighted
74
+ };
75
+ var classes = useUtilityClasses(ownerState);
76
+ var arcLabelPosition = formattedArcLabel ? d3Arc().cornerRadius(cornerRadius).centroid(_extends({}, other, {
77
+ innerRadius: innerRadius,
78
+ outerRadius: outerRadius
79
+ })) : [0, 0];
80
+ return /*#__PURE__*/_jsx(PieArcLabelRoot, {
81
+ className: classes.root,
82
+ x: arcLabelPosition[0],
83
+ y: arcLabelPosition[1],
84
+ children: formattedArcLabel
85
+ });
86
+ }
87
+ process.env.NODE_ENV !== "production" ? PieArcLabel.propTypes = {
88
+ // ----------------------------- Warning --------------------------------
89
+ // | These PropTypes are generated from the TypeScript type definitions |
90
+ // | To update them edit the TypeScript types and run "yarn proptypes" |
91
+ // ----------------------------------------------------------------------
92
+ classes: PropTypes.object,
93
+ cornerRadius: PropTypes.number,
94
+ dataIndex: PropTypes.number.isRequired,
95
+ highlightScope: PropTypes.shape({
96
+ faded: PropTypes.oneOf(['global', 'none', 'series']),
97
+ highlighted: PropTypes.oneOf(['item', 'none', 'series'])
98
+ }),
99
+ innerRadius: PropTypes.number,
100
+ outerRadius: PropTypes.number.isRequired
101
+ } : void 0;
@@ -0,0 +1,297 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
+ import _extends from "@babel/runtime/helpers/esm/extends";
3
+ import * as React from 'react';
4
+ import PropTypes from 'prop-types';
5
+ import { ResponsiveChartContainer } from '../ResponsiveChartContainer';
6
+ import { ChartsAxis } from '../ChartsAxis/ChartsAxis';
7
+ import { DEFAULT_X_AXIS_KEY } from '../constants';
8
+ import { ChartsTooltip } from '../ChartsTooltip';
9
+ import { ChartsLegend } from '../ChartsLegend';
10
+ import { ChartsAxisHighlight } from '../ChartsAxisHighlight';
11
+ import { PiePlot } from './PiePlot';
12
+ import { jsx as _jsx } from "react/jsx-runtime";
13
+ import { jsxs as _jsxs } from "react/jsx-runtime";
14
+ var defaultMargin = {
15
+ top: 5,
16
+ bottom: 5,
17
+ left: 5,
18
+ right: 100
19
+ };
20
+ function PieChart(props) {
21
+ var xAxis = props.xAxis,
22
+ yAxis = props.yAxis,
23
+ series = props.series,
24
+ width = props.width,
25
+ height = props.height,
26
+ marginProps = props.margin,
27
+ colors = props.colors,
28
+ sx = props.sx,
29
+ _props$tooltip = props.tooltip,
30
+ tooltip = _props$tooltip === void 0 ? {
31
+ trigger: 'item'
32
+ } : _props$tooltip,
33
+ _props$axisHighlight = props.axisHighlight,
34
+ axisHighlight = _props$axisHighlight === void 0 ? {
35
+ x: 'none',
36
+ y: 'none'
37
+ } : _props$axisHighlight,
38
+ _props$legend = props.legend,
39
+ legend = _props$legend === void 0 ? {
40
+ direction: 'column',
41
+ position: {
42
+ vertical: 'middle',
43
+ horizontal: 'right'
44
+ }
45
+ } : _props$legend,
46
+ _props$topAxis = props.topAxis,
47
+ topAxis = _props$topAxis === void 0 ? null : _props$topAxis,
48
+ _props$leftAxis = props.leftAxis,
49
+ leftAxis = _props$leftAxis === void 0 ? null : _props$leftAxis,
50
+ _props$rightAxis = props.rightAxis,
51
+ rightAxis = _props$rightAxis === void 0 ? null : _props$rightAxis,
52
+ _props$bottomAxis = props.bottomAxis,
53
+ bottomAxis = _props$bottomAxis === void 0 ? null : _props$bottomAxis,
54
+ children = props.children;
55
+ var margin = _extends({}, defaultMargin, marginProps);
56
+ return /*#__PURE__*/_jsxs(ResponsiveChartContainer, {
57
+ series: series.map(function (s) {
58
+ return _extends({
59
+ type: 'pie'
60
+ }, s);
61
+ }),
62
+ width: width,
63
+ height: height,
64
+ margin: margin,
65
+ xAxis: xAxis != null ? xAxis : [{
66
+ id: DEFAULT_X_AXIS_KEY,
67
+ scaleType: 'point',
68
+ data: _toConsumableArray(new Array(Math.max.apply(Math, _toConsumableArray(series.map(function (s) {
69
+ return s.data.length;
70
+ }))))).map(function (_, index) {
71
+ return index;
72
+ })
73
+ }],
74
+ yAxis: yAxis,
75
+ colors: colors,
76
+ sx: sx,
77
+ disableAxisListener: (tooltip == null ? void 0 : tooltip.trigger) !== 'axis' && (axisHighlight == null ? void 0 : axisHighlight.x) === 'none' && (axisHighlight == null ? void 0 : axisHighlight.y) === 'none',
78
+ children: [/*#__PURE__*/_jsx(ChartsAxis, {
79
+ topAxis: topAxis,
80
+ leftAxis: leftAxis,
81
+ rightAxis: rightAxis,
82
+ bottomAxis: bottomAxis
83
+ }), /*#__PURE__*/_jsx(PiePlot, {}), /*#__PURE__*/_jsx(ChartsLegend, _extends({}, legend)), /*#__PURE__*/_jsx(ChartsAxisHighlight, _extends({}, axisHighlight)), /*#__PURE__*/_jsx(ChartsTooltip, _extends({}, tooltip)), children]
84
+ });
85
+ }
86
+ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
87
+ // ----------------------------- Warning --------------------------------
88
+ // | These PropTypes are generated from the TypeScript type definitions |
89
+ // | To update them edit the TypeScript types and run "yarn proptypes" |
90
+ // ----------------------------------------------------------------------
91
+ axisHighlight: PropTypes.shape({
92
+ x: PropTypes.oneOf(['band', 'line', 'none']),
93
+ y: PropTypes.oneOf(['line', 'none'])
94
+ }),
95
+ /**
96
+ * Indicate which axis to display the bottom of the charts.
97
+ * Can be a string (the id of the axis) or an object `ChartsXAxisProps`
98
+ * @default xAxisIds[0] The id of the first provided axis
99
+ */
100
+ bottomAxis: PropTypes.oneOfType([PropTypes.shape({
101
+ axisId: PropTypes.string.isRequired,
102
+ classes: PropTypes.object,
103
+ disableLine: PropTypes.bool,
104
+ disableTicks: PropTypes.bool,
105
+ fill: PropTypes.string,
106
+ label: PropTypes.string,
107
+ labelFontSize: PropTypes.number,
108
+ position: PropTypes.oneOf(['bottom', 'top']),
109
+ stroke: PropTypes.string,
110
+ tickFontSize: PropTypes.number,
111
+ tickSize: PropTypes.number
112
+ }), PropTypes.string]),
113
+ children: PropTypes.node,
114
+ className: PropTypes.string,
115
+ /**
116
+ * Color palette used to colorize multiple series.
117
+ */
118
+ colors: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string), PropTypes.func]),
119
+ desc: PropTypes.string,
120
+ disableAxisListener: PropTypes.bool,
121
+ height: PropTypes.number,
122
+ /**
123
+ * Indicate which axis to display the left of the charts.
124
+ * Can be a string (the id of the axis) or an object `ChartsYAxisProps`
125
+ * @default yAxisIds[0] The id of the first provided axis
126
+ */
127
+ leftAxis: PropTypes.oneOfType([PropTypes.shape({
128
+ axisId: PropTypes.string.isRequired,
129
+ classes: PropTypes.object,
130
+ disableLine: PropTypes.bool,
131
+ disableTicks: PropTypes.bool,
132
+ fill: PropTypes.string,
133
+ label: PropTypes.string,
134
+ labelFontSize: PropTypes.number,
135
+ position: PropTypes.oneOf(['left', 'right']),
136
+ stroke: PropTypes.string,
137
+ tickFontSize: PropTypes.number,
138
+ tickSize: PropTypes.number
139
+ }), PropTypes.string]),
140
+ legend: PropTypes.shape({
141
+ classes: PropTypes.object,
142
+ direction: PropTypes.oneOf(['column', 'row']),
143
+ hidden: PropTypes.bool,
144
+ itemWidth: PropTypes.number,
145
+ markSize: PropTypes.number,
146
+ offset: PropTypes.shape({
147
+ x: PropTypes.number,
148
+ y: PropTypes.number
149
+ }),
150
+ position: PropTypes.shape({
151
+ horizontal: PropTypes.oneOf(['left', 'middle', 'right']).isRequired,
152
+ vertical: PropTypes.oneOf(['bottom', 'middle', 'top']).isRequired
153
+ }),
154
+ spacing: PropTypes.number
155
+ }),
156
+ margin: PropTypes.shape({
157
+ bottom: PropTypes.number,
158
+ left: PropTypes.number,
159
+ right: PropTypes.number,
160
+ top: PropTypes.number
161
+ }),
162
+ /**
163
+ * Indicate which axis to display the right of the charts.
164
+ * Can be a string (the id of the axis) or an object `ChartsYAxisProps`
165
+ * @default null
166
+ */
167
+ rightAxis: PropTypes.oneOfType([PropTypes.shape({
168
+ axisId: PropTypes.string.isRequired,
169
+ classes: PropTypes.object,
170
+ disableLine: PropTypes.bool,
171
+ disableTicks: PropTypes.bool,
172
+ fill: PropTypes.string,
173
+ label: PropTypes.string,
174
+ labelFontSize: PropTypes.number,
175
+ position: PropTypes.oneOf(['left', 'right']),
176
+ stroke: PropTypes.string,
177
+ tickFontSize: PropTypes.number,
178
+ tickSize: PropTypes.number
179
+ }), PropTypes.string]),
180
+ series: PropTypes.arrayOf(PropTypes.shape({
181
+ arcLabel: PropTypes.oneOfType([PropTypes.oneOf(['formattedValue', 'label', 'value']), PropTypes.func]),
182
+ arcLabelMinAngle: PropTypes.number,
183
+ color: PropTypes.string,
184
+ cornerRadius: PropTypes.number,
185
+ cx: PropTypes.number,
186
+ cy: PropTypes.number,
187
+ data: PropTypes.arrayOf(PropTypes.shape({
188
+ color: PropTypes.string,
189
+ id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
190
+ label: PropTypes.string,
191
+ value: PropTypes.number.isRequired
192
+ })).isRequired,
193
+ endAngle: PropTypes.number,
194
+ faded: PropTypes.shape({
195
+ additionalRadius: PropTypes.number,
196
+ cornerRadius: PropTypes.number,
197
+ innerRadius: PropTypes.number,
198
+ outerRadius: PropTypes.number
199
+ }),
200
+ highlighted: PropTypes.shape({
201
+ additionalRadius: PropTypes.number,
202
+ cornerRadius: PropTypes.number,
203
+ innerRadius: PropTypes.number,
204
+ outerRadius: PropTypes.number
205
+ }),
206
+ highlightScope: PropTypes.shape({
207
+ faded: PropTypes.oneOf(['global', 'none', 'series']),
208
+ highlighted: PropTypes.oneOf(['item', 'none', 'series'])
209
+ }),
210
+ id: PropTypes.string,
211
+ innerRadius: PropTypes.number,
212
+ outerRadius: PropTypes.number,
213
+ paddingAngle: PropTypes.number,
214
+ sortingValues: PropTypes.oneOfType([PropTypes.oneOf(['asc', 'desc', 'none']), PropTypes.func]),
215
+ startAngle: PropTypes.number,
216
+ type: PropTypes.oneOf(['pie']),
217
+ valueFormatter: PropTypes.func
218
+ })).isRequired,
219
+ sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
220
+ title: PropTypes.string,
221
+ tooltip: PropTypes.shape({
222
+ axisContent: PropTypes.elementType,
223
+ classes: PropTypes.object,
224
+ itemContent: PropTypes.elementType,
225
+ trigger: PropTypes.oneOf(['axis', 'item', 'none'])
226
+ }),
227
+ /**
228
+ * Indicate which axis to display the top of the charts.
229
+ * Can be a string (the id of the axis) or an object `ChartsXAxisProps`
230
+ * @default null
231
+ */
232
+ topAxis: PropTypes.oneOfType([PropTypes.shape({
233
+ axisId: PropTypes.string.isRequired,
234
+ classes: PropTypes.object,
235
+ disableLine: PropTypes.bool,
236
+ disableTicks: PropTypes.bool,
237
+ fill: PropTypes.string,
238
+ label: PropTypes.string,
239
+ labelFontSize: PropTypes.number,
240
+ position: PropTypes.oneOf(['bottom', 'top']),
241
+ stroke: PropTypes.string,
242
+ tickFontSize: PropTypes.number,
243
+ tickSize: PropTypes.number
244
+ }), PropTypes.string]),
245
+ viewBox: PropTypes.shape({
246
+ height: PropTypes.number,
247
+ width: PropTypes.number,
248
+ x: PropTypes.number,
249
+ y: PropTypes.number
250
+ }),
251
+ width: PropTypes.number,
252
+ xAxis: PropTypes.arrayOf(PropTypes.shape({
253
+ axisId: PropTypes.string,
254
+ classes: PropTypes.object,
255
+ data: PropTypes.array,
256
+ disableLine: PropTypes.bool,
257
+ disableTicks: PropTypes.bool,
258
+ fill: PropTypes.string,
259
+ id: PropTypes.string,
260
+ label: PropTypes.string,
261
+ labelFontSize: PropTypes.number,
262
+ max: PropTypes.number,
263
+ maxTicks: PropTypes.number,
264
+ min: PropTypes.number,
265
+ minTicks: PropTypes.number,
266
+ position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
267
+ scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
268
+ stroke: PropTypes.string,
269
+ tickFontSize: PropTypes.number,
270
+ tickSize: PropTypes.number,
271
+ tickSpacing: PropTypes.number,
272
+ valueFormatter: PropTypes.func
273
+ })),
274
+ yAxis: PropTypes.arrayOf(PropTypes.shape({
275
+ axisId: PropTypes.string,
276
+ classes: PropTypes.object,
277
+ data: PropTypes.array,
278
+ disableLine: PropTypes.bool,
279
+ disableTicks: PropTypes.bool,
280
+ fill: PropTypes.string,
281
+ id: PropTypes.string,
282
+ label: PropTypes.string,
283
+ labelFontSize: PropTypes.number,
284
+ max: PropTypes.number,
285
+ maxTicks: PropTypes.number,
286
+ min: PropTypes.number,
287
+ minTicks: PropTypes.number,
288
+ position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
289
+ scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
290
+ stroke: PropTypes.string,
291
+ tickFontSize: PropTypes.number,
292
+ tickSize: PropTypes.number,
293
+ tickSpacing: PropTypes.number,
294
+ valueFormatter: PropTypes.func
295
+ }))
296
+ } : void 0;
297
+ export { PieChart };
@@ -0,0 +1,89 @@
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
+ var RATIO = 180 / Math.PI;
11
+ function getItemLabel(arcLabel, arcLabelMinAngle, item) {
12
+ if (!arcLabel) {
13
+ return null;
14
+ }
15
+ var angle = (item.endAngle - item.startAngle) * RATIO;
16
+ if (angle < arcLabelMinAngle) {
17
+ return null;
18
+ }
19
+ if (typeof arcLabel === 'string') {
20
+ var _item$arcLabel;
21
+ return (_item$arcLabel = item[arcLabel]) == null ? void 0 : _item$arcLabel.toString();
22
+ }
23
+ return arcLabel(item);
24
+ }
25
+ export function PiePlot() {
26
+ var seriesData = React.useContext(SeriesContext).pie;
27
+ var _React$useContext = React.useContext(DrawingContext),
28
+ left = _React$useContext.left,
29
+ top = _React$useContext.top,
30
+ width = _React$useContext.width,
31
+ height = _React$useContext.height;
32
+ if (seriesData === undefined) {
33
+ return null;
34
+ }
35
+ var availableRadius = Math.min(width, height) / 2;
36
+ var center = {
37
+ x: left + width / 2,
38
+ y: top + height / 2
39
+ };
40
+ var series = seriesData.series,
41
+ seriesOrder = seriesData.seriesOrder;
42
+ return /*#__PURE__*/_jsx("g", {
43
+ children: seriesOrder.map(function (seriesId) {
44
+ var _series$seriesId = series[seriesId],
45
+ innerRadius = _series$seriesId.innerRadius,
46
+ outerRadius = _series$seriesId.outerRadius,
47
+ cornerRadius = _series$seriesId.cornerRadius,
48
+ arcLabel = _series$seriesId.arcLabel,
49
+ _series$seriesId$arcL = _series$seriesId.arcLabelMinAngle,
50
+ arcLabelMinAngle = _series$seriesId$arcL === void 0 ? 0 : _series$seriesId$arcL,
51
+ data = _series$seriesId.data,
52
+ cx = _series$seriesId.cx,
53
+ cy = _series$seriesId.cy,
54
+ highlighted = _series$seriesId.highlighted,
55
+ faded = _series$seriesId.faded;
56
+ return /*#__PURE__*/_jsx("g", {
57
+ transform: "translate(".concat(cx === undefined ? center.x : left + cx, ", ").concat(cy === undefined ? center.y : top + cy, ")"),
58
+ children: /*#__PURE__*/_jsxs("g", {
59
+ children: [data.map(function (item, index) {
60
+ return /*#__PURE__*/_createElement(PieArc, _extends({}, item, {
61
+ key: item.id,
62
+ innerRadius: innerRadius,
63
+ outerRadius: outerRadius != null ? outerRadius : availableRadius,
64
+ cornerRadius: cornerRadius,
65
+ id: seriesId,
66
+ color: item.color,
67
+ dataIndex: index,
68
+ highlightScope: series[seriesId].highlightScope,
69
+ highlighted: highlighted,
70
+ faded: faded
71
+ }));
72
+ }), data.map(function (item, index) {
73
+ return /*#__PURE__*/_createElement(PieArcLabel, _extends({}, item, {
74
+ key: item.id,
75
+ innerRadius: innerRadius,
76
+ outerRadius: outerRadius != null ? outerRadius : availableRadius,
77
+ cornerRadius: cornerRadius,
78
+ id: seriesId,
79
+ color: item.color,
80
+ dataIndex: index,
81
+ highlightScope: series[seriesId].highlightScope,
82
+ formattedArcLabel: getItemLabel(arcLabel, arcLabelMinAngle, item)
83
+ }));
84
+ })]
85
+ })
86
+ }, seriesId);
87
+ })
88
+ });
89
+ }
@@ -0,0 +1,55 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import { pie as d3Pie } from 'd3-shape';
3
+ var getSortingComparator = function getSortingComparator() {
4
+ var comparator = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'none';
5
+ if (typeof comparator === 'function') {
6
+ return comparator;
7
+ }
8
+ switch (comparator) {
9
+ case 'none':
10
+ return null;
11
+ case 'desc':
12
+ return function (a, b) {
13
+ return b - a;
14
+ };
15
+ case 'asc':
16
+ return function (a, b) {
17
+ return a - b;
18
+ };
19
+ default:
20
+ return null;
21
+ }
22
+ };
23
+ var formatter = function formatter(params) {
24
+ var seriesOrder = params.seriesOrder,
25
+ series = params.series;
26
+ var defaultizedSeries = {};
27
+ seriesOrder.forEach(function (seriesId) {
28
+ var _series$seriesId$star, _series$seriesId$endA, _series$seriesId$padd, _series$seriesId$sort;
29
+ var arcs = d3Pie().startAngle(2 * Math.PI * ((_series$seriesId$star = series[seriesId].startAngle) != null ? _series$seriesId$star : 0) / 360).endAngle(2 * Math.PI * ((_series$seriesId$endA = series[seriesId].endAngle) != null ? _series$seriesId$endA : 360) / 360).padAngle(2 * Math.PI * ((_series$seriesId$padd = series[seriesId].paddingAngle) != null ? _series$seriesId$padd : 0) / 360).sortValues(getSortingComparator((_series$seriesId$sort = series[seriesId].sortingValues) != null ? _series$seriesId$sort : 'none'))(series[seriesId].data.map(function (piePoint) {
30
+ return piePoint.value;
31
+ }));
32
+ defaultizedSeries[seriesId] = _extends({
33
+ valueFormatter: function valueFormatter(item) {
34
+ return item.value.toLocaleString();
35
+ }
36
+ }, series[seriesId], {
37
+ data: series[seriesId].data.map(function (item, index) {
38
+ var _item$id;
39
+ return _extends({}, item, {
40
+ id: (_item$id = item.id) != null ? _item$id : "auto-generated-pie-id-".concat(seriesId, "-").concat(index)
41
+ }, arcs[index]);
42
+ }).map(function (item) {
43
+ var _series$seriesId$valu, _series$seriesId$valu2, _series$seriesId;
44
+ return _extends({}, item, {
45
+ formattedValue: (_series$seriesId$valu = (_series$seriesId$valu2 = (_series$seriesId = series[seriesId]).valueFormatter) == null ? void 0 : _series$seriesId$valu2.call(_series$seriesId, item)) != null ? _series$seriesId$valu : item.value.toLocaleString()
46
+ });
47
+ })
48
+ });
49
+ });
50
+ return {
51
+ seriesOrder: seriesOrder,
52
+ series: defaultizedSeries
53
+ };
54
+ };
55
+ 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,16 @@
1
+ var legendGetter = function legendGetter(params) {
2
+ var seriesOrder = params.seriesOrder,
3
+ series = params.series;
4
+ return seriesOrder.flatMap(function (seriesId) {
5
+ return series[seriesId].data.map(function (item) {
6
+ return {
7
+ color: item.color,
8
+ label: item.label,
9
+ id: item.id
10
+ };
11
+ }).filter(function (item) {
12
+ return item.label !== undefined;
13
+ });
14
+ });
15
+ };
16
+ export default legendGetter;
@@ -1,5 +1,7 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
2
3
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
4
+ var _excluded = ["width", "height"];
3
5
  import * as React from 'react';
4
6
  import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
5
7
  import ownerWindow from '@mui/utils/ownerWindow';
@@ -90,11 +92,18 @@ var ResizableContainer = styled('div', {
90
92
  flexDirection: 'column',
91
93
  alignItems: 'center',
92
94
  justifyContent: 'center',
93
- overflow: 'hidden'
95
+ overflow: 'hidden',
96
+ '&>svg': {
97
+ width: '100%',
98
+ height: '100%'
99
+ }
94
100
  };
95
101
  });
96
- export function ResponsiveChartContainer(props) {
97
- var _useChartDimensions = useChartDimensions(props.width, props.height),
102
+ export var ResponsiveChartContainer = /*#__PURE__*/React.forwardRef(function ResponsiveChartContainer(props, ref) {
103
+ var inWidth = props.width,
104
+ inHeight = props.height,
105
+ other = _objectWithoutProperties(props, _excluded);
106
+ var _useChartDimensions = useChartDimensions(inWidth, inHeight),
98
107
  _useChartDimensions2 = _slicedToArray(_useChartDimensions, 3),
99
108
  containerRef = _useChartDimensions2[0],
100
109
  width = _useChartDimensions2[1],
@@ -102,12 +111,13 @@ export function ResponsiveChartContainer(props) {
102
111
  return /*#__PURE__*/_jsx(ResizableContainer, {
103
112
  ref: containerRef,
104
113
  ownerState: {
105
- width: props.width,
106
- height: props.height
114
+ width: inWidth,
115
+ height: inHeight
107
116
  },
108
- children: /*#__PURE__*/_jsx(ChartContainer, _extends({}, props, {
117
+ children: /*#__PURE__*/_jsx(ChartContainer, _extends({}, other, {
109
118
  width: width,
110
- height: height
119
+ height: height,
120
+ ref: ref
111
121
  }))
112
122
  });
113
- }
123
+ });
@@ -79,7 +79,7 @@ process.env.NODE_ENV !== "production" ? Scatter.propTypes = {
79
79
  color: PropTypes.string.isRequired,
80
80
  markerSize: PropTypes.number.isRequired,
81
81
  series: PropTypes.shape({
82
- color: PropTypes.string.isRequired,
82
+ color: PropTypes.string,
83
83
  data: PropTypes.arrayOf(PropTypes.shape({
84
84
  id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
85
85
  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
+ var ScatterChart = /*#__PURE__*/React.forwardRef(function ScatterChart(props, ref) {
13
13
  var xAxis = props.xAxis,
14
14
  yAxis = props.yAxis,
15
15
  series = props.series,
@@ -27,6 +27,7 @@ function ScatterChart(props) {
27
27
  bottomAxis = props.bottomAxis,
28
28
  children = props.children;
29
29
  return /*#__PURE__*/_jsxs(ResponsiveChartContainer, {
30
+ ref: ref,
30
31
  series: series.map(function (s) {
31
32
  return _extends({
32
33
  type: 'scatter'
@@ -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,15 @@
1
+ var legendGetter = function legendGetter(params) {
2
+ var seriesOrder = params.seriesOrder,
3
+ series = params.series;
4
+ var data = seriesOrder.map(function (seriesId) {
5
+ return {
6
+ color: series[seriesId].color,
7
+ label: series[seriesId].label,
8
+ id: seriesId
9
+ };
10
+ });
11
+ return data.filter(function (item) {
12
+ return item.label !== undefined;
13
+ });
14
+ };
15
+ export default legendGetter;