File tree Expand file tree Collapse file tree 2 files changed +72
-1
lines changed Expand file tree Collapse file tree 2 files changed +72
-1
lines changed Original file line number Diff line number Diff line change @@ -20,7 +20,9 @@ exports.formatPiePercent = function formatPiePercent(v, separators) {
20
20
21
21
exports . formatPieValue = function formatPieValue ( v , separators ) {
22
22
var vRounded = v . toPrecision ( 10 ) ;
23
- if ( vRounded . lastIndexOf ( '.' ) !== - 1 ) {
23
+ if ( vRounded . indexOf ( 'e+' ) !== - 1 ) {
24
+ vRounded = Math . round ( v ) ;
25
+ } else if ( vRounded . lastIndexOf ( '.' ) !== - 1 ) {
24
26
vRounded = vRounded . replace ( / [ . ] ? 0 + $ / , '' ) ;
25
27
}
26
28
return Lib . numSeparate ( vRounded , separators ) ;
Original file line number Diff line number Diff line change @@ -2064,3 +2064,72 @@ describe('pie uniformtext', function() {
2064
2064
. then ( done ) ;
2065
2065
} ) ;
2066
2066
} ) ;
2067
+
2068
+ describe ( 'pie value format' , function ( ) {
2069
+ 'use strict' ;
2070
+
2071
+ var gd ;
2072
+
2073
+ beforeEach ( function ( ) {
2074
+ gd = createGraphDiv ( ) ;
2075
+ } ) ;
2076
+
2077
+ afterEach ( destroyGraphDiv ) ;
2078
+
2079
+ it ( 'should handle rounding big & small numbers' , function ( done ) {
2080
+ Plotly . newPlot ( gd , [ {
2081
+ type : 'pie' ,
2082
+ textinfo : 'value' ,
2083
+ values : [
2084
+ 123456789012 ,
2085
+ 12345678901.2 ,
2086
+ 1234567890.12 ,
2087
+ 123456789.012 ,
2088
+ 12345678.9012 ,
2089
+ 1234567.89012 ,
2090
+ 123456.789012 ,
2091
+ 12345.6789012 ,
2092
+ 1234.56789012 ,
2093
+ 123.456789012 ,
2094
+ 12.3456789012 ,
2095
+ 1.23456789012 ,
2096
+ 0.123456789012 ,
2097
+ 0.0123456789012 ,
2098
+ 0.00123456789012 ,
2099
+ 0.000123456789012 ,
2100
+ 0.0000123456789012 ,
2101
+ 0.00000123456789012 ,
2102
+ ]
2103
+ } ] )
2104
+ . then ( function ( ) {
2105
+ var exp = [
2106
+ '123,456,789,012' ,
2107
+ '12,345,678,901' ,
2108
+ '1,234,567,890' ,
2109
+ '123,456,789' ,
2110
+ '12,345,678.9' ,
2111
+ '1,234,567.89' ,
2112
+ '123,456.789' ,
2113
+ '12,345.6789' ,
2114
+ '1,234.56789' ,
2115
+ '123.456789' ,
2116
+ '12.3456789' ,
2117
+ '1.23456789' ,
2118
+ '0.123456789' ,
2119
+ '0.0123456789' ,
2120
+ '0.00123456789' ,
2121
+ '0.000123456789' ,
2122
+ '0.0000123456789' ,
2123
+ '0.00000123456789'
2124
+ ] ;
2125
+
2126
+ var selection = d3 . selectAll ( SLICES_TEXT_SELECTOR ) ;
2127
+ for ( var i = 0 ; i < selection [ 0 ] . length ; i ++ ) {
2128
+ var text = selection [ 0 ] [ i ] . getAttribute ( 'data-unformatted' ) ;
2129
+ expect ( text ) . toBe ( exp [ i ] ) ;
2130
+ }
2131
+ } )
2132
+ . catch ( failTest )
2133
+ . then ( done ) ;
2134
+ } ) ;
2135
+ } ) ;
You can’t perform that action at this time.
0 commit comments