@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
package/hooks/useAxisEvents.js
CHANGED
|
@@ -8,7 +8,7 @@ var React = _interopRequireWildcard(require("react"));
|
|
|
8
8
|
var _InteractionProvider = require("../context/InteractionProvider");
|
|
9
9
|
var _CartesianProvider = require("../context/CartesianProvider");
|
|
10
10
|
var _isBandScale = require("../internals/isBandScale");
|
|
11
|
-
var
|
|
11
|
+
var _getSVGPoint = require("../internals/getSVGPoint");
|
|
12
12
|
var _useSvgRef = require("./useSvgRef");
|
|
13
13
|
var _useDrawingArea = require("./useDrawingArea");
|
|
14
14
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
@@ -46,10 +46,7 @@ const useAxisEvents = disableAxisListener => {
|
|
|
46
46
|
if (element === null || disableAxisListener) {
|
|
47
47
|
return () => {};
|
|
48
48
|
}
|
|
49
|
-
|
|
50
|
-
if (usedXAxis === null) {
|
|
51
|
-
return null;
|
|
52
|
-
}
|
|
49
|
+
function getNewAxisState(axisConfig, mouseValue) {
|
|
53
50
|
const {
|
|
54
51
|
scale,
|
|
55
52
|
data: axisData,
|
|
@@ -97,7 +94,7 @@ const useAxisEvents = disableAxisListener => {
|
|
|
97
94
|
index: dataIndex,
|
|
98
95
|
value: axisData[dataIndex]
|
|
99
96
|
};
|
|
100
|
-
}
|
|
97
|
+
}
|
|
101
98
|
const handleOut = () => {
|
|
102
99
|
mousePosition.current = {
|
|
103
100
|
x: -1,
|
|
@@ -109,7 +106,7 @@ const useAxisEvents = disableAxisListener => {
|
|
|
109
106
|
};
|
|
110
107
|
const handleMove = event => {
|
|
111
108
|
const target = 'targetTouches' in event ? event.targetTouches[0] : event;
|
|
112
|
-
const svgPoint = (0,
|
|
109
|
+
const svgPoint = (0, _getSVGPoint.getSVGPoint)(svgRef.current, target);
|
|
113
110
|
mousePosition.current = {
|
|
114
111
|
x: svgPoint.x,
|
|
115
112
|
y: svgPoint.y
|
|
@@ -122,8 +119,8 @@ const useAxisEvents = disableAxisListener => {
|
|
|
122
119
|
});
|
|
123
120
|
return;
|
|
124
121
|
}
|
|
125
|
-
const newStateX =
|
|
126
|
-
const newStateY =
|
|
122
|
+
const newStateX = getNewAxisState(xAxis[usedXAxis], svgPoint.x);
|
|
123
|
+
const newStateY = getNewAxisState(yAxis[usedYAxis], svgPoint.y);
|
|
127
124
|
dispatch({
|
|
128
125
|
type: 'updateAxis',
|
|
129
126
|
data: {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { LayoutConfig } from '../models/layout';
|
|
2
|
-
declare const useChartDimensions: (width: number, height: number, margin: LayoutConfig[
|
|
2
|
+
declare const useChartDimensions: (width: number, height: number, margin: LayoutConfig["margin"]) => {
|
|
3
3
|
left: number;
|
|
4
4
|
top: number;
|
|
5
5
|
right: number;
|
package/hooks/useColor.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ChartSeriesType } from '../
|
|
1
|
+
import { ChartSeriesType } from '../models/seriesType/config';
|
|
2
2
|
import { ColorProcessorsConfig } from '../models/plugin';
|
|
3
3
|
export declare function useColorProcessor<T extends ChartSeriesType>(seriesType: T): ColorProcessorsConfig<ChartSeriesType>;
|
|
4
4
|
export declare function useColorProcessor(): ColorProcessorsConfig<ChartSeriesType>;
|
package/hooks/useScale.js
CHANGED
|
@@ -16,7 +16,7 @@ var _isBandScale = require("../internals/isBandScale");
|
|
|
16
16
|
*/
|
|
17
17
|
function getValueToPositionMapper(scale) {
|
|
18
18
|
if ((0, _isBandScale.isBandScale)(scale)) {
|
|
19
|
-
return value => scale(value) + scale.bandwidth() / 2;
|
|
19
|
+
return value => (scale(value) ?? 0) + scale.bandwidth() / 2;
|
|
20
20
|
}
|
|
21
21
|
return value => scale(value);
|
|
22
22
|
}
|
package/hooks/useTicks.js
CHANGED
|
@@ -43,7 +43,8 @@ function useTicks(options) {
|
|
|
43
43
|
const domain = scale.domain();
|
|
44
44
|
if (scale.bandwidth() > 0) {
|
|
45
45
|
// scale type = 'band'
|
|
46
|
-
|
|
46
|
+
const filteredDomain = typeof tickInterval === 'function' && domain.filter(tickInterval) || typeof tickInterval === 'object' && tickInterval || domain;
|
|
47
|
+
return [...filteredDomain.map(value => ({
|
|
47
48
|
value,
|
|
48
49
|
formattedValue: valueFormatter?.(value, {
|
|
49
50
|
location: 'tick'
|
package/index.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
export declare const AxisRoot: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme>, Pick<import("react").SVGProps<SVGGElement>, keyof import("react").SVGProps<SVGGElement>>, {}>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { AxisId } from '../../../models/axis';
|
|
3
|
-
export declare function useChartGradient(): (axisId: AxisId, direction:
|
|
3
|
+
export declare function useChartGradient(): (axisId: AxisId, direction: "x" | "y") => string;
|
|
4
4
|
export declare function ChartsAxesGradients(): React.JSX.Element;
|
|
@@ -2,92 +2,92 @@ import { AllSeriesType } from '../models/seriesType';
|
|
|
2
2
|
export declare function defaultizeColor(series: AllSeriesType, seriesIndex: number, colors?: string[]): {
|
|
3
3
|
data: {
|
|
4
4
|
color: string;
|
|
5
|
-
label?: string | ((location: "tooltip" | "legend" | "arc") => string)
|
|
5
|
+
label?: string | ((location: "tooltip" | "legend" | "arc") => string);
|
|
6
6
|
value: number;
|
|
7
7
|
id?: import("../models/seriesType").PieItemId | undefined;
|
|
8
8
|
}[];
|
|
9
9
|
type: "pie";
|
|
10
|
-
innerRadius?:
|
|
11
|
-
outerRadius?:
|
|
12
|
-
arcLabelRadius?:
|
|
13
|
-
cornerRadius?: number
|
|
14
|
-
startAngle?: number
|
|
15
|
-
endAngle?: number
|
|
16
|
-
paddingAngle?: number
|
|
17
|
-
sortingValues?: import("../models/seriesType").ChartsPieSorting
|
|
18
|
-
arcLabel?: "
|
|
19
|
-
label?: string
|
|
20
|
-
}) => string)
|
|
21
|
-
arcLabelMinAngle?: number
|
|
22
|
-
cx?:
|
|
23
|
-
cy?:
|
|
10
|
+
innerRadius?: number | string;
|
|
11
|
+
outerRadius?: number | string;
|
|
12
|
+
arcLabelRadius?: number | string;
|
|
13
|
+
cornerRadius?: number;
|
|
14
|
+
startAngle?: number;
|
|
15
|
+
endAngle?: number;
|
|
16
|
+
paddingAngle?: number;
|
|
17
|
+
sortingValues?: import("../models/seriesType").ChartsPieSorting;
|
|
18
|
+
arcLabel?: "formattedValue" | "label" | "value" | ((item: Omit<import("../models/seriesType").DefaultizedPieValueType, "label"> & {
|
|
19
|
+
label?: string;
|
|
20
|
+
}) => string);
|
|
21
|
+
arcLabelMinAngle?: number;
|
|
22
|
+
cx?: number | string;
|
|
23
|
+
cy?: number | string;
|
|
24
24
|
highlighted?: {
|
|
25
|
-
additionalRadius?: number
|
|
26
|
-
innerRadius?: number
|
|
27
|
-
outerRadius?: number
|
|
28
|
-
cornerRadius?: number
|
|
29
|
-
paddingAngle?: number
|
|
30
|
-
arcLabelRadius?: number
|
|
31
|
-
color?: string
|
|
32
|
-
}
|
|
25
|
+
additionalRadius?: number;
|
|
26
|
+
innerRadius?: number;
|
|
27
|
+
outerRadius?: number;
|
|
28
|
+
cornerRadius?: number;
|
|
29
|
+
paddingAngle?: number;
|
|
30
|
+
arcLabelRadius?: number;
|
|
31
|
+
color?: string;
|
|
32
|
+
};
|
|
33
33
|
faded?: {
|
|
34
|
-
additionalRadius?: number
|
|
35
|
-
innerRadius?: number
|
|
36
|
-
outerRadius?: number
|
|
37
|
-
cornerRadius?: number
|
|
38
|
-
paddingAngle?: number
|
|
39
|
-
arcLabelRadius?: number
|
|
40
|
-
color?: string
|
|
41
|
-
}
|
|
42
|
-
id?: import(".").SeriesId
|
|
43
|
-
color?: string
|
|
34
|
+
additionalRadius?: number;
|
|
35
|
+
innerRadius?: number;
|
|
36
|
+
outerRadius?: number;
|
|
37
|
+
cornerRadius?: number;
|
|
38
|
+
paddingAngle?: number;
|
|
39
|
+
arcLabelRadius?: number;
|
|
40
|
+
color?: string;
|
|
41
|
+
};
|
|
42
|
+
id?: import(".").SeriesId;
|
|
43
|
+
color?: string;
|
|
44
44
|
valueFormatter?: import(".").SeriesValueFormatter<import(".").MakeOptional<import("../models/seriesType").PieValueType, "id">> | undefined;
|
|
45
|
-
highlightScope?: Partial<import("..").HighlightScope
|
|
45
|
+
highlightScope?: Partial<import("..").HighlightScope>;
|
|
46
46
|
} | {
|
|
47
47
|
type: "bar";
|
|
48
|
-
data?: (number | null)[]
|
|
49
|
-
dataKey?: string
|
|
50
|
-
label?: string | ((location: "tooltip" | "legend") => string)
|
|
51
|
-
layout?: "horizontal" | "vertical"
|
|
52
|
-
stackOffset?: import("..").StackOffsetType
|
|
53
|
-
id?: import(".").SeriesId
|
|
48
|
+
data?: (number | null)[];
|
|
49
|
+
dataKey?: string;
|
|
50
|
+
label?: string | ((location: "tooltip" | "legend") => string);
|
|
51
|
+
layout?: "horizontal" | "vertical";
|
|
52
|
+
stackOffset?: import("..").StackOffsetType;
|
|
53
|
+
id?: import(".").SeriesId;
|
|
54
54
|
color: string;
|
|
55
55
|
valueFormatter?: import(".").SeriesValueFormatter<number | null> | undefined;
|
|
56
|
-
highlightScope?: Partial<import("..").HighlightScope
|
|
57
|
-
xAxisKey?: string
|
|
58
|
-
yAxisKey?: string
|
|
59
|
-
stack?: string
|
|
60
|
-
stackOrder?: import("..").StackOrderType
|
|
56
|
+
highlightScope?: Partial<import("..").HighlightScope>;
|
|
57
|
+
xAxisKey?: string;
|
|
58
|
+
yAxisKey?: string;
|
|
59
|
+
stack?: string;
|
|
60
|
+
stackOrder?: import("..").StackOrderType;
|
|
61
61
|
} | {
|
|
62
62
|
type: "line";
|
|
63
|
-
data?: (number | null)[]
|
|
64
|
-
dataKey?: string
|
|
65
|
-
stack?: string
|
|
66
|
-
area?: boolean
|
|
67
|
-
label?: string | ((location: "tooltip" | "legend") => string)
|
|
68
|
-
curve?: import("../models/seriesType").CurveType
|
|
69
|
-
showMark?: boolean | ((params: import("../models/seriesType").ShowMarkParams
|
|
70
|
-
disableHighlight?: boolean
|
|
71
|
-
connectNulls?: boolean
|
|
72
|
-
stackOffset?: import("..").StackOffsetType
|
|
73
|
-
id?: import(".").SeriesId
|
|
63
|
+
data?: (number | null)[];
|
|
64
|
+
dataKey?: string;
|
|
65
|
+
stack?: string;
|
|
66
|
+
area?: boolean;
|
|
67
|
+
label?: string | ((location: "tooltip" | "legend") => string);
|
|
68
|
+
curve?: import("../models/seriesType").CurveType;
|
|
69
|
+
showMark?: boolean | ((params: import("../models/seriesType").ShowMarkParams) => boolean);
|
|
70
|
+
disableHighlight?: boolean;
|
|
71
|
+
connectNulls?: boolean;
|
|
72
|
+
stackOffset?: import("..").StackOffsetType;
|
|
73
|
+
id?: import(".").SeriesId;
|
|
74
74
|
color: string;
|
|
75
75
|
valueFormatter?: import(".").SeriesValueFormatter<number | null> | undefined;
|
|
76
|
-
highlightScope?: Partial<import("..").HighlightScope
|
|
77
|
-
xAxisKey?: string
|
|
78
|
-
yAxisKey?: string
|
|
79
|
-
stackOrder?: import("..").StackOrderType
|
|
76
|
+
highlightScope?: Partial<import("..").HighlightScope>;
|
|
77
|
+
xAxisKey?: string;
|
|
78
|
+
yAxisKey?: string;
|
|
79
|
+
stackOrder?: import("..").StackOrderType;
|
|
80
80
|
} | {
|
|
81
81
|
type: "scatter";
|
|
82
82
|
data: import("../models/seriesType").ScatterValueType[];
|
|
83
|
-
markerSize?: number
|
|
84
|
-
label?: string | ((location: "tooltip" | "legend") => string)
|
|
85
|
-
disableHover?: boolean
|
|
86
|
-
zAxisKey?: string
|
|
87
|
-
id?: import(".").SeriesId
|
|
83
|
+
markerSize?: number;
|
|
84
|
+
label?: string | ((location: "tooltip" | "legend") => string);
|
|
85
|
+
disableHover?: boolean;
|
|
86
|
+
zAxisKey?: string;
|
|
87
|
+
id?: import(".").SeriesId;
|
|
88
88
|
color: string;
|
|
89
89
|
valueFormatter?: import(".").SeriesValueFormatter<import("../models/seriesType").ScatterValueType> | undefined;
|
|
90
|
-
highlightScope?: Partial<import("..").HighlightScope
|
|
91
|
-
xAxisKey?: string
|
|
92
|
-
yAxisKey?: string
|
|
90
|
+
highlightScope?: Partial<import("..").HighlightScope>;
|
|
91
|
+
xAxisKey?: string;
|
|
92
|
+
yAxisKey?: string;
|
|
93
93
|
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getSVGPoint = getSVGPoint;
|
|
7
|
+
/**
|
|
8
|
+
* Transform mouse event position to coordinates inside the SVG.
|
|
9
|
+
* @param svg The SVG element
|
|
10
|
+
* @param event The mouseEvent to transform
|
|
11
|
+
*/
|
|
12
|
+
function getSVGPoint(svg, event) {
|
|
13
|
+
const pt = svg.createSVGPoint();
|
|
14
|
+
pt.x = event.clientX;
|
|
15
|
+
pt.y = event.clientY;
|
|
16
|
+
return pt.matrixTransform(svg.getScreenCTM().inverse());
|
|
17
|
+
}
|
package/internals/index.d.ts
CHANGED
|
@@ -3,12 +3,14 @@ export * from '../ResponsiveChartContainer/useChartContainerDimensions';
|
|
|
3
3
|
export * from '../ResponsiveChartContainer/ResizableContainer';
|
|
4
4
|
export { useReducedMotion } from '../hooks/useReducedMotion';
|
|
5
5
|
export { useSeries } from '../hooks/useSeries';
|
|
6
|
+
export { useDrawingArea } from '../hooks/useDrawingArea';
|
|
6
7
|
export { useChartContainerHooks } from '../ChartContainer/useChartContainerHooks';
|
|
7
8
|
export { useScatterChartProps } from '../ScatterChart/useScatterChartProps';
|
|
8
9
|
export { useLineChartProps } from '../LineChart/useLineChartProps';
|
|
9
10
|
export { useBarChartProps } from '../BarChart/useBarChartProps';
|
|
10
11
|
export * from './defaultizeValueFormatter';
|
|
11
12
|
export * from './configInit';
|
|
13
|
+
export * from './getSVGPoint';
|
|
12
14
|
export * from '../context/CartesianProvider';
|
|
13
15
|
export * from '../context/DrawingProvider';
|
|
14
16
|
export * from '../context/ColorProvider';
|
package/internals/index.js
CHANGED
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
var _exportNames = {
|
|
7
7
|
useReducedMotion: true,
|
|
8
8
|
useSeries: true,
|
|
9
|
+
useDrawingArea: true,
|
|
9
10
|
useChartContainerHooks: true,
|
|
10
11
|
useScatterChartProps: true,
|
|
11
12
|
useLineChartProps: true,
|
|
@@ -23,6 +24,12 @@ Object.defineProperty(exports, "useChartContainerHooks", {
|
|
|
23
24
|
return _useChartContainerHooks.useChartContainerHooks;
|
|
24
25
|
}
|
|
25
26
|
});
|
|
27
|
+
Object.defineProperty(exports, "useDrawingArea", {
|
|
28
|
+
enumerable: true,
|
|
29
|
+
get: function () {
|
|
30
|
+
return _useDrawingArea.useDrawingArea;
|
|
31
|
+
}
|
|
32
|
+
});
|
|
26
33
|
Object.defineProperty(exports, "useLineChartProps", {
|
|
27
34
|
enumerable: true,
|
|
28
35
|
get: function () {
|
|
@@ -85,6 +92,7 @@ Object.keys(_ResizableContainer).forEach(function (key) {
|
|
|
85
92
|
});
|
|
86
93
|
var _useReducedMotion = require("../hooks/useReducedMotion");
|
|
87
94
|
var _useSeries = require("../hooks/useSeries");
|
|
95
|
+
var _useDrawingArea = require("../hooks/useDrawingArea");
|
|
88
96
|
var _useChartContainerHooks = require("../ChartContainer/useChartContainerHooks");
|
|
89
97
|
var _useScatterChartProps = require("../ScatterChart/useScatterChartProps");
|
|
90
98
|
var _useLineChartProps = require("../LineChart/useLineChartProps");
|
|
@@ -113,6 +121,18 @@ Object.keys(_configInit).forEach(function (key) {
|
|
|
113
121
|
}
|
|
114
122
|
});
|
|
115
123
|
});
|
|
124
|
+
var _getSVGPoint = require("./getSVGPoint");
|
|
125
|
+
Object.keys(_getSVGPoint).forEach(function (key) {
|
|
126
|
+
if (key === "default" || key === "__esModule") return;
|
|
127
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
128
|
+
if (key in exports && exports[key] === _getSVGPoint[key]) return;
|
|
129
|
+
Object.defineProperty(exports, key, {
|
|
130
|
+
enumerable: true,
|
|
131
|
+
get: function () {
|
|
132
|
+
return _getSVGPoint[key];
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
});
|
|
116
136
|
var _CartesianProvider = require("../context/CartesianProvider");
|
|
117
137
|
Object.keys(_CartesianProvider).forEach(function (key) {
|
|
118
138
|
if (key === "default" || key === "__esModule") return;
|
package/internals/utils.d.ts
CHANGED
|
@@ -4,12 +4,6 @@ type Without<T, U> = {
|
|
|
4
4
|
[P in Exclude<keyof T, keyof U>]?: never;
|
|
5
5
|
};
|
|
6
6
|
export type XOR<T, U> = T | U extends object ? (Without<T, U> & U) | (Without<U, T> & T) : T | U;
|
|
7
|
-
/**
|
|
8
|
-
* Transform mouse event position to coordinates inside the SVG.
|
|
9
|
-
* @param svg The SVG element
|
|
10
|
-
* @param event The mouseEvent to transform
|
|
11
|
-
*/
|
|
12
|
-
export declare function getSVGPoint(svg: SVGSVGElement, event: Pick<MouseEvent, 'clientX' | 'clientY'>): DOMPoint;
|
|
13
7
|
/**
|
|
14
8
|
* Helper that converts values and percentages into values.
|
|
15
9
|
* @param value The value provided by the developer. Can either be a number or a string with '%' or 'px'.
|
package/internals/utils.js
CHANGED
|
@@ -5,25 +5,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.cleanId = cleanId;
|
|
7
7
|
exports.getPercentageValue = getPercentageValue;
|
|
8
|
-
exports.getSVGPoint = getSVGPoint;
|
|
9
8
|
exports.getSymbol = getSymbol;
|
|
10
9
|
// Returns the index of a defined shape
|
|
11
10
|
function getSymbol(shape) {
|
|
12
11
|
const symbolNames = 'circle cross diamond square star triangle wye'.split(/ /);
|
|
13
12
|
return symbolNames.indexOf(shape) || 0;
|
|
14
13
|
}
|
|
15
|
-
/**
|
|
16
|
-
* Transform mouse event position to coordinates inside the SVG.
|
|
17
|
-
* @param svg The SVG element
|
|
18
|
-
* @param event The mouseEvent to transform
|
|
19
|
-
*/
|
|
20
|
-
function getSVGPoint(svg, event) {
|
|
21
|
-
const pt = svg.createSVGPoint();
|
|
22
|
-
pt.x = event.clientX;
|
|
23
|
-
pt.y = event.clientY;
|
|
24
|
-
return pt.matrixTransform(svg.getScreenCTM().inverse());
|
|
25
|
-
}
|
|
26
|
-
|
|
27
14
|
/**
|
|
28
15
|
* Helper that converts values and percentages into values.
|
|
29
16
|
* @param value The value provided by the developer. Can either be a number or a string with '%' or 'px'.
|
package/models/axis.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
import type { ScaleBand, ScaleLogarithmic, ScalePower, ScaleTime, ScaleLinear, ScalePoint, ScaleOrdinal, ScaleSequential, ScaleThreshold } from 'd3-scale';
|
|
3
2
|
import { ChartsAxisClasses } from '../ChartsAxis/axisClasses';
|
|
4
3
|
import type { TickParams } from '../hooks/useTicks';
|
|
@@ -126,7 +125,7 @@ export interface ChartsXAxisProps extends ChartsAxisProps {
|
|
|
126
125
|
*/
|
|
127
126
|
position?: 'top' | 'bottom';
|
|
128
127
|
}
|
|
129
|
-
export type ScaleName =
|
|
128
|
+
export type ScaleName = keyof AxisScaleConfig;
|
|
130
129
|
export type ContinuousScaleName = 'linear' | 'log' | 'pow' | 'sqrt' | 'time' | 'utc';
|
|
131
130
|
export interface AxisScaleConfig {
|
|
132
131
|
band: {
|
|
@@ -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/modern/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/modern/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'
|
package/modern/index.js
CHANGED