@mui/x-charts 8.0.0-beta.0 → 8.0.0-beta.2
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/seriesConfig/extremums.js +2 -2
- package/BarChart/useBarChartProps.d.ts +2 -1
- package/BarChart/useBarChartProps.js +20 -13
- package/CHANGELOG.md +171 -0
- package/ChartsAxisHighlight/ChartsXAxisHighlight.js +8 -8
- package/ChartsAxisHighlight/ChartsYAxisHighlight.js +8 -8
- package/ChartsOverlay/ChartsLoadingOverlay.js +1 -1
- package/ChartsOverlay/ChartsNoDataOverlay.js +1 -1
- package/ChartsTooltip/ChartsTooltipContainer.js +2 -1
- package/ChartsTooltip/useAxisTooltip.js +2 -2
- package/LineChart/CircleMarkElement.js +2 -2
- package/LineChart/LineHighlightPlot.js +2 -2
- package/LineChart/MarkElement.js +2 -2
- package/LineChart/useLineChartProps.d.ts +2 -1
- package/LineChart/useLineChartProps.js +7 -4
- package/RadarChart/RadarAxisHighlight/useRadarAxisHighlight.js +9 -5
- package/RadarChart/RadarGrid/RadarGrid.d.ts +1 -1
- package/RadarChart/RadarGrid/RadarGrid.js +5 -1
- package/RadarChart/RadarGrid/useRadarGridData.d.ts +1 -1
- package/RadarChart/RadarGrid/useRadarGridData.js +3 -0
- package/RadarChart/RadarSeriesPlot/useRadarSeriesData.js +2 -2
- package/ScatterChart/useScatterChartProps.d.ts +2 -1
- package/ScatterChart/useScatterChartProps.js +6 -3
- package/esm/BarChart/seriesConfig/extremums.js +2 -2
- package/esm/BarChart/useBarChartProps.d.ts +2 -1
- package/esm/BarChart/useBarChartProps.js +19 -13
- package/esm/ChartsAxisHighlight/ChartsXAxisHighlight.js +8 -8
- package/esm/ChartsAxisHighlight/ChartsYAxisHighlight.js +8 -8
- package/esm/ChartsOverlay/ChartsLoadingOverlay.js +1 -1
- package/esm/ChartsOverlay/ChartsNoDataOverlay.js +1 -1
- package/esm/ChartsTooltip/ChartsTooltipContainer.js +2 -1
- package/esm/ChartsTooltip/useAxisTooltip.js +1 -1
- package/esm/LineChart/CircleMarkElement.js +1 -1
- package/esm/LineChart/LineHighlightPlot.js +1 -1
- package/esm/LineChart/MarkElement.js +1 -1
- package/esm/LineChart/useLineChartProps.d.ts +2 -1
- package/esm/LineChart/useLineChartProps.js +6 -4
- package/esm/RadarChart/RadarAxisHighlight/useRadarAxisHighlight.js +9 -5
- package/esm/RadarChart/RadarGrid/RadarGrid.d.ts +1 -1
- package/esm/RadarChart/RadarGrid/RadarGrid.js +5 -1
- package/esm/RadarChart/RadarGrid/useRadarGridData.d.ts +1 -1
- package/esm/RadarChart/RadarGrid/useRadarGridData.js +3 -0
- package/esm/RadarChart/RadarSeriesPlot/useRadarSeriesData.js +2 -2
- package/esm/ScatterChart/useScatterChartProps.d.ts +2 -1
- package/esm/ScatterChart/useScatterChartProps.js +5 -3
- package/esm/hooks/useAxis.d.ts +5 -5
- package/esm/hooks/useInteractionItemProps.js +1 -1
- package/esm/hooks/useScale.d.ts +2 -2
- package/esm/hooks/useScale.js +2 -2
- package/esm/index.js +1 -1
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisValue.d.ts +8 -6
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisValue.js +28 -22
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/index.d.ts +1 -0
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/index.js +1 -0
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxis.js +10 -43
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianInteraction.selectors.d.ts +1 -0
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianInteraction.selectors.js +41 -0
- package/esm/internals/plugins/featurePlugins/useChartInteraction/useChartInteraction.js +7 -20
- package/esm/internals/plugins/featurePlugins/useChartInteraction/useChartInteraction.selectors.d.ts +36 -242
- package/esm/internals/plugins/featurePlugins/useChartInteraction/useChartInteraction.selectors.js +4 -10
- package/esm/internals/plugins/featurePlugins/useChartInteraction/useChartInteraction.types.d.ts +9 -15
- package/esm/internals/plugins/featurePlugins/useChartPolarAxis/coordinateTransformation.d.ts +12 -0
- package/esm/internals/plugins/featurePlugins/useChartPolarAxis/coordinateTransformation.js +8 -0
- package/esm/internals/plugins/featurePlugins/useChartPolarAxis/getAxisValue.d.ts +6 -4
- package/esm/internals/plugins/featurePlugins/useChartPolarAxis/getAxisValue.js +18 -13
- package/esm/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarAxis.js +17 -33
- package/esm/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarInteraction.selectors.d.ts +3669 -0
- package/esm/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarInteraction.selectors.js +22 -0
- package/hooks/useAxis.d.ts +5 -5
- package/hooks/useInteractionItemProps.js +1 -1
- package/hooks/useScale.d.ts +2 -2
- package/hooks/useScale.js +2 -2
- package/index.js +1 -1
- package/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisValue.d.ts +8 -6
- package/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisValue.js +29 -22
- package/internals/plugins/featurePlugins/useChartCartesianAxis/index.d.ts +1 -0
- package/internals/plugins/featurePlugins/useChartCartesianAxis/index.js +12 -0
- package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxis.js +8 -41
- package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianInteraction.selectors.d.ts +1 -0
- package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianInteraction.selectors.js +47 -0
- package/internals/plugins/featurePlugins/useChartInteraction/useChartInteraction.js +7 -20
- package/internals/plugins/featurePlugins/useChartInteraction/useChartInteraction.selectors.d.ts +36 -242
- package/internals/plugins/featurePlugins/useChartInteraction/useChartInteraction.selectors.js +5 -11
- package/internals/plugins/featurePlugins/useChartInteraction/useChartInteraction.types.d.ts +9 -15
- package/internals/plugins/featurePlugins/useChartPolarAxis/coordinateTransformation.d.ts +12 -0
- package/internals/plugins/featurePlugins/useChartPolarAxis/coordinateTransformation.js +17 -0
- package/internals/plugins/featurePlugins/useChartPolarAxis/getAxisValue.d.ts +6 -4
- package/internals/plugins/featurePlugins/useChartPolarAxis/getAxisValue.js +19 -13
- package/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarAxis.js +17 -33
- package/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarInteraction.selectors.d.ts +3669 -0
- package/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarInteraction.selectors.js +28 -0
- package/modern/BarChart/seriesConfig/extremums.js +2 -2
- package/modern/BarChart/useBarChartProps.d.ts +2 -1
- package/modern/BarChart/useBarChartProps.js +19 -13
- package/modern/ChartsAxisHighlight/ChartsXAxisHighlight.js +8 -8
- package/modern/ChartsAxisHighlight/ChartsYAxisHighlight.js +8 -8
- package/modern/ChartsOverlay/ChartsLoadingOverlay.js +1 -1
- package/modern/ChartsOverlay/ChartsNoDataOverlay.js +1 -1
- package/modern/ChartsTooltip/ChartsTooltipContainer.js +2 -1
- package/modern/ChartsTooltip/useAxisTooltip.js +1 -1
- package/modern/LineChart/CircleMarkElement.js +1 -1
- package/modern/LineChart/LineHighlightPlot.js +1 -1
- package/modern/LineChart/MarkElement.js +1 -1
- package/modern/LineChart/useLineChartProps.d.ts +2 -1
- package/modern/LineChart/useLineChartProps.js +6 -4
- package/modern/RadarChart/RadarAxisHighlight/useRadarAxisHighlight.js +9 -5
- package/modern/RadarChart/RadarGrid/RadarGrid.d.ts +1 -1
- package/modern/RadarChart/RadarGrid/RadarGrid.js +5 -1
- package/modern/RadarChart/RadarGrid/useRadarGridData.d.ts +1 -1
- package/modern/RadarChart/RadarGrid/useRadarGridData.js +3 -0
- package/modern/RadarChart/RadarSeriesPlot/useRadarSeriesData.js +2 -2
- package/modern/ScatterChart/useScatterChartProps.d.ts +2 -1
- package/modern/ScatterChart/useScatterChartProps.js +5 -3
- package/modern/hooks/useAxis.d.ts +5 -5
- package/modern/hooks/useInteractionItemProps.js +1 -1
- package/modern/hooks/useScale.d.ts +2 -2
- package/modern/hooks/useScale.js +2 -2
- package/modern/index.js +1 -1
- package/modern/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisValue.d.ts +8 -6
- package/modern/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisValue.js +28 -22
- package/modern/internals/plugins/featurePlugins/useChartCartesianAxis/index.d.ts +1 -0
- package/modern/internals/plugins/featurePlugins/useChartCartesianAxis/index.js +1 -0
- package/modern/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxis.js +10 -43
- package/modern/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianInteraction.selectors.d.ts +1 -0
- package/modern/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianInteraction.selectors.js +41 -0
- package/modern/internals/plugins/featurePlugins/useChartInteraction/useChartInteraction.js +7 -20
- package/modern/internals/plugins/featurePlugins/useChartInteraction/useChartInteraction.selectors.d.ts +36 -242
- package/modern/internals/plugins/featurePlugins/useChartInteraction/useChartInteraction.selectors.js +4 -10
- package/modern/internals/plugins/featurePlugins/useChartInteraction/useChartInteraction.types.d.ts +9 -15
- package/modern/internals/plugins/featurePlugins/useChartPolarAxis/coordinateTransformation.d.ts +12 -0
- package/modern/internals/plugins/featurePlugins/useChartPolarAxis/coordinateTransformation.js +8 -0
- package/modern/internals/plugins/featurePlugins/useChartPolarAxis/getAxisValue.d.ts +6 -4
- package/modern/internals/plugins/featurePlugins/useChartPolarAxis/getAxisValue.js +18 -13
- package/modern/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarAxis.js +17 -33
- package/modern/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarInteraction.selectors.d.ts +3669 -0
- package/modern/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarInteraction.selectors.js +22 -0
- package/package.json +3 -3
- package/tsconfig.build.tsbuildinfo +1 -1
|
@@ -2,12 +2,14 @@
|
|
|
2
2
|
'use client';
|
|
3
3
|
|
|
4
4
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
5
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
5
6
|
Object.defineProperty(exports, "__esModule", {
|
|
6
7
|
value: true
|
|
7
8
|
});
|
|
8
9
|
exports.useScatterChartProps = void 0;
|
|
9
10
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
10
11
|
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
|
|
12
|
+
var React = _interopRequireWildcard(require("react"));
|
|
11
13
|
var _ScatterChart = require("./ScatterChart.plugins");
|
|
12
14
|
const _excluded = ["xAxis", "yAxis", "zAxis", "series", "axisHighlight", "voronoiMaxRadius", "disableVoronoi", "hideLegend", "width", "height", "margin", "colors", "sx", "grid", "onItemClick", "children", "slots", "slotProps", "loading", "highlightedItem", "onHighlightChange", "className"];
|
|
13
15
|
/**
|
|
@@ -42,10 +44,11 @@ const useScatterChartProps = props => {
|
|
|
42
44
|
className
|
|
43
45
|
} = props,
|
|
44
46
|
other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
|
|
47
|
+
const seriesWithDefault = React.useMemo(() => series.map(s => (0, _extends2.default)({
|
|
48
|
+
type: 'scatter'
|
|
49
|
+
}, s)), [series]);
|
|
45
50
|
const chartContainerProps = (0, _extends2.default)({}, other, {
|
|
46
|
-
series:
|
|
47
|
-
type: 'scatter'
|
|
48
|
-
}, s)),
|
|
51
|
+
series: seriesWithDefault,
|
|
49
52
|
width,
|
|
50
53
|
height,
|
|
51
54
|
margin,
|
|
@@ -36,8 +36,8 @@ const getValueExtremum = direction => params => {
|
|
|
36
36
|
isDefaultAxis
|
|
37
37
|
} = params;
|
|
38
38
|
return Object.keys(series).filter(seriesId => {
|
|
39
|
-
const
|
|
40
|
-
return
|
|
39
|
+
const axisId = direction === 'x' ? series[seriesId].xAxisId : series[seriesId].yAxisId;
|
|
40
|
+
return axisId === axis.id || isDefaultAxis && axisId === undefined;
|
|
41
41
|
}).reduce((acc, seriesId) => {
|
|
42
42
|
const {
|
|
43
43
|
stackedData
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
1
2
|
import type { BarChartProps } from './BarChart';
|
|
2
3
|
import { ChartContainerProps } from "../ChartContainer/index.js";
|
|
3
4
|
import { BarPlotProps } from "./BarPlot.js";
|
|
@@ -29,5 +30,5 @@ export declare const useBarChartProps: (props: BarChartProps) => {
|
|
|
29
30
|
chartsAxisProps: ChartsAxisProps;
|
|
30
31
|
axisHighlightProps: ChartsAxisHighlightProps;
|
|
31
32
|
legendProps: ChartsLegendSlotExtension;
|
|
32
|
-
children:
|
|
33
|
+
children: React.ReactNode;
|
|
33
34
|
};
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
4
4
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
5
5
|
const _excluded = ["xAxis", "yAxis", "series", "width", "height", "margin", "colors", "dataset", "sx", "axisHighlight", "grid", "children", "slots", "slotProps", "skipAnimation", "loading", "layout", "onItemClick", "highlightedItem", "onHighlightChange", "borderRadius", "barLabel", "className", "hideLegend"];
|
|
6
|
+
import * as React from 'react';
|
|
6
7
|
import useId from '@mui/utils/useId';
|
|
7
8
|
import { DEFAULT_X_AXIS_KEY, DEFAULT_Y_AXIS_KEY } from "../constants/index.js";
|
|
8
9
|
import { BAR_CHART_PLUGINS } from "./BarChart.plugins.js";
|
|
@@ -44,29 +45,34 @@ export const useBarChartProps = props => {
|
|
|
44
45
|
const id = useId();
|
|
45
46
|
const clipPathId = `${id}-clip-path`;
|
|
46
47
|
const hasHorizontalSeries = layout === 'horizontal' || layout === undefined && series.some(item => item.layout === 'horizontal');
|
|
47
|
-
const
|
|
48
|
+
const defaultBandXAxis = React.useMemo(() => [{
|
|
49
|
+
id: DEFAULT_X_AXIS_KEY,
|
|
48
50
|
scaleType: 'band',
|
|
49
51
|
data: Array.from({
|
|
50
52
|
length: Math.max(...series.map(s => (s.data ?? dataset ?? []).length))
|
|
51
53
|
}, (_, index) => index)
|
|
52
|
-
};
|
|
54
|
+
}], [dataset, series]);
|
|
55
|
+
const defaultBandYAxis = React.useMemo(() => [{
|
|
56
|
+
id: DEFAULT_Y_AXIS_KEY,
|
|
57
|
+
scaleType: 'band',
|
|
58
|
+
data: Array.from({
|
|
59
|
+
length: Math.max(...series.map(s => (s.data ?? dataset ?? []).length))
|
|
60
|
+
}, (_, index) => index)
|
|
61
|
+
}], [dataset, series]);
|
|
62
|
+
const seriesWithDefault = React.useMemo(() => series.map(s => _extends({
|
|
63
|
+
type: 'bar'
|
|
64
|
+
}, s, {
|
|
65
|
+
layout: hasHorizontalSeries ? 'horizontal' : 'vertical'
|
|
66
|
+
})), [hasHorizontalSeries, series]);
|
|
53
67
|
const chartContainerProps = _extends({}, rest, {
|
|
54
|
-
series:
|
|
55
|
-
type: 'bar'
|
|
56
|
-
}, s, {
|
|
57
|
-
layout: hasHorizontalSeries ? 'horizontal' : 'vertical'
|
|
58
|
-
})),
|
|
68
|
+
series: seriesWithDefault,
|
|
59
69
|
width,
|
|
60
70
|
height,
|
|
61
71
|
margin,
|
|
62
72
|
colors,
|
|
63
73
|
dataset,
|
|
64
|
-
xAxis: xAxis ?? (hasHorizontalSeries ? undefined :
|
|
65
|
-
|
|
66
|
-
}, defaultAxisConfig)]),
|
|
67
|
-
yAxis: yAxis ?? (hasHorizontalSeries ? [_extends({
|
|
68
|
-
id: DEFAULT_Y_AXIS_KEY
|
|
69
|
-
}, defaultAxisConfig)] : undefined),
|
|
74
|
+
xAxis: xAxis ?? (hasHorizontalSeries ? undefined : defaultBandXAxis),
|
|
75
|
+
yAxis: yAxis ?? (hasHorizontalSeries ? defaultBandYAxis : undefined),
|
|
70
76
|
highlightedItem,
|
|
71
77
|
onHighlightChange,
|
|
72
78
|
disableAxisListener: slotProps?.tooltip?.trigger !== 'axis' && axisHighlight?.x === 'none' && axisHighlight?.y === 'none',
|
|
@@ -5,7 +5,7 @@ import { getValueToPositionMapper, useXScale } from "../hooks/useScale.js";
|
|
|
5
5
|
import { isBandScale } from "../internals/isBandScale.js";
|
|
6
6
|
import { useSelector } from "../internals/store/useSelector.js";
|
|
7
7
|
import { useStore } from "../internals/store/useStore.js";
|
|
8
|
-
import {
|
|
8
|
+
import { selectorChartsInteractionXAxisValue } from "../internals/plugins/featurePlugins/useChartCartesianAxis/index.js";
|
|
9
9
|
import { useDrawingArea } from "../hooks/index.js";
|
|
10
10
|
import { ChartsAxisHighlightPath } from "./ChartsAxisHighlightPath.js";
|
|
11
11
|
|
|
@@ -24,26 +24,26 @@ export default function ChartsXHighlight(props) {
|
|
|
24
24
|
} = useDrawingArea();
|
|
25
25
|
const xScale = useXScale();
|
|
26
26
|
const store = useStore();
|
|
27
|
-
const
|
|
27
|
+
const axisXValue = useSelector(store, selectorChartsInteractionXAxisValue);
|
|
28
28
|
const getXPosition = getValueToPositionMapper(xScale);
|
|
29
|
-
const isBandScaleX = type === 'band' &&
|
|
29
|
+
const isBandScaleX = type === 'band' && axisXValue !== null && isBandScale(xScale);
|
|
30
30
|
if (process.env.NODE_ENV !== 'production') {
|
|
31
|
-
const isError = isBandScaleX && xScale(
|
|
31
|
+
const isError = isBandScaleX && xScale(axisXValue) === undefined;
|
|
32
32
|
if (isError) {
|
|
33
33
|
console.error([`MUI X: The position value provided for the axis is not valid for the current scale.`, `This probably means something is wrong with the data passed to the chart.`, `The ChartsAxisHighlight component will not be displayed.`].join('\n'));
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
return /*#__PURE__*/_jsxs(React.Fragment, {
|
|
37
|
-
children: [isBandScaleX && xScale(
|
|
37
|
+
children: [isBandScaleX && xScale(axisXValue) !== undefined && /*#__PURE__*/_jsx(ChartsAxisHighlightPath
|
|
38
38
|
// @ts-expect-error, xScale value is checked in the statement above
|
|
39
39
|
, {
|
|
40
|
-
d: `M ${xScale(
|
|
40
|
+
d: `M ${xScale(axisXValue) - (xScale.step() - xScale.bandwidth()) / 2} ${top} l ${xScale.step()} 0 l 0 ${height} l ${-xScale.step()} 0 Z`,
|
|
41
41
|
className: classes.root,
|
|
42
42
|
ownerState: {
|
|
43
43
|
axisHighlight: 'band'
|
|
44
44
|
}
|
|
45
|
-
}), type === 'line' &&
|
|
46
|
-
d: `M ${getXPosition(
|
|
45
|
+
}), type === 'line' && axisXValue !== null && /*#__PURE__*/_jsx(ChartsAxisHighlightPath, {
|
|
46
|
+
d: `M ${getXPosition(axisXValue)} ${top} L ${getXPosition(axisXValue)} ${top + height}`,
|
|
47
47
|
className: classes.root,
|
|
48
48
|
ownerState: {
|
|
49
49
|
axisHighlight: 'line'
|
|
@@ -5,7 +5,7 @@ import { getValueToPositionMapper, useYScale } from "../hooks/useScale.js";
|
|
|
5
5
|
import { isBandScale } from "../internals/isBandScale.js";
|
|
6
6
|
import { useSelector } from "../internals/store/useSelector.js";
|
|
7
7
|
import { useStore } from "../internals/store/useStore.js";
|
|
8
|
-
import {
|
|
8
|
+
import { selectorChartsInteractionYAxisValue } from "../internals/plugins/featurePlugins/useChartCartesianAxis/index.js";
|
|
9
9
|
import { useDrawingArea } from "../hooks/index.js";
|
|
10
10
|
import { ChartsAxisHighlightPath } from "./ChartsAxisHighlightPath.js";
|
|
11
11
|
|
|
@@ -24,26 +24,26 @@ export default function ChartsYHighlight(props) {
|
|
|
24
24
|
} = useDrawingArea();
|
|
25
25
|
const yScale = useYScale();
|
|
26
26
|
const store = useStore();
|
|
27
|
-
const
|
|
27
|
+
const axisYValue = useSelector(store, selectorChartsInteractionYAxisValue);
|
|
28
28
|
const getYPosition = getValueToPositionMapper(yScale);
|
|
29
|
-
const isBandScaleY = type === 'band' &&
|
|
29
|
+
const isBandScaleY = type === 'band' && axisYValue !== null && isBandScale(yScale);
|
|
30
30
|
if (process.env.NODE_ENV !== 'production') {
|
|
31
|
-
const isError = isBandScaleY && yScale(
|
|
31
|
+
const isError = isBandScaleY && yScale(axisYValue) === undefined;
|
|
32
32
|
if (isError) {
|
|
33
33
|
console.error([`MUI X: The position value provided for the axis is not valid for the current scale.`, `This probably means something is wrong with the data passed to the chart.`, `The ChartsAxisHighlight component will not be displayed.`].join('\n'));
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
return /*#__PURE__*/_jsxs(React.Fragment, {
|
|
37
|
-
children: [isBandScaleY && yScale(
|
|
37
|
+
children: [isBandScaleY && yScale(axisYValue) !== undefined && /*#__PURE__*/_jsx(ChartsAxisHighlightPath, {
|
|
38
38
|
d: `M ${left} ${
|
|
39
39
|
// @ts-expect-error, yScale value is checked in the statement above
|
|
40
|
-
yScale(
|
|
40
|
+
yScale(axisYValue) - (yScale.step() - yScale.bandwidth()) / 2} l 0 ${yScale.step()} l ${width} 0 l 0 ${-yScale.step()} Z`,
|
|
41
41
|
className: classes.root,
|
|
42
42
|
ownerState: {
|
|
43
43
|
axisHighlight: 'band'
|
|
44
44
|
}
|
|
45
|
-
}), type === 'line' &&
|
|
46
|
-
d: `M ${left} ${getYPosition(
|
|
45
|
+
}), type === 'line' && axisYValue !== null && /*#__PURE__*/_jsx(ChartsAxisHighlightPath, {
|
|
46
|
+
d: `M ${left} ${getYPosition(axisYValue)} L ${left + width} ${getYPosition(axisYValue)}`,
|
|
47
47
|
className: classes.root,
|
|
48
48
|
ownerState: {
|
|
49
49
|
axisHighlight: 'line'
|
|
@@ -11,7 +11,7 @@ const StyledText = styled('text')(({
|
|
|
11
11
|
theme
|
|
12
12
|
}) => _extends({}, theme.typography.body2, {
|
|
13
13
|
stroke: 'none',
|
|
14
|
-
fill: theme.palette.text.primary,
|
|
14
|
+
fill: (theme.vars || theme).palette.text.primary,
|
|
15
15
|
shapeRendering: 'crispEdges',
|
|
16
16
|
textAnchor: 'middle',
|
|
17
17
|
dominantBaseline: 'middle'
|
|
@@ -11,7 +11,7 @@ const StyledText = styled('text')(({
|
|
|
11
11
|
theme
|
|
12
12
|
}) => _extends({}, theme.typography.body2, {
|
|
13
13
|
stroke: 'none',
|
|
14
|
-
fill: theme.palette.text.primary,
|
|
14
|
+
fill: (theme.vars || theme).palette.text.primary,
|
|
15
15
|
shapeRendering: 'crispEdges',
|
|
16
16
|
textAnchor: 'middle',
|
|
17
17
|
dominantBaseline: 'middle'
|
|
@@ -15,7 +15,8 @@ import { usePointerType } from "./utils.js";
|
|
|
15
15
|
import { useSelector } from "../internals/store/useSelector.js";
|
|
16
16
|
import { useStore } from "../internals/store/useStore.js";
|
|
17
17
|
import { useXAxis } from "../hooks/index.js";
|
|
18
|
-
import { selectorChartsInteractionItemIsDefined
|
|
18
|
+
import { selectorChartsInteractionItemIsDefined } from "../internals/plugins/featurePlugins/useChartInteraction/index.js";
|
|
19
|
+
import { selectorChartsInteractionXAxisIsDefined, selectorChartsInteractionYAxisIsDefined } from "../internals/plugins/featurePlugins/useChartCartesianAxis/index.js";
|
|
19
20
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
20
21
|
const ChartsTooltipRoot = styled(Popper, {
|
|
21
22
|
name: 'MuiChartsTooltip',
|
|
@@ -9,7 +9,7 @@ import { isCartesianSeriesType } from "../internals/isCartesian.js";
|
|
|
9
9
|
import { utcFormatter } from "./utils.js";
|
|
10
10
|
import { useXAxes, useXAxis, useYAxes, useYAxis } from "../hooks/useAxis.js";
|
|
11
11
|
import { useZAxes } from "../hooks/useZAxis.js";
|
|
12
|
-
import { selectorChartsInteractionXAxis, selectorChartsInteractionYAxis } from "../internals/plugins/featurePlugins/
|
|
12
|
+
import { selectorChartsInteractionXAxis, selectorChartsInteractionYAxis } from "../internals/plugins/featurePlugins/useChartCartesianAxis/index.js";
|
|
13
13
|
export function useAxisTooltip() {
|
|
14
14
|
const defaultXAxis = useXAxis();
|
|
15
15
|
const defaultYAxis = useYAxis();
|
|
@@ -11,7 +11,7 @@ import { useInteractionItemProps } from "../hooks/useInteractionItemProps.js";
|
|
|
11
11
|
import { useItemHighlighted } from "../hooks/useItemHighlighted.js";
|
|
12
12
|
import { useUtilityClasses } from "./markElementClasses.js";
|
|
13
13
|
import { useSelector } from "../internals/store/useSelector.js";
|
|
14
|
-
import { selectorChartsInteractionXAxis } from "../internals/plugins/featurePlugins/
|
|
14
|
+
import { selectorChartsInteractionXAxis } from "../internals/plugins/featurePlugins/useChartCartesianAxis/index.js";
|
|
15
15
|
import { useStore } from "../internals/store/useStore.js";
|
|
16
16
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
17
17
|
/**
|
|
@@ -13,7 +13,7 @@ import { DEFAULT_X_AXIS_KEY } from "../constants/index.js";
|
|
|
13
13
|
import { useLineSeriesContext } from "../hooks/useLineSeries.js";
|
|
14
14
|
import getColor from "./seriesConfig/getColor.js";
|
|
15
15
|
import { useChartContext } from "../context/ChartProvider/index.js";
|
|
16
|
-
import { selectorChartsInteractionXAxis } from "../internals/plugins/featurePlugins/
|
|
16
|
+
import { selectorChartsInteractionXAxis } from "../internals/plugins/featurePlugins/useChartCartesianAxis/index.js";
|
|
17
17
|
import { useXAxes, useYAxes } from "../hooks/useAxis.js";
|
|
18
18
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
19
19
|
/**
|
|
@@ -12,7 +12,7 @@ import { getSymbol } from "../internals/getSymbol.js";
|
|
|
12
12
|
import { useInteractionItemProps } from "../hooks/useInteractionItemProps.js";
|
|
13
13
|
import { useItemHighlighted } from "../hooks/useItemHighlighted.js";
|
|
14
14
|
import { useUtilityClasses } from "./markElementClasses.js";
|
|
15
|
-
import { selectorChartsInteractionXAxis } from "../internals/plugins/featurePlugins/
|
|
15
|
+
import { selectorChartsInteractionXAxis } from "../internals/plugins/featurePlugins/useChartCartesianAxis/index.js";
|
|
16
16
|
import { useSelector } from "../internals/store/useSelector.js";
|
|
17
17
|
import { useStore } from "../internals/store/useStore.js";
|
|
18
18
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
1
2
|
import { ChartsAxisProps } from "../ChartsAxis/index.js";
|
|
2
3
|
import { ChartsAxisHighlightProps } from "../ChartsAxisHighlight/index.js";
|
|
3
4
|
import { ChartsClipPathProps } from "../ChartsClipPath/index.js";
|
|
@@ -35,5 +36,5 @@ export declare const useLineChartProps: (props: LineChartProps) => {
|
|
|
35
36
|
axisHighlightProps: ChartsAxisHighlightProps;
|
|
36
37
|
lineHighlightPlotProps: LineHighlightPlotProps;
|
|
37
38
|
legendProps: ChartsLegendSlotExtension;
|
|
38
|
-
children:
|
|
39
|
+
children: React.ReactNode;
|
|
39
40
|
};
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
4
4
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
5
5
|
const _excluded = ["xAxis", "yAxis", "series", "width", "height", "margin", "colors", "dataset", "sx", "onAreaClick", "onLineClick", "onMarkClick", "axisHighlight", "disableLineItemHighlight", "hideLegend", "grid", "children", "slots", "slotProps", "skipAnimation", "loading", "highlightedItem", "onHighlightChange", "className"];
|
|
6
|
+
import * as React from 'react';
|
|
6
7
|
import useId from '@mui/utils/useId';
|
|
7
8
|
import { DEFAULT_X_AXIS_KEY } from "../constants/index.js";
|
|
8
9
|
import { LINE_CHART_PLUGINS } from "./LineChart.plugins.js";
|
|
@@ -43,11 +44,12 @@ export const useLineChartProps = props => {
|
|
|
43
44
|
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
44
45
|
const id = useId();
|
|
45
46
|
const clipPathId = `${id}-clip-path`;
|
|
47
|
+
const seriesWithDefault = React.useMemo(() => series.map(s => _extends({
|
|
48
|
+
disableHighlight: !!disableLineItemHighlight,
|
|
49
|
+
type: 'line'
|
|
50
|
+
}, s)), [disableLineItemHighlight, series]);
|
|
46
51
|
const chartContainerProps = _extends({}, other, {
|
|
47
|
-
series:
|
|
48
|
-
disableHighlight: !!disableLineItemHighlight,
|
|
49
|
-
type: 'line'
|
|
50
|
-
}, s)),
|
|
52
|
+
series: seriesWithDefault,
|
|
51
53
|
width,
|
|
52
54
|
height,
|
|
53
55
|
margin,
|
|
@@ -5,7 +5,7 @@ import { useSelector } from "../../internals/store/useSelector.js";
|
|
|
5
5
|
import { useStore } from "../../internals/store/useStore.js";
|
|
6
6
|
import { useChartContext } from "../../context/ChartProvider/useChartContext.js";
|
|
7
7
|
import { selectorChartPolarCenter } from "../../internals/plugins/featurePlugins/useChartPolarAxis/index.js";
|
|
8
|
-
import {
|
|
8
|
+
import { selectorChartsInteractionRotationAxisIndex, selectorChartsInteractionRotationAxisValue } from "../../internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarInteraction.selectors.js";
|
|
9
9
|
export function useRadarAxisHighlight(params) {
|
|
10
10
|
const {
|
|
11
11
|
includesNeighbors = false
|
|
@@ -20,10 +20,14 @@ export function useRadarAxisHighlight(params) {
|
|
|
20
20
|
instance
|
|
21
21
|
} = useChartContext();
|
|
22
22
|
const store = useStore();
|
|
23
|
-
const
|
|
23
|
+
const rotationAxisIndex = useSelector(store, selectorChartsInteractionRotationAxisIndex);
|
|
24
|
+
const rotationAxisValue = useSelector(store, selectorChartsInteractionRotationAxisValue);
|
|
24
25
|
const center = useSelector(store, selectorChartPolarCenter);
|
|
25
|
-
const highlightedIndex =
|
|
26
|
-
if (
|
|
26
|
+
const highlightedIndex = rotationAxisIndex;
|
|
27
|
+
if (!rotationScale) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
if (highlightedIndex === null || highlightedIndex === -1) {
|
|
27
31
|
return null;
|
|
28
32
|
}
|
|
29
33
|
if (radarSeries === undefined || radarSeries.length === 0) {
|
|
@@ -31,7 +35,7 @@ export function useRadarAxisHighlight(params) {
|
|
|
31
35
|
}
|
|
32
36
|
const metric = radiusAxisIds[highlightedIndex];
|
|
33
37
|
const radiusScale = radiusAxis[metric].scale;
|
|
34
|
-
const angle = rotationScale(
|
|
38
|
+
const angle = rotationScale(rotationAxisValue);
|
|
35
39
|
const radius = radiusScale.range()[1];
|
|
36
40
|
return {
|
|
37
41
|
center,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { RadarGridProps } from "./RadarGrid.types.js";
|
|
3
|
-
declare function RadarGrid(props: RadarGridProps): React.JSX.Element;
|
|
3
|
+
declare function RadarGrid(props: RadarGridProps): React.JSX.Element | null;
|
|
4
4
|
declare namespace RadarGrid {
|
|
5
5
|
var propTypes: any;
|
|
6
6
|
}
|
|
@@ -9,11 +9,15 @@ function RadarGrid(props) {
|
|
|
9
9
|
divisions = 5,
|
|
10
10
|
shape = 'sharp'
|
|
11
11
|
} = props;
|
|
12
|
+
const gridData = useRadarGridData();
|
|
13
|
+
if (gridData === null) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
12
16
|
const {
|
|
13
17
|
center,
|
|
14
18
|
corners,
|
|
15
19
|
radius
|
|
16
|
-
} =
|
|
20
|
+
} = gridData;
|
|
17
21
|
return shape === 'sharp' ? /*#__PURE__*/_jsx(SharpRadarGrid, {
|
|
18
22
|
divisions: divisions,
|
|
19
23
|
corners: corners,
|
|
@@ -13,6 +13,9 @@ export function useRadarGridData() {
|
|
|
13
13
|
const drawingArea = useDrawingArea();
|
|
14
14
|
const cx = drawingArea.left + drawingArea.width / 2;
|
|
15
15
|
const cy = drawingArea.top + drawingArea.height / 2;
|
|
16
|
+
if (!rotationScale || rotationScale.domain().length === 0) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
16
19
|
const metrics = rotationScale.domain();
|
|
17
20
|
const angles = metrics.map(key => rotationScale(key));
|
|
18
21
|
return {
|
|
@@ -23,8 +23,8 @@ export function useRadarSeriesData(querySeriesId) {
|
|
|
23
23
|
isFaded: isItemFaded,
|
|
24
24
|
isHighlighted: isItemHighlighted
|
|
25
25
|
} = useItemHighlightedGetter();
|
|
26
|
-
const metrics = rotationScale
|
|
27
|
-
const angles = metrics.map(key => rotationScale(key));
|
|
26
|
+
const metrics = rotationScale?.domain() ?? [];
|
|
27
|
+
const angles = metrics.map(key => rotationScale?.(key));
|
|
28
28
|
return radarSeries.map(series => {
|
|
29
29
|
const seriesId = series.id;
|
|
30
30
|
const isSeriesHighlighted = isItemHighlighted({
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
1
2
|
import { ChartsAxisProps } from "../ChartsAxis/index.js";
|
|
2
3
|
import { ChartsAxisHighlightProps } from "../ChartsAxisHighlight/index.js";
|
|
3
4
|
import { ChartsGridProps } from "../ChartsGrid/index.js";
|
|
@@ -24,5 +25,5 @@ export declare const useScatterChartProps: (props: ScatterChartProps) => {
|
|
|
24
25
|
overlayProps: ChartsOverlayProps;
|
|
25
26
|
legendProps: ChartsLegendSlotExtension;
|
|
26
27
|
axisHighlightProps: ChartsAxisHighlightProps;
|
|
27
|
-
children:
|
|
28
|
+
children: React.ReactNode;
|
|
28
29
|
};
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
4
4
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
5
5
|
const _excluded = ["xAxis", "yAxis", "zAxis", "series", "axisHighlight", "voronoiMaxRadius", "disableVoronoi", "hideLegend", "width", "height", "margin", "colors", "sx", "grid", "onItemClick", "children", "slots", "slotProps", "loading", "highlightedItem", "onHighlightChange", "className"];
|
|
6
|
+
import * as React from 'react';
|
|
6
7
|
import { SCATTER_CHART_PLUGINS } from "./ScatterChart.plugins.js";
|
|
7
8
|
/**
|
|
8
9
|
* A helper function that extracts ScatterChartProps from the input props
|
|
@@ -36,10 +37,11 @@ export const useScatterChartProps = props => {
|
|
|
36
37
|
className
|
|
37
38
|
} = props,
|
|
38
39
|
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
40
|
+
const seriesWithDefault = React.useMemo(() => series.map(s => _extends({
|
|
41
|
+
type: 'scatter'
|
|
42
|
+
}, s)), [series]);
|
|
39
43
|
const chartContainerProps = _extends({}, other, {
|
|
40
|
-
series:
|
|
41
|
-
type: 'scatter'
|
|
42
|
-
}, s)),
|
|
44
|
+
series: seriesWithDefault,
|
|
43
45
|
width,
|
|
44
46
|
height,
|
|
45
47
|
margin,
|
package/esm/hooks/useAxis.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AxisId } from "../models/axis.js";
|
|
1
|
+
import { AxisId, ChartsRadiusAxisProps, ChartsRotationAxisProps, PolarAxisDefaultized, ScaleName } from "../models/axis.js";
|
|
2
2
|
/**
|
|
3
3
|
* Get all the x-axes.
|
|
4
4
|
*
|
|
@@ -40,12 +40,12 @@ export declare function useXAxis(axisId?: AxisId): import("../internals").AxisDe
|
|
|
40
40
|
*/
|
|
41
41
|
export declare function useYAxis(axisId?: AxisId): import("../internals").AxisDefaultized<keyof import("../internals").AxisScaleConfig, any, import("..").ChartsYAxisProps>;
|
|
42
42
|
export declare function useRotationAxes(): {
|
|
43
|
-
rotationAxis: import("../internals/plugins/featurePlugins/useChartPolarAxis/computeAxisValue").DefaultizedAxisConfig<
|
|
43
|
+
rotationAxis: import("../internals/plugins/featurePlugins/useChartPolarAxis/computeAxisValue").DefaultizedAxisConfig<ChartsRotationAxisProps>;
|
|
44
44
|
rotationAxisIds: string[];
|
|
45
45
|
};
|
|
46
46
|
export declare function useRadiusAxes(): {
|
|
47
|
-
radiusAxis: import("../internals/plugins/featurePlugins/useChartPolarAxis/computeAxisValue").DefaultizedAxisConfig<
|
|
47
|
+
radiusAxis: import("../internals/plugins/featurePlugins/useChartPolarAxis/computeAxisValue").DefaultizedAxisConfig<ChartsRadiusAxisProps>;
|
|
48
48
|
radiusAxisIds: string[];
|
|
49
49
|
};
|
|
50
|
-
export declare function useRotationAxis(identifier?: number | string):
|
|
51
|
-
export declare function useRadiusAxis(identifier?: number | string):
|
|
50
|
+
export declare function useRotationAxis(identifier?: number | string): PolarAxisDefaultized<ScaleName, any, ChartsRotationAxisProps> | undefined;
|
|
51
|
+
export declare function useRadiusAxis(identifier?: number | string): PolarAxisDefaultized<ScaleName, any, ChartsRadiusAxisProps> | undefined;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import * as React from 'react';
|
|
4
4
|
import { useChartContext } from "../context/ChartProvider/index.js";
|
|
5
5
|
const onPointerDown = event => {
|
|
6
|
-
if (event.currentTarget.hasPointerCapture(event.pointerId)) {
|
|
6
|
+
if ('hasPointerCapture' in event.currentTarget && event.currentTarget.hasPointerCapture(event.pointerId)) {
|
|
7
7
|
event.currentTarget.releasePointerCapture(event.pointerId);
|
|
8
8
|
}
|
|
9
9
|
};
|
package/esm/hooks/useScale.d.ts
CHANGED
|
@@ -20,5 +20,5 @@ export declare function useXScale<S extends ScaleName>(axisId?: AxisId): AxisSca
|
|
|
20
20
|
* @returns {AxisScaleConfig[S]['scale']} The scale for the specified Y axis.
|
|
21
21
|
*/
|
|
22
22
|
export declare function useYScale<S extends ScaleName>(axisId?: AxisId): AxisScaleConfig[S]['scale'];
|
|
23
|
-
export declare function useRotationScale<S extends ScaleName>(identifier?: number | string): AxisScaleConfig[S]['scale'];
|
|
24
|
-
export declare function useRadiusScale<S extends ScaleName>(identifier?: number | string): AxisScaleConfig[S]['scale'];
|
|
23
|
+
export declare function useRotationScale<S extends ScaleName>(identifier?: number | string): AxisScaleConfig[S]['scale'] | undefined;
|
|
24
|
+
export declare function useRadiusScale<S extends ScaleName>(identifier?: number | string): AxisScaleConfig[S]['scale'] | undefined;
|
package/esm/hooks/useScale.js
CHANGED
|
@@ -39,9 +39,9 @@ export function useYScale(axisId) {
|
|
|
39
39
|
}
|
|
40
40
|
export function useRotationScale(identifier) {
|
|
41
41
|
const axis = useRotationAxis(identifier);
|
|
42
|
-
return axis
|
|
42
|
+
return axis?.scale;
|
|
43
43
|
}
|
|
44
44
|
export function useRadiusScale(identifier) {
|
|
45
45
|
const axis = useRadiusAxis(identifier);
|
|
46
|
-
return axis
|
|
46
|
+
return axis?.scale;
|
|
47
47
|
}
|
package/esm/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { AxisDefaultized } from "../../../../models/axis.js";
|
|
2
2
|
/**
|
|
3
|
-
* For a pointer coordinate, this function returns the
|
|
4
|
-
* Returns `
|
|
3
|
+
* For a pointer coordinate, this function returns the dataIndex associated.
|
|
4
|
+
* Returns `-1` if no dataIndex matches.
|
|
5
5
|
*/
|
|
6
|
-
export declare function
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
export declare function getAxisIndex(axisConfig: AxisDefaultized, pointerValue: number): number;
|
|
7
|
+
/**
|
|
8
|
+
* For a pointer coordinate, this function returns the value associated.
|
|
9
|
+
* Returns `null` if the coordinate has no value associated.
|
|
10
|
+
*/
|
|
11
|
+
export declare function getAxisValue(axisConfig: AxisDefaultized, pointerValue: number, dataIndex: number): number | Date | null;
|
|
@@ -4,10 +4,10 @@ function getAsANumber(value) {
|
|
|
4
4
|
}
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* For a pointer coordinate, this function returns the
|
|
8
|
-
* Returns `
|
|
7
|
+
* For a pointer coordinate, this function returns the dataIndex associated.
|
|
8
|
+
* Returns `-1` if no dataIndex matches.
|
|
9
9
|
*/
|
|
10
|
-
export function
|
|
10
|
+
export function getAxisIndex(axisConfig, pointerValue) {
|
|
11
11
|
const {
|
|
12
12
|
scale,
|
|
13
13
|
data: axisData,
|
|
@@ -16,10 +16,7 @@ export function getAxisValue(axisConfig, pointerValue) {
|
|
|
16
16
|
if (!isBandScale(scale)) {
|
|
17
17
|
const value = scale.invert(pointerValue);
|
|
18
18
|
if (axisData === undefined) {
|
|
19
|
-
return
|
|
20
|
-
value,
|
|
21
|
-
index: -1
|
|
22
|
-
};
|
|
19
|
+
return -1;
|
|
23
20
|
}
|
|
24
21
|
const valueAsNumber = getAsANumber(value);
|
|
25
22
|
const closestIndex = axisData?.findIndex((pointValue, index) => {
|
|
@@ -36,24 +33,33 @@ export function getAxisValue(axisConfig, pointerValue) {
|
|
|
36
33
|
}
|
|
37
34
|
return false;
|
|
38
35
|
});
|
|
39
|
-
return
|
|
40
|
-
value: closestIndex !== undefined && closestIndex >= 0 ? axisData[closestIndex] : value,
|
|
41
|
-
index: closestIndex
|
|
42
|
-
};
|
|
36
|
+
return closestIndex;
|
|
43
37
|
}
|
|
44
38
|
const dataIndex = scale.bandwidth() === 0 ? Math.floor((pointerValue - Math.min(...scale.range()) + scale.step() / 2) / scale.step()) : Math.floor((pointerValue - Math.min(...scale.range())) / scale.step());
|
|
45
39
|
if (dataIndex < 0 || dataIndex >= axisData.length) {
|
|
46
|
-
return
|
|
40
|
+
return -1;
|
|
41
|
+
}
|
|
42
|
+
return reverse ? axisData.length - 1 - dataIndex : dataIndex;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* For a pointer coordinate, this function returns the value associated.
|
|
47
|
+
* Returns `null` if the coordinate has no value associated.
|
|
48
|
+
*/
|
|
49
|
+
export function getAxisValue(axisConfig, pointerValue, dataIndex) {
|
|
50
|
+
const {
|
|
51
|
+
scale,
|
|
52
|
+
data: axisData
|
|
53
|
+
} = axisConfig;
|
|
54
|
+
if (!isBandScale(scale)) {
|
|
55
|
+
const value = scale.invert(pointerValue);
|
|
56
|
+
if (dataIndex < 0) {
|
|
57
|
+
return value;
|
|
58
|
+
}
|
|
59
|
+
return axisData[dataIndex];
|
|
47
60
|
}
|
|
48
|
-
if (
|
|
49
|
-
|
|
50
|
-
return {
|
|
51
|
-
index: reverseIndex,
|
|
52
|
-
value: axisData[reverseIndex]
|
|
53
|
-
};
|
|
61
|
+
if (dataIndex < 0 || dataIndex >= axisData.length) {
|
|
62
|
+
return null;
|
|
54
63
|
}
|
|
55
|
-
return
|
|
56
|
-
index: dataIndex,
|
|
57
|
-
value: axisData[dataIndex]
|
|
58
|
-
};
|
|
64
|
+
return axisData[dataIndex];
|
|
59
65
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { useChartCartesianAxis } from "./useChartCartesianAxis.js";
|
|
2
2
|
export type * from './useChartCartesianAxis.types';
|
|
3
3
|
export * from "./useChartCartesianAxisRendering.selectors.js";
|
|
4
|
+
export * from "./useChartCartesianInteraction.selectors.js";
|
|
4
5
|
export { defaultizeXAxis, defaultizeYAxis } from "./defaultizeAxis.js";
|
|
5
6
|
export * from "./computeAxisValue.js";
|
|
6
7
|
export * from "./createZoomLookup.js";
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { useChartCartesianAxis } from "./useChartCartesianAxis.js";
|
|
2
2
|
export * from "./useChartCartesianAxisRendering.selectors.js";
|
|
3
|
+
export * from "./useChartCartesianInteraction.selectors.js";
|
|
3
4
|
export { defaultizeXAxis, defaultizeYAxis } from "./defaultizeAxis.js";
|
|
4
5
|
export * from "./computeAxisValue.js";
|
|
5
6
|
export * from "./createZoomLookup.js";
|