@mui/x-charts 7.7.0 → 7.8.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/BarChart.js +21 -104
- package/BarChart/BarElement.d.ts +225 -228
- package/BarChart/BarLabel/BarLabel.d.ts +225 -228
- package/BarChart/BarLabel/BarLabelPlot.d.ts +0 -3
- package/BarChart/BarLabel/BarLabelPlot.js +1 -24
- package/BarChart/BarLabel/getBarLabel.d.ts +1 -1
- package/BarChart/BarPlot.js +2 -2
- package/BarChart/checkScaleErrors.d.ts +5 -9
- package/BarChart/types.d.ts +2 -2
- package/BarChart/useBarChartProps.d.ts +34 -0
- package/BarChart/useBarChartProps.js +143 -0
- package/CHANGELOG.md +181 -0
- package/ChartContainer/ChartContainer.d.ts +2 -2
- package/ChartContainer/ChartContainer.js +6 -10
- package/ChartContainer/useChartContainerHooks.d.ts +11 -0
- package/ChartContainer/useChartContainerHooks.js +34 -0
- package/ChartContainer/usePluginsMerge.d.ts +1 -2
- package/ChartsAxis/ChartsAxis.js +2 -2
- package/ChartsAxisHighlight/ChartsAxisHighlight.js +21 -6
- package/ChartsGrid/ChartsGrid.js +2 -2
- package/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +2 -2
- package/ChartsReferenceLine/common.d.ts +0 -1
- package/ChartsTooltip/ChartsAxisTooltipContent.js +2 -2
- package/ChartsTooltip/ChartsItemTooltipContent.js +2 -2
- package/ChartsTooltip/ChartsTooltipTable.d.ts +0 -1
- package/ChartsVoronoiHandler/ChartsVoronoiHandler.js +4 -4
- package/ChartsXAxis/ChartsXAxis.js +2 -2
- package/ChartsYAxis/ChartsYAxis.js +5 -3
- package/Gauge/GaugeProvider.d.ts +1 -1
- package/LineChart/AnimatedArea.d.ts +225 -228
- package/LineChart/AnimatedLine.d.ts +225 -228
- package/LineChart/AreaPlot.js +2 -2
- package/LineChart/LineChart.js +24 -106
- package/LineChart/LineHighlightPlot.js +2 -2
- package/LineChart/LinePlot.js +2 -2
- package/LineChart/MarkPlot.js +2 -2
- package/LineChart/useLineChartProps.d.ts +40 -0
- package/LineChart/useLineChartProps.js +152 -0
- package/PieChart/PieArc.d.ts +0 -1
- package/PieChart/PieArcLabel.d.ts +0 -1
- package/PieChart/dataTransform/transition.d.ts +0 -1
- package/ResponsiveChartContainer/ResizableContainer.d.ts +1 -2
- package/ScatterChart/ScatterChart.js +20 -75
- package/ScatterChart/ScatterPlot.js +2 -2
- package/ScatterChart/useScatterChartProps.d.ts +31 -0
- package/ScatterChart/useScatterChartProps.js +116 -0
- package/context/CartesianProvider/CartesianContext.d.ts +25 -0
- package/context/CartesianProvider/CartesianContext.js +21 -0
- package/context/CartesianProvider/CartesianProvider.d.ts +34 -0
- package/context/CartesianProvider/CartesianProvider.js +44 -0
- package/context/CartesianProvider/computeValue.d.ts +19 -0
- package/context/CartesianProvider/computeValue.js +104 -0
- package/context/CartesianProvider/getAxisExtremum.d.ts +4 -0
- package/context/CartesianProvider/getAxisExtremum.js +28 -0
- package/context/CartesianProvider/index.d.ts +9 -0
- package/context/CartesianProvider/index.js +51 -0
- package/context/CartesianProvider/normalizeAxis.d.ts +5 -0
- package/context/CartesianProvider/normalizeAxis.js +23 -0
- package/context/CartesianProvider/useCartesianContext.d.ts +2 -0
- package/context/CartesianProvider/useCartesianContext.js +17 -0
- package/context/ColorProvider.d.ts +2 -2
- package/esm/BarChart/BarChart.js +21 -104
- package/esm/BarChart/BarLabel/BarLabelPlot.js +0 -23
- package/esm/BarChart/BarPlot.js +2 -2
- package/esm/BarChart/useBarChartProps.js +135 -0
- package/esm/ChartContainer/ChartContainer.js +5 -9
- package/esm/ChartContainer/useChartContainerHooks.js +24 -0
- package/esm/ChartsAxis/ChartsAxis.js +2 -2
- package/esm/ChartsAxisHighlight/ChartsAxisHighlight.js +21 -6
- package/esm/ChartsGrid/ChartsGrid.js +2 -2
- package/esm/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +2 -2
- package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +2 -2
- package/esm/ChartsTooltip/ChartsItemTooltipContent.js +2 -2
- package/esm/ChartsVoronoiHandler/ChartsVoronoiHandler.js +3 -3
- package/esm/ChartsXAxis/ChartsXAxis.js +2 -2
- package/esm/ChartsYAxis/ChartsYAxis.js +5 -3
- package/esm/LineChart/AreaPlot.js +2 -2
- package/esm/LineChart/LineChart.js +24 -106
- package/esm/LineChart/LineHighlightPlot.js +2 -2
- package/esm/LineChart/LinePlot.js +2 -2
- package/esm/LineChart/MarkPlot.js +2 -2
- package/esm/LineChart/useLineChartProps.js +144 -0
- package/esm/ScatterChart/ScatterChart.js +20 -75
- package/esm/ScatterChart/ScatterPlot.js +2 -2
- package/esm/ScatterChart/useScatterChartProps.js +108 -0
- package/esm/context/CartesianProvider/CartesianContext.js +13 -0
- package/esm/context/CartesianProvider/CartesianProvider.js +37 -0
- package/esm/context/CartesianProvider/computeValue.js +97 -0
- package/esm/context/CartesianProvider/getAxisExtremum.js +21 -0
- package/esm/context/CartesianProvider/index.js +10 -0
- package/esm/context/CartesianProvider/normalizeAxis.js +15 -0
- package/esm/context/CartesianProvider/useCartesianContext.js +8 -0
- package/esm/hooks/useAxisEvents.js +7 -10
- package/esm/hooks/useColorScale.js +3 -3
- package/esm/hooks/useScale.js +4 -5
- package/esm/hooks/useTicks.js +2 -1
- package/esm/internals/components/ChartsAxesGradients/ChartsAxesGradients.js +2 -2
- package/esm/internals/getSVGPoint.js +11 -0
- package/esm/internals/index.js +8 -2
- package/esm/internals/utils.js +0 -12
- package/hooks/useAxisEvents.js +8 -11
- package/hooks/useChartDimensions.d.ts +1 -1
- package/hooks/useColor.d.ts +1 -1
- package/hooks/useColorScale.js +3 -3
- package/hooks/useDrawingArea.d.ts +2 -8
- package/hooks/useScale.js +4 -7
- package/hooks/useTicks.js +2 -1
- package/index.js +1 -1
- package/internals/components/AxisSharedComponents.d.ts +0 -1
- package/internals/components/ChartsAxesGradients/ChartsAxesGradients.d.ts +2 -1
- package/internals/components/ChartsAxesGradients/ChartsAxesGradients.js +2 -2
- package/internals/defaultizeColor.d.ts +68 -68
- package/internals/getSVGPoint.d.ts +6 -0
- package/internals/getSVGPoint.js +17 -0
- package/internals/getWordsByLines.d.ts +0 -1
- package/internals/index.d.ts +9 -1
- package/internals/index.js +69 -5
- package/internals/useAnimatedPath.d.ts +0 -1
- package/internals/utils.d.ts +0 -6
- package/internals/utils.js +0 -13
- package/models/axis.d.ts +1 -2
- package/models/plugin.d.ts +4 -1
- package/modern/BarChart/BarChart.js +21 -104
- package/modern/BarChart/BarLabel/BarLabelPlot.js +0 -23
- package/modern/BarChart/BarPlot.js +2 -2
- package/modern/BarChart/useBarChartProps.js +135 -0
- package/modern/ChartContainer/ChartContainer.js +5 -9
- package/modern/ChartContainer/useChartContainerHooks.js +24 -0
- package/modern/ChartsAxis/ChartsAxis.js +2 -2
- package/modern/ChartsAxisHighlight/ChartsAxisHighlight.js +21 -6
- package/modern/ChartsGrid/ChartsGrid.js +2 -2
- package/modern/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +2 -2
- package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +2 -2
- package/modern/ChartsTooltip/ChartsItemTooltipContent.js +2 -2
- package/modern/ChartsVoronoiHandler/ChartsVoronoiHandler.js +3 -3
- package/modern/ChartsXAxis/ChartsXAxis.js +2 -2
- package/modern/ChartsYAxis/ChartsYAxis.js +5 -3
- package/modern/LineChart/AreaPlot.js +2 -2
- package/modern/LineChart/LineChart.js +24 -106
- package/modern/LineChart/LineHighlightPlot.js +2 -2
- package/modern/LineChart/LinePlot.js +2 -2
- package/modern/LineChart/MarkPlot.js +2 -2
- package/modern/LineChart/useLineChartProps.js +144 -0
- package/modern/ScatterChart/ScatterChart.js +20 -75
- package/modern/ScatterChart/ScatterPlot.js +2 -2
- package/modern/ScatterChart/useScatterChartProps.js +108 -0
- package/modern/context/CartesianProvider/CartesianContext.js +13 -0
- package/modern/context/CartesianProvider/CartesianProvider.js +37 -0
- package/modern/context/CartesianProvider/computeValue.js +97 -0
- package/modern/context/CartesianProvider/getAxisExtremum.js +21 -0
- package/modern/context/CartesianProvider/index.js +10 -0
- package/modern/context/CartesianProvider/normalizeAxis.js +15 -0
- package/modern/context/CartesianProvider/useCartesianContext.js +8 -0
- package/modern/hooks/useAxisEvents.js +7 -10
- package/modern/hooks/useColorScale.js +3 -3
- package/modern/hooks/useScale.js +4 -5
- package/modern/hooks/useTicks.js +2 -1
- package/modern/index.js +1 -1
- package/modern/internals/components/ChartsAxesGradients/ChartsAxesGradients.js +2 -2
- package/modern/internals/getSVGPoint.js +11 -0
- package/modern/internals/index.js +8 -2
- package/modern/internals/utils.js +0 -12
- package/package.json +3 -3
- package/context/CartesianContextProvider.d.ts +0 -61
- package/context/CartesianContextProvider.js +0 -220
- package/esm/context/CartesianContextProvider.js +0 -211
- package/modern/context/CartesianContextProvider.js +0 -211
package/modern/hooks/useScale.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { CartesianContext } from '../context/CartesianContextProvider';
|
|
1
|
+
import { useCartesianContext } from '../context/CartesianProvider';
|
|
3
2
|
import { isBandScale } from '../internals/isBandScale';
|
|
4
3
|
/**
|
|
5
4
|
* For a given scale return a function that map value to their position.
|
|
@@ -9,7 +8,7 @@ import { isBandScale } from '../internals/isBandScale';
|
|
|
9
8
|
*/
|
|
10
9
|
export function getValueToPositionMapper(scale) {
|
|
11
10
|
if (isBandScale(scale)) {
|
|
12
|
-
return value => scale(value) + scale.bandwidth() / 2;
|
|
11
|
+
return value => (scale(value) ?? 0) + scale.bandwidth() / 2;
|
|
13
12
|
}
|
|
14
13
|
return value => scale(value);
|
|
15
14
|
}
|
|
@@ -17,7 +16,7 @@ export function useXScale(identifier) {
|
|
|
17
16
|
const {
|
|
18
17
|
xAxis,
|
|
19
18
|
xAxisIds
|
|
20
|
-
} =
|
|
19
|
+
} = useCartesianContext();
|
|
21
20
|
const id = typeof identifier === 'string' ? identifier : xAxisIds[identifier ?? 0];
|
|
22
21
|
return xAxis[id].scale;
|
|
23
22
|
}
|
|
@@ -25,7 +24,7 @@ export function useYScale(identifier) {
|
|
|
25
24
|
const {
|
|
26
25
|
yAxis,
|
|
27
26
|
yAxisIds
|
|
28
|
-
} =
|
|
27
|
+
} = useCartesianContext();
|
|
29
28
|
const id = typeof identifier === 'string' ? identifier : yAxisIds[identifier ?? 0];
|
|
30
29
|
return yAxis[id].scale;
|
|
31
30
|
}
|
package/modern/hooks/useTicks.js
CHANGED
|
@@ -34,7 +34,8 @@ export function useTicks(options) {
|
|
|
34
34
|
const domain = scale.domain();
|
|
35
35
|
if (scale.bandwidth() > 0) {
|
|
36
36
|
// scale type = 'band'
|
|
37
|
-
|
|
37
|
+
const filteredDomain = typeof tickInterval === 'function' && domain.filter(tickInterval) || typeof tickInterval === 'object' && tickInterval || domain;
|
|
38
|
+
return [...filteredDomain.map(value => ({
|
|
38
39
|
value,
|
|
39
40
|
formattedValue: valueFormatter?.(value, {
|
|
40
41
|
location: 'tick'
|
package/modern/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { useCartesianContext } from '../../../context/CartesianProvider';
|
|
3
3
|
import { DrawingContext } from '../../../context/DrawingProvider';
|
|
4
4
|
import { useDrawingArea } from '../../../hooks';
|
|
5
5
|
import ChartsPiecewiseGradient from './ChartsPiecewiseGradient';
|
|
@@ -28,7 +28,7 @@ export function ChartsAxesGradients() {
|
|
|
28
28
|
xAxis,
|
|
29
29
|
yAxisIds,
|
|
30
30
|
yAxis
|
|
31
|
-
} =
|
|
31
|
+
} = useCartesianContext();
|
|
32
32
|
return /*#__PURE__*/_jsxs("defs", {
|
|
33
33
|
children: [yAxisIds.filter(axisId => yAxis[axisId].colorMap !== undefined).map(axisId => {
|
|
34
34
|
const gradientId = getGradientId(axisId, 'y');
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transform mouse event position to coordinates inside the SVG.
|
|
3
|
+
* @param svg The SVG element
|
|
4
|
+
* @param event The mouseEvent to transform
|
|
5
|
+
*/
|
|
6
|
+
export function getSVGPoint(svg, event) {
|
|
7
|
+
const pt = svg.createSVGPoint();
|
|
8
|
+
pt.x = event.clientX;
|
|
9
|
+
pt.y = event.clientY;
|
|
10
|
+
return pt.matrixTransform(svg.getScreenCTM().inverse());
|
|
11
|
+
}
|
|
@@ -6,19 +6,25 @@ export * from '../ResponsiveChartContainer/ResizableContainer';
|
|
|
6
6
|
// hooks
|
|
7
7
|
export { useReducedMotion } from '../hooks/useReducedMotion';
|
|
8
8
|
export { useSeries } from '../hooks/useSeries';
|
|
9
|
+
export { useDrawingArea } from '../hooks/useDrawingArea';
|
|
10
|
+
export { useChartContainerHooks } from '../ChartContainer/useChartContainerHooks';
|
|
11
|
+
export { useScatterChartProps } from '../ScatterChart/useScatterChartProps';
|
|
12
|
+
export { useLineChartProps } from '../LineChart/useLineChartProps';
|
|
13
|
+
export { useBarChartProps } from '../BarChart/useBarChartProps';
|
|
9
14
|
|
|
10
15
|
// utils
|
|
11
16
|
export * from './defaultizeValueFormatter';
|
|
12
17
|
export * from './configInit';
|
|
18
|
+
export * from './getSVGPoint';
|
|
13
19
|
|
|
14
20
|
// contexts
|
|
15
21
|
|
|
16
|
-
export * from '../context/
|
|
22
|
+
export * from '../context/CartesianProvider';
|
|
17
23
|
export * from '../context/DrawingProvider';
|
|
24
|
+
export * from '../context/ColorProvider';
|
|
18
25
|
export * from '../context/InteractionProvider';
|
|
19
26
|
export * from '../context/SeriesContextProvider';
|
|
20
27
|
export * from '../context/ZAxisContextProvider';
|
|
21
|
-
|
|
22
28
|
// series configuration
|
|
23
29
|
export * from '../models/seriesType/config';
|
|
24
30
|
export * from '../models/seriesType/common';
|
|
@@ -3,18 +3,6 @@ export function getSymbol(shape) {
|
|
|
3
3
|
const symbolNames = 'circle cross diamond square star triangle wye'.split(/ /);
|
|
4
4
|
return symbolNames.indexOf(shape) || 0;
|
|
5
5
|
}
|
|
6
|
-
/**
|
|
7
|
-
* Transform mouse event position to coordinates inside the SVG.
|
|
8
|
-
* @param svg The SVG element
|
|
9
|
-
* @param event The mouseEvent to transform
|
|
10
|
-
*/
|
|
11
|
-
export function getSVGPoint(svg, event) {
|
|
12
|
-
const pt = svg.createSVGPoint();
|
|
13
|
-
pt.x = event.clientX;
|
|
14
|
-
pt.y = event.clientY;
|
|
15
|
-
return pt.matrixTransform(svg.getScreenCTM().inverse());
|
|
16
|
-
}
|
|
17
|
-
|
|
18
6
|
/**
|
|
19
7
|
* Helper that converts values and percentages into values.
|
|
20
8
|
* @param value The value provided by the developer. Can either be a number or a string with '%' or 'px'.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mui/x-charts",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.8.0",
|
|
4
4
|
"description": "The community edition of the Charts components (MUI X).",
|
|
5
5
|
"author": "MUI Team",
|
|
6
6
|
"main": "./index.js",
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@babel/runtime": "^7.24.7",
|
|
33
33
|
"@mui/base": "^5.0.0-beta.40",
|
|
34
|
-
"@mui/system": "^5.15.
|
|
35
|
-
"@mui/utils": "^5.15.
|
|
34
|
+
"@mui/system": "^5.15.20",
|
|
35
|
+
"@mui/utils": "^5.15.20",
|
|
36
36
|
"@react-spring/rafz": "^9.7.3",
|
|
37
37
|
"@react-spring/web": "^9.7.3",
|
|
38
38
|
"clsx": "^2.1.1",
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { AxisConfig, AxisDefaultized, ChartsXAxisProps, ChartsYAxisProps, ScaleName } from '../models/axis';
|
|
3
|
-
import { CartesianChartSeriesType, ChartSeriesType, DatasetType, ExtremumGetter } from '../models/seriesType/config';
|
|
4
|
-
import { MakeOptional } from '../models/helpers';
|
|
5
|
-
export type ExtremumGettersConfig<T extends ChartSeriesType = CartesianChartSeriesType> = {
|
|
6
|
-
[K in T]?: ExtremumGetter<K>;
|
|
7
|
-
};
|
|
8
|
-
export type CartesianContextProviderProps = {
|
|
9
|
-
/**
|
|
10
|
-
* The configuration of the x-axes.
|
|
11
|
-
* If not provided, a default axis config is used.
|
|
12
|
-
* An array of [[AxisConfig]] objects.
|
|
13
|
-
*/
|
|
14
|
-
xAxis?: MakeOptional<AxisConfig<ScaleName, any, ChartsXAxisProps>, 'id'>[];
|
|
15
|
-
/**
|
|
16
|
-
* The configuration of the y-axes.
|
|
17
|
-
* If not provided, a default axis config is used.
|
|
18
|
-
* An array of [[AxisConfig]] objects.
|
|
19
|
-
*/
|
|
20
|
-
yAxis?: MakeOptional<AxisConfig<ScaleName, any, ChartsYAxisProps>, 'id'>[];
|
|
21
|
-
/**
|
|
22
|
-
* An array of objects that can be used to populate series and axes data using their `dataKey` property.
|
|
23
|
-
*/
|
|
24
|
-
dataset?: DatasetType;
|
|
25
|
-
/**
|
|
26
|
-
* An object with x-axis extremum getters per series type.
|
|
27
|
-
*/
|
|
28
|
-
xExtremumGetters: ExtremumGettersConfig;
|
|
29
|
-
/**
|
|
30
|
-
* An object with y-axis extremum getters per series type.
|
|
31
|
-
*/
|
|
32
|
-
yExtremumGetters: ExtremumGettersConfig;
|
|
33
|
-
children: React.ReactNode;
|
|
34
|
-
};
|
|
35
|
-
type DefaultizedAxisConfig<AxisProps> = {
|
|
36
|
-
[axisKey: string]: AxisDefaultized<ScaleName, any, AxisProps>;
|
|
37
|
-
};
|
|
38
|
-
export declare const CartesianContext: React.Context<{
|
|
39
|
-
/**
|
|
40
|
-
* Mapping from x-axis key to scaling configuration.
|
|
41
|
-
*/
|
|
42
|
-
xAxis: {
|
|
43
|
-
DEFAULT_X_AXIS_KEY: AxisDefaultized<ScaleName, any, ChartsXAxisProps>;
|
|
44
|
-
} & DefaultizedAxisConfig<ChartsXAxisProps>;
|
|
45
|
-
/**
|
|
46
|
-
* Mapping from y-axis key to scaling configuration.
|
|
47
|
-
*/
|
|
48
|
-
yAxis: {
|
|
49
|
-
DEFAULT_X_AXIS_KEY: AxisDefaultized<ScaleName, any, ChartsYAxisProps>;
|
|
50
|
-
} & DefaultizedAxisConfig<ChartsYAxisProps>;
|
|
51
|
-
/**
|
|
52
|
-
* The x-axes IDs sorted by order they got provided.
|
|
53
|
-
*/
|
|
54
|
-
xAxisIds: string[];
|
|
55
|
-
/**
|
|
56
|
-
* The y-axes IDs sorted by order they got provided.
|
|
57
|
-
*/
|
|
58
|
-
yAxisIds: string[];
|
|
59
|
-
}>;
|
|
60
|
-
declare function CartesianContextProvider(props: CartesianContextProviderProps): React.JSX.Element;
|
|
61
|
-
export { CartesianContextProvider };
|
|
@@ -1,220 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.CartesianContext = void 0;
|
|
8
|
-
exports.CartesianContextProvider = CartesianContextProvider;
|
|
9
|
-
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
10
|
-
var React = _interopRequireWildcard(require("react"));
|
|
11
|
-
var _d3Scale = require("d3-scale");
|
|
12
|
-
var _axis = require("../models/axis");
|
|
13
|
-
var _getScale = require("../internals/getScale");
|
|
14
|
-
var _constants = require("../constants");
|
|
15
|
-
var _useTicks = require("../hooks/useTicks");
|
|
16
|
-
var _useDrawingArea = require("../hooks/useDrawingArea");
|
|
17
|
-
var _colorScale = require("../internals/colorScale");
|
|
18
|
-
var _useSeries = require("../hooks/useSeries");
|
|
19
|
-
var _jsxRuntime = require("react/jsx-runtime");
|
|
20
|
-
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); }
|
|
21
|
-
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; }
|
|
22
|
-
const DEFAULT_CATEGORY_GAP_RATIO = 0.2;
|
|
23
|
-
const DEFAULT_BAR_GAP_RATIO = 0.1;
|
|
24
|
-
const CartesianContext = exports.CartesianContext = /*#__PURE__*/React.createContext({
|
|
25
|
-
xAxis: {},
|
|
26
|
-
yAxis: {},
|
|
27
|
-
xAxisIds: [],
|
|
28
|
-
yAxisIds: []
|
|
29
|
-
});
|
|
30
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
31
|
-
CartesianContext.displayName = 'CartesianContext';
|
|
32
|
-
}
|
|
33
|
-
function CartesianContextProvider(props) {
|
|
34
|
-
const {
|
|
35
|
-
xAxis: inXAxis,
|
|
36
|
-
yAxis: inYAxis,
|
|
37
|
-
dataset,
|
|
38
|
-
xExtremumGetters,
|
|
39
|
-
yExtremumGetters,
|
|
40
|
-
children
|
|
41
|
-
} = props;
|
|
42
|
-
const formattedSeries = (0, _useSeries.useSeries)();
|
|
43
|
-
const drawingArea = (0, _useDrawingArea.useDrawingArea)();
|
|
44
|
-
const xAxis = React.useMemo(() => inXAxis?.map(axisConfig => {
|
|
45
|
-
const dataKey = axisConfig.dataKey;
|
|
46
|
-
if (dataKey === undefined || axisConfig.data !== undefined) {
|
|
47
|
-
return axisConfig;
|
|
48
|
-
}
|
|
49
|
-
if (dataset === undefined) {
|
|
50
|
-
throw Error('MUI X Charts: x-axis uses `dataKey` but no `dataset` is provided.');
|
|
51
|
-
}
|
|
52
|
-
return (0, _extends2.default)({}, axisConfig, {
|
|
53
|
-
data: dataset.map(d => d[dataKey])
|
|
54
|
-
});
|
|
55
|
-
}), [inXAxis, dataset]);
|
|
56
|
-
const yAxis = React.useMemo(() => inYAxis?.map(axisConfig => {
|
|
57
|
-
const dataKey = axisConfig.dataKey;
|
|
58
|
-
if (dataKey === undefined || axisConfig.data !== undefined) {
|
|
59
|
-
return axisConfig;
|
|
60
|
-
}
|
|
61
|
-
if (dataset === undefined) {
|
|
62
|
-
throw Error('MUI X Charts: y-axis uses `dataKey` but no `dataset` is provided.');
|
|
63
|
-
}
|
|
64
|
-
return (0, _extends2.default)({}, axisConfig, {
|
|
65
|
-
data: dataset.map(d => d[dataKey])
|
|
66
|
-
});
|
|
67
|
-
}), [inYAxis, dataset]);
|
|
68
|
-
const value = React.useMemo(() => {
|
|
69
|
-
const axisExtremumCallback = (acc, chartType, axis, getters, isDefaultAxis) => {
|
|
70
|
-
const getter = getters[chartType];
|
|
71
|
-
const series = formattedSeries[chartType]?.series ?? {};
|
|
72
|
-
const [minChartTypeData, maxChartTypeData] = getter?.({
|
|
73
|
-
series,
|
|
74
|
-
axis,
|
|
75
|
-
isDefaultAxis
|
|
76
|
-
}) ?? [null, null];
|
|
77
|
-
const [minData, maxData] = acc;
|
|
78
|
-
if (minData === null || maxData === null) {
|
|
79
|
-
return [minChartTypeData, maxChartTypeData];
|
|
80
|
-
}
|
|
81
|
-
if (minChartTypeData === null || maxChartTypeData === null) {
|
|
82
|
-
return [minData, maxData];
|
|
83
|
-
}
|
|
84
|
-
return [Math.min(minChartTypeData, minData), Math.max(maxChartTypeData, maxData)];
|
|
85
|
-
};
|
|
86
|
-
const getAxisExtremum = (axis, getters, isDefaultAxis) => {
|
|
87
|
-
const charTypes = Object.keys(getters);
|
|
88
|
-
return charTypes.reduce((acc, charType) => axisExtremumCallback(acc, charType, axis, getters, isDefaultAxis), [null, null]);
|
|
89
|
-
};
|
|
90
|
-
const allXAxis = [...(xAxis?.map((axis, index) => (0, _extends2.default)({
|
|
91
|
-
id: `defaultized-x-axis-${index}`
|
|
92
|
-
}, axis)) ?? []),
|
|
93
|
-
// Allows to specify an axis with id=DEFAULT_X_AXIS_KEY
|
|
94
|
-
...(xAxis === undefined || xAxis.findIndex(({
|
|
95
|
-
id
|
|
96
|
-
}) => id === _constants.DEFAULT_X_AXIS_KEY) === -1 ? [{
|
|
97
|
-
id: _constants.DEFAULT_X_AXIS_KEY,
|
|
98
|
-
scaleType: 'linear'
|
|
99
|
-
}] : [])];
|
|
100
|
-
const completedXAxis = {};
|
|
101
|
-
allXAxis.forEach((axis, axisIndex) => {
|
|
102
|
-
const isDefaultAxis = axisIndex === 0;
|
|
103
|
-
const [minData, maxData] = getAxisExtremum(axis, xExtremumGetters, isDefaultAxis);
|
|
104
|
-
const range = axis.reverse ? [drawingArea.left + drawingArea.width, drawingArea.left] : [drawingArea.left, drawingArea.left + drawingArea.width];
|
|
105
|
-
if ((0, _axis.isBandScaleConfig)(axis)) {
|
|
106
|
-
const categoryGapRatio = axis.categoryGapRatio ?? DEFAULT_CATEGORY_GAP_RATIO;
|
|
107
|
-
const barGapRatio = axis.barGapRatio ?? DEFAULT_BAR_GAP_RATIO;
|
|
108
|
-
completedXAxis[axis.id] = (0, _extends2.default)({
|
|
109
|
-
categoryGapRatio,
|
|
110
|
-
barGapRatio
|
|
111
|
-
}, axis, {
|
|
112
|
-
scale: (0, _d3Scale.scaleBand)(axis.data, range).paddingInner(categoryGapRatio).paddingOuter(categoryGapRatio / 2),
|
|
113
|
-
tickNumber: axis.data.length,
|
|
114
|
-
colorScale: axis.colorMap && (axis.colorMap.type === 'ordinal' ? (0, _colorScale.getOrdinalColorScale)((0, _extends2.default)({
|
|
115
|
-
values: axis.data
|
|
116
|
-
}, axis.colorMap)) : (0, _colorScale.getColorScale)(axis.colorMap))
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
if ((0, _axis.isPointScaleConfig)(axis)) {
|
|
120
|
-
completedXAxis[axis.id] = (0, _extends2.default)({}, axis, {
|
|
121
|
-
scale: (0, _d3Scale.scalePoint)(axis.data, range),
|
|
122
|
-
tickNumber: axis.data.length,
|
|
123
|
-
colorScale: axis.colorMap && (axis.colorMap.type === 'ordinal' ? (0, _colorScale.getOrdinalColorScale)((0, _extends2.default)({
|
|
124
|
-
values: axis.data
|
|
125
|
-
}, axis.colorMap)) : (0, _colorScale.getColorScale)(axis.colorMap))
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
if (axis.scaleType === 'band' || axis.scaleType === 'point') {
|
|
129
|
-
// Could be merged with the two previous "if conditions" but then TS does not get that `axis.scaleType` can't be `band` or `point`.
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
const scaleType = axis.scaleType ?? 'linear';
|
|
133
|
-
const extremums = [axis.min ?? minData, axis.max ?? maxData];
|
|
134
|
-
const tickNumber = (0, _useTicks.getTickNumber)((0, _extends2.default)({}, axis, {
|
|
135
|
-
range,
|
|
136
|
-
domain: extremums
|
|
137
|
-
}));
|
|
138
|
-
const niceScale = (0, _getScale.getScale)(scaleType, extremums, range).nice(tickNumber);
|
|
139
|
-
const niceDomain = niceScale.domain();
|
|
140
|
-
const domain = [axis.min ?? niceDomain[0], axis.max ?? niceDomain[1]];
|
|
141
|
-
completedXAxis[axis.id] = (0, _extends2.default)({}, axis, {
|
|
142
|
-
scaleType,
|
|
143
|
-
scale: niceScale.domain(domain),
|
|
144
|
-
tickNumber,
|
|
145
|
-
colorScale: axis.colorMap && (0, _colorScale.getColorScale)(axis.colorMap)
|
|
146
|
-
});
|
|
147
|
-
});
|
|
148
|
-
const allYAxis = [...(yAxis?.map((axis, index) => (0, _extends2.default)({
|
|
149
|
-
id: `defaultized-y-axis-${index}`
|
|
150
|
-
}, axis)) ?? []), ...(yAxis === undefined || yAxis.findIndex(({
|
|
151
|
-
id
|
|
152
|
-
}) => id === _constants.DEFAULT_Y_AXIS_KEY) === -1 ? [{
|
|
153
|
-
id: _constants.DEFAULT_Y_AXIS_KEY,
|
|
154
|
-
scaleType: 'linear'
|
|
155
|
-
}] : [])];
|
|
156
|
-
const completedYAxis = {};
|
|
157
|
-
allYAxis.forEach((axis, axisIndex) => {
|
|
158
|
-
const isDefaultAxis = axisIndex === 0;
|
|
159
|
-
const [minData, maxData] = getAxisExtremum(axis, yExtremumGetters, isDefaultAxis);
|
|
160
|
-
const range = axis.reverse ? [drawingArea.top, drawingArea.top + drawingArea.height] : [drawingArea.top + drawingArea.height, drawingArea.top];
|
|
161
|
-
if ((0, _axis.isBandScaleConfig)(axis)) {
|
|
162
|
-
const categoryGapRatio = axis.categoryGapRatio ?? DEFAULT_CATEGORY_GAP_RATIO;
|
|
163
|
-
completedYAxis[axis.id] = (0, _extends2.default)({
|
|
164
|
-
categoryGapRatio,
|
|
165
|
-
barGapRatio: 0
|
|
166
|
-
}, axis, {
|
|
167
|
-
scale: (0, _d3Scale.scaleBand)(axis.data, [range[1], range[0]]).paddingInner(categoryGapRatio).paddingOuter(categoryGapRatio / 2),
|
|
168
|
-
tickNumber: axis.data.length,
|
|
169
|
-
colorScale: axis.colorMap && (axis.colorMap.type === 'ordinal' ? (0, _colorScale.getOrdinalColorScale)((0, _extends2.default)({
|
|
170
|
-
values: axis.data
|
|
171
|
-
}, axis.colorMap)) : (0, _colorScale.getColorScale)(axis.colorMap))
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
if ((0, _axis.isPointScaleConfig)(axis)) {
|
|
175
|
-
completedYAxis[axis.id] = (0, _extends2.default)({}, axis, {
|
|
176
|
-
scale: (0, _d3Scale.scalePoint)(axis.data, [range[1], range[0]]),
|
|
177
|
-
tickNumber: axis.data.length,
|
|
178
|
-
colorScale: axis.colorMap && (axis.colorMap.type === 'ordinal' ? (0, _colorScale.getOrdinalColorScale)((0, _extends2.default)({
|
|
179
|
-
values: axis.data
|
|
180
|
-
}, axis.colorMap)) : (0, _colorScale.getColorScale)(axis.colorMap))
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
if (axis.scaleType === 'band' || axis.scaleType === 'point') {
|
|
184
|
-
// Could be merged with the two previous "if conditions" but then TS does not get that `axis.scaleType` can't be `band` or `point`.
|
|
185
|
-
return;
|
|
186
|
-
}
|
|
187
|
-
const scaleType = axis.scaleType ?? 'linear';
|
|
188
|
-
const extremums = [axis.min ?? minData, axis.max ?? maxData];
|
|
189
|
-
const tickNumber = (0, _useTicks.getTickNumber)((0, _extends2.default)({}, axis, {
|
|
190
|
-
range,
|
|
191
|
-
domain: extremums
|
|
192
|
-
}));
|
|
193
|
-
const niceScale = (0, _getScale.getScale)(scaleType, extremums, range).nice(tickNumber);
|
|
194
|
-
const niceDomain = niceScale.domain();
|
|
195
|
-
const domain = [axis.min ?? niceDomain[0], axis.max ?? niceDomain[1]];
|
|
196
|
-
completedYAxis[axis.id] = (0, _extends2.default)({}, axis, {
|
|
197
|
-
scaleType,
|
|
198
|
-
scale: niceScale.domain(domain),
|
|
199
|
-
tickNumber,
|
|
200
|
-
colorScale: axis.colorMap && (0, _colorScale.getColorScale)(axis.colorMap)
|
|
201
|
-
});
|
|
202
|
-
});
|
|
203
|
-
return {
|
|
204
|
-
xAxis: completedXAxis,
|
|
205
|
-
yAxis: completedYAxis,
|
|
206
|
-
xAxisIds: allXAxis.map(({
|
|
207
|
-
id
|
|
208
|
-
}) => id),
|
|
209
|
-
yAxisIds: allYAxis.map(({
|
|
210
|
-
id
|
|
211
|
-
}) => id)
|
|
212
|
-
};
|
|
213
|
-
}, [drawingArea.height, drawingArea.left, drawingArea.top, drawingArea.width, formattedSeries, xAxis, xExtremumGetters, yAxis, yExtremumGetters]);
|
|
214
|
-
|
|
215
|
-
// @ts-ignore
|
|
216
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(CartesianContext.Provider, {
|
|
217
|
-
value: value,
|
|
218
|
-
children: children
|
|
219
|
-
});
|
|
220
|
-
}
|
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
import { scaleBand, scalePoint } from 'd3-scale';
|
|
4
|
-
import { isBandScaleConfig, isPointScaleConfig } from '../models/axis';
|
|
5
|
-
import { getScale } from '../internals/getScale';
|
|
6
|
-
import { DEFAULT_X_AXIS_KEY, DEFAULT_Y_AXIS_KEY } from '../constants';
|
|
7
|
-
import { getTickNumber } from '../hooks/useTicks';
|
|
8
|
-
import { useDrawingArea } from '../hooks/useDrawingArea';
|
|
9
|
-
import { getColorScale, getOrdinalColorScale } from '../internals/colorScale';
|
|
10
|
-
import { useSeries } from '../hooks/useSeries';
|
|
11
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
12
|
-
const DEFAULT_CATEGORY_GAP_RATIO = 0.2;
|
|
13
|
-
const DEFAULT_BAR_GAP_RATIO = 0.1;
|
|
14
|
-
export const CartesianContext = /*#__PURE__*/React.createContext({
|
|
15
|
-
xAxis: {},
|
|
16
|
-
yAxis: {},
|
|
17
|
-
xAxisIds: [],
|
|
18
|
-
yAxisIds: []
|
|
19
|
-
});
|
|
20
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
21
|
-
CartesianContext.displayName = 'CartesianContext';
|
|
22
|
-
}
|
|
23
|
-
function CartesianContextProvider(props) {
|
|
24
|
-
const {
|
|
25
|
-
xAxis: inXAxis,
|
|
26
|
-
yAxis: inYAxis,
|
|
27
|
-
dataset,
|
|
28
|
-
xExtremumGetters,
|
|
29
|
-
yExtremumGetters,
|
|
30
|
-
children
|
|
31
|
-
} = props;
|
|
32
|
-
const formattedSeries = useSeries();
|
|
33
|
-
const drawingArea = useDrawingArea();
|
|
34
|
-
const xAxis = React.useMemo(() => inXAxis?.map(axisConfig => {
|
|
35
|
-
const dataKey = axisConfig.dataKey;
|
|
36
|
-
if (dataKey === undefined || axisConfig.data !== undefined) {
|
|
37
|
-
return axisConfig;
|
|
38
|
-
}
|
|
39
|
-
if (dataset === undefined) {
|
|
40
|
-
throw Error('MUI X Charts: x-axis uses `dataKey` but no `dataset` is provided.');
|
|
41
|
-
}
|
|
42
|
-
return _extends({}, axisConfig, {
|
|
43
|
-
data: dataset.map(d => d[dataKey])
|
|
44
|
-
});
|
|
45
|
-
}), [inXAxis, dataset]);
|
|
46
|
-
const yAxis = React.useMemo(() => inYAxis?.map(axisConfig => {
|
|
47
|
-
const dataKey = axisConfig.dataKey;
|
|
48
|
-
if (dataKey === undefined || axisConfig.data !== undefined) {
|
|
49
|
-
return axisConfig;
|
|
50
|
-
}
|
|
51
|
-
if (dataset === undefined) {
|
|
52
|
-
throw Error('MUI X Charts: y-axis uses `dataKey` but no `dataset` is provided.');
|
|
53
|
-
}
|
|
54
|
-
return _extends({}, axisConfig, {
|
|
55
|
-
data: dataset.map(d => d[dataKey])
|
|
56
|
-
});
|
|
57
|
-
}), [inYAxis, dataset]);
|
|
58
|
-
const value = React.useMemo(() => {
|
|
59
|
-
const axisExtremumCallback = (acc, chartType, axis, getters, isDefaultAxis) => {
|
|
60
|
-
const getter = getters[chartType];
|
|
61
|
-
const series = formattedSeries[chartType]?.series ?? {};
|
|
62
|
-
const [minChartTypeData, maxChartTypeData] = getter?.({
|
|
63
|
-
series,
|
|
64
|
-
axis,
|
|
65
|
-
isDefaultAxis
|
|
66
|
-
}) ?? [null, null];
|
|
67
|
-
const [minData, maxData] = acc;
|
|
68
|
-
if (minData === null || maxData === null) {
|
|
69
|
-
return [minChartTypeData, maxChartTypeData];
|
|
70
|
-
}
|
|
71
|
-
if (minChartTypeData === null || maxChartTypeData === null) {
|
|
72
|
-
return [minData, maxData];
|
|
73
|
-
}
|
|
74
|
-
return [Math.min(minChartTypeData, minData), Math.max(maxChartTypeData, maxData)];
|
|
75
|
-
};
|
|
76
|
-
const getAxisExtremum = (axis, getters, isDefaultAxis) => {
|
|
77
|
-
const charTypes = Object.keys(getters);
|
|
78
|
-
return charTypes.reduce((acc, charType) => axisExtremumCallback(acc, charType, axis, getters, isDefaultAxis), [null, null]);
|
|
79
|
-
};
|
|
80
|
-
const allXAxis = [...(xAxis?.map((axis, index) => _extends({
|
|
81
|
-
id: `defaultized-x-axis-${index}`
|
|
82
|
-
}, axis)) ?? []),
|
|
83
|
-
// Allows to specify an axis with id=DEFAULT_X_AXIS_KEY
|
|
84
|
-
...(xAxis === undefined || xAxis.findIndex(({
|
|
85
|
-
id
|
|
86
|
-
}) => id === DEFAULT_X_AXIS_KEY) === -1 ? [{
|
|
87
|
-
id: DEFAULT_X_AXIS_KEY,
|
|
88
|
-
scaleType: 'linear'
|
|
89
|
-
}] : [])];
|
|
90
|
-
const completedXAxis = {};
|
|
91
|
-
allXAxis.forEach((axis, axisIndex) => {
|
|
92
|
-
const isDefaultAxis = axisIndex === 0;
|
|
93
|
-
const [minData, maxData] = getAxisExtremum(axis, xExtremumGetters, isDefaultAxis);
|
|
94
|
-
const range = axis.reverse ? [drawingArea.left + drawingArea.width, drawingArea.left] : [drawingArea.left, drawingArea.left + drawingArea.width];
|
|
95
|
-
if (isBandScaleConfig(axis)) {
|
|
96
|
-
const categoryGapRatio = axis.categoryGapRatio ?? DEFAULT_CATEGORY_GAP_RATIO;
|
|
97
|
-
const barGapRatio = axis.barGapRatio ?? DEFAULT_BAR_GAP_RATIO;
|
|
98
|
-
completedXAxis[axis.id] = _extends({
|
|
99
|
-
categoryGapRatio,
|
|
100
|
-
barGapRatio
|
|
101
|
-
}, axis, {
|
|
102
|
-
scale: scaleBand(axis.data, range).paddingInner(categoryGapRatio).paddingOuter(categoryGapRatio / 2),
|
|
103
|
-
tickNumber: axis.data.length,
|
|
104
|
-
colorScale: axis.colorMap && (axis.colorMap.type === 'ordinal' ? getOrdinalColorScale(_extends({
|
|
105
|
-
values: axis.data
|
|
106
|
-
}, axis.colorMap)) : getColorScale(axis.colorMap))
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
if (isPointScaleConfig(axis)) {
|
|
110
|
-
completedXAxis[axis.id] = _extends({}, axis, {
|
|
111
|
-
scale: scalePoint(axis.data, range),
|
|
112
|
-
tickNumber: axis.data.length,
|
|
113
|
-
colorScale: axis.colorMap && (axis.colorMap.type === 'ordinal' ? getOrdinalColorScale(_extends({
|
|
114
|
-
values: axis.data
|
|
115
|
-
}, axis.colorMap)) : getColorScale(axis.colorMap))
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
if (axis.scaleType === 'band' || axis.scaleType === 'point') {
|
|
119
|
-
// Could be merged with the two previous "if conditions" but then TS does not get that `axis.scaleType` can't be `band` or `point`.
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
const scaleType = axis.scaleType ?? 'linear';
|
|
123
|
-
const extremums = [axis.min ?? minData, axis.max ?? maxData];
|
|
124
|
-
const tickNumber = getTickNumber(_extends({}, axis, {
|
|
125
|
-
range,
|
|
126
|
-
domain: extremums
|
|
127
|
-
}));
|
|
128
|
-
const niceScale = getScale(scaleType, extremums, range).nice(tickNumber);
|
|
129
|
-
const niceDomain = niceScale.domain();
|
|
130
|
-
const domain = [axis.min ?? niceDomain[0], axis.max ?? niceDomain[1]];
|
|
131
|
-
completedXAxis[axis.id] = _extends({}, axis, {
|
|
132
|
-
scaleType,
|
|
133
|
-
scale: niceScale.domain(domain),
|
|
134
|
-
tickNumber,
|
|
135
|
-
colorScale: axis.colorMap && getColorScale(axis.colorMap)
|
|
136
|
-
});
|
|
137
|
-
});
|
|
138
|
-
const allYAxis = [...(yAxis?.map((axis, index) => _extends({
|
|
139
|
-
id: `defaultized-y-axis-${index}`
|
|
140
|
-
}, axis)) ?? []), ...(yAxis === undefined || yAxis.findIndex(({
|
|
141
|
-
id
|
|
142
|
-
}) => id === DEFAULT_Y_AXIS_KEY) === -1 ? [{
|
|
143
|
-
id: DEFAULT_Y_AXIS_KEY,
|
|
144
|
-
scaleType: 'linear'
|
|
145
|
-
}] : [])];
|
|
146
|
-
const completedYAxis = {};
|
|
147
|
-
allYAxis.forEach((axis, axisIndex) => {
|
|
148
|
-
const isDefaultAxis = axisIndex === 0;
|
|
149
|
-
const [minData, maxData] = getAxisExtremum(axis, yExtremumGetters, isDefaultAxis);
|
|
150
|
-
const range = axis.reverse ? [drawingArea.top, drawingArea.top + drawingArea.height] : [drawingArea.top + drawingArea.height, drawingArea.top];
|
|
151
|
-
if (isBandScaleConfig(axis)) {
|
|
152
|
-
const categoryGapRatio = axis.categoryGapRatio ?? DEFAULT_CATEGORY_GAP_RATIO;
|
|
153
|
-
completedYAxis[axis.id] = _extends({
|
|
154
|
-
categoryGapRatio,
|
|
155
|
-
barGapRatio: 0
|
|
156
|
-
}, axis, {
|
|
157
|
-
scale: scaleBand(axis.data, [range[1], range[0]]).paddingInner(categoryGapRatio).paddingOuter(categoryGapRatio / 2),
|
|
158
|
-
tickNumber: axis.data.length,
|
|
159
|
-
colorScale: axis.colorMap && (axis.colorMap.type === 'ordinal' ? getOrdinalColorScale(_extends({
|
|
160
|
-
values: axis.data
|
|
161
|
-
}, axis.colorMap)) : getColorScale(axis.colorMap))
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
if (isPointScaleConfig(axis)) {
|
|
165
|
-
completedYAxis[axis.id] = _extends({}, axis, {
|
|
166
|
-
scale: scalePoint(axis.data, [range[1], range[0]]),
|
|
167
|
-
tickNumber: axis.data.length,
|
|
168
|
-
colorScale: axis.colorMap && (axis.colorMap.type === 'ordinal' ? getOrdinalColorScale(_extends({
|
|
169
|
-
values: axis.data
|
|
170
|
-
}, axis.colorMap)) : getColorScale(axis.colorMap))
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
if (axis.scaleType === 'band' || axis.scaleType === 'point') {
|
|
174
|
-
// Could be merged with the two previous "if conditions" but then TS does not get that `axis.scaleType` can't be `band` or `point`.
|
|
175
|
-
return;
|
|
176
|
-
}
|
|
177
|
-
const scaleType = axis.scaleType ?? 'linear';
|
|
178
|
-
const extremums = [axis.min ?? minData, axis.max ?? maxData];
|
|
179
|
-
const tickNumber = getTickNumber(_extends({}, axis, {
|
|
180
|
-
range,
|
|
181
|
-
domain: extremums
|
|
182
|
-
}));
|
|
183
|
-
const niceScale = getScale(scaleType, extremums, range).nice(tickNumber);
|
|
184
|
-
const niceDomain = niceScale.domain();
|
|
185
|
-
const domain = [axis.min ?? niceDomain[0], axis.max ?? niceDomain[1]];
|
|
186
|
-
completedYAxis[axis.id] = _extends({}, axis, {
|
|
187
|
-
scaleType,
|
|
188
|
-
scale: niceScale.domain(domain),
|
|
189
|
-
tickNumber,
|
|
190
|
-
colorScale: axis.colorMap && getColorScale(axis.colorMap)
|
|
191
|
-
});
|
|
192
|
-
});
|
|
193
|
-
return {
|
|
194
|
-
xAxis: completedXAxis,
|
|
195
|
-
yAxis: completedYAxis,
|
|
196
|
-
xAxisIds: allXAxis.map(({
|
|
197
|
-
id
|
|
198
|
-
}) => id),
|
|
199
|
-
yAxisIds: allYAxis.map(({
|
|
200
|
-
id
|
|
201
|
-
}) => id)
|
|
202
|
-
};
|
|
203
|
-
}, [drawingArea.height, drawingArea.left, drawingArea.top, drawingArea.width, formattedSeries, xAxis, xExtremumGetters, yAxis, yExtremumGetters]);
|
|
204
|
-
|
|
205
|
-
// @ts-ignore
|
|
206
|
-
return /*#__PURE__*/_jsx(CartesianContext.Provider, {
|
|
207
|
-
value: value,
|
|
208
|
-
children: children
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
export { CartesianContextProvider };
|