@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
|
@@ -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
|
*/
|
|
@@ -73,7 +73,7 @@ process.env.NODE_ENV !== "production" ? RadarAxis.propTypes = {
|
|
|
73
73
|
/**
|
|
74
74
|
* The labels dominant baseline or a function returning the dominant baseline for a given axis angle (in degree).
|
|
75
75
|
*/
|
|
76
|
-
dominantBaseline: PropTypes.oneOfType([PropTypes.
|
|
76
|
+
dominantBaseline: PropTypes.oneOfType([PropTypes.oneOf(['alphabetic', 'auto', 'central', 'hanging', 'ideographic', 'inherit', 'mathematical', 'middle', 'no-change', 'reset-size', 'text-after-edge', 'text-before-edge', 'use-script']), PropTypes.func]),
|
|
77
77
|
/**
|
|
78
78
|
* Defines how label align with the axis.
|
|
79
79
|
* - 'horizontal': labels stay horizontal and their placement change with the axis angle.
|
|
@@ -89,6 +89,6 @@ process.env.NODE_ENV !== "production" ? RadarAxis.propTypes = {
|
|
|
89
89
|
/**
|
|
90
90
|
* The labels text anchor or a function returning the text anchor for a given axis angle (in degree).
|
|
91
91
|
*/
|
|
92
|
-
textAnchor: PropTypes.oneOfType([PropTypes.
|
|
92
|
+
textAnchor: PropTypes.oneOfType([PropTypes.oneOf(['end', 'inherit', 'middle', 'start']), PropTypes.func])
|
|
93
93
|
} : void 0;
|
|
94
94
|
export { RadarAxis };
|
|
@@ -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 {};
|
|
@@ -19,12 +19,12 @@ function getTextAnchor(angle) {
|
|
|
19
19
|
}
|
|
20
20
|
function getDominantBaseline(angle) {
|
|
21
21
|
if (angle < 160) {
|
|
22
|
-
return '
|
|
22
|
+
return 'auto';
|
|
23
23
|
}
|
|
24
24
|
if (angle < 360 - 20) {
|
|
25
25
|
return 'hanging';
|
|
26
26
|
}
|
|
27
|
-
return '
|
|
27
|
+
return 'auto';
|
|
28
28
|
}
|
|
29
29
|
const LABEL_MARGIN = 2;
|
|
30
30
|
export function getLabelAttributes(params) {
|
|
@@ -37,7 +37,7 @@ export function getLabelAttributes(params) {
|
|
|
37
37
|
const textAnchor = typeof params.textAnchor === 'function' ? params.textAnchor(angle) : params.textAnchor ?? getTextAnchor(angle);
|
|
38
38
|
const dominantBaseline = typeof params.dominantBaseline === 'function' ? params.dominantBaseline(angle) : params.dominantBaseline ?? getDominantBaseline(angle);
|
|
39
39
|
const marginX = textAnchor === 'start' ? LABEL_MARGIN : -LABEL_MARGIN;
|
|
40
|
-
const marginY = dominantBaseline === '
|
|
40
|
+
const marginY = dominantBaseline === 'auto' ? -LABEL_MARGIN : LABEL_MARGIN;
|
|
41
41
|
return {
|
|
42
42
|
x: x + marginX,
|
|
43
43
|
y: y + marginY,
|
|
@@ -49,7 +49,7 @@ export function getLabelAttributes(params) {
|
|
|
49
49
|
// orientation='rotated'
|
|
50
50
|
|
|
51
51
|
const textAnchor = typeof params.textAnchor === 'function' ? params.textAnchor(angle) : params.textAnchor ?? 'start';
|
|
52
|
-
const dominantBaseline = typeof params.dominantBaseline === 'function' ? params.dominantBaseline(angle) : params.dominantBaseline ?? '
|
|
52
|
+
const dominantBaseline = typeof params.dominantBaseline === 'function' ? params.dominantBaseline(angle) : params.dominantBaseline ?? 'auto';
|
|
53
53
|
return {
|
|
54
54
|
x,
|
|
55
55
|
y,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import * as React from 'react';
|
|
4
|
+
import useEventCallback from '@mui/utils/useEventCallback';
|
|
4
5
|
import { useChartContext } from "../context/ChartProvider/index.js";
|
|
5
6
|
function onPointerDown(event) {
|
|
6
7
|
if ('hasPointerCapture' in event.currentTarget && event.currentTarget.hasPointerCapture(event.pointerId)) {
|
|
@@ -12,16 +13,16 @@ export const useInteractionItemProps = (data, skip) => {
|
|
|
12
13
|
instance
|
|
13
14
|
} = useChartContext();
|
|
14
15
|
const interactionActive = React.useRef(false);
|
|
15
|
-
const onPointerEnter =
|
|
16
|
+
const onPointerEnter = useEventCallback(() => {
|
|
16
17
|
interactionActive.current = true;
|
|
17
18
|
instance.setItemInteraction(data);
|
|
18
19
|
instance.setHighlight(data);
|
|
19
|
-
}
|
|
20
|
-
const onPointerLeave =
|
|
20
|
+
});
|
|
21
|
+
const onPointerLeave = useEventCallback(() => {
|
|
21
22
|
interactionActive.current = false;
|
|
22
23
|
instance.removeItemInteraction(data);
|
|
23
24
|
instance.clearHighlight();
|
|
24
|
-
}
|
|
25
|
+
});
|
|
25
26
|
React.useEffect(() => {
|
|
26
27
|
return () => {
|
|
27
28
|
/* Clean up state if this item is unmounted while active. */
|
package/esm/hooks/useTicks.js
CHANGED
|
@@ -72,7 +72,7 @@ export function getTicks(options) {
|
|
|
72
72
|
return [];
|
|
73
73
|
}
|
|
74
74
|
const tickLabelPlacement = tickLabelPlacementProp;
|
|
75
|
-
const ticks = typeof tickInterval === 'object' ? tickInterval : scale
|
|
75
|
+
const ticks = typeof tickInterval === 'object' ? tickInterval : getDefaultTicks(scale, tickNumber);
|
|
76
76
|
|
|
77
77
|
// Ticks inside the drawing area
|
|
78
78
|
const visibleTicks = [];
|
|
@@ -102,6 +102,13 @@ export function getTicks(options) {
|
|
|
102
102
|
}
|
|
103
103
|
return visibleTicks;
|
|
104
104
|
}
|
|
105
|
+
function getDefaultTicks(scale, tickNumber) {
|
|
106
|
+
const domain = scale.domain();
|
|
107
|
+
if (domain[0] === domain[1]) {
|
|
108
|
+
return [domain[0]];
|
|
109
|
+
}
|
|
110
|
+
return scale.ticks(tickNumber);
|
|
111
|
+
}
|
|
105
112
|
export function useTicks(options) {
|
|
106
113
|
const {
|
|
107
114
|
scale,
|
package/esm/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { NumberValue } from '@mui/x-charts-vendor/d3-scale';
|
|
1
2
|
import { AxisConfig } from "../models/index.js";
|
|
2
3
|
import { ChartsAxisProps } from "../models/axis.js";
|
|
3
4
|
/**
|
|
@@ -8,8 +9,9 @@ import { ChartsAxisProps } from "../models/axis.js";
|
|
|
8
9
|
export declare const isDateData: (data?: readonly any[]) => data is Date[];
|
|
9
10
|
/**
|
|
10
11
|
* Creates a formatter function for date values.
|
|
11
|
-
* @param
|
|
12
|
+
* @param data The data array containing Date or NumberValue objects.
|
|
12
13
|
* @param range The range for the time scale.
|
|
14
|
+
* @param tickNumber (Optional) The number of ticks for formatting.
|
|
13
15
|
* @returns A formatter function for date values.
|
|
14
16
|
*/
|
|
15
|
-
export declare function createDateFormatter(
|
|
17
|
+
export declare function createDateFormatter(data: Iterable<Date | NumberValue>, range: number[], tickNumber?: number): AxisConfig<'band' | 'point', any, ChartsAxisProps>['valueFormatter'];
|
|
@@ -8,13 +8,14 @@ export const isDateData = data => data?.[0] instanceof Date;
|
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Creates a formatter function for date values.
|
|
11
|
-
* @param
|
|
11
|
+
* @param data The data array containing Date or NumberValue objects.
|
|
12
12
|
* @param range The range for the time scale.
|
|
13
|
+
* @param tickNumber (Optional) The number of ticks for formatting.
|
|
13
14
|
* @returns A formatter function for date values.
|
|
14
15
|
*/
|
|
15
|
-
export function createDateFormatter(
|
|
16
|
-
const timeScale = scaleTime(
|
|
16
|
+
export function createDateFormatter(data, range, tickNumber) {
|
|
17
|
+
const timeScale = scaleTime(data, range);
|
|
17
18
|
return (v, {
|
|
18
19
|
location
|
|
19
|
-
}) => location === 'tick' ? timeScale.tickFormat(
|
|
20
|
+
}) => location === 'tick' ? timeScale.tickFormat(tickNumber)(v) : `${v.toLocaleString()}`;
|
|
20
21
|
}
|
|
@@ -5,6 +5,11 @@
|
|
|
5
5
|
export function createScalarFormatter(tickNumber, zoomScale) {
|
|
6
6
|
return function defaultScalarValueFormatter(value, context) {
|
|
7
7
|
if (context.location === 'tick') {
|
|
8
|
+
const domain = context.scale.domain();
|
|
9
|
+
const zeroSizeDomain = domain[0] === domain[1];
|
|
10
|
+
if (zeroSizeDomain) {
|
|
11
|
+
return context.scale.tickFormat(1)(value);
|
|
12
|
+
}
|
|
8
13
|
return context.scale.tickFormat(tickNumber)(value);
|
|
9
14
|
}
|
|
10
15
|
if (context.location === 'zoom-slider-tooltip') {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export type ChartsTextBaseline = 'hanging' | 'central' | 'auto' | 'text-after-edge' | 'text-before-edge';
|
|
2
|
+
export type ChartsTextAnchor = 'start' | 'middle' | 'end';
|
|
2
3
|
export interface ChartsTextStyle extends React.CSSProperties {
|
|
3
4
|
angle?: number;
|
|
4
5
|
/**
|
|
@@ -6,6 +7,11 @@ export interface ChartsTextStyle extends React.CSSProperties {
|
|
|
6
7
|
* @default 'central'
|
|
7
8
|
*/
|
|
8
9
|
dominantBaseline?: ChartsTextBaseline;
|
|
10
|
+
/**
|
|
11
|
+
* The text anchor
|
|
12
|
+
* @default 'middle'
|
|
13
|
+
*/
|
|
14
|
+
textAnchor?: ChartsTextAnchor;
|
|
9
15
|
}
|
|
10
16
|
export interface GetWordsByLinesParams {
|
|
11
17
|
/**
|
|
@@ -12,9 +12,9 @@ import { getAxisTriggerTooltip } from "./getAxisTriggerTooltip.js";
|
|
|
12
12
|
import { getAxisDomainLimit } from "./getAxisDomainLimit.js";
|
|
13
13
|
function getRange(drawingArea, axisDirection,
|
|
14
14
|
// | 'rotation' | 'radius',
|
|
15
|
-
|
|
15
|
+
reverse) {
|
|
16
16
|
const range = axisDirection === 'x' ? [drawingArea.left, drawingArea.left + drawingArea.width] : [drawingArea.top + drawingArea.height, drawingArea.top];
|
|
17
|
-
return
|
|
17
|
+
return reverse ? [range[1], range[0]] : range;
|
|
18
18
|
}
|
|
19
19
|
const DEFAULT_CATEGORY_GAP_RATIO = 0.2;
|
|
20
20
|
const DEFAULT_BAR_GAP_RATIO = 0.1;
|
|
@@ -42,7 +42,7 @@ export function computeAxisValue({
|
|
|
42
42
|
const zoomOption = zoomOptions?.[axis.id];
|
|
43
43
|
const zoom = zoomMap?.get(axis.id);
|
|
44
44
|
const zoomRange = zoom ? [zoom.start, zoom.end] : [0, 100];
|
|
45
|
-
const range = getRange(drawingArea, axisDirection, axis);
|
|
45
|
+
const range = getRange(drawingArea, axisDirection, axis.reverse ?? false);
|
|
46
46
|
const [minData, maxData] = getAxisExtremum(axis, axisDirection, seriesConfig, axisIndex, formattedSeries, zoom === undefined && !zoomOption ? getFilters : undefined // Do not apply filtering if zoom is already defined.
|
|
47
47
|
);
|
|
48
48
|
const triggerTooltip = !axis.ignoreTooltip && axisIdsTriggeringTooltip.has(axis.id);
|
|
@@ -68,7 +68,7 @@ export function computeAxisValue({
|
|
|
68
68
|
}, axis.colorMap)) : getColorScale(axis.colorMap))
|
|
69
69
|
});
|
|
70
70
|
if (isDateData(axis.data)) {
|
|
71
|
-
const dateFormatter = createDateFormatter(axis, scaleRange);
|
|
71
|
+
const dateFormatter = createDateFormatter(axis.data, scaleRange, axis.tickNumber);
|
|
72
72
|
completeAxis[axis.id].valueFormatter = axis.valueFormatter ?? dateFormatter;
|
|
73
73
|
}
|
|
74
74
|
}
|
|
@@ -88,7 +88,7 @@ export function computeAxisValue({
|
|
|
88
88
|
}, axis.colorMap)) : getColorScale(axis.colorMap))
|
|
89
89
|
});
|
|
90
90
|
if (isDateData(axis.data)) {
|
|
91
|
-
const dateFormatter = createDateFormatter(axis, scaleRange);
|
|
91
|
+
const dateFormatter = createDateFormatter(axis.data, scaleRange, axis.tickNumber);
|
|
92
92
|
completeAxis[axis.id].valueFormatter = axis.valueFormatter ?? dateFormatter;
|
|
93
93
|
}
|
|
94
94
|
}
|
|
@@ -63,7 +63,7 @@ export function computeAxisValue({
|
|
|
63
63
|
}, axis.colorMap)) : getColorScale(axis.colorMap))
|
|
64
64
|
});
|
|
65
65
|
if (isDateData(axis.data)) {
|
|
66
|
-
const dateFormatter = createDateFormatter(axis, range);
|
|
66
|
+
const dateFormatter = createDateFormatter(axis.data, range, axis.tickNumber);
|
|
67
67
|
completeAxis[axis.id].valueFormatter = axis.valueFormatter ?? dateFormatter;
|
|
68
68
|
}
|
|
69
69
|
}
|
|
@@ -80,7 +80,7 @@ export function computeAxisValue({
|
|
|
80
80
|
}, axis.colorMap)) : getColorScale(axis.colorMap))
|
|
81
81
|
});
|
|
82
82
|
if (isDateData(axis.data)) {
|
|
83
|
-
const dateFormatter = createDateFormatter(axis, range);
|
|
83
|
+
const dateFormatter = createDateFormatter(axis.data, range, axis.tickNumber);
|
|
84
84
|
completeAxis[axis.id].valueFormatter = axis.valueFormatter ?? dateFormatter;
|
|
85
85
|
}
|
|
86
86
|
}
|
package/esm/locales/index.d.ts
CHANGED
package/esm/locales/index.js
CHANGED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ChartsLocaleText } from "./utils/chartsLocaleTextApi.js";
|
|
2
|
+
export declare const svSELocaleText: ChartsLocaleText;
|
|
3
|
+
export declare const svSE: {
|
|
4
|
+
components: {
|
|
5
|
+
MuiChartsLocalizationProvider: {
|
|
6
|
+
defaultProps: {
|
|
7
|
+
localeText: {
|
|
8
|
+
loading?: string | undefined;
|
|
9
|
+
noData?: string | undefined;
|
|
10
|
+
zoomIn?: string | undefined;
|
|
11
|
+
zoomOut?: string | undefined;
|
|
12
|
+
toolbarExport?: string | undefined;
|
|
13
|
+
toolbarExportPrint?: string | undefined;
|
|
14
|
+
toolbarExportImage?: ((mimeType: import("./utils/imageMimeTypes.js").ChartImageExportMimeType | (string & {})) => string) | undefined;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { imageMimeTypes } from "./utils/imageMimeTypes.js";
|
|
2
|
+
import { getChartsLocalization } from "./utils/getChartsLocalization.js";
|
|
3
|
+
export const svSELocaleText = {
|
|
4
|
+
// Overlay
|
|
5
|
+
loading: 'Laddar data…',
|
|
6
|
+
noData: 'Inga data att visa',
|
|
7
|
+
// Toolbar
|
|
8
|
+
zoomIn: 'Zooma in',
|
|
9
|
+
zoomOut: 'Zooma ut',
|
|
10
|
+
toolbarExport: 'Exportera',
|
|
11
|
+
// Toolbar Export Menu
|
|
12
|
+
toolbarExportPrint: 'Skriv ut',
|
|
13
|
+
toolbarExportImage: mimeType => `Exportera som ${imageMimeTypes[mimeType] ?? mimeType}`
|
|
14
|
+
};
|
|
15
|
+
export const svSE = getChartsLocalization(svSELocaleText);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
'use client';
|
|
3
3
|
|
|
4
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
5
|
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
5
6
|
Object.defineProperty(exports, "__esModule", {
|
|
6
7
|
value: true
|
|
@@ -8,6 +9,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
8
9
|
exports.getInteractionItemProps = getInteractionItemProps;
|
|
9
10
|
exports.useInteractionItemProps = exports.useInteractionAllItemProps = void 0;
|
|
10
11
|
var React = _interopRequireWildcard(require("react"));
|
|
12
|
+
var _useEventCallback = _interopRequireDefault(require("@mui/utils/useEventCallback"));
|
|
11
13
|
var _ChartProvider = require("../context/ChartProvider");
|
|
12
14
|
function onPointerDown(event) {
|
|
13
15
|
if ('hasPointerCapture' in event.currentTarget && event.currentTarget.hasPointerCapture(event.pointerId)) {
|
|
@@ -19,16 +21,16 @@ const useInteractionItemProps = (data, skip) => {
|
|
|
19
21
|
instance
|
|
20
22
|
} = (0, _ChartProvider.useChartContext)();
|
|
21
23
|
const interactionActive = React.useRef(false);
|
|
22
|
-
const onPointerEnter =
|
|
24
|
+
const onPointerEnter = (0, _useEventCallback.default)(() => {
|
|
23
25
|
interactionActive.current = true;
|
|
24
26
|
instance.setItemInteraction(data);
|
|
25
27
|
instance.setHighlight(data);
|
|
26
|
-
}
|
|
27
|
-
const onPointerLeave =
|
|
28
|
+
});
|
|
29
|
+
const onPointerLeave = (0, _useEventCallback.default)(() => {
|
|
28
30
|
interactionActive.current = false;
|
|
29
31
|
instance.removeItemInteraction(data);
|
|
30
32
|
instance.clearHighlight();
|
|
31
|
-
}
|
|
33
|
+
});
|
|
32
34
|
React.useEffect(() => {
|
|
33
35
|
return () => {
|
|
34
36
|
/* Clean up state if this item is unmounted while active. */
|
package/hooks/useTicks.js
CHANGED
|
@@ -79,7 +79,7 @@ function getTicks(options) {
|
|
|
79
79
|
return [];
|
|
80
80
|
}
|
|
81
81
|
const tickLabelPlacement = tickLabelPlacementProp;
|
|
82
|
-
const ticks = typeof tickInterval === 'object' ? tickInterval : scale
|
|
82
|
+
const ticks = typeof tickInterval === 'object' ? tickInterval : getDefaultTicks(scale, tickNumber);
|
|
83
83
|
|
|
84
84
|
// Ticks inside the drawing area
|
|
85
85
|
const visibleTicks = [];
|
|
@@ -109,6 +109,13 @@ function getTicks(options) {
|
|
|
109
109
|
}
|
|
110
110
|
return visibleTicks;
|
|
111
111
|
}
|
|
112
|
+
function getDefaultTicks(scale, tickNumber) {
|
|
113
|
+
const domain = scale.domain();
|
|
114
|
+
if (domain[0] === domain[1]) {
|
|
115
|
+
return [domain[0]];
|
|
116
|
+
}
|
|
117
|
+
return scale.ticks(tickNumber);
|
|
118
|
+
}
|
|
112
119
|
function useTicks(options) {
|
|
113
120
|
const {
|
|
114
121
|
scale,
|
package/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { NumberValue } from '@mui/x-charts-vendor/d3-scale';
|
|
1
2
|
import { AxisConfig } from "../models/index.js";
|
|
2
3
|
import { ChartsAxisProps } from "../models/axis.js";
|
|
3
4
|
/**
|
|
@@ -8,8 +9,9 @@ import { ChartsAxisProps } from "../models/axis.js";
|
|
|
8
9
|
export declare const isDateData: (data?: readonly any[]) => data is Date[];
|
|
9
10
|
/**
|
|
10
11
|
* Creates a formatter function for date values.
|
|
11
|
-
* @param
|
|
12
|
+
* @param data The data array containing Date or NumberValue objects.
|
|
12
13
|
* @param range The range for the time scale.
|
|
14
|
+
* @param tickNumber (Optional) The number of ticks for formatting.
|
|
13
15
|
* @returns A formatter function for date values.
|
|
14
16
|
*/
|
|
15
|
-
export declare function createDateFormatter(
|
|
17
|
+
export declare function createDateFormatter(data: Iterable<Date | NumberValue>, range: number[], tickNumber?: number): AxisConfig<'band' | 'point', any, ChartsAxisProps>['valueFormatter'];
|
package/internals/dateHelpers.js
CHANGED
|
@@ -15,14 +15,15 @@ const isDateData = data => data?.[0] instanceof Date;
|
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* Creates a formatter function for date values.
|
|
18
|
-
* @param
|
|
18
|
+
* @param data The data array containing Date or NumberValue objects.
|
|
19
19
|
* @param range The range for the time scale.
|
|
20
|
+
* @param tickNumber (Optional) The number of ticks for formatting.
|
|
20
21
|
* @returns A formatter function for date values.
|
|
21
22
|
*/
|
|
22
23
|
exports.isDateData = isDateData;
|
|
23
|
-
function createDateFormatter(
|
|
24
|
-
const timeScale = (0, _d3Scale.scaleTime)(
|
|
24
|
+
function createDateFormatter(data, range, tickNumber) {
|
|
25
|
+
const timeScale = (0, _d3Scale.scaleTime)(data, range);
|
|
25
26
|
return (v, {
|
|
26
27
|
location
|
|
27
|
-
}) => location === 'tick' ? timeScale.tickFormat(
|
|
28
|
+
}) => location === 'tick' ? timeScale.tickFormat(tickNumber)(v) : `${v.toLocaleString()}`;
|
|
28
29
|
}
|
|
@@ -11,6 +11,11 @@ exports.createScalarFormatter = createScalarFormatter;
|
|
|
11
11
|
function createScalarFormatter(tickNumber, zoomScale) {
|
|
12
12
|
return function defaultScalarValueFormatter(value, context) {
|
|
13
13
|
if (context.location === 'tick') {
|
|
14
|
+
const domain = context.scale.domain();
|
|
15
|
+
const zeroSizeDomain = domain[0] === domain[1];
|
|
16
|
+
if (zeroSizeDomain) {
|
|
17
|
+
return context.scale.tickFormat(1)(value);
|
|
18
|
+
}
|
|
14
19
|
return context.scale.tickFormat(tickNumber)(value);
|
|
15
20
|
}
|
|
16
21
|
if (context.location === 'zoom-slider-tooltip') {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export type ChartsTextBaseline = 'hanging' | 'central' | 'auto' | 'text-after-edge' | 'text-before-edge';
|
|
2
|
+
export type ChartsTextAnchor = 'start' | 'middle' | 'end';
|
|
2
3
|
export interface ChartsTextStyle extends React.CSSProperties {
|
|
3
4
|
angle?: number;
|
|
4
5
|
/**
|
|
@@ -6,6 +7,11 @@ export interface ChartsTextStyle extends React.CSSProperties {
|
|
|
6
7
|
* @default 'central'
|
|
7
8
|
*/
|
|
8
9
|
dominantBaseline?: ChartsTextBaseline;
|
|
10
|
+
/**
|
|
11
|
+
* The text anchor
|
|
12
|
+
* @default 'middle'
|
|
13
|
+
*/
|
|
14
|
+
textAnchor?: ChartsTextAnchor;
|
|
9
15
|
}
|
|
10
16
|
export interface GetWordsByLinesParams {
|
|
11
17
|
/**
|
|
@@ -19,9 +19,9 @@ var _getAxisTriggerTooltip = require("./getAxisTriggerTooltip");
|
|
|
19
19
|
var _getAxisDomainLimit = require("./getAxisDomainLimit");
|
|
20
20
|
function getRange(drawingArea, axisDirection,
|
|
21
21
|
// | 'rotation' | 'radius',
|
|
22
|
-
|
|
22
|
+
reverse) {
|
|
23
23
|
const range = axisDirection === 'x' ? [drawingArea.left, drawingArea.left + drawingArea.width] : [drawingArea.top + drawingArea.height, drawingArea.top];
|
|
24
|
-
return
|
|
24
|
+
return reverse ? [range[1], range[0]] : range;
|
|
25
25
|
}
|
|
26
26
|
const DEFAULT_CATEGORY_GAP_RATIO = 0.2;
|
|
27
27
|
const DEFAULT_BAR_GAP_RATIO = 0.1;
|
|
@@ -49,7 +49,7 @@ function computeAxisValue({
|
|
|
49
49
|
const zoomOption = zoomOptions?.[axis.id];
|
|
50
50
|
const zoom = zoomMap?.get(axis.id);
|
|
51
51
|
const zoomRange = zoom ? [zoom.start, zoom.end] : [0, 100];
|
|
52
|
-
const range = getRange(drawingArea, axisDirection, axis);
|
|
52
|
+
const range = getRange(drawingArea, axisDirection, axis.reverse ?? false);
|
|
53
53
|
const [minData, maxData] = (0, _getAxisExtremum.getAxisExtremum)(axis, axisDirection, seriesConfig, axisIndex, formattedSeries, zoom === undefined && !zoomOption ? getFilters : undefined // Do not apply filtering if zoom is already defined.
|
|
54
54
|
);
|
|
55
55
|
const triggerTooltip = !axis.ignoreTooltip && axisIdsTriggeringTooltip.has(axis.id);
|
|
@@ -75,7 +75,7 @@ function computeAxisValue({
|
|
|
75
75
|
}, axis.colorMap)) : (0, _colorScale.getColorScale)(axis.colorMap))
|
|
76
76
|
});
|
|
77
77
|
if ((0, _dateHelpers.isDateData)(axis.data)) {
|
|
78
|
-
const dateFormatter = (0, _dateHelpers.createDateFormatter)(axis, scaleRange);
|
|
78
|
+
const dateFormatter = (0, _dateHelpers.createDateFormatter)(axis.data, scaleRange, axis.tickNumber);
|
|
79
79
|
completeAxis[axis.id].valueFormatter = axis.valueFormatter ?? dateFormatter;
|
|
80
80
|
}
|
|
81
81
|
}
|
|
@@ -95,7 +95,7 @@ function computeAxisValue({
|
|
|
95
95
|
}, axis.colorMap)) : (0, _colorScale.getColorScale)(axis.colorMap))
|
|
96
96
|
});
|
|
97
97
|
if ((0, _dateHelpers.isDateData)(axis.data)) {
|
|
98
|
-
const dateFormatter = (0, _dateHelpers.createDateFormatter)(axis, scaleRange);
|
|
98
|
+
const dateFormatter = (0, _dateHelpers.createDateFormatter)(axis.data, scaleRange, axis.tickNumber);
|
|
99
99
|
completeAxis[axis.id].valueFormatter = axis.valueFormatter ?? dateFormatter;
|
|
100
100
|
}
|
|
101
101
|
}
|
|
@@ -70,7 +70,7 @@ function computeAxisValue({
|
|
|
70
70
|
}, axis.colorMap)) : (0, _colorScale.getColorScale)(axis.colorMap))
|
|
71
71
|
});
|
|
72
72
|
if ((0, _dateHelpers.isDateData)(axis.data)) {
|
|
73
|
-
const dateFormatter = (0, _dateHelpers.createDateFormatter)(axis, range);
|
|
73
|
+
const dateFormatter = (0, _dateHelpers.createDateFormatter)(axis.data, range, axis.tickNumber);
|
|
74
74
|
completeAxis[axis.id].valueFormatter = axis.valueFormatter ?? dateFormatter;
|
|
75
75
|
}
|
|
76
76
|
}
|
|
@@ -87,7 +87,7 @@ function computeAxisValue({
|
|
|
87
87
|
}, axis.colorMap)) : (0, _colorScale.getColorScale)(axis.colorMap))
|
|
88
88
|
});
|
|
89
89
|
if ((0, _dateHelpers.isDateData)(axis.data)) {
|
|
90
|
-
const dateFormatter = (0, _dateHelpers.createDateFormatter)(axis, range);
|
|
90
|
+
const dateFormatter = (0, _dateHelpers.createDateFormatter)(axis.data, range, axis.tickNumber);
|
|
91
91
|
completeAxis[axis.id].valueFormatter = axis.valueFormatter ?? dateFormatter;
|
|
92
92
|
}
|
|
93
93
|
}
|
package/locales/index.d.ts
CHANGED
package/locales/index.js
CHANGED
|
@@ -57,4 +57,15 @@ Object.keys(_ptPT).forEach(function (key) {
|
|
|
57
57
|
return _ptPT[key];
|
|
58
58
|
}
|
|
59
59
|
});
|
|
60
|
+
});
|
|
61
|
+
var _svSE = require("./svSE");
|
|
62
|
+
Object.keys(_svSE).forEach(function (key) {
|
|
63
|
+
if (key === "default" || key === "__esModule") return;
|
|
64
|
+
if (key in exports && exports[key] === _svSE[key]) return;
|
|
65
|
+
Object.defineProperty(exports, key, {
|
|
66
|
+
enumerable: true,
|
|
67
|
+
get: function () {
|
|
68
|
+
return _svSE[key];
|
|
69
|
+
}
|
|
70
|
+
});
|
|
60
71
|
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ChartsLocaleText } from "./utils/chartsLocaleTextApi.js";
|
|
2
|
+
export declare const svSELocaleText: ChartsLocaleText;
|
|
3
|
+
export declare const svSE: {
|
|
4
|
+
components: {
|
|
5
|
+
MuiChartsLocalizationProvider: {
|
|
6
|
+
defaultProps: {
|
|
7
|
+
localeText: {
|
|
8
|
+
loading?: string | undefined;
|
|
9
|
+
noData?: string | undefined;
|
|
10
|
+
zoomIn?: string | undefined;
|
|
11
|
+
zoomOut?: string | undefined;
|
|
12
|
+
toolbarExport?: string | undefined;
|
|
13
|
+
toolbarExportPrint?: string | undefined;
|
|
14
|
+
toolbarExportImage?: ((mimeType: import("./utils/imageMimeTypes.js").ChartImageExportMimeType | (string & {})) => string) | undefined;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
};
|
package/locales/svSE.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.svSELocaleText = exports.svSE = void 0;
|
|
7
|
+
var _imageMimeTypes = require("./utils/imageMimeTypes");
|
|
8
|
+
var _getChartsLocalization = require("./utils/getChartsLocalization");
|
|
9
|
+
const svSELocaleText = exports.svSELocaleText = {
|
|
10
|
+
// Overlay
|
|
11
|
+
loading: 'Laddar data…',
|
|
12
|
+
noData: 'Inga data att visa',
|
|
13
|
+
// Toolbar
|
|
14
|
+
zoomIn: 'Zooma in',
|
|
15
|
+
zoomOut: 'Zooma ut',
|
|
16
|
+
toolbarExport: 'Exportera',
|
|
17
|
+
// Toolbar Export Menu
|
|
18
|
+
toolbarExportPrint: 'Skriv ut',
|
|
19
|
+
toolbarExportImage: mimeType => `Exportera som ${_imageMimeTypes.imageMimeTypes[mimeType] ?? mimeType}`
|
|
20
|
+
};
|
|
21
|
+
const svSE = exports.svSE = (0, _getChartsLocalization.getChartsLocalization)(svSELocaleText);
|