@@ -20,25 +20,21 @@ function transformExpn(x) {
20
20
return - Math . exp ( - x ) ;
21
21
}
22
22
23
- function pow10 ( x , k ) {
24
- return isFinite ( x ) ? + ( k + "e" + x ) : x < 0 ? 0 : x ;
25
- }
26
-
27
- function exp ( x , k ) {
28
- return Math . exp ( x ) * k ;
23
+ function pow10 ( x ) {
24
+ return isFinite ( x ) ? + ( "1e" + x ) : x < 0 ? 0 : x ;
29
25
}
30
26
31
27
function powp ( base ) {
32
28
return base === 10 ? pow10
33
- : base === Math . E ? exp
34
- : ( x , k ) => Math . pow ( base , x ) * k ;
29
+ : base === Math . E ? Math . exp
30
+ : x => Math . pow ( base , x ) ;
35
31
}
36
32
37
33
function logp ( base ) {
38
34
return base === Math . E ? Math . log
39
35
: base === 10 && Math . log10
40
36
|| base === 2 && Math . log2
41
- || ( base = Math . log ( base ) , ( x ) => Math . log ( x ) / base ) ;
37
+ || ( base = Math . log ( base ) , x => Math . log ( x ) / base ) ;
42
38
}
43
39
44
40
function reflect ( f ) {
@@ -90,24 +86,23 @@ export function loggish(transform) {
90
86
i = Math . floor ( i ) , j = Math . ceil ( j ) ;
91
87
if ( u > 0 ) for ( ; i <= j ; ++ i ) {
92
88
for ( k = 1 ; k < base ; ++ k ) {
93
- t = pows ( i , k ) ;
89
+ t = i < 0 ? k / pows ( - i ) : k * pows ( i ) ;
94
90
if ( t < u ) continue ;
95
91
if ( t > v ) break ;
96
92
z . push ( t ) ;
97
93
}
98
94
} else for ( ; i <= j ; ++ i ) {
99
95
for ( k = base - 1 ; k >= 1 ; -- k ) {
100
- t = pows ( i , k ) ;
96
+ t = i > 0 ? k / pows ( - i ) : k * pows ( i ) ;
101
97
if ( t < u ) continue ;
102
98
if ( t > v ) break ;
103
99
z . push ( t ) ;
104
100
}
105
101
}
106
102
if ( z . length * 2 < n ) z = ticks ( u , v , n ) ;
107
103
} else {
108
- z = ticks ( i , j , Math . min ( j - i , n ) ) . map ( i => pows ( i , 1 ) ) ;
104
+ z = ticks ( i , j , Math . min ( j - i , n ) ) . map ( pows ) ;
109
105
}
110
-
111
106
return r ? z . reverse ( ) : z ;
112
107
} ;
113
108
@@ -121,16 +116,16 @@ export function loggish(transform) {
121
116
if ( count === Infinity ) return specifier ;
122
117
const k = Math . max ( 1 , base * count / scale . ticks ( ) . length ) ; // TODO fast estimate?
123
118
return d => {
124
- let i = d / pows ( Math . round ( logs ( d ) ) , 1 ) ;
119
+ let i = d / pows ( Math . round ( logs ( d ) ) ) ;
125
120
if ( i * base < base - 0.5 ) i *= base ;
126
121
return i <= k ? specifier ( d ) : "" ;
127
122
} ;
128
123
} ;
129
124
130
125
scale . nice = ( ) => {
131
126
return domain ( nice ( domain ( ) , {
132
- floor : x => pows ( Math . floor ( logs ( x ) ) , 1 ) ,
133
- ceil : x => pows ( Math . ceil ( logs ( x ) ) , 1 )
127
+ floor : x => pows ( Math . floor ( logs ( x ) ) ) ,
128
+ ceil : x => pows ( Math . ceil ( logs ( x ) ) )
134
129
} ) ) ;
135
130
} ;
136
131
0 commit comments