Skip to content

Commit 12e239f

Browse files
committed
fix types
1 parent df07682 commit 12e239f

File tree

5 files changed

+39
-42
lines changed

5 files changed

+39
-42
lines changed

packages/x-charts/src/Gauge/GaugeContainer.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,15 @@ const GaugeContainer = React.forwardRef(function GaugeContainer(
5454
pluginParams={{
5555
width: inWidth,
5656
height: inHeight,
57-
margin: { left: 10, right: 10, top: 10, bottom: 10, ...margin },
57+
margin:
58+
typeof margin === 'number'
59+
? {
60+
top: margin,
61+
bottom: margin,
62+
left: margin,
63+
right: margin,
64+
}
65+
: { left: 10, right: 10, top: 10, bottom: 10, ...margin },
5866
}}
5967
plugins={[]}
6068
>

packages/x-charts/src/PieChart/PieChart.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,17 @@ const PieChart = React.forwardRef(function PieChart(
100100
className,
101101
...other
102102
} = props;
103-
const margin = { ...defaultMargin, ...marginProps };
103+
const margin = {
104+
...defaultMargin,
105+
...(typeof marginProps === 'number'
106+
? {
107+
top: marginProps,
108+
bottom: marginProps,
109+
left: marginProps,
110+
right: marginProps,
111+
}
112+
: marginProps),
113+
};
104114

105115
const { chartDataProviderProps, chartsSurfaceProps } = useChartContainerProps(
106116
{

packages/x-charts/src/hooks/useChartDimensions.ts

Lines changed: 0 additions & 34 deletions
This file was deleted.

packages/x-charts/src/internals/calculateMargins.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,19 @@ import { DEFAULT_MARGINS, DEFAULT_LEGEND_FACING_MARGIN } from '../constants';
33
import type { LayoutConfig } from '../models';
44
import type { CartesianChartSeriesType, ChartsSeriesConfig } from '../models/seriesType/config';
55

6+
const numberToMargin = (input: LayoutConfig['margin']) => {
7+
if (typeof input === 'number') {
8+
return {
9+
top: input,
10+
bottom: input,
11+
left: input,
12+
right: input,
13+
};
14+
}
15+
16+
return input;
17+
};
18+
619
export const calculateMargins = <
720
T extends ChartsLegendSlotExtension &
821
Pick<LayoutConfig, 'margin'> & {
@@ -15,7 +28,7 @@ export const calculateMargins = <
1528
if (props.hideLegend || !props.series?.some((s) => s.label)) {
1629
return {
1730
...DEFAULT_MARGINS,
18-
...props.margin,
31+
...numberToMargin(props.margin),
1932
};
2033
}
2134

@@ -24,28 +37,28 @@ export const calculateMargins = <
2437
return {
2538
...DEFAULT_MARGINS,
2639
left: DEFAULT_LEGEND_FACING_MARGIN,
27-
...props.margin,
40+
...numberToMargin(props.margin),
2841
};
2942
}
3043

3144
return {
3245
...DEFAULT_MARGINS,
3346
right: DEFAULT_LEGEND_FACING_MARGIN,
34-
...props.margin,
47+
...numberToMargin(props.margin),
3548
};
3649
}
3750

3851
if (props.slotProps?.legend?.position?.vertical === 'bottom') {
3952
return {
4053
...DEFAULT_MARGINS,
4154
bottom: DEFAULT_LEGEND_FACING_MARGIN,
42-
...props.margin,
55+
...numberToMargin(props.margin),
4356
};
4457
}
4558

4659
return {
4760
...DEFAULT_MARGINS,
4861
top: DEFAULT_LEGEND_FACING_MARGIN,
49-
...props.margin,
62+
...numberToMargin(props.margin),
5063
};
5164
};

packages/x-charts/src/models/layout.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ export type LayoutConfig = {
1616
* Accepts an object with the optional properties: `top`, `bottom`, `left`, and `right`.
1717
* @default object Depends on the charts type.
1818
*/
19-
margin?: Partial<ChartMargin>;
19+
margin?: Partial<ChartMargin> | number;
2020
};

0 commit comments

Comments
 (0)