@mui/x-charts 7.7.1 → 7.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/BarChart/BarElement.d.ts +225 -228
- package/BarChart/BarLabel/BarLabel.d.ts +225 -228
- package/BarChart/BarLabel/getBarLabel.d.ts +1 -1
- package/BarChart/useBarChartProps.d.ts +20 -88
- package/CHANGELOG.md +100 -1
- package/ChartContainer/ChartContainer.d.ts +1 -1
- package/ChartContainer/useChartContainerHooks.d.ts +1 -1
- package/ChartsAxisHighlight/ChartsAxisHighlight.js +19 -4
- package/ChartsReferenceLine/common.d.ts +0 -1
- package/ChartsTooltip/ChartsTooltipTable.d.ts +0 -1
- package/ChartsVoronoiHandler/ChartsVoronoiHandler.js +2 -2
- package/ChartsYAxis/ChartsYAxis.js +3 -1
- package/Gauge/GaugeProvider.d.ts +1 -1
- package/LineChart/AnimatedArea.d.ts +225 -228
- package/LineChart/AnimatedLine.d.ts +225 -228
- package/LineChart/useLineChartProps.d.ts +26 -103
- package/LineChart/useLineChartProps.js +3 -3
- package/PieChart/PieArc.d.ts +0 -1
- package/PieChart/PieArcLabel.d.ts +0 -1
- package/PieChart/dataTransform/transition.d.ts +0 -1
- package/ResponsiveChartContainer/ResizableContainer.d.ts +1 -2
- package/ScatterChart/useScatterChartProps.d.ts +20 -75
- package/context/CartesianProvider/computeValue.js +15 -0
- package/context/CartesianProvider/normalizeAxis.d.ts +1 -1
- package/esm/BarChart/useBarChartProps.js +0 -1
- package/esm/ChartsAxisHighlight/ChartsAxisHighlight.js +19 -4
- package/esm/ChartsVoronoiHandler/ChartsVoronoiHandler.js +1 -1
- package/esm/ChartsYAxis/ChartsYAxis.js +3 -1
- package/esm/LineChart/useLineChartProps.js +3 -3
- package/esm/context/CartesianProvider/computeValue.js +16 -1
- package/esm/hooks/useAxisEvents.js +5 -8
- package/esm/hooks/useScale.js +1 -1
- package/esm/hooks/useTicks.js +2 -1
- package/esm/internals/getSVGPoint.js +11 -0
- package/esm/internals/index.js +2 -0
- package/esm/internals/utils.js +0 -12
- package/hooks/useAxisEvents.js +6 -9
- package/hooks/useChartDimensions.d.ts +1 -1
- package/hooks/useColor.d.ts +1 -1
- package/hooks/useScale.js +1 -1
- package/hooks/useTicks.js +2 -1
- package/index.js +1 -1
- package/internals/components/AxisSharedComponents.d.ts +0 -1
- package/internals/components/ChartsAxesGradients/ChartsAxesGradients.d.ts +1 -1
- package/internals/defaultizeColor.d.ts +68 -68
- package/internals/getSVGPoint.d.ts +6 -0
- package/internals/getSVGPoint.js +17 -0
- package/internals/getWordsByLines.d.ts +0 -1
- package/internals/index.d.ts +2 -0
- package/internals/index.js +20 -0
- package/internals/useAnimatedPath.d.ts +0 -1
- package/internals/utils.d.ts +0 -6
- package/internals/utils.js +0 -13
- package/models/axis.d.ts +1 -2
- package/modern/BarChart/useBarChartProps.js +0 -1
- package/modern/ChartsAxisHighlight/ChartsAxisHighlight.js +19 -4
- package/modern/ChartsVoronoiHandler/ChartsVoronoiHandler.js +1 -1
- package/modern/ChartsYAxis/ChartsYAxis.js +3 -1
- package/modern/LineChart/useLineChartProps.js +3 -3
- package/modern/context/CartesianProvider/computeValue.js +16 -1
- package/modern/hooks/useAxisEvents.js +5 -8
- package/modern/hooks/useScale.js +1 -1
- package/modern/hooks/useTicks.js +2 -1
- package/modern/index.js +1 -1
- package/modern/internals/getSVGPoint.js +11 -0
- package/modern/internals/index.js +2 -0
- package/modern/internals/utils.js +0 -12
- package/package.json +1 -1
|
@@ -1,5 +1,17 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
import type { LineChartProps } from './LineChart';
|
|
2
|
+
import { ResponsiveChartContainerProps } from '../ResponsiveChartContainer';
|
|
3
|
+
import { ChartsOnAxisClickHandlerProps } from '../ChartsOnAxisClickHandler';
|
|
4
|
+
import { ChartsGridProps } from '../ChartsGrid';
|
|
5
|
+
import { ChartsClipPathProps } from '../ChartsClipPath';
|
|
6
|
+
import { AreaPlotProps } from './AreaPlot';
|
|
7
|
+
import { LinePlotProps } from './LinePlot';
|
|
8
|
+
import { MarkPlotProps } from './MarkPlot';
|
|
9
|
+
import { ChartsOverlayProps } from '../ChartsOverlay';
|
|
10
|
+
import { ChartsAxisProps } from '../ChartsAxis';
|
|
11
|
+
import { ChartsAxisHighlightProps } from '../ChartsAxisHighlight';
|
|
12
|
+
import { LineHighlightPlotProps } from './LineHighlightPlot';
|
|
13
|
+
import { ChartsLegendProps } from '../ChartsLegend';
|
|
14
|
+
import { ChartsTooltipProps } from '../ChartsTooltip';
|
|
3
15
|
/**
|
|
4
16
|
* A helper function that extracts LineChartProps from the input props
|
|
5
17
|
* and returns an object with props for the children components of LineChart.
|
|
@@ -8,110 +20,21 @@ import type { LineChartProps } from './LineChart';
|
|
|
8
20
|
* @returns An object with props for the children components of LineChart
|
|
9
21
|
*/
|
|
10
22
|
export declare const useLineChartProps: (props: LineChartProps) => {
|
|
11
|
-
chartContainerProps:
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
data?: (number | null)[] | undefined;
|
|
16
|
-
label?: string | ((location: "tooltip" | "legend") => string) | undefined;
|
|
17
|
-
id?: import("../internals").SeriesId | undefined;
|
|
18
|
-
dataKey?: string | undefined;
|
|
19
|
-
stackOffset?: import("..").StackOffsetType | undefined;
|
|
20
|
-
valueFormatter?: import("../internals").SeriesValueFormatter<number | null> | undefined;
|
|
21
|
-
highlightScope?: Partial<import("..").HighlightScope> | undefined;
|
|
22
|
-
xAxisKey?: string | undefined;
|
|
23
|
-
yAxisKey?: string | undefined;
|
|
24
|
-
stack?: string | undefined;
|
|
25
|
-
stackOrder?: import("..").StackOrderType | undefined;
|
|
26
|
-
curve?: import("..").CurveType | undefined;
|
|
27
|
-
showMark?: boolean | ((params: import("..").ShowMarkParams<number | Date>) => boolean) | undefined;
|
|
28
|
-
disableHighlight: boolean;
|
|
29
|
-
connectNulls?: boolean | undefined;
|
|
30
|
-
type: "line";
|
|
31
|
-
}[];
|
|
32
|
-
width: number | undefined;
|
|
33
|
-
height: number | undefined;
|
|
34
|
-
margin: Partial<import("..").CardinalDirections<number>> | undefined;
|
|
35
|
-
colors: import("..").ChartsColorPalette | undefined;
|
|
36
|
-
dataset: import("../internals").DatasetType | undefined;
|
|
37
|
-
xAxis: import("../internals").MakeOptional<import("..").AxisConfig<import("..").ScaleName, any, import("..").ChartsXAxisProps>, "id">[];
|
|
38
|
-
yAxis: import("../internals").MakeOptional<import("..").AxisConfig<import("..").ScaleName, any, import("..").ChartsYAxisProps>, "id">[] | undefined;
|
|
39
|
-
sx: import("@mui/system").SxProps<import("@mui/material").Theme> | undefined;
|
|
40
|
-
highlightedItem: import("..").HighlightItemData | null | undefined;
|
|
41
|
-
onHighlightChange: ((highlightedItem: import("..").HighlightItemData | null) => void) | undefined;
|
|
42
|
-
disableAxisListener: boolean;
|
|
43
|
-
};
|
|
44
|
-
axisClickHandlerProps: {
|
|
45
|
-
onAxisClick: ((event: MouseEvent, data: {
|
|
46
|
-
dataIndex: number;
|
|
47
|
-
axisValue?: string | number | Date | undefined;
|
|
48
|
-
seriesValues: Record<string, number | null | undefined>;
|
|
49
|
-
} | null) => void) | undefined;
|
|
50
|
-
};
|
|
51
|
-
gridProps: {
|
|
52
|
-
vertical: boolean | undefined;
|
|
53
|
-
horizontal: boolean | undefined;
|
|
54
|
-
};
|
|
55
|
-
clipPathProps: {
|
|
56
|
-
id: string;
|
|
57
|
-
};
|
|
23
|
+
chartContainerProps: ResponsiveChartContainerProps;
|
|
24
|
+
axisClickHandlerProps: ChartsOnAxisClickHandlerProps;
|
|
25
|
+
gridProps: ChartsGridProps;
|
|
26
|
+
clipPathProps: ChartsClipPathProps;
|
|
58
27
|
clipPathGroupProps: {
|
|
59
28
|
clipPath: string;
|
|
60
29
|
};
|
|
61
|
-
areaPlotProps:
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
onLineClick: ((event: import("react").MouseEvent<SVGElement, MouseEvent>, lineItemIdentifier: import("..").LineItemIdentifier) => void) | undefined;
|
|
71
|
-
skipAnimation: boolean | undefined;
|
|
72
|
-
};
|
|
73
|
-
markPlotProps: {
|
|
74
|
-
slots: import("./LineChart").LineChartSlots | undefined;
|
|
75
|
-
slotProps: import("./LineChart").LineChartSlotProps | undefined;
|
|
76
|
-
onMarkClick: ((event: import("react").MouseEvent<SVGElement, MouseEvent>, lineItemIdentifier: import("..").LineItemIdentifier) => void) | undefined;
|
|
77
|
-
skipAnimation: boolean | undefined;
|
|
78
|
-
};
|
|
79
|
-
overlayProps: {
|
|
80
|
-
slots: import("./LineChart").LineChartSlots | undefined;
|
|
81
|
-
slotProps: import("./LineChart").LineChartSlotProps | undefined;
|
|
82
|
-
loading: boolean | undefined;
|
|
83
|
-
};
|
|
84
|
-
chartsAxisProps: {
|
|
85
|
-
topAxis: string | import("..").ChartsXAxisProps | null | undefined;
|
|
86
|
-
leftAxis: string | import("..").ChartsYAxisProps | null | undefined;
|
|
87
|
-
rightAxis: string | import("..").ChartsYAxisProps | null | undefined;
|
|
88
|
-
bottomAxis: string | import("..").ChartsXAxisProps | null | undefined;
|
|
89
|
-
slots: import("./LineChart").LineChartSlots | undefined;
|
|
90
|
-
slotProps: import("./LineChart").LineChartSlotProps | undefined;
|
|
91
|
-
};
|
|
92
|
-
axisHighlightProps: {
|
|
93
|
-
x: "none" | "line" | "band";
|
|
94
|
-
y?: ("none" | "line" | "band") | undefined;
|
|
95
|
-
};
|
|
96
|
-
lineHighlightPlotProps: {
|
|
97
|
-
slots: import("./LineChart").LineChartSlots | undefined;
|
|
98
|
-
slotProps: import("./LineChart").LineChartSlotProps | undefined;
|
|
99
|
-
};
|
|
100
|
-
legendProps: {
|
|
101
|
-
slots: import("./LineChart").LineChartSlots | undefined;
|
|
102
|
-
slotProps: import("./LineChart").LineChartSlotProps | undefined;
|
|
103
|
-
position?: import("..").AnchorPosition | undefined;
|
|
104
|
-
classes?: Partial<import("..").ChartsLegendClasses> | undefined;
|
|
105
|
-
hidden?: boolean | undefined;
|
|
106
|
-
direction?: import("..").Direction | undefined;
|
|
107
|
-
};
|
|
108
|
-
tooltipProps: {
|
|
109
|
-
slots: import("./LineChart").LineChartSlots | undefined;
|
|
110
|
-
slotProps: import("./LineChart").LineChartSlotProps | undefined;
|
|
111
|
-
trigger?: import("../ChartsTooltip/utils").TriggerOptions | undefined;
|
|
112
|
-
itemContent?: import("react").ElementType<import("..").ChartsItemContentProps<any>, keyof import("react").JSX.IntrinsicElements> | undefined;
|
|
113
|
-
axisContent?: import("react").ElementType<import("..").ChartsAxisContentProps, keyof import("react").JSX.IntrinsicElements> | undefined;
|
|
114
|
-
classes?: Partial<import("..").ChartsTooltipClasses> | undefined;
|
|
115
|
-
};
|
|
30
|
+
areaPlotProps: AreaPlotProps;
|
|
31
|
+
linePlotProps: LinePlotProps;
|
|
32
|
+
markPlotProps: MarkPlotProps;
|
|
33
|
+
overlayProps: ChartsOverlayProps;
|
|
34
|
+
chartsAxisProps: ChartsAxisProps;
|
|
35
|
+
axisHighlightProps: ChartsAxisHighlightProps;
|
|
36
|
+
lineHighlightPlotProps: LineHighlightPlotProps;
|
|
37
|
+
legendProps: ChartsLegendProps;
|
|
38
|
+
tooltipProps: ChartsTooltipProps;
|
|
116
39
|
children: import("react").ReactNode;
|
|
117
40
|
};
|
|
@@ -88,19 +88,19 @@ const useLineChartProps = props => {
|
|
|
88
88
|
const areaPlotProps = {
|
|
89
89
|
slots,
|
|
90
90
|
slotProps,
|
|
91
|
-
onAreaClick,
|
|
91
|
+
onItemClick: onAreaClick,
|
|
92
92
|
skipAnimation
|
|
93
93
|
};
|
|
94
94
|
const linePlotProps = {
|
|
95
95
|
slots,
|
|
96
96
|
slotProps,
|
|
97
|
-
onLineClick,
|
|
97
|
+
onItemClick: onLineClick,
|
|
98
98
|
skipAnimation
|
|
99
99
|
};
|
|
100
100
|
const markPlotProps = {
|
|
101
101
|
slots,
|
|
102
102
|
slotProps,
|
|
103
|
-
onMarkClick,
|
|
103
|
+
onItemClick: onMarkClick,
|
|
104
104
|
skipAnimation
|
|
105
105
|
};
|
|
106
106
|
const overlayProps = {
|
package/PieChart/PieArc.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
import type { ResponsiveChartContainerProps } from './ResponsiveChartContainer';
|
|
3
2
|
/**
|
|
4
3
|
* Wrapping div that take the shape of its parent.
|
|
@@ -6,5 +5,5 @@ import type { ResponsiveChartContainerProps } from './ResponsiveChartContainer';
|
|
|
6
5
|
* @ignore - do not document.
|
|
7
6
|
*/
|
|
8
7
|
export declare const ResizableContainer: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme> & {
|
|
9
|
-
ownerState: Pick<ResponsiveChartContainerProps,
|
|
8
|
+
ownerState: Pick<ResponsiveChartContainerProps, "width" | "height">;
|
|
10
9
|
}, Pick<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, keyof import("react").ClassAttributes<HTMLDivElement> | keyof import("react").HTMLAttributes<HTMLDivElement>>, {}>;
|
|
@@ -1,5 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
import { ChartsAxisProps } from '../ChartsAxis';
|
|
2
|
+
import { ChartsAxisHighlightProps } from '../ChartsAxisHighlight';
|
|
3
|
+
import { ChartsGridProps } from '../ChartsGrid';
|
|
4
|
+
import { ChartsLegendProps } from '../ChartsLegend';
|
|
5
|
+
import { ChartsOverlayProps } from '../ChartsOverlay';
|
|
6
|
+
import { ChartsTooltipProps } from '../ChartsTooltip';
|
|
7
|
+
import type { ChartsVoronoiHandlerProps } from '../ChartsVoronoiHandler';
|
|
8
|
+
import { ResponsiveChartContainerProps } from '../ResponsiveChartContainer';
|
|
9
|
+
import { ZAxisContextProviderProps } from '../context';
|
|
2
10
|
import type { ScatterChartProps } from './ScatterChart';
|
|
11
|
+
import type { ScatterPlotProps } from './ScatterPlot';
|
|
3
12
|
/**
|
|
4
13
|
* A helper function that extracts ScatterChartProps from the input props
|
|
5
14
|
* and returns an object with props for the children components of ScatterChart.
|
|
@@ -8,79 +17,15 @@ import type { ScatterChartProps } from './ScatterChart';
|
|
|
8
17
|
* @returns An object with props for the children components of ScatterChart
|
|
9
18
|
*/
|
|
10
19
|
export declare const useScatterChartProps: (props: ScatterChartProps) => {
|
|
11
|
-
chartContainerProps:
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
markerSize?: number | undefined;
|
|
22
|
-
disableHover?: boolean | undefined;
|
|
23
|
-
zAxisKey?: string | undefined;
|
|
24
|
-
type: "scatter";
|
|
25
|
-
}[];
|
|
26
|
-
width: number | undefined;
|
|
27
|
-
height: number | undefined;
|
|
28
|
-
margin: Partial<import("..").CardinalDirections<number>> | undefined;
|
|
29
|
-
colors: import("..").ChartsColorPalette | undefined;
|
|
30
|
-
xAxis: import("../internals").MakeOptional<import("..").AxisConfig<import("..").ScaleName, any, import("..").ChartsXAxisProps>, "id">[] | undefined;
|
|
31
|
-
yAxis: import("../internals").MakeOptional<import("..").AxisConfig<import("..").ScaleName, any, import("..").ChartsYAxisProps>, "id">[] | undefined;
|
|
32
|
-
sx: import("@mui/system").SxProps<import("@mui/material").Theme> | undefined;
|
|
33
|
-
highlightedItem: import("..").HighlightItemData | null | undefined;
|
|
34
|
-
onHighlightChange: ((highlightedItem: import("..").HighlightItemData | null) => void) | undefined;
|
|
35
|
-
};
|
|
36
|
-
zAxisProps: {
|
|
37
|
-
zAxis: import("../internals").MakeOptional<import("../internals").ZAxisConfig<any>, "id">[] | undefined;
|
|
38
|
-
};
|
|
39
|
-
voronoiHandlerProps: {
|
|
40
|
-
voronoiMaxRadius: number | undefined;
|
|
41
|
-
onItemClick: ((event: MouseEvent, scatterItemIdentifier: import("..").ScatterItemIdentifier) => void) | undefined;
|
|
42
|
-
};
|
|
43
|
-
chartsAxisProps: {
|
|
44
|
-
topAxis: string | import("..").ChartsXAxisProps | null | undefined;
|
|
45
|
-
leftAxis: string | import("..").ChartsYAxisProps | null | undefined;
|
|
46
|
-
rightAxis: string | import("..").ChartsYAxisProps | null | undefined;
|
|
47
|
-
bottomAxis: string | import("..").ChartsXAxisProps | null | undefined;
|
|
48
|
-
slots: import("./ScatterChart").ScatterChartSlots | undefined;
|
|
49
|
-
slotProps: import("./ScatterChart").ScatterChartSlotProps | undefined;
|
|
50
|
-
};
|
|
51
|
-
gridProps: {
|
|
52
|
-
vertical: boolean | undefined;
|
|
53
|
-
horizontal: boolean | undefined;
|
|
54
|
-
};
|
|
55
|
-
scatterPlotProps: {
|
|
56
|
-
onItemClick: ((event: import("react").MouseEvent<SVGElement, MouseEvent>, scatterItemIdentifier: import("..").ScatterItemIdentifier) => void) | undefined;
|
|
57
|
-
slots: import("./ScatterChart").ScatterChartSlots | undefined;
|
|
58
|
-
slotProps: import("./ScatterChart").ScatterChartSlotProps | undefined;
|
|
59
|
-
};
|
|
60
|
-
overlayProps: {
|
|
61
|
-
loading: boolean | undefined;
|
|
62
|
-
slots: import("./ScatterChart").ScatterChartSlots | undefined;
|
|
63
|
-
slotProps: import("./ScatterChart").ScatterChartSlotProps | undefined;
|
|
64
|
-
};
|
|
65
|
-
legendProps: {
|
|
66
|
-
slots: import("./ScatterChart").ScatterChartSlots | undefined;
|
|
67
|
-
slotProps: import("./ScatterChart").ScatterChartSlotProps | undefined;
|
|
68
|
-
position?: import("..").AnchorPosition | undefined;
|
|
69
|
-
classes?: Partial<import("..").ChartsLegendClasses> | undefined;
|
|
70
|
-
hidden?: boolean | undefined;
|
|
71
|
-
direction?: import("..").Direction | undefined;
|
|
72
|
-
};
|
|
73
|
-
axisHighlightProps: {
|
|
74
|
-
x: "none" | "line" | "band";
|
|
75
|
-
y: "none" | "line" | "band";
|
|
76
|
-
};
|
|
77
|
-
tooltipProps: {
|
|
78
|
-
slots: import("./ScatterChart").ScatterChartSlots | undefined;
|
|
79
|
-
slotProps: import("./ScatterChart").ScatterChartSlotProps | undefined;
|
|
80
|
-
trigger: import("../ChartsTooltip/utils").TriggerOptions;
|
|
81
|
-
itemContent?: import("react").ElementType<import("..").ChartsItemContentProps<any>, keyof import("react").JSX.IntrinsicElements> | undefined;
|
|
82
|
-
axisContent?: import("react").ElementType<import("..").ChartsAxisContentProps, keyof import("react").JSX.IntrinsicElements> | undefined;
|
|
83
|
-
classes?: Partial<import("..").ChartsTooltipClasses> | undefined;
|
|
84
|
-
};
|
|
20
|
+
chartContainerProps: ResponsiveChartContainerProps;
|
|
21
|
+
zAxisProps: Omit<ZAxisContextProviderProps, "children">;
|
|
22
|
+
voronoiHandlerProps: ChartsVoronoiHandlerProps;
|
|
23
|
+
chartsAxisProps: ChartsAxisProps;
|
|
24
|
+
gridProps: ChartsGridProps;
|
|
25
|
+
scatterPlotProps: ScatterPlotProps;
|
|
26
|
+
overlayProps: ChartsOverlayProps;
|
|
27
|
+
legendProps: ChartsLegendProps;
|
|
28
|
+
axisHighlightProps: ChartsAxisHighlightProps;
|
|
29
|
+
tooltipProps: ChartsTooltipProps;
|
|
85
30
|
children: import("react").ReactNode;
|
|
86
31
|
};
|
|
@@ -17,6 +17,13 @@ const getRange = (drawingArea, axisName, isReverse) => {
|
|
|
17
17
|
const range = axisName === 'x' ? [drawingArea.left, drawingArea.left + drawingArea.width] : [drawingArea.top + drawingArea.height, drawingArea.top];
|
|
18
18
|
return isReverse ? range.reverse() : range;
|
|
19
19
|
};
|
|
20
|
+
const isDateData = data => data?.[0] instanceof Date;
|
|
21
|
+
function createDateFormatter(axis, range) {
|
|
22
|
+
const timeScale = (0, _d3Scale.scaleTime)(axis.data, range);
|
|
23
|
+
return (v, {
|
|
24
|
+
location
|
|
25
|
+
}) => location === 'tick' ? timeScale.tickFormat(axis.tickNumber)(v) : `${v.toLocaleString()}`;
|
|
26
|
+
}
|
|
20
27
|
const DEFAULT_CATEGORY_GAP_RATIO = 0.2;
|
|
21
28
|
const DEFAULT_BAR_GAP_RATIO = 0.1;
|
|
22
29
|
function computeValue(drawingArea, formattedSeries, inAxis, extremumGetters, axisName) {
|
|
@@ -49,6 +56,10 @@ function computeValue(drawingArea, formattedSeries, inAxis, extremumGetters, axi
|
|
|
49
56
|
values: axis.data
|
|
50
57
|
}, axis.colorMap)) : (0, _colorScale.getColorScale)(axis.colorMap))
|
|
51
58
|
});
|
|
59
|
+
if (isDateData(axis.data)) {
|
|
60
|
+
const dateFormatter = createDateFormatter(axis, scaleRange);
|
|
61
|
+
completeAxis[axis.id].valueFormatter = axis.valueFormatter ?? dateFormatter;
|
|
62
|
+
}
|
|
52
63
|
}
|
|
53
64
|
if ((0, _axis.isPointScaleConfig)(axis)) {
|
|
54
65
|
const scaleRange = axisName === 'x' ? range : [...range].reverse();
|
|
@@ -59,6 +70,10 @@ function computeValue(drawingArea, formattedSeries, inAxis, extremumGetters, axi
|
|
|
59
70
|
values: axis.data
|
|
60
71
|
}, axis.colorMap)) : (0, _colorScale.getColorScale)(axis.colorMap))
|
|
61
72
|
});
|
|
73
|
+
if (isDateData(axis.data)) {
|
|
74
|
+
const dateFormatter = createDateFormatter(axis, scaleRange);
|
|
75
|
+
completeAxis[axis.id].valueFormatter = axis.valueFormatter ?? dateFormatter;
|
|
76
|
+
}
|
|
62
77
|
}
|
|
63
78
|
if (axis.scaleType === 'band' || axis.scaleType === 'point') {
|
|
64
79
|
// Could be merged with the two previous "if conditions" but then TS does not get that `axis.scaleType` can't be `band` or `point`.
|
|
@@ -2,4 +2,4 @@ import type { AxisConfig, ScaleName } from '../../models';
|
|
|
2
2
|
import { ChartsAxisProps } from '../../models/axis';
|
|
3
3
|
import { MakeOptional } from '../../models/helpers';
|
|
4
4
|
import { DatasetType } from '../../models/seriesType/config';
|
|
5
|
-
export declare const normalizeAxis: <T extends ChartsAxisProps, R extends MakeOptional<AxisConfig<ScaleName, any, T>, "id">>(axis: R[] | undefined, dataset: DatasetType | undefined, axisName:
|
|
5
|
+
export declare const normalizeAxis: <T extends ChartsAxisProps, R extends MakeOptional<AxisConfig<ScaleName, any, T>, "id">>(axis: R[] | undefined, dataset: DatasetType | undefined, axisName: "x" | "y") => R[] | undefined;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import useId from '@mui/utils/useId';
|
|
3
3
|
import { DEFAULT_X_AXIS_KEY, DEFAULT_Y_AXIS_KEY } from '../constants';
|
|
4
|
-
|
|
5
4
|
/**
|
|
6
5
|
* A helper function that extracts BarChartProps from the input props
|
|
7
6
|
* and returns an object with props for the children components of BarChart.
|
|
@@ -66,15 +66,30 @@ function ChartsAxisHighlight(props) {
|
|
|
66
66
|
} = React.useContext(InteractionContext);
|
|
67
67
|
const getXPosition = getValueToPositionMapper(xScale);
|
|
68
68
|
const getYPosition = getValueToPositionMapper(yScale);
|
|
69
|
+
const axisX = axis.x;
|
|
70
|
+
const axisY = axis.y;
|
|
71
|
+
const isBandScaleX = xAxisHighlight === 'band' && axisX !== null && isBandScale(xScale);
|
|
72
|
+
const isBandScaleY = yAxisHighlight === 'band' && axisY !== null && isBandScale(yScale);
|
|
73
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
74
|
+
const isXError = isBandScaleX && xScale(axisX.value) === undefined;
|
|
75
|
+
const isYError = isBandScaleY && yScale(axisY.value) === undefined;
|
|
76
|
+
if (isXError || isYError) {
|
|
77
|
+
console.error([`MUI X Charts: 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'));
|
|
78
|
+
}
|
|
79
|
+
}
|
|
69
80
|
return /*#__PURE__*/_jsxs(React.Fragment, {
|
|
70
|
-
children: [
|
|
71
|
-
|
|
81
|
+
children: [isBandScaleX && xScale(axisX.value) !== undefined && /*#__PURE__*/_jsx(ChartsAxisHighlightPath
|
|
82
|
+
// @ts-expect-error, xScale value is checked in the statement above
|
|
83
|
+
, {
|
|
84
|
+
d: `M ${xScale(axisX.value) - (xScale.step() - xScale.bandwidth()) / 2} ${yScale.range()[0]} l ${xScale.step()} 0 l 0 ${yScale.range()[1] - yScale.range()[0]} l ${-xScale.step()} 0 Z`,
|
|
72
85
|
className: classes.root,
|
|
73
86
|
ownerState: {
|
|
74
87
|
axisHighlight: 'band'
|
|
75
88
|
}
|
|
76
|
-
}),
|
|
77
|
-
d: `M ${xScale.range()[0]} ${
|
|
89
|
+
}), isBandScaleY && yScale(axisY.value) === undefined && /*#__PURE__*/_jsx(ChartsAxisHighlightPath, {
|
|
90
|
+
d: `M ${xScale.range()[0]} ${
|
|
91
|
+
// @ts-expect-error, yScale value is checked in the statement above
|
|
92
|
+
yScale(axisY.value) - (yScale.step() - yScale.bandwidth()) / 2} l 0 ${yScale.step()} l ${xScale.range()[1] - xScale.range()[0]} 0 l 0 ${-yScale.step()} Z`,
|
|
78
93
|
className: classes.root,
|
|
79
94
|
ownerState: {
|
|
80
95
|
axisHighlight: 'band'
|
|
@@ -5,7 +5,7 @@ import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
|
|
|
5
5
|
import { InteractionContext } from '../context/InteractionProvider';
|
|
6
6
|
import { useCartesianContext } from '../context/CartesianProvider';
|
|
7
7
|
import { getValueToPositionMapper } from '../hooks/useScale';
|
|
8
|
-
import { getSVGPoint } from '../internals/
|
|
8
|
+
import { getSVGPoint } from '../internals/getSVGPoint';
|
|
9
9
|
import { useDrawingArea, useSvgRef } from '../hooks';
|
|
10
10
|
import { useHighlighted } from '../context';
|
|
11
11
|
import { useScatterSeries } from '../hooks/useSeries';
|
|
@@ -81,6 +81,7 @@ function ChartsYAxis(inProps) {
|
|
|
81
81
|
tickLabelInterval
|
|
82
82
|
} = defaultizedProps;
|
|
83
83
|
const theme = useTheme();
|
|
84
|
+
const isRTL = theme.direction === 'rtl';
|
|
84
85
|
const classes = useUtilityClasses(_extends({}, defaultizedProps, {
|
|
85
86
|
theme
|
|
86
87
|
}));
|
|
@@ -108,13 +109,14 @@ function ChartsYAxis(inProps) {
|
|
|
108
109
|
const Tick = slots?.axisTick ?? 'line';
|
|
109
110
|
const TickLabel = slots?.axisTickLabel ?? ChartsText;
|
|
110
111
|
const Label = slots?.axisLabel ?? ChartsText;
|
|
112
|
+
const revertAnchor = !isRTL && position === 'right' || isRTL && position !== 'right';
|
|
111
113
|
const axisTickLabelProps = useSlotProps({
|
|
112
114
|
elementType: TickLabel,
|
|
113
115
|
externalSlotProps: slotProps?.axisTickLabel,
|
|
114
116
|
additionalProps: {
|
|
115
117
|
style: _extends({
|
|
116
118
|
fontSize: tickFontSize,
|
|
117
|
-
textAnchor:
|
|
119
|
+
textAnchor: revertAnchor ? 'start' : 'end',
|
|
118
120
|
dominantBaseline: 'central'
|
|
119
121
|
}, tickLabelStyle)
|
|
120
122
|
},
|
|
@@ -81,19 +81,19 @@ export const useLineChartProps = props => {
|
|
|
81
81
|
const areaPlotProps = {
|
|
82
82
|
slots,
|
|
83
83
|
slotProps,
|
|
84
|
-
onAreaClick,
|
|
84
|
+
onItemClick: onAreaClick,
|
|
85
85
|
skipAnimation
|
|
86
86
|
};
|
|
87
87
|
const linePlotProps = {
|
|
88
88
|
slots,
|
|
89
89
|
slotProps,
|
|
90
|
-
onLineClick,
|
|
90
|
+
onItemClick: onLineClick,
|
|
91
91
|
skipAnimation
|
|
92
92
|
};
|
|
93
93
|
const markPlotProps = {
|
|
94
94
|
slots,
|
|
95
95
|
slotProps,
|
|
96
|
-
onMarkClick,
|
|
96
|
+
onItemClick: onMarkClick,
|
|
97
97
|
skipAnimation
|
|
98
98
|
};
|
|
99
99
|
const overlayProps = {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
-
import { scaleBand, scalePoint } from 'd3-scale';
|
|
2
|
+
import { scaleBand, scalePoint, scaleTime } from 'd3-scale';
|
|
3
3
|
import { DEFAULT_X_AXIS_KEY, DEFAULT_Y_AXIS_KEY } from '../../constants';
|
|
4
4
|
import { isBandScaleConfig, isPointScaleConfig } from '../../models/axis';
|
|
5
5
|
import { getColorScale, getOrdinalColorScale } from '../../internals/colorScale';
|
|
@@ -10,6 +10,13 @@ const getRange = (drawingArea, axisName, isReverse) => {
|
|
|
10
10
|
const range = axisName === 'x' ? [drawingArea.left, drawingArea.left + drawingArea.width] : [drawingArea.top + drawingArea.height, drawingArea.top];
|
|
11
11
|
return isReverse ? range.reverse() : range;
|
|
12
12
|
};
|
|
13
|
+
const isDateData = data => data?.[0] instanceof Date;
|
|
14
|
+
function createDateFormatter(axis, range) {
|
|
15
|
+
const timeScale = scaleTime(axis.data, range);
|
|
16
|
+
return (v, {
|
|
17
|
+
location
|
|
18
|
+
}) => location === 'tick' ? timeScale.tickFormat(axis.tickNumber)(v) : `${v.toLocaleString()}`;
|
|
19
|
+
}
|
|
13
20
|
const DEFAULT_CATEGORY_GAP_RATIO = 0.2;
|
|
14
21
|
const DEFAULT_BAR_GAP_RATIO = 0.1;
|
|
15
22
|
export function computeValue(drawingArea, formattedSeries, inAxis, extremumGetters, axisName) {
|
|
@@ -42,6 +49,10 @@ export function computeValue(drawingArea, formattedSeries, inAxis, extremumGette
|
|
|
42
49
|
values: axis.data
|
|
43
50
|
}, axis.colorMap)) : getColorScale(axis.colorMap))
|
|
44
51
|
});
|
|
52
|
+
if (isDateData(axis.data)) {
|
|
53
|
+
const dateFormatter = createDateFormatter(axis, scaleRange);
|
|
54
|
+
completeAxis[axis.id].valueFormatter = axis.valueFormatter ?? dateFormatter;
|
|
55
|
+
}
|
|
45
56
|
}
|
|
46
57
|
if (isPointScaleConfig(axis)) {
|
|
47
58
|
const scaleRange = axisName === 'x' ? range : [...range].reverse();
|
|
@@ -52,6 +63,10 @@ export function computeValue(drawingArea, formattedSeries, inAxis, extremumGette
|
|
|
52
63
|
values: axis.data
|
|
53
64
|
}, axis.colorMap)) : getColorScale(axis.colorMap))
|
|
54
65
|
});
|
|
66
|
+
if (isDateData(axis.data)) {
|
|
67
|
+
const dateFormatter = createDateFormatter(axis, scaleRange);
|
|
68
|
+
completeAxis[axis.id].valueFormatter = axis.valueFormatter ?? dateFormatter;
|
|
69
|
+
}
|
|
55
70
|
}
|
|
56
71
|
if (axis.scaleType === 'band' || axis.scaleType === 'point') {
|
|
57
72
|
// Could be merged with the two previous "if conditions" but then TS does not get that `axis.scaleType` can't be `band` or `point`.
|
|
@@ -2,7 +2,7 @@ import * as React from 'react';
|
|
|
2
2
|
import { InteractionContext } from '../context/InteractionProvider';
|
|
3
3
|
import { useCartesianContext } from '../context/CartesianProvider';
|
|
4
4
|
import { isBandScale } from '../internals/isBandScale';
|
|
5
|
-
import { getSVGPoint } from '../internals/
|
|
5
|
+
import { getSVGPoint } from '../internals/getSVGPoint';
|
|
6
6
|
import { useSvgRef } from './useSvgRef';
|
|
7
7
|
import { useDrawingArea } from './useDrawingArea';
|
|
8
8
|
function getAsANumber(value) {
|
|
@@ -38,10 +38,7 @@ export const useAxisEvents = disableAxisListener => {
|
|
|
38
38
|
if (element === null || disableAxisListener) {
|
|
39
39
|
return () => {};
|
|
40
40
|
}
|
|
41
|
-
|
|
42
|
-
if (usedXAxis === null) {
|
|
43
|
-
return null;
|
|
44
|
-
}
|
|
41
|
+
function getNewAxisState(axisConfig, mouseValue) {
|
|
45
42
|
const {
|
|
46
43
|
scale,
|
|
47
44
|
data: axisData,
|
|
@@ -89,7 +86,7 @@ export const useAxisEvents = disableAxisListener => {
|
|
|
89
86
|
index: dataIndex,
|
|
90
87
|
value: axisData[dataIndex]
|
|
91
88
|
};
|
|
92
|
-
}
|
|
89
|
+
}
|
|
93
90
|
const handleOut = () => {
|
|
94
91
|
mousePosition.current = {
|
|
95
92
|
x: -1,
|
|
@@ -114,8 +111,8 @@ export const useAxisEvents = disableAxisListener => {
|
|
|
114
111
|
});
|
|
115
112
|
return;
|
|
116
113
|
}
|
|
117
|
-
const newStateX =
|
|
118
|
-
const newStateY =
|
|
114
|
+
const newStateX = getNewAxisState(xAxis[usedXAxis], svgPoint.x);
|
|
115
|
+
const newStateY = getNewAxisState(yAxis[usedYAxis], svgPoint.y);
|
|
119
116
|
dispatch({
|
|
120
117
|
type: 'updateAxis',
|
|
121
118
|
data: {
|
package/esm/hooks/useScale.js
CHANGED
|
@@ -8,7 +8,7 @@ import { isBandScale } from '../internals/isBandScale';
|
|
|
8
8
|
*/
|
|
9
9
|
export function getValueToPositionMapper(scale) {
|
|
10
10
|
if (isBandScale(scale)) {
|
|
11
|
-
return value => scale(value) + scale.bandwidth() / 2;
|
|
11
|
+
return value => (scale(value) ?? 0) + scale.bandwidth() / 2;
|
|
12
12
|
}
|
|
13
13
|
return value => scale(value);
|
|
14
14
|
}
|
package/esm/hooks/useTicks.js
CHANGED
|
@@ -34,7 +34,8 @@ export function useTicks(options) {
|
|
|
34
34
|
const domain = scale.domain();
|
|
35
35
|
if (scale.bandwidth() > 0) {
|
|
36
36
|
// scale type = 'band'
|
|
37
|
-
|
|
37
|
+
const filteredDomain = typeof tickInterval === 'function' && domain.filter(tickInterval) || typeof tickInterval === 'object' && tickInterval || domain;
|
|
38
|
+
return [...filteredDomain.map(value => ({
|
|
38
39
|
value,
|
|
39
40
|
formattedValue: valueFormatter?.(value, {
|
|
40
41
|
location: 'tick'
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transform mouse event position to coordinates inside the SVG.
|
|
3
|
+
* @param svg The SVG element
|
|
4
|
+
* @param event The mouseEvent to transform
|
|
5
|
+
*/
|
|
6
|
+
export function getSVGPoint(svg, event) {
|
|
7
|
+
const pt = svg.createSVGPoint();
|
|
8
|
+
pt.x = event.clientX;
|
|
9
|
+
pt.y = event.clientY;
|
|
10
|
+
return pt.matrixTransform(svg.getScreenCTM().inverse());
|
|
11
|
+
}
|
package/esm/internals/index.js
CHANGED
|
@@ -6,6 +6,7 @@ export * from '../ResponsiveChartContainer/ResizableContainer';
|
|
|
6
6
|
// hooks
|
|
7
7
|
export { useReducedMotion } from '../hooks/useReducedMotion';
|
|
8
8
|
export { useSeries } from '../hooks/useSeries';
|
|
9
|
+
export { useDrawingArea } from '../hooks/useDrawingArea';
|
|
9
10
|
export { useChartContainerHooks } from '../ChartContainer/useChartContainerHooks';
|
|
10
11
|
export { useScatterChartProps } from '../ScatterChart/useScatterChartProps';
|
|
11
12
|
export { useLineChartProps } from '../LineChart/useLineChartProps';
|
|
@@ -14,6 +15,7 @@ export { useBarChartProps } from '../BarChart/useBarChartProps';
|
|
|
14
15
|
// utils
|
|
15
16
|
export * from './defaultizeValueFormatter';
|
|
16
17
|
export * from './configInit';
|
|
18
|
+
export * from './getSVGPoint';
|
|
17
19
|
|
|
18
20
|
// contexts
|
|
19
21
|
|
package/esm/internals/utils.js
CHANGED
|
@@ -3,18 +3,6 @@ export function getSymbol(shape) {
|
|
|
3
3
|
const symbolNames = 'circle cross diamond square star triangle wye'.split(/ /);
|
|
4
4
|
return symbolNames.indexOf(shape) || 0;
|
|
5
5
|
}
|
|
6
|
-
/**
|
|
7
|
-
* Transform mouse event position to coordinates inside the SVG.
|
|
8
|
-
* @param svg The SVG element
|
|
9
|
-
* @param event The mouseEvent to transform
|
|
10
|
-
*/
|
|
11
|
-
export function getSVGPoint(svg, event) {
|
|
12
|
-
const pt = svg.createSVGPoint();
|
|
13
|
-
pt.x = event.clientX;
|
|
14
|
-
pt.y = event.clientY;
|
|
15
|
-
return pt.matrixTransform(svg.getScreenCTM().inverse());
|
|
16
|
-
}
|
|
17
|
-
|
|
18
6
|
/**
|
|
19
7
|
* Helper that converts values and percentages into values.
|
|
20
8
|
* @param value The value provided by the developer. Can either be a number or a string with '%' or 'px'.
|