@mui/x-charts 6.0.0-alpha.15 → 6.0.0-alpha.16
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 +13 -2
- package/BarChart/BarChart.js +45 -3
- package/BarChart/BarElement.d.ts +1318 -3
- package/BarChart/BarElement.js +10 -8
- package/BarChart/BarPlot.d.ts +17 -1
- package/BarChart/BarPlot.js +152 -66
- package/CHANGELOG.md +65 -0
- package/ChartContainer/index.js +5 -2
- package/ChartsAxis/ChartsAxis.js +18 -2
- package/ChartsAxis/axisClasses.d.ts +1 -1
- package/ChartsAxisHighlight/ChartsAxisHighlight.js +2 -2
- package/ChartsClipPath/ChartsClipPath.js +2 -2
- package/ChartsLegend/ChartsLegend.d.ts +2 -1
- package/ChartsLegend/ChartsLegend.js +12 -8
- package/ChartsSurface.js +2 -2
- package/ChartsTooltip/ChartsAxisTooltipContent.js +2 -2
- package/ChartsTooltip/ChartsItemTooltipContent.js +2 -2
- package/ChartsTooltip/ChartsTooltip.js +2 -2
- package/ChartsTooltip/utils.js +2 -2
- package/ChartsXAxis/ChartsXAxis.js +123 -35
- package/ChartsYAxis/ChartsYAxis.js +38 -16
- package/LineChart/AreaElement.d.ts +10 -0
- package/LineChart/AreaElement.js +12 -2
- package/LineChart/AreaPlot.d.ts +11 -0
- package/LineChart/AreaPlot.js +13 -2
- package/LineChart/LineChart.d.ts +10 -0
- package/LineChart/LineChart.js +36 -2
- package/LineChart/LineElement.d.ts +10 -0
- package/LineChart/LineElement.js +12 -2
- package/LineChart/LineHighlightElement.d.ts +10 -0
- package/LineChart/LineHighlightElement.js +12 -2
- package/LineChart/LineHighlightPlot.d.ts +10 -0
- package/LineChart/LineHighlightPlot.js +12 -2
- package/LineChart/LinePlot.d.ts +10 -0
- package/LineChart/LinePlot.js +12 -2
- package/LineChart/MarkElement.d.ts +10 -0
- package/LineChart/MarkElement.js +12 -2
- package/LineChart/MarkPlot.d.ts +10 -0
- package/LineChart/MarkPlot.js +12 -2
- package/PieChart/PieArc.js +2 -2
- package/PieChart/PieArcLabel.js +2 -2
- package/PieChart/PieChart.d.ts +10 -0
- package/PieChart/PieChart.js +37 -2
- package/PieChart/PiePlot.d.ts +10 -0
- package/PieChart/PiePlot.js +12 -2
- package/ResponsiveChartContainer/index.js +4 -4
- package/ScatterChart/Scatter.d.ts +10 -0
- package/ScatterChart/Scatter.js +12 -2
- package/ScatterChart/ScatterChart.d.ts +10 -0
- package/ScatterChart/ScatterChart.js +36 -2
- package/ScatterChart/ScatterPlot.d.ts +10 -0
- package/ScatterChart/ScatterPlot.js +12 -2
- package/SparkLineChart/SparkLineChart.d.ts +9 -0
- package/SparkLineChart/SparkLineChart.js +16 -2
- package/context/CartesianContextProvider.js +10 -2
- package/context/DrawingProvider.js +2 -2
- package/context/HighlightProvider.js +2 -2
- package/context/InteractionProvider.js +2 -2
- package/context/SeriesContextProvider.js +2 -2
- package/esm/BarChart/BarChart.js +43 -1
- package/esm/BarChart/BarElement.js +7 -4
- package/esm/BarChart/BarPlot.js +152 -67
- package/esm/ChartContainer/index.js +3 -0
- package/esm/ChartsAxis/ChartsAxis.js +16 -0
- package/esm/ChartsLegend/ChartsLegend.js +10 -6
- package/esm/ChartsXAxis/ChartsXAxis.js +122 -34
- package/esm/ChartsYAxis/ChartsYAxis.js +36 -14
- package/esm/LineChart/AreaElement.js +10 -0
- package/esm/LineChart/AreaPlot.js +11 -0
- package/esm/LineChart/LineChart.js +34 -0
- package/esm/LineChart/LineElement.js +10 -0
- package/esm/LineChart/LineHighlightElement.js +10 -0
- package/esm/LineChart/LineHighlightPlot.js +10 -0
- package/esm/LineChart/LinePlot.js +10 -0
- package/esm/LineChart/MarkElement.js +10 -0
- package/esm/LineChart/MarkPlot.js +10 -0
- package/esm/PieChart/PieChart.js +35 -0
- package/esm/PieChart/PiePlot.js +10 -0
- package/esm/ResponsiveChartContainer/index.js +2 -2
- package/esm/ScatterChart/Scatter.js +10 -0
- package/esm/ScatterChart/ScatterChart.js +34 -0
- package/esm/ScatterChart/ScatterPlot.js +10 -0
- package/esm/SparkLineChart/SparkLineChart.js +14 -0
- package/esm/context/CartesianContextProvider.js +8 -0
- package/esm/hooks/useMounted.js +16 -0
- package/esm/hooks/useReducedMotion.js +27 -0
- package/esm/hooks/useTicks.js +12 -6
- package/esm/internals/components/ChartsText.js +17 -13
- package/esm/internals/geometry.js +36 -0
- package/hooks/useAxisEvents.js +2 -2
- package/hooks/useChartDimensions.js +2 -2
- package/hooks/useDrawingArea.js +2 -2
- package/hooks/useInteractionItemProps.js +2 -2
- package/hooks/useMounted.d.ts +1 -0
- package/hooks/useMounted.js +25 -0
- package/hooks/useReducedMotion.d.ts +8 -0
- package/hooks/useReducedMotion.js +33 -0
- package/hooks/useScale.d.ts +2 -2
- package/hooks/useScale.js +2 -2
- package/hooks/useTicks.d.ts +18 -9
- package/hooks/useTicks.js +14 -8
- package/index.js +1 -1
- package/internals/components/ChartsText.d.ts +11 -8
- package/internals/components/ChartsText.js +19 -15
- package/internals/defaultizeColor.d.ts +1 -1
- package/internals/domUtils.d.ts +0 -1
- package/internals/geometry.d.ts +9 -0
- package/internals/geometry.js +42 -0
- package/legacy/BarChart/BarChart.js +43 -1
- package/legacy/BarChart/BarElement.js +6 -3
- package/legacy/BarChart/BarPlot.js +151 -63
- package/legacy/ChartContainer/index.js +3 -0
- package/legacy/ChartsAxis/ChartsAxis.js +16 -0
- package/legacy/ChartsLegend/ChartsLegend.js +14 -7
- package/legacy/ChartsXAxis/ChartsXAxis.js +126 -36
- package/legacy/ChartsYAxis/ChartsYAxis.js +36 -14
- package/legacy/LineChart/AreaElement.js +10 -0
- package/legacy/LineChart/AreaPlot.js +11 -0
- package/legacy/LineChart/LineChart.js +34 -0
- package/legacy/LineChart/LineElement.js +10 -0
- package/legacy/LineChart/LineHighlightElement.js +10 -0
- package/legacy/LineChart/LineHighlightPlot.js +10 -0
- package/legacy/LineChart/LinePlot.js +10 -0
- package/legacy/LineChart/MarkElement.js +10 -0
- package/legacy/LineChart/MarkPlot.js +10 -0
- package/legacy/PieChart/PieChart.js +35 -0
- package/legacy/PieChart/PiePlot.js +10 -0
- package/legacy/ResponsiveChartContainer/index.js +2 -2
- package/legacy/ScatterChart/Scatter.js +10 -0
- package/legacy/ScatterChart/ScatterChart.js +34 -0
- package/legacy/ScatterChart/ScatterPlot.js +10 -0
- package/legacy/SparkLineChart/SparkLineChart.js +14 -0
- package/legacy/context/CartesianContextProvider.js +8 -0
- package/legacy/hooks/useMounted.js +21 -0
- package/legacy/hooks/useReducedMotion.js +27 -0
- package/legacy/hooks/useTicks.js +13 -6
- package/legacy/index.js +1 -1
- package/legacy/internals/components/ChartsText.js +15 -15
- package/legacy/internals/geometry.js +37 -0
- package/models/axis.d.ts +19 -2
- package/models/seriesType/line.d.ts +2 -2
- package/modern/BarChart/BarChart.js +43 -1
- package/modern/BarChart/BarElement.js +7 -4
- package/modern/BarChart/BarPlot.js +149 -65
- package/modern/ChartContainer/index.js +3 -0
- package/modern/ChartsAxis/ChartsAxis.js +16 -0
- package/modern/ChartsLegend/ChartsLegend.js +10 -6
- package/modern/ChartsXAxis/ChartsXAxis.js +122 -34
- package/modern/ChartsYAxis/ChartsYAxis.js +36 -14
- package/modern/LineChart/AreaElement.js +10 -0
- package/modern/LineChart/AreaPlot.js +11 -0
- package/modern/LineChart/LineChart.js +34 -0
- package/modern/LineChart/LineElement.js +10 -0
- package/modern/LineChart/LineHighlightElement.js +10 -0
- package/modern/LineChart/LineHighlightPlot.js +10 -0
- package/modern/LineChart/LinePlot.js +10 -0
- package/modern/LineChart/MarkElement.js +10 -0
- package/modern/LineChart/MarkPlot.js +10 -0
- package/modern/PieChart/PieChart.js +35 -0
- package/modern/PieChart/PiePlot.js +10 -0
- package/modern/ResponsiveChartContainer/index.js +2 -2
- package/modern/ScatterChart/Scatter.js +10 -0
- package/modern/ScatterChart/ScatterChart.js +34 -0
- package/modern/ScatterChart/ScatterPlot.js +10 -0
- package/modern/SparkLineChart/SparkLineChart.js +14 -0
- package/modern/context/CartesianContextProvider.js +8 -0
- package/modern/hooks/useMounted.js +16 -0
- package/modern/hooks/useReducedMotion.js +27 -0
- package/modern/hooks/useTicks.js +12 -6
- package/modern/index.js +1 -1
- package/modern/internals/components/ChartsText.js +17 -13
- package/modern/internals/geometry.js +36 -0
- package/package.json +5 -3
|
@@ -15,6 +15,16 @@ var SPARKLINE_DEFAULT_MARGIN = {
|
|
|
15
15
|
left: 5,
|
|
16
16
|
right: 5
|
|
17
17
|
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Demos:
|
|
21
|
+
*
|
|
22
|
+
* - [SparkLine](https://mui.com/x/react-charts/sparkline/)
|
|
23
|
+
*
|
|
24
|
+
* API:
|
|
25
|
+
*
|
|
26
|
+
* - [SparkLineChart API](https://mui.com/x/api/charts/spark-line-chart/)
|
|
27
|
+
*/
|
|
18
28
|
var SparkLineChart = /*#__PURE__*/React.forwardRef(function SparkLineChart(props, ref) {
|
|
19
29
|
var xAxis = props.xAxis,
|
|
20
30
|
width = props.width,
|
|
@@ -201,6 +211,7 @@ process.env.NODE_ENV !== "production" ? SparkLineChart.propTypes = {
|
|
|
201
211
|
id: PropTypes.string,
|
|
202
212
|
label: PropTypes.string,
|
|
203
213
|
labelFontSize: PropTypes.number,
|
|
214
|
+
labelStyle: PropTypes.object,
|
|
204
215
|
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
205
216
|
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
206
217
|
position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
|
|
@@ -209,6 +220,9 @@ process.env.NODE_ENV !== "production" ? SparkLineChart.propTypes = {
|
|
|
209
220
|
slots: PropTypes.object,
|
|
210
221
|
stroke: PropTypes.string,
|
|
211
222
|
tickFontSize: PropTypes.number,
|
|
223
|
+
tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
|
|
224
|
+
tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
|
|
225
|
+
tickLabelStyle: PropTypes.object,
|
|
212
226
|
tickMaxStep: PropTypes.number,
|
|
213
227
|
tickMinStep: PropTypes.number,
|
|
214
228
|
tickNumber: PropTypes.number,
|
|
@@ -256,6 +256,7 @@ process.env.NODE_ENV !== "production" ? CartesianContextProvider.propTypes = {
|
|
|
256
256
|
id: PropTypes.string,
|
|
257
257
|
label: PropTypes.string,
|
|
258
258
|
labelFontSize: PropTypes.number,
|
|
259
|
+
labelStyle: PropTypes.object,
|
|
259
260
|
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
260
261
|
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
261
262
|
position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
|
|
@@ -264,6 +265,9 @@ process.env.NODE_ENV !== "production" ? CartesianContextProvider.propTypes = {
|
|
|
264
265
|
slots: PropTypes.object,
|
|
265
266
|
stroke: PropTypes.string,
|
|
266
267
|
tickFontSize: PropTypes.number,
|
|
268
|
+
tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
|
|
269
|
+
tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
|
|
270
|
+
tickLabelStyle: PropTypes.object,
|
|
267
271
|
tickMaxStep: PropTypes.number,
|
|
268
272
|
tickMinStep: PropTypes.number,
|
|
269
273
|
tickNumber: PropTypes.number,
|
|
@@ -282,6 +286,7 @@ process.env.NODE_ENV !== "production" ? CartesianContextProvider.propTypes = {
|
|
|
282
286
|
id: PropTypes.string,
|
|
283
287
|
label: PropTypes.string,
|
|
284
288
|
labelFontSize: PropTypes.number,
|
|
289
|
+
labelStyle: PropTypes.object,
|
|
285
290
|
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
286
291
|
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
287
292
|
position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
|
|
@@ -290,6 +295,9 @@ process.env.NODE_ENV !== "production" ? CartesianContextProvider.propTypes = {
|
|
|
290
295
|
slots: PropTypes.object,
|
|
291
296
|
stroke: PropTypes.string,
|
|
292
297
|
tickFontSize: PropTypes.number,
|
|
298
|
+
tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
|
|
299
|
+
tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
|
|
300
|
+
tickLabelStyle: PropTypes.object,
|
|
293
301
|
tickMaxStep: PropTypes.number,
|
|
294
302
|
tickMinStep: PropTypes.number,
|
|
295
303
|
tickNumber: PropTypes.number,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
|
|
4
|
+
export function useMounted() {
|
|
5
|
+
var defer = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
6
|
+
var _React$useState = React.useState(false),
|
|
7
|
+
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
8
|
+
mountedState = _React$useState2[0],
|
|
9
|
+
setMountedState = _React$useState2[1];
|
|
10
|
+
useEnhancedEffect(function () {
|
|
11
|
+
if (!defer) {
|
|
12
|
+
setMountedState(true);
|
|
13
|
+
}
|
|
14
|
+
}, [defer]);
|
|
15
|
+
React.useEffect(function () {
|
|
16
|
+
if (defer) {
|
|
17
|
+
setMountedState(true);
|
|
18
|
+
}
|
|
19
|
+
}, [defer]);
|
|
20
|
+
return mountedState;
|
|
21
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { useIsomorphicLayoutEffect, Globals } from '@react-spring/web';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns `boolean` or `null`, used to automatically
|
|
5
|
+
* set skipAnimations to the value of the user's
|
|
6
|
+
* `prefers-reduced-motion` query.
|
|
7
|
+
*
|
|
8
|
+
* The return value, post-effect, is the value of their prefered setting
|
|
9
|
+
*/
|
|
10
|
+
export var useReducedMotion = function useReducedMotion() {
|
|
11
|
+
// Taken from: https://github.com/pmndrs/react-spring/blob/02ec877bbfab0df46da0e4a47d5f68d3e731206a/packages/shared/src/hooks/useReducedMotion.ts#L13
|
|
12
|
+
|
|
13
|
+
useIsomorphicLayoutEffect(function () {
|
|
14
|
+
var mql = window.matchMedia('(prefers-reduced-motion)');
|
|
15
|
+
var handleMediaChange = function handleMediaChange(e) {
|
|
16
|
+
Globals.assign({
|
|
17
|
+
// Modification such the react-spring implementation such that this hook can remove animation but never activate animation.
|
|
18
|
+
skipAnimation: e.matches || undefined
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
handleMediaChange(mql);
|
|
22
|
+
mql.addEventListener('change', handleMediaChange);
|
|
23
|
+
return function () {
|
|
24
|
+
mql.removeEventListener('change', handleMediaChange);
|
|
25
|
+
};
|
|
26
|
+
}, []);
|
|
27
|
+
};
|
package/legacy/hooks/useTicks.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _typeof from "@babel/runtime/helpers/esm/typeof";
|
|
1
2
|
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
2
3
|
import * as React from 'react';
|
|
3
4
|
import { isBandScale } from '../internals/isBandScale';
|
|
@@ -15,7 +16,8 @@ export function getTickNumber(params) {
|
|
|
15
16
|
function useTicks(options) {
|
|
16
17
|
var scale = options.scale,
|
|
17
18
|
tickNumber = options.tickNumber,
|
|
18
|
-
valueFormatter = options.valueFormatter
|
|
19
|
+
valueFormatter = options.valueFormatter,
|
|
20
|
+
tickInterval = options.tickInterval;
|
|
19
21
|
return React.useMemo(function () {
|
|
20
22
|
// band scale
|
|
21
23
|
if (isBandScale(scale)) {
|
|
@@ -25,7 +27,8 @@ function useTicks(options) {
|
|
|
25
27
|
return [].concat(_toConsumableArray(domain.map(function (value) {
|
|
26
28
|
var _valueFormatter;
|
|
27
29
|
return {
|
|
28
|
-
|
|
30
|
+
value: value,
|
|
31
|
+
formattedValue: (_valueFormatter = valueFormatter == null ? void 0 : valueFormatter(value)) != null ? _valueFormatter : "".concat(value),
|
|
29
32
|
offset: scale(value) - (scale.step() - scale.bandwidth()) / 2,
|
|
30
33
|
labelOffset: scale.step() / 2
|
|
31
34
|
};
|
|
@@ -37,23 +40,27 @@ function useTicks(options) {
|
|
|
37
40
|
}
|
|
38
41
|
|
|
39
42
|
// scale type = 'point'
|
|
40
|
-
|
|
43
|
+
var filteredDomain = typeof tickInterval === 'function' && domain.filter(tickInterval) || _typeof(tickInterval) === 'object' && tickInterval || domain;
|
|
44
|
+
return filteredDomain.map(function (value) {
|
|
41
45
|
var _valueFormatter2;
|
|
42
46
|
return {
|
|
43
|
-
|
|
47
|
+
value: value,
|
|
48
|
+
formattedValue: (_valueFormatter2 = valueFormatter == null ? void 0 : valueFormatter(value)) != null ? _valueFormatter2 : "".concat(value),
|
|
44
49
|
offset: scale(value),
|
|
45
50
|
labelOffset: 0
|
|
46
51
|
};
|
|
47
52
|
});
|
|
48
53
|
}
|
|
49
|
-
|
|
54
|
+
var ticks = _typeof(tickInterval) === 'object' ? tickInterval : scale.ticks(tickNumber);
|
|
55
|
+
return ticks.map(function (value) {
|
|
50
56
|
var _valueFormatter3;
|
|
51
57
|
return {
|
|
58
|
+
value: value,
|
|
52
59
|
formattedValue: (_valueFormatter3 = valueFormatter == null ? void 0 : valueFormatter(value)) != null ? _valueFormatter3 : scale.tickFormat(tickNumber)(value),
|
|
53
60
|
offset: scale(value),
|
|
54
61
|
labelOffset: 0
|
|
55
62
|
};
|
|
56
63
|
});
|
|
57
|
-
}, [tickNumber, scale, valueFormatter]);
|
|
64
|
+
}, [tickNumber, scale, valueFormatter, tickInterval]);
|
|
58
65
|
}
|
|
59
66
|
export default useTicks;
|
package/legacy/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
2
2
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
3
|
-
var _excluded = ["x", "y", "
|
|
3
|
+
var _excluded = ["x", "y", "style", "text", "ownerState"],
|
|
4
|
+
_excluded2 = ["angle", "textAnchor", "dominantBaseline"];
|
|
4
5
|
import * as React from 'react';
|
|
5
6
|
import { getStringSize } from '../domUtils';
|
|
6
7
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
@@ -20,14 +21,15 @@ export function getWordsByLines(_ref) {
|
|
|
20
21
|
export function ChartsText(props) {
|
|
21
22
|
var x = props.x,
|
|
22
23
|
y = props.y,
|
|
23
|
-
|
|
24
|
-
textAnchor = _props$textAnchor === void 0 ? 'start' : _props$textAnchor,
|
|
25
|
-
_props$dominantBaseli = props.dominantBaseline,
|
|
26
|
-
dominantBaseline = _props$dominantBaseli === void 0 ? 'central' : _props$dominantBaseli,
|
|
27
|
-
style = props.style,
|
|
24
|
+
styleProps = props.style,
|
|
28
25
|
text = props.text,
|
|
29
26
|
ownerState = props.ownerState,
|
|
30
27
|
textProps = _objectWithoutProperties(props, _excluded);
|
|
28
|
+
var _ref2 = styleProps != null ? styleProps : {},
|
|
29
|
+
angle = _ref2.angle,
|
|
30
|
+
textAnchor = _ref2.textAnchor,
|
|
31
|
+
dominantBaseline = _ref2.dominantBaseline,
|
|
32
|
+
style = _objectWithoutProperties(_ref2, _excluded2);
|
|
31
33
|
var wordsByLines = React.useMemo(function () {
|
|
32
34
|
return getWordsByLines({
|
|
33
35
|
style: style,
|
|
@@ -47,19 +49,17 @@ export function ChartsText(props) {
|
|
|
47
49
|
startDy = (wordsByLines.length - 1) * -wordsByLines[0].height;
|
|
48
50
|
break;
|
|
49
51
|
}
|
|
50
|
-
|
|
51
|
-
// const transforms = [];
|
|
52
|
+
var transforms = [];
|
|
52
53
|
// if (scaleToFit) {
|
|
53
54
|
// const lineWidth = wordsByLines[0].width;
|
|
54
55
|
// transforms.push(`scale(${(isNumber(width as number) ? (width as number) / lineWidth : 1) / lineWidth})`);
|
|
55
56
|
// }
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
57
|
+
if (angle) {
|
|
58
|
+
transforms.push("rotate(".concat(angle, ", ").concat(x, ", ").concat(y, ")"));
|
|
59
|
+
}
|
|
60
|
+
if (transforms.length) {
|
|
61
|
+
textProps.transform = transforms.join(' ');
|
|
62
|
+
}
|
|
63
63
|
return /*#__PURE__*/_jsx("text", _extends({}, textProps, {
|
|
64
64
|
x: x,
|
|
65
65
|
y: y,
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
var ANGLE_APPROX = 5; // Angle (in deg) for which we approximate the rectangle as perfectly horizontal/vertical
|
|
2
|
+
|
|
3
|
+
var warnedOnce = false;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Return the minimal translation along the x-axis to avoid overflow of a rectangle of a given width, height, and rotation.
|
|
7
|
+
* This assumes that all rectangles have the same height and angle between -90 and 90.
|
|
8
|
+
* Otherwise it would be problematic because you need the height/width of the next rectangle to do the correct computation.
|
|
9
|
+
* @param width the side along the x axis.
|
|
10
|
+
* @param height the side along the y axis.
|
|
11
|
+
* @param angle the rotation in degrees.
|
|
12
|
+
*/
|
|
13
|
+
export function getMinXTranslation(width, height) {
|
|
14
|
+
var angle = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
15
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
16
|
+
if (!warnedOnce && angle > 90 && angle < -90) {
|
|
17
|
+
warnedOnce = true;
|
|
18
|
+
console.warn(["MUI X: It seems you applied an angle larger than 90\xB0 or smaller than -90\xB0 to an axis text.", "This could cause some text overlapping.", "If you encounter a use case where it's needed, please open an issue."].join('\n'));
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
var standardAngle = Math.min(Math.abs(angle) % 180, Math.abs(Math.abs(angle) % 180 - 180) % 180); // Map from R to [0, 90]
|
|
22
|
+
|
|
23
|
+
if (standardAngle < ANGLE_APPROX) {
|
|
24
|
+
// It's nearly horizontal
|
|
25
|
+
return width;
|
|
26
|
+
}
|
|
27
|
+
if (standardAngle > 90 - ANGLE_APPROX) {
|
|
28
|
+
// It's nearly vertical
|
|
29
|
+
return height;
|
|
30
|
+
}
|
|
31
|
+
var radAngle = standardAngle * Math.PI / 180;
|
|
32
|
+
var angleSwich = Math.atan2(height, width);
|
|
33
|
+
if (radAngle < angleSwich) {
|
|
34
|
+
return width / Math.cos(radAngle);
|
|
35
|
+
}
|
|
36
|
+
return height / Math.sin(radAngle);
|
|
37
|
+
}
|
package/models/axis.d.ts
CHANGED
|
@@ -3,8 +3,8 @@ import type { ScaleBand, ScaleLogarithmic, ScalePower, ScaleTime, ScaleLinear, S
|
|
|
3
3
|
import { ChartsAxisClasses } from '../ChartsAxis/axisClasses';
|
|
4
4
|
import type { TickParams } from '../hooks/useTicks';
|
|
5
5
|
import { ChartsTextProps } from '../internals/components/ChartsText';
|
|
6
|
-
export type D3Scale = ScaleBand<any> | ScaleLogarithmic<any,
|
|
7
|
-
export type D3ContinuouseScale = ScaleLogarithmic<any,
|
|
6
|
+
export type D3Scale = ScaleBand<any> | ScaleLogarithmic<any, number> | ScalePoint<any> | ScalePower<any, number> | ScaleTime<any, number> | ScaleLinear<any, number>;
|
|
7
|
+
export type D3ContinuouseScale = ScaleLogarithmic<any, number> | ScalePower<any, number> | ScaleTime<any, number> | ScaleLinear<any, number>;
|
|
8
8
|
export interface ChartsAxisSlotsComponent {
|
|
9
9
|
axisLine?: React.JSXElementConstructor<React.SVGAttributes<SVGPathElement>>;
|
|
10
10
|
axisTick?: React.JSXElementConstructor<React.SVGAttributes<SVGPathElement>>;
|
|
@@ -40,8 +40,24 @@ export interface ChartsAxisProps extends TickParams {
|
|
|
40
40
|
/**
|
|
41
41
|
* The font size of the axis ticks text.
|
|
42
42
|
* @default 12
|
|
43
|
+
* @deprecated Consider using `tickLabelStyle.fontSize` instead.
|
|
43
44
|
*/
|
|
44
45
|
tickFontSize?: number;
|
|
46
|
+
/**
|
|
47
|
+
* The style applied to ticks text.
|
|
48
|
+
*/
|
|
49
|
+
tickLabelStyle?: ChartsTextProps['style'];
|
|
50
|
+
/**
|
|
51
|
+
* The style applied to the axis label.
|
|
52
|
+
*/
|
|
53
|
+
labelStyle?: ChartsTextProps['style'];
|
|
54
|
+
/**
|
|
55
|
+
* Defines which ticks get its label displayed. Its value can be:
|
|
56
|
+
* - 'auto' In such case, labels are displayed if they do not overlap with the previous one.
|
|
57
|
+
* - a filtering function of the form (value, index) => boolean. Warning: the index is tick index, not data ones.
|
|
58
|
+
* @default 'auto'
|
|
59
|
+
*/
|
|
60
|
+
tickLabelInterval?: 'auto' | ((value: any, index: number) => boolean);
|
|
45
61
|
/**
|
|
46
62
|
* The label of the axis.
|
|
47
63
|
*/
|
|
@@ -49,6 +65,7 @@ export interface ChartsAxisProps extends TickParams {
|
|
|
49
65
|
/**
|
|
50
66
|
* The font size of the axis label.
|
|
51
67
|
* @default 14
|
|
68
|
+
* @deprecated Consider using `labelStyle.fontSize` instead.
|
|
52
69
|
*/
|
|
53
70
|
labelFontSize?: number;
|
|
54
71
|
/**
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DefaultizedProps } from '../helpers';
|
|
2
2
|
import { CartesianSeriesType, CommonDefaultizedProps, CommonSeriesType, StackableSeriesType } from './common';
|
|
3
3
|
export type CurveType = 'catmullRom' | 'linear' | 'monotoneX' | 'monotoneY' | 'natural' | 'step' | 'stepBefore' | 'stepAfter';
|
|
4
|
-
export interface ShowMarkParams {
|
|
4
|
+
export interface ShowMarkParams<AxisValue = number | Date> {
|
|
5
5
|
/**
|
|
6
6
|
* The item index.
|
|
7
7
|
*/
|
|
@@ -17,7 +17,7 @@ export interface ShowMarkParams {
|
|
|
17
17
|
/**
|
|
18
18
|
* The item position value. It likely comes from the axis `data` property.
|
|
19
19
|
*/
|
|
20
|
-
position:
|
|
20
|
+
position: AxisValue;
|
|
21
21
|
/**
|
|
22
22
|
* The item value. It comes from the series `data` property.
|
|
23
23
|
*/
|
|
@@ -12,6 +12,17 @@ import { ChartsAxisHighlight } from '../ChartsAxisHighlight';
|
|
|
12
12
|
import { ChartsClipPath } from '../ChartsClipPath';
|
|
13
13
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
14
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
15
|
+
/**
|
|
16
|
+
* Demos:
|
|
17
|
+
*
|
|
18
|
+
* - [Bars](https://mui.com/x/react-charts/bars/)
|
|
19
|
+
* - [Bar demonstration](https://mui.com/x/react-charts/bar-demo/)
|
|
20
|
+
* - [Stacking](https://mui.com/x/react-charts/stacking/)
|
|
21
|
+
*
|
|
22
|
+
* API:
|
|
23
|
+
*
|
|
24
|
+
* - [BarChart API](https://mui.com/x/api/charts/bar-chart/)
|
|
25
|
+
*/
|
|
15
26
|
const BarChart = /*#__PURE__*/React.forwardRef(function BarChart(props, ref) {
|
|
16
27
|
const {
|
|
17
28
|
xAxis,
|
|
@@ -31,6 +42,7 @@ const BarChart = /*#__PURE__*/React.forwardRef(function BarChart(props, ref) {
|
|
|
31
42
|
leftAxis,
|
|
32
43
|
rightAxis,
|
|
33
44
|
bottomAxis,
|
|
45
|
+
skipAnimation,
|
|
34
46
|
children,
|
|
35
47
|
slots,
|
|
36
48
|
slotProps
|
|
@@ -73,7 +85,8 @@ const BarChart = /*#__PURE__*/React.forwardRef(function BarChart(props, ref) {
|
|
|
73
85
|
clipPath: `url(#${clipPathId})`,
|
|
74
86
|
children: /*#__PURE__*/_jsx(BarPlot, {
|
|
75
87
|
slots: slots,
|
|
76
|
-
slotProps: slotProps
|
|
88
|
+
slotProps: slotProps,
|
|
89
|
+
skipAnimation: skipAnimation
|
|
77
90
|
})
|
|
78
91
|
}), /*#__PURE__*/_jsx(ChartsAxis, {
|
|
79
92
|
topAxis: topAxis,
|
|
@@ -115,11 +128,15 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
115
128
|
fill: PropTypes.string,
|
|
116
129
|
label: PropTypes.string,
|
|
117
130
|
labelFontSize: PropTypes.number,
|
|
131
|
+
labelStyle: PropTypes.object,
|
|
118
132
|
position: PropTypes.oneOf(['bottom', 'top']),
|
|
119
133
|
slotProps: PropTypes.object,
|
|
120
134
|
slots: PropTypes.object,
|
|
121
135
|
stroke: PropTypes.string,
|
|
122
136
|
tickFontSize: PropTypes.number,
|
|
137
|
+
tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
|
|
138
|
+
tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
|
|
139
|
+
tickLabelStyle: PropTypes.object,
|
|
123
140
|
tickMaxStep: PropTypes.number,
|
|
124
141
|
tickMinStep: PropTypes.number,
|
|
125
142
|
tickNumber: PropTypes.number,
|
|
@@ -149,11 +166,15 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
149
166
|
fill: PropTypes.string,
|
|
150
167
|
label: PropTypes.string,
|
|
151
168
|
labelFontSize: PropTypes.number,
|
|
169
|
+
labelStyle: PropTypes.object,
|
|
152
170
|
position: PropTypes.oneOf(['left', 'right']),
|
|
153
171
|
slotProps: PropTypes.object,
|
|
154
172
|
slots: PropTypes.object,
|
|
155
173
|
stroke: PropTypes.string,
|
|
156
174
|
tickFontSize: PropTypes.number,
|
|
175
|
+
tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
|
|
176
|
+
tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
|
|
177
|
+
tickLabelStyle: PropTypes.object,
|
|
157
178
|
tickMaxStep: PropTypes.number,
|
|
158
179
|
tickMinStep: PropTypes.number,
|
|
159
180
|
tickNumber: PropTypes.number,
|
|
@@ -192,11 +213,15 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
192
213
|
fill: PropTypes.string,
|
|
193
214
|
label: PropTypes.string,
|
|
194
215
|
labelFontSize: PropTypes.number,
|
|
216
|
+
labelStyle: PropTypes.object,
|
|
195
217
|
position: PropTypes.oneOf(['left', 'right']),
|
|
196
218
|
slotProps: PropTypes.object,
|
|
197
219
|
slots: PropTypes.object,
|
|
198
220
|
stroke: PropTypes.string,
|
|
199
221
|
tickFontSize: PropTypes.number,
|
|
222
|
+
tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
|
|
223
|
+
tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
|
|
224
|
+
tickLabelStyle: PropTypes.object,
|
|
200
225
|
tickMaxStep: PropTypes.number,
|
|
201
226
|
tickMinStep: PropTypes.number,
|
|
202
227
|
tickNumber: PropTypes.number,
|
|
@@ -221,6 +246,11 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
221
246
|
xAxisKey: PropTypes.string,
|
|
222
247
|
yAxisKey: PropTypes.string
|
|
223
248
|
})).isRequired,
|
|
249
|
+
/**
|
|
250
|
+
* If `true`, animations are skiped.
|
|
251
|
+
* @default false
|
|
252
|
+
*/
|
|
253
|
+
skipAnimation: PropTypes.bool,
|
|
224
254
|
/**
|
|
225
255
|
* The props used for each component slot.
|
|
226
256
|
* @default {}
|
|
@@ -254,11 +284,15 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
254
284
|
fill: PropTypes.string,
|
|
255
285
|
label: PropTypes.string,
|
|
256
286
|
labelFontSize: PropTypes.number,
|
|
287
|
+
labelStyle: PropTypes.object,
|
|
257
288
|
position: PropTypes.oneOf(['bottom', 'top']),
|
|
258
289
|
slotProps: PropTypes.object,
|
|
259
290
|
slots: PropTypes.object,
|
|
260
291
|
stroke: PropTypes.string,
|
|
261
292
|
tickFontSize: PropTypes.number,
|
|
293
|
+
tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
|
|
294
|
+
tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
|
|
295
|
+
tickLabelStyle: PropTypes.object,
|
|
262
296
|
tickMaxStep: PropTypes.number,
|
|
263
297
|
tickMinStep: PropTypes.number,
|
|
264
298
|
tickNumber: PropTypes.number,
|
|
@@ -283,6 +317,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
283
317
|
id: PropTypes.string,
|
|
284
318
|
label: PropTypes.string,
|
|
285
319
|
labelFontSize: PropTypes.number,
|
|
320
|
+
labelStyle: PropTypes.object,
|
|
286
321
|
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
287
322
|
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
288
323
|
position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
|
|
@@ -291,6 +326,9 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
291
326
|
slots: PropTypes.object,
|
|
292
327
|
stroke: PropTypes.string,
|
|
293
328
|
tickFontSize: PropTypes.number,
|
|
329
|
+
tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
|
|
330
|
+
tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
|
|
331
|
+
tickLabelStyle: PropTypes.object,
|
|
294
332
|
tickMaxStep: PropTypes.number,
|
|
295
333
|
tickMinStep: PropTypes.number,
|
|
296
334
|
tickNumber: PropTypes.number,
|
|
@@ -309,6 +347,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
309
347
|
id: PropTypes.string,
|
|
310
348
|
label: PropTypes.string,
|
|
311
349
|
labelFontSize: PropTypes.number,
|
|
350
|
+
labelStyle: PropTypes.object,
|
|
312
351
|
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
313
352
|
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
314
353
|
position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
|
|
@@ -317,6 +356,9 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
317
356
|
slots: PropTypes.object,
|
|
318
357
|
stroke: PropTypes.string,
|
|
319
358
|
tickFontSize: PropTypes.number,
|
|
359
|
+
tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
|
|
360
|
+
tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
|
|
361
|
+
tickLabelStyle: PropTypes.object,
|
|
320
362
|
tickMaxStep: PropTypes.number,
|
|
321
363
|
tickMinStep: PropTypes.number,
|
|
322
364
|
tickNumber: PropTypes.number,
|
|
@@ -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", "slots", "slotProps"];
|
|
3
|
+
const _excluded = ["id", "dataIndex", "classes", "color", "highlightScope", "slots", "slotProps", "style"];
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import composeClasses from '@mui/utils/composeClasses';
|
|
6
6
|
import { useSlotProps } from '@mui/base/utils';
|
|
@@ -8,13 +8,14 @@ import generateUtilityClass from '@mui/utils/generateUtilityClass';
|
|
|
8
8
|
import { styled } from '@mui/material/styles';
|
|
9
9
|
import { color as d3Color } from 'd3-color';
|
|
10
10
|
import generateUtilityClasses from '@mui/utils/generateUtilityClasses';
|
|
11
|
+
import { animated } from '@react-spring/web';
|
|
11
12
|
import { getIsFaded, getIsHighlighted, useInteractionItemProps } from '../hooks/useInteractionItemProps';
|
|
12
13
|
import { InteractionContext } from '../context/InteractionProvider';
|
|
13
14
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
15
|
export function getBarElementUtilityClass(slot) {
|
|
15
16
|
return generateUtilityClass('MuiBarElement', slot);
|
|
16
17
|
}
|
|
17
|
-
export const
|
|
18
|
+
export const barElementClasses = generateUtilityClasses('MuiBarElement', ['root']);
|
|
18
19
|
const useUtilityClasses = ownerState => {
|
|
19
20
|
const {
|
|
20
21
|
classes,
|
|
@@ -25,7 +26,7 @@ const useUtilityClasses = ownerState => {
|
|
|
25
26
|
};
|
|
26
27
|
return composeClasses(slots, getBarElementUtilityClass, classes);
|
|
27
28
|
};
|
|
28
|
-
export const BarElementPath = styled(
|
|
29
|
+
export const BarElementPath = styled(animated.rect, {
|
|
29
30
|
name: 'MuiBarElement',
|
|
30
31
|
slot: 'Root',
|
|
31
32
|
overridesResolver: (_, styles) => styles.root
|
|
@@ -46,7 +47,8 @@ export function BarElement(props) {
|
|
|
46
47
|
color,
|
|
47
48
|
highlightScope,
|
|
48
49
|
slots,
|
|
49
|
-
slotProps
|
|
50
|
+
slotProps,
|
|
51
|
+
style
|
|
50
52
|
} = props,
|
|
51
53
|
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
52
54
|
const getInteractionItemProps = useInteractionItemProps(highlightScope);
|
|
@@ -81,6 +83,7 @@ export function BarElement(props) {
|
|
|
81
83
|
seriesId: id,
|
|
82
84
|
dataIndex
|
|
83
85
|
}), {
|
|
86
|
+
style,
|
|
84
87
|
className: classes.root
|
|
85
88
|
}),
|
|
86
89
|
ownerState
|