@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
|
@@ -47,7 +47,8 @@ export function useBarPlotData(drawingArea, xAxes, yAxes) {
|
|
|
47
47
|
const {
|
|
48
48
|
stackedData,
|
|
49
49
|
data: currentSeriesData,
|
|
50
|
-
layout
|
|
50
|
+
layout,
|
|
51
|
+
minBarSize
|
|
51
52
|
} = series[seriesId];
|
|
52
53
|
const seriesDataPoints = baseScaleConfig.data.map((baseValue, dataIndex) => {
|
|
53
54
|
if (currentSeriesData[dataIndex] == null) {
|
|
@@ -58,16 +59,20 @@ export function useBarPlotData(drawingArea, xAxes, yAxes) {
|
|
|
58
59
|
const minValueCoord = Math.round(Math.min(...valueCoordinates));
|
|
59
60
|
const maxValueCoord = Math.round(Math.max(...valueCoordinates));
|
|
60
61
|
const stackId = series[seriesId].stack;
|
|
62
|
+
const {
|
|
63
|
+
barSize,
|
|
64
|
+
startCoordinate
|
|
65
|
+
} = getValueCoordinate(verticalLayout, minValueCoord, maxValueCoord, currentSeriesData[dataIndex], minBarSize);
|
|
61
66
|
const result = {
|
|
62
67
|
seriesId,
|
|
63
68
|
dataIndex,
|
|
64
69
|
layout,
|
|
65
|
-
x: verticalLayout ? xScale(baseValue) + barOffset :
|
|
66
|
-
y: verticalLayout ?
|
|
70
|
+
x: verticalLayout ? xScale(baseValue) + barOffset : startCoordinate,
|
|
71
|
+
y: verticalLayout ? startCoordinate : yScale(baseValue) + barOffset,
|
|
67
72
|
xOrigin: xScale(0) ?? 0,
|
|
68
73
|
yOrigin: yScale(0) ?? 0,
|
|
69
|
-
height: verticalLayout ?
|
|
70
|
-
width: verticalLayout ? barWidth :
|
|
74
|
+
height: verticalLayout ? barSize : barWidth,
|
|
75
|
+
width: verticalLayout ? barWidth : barSize,
|
|
71
76
|
color: colorGetter(dataIndex),
|
|
72
77
|
value: currentSeriesData[dataIndex],
|
|
73
78
|
maskId: `${chartId}_${stackId || seriesId}_${groupIndex}_${dataIndex}`
|
|
@@ -136,4 +141,26 @@ function getBandSize({
|
|
|
136
141
|
barWidth,
|
|
137
142
|
offset
|
|
138
143
|
};
|
|
144
|
+
}
|
|
145
|
+
function getValueCoordinate(isVertical, minValueCoord, maxValueCoord, baseValue, minBarSize) {
|
|
146
|
+
if (baseValue === 0 || baseValue == null) {
|
|
147
|
+
return {
|
|
148
|
+
barSize: 0,
|
|
149
|
+
startCoordinate: minValueCoord
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
const isSizeLessThanMin = maxValueCoord - minValueCoord < minBarSize;
|
|
153
|
+
const barSize = isSizeLessThanMin ? minBarSize : maxValueCoord - minValueCoord;
|
|
154
|
+
const isVerticalAndPositive = isVertical && baseValue >= 0;
|
|
155
|
+
const isHorizontalAndNegative = !isVertical && baseValue < 0;
|
|
156
|
+
if (isSizeLessThanMin && (isVerticalAndPositive || isHorizontalAndNegative)) {
|
|
157
|
+
return {
|
|
158
|
+
barSize,
|
|
159
|
+
startCoordinate: maxValueCoord - barSize
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
return {
|
|
163
|
+
barSize,
|
|
164
|
+
startCoordinate: minValueCoord
|
|
165
|
+
};
|
|
139
166
|
}
|
|
@@ -6,12 +6,13 @@ export interface ChartsLabelCustomMarkProps {
|
|
|
6
6
|
/** Color of the series this mark refers to. */
|
|
7
7
|
color?: string;
|
|
8
8
|
}
|
|
9
|
+
export type ChartsLabelMarkType = 'square' | 'circle' | 'line' | React.ComponentType<ChartsLabelCustomMarkProps>;
|
|
9
10
|
export interface ChartsLabelMarkProps {
|
|
10
11
|
/**
|
|
11
12
|
* The type of the mark.
|
|
12
13
|
* @default 'square'
|
|
13
14
|
*/
|
|
14
|
-
type?:
|
|
15
|
+
type?: ChartsLabelMarkType;
|
|
15
16
|
/**
|
|
16
17
|
* The color of the mark.
|
|
17
18
|
*/
|
package/esm/ChartsLabel/index.js
CHANGED
|
@@ -16,5 +16,5 @@ export interface ChartsLegendClasses {
|
|
|
16
16
|
/** Styles applied to the legend in row layout. */
|
|
17
17
|
horizontal: string;
|
|
18
18
|
}
|
|
19
|
-
export declare const useUtilityClasses: (props: ChartsLegendProps & ChartsLegendSlotExtension) => Record<"
|
|
19
|
+
export declare const useUtilityClasses: (props: ChartsLegendProps & ChartsLegendSlotExtension) => Record<"item" | "series" | "root" | "label" | "mark", string>;
|
|
20
20
|
export declare const legendClasses: ChartsLegendClasses;
|
|
@@ -24,5 +24,5 @@ export interface PiecewiseColorLegendClasses {
|
|
|
24
24
|
/** Styles applied to the series label. */
|
|
25
25
|
label: string;
|
|
26
26
|
}
|
|
27
|
-
export declare const useUtilityClasses: (props: PiecewiseColorLegendProps & ChartsLegendSlotExtension) => Record<"
|
|
27
|
+
export declare const useUtilityClasses: (props: PiecewiseColorLegendProps & ChartsLegendSlotExtension) => Record<"item" | "root" | "label" | "mark" | "minLabel" | "maxLabel", string>;
|
|
28
28
|
export declare const piecewiseColorLegendClasses: PiecewiseColorLegendClasses;
|
|
@@ -18,12 +18,13 @@ import { LineChartPluginsSignatures } from "./LineChart.plugins.js";
|
|
|
18
18
|
import { ChartsToolbarSlots, ChartsToolbarSlotProps } from "../Toolbar/index.js";
|
|
19
19
|
export interface LineChartSlots extends ChartsAxisSlots, AreaPlotSlots, LinePlotSlots, MarkPlotSlots, LineHighlightPlotSlots, ChartsLegendSlots, ChartsOverlaySlots, ChartsTooltipSlots, ChartsToolbarSlots, Partial<ChartsSlots> {}
|
|
20
20
|
export interface LineChartSlotProps extends ChartsAxisSlotProps, AreaPlotSlotProps, LinePlotSlotProps, MarkPlotSlotProps, LineHighlightPlotSlotProps, ChartsLegendSlotProps, ChartsOverlaySlotProps, ChartsTooltipSlotProps, ChartsToolbarSlotProps, Partial<ChartsSlotProps> {}
|
|
21
|
+
export type LineSeries = MakeOptional<LineSeriesType, 'type'>;
|
|
21
22
|
export interface LineChartProps extends Omit<ChartContainerProps<'line', LineChartPluginsSignatures>, 'series' | 'plugins' | 'zAxis'>, Omit<ChartsAxisProps, 'slots' | 'slotProps'>, Omit<ChartsOverlayProps, 'slots' | 'slotProps'> {
|
|
22
23
|
/**
|
|
23
24
|
* The series to display in the line chart.
|
|
24
|
-
* An array of [[
|
|
25
|
+
* An array of [[LineSeries]] objects.
|
|
25
26
|
*/
|
|
26
|
-
series: Readonly<
|
|
27
|
+
series: Readonly<LineSeries[]>;
|
|
27
28
|
/**
|
|
28
29
|
* Option to display a cartesian grid in the background.
|
|
29
30
|
*/
|
|
@@ -209,7 +209,7 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
|
|
|
209
209
|
onMarkClick: PropTypes.func,
|
|
210
210
|
/**
|
|
211
211
|
* The series to display in the line chart.
|
|
212
|
-
* An array of [[
|
|
212
|
+
* An array of [[LineSeries]] objects.
|
|
213
213
|
*/
|
|
214
214
|
series: PropTypes.arrayOf(PropTypes.object).isRequired,
|
|
215
215
|
/**
|
|
@@ -145,6 +145,9 @@ process.env.NODE_ENV !== "production" ? PieArcLabelPlot.propTypes = {
|
|
|
145
145
|
outerRadius: PropTypes.number,
|
|
146
146
|
paddingAngle: PropTypes.number
|
|
147
147
|
}),
|
|
148
|
+
/**
|
|
149
|
+
* The id of this series.
|
|
150
|
+
*/
|
|
148
151
|
id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
|
|
149
152
|
/**
|
|
150
153
|
* The radius between circle center and the beginning of the arc.
|
|
@@ -116,6 +116,9 @@ process.env.NODE_ENV !== "production" ? PieArcPlot.propTypes = {
|
|
|
116
116
|
outerRadius: PropTypes.number,
|
|
117
117
|
paddingAngle: PropTypes.number
|
|
118
118
|
}),
|
|
119
|
+
/**
|
|
120
|
+
* The id of this series.
|
|
121
|
+
*/
|
|
119
122
|
id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
|
|
120
123
|
/**
|
|
121
124
|
* The radius between circle center and the beginning of the arc.
|
|
@@ -12,12 +12,13 @@ import { ChartsOverlayProps, ChartsOverlaySlotProps, ChartsOverlaySlots } from "
|
|
|
12
12
|
import { PieChartPluginSignatures } from "./PieChart.plugins.js";
|
|
13
13
|
export interface PieChartSlots extends PiePlotSlots, ChartsLegendSlots, ChartsOverlaySlots, ChartsTooltipSlots, ChartsToolbarSlots, Partial<ChartsSlots> {}
|
|
14
14
|
export interface PieChartSlotProps extends PiePlotSlotProps, ChartsLegendSlotProps, ChartsOverlaySlotProps, ChartsTooltipSlotProps, ChartsToolbarSlotProps, Partial<ChartsSlotProps> {}
|
|
15
|
+
export type PieSeries = MakeOptional<PieSeriesType<MakeOptional<PieValueType, 'id'>>, 'type'>;
|
|
15
16
|
export interface PieChartProps extends Omit<ChartContainerProps<'pie', PieChartPluginSignatures>, 'series' | 'slots' | 'slotProps' | 'experimentalFeatures'>, Omit<ChartsOverlayProps, 'slots' | 'slotProps'>, Pick<PiePlotProps, 'skipAnimation'> {
|
|
16
17
|
/**
|
|
17
18
|
* The series to display in the pie chart.
|
|
18
|
-
* An array of [[
|
|
19
|
+
* An array of [[PieSeries]] objects.
|
|
19
20
|
*/
|
|
20
|
-
series: Readonly<
|
|
21
|
+
series: Readonly<PieSeries[]>;
|
|
21
22
|
/**
|
|
22
23
|
* If `true`, the legend is not rendered.
|
|
23
24
|
*/
|
package/esm/PieChart/PieChart.js
CHANGED
|
@@ -173,7 +173,7 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
|
|
|
173
173
|
onItemClick: PropTypes.func,
|
|
174
174
|
/**
|
|
175
175
|
* The series to display in the pie chart.
|
|
176
|
-
* An array of [[
|
|
176
|
+
* An array of [[PieSeries]] objects.
|
|
177
177
|
*/
|
|
178
178
|
series: PropTypes.arrayOf(PropTypes.object).isRequired,
|
|
179
179
|
/**
|
|
@@ -9,4 +9,4 @@ export interface PieClasses {
|
|
|
9
9
|
export type PieClassKey = keyof PieClasses;
|
|
10
10
|
export declare function getPieUtilityClass(slot: string): string;
|
|
11
11
|
export declare const pieClasses: PieClasses;
|
|
12
|
-
export declare const useUtilityClasses: (classes?: Partial<PieClasses>) => Record<"
|
|
12
|
+
export declare const useUtilityClasses: (classes?: Partial<PieClasses>) => Record<"series" | "root" | "seriesLabels", string>;
|
|
@@ -54,13 +54,11 @@ function RadarAxisHighlight(props) {
|
|
|
54
54
|
className: classes.line,
|
|
55
55
|
pointerEvents: "none",
|
|
56
56
|
strokeDasharray: "4 4"
|
|
57
|
-
}), points.map(({
|
|
58
|
-
highlighted
|
|
59
|
-
}, seriesIndex) => {
|
|
57
|
+
}), points.map((point, seriesIndex) => {
|
|
60
58
|
return /*#__PURE__*/_jsx("circle", _extends({
|
|
61
59
|
fill: series[seriesIndex].color,
|
|
62
|
-
cx:
|
|
63
|
-
cy:
|
|
60
|
+
cx: point.x,
|
|
61
|
+
cy: point.y,
|
|
64
62
|
className: classes.dot,
|
|
65
63
|
pointerEvents: "none"
|
|
66
64
|
}, series[seriesIndex].hideMark ? highlightMark : highlightMarkShadow), series[seriesIndex].id);
|
|
@@ -2,12 +2,6 @@ import { UseChartPolarAxisSignature } from "../../internals/plugins/featurePlugi
|
|
|
2
2
|
import { AxisId } from "../../models/axis.js";
|
|
3
3
|
import { DefaultizedRadarSeriesType } from "../../models/seriesType/radar.js";
|
|
4
4
|
import { ChartInstance } from "../../internals/plugins/models/index.js";
|
|
5
|
-
interface UseRadarAxisHighlightParams {
|
|
6
|
-
/**
|
|
7
|
-
* If true, coordinates of the previous/next point will be added.
|
|
8
|
-
*/
|
|
9
|
-
includesNeighbors?: boolean;
|
|
10
|
-
}
|
|
11
5
|
interface UseRadarAxisHighlightReturnValue {
|
|
12
6
|
/**
|
|
13
7
|
* The radar center.
|
|
@@ -40,7 +34,7 @@ interface UseRadarAxisHighlightReturnValue {
|
|
|
40
34
|
* The { x, y, value } values for the highlighted points in the same order as the `series` array.
|
|
41
35
|
* If `includesNeighbors` is set to `true` it also contains the information for `previous` and `next` data point.
|
|
42
36
|
*/
|
|
43
|
-
points:
|
|
37
|
+
points: Point[];
|
|
44
38
|
/**
|
|
45
39
|
* Charts instances giving access to `polar2svg` and `svg2polar` helpers.
|
|
46
40
|
*/
|
|
@@ -53,10 +47,5 @@ interface Point {
|
|
|
53
47
|
angle: number;
|
|
54
48
|
value: number;
|
|
55
49
|
}
|
|
56
|
-
|
|
57
|
-
highlighted: Point;
|
|
58
|
-
previous?: Point;
|
|
59
|
-
next?: Point;
|
|
60
|
-
}
|
|
61
|
-
export declare function useRadarAxisHighlight(params?: UseRadarAxisHighlightParams): UseRadarAxisHighlightReturnValue | null;
|
|
50
|
+
export declare function useRadarAxisHighlight(): UseRadarAxisHighlightReturnValue | null;
|
|
62
51
|
export {};
|
|
@@ -6,10 +6,7 @@ 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
8
|
import { selectorChartsInteractionRotationAxisIndex, selectorChartsInteractionRotationAxisValue } from "../../internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarInteraction.selectors.js";
|
|
9
|
-
export function useRadarAxisHighlight(
|
|
10
|
-
const {
|
|
11
|
-
includesNeighbors = false
|
|
12
|
-
} = params ?? {};
|
|
9
|
+
export function useRadarAxisHighlight() {
|
|
13
10
|
const radarSeries = useRadarSeries();
|
|
14
11
|
const rotationScale = useRotationScale();
|
|
15
12
|
const {
|
|
@@ -49,48 +46,14 @@ export function useRadarAxisHighlight(params) {
|
|
|
49
46
|
const value = series.data[highlightedIndex];
|
|
50
47
|
const r = radiusScale(value);
|
|
51
48
|
const [x, y] = instance.polar2svg(r, angle);
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
value
|
|
59
|
-
}
|
|
49
|
+
const returnedValue = {
|
|
50
|
+
x,
|
|
51
|
+
y,
|
|
52
|
+
r,
|
|
53
|
+
angle,
|
|
54
|
+
value
|
|
60
55
|
};
|
|
61
|
-
|
|
62
|
-
return retrunedValue;
|
|
63
|
-
}
|
|
64
|
-
const dataLength = series.data.length;
|
|
65
|
-
const prevIndex = (dataLength + highlightedIndex - 1) % dataLength;
|
|
66
|
-
const nextIndex = (highlightedIndex + 1) % dataLength;
|
|
67
|
-
const prevValue = series.data[prevIndex];
|
|
68
|
-
const nextValue = series.data[nextIndex];
|
|
69
|
-
if (prevValue != null) {
|
|
70
|
-
const prevR = radiusAxis[radiusAxisIds[prevIndex]].scale(prevValue);
|
|
71
|
-
const prevAngle = rotationScale(rotationScale.domain()[prevIndex]);
|
|
72
|
-
const [px, py] = instance.polar2svg(prevR, prevAngle);
|
|
73
|
-
retrunedValue.previous = {
|
|
74
|
-
x: px,
|
|
75
|
-
y: py,
|
|
76
|
-
r: prevR,
|
|
77
|
-
angle: prevAngle,
|
|
78
|
-
value: prevValue
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
if (nextValue != null) {
|
|
82
|
-
const nextR = radiusAxis[radiusAxisIds[nextIndex]].scale(nextValue);
|
|
83
|
-
const nextAngle = rotationScale(rotationScale.domain()[nextIndex]);
|
|
84
|
-
const [nx, ny] = instance.polar2svg(nextR, nextAngle);
|
|
85
|
-
retrunedValue.next = {
|
|
86
|
-
x: nx,
|
|
87
|
-
y: ny,
|
|
88
|
-
r: nextR,
|
|
89
|
-
angle: nextAngle,
|
|
90
|
-
value: nextValue
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
return retrunedValue;
|
|
56
|
+
return returnedValue;
|
|
94
57
|
})
|
|
95
58
|
};
|
|
96
59
|
}
|
|
@@ -5,13 +5,14 @@ import { ChartsSurfaceProps } from "../ChartsSurface/index.js";
|
|
|
5
5
|
import { ChartsWrapperProps } from "../internals/components/ChartsWrapper/index.js";
|
|
6
6
|
import { RadarGridProps } from "./RadarGrid/index.js";
|
|
7
7
|
import { RadarDataProviderProps } from "./RadarDataProvider/RadarDataProvider.js";
|
|
8
|
+
import { RadarSeriesPlotProps } from "./RadarSeriesPlot/index.js";
|
|
8
9
|
import { RadarAxisHighlightProps } from "./RadarAxisHighlight/index.js";
|
|
9
10
|
import { ChartsTooltipSlotProps, ChartsTooltipSlots } from "../ChartsTooltip/index.js";
|
|
10
11
|
import { ChartsSlotProps, ChartsSlots } from "../internals/material/index.js";
|
|
11
12
|
import { ChartsToolbarSlotProps, ChartsToolbarSlots } from "../Toolbar/index.js";
|
|
12
13
|
export interface RadarChartSlots extends ChartsTooltipSlots, ChartsOverlaySlots, ChartsLegendSlots, ChartsToolbarSlots, Partial<ChartsSlots> {}
|
|
13
14
|
export interface RadarChartSlotProps extends ChartsTooltipSlotProps, ChartsOverlaySlotProps, ChartsLegendSlotProps, ChartsToolbarSlotProps, Partial<ChartsSlotProps> {}
|
|
14
|
-
export interface RadarChartProps extends RadarDataProviderProps, Omit<RadarGridProps, 'classes'>, Omit<Partial<RadarAxisHighlightProps>, 'classes'>, Omit<ChartsOverlayProps, 'slots' | 'slotProps'>, Pick<ChartsWrapperProps, 'sx'>, Omit<ChartsSurfaceProps, 'sx'> {
|
|
15
|
+
export interface RadarChartProps extends RadarDataProviderProps, Omit<RadarGridProps, 'classes'>, Omit<Partial<RadarAxisHighlightProps>, 'classes'>, Omit<ChartsOverlayProps, 'slots' | 'slotProps'>, Pick<ChartsWrapperProps, 'sx'>, Omit<ChartsSurfaceProps, 'sx'>, Pick<RadarSeriesPlotProps, 'onAreaClick' | 'onMarkClick'> {
|
|
15
16
|
/**
|
|
16
17
|
* If `true`, the legend is not rendered.
|
|
17
18
|
*/
|
|
@@ -35,6 +35,8 @@ const RadarChart = /*#__PURE__*/React.forwardRef(function RadarChart(inProps, re
|
|
|
35
35
|
chartsSurfaceProps,
|
|
36
36
|
radarDataProviderProps,
|
|
37
37
|
radarGrid,
|
|
38
|
+
radarSeriesAreaProps,
|
|
39
|
+
radarSeriesMarksProps,
|
|
38
40
|
overlayProps,
|
|
39
41
|
legendProps,
|
|
40
42
|
highlight,
|
|
@@ -46,7 +48,7 @@ const RadarChart = /*#__PURE__*/React.forwardRef(function RadarChart(inProps, re
|
|
|
46
48
|
children: /*#__PURE__*/_jsxs(ChartsWrapper, _extends({}, chartsWrapperProps, {
|
|
47
49
|
children: [props.showToolbar && Toolbar ? /*#__PURE__*/_jsx(Toolbar, _extends({}, props.slotProps?.toolbar)) : null, !props.hideLegend && /*#__PURE__*/_jsx(ChartsLegend, _extends({}, legendProps)), /*#__PURE__*/_jsxs(ChartsSurface, _extends({}, chartsSurfaceProps, {
|
|
48
50
|
ref: ref,
|
|
49
|
-
children: [/*#__PURE__*/_jsx(RadarGrid, _extends({}, radarGrid)), /*#__PURE__*/_jsx(RadarMetricLabels, {}), /*#__PURE__*/_jsx(RadarSeriesArea, {}), highlight === 'axis' && /*#__PURE__*/_jsx(RadarAxisHighlight, {}), /*#__PURE__*/_jsx(RadarSeriesMarks, {}), /*#__PURE__*/_jsx(ChartsOverlay, _extends({}, overlayProps)), children]
|
|
51
|
+
children: [/*#__PURE__*/_jsx(RadarGrid, _extends({}, radarGrid)), /*#__PURE__*/_jsx(RadarMetricLabels, {}), /*#__PURE__*/_jsx(RadarSeriesArea, _extends({}, radarSeriesAreaProps)), highlight === 'axis' && /*#__PURE__*/_jsx(RadarAxisHighlight, {}), /*#__PURE__*/_jsx(RadarSeriesMarks, _extends({}, radarSeriesMarksProps)), /*#__PURE__*/_jsx(ChartsOverlay, _extends({}, overlayProps)), children]
|
|
50
52
|
})), !props.loading && /*#__PURE__*/_jsx(Tooltip, _extends({}, props.slotProps?.tooltip))]
|
|
51
53
|
}))
|
|
52
54
|
}));
|
|
@@ -125,12 +127,31 @@ process.env.NODE_ENV !== "production" ? RadarChart.propTypes = {
|
|
|
125
127
|
right: PropTypes.number,
|
|
126
128
|
top: PropTypes.number
|
|
127
129
|
})]),
|
|
130
|
+
/**
|
|
131
|
+
* Callback fired when an area is clicked.
|
|
132
|
+
* @param {React.MouseEvent<SVGPathElement, MouseEvent>} event The event source of the callback.
|
|
133
|
+
* @param {RadarItemIdentifier} radarItemIdentifier The radar item identifier.
|
|
134
|
+
*/
|
|
135
|
+
onAreaClick: PropTypes.func,
|
|
136
|
+
/**
|
|
137
|
+
* The function called for onClick events.
|
|
138
|
+
* The second argument contains information about all line/bar elements at the current mouse position.
|
|
139
|
+
* @param {MouseEvent} event The mouse event recorded on the `<svg/>` element.
|
|
140
|
+
* @param {null | ChartsAxisData} data The data about the clicked axis and items associated with it.
|
|
141
|
+
*/
|
|
142
|
+
onAxisClick: PropTypes.func,
|
|
128
143
|
/**
|
|
129
144
|
* The callback fired when the highlighted item changes.
|
|
130
145
|
*
|
|
131
146
|
* @param {HighlightItemData | null} highlightedItem The newly highlighted item.
|
|
132
147
|
*/
|
|
133
148
|
onHighlightChange: PropTypes.func,
|
|
149
|
+
/**
|
|
150
|
+
* Callback fired when a mark is clicked.
|
|
151
|
+
* @param {React.MouseEvent<SVGPathElement, MouseEvent>} event The event source of the callback.
|
|
152
|
+
* @param {RadarItemIdentifier} radarItemIdentifier The radar item identifier.
|
|
153
|
+
*/
|
|
154
|
+
onMarkClick: PropTypes.func,
|
|
134
155
|
/**
|
|
135
156
|
* The configuration of the radar scales.
|
|
136
157
|
*/
|
|
@@ -147,7 +168,7 @@ process.env.NODE_ENV !== "production" ? RadarChart.propTypes = {
|
|
|
147
168
|
}).isRequired,
|
|
148
169
|
/**
|
|
149
170
|
* The series to display in the bar chart.
|
|
150
|
-
* An array of [[
|
|
171
|
+
* An array of [[RadarSeries]] objects.
|
|
151
172
|
*/
|
|
152
173
|
series: PropTypes.arrayOf(PropTypes.object).isRequired,
|
|
153
174
|
/**
|
|
@@ -5,12 +5,13 @@ import { RadarSeriesType } from "../../models/seriesType/radar.js";
|
|
|
5
5
|
import { ChartDataProviderProps } from "../../ChartDataProvider/index.js";
|
|
6
6
|
import { RadarConfig } from "./radar.types.js";
|
|
7
7
|
import { ChartAnyPluginSignature } from "../../internals/plugins/models/plugin.js";
|
|
8
|
+
export type RadarSeries = MakeOptional<RadarSeriesType, 'type'>;
|
|
8
9
|
export type RadarDataProviderProps<TSignatures extends readonly ChartAnyPluginSignature[] = RadarChartPluginsSignatures> = Omit<ChartDataProviderProps<'radar', TSignatures>, 'series' | 'rotationAxis' | 'radiusAxis' | 'dataset' | 'experimentalFeatures'> & {
|
|
9
10
|
/**
|
|
10
11
|
* The series to display in the bar chart.
|
|
11
|
-
* An array of [[
|
|
12
|
+
* An array of [[RadarSeries]] objects.
|
|
12
13
|
*/
|
|
13
|
-
series: Readonly<
|
|
14
|
+
series: Readonly<RadarSeries>[];
|
|
14
15
|
/**
|
|
15
16
|
* The configuration of the radar scales.
|
|
16
17
|
*/
|
|
@@ -21,14 +21,16 @@ export function useRadarMetricData() {
|
|
|
21
21
|
const radiusScale = radiusAxis[metric].scale;
|
|
22
22
|
const r = radiusScale.range()[1] + labelGap;
|
|
23
23
|
const angle = angles[dataIndex];
|
|
24
|
+
const defaultTickLabel = metric;
|
|
24
25
|
return {
|
|
25
26
|
x: cx + r * Math.sin(angle),
|
|
26
27
|
y: cy - r * Math.cos(angle),
|
|
27
28
|
angle: rad2deg(angle),
|
|
28
29
|
label: valueFormatter?.(metric, {
|
|
29
30
|
location: 'tick',
|
|
30
|
-
scale: rotationScale
|
|
31
|
-
|
|
31
|
+
scale: rotationScale,
|
|
32
|
+
defaultTickLabel
|
|
33
|
+
}) ?? defaultTickLabel
|
|
32
34
|
};
|
|
33
35
|
})
|
|
34
36
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
|
-
const _excluded = ["seriesId"];
|
|
3
|
+
const _excluded = ["seriesId", "onItemClick"];
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import PropTypes from 'prop-types';
|
|
6
6
|
import clsx from 'clsx';
|
|
@@ -9,6 +9,7 @@ import { getAreaPath } from "./getAreaPath.js";
|
|
|
9
9
|
import { useUtilityClasses } from "./radarSeriesPlotClasses.js";
|
|
10
10
|
import { useItemHighlightedGetter } from "../../hooks/useItemHighlightedGetter.js";
|
|
11
11
|
import { useInteractionAllItemProps } from "../../hooks/useInteractionItemProps.js";
|
|
12
|
+
import { useRadarRotationIndex } from "./useRadarRotationIndex.js";
|
|
12
13
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
14
|
export function getPathProps(params) {
|
|
14
15
|
const {
|
|
@@ -38,10 +39,12 @@ export function getPathProps(params) {
|
|
|
38
39
|
}
|
|
39
40
|
function RadarSeriesArea(props) {
|
|
40
41
|
const {
|
|
41
|
-
seriesId
|
|
42
|
+
seriesId,
|
|
43
|
+
onItemClick
|
|
42
44
|
} = props,
|
|
43
45
|
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
44
46
|
const seriesCoordinates = useRadarSeriesData(seriesId);
|
|
47
|
+
const getRotationIndex = useRadarRotationIndex();
|
|
45
48
|
const interactionProps = useInteractionAllItemProps(seriesCoordinates);
|
|
46
49
|
const {
|
|
47
50
|
isFaded,
|
|
@@ -63,7 +66,14 @@ function RadarSeriesArea(props) {
|
|
|
63
66
|
isFaded,
|
|
64
67
|
isHighlighted,
|
|
65
68
|
classes
|
|
66
|
-
}),
|
|
69
|
+
}), {
|
|
70
|
+
onClick: event => onItemClick?.(event, {
|
|
71
|
+
type: 'radar',
|
|
72
|
+
seriesId: id,
|
|
73
|
+
dataIndex: getRotationIndex(event)
|
|
74
|
+
}),
|
|
75
|
+
cursor: onItemClick ? 'pointer' : 'unset'
|
|
76
|
+
}, interactionProps[seriesIndex], other), id);
|
|
67
77
|
})
|
|
68
78
|
});
|
|
69
79
|
}
|
|
@@ -76,6 +86,12 @@ process.env.NODE_ENV !== "production" ? RadarSeriesArea.propTypes = {
|
|
|
76
86
|
* Override or extend the styles applied to the component.
|
|
77
87
|
*/
|
|
78
88
|
classes: PropTypes.object,
|
|
89
|
+
/**
|
|
90
|
+
* Callback fired when an area is clicked.
|
|
91
|
+
* @param {React.MouseEvent<SVGPathElement, MouseEvent>} event The event source of the callback.
|
|
92
|
+
* @param {RadarItemIdentifier} radarItemIdentifier The radar item identifier.
|
|
93
|
+
*/
|
|
94
|
+
onItemClick: PropTypes.func,
|
|
79
95
|
/**
|
|
80
96
|
* The id of the series to display.
|
|
81
97
|
* If undefined all series are displayed.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
|
-
const _excluded = ["seriesId"];
|
|
3
|
+
const _excluded = ["seriesId", "onItemClick"];
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import { clsx } from 'clsx';
|
|
6
6
|
import PropTypes from 'prop-types';
|
|
@@ -31,12 +31,14 @@ export function getCircleProps(params) {
|
|
|
31
31
|
fill: color,
|
|
32
32
|
stroke: color,
|
|
33
33
|
opacity: fillArea && isItemFaded ? 0.5 : 1,
|
|
34
|
-
pointerEvents: 'none',
|
|
35
34
|
className: clsx(classes.mark, isItemHighlighted && classes.highlighted || isItemFaded && classes.faded)
|
|
36
35
|
};
|
|
37
36
|
}
|
|
38
37
|
function RadarSeriesMarks(props) {
|
|
39
|
-
const
|
|
38
|
+
const {
|
|
39
|
+
onItemClick
|
|
40
|
+
} = props,
|
|
41
|
+
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
40
42
|
const seriesCoordinates = useRadarSeriesData(props.seriesId);
|
|
41
43
|
const classes = useUtilityClasses(props.classes);
|
|
42
44
|
const {
|
|
@@ -63,7 +65,15 @@ function RadarSeriesMarks(props) {
|
|
|
63
65
|
isFaded,
|
|
64
66
|
isHighlighted,
|
|
65
67
|
classes
|
|
66
|
-
}),
|
|
68
|
+
}), {
|
|
69
|
+
pointerEvents: onItemClick ? undefined : 'none',
|
|
70
|
+
onClick: event => onItemClick?.(event, {
|
|
71
|
+
type: 'radar',
|
|
72
|
+
seriesId: id,
|
|
73
|
+
dataIndex: index
|
|
74
|
+
}),
|
|
75
|
+
cursor: onItemClick ? 'pointer' : 'unset'
|
|
76
|
+
}, other), index))
|
|
67
77
|
}, id);
|
|
68
78
|
})
|
|
69
79
|
});
|
|
@@ -77,6 +87,12 @@ process.env.NODE_ENV !== "production" ? RadarSeriesMarks.propTypes = {
|
|
|
77
87
|
* Override or extend the styles applied to the component.
|
|
78
88
|
*/
|
|
79
89
|
classes: PropTypes.object,
|
|
90
|
+
/**
|
|
91
|
+
* Callback fired when a mark is clicked.
|
|
92
|
+
* @param {React.MouseEvent<SVGPathElement, MouseEvent>} event The event source of the callback.
|
|
93
|
+
* @param {RadarItemIdentifier} radarItemIdentifier The radar item identifier.
|
|
94
|
+
*/
|
|
95
|
+
onItemClick: PropTypes.func,
|
|
80
96
|
/**
|
|
81
97
|
* The id of the series to display.
|
|
82
98
|
* If undefined all series are displayed.
|
|
@@ -7,15 +7,23 @@ import { useItemHighlightedGetter } from "../../hooks/useItemHighlightedGetter.j
|
|
|
7
7
|
import { useUtilityClasses } from "./radarSeriesPlotClasses.js";
|
|
8
8
|
import { getPathProps } from "./RadarSeriesArea.js";
|
|
9
9
|
import { getCircleProps } from "./RadarSeriesMarks.js";
|
|
10
|
+
import { useRadarRotationIndex } from "./useRadarRotationIndex.js";
|
|
10
11
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
11
12
|
function RadarSeriesPlot(props) {
|
|
12
|
-
const
|
|
13
|
+
const {
|
|
14
|
+
seriesId: inSeriesId,
|
|
15
|
+
classes: inClasses,
|
|
16
|
+
onAreaClick,
|
|
17
|
+
onMarkClick
|
|
18
|
+
} = props;
|
|
19
|
+
const seriesCoordinates = useRadarSeriesData(inSeriesId);
|
|
20
|
+
const getRotationIndex = useRadarRotationIndex();
|
|
13
21
|
const interactionProps = useInteractionAllItemProps(seriesCoordinates);
|
|
14
22
|
const {
|
|
15
23
|
isFaded,
|
|
16
24
|
isHighlighted
|
|
17
25
|
} = useItemHighlightedGetter();
|
|
18
|
-
const classes = useUtilityClasses(
|
|
26
|
+
const classes = useUtilityClasses(inClasses);
|
|
19
27
|
return /*#__PURE__*/_jsx("g", {
|
|
20
28
|
className: classes.root,
|
|
21
29
|
children: seriesCoordinates?.map(({
|
|
@@ -34,7 +42,14 @@ function RadarSeriesPlot(props) {
|
|
|
34
42
|
isFaded,
|
|
35
43
|
isHighlighted,
|
|
36
44
|
classes
|
|
37
|
-
}),
|
|
45
|
+
}), {
|
|
46
|
+
onClick: event => onAreaClick?.(event, {
|
|
47
|
+
type: 'radar',
|
|
48
|
+
seriesId,
|
|
49
|
+
dataIndex: getRotationIndex(event)
|
|
50
|
+
}),
|
|
51
|
+
cursor: onAreaClick ? 'pointer' : 'unset'
|
|
52
|
+
}, interactionProps[seriesIndex]), seriesId), !hideMark && points.map((point, index) => /*#__PURE__*/_jsx("circle", _extends({}, getCircleProps({
|
|
38
53
|
seriesId,
|
|
39
54
|
point,
|
|
40
55
|
color,
|
|
@@ -42,7 +57,14 @@ function RadarSeriesPlot(props) {
|
|
|
42
57
|
isFaded,
|
|
43
58
|
isHighlighted,
|
|
44
59
|
classes
|
|
45
|
-
})
|
|
60
|
+
}), {
|
|
61
|
+
onClick: event => onMarkClick?.(event, {
|
|
62
|
+
type: 'radar',
|
|
63
|
+
seriesId,
|
|
64
|
+
dataIndex: index
|
|
65
|
+
}),
|
|
66
|
+
cursor: onMarkClick ? 'pointer' : 'unset'
|
|
67
|
+
}), index))]
|
|
46
68
|
}, seriesId);
|
|
47
69
|
})
|
|
48
70
|
});
|
|
@@ -56,6 +78,18 @@ process.env.NODE_ENV !== "production" ? RadarSeriesPlot.propTypes = {
|
|
|
56
78
|
* Override or extend the styles applied to the component.
|
|
57
79
|
*/
|
|
58
80
|
classes: PropTypes.object,
|
|
81
|
+
/**
|
|
82
|
+
* Callback fired when an area is clicked.
|
|
83
|
+
* @param {React.MouseEvent<SVGPathElement, MouseEvent>} event The event source of the callback.
|
|
84
|
+
* @param {RadarItemIdentifier} radarItemIdentifier The radar item identifier.
|
|
85
|
+
*/
|
|
86
|
+
onAreaClick: PropTypes.func,
|
|
87
|
+
/**
|
|
88
|
+
* Callback fired when a mark is clicked.
|
|
89
|
+
* @param {React.MouseEvent<SVGPathElement, MouseEvent>} event The event source of the callback.
|
|
90
|
+
* @param {RadarItemIdentifier} radarItemIdentifier The radar item identifier.
|
|
91
|
+
*/
|
|
92
|
+
onMarkClick: PropTypes.func,
|
|
59
93
|
/**
|
|
60
94
|
* The id of the series to display.
|
|
61
95
|
* If undefined all series are displayed.
|