@mui/x-charts 8.11.0 → 8.11.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +169 -0
- package/ChartsXAxis/ChartsGroupedXAxisTicks.d.ts +8 -0
- package/ChartsXAxis/{ChartsGroupedXAxis.js → ChartsGroupedXAxisTicks.js} +9 -52
- package/ChartsXAxis/ChartsSingleXAxisTicks.d.ts +10 -0
- package/ChartsXAxis/{ChartsSingleXAxis.js → ChartsSingleXAxisTicks.js} +15 -51
- package/ChartsXAxis/ChartsXAxis.d.ts +1 -1
- package/ChartsXAxis/ChartsXAxis.js +8 -5
- package/ChartsXAxis/ChartsXAxisImpl.d.ts +13 -0
- package/ChartsXAxis/ChartsXAxisImpl.js +117 -0
- package/ChartsXAxis/{useAxisProps.d.ts → useAxisTicksProps.d.ts} +2 -497
- package/ChartsXAxis/{useAxisProps.js → useAxisTicksProps.js} +4 -31
- package/ChartsXAxis/utilities.d.ts +1 -2
- package/ChartsXAxis/utilities.js +1 -7
- package/{esm/ChartsYAxis/ChartsGroupedYAxis.d.ts → ChartsYAxis/ChartsGroupedYAxisTicks.d.ts} +2 -2
- package/ChartsYAxis/{ChartsGroupedYAxis.js → ChartsGroupedYAxisTicks.js} +9 -52
- package/ChartsYAxis/ChartsSingleYAxisTicks.d.ts +10 -0
- package/ChartsYAxis/{ChartsSingleYAxis.js → ChartsSingleYAxisTicks.js} +15 -50
- package/ChartsYAxis/ChartsYAxis.d.ts +1 -1
- package/ChartsYAxis/ChartsYAxis.js +10 -7
- package/ChartsYAxis/ChartsYAxisImpl.d.ts +13 -0
- package/ChartsYAxis/ChartsYAxisImpl.js +133 -0
- package/ChartsYAxis/{useAxisProps.d.ts → useAxisTicksProps.d.ts} +2 -505
- package/ChartsYAxis/{useAxisProps.js → useAxisTicksProps.js} +5 -44
- package/ChartsYAxis/utilities.d.ts +0 -1
- package/ChartsYAxis/utilities.js +1 -7
- package/RadarChart/RadarAxis/RadarAxis.d.ts +2 -2
- package/RadarChart/RadarAxis/RadarAxis.js +2 -2
- package/RadarChart/RadarAxis/RadarAxis.utils.d.ts +4 -4
- package/RadarChart/RadarAxis/RadarAxis.utils.js +4 -4
- package/esm/ChartsXAxis/ChartsGroupedXAxisTicks.d.ts +8 -0
- package/esm/ChartsXAxis/{ChartsGroupedXAxis.js → ChartsGroupedXAxisTicks.js} +10 -53
- package/esm/ChartsXAxis/ChartsSingleXAxisTicks.d.ts +10 -0
- package/esm/ChartsXAxis/{ChartsSingleXAxis.js → ChartsSingleXAxisTicks.js} +16 -54
- package/esm/ChartsXAxis/ChartsXAxis.d.ts +1 -1
- package/esm/ChartsXAxis/ChartsXAxis.js +8 -5
- package/esm/ChartsXAxis/ChartsXAxisImpl.d.ts +13 -0
- package/esm/ChartsXAxis/ChartsXAxisImpl.js +110 -0
- package/esm/ChartsXAxis/{useAxisProps.d.ts → useAxisTicksProps.d.ts} +2 -497
- package/esm/ChartsXAxis/{useAxisProps.js → useAxisTicksProps.js} +3 -29
- package/esm/ChartsXAxis/utilities.d.ts +1 -2
- package/esm/ChartsXAxis/utilities.js +0 -6
- package/{ChartsYAxis/ChartsGroupedYAxis.d.ts → esm/ChartsYAxis/ChartsGroupedYAxisTicks.d.ts} +2 -2
- package/esm/ChartsYAxis/{ChartsGroupedYAxis.js → ChartsGroupedYAxisTicks.js} +10 -53
- package/esm/ChartsYAxis/ChartsSingleYAxisTicks.d.ts +10 -0
- package/esm/ChartsYAxis/{ChartsSingleYAxis.js → ChartsSingleYAxisTicks.js} +16 -53
- package/esm/ChartsYAxis/ChartsYAxis.d.ts +1 -1
- package/esm/ChartsYAxis/ChartsYAxis.js +9 -6
- package/esm/ChartsYAxis/ChartsYAxisImpl.d.ts +13 -0
- package/esm/ChartsYAxis/ChartsYAxisImpl.js +126 -0
- package/esm/ChartsYAxis/{useAxisProps.d.ts → useAxisTicksProps.d.ts} +2 -505
- package/esm/ChartsYAxis/{useAxisProps.js → useAxisTicksProps.js} +4 -42
- package/esm/ChartsYAxis/utilities.d.ts +0 -1
- package/esm/ChartsYAxis/utilities.js +0 -6
- package/esm/RadarChart/RadarAxis/RadarAxis.d.ts +2 -2
- package/esm/RadarChart/RadarAxis/RadarAxis.js +2 -2
- package/esm/RadarChart/RadarAxis/RadarAxis.utils.d.ts +4 -4
- package/esm/RadarChart/RadarAxis/RadarAxis.utils.js +4 -4
- package/esm/hooks/useInteractionItemProps.js +5 -4
- package/esm/hooks/useTicks.js +8 -1
- package/esm/index.js +1 -1
- package/esm/internals/dateHelpers.d.ts +4 -2
- package/esm/internals/dateHelpers.js +5 -4
- package/esm/internals/defaultValueFormatters.js +5 -0
- package/esm/internals/getWordsByLines.d.ts +6 -0
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/computeAxisValue.js +5 -5
- package/esm/internals/plugins/featurePlugins/useChartPolarAxis/computeAxisValue.js +2 -2
- package/esm/locales/index.d.ts +2 -1
- package/esm/locales/index.js +1 -0
- package/esm/locales/svSE.d.ts +19 -0
- package/esm/locales/svSE.js +15 -0
- package/hooks/useInteractionItemProps.js +6 -4
- package/hooks/useTicks.js +8 -1
- package/index.js +1 -1
- package/internals/dateHelpers.d.ts +4 -2
- package/internals/dateHelpers.js +5 -4
- package/internals/defaultValueFormatters.js +5 -0
- package/internals/getWordsByLines.d.ts +6 -0
- package/internals/plugins/featurePlugins/useChartCartesianAxis/computeAxisValue.js +5 -5
- package/internals/plugins/featurePlugins/useChartPolarAxis/computeAxisValue.js +2 -2
- package/locales/index.d.ts +2 -1
- package/locales/index.js +11 -0
- package/locales/svSE.d.ts +19 -0
- package/locales/svSE.js +21 -0
- package/package.json +13 -13
- package/ChartsXAxis/ChartsGroupedXAxis.d.ts +0 -7
- package/ChartsXAxis/ChartsSingleXAxis.d.ts +0 -7
- package/ChartsYAxis/ChartsSingleYAxis.d.ts +0 -7
- package/esm/ChartsXAxis/ChartsGroupedXAxis.d.ts +0 -7
- package/esm/ChartsXAxis/ChartsSingleXAxis.d.ts +0 -7
- package/esm/ChartsYAxis/ChartsSingleYAxis.d.ts +0 -7
package/ChartsYAxis/utilities.js
CHANGED
|
@@ -4,11 +4,9 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.useUtilityClasses = exports.defaultProps = exports.
|
|
7
|
+
exports.useUtilityClasses = exports.defaultProps = exports.TICK_LABEL_GAP = exports.AXIS_LABEL_TICK_LABEL_GAP = void 0;
|
|
8
8
|
var _composeClasses = _interopRequireDefault(require("@mui/utils/composeClasses"));
|
|
9
|
-
var _styles = require("@mui/material/styles");
|
|
10
9
|
var _axisClasses = require("../ChartsAxis/axisClasses");
|
|
11
|
-
var _AxisSharedComponents = require("../internals/components/AxisSharedComponents");
|
|
12
10
|
const useUtilityClasses = ownerState => {
|
|
13
11
|
const {
|
|
14
12
|
classes,
|
|
@@ -31,10 +29,6 @@ exports.useUtilityClasses = useUtilityClasses;
|
|
|
31
29
|
const TICK_LABEL_GAP = exports.TICK_LABEL_GAP = 2;
|
|
32
30
|
/* Gap between the axis label and tick labels. */
|
|
33
31
|
const AXIS_LABEL_TICK_LABEL_GAP = exports.AXIS_LABEL_TICK_LABEL_GAP = 2;
|
|
34
|
-
const YAxisRoot = exports.YAxisRoot = (0, _styles.styled)(_AxisSharedComponents.AxisRoot, {
|
|
35
|
-
name: 'MuiChartsYAxis',
|
|
36
|
-
slot: 'Root'
|
|
37
|
-
})({});
|
|
38
32
|
const defaultProps = exports.defaultProps = {
|
|
39
33
|
disableLine: false,
|
|
40
34
|
disableTicks: false,
|
|
@@ -12,11 +12,11 @@ export interface RadarAxisProps extends UseRadarAxisParams {
|
|
|
12
12
|
/**
|
|
13
13
|
* The labels text anchor or a function returning the text anchor for a given axis angle (in degree).
|
|
14
14
|
*/
|
|
15
|
-
textAnchor?:
|
|
15
|
+
textAnchor?: React.SVGProps<SVGTextElement>['textAnchor'] | ((angle: number) => React.SVGProps<SVGTextElement>['textAnchor']);
|
|
16
16
|
/**
|
|
17
17
|
* The labels dominant baseline or a function returning the dominant baseline for a given axis angle (in degree).
|
|
18
18
|
*/
|
|
19
|
-
dominantBaseline?:
|
|
19
|
+
dominantBaseline?: React.SVGProps<SVGTextElement>['dominantBaseline'] | ((angle: number) => React.SVGProps<SVGTextElement>['dominantBaseline']);
|
|
20
20
|
/**
|
|
21
21
|
* Override or extend the styles applied to the component.
|
|
22
22
|
*/
|
|
@@ -81,7 +81,7 @@ process.env.NODE_ENV !== "production" ? RadarAxis.propTypes = {
|
|
|
81
81
|
/**
|
|
82
82
|
* The labels dominant baseline or a function returning the dominant baseline for a given axis angle (in degree).
|
|
83
83
|
*/
|
|
84
|
-
dominantBaseline: _propTypes.default.oneOfType([_propTypes.default.
|
|
84
|
+
dominantBaseline: _propTypes.default.oneOfType([_propTypes.default.oneOf(['alphabetic', 'auto', 'central', 'hanging', 'ideographic', 'inherit', 'mathematical', 'middle', 'no-change', 'reset-size', 'text-after-edge', 'text-before-edge', 'use-script']), _propTypes.default.func]),
|
|
85
85
|
/**
|
|
86
86
|
* Defines how label align with the axis.
|
|
87
87
|
* - 'horizontal': labels stay horizontal and their placement change with the axis angle.
|
|
@@ -97,5 +97,5 @@ process.env.NODE_ENV !== "production" ? RadarAxis.propTypes = {
|
|
|
97
97
|
/**
|
|
98
98
|
* The labels text anchor or a function returning the text anchor for a given axis angle (in degree).
|
|
99
99
|
*/
|
|
100
|
-
textAnchor: _propTypes.default.oneOfType([_propTypes.default.
|
|
100
|
+
textAnchor: _propTypes.default.oneOfType([_propTypes.default.oneOf(['end', 'inherit', 'middle', 'start']), _propTypes.default.func])
|
|
101
101
|
} : void 0;
|
|
@@ -7,14 +7,14 @@ interface GetLabelAttributesParams extends Required<Pick<RadarAxisProps, 'labelO
|
|
|
7
7
|
export declare function getLabelAttributes(params: GetLabelAttributesParams): {
|
|
8
8
|
x: number;
|
|
9
9
|
y: number;
|
|
10
|
-
textAnchor:
|
|
11
|
-
dominantBaseline:
|
|
10
|
+
textAnchor: "inherit" | "end" | "start" | "middle" | undefined;
|
|
11
|
+
dominantBaseline: "inherit" | "auto" | "middle" | "alphabetic" | "hanging" | "ideographic" | "mathematical" | "text-before-edge" | "central" | "text-after-edge" | "use-script" | "no-change" | "reset-size" | undefined;
|
|
12
12
|
transform?: undefined;
|
|
13
13
|
} | {
|
|
14
14
|
x: number;
|
|
15
15
|
y: number;
|
|
16
|
-
textAnchor:
|
|
17
|
-
dominantBaseline:
|
|
16
|
+
textAnchor: "inherit" | "end" | "start" | "middle" | undefined;
|
|
17
|
+
dominantBaseline: "inherit" | "auto" | "middle" | "alphabetic" | "hanging" | "ideographic" | "mathematical" | "text-before-edge" | "central" | "text-after-edge" | "use-script" | "no-change" | "reset-size" | undefined;
|
|
18
18
|
transform: string;
|
|
19
19
|
};
|
|
20
20
|
export {};
|
|
@@ -25,12 +25,12 @@ function getTextAnchor(angle) {
|
|
|
25
25
|
}
|
|
26
26
|
function getDominantBaseline(angle) {
|
|
27
27
|
if (angle < 160) {
|
|
28
|
-
return '
|
|
28
|
+
return 'auto';
|
|
29
29
|
}
|
|
30
30
|
if (angle < 360 - 20) {
|
|
31
31
|
return 'hanging';
|
|
32
32
|
}
|
|
33
|
-
return '
|
|
33
|
+
return 'auto';
|
|
34
34
|
}
|
|
35
35
|
const LABEL_MARGIN = 2;
|
|
36
36
|
function getLabelAttributes(params) {
|
|
@@ -43,7 +43,7 @@ function getLabelAttributes(params) {
|
|
|
43
43
|
const textAnchor = typeof params.textAnchor === 'function' ? params.textAnchor(angle) : params.textAnchor ?? getTextAnchor(angle);
|
|
44
44
|
const dominantBaseline = typeof params.dominantBaseline === 'function' ? params.dominantBaseline(angle) : params.dominantBaseline ?? getDominantBaseline(angle);
|
|
45
45
|
const marginX = textAnchor === 'start' ? LABEL_MARGIN : -LABEL_MARGIN;
|
|
46
|
-
const marginY = dominantBaseline === '
|
|
46
|
+
const marginY = dominantBaseline === 'auto' ? -LABEL_MARGIN : LABEL_MARGIN;
|
|
47
47
|
return {
|
|
48
48
|
x: x + marginX,
|
|
49
49
|
y: y + marginY,
|
|
@@ -55,7 +55,7 @@ function getLabelAttributes(params) {
|
|
|
55
55
|
// orientation='rotated'
|
|
56
56
|
|
|
57
57
|
const textAnchor = typeof params.textAnchor === 'function' ? params.textAnchor(angle) : params.textAnchor ?? 'start';
|
|
58
|
-
const dominantBaseline = typeof params.dominantBaseline === 'function' ? params.dominantBaseline(angle) : params.dominantBaseline ?? '
|
|
58
|
+
const dominantBaseline = typeof params.dominantBaseline === 'function' ? params.dominantBaseline(angle) : params.dominantBaseline ?? 'auto';
|
|
59
59
|
return {
|
|
60
60
|
x,
|
|
61
61
|
y,
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { ChartsXAxisProps } from "../models/axis.js";
|
|
3
|
+
interface ChartsGroupedXAxisProps extends ChartsXAxisProps {}
|
|
4
|
+
/**
|
|
5
|
+
* @ignore - internal component.
|
|
6
|
+
*/
|
|
7
|
+
declare function ChartsGroupedXAxisTicks(inProps: ChartsGroupedXAxisProps): React.JSX.Element;
|
|
8
|
+
export { ChartsGroupedXAxisTicks };
|
|
@@ -2,12 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
4
4
|
import * as React from 'react';
|
|
5
|
-
import { useDrawingArea } from "../hooks/useDrawingArea.js";
|
|
6
5
|
import { isBandScale } from "../internals/isBandScale.js";
|
|
7
6
|
import { useChartContext } from "../context/ChartProvider/useChartContext.js";
|
|
8
|
-
import { TICK_LABEL_GAP
|
|
7
|
+
import { TICK_LABEL_GAP } from "./utilities.js";
|
|
9
8
|
import { useTicksGrouped } from "../hooks/useTicksGrouped.js";
|
|
10
|
-
import {
|
|
9
|
+
import { useAxisTicksProps } from "./useAxisTicksProps.js";
|
|
11
10
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
12
11
|
const DEFAULT_GROUPING_CONFIG = {
|
|
13
12
|
tickSize: 6
|
|
@@ -20,58 +19,36 @@ const getGroupingConfig = (groups, groupIndex, tickSize) => {
|
|
|
20
19
|
tickSize: config.tickSize ?? calculatedTickSize
|
|
21
20
|
});
|
|
22
21
|
};
|
|
23
|
-
|
|
24
22
|
/**
|
|
25
23
|
* @ignore - internal component.
|
|
26
24
|
*/
|
|
27
|
-
function
|
|
25
|
+
function ChartsGroupedXAxisTicks(inProps) {
|
|
28
26
|
const {
|
|
29
27
|
xScale,
|
|
30
28
|
defaultizedProps,
|
|
31
29
|
tickNumber,
|
|
32
30
|
positionSign,
|
|
33
|
-
skipAxisRendering,
|
|
34
31
|
classes,
|
|
35
|
-
Line,
|
|
36
32
|
Tick,
|
|
37
33
|
TickLabel,
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
axisLabelProps
|
|
41
|
-
} = useAxisProps(inProps);
|
|
34
|
+
axisTickLabelProps
|
|
35
|
+
} = useAxisTicksProps(inProps);
|
|
42
36
|
if (!isBandScale(xScale)) {
|
|
43
37
|
throw new Error('MUI X Charts: ChartsGroupedXAxis only supports the `band` and `point` scale types.');
|
|
44
38
|
}
|
|
45
39
|
const {
|
|
46
|
-
position,
|
|
47
|
-
disableLine,
|
|
48
40
|
disableTicks,
|
|
49
|
-
label,
|
|
50
41
|
tickSize,
|
|
51
42
|
valueFormatter,
|
|
52
43
|
slotProps,
|
|
53
44
|
tickInterval,
|
|
54
45
|
tickPlacement,
|
|
55
|
-
tickLabelPlacement
|
|
56
|
-
sx,
|
|
57
|
-
offset,
|
|
58
|
-
height: axisHeight
|
|
46
|
+
tickLabelPlacement
|
|
59
47
|
} = defaultizedProps;
|
|
60
48
|
const groups = defaultizedProps.groups;
|
|
61
|
-
const drawingArea = useDrawingArea();
|
|
62
|
-
const {
|
|
63
|
-
left,
|
|
64
|
-
top,
|
|
65
|
-
width,
|
|
66
|
-
height
|
|
67
|
-
} = drawingArea;
|
|
68
49
|
const {
|
|
69
50
|
instance
|
|
70
51
|
} = useChartContext();
|
|
71
|
-
const labelRefPoint = {
|
|
72
|
-
x: left + width / 2,
|
|
73
|
-
y: positionSign * axisHeight
|
|
74
|
-
};
|
|
75
52
|
const xTicks = useTicksGrouped({
|
|
76
53
|
scale: xScale,
|
|
77
54
|
tickNumber,
|
|
@@ -82,23 +59,8 @@ function ChartsGroupedXAxis(inProps) {
|
|
|
82
59
|
direction: 'x',
|
|
83
60
|
groups
|
|
84
61
|
});
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
// - The domain is an empty array for band/point scales.
|
|
88
|
-
// - The domains contains Infinity for continuous scales.
|
|
89
|
-
// - The position is set to 'none'.
|
|
90
|
-
if (skipAxisRendering) {
|
|
91
|
-
return null;
|
|
92
|
-
}
|
|
93
|
-
return /*#__PURE__*/_jsxs(XAxisRoot, {
|
|
94
|
-
transform: `translate(0, ${position === 'bottom' ? top + height + offset : top - offset})`,
|
|
95
|
-
className: classes.root,
|
|
96
|
-
sx: sx,
|
|
97
|
-
children: [!disableLine && /*#__PURE__*/_jsx(Line, _extends({
|
|
98
|
-
x1: left,
|
|
99
|
-
x2: left + width,
|
|
100
|
-
className: classes.line
|
|
101
|
-
}, slotProps?.axisLine)), xTicks.map((item, index) => {
|
|
62
|
+
return /*#__PURE__*/_jsx(React.Fragment, {
|
|
63
|
+
children: xTicks.map((item, index) => {
|
|
102
64
|
const {
|
|
103
65
|
offset: tickOffset,
|
|
104
66
|
labelOffset
|
|
@@ -126,12 +88,7 @@ function ChartsGroupedXAxis(inProps) {
|
|
|
126
88
|
text: tickLabel
|
|
127
89
|
}))]
|
|
128
90
|
}, index);
|
|
129
|
-
})
|
|
130
|
-
className: classes.label,
|
|
131
|
-
children: /*#__PURE__*/_jsx(Label, _extends({}, labelRefPoint, axisLabelProps, {
|
|
132
|
-
text: label
|
|
133
|
-
}))
|
|
134
|
-
})]
|
|
91
|
+
})
|
|
135
92
|
});
|
|
136
93
|
}
|
|
137
|
-
export {
|
|
94
|
+
export { ChartsGroupedXAxisTicks };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { ChartsXAxisProps } from "../models/axis.js";
|
|
3
|
+
interface ChartsSingleXAxisProps extends ChartsXAxisProps {
|
|
4
|
+
axisLabelHeight: number;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* @ignore - internal component.
|
|
8
|
+
*/
|
|
9
|
+
declare function ChartsSingleXAxisTicks(inProps: ChartsSingleXAxisProps): React.JSX.Element;
|
|
10
|
+
export { ChartsSingleXAxisTicks };
|
|
@@ -2,44 +2,39 @@
|
|
|
2
2
|
|
|
3
3
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
4
4
|
import * as React from 'react';
|
|
5
|
+
import { useRtl } from '@mui/system/RtlProvider';
|
|
5
6
|
import { useIsHydrated } from "../hooks/useIsHydrated.js";
|
|
6
|
-
import { getStringSize } from "../internals/domUtils.js";
|
|
7
7
|
import { useTicks } from "../hooks/useTicks.js";
|
|
8
8
|
import { useMounted } from "../hooks/useMounted.js";
|
|
9
9
|
import { useDrawingArea } from "../hooks/useDrawingArea.js";
|
|
10
10
|
import { useChartContext } from "../context/ChartProvider/useChartContext.js";
|
|
11
11
|
import { shortenLabels } from "./shortenLabels.js";
|
|
12
12
|
import { getVisibleLabels } from "./getVisibleLabels.js";
|
|
13
|
-
import { AXIS_LABEL_TICK_LABEL_GAP, TICK_LABEL_GAP
|
|
14
|
-
import {
|
|
15
|
-
|
|
13
|
+
import { AXIS_LABEL_TICK_LABEL_GAP, TICK_LABEL_GAP } from "./utilities.js";
|
|
14
|
+
import { useAxisTicksProps } from "./useAxisTicksProps.js";
|
|
15
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
16
16
|
/**
|
|
17
17
|
* @ignore - internal component.
|
|
18
18
|
*/
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
function ChartsSingleXAxisTicks(inProps) {
|
|
20
|
+
const {
|
|
21
|
+
axisLabelHeight
|
|
22
|
+
} = inProps;
|
|
21
23
|
const {
|
|
22
24
|
xScale,
|
|
23
25
|
defaultizedProps,
|
|
24
26
|
tickNumber,
|
|
25
27
|
positionSign,
|
|
26
|
-
skipAxisRendering,
|
|
27
28
|
classes,
|
|
28
|
-
Line,
|
|
29
29
|
Tick,
|
|
30
30
|
TickLabel,
|
|
31
|
-
Label,
|
|
32
31
|
axisTickLabelProps,
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
} = useAxisProps(inProps);
|
|
32
|
+
reverse
|
|
33
|
+
} = useAxisTicksProps(inProps);
|
|
34
|
+
const isRtl = useRtl();
|
|
37
35
|
const isMounted = useMounted();
|
|
38
36
|
const {
|
|
39
|
-
position,
|
|
40
|
-
disableLine,
|
|
41
37
|
disableTicks,
|
|
42
|
-
label,
|
|
43
38
|
tickSize: tickSizeProp,
|
|
44
39
|
valueFormatter,
|
|
45
40
|
slotProps,
|
|
@@ -48,17 +43,9 @@ function ChartsSingleXAxis(inProps) {
|
|
|
48
43
|
tickPlacement,
|
|
49
44
|
tickLabelPlacement,
|
|
50
45
|
tickLabelMinGap,
|
|
51
|
-
sx,
|
|
52
|
-
offset,
|
|
53
46
|
height: axisHeight
|
|
54
47
|
} = defaultizedProps;
|
|
55
48
|
const drawingArea = useDrawingArea();
|
|
56
|
-
const {
|
|
57
|
-
left,
|
|
58
|
-
top,
|
|
59
|
-
width,
|
|
60
|
-
height
|
|
61
|
-
} = drawingArea;
|
|
62
49
|
const {
|
|
63
50
|
instance
|
|
64
51
|
} = useChartContext();
|
|
@@ -82,31 +69,11 @@ function ChartsSingleXAxis(inProps) {
|
|
|
82
69
|
isXInside: instance.isXInside
|
|
83
70
|
});
|
|
84
71
|
|
|
85
|
-
// Skip axis rendering if no data is available
|
|
86
|
-
// - The domain is an empty array for band/point scales.
|
|
87
|
-
// - The domains contains Infinity for continuous scales.
|
|
88
|
-
// - The position is set to 'none'.
|
|
89
|
-
if (skipAxisRendering) {
|
|
90
|
-
return null;
|
|
91
|
-
}
|
|
92
|
-
const labelHeight = label ? getStringSize(label, axisLabelProps.style).height : 0;
|
|
93
|
-
const labelRefPoint = {
|
|
94
|
-
x: left + width / 2,
|
|
95
|
-
y: positionSign * axisHeight
|
|
96
|
-
};
|
|
97
|
-
|
|
98
72
|
/* If there's an axis title, the tick labels have less space to render */
|
|
99
|
-
const tickLabelsMaxHeight = Math.max(0, axisHeight - (
|
|
73
|
+
const tickLabelsMaxHeight = Math.max(0, axisHeight - (axisLabelHeight > 0 ? axisLabelHeight + AXIS_LABEL_TICK_LABEL_GAP : 0) - tickSize - TICK_LABEL_GAP);
|
|
100
74
|
const tickLabels = isHydrated ? shortenLabels(visibleLabels, drawingArea, tickLabelsMaxHeight, isRtl, axisTickLabelProps.style) : new Map(Array.from(visibleLabels).map(item => [item, item.formattedValue]));
|
|
101
|
-
return /*#__PURE__*/
|
|
102
|
-
|
|
103
|
-
className: classes.root,
|
|
104
|
-
sx: sx,
|
|
105
|
-
children: [!disableLine && /*#__PURE__*/_jsx(Line, _extends({
|
|
106
|
-
x1: left,
|
|
107
|
-
x2: left + width,
|
|
108
|
-
className: classes.line
|
|
109
|
-
}, slotProps?.axisLine)), xTicks.map((item, index) => {
|
|
75
|
+
return /*#__PURE__*/_jsx(React.Fragment, {
|
|
76
|
+
children: xTicks.map((item, index) => {
|
|
110
77
|
const {
|
|
111
78
|
offset: tickOffset,
|
|
112
79
|
labelOffset
|
|
@@ -129,12 +96,7 @@ function ChartsSingleXAxis(inProps) {
|
|
|
129
96
|
text: tickLabel
|
|
130
97
|
}))]
|
|
131
98
|
}, index);
|
|
132
|
-
})
|
|
133
|
-
className: classes.label,
|
|
134
|
-
children: /*#__PURE__*/_jsx(Label, _extends({}, labelRefPoint, axisLabelProps, {
|
|
135
|
-
text: label
|
|
136
|
-
}))
|
|
137
|
-
})]
|
|
99
|
+
})
|
|
138
100
|
});
|
|
139
101
|
}
|
|
140
|
-
export {
|
|
102
|
+
export { ChartsSingleXAxisTicks };
|
|
@@ -9,7 +9,7 @@ import { ChartsXAxisProps } from "../models/axis.js";
|
|
|
9
9
|
*
|
|
10
10
|
* - [ChartsXAxis API](https://mui.com/x/api/charts/charts-x-axis/)
|
|
11
11
|
*/
|
|
12
|
-
declare function ChartsXAxis(inProps: ChartsXAxisProps): React.JSX.Element;
|
|
12
|
+
declare function ChartsXAxis(inProps: ChartsXAxisProps): React.JSX.Element | null;
|
|
13
13
|
declare namespace ChartsXAxis {
|
|
14
14
|
var propTypes: any;
|
|
15
15
|
}
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import PropTypes from 'prop-types';
|
|
6
|
+
import { warnOnce } from '@mui/x-internals/warning';
|
|
6
7
|
import { useXAxes } from "../hooks/useAxis.js";
|
|
7
|
-
import {
|
|
8
|
-
import { ChartsGroupedXAxis } from "./ChartsGroupedXAxis.js";
|
|
8
|
+
import { ChartsXAxisImpl } from "./ChartsXAxisImpl.js";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Demos:
|
|
@@ -23,10 +23,13 @@ function ChartsXAxis(inProps) {
|
|
|
23
23
|
xAxisIds
|
|
24
24
|
} = useXAxes();
|
|
25
25
|
const axis = xAxis[inProps.axisId ?? xAxisIds[0]];
|
|
26
|
-
if (
|
|
27
|
-
|
|
26
|
+
if (!axis) {
|
|
27
|
+
warnOnce(`MUI X Charts: No axis found. The axisId "${inProps.axisId}" is probably invalid.`);
|
|
28
|
+
return null;
|
|
28
29
|
}
|
|
29
|
-
return /*#__PURE__*/_jsx(
|
|
30
|
+
return /*#__PURE__*/_jsx(ChartsXAxisImpl, _extends({}, inProps, {
|
|
31
|
+
axis: axis
|
|
32
|
+
}));
|
|
30
33
|
}
|
|
31
34
|
process.env.NODE_ENV !== "production" ? ChartsXAxis.propTypes = {
|
|
32
35
|
// ----------------------------- Warning --------------------------------
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { AxisScaleConfig, ChartsXAxisProps, ComputedAxis } from "../models/axis.js";
|
|
3
|
+
interface ChartsXAxisImplProps extends Omit<ChartsXAxisProps, 'axis'> {
|
|
4
|
+
axis: ComputedAxis<keyof AxisScaleConfig, any, ChartsXAxisProps>;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* @ignore - internal component. Use `ChartsXAxis` instead.
|
|
8
|
+
*/
|
|
9
|
+
export declare function ChartsXAxisImpl({
|
|
10
|
+
axis,
|
|
11
|
+
...inProps
|
|
12
|
+
}: ChartsXAxisImplProps): React.JSX.Element | null;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
4
|
+
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
5
|
+
const _excluded = ["axis"],
|
|
6
|
+
_excluded2 = ["scale", "tickNumber", "reverse"];
|
|
7
|
+
import * as React from 'react';
|
|
8
|
+
import useSlotProps from '@mui/utils/useSlotProps';
|
|
9
|
+
import { styled, useTheme, useThemeProps } from '@mui/material/styles';
|
|
10
|
+
import { ChartsSingleXAxisTicks } from "./ChartsSingleXAxisTicks.js";
|
|
11
|
+
import { ChartsGroupedXAxisTicks } from "./ChartsGroupedXAxisTicks.js";
|
|
12
|
+
import { ChartsText } from "../ChartsText/index.js";
|
|
13
|
+
import { isBandScale } from "../internals/isBandScale.js";
|
|
14
|
+
import { isInfinity } from "../internals/isInfinity.js";
|
|
15
|
+
import { defaultProps, useUtilityClasses } from "./utilities.js";
|
|
16
|
+
import { useDrawingArea } from "../hooks/index.js";
|
|
17
|
+
import { getStringSize } from "../internals/domUtils.js";
|
|
18
|
+
import { AxisRoot } from "../internals/components/AxisSharedComponents.js";
|
|
19
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
20
|
+
const XAxisRoot = styled(AxisRoot, {
|
|
21
|
+
name: 'MuiChartsXAxis',
|
|
22
|
+
slot: 'Root'
|
|
23
|
+
})({});
|
|
24
|
+
/**
|
|
25
|
+
* @ignore - internal component. Use `ChartsXAxis` instead.
|
|
26
|
+
*/
|
|
27
|
+
export function ChartsXAxisImpl(_ref) {
|
|
28
|
+
let {
|
|
29
|
+
axis
|
|
30
|
+
} = _ref,
|
|
31
|
+
inProps = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
32
|
+
const {
|
|
33
|
+
scale: xScale
|
|
34
|
+
} = axis,
|
|
35
|
+
settings = _objectWithoutPropertiesLoose(axis, _excluded2);
|
|
36
|
+
|
|
37
|
+
// eslint-disable-next-line material-ui/mui-name-matches-component-name
|
|
38
|
+
const themedProps = useThemeProps({
|
|
39
|
+
props: _extends({}, settings, inProps),
|
|
40
|
+
name: 'MuiChartsXAxis'
|
|
41
|
+
});
|
|
42
|
+
const defaultizedProps = _extends({}, defaultProps, themedProps);
|
|
43
|
+
const {
|
|
44
|
+
position,
|
|
45
|
+
labelStyle,
|
|
46
|
+
offset,
|
|
47
|
+
slots,
|
|
48
|
+
slotProps,
|
|
49
|
+
sx,
|
|
50
|
+
disableLine,
|
|
51
|
+
label,
|
|
52
|
+
height: axisHeight
|
|
53
|
+
} = defaultizedProps;
|
|
54
|
+
const theme = useTheme();
|
|
55
|
+
const classes = useUtilityClasses(defaultizedProps);
|
|
56
|
+
const {
|
|
57
|
+
left,
|
|
58
|
+
top,
|
|
59
|
+
width,
|
|
60
|
+
height
|
|
61
|
+
} = useDrawingArea();
|
|
62
|
+
const positionSign = position === 'bottom' ? 1 : -1;
|
|
63
|
+
const Line = slots?.axisLine ?? 'line';
|
|
64
|
+
const Label = slots?.axisLabel ?? ChartsText;
|
|
65
|
+
const axisLabelProps = useSlotProps({
|
|
66
|
+
elementType: Label,
|
|
67
|
+
externalSlotProps: slotProps?.axisLabel,
|
|
68
|
+
additionalProps: {
|
|
69
|
+
style: _extends({}, theme.typography.body1, {
|
|
70
|
+
lineHeight: 1,
|
|
71
|
+
fontSize: 14,
|
|
72
|
+
textAnchor: 'middle',
|
|
73
|
+
dominantBaseline: position === 'bottom' ? 'text-after-edge' : 'text-before-edge'
|
|
74
|
+
}, labelStyle)
|
|
75
|
+
},
|
|
76
|
+
ownerState: {}
|
|
77
|
+
});
|
|
78
|
+
if (position === 'none') {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
const labelHeight = label ? getStringSize(label, axisLabelProps.style).height : 0;
|
|
82
|
+
const domain = xScale.domain();
|
|
83
|
+
const isScaleBand = isBandScale(xScale);
|
|
84
|
+
const skipTickRendering = isScaleBand && domain.length === 0 || !isScaleBand && domain.some(isInfinity);
|
|
85
|
+
let children = null;
|
|
86
|
+
if (!skipTickRendering) {
|
|
87
|
+
children = 'groups' in axis && Array.isArray(axis.groups) ? /*#__PURE__*/_jsx(ChartsGroupedXAxisTicks, _extends({}, inProps)) : /*#__PURE__*/_jsx(ChartsSingleXAxisTicks, _extends({}, inProps, {
|
|
88
|
+
axisLabelHeight: labelHeight
|
|
89
|
+
}));
|
|
90
|
+
}
|
|
91
|
+
const labelRefPoint = {
|
|
92
|
+
x: left + width / 2,
|
|
93
|
+
y: positionSign * axisHeight
|
|
94
|
+
};
|
|
95
|
+
return /*#__PURE__*/_jsxs(XAxisRoot, {
|
|
96
|
+
transform: `translate(0, ${position === 'bottom' ? top + height + offset : top - offset})`,
|
|
97
|
+
className: classes.root,
|
|
98
|
+
sx: sx,
|
|
99
|
+
children: [!disableLine && /*#__PURE__*/_jsx(Line, _extends({
|
|
100
|
+
x1: left,
|
|
101
|
+
x2: left + width,
|
|
102
|
+
className: classes.line
|
|
103
|
+
}, slotProps?.axisLine)), children, label && /*#__PURE__*/_jsx("g", {
|
|
104
|
+
className: classes.label,
|
|
105
|
+
children: /*#__PURE__*/_jsx(Label, _extends({}, labelRefPoint, axisLabelProps, {
|
|
106
|
+
text: label
|
|
107
|
+
}))
|
|
108
|
+
})]
|
|
109
|
+
});
|
|
110
|
+
}
|