@@ -4,63 +4,59 @@ import {initRange} from "./init.js";
44import tickFormat from "./tickFormat.js" ;
55
66export function linearish ( scale ) {
7- var domain = scale . domain ;
7+ const domain = scale . domain ;
88
99 scale . ticks = function ( count ) {
10- var d = domain ( ) ;
10+ const d = domain ( ) ;
1111 return ticks ( d [ 0 ] , d [ d . length - 1 ] , count == null ? 10 : count ) ;
1212 } ;
1313
1414 scale . tickFormat = function ( count , specifier ) {
15- var d = domain ( ) ;
15+ const d = domain ( ) ;
1616 return tickFormat ( d [ 0 ] , d [ d . length - 1 ] , count == null ? 10 : count , specifier ) ;
1717 } ;
1818
1919 scale . nice = function ( count ) {
2020 if ( count == null ) count = 10 ;
2121
22- var d = domain ( ) ,
23- i0 = 0 ,
24- i1 = d . length - 1 ,
25- start = d [ i0 ] ,
26- stop = d [ i1 ] ,
27- step ;
22+ const d = domain ( ) ;
23+ let i0 = 0 ;
24+ let i1 = d . length - 1 ;
25+ let start = d [ i0 ] ;
26+ let stop = d [ i1 ] ;
27+ let prestep ;
28+ let step ;
2829
2930 if ( stop < start ) {
3031 step = start , start = stop , stop = step ;
3132 step = i0 , i0 = i1 , i1 = step ;
3233 }
33-
34- step = tickIncrement ( start , stop , count ) ;
35-
36- if ( step > 0 ) {
37- start = Math . floor ( start / step ) * step ;
38- stop = Math . ceil ( stop / step ) * step ;
39- step = tickIncrement ( start , stop , count ) ;
40- } else if ( step < 0 ) {
41- start = Math . ceil ( start * step ) / step ;
42- stop = Math . floor ( stop * step ) / step ;
43- step = tickIncrement ( start , stop , count ) ;
34+
35+ // eslint-disable-next-line no-constant-condition
36+ while ( true ) {
37+ const step = tickIncrement ( start , stop , count ) ;
38+ if ( step === prestep ) {
39+ d [ i0 ] = start
40+ d [ i1 ] = stop
41+ return domain ( d ) ;
42+ } else if ( step > 0 ) {
43+ start = Math . floor ( start / step ) * step ;
44+ stop = Math . ceil ( stop / step ) * step ;
45+ } else if ( step < 0 ) {
46+ start = Math . ceil ( start * step ) / step ;
47+ stop = Math . floor ( stop * step ) / step ;
48+ } else {
49+ return scale ;
50+ }
51+ prestep = step ;
4452 }
45-
46- if ( step > 0 ) {
47- d [ i0 ] = Math . floor ( start / step ) * step ;
48- d [ i1 ] = Math . ceil ( stop / step ) * step ;
49- domain ( d ) ;
50- } else if ( step < 0 ) {
51- d [ i0 ] = Math . ceil ( start * step ) / step ;
52- d [ i1 ] = Math . floor ( stop * step ) / step ;
53- domain ( d ) ;
54- }
55-
56- return scale ;
5753 } ;
5854
5955 return scale ;
6056}
6157
6258export default function linear ( ) {
63- var scale = continuous ( ) ;
59+ const scale = continuous ( ) ;
6460
6561 scale . copy = function ( ) {
6662 return copy ( scale , linear ( ) ) ;
0 commit comments