@mui/x-charts 6.0.0-alpha.0 → 6.0.0-alpha.2

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 (126) hide show
  1. package/BarChart/BarChart.js +8 -5
  2. package/BarChart/legend.d.ts +3 -0
  3. package/BarChart/legend.js +20 -0
  4. package/CHANGELOG.md +136 -8
  5. package/ChartsAxis/ChartsAxis.d.ts +4 -4
  6. package/ChartsAxis/ChartsAxis.js +4 -4
  7. package/ChartsLegend/ChartsLegend.d.ts +5 -1
  8. package/ChartsLegend/ChartsLegend.js +5 -1
  9. package/ChartsLegend/utils.d.ts +1 -1
  10. package/ChartsLegend/utils.js +12 -1
  11. package/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
  12. package/ChartsTooltip/ChartsItemTooltipContent.js +11 -2
  13. package/ChartsTooltip/ChartsTooltipTable.js +8 -8
  14. package/LineChart/LineChart.js +8 -5
  15. package/LineChart/legend.d.ts +3 -0
  16. package/LineChart/legend.js +20 -0
  17. package/PieChart/PieArc.d.ts +36 -0
  18. package/PieChart/PieArc.js +128 -0
  19. package/PieChart/PieArcLabel.d.ts +36 -0
  20. package/PieChart/PieArcLabel.js +113 -0
  21. package/PieChart/PieChart.d.ts +20 -0
  22. package/PieChart/PieChart.js +292 -0
  23. package/PieChart/PiePlot.d.ts +2 -0
  24. package/PieChart/PiePlot.js +98 -0
  25. package/PieChart/formatter.d.ts +3 -0
  26. package/PieChart/formatter.js +49 -0
  27. package/PieChart/index.d.ts +4 -0
  28. package/PieChart/index.js +47 -0
  29. package/PieChart/legend.d.ts +3 -0
  30. package/PieChart/legend.js +19 -0
  31. package/PieChart/package.json +6 -0
  32. package/README.md +30 -2
  33. package/ResponsiveChartContainer/index.js +91 -25
  34. package/ScatterChart/Scatter.js +1 -1
  35. package/ScatterChart/ScatterChart.js +5 -4
  36. package/ScatterChart/legend.d.ts +3 -0
  37. package/ScatterChart/legend.js +20 -0
  38. package/context/SeriesContextProvider.js +11 -1
  39. package/esm/BarChart/BarChart.js +8 -5
  40. package/esm/BarChart/legend.js +13 -0
  41. package/esm/ChartsAxis/ChartsAxis.js +4 -4
  42. package/esm/ChartsLegend/ChartsLegend.js +5 -1
  43. package/esm/ChartsLegend/utils.js +11 -1
  44. package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
  45. package/esm/ChartsTooltip/ChartsItemTooltipContent.js +11 -3
  46. package/esm/ChartsTooltip/ChartsTooltipTable.js +8 -8
  47. package/esm/LineChart/LineChart.js +8 -5
  48. package/esm/LineChart/legend.js +13 -0
  49. package/esm/PieChart/PieArc.js +117 -0
  50. package/esm/PieChart/PieArcLabel.js +101 -0
  51. package/esm/PieChart/PieChart.js +285 -0
  52. package/esm/PieChart/PiePlot.js +92 -0
  53. package/esm/PieChart/formatter.js +48 -0
  54. package/esm/PieChart/index.js +4 -0
  55. package/esm/PieChart/legend.js +12 -0
  56. package/esm/ResponsiveChartContainer/index.js +94 -26
  57. package/esm/ScatterChart/Scatter.js +1 -1
  58. package/esm/ScatterChart/ScatterChart.js +5 -4
  59. package/esm/ScatterChart/legend.js +13 -0
  60. package/esm/context/SeriesContextProvider.js +11 -1
  61. package/esm/index.js +1 -0
  62. package/esm/internals/defaultizeColor.js +7 -0
  63. package/esm/models/seriesType/index.js +1 -8
  64. package/index.d.ts +1 -0
  65. package/index.js +12 -1
  66. package/internals/defaultizeColor.d.ts +35 -0
  67. package/internals/defaultizeColor.js +7 -0
  68. package/legacy/BarChart/BarChart.js +10 -7
  69. package/legacy/BarChart/legend.js +15 -0
  70. package/legacy/ChartsAxis/ChartsAxis.js +4 -4
  71. package/legacy/ChartsLegend/ChartsLegend.js +5 -1
  72. package/legacy/ChartsLegend/utils.js +12 -6
  73. package/legacy/ChartsTooltip/ChartsAxisTooltipContent.js +3 -1
  74. package/legacy/ChartsTooltip/ChartsItemTooltipContent.js +10 -3
  75. package/legacy/ChartsTooltip/ChartsTooltipTable.js +7 -9
  76. package/legacy/LineChart/LineChart.js +10 -7
  77. package/legacy/LineChart/legend.js +15 -0
  78. package/legacy/PieChart/PieArc.js +118 -0
  79. package/legacy/PieChart/PieArcLabel.js +101 -0
  80. package/legacy/PieChart/PieChart.js +297 -0
  81. package/legacy/PieChart/PiePlot.js +89 -0
  82. package/legacy/PieChart/formatter.js +55 -0
  83. package/legacy/PieChart/index.js +4 -0
  84. package/legacy/PieChart/legend.js +16 -0
  85. package/legacy/ResponsiveChartContainer/index.js +89 -26
  86. package/legacy/ScatterChart/Scatter.js +1 -1
  87. package/legacy/ScatterChart/ScatterChart.js +5 -4
  88. package/legacy/ScatterChart/legend.js +15 -0
  89. package/legacy/context/SeriesContextProvider.js +11 -1
  90. package/legacy/index.js +2 -1
  91. package/legacy/internals/defaultizeColor.js +9 -0
  92. package/legacy/models/seriesType/index.js +1 -8
  93. package/models/seriesType/bar.d.ts +1 -1
  94. package/models/seriesType/common.d.ts +1 -1
  95. package/models/seriesType/config.d.ts +29 -2
  96. package/models/seriesType/index.d.ts +7 -3
  97. package/models/seriesType/index.js +11 -0
  98. package/models/seriesType/line.d.ts +1 -1
  99. package/models/seriesType/pie.d.ts +103 -3
  100. package/models/seriesType/scatter.d.ts +1 -1
  101. package/modern/BarChart/BarChart.js +8 -5
  102. package/modern/BarChart/legend.js +13 -0
  103. package/modern/ChartsAxis/ChartsAxis.js +4 -4
  104. package/modern/ChartsLegend/ChartsLegend.js +5 -1
  105. package/modern/ChartsLegend/utils.js +11 -1
  106. package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
  107. package/modern/ChartsTooltip/ChartsItemTooltipContent.js +11 -2
  108. package/modern/ChartsTooltip/ChartsTooltipTable.js +8 -8
  109. package/modern/LineChart/LineChart.js +8 -5
  110. package/modern/LineChart/legend.js +13 -0
  111. package/modern/PieChart/PieArc.js +116 -0
  112. package/modern/PieChart/PieArcLabel.js +101 -0
  113. package/modern/PieChart/PieChart.js +285 -0
  114. package/modern/PieChart/PiePlot.js +91 -0
  115. package/modern/PieChart/formatter.js +41 -0
  116. package/modern/PieChart/index.js +4 -0
  117. package/modern/PieChart/legend.js +12 -0
  118. package/modern/ResponsiveChartContainer/index.js +91 -25
  119. package/modern/ScatterChart/Scatter.js +1 -1
  120. package/modern/ScatterChart/ScatterChart.js +5 -4
  121. package/modern/ScatterChart/legend.js +13 -0
  122. package/modern/context/SeriesContextProvider.js +11 -1
  123. package/modern/index.js +2 -1
  124. package/modern/internals/defaultizeColor.js +7 -0
  125. package/modern/models/seriesType/index.js +1 -8
  126. package/package.json +1 -3
