@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
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
1
2
|
import * as React from 'react';
|
|
2
3
|
import { InteractionContext } from '../context/InteractionProvider';
|
|
3
4
|
import { CartesianContext } from '../context/CartesianContextProvider';
|
|
@@ -30,64 +31,47 @@ export var useAxisEvents = function useAxisEvents(disableAxisListener) {
|
|
|
30
31
|
if (element === null || disableAxisListener) {
|
|
31
32
|
return function () {};
|
|
32
33
|
}
|
|
33
|
-
var
|
|
34
|
-
if (usedYAxis === null) {
|
|
35
|
-
return null;
|
|
36
|
-
}
|
|
37
|
-
var _yAxis$usedYAxis = yAxis[usedYAxis],
|
|
38
|
-
yScale = _yAxis$usedYAxis.scale,
|
|
39
|
-
yAxisData = _yAxis$usedYAxis.data;
|
|
40
|
-
if (!isBandScale(yScale)) {
|
|
41
|
-
return {
|
|
42
|
-
value: yScale.invert(y)
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
var dataIndex = Math.floor((y - yScale.range()[0]) / yScale.step());
|
|
46
|
-
if (dataIndex < 0 || dataIndex >= yAxisData.length) {
|
|
47
|
-
return null;
|
|
48
|
-
}
|
|
49
|
-
return {
|
|
50
|
-
index: dataIndex,
|
|
51
|
-
value: yAxisData[dataIndex]
|
|
52
|
-
};
|
|
53
|
-
};
|
|
54
|
-
var getUpdateX = function getUpdateX(x) {
|
|
34
|
+
var getUpdate = function getUpdate(axisConfig, mouseValue) {
|
|
55
35
|
if (usedXAxis === null) {
|
|
56
36
|
return null;
|
|
57
37
|
}
|
|
58
|
-
var
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
38
|
+
var scale = axisConfig.scale,
|
|
39
|
+
axisData = axisConfig.data;
|
|
40
|
+
if (!isBandScale(scale)) {
|
|
41
|
+
var value = scale.invert(mouseValue);
|
|
42
|
+
if (axisData === undefined) {
|
|
43
|
+
return {
|
|
44
|
+
value: value
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
var closestIndex = axisData == null ? void 0 : axisData.findIndex(function (v, index) {
|
|
64
48
|
if (v > value) {
|
|
65
49
|
// @ts-ignore
|
|
66
|
-
if (index === 0 || Math.abs(value - v) <= Math.abs(value -
|
|
50
|
+
if (index === 0 || Math.abs(value - v) <= Math.abs(value - axisData[index - 1])) {
|
|
67
51
|
return true;
|
|
68
52
|
}
|
|
69
53
|
}
|
|
70
54
|
if (v <= value) {
|
|
71
|
-
if (index ===
|
|
55
|
+
if (index === axisData.length - 1 ||
|
|
72
56
|
// @ts-ignore
|
|
73
|
-
Math.abs(value - v) < Math.abs(value -
|
|
57
|
+
Math.abs(value - v) < Math.abs(value - axisData[index + 1])) {
|
|
74
58
|
return true;
|
|
75
59
|
}
|
|
76
60
|
}
|
|
77
61
|
return false;
|
|
78
62
|
});
|
|
79
63
|
return {
|
|
80
|
-
value: closestIndex !== undefined && closestIndex >= 0 ?
|
|
64
|
+
value: closestIndex !== undefined && closestIndex >= 0 ? axisData[closestIndex] : value,
|
|
81
65
|
index: closestIndex
|
|
82
66
|
};
|
|
83
67
|
}
|
|
84
|
-
var dataIndex =
|
|
85
|
-
if (dataIndex < 0 || dataIndex >=
|
|
68
|
+
var dataIndex = scale.bandwidth() === 0 ? Math.floor((mouseValue - Math.min.apply(Math, _toConsumableArray(scale.range())) + scale.step() / 2) / scale.step()) : Math.floor((mouseValue - Math.min.apply(Math, _toConsumableArray(scale.range()))) / scale.step());
|
|
69
|
+
if (dataIndex < 0 || dataIndex >= axisData.length) {
|
|
86
70
|
return null;
|
|
87
71
|
}
|
|
88
72
|
return {
|
|
89
73
|
index: dataIndex,
|
|
90
|
-
value:
|
|
74
|
+
value: axisData[dataIndex]
|
|
91
75
|
};
|
|
92
76
|
};
|
|
93
77
|
var handleMouseOut = function handleMouseOut() {
|
|
@@ -125,8 +109,8 @@ export var useAxisEvents = function useAxisEvents(disableAxisListener) {
|
|
|
125
109
|
});
|
|
126
110
|
return;
|
|
127
111
|
}
|
|
128
|
-
var newStateX =
|
|
129
|
-
var newStateY =
|
|
112
|
+
var newStateX = getUpdate(xAxis[usedXAxis], svgPt.x);
|
|
113
|
+
var newStateY = getUpdate(yAxis[usedYAxis], svgPt.y);
|
|
130
114
|
dispatch({
|
|
131
115
|
type: 'updateAxis',
|
|
132
116
|
data: {
|
package/legacy/hooks/useTicks.js
CHANGED
|
@@ -2,15 +2,15 @@ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import { isBandScale } from '../internals/isBandScale';
|
|
4
4
|
export function getTicksNumber(params) {
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
var
|
|
13
|
-
return Math.min(maxTicks, Math.max(minTicks,
|
|
5
|
+
var tickMaxStep = params.tickMaxStep,
|
|
6
|
+
tickMinStep = params.tickMinStep,
|
|
7
|
+
tickNumber = params.tickNumber,
|
|
8
|
+
range = params.range,
|
|
9
|
+
domain = params.domain;
|
|
10
|
+
var maxTicks = tickMinStep === undefined ? 999 : Math.floor(Math.abs(domain[1] - domain[0]) / tickMinStep);
|
|
11
|
+
var minTicks = tickMaxStep === undefined ? 2 : Math.ceil(Math.abs(domain[1] - domain[0]) / tickMaxStep);
|
|
12
|
+
var defaultizedTickNumber = tickNumber != null ? tickNumber : Math.floor(Math.abs(range[1] - range[0]) / 50);
|
|
13
|
+
return Math.min(maxTicks, Math.max(minTicks, defaultizedTickNumber));
|
|
14
14
|
}
|
|
15
15
|
function useTicks(options) {
|
|
16
16
|
var scale = options.scale,
|
|
@@ -22,11 +22,11 @@ function useTicks(options) {
|
|
|
22
22
|
var domain = scale.domain();
|
|
23
23
|
if (scale.bandwidth() > 0) {
|
|
24
24
|
// scale type = 'band'
|
|
25
|
-
return [].concat(_toConsumableArray(domain.map(function (value
|
|
25
|
+
return [].concat(_toConsumableArray(domain.map(function (value) {
|
|
26
26
|
var _valueFormatter;
|
|
27
27
|
return {
|
|
28
28
|
formattedValue: (_valueFormatter = valueFormatter == null ? void 0 : valueFormatter(value)) != null ? _valueFormatter : value,
|
|
29
|
-
offset:
|
|
29
|
+
offset: scale(value) - (scale.step() - scale.bandwidth()) / 2,
|
|
30
30
|
labelOffset: scale.step() / 2
|
|
31
31
|
};
|
|
32
32
|
})), [{
|
package/legacy/index.js
CHANGED
|
@@ -10,24 +10,24 @@ export var AxisRoot = styled('g', {
|
|
|
10
10
|
return styles.root;
|
|
11
11
|
}
|
|
12
12
|
})((_styled = {}, _defineProperty(_styled, "&.".concat(axisClasses.directionY), (_$concat = {}, _defineProperty(_$concat, ".".concat(axisClasses.tickLabel), {
|
|
13
|
-
|
|
13
|
+
dominantBaseline: 'middle'
|
|
14
14
|
}), _defineProperty(_$concat, ".".concat(axisClasses.label), {
|
|
15
|
-
|
|
15
|
+
dominantBaseline: 'auto',
|
|
16
16
|
textAnchor: 'middle'
|
|
17
17
|
}), _$concat)), _defineProperty(_styled, "&.".concat(axisClasses.left), _defineProperty({}, ".".concat(axisClasses.tickLabel), {
|
|
18
|
-
|
|
18
|
+
dominantBaseline: 'central',
|
|
19
19
|
textAnchor: 'end'
|
|
20
20
|
})), _defineProperty(_styled, "&.".concat(axisClasses.right), _defineProperty({}, ".".concat(axisClasses.tickLabel), {
|
|
21
|
-
|
|
21
|
+
dominantBaseline: 'central',
|
|
22
22
|
textAnchor: 'start'
|
|
23
23
|
})), _defineProperty(_styled, "&.".concat(axisClasses.bottom), _defineProperty({}, ".".concat(axisClasses.tickLabel, ", .").concat(axisClasses.label), {
|
|
24
|
-
|
|
24
|
+
dominantBaseline: 'hanging',
|
|
25
25
|
textAnchor: 'middle'
|
|
26
26
|
})), _defineProperty(_styled, "&.".concat(axisClasses.top), _defineProperty({}, ".".concat(axisClasses.tickLabel, ", .").concat(axisClasses.label), {
|
|
27
|
-
|
|
27
|
+
dominantBaseline: 'baseline',
|
|
28
28
|
textAnchor: 'middle'
|
|
29
29
|
})), _styled));
|
|
30
|
-
export var
|
|
30
|
+
export var ChartsLine = styled('line', {
|
|
31
31
|
name: 'MuiChartsAxis',
|
|
32
32
|
slot: 'Line',
|
|
33
33
|
overridesResolver: function overridesResolver(props, styles) {
|
|
@@ -41,7 +41,7 @@ export var Line = styled('line', {
|
|
|
41
41
|
strokeWidth: 1
|
|
42
42
|
};
|
|
43
43
|
});
|
|
44
|
-
export var
|
|
44
|
+
export var ChartsTick = styled('line', {
|
|
45
45
|
name: 'MuiChartsAxis',
|
|
46
46
|
slot: 'Tick',
|
|
47
47
|
overridesResolver: function overridesResolver(props, styles) {
|
|
@@ -54,7 +54,7 @@ export var Tick = styled('line', {
|
|
|
54
54
|
shapeRendering: 'crispEdges'
|
|
55
55
|
};
|
|
56
56
|
});
|
|
57
|
-
export var
|
|
57
|
+
export var ChartsTickLabel = styled('text', {
|
|
58
58
|
name: 'MuiChartsAxis',
|
|
59
59
|
slot: 'TickLabel',
|
|
60
60
|
overridesResolver: function overridesResolver(props, styles) {
|
|
@@ -66,7 +66,7 @@ export var TickLabel = styled('text', {
|
|
|
66
66
|
fill: theme.palette.text.primary
|
|
67
67
|
});
|
|
68
68
|
});
|
|
69
|
-
export var
|
|
69
|
+
export var ChartsLabel = styled('text', {
|
|
70
70
|
name: 'MuiChartsAxis',
|
|
71
71
|
slot: 'Label',
|
|
72
72
|
overridesResolver: function overridesResolver(props, styles) {
|
package/models/axis.d.ts
CHANGED
|
@@ -1,9 +1,22 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
import type { ScaleBand, ScaleLogarithmic, ScalePower, ScaleTime, ScaleLinear, ScalePoint } from 'd3-scale';
|
|
2
3
|
import { ChartsAxisClasses } from '../ChartsAxis/axisClasses';
|
|
3
4
|
import type { TickParams } from '../hooks/useTicks';
|
|
4
5
|
export type D3Scale = ScaleBand<any> | ScaleLogarithmic<any, any> | ScalePoint<any> | ScalePower<any, any> | ScaleTime<any, any> | ScaleLinear<any, any>;
|
|
5
6
|
export type D3ContinuouseScale = ScaleLogarithmic<any, any> | ScalePower<any, any> | ScaleTime<any, any> | ScaleLinear<any, any>;
|
|
6
|
-
export interface
|
|
7
|
+
export interface ChartsAxisSlotsComponent {
|
|
8
|
+
axisLine?: React.JSXElementConstructor<React.SVGAttributes<SVGPathElement>>;
|
|
9
|
+
axisTick?: React.JSXElementConstructor<React.SVGAttributes<SVGPathElement>>;
|
|
10
|
+
axisTickLabel?: React.JSXElementConstructor<React.SVGAttributes<SVGTextElement>>;
|
|
11
|
+
axisLabel?: React.JSXElementConstructor<React.SVGAttributes<SVGTextElement>>;
|
|
12
|
+
}
|
|
13
|
+
export interface ChartsAxisSlotComponentProps {
|
|
14
|
+
axisLine?: Partial<React.SVGAttributes<SVGPathElement>>;
|
|
15
|
+
axisTick?: Partial<React.SVGAttributes<SVGPathElement>>;
|
|
16
|
+
axisTickLabel?: Partial<React.SVGAttributes<SVGTextElement>>;
|
|
17
|
+
axisLabel?: Partial<React.SVGAttributes<SVGTextElement>>;
|
|
18
|
+
}
|
|
19
|
+
export interface ChartsAxisProps extends TickParams {
|
|
7
20
|
/**
|
|
8
21
|
* Id of the axis to render.
|
|
9
22
|
*/
|
|
@@ -51,6 +64,16 @@ export interface ChartsAxisProps {
|
|
|
51
64
|
* Override or extend the styles applied to the component.
|
|
52
65
|
*/
|
|
53
66
|
classes?: Partial<ChartsAxisClasses>;
|
|
67
|
+
/**
|
|
68
|
+
* Overridable component slots.
|
|
69
|
+
* @default {}
|
|
70
|
+
*/
|
|
71
|
+
slots?: Partial<ChartsAxisSlotsComponent>;
|
|
72
|
+
/**
|
|
73
|
+
* The props used for each component slot.
|
|
74
|
+
* @default {}
|
|
75
|
+
*/
|
|
76
|
+
slotProps?: Partial<ChartsAxisSlotComponentProps>;
|
|
54
77
|
}
|
|
55
78
|
export interface ChartsYAxisProps extends ChartsAxisProps {
|
|
56
79
|
/**
|
|
@@ -11,6 +11,11 @@ export interface BarSeriesType extends CommonSeriesType<number>, CartesianSeries
|
|
|
11
11
|
*/
|
|
12
12
|
dataKey?: string;
|
|
13
13
|
label?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Layout of the bars. All bar should have the same layout.
|
|
16
|
+
* @default 'vertical'
|
|
17
|
+
*/
|
|
18
|
+
layout?: 'horizontal' | 'vertical';
|
|
14
19
|
}
|
|
15
20
|
/**
|
|
16
21
|
* An object that allows to identify a single bar.
|
|
@@ -21,5 +26,5 @@ export type BarItemIdentifier = {
|
|
|
21
26
|
seriesId: DefaultizedBarSeriesType['id'];
|
|
22
27
|
dataIndex: number;
|
|
23
28
|
};
|
|
24
|
-
export interface DefaultizedBarSeriesType extends DefaultizedProps<BarSeriesType, CommonDefaultizedProps | 'color'> {
|
|
29
|
+
export interface DefaultizedBarSeriesType extends DefaultizedProps<BarSeriesType, CommonDefaultizedProps | 'color' | 'layout'> {
|
|
25
30
|
}
|
|
@@ -5,7 +5,7 @@ import PropTypes from 'prop-types';
|
|
|
5
5
|
import { BarPlot } from './BarPlot';
|
|
6
6
|
import { ResponsiveChartContainer } from '../ResponsiveChartContainer';
|
|
7
7
|
import { ChartsAxis } from '../ChartsAxis';
|
|
8
|
-
import { DEFAULT_X_AXIS_KEY } from '../constants';
|
|
8
|
+
import { DEFAULT_X_AXIS_KEY, DEFAULT_Y_AXIS_KEY } from '../constants';
|
|
9
9
|
import { ChartsTooltip } from '../ChartsTooltip';
|
|
10
10
|
import { ChartsLegend } from '../ChartsLegend';
|
|
11
11
|
import { ChartsAxisHighlight } from '../ChartsAxisHighlight';
|
|
@@ -23,6 +23,7 @@ const BarChart = /*#__PURE__*/React.forwardRef(function BarChart(props, ref) {
|
|
|
23
23
|
colors,
|
|
24
24
|
dataset,
|
|
25
25
|
sx,
|
|
26
|
+
layout,
|
|
26
27
|
tooltip,
|
|
27
28
|
axisHighlight,
|
|
28
29
|
legend,
|
|
@@ -30,41 +31,64 @@ const BarChart = /*#__PURE__*/React.forwardRef(function BarChart(props, ref) {
|
|
|
30
31
|
leftAxis,
|
|
31
32
|
rightAxis,
|
|
32
33
|
bottomAxis,
|
|
33
|
-
children
|
|
34
|
+
children,
|
|
35
|
+
slots,
|
|
36
|
+
slotProps
|
|
34
37
|
} = props;
|
|
35
38
|
const id = useId();
|
|
36
39
|
const clipPathId = `${id}-clip-path`;
|
|
40
|
+
const hasHorizontalSeries = layout === 'horizontal' || layout === undefined && series.some(item => item.layout === 'horizontal');
|
|
41
|
+
const defaultAxisConfig = {
|
|
42
|
+
scaleType: 'band',
|
|
43
|
+
data: Array.from({
|
|
44
|
+
length: Math.max(...series.map(s => (s.data ?? dataset ?? []).length))
|
|
45
|
+
}, (_, index) => index)
|
|
46
|
+
};
|
|
47
|
+
const defaultizedAxisHighlight = _extends({}, hasHorizontalSeries ? {
|
|
48
|
+
y: 'band'
|
|
49
|
+
} : {
|
|
50
|
+
x: 'band'
|
|
51
|
+
}, axisHighlight);
|
|
37
52
|
return /*#__PURE__*/_jsxs(ResponsiveChartContainer, {
|
|
38
53
|
ref: ref,
|
|
39
54
|
series: series.map(s => _extends({
|
|
40
55
|
type: 'bar'
|
|
41
|
-
}, s
|
|
56
|
+
}, s, {
|
|
57
|
+
layout: hasHorizontalSeries ? 'horizontal' : 'vertical'
|
|
58
|
+
})),
|
|
42
59
|
width: width,
|
|
43
60
|
height: height,
|
|
44
61
|
margin: margin,
|
|
45
|
-
xAxis: xAxis ?? [{
|
|
46
|
-
id: DEFAULT_X_AXIS_KEY
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}],
|
|
52
|
-
yAxis: yAxis,
|
|
62
|
+
xAxis: xAxis ?? (hasHorizontalSeries ? undefined : [_extends({
|
|
63
|
+
id: DEFAULT_X_AXIS_KEY
|
|
64
|
+
}, defaultAxisConfig)]),
|
|
65
|
+
yAxis: yAxis ?? (hasHorizontalSeries ? [_extends({
|
|
66
|
+
id: DEFAULT_Y_AXIS_KEY
|
|
67
|
+
}, defaultAxisConfig)] : undefined),
|
|
53
68
|
colors: colors,
|
|
54
69
|
dataset: dataset,
|
|
55
70
|
sx: sx,
|
|
56
71
|
disableAxisListener: tooltip?.trigger !== 'axis' && axisHighlight?.x === 'none' && axisHighlight?.y === 'none',
|
|
57
72
|
children: [/*#__PURE__*/_jsx("g", {
|
|
58
73
|
clipPath: `url(#${clipPathId})`,
|
|
59
|
-
children: /*#__PURE__*/_jsx(BarPlot, {
|
|
74
|
+
children: /*#__PURE__*/_jsx(BarPlot, {
|
|
75
|
+
slots: slots,
|
|
76
|
+
slotProps: slotProps
|
|
77
|
+
})
|
|
60
78
|
}), /*#__PURE__*/_jsx(ChartsAxis, {
|
|
61
79
|
topAxis: topAxis,
|
|
62
80
|
leftAxis: leftAxis,
|
|
63
81
|
rightAxis: rightAxis,
|
|
64
|
-
bottomAxis: bottomAxis
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
82
|
+
bottomAxis: bottomAxis,
|
|
83
|
+
slots: slots,
|
|
84
|
+
slotProps: slotProps
|
|
85
|
+
}), /*#__PURE__*/_jsx(ChartsLegend, _extends({}, legend, {
|
|
86
|
+
slots: slots,
|
|
87
|
+
slotProps: slotProps
|
|
88
|
+
})), /*#__PURE__*/_jsx(ChartsAxisHighlight, _extends({}, defaultizedAxisHighlight)), /*#__PURE__*/_jsx(ChartsTooltip, _extends({}, tooltip, {
|
|
89
|
+
slots: slots,
|
|
90
|
+
slotProps: slotProps
|
|
91
|
+
})), /*#__PURE__*/_jsx(ChartsClipPath, {
|
|
68
92
|
id: clipPathId
|
|
69
93
|
}), children]
|
|
70
94
|
});
|
|
@@ -76,7 +100,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
76
100
|
// ----------------------------------------------------------------------
|
|
77
101
|
axisHighlight: PropTypes.shape({
|
|
78
102
|
x: PropTypes.oneOf(['band', 'line', 'none']),
|
|
79
|
-
y: PropTypes.oneOf(['line', 'none'])
|
|
103
|
+
y: PropTypes.oneOf(['band', 'line', 'none'])
|
|
80
104
|
}),
|
|
81
105
|
/**
|
|
82
106
|
* Indicate which axis to display the bottom of the charts.
|
|
@@ -92,8 +116,13 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
92
116
|
label: PropTypes.string,
|
|
93
117
|
labelFontSize: PropTypes.number,
|
|
94
118
|
position: PropTypes.oneOf(['bottom', 'top']),
|
|
119
|
+
slotProps: PropTypes.object,
|
|
120
|
+
slots: PropTypes.object,
|
|
95
121
|
stroke: PropTypes.string,
|
|
96
122
|
tickFontSize: PropTypes.number,
|
|
123
|
+
tickMaxStep: PropTypes.number,
|
|
124
|
+
tickMinStep: PropTypes.number,
|
|
125
|
+
tickNumber: PropTypes.number,
|
|
97
126
|
tickSize: PropTypes.number
|
|
98
127
|
}), PropTypes.string]),
|
|
99
128
|
children: PropTypes.node,
|
|
@@ -106,6 +135,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
106
135
|
desc: PropTypes.string,
|
|
107
136
|
disableAxisListener: PropTypes.bool,
|
|
108
137
|
height: PropTypes.number,
|
|
138
|
+
layout: PropTypes.oneOf(['horizontal', 'vertical']),
|
|
109
139
|
/**
|
|
110
140
|
* Indicate which axis to display the left of the charts.
|
|
111
141
|
* Can be a string (the id of the axis) or an object `ChartsYAxisProps`.
|
|
@@ -120,8 +150,13 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
120
150
|
label: PropTypes.string,
|
|
121
151
|
labelFontSize: PropTypes.number,
|
|
122
152
|
position: PropTypes.oneOf(['left', 'right']),
|
|
153
|
+
slotProps: PropTypes.object,
|
|
154
|
+
slots: PropTypes.object,
|
|
123
155
|
stroke: PropTypes.string,
|
|
124
156
|
tickFontSize: PropTypes.number,
|
|
157
|
+
tickMaxStep: PropTypes.number,
|
|
158
|
+
tickMinStep: PropTypes.number,
|
|
159
|
+
tickNumber: PropTypes.number,
|
|
125
160
|
tickSize: PropTypes.number
|
|
126
161
|
}), PropTypes.string]),
|
|
127
162
|
legend: PropTypes.shape({
|
|
@@ -138,6 +173,8 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
138
173
|
horizontal: PropTypes.oneOf(['left', 'middle', 'right']).isRequired,
|
|
139
174
|
vertical: PropTypes.oneOf(['bottom', 'middle', 'top']).isRequired
|
|
140
175
|
}),
|
|
176
|
+
slotProps: PropTypes.object,
|
|
177
|
+
slots: PropTypes.object,
|
|
141
178
|
spacing: PropTypes.number
|
|
142
179
|
}),
|
|
143
180
|
margin: PropTypes.shape({
|
|
@@ -160,8 +197,13 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
160
197
|
label: PropTypes.string,
|
|
161
198
|
labelFontSize: PropTypes.number,
|
|
162
199
|
position: PropTypes.oneOf(['left', 'right']),
|
|
200
|
+
slotProps: PropTypes.object,
|
|
201
|
+
slots: PropTypes.object,
|
|
163
202
|
stroke: PropTypes.string,
|
|
164
203
|
tickFontSize: PropTypes.number,
|
|
204
|
+
tickMaxStep: PropTypes.number,
|
|
205
|
+
tickMinStep: PropTypes.number,
|
|
206
|
+
tickNumber: PropTypes.number,
|
|
165
207
|
tickSize: PropTypes.number
|
|
166
208
|
}), PropTypes.string]),
|
|
167
209
|
series: PropTypes.arrayOf(PropTypes.shape({
|
|
@@ -174,6 +216,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
174
216
|
}),
|
|
175
217
|
id: PropTypes.string,
|
|
176
218
|
label: PropTypes.string,
|
|
219
|
+
layout: PropTypes.oneOf(['horizontal', 'vertical']),
|
|
177
220
|
stack: PropTypes.string,
|
|
178
221
|
stackOffset: PropTypes.oneOf(['diverging', 'expand', 'none', 'silhouette', 'wiggle']),
|
|
179
222
|
stackOrder: PropTypes.oneOf(['appearance', 'ascending', 'descending', 'insideOut', 'none', 'reverse']),
|
|
@@ -182,6 +225,16 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
182
225
|
xAxisKey: PropTypes.string,
|
|
183
226
|
yAxisKey: PropTypes.string
|
|
184
227
|
})).isRequired,
|
|
228
|
+
/**
|
|
229
|
+
* The props used for each component slot.
|
|
230
|
+
* @default {}
|
|
231
|
+
*/
|
|
232
|
+
slotProps: PropTypes.object,
|
|
233
|
+
/**
|
|
234
|
+
* Overridable component slots.
|
|
235
|
+
* @default {}
|
|
236
|
+
*/
|
|
237
|
+
slots: PropTypes.object,
|
|
185
238
|
sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
|
|
186
239
|
title: PropTypes.string,
|
|
187
240
|
tooltip: PropTypes.shape({
|
|
@@ -204,8 +257,13 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
204
257
|
label: PropTypes.string,
|
|
205
258
|
labelFontSize: PropTypes.number,
|
|
206
259
|
position: PropTypes.oneOf(['bottom', 'top']),
|
|
260
|
+
slotProps: PropTypes.object,
|
|
261
|
+
slots: PropTypes.object,
|
|
207
262
|
stroke: PropTypes.string,
|
|
208
263
|
tickFontSize: PropTypes.number,
|
|
264
|
+
tickMaxStep: PropTypes.number,
|
|
265
|
+
tickMinStep: PropTypes.number,
|
|
266
|
+
tickNumber: PropTypes.number,
|
|
209
267
|
tickSize: PropTypes.number
|
|
210
268
|
}), PropTypes.string]),
|
|
211
269
|
viewBox: PropTypes.shape({
|
|
@@ -228,15 +286,17 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
228
286
|
label: PropTypes.string,
|
|
229
287
|
labelFontSize: PropTypes.number,
|
|
230
288
|
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
231
|
-
maxTicks: PropTypes.number,
|
|
232
289
|
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
233
|
-
minTicks: PropTypes.number,
|
|
234
290
|
position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
|
|
235
291
|
scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
|
|
292
|
+
slotProps: PropTypes.object,
|
|
293
|
+
slots: PropTypes.object,
|
|
236
294
|
stroke: PropTypes.string,
|
|
237
295
|
tickFontSize: PropTypes.number,
|
|
296
|
+
tickMaxStep: PropTypes.number,
|
|
297
|
+
tickMinStep: PropTypes.number,
|
|
298
|
+
tickNumber: PropTypes.number,
|
|
238
299
|
tickSize: PropTypes.number,
|
|
239
|
-
tickSpacing: PropTypes.number,
|
|
240
300
|
valueFormatter: PropTypes.func
|
|
241
301
|
})),
|
|
242
302
|
yAxis: PropTypes.arrayOf(PropTypes.shape({
|
|
@@ -252,15 +312,17 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
252
312
|
label: PropTypes.string,
|
|
253
313
|
labelFontSize: PropTypes.number,
|
|
254
314
|
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
255
|
-
maxTicks: PropTypes.number,
|
|
256
315
|
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
257
|
-
minTicks: PropTypes.number,
|
|
258
316
|
position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
|
|
259
317
|
scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
|
|
318
|
+
slotProps: PropTypes.object,
|
|
319
|
+
slots: PropTypes.object,
|
|
260
320
|
stroke: PropTypes.string,
|
|
261
321
|
tickFontSize: PropTypes.number,
|
|
322
|
+
tickMaxStep: PropTypes.number,
|
|
323
|
+
tickMinStep: PropTypes.number,
|
|
324
|
+
tickNumber: PropTypes.number,
|
|
262
325
|
tickSize: PropTypes.number,
|
|
263
|
-
tickSpacing: PropTypes.number,
|
|
264
326
|
valueFormatter: PropTypes.func
|
|
265
327
|
}))
|
|
266
328
|
} : void 0;
|
|
@@ -1,8 +1,9 @@
|
|
|
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"];
|
|
3
|
+
const _excluded = ["id", "dataIndex", "classes", "color", "highlightScope", "slots", "slotProps"];
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import composeClasses from '@mui/utils/composeClasses';
|
|
6
|
+
import { useSlotProps } from '@mui/base/utils';
|
|
6
7
|
import generateUtilityClass from '@mui/utils/generateUtilityClass';
|
|
7
8
|
import { styled } from '@mui/material/styles';
|
|
8
9
|
import { color as d3Color } from 'd3-color';
|
|
@@ -24,7 +25,7 @@ const useUtilityClasses = ownerState => {
|
|
|
24
25
|
};
|
|
25
26
|
return composeClasses(slots, getBarElementUtilityClass, classes);
|
|
26
27
|
};
|
|
27
|
-
const BarElementPath = styled('rect', {
|
|
28
|
+
export const BarElementPath = styled('rect', {
|
|
28
29
|
name: 'MuiBarElement',
|
|
29
30
|
slot: 'Root',
|
|
30
31
|
overridesResolver: (_, styles) => styles.root
|
|
@@ -43,7 +44,9 @@ export function BarElement(props) {
|
|
|
43
44
|
dataIndex,
|
|
44
45
|
classes: innerClasses,
|
|
45
46
|
color,
|
|
46
|
-
highlightScope
|
|
47
|
+
highlightScope,
|
|
48
|
+
slots,
|
|
49
|
+
slotProps
|
|
47
50
|
} = props,
|
|
48
51
|
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
49
52
|
const getInteractionItemProps = useInteractionItemProps(highlightScope);
|
|
@@ -69,12 +72,18 @@ export function BarElement(props) {
|
|
|
69
72
|
isHighlighted
|
|
70
73
|
};
|
|
71
74
|
const classes = useUtilityClasses(ownerState);
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
75
|
+
const Bar = slots?.bar ?? BarElementPath;
|
|
76
|
+
const barProps = useSlotProps({
|
|
77
|
+
elementType: Bar,
|
|
78
|
+
externalSlotProps: slotProps?.bar,
|
|
79
|
+
additionalProps: _extends({}, other, getInteractionItemProps({
|
|
80
|
+
type: 'bar',
|
|
81
|
+
seriesId: id,
|
|
82
|
+
dataIndex
|
|
83
|
+
}), {
|
|
84
|
+
className: classes.root
|
|
85
|
+
}),
|
|
86
|
+
ownerState
|
|
87
|
+
});
|
|
88
|
+
return /*#__PURE__*/_jsx(Bar, _extends({}, barProps));
|
|
80
89
|
}
|