@@ -15,16 +15,35 @@ export const getPixelPropertyStr = (num?: number | number[], defaultStr?: string
1515} ;
1616
1717export 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