@mui/x-charts 7.3.1 → 7.3.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.
- package/BarChart/BarChart.d.ts +4 -3
- package/BarChart/BarChart.js +15 -5
- package/BarChart/BarPlot.js +6 -6
- package/CHANGELOG.md +76 -5
- package/ChartsAxis/axisClasses.d.ts +1 -1
- package/ChartsOverlay/ChartsLoadingOverlay.d.ts +3 -0
- package/ChartsOverlay/ChartsLoadingOverlay.js +43 -0
- package/ChartsOverlay/ChartsNoDataOverlay.d.ts +3 -0
- package/ChartsOverlay/ChartsNoDataOverlay.js +43 -0
- package/ChartsOverlay/ChartsOverlay.d.ts +35 -0
- package/ChartsOverlay/ChartsOverlay.js +41 -0
- package/ChartsOverlay/index.d.ts +3 -0
- package/ChartsOverlay/index.js +26 -0
- package/ChartsOverlay/package.json +6 -0
- package/ChartsReferenceLine/ChartsReferenceLine.js +1 -1
- package/ChartsReferenceLine/common.d.ts +1 -1
- package/ChartsTooltip/ChartsAxisTooltipContent.d.ts +1 -1
- package/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
- package/ChartsTooltip/ChartsTooltip.d.ts +2 -2
- package/ChartsTooltip/ChartsTooltip.js +2 -2
- package/ChartsTooltip/DefaultChartsAxisTooltipContent.js +1 -1
- package/ChartsXAxis/ChartsXAxis.d.ts +1 -1
- package/ChartsXAxis/ChartsXAxis.js +7 -0
- package/ChartsYAxis/ChartsYAxis.d.ts +1 -1
- package/ChartsYAxis/ChartsYAxis.js +7 -0
- package/Gauge/Gauge.js +1 -1
- package/Gauge/GaugeContainer.js +1 -1
- package/Gauge/GaugeProvider.d.ts +2 -2
- package/Gauge/GaugeProvider.js +1 -1
- package/Gauge/gaugeClasses.d.ts +2 -2
- package/Gauge/utils.d.ts +1 -1
- package/Gauge/utils.js +4 -4
- package/LineChart/AreaElement.d.ts +1 -1
- package/LineChart/LineChart.d.ts +4 -3
- package/LineChart/LineChart.js +12 -2
- package/LineChart/LineElement.d.ts +1 -1
- package/LineChart/MarkElement.d.ts +1 -1
- package/PieChart/PieArc.d.ts +1 -1
- package/PieChart/PieArcLabel.d.ts +1 -1
- package/PieChart/PieArcLabel.js +1 -1
- package/PieChart/PieArcLabelPlot.d.ts +1 -1
- package/PieChart/PieArcLabelPlot.js +3 -3
- package/PieChart/PieArcPlot.d.ts +1 -1
- package/PieChart/PieArcPlot.js +3 -3
- package/PieChart/PieChart.d.ts +4 -3
- package/PieChart/PieChart.js +15 -2
- package/ScatterChart/ScatterChart.d.ts +4 -3
- package/ScatterChart/ScatterChart.js +12 -2
- package/context/SeriesContextProvider.js +1 -1
- package/esm/BarChart/BarChart.js +15 -5
- package/esm/BarChart/BarPlot.js +6 -6
- package/esm/ChartsOverlay/ChartsLoadingOverlay.js +34 -0
- package/esm/ChartsOverlay/ChartsNoDataOverlay.js +34 -0
- package/esm/ChartsOverlay/ChartsOverlay.js +31 -0
- package/esm/ChartsOverlay/index.js +3 -0
- package/esm/ChartsReferenceLine/ChartsReferenceLine.js +1 -1
- package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
- package/esm/ChartsTooltip/ChartsTooltip.js +2 -2
- package/esm/ChartsTooltip/DefaultChartsAxisTooltipContent.js +1 -1
- package/esm/ChartsXAxis/ChartsXAxis.js +7 -0
- package/esm/ChartsYAxis/ChartsYAxis.js +7 -0
- package/esm/Gauge/Gauge.js +1 -1
- package/esm/Gauge/GaugeContainer.js +1 -1
- package/esm/Gauge/GaugeProvider.js +1 -1
- package/esm/Gauge/utils.js +4 -4
- package/esm/LineChart/LineChart.js +12 -2
- package/esm/PieChart/PieArcLabel.js +1 -1
- package/esm/PieChart/PieArcLabelPlot.js +3 -3
- package/esm/PieChart/PieArcPlot.js +3 -3
- package/esm/PieChart/PieChart.js +15 -2
- package/esm/ScatterChart/ScatterChart.js +12 -2
- package/esm/context/SeriesContextProvider.js +1 -1
- package/esm/hooks/useReducedMotion.js +1 -1
- package/esm/hooks/useScale.js +1 -1
- package/esm/hooks/useTicks.js +4 -0
- package/esm/internals/components/ChartsAxesGradients/ChartsAxesGradients.js +5 -5
- package/esm/internals/components/ChartsAxesGradients/ChartsContinuousGradient.js +3 -3
- package/esm/internals/components/ChartsAxesGradients/ChartsPiecewiseGradient.js +3 -3
- package/esm/internals/utils.js +1 -1
- package/hooks/useReducedMotion.d.ts +1 -1
- package/hooks/useReducedMotion.js +1 -1
- package/hooks/useScale.d.ts +4 -4
- package/hooks/useScale.js +1 -1
- package/hooks/useTicks.js +4 -0
- package/index.js +1 -1
- package/internals/components/ChartsAxesGradients/ChartsAxesGradients.js +5 -5
- package/internals/components/ChartsAxesGradients/ChartsContinuousGradient.d.ts +1 -1
- package/internals/components/ChartsAxesGradients/ChartsContinuousGradient.js +3 -3
- package/internals/components/ChartsAxesGradients/ChartsPiecewiseGradient.d.ts +1 -1
- package/internals/components/ChartsAxesGradients/ChartsPiecewiseGradient.js +3 -3
- package/internals/utils.d.ts +1 -1
- package/internals/utils.js +1 -1
- package/models/axis.d.ts +1 -1
- package/models/seriesType/bar.d.ts +1 -1
- package/models/seriesType/line.d.ts +1 -1
- package/models/seriesType/pie.d.ts +4 -4
- package/modern/BarChart/BarChart.js +15 -5
- package/modern/BarChart/BarPlot.js +6 -6
- package/modern/ChartsOverlay/ChartsLoadingOverlay.js +34 -0
- package/modern/ChartsOverlay/ChartsNoDataOverlay.js +34 -0
- package/modern/ChartsOverlay/ChartsOverlay.js +31 -0
- package/modern/ChartsOverlay/index.js +3 -0
- package/modern/ChartsReferenceLine/ChartsReferenceLine.js +1 -1
- package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
- package/modern/ChartsTooltip/ChartsTooltip.js +2 -2
- package/modern/ChartsTooltip/DefaultChartsAxisTooltipContent.js +1 -1
- package/modern/ChartsXAxis/ChartsXAxis.js +7 -0
- package/modern/ChartsYAxis/ChartsYAxis.js +7 -0
- package/modern/Gauge/Gauge.js +1 -1
- package/modern/Gauge/GaugeContainer.js +1 -1
- package/modern/Gauge/GaugeProvider.js +1 -1
- package/modern/Gauge/utils.js +4 -4
- package/modern/LineChart/LineChart.js +12 -2
- package/modern/PieChart/PieArcLabel.js +1 -1
- package/modern/PieChart/PieArcLabelPlot.js +3 -3
- package/modern/PieChart/PieArcPlot.js +3 -3
- package/modern/PieChart/PieChart.js +15 -2
- package/modern/ScatterChart/ScatterChart.js +12 -2
- package/modern/context/SeriesContextProvider.js +1 -1
- package/modern/hooks/useReducedMotion.js +1 -1
- package/modern/hooks/useScale.js +1 -1
- package/modern/hooks/useTicks.js +4 -0
- package/modern/index.js +1 -1
- package/modern/internals/components/ChartsAxesGradients/ChartsAxesGradients.js +5 -5
- package/modern/internals/components/ChartsAxesGradients/ChartsContinuousGradient.js +3 -3
- package/modern/internals/components/ChartsAxesGradients/ChartsPiecewiseGradient.js +3 -3
- package/modern/internals/utils.js +1 -1
- package/package.json +1 -1
|
@@ -100,7 +100,7 @@ process.env.NODE_ENV !== "production" ? DefaultChartsAxisTooltipContent.propType
|
|
|
100
100
|
/**
|
|
101
101
|
* The value associated to the current mouse position.
|
|
102
102
|
*/
|
|
103
|
-
axisValue: PropTypes.
|
|
103
|
+
axisValue: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]),
|
|
104
104
|
/**
|
|
105
105
|
* Override or extend the styles applied to the component.
|
|
106
106
|
*/
|
|
@@ -203,6 +203,13 @@ function ChartsXAxis(inProps) {
|
|
|
203
203
|
},
|
|
204
204
|
ownerState: {}
|
|
205
205
|
});
|
|
206
|
+
const domain = xScale.domain();
|
|
207
|
+
if (domain.length === 0 || domain[0] === domain[1]) {
|
|
208
|
+
// Skip axis rendering if
|
|
209
|
+
// - the data is empty (for band and point axis)
|
|
210
|
+
// - No data is associated to the axis (other scale types)
|
|
211
|
+
return null;
|
|
212
|
+
}
|
|
206
213
|
return /*#__PURE__*/_jsxs(AxisRoot, {
|
|
207
214
|
transform: `translate(0, ${position === 'bottom' ? top + height : top})`,
|
|
208
215
|
className: classes.root,
|
|
@@ -138,6 +138,13 @@ function ChartsYAxis(inProps) {
|
|
|
138
138
|
},
|
|
139
139
|
ownerState: {}
|
|
140
140
|
});
|
|
141
|
+
const domain = yScale.domain();
|
|
142
|
+
if (domain.length === 0 || domain[0] === domain[1]) {
|
|
143
|
+
// Skip axis rendering if
|
|
144
|
+
// - the data is empty (for band and point axis)
|
|
145
|
+
// - No data is associated to the axis (other scale types)
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
141
148
|
return /*#__PURE__*/_jsxs(AxisRoot, {
|
|
142
149
|
transform: `translate(${position === 'right' ? left + width : left}, 0)`,
|
|
143
150
|
className: classes.root,
|
package/esm/Gauge/Gauge.js
CHANGED
|
@@ -84,7 +84,7 @@ process.env.NODE_ENV !== "production" ? Gauge.propTypes = {
|
|
|
84
84
|
*/
|
|
85
85
|
height: PropTypes.number,
|
|
86
86
|
/**
|
|
87
|
-
* The radius between circle center and the
|
|
87
|
+
* The radius between circle center and the beginning of the arc.
|
|
88
88
|
* Can be a number (in px) or a string with a percentage such as '50%'.
|
|
89
89
|
* The '100%' is the maximal radius that fit into the drawing area.
|
|
90
90
|
* @default '80%'
|
|
@@ -145,7 +145,7 @@ process.env.NODE_ENV !== "production" ? GaugeContainer.propTypes = {
|
|
|
145
145
|
*/
|
|
146
146
|
height: PropTypes.number,
|
|
147
147
|
/**
|
|
148
|
-
* The radius between circle center and the
|
|
148
|
+
* The radius between circle center and the beginning of the arc.
|
|
149
149
|
* Can be a number (in px) or a string with a percentage such as '50%'.
|
|
150
150
|
* The '100%' is the maximal radius that fit into the drawing area.
|
|
151
151
|
* @default '80%'
|
|
@@ -48,7 +48,7 @@ export function GaugeProvider(props) {
|
|
|
48
48
|
let cy = top + innerCy;
|
|
49
49
|
const maxRadius = getAvailableRadius(innerCx, innerCy, width, height, ratios);
|
|
50
50
|
|
|
51
|
-
// If the center is not defined, after computation of the available radius,
|
|
51
|
+
// If the center is not defined, after computation of the available radius, update the center to use the remaining space.
|
|
52
52
|
if (cxParam === undefined) {
|
|
53
53
|
const usedWidth = maxRadius * (ratios.maxX - ratios.minX);
|
|
54
54
|
cx = left + (width - usedWidth) / 2 + ratios.cx * usedWidth;
|
package/esm/Gauge/utils.js
CHANGED
|
@@ -7,7 +7,7 @@ function getPoint(angle) {
|
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
10
|
+
* Returns the ratio of the arc bounding box and its center.
|
|
11
11
|
* @param startAngle The start angle (in deg)
|
|
12
12
|
* @param endAngle The end angle (in deg)
|
|
13
13
|
*/
|
|
@@ -20,9 +20,9 @@ export function getArcRatios(startAngle, endAngle) {
|
|
|
20
20
|
const maxAngle = Math.max(startAngle, endAngle);
|
|
21
21
|
const initialAngle = Math.floor(minAngle / 90) * 90;
|
|
22
22
|
for (let step = 1; step <= 4; step += 1) {
|
|
23
|
-
const
|
|
24
|
-
if (
|
|
25
|
-
points.push(getPoint(
|
|
23
|
+
const cardinalAngle = initialAngle + step * 90;
|
|
24
|
+
if (cardinalAngle < maxAngle) {
|
|
25
|
+
points.push(getPoint(cardinalAngle));
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
const minX = Math.min(...points.map(([x]) => x));
|
|
@@ -15,6 +15,7 @@ import { ChartsClipPath } from '../ChartsClipPath';
|
|
|
15
15
|
import { LineHighlightPlot } from './LineHighlightPlot';
|
|
16
16
|
import { ChartsGrid } from '../ChartsGrid';
|
|
17
17
|
import { ChartsOnAxisClickHandler } from '../ChartsOnAxisClickHandler';
|
|
18
|
+
import { ChartsOverlay } from '../ChartsOverlay/ChartsOverlay';
|
|
18
19
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
19
20
|
/**
|
|
20
21
|
* Demos:
|
|
@@ -55,7 +56,8 @@ const LineChart = /*#__PURE__*/React.forwardRef(function LineChart(props, ref) {
|
|
|
55
56
|
children,
|
|
56
57
|
slots,
|
|
57
58
|
slotProps,
|
|
58
|
-
skipAnimation
|
|
59
|
+
skipAnimation,
|
|
60
|
+
loading
|
|
59
61
|
} = props;
|
|
60
62
|
const id = useId();
|
|
61
63
|
const clipPathId = `${id}-clip-path`;
|
|
@@ -97,6 +99,10 @@ const LineChart = /*#__PURE__*/React.forwardRef(function LineChart(props, ref) {
|
|
|
97
99
|
slotProps: slotProps,
|
|
98
100
|
onItemClick: onLineClick,
|
|
99
101
|
skipAnimation: skipAnimation
|
|
102
|
+
}), /*#__PURE__*/_jsx(ChartsOverlay, {
|
|
103
|
+
loading: loading,
|
|
104
|
+
slots: slots,
|
|
105
|
+
slotProps: slotProps
|
|
100
106
|
})]
|
|
101
107
|
}), /*#__PURE__*/_jsx(ChartsAxis, {
|
|
102
108
|
topAxis: topAxis,
|
|
@@ -116,7 +122,7 @@ const LineChart = /*#__PURE__*/React.forwardRef(function LineChart(props, ref) {
|
|
|
116
122
|
}), /*#__PURE__*/_jsx(ChartsLegend, _extends({}, legend, {
|
|
117
123
|
slots: slots,
|
|
118
124
|
slotProps: slotProps
|
|
119
|
-
})), /*#__PURE__*/_jsx(ChartsTooltip, _extends({}, tooltip, {
|
|
125
|
+
})), !loading && /*#__PURE__*/_jsx(ChartsTooltip, _extends({}, tooltip, {
|
|
120
126
|
slots: slots,
|
|
121
127
|
slotProps: slotProps
|
|
122
128
|
})), /*#__PURE__*/_jsx(ChartsClipPath, {
|
|
@@ -197,6 +203,10 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
|
|
|
197
203
|
slotProps: PropTypes.object,
|
|
198
204
|
slots: PropTypes.object
|
|
199
205
|
}),
|
|
206
|
+
/**
|
|
207
|
+
* If `true`, a loading overlay is displayed.
|
|
208
|
+
*/
|
|
209
|
+
loading: PropTypes.bool,
|
|
200
210
|
/**
|
|
201
211
|
* The margin between the SVG and the drawing area.
|
|
202
212
|
* It's used for leaving some space for extra information such as the x- and y-axis or legend.
|
|
@@ -39,7 +39,7 @@ const PieArcLabelRoot = styled(animated.text, {
|
|
|
39
39
|
}));
|
|
40
40
|
/**
|
|
41
41
|
* Helper to compute label position.
|
|
42
|
-
* It's not an inline function because we need it in
|
|
42
|
+
* It's not an inline function because we need it in interpolation.
|
|
43
43
|
*/
|
|
44
44
|
const getLabelPosition = (formattedArcLabel, variable) => (startAngle, endAngle, padAngle, arcLabelRadius, cornerRadius) => {
|
|
45
45
|
if (!formattedArcLabel) {
|
|
@@ -129,7 +129,7 @@ process.env.NODE_ENV !== "production" ? PieArcLabelPlot.propTypes = {
|
|
|
129
129
|
value: PropTypes.number.isRequired
|
|
130
130
|
})).isRequired,
|
|
131
131
|
/**
|
|
132
|
-
* Override the arc
|
|
132
|
+
* Override the arc attributes when it is faded.
|
|
133
133
|
* @default { additionalRadius: -5 }
|
|
134
134
|
*/
|
|
135
135
|
faded: PropTypes.shape({
|
|
@@ -142,7 +142,7 @@ process.env.NODE_ENV !== "production" ? PieArcLabelPlot.propTypes = {
|
|
|
142
142
|
paddingAngle: PropTypes.number
|
|
143
143
|
}),
|
|
144
144
|
/**
|
|
145
|
-
* Override the arc
|
|
145
|
+
* Override the arc attributes when it is highlighted.
|
|
146
146
|
*/
|
|
147
147
|
highlighted: PropTypes.shape({
|
|
148
148
|
additionalRadius: PropTypes.number,
|
|
@@ -159,7 +159,7 @@ process.env.NODE_ENV !== "production" ? PieArcLabelPlot.propTypes = {
|
|
|
159
159
|
}),
|
|
160
160
|
id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
|
|
161
161
|
/**
|
|
162
|
-
* The radius between circle center and the
|
|
162
|
+
* The radius between circle center and the beginning of the arc.
|
|
163
163
|
* @default 0
|
|
164
164
|
*/
|
|
165
165
|
innerRadius: PropTypes.number,
|
|
@@ -109,7 +109,7 @@ process.env.NODE_ENV !== "production" ? PieArcPlot.propTypes = {
|
|
|
109
109
|
value: PropTypes.number.isRequired
|
|
110
110
|
})).isRequired,
|
|
111
111
|
/**
|
|
112
|
-
* Override the arc
|
|
112
|
+
* Override the arc attributes when it is faded.
|
|
113
113
|
* @default { additionalRadius: -5 }
|
|
114
114
|
*/
|
|
115
115
|
faded: PropTypes.shape({
|
|
@@ -122,7 +122,7 @@ process.env.NODE_ENV !== "production" ? PieArcPlot.propTypes = {
|
|
|
122
122
|
paddingAngle: PropTypes.number
|
|
123
123
|
}),
|
|
124
124
|
/**
|
|
125
|
-
* Override the arc
|
|
125
|
+
* Override the arc attributes when it is highlighted.
|
|
126
126
|
*/
|
|
127
127
|
highlighted: PropTypes.shape({
|
|
128
128
|
additionalRadius: PropTypes.number,
|
|
@@ -139,7 +139,7 @@ process.env.NODE_ENV !== "production" ? PieArcPlot.propTypes = {
|
|
|
139
139
|
}),
|
|
140
140
|
id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
|
|
141
141
|
/**
|
|
142
|
-
* The radius between circle center and the
|
|
142
|
+
* The radius between circle center and the beginning of the arc.
|
|
143
143
|
* @default 0
|
|
144
144
|
*/
|
|
145
145
|
innerRadius: PropTypes.number,
|
package/esm/PieChart/PieChart.js
CHANGED
|
@@ -9,6 +9,7 @@ import { ChartsLegend } from '../ChartsLegend';
|
|
|
9
9
|
import { ChartsAxisHighlight } from '../ChartsAxisHighlight';
|
|
10
10
|
import { PiePlot } from './PiePlot';
|
|
11
11
|
import { useIsRTL } from '../internals/useIsRTL';
|
|
12
|
+
import { ChartsOverlay } from '../ChartsOverlay/ChartsOverlay';
|
|
12
13
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
14
|
const defaultMargin = {
|
|
14
15
|
top: 5,
|
|
@@ -59,7 +60,8 @@ function PieChart(props) {
|
|
|
59
60
|
children,
|
|
60
61
|
slots,
|
|
61
62
|
slotProps,
|
|
62
|
-
onItemClick
|
|
63
|
+
onItemClick,
|
|
64
|
+
loading
|
|
63
65
|
} = props;
|
|
64
66
|
const isRTL = useIsRTL();
|
|
65
67
|
const margin = _extends({}, isRTL ? defaultRTLMargin : defaultMargin, marginProps);
|
|
@@ -98,10 +100,17 @@ function PieChart(props) {
|
|
|
98
100
|
slotProps: slotProps,
|
|
99
101
|
onItemClick: onItemClick,
|
|
100
102
|
skipAnimation: skipAnimation
|
|
103
|
+
}), /*#__PURE__*/_jsx(ChartsOverlay, {
|
|
104
|
+
loading: loading,
|
|
105
|
+
slots: slots,
|
|
106
|
+
slotProps: slotProps
|
|
101
107
|
}), /*#__PURE__*/_jsx(ChartsLegend, _extends({}, legend, {
|
|
102
108
|
slots: slots,
|
|
103
109
|
slotProps: slotProps
|
|
104
|
-
})), /*#__PURE__*/_jsx(ChartsAxisHighlight, _extends({}, axisHighlight)), /*#__PURE__*/_jsx(ChartsTooltip, _extends({}, tooltip
|
|
110
|
+
})), /*#__PURE__*/_jsx(ChartsAxisHighlight, _extends({}, axisHighlight)), !loading && /*#__PURE__*/_jsx(ChartsTooltip, _extends({}, tooltip, {
|
|
111
|
+
slots: slots,
|
|
112
|
+
slotProps: slotProps
|
|
113
|
+
})), children]
|
|
105
114
|
});
|
|
106
115
|
}
|
|
107
116
|
process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
|
|
@@ -168,6 +177,10 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
|
|
|
168
177
|
slotProps: PropTypes.object,
|
|
169
178
|
slots: PropTypes.object
|
|
170
179
|
}),
|
|
180
|
+
/**
|
|
181
|
+
* If `true`, a loading overlay is displayed.
|
|
182
|
+
*/
|
|
183
|
+
loading: PropTypes.bool,
|
|
171
184
|
/**
|
|
172
185
|
* The margin between the SVG and the drawing area.
|
|
173
186
|
* It's used for leaving some space for extra information such as the x- and y-axis or legend.
|
|
@@ -6,6 +6,7 @@ import { ResponsiveChartContainer } from '../ResponsiveChartContainer';
|
|
|
6
6
|
import { ChartsAxis } from '../ChartsAxis';
|
|
7
7
|
import { ChartsTooltip } from '../ChartsTooltip';
|
|
8
8
|
import { ChartsLegend } from '../ChartsLegend';
|
|
9
|
+
import { ChartsOverlay } from '../ChartsOverlay/ChartsOverlay';
|
|
9
10
|
import { ChartsAxisHighlight } from '../ChartsAxisHighlight';
|
|
10
11
|
import { ChartsVoronoiHandler } from '../ChartsVoronoiHandler/ChartsVoronoiHandler';
|
|
11
12
|
import { ChartsGrid } from '../ChartsGrid';
|
|
@@ -45,7 +46,8 @@ const ScatterChart = /*#__PURE__*/React.forwardRef(function ScatterChart(props,
|
|
|
45
46
|
onItemClick,
|
|
46
47
|
children,
|
|
47
48
|
slots,
|
|
48
|
-
slotProps
|
|
49
|
+
slotProps,
|
|
50
|
+
loading
|
|
49
51
|
} = props;
|
|
50
52
|
return /*#__PURE__*/_jsx(ResponsiveChartContainer, {
|
|
51
53
|
ref: ref,
|
|
@@ -78,13 +80,17 @@ const ScatterChart = /*#__PURE__*/React.forwardRef(function ScatterChart(props,
|
|
|
78
80
|
slots: slots,
|
|
79
81
|
slotProps: slotProps,
|
|
80
82
|
onItemClick: disableVoronoi ? onItemClick : undefined
|
|
83
|
+
}), /*#__PURE__*/_jsx(ChartsOverlay, {
|
|
84
|
+
loading: loading,
|
|
85
|
+
slots: slots,
|
|
86
|
+
slotProps: slotProps
|
|
81
87
|
}), /*#__PURE__*/_jsx(ChartsLegend, _extends({}, legend, {
|
|
82
88
|
slots: slots,
|
|
83
89
|
slotProps: slotProps
|
|
84
90
|
})), /*#__PURE__*/_jsx(ChartsAxisHighlight, _extends({
|
|
85
91
|
x: "none",
|
|
86
92
|
y: "none"
|
|
87
|
-
}, axisHighlight)), /*#__PURE__*/_jsx(ChartsTooltip, _extends({
|
|
93
|
+
}, axisHighlight)), !loading && /*#__PURE__*/_jsx(ChartsTooltip, _extends({
|
|
88
94
|
trigger: "item"
|
|
89
95
|
}, tooltip)), children]
|
|
90
96
|
})
|
|
@@ -164,6 +170,10 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
|
|
|
164
170
|
slotProps: PropTypes.object,
|
|
165
171
|
slots: PropTypes.object
|
|
166
172
|
}),
|
|
173
|
+
/**
|
|
174
|
+
* If `true`, a loading overlay is displayed.
|
|
175
|
+
*/
|
|
176
|
+
loading: PropTypes.bool,
|
|
167
177
|
/**
|
|
168
178
|
* The margin between the SVG and the drawing area.
|
|
169
179
|
* It's used for leaving some space for extra information such as the x- and y-axis or legend.
|
|
@@ -50,7 +50,7 @@ const formatSeries = (series, colors, dataset) => {
|
|
|
50
50
|
seriesGroups[type].seriesOrder.push(id);
|
|
51
51
|
});
|
|
52
52
|
const formattedSeries = {};
|
|
53
|
-
// Apply
|
|
53
|
+
// Apply formatter on a type group
|
|
54
54
|
Object.keys(seriesTypeFormatter).forEach(type => {
|
|
55
55
|
if (seriesGroups[type] !== undefined) {
|
|
56
56
|
formattedSeries[type] = seriesTypeFormatter[type]?.(seriesGroups[type], dataset) ?? seriesGroups[type];
|
|
@@ -5,7 +5,7 @@ import { useIsomorphicLayoutEffect, Globals } from '@react-spring/web';
|
|
|
5
5
|
* set skipAnimations to the value of the user's
|
|
6
6
|
* `prefers-reduced-motion` query.
|
|
7
7
|
*
|
|
8
|
-
* The return value, post-effect, is the value of their
|
|
8
|
+
* The return value, post-effect, is the value of their preferred setting
|
|
9
9
|
*/
|
|
10
10
|
export const useReducedMotion = () => {
|
|
11
11
|
// Taken from: https://github.com/pmndrs/react-spring/blob/02ec877bbfab0df46da0e4a47d5f68d3e731206a/packages/shared/src/hooks/useReducedMotion.ts#L13
|
package/esm/hooks/useScale.js
CHANGED
|
@@ -3,7 +3,7 @@ import { CartesianContext } from '../context/CartesianContextProvider';
|
|
|
3
3
|
import { isBandScale } from '../internals/isBandScale';
|
|
4
4
|
/**
|
|
5
5
|
* For a given scale return a function that map value to their position.
|
|
6
|
-
*
|
|
6
|
+
* Useful when dealing with specific scale such as band.
|
|
7
7
|
* @param scale The scale to use
|
|
8
8
|
* @returns (value: any) => number
|
|
9
9
|
*/
|
package/esm/hooks/useTicks.js
CHANGED
|
@@ -59,6 +59,10 @@ export function useTicks(options) {
|
|
|
59
59
|
labelOffset: 0
|
|
60
60
|
}));
|
|
61
61
|
}
|
|
62
|
+
if (scale.domain().length === 0 || scale.domain()[0] === scale.domain()[1]) {
|
|
63
|
+
// The axis should not be visible, so ticks should also be hidden.
|
|
64
|
+
return [];
|
|
65
|
+
}
|
|
62
66
|
const ticks = typeof tickInterval === 'object' ? tickInterval : scale.ticks(tickNumber);
|
|
63
67
|
return ticks.map(value => ({
|
|
64
68
|
value,
|
|
@@ -9,7 +9,7 @@ export function useChartGradient() {
|
|
|
9
9
|
const {
|
|
10
10
|
chartId
|
|
11
11
|
} = React.useContext(DrawingContext);
|
|
12
|
-
return React.useCallback((axisId, direction) => `${chartId}-
|
|
12
|
+
return React.useCallback((axisId, direction) => `${chartId}-gradient-${direction}-${axisId}`, [chartId]);
|
|
13
13
|
}
|
|
14
14
|
export function ChartsAxesGradients() {
|
|
15
15
|
const {
|
|
@@ -40,7 +40,7 @@ export function ChartsAxesGradients() {
|
|
|
40
40
|
} = yAxis[axisId];
|
|
41
41
|
if (colorMap?.type === 'piecewise') {
|
|
42
42
|
return /*#__PURE__*/_jsx(ChartsPiecewiseGradient, {
|
|
43
|
-
|
|
43
|
+
isReversed: !reverse,
|
|
44
44
|
scale: scale,
|
|
45
45
|
colorMap: colorMap,
|
|
46
46
|
size: svgHeight,
|
|
@@ -50,7 +50,7 @@ export function ChartsAxesGradients() {
|
|
|
50
50
|
}
|
|
51
51
|
if (colorMap?.type === 'continuous') {
|
|
52
52
|
return /*#__PURE__*/_jsx(ChartsContinuousGradient, {
|
|
53
|
-
|
|
53
|
+
isReversed: !reverse,
|
|
54
54
|
scale: scale,
|
|
55
55
|
colorScale: colorScale,
|
|
56
56
|
colorMap: colorMap,
|
|
@@ -70,7 +70,7 @@ export function ChartsAxesGradients() {
|
|
|
70
70
|
} = xAxis[axisId];
|
|
71
71
|
if (colorMap?.type === 'piecewise') {
|
|
72
72
|
return /*#__PURE__*/_jsx(ChartsPiecewiseGradient, {
|
|
73
|
-
|
|
73
|
+
isReversed: reverse,
|
|
74
74
|
scale: scale,
|
|
75
75
|
colorMap: colorMap,
|
|
76
76
|
size: svgWidth,
|
|
@@ -80,7 +80,7 @@ export function ChartsAxesGradients() {
|
|
|
80
80
|
}
|
|
81
81
|
if (colorMap?.type === 'continuous') {
|
|
82
82
|
return /*#__PURE__*/_jsx(ChartsContinuousGradient, {
|
|
83
|
-
|
|
83
|
+
isReversed: reverse,
|
|
84
84
|
scale: scale,
|
|
85
85
|
colorScale: colorScale,
|
|
86
86
|
colorMap: colorMap,
|
|
@@ -4,7 +4,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
4
4
|
const PX_PRECISION = 10;
|
|
5
5
|
export default function ChartsContinuousGradient(props) {
|
|
6
6
|
const {
|
|
7
|
-
|
|
7
|
+
isReversed,
|
|
8
8
|
gradientId,
|
|
9
9
|
size,
|
|
10
10
|
direction,
|
|
@@ -26,7 +26,7 @@ export default function ChartsContinuousGradient(props) {
|
|
|
26
26
|
x2: "0",
|
|
27
27
|
y1: "0",
|
|
28
28
|
y2: "0",
|
|
29
|
-
[`${direction}${
|
|
29
|
+
[`${direction}${isReversed ? 1 : 2}`]: `${size}px`,
|
|
30
30
|
gradientUnits: "userSpaceOnUse" // Use the SVG coordinate instead of the component ones.
|
|
31
31
|
,
|
|
32
32
|
children: Array.from({
|
|
@@ -40,7 +40,7 @@ export default function ChartsContinuousGradient(props) {
|
|
|
40
40
|
if (x === undefined) {
|
|
41
41
|
return null;
|
|
42
42
|
}
|
|
43
|
-
const offset =
|
|
43
|
+
const offset = isReversed ? 1 - x / size : x / size;
|
|
44
44
|
const color = colorScale(value);
|
|
45
45
|
if (color === null) {
|
|
46
46
|
return null;
|
|
@@ -2,7 +2,7 @@ import * as React from 'react';
|
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
export default function ChartsPiecewiseGradient(props) {
|
|
4
4
|
const {
|
|
5
|
-
|
|
5
|
+
isReversed,
|
|
6
6
|
gradientId,
|
|
7
7
|
size,
|
|
8
8
|
direction,
|
|
@@ -15,7 +15,7 @@ export default function ChartsPiecewiseGradient(props) {
|
|
|
15
15
|
x2: "0",
|
|
16
16
|
y1: "0",
|
|
17
17
|
y2: "0",
|
|
18
|
-
[`${direction}${
|
|
18
|
+
[`${direction}${isReversed ? 1 : 2}`]: `${size}px`,
|
|
19
19
|
gradientUnits: "userSpaceOnUse" // Use the SVG coordinate instead of the component ones.
|
|
20
20
|
,
|
|
21
21
|
children: colorMap.thresholds.map((threshold, index) => {
|
|
@@ -23,7 +23,7 @@ export default function ChartsPiecewiseGradient(props) {
|
|
|
23
23
|
if (x === undefined) {
|
|
24
24
|
return null;
|
|
25
25
|
}
|
|
26
|
-
const offset =
|
|
26
|
+
const offset = isReversed ? 1 - x / size : x / size;
|
|
27
27
|
return /*#__PURE__*/_jsxs(React.Fragment, {
|
|
28
28
|
children: [/*#__PURE__*/_jsx("stop", {
|
|
29
29
|
offset: offset,
|
package/esm/internals/utils.js
CHANGED
|
@@ -4,7 +4,7 @@ export function getSymbol(shape) {
|
|
|
4
4
|
return symbolNames.indexOf(shape) || 0;
|
|
5
5
|
}
|
|
6
6
|
/**
|
|
7
|
-
* Transform mouse event position to
|
|
7
|
+
* Transform mouse event position to coordinates inside the SVG.
|
|
8
8
|
* @param svg The SVG element
|
|
9
9
|
* @param event The mouseEvent to transform
|
|
10
10
|
*/
|
|
@@ -3,6 +3,6 @@
|
|
|
3
3
|
* set skipAnimations to the value of the user's
|
|
4
4
|
* `prefers-reduced-motion` query.
|
|
5
5
|
*
|
|
6
|
-
* The return value, post-effect, is the value of their
|
|
6
|
+
* The return value, post-effect, is the value of their preferred setting
|
|
7
7
|
*/
|
|
8
8
|
export declare const useReducedMotion: () => void;
|
|
@@ -10,7 +10,7 @@ var _web = require("@react-spring/web");
|
|
|
10
10
|
* set skipAnimations to the value of the user's
|
|
11
11
|
* `prefers-reduced-motion` query.
|
|
12
12
|
*
|
|
13
|
-
* The return value, post-effect, is the value of their
|
|
13
|
+
* The return value, post-effect, is the value of their preferred setting
|
|
14
14
|
*/
|
|
15
15
|
const useReducedMotion = () => {
|
|
16
16
|
// Taken from: https://github.com/pmndrs/react-spring/blob/02ec877bbfab0df46da0e4a47d5f68d3e731206a/packages/shared/src/hooks/useReducedMotion.ts#L13
|
package/hooks/useScale.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { D3Scale } from '../models/axis';
|
|
1
|
+
import { AxisScaleConfig, D3Scale, ScaleName } from '../models/axis';
|
|
2
2
|
/**
|
|
3
3
|
* For a given scale return a function that map value to their position.
|
|
4
|
-
*
|
|
4
|
+
* Useful when dealing with specific scale such as band.
|
|
5
5
|
* @param scale The scale to use
|
|
6
6
|
* @returns (value: any) => number
|
|
7
7
|
*/
|
|
8
8
|
export declare function getValueToPositionMapper(scale: D3Scale): (value: any) => number;
|
|
9
|
-
export declare function useXScale(identifier?: number | string):
|
|
10
|
-
export declare function useYScale(identifier?: number | string):
|
|
9
|
+
export declare function useXScale<S extends ScaleName>(identifier?: number | string): AxisScaleConfig[S]['scale'];
|
|
10
|
+
export declare function useYScale<S extends ScaleName>(identifier?: number | string): AxisScaleConfig[S]['scale'];
|
package/hooks/useScale.js
CHANGED
|
@@ -13,7 +13,7 @@ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return
|
|
|
13
13
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
14
14
|
/**
|
|
15
15
|
* For a given scale return a function that map value to their position.
|
|
16
|
-
*
|
|
16
|
+
* Useful when dealing with specific scale such as band.
|
|
17
17
|
* @param scale The scale to use
|
|
18
18
|
* @returns (value: any) => number
|
|
19
19
|
*/
|
package/hooks/useTicks.js
CHANGED
|
@@ -68,6 +68,10 @@ function useTicks(options) {
|
|
|
68
68
|
labelOffset: 0
|
|
69
69
|
}));
|
|
70
70
|
}
|
|
71
|
+
if (scale.domain().length === 0 || scale.domain()[0] === scale.domain()[1]) {
|
|
72
|
+
// The axis should not be visible, so ticks should also be hidden.
|
|
73
|
+
return [];
|
|
74
|
+
}
|
|
71
75
|
const ticks = typeof tickInterval === 'object' ? tickInterval : scale.ticks(tickNumber);
|
|
72
76
|
return ticks.map(value => ({
|
|
73
77
|
value,
|
package/index.js
CHANGED
|
@@ -19,7 +19,7 @@ function useChartGradient() {
|
|
|
19
19
|
const {
|
|
20
20
|
chartId
|
|
21
21
|
} = React.useContext(_DrawingProvider.DrawingContext);
|
|
22
|
-
return React.useCallback((axisId, direction) => `${chartId}-
|
|
22
|
+
return React.useCallback((axisId, direction) => `${chartId}-gradient-${direction}-${axisId}`, [chartId]);
|
|
23
23
|
}
|
|
24
24
|
function ChartsAxesGradients() {
|
|
25
25
|
const {
|
|
@@ -50,7 +50,7 @@ function ChartsAxesGradients() {
|
|
|
50
50
|
} = yAxis[axisId];
|
|
51
51
|
if (colorMap?.type === 'piecewise') {
|
|
52
52
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsPiecewiseGradient.default, {
|
|
53
|
-
|
|
53
|
+
isReversed: !reverse,
|
|
54
54
|
scale: scale,
|
|
55
55
|
colorMap: colorMap,
|
|
56
56
|
size: svgHeight,
|
|
@@ -60,7 +60,7 @@ function ChartsAxesGradients() {
|
|
|
60
60
|
}
|
|
61
61
|
if (colorMap?.type === 'continuous') {
|
|
62
62
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsContinuousGradient.default, {
|
|
63
|
-
|
|
63
|
+
isReversed: !reverse,
|
|
64
64
|
scale: scale,
|
|
65
65
|
colorScale: colorScale,
|
|
66
66
|
colorMap: colorMap,
|
|
@@ -80,7 +80,7 @@ function ChartsAxesGradients() {
|
|
|
80
80
|
} = xAxis[axisId];
|
|
81
81
|
if (colorMap?.type === 'piecewise') {
|
|
82
82
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsPiecewiseGradient.default, {
|
|
83
|
-
|
|
83
|
+
isReversed: reverse,
|
|
84
84
|
scale: scale,
|
|
85
85
|
colorMap: colorMap,
|
|
86
86
|
size: svgWidth,
|
|
@@ -90,7 +90,7 @@ function ChartsAxesGradients() {
|
|
|
90
90
|
}
|
|
91
91
|
if (colorMap?.type === 'continuous') {
|
|
92
92
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsContinuousGradient.default, {
|
|
93
|
-
|
|
93
|
+
isReversed: reverse,
|
|
94
94
|
scale: scale,
|
|
95
95
|
colorScale: colorScale,
|
|
96
96
|
colorMap: colorMap,
|
|
@@ -12,7 +12,7 @@ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e;
|
|
|
12
12
|
const PX_PRECISION = 10;
|
|
13
13
|
function ChartsContinuousGradient(props) {
|
|
14
14
|
const {
|
|
15
|
-
|
|
15
|
+
isReversed,
|
|
16
16
|
gradientId,
|
|
17
17
|
size,
|
|
18
18
|
direction,
|
|
@@ -34,7 +34,7 @@ function ChartsContinuousGradient(props) {
|
|
|
34
34
|
x2: "0",
|
|
35
35
|
y1: "0",
|
|
36
36
|
y2: "0",
|
|
37
|
-
[`${direction}${
|
|
37
|
+
[`${direction}${isReversed ? 1 : 2}`]: `${size}px`,
|
|
38
38
|
gradientUnits: "userSpaceOnUse" // Use the SVG coordinate instead of the component ones.
|
|
39
39
|
,
|
|
40
40
|
children: Array.from({
|
|
@@ -48,7 +48,7 @@ function ChartsContinuousGradient(props) {
|
|
|
48
48
|
if (x === undefined) {
|
|
49
49
|
return null;
|
|
50
50
|
}
|
|
51
|
-
const offset =
|
|
51
|
+
const offset = isReversed ? 1 - x / size : x / size;
|
|
52
52
|
const color = colorScale(value);
|
|
53
53
|
if (color === null) {
|
|
54
54
|
return null;
|
|
@@ -10,7 +10,7 @@ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return
|
|
|
10
10
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
11
11
|
function ChartsPiecewiseGradient(props) {
|
|
12
12
|
const {
|
|
13
|
-
|
|
13
|
+
isReversed,
|
|
14
14
|
gradientId,
|
|
15
15
|
size,
|
|
16
16
|
direction,
|
|
@@ -23,7 +23,7 @@ function ChartsPiecewiseGradient(props) {
|
|
|
23
23
|
x2: "0",
|
|
24
24
|
y1: "0",
|
|
25
25
|
y2: "0",
|
|
26
|
-
[`${direction}${
|
|
26
|
+
[`${direction}${isReversed ? 1 : 2}`]: `${size}px`,
|
|
27
27
|
gradientUnits: "userSpaceOnUse" // Use the SVG coordinate instead of the component ones.
|
|
28
28
|
,
|
|
29
29
|
children: colorMap.thresholds.map((threshold, index) => {
|
|
@@ -31,7 +31,7 @@ function ChartsPiecewiseGradient(props) {
|
|
|
31
31
|
if (x === undefined) {
|
|
32
32
|
return null;
|
|
33
33
|
}
|
|
34
|
-
const offset =
|
|
34
|
+
const offset = isReversed ? 1 - x / size : x / size;
|
|
35
35
|
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(React.Fragment, {
|
|
36
36
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("stop", {
|
|
37
37
|
offset: offset,
|
package/internals/utils.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ type Without<T, U> = {
|
|
|
5
5
|
};
|
|
6
6
|
export type XOR<T, U> = T | U extends object ? (Without<T, U> & U) | (Without<U, T> & T) : T | U;
|
|
7
7
|
/**
|
|
8
|
-
* Transform mouse event position to
|
|
8
|
+
* Transform mouse event position to coordinates inside the SVG.
|
|
9
9
|
* @param svg The SVG element
|
|
10
10
|
* @param event The mouseEvent to transform
|
|
11
11
|
*/
|