@@ -120,25 +120,20 @@ function d3_scale_linearTickFormat(domain, m, format) {
120120 var formatString = format ?
121121 format . replace ( d3_format_re ,
122122 function ( a , b , c , d , e , f , g , h , i , j ) {
123- // Compute "decimal precision" of the tick step size, i.e., the position of its last
124- // significant digit with respect to the decimal point.
125- var decimalPrecisionStep = decimalPrecision ( range [ 2 ] ) ;
126- var precision ;
127- if ( j === "s" || j === "g" || j === "e" ) {
128- // For these formats, "precision" specifies the number of significant digits, which equals
129- // one plus the difference between the decimal precision of the range's maximum absolute
130- // value (which will equal one of its bounds) and the tick step's decimal precision.
131- var precisionMaxAbsValue = decimalPrecision ( Math . max ( Math . abs ( range [ 0 ] ) , Math . abs ( range [ 1 ] ) ) ) ;
132- precision = Math . abs ( decimalPrecisionStep - precisionMaxAbsValue ) + 1 ;
133- if ( j === "e" ) {
134- // The digit before the decimal point counts as one.
135- precision -= 1 ;
136- }
137- } else {
138- // Formats such as "f" use decimal precision.
139- precision = decimalPrecisionStep ;
123+ function computePrecision ( ) {
124+ // Compute the "decimal precision" of the tick step size, i.e., the position of its last
125+ // significant digit with respect to the decimal point.
126+ var decimalPrecisionStep = decimalPrecision ( range [ 2 ] ) ;
127+ return ( j === "s" || j === "g" || j === "e" ) ?
128+ // For formats "s" and "g", "precision" specifies the number of significant digits, which
129+ // equals one plus the difference between the decimal precision of the range's maximum
130+ // absolute value (which equals one of its bounds) and the tick step's decimal precision.
131+ // Format "e" is similar except that the digit before the decimal point counts as one.
132+ Math . abs ( decimalPrecisionStep - decimalPrecision ( Math . max ( Math . abs ( range [ 0 ] ) , Math . abs ( range [ 1 ] ) ) ) ) + ( j !== "e" ) * 1 :
133+ // Formats such as "f" and "%" depend only on step precision.
134+ decimalPrecisionStep - ( j === "%" ) * 2 ;
140135 }
141- return [ b , c , d , e , f , g , h , i || "." + ( precision - ( j === "%" ) * 2 ) , j ] . join ( "" ) ;
136+ return [ b , c , d , e , f , g , h , i || "." + computePrecision ( ) , j ] . join ( "" ) ;
142137 } )
143138 : ",." + decimalPrecision ( range [ 2 ] ) + "f" ;
144139 return d3 . format ( formatString ) ;
0 commit comments