Skip to content

Commit 93f4a8e

Browse files
Moves tickmode sync to use last position on the grid
1 parent e62be46 commit 93f4a8e

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

src/plots/cartesian/axes.js

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -661,29 +661,30 @@ axes.prepTicks = function(ax, opts) {
661661
if(ax.tickmode === 'sync') {
662662
var baseAxis = ax._mainAxis;
663663

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-
669664
// get range min and max to find range delta of axis 2
670665
var minValAxis = Math.min(ax.range[0], ax.range[1]);
671666
var maxValAxis = Math.max(ax.range[0], ax.range[1]);
672667
var rangeDeltaCurrentAxis = maxValAxis - minValAxis;
673668

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-
678669
// validate that the axis has values before we try to use them for tick0 calculation
679670
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
681674
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;
683681

684682
// 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);
687688
}
688689
} else if(ax.tickmode === 'auto' || !ax.dtick) { // calculate max number of (auto) ticks to display based on plot size
689690
var nt = ax.nticks;

0 commit comments

Comments
 (0)