@@ -0,0 +1,116 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
+ const _excluded = ["id", "dataIndex", "classes", "color", "highlightScope", "innerRadius", "outerRadius", "cornerRadius", "highlighted", "faded"];
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, useInteractionItemProps } from '../hooks/useInteractionItemProps';
13
+ import { jsx as _jsx } from "react/jsx-runtime";
14
+ export function getPieArcUtilityClass(slot) {
15
+ return generateUtilityClass('MuiPieArc', slot);
16
+ }
17
+ export const pieArcClasses = generateUtilityClasses('MuiPieArc', ['root', 'highlighted', 'faded']);
18
+ const useUtilityClasses = ownerState => {
19
+ const {
20
+ classes,
21
+ id,
22
+ isFaded,
23
+ isHighlighted
24
+ } = ownerState;
25
+ const slots = {
26
+ root: ['root', `series-${id}`, isHighlighted && 'highlighted', isFaded && 'faded']
27
+ };
28
+ return composeClasses(slots, getPieArcUtilityClass, classes);
29
+ };
30
+ const PieArcRoot = styled('path', {
31
+ name: 'MuiPieArc',
32
+ slot: 'Root',
33
+ overridesResolver: (_, styles) => styles.arc
34
+ })(({
35
+ ownerState,
36
+ theme
37
+ }) => ({
38
+ stroke: theme.palette.background.paper,
39
+ strokeWidth: 1,
40
+ strokeLinejoin: 'round',
41
+ fill: ownerState.color,
42
+ opacity: ownerState.isFaded ? 0.3 : 1
43
+ }));
44
+ export default function PieArc(props) {
45
+ const {
46
+ id,
47
+ dataIndex,
48
+ classes: innerClasses,
49
+ color,
50
+ highlightScope,
51
+ innerRadius: baseInnerRadius = 0,
52
+ outerRadius: baseOuterRadius,
53
+ cornerRadius: baseCornerRadius = 0,
54
+ highlighted,
55
+ faded = {
56
+ additionalRadius: -5
57
+ }
58
+ } = props,
59
+ other = _objectWithoutPropertiesLoose(props, _excluded);
60
+ const getInteractionItemProps = useInteractionItemProps(highlightScope);
61
+ const {
62
+ item
63
+ } = React.useContext(InteractionContext);
64
+ const isHighlighted = getIsHighlighted(item, {
65
+ type: 'pie',
66
+ seriesId: id,
67
+ dataIndex
68
+ }, highlightScope);
69
+ const isFaded = !isHighlighted && getIsFaded(item, {
70
+ type: 'pie',
71
+ seriesId: id,
72
+ dataIndex
73
+ }, highlightScope);
74
+ const ownerState = {
75
+ id,
76
+ dataIndex,
77
+ classes: innerClasses,
78
+ color,
79
+ isFaded,
80
+ isHighlighted
81
+ };
82
+ const classes = useUtilityClasses(ownerState);
83
+ const attibuesOverride = _extends({
84
+ additionalRadius: 0
85
+ }, isFaded && faded || isHighlighted && highlighted || {});
86
+ const innerRadius = Math.max(0, attibuesOverride.innerRadius ?? baseInnerRadius);
87
+ const outerRadius = Math.max(0, attibuesOverride.outerRadius ?? baseOuterRadius + attibuesOverride.additionalRadius);
88
+ const cornerRadius = attibuesOverride.cornerRadius ?? baseCornerRadius;
89
+ return /*#__PURE__*/_jsx(PieArcRoot, _extends({
90
+ d: d3Arc().cornerRadius(cornerRadius)(_extends({}, other, {
91
+ innerRadius,
92
+ outerRadius
93
+ })),
94
+ ownerState: ownerState,
95
+ className: classes.root
96
+ }, getInteractionItemProps({
97
+ type: 'pie',
98
+ seriesId: id,
99
+ dataIndex
100
+ })));
101
+ }
102
+ process.env.NODE_ENV !== "production" ? PieArc.propTypes = {
103
+ // ----------------------------- Warning --------------------------------
104
+ // | These PropTypes are generated from the TypeScript type definitions |
105
+ // | To update them edit the TypeScript types and run "yarn proptypes" |
106
+ // ----------------------------------------------------------------------
107
+ classes: PropTypes.object,
108
+ cornerRadius: PropTypes.number,
109
+ dataIndex: PropTypes.number.isRequired,
110
+ highlightScope: PropTypes.shape({
111
+ faded: PropTypes.oneOf(['global', 'none', 'series']),
112
+ highlighted: PropTypes.oneOf(['item', 'none', 'series'])
113
+ }),
114
+ innerRadius: PropTypes.number,
115
+ outerRadius: PropTypes.number.isRequired
116
+ } : void 0;
@@ -0,0 +1,101 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
+ const _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 const pieArcLabelClasses = generateUtilityClasses('MuiPieArcLabel', ['root', 'highlighted', 'faded']);
18
+ const useUtilityClasses = ownerState => {
19
+ const {
20
+ classes,
21
+ id,
22
+ isFaded,
23
+ isHighlighted
24
+ } = ownerState;
25
+ const slots = {
26
+ root: ['root', `series-${id}`, isHighlighted && 'highlighted', isFaded && 'faded']
27
+ };
28
+ return composeClasses(slots, getPieArcLabelUtilityClass, classes);
29
+ };
30
+ const PieArcLabelRoot = styled('text', {
31
+ name: 'MuiPieArcLabel',
32
+ slot: 'Root',
33
+ overridesResolver: (_, styles) => styles.root
34
+ })(({
35
+ theme
36
+ }) => ({
37
+ fill: theme.palette.text.primary,
38
+ alignmentBaseline: 'baseline',
39
+ textAnchor: 'middle'
40
+ }));
41
+ export default function PieArcLabel(props) {
42
+ const {
43
+ id,
44
+ dataIndex,
45
+ classes: innerClasses,
46
+ color,
47
+ highlightScope,
48
+ innerRadius = 0,
49
+ outerRadius,
50
+ cornerRadius = 0,
51
+ formattedArcLabel
52
+ } = props,
53
+ other = _objectWithoutPropertiesLoose(props, _excluded);
54
+ const {
55
+ item
56
+ } = React.useContext(InteractionContext);
57
+ const isHighlighted = getIsHighlighted(item, {
58
+ type: 'pie',
59
+ seriesId: id,
60
+ dataIndex
61
+ }, highlightScope);
62
+ const isFaded = !isHighlighted && getIsFaded(item, {
63
+ type: 'pie',
64
+ seriesId: id,
65
+ dataIndex
66
+ }, highlightScope);
67
+ const ownerState = {
68
+ id,
69
+ dataIndex,
70
+ classes: innerClasses,
71
+ color,
72
+ isFaded,
73
+ isHighlighted
74
+ };
75
+ const classes = useUtilityClasses(ownerState);
76
+ const arcLabelPosition = formattedArcLabel ? d3Arc().cornerRadius(cornerRadius).centroid(_extends({}, other, {
77
+ innerRadius,
78
+ 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,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;