@@ -270,12 +270,12 @@ function determineUnitForAutoTicks(minUnit, min, max, capacity) {
270
270
/**
271
271
* Figures out what unit to format a set of ticks with
272
272
*/
273
- function determineUnitForFormatting ( scale , ticks , minUnit , min , max ) {
273
+ function determineUnitForFormatting ( scale , numTicks , minUnit , min , max ) {
274
274
var i , unit ;
275
275
276
276
for ( i = UNITS . length - 1 ; i >= UNITS . indexOf ( minUnit ) ; i -- ) {
277
277
unit = UNITS [ i ] ;
278
- if ( INTERVALS [ unit ] . common && scale . _adapter . diff ( max , min , unit ) >= ticks . length - 1 ) {
278
+ if ( INTERVALS [ unit ] . common && scale . _adapter . diff ( max , min , unit ) >= numTicks - 1 ) {
279
279
return unit ;
280
280
}
281
281
}
@@ -562,11 +562,12 @@ module.exports = Scale.extend({
562
562
var min = me . min ;
563
563
var max = me . max ;
564
564
var options = me . options ;
565
+ var tickOpts = options . ticks ;
565
566
var timeOpts = options . time ;
566
567
var timestamps = me . _timestamps ;
567
568
var ticks = [ ] ;
568
569
var capacity = me . getLabelCapacity ( min ) ;
569
- var source = options . ticks . source ;
570
+ var source = tickOpts . source ;
570
571
var distribution = options . distribution ;
571
572
var i , ilen , timestamp ;
572
573
@@ -599,13 +600,17 @@ module.exports = Scale.extend({
599
600
me . max = max ;
600
601
601
602
// PRIVATE
602
- me . _unit = timeOpts . unit || determineUnitForFormatting ( me , ticks , timeOpts . minUnit , me . min , me . max ) ;
603
- me . _majorUnit = ! options . ticks . major . enabled || me . _unit === 'year' ? undefined
603
+ // determineUnitForFormatting relies on the number of ticks so we don't use it when
604
+ // autoSkip is enabled because we don't yet know what the final number of ticks will be
605
+ me . _unit = timeOpts . unit || ( tickOpts . autoSkip
606
+ ? determineUnitForAutoTicks ( timeOpts . minUnit , me . min , me . max , capacity )
607
+ : determineUnitForFormatting ( me , ticks . length , timeOpts . minUnit , me . min , me . max ) ) ;
608
+ me . _majorUnit = ! tickOpts . major . enabled || me . _unit === 'year' ? undefined
604
609
: determineMajorUnit ( me . _unit ) ;
605
610
me . _table = buildLookupTable ( me . _timestamps . data , min , max , distribution ) ;
606
611
me . _offsets = computeOffsets ( me . _table , ticks , min , max , options ) ;
607
612
608
- if ( options . ticks . reverse ) {
613
+ if ( tickOpts . reverse ) {
609
614
ticks . reverse ( ) ;
610
615
}
611
616
0 commit comments