@@ -661,29 +661,30 @@ axes.prepTicks = function(ax, opts) {
661
661
if ( ax . tickmode === 'sync' ) {
662
662
var baseAxis = ax . _mainAxis ;
663
663
664
- // get range min and max to find range delta of axis 1
665
- var minValBaseAxis = Math . min ( baseAxis . range [ 0 ] , baseAxis . range [ 1 ] ) ;
666
- var maxValBaseAxis = Math . max ( baseAxis . range [ 0 ] , baseAxis . range [ 1 ] ) ;
667
- var rangeDeltaBaseAxis = maxValBaseAxis - minValBaseAxis ;
668
-
669
664
// get range min and max to find range delta of axis 2
670
665
var minValAxis = Math . min ( ax . range [ 0 ] , ax . range [ 1 ] ) ;
671
666
var maxValAxis = Math . max ( ax . range [ 0 ] , ax . range [ 1 ] ) ;
672
667
var rangeDeltaCurrentAxis = maxValAxis - minValAxis ;
673
668
674
- // set second axis' dtick value to be based off of same ratio as the first axis
675
- var dtickRatio = rangeDeltaBaseAxis / baseAxis . dtick ;
676
- ax . dtick = rangeDeltaCurrentAxis / dtickRatio ;
677
-
678
669
// validate that the axis has values before we try to use them for tick0 calculation
679
670
if ( baseAxis && baseAxis . _vals . length > 0 ) {
680
- // get position of first axis' starting tick
671
+ var _len = baseAxis . _length - 1 ;
672
+
673
+ // get position of first & last axis' starting ticks
681
674
var firstTickPosition = baseAxis . l2p ( baseAxis . _vals [ 0 ] . x ) ;
682
- var firstTickPercentage = firstTickPosition / baseAxis . _length ;
675
+ var firstTickPercentage = firstTickPosition / _len ;
676
+ firstTickPercentage = Math . round ( firstTickPercentage * 100 ) / 100 ;
677
+
678
+ var lastTickPosition = baseAxis . l2p ( baseAxis . _vals [ baseAxis . _vals . length - 1 ] . x ) ;
679
+ var lastTickPercentage = lastTickPosition / _len ;
680
+ lastTickPercentage = Math . round ( lastTickPercentage * 100 ) / 100 ;
683
681
684
682
// set current axis to have same starting tick position
685
- var currentAxisOffsetVal = rangeDeltaCurrentAxis * ( 1 - firstTickPercentage ) ;
686
- ax . tick0 = currentAxisOffsetVal + minValAxis ;
683
+ var firstOffset = rangeDeltaCurrentAxis * ( 1 - firstTickPercentage ) ;
684
+ ax . tick0 = firstOffset + minValAxis ;
685
+
686
+ var lastOffset = rangeDeltaCurrentAxis * ( 1 - lastTickPercentage ) ;
687
+ ax . dtick = ( lastOffset - firstOffset ) / ( baseAxis . _vals . length - 1 ) ;
687
688
}
688
689
} else if ( ax . tickmode === 'auto' || ! ax . dtick ) { // calculate max number of (auto) ticks to display based on plot size
689
690
var nt = ax . nticks ;
0 commit comments