@mui/x-charts 7.17.0 → 7.19.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 +10 -0
- package/BarChart/BarElement.d.ts +1 -1
- package/BarChart/BarLabel/BarLabel.d.ts +1 -1
- package/BarChart/formatter.js +5 -4
- package/CHANGELOG.md +208 -5
- package/ChartContainer/useDefaultizeAxis.d.ts +4 -4
- package/ChartContainer/useDefaultizeAxis.js +1 -1
- package/ChartsAxis/ChartsAxis.js +4 -4
- package/ChartsAxisHighlight/ChartsAxisHighlight.d.ts +1 -1
- package/ChartsGrid/styledCommonents.d.ts +2 -2
- package/ChartsLegend/ChartsLegend.d.ts +2 -2
- package/ChartsLegend/DefaultChartsLegend.js +1 -1
- package/ChartsLegend/LegendPerItem.d.ts +1 -1
- package/ChartsLegend/LegendPerItem.js +1 -1
- package/ChartsLegend/PiecewiseColorLegend.js +1 -1
- package/ChartsReferenceLine/common.d.ts +1 -1
- package/ChartsTooltip/ChartsTooltipTable.d.ts +5 -5
- package/ChartsTooltip/index.d.ts +3 -0
- package/ChartsTooltip/index.js +4 -1
- package/ChartsTooltip/useAxisTooltip.d.ts +18 -0
- package/ChartsTooltip/useAxisTooltip.js +84 -0
- package/ChartsTooltip/useItemTooltip.d.ts +10 -0
- package/ChartsTooltip/useItemTooltip.js +64 -0
- package/ChartsTooltip/utils.d.ts +2 -1
- package/LineChart/AnimatedArea.d.ts +1 -1
- package/LineChart/AnimatedArea.js +9 -45
- package/LineChart/AnimatedLine.d.ts +1 -1
- package/LineChart/AnimatedLine.js +9 -46
- package/LineChart/AppearingMask.d.ts +12 -0
- package/LineChart/AppearingMask.js +42 -0
- package/LineChart/LineChart.js +10 -0
- package/LineChart/formatter.js +5 -5
- package/PieChart/PieChart.js +10 -0
- package/ResponsiveChartContainer/ResizableContainer.d.ts +1 -1
- package/ResponsiveChartContainer/ResponsiveChartContainer.d.ts +10 -0
- package/ResponsiveChartContainer/ResponsiveChartContainer.js +10 -0
- package/ResponsiveChartContainer/useChartContainerDimensions.d.ts +1 -1
- package/ResponsiveChartContainer/useChartContainerDimensions.js +32 -8
- package/ResponsiveChartContainer/useResponsiveChartContainerProps.d.ts +1 -1
- package/ResponsiveChartContainer/useResponsiveChartContainerProps.js +3 -2
- package/ScatterChart/ScatterChart.js +10 -0
- package/SparkLineChart/SparkLineChart.d.ts +1 -1
- package/SparkLineChart/SparkLineChart.js +10 -0
- package/context/CartesianProvider/CartesianProvider.js +3 -3
- package/context/CartesianProvider/defaultizeAxis.d.ts +4 -4
- package/context/CartesianProvider/getAxisExtremum.d.ts +1 -1
- package/context/CartesianProvider/getAxisExtremum.js +5 -4
- package/context/CartesianProvider/index.d.ts +0 -5
- package/context/CartesianProvider/index.js +1 -6
- package/context/PluginProvider/ExtremumGetter.types.d.ts +1 -0
- package/context/PluginProvider/Plugin.types.d.ts +4 -0
- package/context/PluginProvider/PluginContext.js +3 -1
- package/context/PluginProvider/index.d.ts +2 -0
- package/context/PluginProvider/index.js +3 -1
- package/context/PluginProvider/mergePlugins.d.ts +14 -4
- package/context/PluginProvider/mergePlugins.js +11 -1
- package/context/PluginProvider/useRadiusExtremumGetter.d.ts +4 -0
- package/context/PluginProvider/useRadiusExtremumGetter.js +17 -0
- package/context/PluginProvider/useRotationExtremumGetter.d.ts +4 -0
- package/context/PluginProvider/useRotationExtremumGetter.js +17 -0
- package/context/PolarProvider/Polar.types.d.ts +42 -0
- package/context/PolarProvider/Polar.types.js +1 -0
- package/context/PolarProvider/PolarContext.d.ts +4 -0
- package/context/PolarProvider/PolarContext.js +13 -0
- package/context/PolarProvider/PolarProvider.d.ts +4 -0
- package/context/PolarProvider/PolarProvider.js +49 -0
- package/context/PolarProvider/getAxisExtremum.d.ts +4 -0
- package/context/PolarProvider/getAxisExtremum.js +20 -0
- package/context/PolarProvider/index.d.ts +0 -0
- package/context/PolarProvider/index.js +0 -0
- package/context/PolarProvider/usePolarContext.d.ts +2 -0
- package/context/PolarProvider/usePolarContext.js +10 -0
- package/context/ZAxisContextProvider.js +1 -1
- package/hooks/useReducedMotion.js +2 -2
- package/hooks/useSeries.d.ts +4 -4
- package/hooks/useSeries.js +4 -4
- package/index.js +1 -1
- package/internals/components/AxisSharedComponents.d.ts +1 -1
- package/internals/computeAxisValue.d.ts +38 -0
- package/{context/CartesianProvider/computeValue.js → internals/computeAxisValue.js} +28 -15
- package/internals/configInit.d.ts +1 -1
- package/internals/defaultizeColor.d.ts +8 -8
- package/internals/domUtils.js +1 -1
- package/internals/geometry.js +3 -5
- package/internals/getPercentageValue.js +1 -1
- package/internals/index.d.ts +1 -0
- package/internals/index.js +1 -0
- package/models/axis.d.ts +20 -0
- package/models/seriesType/config.d.ts +6 -2
- package/models/seriesType/line.d.ts +5 -0
- package/modern/BarChart/BarChart.js +10 -0
- package/modern/BarChart/formatter.js +5 -4
- package/modern/ChartContainer/useDefaultizeAxis.js +1 -1
- package/modern/ChartsAxis/ChartsAxis.js +4 -4
- package/modern/ChartsLegend/DefaultChartsLegend.js +1 -1
- package/modern/ChartsLegend/LegendPerItem.js +1 -1
- package/modern/ChartsLegend/PiecewiseColorLegend.js +1 -1
- package/modern/ChartsTooltip/index.js +4 -1
- package/modern/ChartsTooltip/useAxisTooltip.js +84 -0
- package/modern/ChartsTooltip/useItemTooltip.js +64 -0
- package/modern/LineChart/AnimatedArea.js +9 -45
- package/modern/LineChart/AnimatedLine.js +9 -46
- package/modern/LineChart/AppearingMask.js +42 -0
- package/modern/LineChart/LineChart.js +10 -0
- package/modern/LineChart/formatter.js +5 -5
- package/modern/PieChart/PieChart.js +10 -0
- package/modern/ResponsiveChartContainer/ResponsiveChartContainer.js +10 -0
- package/modern/ResponsiveChartContainer/useChartContainerDimensions.js +32 -8
- package/modern/ResponsiveChartContainer/useResponsiveChartContainerProps.js +3 -2
- package/modern/ScatterChart/ScatterChart.js +10 -0
- package/modern/SparkLineChart/SparkLineChart.js +10 -0
- package/modern/context/CartesianProvider/CartesianProvider.js +3 -3
- package/modern/context/CartesianProvider/getAxisExtremum.js +5 -4
- package/modern/context/CartesianProvider/index.js +1 -6
- package/modern/context/PluginProvider/PluginContext.js +3 -1
- package/modern/context/PluginProvider/index.js +3 -1
- package/modern/context/PluginProvider/mergePlugins.js +11 -1
- package/modern/context/PluginProvider/useRadiusExtremumGetter.js +17 -0
- package/modern/context/PluginProvider/useRotationExtremumGetter.js +17 -0
- package/modern/context/PolarProvider/Polar.types.js +1 -0
- package/modern/context/PolarProvider/PolarContext.js +13 -0
- package/modern/context/PolarProvider/PolarProvider.js +49 -0
- package/modern/context/PolarProvider/getAxisExtremum.js +20 -0
- package/modern/context/PolarProvider/index.js +0 -0
- package/modern/context/PolarProvider/usePolarContext.js +10 -0
- package/modern/context/ZAxisContextProvider.js +1 -1
- package/modern/hooks/useReducedMotion.js +2 -2
- package/modern/hooks/useSeries.js +4 -4
- package/modern/index.js +1 -1
- package/modern/{context/CartesianProvider/computeValue.js → internals/computeAxisValue.js} +28 -15
- package/modern/internals/domUtils.js +1 -1
- package/modern/internals/geometry.js +3 -5
- package/modern/internals/getPercentageValue.js +1 -1
- package/modern/internals/index.js +1 -0
- package/node/BarChart/BarChart.js +10 -0
- package/node/BarChart/formatter.js +5 -4
- package/node/ChartContainer/useDefaultizeAxis.js +1 -1
- package/node/ChartsAxis/ChartsAxis.js +4 -4
- package/node/ChartsLegend/DefaultChartsLegend.js +1 -1
- package/node/ChartsLegend/LegendPerItem.js +1 -1
- package/node/ChartsLegend/PiecewiseColorLegend.js +1 -1
- package/node/ChartsTooltip/index.js +42 -1
- package/node/ChartsTooltip/useAxisTooltip.js +90 -0
- package/node/ChartsTooltip/useItemTooltip.js +71 -0
- package/node/LineChart/AnimatedArea.js +8 -44
- package/node/LineChart/AnimatedLine.js +8 -45
- package/node/LineChart/AppearingMask.js +48 -0
- package/node/LineChart/LineChart.js +10 -0
- package/node/LineChart/formatter.js +5 -5
- package/node/PieChart/PieChart.js +10 -0
- package/node/ResponsiveChartContainer/ResponsiveChartContainer.js +10 -0
- package/node/ResponsiveChartContainer/useChartContainerDimensions.js +32 -8
- package/node/ResponsiveChartContainer/useResponsiveChartContainerProps.js +3 -2
- package/node/ScatterChart/ScatterChart.js +10 -0
- package/node/SparkLineChart/SparkLineChart.js +10 -0
- package/node/context/CartesianProvider/CartesianProvider.js +3 -3
- package/node/context/CartesianProvider/getAxisExtremum.js +5 -4
- package/node/context/CartesianProvider/index.js +1 -13
- package/node/context/PluginProvider/PluginContext.js +3 -1
- package/node/context/PluginProvider/index.js +22 -0
- package/node/context/PluginProvider/mergePlugins.js +11 -1
- package/node/context/PluginProvider/useRadiusExtremumGetter.js +23 -0
- package/node/context/PluginProvider/useRotationExtremumGetter.js +23 -0
- package/node/context/PolarProvider/Polar.types.js +5 -0
- package/node/context/PolarProvider/PolarContext.js +20 -0
- package/node/context/PolarProvider/PolarProvider.js +54 -0
- package/node/context/PolarProvider/getAxisExtremum.js +27 -0
- package/node/context/PolarProvider/index.js +1 -0
- package/node/context/PolarProvider/usePolarContext.js +17 -0
- package/node/context/ZAxisContextProvider.js +1 -1
- package/node/hooks/useReducedMotion.js +2 -2
- package/node/hooks/useSeries.js +4 -4
- package/node/index.js +1 -1
- package/node/{context/CartesianProvider/computeValue.js → internals/computeAxisValue.js} +29 -16
- package/node/internals/domUtils.js +1 -1
- package/node/internals/geometry.js +3 -5
- package/node/internals/getPercentageValue.js +1 -1
- package/node/internals/index.js +12 -0
- package/package.json +4 -4
- package/context/CartesianProvider/computeValue.d.ts +0 -30
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import { useIsomorphicLayoutEffect, Globals } from '@react-spring/web';
|
|
4
|
-
const handleMediaChange =
|
|
4
|
+
const handleMediaChange = event => {
|
|
5
5
|
Globals.assign({
|
|
6
6
|
// Modification such the react-spring implementation such that this hook can remove animation but never activate animation.
|
|
7
|
-
skipAnimation:
|
|
7
|
+
skipAnimation: event.matches || undefined
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
|
package/hooks/useSeries.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export declare function useSeries(): FormattedSeries;
|
|
|
11
11
|
* The returned object contains:
|
|
12
12
|
* - series: a mapping from ids to series attributes.
|
|
13
13
|
* - seriesOrder: the array of series ids.
|
|
14
|
-
* @returns { series: Record<SeriesId, DefaultizedPieSeriesType>; seriesOrder: SeriesId[]; } | undefined
|
|
14
|
+
* @returns {{ series: Record<SeriesId, DefaultizedPieSeriesType>; seriesOrder: SeriesId[]; } | undefined} pieSeries
|
|
15
15
|
*/
|
|
16
16
|
export declare function usePieSeries(): FormattedSeries['pie'];
|
|
17
17
|
/**
|
|
@@ -19,7 +19,7 @@ export declare function usePieSeries(): FormattedSeries['pie'];
|
|
|
19
19
|
* The returned object contains:
|
|
20
20
|
* - series: a mapping from ids to series attributes.
|
|
21
21
|
* - seriesOrder: the array of series ids.
|
|
22
|
-
* @returns { series: Record<SeriesId, DefaultizedLineSeriesType>; seriesOrder: SeriesId[]; } | undefined
|
|
22
|
+
* @returns {{ series: Record<SeriesId, DefaultizedLineSeriesType>; seriesOrder: SeriesId[]; } | undefined} lineSeries
|
|
23
23
|
*/
|
|
24
24
|
export declare function useLineSeries(): FormattedSeries['line'];
|
|
25
25
|
/**
|
|
@@ -27,7 +27,7 @@ export declare function useLineSeries(): FormattedSeries['line'];
|
|
|
27
27
|
* The returned object contains:
|
|
28
28
|
* - series: a mapping from ids to series attributes.
|
|
29
29
|
* - seriesOrder: the array of series ids.
|
|
30
|
-
* @returns { series: Record<SeriesId, DefaultizedBarSeriesType>; seriesOrder: SeriesId[]; } | undefined
|
|
30
|
+
* @returns {{ series: Record<SeriesId, DefaultizedBarSeriesType>; seriesOrder: SeriesId[]; } | undefined} barSeries
|
|
31
31
|
*/
|
|
32
32
|
export declare function useBarSeries(): FormattedSeries['bar'];
|
|
33
33
|
/**
|
|
@@ -35,6 +35,6 @@ export declare function useBarSeries(): FormattedSeries['bar'];
|
|
|
35
35
|
* The returned object contains:
|
|
36
36
|
* - series: a mapping from ids to series attributes.
|
|
37
37
|
* - seriesOrder: the array of series ids.
|
|
38
|
-
* @returns { series: Record<SeriesId, DefaultizedScatterSeriesType>; seriesOrder: SeriesId[]; } | undefined
|
|
38
|
+
* @returns {{ series: Record<SeriesId, DefaultizedScatterSeriesType>; seriesOrder: SeriesId[]; } | undefined} scatterSeries
|
|
39
39
|
*/
|
|
40
40
|
export declare function useScatterSeries(): FormattedSeries['scatter'];
|
package/hooks/useSeries.js
CHANGED
|
@@ -25,7 +25,7 @@ export function useSeries() {
|
|
|
25
25
|
* The returned object contains:
|
|
26
26
|
* - series: a mapping from ids to series attributes.
|
|
27
27
|
* - seriesOrder: the array of series ids.
|
|
28
|
-
* @returns { series: Record<SeriesId, DefaultizedPieSeriesType>; seriesOrder: SeriesId[]; } | undefined
|
|
28
|
+
* @returns {{ series: Record<SeriesId, DefaultizedPieSeriesType>; seriesOrder: SeriesId[]; } | undefined} pieSeries
|
|
29
29
|
*/
|
|
30
30
|
export function usePieSeries() {
|
|
31
31
|
const series = useSeries();
|
|
@@ -37,7 +37,7 @@ export function usePieSeries() {
|
|
|
37
37
|
* The returned object contains:
|
|
38
38
|
* - series: a mapping from ids to series attributes.
|
|
39
39
|
* - seriesOrder: the array of series ids.
|
|
40
|
-
* @returns { series: Record<SeriesId, DefaultizedLineSeriesType>; seriesOrder: SeriesId[]; } | undefined
|
|
40
|
+
* @returns {{ series: Record<SeriesId, DefaultizedLineSeriesType>; seriesOrder: SeriesId[]; } | undefined} lineSeries
|
|
41
41
|
*/
|
|
42
42
|
export function useLineSeries() {
|
|
43
43
|
const series = useSeries();
|
|
@@ -49,7 +49,7 @@ export function useLineSeries() {
|
|
|
49
49
|
* The returned object contains:
|
|
50
50
|
* - series: a mapping from ids to series attributes.
|
|
51
51
|
* - seriesOrder: the array of series ids.
|
|
52
|
-
* @returns { series: Record<SeriesId, DefaultizedBarSeriesType>; seriesOrder: SeriesId[]; } | undefined
|
|
52
|
+
* @returns {{ series: Record<SeriesId, DefaultizedBarSeriesType>; seriesOrder: SeriesId[]; } | undefined} barSeries
|
|
53
53
|
*/
|
|
54
54
|
export function useBarSeries() {
|
|
55
55
|
const series = useSeries();
|
|
@@ -61,7 +61,7 @@ export function useBarSeries() {
|
|
|
61
61
|
* The returned object contains:
|
|
62
62
|
* - series: a mapping from ids to series attributes.
|
|
63
63
|
* - seriesOrder: the array of series ids.
|
|
64
|
-
* @returns { series: Record<SeriesId, DefaultizedScatterSeriesType>; seriesOrder: SeriesId[]; } | undefined
|
|
64
|
+
* @returns {{ series: Record<SeriesId, DefaultizedScatterSeriesType>; seriesOrder: SeriesId[]; } | undefined} scatterSeries
|
|
65
65
|
*/
|
|
66
66
|
export function useScatterSeries() {
|
|
67
67
|
const series = useSeries();
|
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const AxisRoot: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<import("@mui/material
|
|
1
|
+
export declare const AxisRoot: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<import("@mui/material").Theme>, Pick<import("react").SVGProps<SVGGElement>, keyof import("react").SVGProps<SVGGElement>>, {}>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { AxisConfig, ScaleName } from '../models';
|
|
2
|
+
import { ChartsXAxisProps, ChartsAxisProps, ChartsYAxisProps, ChartsRadiusAxisProps, ChartsRotationAxisProps } from '../models/axis';
|
|
3
|
+
import { CartesianChartSeriesType } from '../models/seriesType/config';
|
|
4
|
+
import { DrawingArea } from '../context/DrawingProvider';
|
|
5
|
+
import { FormattedSeries } from '../context/SeriesProvider';
|
|
6
|
+
import { ExtremumGetter } from '../context/PluginProvider';
|
|
7
|
+
import { DefaultizedAxisConfig, ZoomData, ZoomOptions, GetZoomAxisFilters } from '../context/CartesianProvider/Cartesian.types';
|
|
8
|
+
type ComputeResult<T extends ChartsAxisProps> = {
|
|
9
|
+
axis: DefaultizedAxisConfig<T>;
|
|
10
|
+
axisIds: string[];
|
|
11
|
+
};
|
|
12
|
+
type ComputeCommonParams = {
|
|
13
|
+
drawingArea: DrawingArea;
|
|
14
|
+
formattedSeries: FormattedSeries;
|
|
15
|
+
extremumGetters: {
|
|
16
|
+
[K in CartesianChartSeriesType]?: ExtremumGetter<K>;
|
|
17
|
+
};
|
|
18
|
+
zoomData?: ZoomData[];
|
|
19
|
+
zoomOptions?: ZoomOptions;
|
|
20
|
+
getFilters?: GetZoomAxisFilters;
|
|
21
|
+
};
|
|
22
|
+
export declare function computeAxisValue(options: ComputeCommonParams & {
|
|
23
|
+
axis: AxisConfig<ScaleName, any, ChartsYAxisProps>[];
|
|
24
|
+
axisDirection: 'y';
|
|
25
|
+
}): ComputeResult<ChartsYAxisProps>;
|
|
26
|
+
export declare function computeAxisValue(options: ComputeCommonParams & {
|
|
27
|
+
axis: AxisConfig<ScaleName, any, ChartsXAxisProps>[];
|
|
28
|
+
axisDirection: 'x';
|
|
29
|
+
}): ComputeResult<ChartsAxisProps>;
|
|
30
|
+
export declare function computeAxisValue(options: ComputeCommonParams & {
|
|
31
|
+
axis: AxisConfig<ScaleName, any, ChartsRadiusAxisProps>[];
|
|
32
|
+
axisDirection: 'radius';
|
|
33
|
+
}): ComputeResult<ChartsRadiusAxisProps>;
|
|
34
|
+
export declare function computeAxisValue(options: ComputeCommonParams & {
|
|
35
|
+
axis: AxisConfig<ScaleName, any, ChartsRotationAxisProps>[];
|
|
36
|
+
axisDirection: 'rotation';
|
|
37
|
+
}): ComputeResult<ChartsRotationAxisProps>;
|
|
38
|
+
export {};
|
|
@@ -1,15 +1,29 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import { scaleBand, scalePoint, scaleTime } from '@mui/x-charts-vendor/d3-scale';
|
|
3
|
-
import { isBandScaleConfig, isPointScaleConfig } from "
|
|
4
|
-
import { getColorScale, getOrdinalColorScale } from "
|
|
5
|
-
import { getTickNumber } from "
|
|
6
|
-
import { getScale } from "
|
|
7
|
-
import { zoomScaleRange } from "
|
|
8
|
-
import { getAxisExtremum } from "
|
|
9
|
-
|
|
3
|
+
import { isBandScaleConfig, isPointScaleConfig } from "../models/axis.js";
|
|
4
|
+
import { getColorScale, getOrdinalColorScale } from "./colorScale.js";
|
|
5
|
+
import { getTickNumber } from "../hooks/useTicks.js";
|
|
6
|
+
import { getScale } from "./getScale.js";
|
|
7
|
+
import { zoomScaleRange } from "../context/CartesianProvider/zoom.js";
|
|
8
|
+
import { getAxisExtremum } from "../context/CartesianProvider/getAxisExtremum.js";
|
|
9
|
+
function getRange(drawingArea, axisDirection, axis) {
|
|
10
|
+
if (axisDirection === 'rotation') {
|
|
11
|
+
const {
|
|
12
|
+
startAngle = 0,
|
|
13
|
+
endAngle = startAngle + 360
|
|
14
|
+
} = axis;
|
|
15
|
+
return axis.reverse ? [Math.PI * startAngle / 180, Math.PI * endAngle / 180] : [Math.PI * endAngle / 180, Math.PI * startAngle / 180];
|
|
16
|
+
}
|
|
17
|
+
if (axisDirection === 'radius') {
|
|
18
|
+
const {
|
|
19
|
+
minRadius = 0,
|
|
20
|
+
maxRadius = Math.min(drawingArea.width, drawingArea.height) / 2
|
|
21
|
+
} = axis;
|
|
22
|
+
return [minRadius, maxRadius];
|
|
23
|
+
}
|
|
10
24
|
const range = axisDirection === 'x' ? [drawingArea.left, drawingArea.left + drawingArea.width] : [drawingArea.top + drawingArea.height, drawingArea.top];
|
|
11
|
-
return
|
|
12
|
-
}
|
|
25
|
+
return axis.reverse ? [range[1], range[0]] : range;
|
|
26
|
+
}
|
|
13
27
|
const isDateData = data => data?.[0] instanceof Date;
|
|
14
28
|
function createDateFormatter(axis, range) {
|
|
15
29
|
const timeScale = scaleTime(axis.data, range);
|
|
@@ -19,7 +33,7 @@ function createDateFormatter(axis, range) {
|
|
|
19
33
|
}
|
|
20
34
|
const DEFAULT_CATEGORY_GAP_RATIO = 0.2;
|
|
21
35
|
const DEFAULT_BAR_GAP_RATIO = 0.1;
|
|
22
|
-
export function
|
|
36
|
+
export function computeAxisValue({
|
|
23
37
|
drawingArea,
|
|
24
38
|
formattedSeries,
|
|
25
39
|
axis: allAxis,
|
|
@@ -32,21 +46,20 @@ export function computeValue({
|
|
|
32
46
|
const completeAxis = {};
|
|
33
47
|
allAxis.forEach((eachAxis, axisIndex) => {
|
|
34
48
|
const axis = eachAxis;
|
|
35
|
-
const isDefaultAxis = axisIndex === 0;
|
|
36
49
|
const zoomOption = zoomOptions?.[axis.id];
|
|
37
50
|
const zoom = zoomData?.find(({
|
|
38
51
|
axisId
|
|
39
52
|
}) => axisId === axis.id);
|
|
40
53
|
const zoomRange = zoom ? [zoom.start, zoom.end] : [0, 100];
|
|
41
|
-
const range = getRange(drawingArea, axisDirection, axis
|
|
42
|
-
const [minData, maxData] = getAxisExtremum(axis, extremumGetters,
|
|
54
|
+
const range = getRange(drawingArea, axisDirection, axis);
|
|
55
|
+
const [minData, maxData] = getAxisExtremum(axis, extremumGetters, axisIndex, formattedSeries, zoom === undefined && !zoomOption ? getFilters : undefined // Do not apply filtering if zoom is already defined.
|
|
43
56
|
);
|
|
44
57
|
const data = axis.data ?? [];
|
|
45
58
|
if (isBandScaleConfig(axis)) {
|
|
46
59
|
const categoryGapRatio = axis.categoryGapRatio ?? DEFAULT_CATEGORY_GAP_RATIO;
|
|
47
60
|
const barGapRatio = axis.barGapRatio ?? DEFAULT_BAR_GAP_RATIO;
|
|
48
61
|
// Reverse range because ordinal scales are presented from top to bottom on y-axis
|
|
49
|
-
const scaleRange = axisDirection === '
|
|
62
|
+
const scaleRange = axisDirection === 'y' ? [range[1], range[0]] : range;
|
|
50
63
|
const zoomedRange = zoomScaleRange(scaleRange, zoomRange);
|
|
51
64
|
completeAxis[axis.id] = _extends({
|
|
52
65
|
categoryGapRatio,
|
|
@@ -65,7 +78,7 @@ export function computeValue({
|
|
|
65
78
|
}
|
|
66
79
|
}
|
|
67
80
|
if (isPointScaleConfig(axis)) {
|
|
68
|
-
const scaleRange = axisDirection === '
|
|
81
|
+
const scaleRange = axisDirection === 'y' ? [...range].reverse() : range;
|
|
69
82
|
const zoomedRange = zoomScaleRange(scaleRange, zoomRange);
|
|
70
83
|
completeAxis[axis.id] = _extends({}, axis, {
|
|
71
84
|
data,
|
|
@@ -3,7 +3,7 @@ declare class CartesianSeriesTypes {
|
|
|
3
3
|
types: Set<ChartSeriesType>;
|
|
4
4
|
constructor();
|
|
5
5
|
addType(value: ChartSeriesType): void;
|
|
6
|
-
getTypes(): Set<keyof import("
|
|
6
|
+
getTypes(): Set<keyof import(".").ChartsSeriesConfig>;
|
|
7
7
|
}
|
|
8
8
|
export declare const cartesianSeriesTypes: CartesianSeriesTypes;
|
|
9
9
|
export {};
|
|
@@ -4,7 +4,7 @@ export declare function defaultizeColor(series: AllSeriesType, seriesIndex: numb
|
|
|
4
4
|
color: string;
|
|
5
5
|
label?: (string | ((location: "tooltip" | "legend" | "arc") => string)) | undefined;
|
|
6
6
|
value: number;
|
|
7
|
-
id?: import("
|
|
7
|
+
id?: import("..").PieItemId | undefined;
|
|
8
8
|
}[];
|
|
9
9
|
type: "pie";
|
|
10
10
|
innerRadius?: number | string;
|
|
@@ -14,8 +14,8 @@ export declare function defaultizeColor(series: AllSeriesType, seriesIndex: numb
|
|
|
14
14
|
startAngle?: number;
|
|
15
15
|
endAngle?: number;
|
|
16
16
|
paddingAngle?: number;
|
|
17
|
-
sortingValues?: import("
|
|
18
|
-
arcLabel?: "formattedValue" | "label" | "value" | ((item: Omit<import("
|
|
17
|
+
sortingValues?: import("..").ChartsPieSorting;
|
|
18
|
+
arcLabel?: "formattedValue" | "label" | "value" | ((item: Omit<import("..").DefaultizedPieValueType, "label"> & {
|
|
19
19
|
label?: string;
|
|
20
20
|
}) => string);
|
|
21
21
|
arcLabelMinAngle?: number;
|
|
@@ -41,7 +41,7 @@ export declare function defaultizeColor(series: AllSeriesType, seriesIndex: numb
|
|
|
41
41
|
};
|
|
42
42
|
id?: import(".").SeriesId;
|
|
43
43
|
color?: string;
|
|
44
|
-
valueFormatter?: import(".").SeriesValueFormatter<import(".").MakeOptional<import("
|
|
44
|
+
valueFormatter?: import(".").SeriesValueFormatter<import(".").MakeOptional<import("..").PieValueType, "id">> | undefined;
|
|
45
45
|
highlightScope?: Partial<import("..").HighlightScope>;
|
|
46
46
|
} | {
|
|
47
47
|
type: "bar";
|
|
@@ -62,7 +62,7 @@ export declare function defaultizeColor(series: AllSeriesType, seriesIndex: numb
|
|
|
62
62
|
stackOrder?: import("..").StackOrderType;
|
|
63
63
|
} | {
|
|
64
64
|
type: "scatter";
|
|
65
|
-
data: import("
|
|
65
|
+
data: import("..").ScatterValueType[];
|
|
66
66
|
markerSize?: number;
|
|
67
67
|
label?: string | ((location: "tooltip" | "legend") => string);
|
|
68
68
|
disableHover?: boolean;
|
|
@@ -70,7 +70,7 @@ export declare function defaultizeColor(series: AllSeriesType, seriesIndex: numb
|
|
|
70
70
|
zAxisId?: string;
|
|
71
71
|
id?: import(".").SeriesId;
|
|
72
72
|
color: string;
|
|
73
|
-
valueFormatter?: import(".").SeriesValueFormatter<import("
|
|
73
|
+
valueFormatter?: import(".").SeriesValueFormatter<import("..").ScatterValueType> | undefined;
|
|
74
74
|
highlightScope?: Partial<import("..").HighlightScope>;
|
|
75
75
|
xAxisKey?: string;
|
|
76
76
|
yAxisKey?: string;
|
|
@@ -83,8 +83,8 @@ export declare function defaultizeColor(series: AllSeriesType, seriesIndex: numb
|
|
|
83
83
|
stack?: string;
|
|
84
84
|
area?: boolean;
|
|
85
85
|
label?: string | ((location: "tooltip" | "legend") => string);
|
|
86
|
-
curve?: import("
|
|
87
|
-
showMark?: boolean | ((params: import("
|
|
86
|
+
curve?: import("..").CurveType;
|
|
87
|
+
showMark?: boolean | ((params: import("..").ShowMarkParams) => boolean);
|
|
88
88
|
disableHighlight?: boolean;
|
|
89
89
|
connectNulls?: boolean;
|
|
90
90
|
stackOffset?: import("..").StackOffsetType;
|
package/internals/domUtils.js
CHANGED
package/internals/geometry.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
+
import { warnOnce } from '@mui/x-internals/warning';
|
|
1
2
|
const ANGLE_APPROX = 5; // Angle (in deg) for which we approximate the rectangle as perfectly horizontal/vertical
|
|
2
3
|
|
|
3
|
-
let warnedOnce = false;
|
|
4
|
-
|
|
5
4
|
/**
|
|
6
5
|
* Return the minimal translation along the x-axis to avoid overflow of a rectangle of a given width, height, and rotation.
|
|
7
6
|
* This assumes that all rectangles have the same height and angle between -90 and 90.
|
|
@@ -12,9 +11,8 @@ let warnedOnce = false;
|
|
|
12
11
|
*/
|
|
13
12
|
export function getMinXTranslation(width, height, angle = 0) {
|
|
14
13
|
if (process.env.NODE_ENV !== 'production') {
|
|
15
|
-
if (
|
|
16
|
-
|
|
17
|
-
console.warn([`MUI X: It seems you applied an angle larger than 90° or smaller than -90° to an axis text.`, `This could cause some text overlapping.`, `If you encounter a use case where it's needed, please open an issue.`].join('\n'));
|
|
14
|
+
if (angle > 90 && angle < -90) {
|
|
15
|
+
warnOnce([`MUI X: It seems you applied an angle larger than 90° or smaller than -90° to an axis text.`, `This could cause some text overlapping.`, `If you encounter a use case where it's needed, please open an issue.`]);
|
|
18
16
|
}
|
|
19
17
|
}
|
|
20
18
|
const standardAngle = Math.min(Math.abs(angle) % 180, Math.abs(Math.abs(angle) % 180 - 180) % 180); // Map from R to [0, 90]
|
|
@@ -24,5 +24,5 @@ export function getPercentageValue(value, refValue) {
|
|
|
24
24
|
return val;
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
|
-
throw Error(`MUI X: Received an unknown value "${value}". It should be a number, or a string with a percentage value.`);
|
|
27
|
+
throw new Error(`MUI X: Received an unknown value "${value}". It should be a number, or a string with a percentage value.`);
|
|
28
28
|
}
|
package/internals/index.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ export * from './getSVGPoint';
|
|
|
17
17
|
export * from './isDefined';
|
|
18
18
|
export { unstable_cleanupDOM } from './domUtils';
|
|
19
19
|
export * from './getScale';
|
|
20
|
+
export * from './computeAxisValue';
|
|
20
21
|
export * from '../context/CartesianProvider';
|
|
21
22
|
export * from '../context/DrawingProvider';
|
|
22
23
|
export * from '../context/InteractionProvider';
|
package/internals/index.js
CHANGED
package/models/axis.d.ts
CHANGED
|
@@ -127,6 +127,26 @@ export interface ChartsXAxisProps extends ChartsAxisProps {
|
|
|
127
127
|
*/
|
|
128
128
|
position?: 'top' | 'bottom';
|
|
129
129
|
}
|
|
130
|
+
export interface ChartsRotationAxisProps extends ChartsAxisProps {
|
|
131
|
+
/**
|
|
132
|
+
* The start angle (in deg).
|
|
133
|
+
*/
|
|
134
|
+
startAngle?: number;
|
|
135
|
+
/**
|
|
136
|
+
* The end angle (in deg).
|
|
137
|
+
*/
|
|
138
|
+
endAngle?: number;
|
|
139
|
+
}
|
|
140
|
+
export interface ChartsRadiusAxisProps extends ChartsAxisProps {
|
|
141
|
+
/**
|
|
142
|
+
* The minimal radius.
|
|
143
|
+
*/
|
|
144
|
+
minRadius?: number;
|
|
145
|
+
/**
|
|
146
|
+
* The maximal radius.
|
|
147
|
+
*/
|
|
148
|
+
maxRadius?: number;
|
|
149
|
+
}
|
|
130
150
|
export type ScaleName = keyof AxisScaleConfig;
|
|
131
151
|
export type ContinuousScaleName = 'linear' | 'log' | 'pow' | 'sqrt' | 'time' | 'utc';
|
|
132
152
|
export interface AxisScaleConfig {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { ScatterSeriesType, DefaultizedScatterSeriesType, ScatterItemIdentifier } from './scatter';
|
|
1
|
+
import { ScatterSeriesType, DefaultizedScatterSeriesType, ScatterItemIdentifier, ScatterValueType } from './scatter';
|
|
2
2
|
import { LineSeriesType, DefaultizedLineSeriesType, LineItemIdentifier } from './line';
|
|
3
3
|
import { BarItemIdentifier, BarSeriesType, DefaultizedBarSeriesType } from './bar';
|
|
4
|
-
import { PieSeriesType, DefaultizedPieSeriesType, PieItemIdentifier, PieValueType } from './pie';
|
|
4
|
+
import { PieSeriesType, DefaultizedPieSeriesType, PieItemIdentifier, PieValueType, DefaultizedPieValueType } from './pie';
|
|
5
5
|
import { DefaultizedProps, MakeOptional } from '../helpers';
|
|
6
6
|
export interface ChartsSeriesConfig {
|
|
7
7
|
bar: {
|
|
@@ -20,6 +20,7 @@ export interface ChartsSeriesConfig {
|
|
|
20
20
|
*/
|
|
21
21
|
seriesProp: BarSeriesType;
|
|
22
22
|
itemIdentifier: BarItemIdentifier;
|
|
23
|
+
valueType: number | null;
|
|
23
24
|
canBeStacked: true;
|
|
24
25
|
cartesian: true;
|
|
25
26
|
};
|
|
@@ -30,6 +31,7 @@ export interface ChartsSeriesConfig {
|
|
|
30
31
|
series: DefaultizedLineSeriesType;
|
|
31
32
|
seriesProp: LineSeriesType;
|
|
32
33
|
itemIdentifier: LineItemIdentifier;
|
|
34
|
+
valueType: number | null;
|
|
33
35
|
canBeStacked: true;
|
|
34
36
|
cartesian: true;
|
|
35
37
|
};
|
|
@@ -39,6 +41,7 @@ export interface ChartsSeriesConfig {
|
|
|
39
41
|
};
|
|
40
42
|
series: DefaultizedScatterSeriesType;
|
|
41
43
|
seriesProp: ScatterSeriesType;
|
|
44
|
+
valueType: ScatterValueType;
|
|
42
45
|
itemIdentifier: ScatterItemIdentifier;
|
|
43
46
|
cartesian: true;
|
|
44
47
|
};
|
|
@@ -51,6 +54,7 @@ export interface ChartsSeriesConfig {
|
|
|
51
54
|
series: DefaultizedPieSeriesType;
|
|
52
55
|
seriesProp: PieSeriesType<MakeOptional<PieValueType, 'id'>>;
|
|
53
56
|
itemIdentifier: PieItemIdentifier;
|
|
57
|
+
valueType: DefaultizedPieValueType;
|
|
54
58
|
};
|
|
55
59
|
}
|
|
56
60
|
export type ChartSeriesType = keyof ChartsSeriesConfig;
|
|
@@ -40,6 +40,11 @@ export interface LineSeriesType extends CommonSeriesType<number | null>, Cartesi
|
|
|
40
40
|
* The label to display on the tooltip or the legend. It can be a string or a function.
|
|
41
41
|
*/
|
|
42
42
|
label?: string | ((location: 'tooltip' | 'legend') => string);
|
|
43
|
+
/**
|
|
44
|
+
* The type of curve to use for the line.
|
|
45
|
+
* Read more about curves at [line interpolation](https://mui.com/x/react-charts/lines/#interpolation).
|
|
46
|
+
* @default 'monotoneX'
|
|
47
|
+
*/
|
|
43
48
|
curve?: CurveType;
|
|
44
49
|
/**
|
|
45
50
|
* Define which items of the series should display a mark.
|
|
@@ -196,6 +196,16 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
196
196
|
* @param {BarItemIdentifier} barItemIdentifier The bar item identifier.
|
|
197
197
|
*/
|
|
198
198
|
onItemClick: PropTypes.func,
|
|
199
|
+
/**
|
|
200
|
+
* The chart will try to wait for the parent container to resolve its size
|
|
201
|
+
* before it renders for the first time.
|
|
202
|
+
*
|
|
203
|
+
* This can be useful in some scenarios where the chart appear to grow after
|
|
204
|
+
* the first render, like when used inside a grid.
|
|
205
|
+
*
|
|
206
|
+
* @default false
|
|
207
|
+
*/
|
|
208
|
+
resolveSizeBeforeRender: PropTypes.bool,
|
|
199
209
|
/**
|
|
200
210
|
* Indicate which axis to display the right of the charts.
|
|
201
211
|
* Can be a string (the id of the axis) or an object `ChartsYAxisProps`.
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import { stack as d3Stack } from '@mui/x-charts-vendor/d3-shape';
|
|
3
|
+
import { warnOnce } from '@mui/x-internals/warning';
|
|
3
4
|
import { getStackingGroups } from "../internals/stackSeries.js";
|
|
4
5
|
import { defaultizeValueFormatter } from "../internals/defaultizeValueFormatter.js";
|
|
5
|
-
let warnOnce = false;
|
|
6
6
|
const formatter = (params, dataset) => {
|
|
7
7
|
const {
|
|
8
8
|
seriesOrder,
|
|
@@ -50,9 +50,10 @@ const formatter = (params, dataset) => {
|
|
|
50
50
|
data: dataKey ? dataset.map(data => {
|
|
51
51
|
const value = data[dataKey];
|
|
52
52
|
if (typeof value !== 'number') {
|
|
53
|
-
if (process.env.NODE_ENV !== 'production'
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
54
|
+
if (value !== null) {
|
|
55
|
+
warnOnce([`MUI X: your dataset key "${dataKey}" is used for plotting bars, but contains nonnumerical elements.`, 'Bar plots only support numbers and null values.']);
|
|
56
|
+
}
|
|
56
57
|
}
|
|
57
58
|
return 0;
|
|
58
59
|
}
|
|
@@ -18,7 +18,7 @@ const defaultizeAxis = (inAxis, dataset, axisName) => {
|
|
|
18
18
|
return axisConfig;
|
|
19
19
|
}
|
|
20
20
|
if (dataset === undefined) {
|
|
21
|
-
throw Error(`MUI X: ${axisName}-axis uses \`dataKey\` but no \`dataset\` is provided.`);
|
|
21
|
+
throw new Error(`MUI X: ${axisName}-axis uses \`dataKey\` but no \`dataset\` is provided.`);
|
|
22
22
|
}
|
|
23
23
|
return _extends({}, axisConfig, {
|
|
24
24
|
data: dataset.map(d => d[dataKey])
|
|
@@ -59,16 +59,16 @@ function ChartsAxis(props) {
|
|
|
59
59
|
const topId = getAxisId(topAxis, xAxisIds[0]);
|
|
60
60
|
const rightId = getAxisId(rightAxis, yAxisIds[0]);
|
|
61
61
|
if (topId !== null && !xAxis[topId]) {
|
|
62
|
-
throw Error([`MUI X: id used for top axis "${topId}" is not defined.`, `Available ids are: ${xAxisIds.join(', ')}.`].join('\n'));
|
|
62
|
+
throw new Error([`MUI X: id used for top axis "${topId}" is not defined.`, `Available ids are: ${xAxisIds.join(', ')}.`].join('\n'));
|
|
63
63
|
}
|
|
64
64
|
if (leftId !== null && !yAxis[leftId]) {
|
|
65
|
-
throw Error([`MUI X: id used for left axis "${leftId}" is not defined.`, `Available ids are: ${yAxisIds.join(', ')}.`].join('\n'));
|
|
65
|
+
throw new Error([`MUI X: id used for left axis "${leftId}" is not defined.`, `Available ids are: ${yAxisIds.join(', ')}.`].join('\n'));
|
|
66
66
|
}
|
|
67
67
|
if (rightId !== null && !yAxis[rightId]) {
|
|
68
|
-
throw Error([`MUI X: id used for right axis "${rightId}" is not defined.`, `Available ids are: ${yAxisIds.join(', ')}.`].join('\n'));
|
|
68
|
+
throw new Error([`MUI X: id used for right axis "${rightId}" is not defined.`, `Available ids are: ${yAxisIds.join(', ')}.`].join('\n'));
|
|
69
69
|
}
|
|
70
70
|
if (bottomId !== null && !xAxis[bottomId]) {
|
|
71
|
-
throw Error([`MUI X: id used for bottom axis "${bottomId}" is not defined.`, `Available ids are: ${xAxisIds.join(', ')}.`].join('\n'));
|
|
71
|
+
throw new Error([`MUI X: id used for bottom axis "${bottomId}" is not defined.`, `Available ids are: ${xAxisIds.join(', ')}.`].join('\n'));
|
|
72
72
|
}
|
|
73
73
|
const topAxisProps = mergeProps(topAxis, slots, slotProps);
|
|
74
74
|
const bottomAxisProps = mergeProps(bottomAxis, slots, slotProps);
|
|
@@ -26,7 +26,7 @@ function DefaultChartsLegend(props) {
|
|
|
26
26
|
}
|
|
27
27
|
return /*#__PURE__*/_jsx(LegendPerItem, _extends({}, other, {
|
|
28
28
|
itemsToDisplay: seriesToDisplay,
|
|
29
|
-
onItemClick: onItemClick ? (
|
|
29
|
+
onItemClick: onItemClick ? (event, i) => onItemClick(event, seriesContextBuilder(seriesToDisplay[i]), i) : undefined
|
|
30
30
|
}));
|
|
31
31
|
}
|
|
32
32
|
process.env.NODE_ENV !== "production" ? DefaultChartsLegend.propTypes = {
|
|
@@ -122,7 +122,7 @@ export function LegendPerItem(props) {
|
|
|
122
122
|
markGap: markGap,
|
|
123
123
|
labelStyle: labelStyle,
|
|
124
124
|
classes: classes,
|
|
125
|
-
onClick: onItemClick ?
|
|
125
|
+
onClick: onItemClick ? event => onItemClick(event, i) : undefined
|
|
126
126
|
})))
|
|
127
127
|
})
|
|
128
128
|
});
|
|
@@ -80,7 +80,7 @@ function PiecewiseColorLegend(props) {
|
|
|
80
80
|
}).filter(notNull);
|
|
81
81
|
return /*#__PURE__*/_jsx(LegendPerItem, _extends({}, other, {
|
|
82
82
|
itemsToDisplay: itemsToDisplay,
|
|
83
|
-
onItemClick: onItemClick ? (
|
|
83
|
+
onItemClick: onItemClick ? (event, i) => onItemClick(event, piecewiseColorContextBuilder(itemsToDisplay[i]), i) : undefined
|
|
84
84
|
}));
|
|
85
85
|
}
|
|
86
86
|
process.env.NODE_ENV !== "production" ? PiecewiseColorLegend.propTypes = {
|
|
@@ -4,4 +4,7 @@ export * from "./ChartsAxisTooltipContent.js";
|
|
|
4
4
|
export * from "./ChartsItemTooltipContent.js";
|
|
5
5
|
export * from "./DefaultChartsAxisTooltipContent.js";
|
|
6
6
|
export * from "./DefaultChartsItemTooltipContent.js";
|
|
7
|
-
export * from "./ChartsTooltipTable.js";
|
|
7
|
+
export * from "./ChartsTooltipTable.js";
|
|
8
|
+
export * from "./useItemTooltip.js";
|
|
9
|
+
export * from "./useAxisTooltip.js";
|
|
10
|
+
export { useMouseTracker } from "./utils.js";
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { InteractionContext } from "../context/InteractionProvider.js";
|
|
5
|
+
import { useSeries } from "../hooks/useSeries.js";
|
|
6
|
+
import { useCartesianContext } from "../context/CartesianProvider/index.js";
|
|
7
|
+
import { ZAxisContext } from "../context/ZAxisContextProvider.js";
|
|
8
|
+
import { useColorProcessor } from "../context/PluginProvider/useColorProcessor.js";
|
|
9
|
+
import { getLabel } from "../internals/getLabel.js";
|
|
10
|
+
import { isCartesianSeriesType } from "../internals/isCartesian.js";
|
|
11
|
+
import { utcFormatter } from "./utils.js";
|
|
12
|
+
export function useAxisTooltip() {
|
|
13
|
+
const {
|
|
14
|
+
axis
|
|
15
|
+
} = React.useContext(InteractionContext);
|
|
16
|
+
const series = useSeries();
|
|
17
|
+
const {
|
|
18
|
+
xAxis,
|
|
19
|
+
yAxis,
|
|
20
|
+
xAxisIds,
|
|
21
|
+
yAxisIds
|
|
22
|
+
} = useCartesianContext();
|
|
23
|
+
const {
|
|
24
|
+
zAxis,
|
|
25
|
+
zAxisIds
|
|
26
|
+
} = React.useContext(ZAxisContext);
|
|
27
|
+
const colorProcessors = useColorProcessor();
|
|
28
|
+
|
|
29
|
+
// By default use the x-axis
|
|
30
|
+
const isXaxis = axis.x !== null && axis.x.index !== -1;
|
|
31
|
+
const axisData = isXaxis ? axis.x && axis.x : axis.y && axis.y;
|
|
32
|
+
if (axisData === null) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
const {
|
|
36
|
+
index: dataIndex,
|
|
37
|
+
value: axisValue
|
|
38
|
+
} = axisData;
|
|
39
|
+
const USED_AXIS_ID = isXaxis ? xAxisIds[0] : yAxisIds[0];
|
|
40
|
+
const usedAxis = isXaxis ? xAxis[USED_AXIS_ID] : yAxis[USED_AXIS_ID];
|
|
41
|
+
const relevantSeries = Object.keys(series).filter(isCartesianSeriesType).flatMap(seriesType => {
|
|
42
|
+
const seriesOfType = series[seriesType];
|
|
43
|
+
if (!seriesOfType) {
|
|
44
|
+
return [];
|
|
45
|
+
}
|
|
46
|
+
return seriesOfType.seriesOrder.map(seriesId => {
|
|
47
|
+
const seriesToAdd = seriesOfType.series[seriesId];
|
|
48
|
+
const providedXAxisId = seriesToAdd.xAxisId ?? seriesToAdd.xAxisKey;
|
|
49
|
+
const providedYAxisId = seriesToAdd.yAxisId ?? seriesToAdd.yAxisKey;
|
|
50
|
+
const axisKey = isXaxis ? providedXAxisId : providedYAxisId;
|
|
51
|
+
|
|
52
|
+
// Test if the series uses the default axis
|
|
53
|
+
if (axisKey === undefined || axisKey === USED_AXIS_ID) {
|
|
54
|
+
const xAxisId = providedXAxisId ?? xAxisIds[0];
|
|
55
|
+
const yAxisId = providedYAxisId ?? yAxisIds[0];
|
|
56
|
+
const zAxisId = seriesToAdd.zAxisId ?? seriesToAdd.zAxisKey ?? zAxisIds[0];
|
|
57
|
+
const color = colorProcessors[seriesType]?.(seriesToAdd, xAxis[xAxisId], yAxis[yAxisId], zAxisId && zAxis[zAxisId])(dataIndex) ?? '';
|
|
58
|
+
const value = seriesToAdd.data[dataIndex] ?? null;
|
|
59
|
+
const formattedValue = seriesToAdd.valueFormatter(value, {
|
|
60
|
+
dataIndex
|
|
61
|
+
});
|
|
62
|
+
const formattedLabel = getLabel(seriesToAdd.label, 'tooltip') ?? null;
|
|
63
|
+
return {
|
|
64
|
+
seriesId,
|
|
65
|
+
color,
|
|
66
|
+
value,
|
|
67
|
+
formattedValue,
|
|
68
|
+
formattedLabel
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
return undefined;
|
|
72
|
+
});
|
|
73
|
+
}).filter(item => item != null);
|
|
74
|
+
const axisFormatter = usedAxis.valueFormatter ?? (v => usedAxis.scaleType === 'utc' ? utcFormatter(v) : v.toLocaleString());
|
|
75
|
+
const axisFormattedValue = axisFormatter(axisValue, {
|
|
76
|
+
location: 'tooltip'
|
|
77
|
+
});
|
|
78
|
+
return {
|
|
79
|
+
identifier: axis,
|
|
80
|
+
seriesItems: relevantSeries,
|
|
81
|
+
axisValue,
|
|
82
|
+
axisFormattedValue
|
|
83
|
+
};
|
|
84
|
+
}
|