@mui/x-charts 6.0.0-alpha.13 → 6.0.0-alpha.15
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.
- package/BarChart/BarChart.d.ts +6 -3
- package/BarChart/BarChart.js +7 -10
- package/BarChart/BarElement.js +2 -4
- package/BarChart/formatter.js +1 -2
- package/BarChart/legend.js +1 -2
- package/CHANGELOG.md +165 -1
- package/ChartContainer/index.js +2 -3
- package/ChartsAxis/axisClasses.js +1 -2
- package/ChartsLegend/ChartsLegend.d.ts +43 -24
- package/ChartsLegend/ChartsLegend.js +186 -148
- package/ChartsLegend/chartsLegendClasses.js +1 -2
- package/ChartsLegend/utils.d.ts +1 -6
- package/ChartsSurface.js +5 -14
- package/ChartsTooltip/ChartsAxisTooltipContent.d.ts +1 -0
- package/ChartsTooltip/ChartsAxisTooltipContent.js +17 -8
- package/ChartsTooltip/ChartsItemTooltipContent.d.ts +3 -2
- package/ChartsTooltip/ChartsItemTooltipContent.js +16 -6
- package/ChartsTooltip/ChartsTooltip.d.ts +23 -0
- package/ChartsTooltip/ChartsTooltip.js +47 -13
- package/ChartsTooltip/ChartsTooltipTable.js +6 -11
- package/ChartsTooltip/tooltipClasses.js +1 -2
- package/ChartsXAxis/ChartsXAxis.js +48 -25
- package/ChartsYAxis/ChartsYAxis.js +47 -26
- package/LineChart/AreaElement.js +2 -4
- package/LineChart/LineChart.d.ts +6 -3
- package/LineChart/LineChart.js +11 -11
- package/LineChart/LineElement.js +2 -4
- package/LineChart/LineHighlightElement.js +1 -2
- package/LineChart/MarkElement.js +1 -2
- package/LineChart/formatter.js +1 -2
- package/LineChart/legend.js +1 -2
- package/PieChart/PieArc.d.ts +1 -0
- package/PieChart/PieArc.js +6 -4
- package/PieChart/PieArcLabel.js +1 -2
- package/PieChart/PieChart.d.ts +8 -4
- package/PieChart/PieChart.js +11 -10
- package/PieChart/PiePlot.d.ts +8 -0
- package/PieChart/PiePlot.js +21 -5
- package/PieChart/formatter.js +1 -2
- package/PieChart/legend.js +1 -2
- package/ResponsiveChartContainer/index.js +2 -3
- package/ScatterChart/ScatterChart.d.ts +6 -3
- package/ScatterChart/ScatterChart.js +7 -10
- package/ScatterChart/formatter.js +1 -2
- package/ScatterChart/legend.js +1 -2
- package/SparkLineChart/SparkLineChart.d.ts +3 -3
- package/SparkLineChart/SparkLineChart.js +7 -3
- package/colorPalettes/colorPalettes.js +6 -12
- package/constants.js +5 -8
- package/context/CartesianContextProvider.js +11 -12
- package/context/DrawingProvider.d.ts +2 -0
- package/context/DrawingProvider.js +4 -4
- package/context/HighlightProvider.js +1 -2
- package/context/InteractionProvider.js +1 -2
- package/context/SeriesContextProvider.js +1 -2
- package/esm/BarChart/BarChart.js +6 -8
- package/esm/ChartsLegend/ChartsLegend.js +184 -142
- package/esm/ChartsSurface.js +3 -11
- package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +17 -8
- package/esm/ChartsTooltip/ChartsItemTooltipContent.js +15 -6
- package/esm/ChartsTooltip/ChartsTooltip.js +47 -12
- package/esm/ChartsXAxis/ChartsXAxis.js +47 -24
- package/esm/ChartsYAxis/ChartsYAxis.js +46 -25
- package/esm/LineChart/LineChart.js +10 -9
- package/esm/PieChart/PieArc.js +5 -2
- package/esm/PieChart/PieChart.js +11 -10
- package/esm/PieChart/PiePlot.js +17 -2
- package/esm/ScatterChart/ScatterChart.js +6 -8
- package/esm/SparkLineChart/SparkLineChart.js +6 -1
- package/esm/constants.js +1 -1
- package/esm/context/CartesianContextProvider.js +11 -11
- package/esm/context/DrawingProvider.js +2 -0
- package/esm/hooks/useChartDimensions.js +2 -0
- package/esm/hooks/useTicks.js +5 -5
- package/esm/internals/components/AxisSharedComponents.js +15 -70
- package/esm/internals/components/ChartsText.js +71 -0
- package/esm/internals/domUtils.js +113 -0
- package/hooks/useChartDimensions.d.ts +2 -0
- package/hooks/useChartDimensions.js +3 -2
- package/hooks/useTicks.d.ts +2 -3
- package/hooks/useTicks.js +7 -8
- package/index.js +1 -1
- package/internals/components/AxisSharedComponents.d.ts +0 -4
- package/internals/components/AxisSharedComponents.js +18 -78
- package/internals/components/ChartsText.d.ts +32 -0
- package/internals/components/ChartsText.js +81 -0
- package/internals/defaultizeValueFormatter.js +1 -2
- package/internals/domUtils.d.ts +14 -0
- package/internals/domUtils.js +122 -0
- package/internals/stackSeries.js +2 -4
- package/legacy/BarChart/BarChart.js +6 -8
- package/legacy/ChartsLegend/ChartsLegend.js +196 -140
- package/legacy/ChartsSurface.js +2 -11
- package/legacy/ChartsTooltip/ChartsAxisTooltipContent.js +17 -8
- package/legacy/ChartsTooltip/ChartsItemTooltipContent.js +15 -6
- package/legacy/ChartsTooltip/ChartsTooltip.js +50 -12
- package/legacy/ChartsXAxis/ChartsXAxis.js +47 -24
- package/legacy/ChartsYAxis/ChartsYAxis.js +46 -25
- package/legacy/LineChart/LineChart.js +10 -9
- package/legacy/PieChart/PieArc.js +4 -1
- package/legacy/PieChart/PieChart.js +11 -10
- package/legacy/PieChart/PiePlot.js +17 -2
- package/legacy/ScatterChart/ScatterChart.js +6 -8
- package/legacy/SparkLineChart/SparkLineChart.js +6 -1
- package/legacy/constants.js +1 -1
- package/legacy/context/CartesianContextProvider.js +11 -11
- package/legacy/context/DrawingProvider.js +2 -0
- package/legacy/hooks/useChartDimensions.js +2 -0
- package/legacy/hooks/useTicks.js +5 -5
- package/legacy/index.js +1 -1
- package/legacy/internals/components/AxisSharedComponents.js +9 -63
- package/legacy/internals/components/ChartsText.js +77 -0
- package/legacy/internals/domUtils.js +121 -0
- package/models/axis.d.ts +6 -5
- package/models/layout.d.ts +7 -6
- package/modern/BarChart/BarChart.js +6 -8
- package/modern/ChartsLegend/ChartsLegend.js +184 -142
- package/modern/ChartsSurface.js +3 -11
- package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +17 -8
- package/modern/ChartsTooltip/ChartsItemTooltipContent.js +15 -6
- package/modern/ChartsTooltip/ChartsTooltip.js +46 -12
- package/modern/ChartsXAxis/ChartsXAxis.js +47 -24
- package/modern/ChartsYAxis/ChartsYAxis.js +46 -25
- package/modern/LineChart/LineChart.js +10 -9
- package/modern/PieChart/PieArc.js +5 -2
- package/modern/PieChart/PieChart.js +11 -10
- package/modern/PieChart/PiePlot.js +17 -2
- package/modern/ScatterChart/ScatterChart.js +6 -8
- package/modern/SparkLineChart/SparkLineChart.js +6 -1
- package/modern/constants.js +1 -1
- package/modern/context/CartesianContextProvider.js +11 -11
- package/modern/context/DrawingProvider.js +2 -0
- package/modern/hooks/useChartDimensions.js +2 -0
- package/modern/hooks/useTicks.js +5 -5
- package/modern/index.js +1 -1
- package/modern/internals/components/AxisSharedComponents.js +15 -70
- package/modern/internals/components/ChartsText.js +71 -0
- package/modern/internals/domUtils.js +113 -0
- package/package.json +3 -3
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
2
2
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
3
|
-
const _excluded = ["scale", "
|
|
3
|
+
const _excluded = ["scale", "tickNumber"];
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import PropTypes from 'prop-types';
|
|
6
|
+
import { useSlotProps } from '@mui/base/utils';
|
|
6
7
|
import { unstable_composeClasses as composeClasses } from '@mui/utils';
|
|
7
8
|
import { useThemeProps, useTheme } from '@mui/material/styles';
|
|
8
9
|
import { CartesianContext } from '../context/CartesianContextProvider';
|
|
9
10
|
import { DrawingContext } from '../context/DrawingProvider';
|
|
10
11
|
import useTicks from '../hooks/useTicks';
|
|
11
12
|
import { getAxisUtilityClass } from '../ChartsAxis/axisClasses';
|
|
12
|
-
import {
|
|
13
|
+
import { AxisRoot } from '../internals/components/AxisSharedComponents';
|
|
14
|
+
import { ChartsText } from '../internals/components/ChartsText';
|
|
13
15
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
16
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
15
17
|
const useUtilityClasses = ownerState => {
|
|
@@ -46,7 +48,7 @@ function ChartsXAxis(inProps) {
|
|
|
46
48
|
xAxis: {
|
|
47
49
|
[_props$axisId]: {
|
|
48
50
|
scale: xScale,
|
|
49
|
-
|
|
51
|
+
tickNumber
|
|
50
52
|
}
|
|
51
53
|
}
|
|
52
54
|
} = _React$useContext,
|
|
@@ -77,7 +79,7 @@ function ChartsXAxis(inProps) {
|
|
|
77
79
|
const tickSize = disableTicks ? 4 : tickSizeProp;
|
|
78
80
|
const xTicks = useTicks({
|
|
79
81
|
scale: xScale,
|
|
80
|
-
|
|
82
|
+
tickNumber,
|
|
81
83
|
valueFormatter
|
|
82
84
|
});
|
|
83
85
|
const positionSigne = position === 'bottom' ? 1 : -1;
|
|
@@ -85,10 +87,38 @@ function ChartsXAxis(inProps) {
|
|
|
85
87
|
x: left + width / 2,
|
|
86
88
|
y: positionSigne * (tickFontSize + tickSize + 10)
|
|
87
89
|
};
|
|
88
|
-
const Line = slots?.axisLine ??
|
|
89
|
-
const Tick = slots?.axisTick ??
|
|
90
|
-
const TickLabel = slots?.axisTickLabel ??
|
|
91
|
-
const Label = slots?.axisLabel ??
|
|
90
|
+
const Line = slots?.axisLine ?? 'line';
|
|
91
|
+
const Tick = slots?.axisTick ?? 'line';
|
|
92
|
+
const TickLabel = slots?.axisTickLabel ?? ChartsText;
|
|
93
|
+
const Label = slots?.axisLabel ?? ChartsText;
|
|
94
|
+
const axisTickLabelProps = useSlotProps({
|
|
95
|
+
elementType: TickLabel,
|
|
96
|
+
externalSlotProps: slotProps?.axisTickLabel,
|
|
97
|
+
additionalProps: {
|
|
98
|
+
textAnchor: 'middle',
|
|
99
|
+
dominantBaseline: position === 'bottom' ? 'hanging' : 'auto',
|
|
100
|
+
style: {
|
|
101
|
+
fontSize: tickFontSize
|
|
102
|
+
},
|
|
103
|
+
className: classes.tickLabel
|
|
104
|
+
},
|
|
105
|
+
className: classes.tickLabel,
|
|
106
|
+
ownerState: {}
|
|
107
|
+
});
|
|
108
|
+
const axisLabelProps = useSlotProps({
|
|
109
|
+
elementType: Label,
|
|
110
|
+
externalSlotProps: slotProps?.axisLabel,
|
|
111
|
+
additionalProps: {
|
|
112
|
+
textAnchor: 'middle',
|
|
113
|
+
dominantBaseline: position === 'bottom' ? 'hanging' : 'auto',
|
|
114
|
+
style: {
|
|
115
|
+
fontSize: labelFontSize,
|
|
116
|
+
transformOrigin: `${labelRefPoint.x}px ${labelRefPoint.y}px`
|
|
117
|
+
},
|
|
118
|
+
className: classes.label
|
|
119
|
+
},
|
|
120
|
+
ownerState: {}
|
|
121
|
+
});
|
|
92
122
|
return /*#__PURE__*/_jsxs(AxisRoot, {
|
|
93
123
|
transform: `translate(0, ${position === 'bottom' ? top + height : top})`,
|
|
94
124
|
className: classes.root,
|
|
@@ -112,24 +142,17 @@ function ChartsXAxis(inProps) {
|
|
|
112
142
|
}, slotProps?.axisTick)), formattedValue !== undefined && /*#__PURE__*/_jsx(TickLabel, _extends({
|
|
113
143
|
x: xTickLabel,
|
|
114
144
|
y: yTickLabel,
|
|
115
|
-
"transform-origin": `${xTickLabel}px ${yTickLabel}px
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
},
|
|
119
|
-
className: classes.tickLabel
|
|
120
|
-
}, slotProps?.axisTickLabel, {
|
|
121
|
-
children: formattedValue
|
|
145
|
+
"transform-origin": `${xTickLabel}px ${yTickLabel}px`
|
|
146
|
+
}, axisTickLabelProps, {
|
|
147
|
+
text: formattedValue.toString()
|
|
122
148
|
}))]
|
|
123
149
|
}, index);
|
|
124
|
-
}), label && /*#__PURE__*/_jsx(
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
}, slotProps?.axisLabel, {
|
|
131
|
-
children: label
|
|
132
|
-
}))]
|
|
150
|
+
}), label && /*#__PURE__*/_jsx("g", {
|
|
151
|
+
className: classes.label,
|
|
152
|
+
children: /*#__PURE__*/_jsx(Label, _extends({}, labelRefPoint, axisLabelProps, {
|
|
153
|
+
text: label
|
|
154
|
+
}))
|
|
155
|
+
})]
|
|
133
156
|
});
|
|
134
157
|
}
|
|
135
158
|
process.env.NODE_ENV !== "production" ? ChartsXAxis.propTypes = {
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
2
2
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
3
|
-
const _excluded = ["scale", "
|
|
3
|
+
const _excluded = ["scale", "tickNumber"];
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import PropTypes from 'prop-types';
|
|
6
|
+
import { useSlotProps } from '@mui/base/utils';
|
|
6
7
|
import { unstable_composeClasses as composeClasses } from '@mui/utils';
|
|
7
8
|
import { useThemeProps, useTheme } from '@mui/material/styles';
|
|
8
9
|
import { CartesianContext } from '../context/CartesianContextProvider';
|
|
9
10
|
import { DrawingContext } from '../context/DrawingProvider';
|
|
10
11
|
import useTicks from '../hooks/useTicks';
|
|
11
|
-
import {
|
|
12
|
+
import { AxisRoot } from '../internals/components/AxisSharedComponents';
|
|
13
|
+
import { ChartsText } from '../internals/components/ChartsText';
|
|
12
14
|
import { getAxisUtilityClass } from '../ChartsAxis/axisClasses';
|
|
13
15
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
16
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
@@ -46,7 +48,7 @@ function ChartsYAxis(inProps) {
|
|
|
46
48
|
yAxis: {
|
|
47
49
|
[_props$axisId]: {
|
|
48
50
|
scale: yScale,
|
|
49
|
-
|
|
51
|
+
tickNumber
|
|
50
52
|
}
|
|
51
53
|
}
|
|
52
54
|
} = _React$useContext,
|
|
@@ -77,7 +79,7 @@ function ChartsYAxis(inProps) {
|
|
|
77
79
|
const tickSize = disableTicks ? 4 : tickSizeProp;
|
|
78
80
|
const yTicks = useTicks({
|
|
79
81
|
scale: yScale,
|
|
80
|
-
|
|
82
|
+
tickNumber,
|
|
81
83
|
valueFormatter
|
|
82
84
|
});
|
|
83
85
|
const positionSigne = position === 'right' ? 1 : -1;
|
|
@@ -85,10 +87,38 @@ function ChartsYAxis(inProps) {
|
|
|
85
87
|
x: positionSigne * (tickFontSize + tickSize + 10),
|
|
86
88
|
y: top + height / 2
|
|
87
89
|
};
|
|
88
|
-
const Line = slots?.axisLine ??
|
|
89
|
-
const Tick = slots?.axisTick ??
|
|
90
|
-
const TickLabel = slots?.axisTickLabel ??
|
|
91
|
-
const Label = slots?.axisLabel ??
|
|
90
|
+
const Line = slots?.axisLine ?? 'line';
|
|
91
|
+
const Tick = slots?.axisTick ?? 'line';
|
|
92
|
+
const TickLabel = slots?.axisTickLabel ?? ChartsText;
|
|
93
|
+
const Label = slots?.axisLabel ?? ChartsText;
|
|
94
|
+
const axisTickLabelProps = useSlotProps({
|
|
95
|
+
elementType: TickLabel,
|
|
96
|
+
externalSlotProps: slotProps?.axisTickLabel,
|
|
97
|
+
additionalProps: {
|
|
98
|
+
textAnchor: position === 'right' ? 'start' : 'end',
|
|
99
|
+
dominantBaseline: 'central',
|
|
100
|
+
style: {
|
|
101
|
+
fontSize: tickFontSize
|
|
102
|
+
},
|
|
103
|
+
className: classes.tickLabel
|
|
104
|
+
},
|
|
105
|
+
ownerState: {}
|
|
106
|
+
});
|
|
107
|
+
const axisLabelProps = useSlotProps({
|
|
108
|
+
elementType: Label,
|
|
109
|
+
externalSlotProps: slotProps?.axisLabel,
|
|
110
|
+
additionalProps: {
|
|
111
|
+
textAnchor: 'middle',
|
|
112
|
+
dominantBaseline: 'auto',
|
|
113
|
+
style: {
|
|
114
|
+
fontSize: labelFontSize,
|
|
115
|
+
transform: `rotate(${positionSigne * 90}deg)`,
|
|
116
|
+
transformOrigin: `${labelRefPoint.x}px ${labelRefPoint.y}px`
|
|
117
|
+
},
|
|
118
|
+
className: classes.label
|
|
119
|
+
},
|
|
120
|
+
ownerState: {}
|
|
121
|
+
});
|
|
92
122
|
return /*#__PURE__*/_jsxs(AxisRoot, {
|
|
93
123
|
transform: `translate(${position === 'right' ? left + width : left}, 0)`,
|
|
94
124
|
className: classes.root,
|
|
@@ -113,24 +143,15 @@ function ChartsYAxis(inProps) {
|
|
|
113
143
|
x: xTickLabel,
|
|
114
144
|
y: yTickLabel,
|
|
115
145
|
"transform-origin": `${xTickLabel}px ${yTickLabel}px`,
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
},
|
|
119
|
-
className: classes.tickLabel
|
|
120
|
-
}, slotProps?.axisTickLabel, {
|
|
121
|
-
children: formattedValue.toLocaleString()
|
|
122
|
-
}))]
|
|
146
|
+
text: formattedValue.toString()
|
|
147
|
+
}, axisTickLabelProps))]
|
|
123
148
|
}, index);
|
|
124
|
-
}), label && /*#__PURE__*/_jsx(
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
className: classes.label
|
|
131
|
-
}, slotProps?.axisLabel, {
|
|
132
|
-
children: label
|
|
133
|
-
}))]
|
|
149
|
+
}), label && /*#__PURE__*/_jsx("g", {
|
|
150
|
+
className: classes.label,
|
|
151
|
+
children: /*#__PURE__*/_jsx(Label, _extends({}, labelRefPoint, axisLabelProps, {
|
|
152
|
+
text: label
|
|
153
|
+
}))
|
|
154
|
+
})]
|
|
134
155
|
});
|
|
135
156
|
}
|
|
136
157
|
process.env.NODE_ENV !== "production" ? ChartsYAxis.propTypes = {
|
|
@@ -88,7 +88,10 @@ const LineChart = /*#__PURE__*/React.forwardRef(function LineChart(props, ref) {
|
|
|
88
88
|
}), /*#__PURE__*/_jsx(ChartsLegend, _extends({}, legend, {
|
|
89
89
|
slots: slots,
|
|
90
90
|
slotProps: slotProps
|
|
91
|
-
})), /*#__PURE__*/_jsx(ChartsTooltip, _extends({}, tooltip
|
|
91
|
+
})), /*#__PURE__*/_jsx(ChartsTooltip, _extends({}, tooltip, {
|
|
92
|
+
slots: slots,
|
|
93
|
+
slotProps: slotProps
|
|
94
|
+
})), /*#__PURE__*/_jsx(ChartsClipPath, {
|
|
92
95
|
id: clipPathId
|
|
93
96
|
}), children]
|
|
94
97
|
});
|
|
@@ -162,23 +165,19 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
|
|
|
162
165
|
tickNumber: PropTypes.number,
|
|
163
166
|
tickSize: PropTypes.number
|
|
164
167
|
}), PropTypes.string]),
|
|
168
|
+
/**
|
|
169
|
+
* @deprecated Consider using `slotProps.legend` instead.
|
|
170
|
+
*/
|
|
165
171
|
legend: PropTypes.shape({
|
|
166
172
|
classes: PropTypes.object,
|
|
167
173
|
direction: PropTypes.oneOf(['column', 'row']),
|
|
168
174
|
hidden: PropTypes.bool,
|
|
169
|
-
itemWidth: PropTypes.number,
|
|
170
|
-
markSize: PropTypes.number,
|
|
171
|
-
offset: PropTypes.shape({
|
|
172
|
-
x: PropTypes.number,
|
|
173
|
-
y: PropTypes.number
|
|
174
|
-
}),
|
|
175
175
|
position: PropTypes.shape({
|
|
176
176
|
horizontal: PropTypes.oneOf(['left', 'middle', 'right']).isRequired,
|
|
177
177
|
vertical: PropTypes.oneOf(['bottom', 'middle', 'top']).isRequired
|
|
178
178
|
}),
|
|
179
179
|
slotProps: PropTypes.object,
|
|
180
|
-
slots: PropTypes.object
|
|
181
|
-
spacing: PropTypes.number
|
|
180
|
+
slots: PropTypes.object
|
|
182
181
|
}),
|
|
183
182
|
margin: PropTypes.shape({
|
|
184
183
|
bottom: PropTypes.number,
|
|
@@ -247,6 +246,8 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
|
|
|
247
246
|
axisContent: PropTypes.elementType,
|
|
248
247
|
classes: PropTypes.object,
|
|
249
248
|
itemContent: PropTypes.elementType,
|
|
249
|
+
slotProps: PropTypes.object,
|
|
250
|
+
slots: PropTypes.object,
|
|
250
251
|
trigger: PropTypes.oneOf(['axis', 'item', 'none'])
|
|
251
252
|
}),
|
|
252
253
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
|
-
const _excluded = ["id", "dataIndex", "classes", "color", "highlightScope", "innerRadius", "outerRadius", "cornerRadius", "highlighted", "faded"];
|
|
3
|
+
const _excluded = ["id", "dataIndex", "classes", "color", "highlightScope", "innerRadius", "outerRadius", "cornerRadius", "highlighted", "faded", "onClick"];
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import { arc as d3Arc } from 'd3-shape';
|
|
6
6
|
import PropTypes from 'prop-types';
|
|
@@ -54,7 +54,8 @@ export default function PieArc(props) {
|
|
|
54
54
|
highlighted,
|
|
55
55
|
faded = {
|
|
56
56
|
additionalRadius: -5
|
|
57
|
-
}
|
|
57
|
+
},
|
|
58
|
+
onClick
|
|
58
59
|
} = props,
|
|
59
60
|
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
60
61
|
const getInteractionItemProps = useInteractionItemProps(highlightScope);
|
|
@@ -91,6 +92,8 @@ export default function PieArc(props) {
|
|
|
91
92
|
innerRadius,
|
|
92
93
|
outerRadius
|
|
93
94
|
})),
|
|
95
|
+
onClick: onClick,
|
|
96
|
+
cursor: onClick ? 'pointer' : 'unset',
|
|
94
97
|
ownerState: ownerState,
|
|
95
98
|
className: classes.root
|
|
96
99
|
}, getInteractionItemProps({
|
|
@@ -46,7 +46,8 @@ function PieChart(props) {
|
|
|
46
46
|
bottomAxis = null,
|
|
47
47
|
children,
|
|
48
48
|
slots,
|
|
49
|
-
slotProps
|
|
49
|
+
slotProps,
|
|
50
|
+
onClick
|
|
50
51
|
} = props;
|
|
51
52
|
const margin = _extends({}, defaultMargin, marginProps);
|
|
52
53
|
return /*#__PURE__*/_jsxs(ResponsiveChartContainer, {
|
|
@@ -74,7 +75,8 @@ function PieChart(props) {
|
|
|
74
75
|
slotProps: slotProps
|
|
75
76
|
}), /*#__PURE__*/_jsx(PiePlot, {
|
|
76
77
|
slots: slots,
|
|
77
|
-
slotProps: slotProps
|
|
78
|
+
slotProps: slotProps,
|
|
79
|
+
onClick: onClick
|
|
78
80
|
}), /*#__PURE__*/_jsx(ChartsLegend, _extends({}, legend, {
|
|
79
81
|
slots: slots,
|
|
80
82
|
slotProps: slotProps
|
|
@@ -146,23 +148,19 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
|
|
|
146
148
|
tickNumber: PropTypes.number,
|
|
147
149
|
tickSize: PropTypes.number
|
|
148
150
|
}), PropTypes.string]),
|
|
151
|
+
/**
|
|
152
|
+
* @deprecated Consider using `slotProps.legend` instead.
|
|
153
|
+
*/
|
|
149
154
|
legend: PropTypes.shape({
|
|
150
155
|
classes: PropTypes.object,
|
|
151
156
|
direction: PropTypes.oneOf(['column', 'row']),
|
|
152
157
|
hidden: PropTypes.bool,
|
|
153
|
-
itemWidth: PropTypes.number,
|
|
154
|
-
markSize: PropTypes.number,
|
|
155
|
-
offset: PropTypes.shape({
|
|
156
|
-
x: PropTypes.number,
|
|
157
|
-
y: PropTypes.number
|
|
158
|
-
}),
|
|
159
158
|
position: PropTypes.shape({
|
|
160
159
|
horizontal: PropTypes.oneOf(['left', 'middle', 'right']).isRequired,
|
|
161
160
|
vertical: PropTypes.oneOf(['bottom', 'middle', 'top']).isRequired
|
|
162
161
|
}),
|
|
163
162
|
slotProps: PropTypes.object,
|
|
164
|
-
slots: PropTypes.object
|
|
165
|
-
spacing: PropTypes.number
|
|
163
|
+
slots: PropTypes.object
|
|
166
164
|
}),
|
|
167
165
|
margin: PropTypes.shape({
|
|
168
166
|
bottom: PropTypes.number,
|
|
@@ -170,6 +168,7 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
|
|
|
170
168
|
right: PropTypes.number,
|
|
171
169
|
top: PropTypes.number
|
|
172
170
|
}),
|
|
171
|
+
onClick: PropTypes.func,
|
|
173
172
|
/**
|
|
174
173
|
* Indicate which axis to display the right of the charts.
|
|
175
174
|
* Can be a string (the id of the axis) or an object `ChartsYAxisProps`.
|
|
@@ -244,6 +243,8 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
|
|
|
244
243
|
axisContent: PropTypes.elementType,
|
|
245
244
|
classes: PropTypes.object,
|
|
246
245
|
itemContent: PropTypes.elementType,
|
|
246
|
+
slotProps: PropTypes.object,
|
|
247
|
+
slots: PropTypes.object,
|
|
247
248
|
trigger: PropTypes.oneOf(['axis', 'item', 'none'])
|
|
248
249
|
}),
|
|
249
250
|
/**
|
|
@@ -25,7 +25,8 @@ function getItemLabel(arcLabel, arcLabelMinAngle, item) {
|
|
|
25
25
|
function PiePlot(props) {
|
|
26
26
|
const {
|
|
27
27
|
slots,
|
|
28
|
-
slotProps
|
|
28
|
+
slotProps,
|
|
29
|
+
onClick
|
|
29
30
|
} = props;
|
|
30
31
|
const seriesData = React.useContext(SeriesContext).pie;
|
|
31
32
|
const {
|
|
@@ -76,7 +77,14 @@ function PiePlot(props) {
|
|
|
76
77
|
dataIndex: index,
|
|
77
78
|
highlightScope: series[seriesId].highlightScope,
|
|
78
79
|
highlighted: highlighted,
|
|
79
|
-
faded: faded
|
|
80
|
+
faded: faded,
|
|
81
|
+
onClick: onClick && (event => {
|
|
82
|
+
onClick(event, {
|
|
83
|
+
type: 'pie',
|
|
84
|
+
seriesId,
|
|
85
|
+
dataIndex: index
|
|
86
|
+
}, item);
|
|
87
|
+
})
|
|
80
88
|
}, slotProps?.pieArc));
|
|
81
89
|
}), data.map((item, index) => {
|
|
82
90
|
return /*#__PURE__*/_createElement(ArcLabel, _extends({}, item, {
|
|
@@ -101,6 +109,13 @@ process.env.NODE_ENV !== "production" ? PiePlot.propTypes = {
|
|
|
101
109
|
// | These PropTypes are generated from the TypeScript type definitions |
|
|
102
110
|
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
103
111
|
// ----------------------------------------------------------------------
|
|
112
|
+
/**
|
|
113
|
+
* Callback fired when a pie item is clicked.
|
|
114
|
+
* @param {React.MouseEvent<SVGPathElement, MouseEvent>} event The event source of the callback.
|
|
115
|
+
* @param {PieItemIdentifier} pieItemIdentifier The pie item identifier.
|
|
116
|
+
* @param {DefaultizedPieValueType} item The pie item.
|
|
117
|
+
*/
|
|
118
|
+
onClick: PropTypes.func,
|
|
104
119
|
/**
|
|
105
120
|
* The props used for each component slot.
|
|
106
121
|
* @default {}
|
|
@@ -128,23 +128,19 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
|
|
|
128
128
|
tickNumber: PropTypes.number,
|
|
129
129
|
tickSize: PropTypes.number
|
|
130
130
|
}), PropTypes.string]),
|
|
131
|
+
/**
|
|
132
|
+
* @deprecated Consider using `slotProps.legend` instead.
|
|
133
|
+
*/
|
|
131
134
|
legend: PropTypes.shape({
|
|
132
135
|
classes: PropTypes.object,
|
|
133
136
|
direction: PropTypes.oneOf(['column', 'row']),
|
|
134
137
|
hidden: PropTypes.bool,
|
|
135
|
-
itemWidth: PropTypes.number,
|
|
136
|
-
markSize: PropTypes.number,
|
|
137
|
-
offset: PropTypes.shape({
|
|
138
|
-
x: PropTypes.number,
|
|
139
|
-
y: PropTypes.number
|
|
140
|
-
}),
|
|
141
138
|
position: PropTypes.shape({
|
|
142
139
|
horizontal: PropTypes.oneOf(['left', 'middle', 'right']).isRequired,
|
|
143
140
|
vertical: PropTypes.oneOf(['bottom', 'middle', 'top']).isRequired
|
|
144
141
|
}),
|
|
145
142
|
slotProps: PropTypes.object,
|
|
146
|
-
slots: PropTypes.object
|
|
147
|
-
spacing: PropTypes.number
|
|
143
|
+
slots: PropTypes.object
|
|
148
144
|
}),
|
|
149
145
|
margin: PropTypes.shape({
|
|
150
146
|
bottom: PropTypes.number,
|
|
@@ -210,6 +206,8 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
|
|
|
210
206
|
axisContent: PropTypes.elementType,
|
|
211
207
|
classes: PropTypes.object,
|
|
212
208
|
itemContent: PropTypes.elementType,
|
|
209
|
+
slotProps: PropTypes.object,
|
|
210
|
+
slots: PropTypes.object,
|
|
213
211
|
trigger: PropTypes.oneOf(['axis', 'item', 'none'])
|
|
214
212
|
}),
|
|
215
213
|
/**
|
|
@@ -84,7 +84,10 @@ const SparkLineChart = /*#__PURE__*/React.forwardRef(function SparkLineChart(pro
|
|
|
84
84
|
slots: slots,
|
|
85
85
|
slotProps: slotProps
|
|
86
86
|
})]
|
|
87
|
-
}), /*#__PURE__*/_jsx(ChartsAxisHighlight, _extends({}, axisHighlight)), showTooltip && /*#__PURE__*/_jsx(ChartsTooltip, _extends({}, tooltip
|
|
87
|
+
}), /*#__PURE__*/_jsx(ChartsAxisHighlight, _extends({}, axisHighlight)), showTooltip && /*#__PURE__*/_jsx(ChartsTooltip, _extends({}, tooltip, {
|
|
88
|
+
slotProps: slotProps,
|
|
89
|
+
slots: slots
|
|
90
|
+
})), children]
|
|
88
91
|
});
|
|
89
92
|
});
|
|
90
93
|
process.env.NODE_ENV !== "production" ? SparkLineChart.propTypes = {
|
|
@@ -159,6 +162,8 @@ process.env.NODE_ENV !== "production" ? SparkLineChart.propTypes = {
|
|
|
159
162
|
axisContent: PropTypes.elementType,
|
|
160
163
|
classes: PropTypes.object,
|
|
161
164
|
itemContent: PropTypes.elementType,
|
|
165
|
+
slotProps: PropTypes.object,
|
|
166
|
+
slots: PropTypes.object,
|
|
162
167
|
trigger: PropTypes.oneOf(['axis', 'item', 'none'])
|
|
163
168
|
}),
|
|
164
169
|
/**
|
package/modern/constants.js
CHANGED
|
@@ -10,7 +10,7 @@ import { getScale } from '../internals/getScale';
|
|
|
10
10
|
import { DrawingContext } from './DrawingProvider';
|
|
11
11
|
import { SeriesContext } from './SeriesContextProvider';
|
|
12
12
|
import { DEFAULT_X_AXIS_KEY, DEFAULT_Y_AXIS_KEY } from '../constants';
|
|
13
|
-
import {
|
|
13
|
+
import { getTickNumber } from '../hooks/useTicks';
|
|
14
14
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
15
15
|
const DEFAULT_CATEGORY_GAP_RATIO = 0.2;
|
|
16
16
|
const DEFAULT_BAR_GAP_RATIO = 0.1;
|
|
@@ -109,13 +109,13 @@ function CartesianContextProvider({
|
|
|
109
109
|
barGapRatio
|
|
110
110
|
}, axis, {
|
|
111
111
|
scale: scaleBand(axis.data, range).paddingInner(categoryGapRatio).paddingOuter(categoryGapRatio / 2),
|
|
112
|
-
|
|
112
|
+
tickNumber: axis.data.length
|
|
113
113
|
});
|
|
114
114
|
}
|
|
115
115
|
if (isPointScaleConfig(axis)) {
|
|
116
116
|
completedXAxis[axis.id] = _extends({}, axis, {
|
|
117
117
|
scale: scalePoint(axis.data, range),
|
|
118
|
-
|
|
118
|
+
tickNumber: axis.data.length
|
|
119
119
|
});
|
|
120
120
|
}
|
|
121
121
|
if (axis.scaleType === 'band' || axis.scaleType === 'point') {
|
|
@@ -124,17 +124,17 @@ function CartesianContextProvider({
|
|
|
124
124
|
}
|
|
125
125
|
const scaleType = axis.scaleType ?? 'linear';
|
|
126
126
|
const extremums = [axis.min ?? minData, axis.max ?? maxData];
|
|
127
|
-
const
|
|
127
|
+
const tickNumber = getTickNumber(_extends({}, axis, {
|
|
128
128
|
range,
|
|
129
129
|
domain: extremums
|
|
130
130
|
}));
|
|
131
|
-
const niceScale = getScale(scaleType, extremums, range).nice(
|
|
131
|
+
const niceScale = getScale(scaleType, extremums, range).nice(tickNumber);
|
|
132
132
|
const niceDomain = niceScale.domain();
|
|
133
133
|
const domain = [axis.min ?? niceDomain[0], axis.max ?? niceDomain[1]];
|
|
134
134
|
completedXAxis[axis.id] = _extends({}, axis, {
|
|
135
135
|
scaleType,
|
|
136
136
|
scale: niceScale.domain(domain),
|
|
137
|
-
|
|
137
|
+
tickNumber
|
|
138
138
|
});
|
|
139
139
|
});
|
|
140
140
|
const allYAxis = [...(yAxis?.map((axis, index) => _extends({
|
|
@@ -157,13 +157,13 @@ function CartesianContextProvider({
|
|
|
157
157
|
barGapRatio: 0
|
|
158
158
|
}, axis, {
|
|
159
159
|
scale: scaleBand(axis.data, [range[1], range[0]]).paddingInner(categoryGapRatio).paddingOuter(categoryGapRatio / 2),
|
|
160
|
-
|
|
160
|
+
tickNumber: axis.data.length
|
|
161
161
|
});
|
|
162
162
|
}
|
|
163
163
|
if (isPointScaleConfig(axis)) {
|
|
164
164
|
completedYAxis[axis.id] = _extends({}, axis, {
|
|
165
165
|
scale: scalePoint(axis.data, [range[1], range[0]]),
|
|
166
|
-
|
|
166
|
+
tickNumber: axis.data.length
|
|
167
167
|
});
|
|
168
168
|
}
|
|
169
169
|
if (axis.scaleType === 'band' || axis.scaleType === 'point') {
|
|
@@ -172,17 +172,17 @@ function CartesianContextProvider({
|
|
|
172
172
|
}
|
|
173
173
|
const scaleType = axis.scaleType ?? 'linear';
|
|
174
174
|
const extremums = [axis.min ?? minData, axis.max ?? maxData];
|
|
175
|
-
const
|
|
175
|
+
const tickNumber = getTickNumber(_extends({}, axis, {
|
|
176
176
|
range,
|
|
177
177
|
domain: extremums
|
|
178
178
|
}));
|
|
179
|
-
const niceScale = getScale(scaleType, extremums, range).nice(
|
|
179
|
+
const niceScale = getScale(scaleType, extremums, range).nice(tickNumber);
|
|
180
180
|
const niceDomain = niceScale.domain();
|
|
181
181
|
const domain = [axis.min ?? niceDomain[0], axis.max ?? niceDomain[1]];
|
|
182
182
|
completedYAxis[axis.id] = _extends({}, axis, {
|
|
183
183
|
scaleType,
|
|
184
184
|
scale: niceScale.domain(domain),
|
|
185
|
-
|
|
185
|
+
tickNumber
|
|
186
186
|
});
|
|
187
187
|
});
|
|
188
188
|
return {
|
|
@@ -6,6 +6,8 @@ const useChartDimensions = (width, height, margin) => {
|
|
|
6
6
|
const drawingArea = React.useMemo(() => ({
|
|
7
7
|
left: defaultizedMargin.left,
|
|
8
8
|
top: defaultizedMargin.top,
|
|
9
|
+
right: defaultizedMargin.right,
|
|
10
|
+
bottom: defaultizedMargin.bottom,
|
|
9
11
|
width: Math.max(0, width - defaultizedMargin.left - defaultizedMargin.right),
|
|
10
12
|
height: Math.max(0, height - defaultizedMargin.top - defaultizedMargin.bottom)
|
|
11
13
|
}), [width, height, defaultizedMargin.top, defaultizedMargin.bottom, defaultizedMargin.left, defaultizedMargin.right]);
|
package/modern/hooks/useTicks.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { isBandScale } from '../internals/isBandScale';
|
|
3
|
-
export function
|
|
3
|
+
export function getTickNumber(params) {
|
|
4
4
|
const {
|
|
5
5
|
tickMaxStep,
|
|
6
6
|
tickMinStep,
|
|
@@ -16,7 +16,7 @@ export function getTicksNumber(params) {
|
|
|
16
16
|
function useTicks(options) {
|
|
17
17
|
const {
|
|
18
18
|
scale,
|
|
19
|
-
|
|
19
|
+
tickNumber,
|
|
20
20
|
valueFormatter
|
|
21
21
|
} = options;
|
|
22
22
|
return React.useMemo(() => {
|
|
@@ -43,11 +43,11 @@ function useTicks(options) {
|
|
|
43
43
|
labelOffset: 0
|
|
44
44
|
}));
|
|
45
45
|
}
|
|
46
|
-
return scale.ticks(
|
|
47
|
-
formattedValue: valueFormatter?.(value) ?? scale.tickFormat(
|
|
46
|
+
return scale.ticks(tickNumber).map(value => ({
|
|
47
|
+
formattedValue: valueFormatter?.(value) ?? scale.tickFormat(tickNumber)(value),
|
|
48
48
|
offset: scale(value),
|
|
49
49
|
labelOffset: 0
|
|
50
50
|
}));
|
|
51
|
-
}, [
|
|
51
|
+
}, [tickNumber, scale, valueFormatter]);
|
|
52
52
|
}
|
|
53
53
|
export default useTicks;
|
package/modern/index.js
CHANGED