@mui/x-charts 8.11.1 → 8.11.3
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/index.d.ts +1 -0
- package/BarChart/useBarChartProps.js +4 -3
- package/CHANGELOG.md +181 -0
- package/ChartsAxisHighlight/ChartsXAxisHighlight.js +4 -4
- package/ChartsAxisHighlight/ChartsYAxisHighlight.js +4 -4
- package/ChartsLegend/ChartsLegend.js +2 -1
- package/ChartsLegend/PiecewiseColorLegend.d.ts +2 -2
- package/ChartsLegend/PiecewiseColorLegend.js +32 -22
- package/ChartsLegend/piecewiseColorLegendClasses.d.ts +4 -0
- package/ChartsLegend/piecewiseColorLegendClasses.js +2 -2
- package/ChartsSurface/ChartsSurface.js +2 -1
- package/ChartsWrapper/ChartsWrapper.d.ts +4 -0
- package/ChartsWrapper/ChartsWrapper.js +73 -25
- package/ChartsXAxis/ChartsGroupedXAxisTicks.d.ts +8 -0
- package/ChartsXAxis/{ChartsGroupedXAxis.js → ChartsGroupedXAxisTicks.js} +11 -54
- package/ChartsXAxis/ChartsSingleXAxisTicks.d.ts +10 -0
- package/ChartsXAxis/{ChartsSingleXAxis.js → ChartsSingleXAxisTicks.js} +15 -51
- package/ChartsXAxis/ChartsXAxis.js +4 -6
- package/ChartsXAxis/ChartsXAxisImpl.d.ts +13 -0
- package/ChartsXAxis/ChartsXAxisImpl.js +117 -0
- package/ChartsXAxis/getVisibleLabels.js +5 -1
- package/ChartsXAxis/{useAxisProps.d.ts → useAxisTicksProps.d.ts} +1 -496
- 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} +11 -54
- package/ChartsYAxis/ChartsSingleYAxisTicks.d.ts +10 -0
- package/ChartsYAxis/{ChartsSingleYAxis.js → ChartsSingleYAxisTicks.js} +15 -50
- package/ChartsYAxis/ChartsYAxis.js +6 -8
- package/ChartsYAxis/ChartsYAxisImpl.d.ts +13 -0
- package/ChartsYAxis/ChartsYAxisImpl.js +133 -0
- package/ChartsYAxis/{useAxisProps.d.ts → useAxisTicksProps.d.ts} +1 -504
- package/ChartsYAxis/{useAxisProps.js → useAxisTicksProps.js} +5 -44
- package/ChartsYAxis/utilities.d.ts +0 -1
- package/ChartsYAxis/utilities.js +1 -7
- package/LineChart/useAreaPlotData.js +2 -2
- package/LineChart/useLineChartProps.js +2 -1
- package/LineChart/useLinePlotData.js +2 -2
- package/PieChart/PieChart.js +1 -0
- package/RadarChart/RadarAxis/useRadarAxis.js +2 -2
- package/RadarChart/useRadarChartProps.js +2 -1
- package/ScatterChart/useScatterChartProps.js +2 -1
- package/Toolbar/Toolbar.js +2 -1
- package/esm/BarChart/index.d.ts +1 -0
- package/esm/BarChart/useBarChartProps.js +4 -3
- package/esm/ChartsAxisHighlight/ChartsXAxisHighlight.js +4 -4
- package/esm/ChartsAxisHighlight/ChartsYAxisHighlight.js +4 -4
- package/esm/ChartsLegend/ChartsLegend.js +2 -1
- package/esm/ChartsLegend/PiecewiseColorLegend.d.ts +2 -2
- package/esm/ChartsLegend/PiecewiseColorLegend.js +32 -22
- package/esm/ChartsLegend/piecewiseColorLegendClasses.d.ts +4 -0
- package/esm/ChartsLegend/piecewiseColorLegendClasses.js +2 -2
- package/esm/ChartsSurface/ChartsSurface.js +2 -1
- package/esm/ChartsWrapper/ChartsWrapper.d.ts +4 -0
- package/esm/ChartsWrapper/ChartsWrapper.js +73 -25
- package/esm/ChartsXAxis/ChartsGroupedXAxisTicks.d.ts +8 -0
- package/esm/ChartsXAxis/{ChartsGroupedXAxis.js → ChartsGroupedXAxisTicks.js} +12 -55
- package/esm/ChartsXAxis/ChartsSingleXAxisTicks.d.ts +10 -0
- package/esm/ChartsXAxis/{ChartsSingleXAxis.js → ChartsSingleXAxisTicks.js} +16 -54
- package/esm/ChartsXAxis/ChartsXAxis.js +4 -6
- package/esm/ChartsXAxis/ChartsXAxisImpl.d.ts +13 -0
- package/esm/ChartsXAxis/ChartsXAxisImpl.js +110 -0
- package/esm/ChartsXAxis/getVisibleLabels.js +5 -1
- package/esm/ChartsXAxis/{useAxisProps.d.ts → useAxisTicksProps.d.ts} +1 -496
- 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} +12 -55
- package/esm/ChartsYAxis/ChartsSingleYAxisTicks.d.ts +10 -0
- package/esm/ChartsYAxis/{ChartsSingleYAxis.js → ChartsSingleYAxisTicks.js} +16 -53
- package/esm/ChartsYAxis/ChartsYAxis.js +5 -7
- package/esm/ChartsYAxis/ChartsYAxisImpl.d.ts +13 -0
- package/esm/ChartsYAxis/ChartsYAxisImpl.js +126 -0
- package/esm/ChartsYAxis/{useAxisProps.d.ts → useAxisTicksProps.d.ts} +1 -504
- 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/LineChart/useAreaPlotData.js +2 -2
- package/esm/LineChart/useLineChartProps.js +2 -1
- package/esm/LineChart/useLinePlotData.js +2 -2
- package/esm/PieChart/PieChart.js +1 -0
- package/esm/RadarChart/RadarAxis/useRadarAxis.js +2 -2
- package/esm/RadarChart/useRadarChartProps.js +2 -1
- package/esm/ScatterChart/useScatterChartProps.js +2 -1
- package/esm/Toolbar/Toolbar.js +2 -1
- package/esm/hooks/useInteractionItemProps.js +5 -4
- package/esm/hooks/useScale.js +2 -2
- package/esm/hooks/useTicks.js +10 -3
- package/esm/hooks/useTicksGrouped.js +2 -2
- 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/index.d.ts +1 -1
- package/esm/internals/index.js +1 -1
- package/esm/internals/invertScale.js +2 -2
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/computeAxisValue.js +5 -5
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisValue.js +3 -3
- package/esm/internals/plugins/featurePlugins/useChartPolarAxis/computeAxisValue.js +2 -2
- package/esm/internals/plugins/featurePlugins/useChartPolarAxis/getAxisIndex.js +2 -2
- package/esm/internals/scaleGuards.d.ts +4 -0
- package/esm/internals/scaleGuards.js +3 -0
- 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/esm/models/axis.d.ts +3 -0
- package/hooks/useInteractionItemProps.js +6 -4
- package/hooks/useScale.js +2 -2
- package/hooks/useTicks.js +10 -3
- package/hooks/useTicksGrouped.js +2 -2
- 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/index.d.ts +1 -1
- package/internals/index.js +4 -4
- package/internals/invertScale.js +2 -2
- package/internals/plugins/featurePlugins/useChartCartesianAxis/computeAxisValue.js +5 -5
- package/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisValue.js +3 -3
- package/internals/plugins/featurePlugins/useChartPolarAxis/computeAxisValue.js +2 -2
- package/internals/plugins/featurePlugins/useChartPolarAxis/getAxisIndex.js +2 -2
- package/internals/scaleGuards.d.ts +4 -0
- package/internals/{isBandScale.js → scaleGuards.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/models/axis.d.ts +3 -0
- package/package.json +5 -5
- 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/esm/internals/isBandScale.d.ts +0 -5
- package/esm/internals/isBandScale.js +0 -3
- package/internals/isBandScale.d.ts +0 -5
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { area as d3Area } from '@mui/x-charts-vendor/d3-shape';
|
|
3
3
|
import { useChartGradientIdBuilder } from "../hooks/useChartGradientId.js";
|
|
4
|
-
import {
|
|
4
|
+
import { isOrdinalScale } from "../internals/scaleGuards.js";
|
|
5
5
|
import { getCurveFactory } from "../internals/getCurve.js";
|
|
6
6
|
import { getValueToPositionMapper, useLineSeriesContext, useXAxes, useYAxes } from "../hooks/index.js";
|
|
7
7
|
import { DEFAULT_X_AXIS_KEY } from "../constants/index.js";
|
|
@@ -52,7 +52,7 @@ export function useAreaPlotData(xAxes, yAxes) {
|
|
|
52
52
|
throw new Error(`MUI X Charts: The data length of the x axis (${xData.length} items) is lower than the length of series (${stackedData.length} items).`);
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
|
-
const shouldExpand = curve?.includes('step') && !strictStepCurve &&
|
|
55
|
+
const shouldExpand = curve?.includes('step') && !strictStepCurve && isOrdinalScale(xScale);
|
|
56
56
|
const formattedData = xData?.flatMap((x, index) => {
|
|
57
57
|
const nullData = data[index] == null;
|
|
58
58
|
if (shouldExpand) {
|
|
@@ -119,7 +119,8 @@ export const useLineChartProps = props => {
|
|
|
119
119
|
const chartsWrapperProps = {
|
|
120
120
|
sx,
|
|
121
121
|
legendPosition: props.slotProps?.legend?.position,
|
|
122
|
-
legendDirection: props.slotProps?.legend?.direction
|
|
122
|
+
legendDirection: props.slotProps?.legend?.direction,
|
|
123
|
+
hideLegend: props.hideLegend ?? false
|
|
123
124
|
};
|
|
124
125
|
return {
|
|
125
126
|
chartsWrapperProps,
|
|
@@ -2,7 +2,7 @@ import * as React from 'react';
|
|
|
2
2
|
import { warnOnce } from '@mui/x-internals/warning';
|
|
3
3
|
import { line as d3Line } from '@mui/x-charts-vendor/d3-shape';
|
|
4
4
|
import { useChartGradientIdBuilder } from "../hooks/useChartGradientId.js";
|
|
5
|
-
import {
|
|
5
|
+
import { isOrdinalScale } from "../internals/scaleGuards.js";
|
|
6
6
|
import { getCurveFactory } from "../internals/getCurve.js";
|
|
7
7
|
import { getValueToPositionMapper, useLineSeriesContext, useXAxes, useYAxes } from "../hooks/index.js";
|
|
8
8
|
import { DEFAULT_X_AXIS_KEY } from "../constants/index.js";
|
|
@@ -50,7 +50,7 @@ export function useLinePlotData(xAxes, yAxes) {
|
|
|
50
50
|
warnOnce(`MUI X Charts: The data length of the x axis (${xData.length} items) is lower than the length of series (${stackedData.length} items).`, 'error');
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
|
-
const shouldExpand = curve?.includes('step') && !strictStepCurve &&
|
|
53
|
+
const shouldExpand = curve?.includes('step') && !strictStepCurve && isOrdinalScale(xScale);
|
|
54
54
|
const formattedData = xData?.flatMap((x, index) => {
|
|
55
55
|
const nullData = data[index] == null;
|
|
56
56
|
if (shouldExpand) {
|
package/esm/PieChart/PieChart.js
CHANGED
|
@@ -78,6 +78,7 @@ const PieChart = /*#__PURE__*/React.forwardRef(function PieChart(inProps, ref) {
|
|
|
78
78
|
legendPosition: props.slotProps?.legend?.position,
|
|
79
79
|
legendDirection: props.slotProps?.legend?.direction ?? 'vertical',
|
|
80
80
|
sx: sx,
|
|
81
|
+
hideLegend: hideLegend ?? false,
|
|
81
82
|
children: [showToolbar && Toolbar ? /*#__PURE__*/_jsx(Toolbar, _extends({}, props.slotProps?.toolbar)) : null, !hideLegend && /*#__PURE__*/_jsx(ChartsLegend, {
|
|
82
83
|
direction: props.slotProps?.legend?.direction ?? 'vertical',
|
|
83
84
|
slots: slots,
|
|
@@ -3,7 +3,7 @@ import { useRadiusAxes } from "../../hooks/useAxis.js";
|
|
|
3
3
|
import { useRotationScale } from "../../hooks/useScale.js";
|
|
4
4
|
import { useChartContext } from "../../context/ChartProvider/useChartContext.js";
|
|
5
5
|
import { selectorChartPolarCenter } from "../../internals/plugins/featurePlugins/useChartPolarAxis/index.js";
|
|
6
|
-
import {
|
|
6
|
+
import { isOrdinalScale } from "../../internals/scaleGuards.js";
|
|
7
7
|
import { degToRad } from "../../internals/degToRad.js";
|
|
8
8
|
import { clampAngle } from "../../internals/clampAngle.js";
|
|
9
9
|
import { useSelector } from "../../internals/store/useSelector.js";
|
|
@@ -42,7 +42,7 @@ export function useRadarAxis(params) {
|
|
|
42
42
|
}, (_, index) => (index + 1) / divisions);
|
|
43
43
|
const radiusScale = radiusAxis[metric].scale;
|
|
44
44
|
const R = radiusScale.range()[1];
|
|
45
|
-
if (
|
|
45
|
+
if (isOrdinalScale(radiusScale)) {
|
|
46
46
|
if (process.env.NODE_ENV !== 'production') {
|
|
47
47
|
console.error('MUI X Charts: Radar chart does not support ordinal axes');
|
|
48
48
|
}
|
|
@@ -88,7 +88,8 @@ export const useScatterChartProps = props => {
|
|
|
88
88
|
const chartsWrapperProps = {
|
|
89
89
|
sx,
|
|
90
90
|
legendPosition: props.slotProps?.legend?.position,
|
|
91
|
-
legendDirection: props.slotProps?.legend?.direction
|
|
91
|
+
legendDirection: props.slotProps?.legend?.direction,
|
|
92
|
+
hideLegend: props.hideLegend ?? false
|
|
92
93
|
};
|
|
93
94
|
return {
|
|
94
95
|
chartsWrapperProps,
|
package/esm/Toolbar/Toolbar.js
CHANGED
|
@@ -25,7 +25,8 @@ const ToolbarRoot = styled('div', {
|
|
|
25
25
|
minHeight: 44,
|
|
26
26
|
boxSizing: 'border-box',
|
|
27
27
|
border: `1px solid ${(theme.vars || theme).palette.divider}`,
|
|
28
|
-
borderRadius: 4
|
|
28
|
+
borderRadius: 4,
|
|
29
|
+
gridArea: 'toolbar'
|
|
29
30
|
}));
|
|
30
31
|
export const Toolbar = /*#__PURE__*/React.forwardRef(function Toolbar(_ref, ref) {
|
|
31
32
|
let {
|
|
@@ -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/useScale.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { isOrdinalScale } from "../internals/scaleGuards.js";
|
|
4
4
|
import { useRadiusAxis, useRotationAxis, useXAxis, useYAxis } from "./useAxis.js";
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -10,7 +10,7 @@ import { useRadiusAxis, useRotationAxis, useXAxis, useYAxis } from "./useAxis.js
|
|
|
10
10
|
* @returns {(value: any) => number} A function that map value to their position
|
|
11
11
|
*/
|
|
12
12
|
export function getValueToPositionMapper(scale) {
|
|
13
|
-
if (
|
|
13
|
+
if (isOrdinalScale(scale)) {
|
|
14
14
|
return value => (scale(value) ?? 0) + scale.bandwidth() / 2;
|
|
15
15
|
}
|
|
16
16
|
return value => scale(value);
|
package/esm/hooks/useTicks.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import * as React from 'react';
|
|
4
4
|
import { useChartContext } from "../context/ChartProvider/index.js";
|
|
5
|
-
import {
|
|
5
|
+
import { isOrdinalScale } from "../internals/scaleGuards.js";
|
|
6
6
|
import { isInfinity } from "../internals/isInfinity.js";
|
|
7
7
|
const offsetRatio = {
|
|
8
8
|
start: 0,
|
|
@@ -22,7 +22,7 @@ export function getTicks(options) {
|
|
|
22
22
|
} = options;
|
|
23
23
|
|
|
24
24
|
// band scale
|
|
25
|
-
if (
|
|
25
|
+
if (isOrdinalScale(scale)) {
|
|
26
26
|
const domain = scale.domain();
|
|
27
27
|
const tickLabelPlacement = tickLabelPlacementProp ?? 'middle';
|
|
28
28
|
if (scale.bandwidth() > 0) {
|
|
@@ -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,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import * as React from 'react';
|
|
4
|
-
import {
|
|
4
|
+
import { isOrdinalScale } from "../internals/scaleGuards.js";
|
|
5
5
|
const offsetRatio = {
|
|
6
6
|
start: 0,
|
|
7
7
|
extremities: 0,
|
|
@@ -62,7 +62,7 @@ function mapToGrouping(tickValues, groups, tickPlacement, tickLabelPlacement, sc
|
|
|
62
62
|
if (isNew) {
|
|
63
63
|
currentValueCount = 1;
|
|
64
64
|
// Calculate tick offset
|
|
65
|
-
const tickOffset =
|
|
65
|
+
const tickOffset = isOrdinalScale(scale) ? scale(tickValue) - (scale.step() - scale.bandwidth()) / 2 + offsetRatio[tickPlacement] * scale.step() : scale(tickValue);
|
|
66
66
|
|
|
67
67
|
// Calculate the label offset
|
|
68
68
|
const labelOffset = scale.step() * currentValueCount * (offsetRatio[tickLabelPlacement] - offsetRatio[tickPlacement]);
|
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') {
|
package/esm/internals/index.d.ts
CHANGED
|
@@ -52,7 +52,7 @@ export * from "./colorScale.js";
|
|
|
52
52
|
export * from "./ticks.js";
|
|
53
53
|
export * from "./dateHelpers.js";
|
|
54
54
|
export * from "./invertScale.js";
|
|
55
|
-
export * from "./
|
|
55
|
+
export * from "./scaleGuards.js";
|
|
56
56
|
export * from "./findMinMax.js";
|
|
57
57
|
export { getAxisExtremum } from "./plugins/featurePlugins/useChartCartesianAxis/getAxisExtremum.js";
|
|
58
58
|
export * from "../context/ChartProvider/index.js";
|
package/esm/internals/index.js
CHANGED
|
@@ -62,7 +62,7 @@ export * from "./colorScale.js";
|
|
|
62
62
|
export * from "./ticks.js";
|
|
63
63
|
export * from "./dateHelpers.js";
|
|
64
64
|
export * from "./invertScale.js";
|
|
65
|
-
export * from "./
|
|
65
|
+
export * from "./scaleGuards.js";
|
|
66
66
|
export * from "./findMinMax.js";
|
|
67
67
|
|
|
68
68
|
// contexts
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isOrdinalScale } from "./scaleGuards.js";
|
|
2
2
|
export function invertScale(scale, data, value) {
|
|
3
|
-
if (
|
|
3
|
+
if (isOrdinalScale(scale)) {
|
|
4
4
|
const dataIndex = scale.bandwidth() === 0 ? Math.floor((value - Math.min(...scale.range()) + scale.step() / 2) / scale.step()) : Math.floor((value - Math.min(...scale.range())) / scale.step());
|
|
5
5
|
return data[dataIndex];
|
|
6
6
|
}
|
|
@@ -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
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isOrdinalScale } from "../../../scaleGuards.js";
|
|
2
2
|
function getAsANumber(value) {
|
|
3
3
|
return value instanceof Date ? value.getTime() : value;
|
|
4
4
|
}
|
|
@@ -13,7 +13,7 @@ export function getAxisIndex(axisConfig, pointerValue) {
|
|
|
13
13
|
data: axisData,
|
|
14
14
|
reverse
|
|
15
15
|
} = axisConfig;
|
|
16
|
-
if (!
|
|
16
|
+
if (!isOrdinalScale(scale)) {
|
|
17
17
|
const value = scale.invert(pointerValue);
|
|
18
18
|
if (axisData === undefined) {
|
|
19
19
|
return -1;
|
|
@@ -51,7 +51,7 @@ export function getAxisValue(axisConfig, pointerValue, dataIndex) {
|
|
|
51
51
|
scale,
|
|
52
52
|
data: axisData
|
|
53
53
|
} = axisConfig;
|
|
54
|
-
if (!
|
|
54
|
+
if (!isOrdinalScale(scale)) {
|
|
55
55
|
if (dataIndex === null) {
|
|
56
56
|
return scale.invert(pointerValue);
|
|
57
57
|
}
|
|
@@ -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
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isOrdinalScale } from "../../../scaleGuards.js";
|
|
2
2
|
import { clampAngleRad } from "../../../clampAngle.js";
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -11,7 +11,7 @@ export function getAxisIndex(axisConfig, pointerValue) {
|
|
|
11
11
|
data: axisData,
|
|
12
12
|
reverse
|
|
13
13
|
} = axisConfig;
|
|
14
|
-
if (!
|
|
14
|
+
if (!isOrdinalScale(scale)) {
|
|
15
15
|
throw new Error('MUI X Charts: getAxisValue is not implemented for polare continuous axes.');
|
|
16
16
|
}
|
|
17
17
|
if (!axisData) {
|
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);
|
package/esm/models/axis.d.ts
CHANGED
|
@@ -11,6 +11,9 @@ export type D3Scale<Domain extends {
|
|
|
11
11
|
toString(): string;
|
|
12
12
|
} = number | Date | string, Range = number, Output = number> = ScaleBand<Domain> | ScaleSymLog<Range, Output> | ScaleLogarithmic<Range, Output> | ScalePoint<Domain> | ScalePower<Range, Output> | ScaleTime<Range, Output> | ScaleLinear<Range, Output>;
|
|
13
13
|
export type D3ContinuousScale<Range = number, Output = number> = ScaleSymLog<Range, Output> | ScaleLogarithmic<Range, Output> | ScalePower<Range, Output> | ScaleTime<Range, Output> | ScaleLinear<Range, Output>;
|
|
14
|
+
export type D3OrdinalScale<Domain extends {
|
|
15
|
+
toString(): string;
|
|
16
|
+
} = number | Date | string> = ScaleBand<Domain> | ScalePoint<Domain>;
|
|
14
17
|
export interface ChartsAxisSlots {
|
|
15
18
|
/**
|
|
16
19
|
* Custom component for the axis main line.
|
|
@@ -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/useScale.js
CHANGED
|
@@ -9,7 +9,7 @@ exports.useRadiusScale = useRadiusScale;
|
|
|
9
9
|
exports.useRotationScale = useRotationScale;
|
|
10
10
|
exports.useXScale = useXScale;
|
|
11
11
|
exports.useYScale = useYScale;
|
|
12
|
-
var
|
|
12
|
+
var _scaleGuards = require("../internals/scaleGuards");
|
|
13
13
|
var _useAxis = require("./useAxis");
|
|
14
14
|
/**
|
|
15
15
|
* For a given scale return a function that map value to their position.
|
|
@@ -18,7 +18,7 @@ var _useAxis = require("./useAxis");
|
|
|
18
18
|
* @returns {(value: any) => number} A function that map value to their position
|
|
19
19
|
*/
|
|
20
20
|
function getValueToPositionMapper(scale) {
|
|
21
|
-
if ((0,
|
|
21
|
+
if ((0, _scaleGuards.isOrdinalScale)(scale)) {
|
|
22
22
|
return value => (scale(value) ?? 0) + scale.bandwidth() / 2;
|
|
23
23
|
}
|
|
24
24
|
return value => scale(value);
|
package/hooks/useTicks.js
CHANGED
|
@@ -9,7 +9,7 @@ exports.getTicks = getTicks;
|
|
|
9
9
|
exports.useTicks = useTicks;
|
|
10
10
|
var React = _interopRequireWildcard(require("react"));
|
|
11
11
|
var _ChartProvider = require("../context/ChartProvider");
|
|
12
|
-
var
|
|
12
|
+
var _scaleGuards = require("../internals/scaleGuards");
|
|
13
13
|
var _isInfinity = require("../internals/isInfinity");
|
|
14
14
|
const offsetRatio = {
|
|
15
15
|
start: 0,
|
|
@@ -29,7 +29,7 @@ function getTicks(options) {
|
|
|
29
29
|
} = options;
|
|
30
30
|
|
|
31
31
|
// band scale
|
|
32
|
-
if ((0,
|
|
32
|
+
if ((0, _scaleGuards.isOrdinalScale)(scale)) {
|
|
33
33
|
const domain = scale.domain();
|
|
34
34
|
const tickLabelPlacement = tickLabelPlacementProp ?? 'middle';
|
|
35
35
|
if (scale.bandwidth() > 0) {
|
|
@@ -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/hooks/useTicksGrouped.js
CHANGED
|
@@ -7,7 +7,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
});
|
|
8
8
|
exports.useTicksGrouped = useTicksGrouped;
|
|
9
9
|
var React = _interopRequireWildcard(require("react"));
|
|
10
|
-
var
|
|
10
|
+
var _scaleGuards = require("../internals/scaleGuards");
|
|
11
11
|
const offsetRatio = {
|
|
12
12
|
start: 0,
|
|
13
13
|
extremities: 0,
|
|
@@ -68,7 +68,7 @@ function mapToGrouping(tickValues, groups, tickPlacement, tickLabelPlacement, sc
|
|
|
68
68
|
if (isNew) {
|
|
69
69
|
currentValueCount = 1;
|
|
70
70
|
// Calculate tick offset
|
|
71
|
-
const tickOffset = (0,
|
|
71
|
+
const tickOffset = (0, _scaleGuards.isOrdinalScale)(scale) ? scale(tickValue) - (scale.step() - scale.bandwidth()) / 2 + offsetRatio[tickPlacement] * scale.step() : scale(tickValue);
|
|
72
72
|
|
|
73
73
|
// Calculate the label offset
|
|
74
74
|
const labelOffset = scale.step() * currentValueCount * (offsetRatio[tickLabelPlacement] - offsetRatio[tickPlacement]);
|
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'];
|