@@ -117,26 +117,29 @@ function d3_scale_linearTicks(domain, m) {
117117function d3_scale_linearTickFormat ( domain , m , format ) {
118118 function decimalPrecision ( value ) { return - Math . floor ( Math . log ( value ) / Math . LN10 + .01 ) ; } ;
119119 var range = d3_scale_linearTickRange ( domain , m ) ;
120- // Compute "decimal precision" of the tick step size, i.e., the position of its last significant
121- // digit with respect to the decimal point.
122- var decimalPrecisionStep = decimalPrecision ( range [ 2 ] ) ;
123- var precision ;
124- if ( format === "s" || format === "g" || format === "e" ) {
125- // For these formats, "precision" specifies the number of significant digits, which equals one
126- // plus the difference between the decimal precision of the range's maximum absolute value
127- // (which will equal one of its bounds) and the tick step's decimal precision.
128- var precisionMaxAbsValue = decimalPrecision ( Math . max ( Math . abs ( range [ 0 ] ) , Math . abs ( range [ 1 ] ) ) ) ;
129- precision = Math . abs ( decimalPrecisionStep - precisionMaxAbsValue ) + 1 ;
130- if ( format == "e" ) {
131- // The digit before the decimal point counts as one
132- precision -= 1 ;
133- }
134- } else {
135- // Formats such as "f" use decimal precision.
136- precision = decimalPrecisionStep ;
137- }
138- var formatString = format ? format . replace ( d3_format_re , function ( a , b , c , d , e , f , g , h , i , j ) {
139- return [ b , c , d , e , f , g , h , i || "." + ( precision - ( j === "%" ) * 2 ) , j ] . join ( "" ) ;
140- } ) : ",." + precision + "f" ;
120+ var formatString = format ?
121+ format . replace ( d3_format_re ,
122+ 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 ;
140+ }
141+ return [ b , c , d , e , f , g , h , i || "." + ( precision - ( j === "%" ) * 2 ) , j ] . join ( "" ) ;
142+ } )
143+ : ",." + decimalPrecision ( range [ 2 ] ) + "f" ;
141144 return d3 . format ( formatString ) ;
142145}
0 commit comments