@mui/x-charts 8.5.3 → 8.7.0
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/AnimatedBarElement.js +3 -1
- package/BarChart/BarLabel/BarLabelPlot.d.ts +2 -2
- package/BarChart/BarLabel/BarLabelPlot.js +33 -25
- package/BarChart/BarPlot.js +59 -183
- package/BarChart/barClasses.d.ts +12 -0
- package/BarChart/barClasses.js +25 -0
- package/BarChart/index.d.ts +3 -1
- package/BarChart/index.js +23 -1
- package/BarChart/types.d.ts +5 -1
- package/BarChart/useBarPlotData.d.ts +8 -0
- package/BarChart/useBarPlotData.js +146 -0
- package/CHANGELOG.md +210 -0
- package/ChartContainer/ChartContainer.d.ts +1 -21
- package/ChartContainer/ChartContainer.js +0 -8
- package/ChartContainer/index.d.ts +8 -1
- package/ChartsLegend/ChartsLegend.js +1 -0
- package/ChartsReferenceLine/ChartsReferenceLine.d.ts +1 -1
- package/ChartsReferenceLine/ChartsXReferenceLine.d.ts +3 -0
- package/ChartsReferenceLine/ChartsXReferenceLine.js +48 -1
- package/ChartsReferenceLine/ChartsYReferenceLine.d.ts +3 -0
- package/ChartsReferenceLine/ChartsYReferenceLine.js +48 -1
- package/ChartsReferenceLine/index.d.ts +3 -1
- package/ChartsSurface/ChartsSurface.js +2 -1
- package/ChartsTooltip/ChartsTooltipContainer.js +6 -3
- package/ChartsTooltip/ChartsTooltipTable.d.ts +1 -1
- package/ChartsTooltip/utils.js +18 -29
- package/ChartsXAxis/ChartsXAxis.js +4 -108
- package/ChartsXAxis/getVisibleLabels.d.ts +14 -0
- package/ChartsXAxis/getVisibleLabels.js +71 -0
- package/ChartsXAxis/shortenLabels.d.ts +4 -0
- package/ChartsXAxis/shortenLabels.js +48 -0
- package/ChartsYAxis/ChartsYAxis.js +2 -39
- package/ChartsYAxis/shortenLabels.d.ts +4 -0
- package/ChartsYAxis/shortenLabels.js +46 -0
- package/LineChart/AnimatedArea.js +4 -1
- package/LineChart/AnimatedLine.js +4 -1
- package/LineChart/AreaPlot.js +5 -115
- package/LineChart/CircleMarkElement.js +4 -1
- package/LineChart/LinePlot.js +5 -99
- package/LineChart/MarkElement.js +4 -1
- package/LineChart/MarkPlot.js +1 -0
- package/LineChart/useAreaPlotData.d.ts +12 -0
- package/LineChart/useAreaPlotData.js +125 -0
- package/LineChart/useLinePlotData.d.ts +11 -0
- package/LineChart/useLinePlotData.js +108 -0
- package/PieChart/PieArc.js +3 -1
- package/PieChart/PiePlot.js +6 -0
- package/PieChart/index.d.ts +3 -1
- package/PieChart/index.js +18 -1
- package/PieChart/pieClasses.d.ts +12 -0
- package/PieChart/pieClasses.js +24 -0
- package/ScatterChart/Scatter.js +22 -48
- package/ScatterChart/useScatterPlotData.d.ts +8 -0
- package/ScatterChart/useScatterPlotData.js +33 -0
- package/Toolbar/ToolbarButton.js +2 -0
- package/context/ChartApi.d.ts +22 -0
- package/context/ChartApi.js +5 -0
- package/context/ChartProvider/ChartContext.js +1 -0
- package/context/index.d.ts +2 -1
- package/context/useChartApiContext.d.ts +1 -1
- package/esm/BarChart/AnimatedBarElement.js +3 -1
- package/esm/BarChart/BarLabel/BarLabelPlot.d.ts +2 -2
- package/esm/BarChart/BarLabel/BarLabelPlot.js +33 -25
- package/esm/BarChart/BarPlot.js +60 -185
- package/esm/BarChart/barClasses.d.ts +12 -0
- package/esm/BarChart/barClasses.js +15 -0
- package/esm/BarChart/index.d.ts +3 -1
- package/esm/BarChart/index.js +2 -1
- package/esm/BarChart/types.d.ts +5 -1
- package/esm/BarChart/useBarPlotData.d.ts +8 -0
- package/esm/BarChart/useBarPlotData.js +139 -0
- package/esm/ChartContainer/ChartContainer.d.ts +1 -21
- package/esm/ChartContainer/ChartContainer.js +0 -8
- package/esm/ChartContainer/index.d.ts +8 -1
- package/esm/ChartContainer/index.js +6 -1
- package/esm/ChartsLegend/ChartsLegend.js +1 -0
- package/esm/ChartsReferenceLine/ChartsReferenceLine.d.ts +1 -1
- package/esm/ChartsReferenceLine/ChartsXReferenceLine.d.ts +3 -0
- package/esm/ChartsReferenceLine/ChartsXReferenceLine.js +47 -0
- package/esm/ChartsReferenceLine/ChartsYReferenceLine.d.ts +3 -0
- package/esm/ChartsReferenceLine/ChartsYReferenceLine.js +47 -0
- package/esm/ChartsReferenceLine/index.d.ts +3 -1
- package/esm/ChartsReferenceLine/index.js +2 -1
- package/esm/ChartsSurface/ChartsSurface.js +2 -1
- package/esm/ChartsTooltip/ChartsTooltipContainer.js +6 -3
- package/esm/ChartsTooltip/ChartsTooltipTable.d.ts +1 -1
- package/esm/ChartsTooltip/utils.js +18 -29
- package/esm/ChartsXAxis/ChartsXAxis.js +2 -106
- package/esm/ChartsXAxis/getVisibleLabels.d.ts +14 -0
- package/esm/ChartsXAxis/getVisibleLabels.js +67 -0
- package/esm/ChartsXAxis/shortenLabels.d.ts +4 -0
- package/esm/ChartsXAxis/shortenLabels.js +42 -0
- package/esm/ChartsYAxis/ChartsYAxis.js +1 -38
- package/esm/ChartsYAxis/shortenLabels.d.ts +4 -0
- package/esm/ChartsYAxis/shortenLabels.js +41 -0
- package/esm/LineChart/AnimatedArea.js +4 -1
- package/esm/LineChart/AnimatedLine.js +4 -1
- package/esm/LineChart/AreaPlot.js +5 -115
- package/esm/LineChart/CircleMarkElement.js +4 -1
- package/esm/LineChart/LinePlot.js +5 -99
- package/esm/LineChart/MarkElement.js +4 -1
- package/esm/LineChart/MarkPlot.js +1 -0
- package/esm/LineChart/useAreaPlotData.d.ts +12 -0
- package/esm/LineChart/useAreaPlotData.js +118 -0
- package/esm/LineChart/useLinePlotData.d.ts +11 -0
- package/esm/LineChart/useLinePlotData.js +101 -0
- package/esm/PieChart/PieArc.js +3 -1
- package/esm/PieChart/PiePlot.js +6 -0
- package/esm/PieChart/index.d.ts +3 -1
- package/esm/PieChart/index.js +2 -1
- package/esm/PieChart/pieClasses.d.ts +12 -0
- package/esm/PieChart/pieClasses.js +15 -0
- package/esm/ScatterChart/Scatter.js +23 -49
- package/esm/ScatterChart/useScatterPlotData.d.ts +8 -0
- package/esm/ScatterChart/useScatterPlotData.js +26 -0
- package/esm/Toolbar/ToolbarButton.js +2 -0
- package/esm/context/ChartApi.d.ts +22 -0
- package/esm/context/ChartApi.js +1 -0
- package/esm/context/ChartProvider/ChartContext.js +2 -0
- package/esm/context/index.d.ts +2 -1
- package/esm/context/useChartApiContext.d.ts +1 -1
- package/esm/hooks/useInteractionItemProps.d.ts +14 -9
- package/esm/hooks/useInteractionItemProps.js +28 -28
- package/esm/index.d.ts +2 -1
- package/esm/index.js +2 -2
- package/esm/internals/components/NotRendered.d.ts +9 -0
- package/esm/internals/components/NotRendered.js +10 -0
- package/esm/internals/index.d.ts +6 -0
- package/esm/internals/index.js +6 -0
- package/esm/internals/plugins/corePlugins/corePlugins.d.ts +3 -2
- package/esm/internals/plugins/corePlugins/corePlugins.js +2 -1
- package/esm/internals/plugins/corePlugins/useChartAnimation/useChartAnimation.selectors.d.ts +1 -1
- package/esm/internals/plugins/corePlugins/useChartDimensions/useChartDimensions.js +1 -1
- package/esm/internals/plugins/corePlugins/useChartDimensions/useChartDimensions.selectors.d.ts +3 -3
- package/esm/internals/plugins/corePlugins/useChartDimensions/useChartDimensions.types.d.ts +2 -2
- package/esm/internals/plugins/corePlugins/useChartId/useChartId.js +2 -0
- package/esm/internals/plugins/corePlugins/useChartId/useChartId.selectors.d.ts +1 -1
- package/esm/internals/plugins/corePlugins/useChartInteractionListener/index.d.ts +2 -0
- package/esm/internals/plugins/corePlugins/useChartInteractionListener/index.js +1 -0
- package/esm/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.d.ts +3 -0
- package/esm/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.js +77 -0
- package/esm/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.types.d.ts +31 -0
- package/esm/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.types.js +1 -0
- package/esm/internals/plugins/corePlugins/useChartSeries/useChartSeries.selectors.d.ts +2 -2
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartAxisSize.selectors.d.ts +4 -4
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxis.js +44 -33
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisRendering.selectors.d.ts +5 -5
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianInteraction.selectors.d.ts +7 -7
- package/esm/internals/plugins/featurePlugins/useChartHighlight/useChartHighlight.selectors.d.ts +5 -5
- package/esm/internals/plugins/featurePlugins/useChartInteraction/useChartInteraction.selectors.d.ts +6 -6
- package/esm/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarAxis.js +52 -36
- package/esm/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarAxis.selectors.d.ts +5 -5
- package/esm/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarInteraction.selectors.d.ts +6 -6
- package/esm/internals/plugins/featurePlugins/useChartVoronoi/useChartVoronoi.js +47 -30
- package/esm/internals/plugins/featurePlugins/useChartVoronoi/useChartVoronoi.selectors.d.ts +1 -1
- package/esm/internals/plugins/featurePlugins/useChartZAxis/useChartZAxis.selectors.d.ts +1 -1
- package/esm/internals/store/useCharts.d.ts +1 -1
- package/esm/locales/elGR.d.ts +19 -0
- package/esm/locales/elGR.js +15 -0
- package/esm/locales/enUS.d.ts +3 -0
- package/esm/locales/enUS.js +8 -2
- package/esm/locales/frFR.d.ts +3 -0
- package/esm/locales/frFR.js +7 -0
- package/esm/locales/index.d.ts +1 -0
- package/esm/locales/index.js +1 -0
- package/esm/locales/ptBR.d.ts +3 -0
- package/esm/locales/ptBR.js +7 -1
- package/esm/locales/ptPT.d.ts +3 -0
- package/esm/locales/ptPT.js +7 -1
- package/esm/locales/utils/chartsLocaleTextApi.d.ts +17 -0
- package/esm/locales/utils/getChartsLocalization.d.ts +3 -0
- package/esm/locales/utils/imageMimeTypes.d.ts +2 -0
- package/esm/locales/utils/imageMimeTypes.js +5 -0
- package/esm/models/slots/chartsBaseSlotProps.d.ts +4 -0
- package/hooks/useInteractionItemProps.d.ts +14 -9
- package/hooks/useInteractionItemProps.js +29 -28
- package/index.d.ts +2 -1
- package/index.js +37 -11
- package/internals/components/NotRendered.d.ts +9 -0
- package/internals/components/NotRendered.js +16 -0
- package/internals/index.d.ts +6 -0
- package/internals/index.js +56 -0
- package/internals/plugins/corePlugins/corePlugins.d.ts +3 -2
- package/internals/plugins/corePlugins/corePlugins.js +2 -1
- package/internals/plugins/corePlugins/useChartAnimation/useChartAnimation.selectors.d.ts +1 -1
- package/internals/plugins/corePlugins/useChartDimensions/useChartDimensions.js +1 -1
- package/internals/plugins/corePlugins/useChartDimensions/useChartDimensions.selectors.d.ts +3 -3
- package/internals/plugins/corePlugins/useChartDimensions/useChartDimensions.types.d.ts +2 -2
- package/internals/plugins/corePlugins/useChartId/useChartId.js +1 -0
- package/internals/plugins/corePlugins/useChartId/useChartId.selectors.d.ts +1 -1
- package/internals/plugins/corePlugins/useChartInteractionListener/index.d.ts +2 -0
- package/internals/plugins/corePlugins/useChartInteractionListener/index.js +12 -0
- package/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.d.ts +3 -0
- package/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.js +84 -0
- package/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.types.d.ts +31 -0
- package/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.types.js +5 -0
- package/internals/plugins/corePlugins/useChartSeries/useChartSeries.selectors.d.ts +2 -2
- package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartAxisSize.selectors.d.ts +4 -4
- package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxis.js +44 -33
- package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisRendering.selectors.d.ts +5 -5
- package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianInteraction.selectors.d.ts +7 -7
- package/internals/plugins/featurePlugins/useChartHighlight/useChartHighlight.selectors.d.ts +5 -5
- package/internals/plugins/featurePlugins/useChartInteraction/useChartInteraction.selectors.d.ts +6 -6
- package/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarAxis.js +52 -36
- package/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarAxis.selectors.d.ts +5 -5
- package/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarInteraction.selectors.d.ts +6 -6
- package/internals/plugins/featurePlugins/useChartVoronoi/useChartVoronoi.js +46 -30
- package/internals/plugins/featurePlugins/useChartVoronoi/useChartVoronoi.selectors.d.ts +1 -1
- package/internals/plugins/featurePlugins/useChartZAxis/useChartZAxis.selectors.d.ts +1 -1
- package/internals/store/useCharts.d.ts +1 -1
- package/locales/elGR.d.ts +19 -0
- package/locales/elGR.js +21 -0
- package/locales/enUS.d.ts +3 -0
- package/locales/enUS.js +8 -2
- package/locales/frFR.d.ts +3 -0
- package/locales/frFR.js +7 -0
- package/locales/index.d.ts +1 -0
- package/locales/index.js +11 -0
- package/locales/ptBR.d.ts +3 -0
- package/locales/ptBR.js +7 -1
- package/locales/ptPT.d.ts +3 -0
- package/locales/ptPT.js +7 -1
- package/locales/utils/chartsLocaleTextApi.d.ts +17 -0
- package/locales/utils/getChartsLocalization.d.ts +3 -0
- package/locales/utils/imageMimeTypes.d.ts +2 -0
- package/locales/utils/imageMimeTypes.js +11 -0
- package/models/slots/chartsBaseSlotProps.d.ts +4 -0
- package/package.json +3 -2
|
@@ -21,6 +21,8 @@ function AnimatedBarElement(props) {
|
|
|
21
21
|
const animatedProps = (0, _useAnimateBar.useAnimateBar)(props);
|
|
22
22
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("rect", (0, _extends2.default)({}, other, {
|
|
23
23
|
filter: ownerState.isHighlighted ? 'brightness(120%)' : undefined,
|
|
24
|
-
opacity: ownerState.isFaded ? 0.3 : 1
|
|
24
|
+
opacity: ownerState.isFaded ? 0.3 : 1,
|
|
25
|
+
"data-highlighted": ownerState.isHighlighted || undefined,
|
|
26
|
+
"data-faded": ownerState.isFaded || undefined
|
|
25
27
|
}, animatedProps));
|
|
26
28
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import type {
|
|
2
|
+
import type { ProcessedBarSeriesData } from "../types.js";
|
|
3
3
|
import { BarLabelItemProps } from "./BarLabelItem.js";
|
|
4
4
|
type BarLabelPlotProps = {
|
|
5
|
-
bars:
|
|
5
|
+
bars: ProcessedBarSeriesData[];
|
|
6
6
|
skipAnimation?: boolean;
|
|
7
7
|
barLabel?: BarLabelItemProps['barLabel'];
|
|
8
8
|
};
|
|
@@ -10,6 +10,7 @@ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")
|
|
|
10
10
|
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
|
|
11
11
|
var React = _interopRequireWildcard(require("react"));
|
|
12
12
|
var _BarLabelItem = require("./BarLabelItem");
|
|
13
|
+
var _barClasses = require("../barClasses");
|
|
13
14
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
14
15
|
const _excluded = ["bars", "skipAnimation"];
|
|
15
16
|
/**
|
|
@@ -21,32 +22,39 @@ function BarLabelPlot(props) {
|
|
|
21
22
|
skipAnimation
|
|
22
23
|
} = props,
|
|
23
24
|
other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
|
|
25
|
+
const classes = (0, _barClasses.useUtilityClasses)();
|
|
24
26
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(React.Fragment, {
|
|
25
|
-
children: bars.
|
|
26
|
-
xOrigin,
|
|
27
|
-
yOrigin,
|
|
28
|
-
x,
|
|
29
|
-
y,
|
|
27
|
+
children: bars.flatMap(({
|
|
30
28
|
seriesId,
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
29
|
+
data
|
|
30
|
+
}) => /*#__PURE__*/(0, _jsxRuntime.jsx)("g", {
|
|
31
|
+
className: classes.seriesLabels,
|
|
32
|
+
"data-series": seriesId,
|
|
33
|
+
children: data.map(({
|
|
34
|
+
xOrigin,
|
|
35
|
+
yOrigin,
|
|
36
|
+
x,
|
|
37
|
+
y,
|
|
38
|
+
dataIndex,
|
|
39
|
+
color,
|
|
40
|
+
value,
|
|
41
|
+
width,
|
|
42
|
+
height,
|
|
43
|
+
layout
|
|
44
|
+
}) => /*#__PURE__*/(0, _jsxRuntime.jsx)(_BarLabelItem.BarLabelItem, (0, _extends2.default)({
|
|
45
|
+
seriesId: seriesId,
|
|
46
|
+
dataIndex: dataIndex,
|
|
47
|
+
value: value,
|
|
48
|
+
color: color,
|
|
49
|
+
xOrigin: xOrigin,
|
|
50
|
+
yOrigin: yOrigin,
|
|
51
|
+
x: x,
|
|
52
|
+
y: y,
|
|
53
|
+
width: width,
|
|
54
|
+
height: height,
|
|
55
|
+
skipAnimation: skipAnimation ?? false,
|
|
56
|
+
layout: layout ?? 'vertical'
|
|
57
|
+
}, other), dataIndex))
|
|
58
|
+
}, seriesId))
|
|
51
59
|
});
|
|
52
60
|
}
|
package/BarChart/BarPlot.js
CHANGED
|
@@ -14,155 +14,15 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
|
14
14
|
var _styles = require("@mui/material/styles");
|
|
15
15
|
var _barElementClasses = require("./barElementClasses");
|
|
16
16
|
var _BarElement = require("./BarElement");
|
|
17
|
-
var _getColor = _interopRequireDefault(require("./seriesConfig/getColor"));
|
|
18
17
|
var _hooks = require("../hooks");
|
|
19
18
|
var _BarClipPath = require("./BarClipPath");
|
|
20
19
|
var _BarLabelPlot = require("./BarLabel/BarLabelPlot");
|
|
21
|
-
var _checkScaleErrors = require("./checkScaleErrors");
|
|
22
|
-
var _useBarSeries = require("../hooks/useBarSeries");
|
|
23
20
|
var _useSkipAnimation = require("../hooks/useSkipAnimation");
|
|
24
21
|
var _useInternalIsZoomInteracting = require("../internals/plugins/featurePlugins/useChartCartesianAxis/useInternalIsZoomInteracting");
|
|
22
|
+
var _useBarPlotData = require("./useBarPlotData");
|
|
23
|
+
var _barClasses = require("./barClasses");
|
|
25
24
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
26
25
|
const _excluded = ["skipAnimation", "onItemClick", "borderRadius", "barLabel"];
|
|
27
|
-
/**
|
|
28
|
-
* Solution of the equations
|
|
29
|
-
* W = barWidth * N + offset * (N-1)
|
|
30
|
-
* offset / (offset + barWidth) = r
|
|
31
|
-
* @param bandWidth The width available to place bars.
|
|
32
|
-
* @param numberOfGroups The number of bars to place in that space.
|
|
33
|
-
* @param gapRatio The ratio of the gap between bars over the bar width.
|
|
34
|
-
* @returns The bar width and the offset between bars.
|
|
35
|
-
*/
|
|
36
|
-
function getBandSize({
|
|
37
|
-
bandWidth: W,
|
|
38
|
-
numberOfGroups: N,
|
|
39
|
-
gapRatio: r
|
|
40
|
-
}) {
|
|
41
|
-
if (r === 0) {
|
|
42
|
-
return {
|
|
43
|
-
barWidth: W / N,
|
|
44
|
-
offset: 0
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
const barWidth = W / (N + (N - 1) * r);
|
|
48
|
-
const offset = r * barWidth;
|
|
49
|
-
return {
|
|
50
|
-
barWidth,
|
|
51
|
-
offset
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
const useAggregatedData = () => {
|
|
55
|
-
const seriesData = (0, _useBarSeries.useBarSeriesContext)() ?? {
|
|
56
|
-
series: {},
|
|
57
|
-
stackingGroups: [],
|
|
58
|
-
seriesOrder: []
|
|
59
|
-
};
|
|
60
|
-
const drawingArea = (0, _hooks.useDrawingArea)();
|
|
61
|
-
const chartId = (0, _hooks.useChartId)();
|
|
62
|
-
const {
|
|
63
|
-
series,
|
|
64
|
-
stackingGroups
|
|
65
|
-
} = seriesData;
|
|
66
|
-
const {
|
|
67
|
-
xAxis,
|
|
68
|
-
xAxisIds
|
|
69
|
-
} = (0, _hooks.useXAxes)();
|
|
70
|
-
const {
|
|
71
|
-
yAxis,
|
|
72
|
-
yAxisIds
|
|
73
|
-
} = (0, _hooks.useYAxes)();
|
|
74
|
-
const defaultXAxisId = xAxisIds[0];
|
|
75
|
-
const defaultYAxisId = yAxisIds[0];
|
|
76
|
-
const masks = {};
|
|
77
|
-
const data = stackingGroups.flatMap(({
|
|
78
|
-
ids: groupIds
|
|
79
|
-
}, groupIndex) => {
|
|
80
|
-
const xMin = drawingArea.left;
|
|
81
|
-
const xMax = drawingArea.left + drawingArea.width;
|
|
82
|
-
const yMin = drawingArea.top;
|
|
83
|
-
const yMax = drawingArea.top + drawingArea.height;
|
|
84
|
-
return groupIds.flatMap(seriesId => {
|
|
85
|
-
const xAxisId = series[seriesId].xAxisId ?? defaultXAxisId;
|
|
86
|
-
const yAxisId = series[seriesId].yAxisId ?? defaultYAxisId;
|
|
87
|
-
const xAxisConfig = xAxis[xAxisId];
|
|
88
|
-
const yAxisConfig = yAxis[yAxisId];
|
|
89
|
-
const verticalLayout = series[seriesId].layout === 'vertical';
|
|
90
|
-
(0, _checkScaleErrors.checkScaleErrors)(verticalLayout, seriesId, series[seriesId], xAxisId, xAxis, yAxisId, yAxis);
|
|
91
|
-
const baseScaleConfig = verticalLayout ? xAxisConfig : yAxisConfig;
|
|
92
|
-
const xScale = xAxisConfig.scale;
|
|
93
|
-
const yScale = yAxisConfig.scale;
|
|
94
|
-
const colorGetter = (0, _getColor.default)(series[seriesId], xAxis[xAxisId], yAxis[yAxisId]);
|
|
95
|
-
const bandWidth = baseScaleConfig.scale.bandwidth();
|
|
96
|
-
const {
|
|
97
|
-
barWidth,
|
|
98
|
-
offset
|
|
99
|
-
} = getBandSize({
|
|
100
|
-
bandWidth,
|
|
101
|
-
numberOfGroups: stackingGroups.length,
|
|
102
|
-
gapRatio: baseScaleConfig.barGapRatio
|
|
103
|
-
});
|
|
104
|
-
const barOffset = groupIndex * (barWidth + offset);
|
|
105
|
-
const {
|
|
106
|
-
stackedData,
|
|
107
|
-
data: currentSeriesData,
|
|
108
|
-
layout
|
|
109
|
-
} = series[seriesId];
|
|
110
|
-
return baseScaleConfig.data.map((baseValue, dataIndex) => {
|
|
111
|
-
if (currentSeriesData[dataIndex] == null) {
|
|
112
|
-
return null;
|
|
113
|
-
}
|
|
114
|
-
const values = stackedData[dataIndex];
|
|
115
|
-
const valueCoordinates = values.map(v => verticalLayout ? yScale(v) : xScale(v));
|
|
116
|
-
const minValueCoord = Math.round(Math.min(...valueCoordinates));
|
|
117
|
-
const maxValueCoord = Math.round(Math.max(...valueCoordinates));
|
|
118
|
-
const stackId = series[seriesId].stack;
|
|
119
|
-
const result = {
|
|
120
|
-
seriesId,
|
|
121
|
-
dataIndex,
|
|
122
|
-
layout,
|
|
123
|
-
x: verticalLayout ? xScale(baseValue) + barOffset : minValueCoord,
|
|
124
|
-
y: verticalLayout ? minValueCoord : yScale(baseValue) + barOffset,
|
|
125
|
-
xOrigin: xScale(0) ?? 0,
|
|
126
|
-
yOrigin: yScale(0) ?? 0,
|
|
127
|
-
height: verticalLayout ? maxValueCoord - minValueCoord : barWidth,
|
|
128
|
-
width: verticalLayout ? barWidth : maxValueCoord - minValueCoord,
|
|
129
|
-
color: colorGetter(dataIndex),
|
|
130
|
-
value: currentSeriesData[dataIndex],
|
|
131
|
-
maskId: `${chartId}_${stackId || seriesId}_${groupIndex}_${dataIndex}`
|
|
132
|
-
};
|
|
133
|
-
if (result.x > xMax || result.x + result.width < xMin || result.y > yMax || result.y + result.height < yMin) {
|
|
134
|
-
return null;
|
|
135
|
-
}
|
|
136
|
-
if (!masks[result.maskId]) {
|
|
137
|
-
masks[result.maskId] = {
|
|
138
|
-
id: result.maskId,
|
|
139
|
-
width: 0,
|
|
140
|
-
height: 0,
|
|
141
|
-
hasNegative: false,
|
|
142
|
-
hasPositive: false,
|
|
143
|
-
layout: result.layout,
|
|
144
|
-
xOrigin: xScale(0),
|
|
145
|
-
yOrigin: yScale(0),
|
|
146
|
-
x: 0,
|
|
147
|
-
y: 0
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
const mask = masks[result.maskId];
|
|
151
|
-
mask.width = result.layout === 'vertical' ? result.width : mask.width + result.width;
|
|
152
|
-
mask.height = result.layout === 'vertical' ? mask.height + result.height : result.height;
|
|
153
|
-
mask.x = Math.min(mask.x === 0 ? Infinity : mask.x, result.x);
|
|
154
|
-
mask.y = Math.min(mask.y === 0 ? Infinity : mask.y, result.y);
|
|
155
|
-
mask.hasNegative = mask.hasNegative || (result.value ?? 0) < 0;
|
|
156
|
-
mask.hasPositive = mask.hasPositive || (result.value ?? 0) > 0;
|
|
157
|
-
return result;
|
|
158
|
-
}).filter(rectangle => rectangle !== null);
|
|
159
|
-
});
|
|
160
|
-
});
|
|
161
|
-
return {
|
|
162
|
-
completedData: data,
|
|
163
|
-
masksData: Object.values(masks)
|
|
164
|
-
};
|
|
165
|
-
};
|
|
166
26
|
const BarPlotRoot = (0, _styles.styled)('g', {
|
|
167
27
|
name: 'MuiBarPlot',
|
|
168
28
|
slot: 'Root'
|
|
@@ -184,10 +44,6 @@ const BarPlotRoot = (0, _styles.styled)('g', {
|
|
|
184
44
|
* - [BarPlot API](https://mui.com/x/api/charts/bar-plot/)
|
|
185
45
|
*/
|
|
186
46
|
function BarPlot(props) {
|
|
187
|
-
const {
|
|
188
|
-
completedData,
|
|
189
|
-
masksData
|
|
190
|
-
} = useAggregatedData();
|
|
191
47
|
const {
|
|
192
48
|
skipAnimation: inSkipAnimation,
|
|
193
49
|
onItemClick,
|
|
@@ -197,8 +53,20 @@ function BarPlot(props) {
|
|
|
197
53
|
other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
|
|
198
54
|
const isZoomInteracting = (0, _useInternalIsZoomInteracting.useInternalIsZoomInteracting)();
|
|
199
55
|
const skipAnimation = (0, _useSkipAnimation.useSkipAnimation)(isZoomInteracting || inSkipAnimation);
|
|
56
|
+
const {
|
|
57
|
+
xAxis: xAxes
|
|
58
|
+
} = (0, _hooks.useXAxes)();
|
|
59
|
+
const {
|
|
60
|
+
yAxis: yAxes
|
|
61
|
+
} = (0, _hooks.useYAxes)();
|
|
62
|
+
const {
|
|
63
|
+
completedData,
|
|
64
|
+
masksData
|
|
65
|
+
} = (0, _useBarPlotData.useBarPlotData)((0, _hooks.useDrawingArea)(), xAxes, yAxes);
|
|
200
66
|
const withoutBorderRadius = !borderRadius || borderRadius <= 0;
|
|
67
|
+
const classes = (0, _barClasses.useUtilityClasses)();
|
|
201
68
|
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(BarPlotRoot, {
|
|
69
|
+
className: classes.root,
|
|
202
70
|
children: [!withoutBorderRadius && masksData.map(({
|
|
203
71
|
id,
|
|
204
72
|
x,
|
|
@@ -223,45 +91,53 @@ function BarPlot(props) {
|
|
|
223
91
|
}, id);
|
|
224
92
|
}), completedData.map(({
|
|
225
93
|
seriesId,
|
|
226
|
-
|
|
227
|
-
color,
|
|
228
|
-
maskId,
|
|
229
|
-
layout,
|
|
230
|
-
x,
|
|
231
|
-
xOrigin,
|
|
232
|
-
y,
|
|
233
|
-
yOrigin,
|
|
234
|
-
width,
|
|
235
|
-
height
|
|
94
|
+
data
|
|
236
95
|
}) => {
|
|
237
|
-
const barElement = /*#__PURE__*/(0, _jsxRuntime.jsx)(_BarElement.BarElement, (0, _extends2.default)({
|
|
238
|
-
id: seriesId,
|
|
239
|
-
dataIndex: dataIndex,
|
|
240
|
-
color: color,
|
|
241
|
-
skipAnimation: skipAnimation ?? false,
|
|
242
|
-
layout: layout ?? 'vertical',
|
|
243
|
-
x: x,
|
|
244
|
-
xOrigin: xOrigin,
|
|
245
|
-
y: y,
|
|
246
|
-
yOrigin: yOrigin,
|
|
247
|
-
width: width,
|
|
248
|
-
height: height
|
|
249
|
-
}, other, {
|
|
250
|
-
onClick: onItemClick && (event => {
|
|
251
|
-
onItemClick(event, {
|
|
252
|
-
type: 'bar',
|
|
253
|
-
seriesId,
|
|
254
|
-
dataIndex
|
|
255
|
-
});
|
|
256
|
-
})
|
|
257
|
-
}), `${seriesId}-${dataIndex}`);
|
|
258
|
-
if (withoutBorderRadius) {
|
|
259
|
-
return barElement;
|
|
260
|
-
}
|
|
261
96
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("g", {
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
97
|
+
"data-series": seriesId,
|
|
98
|
+
className: classes.series,
|
|
99
|
+
children: data.map(({
|
|
100
|
+
dataIndex,
|
|
101
|
+
color,
|
|
102
|
+
maskId,
|
|
103
|
+
layout,
|
|
104
|
+
x,
|
|
105
|
+
xOrigin,
|
|
106
|
+
y,
|
|
107
|
+
yOrigin,
|
|
108
|
+
width,
|
|
109
|
+
height
|
|
110
|
+
}) => {
|
|
111
|
+
const barElement = /*#__PURE__*/(0, _jsxRuntime.jsx)(_BarElement.BarElement, (0, _extends2.default)({
|
|
112
|
+
id: seriesId,
|
|
113
|
+
dataIndex: dataIndex,
|
|
114
|
+
color: color,
|
|
115
|
+
skipAnimation: skipAnimation ?? false,
|
|
116
|
+
layout: layout ?? 'vertical',
|
|
117
|
+
x: x,
|
|
118
|
+
xOrigin: xOrigin,
|
|
119
|
+
y: y,
|
|
120
|
+
yOrigin: yOrigin,
|
|
121
|
+
width: width,
|
|
122
|
+
height: height
|
|
123
|
+
}, other, {
|
|
124
|
+
onClick: onItemClick && (event => {
|
|
125
|
+
onItemClick(event, {
|
|
126
|
+
type: 'bar',
|
|
127
|
+
seriesId,
|
|
128
|
+
dataIndex
|
|
129
|
+
});
|
|
130
|
+
})
|
|
131
|
+
}), dataIndex);
|
|
132
|
+
if (withoutBorderRadius) {
|
|
133
|
+
return barElement;
|
|
134
|
+
}
|
|
135
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)("g", {
|
|
136
|
+
clipPath: `url(#${maskId})`,
|
|
137
|
+
children: barElement
|
|
138
|
+
}, dataIndex);
|
|
139
|
+
})
|
|
140
|
+
}, seriesId);
|
|
265
141
|
}), barLabel && /*#__PURE__*/(0, _jsxRuntime.jsx)(_BarLabelPlot.BarLabelPlot, (0, _extends2.default)({
|
|
266
142
|
bars: completedData,
|
|
267
143
|
skipAnimation: skipAnimation,
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface BarClasses {
|
|
2
|
+
/** Styles applied to the bar plot element. */
|
|
3
|
+
root: string;
|
|
4
|
+
/** Styles applied to the group surrounding a series' bar elements. */
|
|
5
|
+
series: string;
|
|
6
|
+
/** Styles applied to the group surrounding a series' labels. */
|
|
7
|
+
seriesLabels: string;
|
|
8
|
+
}
|
|
9
|
+
export type BarClassKey = keyof BarClasses;
|
|
10
|
+
export declare function getBarUtilityClass(slot: string): string;
|
|
11
|
+
export declare const barClasses: BarClasses;
|
|
12
|
+
export declare const useUtilityClasses: (classes?: Partial<BarClasses>) => Record<"root" | "series" | "seriesLabels", string>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.barClasses = void 0;
|
|
8
|
+
exports.getBarUtilityClass = getBarUtilityClass;
|
|
9
|
+
exports.useUtilityClasses = void 0;
|
|
10
|
+
var _generateUtilityClass = _interopRequireDefault(require("@mui/utils/generateUtilityClass"));
|
|
11
|
+
var _composeClasses = _interopRequireDefault(require("@mui/utils/composeClasses"));
|
|
12
|
+
var _generateUtilityClasses = _interopRequireDefault(require("@mui/utils/generateUtilityClasses"));
|
|
13
|
+
function getBarUtilityClass(slot) {
|
|
14
|
+
return (0, _generateUtilityClass.default)('MuiBar', slot);
|
|
15
|
+
}
|
|
16
|
+
const barClasses = exports.barClasses = (0, _generateUtilityClasses.default)('MuiBar', ['root', 'series', 'seriesLabels']);
|
|
17
|
+
const useUtilityClasses = classes => {
|
|
18
|
+
const slots = {
|
|
19
|
+
root: ['root'],
|
|
20
|
+
series: ['series'],
|
|
21
|
+
seriesLabels: ['seriesLabels']
|
|
22
|
+
};
|
|
23
|
+
return (0, _composeClasses.default)(slots, getBarUtilityClass, classes);
|
|
24
|
+
};
|
|
25
|
+
exports.useUtilityClasses = useUtilityClasses;
|
package/BarChart/index.d.ts
CHANGED
|
@@ -2,4 +2,6 @@ export * from "./BarChart.js";
|
|
|
2
2
|
export * from "./BarPlot.js";
|
|
3
3
|
export * from "./BarElement.js";
|
|
4
4
|
export * from "./BarLabel/index.js";
|
|
5
|
-
export * from "./barElementClasses.js";
|
|
5
|
+
export * from "./barElementClasses.js";
|
|
6
|
+
export { barClasses, getBarUtilityClass } from "./barClasses.js";
|
|
7
|
+
export type { BarClassKey, BarClasses } from "./barClasses.js";
|
package/BarChart/index.js
CHANGED
|
@@ -3,9 +3,26 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
var _exportNames = {
|
|
7
|
+
barClasses: true,
|
|
8
|
+
getBarUtilityClass: true
|
|
9
|
+
};
|
|
10
|
+
Object.defineProperty(exports, "barClasses", {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () {
|
|
13
|
+
return _barClasses.barClasses;
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
Object.defineProperty(exports, "getBarUtilityClass", {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
get: function () {
|
|
19
|
+
return _barClasses.getBarUtilityClass;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
6
22
|
var _BarChart = require("./BarChart");
|
|
7
23
|
Object.keys(_BarChart).forEach(function (key) {
|
|
8
24
|
if (key === "default" || key === "__esModule") return;
|
|
25
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
9
26
|
if (key in exports && exports[key] === _BarChart[key]) return;
|
|
10
27
|
Object.defineProperty(exports, key, {
|
|
11
28
|
enumerable: true,
|
|
@@ -17,6 +34,7 @@ Object.keys(_BarChart).forEach(function (key) {
|
|
|
17
34
|
var _BarPlot = require("./BarPlot");
|
|
18
35
|
Object.keys(_BarPlot).forEach(function (key) {
|
|
19
36
|
if (key === "default" || key === "__esModule") return;
|
|
37
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
20
38
|
if (key in exports && exports[key] === _BarPlot[key]) return;
|
|
21
39
|
Object.defineProperty(exports, key, {
|
|
22
40
|
enumerable: true,
|
|
@@ -28,6 +46,7 @@ Object.keys(_BarPlot).forEach(function (key) {
|
|
|
28
46
|
var _BarElement = require("./BarElement");
|
|
29
47
|
Object.keys(_BarElement).forEach(function (key) {
|
|
30
48
|
if (key === "default" || key === "__esModule") return;
|
|
49
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
31
50
|
if (key in exports && exports[key] === _BarElement[key]) return;
|
|
32
51
|
Object.defineProperty(exports, key, {
|
|
33
52
|
enumerable: true,
|
|
@@ -39,6 +58,7 @@ Object.keys(_BarElement).forEach(function (key) {
|
|
|
39
58
|
var _BarLabel = require("./BarLabel");
|
|
40
59
|
Object.keys(_BarLabel).forEach(function (key) {
|
|
41
60
|
if (key === "default" || key === "__esModule") return;
|
|
61
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
42
62
|
if (key in exports && exports[key] === _BarLabel[key]) return;
|
|
43
63
|
Object.defineProperty(exports, key, {
|
|
44
64
|
enumerable: true,
|
|
@@ -50,6 +70,7 @@ Object.keys(_BarLabel).forEach(function (key) {
|
|
|
50
70
|
var _barElementClasses = require("./barElementClasses");
|
|
51
71
|
Object.keys(_barElementClasses).forEach(function (key) {
|
|
52
72
|
if (key === "default" || key === "__esModule") return;
|
|
73
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
53
74
|
if (key in exports && exports[key] === _barElementClasses[key]) return;
|
|
54
75
|
Object.defineProperty(exports, key, {
|
|
55
76
|
enumerable: true,
|
|
@@ -57,4 +78,5 @@ Object.keys(_barElementClasses).forEach(function (key) {
|
|
|
57
78
|
return _barElementClasses[key];
|
|
58
79
|
}
|
|
59
80
|
});
|
|
60
|
-
});
|
|
81
|
+
});
|
|
82
|
+
var _barClasses = require("./barClasses");
|
package/BarChart/types.d.ts
CHANGED
|
@@ -9,7 +9,11 @@ export type AnimationData = {
|
|
|
9
9
|
xOrigin: number;
|
|
10
10
|
layout: BarSeriesType['layout'];
|
|
11
11
|
};
|
|
12
|
-
export interface
|
|
12
|
+
export interface ProcessedBarSeriesData {
|
|
13
|
+
seriesId: SeriesId;
|
|
14
|
+
data: ProcessedBarData[];
|
|
15
|
+
}
|
|
16
|
+
export interface ProcessedBarData extends AnimationData {
|
|
13
17
|
seriesId: SeriesId;
|
|
14
18
|
dataIndex: number;
|
|
15
19
|
color: string;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ChartsXAxisProps, ChartsYAxisProps } from "../models/axis.js";
|
|
2
|
+
import { ChartDrawingArea } from "../hooks/index.js";
|
|
3
|
+
import { MaskData, ProcessedBarSeriesData } from "./types.js";
|
|
4
|
+
import { ComputedAxisConfig } from "../internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxis.types.js";
|
|
5
|
+
export declare function useBarPlotData(drawingArea: ChartDrawingArea, xAxes: ComputedAxisConfig<ChartsXAxisProps>, yAxes: ComputedAxisConfig<ChartsYAxisProps>): {
|
|
6
|
+
completedData: ProcessedBarSeriesData[];
|
|
7
|
+
masksData: MaskData[];
|
|
8
|
+
};
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.useBarPlotData = useBarPlotData;
|
|
8
|
+
var _getColor = _interopRequireDefault(require("./seriesConfig/getColor"));
|
|
9
|
+
var _hooks = require("../hooks");
|
|
10
|
+
var _checkScaleErrors = require("./checkScaleErrors");
|
|
11
|
+
var _useBarSeries = require("../hooks/useBarSeries");
|
|
12
|
+
function useBarPlotData(drawingArea, xAxes, yAxes) {
|
|
13
|
+
const seriesData = (0, _useBarSeries.useBarSeriesContext)() ?? {
|
|
14
|
+
series: {},
|
|
15
|
+
stackingGroups: [],
|
|
16
|
+
seriesOrder: []
|
|
17
|
+
};
|
|
18
|
+
const defaultXAxisId = (0, _hooks.useXAxes)().xAxisIds[0];
|
|
19
|
+
const defaultYAxisId = (0, _hooks.useYAxes)().yAxisIds[0];
|
|
20
|
+
const chartId = (0, _hooks.useChartId)();
|
|
21
|
+
const {
|
|
22
|
+
series,
|
|
23
|
+
stackingGroups
|
|
24
|
+
} = seriesData;
|
|
25
|
+
const masks = {};
|
|
26
|
+
const data = stackingGroups.flatMap(({
|
|
27
|
+
ids: seriesIds
|
|
28
|
+
}, groupIndex) => {
|
|
29
|
+
const xMin = drawingArea.left;
|
|
30
|
+
const xMax = drawingArea.left + drawingArea.width;
|
|
31
|
+
const yMin = drawingArea.top;
|
|
32
|
+
const yMax = drawingArea.top + drawingArea.height;
|
|
33
|
+
return seriesIds.map(seriesId => {
|
|
34
|
+
const xAxisId = series[seriesId].xAxisId ?? defaultXAxisId;
|
|
35
|
+
const yAxisId = series[seriesId].yAxisId ?? defaultYAxisId;
|
|
36
|
+
const xAxisConfig = xAxes[xAxisId];
|
|
37
|
+
const yAxisConfig = yAxes[yAxisId];
|
|
38
|
+
const verticalLayout = series[seriesId].layout === 'vertical';
|
|
39
|
+
(0, _checkScaleErrors.checkScaleErrors)(verticalLayout, seriesId, series[seriesId], xAxisId, xAxes, yAxisId, yAxes);
|
|
40
|
+
const baseScaleConfig = verticalLayout ? xAxisConfig : yAxisConfig;
|
|
41
|
+
const xScale = xAxisConfig.scale;
|
|
42
|
+
const yScale = yAxisConfig.scale;
|
|
43
|
+
const colorGetter = (0, _getColor.default)(series[seriesId], xAxes[xAxisId], yAxes[yAxisId]);
|
|
44
|
+
const bandWidth = baseScaleConfig.scale.bandwidth();
|
|
45
|
+
const {
|
|
46
|
+
barWidth,
|
|
47
|
+
offset
|
|
48
|
+
} = getBandSize({
|
|
49
|
+
bandWidth,
|
|
50
|
+
numberOfGroups: stackingGroups.length,
|
|
51
|
+
gapRatio: baseScaleConfig.barGapRatio
|
|
52
|
+
});
|
|
53
|
+
const barOffset = groupIndex * (barWidth + offset);
|
|
54
|
+
const {
|
|
55
|
+
stackedData,
|
|
56
|
+
data: currentSeriesData,
|
|
57
|
+
layout
|
|
58
|
+
} = series[seriesId];
|
|
59
|
+
const seriesDataPoints = baseScaleConfig.data.map((baseValue, dataIndex) => {
|
|
60
|
+
if (currentSeriesData[dataIndex] == null) {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
const values = stackedData[dataIndex];
|
|
64
|
+
const valueCoordinates = values.map(v => verticalLayout ? yScale(v) : xScale(v));
|
|
65
|
+
const minValueCoord = Math.round(Math.min(...valueCoordinates));
|
|
66
|
+
const maxValueCoord = Math.round(Math.max(...valueCoordinates));
|
|
67
|
+
const stackId = series[seriesId].stack;
|
|
68
|
+
const result = {
|
|
69
|
+
seriesId,
|
|
70
|
+
dataIndex,
|
|
71
|
+
layout,
|
|
72
|
+
x: verticalLayout ? xScale(baseValue) + barOffset : minValueCoord,
|
|
73
|
+
y: verticalLayout ? minValueCoord : yScale(baseValue) + barOffset,
|
|
74
|
+
xOrigin: xScale(0) ?? 0,
|
|
75
|
+
yOrigin: yScale(0) ?? 0,
|
|
76
|
+
height: verticalLayout ? maxValueCoord - minValueCoord : barWidth,
|
|
77
|
+
width: verticalLayout ? barWidth : maxValueCoord - minValueCoord,
|
|
78
|
+
color: colorGetter(dataIndex),
|
|
79
|
+
value: currentSeriesData[dataIndex],
|
|
80
|
+
maskId: `${chartId}_${stackId || seriesId}_${groupIndex}_${dataIndex}`
|
|
81
|
+
};
|
|
82
|
+
if (result.x > xMax || result.x + result.width < xMin || result.y > yMax || result.y + result.height < yMin) {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
if (!masks[result.maskId]) {
|
|
86
|
+
masks[result.maskId] = {
|
|
87
|
+
id: result.maskId,
|
|
88
|
+
width: 0,
|
|
89
|
+
height: 0,
|
|
90
|
+
hasNegative: false,
|
|
91
|
+
hasPositive: false,
|
|
92
|
+
layout: result.layout,
|
|
93
|
+
xOrigin: xScale(0),
|
|
94
|
+
yOrigin: yScale(0),
|
|
95
|
+
x: 0,
|
|
96
|
+
y: 0
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
const mask = masks[result.maskId];
|
|
100
|
+
mask.width = result.layout === 'vertical' ? result.width : mask.width + result.width;
|
|
101
|
+
mask.height = result.layout === 'vertical' ? mask.height + result.height : result.height;
|
|
102
|
+
mask.x = Math.min(mask.x === 0 ? Infinity : mask.x, result.x);
|
|
103
|
+
mask.y = Math.min(mask.y === 0 ? Infinity : mask.y, result.y);
|
|
104
|
+
mask.hasNegative = mask.hasNegative || (result.value ?? 0) < 0;
|
|
105
|
+
mask.hasPositive = mask.hasPositive || (result.value ?? 0) > 0;
|
|
106
|
+
return result;
|
|
107
|
+
}).filter(rectangle => rectangle !== null);
|
|
108
|
+
return {
|
|
109
|
+
seriesId,
|
|
110
|
+
data: seriesDataPoints
|
|
111
|
+
};
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
return {
|
|
115
|
+
completedData: data,
|
|
116
|
+
masksData: Object.values(masks)
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Solution of the equations
|
|
122
|
+
* W = barWidth * N + offset * (N-1)
|
|
123
|
+
* offset / (offset + barWidth) = r
|
|
124
|
+
* @param bandWidth The width available to place bars.
|
|
125
|
+
* @param numberOfGroups The number of bars to place in that space.
|
|
126
|
+
* @param gapRatio The ratio of the gap between bars over the bar width.
|
|
127
|
+
* @returns The bar width and the offset between bars.
|
|
128
|
+
*/
|
|
129
|
+
function getBandSize({
|
|
130
|
+
bandWidth: W,
|
|
131
|
+
numberOfGroups: N,
|
|
132
|
+
gapRatio: r
|
|
133
|
+
}) {
|
|
134
|
+
if (r === 0) {
|
|
135
|
+
return {
|
|
136
|
+
barWidth: W / N,
|
|
137
|
+
offset: 0
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
const barWidth = W / (N + (N - 1) * r);
|
|
141
|
+
const offset = r * barWidth;
|
|
142
|
+
return {
|
|
143
|
+
barWidth,
|
|
144
|
+
offset
|
|
145
|
+
};
|
|
146
|
+
}
|