@mui/x-charts 7.10.0 → 7.11.1
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.js +2 -2
- package/BarChart/BarElement.d.ts +2 -1
- package/BarChart/BarLabel/BarLabelItem.d.ts +2 -1
- package/BarChart/BarPlot.js +8 -8
- package/BarChart/checkScaleErrors.d.ts +4 -4
- package/BarChart/checkScaleErrors.js +11 -11
- package/BarChart/extremums.js +4 -1
- package/BarChart/formatter.js +2 -2
- package/BarChart/useBarChartProps.js +38 -33
- package/CHANGELOG.md +169 -0
- package/ChartContainer/ChartContainer.d.ts +28 -2
- package/ChartContainer/ChartContainer.js +25 -66
- package/ChartContainer/useChartContainerHooks.d.ts +1 -1
- package/ChartContainer/useChartContainerHooks.js +2 -2
- package/ChartContainer/useChartContainerProps.d.ts +86 -0
- package/ChartContainer/useChartContainerProps.js +95 -0
- package/ChartContainer/useDefaultizeAxis.d.ts +36 -0
- package/ChartContainer/useDefaultizeAxis.js +29 -0
- package/ChartsAxis/ChartsAxis.js +4 -4
- package/ChartsAxisHighlight/ChartsAxisHighlight.js +1 -1
- package/ChartsLegend/ChartsLegend.d.ts +3 -12
- package/ChartsLegend/ContinuousColorLegend.d.ts +65 -0
- package/ChartsLegend/ContinuousColorLegend.js +398 -0
- package/ChartsLegend/DefaultChartsLegend.d.ts +7 -50
- package/ChartsLegend/DefaultChartsLegend.js +13 -198
- package/ChartsLegend/LegendPerItem.d.ts +61 -0
- package/ChartsLegend/LegendPerItem.js +151 -0
- package/ChartsLegend/PiecewiseColorLegend.d.ts +26 -0
- package/ChartsLegend/PiecewiseColorLegend.js +169 -0
- package/ChartsLegend/chartsLegend.types.d.ts +31 -0
- package/ChartsLegend/chartsLegend.types.js +5 -0
- package/ChartsLegend/index.d.ts +2 -0
- package/ChartsLegend/index.js +22 -0
- package/ChartsLegend/legend.types.d.ts +62 -0
- package/ChartsLegend/legend.types.js +5 -0
- package/ChartsLegend/legendItemsPlacement.d.ts +3 -0
- package/ChartsLegend/legendItemsPlacement.js +79 -0
- package/ChartsLegend/useAxis.d.ts +7 -0
- package/ChartsLegend/useAxis.js +47 -0
- package/ChartsLegend/utils.d.ts +1 -8
- package/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +3 -1
- package/ChartsOverlay/ChartsOverlay.d.ts +3 -2
- package/ChartsReferenceLine/ChartsReferenceLine.d.ts +1 -1
- package/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
- package/ChartsReferenceLine/ChartsXReferenceLine.js +1 -2
- package/ChartsReferenceLine/ChartsYReferenceLine.js +1 -2
- package/ChartsSurface.js +3 -1
- package/ChartsTooltip/ChartsAxisTooltipContent.js +7 -3
- package/ChartsTooltip/ChartsItemTooltipContent.js +4 -4
- package/ChartsVoronoiHandler/ChartsVoronoiHandler.js +30 -20
- package/ChartsXAxis/ChartsXAxis.js +1 -1
- package/ChartsYAxis/ChartsYAxis.js +15 -3
- package/Gauge/Gauge.d.ts +1 -4
- package/Gauge/Gauge.js +9 -6
- package/Gauge/GaugeContainer.js +8 -4
- package/Gauge/GaugeProvider.js +9 -9
- package/LineChart/AnimatedArea.js +2 -2
- package/LineChart/AnimatedLine.js +2 -2
- package/LineChart/AreaElement.d.ts +2 -1
- package/LineChart/AreaPlot.js +10 -6
- package/LineChart/LineChart.js +5 -2
- package/LineChart/LineElement.d.ts +2 -1
- package/LineChart/LineHighlightPlot.d.ts +2 -1
- package/LineChart/LineHighlightPlot.js +17 -5
- package/LineChart/LinePlot.js +10 -6
- package/LineChart/MarkElement.js +2 -2
- package/LineChart/MarkPlot.js +13 -25
- package/LineChart/extremums.js +4 -1
- package/LineChart/formatter.js +2 -2
- package/LineChart/useLineChartProps.js +38 -33
- package/PieChart/PieArc.js +1 -0
- package/PieChart/PieChart.d.ts +1 -4
- package/PieChart/PieChart.js +40 -34
- package/PieChart/PiePlot.js +6 -6
- package/PieChart/getPieCoordinates.js +3 -3
- package/ResponsiveChartContainer/ResponsiveChartContainer.js +8 -20
- package/ResponsiveChartContainer/useChartContainerDimensions.d.ts +5 -1
- package/ResponsiveChartContainer/useChartContainerDimensions.js +8 -4
- package/ResponsiveChartContainer/useResponsiveChartContainerProps.d.ts +20 -0
- package/ResponsiveChartContainer/useResponsiveChartContainerProps.js +73 -0
- package/ScatterChart/Scatter.js +6 -9
- package/ScatterChart/ScatterChart.js +4 -1
- package/ScatterChart/ScatterPlot.js +6 -3
- package/ScatterChart/extremums.js +8 -2
- package/ScatterChart/useScatterChartProps.js +35 -30
- package/SparkLineChart/SparkLineChart.js +27 -22
- package/context/CartesianProvider/CartesianContext.d.ts +1 -1
- package/context/CartesianProvider/CartesianProvider.d.ts +2 -3
- package/context/CartesianProvider/CartesianProvider.js +18 -7
- package/context/CartesianProvider/computeValue.d.ts +32 -9
- package/context/CartesianProvider/computeValue.js +20 -16
- package/context/CartesianProvider/defaultizeAxis.d.ts +36 -0
- package/context/CartesianProvider/defaultizeAxis.js +21 -0
- package/context/CartesianProvider/index.d.ts +0 -1
- package/context/CartesianProvider/index.js +1 -3
- package/context/CartesianProvider/normalizeAxis.d.ts +1 -1
- package/context/CartesianProvider/normalizeAxis.js +2 -2
- package/context/DrawingProvider.d.ts +12 -0
- package/context/DrawingProvider.js +15 -2
- package/context/HighlightedProvider/HighlightedProvider.js +2 -2
- package/context/SeriesContextProvider.js +1 -1
- package/context/ZAxisContextProvider.d.ts +1 -1
- package/context/ZAxisContextProvider.js +1 -1
- package/esm/BarChart/BarChart.js +2 -2
- package/esm/BarChart/BarPlot.js +8 -8
- package/esm/BarChart/checkScaleErrors.js +11 -11
- package/esm/BarChart/extremums.js +4 -1
- package/esm/BarChart/formatter.js +2 -2
- package/esm/BarChart/useBarChartProps.js +38 -33
- package/esm/ChartContainer/ChartContainer.js +25 -66
- package/esm/ChartContainer/useChartContainerHooks.js +2 -2
- package/esm/ChartContainer/useChartContainerProps.js +87 -0
- package/esm/ChartContainer/useDefaultizeAxis.js +19 -0
- package/esm/ChartsAxis/ChartsAxis.js +4 -4
- package/esm/ChartsAxisHighlight/ChartsAxisHighlight.js +1 -1
- package/esm/ChartsLegend/ContinuousColorLegend.js +390 -0
- package/esm/ChartsLegend/DefaultChartsLegend.js +14 -198
- package/esm/ChartsLegend/LegendPerItem.js +141 -0
- package/esm/ChartsLegend/PiecewiseColorLegend.js +161 -0
- package/esm/ChartsLegend/chartsLegend.types.js +1 -0
- package/esm/ChartsLegend/index.js +2 -0
- package/esm/ChartsLegend/legend.types.js +1 -0
- package/esm/ChartsLegend/legendItemsPlacement.js +72 -0
- package/esm/ChartsLegend/useAxis.js +39 -0
- package/esm/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +3 -1
- package/esm/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
- package/esm/ChartsReferenceLine/ChartsXReferenceLine.js +2 -3
- package/esm/ChartsReferenceLine/ChartsYReferenceLine.js +2 -3
- package/esm/ChartsSurface.js +3 -1
- package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +7 -3
- package/esm/ChartsTooltip/ChartsItemTooltipContent.js +4 -4
- package/esm/ChartsVoronoiHandler/ChartsVoronoiHandler.js +30 -20
- package/esm/ChartsXAxis/ChartsXAxis.js +1 -1
- package/esm/ChartsYAxis/ChartsYAxis.js +15 -3
- package/esm/Gauge/Gauge.js +8 -5
- package/esm/Gauge/GaugeContainer.js +8 -4
- package/esm/Gauge/GaugeProvider.js +1 -1
- package/esm/LineChart/AnimatedArea.js +1 -1
- package/esm/LineChart/AnimatedLine.js +1 -1
- package/esm/LineChart/AreaPlot.js +10 -6
- package/esm/LineChart/LineChart.js +5 -2
- package/esm/LineChart/LineHighlightPlot.js +17 -5
- package/esm/LineChart/LinePlot.js +10 -6
- package/esm/LineChart/MarkElement.js +1 -1
- package/esm/LineChart/MarkPlot.js +12 -24
- package/esm/LineChart/extremums.js +4 -1
- package/esm/LineChart/formatter.js +2 -2
- package/esm/LineChart/useLineChartProps.js +38 -33
- package/esm/PieChart/PieArc.js +1 -0
- package/esm/PieChart/PieChart.js +39 -33
- package/esm/PieChart/PiePlot.js +1 -1
- package/esm/PieChart/getPieCoordinates.js +1 -1
- package/esm/ResponsiveChartContainer/ResponsiveChartContainer.js +8 -20
- package/esm/ResponsiveChartContainer/useChartContainerDimensions.js +8 -4
- package/esm/ResponsiveChartContainer/useResponsiveChartContainerProps.js +65 -0
- package/esm/ScatterChart/Scatter.js +6 -9
- package/esm/ScatterChart/ScatterChart.js +4 -1
- package/esm/ScatterChart/ScatterPlot.js +6 -3
- package/esm/ScatterChart/extremums.js +8 -2
- package/esm/ScatterChart/useScatterChartProps.js +35 -30
- package/esm/SparkLineChart/SparkLineChart.js +27 -22
- package/esm/context/CartesianProvider/CartesianProvider.js +18 -7
- package/esm/context/CartesianProvider/computeValue.js +20 -16
- package/esm/context/CartesianProvider/defaultizeAxis.js +13 -0
- package/esm/context/CartesianProvider/index.js +1 -3
- package/esm/context/CartesianProvider/normalizeAxis.js +2 -2
- package/esm/context/DrawingProvider.js +15 -2
- package/esm/context/HighlightedProvider/HighlightedProvider.js +2 -2
- package/esm/context/SeriesContextProvider.js +1 -1
- package/esm/context/ZAxisContextProvider.js +1 -1
- package/esm/hooks/useAxisEvents.js +14 -17
- package/esm/hooks/useDrawingArea.js +5 -3
- package/esm/hooks/useReducedMotion.js +4 -2
- package/esm/internals/SlotComponentPropsFromProps.js +1 -0
- package/esm/internals/cleanId.js +6 -0
- package/esm/internals/components/ChartsAxesGradients/ChartsContinuousGradient.js +3 -2
- package/esm/internals/geometry.js +1 -1
- package/esm/internals/{utils.js → getPercentageValue.js} +1 -13
- package/esm/internals/getSymbol.js +5 -0
- package/esm/internals/index.js +3 -1
- package/esm/internals/isDefined.js +3 -0
- package/esm/internals/notNull.js +3 -0
- package/esm/internals/ts-generic.js +1 -0
- package/esm/internals/warning.js +19 -11
- package/hooks/useAxisEvents.js +14 -17
- package/hooks/useDrawingArea.js +5 -3
- package/hooks/useReducedMotion.js +4 -2
- package/index.js +1 -1
- package/internals/SlotComponentPropsFromProps.d.ts +1 -0
- package/internals/SlotComponentPropsFromProps.js +5 -0
- package/internals/cleanId.d.ts +4 -0
- package/internals/cleanId.js +12 -0
- package/internals/components/ChartsAxesGradients/ChartsContinuousGradient.d.ts +6 -0
- package/internals/components/ChartsAxesGradients/ChartsContinuousGradient.js +3 -2
- package/internals/defaultizeColor.d.ts +7 -0
- package/internals/geometry.js +1 -1
- package/internals/getPercentageValue.d.ts +7 -0
- package/internals/{utils.js → getPercentageValue.js} +1 -15
- package/internals/getSymbol.d.ts +2 -0
- package/internals/getSymbol.js +11 -0
- package/internals/index.d.ts +3 -1
- package/internals/index.js +25 -5
- package/internals/isDefined.d.ts +1 -0
- package/internals/isDefined.js +9 -0
- package/internals/notNull.d.ts +1 -0
- package/internals/notNull.js +9 -0
- package/internals/ts-generic.d.ts +5 -0
- package/internals/ts-generic.js +5 -0
- package/internals/warning.d.ts +2 -1
- package/internals/warning.js +21 -12
- package/models/axis.d.ts +5 -2
- package/models/helpers.d.ts +1 -0
- package/models/seriesType/common.d.ts +10 -0
- package/models/seriesType/config.d.ts +2 -16
- package/models/seriesType/scatter.d.ts +5 -0
- package/modern/BarChart/BarChart.js +2 -2
- package/modern/BarChart/BarPlot.js +8 -8
- package/modern/BarChart/checkScaleErrors.js +11 -11
- package/modern/BarChart/extremums.js +4 -1
- package/modern/BarChart/formatter.js +2 -2
- package/modern/BarChart/useBarChartProps.js +38 -33
- package/modern/ChartContainer/ChartContainer.js +25 -66
- package/modern/ChartContainer/useChartContainerHooks.js +2 -2
- package/modern/ChartContainer/useChartContainerProps.js +87 -0
- package/modern/ChartContainer/useDefaultizeAxis.js +19 -0
- package/modern/ChartsAxis/ChartsAxis.js +4 -4
- package/modern/ChartsAxisHighlight/ChartsAxisHighlight.js +1 -1
- package/modern/ChartsLegend/ContinuousColorLegend.js +390 -0
- package/modern/ChartsLegend/DefaultChartsLegend.js +14 -198
- package/modern/ChartsLegend/LegendPerItem.js +141 -0
- package/modern/ChartsLegend/PiecewiseColorLegend.js +161 -0
- package/modern/ChartsLegend/chartsLegend.types.js +1 -0
- package/modern/ChartsLegend/index.js +2 -0
- package/modern/ChartsLegend/legend.types.js +1 -0
- package/modern/ChartsLegend/legendItemsPlacement.js +72 -0
- package/modern/ChartsLegend/useAxis.js +39 -0
- package/modern/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +3 -1
- package/modern/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
- package/modern/ChartsReferenceLine/ChartsXReferenceLine.js +2 -3
- package/modern/ChartsReferenceLine/ChartsYReferenceLine.js +2 -3
- package/modern/ChartsSurface.js +3 -1
- package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +7 -3
- package/modern/ChartsTooltip/ChartsItemTooltipContent.js +4 -4
- package/modern/ChartsVoronoiHandler/ChartsVoronoiHandler.js +30 -20
- package/modern/ChartsXAxis/ChartsXAxis.js +1 -1
- package/modern/ChartsYAxis/ChartsYAxis.js +15 -3
- package/modern/Gauge/Gauge.js +8 -5
- package/modern/Gauge/GaugeContainer.js +8 -4
- package/modern/Gauge/GaugeProvider.js +1 -1
- package/modern/LineChart/AnimatedArea.js +1 -1
- package/modern/LineChart/AnimatedLine.js +1 -1
- package/modern/LineChart/AreaPlot.js +10 -6
- package/modern/LineChart/LineChart.js +5 -2
- package/modern/LineChart/LineHighlightPlot.js +17 -5
- package/modern/LineChart/LinePlot.js +10 -6
- package/modern/LineChart/MarkElement.js +1 -1
- package/modern/LineChart/MarkPlot.js +12 -24
- package/modern/LineChart/extremums.js +4 -1
- package/modern/LineChart/formatter.js +2 -2
- package/modern/LineChart/useLineChartProps.js +38 -33
- package/modern/PieChart/PieArc.js +1 -0
- package/modern/PieChart/PieChart.js +39 -33
- package/modern/PieChart/PiePlot.js +1 -1
- package/modern/PieChart/getPieCoordinates.js +1 -1
- package/modern/ResponsiveChartContainer/ResponsiveChartContainer.js +8 -20
- package/modern/ResponsiveChartContainer/useChartContainerDimensions.js +8 -4
- package/modern/ResponsiveChartContainer/useResponsiveChartContainerProps.js +65 -0
- package/modern/ScatterChart/Scatter.js +6 -9
- package/modern/ScatterChart/ScatterChart.js +4 -1
- package/modern/ScatterChart/ScatterPlot.js +6 -3
- package/modern/ScatterChart/extremums.js +8 -2
- package/modern/ScatterChart/useScatterChartProps.js +35 -30
- package/modern/SparkLineChart/SparkLineChart.js +27 -22
- package/modern/context/CartesianProvider/CartesianProvider.js +18 -7
- package/modern/context/CartesianProvider/computeValue.js +20 -16
- package/modern/context/CartesianProvider/defaultizeAxis.js +13 -0
- package/modern/context/CartesianProvider/index.js +1 -3
- package/modern/context/CartesianProvider/normalizeAxis.js +2 -2
- package/modern/context/DrawingProvider.js +15 -2
- package/modern/context/HighlightedProvider/HighlightedProvider.js +2 -2
- package/modern/context/SeriesContextProvider.js +1 -1
- package/modern/context/ZAxisContextProvider.js +1 -1
- package/modern/hooks/useAxisEvents.js +14 -17
- package/modern/hooks/useDrawingArea.js +5 -3
- package/modern/hooks/useReducedMotion.js +4 -2
- package/modern/index.js +1 -1
- package/modern/internals/SlotComponentPropsFromProps.js +1 -0
- package/modern/internals/cleanId.js +6 -0
- package/modern/internals/components/ChartsAxesGradients/ChartsContinuousGradient.js +3 -2
- package/modern/internals/geometry.js +1 -1
- package/modern/internals/{utils.js → getPercentageValue.js} +1 -13
- package/modern/internals/getSymbol.js +5 -0
- package/modern/internals/index.js +3 -1
- package/modern/internals/isDefined.js +3 -0
- package/modern/internals/notNull.js +3 -0
- package/modern/internals/ts-generic.js +1 -0
- package/modern/internals/warning.js +19 -11
- package/package.json +4 -4
- package/internals/utils.d.ts +0 -18
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { AxisConfig, ChartsXAxisProps, ChartsYAxisProps, ScaleName } from '../../models/axis';
|
|
3
3
|
import { DatasetType } from '../../models/seriesType/config';
|
|
4
|
-
import { MakeOptional } from '../../models/helpers';
|
|
5
4
|
import { ExtremumGettersConfig } from '../../models';
|
|
6
5
|
export type CartesianContextProviderProps = {
|
|
7
6
|
/**
|
|
@@ -9,13 +8,13 @@ export type CartesianContextProviderProps = {
|
|
|
9
8
|
* If not provided, a default axis config is used.
|
|
10
9
|
* An array of [[AxisConfig]] objects.
|
|
11
10
|
*/
|
|
12
|
-
xAxis
|
|
11
|
+
xAxis: AxisConfig<ScaleName, any, ChartsXAxisProps>[];
|
|
13
12
|
/**
|
|
14
13
|
* The configuration of the y-axes.
|
|
15
14
|
* If not provided, a default axis config is used.
|
|
16
15
|
* An array of [[AxisConfig]] objects.
|
|
17
16
|
*/
|
|
18
|
-
yAxis
|
|
17
|
+
yAxis: AxisConfig<ScaleName, any, ChartsYAxisProps>[];
|
|
19
18
|
/**
|
|
20
19
|
* An array of objects that can be used to populate series and axes data using their `dataKey` property.
|
|
21
20
|
*/
|
|
@@ -8,15 +8,14 @@ var React = _interopRequireWildcard(require("react"));
|
|
|
8
8
|
var _useDrawingArea = require("../../hooks/useDrawingArea");
|
|
9
9
|
var _useSeries = require("../../hooks/useSeries");
|
|
10
10
|
var _CartesianContext = require("./CartesianContext");
|
|
11
|
-
var _normalizeAxis = require("./normalizeAxis");
|
|
12
11
|
var _computeValue = require("./computeValue");
|
|
13
12
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
14
13
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
15
14
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
16
15
|
function CartesianContextProvider(props) {
|
|
17
16
|
const {
|
|
18
|
-
xAxis
|
|
19
|
-
yAxis
|
|
17
|
+
xAxis,
|
|
18
|
+
yAxis,
|
|
20
19
|
dataset,
|
|
21
20
|
xExtremumGetters,
|
|
22
21
|
yExtremumGetters,
|
|
@@ -24,10 +23,22 @@ function CartesianContextProvider(props) {
|
|
|
24
23
|
} = props;
|
|
25
24
|
const formattedSeries = (0, _useSeries.useSeries)();
|
|
26
25
|
const drawingArea = (0, _useDrawingArea.useDrawingArea)();
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
const xValues = React.useMemo(() => (0, _computeValue.computeValue)({
|
|
27
|
+
drawingArea,
|
|
28
|
+
formattedSeries,
|
|
29
|
+
axis: xAxis,
|
|
30
|
+
extremumGetters: xExtremumGetters,
|
|
31
|
+
dataset,
|
|
32
|
+
axisDirection: 'x'
|
|
33
|
+
}), [drawingArea, formattedSeries, xAxis, xExtremumGetters, dataset]);
|
|
34
|
+
const yValues = React.useMemo(() => (0, _computeValue.computeValue)({
|
|
35
|
+
drawingArea,
|
|
36
|
+
formattedSeries,
|
|
37
|
+
axis: yAxis,
|
|
38
|
+
extremumGetters: yExtremumGetters,
|
|
39
|
+
dataset,
|
|
40
|
+
axisDirection: 'y'
|
|
41
|
+
}), [drawingArea, formattedSeries, yAxis, yExtremumGetters, dataset]);
|
|
31
42
|
const value = React.useMemo(() => ({
|
|
32
43
|
isInitialized: true,
|
|
33
44
|
data: {
|
|
@@ -1,19 +1,42 @@
|
|
|
1
1
|
import { AxisConfig, ScaleName } from '../../models';
|
|
2
|
-
import { ChartsXAxisProps, ChartsAxisProps, ChartsYAxisProps } from '../../models/axis';
|
|
3
|
-
import { CartesianChartSeriesType, ExtremumGetter } from '../../models/seriesType/config';
|
|
2
|
+
import { ChartsXAxisProps, ChartsAxisProps, ChartsYAxisProps, AxisId } from '../../models/axis';
|
|
3
|
+
import { CartesianChartSeriesType, DatasetType, ExtremumGetter } from '../../models/seriesType/config';
|
|
4
4
|
import { DefaultizedAxisConfig } from './CartesianContext';
|
|
5
5
|
import { DrawingArea } from '../DrawingProvider';
|
|
6
6
|
import { FormattedSeries } from '../SeriesContextProvider';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
export declare function computeValue(options: {
|
|
8
|
+
drawingArea: DrawingArea;
|
|
9
|
+
formattedSeries: FormattedSeries;
|
|
10
|
+
axis: AxisConfig<ScaleName, any, ChartsYAxisProps>[] | undefined;
|
|
11
|
+
extremumGetters: {
|
|
12
|
+
[K in CartesianChartSeriesType]?: ExtremumGetter<K>;
|
|
13
|
+
};
|
|
14
|
+
axisDirection: 'y';
|
|
15
|
+
dataset: DatasetType | undefined;
|
|
16
|
+
zoomData?: {
|
|
17
|
+
axisId: AxisId;
|
|
18
|
+
start: number;
|
|
19
|
+
end: number;
|
|
20
|
+
}[];
|
|
21
|
+
}): {
|
|
11
22
|
axis: DefaultizedAxisConfig<ChartsYAxisProps>;
|
|
12
23
|
axisIds: string[];
|
|
13
24
|
};
|
|
14
|
-
export declare function computeValue(
|
|
15
|
-
|
|
16
|
-
|
|
25
|
+
export declare function computeValue(options: {
|
|
26
|
+
drawingArea: DrawingArea;
|
|
27
|
+
formattedSeries: FormattedSeries;
|
|
28
|
+
axis: AxisConfig<ScaleName, any, ChartsXAxisProps>[] | undefined;
|
|
29
|
+
extremumGetters: {
|
|
30
|
+
[K in CartesianChartSeriesType]?: ExtremumGetter<K>;
|
|
31
|
+
};
|
|
32
|
+
axisDirection: 'x';
|
|
33
|
+
dataset: DatasetType | undefined;
|
|
34
|
+
zoomData?: {
|
|
35
|
+
axisId: AxisId;
|
|
36
|
+
start: number;
|
|
37
|
+
end: number;
|
|
38
|
+
}[];
|
|
39
|
+
}): {
|
|
17
40
|
axis: DefaultizedAxisConfig<ChartsAxisProps>;
|
|
18
41
|
axisIds: string[];
|
|
19
42
|
};
|
|
@@ -7,14 +7,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports.computeValue = computeValue;
|
|
8
8
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
9
9
|
var _d3Scale = require("d3-scale");
|
|
10
|
-
var _constants = require("../../constants");
|
|
11
10
|
var _axis = require("../../models/axis");
|
|
12
11
|
var _colorScale = require("../../internals/colorScale");
|
|
13
12
|
var _useTicks = require("../../hooks/useTicks");
|
|
14
13
|
var _getScale = require("../../internals/getScale");
|
|
15
14
|
var _getAxisExtremum = require("./getAxisExtremum");
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
var _normalizeAxis = require("./normalizeAxis");
|
|
16
|
+
const getRange = (drawingArea, axisDirection, isReverse) => {
|
|
17
|
+
const range = axisDirection === 'x' ? [drawingArea.left, drawingArea.left + drawingArea.width] : [drawingArea.top + drawingArea.height, drawingArea.top];
|
|
18
18
|
return isReverse ? range.reverse() : range;
|
|
19
19
|
};
|
|
20
20
|
const zoomedScaleRange = (scaleRange, zoomRange) => {
|
|
@@ -36,26 +36,30 @@ function createDateFormatter(axis, range) {
|
|
|
36
36
|
}
|
|
37
37
|
const DEFAULT_CATEGORY_GAP_RATIO = 0.2;
|
|
38
38
|
const DEFAULT_BAR_GAP_RATIO = 0.1;
|
|
39
|
-
function computeValue(
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
39
|
+
function computeValue({
|
|
40
|
+
drawingArea,
|
|
41
|
+
formattedSeries,
|
|
42
|
+
axis: inAxis,
|
|
43
|
+
extremumGetters,
|
|
44
|
+
dataset,
|
|
45
|
+
axisDirection,
|
|
46
|
+
zoomData
|
|
47
|
+
}) {
|
|
48
|
+
const allAxis = (0, _normalizeAxis.normalizeAxis)(inAxis, dataset, axisDirection);
|
|
49
49
|
const completeAxis = {};
|
|
50
50
|
allAxis.forEach((axis, axisIndex) => {
|
|
51
51
|
const isDefaultAxis = axisIndex === 0;
|
|
52
52
|
const [minData, maxData] = (0, _getAxisExtremum.getAxisExtremum)(axis, extremumGetters, isDefaultAxis, formattedSeries);
|
|
53
|
-
const
|
|
53
|
+
const zoom = zoomData?.find(({
|
|
54
|
+
axisId
|
|
55
|
+
}) => axisId === axis.id);
|
|
56
|
+
const zoomRange = zoom ? [zoom.start, zoom.end] : [0, 100];
|
|
57
|
+
const range = getRange(drawingArea, axisDirection, axis.reverse);
|
|
54
58
|
if ((0, _axis.isBandScaleConfig)(axis)) {
|
|
55
59
|
const categoryGapRatio = axis.categoryGapRatio ?? DEFAULT_CATEGORY_GAP_RATIO;
|
|
56
60
|
const barGapRatio = axis.barGapRatio ?? DEFAULT_BAR_GAP_RATIO;
|
|
57
61
|
// Reverse range because ordinal scales are presented from top to bottom on y-axis
|
|
58
|
-
const scaleRange =
|
|
62
|
+
const scaleRange = axisDirection === 'x' ? range : [range[1], range[0]];
|
|
59
63
|
const zoomedRange = zoomedScaleRange(scaleRange, zoomRange);
|
|
60
64
|
completeAxis[axis.id] = (0, _extends2.default)({
|
|
61
65
|
categoryGapRatio,
|
|
@@ -73,7 +77,7 @@ function computeValue(drawingArea, formattedSeries, inAxis, extremumGetters, axi
|
|
|
73
77
|
}
|
|
74
78
|
}
|
|
75
79
|
if ((0, _axis.isPointScaleConfig)(axis)) {
|
|
76
|
-
const scaleRange =
|
|
80
|
+
const scaleRange = axisDirection === 'x' ? range : [...range].reverse();
|
|
77
81
|
const zoomedRange = zoomedScaleRange(scaleRange, zoomRange);
|
|
78
82
|
completeAxis[axis.id] = (0, _extends2.default)({}, axis, {
|
|
79
83
|
scale: (0, _d3Scale.scalePoint)(axis.data, zoomedRange),
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { MakeOptional } from '../../models/helpers';
|
|
2
|
+
import { AxisConfig, ScaleName } from '../../models';
|
|
3
|
+
import { ChartsAxisProps } from '../../models/axis';
|
|
4
|
+
export declare const defaultizeAxis: (inAxis: MakeOptional<AxisConfig<ScaleName, any, ChartsAxisProps>, "id">[] | undefined, axisName: "x" | "y") => {
|
|
5
|
+
reverse?: boolean;
|
|
6
|
+
fill?: string;
|
|
7
|
+
stroke?: string;
|
|
8
|
+
data?: any[] | undefined;
|
|
9
|
+
label?: string;
|
|
10
|
+
max?: number | Date;
|
|
11
|
+
min?: number | Date;
|
|
12
|
+
classes?: Partial<import("../..").ChartsAxisClasses>;
|
|
13
|
+
slots?: Partial<import("../../models/axis").ChartsAxisSlots>;
|
|
14
|
+
slotProps?: Partial<import("../../models/axis").ChartsAxisSlotProps>;
|
|
15
|
+
dataKey?: string;
|
|
16
|
+
valueFormatter?: ((value: any, context: import("../../models/axis").AxisValueFormatterContext) => string) | undefined;
|
|
17
|
+
colorMap?: import("../../models/colorMapping").ContinuousColorConfig<number | Date> | import("../../models/colorMapping").PiecewiseColorConfig<number | Date> | import("../../models/colorMapping").OrdinalColorConfig<string | number | Date> | undefined;
|
|
18
|
+
tickMaxStep?: number;
|
|
19
|
+
tickMinStep?: number;
|
|
20
|
+
tickNumber?: number;
|
|
21
|
+
tickPlacement?: "start" | "end" | "middle" | "extremities";
|
|
22
|
+
tickLabelPlacement?: "middle" | "tick";
|
|
23
|
+
scaleType?: "linear" | "time" | "log" | "band" | "point" | "pow" | "sqrt" | "utc" | undefined;
|
|
24
|
+
axisId?: import("../../models/axis").AxisId;
|
|
25
|
+
disableLine?: boolean;
|
|
26
|
+
disableTicks?: boolean;
|
|
27
|
+
tickFontSize?: number;
|
|
28
|
+
tickLabelStyle?: import("../..").ChartsTextProps["style"];
|
|
29
|
+
labelStyle?: import("../..").ChartsTextProps["style"];
|
|
30
|
+
tickLabelInterval?: "auto" | ((value: any, index: number) => boolean);
|
|
31
|
+
labelFontSize?: number;
|
|
32
|
+
tickSize?: number;
|
|
33
|
+
tickInterval?: "auto" | ((value: any, index: number) => boolean) | any[];
|
|
34
|
+
hideTooltip?: boolean;
|
|
35
|
+
id: import("../../models/axis").AxisId;
|
|
36
|
+
}[];
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.defaultizeAxis = void 0;
|
|
8
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
9
|
+
var _constants = require("../../constants");
|
|
10
|
+
const defaultizeAxis = (inAxis, axisName) => {
|
|
11
|
+
const DEFAULT_AXIS_KEY = axisName === 'x' ? _constants.DEFAULT_X_AXIS_KEY : _constants.DEFAULT_Y_AXIS_KEY;
|
|
12
|
+
return [...(inAxis?.map((axis, index) => (0, _extends2.default)({
|
|
13
|
+
id: `defaultized-${axisName}-axis-${index}`
|
|
14
|
+
}, axis)) ?? []), ...(inAxis === undefined || inAxis.findIndex(({
|
|
15
|
+
id
|
|
16
|
+
}) => id === DEFAULT_AXIS_KEY) === -1 ? [{
|
|
17
|
+
id: DEFAULT_AXIS_KEY,
|
|
18
|
+
scaleType: 'linear'
|
|
19
|
+
}] : [])];
|
|
20
|
+
};
|
|
21
|
+
exports.defaultizeAxis = defaultizeAxis;
|
|
@@ -4,6 +4,5 @@ export * from './CartesianContext';
|
|
|
4
4
|
export * from './useCartesianContext';
|
|
5
5
|
declare const cartesianProviderUtils: {
|
|
6
6
|
computeValue: typeof computeValue;
|
|
7
|
-
normalizeAxis: <T extends import("../../internals").ChartsAxisProps, R extends import("../../internals").MakeOptional<import("../..").AxisConfig<import("../..").ScaleName, any, T>, "id">>(axis: R[] | undefined, dataset: import("../../internals").DatasetType | undefined, axisName: "x" | "y") => R[] | undefined;
|
|
8
7
|
};
|
|
9
8
|
export { cartesianProviderUtils };
|
|
@@ -8,7 +8,6 @@ var _exportNames = {
|
|
|
8
8
|
};
|
|
9
9
|
exports.cartesianProviderUtils = void 0;
|
|
10
10
|
var _computeValue = require("./computeValue");
|
|
11
|
-
var _normalizeAxis = require("./normalizeAxis");
|
|
12
11
|
var _CartesianProvider = require("./CartesianProvider");
|
|
13
12
|
Object.keys(_CartesianProvider).forEach(function (key) {
|
|
14
13
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -46,6 +45,5 @@ Object.keys(_useCartesianContext).forEach(function (key) {
|
|
|
46
45
|
});
|
|
47
46
|
});
|
|
48
47
|
const cartesianProviderUtils = exports.cartesianProviderUtils = {
|
|
49
|
-
computeValue: _computeValue.computeValue
|
|
50
|
-
normalizeAxis: _normalizeAxis.normalizeAxis
|
|
48
|
+
computeValue: _computeValue.computeValue
|
|
51
49
|
};
|
|
@@ -2,4 +2,4 @@ import type { AxisConfig, ScaleName } from '../../models';
|
|
|
2
2
|
import { ChartsAxisProps } from '../../models/axis';
|
|
3
3
|
import { MakeOptional } from '../../models/helpers';
|
|
4
4
|
import { DatasetType } from '../../models/seriesType/config';
|
|
5
|
-
export declare const normalizeAxis: <T extends ChartsAxisProps, R extends MakeOptional<AxisConfig<ScaleName, any, T>, "id">>(axis: R[] | undefined, dataset: DatasetType | undefined, axisName: "x" | "y") => R[]
|
|
5
|
+
export declare const normalizeAxis: <T extends ChartsAxisProps, R extends MakeOptional<AxisConfig<ScaleName, any, T>, "id">>(axis: R[] | undefined, dataset: DatasetType | undefined, axisName: "x" | "y") => R[];
|
|
@@ -13,11 +13,11 @@ const normalizeAxis = (axis, dataset, axisName) => {
|
|
|
13
13
|
return axisConfig;
|
|
14
14
|
}
|
|
15
15
|
if (dataset === undefined) {
|
|
16
|
-
throw Error(`MUI X
|
|
16
|
+
throw Error(`MUI X: ${axisName}-axis uses \`dataKey\` but no \`dataset\` is provided.`);
|
|
17
17
|
}
|
|
18
18
|
return (0, _extends2.default)({}, axisConfig, {
|
|
19
19
|
data: dataset.map(d => d[dataKey])
|
|
20
20
|
});
|
|
21
|
-
});
|
|
21
|
+
}) ?? [];
|
|
22
22
|
};
|
|
23
23
|
exports.normalizeAxis = normalizeAxis;
|
|
@@ -33,6 +33,18 @@ export type DrawingArea = {
|
|
|
33
33
|
* The height of the drawing area.
|
|
34
34
|
*/
|
|
35
35
|
height: number;
|
|
36
|
+
/**
|
|
37
|
+
* Checks if a point is inside the drawing area.
|
|
38
|
+
* @param {Object} point The point to check.
|
|
39
|
+
* @param {number} point.x The x coordinate of the point.
|
|
40
|
+
* @param {number} point.y The y coordinate of the point.
|
|
41
|
+
* @param {Element} targetElement The target element if relevant.
|
|
42
|
+
* @returns {boolean} `true` if the point is inside the drawing area, `false` otherwise.
|
|
43
|
+
*/
|
|
44
|
+
isPointInside: (point: {
|
|
45
|
+
x: number;
|
|
46
|
+
y: number;
|
|
47
|
+
}, targetElement?: Element) => boolean;
|
|
36
48
|
};
|
|
37
49
|
export declare const DrawingContext: React.Context<DrawingArea & {
|
|
38
50
|
/**
|
|
@@ -25,7 +25,8 @@ const DrawingContext = exports.DrawingContext = /*#__PURE__*/React.createContext
|
|
|
25
25
|
right: 0,
|
|
26
26
|
height: 300,
|
|
27
27
|
width: 400,
|
|
28
|
-
chartId: ''
|
|
28
|
+
chartId: '',
|
|
29
|
+
isPointInside: () => false
|
|
29
30
|
});
|
|
30
31
|
if (process.env.NODE_ENV !== 'production') {
|
|
31
32
|
DrawingContext.displayName = 'DrawingContext';
|
|
@@ -49,9 +50,21 @@ function DrawingProvider(props) {
|
|
|
49
50
|
} = props;
|
|
50
51
|
const drawingArea = (0, _useChartDimensions.default)(width, height, margin);
|
|
51
52
|
const chartId = (0, _useId.default)();
|
|
53
|
+
const isPointInside = React.useCallback(({
|
|
54
|
+
x,
|
|
55
|
+
y
|
|
56
|
+
}, targetElement) => {
|
|
57
|
+
// For element allowed to overflow, wrapping them in <g data-drawing-container /> make them fully part of the drawing area.
|
|
58
|
+
if (targetElement && targetElement.closest('[data-drawing-container]')) {
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
return x >= drawingArea.left && x <= drawingArea.left + drawingArea.width && y >= drawingArea.top && y <= drawingArea.top + drawingArea.height;
|
|
62
|
+
}, [drawingArea]);
|
|
52
63
|
const value = React.useMemo(() => (0, _extends2.default)({
|
|
53
64
|
chartId: chartId ?? ''
|
|
54
|
-
}, drawingArea
|
|
65
|
+
}, drawingArea, {
|
|
66
|
+
isPointInside
|
|
67
|
+
}), [chartId, drawingArea, isPointInside]);
|
|
55
68
|
const refValue = React.useMemo(() => ({
|
|
56
69
|
isInitialized: true,
|
|
57
70
|
data: svgRef
|
|
@@ -24,11 +24,11 @@ const mergeDeprecatedOptions = options => {
|
|
|
24
24
|
highlighted,
|
|
25
25
|
faded
|
|
26
26
|
} = _ref,
|
|
27
|
-
|
|
27
|
+
other = (0, _objectWithoutPropertiesLoose2.default)(_ref, _excluded);
|
|
28
28
|
return (0, _extends2.default)({
|
|
29
29
|
highlight: highlighted,
|
|
30
30
|
fade: faded
|
|
31
|
-
},
|
|
31
|
+
}, other);
|
|
32
32
|
};
|
|
33
33
|
function HighlightedProvider({
|
|
34
34
|
children,
|
|
@@ -44,7 +44,7 @@ const preprocessSeries = (series, colors, seriesFormatters, dataset) => {
|
|
|
44
44
|
};
|
|
45
45
|
}
|
|
46
46
|
if (seriesGroups[type]?.series[id] !== undefined) {
|
|
47
|
-
throw new Error(`MUI X
|
|
47
|
+
throw new Error(`MUI X: series' id "${id}" is not unique.`);
|
|
48
48
|
}
|
|
49
49
|
seriesGroups[type].series[id] = (0, _extends2.default)({
|
|
50
50
|
id
|
|
@@ -32,7 +32,7 @@ function ZAxisContextProvider(props) {
|
|
|
32
32
|
return axisConfig;
|
|
33
33
|
}
|
|
34
34
|
if (dataset === undefined) {
|
|
35
|
-
throw Error('MUI X
|
|
35
|
+
throw Error('MUI X: z-axis uses `dataKey` but no `dataset` is provided.');
|
|
36
36
|
}
|
|
37
37
|
return (0, _extends2.default)({}, axisConfig, {
|
|
38
38
|
data: dataset.map(d => d[dataKey])
|
package/esm/BarChart/BarChart.js
CHANGED
|
@@ -43,8 +43,8 @@ const BarChart = /*#__PURE__*/React.forwardRef(function BarChart(props, ref) {
|
|
|
43
43
|
ref: ref
|
|
44
44
|
}, chartContainerProps, {
|
|
45
45
|
children: [props.onAxisClick && /*#__PURE__*/_jsx(ChartsOnAxisClickHandler, _extends({}, axisClickHandlerProps)), props.grid && /*#__PURE__*/_jsx(ChartsGrid, _extends({}, gridProps)), /*#__PURE__*/_jsxs("g", _extends({}, clipPathGroupProps, {
|
|
46
|
-
children: [/*#__PURE__*/_jsx(BarPlot, _extends({}, barPlotProps)), /*#__PURE__*/_jsx(ChartsOverlay, _extends({}, overlayProps))]
|
|
47
|
-
})), /*#__PURE__*/_jsx(ChartsAxis, _extends({}, chartsAxisProps)), /*#__PURE__*/_jsx(ChartsLegend, _extends({}, legendProps)),
|
|
46
|
+
children: [/*#__PURE__*/_jsx(BarPlot, _extends({}, barPlotProps)), /*#__PURE__*/_jsx(ChartsOverlay, _extends({}, overlayProps)), /*#__PURE__*/_jsx(ChartsAxisHighlight, _extends({}, axisHighlightProps))]
|
|
47
|
+
})), /*#__PURE__*/_jsx(ChartsAxis, _extends({}, chartsAxisProps)), /*#__PURE__*/_jsx(ChartsLegend, _extends({}, legendProps)), !props.loading && /*#__PURE__*/_jsx(ChartsTooltip, _extends({}, tooltipProps)), /*#__PURE__*/_jsx(ChartsClipPath, _extends({}, clipPathProps)), children]
|
|
48
48
|
}));
|
|
49
49
|
});
|
|
50
50
|
process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
package/esm/BarChart/BarPlot.js
CHANGED
|
@@ -66,16 +66,16 @@ const useAggregatedData = () => {
|
|
|
66
66
|
ids: groupIds
|
|
67
67
|
}, groupIndex) => {
|
|
68
68
|
return groupIds.flatMap(seriesId => {
|
|
69
|
-
const
|
|
70
|
-
const
|
|
71
|
-
const xAxisConfig = xAxis[
|
|
72
|
-
const yAxisConfig = yAxis[
|
|
69
|
+
const xAxisId = series[seriesId].xAxisId ?? series[seriesId].xAxisKey ?? defaultXAxisId;
|
|
70
|
+
const yAxisId = series[seriesId].yAxisId ?? series[seriesId].yAxisKey ?? defaultYAxisId;
|
|
71
|
+
const xAxisConfig = xAxis[xAxisId];
|
|
72
|
+
const yAxisConfig = yAxis[yAxisId];
|
|
73
73
|
const verticalLayout = series[seriesId].layout === 'vertical';
|
|
74
|
-
checkScaleErrors(verticalLayout, seriesId,
|
|
74
|
+
checkScaleErrors(verticalLayout, seriesId, xAxisId, xAxis, yAxisId, yAxis);
|
|
75
75
|
const baseScaleConfig = verticalLayout ? xAxisConfig : yAxisConfig;
|
|
76
76
|
const xScale = xAxisConfig.scale;
|
|
77
77
|
const yScale = yAxisConfig.scale;
|
|
78
|
-
const colorGetter = getColor(series[seriesId], xAxis[
|
|
78
|
+
const colorGetter = getColor(series[seriesId], xAxis[xAxisId], yAxis[yAxisId]);
|
|
79
79
|
const bandWidth = baseScaleConfig.scale.bandwidth();
|
|
80
80
|
const {
|
|
81
81
|
barWidth,
|
|
@@ -98,8 +98,8 @@ const useAggregatedData = () => {
|
|
|
98
98
|
seriesId,
|
|
99
99
|
dataIndex,
|
|
100
100
|
layout: series[seriesId].layout,
|
|
101
|
-
x: verticalLayout ? xScale(xAxis[
|
|
102
|
-
y: verticalLayout ? minValueCoord : yScale(yAxis[
|
|
101
|
+
x: verticalLayout ? xScale(xAxis[xAxisId].data?.[dataIndex]) + barOffset : minValueCoord,
|
|
102
|
+
y: verticalLayout ? minValueCoord : yScale(yAxis[yAxisId].data?.[dataIndex]) + barOffset,
|
|
103
103
|
xOrigin: xScale(0),
|
|
104
104
|
yOrigin: yScale(0),
|
|
105
105
|
height: verticalLayout ? maxValueCoord - minValueCoord : barWidth,
|
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
import { DEFAULT_X_AXIS_KEY, DEFAULT_Y_AXIS_KEY } from '../constants';
|
|
2
2
|
import { isBandScaleConfig, isPointScaleConfig } from '../models/axis';
|
|
3
|
-
const getAxisMessage = (axisDirection,
|
|
3
|
+
const getAxisMessage = (axisDirection, axisId) => {
|
|
4
4
|
const axisName = `${axisDirection}-axis`;
|
|
5
|
-
const
|
|
5
|
+
const axisIdName = `${axisDirection}Axis`;
|
|
6
6
|
const axisDefaultKey = axisDirection === 'x' ? DEFAULT_X_AXIS_KEY : DEFAULT_Y_AXIS_KEY;
|
|
7
|
-
return
|
|
7
|
+
return axisId === axisDefaultKey ? `The first \`${axisIdName}\`` : `The ${axisName} with id "${axisId}"`;
|
|
8
8
|
};
|
|
9
|
-
export function checkScaleErrors(verticalLayout, seriesId,
|
|
10
|
-
const xAxisConfig = xAxis[
|
|
11
|
-
const yAxisConfig = yAxis[
|
|
9
|
+
export function checkScaleErrors(verticalLayout, seriesId, xAxisId, xAxis, yAxisId, yAxis) {
|
|
10
|
+
const xAxisConfig = xAxis[xAxisId];
|
|
11
|
+
const yAxisConfig = yAxis[yAxisId];
|
|
12
12
|
const discreteAxisConfig = verticalLayout ? xAxisConfig : yAxisConfig;
|
|
13
13
|
const continuousAxisConfig = verticalLayout ? yAxisConfig : xAxisConfig;
|
|
14
|
-
const
|
|
15
|
-
const
|
|
14
|
+
const discreteAxisId = verticalLayout ? xAxisId : yAxisId;
|
|
15
|
+
const continuousAxisId = verticalLayout ? yAxisId : xAxisId;
|
|
16
16
|
const discreteAxisDirection = verticalLayout ? 'x' : 'y';
|
|
17
17
|
const continuousAxisDirection = verticalLayout ? 'y' : 'x';
|
|
18
18
|
if (!isBandScaleConfig(discreteAxisConfig)) {
|
|
19
|
-
throw new Error(`MUI X
|
|
19
|
+
throw new Error(`MUI X: ${getAxisMessage(discreteAxisDirection, discreteAxisId)} should be of type "band" to display the bar series of id "${seriesId}".`);
|
|
20
20
|
}
|
|
21
21
|
if (discreteAxisConfig.data === undefined) {
|
|
22
|
-
throw new Error(`MUI X
|
|
22
|
+
throw new Error(`MUI X: ${getAxisMessage(discreteAxisDirection, discreteAxisId)} should have data property.`);
|
|
23
23
|
}
|
|
24
24
|
if (isBandScaleConfig(continuousAxisConfig) || isPointScaleConfig(continuousAxisConfig)) {
|
|
25
|
-
throw new Error(`MUI X
|
|
25
|
+
throw new Error(`MUI X: ${getAxisMessage(continuousAxisDirection, continuousAxisId)} should be a continuous type to display the bar series of id "${seriesId}".`);
|
|
26
26
|
}
|
|
27
27
|
}
|
|
@@ -12,7 +12,10 @@ const getValueExtremum = params => {
|
|
|
12
12
|
axis,
|
|
13
13
|
isDefaultAxis
|
|
14
14
|
} = params;
|
|
15
|
-
return Object.keys(series).filter(seriesId =>
|
|
15
|
+
return Object.keys(series).filter(seriesId => {
|
|
16
|
+
const yAxisId = series[seriesId].yAxisId ?? series[seriesId].yAxisKey;
|
|
17
|
+
return yAxisId === axis.id || isDefaultAxis && yAxisId === undefined;
|
|
18
|
+
}).reduce((acc, seriesId) => {
|
|
16
19
|
const [seriesMin, seriesMax] = series[seriesId].stackedData?.reduce((seriesAcc, values) => [Math.min(...values, ...(seriesAcc[0] === null ? [] : [seriesAcc[0]])), Math.max(...values, ...(seriesAcc[1] === null ? [] : [seriesAcc[1]]))], series[seriesId].stackedData[0]) ?? [null, null];
|
|
17
20
|
return [acc[0] === null ? seriesMin : Math.min(seriesMin, acc[0]), acc[1] === null ? seriesMax : Math.max(seriesMax, acc[1])];
|
|
18
21
|
}, [null, null]);
|
|
@@ -25,7 +25,7 @@ const formatter = (params, dataset) => {
|
|
|
25
25
|
}
|
|
26
26
|
});
|
|
27
27
|
} else if (dataset === undefined) {
|
|
28
|
-
throw new Error([`MUI X
|
|
28
|
+
throw new Error([`MUI X: bar series with id='${id}' has no data.`, 'Either provide a data property to the series or use the dataset prop.'].join('\n'));
|
|
29
29
|
}
|
|
30
30
|
});
|
|
31
31
|
const completedSeries = {};
|
|
@@ -52,7 +52,7 @@ const formatter = (params, dataset) => {
|
|
|
52
52
|
if (typeof value !== 'number') {
|
|
53
53
|
if (process.env.NODE_ENV !== 'production' && !warnOnce && value !== null) {
|
|
54
54
|
warnOnce = true;
|
|
55
|
-
console.error([`MUI
|
|
55
|
+
console.error([`MUI X charts: your dataset key "${dataKey}" is used for plotting bars, but contains nonnumerical elements.`, 'Bar plots only support numbers and null values.'].join('\n'));
|
|
56
56
|
}
|
|
57
57
|
return 0;
|
|
58
58
|
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
|
+
const _excluded = ["xAxis", "yAxis", "series", "width", "height", "margin", "colors", "dataset", "sx", "tooltip", "onAxisClick", "axisHighlight", "legend", "grid", "topAxis", "leftAxis", "rightAxis", "bottomAxis", "children", "slots", "slotProps", "skipAnimation", "loading", "layout", "onItemClick", "highlightedItem", "onHighlightChange", "borderRadius", "barLabel", "className"];
|
|
2
4
|
import useId from '@mui/utils/useId';
|
|
3
5
|
import { DEFAULT_X_AXIS_KEY, DEFAULT_Y_AXIS_KEY } from '../constants';
|
|
4
6
|
/**
|
|
@@ -10,36 +12,38 @@ import { DEFAULT_X_AXIS_KEY, DEFAULT_Y_AXIS_KEY } from '../constants';
|
|
|
10
12
|
*/
|
|
11
13
|
export const useBarChartProps = props => {
|
|
12
14
|
const {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
15
|
+
xAxis,
|
|
16
|
+
yAxis,
|
|
17
|
+
series,
|
|
18
|
+
width,
|
|
19
|
+
height,
|
|
20
|
+
margin,
|
|
21
|
+
colors,
|
|
22
|
+
dataset,
|
|
23
|
+
sx,
|
|
24
|
+
tooltip,
|
|
25
|
+
onAxisClick,
|
|
26
|
+
axisHighlight,
|
|
27
|
+
legend,
|
|
28
|
+
grid,
|
|
29
|
+
topAxis,
|
|
30
|
+
leftAxis,
|
|
31
|
+
rightAxis,
|
|
32
|
+
bottomAxis,
|
|
33
|
+
children,
|
|
34
|
+
slots,
|
|
35
|
+
slotProps,
|
|
36
|
+
skipAnimation,
|
|
37
|
+
loading,
|
|
38
|
+
layout,
|
|
39
|
+
onItemClick,
|
|
40
|
+
highlightedItem,
|
|
41
|
+
onHighlightChange,
|
|
42
|
+
borderRadius,
|
|
43
|
+
barLabel,
|
|
44
|
+
className
|
|
45
|
+
} = props,
|
|
46
|
+
rest = _objectWithoutPropertiesLoose(props, _excluded);
|
|
43
47
|
const id = useId();
|
|
44
48
|
const clipPathId = `${id}-clip-path`;
|
|
45
49
|
const hasHorizontalSeries = layout === 'horizontal' || layout === undefined && series.some(item => item.layout === 'horizontal');
|
|
@@ -49,7 +53,7 @@ export const useBarChartProps = props => {
|
|
|
49
53
|
length: Math.max(...series.map(s => (s.data ?? dataset ?? []).length))
|
|
50
54
|
}, (_, index) => index)
|
|
51
55
|
};
|
|
52
|
-
const chartContainerProps = {
|
|
56
|
+
const chartContainerProps = _extends({}, rest, {
|
|
53
57
|
series: series.map(s => _extends({
|
|
54
58
|
type: 'bar'
|
|
55
59
|
}, s, {
|
|
@@ -69,8 +73,9 @@ export const useBarChartProps = props => {
|
|
|
69
73
|
sx,
|
|
70
74
|
highlightedItem,
|
|
71
75
|
onHighlightChange,
|
|
72
|
-
disableAxisListener: tooltip?.trigger !== 'axis' && axisHighlight?.x === 'none' && axisHighlight?.y === 'none' && !onAxisClick
|
|
73
|
-
|
|
76
|
+
disableAxisListener: tooltip?.trigger !== 'axis' && axisHighlight?.x === 'none' && axisHighlight?.y === 'none' && !onAxisClick,
|
|
77
|
+
className
|
|
78
|
+
});
|
|
74
79
|
const barPlotProps = {
|
|
75
80
|
onItemClick,
|
|
76
81
|
slots,
|