@mui/x-charts 8.8.0 → 8.9.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.d.ts +3 -2
- package/BarChart/BarChart.js +1 -1
- package/BarChart/barClasses.d.ts +1 -1
- package/BarChart/seriesConfig/seriesProcessor.js +5 -3
- package/BarChart/useBarPlotData.js +32 -5
- package/CHANGELOG.md +101 -24
- package/ChartsLabel/ChartsLabelMark.d.ts +2 -1
- package/ChartsLabel/index.d.ts +1 -0
- package/ChartsLabel/index.js +18 -0
- package/ChartsLegend/chartsLegendClasses.d.ts +1 -1
- package/ChartsLegend/piecewiseColorLegendClasses.d.ts +1 -1
- package/LineChart/LineChart.d.ts +3 -2
- package/LineChart/LineChart.js +1 -1
- package/PieChart/PieArcLabelPlot.js +3 -0
- package/PieChart/PieArcPlot.js +3 -0
- package/PieChart/PieChart.d.ts +3 -2
- package/PieChart/PieChart.js +1 -1
- package/PieChart/pieClasses.d.ts +1 -1
- package/RadarChart/RadarAxisHighlight/RadarAxisHighlight.js +3 -5
- package/RadarChart/RadarAxisHighlight/useRadarAxisHighlight.d.ts +2 -13
- package/RadarChart/RadarAxisHighlight/useRadarAxisHighlight.js +8 -45
- package/RadarChart/RadarChart.d.ts +2 -1
- package/RadarChart/RadarChart.js +23 -2
- package/RadarChart/RadarDataProvider/RadarDataProvider.d.ts +3 -2
- package/RadarChart/RadarMetricLabels/useRadarMetricData.js +4 -2
- package/RadarChart/RadarSeriesPlot/RadarSeriesArea.js +19 -3
- package/RadarChart/RadarSeriesPlot/RadarSeriesMarks.js +20 -4
- package/RadarChart/RadarSeriesPlot/RadarSeriesPlot.js +38 -4
- package/RadarChart/RadarSeriesPlot/RadarSeriesPlot.types.d.ts +32 -3
- package/RadarChart/RadarSeriesPlot/useRadarRotationIndex.d.ts +8 -0
- package/RadarChart/RadarSeriesPlot/useRadarRotationIndex.js +38 -0
- package/RadarChart/RadarSeriesPlot/useRadarSeriesData.d.ts +2 -2
- package/RadarChart/index.d.ts +1 -1
- package/RadarChart/useRadarChartProps.d.ts +3 -0
- package/RadarChart/useRadarChartProps.js +15 -3
- package/ScatterChart/ScatterChart.d.ts +3 -2
- package/ScatterChart/ScatterChart.js +1 -1
- package/esm/BarChart/BarChart.d.ts +3 -2
- package/esm/BarChart/BarChart.js +1 -1
- package/esm/BarChart/barClasses.d.ts +1 -1
- package/esm/BarChart/seriesConfig/seriesProcessor.js +5 -3
- package/esm/BarChart/useBarPlotData.js +32 -5
- package/esm/ChartsLabel/ChartsLabelMark.d.ts +2 -1
- package/esm/ChartsLabel/index.d.ts +1 -0
- package/esm/ChartsLabel/index.js +1 -0
- package/esm/ChartsLegend/chartsLegendClasses.d.ts +1 -1
- package/esm/ChartsLegend/piecewiseColorLegendClasses.d.ts +1 -1
- package/esm/LineChart/LineChart.d.ts +3 -2
- package/esm/LineChart/LineChart.js +1 -1
- package/esm/PieChart/PieArcLabelPlot.js +3 -0
- package/esm/PieChart/PieArcPlot.js +3 -0
- package/esm/PieChart/PieChart.d.ts +3 -2
- package/esm/PieChart/PieChart.js +1 -1
- package/esm/PieChart/pieClasses.d.ts +1 -1
- package/esm/RadarChart/RadarAxisHighlight/RadarAxisHighlight.js +3 -5
- package/esm/RadarChart/RadarAxisHighlight/useRadarAxisHighlight.d.ts +2 -13
- package/esm/RadarChart/RadarAxisHighlight/useRadarAxisHighlight.js +8 -45
- package/esm/RadarChart/RadarChart.d.ts +2 -1
- package/esm/RadarChart/RadarChart.js +23 -2
- package/esm/RadarChart/RadarDataProvider/RadarDataProvider.d.ts +3 -2
- package/esm/RadarChart/RadarMetricLabels/useRadarMetricData.js +4 -2
- package/esm/RadarChart/RadarSeriesPlot/RadarSeriesArea.js +19 -3
- package/esm/RadarChart/RadarSeriesPlot/RadarSeriesMarks.js +20 -4
- package/esm/RadarChart/RadarSeriesPlot/RadarSeriesPlot.js +38 -4
- package/esm/RadarChart/RadarSeriesPlot/RadarSeriesPlot.types.d.ts +32 -3
- package/esm/RadarChart/RadarSeriesPlot/useRadarRotationIndex.d.ts +8 -0
- package/esm/RadarChart/RadarSeriesPlot/useRadarRotationIndex.js +32 -0
- package/esm/RadarChart/RadarSeriesPlot/useRadarSeriesData.d.ts +2 -2
- package/esm/RadarChart/index.d.ts +1 -1
- package/esm/RadarChart/useRadarChartProps.d.ts +3 -0
- package/esm/RadarChart/useRadarChartProps.js +15 -3
- package/esm/ScatterChart/ScatterChart.d.ts +3 -2
- package/esm/ScatterChart/ScatterChart.js +1 -1
- package/esm/hooks/useTicks.d.ts +6 -1
- package/esm/hooks/useTicks.js +94 -58
- package/esm/index.js +1 -1
- package/esm/internals/plugins/featurePlugins/useChartHighlight/createIsFaded.d.ts +1 -1
- package/esm/internals/plugins/featurePlugins/useChartHighlight/createIsFaded.js +19 -11
- package/esm/internals/plugins/featurePlugins/useChartHighlight/createIsHighlighted.d.ts +1 -1
- package/esm/internals/plugins/featurePlugins/useChartHighlight/createIsHighlighted.js +19 -11
- package/esm/internals/plugins/featurePlugins/useChartHighlight/useChartHighlight.selectors.js +10 -4
- package/esm/internals/plugins/featurePlugins/useChartInteraction/useChartInteraction.js +4 -4
- package/esm/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarAxis.js +44 -1
- package/esm/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarAxis.types.d.ts +8 -1
- package/esm/models/axis.d.ts +27 -1
- package/esm/models/seriesType/bar.d.ts +11 -1
- package/esm/models/seriesType/common.d.ts +9 -3
- package/esm/models/seriesType/line.d.ts +3 -1
- package/esm/models/seriesType/scatter.d.ts +4 -1
- package/esm/tests/web-components.js +49 -0
- package/hooks/useTicks.d.ts +6 -1
- package/hooks/useTicks.js +95 -58
- package/index.js +1 -1
- package/internals/plugins/featurePlugins/useChartHighlight/createIsFaded.d.ts +1 -1
- package/internals/plugins/featurePlugins/useChartHighlight/createIsFaded.js +20 -13
- package/internals/plugins/featurePlugins/useChartHighlight/createIsHighlighted.d.ts +1 -1
- package/internals/plugins/featurePlugins/useChartHighlight/createIsHighlighted.js +20 -13
- package/internals/plugins/featurePlugins/useChartHighlight/useChartHighlight.selectors.js +10 -4
- package/internals/plugins/featurePlugins/useChartInteraction/useChartInteraction.js +4 -4
- package/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarAxis.js +44 -1
- package/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarAxis.types.d.ts +8 -1
- package/models/axis.d.ts +27 -1
- package/models/seriesType/bar.d.ts +11 -1
- package/models/seriesType/common.d.ts +9 -3
- package/models/seriesType/line.d.ts +3 -1
- package/models/seriesType/scatter.d.ts +4 -1
- package/package.json +4 -4
- package/tests/web-components.js +55 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { RadarSeriesPlotClasses } from "./radarSeriesPlotClasses.js";
|
|
3
|
+
import { RadarItemIdentifier } from "../../models/seriesType/radar.js";
|
|
3
4
|
interface CommonRadarSeriesPlotProps {
|
|
4
5
|
/**
|
|
5
6
|
* The id of the series to display.
|
|
@@ -11,7 +12,35 @@ interface CommonRadarSeriesPlotProps {
|
|
|
11
12
|
*/
|
|
12
13
|
classes?: Partial<RadarSeriesPlotClasses>;
|
|
13
14
|
}
|
|
14
|
-
export interface RadarSeriesPlotProps extends CommonRadarSeriesPlotProps {
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
export interface RadarSeriesPlotProps extends CommonRadarSeriesPlotProps {
|
|
16
|
+
/**
|
|
17
|
+
* Callback fired when an area is clicked.
|
|
18
|
+
* @param {React.MouseEvent<SVGPathElement, MouseEvent>} event The event source of the callback.
|
|
19
|
+
* @param {RadarItemIdentifier} radarItemIdentifier The radar item identifier.
|
|
20
|
+
*/
|
|
21
|
+
onAreaClick?: RadarSeriesAreaProps['onItemClick'];
|
|
22
|
+
/**
|
|
23
|
+
* Callback fired when a mark is clicked.
|
|
24
|
+
* @param {React.MouseEvent<SVGPathElement, MouseEvent>} event The event source of the callback.
|
|
25
|
+
* @param {RadarItemIdentifier} radarItemIdentifier The radar item identifier.
|
|
26
|
+
*/
|
|
27
|
+
onMarkClick?: RadarSeriesMarksProps['onItemClick'];
|
|
28
|
+
}
|
|
29
|
+
type RadarClickIdentifier = Required<RadarItemIdentifier>;
|
|
30
|
+
export interface RadarSeriesMarksProps extends CommonRadarSeriesPlotProps, React.SVGAttributes<SVGCircleElement> {
|
|
31
|
+
/**
|
|
32
|
+
* Callback fired when a mark is clicked.
|
|
33
|
+
* @param {React.MouseEvent<SVGPathElement, MouseEvent>} event The event source of the callback.
|
|
34
|
+
* @param {RadarItemIdentifier} radarItemIdentifier The radar item identifier.
|
|
35
|
+
*/
|
|
36
|
+
onItemClick?: (event: React.MouseEvent<SVGElement, MouseEvent>, radarItemIdentifier: RadarClickIdentifier) => void;
|
|
37
|
+
}
|
|
38
|
+
export interface RadarSeriesAreaProps extends CommonRadarSeriesPlotProps, React.SVGAttributes<SVGPathElement> {
|
|
39
|
+
/**
|
|
40
|
+
* Callback fired when an area is clicked.
|
|
41
|
+
* @param {React.MouseEvent<SVGPathElement, MouseEvent>} event The event source of the callback.
|
|
42
|
+
* @param {RadarItemIdentifier} radarItemIdentifier The radar item identifier.
|
|
43
|
+
*/
|
|
44
|
+
onItemClick?: (event: React.MouseEvent<SVGElement, MouseEvent>, radarItemIdentifier: RadarClickIdentifier) => void;
|
|
45
|
+
}
|
|
17
46
|
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This hook provides a function that from pointer event returns the rotation index.
|
|
3
|
+
* @return {(event: { clientX: number; clientY: number }) => number | null} rotationIndexGetter Returns the rotation data index.
|
|
4
|
+
*/
|
|
5
|
+
export declare function useRadarRotationIndex(): (event: {
|
|
6
|
+
clientX: number;
|
|
7
|
+
clientY: number;
|
|
8
|
+
}) => number;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { selectorChartPolarCenter } from "../../internals/plugins/featurePlugins/useChartPolarAxis/index.js";
|
|
3
|
+
import { getSVGPoint } from "../../internals/getSVGPoint.js";
|
|
4
|
+
import { generateSvg2rotation } from "../../internals/plugins/featurePlugins/useChartPolarAxis/coordinateTransformation.js";
|
|
5
|
+
import { useSelector } from "../../internals/store/useSelector.js";
|
|
6
|
+
import { getAxisIndex } from "../../internals/plugins/featurePlugins/useChartPolarAxis/getAxisIndex.js";
|
|
7
|
+
import { useStore } from "../../internals/store/useStore.js";
|
|
8
|
+
import { useSvgRef } from "../../hooks/useSvgRef.js";
|
|
9
|
+
import { useRotationAxis } from "../../hooks/useAxis.js";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* This hook provides a function that from pointer event returns the rotation index.
|
|
13
|
+
* @return {(event: { clientX: number; clientY: number }) => number | null} rotationIndexGetter Returns the rotation data index.
|
|
14
|
+
*/
|
|
15
|
+
export function useRadarRotationIndex() {
|
|
16
|
+
const svgRef = useSvgRef();
|
|
17
|
+
const store = useStore();
|
|
18
|
+
const rotationAxis = useRotationAxis();
|
|
19
|
+
const center = useSelector(store, selectorChartPolarCenter);
|
|
20
|
+
const rotationIndexGetter = React.useCallback(function rotationIndexGetter(event) {
|
|
21
|
+
const element = svgRef.current;
|
|
22
|
+
if (!element || !rotationAxis) {
|
|
23
|
+
// Should never append
|
|
24
|
+
throw new Error(`MUI X Charts: The ${!element ? 'SVG' : 'rotation axis'} was not found to compute radar dataIndex.`);
|
|
25
|
+
}
|
|
26
|
+
const svgPoint = getSVGPoint(element, event);
|
|
27
|
+
const rotation = generateSvg2rotation(center)(svgPoint.x, svgPoint.y);
|
|
28
|
+
const rotationIndex = getAxisIndex(rotationAxis, rotation);
|
|
29
|
+
return rotationIndex;
|
|
30
|
+
}, [center, rotationAxis, svgRef]);
|
|
31
|
+
return rotationIndexGetter;
|
|
32
|
+
}
|
|
@@ -17,8 +17,8 @@ export declare function useRadarSeriesData(querySeriesId?: SeriesId): {
|
|
|
17
17
|
}[];
|
|
18
18
|
type: "radar";
|
|
19
19
|
label?: string | ((location: "tooltip" | "legend") => string) | undefined;
|
|
20
|
-
highlightScope?:
|
|
21
|
-
labelMarkType?:
|
|
20
|
+
highlightScope?: import("../../index.js").HighlightScope | undefined;
|
|
21
|
+
labelMarkType?: import("../../internals/index.js").ChartsLabelMarkType | undefined;
|
|
22
22
|
hideMark?: boolean | undefined;
|
|
23
23
|
fillArea?: boolean | undefined;
|
|
24
24
|
data: number[];
|
|
@@ -3,7 +3,7 @@ export { RadarChart } from "./RadarChart.js";
|
|
|
3
3
|
export { RadarDataProvider as Unstable_RadarDataProvider } from "./RadarDataProvider/index.js";
|
|
4
4
|
export { RadarDataProvider } from "./RadarDataProvider/index.js";
|
|
5
5
|
export type { RadarChartProps, RadarChartSlots, RadarChartSlotProps } from "./RadarChart.js";
|
|
6
|
-
export type { RadarDataProviderProps } from "./RadarDataProvider/index.js";
|
|
6
|
+
export type { RadarDataProviderProps, RadarSeries } from "./RadarDataProvider/index.js";
|
|
7
7
|
export * from "./RadarGrid/index.js";
|
|
8
8
|
export * from "./RadarAxisHighlight/index.js";
|
|
9
9
|
export * from "./RadarMetricLabels/index.js";
|
|
@@ -6,6 +6,7 @@ import { RadarDataProviderProps } from "./RadarDataProvider/RadarDataProvider.js
|
|
|
6
6
|
import { ChartsSurfaceProps } from "../ChartsSurface/index.js";
|
|
7
7
|
import { RadarGridProps } from "./RadarGrid/index.js";
|
|
8
8
|
import { RadarChartPluginsSignatures } from "./RadarChart.plugins.js";
|
|
9
|
+
import { RadarSeriesAreaProps, RadarSeriesMarksProps } from "./RadarSeriesPlot/index.js";
|
|
9
10
|
/**
|
|
10
11
|
* A helper function that extracts RadarChartProps from the input props
|
|
11
12
|
* and returns an object with props for the children components of RadarChart.
|
|
@@ -19,6 +20,8 @@ export declare const useRadarChartProps: (props: RadarChartProps) => {
|
|
|
19
20
|
chartsSurfaceProps: ChartsSurfaceProps;
|
|
20
21
|
radarDataProviderProps: RadarDataProviderProps<RadarChartPluginsSignatures>;
|
|
21
22
|
radarGrid: RadarGridProps;
|
|
23
|
+
radarSeriesAreaProps: RadarSeriesAreaProps;
|
|
24
|
+
radarSeriesMarksProps: RadarSeriesMarksProps;
|
|
22
25
|
overlayProps: ChartsOverlayProps;
|
|
23
26
|
legendProps: ChartsLegendSlotExtension;
|
|
24
27
|
children: import("react").ReactNode;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
4
|
-
const _excluded = ["apiRef", "series", "radar", "width", "height", "margin", "colors", "sx", "children", "slots", "slotProps", "skipAnimation", "loading", "highlightedItem", "onHighlightChange", "hideLegend", "divisions", "shape", "stripeColor", "highlight", "showToolbar"];
|
|
4
|
+
const _excluded = ["apiRef", "series", "radar", "width", "height", "margin", "colors", "sx", "children", "slots", "slotProps", "skipAnimation", "loading", "highlightedItem", "onHighlightChange", "hideLegend", "divisions", "shape", "stripeColor", "highlight", "showToolbar", "onAxisClick", "onAreaClick", "onMarkClick"];
|
|
5
5
|
/**
|
|
6
6
|
* A helper function that extracts RadarChartProps from the input props
|
|
7
7
|
* and returns an object with props for the children components of RadarChart.
|
|
@@ -29,7 +29,10 @@ export const useRadarChartProps = props => {
|
|
|
29
29
|
divisions,
|
|
30
30
|
shape,
|
|
31
31
|
stripeColor,
|
|
32
|
-
highlight = 'axis'
|
|
32
|
+
highlight = 'axis',
|
|
33
|
+
onAxisClick,
|
|
34
|
+
onAreaClick,
|
|
35
|
+
onMarkClick
|
|
33
36
|
} = props,
|
|
34
37
|
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
35
38
|
const radarDataProviderProps = {
|
|
@@ -43,7 +46,8 @@ export const useRadarChartProps = props => {
|
|
|
43
46
|
colors,
|
|
44
47
|
highlightedItem,
|
|
45
48
|
onHighlightChange,
|
|
46
|
-
skipAnimation
|
|
49
|
+
skipAnimation,
|
|
50
|
+
onAxisClick
|
|
47
51
|
};
|
|
48
52
|
const overlayProps = {
|
|
49
53
|
slots,
|
|
@@ -62,6 +66,12 @@ export const useRadarChartProps = props => {
|
|
|
62
66
|
shape,
|
|
63
67
|
stripeColor
|
|
64
68
|
};
|
|
69
|
+
const radarSeriesAreaProps = {
|
|
70
|
+
onItemClick: onAreaClick
|
|
71
|
+
};
|
|
72
|
+
const radarSeriesMarksProps = {
|
|
73
|
+
onItemClick: onMarkClick
|
|
74
|
+
};
|
|
65
75
|
const chartsSurfaceProps = other;
|
|
66
76
|
return {
|
|
67
77
|
highlight,
|
|
@@ -69,6 +79,8 @@ export const useRadarChartProps = props => {
|
|
|
69
79
|
chartsSurfaceProps,
|
|
70
80
|
radarDataProviderProps,
|
|
71
81
|
radarGrid,
|
|
82
|
+
radarSeriesAreaProps,
|
|
83
|
+
radarSeriesMarksProps,
|
|
72
84
|
overlayProps,
|
|
73
85
|
legendProps,
|
|
74
86
|
children
|
|
@@ -16,12 +16,13 @@ import { UseChartVoronoiSignature } from "../internals/plugins/featurePlugins/us
|
|
|
16
16
|
import { ScatterChartPluginsSignatures } from "./ScatterChart.plugins.js";
|
|
17
17
|
export interface ScatterChartSlots extends ChartsAxisSlots, ScatterPlotSlots, ChartsLegendSlots, ChartsOverlaySlots, ChartsTooltipSlots, ChartsToolbarSlots, Partial<ChartsSlots> {}
|
|
18
18
|
export interface ScatterChartSlotProps extends ChartsAxisSlotProps, ScatterPlotSlotProps, ChartsLegendSlotProps, ChartsOverlaySlotProps, ChartsTooltipSlotProps, ChartsToolbarSlotProps, Partial<ChartsSlotProps> {}
|
|
19
|
+
export type ScatterSeries = MakeOptional<ScatterSeriesType, 'type'>;
|
|
19
20
|
export interface ScatterChartProps extends Omit<ChartContainerProps<'scatter', ScatterChartPluginsSignatures>, 'series' | 'plugins' | 'onItemClick' | 'experimentalFeatures' | 'highlightedAxis' | 'onHighlightedAxisChange'>, Omit<ChartsAxisProps, 'slots' | 'slotProps'>, Omit<ChartsOverlayProps, 'slots' | 'slotProps'> {
|
|
20
21
|
/**
|
|
21
22
|
* The series to display in the scatter chart.
|
|
22
|
-
* An array of [[
|
|
23
|
+
* An array of [[ScatterSeries]] objects.
|
|
23
24
|
*/
|
|
24
|
-
series: Readonly<
|
|
25
|
+
series: Readonly<ScatterSeries[]>;
|
|
25
26
|
/**
|
|
26
27
|
* The configuration of axes highlight.
|
|
27
28
|
* @see See {@link https://mui.com/x/react-charts/highlighting/ highlighting docs} for more details.
|
|
@@ -173,7 +173,7 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
|
|
|
173
173
|
onItemClick: PropTypes.func,
|
|
174
174
|
/**
|
|
175
175
|
* The series to display in the scatter chart.
|
|
176
|
-
* An array of [[
|
|
176
|
+
* An array of [[ScatterSeries]] objects.
|
|
177
177
|
*/
|
|
178
178
|
series: PropTypes.arrayOf(PropTypes.object).isRequired,
|
|
179
179
|
/**
|
package/esm/hooks/useTicks.d.ts
CHANGED
|
@@ -49,8 +49,13 @@ export type TickItemType = {
|
|
|
49
49
|
offset: number;
|
|
50
50
|
labelOffset: number;
|
|
51
51
|
};
|
|
52
|
+
export declare function getTicks(options: {
|
|
53
|
+
scale: D3Scale;
|
|
54
|
+
valueFormatter?: AxisConfig['valueFormatter'];
|
|
55
|
+
isInside: (offset: number) => boolean;
|
|
56
|
+
} & Pick<TickParams, 'tickInterval' | 'tickPlacement' | 'tickLabelPlacement'> & Required<Pick<TickParams, 'tickNumber'>>): TickItemType[];
|
|
52
57
|
export declare function useTicks(options: {
|
|
53
58
|
scale: D3Scale;
|
|
54
59
|
valueFormatter?: AxisConfig['valueFormatter'];
|
|
55
60
|
direction: 'x' | 'y';
|
|
56
|
-
} & Pick<TickParams, '
|
|
61
|
+
} & Pick<TickParams, 'tickInterval' | 'tickPlacement' | 'tickLabelPlacement'> & Required<Pick<TickParams, 'tickNumber'>>): TickItemType[];
|
package/esm/hooks/useTicks.js
CHANGED
|
@@ -10,7 +10,7 @@ const offsetRatio = {
|
|
|
10
10
|
end: 1,
|
|
11
11
|
middle: 0.5
|
|
12
12
|
};
|
|
13
|
-
export function
|
|
13
|
+
export function getTicks(options) {
|
|
14
14
|
const {
|
|
15
15
|
scale,
|
|
16
16
|
tickNumber,
|
|
@@ -18,75 +18,111 @@ export function useTicks(options) {
|
|
|
18
18
|
tickInterval,
|
|
19
19
|
tickPlacement = 'extremities',
|
|
20
20
|
tickLabelPlacement: tickLabelPlacementProp,
|
|
21
|
-
|
|
21
|
+
isInside
|
|
22
22
|
} = options;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if (
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return [...filteredDomain.map(value => ({
|
|
23
|
+
|
|
24
|
+
// band scale
|
|
25
|
+
if (isBandScale(scale)) {
|
|
26
|
+
const domain = scale.domain();
|
|
27
|
+
const tickLabelPlacement = tickLabelPlacementProp ?? 'middle';
|
|
28
|
+
if (scale.bandwidth() > 0) {
|
|
29
|
+
// scale type = 'band'
|
|
30
|
+
const filteredDomain = typeof tickInterval === 'function' && domain.filter(tickInterval) || typeof tickInterval === 'object' && tickInterval || domain;
|
|
31
|
+
return [...filteredDomain.map(value => {
|
|
32
|
+
const defaultTickLabel = `${value}`;
|
|
33
|
+
return {
|
|
35
34
|
value,
|
|
36
35
|
formattedValue: valueFormatter?.(value, {
|
|
37
36
|
location: 'tick',
|
|
38
|
-
scale
|
|
39
|
-
|
|
37
|
+
scale,
|
|
38
|
+
tickNumber,
|
|
39
|
+
defaultTickLabel
|
|
40
|
+
}) ?? defaultTickLabel,
|
|
40
41
|
offset: scale(value) - (scale.step() - scale.bandwidth()) / 2 + offsetRatio[tickPlacement] * scale.step(),
|
|
41
42
|
labelOffset: tickLabelPlacement === 'tick' ? 0 : scale.step() * (offsetRatio[tickLabelPlacement] - offsetRatio[tickPlacement])
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
43
|
+
};
|
|
44
|
+
}), ...(tickPlacement === 'extremities' ? [{
|
|
45
|
+
formattedValue: undefined,
|
|
46
|
+
offset: scale.range()[1],
|
|
47
|
+
labelOffset: 0
|
|
48
|
+
}] : [])];
|
|
49
|
+
}
|
|
48
50
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
51
|
+
// scale type = 'point'
|
|
52
|
+
const filteredDomain = typeof tickInterval === 'function' && domain.filter(tickInterval) || typeof tickInterval === 'object' && tickInterval || domain;
|
|
53
|
+
return filteredDomain.map(value => {
|
|
54
|
+
const defaultTickLabel = `${value}`;
|
|
55
|
+
return {
|
|
52
56
|
value,
|
|
53
57
|
formattedValue: valueFormatter?.(value, {
|
|
54
58
|
location: 'tick',
|
|
55
|
-
scale
|
|
56
|
-
|
|
59
|
+
scale,
|
|
60
|
+
tickNumber,
|
|
61
|
+
defaultTickLabel
|
|
62
|
+
}) ?? defaultTickLabel,
|
|
57
63
|
offset: scale(value),
|
|
58
64
|
labelOffset: 0
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
65
|
+
};
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
const domain = scale.domain();
|
|
69
|
+
// Skip axis rendering if no data is available
|
|
70
|
+
// - The domains contains Infinity for continuous scales.
|
|
71
|
+
if (domain.some(isInfinity)) {
|
|
72
|
+
return [];
|
|
73
|
+
}
|
|
74
|
+
const tickLabelPlacement = tickLabelPlacementProp;
|
|
75
|
+
const ticks = typeof tickInterval === 'object' ? tickInterval : scale.ticks(tickNumber);
|
|
69
76
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
77
|
+
// Ticks inside the drawing area
|
|
78
|
+
const visibleTicks = [];
|
|
79
|
+
for (let i = 0; i < ticks.length; i += 1) {
|
|
80
|
+
const value = ticks[i];
|
|
81
|
+
const offset = scale(value);
|
|
82
|
+
if (isInside(offset)) {
|
|
83
|
+
/* If d3 returns an empty string, it means that a tick should be shown, but its label shouldn't.
|
|
84
|
+
* This is especially useful in a log scale where we want to show ticks to demonstrate it's a log
|
|
85
|
+
* scale, but don't want to show labels because they would overlap.
|
|
86
|
+
* https://github.com/mui/mui-x/issues/18239 */
|
|
87
|
+
const defaultTickLabel = scale.tickFormat(tickNumber)(value);
|
|
88
|
+
visibleTicks.push({
|
|
89
|
+
value,
|
|
90
|
+
formattedValue: valueFormatter?.(value, {
|
|
91
|
+
location: 'tick',
|
|
92
|
+
scale,
|
|
93
|
+
tickNumber,
|
|
94
|
+
defaultTickLabel
|
|
95
|
+
}) ?? defaultTickLabel,
|
|
96
|
+
offset,
|
|
97
|
+
// Allowing the label to be placed in the middle of a continuous scale is weird.
|
|
98
|
+
// But it is useful in some cases, like funnel categories with a linear scale.
|
|
99
|
+
labelOffset: tickLabelPlacement === 'middle' ? scale(ticks[i - 1] ?? 0) - (offset + scale(ticks[i - 1] ?? 0)) / 2 : 0
|
|
100
|
+
});
|
|
89
101
|
}
|
|
90
|
-
|
|
91
|
-
|
|
102
|
+
}
|
|
103
|
+
return visibleTicks;
|
|
104
|
+
}
|
|
105
|
+
export function useTicks(options) {
|
|
106
|
+
const {
|
|
107
|
+
scale,
|
|
108
|
+
tickNumber,
|
|
109
|
+
valueFormatter,
|
|
110
|
+
tickInterval,
|
|
111
|
+
tickPlacement = 'extremities',
|
|
112
|
+
tickLabelPlacement,
|
|
113
|
+
direction
|
|
114
|
+
} = options;
|
|
115
|
+
const {
|
|
116
|
+
instance
|
|
117
|
+
} = useChartContext();
|
|
118
|
+
const isInside = direction === 'x' ? instance.isXInside : instance.isYInside;
|
|
119
|
+
return React.useMemo(() => getTicks({
|
|
120
|
+
scale,
|
|
121
|
+
tickNumber,
|
|
122
|
+
tickPlacement,
|
|
123
|
+
tickInterval,
|
|
124
|
+
tickLabelPlacement,
|
|
125
|
+
valueFormatter,
|
|
126
|
+
isInside
|
|
127
|
+
}), [scale, tickNumber, tickPlacement, tickInterval, tickLabelPlacement, valueFormatter, isInside]);
|
|
92
128
|
}
|
package/esm/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { HighlightScope } from "./highlightConfig.types.js";
|
|
2
2
|
import { HighlightItemData } from "./useChartHighlight.types.js";
|
|
3
|
-
export declare
|
|
3
|
+
export declare function createIsFaded(highlightScope: HighlightScope | null | undefined, highlightedItem: HighlightItemData | null): (item: HighlightItemData | null) => boolean;
|
|
@@ -1,12 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
if (!highlightScope || !highlightedItem || !item) {
|
|
3
|
-
return false;
|
|
4
|
-
}
|
|
5
|
-
if (highlightScope.fade === 'series') {
|
|
6
|
-
return item.seriesId === highlightedItem.seriesId && item.dataIndex !== highlightedItem.dataIndex;
|
|
7
|
-
}
|
|
8
|
-
if (highlightScope.fade === 'global') {
|
|
9
|
-
return item.seriesId !== highlightedItem.seriesId || item.dataIndex !== highlightedItem.dataIndex;
|
|
10
|
-
}
|
|
1
|
+
function alwaysFalse() {
|
|
11
2
|
return false;
|
|
12
|
-
}
|
|
3
|
+
}
|
|
4
|
+
export function createIsFaded(highlightScope, highlightedItem) {
|
|
5
|
+
if (!highlightScope || !highlightedItem) {
|
|
6
|
+
return alwaysFalse;
|
|
7
|
+
}
|
|
8
|
+
return function isFaded(item) {
|
|
9
|
+
if (!item) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
if (highlightScope.fade === 'series') {
|
|
13
|
+
return item.seriesId === highlightedItem.seriesId && item.dataIndex !== highlightedItem.dataIndex;
|
|
14
|
+
}
|
|
15
|
+
if (highlightScope.fade === 'global') {
|
|
16
|
+
return item.seriesId !== highlightedItem.seriesId || item.dataIndex !== highlightedItem.dataIndex;
|
|
17
|
+
}
|
|
18
|
+
return false;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { HighlightScope } from "./highlightConfig.types.js";
|
|
2
2
|
import { HighlightItemData } from "./useChartHighlight.types.js";
|
|
3
|
-
export declare
|
|
3
|
+
export declare function createIsHighlighted(highlightScope: HighlightScope | null | undefined, highlightedItem: HighlightItemData | null): (item: HighlightItemData | null) => boolean;
|
|
@@ -1,12 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
if (!highlightScope || !highlightedItem || !item) {
|
|
3
|
-
return false;
|
|
4
|
-
}
|
|
5
|
-
if (highlightScope.highlight === 'series') {
|
|
6
|
-
return item.seriesId === highlightedItem.seriesId;
|
|
7
|
-
}
|
|
8
|
-
if (highlightScope.highlight === 'item') {
|
|
9
|
-
return item.dataIndex === highlightedItem.dataIndex && item.seriesId === highlightedItem.seriesId;
|
|
10
|
-
}
|
|
1
|
+
function alwaysFalse() {
|
|
11
2
|
return false;
|
|
12
|
-
}
|
|
3
|
+
}
|
|
4
|
+
export function createIsHighlighted(highlightScope, highlightedItem) {
|
|
5
|
+
if (!highlightScope || !highlightedItem) {
|
|
6
|
+
return alwaysFalse;
|
|
7
|
+
}
|
|
8
|
+
return function isHighlighted(item) {
|
|
9
|
+
if (!item) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
if (highlightScope.highlight === 'series') {
|
|
13
|
+
return item.seriesId === highlightedItem.seriesId;
|
|
14
|
+
}
|
|
15
|
+
if (highlightScope.highlight === 'item') {
|
|
16
|
+
return item.dataIndex === highlightedItem.dataIndex && item.seriesId === highlightedItem.seriesId;
|
|
17
|
+
}
|
|
18
|
+
return false;
|
|
19
|
+
};
|
|
20
|
+
}
|
package/esm/internals/plugins/featurePlugins/useChartHighlight/useChartHighlight.selectors.js
CHANGED
|
@@ -14,8 +14,10 @@ export const selectorChartsHighlightScopePerSeriesId = createSelector([selectSer
|
|
|
14
14
|
});
|
|
15
15
|
return map;
|
|
16
16
|
});
|
|
17
|
-
export const selectorChartsHighlightedItem = createSelector([selectHighlight],
|
|
18
|
-
|
|
17
|
+
export const selectorChartsHighlightedItem = createSelector([selectHighlight], function selectorChartsHighlightedItem(highlight) {
|
|
18
|
+
return highlight.item;
|
|
19
|
+
});
|
|
20
|
+
export const selectorChartsHighlightScope = createSelector([selectorChartsHighlightScopePerSeriesId, selectorChartsHighlightedItem], function selectorChartsHighlightScope(seriesIdToHighlightScope, highlightedItem) {
|
|
19
21
|
if (!highlightedItem) {
|
|
20
22
|
return null;
|
|
21
23
|
}
|
|
@@ -27,5 +29,9 @@ export const selectorChartsHighlightScope = createSelector([selectorChartsHighli
|
|
|
27
29
|
});
|
|
28
30
|
export const selectorChartsIsHighlightedCallback = createSelector([selectorChartsHighlightScope, selectorChartsHighlightedItem], createIsHighlighted);
|
|
29
31
|
export const selectorChartsIsFadedCallback = createSelector([selectorChartsHighlightScope, selectorChartsHighlightedItem], createIsFaded);
|
|
30
|
-
export const selectorChartsIsHighlighted = createSelector([selectorChartsHighlightScope, selectorChartsHighlightedItem, (_, item) => item], (highlightScope, highlightedItem, item)
|
|
31
|
-
|
|
32
|
+
export const selectorChartsIsHighlighted = createSelector([selectorChartsHighlightScope, selectorChartsHighlightedItem, (_, item) => item], function selectorChartsIsHighlighted(highlightScope, highlightedItem, item) {
|
|
33
|
+
return createIsHighlighted(highlightScope, highlightedItem)(item);
|
|
34
|
+
});
|
|
35
|
+
export const selectorChartsIsFaded = createSelector([selectorChartsHighlightScope, selectorChartsHighlightedItem, (_, item) => item], function selectorChartsIsFaded(highlightScope, highlightedItem, item) {
|
|
36
|
+
return createIsFaded(highlightScope, highlightedItem)(item);
|
|
37
|
+
});
|
|
@@ -4,7 +4,7 @@ import { fastObjectShallowCompare } from '@mui/x-internals/fastObjectShallowComp
|
|
|
4
4
|
export const useChartInteraction = ({
|
|
5
5
|
store
|
|
6
6
|
}) => {
|
|
7
|
-
const cleanInteraction = useEventCallback(()
|
|
7
|
+
const cleanInteraction = useEventCallback(function cleanInteraction() {
|
|
8
8
|
store.update(prev => {
|
|
9
9
|
return _extends({}, prev, {
|
|
10
10
|
interaction: {
|
|
@@ -14,7 +14,7 @@ export const useChartInteraction = ({
|
|
|
14
14
|
});
|
|
15
15
|
});
|
|
16
16
|
});
|
|
17
|
-
const removeItemInteraction = useEventCallback(itemToRemove
|
|
17
|
+
const removeItemInteraction = useEventCallback(function removeItemInteraction(itemToRemove) {
|
|
18
18
|
store.update(prev => {
|
|
19
19
|
const prevItem = prev.interaction.item;
|
|
20
20
|
if (!itemToRemove) {
|
|
@@ -36,7 +36,7 @@ export const useChartInteraction = ({
|
|
|
36
36
|
});
|
|
37
37
|
});
|
|
38
38
|
});
|
|
39
|
-
const setItemInteraction = useEventCallback(newItem
|
|
39
|
+
const setItemInteraction = useEventCallback(function setItemInteraction(newItem) {
|
|
40
40
|
store.update(prev => {
|
|
41
41
|
if (fastObjectShallowCompare(prev.interaction.item, newItem)) {
|
|
42
42
|
return prev;
|
|
@@ -48,7 +48,7 @@ export const useChartInteraction = ({
|
|
|
48
48
|
});
|
|
49
49
|
});
|
|
50
50
|
});
|
|
51
|
-
const setPointerCoordinate = useEventCallback(coordinate
|
|
51
|
+
const setPointerCoordinate = useEventCallback(function setPointerCoordinate(coordinate) {
|
|
52
52
|
store.update(prev => _extends({}, prev, {
|
|
53
53
|
interaction: _extends({}, prev.interaction, {
|
|
54
54
|
pointer: coordinate
|
|
@@ -10,6 +10,8 @@ import { selectorChartsInteractionIsInitialized } from "../useChartInteraction/i
|
|
|
10
10
|
import { selectorChartPolarCenter, selectorChartRadiusAxis, selectorChartRotationAxis } from "./useChartPolarAxis.selectors.js";
|
|
11
11
|
import { getSVGPoint } from "../../../getSVGPoint.js";
|
|
12
12
|
import { generatePolar2svg, generateSvg2polar, generateSvg2rotation } from "./coordinateTransformation.js";
|
|
13
|
+
import { getAxisIndex } from "./getAxisIndex.js";
|
|
14
|
+
import { selectorChartSeriesProcessed } from "../../corePlugins/useChartSeries/index.js";
|
|
13
15
|
export const useChartPolarAxis = ({
|
|
14
16
|
params,
|
|
15
17
|
store,
|
|
@@ -30,6 +32,7 @@ export const useChartPolarAxis = ({
|
|
|
30
32
|
}
|
|
31
33
|
}
|
|
32
34
|
const drawingArea = useSelector(store, selectorChartDrawingArea);
|
|
35
|
+
const processedSeries = useSelector(store, selectorChartSeriesProcessed);
|
|
33
36
|
const center = useSelector(store, selectorChartPolarCenter);
|
|
34
37
|
const isInteractionEnabled = useSelector(store, selectorChartsInteractionIsInitialized);
|
|
35
38
|
const {
|
|
@@ -156,6 +159,45 @@ export const useChartPolarAxis = ({
|
|
|
156
159
|
pressEndHandler.cleanup();
|
|
157
160
|
};
|
|
158
161
|
}, [svgRef, store, center, radiusAxisWithScale, usedRadiusAxisId, rotationAxisWithScale, usedRotationAxisId, instance, params.disableAxisListener, isInteractionEnabled, svg2rotation]);
|
|
162
|
+
React.useEffect(() => {
|
|
163
|
+
const element = svgRef.current;
|
|
164
|
+
const onAxisClick = params.onAxisClick;
|
|
165
|
+
if (element === null || !onAxisClick) {
|
|
166
|
+
return () => {};
|
|
167
|
+
}
|
|
168
|
+
const axisClickHandler = instance.addInteractionListener('tap', event => {
|
|
169
|
+
let dataIndex = null;
|
|
170
|
+
let isRotationAxis = false;
|
|
171
|
+
const svgPoint = getSVGPoint(element, event.detail.srcEvent);
|
|
172
|
+
const rotation = generateSvg2rotation(center)(svgPoint.x, svgPoint.y);
|
|
173
|
+
const rotationIndex = getAxisIndex(rotationAxisWithScale[usedRotationAxisId], rotation);
|
|
174
|
+
isRotationAxis = rotationIndex !== -1;
|
|
175
|
+
dataIndex = isRotationAxis ? rotationIndex : null; // radius index is not yet implemented.
|
|
176
|
+
|
|
177
|
+
const USED_AXIS_ID = isRotationAxis ? usedRotationAxisId : usedRadiusAxisId;
|
|
178
|
+
if (dataIndex == null || dataIndex === -1) {
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// The .data exist because otherwise the dataIndex would be null or -1.
|
|
183
|
+
const axisValue = (isRotationAxis ? rotationAxisWithScale : radiusAxisWithScale)[USED_AXIS_ID].data[dataIndex];
|
|
184
|
+
const seriesValues = {};
|
|
185
|
+
Object.keys(processedSeries).filter(seriesType => seriesType === 'radar').forEach(seriesType => {
|
|
186
|
+
processedSeries[seriesType]?.seriesOrder.forEach(seriesId => {
|
|
187
|
+
const seriesItem = processedSeries[seriesType].series[seriesId];
|
|
188
|
+
seriesValues[seriesId] = seriesItem.data[dataIndex];
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
onAxisClick(event.detail.srcEvent, {
|
|
192
|
+
dataIndex,
|
|
193
|
+
axisValue,
|
|
194
|
+
seriesValues
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
return () => {
|
|
198
|
+
axisClickHandler.cleanup();
|
|
199
|
+
};
|
|
200
|
+
}, [center, instance, params.onAxisClick, processedSeries, radiusAxisWithScale, rotationAxisWithScale, svgRef, usedRadiusAxisId, usedRotationAxisId]);
|
|
159
201
|
return {
|
|
160
202
|
instance: {
|
|
161
203
|
svg2polar,
|
|
@@ -168,7 +210,8 @@ useChartPolarAxis.params = {
|
|
|
168
210
|
rotationAxis: true,
|
|
169
211
|
radiusAxis: true,
|
|
170
212
|
dataset: true,
|
|
171
|
-
disableAxisListener: true
|
|
213
|
+
disableAxisListener: true,
|
|
214
|
+
onAxisClick: true
|
|
172
215
|
};
|
|
173
216
|
useChartPolarAxis.getInitialState = params => ({
|
|
174
217
|
polarAxis: {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ChartPluginSignature } from "../../models/index.js";
|
|
2
2
|
import { ChartSeriesType, DatasetType } from "../../../../models/seriesType/config.js";
|
|
3
|
-
import { ScaleName, AxisConfig, ChartsRotationAxisProps, ChartsRadiusAxisProps, RadiusAxis, RotationAxis } from "../../../../models/axis.js";
|
|
3
|
+
import { ScaleName, AxisConfig, ChartsRotationAxisProps, ChartsRadiusAxisProps, RadiusAxis, RotationAxis, ChartsAxisData } from "../../../../models/axis.js";
|
|
4
4
|
import { UseChartSeriesSignature } from "../../corePlugins/useChartSeries/index.js";
|
|
5
5
|
import { UseChartInteractionSignature } from "../useChartInteraction/index.js";
|
|
6
6
|
export interface UseChartPolarAxisInstance {
|
|
@@ -49,6 +49,13 @@ export interface UseChartPolarAxisParameters {
|
|
|
49
49
|
* @default false
|
|
50
50
|
*/
|
|
51
51
|
disableAxisListener?: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* The function called for onClick events.
|
|
54
|
+
* The second argument contains information about all line/bar elements at the current mouse position.
|
|
55
|
+
* @param {MouseEvent} event The mouse event recorded on the `<svg/>` element.
|
|
56
|
+
* @param {null | ChartsAxisData} data The data about the clicked axis and items associated with it.
|
|
57
|
+
*/
|
|
58
|
+
onAxisClick?: (event: MouseEvent, data: null | ChartsAxisData) => void;
|
|
52
59
|
}
|
|
53
60
|
export type UseChartPolarAxisDefaultizedParameters = UseChartPolarAxisParameters & {};
|
|
54
61
|
export interface UseChartPolarAxisState {
|