Skip to content

Commit fd456f6

Browse files
committed
fix: fix invalid style value in tooltip
1 parent 85807e2 commit fd456f6

File tree

1 file changed

+29
-10
lines changed
  • packages/vchart/src/plugin/components/tooltip-handler/utils

1 file changed

+29
-10
lines changed

packages/vchart/src/plugin/components/tooltip-handler/utils/style.ts

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,35 @@ export const getPixelPropertyStr = (num?: number | number[], defaultStr?: string
1515
};
1616

1717
export const getTextStyle = (style: ITooltipTextTheme = {}) => {
18-
const textStyle: Partial<CSSStyleDeclaration> = {
19-
color: style.fill ?? style.fontColor,
20-
fontFamily: style.fontFamily,
21-
fontSize: getPixelPropertyStr(style.fontSize as number),
22-
fontWeight: style.fontWeight as string,
23-
textAlign: style.textAlign,
24-
maxWidth: getPixelPropertyStr(style.maxWidth),
25-
whiteSpace: style.multiLine ? 'initial' : 'nowrap',
26-
wordBreak: style.multiLine ? style.wordBreak ?? 'break-word' : 'normal'
27-
};
18+
const textStyle: Partial<CSSStyleDeclaration> = {};
19+
20+
if (isValid(style.fontFamily)) {
21+
textStyle.fontFamily = style.fontFamily;
22+
}
23+
const color = style.fill ?? style.fontColor;
24+
25+
if (isValid(color)) {
26+
textStyle.color = color;
27+
}
28+
if (isValid(style.fontWeight)) {
29+
textStyle.fontWeight = style.fontWeight as string;
30+
}
31+
if (isValid(style.textAlign)) {
32+
textStyle.textAlign = style.textAlign as string;
33+
}
34+
if (isValid(style.fontSize)) {
35+
textStyle.fontSize = getPixelPropertyStr(style.fontSize as number);
36+
}
37+
if (isValid(style.maxWidth)) {
38+
textStyle.maxWidth = getPixelPropertyStr(style.maxWidth as number);
39+
}
40+
if (style.multiLine) {
41+
textStyle.whiteSpace = 'initial';
42+
textStyle.wordBreak = style.wordBreak ?? 'break-word';
43+
} else {
44+
textStyle.wordBreak = 'normal';
45+
textStyle.whiteSpace = 'nowrap';
46+
}
2847

2948
return textStyle;
3049
};

0 commit comments

Comments
 (0)