@mui/x-charts 6.0.0-alpha.6 → 6.0.0-alpha.8
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 +19 -2
- package/BarChart/BarChart.js +84 -22
- package/BarChart/BarElement.d.ts +22 -0
- package/BarChart/BarElement.js +21 -10
- package/BarChart/BarPlot.d.ts +14 -1
- package/BarChart/BarPlot.js +48 -19
- package/BarChart/extremums.js +19 -3
- package/BarChart/formatter.js +3 -1
- package/CHANGELOG.md +213 -28
- package/ChartsAxis/ChartsAxis.d.ts +11 -1
- package/ChartsAxis/ChartsAxis.js +51 -6
- package/ChartsAxisHighlight/ChartsAxisHighlight.d.ts +3 -2
- package/ChartsAxisHighlight/ChartsAxisHighlight.js +11 -3
- package/ChartsLegend/ChartsLegend.d.ts +25 -2
- package/ChartsLegend/ChartsLegend.js +49 -17
- package/ChartsTooltip/ChartsAxisTooltipContent.js +13 -9
- package/ChartsTooltip/ChartsTooltipTable.d.ts +2 -9
- package/ChartsXAxis/ChartsXAxis.js +44 -9
- package/ChartsYAxis/ChartsYAxis.js +44 -9
- package/LineChart/AreaElement.d.ts +22 -0
- package/LineChart/AreaElement.js +31 -11
- package/LineChart/AreaPlot.d.ts +14 -1
- package/LineChart/AreaPlot.js +29 -3
- package/LineChart/LineChart.d.ts +20 -2
- package/LineChart/LineChart.js +63 -11
- package/LineChart/LineElement.d.ts +22 -0
- package/LineChart/LineElement.js +31 -10
- package/LineChart/LinePlot.d.ts +14 -1
- package/LineChart/LinePlot.js +35 -4
- package/LineChart/MarkPlot.d.ts +24 -1
- package/LineChart/MarkPlot.js +29 -4
- package/PieChart/PieArcLabel.js +0 -1
- package/PieChart/PieChart.d.ts +14 -2
- package/PieChart/PieChart.js +52 -10
- package/PieChart/PiePlot.d.ts +27 -1
- package/PieChart/PiePlot.js +29 -6
- package/ScatterChart/ScatterChart.d.ts +18 -2
- package/ScatterChart/ScatterChart.js +56 -10
- package/ScatterChart/ScatterPlot.d.ts +24 -1
- package/ScatterChart/ScatterPlot.js +28 -4
- package/SparkLineChart/SparkLineChart.d.ts +18 -0
- package/SparkLineChart/SparkLineChart.js +29 -6
- package/colorPalettes/colorPalettes.js +2 -2
- package/context/CartesianContextProvider.js +18 -12
- package/esm/BarChart/BarChart.js +88 -26
- package/esm/BarChart/BarElement.js +21 -11
- package/esm/BarChart/BarPlot.js +49 -20
- package/esm/BarChart/extremums.js +18 -2
- package/esm/BarChart/formatter.js +3 -1
- package/esm/ChartsAxis/ChartsAxis.js +51 -6
- package/esm/ChartsAxisHighlight/ChartsAxisHighlight.js +11 -3
- package/esm/ChartsLegend/ChartsLegend.js +47 -14
- package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +13 -9
- package/esm/ChartsXAxis/ChartsXAxis.js +45 -9
- package/esm/ChartsYAxis/ChartsYAxis.js +45 -9
- package/esm/LineChart/AreaElement.js +31 -11
- package/esm/LineChart/AreaPlot.js +31 -4
- package/esm/LineChart/LineChart.js +63 -11
- package/esm/LineChart/LineElement.js +31 -11
- package/esm/LineChart/LinePlot.js +43 -8
- package/esm/LineChart/MarkPlot.js +32 -5
- package/esm/PieChart/PieArcLabel.js +0 -1
- package/esm/PieChart/PieChart.js +52 -10
- package/esm/PieChart/PiePlot.js +31 -6
- package/esm/ScatterChart/ScatterChart.js +56 -10
- package/esm/ScatterChart/ScatterPlot.js +29 -4
- package/esm/SparkLineChart/SparkLineChart.js +29 -6
- package/esm/colorPalettes/colorPalettes.js +2 -2
- package/esm/context/CartesianContextProvider.js +18 -12
- package/esm/hooks/useAxisEvents.js +21 -38
- package/esm/hooks/useTicks.js +11 -8
- package/esm/internals/components/AxisSharedComponents.js +10 -10
- package/hooks/useAxisEvents.js +21 -38
- package/hooks/useTicks.d.ts +20 -5
- package/hooks/useTicks.js +11 -8
- package/index.js +1 -1
- package/internals/components/AxisSharedComponents.d.ts +4 -4
- package/internals/components/AxisSharedComponents.js +15 -15
- package/internals/defaultizeColor.d.ts +1 -0
- package/legacy/BarChart/BarChart.js +93 -29
- package/legacy/BarChart/BarElement.js +20 -10
- package/legacy/BarChart/BarPlot.js +49 -20
- package/legacy/BarChart/extremums.js +22 -2
- package/legacy/BarChart/formatter.js +3 -1
- package/legacy/ChartsAxis/ChartsAxis.js +51 -6
- package/legacy/ChartsAxisHighlight/ChartsAxisHighlight.js +11 -3
- package/legacy/ChartsLegend/ChartsLegend.js +46 -15
- package/legacy/ChartsTooltip/ChartsAxisTooltipContent.js +13 -9
- package/legacy/ChartsXAxis/ChartsXAxis.js +45 -9
- package/legacy/ChartsYAxis/ChartsYAxis.js +45 -9
- package/legacy/LineChart/AreaElement.js +30 -10
- package/legacy/LineChart/AreaPlot.js +29 -4
- package/legacy/LineChart/LineChart.js +63 -11
- package/legacy/LineChart/LineElement.js +30 -10
- package/legacy/LineChart/LinePlot.js +36 -5
- package/legacy/LineChart/MarkPlot.js +30 -5
- package/legacy/PieChart/PieArcLabel.js +0 -1
- package/legacy/PieChart/PieChart.js +52 -10
- package/legacy/PieChart/PiePlot.js +29 -6
- package/legacy/ScatterChart/ScatterChart.js +56 -10
- package/legacy/ScatterChart/ScatterPlot.js +27 -4
- package/legacy/SparkLineChart/SparkLineChart.js +29 -6
- package/legacy/colorPalettes/colorPalettes.js +2 -2
- package/legacy/context/CartesianContextProvider.js +18 -12
- package/legacy/hooks/useAxisEvents.js +21 -37
- package/legacy/hooks/useTicks.js +11 -11
- package/legacy/index.js +1 -1
- package/legacy/internals/components/AxisSharedComponents.js +10 -10
- package/models/axis.d.ts +24 -1
- package/models/seriesType/bar.d.ts +6 -1
- package/modern/BarChart/BarChart.js +85 -23
- package/modern/BarChart/BarElement.js +20 -11
- package/modern/BarChart/BarPlot.js +48 -19
- package/modern/BarChart/extremums.js +18 -2
- package/modern/BarChart/formatter.js +3 -1
- package/modern/ChartsAxis/ChartsAxis.js +51 -6
- package/modern/ChartsAxisHighlight/ChartsAxisHighlight.js +11 -3
- package/modern/ChartsLegend/ChartsLegend.js +46 -14
- package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +13 -9
- package/modern/ChartsXAxis/ChartsXAxis.js +44 -9
- package/modern/ChartsYAxis/ChartsYAxis.js +44 -9
- package/modern/LineChart/AreaElement.js +30 -11
- package/modern/LineChart/AreaPlot.js +31 -4
- package/modern/LineChart/LineChart.js +63 -11
- package/modern/LineChart/LineElement.js +30 -11
- package/modern/LineChart/LinePlot.js +37 -5
- package/modern/LineChart/MarkPlot.js +31 -5
- package/modern/PieChart/PieArcLabel.js +0 -1
- package/modern/PieChart/PieChart.js +52 -10
- package/modern/PieChart/PiePlot.js +30 -6
- package/modern/ScatterChart/ScatterChart.js +56 -10
- package/modern/ScatterChart/ScatterPlot.js +28 -4
- package/modern/SparkLineChart/SparkLineChart.js +29 -6
- package/modern/colorPalettes/colorPalettes.js +2 -2
- package/modern/context/CartesianContextProvider.js +18 -12
- package/modern/hooks/useAxisEvents.js +21 -38
- package/modern/hooks/useTicks.js +11 -8
- package/modern/index.js +1 -1
- package/modern/internals/components/AxisSharedComponents.js +10 -10
- package/package.json +5 -5
- package/themeAugmentation/components.d.ts +0 -10
- package/themeAugmentation/overrides.d.ts +0 -2
|
@@ -8,39 +8,39 @@ export const AxisRoot = styled('g', {
|
|
|
8
8
|
})({
|
|
9
9
|
[`&.${axisClasses.directionY}`]: {
|
|
10
10
|
[`.${axisClasses.tickLabel}`]: {
|
|
11
|
-
|
|
11
|
+
dominantBaseline: 'middle'
|
|
12
12
|
},
|
|
13
13
|
[`.${axisClasses.label}`]: {
|
|
14
|
-
|
|
14
|
+
dominantBaseline: 'auto',
|
|
15
15
|
textAnchor: 'middle'
|
|
16
16
|
}
|
|
17
17
|
},
|
|
18
18
|
[`&.${axisClasses.left}`]: {
|
|
19
19
|
[`.${axisClasses.tickLabel}`]: {
|
|
20
|
-
|
|
20
|
+
dominantBaseline: 'central',
|
|
21
21
|
textAnchor: 'end'
|
|
22
22
|
}
|
|
23
23
|
},
|
|
24
24
|
[`&.${axisClasses.right}`]: {
|
|
25
25
|
[`.${axisClasses.tickLabel}`]: {
|
|
26
|
-
|
|
26
|
+
dominantBaseline: 'central',
|
|
27
27
|
textAnchor: 'start'
|
|
28
28
|
}
|
|
29
29
|
},
|
|
30
30
|
[`&.${axisClasses.bottom}`]: {
|
|
31
31
|
[`.${axisClasses.tickLabel}, .${axisClasses.label}`]: {
|
|
32
|
-
|
|
32
|
+
dominantBaseline: 'hanging',
|
|
33
33
|
textAnchor: 'middle'
|
|
34
34
|
}
|
|
35
35
|
},
|
|
36
36
|
[`&.${axisClasses.top}`]: {
|
|
37
37
|
[`.${axisClasses.tickLabel}, .${axisClasses.label}`]: {
|
|
38
|
-
|
|
38
|
+
dominantBaseline: 'baseline',
|
|
39
39
|
textAnchor: 'middle'
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
});
|
|
43
|
-
export const
|
|
43
|
+
export const ChartsLine = styled('line', {
|
|
44
44
|
name: 'MuiChartsAxis',
|
|
45
45
|
slot: 'Line',
|
|
46
46
|
overridesResolver: (props, styles) => styles.line
|
|
@@ -51,7 +51,7 @@ export const Line = styled('line', {
|
|
|
51
51
|
shapeRendering: 'crispEdges',
|
|
52
52
|
strokeWidth: 1
|
|
53
53
|
}));
|
|
54
|
-
export const
|
|
54
|
+
export const ChartsTick = styled('line', {
|
|
55
55
|
name: 'MuiChartsAxis',
|
|
56
56
|
slot: 'Tick',
|
|
57
57
|
overridesResolver: (props, styles) => styles.tick
|
|
@@ -61,7 +61,7 @@ export const Tick = styled('line', {
|
|
|
61
61
|
stroke: theme.palette.text.primary,
|
|
62
62
|
shapeRendering: 'crispEdges'
|
|
63
63
|
}));
|
|
64
|
-
export const
|
|
64
|
+
export const ChartsTickLabel = styled('text', {
|
|
65
65
|
name: 'MuiChartsAxis',
|
|
66
66
|
slot: 'TickLabel',
|
|
67
67
|
overridesResolver: (props, styles) => styles.tickLabel
|
|
@@ -70,7 +70,7 @@ export const TickLabel = styled('text', {
|
|
|
70
70
|
}) => _extends({}, theme.typography.caption, {
|
|
71
71
|
fill: theme.palette.text.primary
|
|
72
72
|
}));
|
|
73
|
-
export const
|
|
73
|
+
export const ChartsLabel = styled('text', {
|
|
74
74
|
name: 'MuiChartsAxis',
|
|
75
75
|
slot: 'Label',
|
|
76
76
|
overridesResolver: (props, styles) => styles.label
|
package/hooks/useAxisEvents.js
CHANGED
|
@@ -41,66 +41,49 @@ const useAxisEvents = disableAxisListener => {
|
|
|
41
41
|
if (element === null || disableAxisListener) {
|
|
42
42
|
return () => {};
|
|
43
43
|
}
|
|
44
|
-
const
|
|
45
|
-
if (usedYAxis === null) {
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
48
|
-
const {
|
|
49
|
-
scale: yScale,
|
|
50
|
-
data: yAxisData
|
|
51
|
-
} = yAxis[usedYAxis];
|
|
52
|
-
if (!(0, _isBandScale.isBandScale)(yScale)) {
|
|
53
|
-
return {
|
|
54
|
-
value: yScale.invert(y)
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
const dataIndex = Math.floor((y - yScale.range()[0]) / yScale.step());
|
|
58
|
-
if (dataIndex < 0 || dataIndex >= yAxisData.length) {
|
|
59
|
-
return null;
|
|
60
|
-
}
|
|
61
|
-
return {
|
|
62
|
-
index: dataIndex,
|
|
63
|
-
value: yAxisData[dataIndex]
|
|
64
|
-
};
|
|
65
|
-
};
|
|
66
|
-
const getUpdateX = x => {
|
|
44
|
+
const getUpdate = (axisConfig, mouseValue) => {
|
|
67
45
|
if (usedXAxis === null) {
|
|
68
46
|
return null;
|
|
69
47
|
}
|
|
70
48
|
const {
|
|
71
|
-
scale
|
|
72
|
-
data:
|
|
73
|
-
} =
|
|
74
|
-
if (!(0, _isBandScale.isBandScale)(
|
|
75
|
-
const value =
|
|
76
|
-
|
|
49
|
+
scale,
|
|
50
|
+
data: axisData
|
|
51
|
+
} = axisConfig;
|
|
52
|
+
if (!(0, _isBandScale.isBandScale)(scale)) {
|
|
53
|
+
const value = scale.invert(mouseValue);
|
|
54
|
+
if (axisData === undefined) {
|
|
55
|
+
return {
|
|
56
|
+
value
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
const closestIndex = axisData?.findIndex((v, index) => {
|
|
77
60
|
if (v > value) {
|
|
78
61
|
// @ts-ignore
|
|
79
|
-
if (index === 0 || Math.abs(value - v) <= Math.abs(value -
|
|
62
|
+
if (index === 0 || Math.abs(value - v) <= Math.abs(value - axisData[index - 1])) {
|
|
80
63
|
return true;
|
|
81
64
|
}
|
|
82
65
|
}
|
|
83
66
|
if (v <= value) {
|
|
84
|
-
if (index ===
|
|
67
|
+
if (index === axisData.length - 1 ||
|
|
85
68
|
// @ts-ignore
|
|
86
|
-
Math.abs(value - v) < Math.abs(value -
|
|
69
|
+
Math.abs(value - v) < Math.abs(value - axisData[index + 1])) {
|
|
87
70
|
return true;
|
|
88
71
|
}
|
|
89
72
|
}
|
|
90
73
|
return false;
|
|
91
74
|
});
|
|
92
75
|
return {
|
|
93
|
-
value: closestIndex !== undefined && closestIndex >= 0 ?
|
|
76
|
+
value: closestIndex !== undefined && closestIndex >= 0 ? axisData[closestIndex] : value,
|
|
94
77
|
index: closestIndex
|
|
95
78
|
};
|
|
96
79
|
}
|
|
97
|
-
const dataIndex =
|
|
98
|
-
if (dataIndex < 0 || dataIndex >=
|
|
80
|
+
const dataIndex = scale.bandwidth() === 0 ? Math.floor((mouseValue - Math.min(...scale.range()) + scale.step() / 2) / scale.step()) : Math.floor((mouseValue - Math.min(...scale.range())) / scale.step());
|
|
81
|
+
if (dataIndex < 0 || dataIndex >= axisData.length) {
|
|
99
82
|
return null;
|
|
100
83
|
}
|
|
101
84
|
return {
|
|
102
85
|
index: dataIndex,
|
|
103
|
-
value:
|
|
86
|
+
value: axisData[dataIndex]
|
|
104
87
|
};
|
|
105
88
|
};
|
|
106
89
|
const handleMouseOut = () => {
|
|
@@ -138,8 +121,8 @@ const useAxisEvents = disableAxisListener => {
|
|
|
138
121
|
});
|
|
139
122
|
return;
|
|
140
123
|
}
|
|
141
|
-
const newStateX =
|
|
142
|
-
const newStateY =
|
|
124
|
+
const newStateX = getUpdate(xAxis[usedXAxis], svgPt.x);
|
|
125
|
+
const newStateY = getUpdate(yAxis[usedYAxis], svgPt.y);
|
|
143
126
|
dispatch({
|
|
144
127
|
type: 'updateAxis',
|
|
145
128
|
data: {
|
package/hooks/useTicks.d.ts
CHANGED
|
@@ -1,11 +1,26 @@
|
|
|
1
1
|
import { D3Scale } from '../models/axis';
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
export interface TickParams {
|
|
3
|
+
/**
|
|
4
|
+
* Maximal step between two ticks.
|
|
5
|
+
* When using time data, the value is assumed to be in ms.
|
|
6
|
+
* Not supported by categorical axis (band, points).
|
|
7
|
+
*/
|
|
8
|
+
tickMaxStep?: number;
|
|
9
|
+
/**
|
|
10
|
+
* Maximal step between two ticks.
|
|
11
|
+
* When using time data, the value is assumed to be in ms.
|
|
12
|
+
* Not supported by categorical axis (band, points).
|
|
13
|
+
*/
|
|
14
|
+
tickMinStep?: number;
|
|
15
|
+
/**
|
|
16
|
+
* The number of ticks. This number is not guaranted.
|
|
17
|
+
* Not supported by categorical axis (band, points).
|
|
18
|
+
*/
|
|
19
|
+
tickNumber?: number;
|
|
20
|
+
}
|
|
7
21
|
export declare function getTicksNumber(params: TickParams & {
|
|
8
22
|
range: any[];
|
|
23
|
+
domain: any[];
|
|
9
24
|
}): number;
|
|
10
25
|
declare function useTicks(options: {
|
|
11
26
|
scale: D3Scale;
|
package/hooks/useTicks.js
CHANGED
|
@@ -11,13 +11,16 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
|
11
11
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
12
12
|
function getTicksNumber(params) {
|
|
13
13
|
const {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
range
|
|
14
|
+
tickMaxStep,
|
|
15
|
+
tickMinStep,
|
|
16
|
+
tickNumber,
|
|
17
|
+
range,
|
|
18
|
+
domain
|
|
18
19
|
} = params;
|
|
19
|
-
const
|
|
20
|
-
|
|
20
|
+
const maxTicks = tickMinStep === undefined ? 999 : Math.floor(Math.abs(domain[1] - domain[0]) / tickMinStep);
|
|
21
|
+
const minTicks = tickMaxStep === undefined ? 2 : Math.ceil(Math.abs(domain[1] - domain[0]) / tickMaxStep);
|
|
22
|
+
const defaultizedTickNumber = tickNumber ?? Math.floor(Math.abs(range[1] - range[0]) / 50);
|
|
23
|
+
return Math.min(maxTicks, Math.max(minTicks, defaultizedTickNumber));
|
|
21
24
|
}
|
|
22
25
|
function useTicks(options) {
|
|
23
26
|
const {
|
|
@@ -31,9 +34,9 @@ function useTicks(options) {
|
|
|
31
34
|
const domain = scale.domain();
|
|
32
35
|
if (scale.bandwidth() > 0) {
|
|
33
36
|
// scale type = 'band'
|
|
34
|
-
return [...domain.map(
|
|
37
|
+
return [...domain.map(value => ({
|
|
35
38
|
formattedValue: valueFormatter?.(value) ?? value,
|
|
36
|
-
offset:
|
|
39
|
+
offset: scale(value) - (scale.step() - scale.bandwidth()) / 2,
|
|
37
40
|
labelOffset: scale.step() / 2
|
|
38
41
|
})), {
|
|
39
42
|
formattedValue: undefined,
|
package/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
export declare const AxisRoot: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme>, Pick<import("react").SVGProps<SVGGElement>, keyof import("react").SVGProps<SVGGElement>>, {}>;
|
|
3
|
-
export declare const
|
|
4
|
-
export declare const
|
|
5
|
-
export declare const
|
|
6
|
-
export declare const
|
|
3
|
+
export declare const ChartsLine: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme>, Pick<import("react").SVGLineElementAttributes<SVGLineElement>, keyof import("react").SVGLineElementAttributes<SVGLineElement>>, {}>;
|
|
4
|
+
export declare const ChartsTick: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme>, Pick<import("react").SVGLineElementAttributes<SVGLineElement>, keyof import("react").SVGLineElementAttributes<SVGLineElement>>, {}>;
|
|
5
|
+
export declare const ChartsTickLabel: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme>, Pick<import("react").SVGTextElementAttributes<SVGTextElement>, keyof import("react").SVGTextElementAttributes<SVGTextElement>>, {}>;
|
|
6
|
+
export declare const ChartsLabel: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme>, Pick<import("react").SVGTextElementAttributes<SVGTextElement>, keyof import("react").SVGTextElementAttributes<SVGTextElement>>, {}>;
|
|
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.
|
|
7
|
+
exports.ChartsTickLabel = exports.ChartsTick = exports.ChartsLine = exports.ChartsLabel = exports.AxisRoot = void 0;
|
|
8
8
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
9
9
|
var _styles = require("@mui/material/styles");
|
|
10
10
|
var _axisClasses = require("../../ChartsAxis/axisClasses");
|
|
@@ -15,40 +15,40 @@ const AxisRoot = (0, _styles.styled)('g', {
|
|
|
15
15
|
})({
|
|
16
16
|
[`&.${_axisClasses.axisClasses.directionY}`]: {
|
|
17
17
|
[`.${_axisClasses.axisClasses.tickLabel}`]: {
|
|
18
|
-
|
|
18
|
+
dominantBaseline: 'middle'
|
|
19
19
|
},
|
|
20
20
|
[`.${_axisClasses.axisClasses.label}`]: {
|
|
21
|
-
|
|
21
|
+
dominantBaseline: 'auto',
|
|
22
22
|
textAnchor: 'middle'
|
|
23
23
|
}
|
|
24
24
|
},
|
|
25
25
|
[`&.${_axisClasses.axisClasses.left}`]: {
|
|
26
26
|
[`.${_axisClasses.axisClasses.tickLabel}`]: {
|
|
27
|
-
|
|
27
|
+
dominantBaseline: 'central',
|
|
28
28
|
textAnchor: 'end'
|
|
29
29
|
}
|
|
30
30
|
},
|
|
31
31
|
[`&.${_axisClasses.axisClasses.right}`]: {
|
|
32
32
|
[`.${_axisClasses.axisClasses.tickLabel}`]: {
|
|
33
|
-
|
|
33
|
+
dominantBaseline: 'central',
|
|
34
34
|
textAnchor: 'start'
|
|
35
35
|
}
|
|
36
36
|
},
|
|
37
37
|
[`&.${_axisClasses.axisClasses.bottom}`]: {
|
|
38
38
|
[`.${_axisClasses.axisClasses.tickLabel}, .${_axisClasses.axisClasses.label}`]: {
|
|
39
|
-
|
|
39
|
+
dominantBaseline: 'hanging',
|
|
40
40
|
textAnchor: 'middle'
|
|
41
41
|
}
|
|
42
42
|
},
|
|
43
43
|
[`&.${_axisClasses.axisClasses.top}`]: {
|
|
44
44
|
[`.${_axisClasses.axisClasses.tickLabel}, .${_axisClasses.axisClasses.label}`]: {
|
|
45
|
-
|
|
45
|
+
dominantBaseline: 'baseline',
|
|
46
46
|
textAnchor: 'middle'
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
});
|
|
50
50
|
exports.AxisRoot = AxisRoot;
|
|
51
|
-
const
|
|
51
|
+
const ChartsLine = (0, _styles.styled)('line', {
|
|
52
52
|
name: 'MuiChartsAxis',
|
|
53
53
|
slot: 'Line',
|
|
54
54
|
overridesResolver: (props, styles) => styles.line
|
|
@@ -59,8 +59,8 @@ const Line = (0, _styles.styled)('line', {
|
|
|
59
59
|
shapeRendering: 'crispEdges',
|
|
60
60
|
strokeWidth: 1
|
|
61
61
|
}));
|
|
62
|
-
exports.
|
|
63
|
-
const
|
|
62
|
+
exports.ChartsLine = ChartsLine;
|
|
63
|
+
const ChartsTick = (0, _styles.styled)('line', {
|
|
64
64
|
name: 'MuiChartsAxis',
|
|
65
65
|
slot: 'Tick',
|
|
66
66
|
overridesResolver: (props, styles) => styles.tick
|
|
@@ -70,8 +70,8 @@ const Tick = (0, _styles.styled)('line', {
|
|
|
70
70
|
stroke: theme.palette.text.primary,
|
|
71
71
|
shapeRendering: 'crispEdges'
|
|
72
72
|
}));
|
|
73
|
-
exports.
|
|
74
|
-
const
|
|
73
|
+
exports.ChartsTick = ChartsTick;
|
|
74
|
+
const ChartsTickLabel = (0, _styles.styled)('text', {
|
|
75
75
|
name: 'MuiChartsAxis',
|
|
76
76
|
slot: 'TickLabel',
|
|
77
77
|
overridesResolver: (props, styles) => styles.tickLabel
|
|
@@ -80,8 +80,8 @@ const TickLabel = (0, _styles.styled)('text', {
|
|
|
80
80
|
}) => (0, _extends2.default)({}, theme.typography.caption, {
|
|
81
81
|
fill: theme.palette.text.primary
|
|
82
82
|
}));
|
|
83
|
-
exports.
|
|
84
|
-
const
|
|
83
|
+
exports.ChartsTickLabel = ChartsTickLabel;
|
|
84
|
+
const ChartsLabel = (0, _styles.styled)('text', {
|
|
85
85
|
name: 'MuiChartsAxis',
|
|
86
86
|
slot: 'Label',
|
|
87
87
|
overridesResolver: (props, styles) => styles.label
|
|
@@ -90,4 +90,4 @@ const Label = (0, _styles.styled)('text', {
|
|
|
90
90
|
}) => (0, _extends2.default)({}, theme.typography.body1, {
|
|
91
91
|
fill: theme.palette.text.primary
|
|
92
92
|
}));
|
|
93
|
-
exports.
|
|
93
|
+
exports.ChartsLabel = ChartsLabel;
|
|
@@ -39,6 +39,7 @@ export declare function defaultizeColor(series: AllSeriesType, seriesIndex: numb
|
|
|
39
39
|
data?: number[] | undefined;
|
|
40
40
|
dataKey?: string | undefined;
|
|
41
41
|
label?: string | undefined;
|
|
42
|
+
layout?: "horizontal" | "vertical" | undefined;
|
|
42
43
|
id?: string | undefined;
|
|
43
44
|
color: string;
|
|
44
45
|
valueFormatter?: ((value: number) => string) | undefined;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
2
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
3
3
|
import * as React from 'react';
|
|
4
4
|
import useId from '@mui/utils/useId';
|
|
5
5
|
import PropTypes from 'prop-types';
|
|
6
6
|
import { BarPlot } from './BarPlot';
|
|
7
7
|
import { ResponsiveChartContainer } from '../ResponsiveChartContainer';
|
|
8
8
|
import { ChartsAxis } from '../ChartsAxis';
|
|
9
|
-
import { DEFAULT_X_AXIS_KEY } from '../constants';
|
|
9
|
+
import { DEFAULT_X_AXIS_KEY, DEFAULT_Y_AXIS_KEY } from '../constants';
|
|
10
10
|
import { ChartsTooltip } from '../ChartsTooltip';
|
|
11
11
|
import { ChartsLegend } from '../ChartsLegend';
|
|
12
12
|
import { ChartsAxisHighlight } from '../ChartsAxisHighlight';
|
|
@@ -23,6 +23,7 @@ var BarChart = /*#__PURE__*/React.forwardRef(function BarChart(props, ref) {
|
|
|
23
23
|
colors = props.colors,
|
|
24
24
|
dataset = props.dataset,
|
|
25
25
|
sx = props.sx,
|
|
26
|
+
layout = props.layout,
|
|
26
27
|
tooltip = props.tooltip,
|
|
27
28
|
axisHighlight = props.axisHighlight,
|
|
28
29
|
legend = props.legend,
|
|
@@ -30,47 +31,72 @@ var BarChart = /*#__PURE__*/React.forwardRef(function BarChart(props, ref) {
|
|
|
30
31
|
leftAxis = props.leftAxis,
|
|
31
32
|
rightAxis = props.rightAxis,
|
|
32
33
|
bottomAxis = props.bottomAxis,
|
|
33
|
-
children = props.children
|
|
34
|
+
children = props.children,
|
|
35
|
+
slots = props.slots,
|
|
36
|
+
slotProps = props.slotProps;
|
|
34
37
|
var id = useId();
|
|
35
38
|
var clipPathId = "".concat(id, "-clip-path");
|
|
39
|
+
var hasHorizontalSeries = layout === 'horizontal' || layout === undefined && series.some(function (item) {
|
|
40
|
+
return item.layout === 'horizontal';
|
|
41
|
+
});
|
|
42
|
+
var defaultAxisConfig = {
|
|
43
|
+
scaleType: 'band',
|
|
44
|
+
data: Array.from({
|
|
45
|
+
length: Math.max.apply(Math, _toConsumableArray(series.map(function (s) {
|
|
46
|
+
var _ref, _s$data;
|
|
47
|
+
return ((_ref = (_s$data = s.data) != null ? _s$data : dataset) != null ? _ref : []).length;
|
|
48
|
+
})))
|
|
49
|
+
}, function (_, index) {
|
|
50
|
+
return index;
|
|
51
|
+
})
|
|
52
|
+
};
|
|
53
|
+
var defaultizedAxisHighlight = _extends({}, hasHorizontalSeries ? {
|
|
54
|
+
y: 'band'
|
|
55
|
+
} : {
|
|
56
|
+
x: 'band'
|
|
57
|
+
}, axisHighlight);
|
|
36
58
|
return /*#__PURE__*/_jsxs(ResponsiveChartContainer, {
|
|
37
59
|
ref: ref,
|
|
38
60
|
series: series.map(function (s) {
|
|
39
61
|
return _extends({
|
|
40
62
|
type: 'bar'
|
|
41
|
-
}, s
|
|
63
|
+
}, s, {
|
|
64
|
+
layout: hasHorizontalSeries ? 'horizontal' : 'vertical'
|
|
65
|
+
});
|
|
42
66
|
}),
|
|
43
67
|
width: width,
|
|
44
68
|
height: height,
|
|
45
69
|
margin: margin,
|
|
46
|
-
xAxis: xAxis != null ? xAxis : [{
|
|
47
|
-
id: DEFAULT_X_AXIS_KEY
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
return ((_ref = (_s$data = s.data) != null ? _s$data : dataset) != null ? _ref : []).length;
|
|
53
|
-
})))
|
|
54
|
-
}, function (_, index) {
|
|
55
|
-
return index;
|
|
56
|
-
})
|
|
57
|
-
}],
|
|
58
|
-
yAxis: yAxis,
|
|
70
|
+
xAxis: xAxis != null ? xAxis : hasHorizontalSeries ? undefined : [_extends({
|
|
71
|
+
id: DEFAULT_X_AXIS_KEY
|
|
72
|
+
}, defaultAxisConfig)],
|
|
73
|
+
yAxis: yAxis != null ? yAxis : hasHorizontalSeries ? [_extends({
|
|
74
|
+
id: DEFAULT_Y_AXIS_KEY
|
|
75
|
+
}, defaultAxisConfig)] : undefined,
|
|
59
76
|
colors: colors,
|
|
60
77
|
dataset: dataset,
|
|
61
78
|
sx: sx,
|
|
62
79
|
disableAxisListener: (tooltip == null ? void 0 : tooltip.trigger) !== 'axis' && (axisHighlight == null ? void 0 : axisHighlight.x) === 'none' && (axisHighlight == null ? void 0 : axisHighlight.y) === 'none',
|
|
63
80
|
children: [/*#__PURE__*/_jsx("g", {
|
|
64
81
|
clipPath: "url(#".concat(clipPathId, ")"),
|
|
65
|
-
children: /*#__PURE__*/_jsx(BarPlot, {
|
|
82
|
+
children: /*#__PURE__*/_jsx(BarPlot, {
|
|
83
|
+
slots: slots,
|
|
84
|
+
slotProps: slotProps
|
|
85
|
+
})
|
|
66
86
|
}), /*#__PURE__*/_jsx(ChartsAxis, {
|
|
67
87
|
topAxis: topAxis,
|
|
68
88
|
leftAxis: leftAxis,
|
|
69
89
|
rightAxis: rightAxis,
|
|
70
|
-
bottomAxis: bottomAxis
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
90
|
+
bottomAxis: bottomAxis,
|
|
91
|
+
slots: slots,
|
|
92
|
+
slotProps: slotProps
|
|
93
|
+
}), /*#__PURE__*/_jsx(ChartsLegend, _extends({}, legend, {
|
|
94
|
+
slots: slots,
|
|
95
|
+
slotProps: slotProps
|
|
96
|
+
})), /*#__PURE__*/_jsx(ChartsAxisHighlight, _extends({}, defaultizedAxisHighlight)), /*#__PURE__*/_jsx(ChartsTooltip, _extends({}, tooltip, {
|
|
97
|
+
slots: slots,
|
|
98
|
+
slotProps: slotProps
|
|
99
|
+
})), /*#__PURE__*/_jsx(ChartsClipPath, {
|
|
74
100
|
id: clipPathId
|
|
75
101
|
}), children]
|
|
76
102
|
});
|
|
@@ -82,7 +108,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
82
108
|
// ----------------------------------------------------------------------
|
|
83
109
|
axisHighlight: PropTypes.shape({
|
|
84
110
|
x: PropTypes.oneOf(['band', 'line', 'none']),
|
|
85
|
-
y: PropTypes.oneOf(['line', 'none'])
|
|
111
|
+
y: PropTypes.oneOf(['band', 'line', 'none'])
|
|
86
112
|
}),
|
|
87
113
|
/**
|
|
88
114
|
* Indicate which axis to display the bottom of the charts.
|
|
@@ -98,8 +124,13 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
98
124
|
label: PropTypes.string,
|
|
99
125
|
labelFontSize: PropTypes.number,
|
|
100
126
|
position: PropTypes.oneOf(['bottom', 'top']),
|
|
127
|
+
slotProps: PropTypes.object,
|
|
128
|
+
slots: PropTypes.object,
|
|
101
129
|
stroke: PropTypes.string,
|
|
102
130
|
tickFontSize: PropTypes.number,
|
|
131
|
+
tickMaxStep: PropTypes.number,
|
|
132
|
+
tickMinStep: PropTypes.number,
|
|
133
|
+
tickNumber: PropTypes.number,
|
|
103
134
|
tickSize: PropTypes.number
|
|
104
135
|
}), PropTypes.string]),
|
|
105
136
|
children: PropTypes.node,
|
|
@@ -112,6 +143,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
112
143
|
desc: PropTypes.string,
|
|
113
144
|
disableAxisListener: PropTypes.bool,
|
|
114
145
|
height: PropTypes.number,
|
|
146
|
+
layout: PropTypes.oneOf(['horizontal', 'vertical']),
|
|
115
147
|
/**
|
|
116
148
|
* Indicate which axis to display the left of the charts.
|
|
117
149
|
* Can be a string (the id of the axis) or an object `ChartsYAxisProps`.
|
|
@@ -126,8 +158,13 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
126
158
|
label: PropTypes.string,
|
|
127
159
|
labelFontSize: PropTypes.number,
|
|
128
160
|
position: PropTypes.oneOf(['left', 'right']),
|
|
161
|
+
slotProps: PropTypes.object,
|
|
162
|
+
slots: PropTypes.object,
|
|
129
163
|
stroke: PropTypes.string,
|
|
130
164
|
tickFontSize: PropTypes.number,
|
|
165
|
+
tickMaxStep: PropTypes.number,
|
|
166
|
+
tickMinStep: PropTypes.number,
|
|
167
|
+
tickNumber: PropTypes.number,
|
|
131
168
|
tickSize: PropTypes.number
|
|
132
169
|
}), PropTypes.string]),
|
|
133
170
|
legend: PropTypes.shape({
|
|
@@ -144,6 +181,8 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
144
181
|
horizontal: PropTypes.oneOf(['left', 'middle', 'right']).isRequired,
|
|
145
182
|
vertical: PropTypes.oneOf(['bottom', 'middle', 'top']).isRequired
|
|
146
183
|
}),
|
|
184
|
+
slotProps: PropTypes.object,
|
|
185
|
+
slots: PropTypes.object,
|
|
147
186
|
spacing: PropTypes.number
|
|
148
187
|
}),
|
|
149
188
|
margin: PropTypes.shape({
|
|
@@ -166,8 +205,13 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
166
205
|
label: PropTypes.string,
|
|
167
206
|
labelFontSize: PropTypes.number,
|
|
168
207
|
position: PropTypes.oneOf(['left', 'right']),
|
|
208
|
+
slotProps: PropTypes.object,
|
|
209
|
+
slots: PropTypes.object,
|
|
169
210
|
stroke: PropTypes.string,
|
|
170
211
|
tickFontSize: PropTypes.number,
|
|
212
|
+
tickMaxStep: PropTypes.number,
|
|
213
|
+
tickMinStep: PropTypes.number,
|
|
214
|
+
tickNumber: PropTypes.number,
|
|
171
215
|
tickSize: PropTypes.number
|
|
172
216
|
}), PropTypes.string]),
|
|
173
217
|
series: PropTypes.arrayOf(PropTypes.shape({
|
|
@@ -180,6 +224,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
180
224
|
}),
|
|
181
225
|
id: PropTypes.string,
|
|
182
226
|
label: PropTypes.string,
|
|
227
|
+
layout: PropTypes.oneOf(['horizontal', 'vertical']),
|
|
183
228
|
stack: PropTypes.string,
|
|
184
229
|
stackOffset: PropTypes.oneOf(['diverging', 'expand', 'none', 'silhouette', 'wiggle']),
|
|
185
230
|
stackOrder: PropTypes.oneOf(['appearance', 'ascending', 'descending', 'insideOut', 'none', 'reverse']),
|
|
@@ -188,6 +233,16 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
188
233
|
xAxisKey: PropTypes.string,
|
|
189
234
|
yAxisKey: PropTypes.string
|
|
190
235
|
})).isRequired,
|
|
236
|
+
/**
|
|
237
|
+
* The props used for each component slot.
|
|
238
|
+
* @default {}
|
|
239
|
+
*/
|
|
240
|
+
slotProps: PropTypes.object,
|
|
241
|
+
/**
|
|
242
|
+
* Overridable component slots.
|
|
243
|
+
* @default {}
|
|
244
|
+
*/
|
|
245
|
+
slots: PropTypes.object,
|
|
191
246
|
sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
|
|
192
247
|
title: PropTypes.string,
|
|
193
248
|
tooltip: PropTypes.shape({
|
|
@@ -210,8 +265,13 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
210
265
|
label: PropTypes.string,
|
|
211
266
|
labelFontSize: PropTypes.number,
|
|
212
267
|
position: PropTypes.oneOf(['bottom', 'top']),
|
|
268
|
+
slotProps: PropTypes.object,
|
|
269
|
+
slots: PropTypes.object,
|
|
213
270
|
stroke: PropTypes.string,
|
|
214
271
|
tickFontSize: PropTypes.number,
|
|
272
|
+
tickMaxStep: PropTypes.number,
|
|
273
|
+
tickMinStep: PropTypes.number,
|
|
274
|
+
tickNumber: PropTypes.number,
|
|
215
275
|
tickSize: PropTypes.number
|
|
216
276
|
}), PropTypes.string]),
|
|
217
277
|
viewBox: PropTypes.shape({
|
|
@@ -234,15 +294,17 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
234
294
|
label: PropTypes.string,
|
|
235
295
|
labelFontSize: PropTypes.number,
|
|
236
296
|
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
237
|
-
maxTicks: PropTypes.number,
|
|
238
297
|
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
239
|
-
minTicks: PropTypes.number,
|
|
240
298
|
position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
|
|
241
299
|
scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
|
|
300
|
+
slotProps: PropTypes.object,
|
|
301
|
+
slots: PropTypes.object,
|
|
242
302
|
stroke: PropTypes.string,
|
|
243
303
|
tickFontSize: PropTypes.number,
|
|
304
|
+
tickMaxStep: PropTypes.number,
|
|
305
|
+
tickMinStep: PropTypes.number,
|
|
306
|
+
tickNumber: PropTypes.number,
|
|
244
307
|
tickSize: PropTypes.number,
|
|
245
|
-
tickSpacing: PropTypes.number,
|
|
246
308
|
valueFormatter: PropTypes.func
|
|
247
309
|
})),
|
|
248
310
|
yAxis: PropTypes.arrayOf(PropTypes.shape({
|
|
@@ -258,15 +320,17 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
258
320
|
label: PropTypes.string,
|
|
259
321
|
labelFontSize: PropTypes.number,
|
|
260
322
|
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
261
|
-
maxTicks: PropTypes.number,
|
|
262
323
|
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
263
|
-
minTicks: PropTypes.number,
|
|
264
324
|
position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
|
|
265
325
|
scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
|
|
326
|
+
slotProps: PropTypes.object,
|
|
327
|
+
slots: PropTypes.object,
|
|
266
328
|
stroke: PropTypes.string,
|
|
267
329
|
tickFontSize: PropTypes.number,
|
|
330
|
+
tickMaxStep: PropTypes.number,
|
|
331
|
+
tickMinStep: PropTypes.number,
|
|
332
|
+
tickNumber: PropTypes.number,
|
|
268
333
|
tickSize: PropTypes.number,
|
|
269
|
-
tickSpacing: PropTypes.number,
|
|
270
334
|
valueFormatter: PropTypes.func
|
|
271
335
|
}))
|
|
272
336
|
} : void 0;
|