@@ -4,6 +4,7 @@ import { ChartType, StackType } from './interface';
44import { Strings , t } from '../i18n' ;
55import { sortBy } from '../sortBy' ;
66import { getNumberBaseFieldPrecision , maxRenderNum , processChartData , processRecords } from '../helper' ;
7+ import { safeParseNumberOrText } from '../utils' ;
78
89export class EchartsPie extends EchartsBase {
910 type = ChartType . EchartsPie ;
@@ -15,29 +16,29 @@ export class EchartsPie extends EchartsBase {
1516 add ( arg1 , arg2 ) {
1617 let len1 , len2 , expand , subLen ;
1718 try {
18- len1 = arg1 . toString ( ) . split ( "." ) [ 1 ] . length ;
19+ len1 = arg1 . toString ( ) . split ( '.' ) [ 1 ] . length ;
1920 } catch ( e ) {
2021 len1 = 0 ;
2122 }
2223 try {
23- len2 = arg2 . toString ( ) . split ( "." ) [ 1 ] . length ;
24+ len2 = arg2 . toString ( ) . split ( '.' ) [ 1 ] . length ;
2425 } catch ( e ) {
2526 len2 = 0 ;
2627 }
2728 subLen = Math . abs ( len1 - len2 ) ;
2829 expand = Math . pow ( 10 , Math . max ( len1 , len2 ) ) ;
2930 if ( subLen > 0 ) {
30- let scale = Math . pow ( 10 , subLen ) ;
31+ const scale = Math . pow ( 10 , subLen ) ;
3132 if ( len1 > len2 ) {
32- arg1 = Number ( arg1 . toString ( ) . replace ( "." , "" ) ) ;
33- arg2 = Number ( arg2 . toString ( ) . replace ( "." , "" ) ) * scale ;
33+ arg1 = Number ( arg1 . toString ( ) . replace ( '.' , '' ) ) ;
34+ arg2 = Number ( arg2 . toString ( ) . replace ( '.' , '' ) ) * scale ;
3435 } else {
35- arg1 = Number ( arg1 . toString ( ) . replace ( "." , "" ) ) * scale ;
36- arg2 = Number ( arg2 . toString ( ) . replace ( "." , "" ) ) ;
36+ arg1 = Number ( arg1 . toString ( ) . replace ( '.' , '' ) ) * scale ;
37+ arg2 = Number ( arg2 . toString ( ) . replace ( '.' , '' ) ) ;
3738 }
3839 } else {
39- arg1 = Number ( arg1 . toString ( ) . replace ( "." , "" ) ) ;
40- arg2 = Number ( arg2 . toString ( ) . replace ( "." , "" ) ) ;
40+ arg1 = Number ( arg1 . toString ( ) . replace ( '.' , '' ) ) ;
41+ arg2 = Number ( arg2 . toString ( ) . replace ( '.' , '' ) ) ;
4142 }
4243 return ( arg1 + arg2 ) / expand ;
4344 }
@@ -86,8 +87,7 @@ export class EchartsPie extends EchartsBase {
8687 label : {
8788 ...color ,
8889 show : showDataTips ,
89- formatter : ( params ) => `${ params . name } : ${ params . percent . toFixed ( 1 ) } %`
90- // formatter: (params) => `${params.name}: ${Number(params.value / dataSum * 100).toFixed(2)}%`
90+ formatter : ( params ) => `${ params . name } : ${ safeParseNumberOrText ( params . percent , 1 ) } %`
9191 } ,
9292 } ,
9393 } ;
@@ -108,7 +108,7 @@ export class EchartsPie extends EchartsBase {
108108 // const totalContent = Math.round(params.value / (params.percent / 100));
109109 // console.log(totalContent, params.value / (params.percent / 100));
110110 // return `{a|${t(Strings.total)}}\n{b|${totalContent}}`;
111- return `{a|${ t ( Strings . total ) } }\n{b|${ dataSum . toFixed ( fieldPrecision ) } }` ;
111+ return `{a|${ t ( Strings . total ) } }\n{b|${ safeParseNumberOrText ( dataSum , fieldPrecision ) } }` ;
112112 } ,
113113 // formatter: () => {
114114 // const precision = guessNumberFieldPrecision(data.map(item => item.value).filter(Boolean));
@@ -117,7 +117,7 @@ export class EchartsPie extends EchartsBase {
117117 // return `{a|${t(Strings.total)}}\n{b|${totalContent}}`;
118118 // },
119119 rich : {
120- a : { fontSize : 18 , height : 24 , } ,
120+ a : { fontSize : 18 , height : 24 } ,
121121 b : { fontSize : 24 , fontWeight : 'bolder' }
122122 }
123123 } ,
@@ -132,7 +132,7 @@ export class EchartsPie extends EchartsBase {
132132 label : {
133133 ...styleOption . series . label ,
134134 formatter : ( params ) => {
135- return `${ params . name } : ${ params . percent . toFixed ( 1 ) } %`
135+ return `${ params . name } : ${ safeParseNumberOrText ( params . percent , 1 ) } %` ;
136136 }
137137 }
138138 } ;
@@ -203,7 +203,7 @@ export class EchartsPie extends EchartsBase {
203203 return {
204204 ...options ,
205205 series : [
206- { ...styleOption . series , data} ,
206+ { ...styleOption . series , data } ,
207207 { ...styleOption . stackSeries , data }
208208 ]
209209 } ;
0 commit comments