@mui/x-charts 8.11.2 → 8.11.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/BarChart/index.d.ts +1 -0
- package/BarChart/useBarChartProps.js +4 -3
- package/CHANGELOG.md +86 -0
- package/ChartsAxisHighlight/ChartsXAxisHighlight.js +4 -4
- package/ChartsAxisHighlight/ChartsYAxisHighlight.js +4 -4
- package/ChartsLegend/ChartsLegend.js +2 -1
- package/ChartsLegend/PiecewiseColorLegend.d.ts +2 -2
- package/ChartsLegend/PiecewiseColorLegend.js +32 -22
- package/ChartsLegend/piecewiseColorLegendClasses.d.ts +4 -0
- package/ChartsLegend/piecewiseColorLegendClasses.js +2 -2
- package/ChartsSurface/ChartsSurface.js +2 -1
- package/ChartsWrapper/ChartsWrapper.d.ts +4 -0
- package/ChartsWrapper/ChartsWrapper.js +73 -25
- package/ChartsXAxis/ChartsGroupedXAxisTicks.js +2 -2
- package/ChartsXAxis/ChartsXAxisImpl.js +3 -3
- package/ChartsXAxis/getVisibleLabels.js +5 -1
- package/ChartsYAxis/ChartsGroupedYAxisTicks.js +2 -2
- package/ChartsYAxis/ChartsYAxisImpl.js +3 -3
- package/LineChart/useAreaPlotData.js +2 -2
- package/LineChart/useLineChartProps.js +2 -1
- package/LineChart/useLinePlotData.js +2 -2
- package/PieChart/PieChart.js +1 -0
- package/RadarChart/RadarAxis/useRadarAxis.js +2 -2
- package/RadarChart/useRadarChartProps.js +2 -1
- package/ScatterChart/useScatterChartProps.js +2 -1
- package/Toolbar/Toolbar.js +2 -1
- package/esm/BarChart/index.d.ts +1 -0
- package/esm/BarChart/useBarChartProps.js +4 -3
- package/esm/ChartsAxisHighlight/ChartsXAxisHighlight.js +4 -4
- package/esm/ChartsAxisHighlight/ChartsYAxisHighlight.js +4 -4
- package/esm/ChartsLegend/ChartsLegend.js +2 -1
- package/esm/ChartsLegend/PiecewiseColorLegend.d.ts +2 -2
- package/esm/ChartsLegend/PiecewiseColorLegend.js +32 -22
- package/esm/ChartsLegend/piecewiseColorLegendClasses.d.ts +4 -0
- package/esm/ChartsLegend/piecewiseColorLegendClasses.js +2 -2
- package/esm/ChartsSurface/ChartsSurface.js +2 -1
- package/esm/ChartsWrapper/ChartsWrapper.d.ts +4 -0
- package/esm/ChartsWrapper/ChartsWrapper.js +73 -25
- package/esm/ChartsXAxis/ChartsGroupedXAxisTicks.js +2 -2
- package/esm/ChartsXAxis/ChartsXAxisImpl.js +3 -3
- package/esm/ChartsXAxis/getVisibleLabels.js +5 -1
- package/esm/ChartsYAxis/ChartsGroupedYAxisTicks.js +2 -2
- package/esm/ChartsYAxis/ChartsYAxisImpl.js +3 -3
- package/esm/LineChart/useAreaPlotData.js +2 -2
- package/esm/LineChart/useLineChartProps.js +2 -1
- package/esm/LineChart/useLinePlotData.js +2 -2
- package/esm/PieChart/PieChart.js +1 -0
- package/esm/RadarChart/RadarAxis/useRadarAxis.js +2 -2
- package/esm/RadarChart/useRadarChartProps.js +2 -1
- package/esm/ScatterChart/useScatterChartProps.js +2 -1
- package/esm/Toolbar/Toolbar.js +2 -1
- package/esm/hooks/useScale.js +2 -2
- package/esm/hooks/useTicks.js +2 -2
- package/esm/hooks/useTicksGrouped.js +2 -2
- package/esm/index.js +1 -1
- package/esm/internals/index.d.ts +1 -1
- package/esm/internals/index.js +1 -1
- package/esm/internals/invertScale.js +2 -2
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisValue.js +3 -3
- package/esm/internals/plugins/featurePlugins/useChartPolarAxis/getAxisIndex.js +2 -2
- package/esm/internals/scaleGuards.d.ts +4 -0
- package/esm/internals/scaleGuards.js +3 -0
- package/esm/models/axis.d.ts +3 -0
- package/hooks/useScale.js +2 -2
- package/hooks/useTicks.js +2 -2
- package/hooks/useTicksGrouped.js +2 -2
- package/index.js +1 -1
- package/internals/index.d.ts +1 -1
- package/internals/index.js +4 -4
- package/internals/invertScale.js +2 -2
- package/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisValue.js +3 -3
- package/internals/plugins/featurePlugins/useChartPolarAxis/getAxisIndex.js +2 -2
- package/internals/scaleGuards.d.ts +4 -0
- package/internals/{isBandScale.js → scaleGuards.js} +2 -2
- package/models/axis.d.ts +3 -0
- package/package.json +4 -4
- package/esm/internals/isBandScale.d.ts +0 -5
- package/esm/internals/isBandScale.js +0 -3
- package/internals/isBandScale.d.ts +0 -5
|
@@ -8,7 +8,7 @@ exports.useAreaPlotData = useAreaPlotData;
|
|
|
8
8
|
var React = _interopRequireWildcard(require("react"));
|
|
9
9
|
var _d3Shape = require("@mui/x-charts-vendor/d3-shape");
|
|
10
10
|
var _useChartGradientId = require("../hooks/useChartGradientId");
|
|
11
|
-
var
|
|
11
|
+
var _scaleGuards = require("../internals/scaleGuards");
|
|
12
12
|
var _getCurve = require("../internals/getCurve");
|
|
13
13
|
var _hooks = require("../hooks");
|
|
14
14
|
var _constants = require("../constants");
|
|
@@ -59,7 +59,7 @@ function useAreaPlotData(xAxes, yAxes) {
|
|
|
59
59
|
throw new Error(`MUI X Charts: The data length of the x axis (${xData.length} items) is lower than the length of series (${stackedData.length} items).`);
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
|
-
const shouldExpand = curve?.includes('step') && !strictStepCurve && (0,
|
|
62
|
+
const shouldExpand = curve?.includes('step') && !strictStepCurve && (0, _scaleGuards.isOrdinalScale)(xScale);
|
|
63
63
|
const formattedData = xData?.flatMap((x, index) => {
|
|
64
64
|
const nullData = data[index] == null;
|
|
65
65
|
if (shouldExpand) {
|
|
@@ -125,7 +125,8 @@ const useLineChartProps = props => {
|
|
|
125
125
|
const chartsWrapperProps = {
|
|
126
126
|
sx,
|
|
127
127
|
legendPosition: props.slotProps?.legend?.position,
|
|
128
|
-
legendDirection: props.slotProps?.legend?.direction
|
|
128
|
+
legendDirection: props.slotProps?.legend?.direction,
|
|
129
|
+
hideLegend: props.hideLegend ?? false
|
|
129
130
|
};
|
|
130
131
|
return {
|
|
131
132
|
chartsWrapperProps,
|
|
@@ -9,7 +9,7 @@ var React = _interopRequireWildcard(require("react"));
|
|
|
9
9
|
var _warning = require("@mui/x-internals/warning");
|
|
10
10
|
var _d3Shape = require("@mui/x-charts-vendor/d3-shape");
|
|
11
11
|
var _useChartGradientId = require("../hooks/useChartGradientId");
|
|
12
|
-
var
|
|
12
|
+
var _scaleGuards = require("../internals/scaleGuards");
|
|
13
13
|
var _getCurve = require("../internals/getCurve");
|
|
14
14
|
var _hooks = require("../hooks");
|
|
15
15
|
var _constants = require("../constants");
|
|
@@ -57,7 +57,7 @@ function useLinePlotData(xAxes, yAxes) {
|
|
|
57
57
|
(0, _warning.warnOnce)(`MUI X Charts: The data length of the x axis (${xData.length} items) is lower than the length of series (${stackedData.length} items).`, 'error');
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
|
-
const shouldExpand = curve?.includes('step') && !strictStepCurve && (0,
|
|
60
|
+
const shouldExpand = curve?.includes('step') && !strictStepCurve && (0, _scaleGuards.isOrdinalScale)(xScale);
|
|
61
61
|
const formattedData = xData?.flatMap((x, index) => {
|
|
62
62
|
const nullData = data[index] == null;
|
|
63
63
|
if (shouldExpand) {
|
package/PieChart/PieChart.js
CHANGED
|
@@ -85,6 +85,7 @@ const PieChart = exports.PieChart = /*#__PURE__*/React.forwardRef(function PieCh
|
|
|
85
85
|
legendPosition: props.slotProps?.legend?.position,
|
|
86
86
|
legendDirection: props.slotProps?.legend?.direction ?? 'vertical',
|
|
87
87
|
sx: sx,
|
|
88
|
+
hideLegend: hideLegend ?? false,
|
|
88
89
|
children: [showToolbar && Toolbar ? /*#__PURE__*/(0, _jsxRuntime.jsx)(Toolbar, (0, _extends2.default)({}, props.slotProps?.toolbar)) : null, !hideLegend && /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsLegend.ChartsLegend, {
|
|
89
90
|
direction: props.slotProps?.legend?.direction ?? 'vertical',
|
|
90
91
|
slots: slots,
|
|
@@ -9,7 +9,7 @@ var _useAxis = require("../../hooks/useAxis");
|
|
|
9
9
|
var _useScale = require("../../hooks/useScale");
|
|
10
10
|
var _useChartContext = require("../../context/ChartProvider/useChartContext");
|
|
11
11
|
var _useChartPolarAxis = require("../../internals/plugins/featurePlugins/useChartPolarAxis");
|
|
12
|
-
var
|
|
12
|
+
var _scaleGuards = require("../../internals/scaleGuards");
|
|
13
13
|
var _degToRad = require("../../internals/degToRad");
|
|
14
14
|
var _clampAngle = require("../../internals/clampAngle");
|
|
15
15
|
var _useSelector = require("../../internals/store/useSelector");
|
|
@@ -48,7 +48,7 @@ function useRadarAxis(params) {
|
|
|
48
48
|
}, (_, index) => (index + 1) / divisions);
|
|
49
49
|
const radiusScale = radiusAxis[metric].scale;
|
|
50
50
|
const R = radiusScale.range()[1];
|
|
51
|
-
if ((0,
|
|
51
|
+
if ((0, _scaleGuards.isOrdinalScale)(radiusScale)) {
|
|
52
52
|
if (process.env.NODE_ENV !== 'production') {
|
|
53
53
|
console.error('MUI X Charts: Radar chart does not support ordinal axes');
|
|
54
54
|
}
|
|
@@ -95,7 +95,8 @@ const useScatterChartProps = props => {
|
|
|
95
95
|
const chartsWrapperProps = {
|
|
96
96
|
sx,
|
|
97
97
|
legendPosition: props.slotProps?.legend?.position,
|
|
98
|
-
legendDirection: props.slotProps?.legend?.direction
|
|
98
|
+
legendDirection: props.slotProps?.legend?.direction,
|
|
99
|
+
hideLegend: props.hideLegend ?? false
|
|
99
100
|
};
|
|
100
101
|
return {
|
|
101
102
|
chartsWrapperProps,
|
package/Toolbar/Toolbar.js
CHANGED
|
@@ -33,7 +33,8 @@ const ToolbarRoot = (0, _styles.styled)('div', {
|
|
|
33
33
|
minHeight: 44,
|
|
34
34
|
boxSizing: 'border-box',
|
|
35
35
|
border: `1px solid ${(theme.vars || theme).palette.divider}`,
|
|
36
|
-
borderRadius: 4
|
|
36
|
+
borderRadius: 4,
|
|
37
|
+
gridArea: 'toolbar'
|
|
37
38
|
}));
|
|
38
39
|
const Toolbar = exports.Toolbar = /*#__PURE__*/React.forwardRef(function Toolbar(_ref, ref) {
|
|
39
40
|
let {
|
package/esm/BarChart/index.d.ts
CHANGED
|
@@ -3,5 +3,6 @@ export * from "./BarPlot.js";
|
|
|
3
3
|
export * from "./BarElement.js";
|
|
4
4
|
export * from "./BarLabel/index.js";
|
|
5
5
|
export * from "./barElementClasses.js";
|
|
6
|
+
export { type BarProps } from "./AnimatedBarElement.js";
|
|
6
7
|
export { barClasses, getBarUtilityClass } from "./barClasses.js";
|
|
7
8
|
export type { BarClassKey, BarClasses } from "./barClasses.js";
|
|
@@ -41,7 +41,7 @@ export const useBarChartProps = props => {
|
|
|
41
41
|
barLabel,
|
|
42
42
|
className
|
|
43
43
|
} = props,
|
|
44
|
-
|
|
44
|
+
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
45
45
|
const id = useId();
|
|
46
46
|
const clipPathId = `${id}-clip-path`;
|
|
47
47
|
const hasHorizontalSeries = layout === 'horizontal' || layout === undefined && series.some(item => item.layout === 'horizontal');
|
|
@@ -82,7 +82,7 @@ export const useBarChartProps = props => {
|
|
|
82
82
|
scaleType: 'band'
|
|
83
83
|
}, axis)) : yAxis;
|
|
84
84
|
}, [defaultYAxis, hasHorizontalSeries, yAxis]);
|
|
85
|
-
const chartContainerProps = _extends({},
|
|
85
|
+
const chartContainerProps = _extends({}, other, {
|
|
86
86
|
series: seriesWithDefault,
|
|
87
87
|
width,
|
|
88
88
|
height,
|
|
@@ -136,7 +136,8 @@ export const useBarChartProps = props => {
|
|
|
136
136
|
const chartsWrapperProps = {
|
|
137
137
|
sx,
|
|
138
138
|
legendPosition: props.slotProps?.legend?.position,
|
|
139
|
-
legendDirection: props.slotProps?.legend?.direction
|
|
139
|
+
legendDirection: props.slotProps?.legend?.direction,
|
|
140
|
+
hideLegend: props.hideLegend ?? false
|
|
140
141
|
};
|
|
141
142
|
return {
|
|
142
143
|
chartsWrapperProps,
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import * as React from 'react';
|
|
4
4
|
import { getValueToPositionMapper } from "../hooks/useScale.js";
|
|
5
|
-
import {
|
|
5
|
+
import { isOrdinalScale } from "../internals/scaleGuards.js";
|
|
6
6
|
import { useSelector } from "../internals/store/useSelector.js";
|
|
7
7
|
import { useStore } from "../internals/store/useStore.js";
|
|
8
8
|
import { selectorChartsHighlightXAxisValue, selectorChartXAxis } from "../internals/plugins/featurePlugins/useChartCartesianAxis/index.js";
|
|
@@ -35,15 +35,15 @@ export default function ChartsXHighlight(props) {
|
|
|
35
35
|
const xAxis = xAxes.axis[axisId];
|
|
36
36
|
const xScale = xAxis.scale;
|
|
37
37
|
const getXPosition = getValueToPositionMapper(xScale);
|
|
38
|
-
const
|
|
38
|
+
const isXScaleOrdinal = type === 'band' && value !== null && isOrdinalScale(xScale);
|
|
39
39
|
if (process.env.NODE_ENV !== 'production') {
|
|
40
|
-
const isError =
|
|
40
|
+
const isError = isXScaleOrdinal && xScale(value) === undefined;
|
|
41
41
|
if (isError) {
|
|
42
42
|
console.error([`MUI X Charts: The position value provided for the axis is not valid for the current scale.`, `This probably means something is wrong with the data passed to the chart.`, `The ChartsAxisHighlight component will not be displayed.`].join('\n'));
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
return /*#__PURE__*/_jsxs(React.Fragment, {
|
|
46
|
-
children: [
|
|
46
|
+
children: [isXScaleOrdinal && xScale(value) !== undefined && /*#__PURE__*/_jsx(ChartsAxisHighlightPath, {
|
|
47
47
|
d: `M ${xScale(value) - (xScale.step() - xScale.bandwidth()) / 2} ${top} l ${xScale.step()} 0 l 0 ${height} l ${-xScale.step()} 0 Z`,
|
|
48
48
|
className: classes.root,
|
|
49
49
|
ownerState: {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import * as React from 'react';
|
|
4
4
|
import { getValueToPositionMapper } from "../hooks/useScale.js";
|
|
5
|
-
import {
|
|
5
|
+
import { isOrdinalScale } from "../internals/scaleGuards.js";
|
|
6
6
|
import { useSelector } from "../internals/store/useSelector.js";
|
|
7
7
|
import { useStore } from "../internals/store/useStore.js";
|
|
8
8
|
import { selectorChartsHighlightYAxisValue, selectorChartYAxis } from "../internals/plugins/featurePlugins/useChartCartesianAxis/index.js";
|
|
@@ -35,15 +35,15 @@ export default function ChartsYHighlight(props) {
|
|
|
35
35
|
const yAxis = yAxes.axis[axisId];
|
|
36
36
|
const yScale = yAxis.scale;
|
|
37
37
|
const getYPosition = getValueToPositionMapper(yScale);
|
|
38
|
-
const
|
|
38
|
+
const isYScaleOrdinal = type === 'band' && value !== null && isOrdinalScale(yScale);
|
|
39
39
|
if (process.env.NODE_ENV !== 'production') {
|
|
40
|
-
const isError =
|
|
40
|
+
const isError = isYScaleOrdinal && yScale(value) === undefined;
|
|
41
41
|
if (isError) {
|
|
42
42
|
console.error([`MUI X Charts: The position value provided for the axis is not valid for the current scale.`, `This probably means something is wrong with the data passed to the chart.`, `The ChartsAxisHighlight component will not be displayed.`].join('\n'));
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
return /*#__PURE__*/_jsxs(React.Fragment, {
|
|
46
|
-
children: [
|
|
46
|
+
children: [isYScaleOrdinal && yScale(value) !== undefined && /*#__PURE__*/_jsx(ChartsAxisHighlightPath, {
|
|
47
47
|
d: `M ${left} ${yScale(value) - (yScale.step() - yScale.bandwidth()) / 2} l 0 ${yScale.step()} l ${width} 0 l 0 ${-yScale.step()} Z`,
|
|
48
48
|
className: classes.root,
|
|
49
49
|
ownerState: {
|
|
@@ -51,7 +51,8 @@ const RootElement = styled('ul', {
|
|
|
51
51
|
display: ownerState.direction === 'vertical' ? 'flex' : 'inline-flex',
|
|
52
52
|
alignItems: 'center',
|
|
53
53
|
gap: theme.spacing(1)
|
|
54
|
-
}
|
|
54
|
+
},
|
|
55
|
+
gridArea: 'legend'
|
|
55
56
|
}));
|
|
56
57
|
const ChartsLegend = consumeSlots('MuiChartsLegend', 'legend', {
|
|
57
58
|
defaultProps: {
|
|
@@ -20,10 +20,10 @@ export interface PiecewiseColorLegendProps extends ColorLegendSelector, PrependK
|
|
|
20
20
|
*/
|
|
21
21
|
labelFormatter?: (params: PiecewiseLabelFormatterParams) => string | null;
|
|
22
22
|
/**
|
|
23
|
-
* Where to position the labels relative to the
|
|
23
|
+
* Where to position the labels relative to the color marks.
|
|
24
24
|
* @default 'extremes'
|
|
25
25
|
*/
|
|
26
|
-
labelPosition?: 'start' | 'end' | 'extremes';
|
|
26
|
+
labelPosition?: 'start' | 'end' | 'extremes' | 'inline-start' | 'inline-end';
|
|
27
27
|
/**
|
|
28
28
|
* Callback fired when a legend item is clicked.
|
|
29
29
|
* @param {React.MouseEvent<HTMLButtonElement, MouseEvent>} event The click event.
|
|
@@ -21,6 +21,7 @@ const RootElement = styled('ul', {
|
|
|
21
21
|
theme,
|
|
22
22
|
ownerState
|
|
23
23
|
}) => {
|
|
24
|
+
const classes = piecewiseColorLegendClasses;
|
|
24
25
|
return _extends({}, theme.typography.caption, {
|
|
25
26
|
color: (theme.vars || theme).palette.text.primary,
|
|
26
27
|
lineHeight: '100%',
|
|
@@ -32,8 +33,8 @@ const RootElement = styled('ul', {
|
|
|
32
33
|
paddingInlineStart: 0,
|
|
33
34
|
marginBlock: theme.spacing(1),
|
|
34
35
|
marginInline: theme.spacing(1),
|
|
35
|
-
width: '
|
|
36
|
-
[`button.${
|
|
36
|
+
width: 'fit-content',
|
|
37
|
+
[`button.${classes.item}`]: {
|
|
37
38
|
// Reset button styles
|
|
38
39
|
background: 'none',
|
|
39
40
|
border: 'none',
|
|
@@ -45,55 +46,62 @@ const RootElement = styled('ul', {
|
|
|
45
46
|
letterSpacing: 'inherit',
|
|
46
47
|
color: 'inherit'
|
|
47
48
|
},
|
|
48
|
-
[`.${
|
|
49
|
+
[`.${classes.item}`]: {
|
|
49
50
|
display: 'flex',
|
|
50
51
|
gap: theme.spacing(0.5)
|
|
51
52
|
},
|
|
52
|
-
[`li :not(.${
|
|
53
|
+
[`li :not(.${classes.minLabel}, .${classes.maxLabel}) .${classes?.mark}`]: {
|
|
53
54
|
alignSelf: 'center'
|
|
54
55
|
},
|
|
55
|
-
[`&.${
|
|
56
|
+
[`&.${classes.start}`]: {
|
|
56
57
|
alignItems: 'end'
|
|
57
58
|
},
|
|
58
|
-
[`&.${
|
|
59
|
+
[`&.${classes.end}`]: {
|
|
59
60
|
alignItems: 'start'
|
|
60
61
|
},
|
|
61
|
-
[`&.${
|
|
62
|
+
[`&.${classes.horizontal}`]: {
|
|
62
63
|
alignItems: 'center',
|
|
63
|
-
[`.${
|
|
64
|
+
[`.${classes.item}`]: {
|
|
64
65
|
flexDirection: 'column'
|
|
65
66
|
},
|
|
66
|
-
[`&.${
|
|
67
|
+
[`&.${classes.inlineStart}, &.${classes.inlineEnd}`]: {
|
|
68
|
+
gap: theme.spacing(1.5),
|
|
69
|
+
flexWrap: 'wrap',
|
|
70
|
+
[`.${classes.item}`]: {
|
|
71
|
+
flexDirection: 'row'
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
[`&.${classes.start}`]: {
|
|
67
75
|
alignItems: 'end'
|
|
68
76
|
},
|
|
69
|
-
[`&.${
|
|
77
|
+
[`&.${classes.end}`]: {
|
|
70
78
|
alignItems: 'start'
|
|
71
79
|
},
|
|
72
|
-
[`.${
|
|
80
|
+
[`.${classes.minLabel}`]: {
|
|
73
81
|
alignItems: 'end'
|
|
74
82
|
},
|
|
75
|
-
[`&.${
|
|
76
|
-
[`.${
|
|
83
|
+
[`&.${classes.extremes}`]: {
|
|
84
|
+
[`.${classes.minLabel}, .${classes.maxLabel}`]: {
|
|
77
85
|
alignItems: 'center',
|
|
78
86
|
display: 'flex',
|
|
79
87
|
flexDirection: 'row'
|
|
80
88
|
}
|
|
81
89
|
}
|
|
82
90
|
},
|
|
83
|
-
[`&.${
|
|
84
|
-
[`.${
|
|
91
|
+
[`&.${classes.vertical}`]: {
|
|
92
|
+
[`.${classes.item}`]: {
|
|
85
93
|
flexDirection: 'row',
|
|
86
94
|
alignItems: 'center'
|
|
87
95
|
},
|
|
88
|
-
[`&.${
|
|
96
|
+
[`&.${classes.start}, &.${classes.inlineStart}`]: {
|
|
89
97
|
alignItems: 'end'
|
|
90
98
|
},
|
|
91
|
-
[`&.${
|
|
99
|
+
[`&.${classes.end}, &.${classes.inlineEnd}`]: {
|
|
92
100
|
alignItems: 'start'
|
|
93
101
|
},
|
|
94
|
-
[`&.${
|
|
102
|
+
[`&.${classes.extremes}`]: {
|
|
95
103
|
alignItems: 'center',
|
|
96
|
-
[`.${
|
|
104
|
+
[`.${classes.minLabel}, .${classes.maxLabel}`]: {
|
|
97
105
|
alignItems: 'center',
|
|
98
106
|
display: 'flex',
|
|
99
107
|
flexDirection: 'column'
|
|
@@ -146,6 +154,8 @@ const PiecewiseColorLegend = consumeThemeProps('MuiPiecewiseColorLegend', {
|
|
|
146
154
|
const isStart = labelPosition === 'start';
|
|
147
155
|
const isEnd = labelPosition === 'end';
|
|
148
156
|
const isExtremes = labelPosition === 'extremes';
|
|
157
|
+
const isInlineStart = labelPosition === 'inline-start';
|
|
158
|
+
const isInlineEnd = labelPosition === 'inline-end';
|
|
149
159
|
return /*#__PURE__*/_jsx(RootElement, _extends({
|
|
150
160
|
className: clsx(classes?.root, className),
|
|
151
161
|
ref: ref
|
|
@@ -179,8 +189,8 @@ const PiecewiseColorLegend = consumeThemeProps('MuiPiecewiseColorLegend', {
|
|
|
179
189
|
if (label === null || label === undefined) {
|
|
180
190
|
return null;
|
|
181
191
|
}
|
|
182
|
-
const isTextBefore = isStart || isExtremes && isFirst;
|
|
183
|
-
const isTextAfter = isEnd || isExtremes && isLast;
|
|
192
|
+
const isTextBefore = isStart || isExtremes && isFirst || isInlineStart;
|
|
193
|
+
const isTextAfter = isEnd || isExtremes && isLast || isInlineEnd;
|
|
184
194
|
const clickObject = {
|
|
185
195
|
type: 'piecewiseColor',
|
|
186
196
|
color,
|
|
@@ -248,7 +258,7 @@ process.env.NODE_ENV !== "production" ? PiecewiseColorLegend.propTypes = {
|
|
|
248
258
|
* Where to position the labels relative to the gradient.
|
|
249
259
|
* @default 'extremes'
|
|
250
260
|
*/
|
|
251
|
-
labelPosition: PropTypes.oneOf(['start', 'end', 'extremes']),
|
|
261
|
+
labelPosition: PropTypes.oneOf(['start', 'end', 'extremes', 'inline-start', 'inline-end']),
|
|
252
262
|
/**
|
|
253
263
|
* The type of the mark.
|
|
254
264
|
* @default 'square'
|
|
@@ -19,6 +19,10 @@ export interface PiecewiseColorLegendClasses {
|
|
|
19
19
|
end: string;
|
|
20
20
|
/** Styles applied to the legend with the labels on the extremes of the color marks. */
|
|
21
21
|
extremes: string;
|
|
22
|
+
/** Styles applied to the legend with the labels inlined before the color marks. */
|
|
23
|
+
inlineStart: string;
|
|
24
|
+
/** Styles applied to the legend with the labels inlined after the color marks. */
|
|
25
|
+
inlineEnd: string;
|
|
22
26
|
/** Styles applied to the marks. */
|
|
23
27
|
mark: string;
|
|
24
28
|
/** Styles applied to the series label. */
|
|
@@ -11,7 +11,7 @@ export const useUtilityClasses = props => {
|
|
|
11
11
|
labelPosition
|
|
12
12
|
} = props;
|
|
13
13
|
const slots = {
|
|
14
|
-
root: ['root', direction, labelPosition],
|
|
14
|
+
root: ['root', direction, labelPosition?.replaceAll(/-(\w)/g, match => match[1].toUpperCase())],
|
|
15
15
|
minLabel: ['minLabel'],
|
|
16
16
|
maxLabel: ['maxLabel'],
|
|
17
17
|
item: ['item'],
|
|
@@ -20,4 +20,4 @@ export const useUtilityClasses = props => {
|
|
|
20
20
|
};
|
|
21
21
|
return composeClasses(slots, getLegendUtilityClass, classes);
|
|
22
22
|
};
|
|
23
|
-
export const piecewiseColorLegendClasses = generateUtilityClasses('MuiPiecewiseColorLegendClasses', ['root', 'minLabel', 'maxLabel', 'item', 'vertical', 'horizontal', 'start', 'end', 'extremes', 'mark', 'label']);
|
|
23
|
+
export const piecewiseColorLegendClasses = generateUtilityClasses('MuiPiecewiseColorLegendClasses', ['root', 'minLabel', 'maxLabel', 'item', 'vertical', 'horizontal', 'start', 'end', 'extremes', 'inlineStart', 'inlineEnd', 'mark', 'label']);
|
|
@@ -30,7 +30,8 @@ const ChartsSurfaceStyles = styled('svg', {
|
|
|
30
30
|
// This prevents default touch actions when using the svg on mobile devices.
|
|
31
31
|
// For example, prevent page scroll & zoom.
|
|
32
32
|
touchAction: 'pan-y',
|
|
33
|
-
userSelect: 'none'
|
|
33
|
+
userSelect: 'none',
|
|
34
|
+
gridArea: 'chart'
|
|
34
35
|
}));
|
|
35
36
|
|
|
36
37
|
/**
|
|
@@ -13,6 +13,10 @@ export interface ChartsWrapperProps {
|
|
|
13
13
|
* @default 'horizontal'
|
|
14
14
|
*/
|
|
15
15
|
legendDirection?: Direction;
|
|
16
|
+
/**
|
|
17
|
+
* If `true`, the legend is not rendered.
|
|
18
|
+
*/
|
|
19
|
+
hideLegend: boolean;
|
|
16
20
|
/**
|
|
17
21
|
* If `true`, the chart wrapper set `height: 100%`.
|
|
18
22
|
* @default `false` if the `height` prop is set. And `true` otherwise.
|
|
@@ -6,50 +6,76 @@ import { useChartRootRef } from "../hooks/useChartRootRef.js";
|
|
|
6
6
|
import { useStore } from "../internals/store/useStore.js";
|
|
7
7
|
import { useSelector } from "../internals/store/useSelector.js";
|
|
8
8
|
import { selectorChartPropsSize } from "../internals/plugins/corePlugins/useChartDimensions/index.js";
|
|
9
|
+
import { chartsToolbarClasses } from "../Toolbar/index.js";
|
|
9
10
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
10
|
-
const
|
|
11
|
+
const getJustifyItems = position => {
|
|
12
|
+
if (position?.horizontal === 'start') {
|
|
13
|
+
return 'start';
|
|
14
|
+
}
|
|
15
|
+
if (position?.horizontal === 'end') {
|
|
16
|
+
return 'end';
|
|
17
|
+
}
|
|
18
|
+
return 'center';
|
|
19
|
+
};
|
|
20
|
+
const getAlignItems = position => {
|
|
21
|
+
if (position?.vertical === 'top') {
|
|
22
|
+
return 'flex-start';
|
|
23
|
+
}
|
|
24
|
+
if (position?.vertical === 'bottom') {
|
|
25
|
+
return 'flex-end';
|
|
26
|
+
}
|
|
27
|
+
return 'center';
|
|
28
|
+
};
|
|
29
|
+
const addToolbar = template => {
|
|
30
|
+
return `"toolbar"
|
|
31
|
+
${template}`;
|
|
32
|
+
};
|
|
33
|
+
const getGridTemplateAreas = (hideLegend, direction, position) => {
|
|
34
|
+
if (hideLegend) {
|
|
35
|
+
return `"chart"`;
|
|
36
|
+
}
|
|
11
37
|
if (direction === 'vertical') {
|
|
12
38
|
if (position?.horizontal === 'start') {
|
|
13
|
-
return
|
|
39
|
+
return `"legend chart"`;
|
|
14
40
|
}
|
|
15
|
-
return
|
|
41
|
+
return `"chart legend"`;
|
|
16
42
|
}
|
|
17
43
|
if (position?.vertical === 'bottom') {
|
|
18
|
-
return
|
|
44
|
+
return `"chart"
|
|
45
|
+
"legend"`;
|
|
19
46
|
}
|
|
20
|
-
return
|
|
47
|
+
return `"legend"
|
|
48
|
+
"chart"`;
|
|
21
49
|
};
|
|
22
|
-
const
|
|
50
|
+
const getTemplateColumns = (hideLegend, direction, position, width) => {
|
|
23
51
|
if (direction === 'vertical') {
|
|
24
|
-
if (
|
|
25
|
-
return '
|
|
26
|
-
}
|
|
27
|
-
if (position?.vertical === 'bottom') {
|
|
28
|
-
return 'flex-end';
|
|
52
|
+
if (hideLegend) {
|
|
53
|
+
return '1fr';
|
|
29
54
|
}
|
|
30
|
-
}
|
|
31
|
-
if (direction === 'horizontal') {
|
|
32
55
|
if (position?.horizontal === 'start') {
|
|
33
|
-
return '
|
|
56
|
+
return 'auto 1fr';
|
|
34
57
|
}
|
|
35
|
-
|
|
36
|
-
|
|
58
|
+
return `${width ? 'auto' : '1fr'} auto`;
|
|
59
|
+
}
|
|
60
|
+
return '100%';
|
|
61
|
+
};
|
|
62
|
+
const getTemplateRows = (hideLegend, direction) => {
|
|
63
|
+
if (direction === 'vertical') {
|
|
64
|
+
if (hideLegend) {
|
|
65
|
+
return 'auto';
|
|
37
66
|
}
|
|
67
|
+
return 'auto 1fr';
|
|
38
68
|
}
|
|
39
|
-
return '
|
|
69
|
+
return 'auto 1fr';
|
|
40
70
|
};
|
|
41
71
|
const Root = styled('div', {
|
|
42
72
|
name: 'MuiChartsWrapper',
|
|
43
73
|
slot: 'Root',
|
|
44
|
-
shouldForwardProp: prop => shouldForwardProp(prop) && prop !== 'extendVertically'
|
|
74
|
+
shouldForwardProp: prop => shouldForwardProp(prop) && prop !== 'extendVertically' && prop !== 'width'
|
|
45
75
|
})(({
|
|
46
|
-
ownerState
|
|
76
|
+
ownerState,
|
|
77
|
+
width
|
|
47
78
|
}) => ({
|
|
48
|
-
display: 'flex',
|
|
49
|
-
flexDirection: getDirection(ownerState.legendDirection, ownerState.legendPosition),
|
|
50
|
-
flex: 1,
|
|
51
|
-
justifyContent: 'center',
|
|
52
|
-
alignItems: getAlign(ownerState.legendDirection, ownerState.legendPosition),
|
|
53
79
|
variants: [{
|
|
54
80
|
props: {
|
|
55
81
|
extendVertically: true
|
|
@@ -57,7 +83,23 @@ const Root = styled('div', {
|
|
|
57
83
|
style: {
|
|
58
84
|
height: '100%'
|
|
59
85
|
}
|
|
60
|
-
}]
|
|
86
|
+
}],
|
|
87
|
+
flex: 1,
|
|
88
|
+
display: 'grid',
|
|
89
|
+
gridTemplateColumns: getTemplateColumns(ownerState.hideLegend, ownerState.legendDirection, ownerState.legendPosition, width),
|
|
90
|
+
gridTemplateRows: getTemplateRows(ownerState.hideLegend, ownerState.legendDirection),
|
|
91
|
+
[`&:has(.${chartsToolbarClasses.root})`]: {
|
|
92
|
+
gridTemplateAreas: addToolbar(getGridTemplateAreas(ownerState.hideLegend, ownerState.legendDirection, ownerState.legendPosition))
|
|
93
|
+
},
|
|
94
|
+
[`&:not(:has(.${chartsToolbarClasses.root}))`]: {
|
|
95
|
+
gridTemplateAreas: getGridTemplateAreas(ownerState.hideLegend, ownerState.legendDirection, ownerState.legendPosition)
|
|
96
|
+
},
|
|
97
|
+
justifyContent: 'center',
|
|
98
|
+
justifyItems: getJustifyItems(ownerState.legendPosition),
|
|
99
|
+
alignItems: getAlignItems(ownerState.legendPosition),
|
|
100
|
+
[`& > .${chartsToolbarClasses.root}`]: {
|
|
101
|
+
justifySelf: 'center'
|
|
102
|
+
}
|
|
61
103
|
}));
|
|
62
104
|
|
|
63
105
|
/**
|
|
@@ -73,6 +115,7 @@ function ChartsWrapper(props) {
|
|
|
73
115
|
const chartRootRef = useChartRootRef();
|
|
74
116
|
const store = useStore();
|
|
75
117
|
const {
|
|
118
|
+
width: propsWidth,
|
|
76
119
|
height: propsHeight
|
|
77
120
|
} = useSelector(store, selectorChartPropsSize);
|
|
78
121
|
return /*#__PURE__*/_jsx(Root, {
|
|
@@ -80,6 +123,7 @@ function ChartsWrapper(props) {
|
|
|
80
123
|
ownerState: props,
|
|
81
124
|
sx: sx,
|
|
82
125
|
extendVertically: extendVertically ?? propsHeight === undefined,
|
|
126
|
+
width: propsWidth,
|
|
83
127
|
children: children
|
|
84
128
|
});
|
|
85
129
|
}
|
|
@@ -94,6 +138,10 @@ process.env.NODE_ENV !== "production" ? ChartsWrapper.propTypes = {
|
|
|
94
138
|
* @default `false` if the `height` prop is set. And `true` otherwise.
|
|
95
139
|
*/
|
|
96
140
|
extendVertically: PropTypes.bool,
|
|
141
|
+
/**
|
|
142
|
+
* If `true`, the legend is not rendered.
|
|
143
|
+
*/
|
|
144
|
+
hideLegend: PropTypes.bool.isRequired,
|
|
97
145
|
/**
|
|
98
146
|
* The direction of the legend.
|
|
99
147
|
* @default 'horizontal'
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
4
4
|
import * as React from 'react';
|
|
5
|
-
import {
|
|
5
|
+
import { isOrdinalScale } from "../internals/scaleGuards.js";
|
|
6
6
|
import { useChartContext } from "../context/ChartProvider/useChartContext.js";
|
|
7
7
|
import { TICK_LABEL_GAP } from "./utilities.js";
|
|
8
8
|
import { useTicksGrouped } from "../hooks/useTicksGrouped.js";
|
|
@@ -33,7 +33,7 @@ function ChartsGroupedXAxisTicks(inProps) {
|
|
|
33
33
|
TickLabel,
|
|
34
34
|
axisTickLabelProps
|
|
35
35
|
} = useAxisTicksProps(inProps);
|
|
36
|
-
if (!
|
|
36
|
+
if (!isOrdinalScale(xScale)) {
|
|
37
37
|
throw new Error('MUI X Charts: ChartsGroupedXAxis only supports the `band` and `point` scale types.');
|
|
38
38
|
}
|
|
39
39
|
const {
|
|
@@ -10,7 +10,7 @@ import { styled, useTheme, useThemeProps } from '@mui/material/styles';
|
|
|
10
10
|
import { ChartsSingleXAxisTicks } from "./ChartsSingleXAxisTicks.js";
|
|
11
11
|
import { ChartsGroupedXAxisTicks } from "./ChartsGroupedXAxisTicks.js";
|
|
12
12
|
import { ChartsText } from "../ChartsText/index.js";
|
|
13
|
-
import {
|
|
13
|
+
import { isOrdinalScale } from "../internals/scaleGuards.js";
|
|
14
14
|
import { isInfinity } from "../internals/isInfinity.js";
|
|
15
15
|
import { defaultProps, useUtilityClasses } from "./utilities.js";
|
|
16
16
|
import { useDrawingArea } from "../hooks/index.js";
|
|
@@ -80,8 +80,8 @@ export function ChartsXAxisImpl(_ref) {
|
|
|
80
80
|
}
|
|
81
81
|
const labelHeight = label ? getStringSize(label, axisLabelProps.style).height : 0;
|
|
82
82
|
const domain = xScale.domain();
|
|
83
|
-
const
|
|
84
|
-
const skipTickRendering =
|
|
83
|
+
const isScaleOrdinal = isOrdinalScale(xScale);
|
|
84
|
+
const skipTickRendering = isScaleOrdinal ? domain.length === 0 : domain.some(isInfinity);
|
|
85
85
|
let children = null;
|
|
86
86
|
if (!skipTickRendering) {
|
|
87
87
|
children = 'groups' in axis && Array.isArray(axis.groups) ? /*#__PURE__*/_jsx(ChartsGroupedXAxisTicks, _extends({}, inProps)) : /*#__PURE__*/_jsx(ChartsSingleXAxisTicks, _extends({}, inProps, {
|
|
@@ -39,8 +39,12 @@ export function getVisibleLabels(xTicks, {
|
|
|
39
39
|
return new Set(xTicks.filter((item, labelIndex) => {
|
|
40
40
|
const {
|
|
41
41
|
offset,
|
|
42
|
-
labelOffset
|
|
42
|
+
labelOffset,
|
|
43
|
+
formattedValue
|
|
43
44
|
} = item;
|
|
45
|
+
if (formattedValue === '') {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
44
48
|
const textPosition = offset + labelOffset;
|
|
45
49
|
if (labelIndex > 0 && direction * textPosition < direction * (previousTextLimit + tickLabelMinGap)) {
|
|
46
50
|
return false;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
4
4
|
import * as React from 'react';
|
|
5
|
-
import {
|
|
5
|
+
import { isOrdinalScale } from "../internals/scaleGuards.js";
|
|
6
6
|
import { useChartContext } from "../context/ChartProvider/useChartContext.js";
|
|
7
7
|
import { TICK_LABEL_GAP } from "./utilities.js";
|
|
8
8
|
import { useTicksGrouped } from "../hooks/useTicksGrouped.js";
|
|
@@ -34,7 +34,7 @@ function ChartsGroupedYAxisTicks(inProps) {
|
|
|
34
34
|
TickLabel,
|
|
35
35
|
axisTickLabelProps
|
|
36
36
|
} = useAxisTicksProps(inProps);
|
|
37
|
-
if (!
|
|
37
|
+
if (!isOrdinalScale(yScale)) {
|
|
38
38
|
throw new Error('MUI X Charts: ChartsGroupedYAxis only supports the `band` and `point` scale types.');
|
|
39
39
|
}
|
|
40
40
|
const {
|