Skip to content

Commit 1f0168d

Browse files
committed
fix(Legend): fix postion for justifyContent center
1 parent 63f5644 commit 1f0168d

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/components/Legend/index.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,16 @@ const getLegendItemPosition = (args: {
4343
align: PreparedLegend['align'];
4444
contentWidth: number;
4545
width: number;
46+
offsetLeft: number;
4647
}) => {
47-
const {align, width, contentWidth} = args;
48+
const {align, width, contentWidth, offsetLeft} = args;
4849

4950
if (align === 'right') {
5051
return {left: width - contentWidth};
5152
} else if (align === 'left') {
5253
return {left: 0};
5354
} else {
54-
return {left: width / 2 - contentWidth / 2};
55+
return {left: offsetLeft + width / 2 - contentWidth / 2};
5556
}
5657
};
5758

@@ -351,7 +352,9 @@ export const Legend = (props: Props) => {
351352
align: legend.align,
352353
width: config.maxWidth,
353354
contentWidth,
355+
offsetLeft: config.offset.left,
354356
});
357+
355358
left = legendLinePostion.left;
356359
legendWidth = config.maxWidth;
357360
break;
@@ -395,6 +398,7 @@ export const Legend = (props: Props) => {
395398
align: legend.align,
396399
width: config.maxWidth,
397400
contentWidth: legend.width,
401+
offsetLeft: config.offset.left,
398402
});
399403
const {top} = getLegendPosition({
400404
width: config.maxWidth,

0 commit comments

Comments
 (0)