Skip to content

Commit

Permalink
fixup autorange on interactions
Browse files Browse the repository at this point in the history
  • Loading branch information
archmoj committed Dec 2, 2020
1 parent 7b22175 commit 445eee4
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 40 deletions.
4 changes: 0 additions & 4 deletions src/components/modebar/buttons.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,6 @@ function handleCartesian(gd, ev) {
var astr = button.getAttribute('data-attr');
var val = button.getAttribute('data-val') || true;
var fullLayout = gd._fullLayout;
if(val === 'auto') {
fullLayout._insideTickLabelsAutorangeDone = false;
}

var aobj = {};
var axList = axisIds.list(gd, null, true);
var allSpikesEnabled = fullLayout._cartesianSpikesEnabled;
Expand Down
30 changes: 19 additions & 11 deletions src/plot_api/plot_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,18 @@ function plot(gd, data, layout, config) {
if(hasCartesian) seq.push(positionAndAutorange);

seq.push(subroutines.layoutStyles);
if(hasCartesian) seq.push(drawAxes);
if(hasCartesian) {
seq.push(
drawAxes,
function insideTickLabelsAutorange(gd) {
if(gd._fullLayout._insideTickLabelsAutorange) {
relayout(gd, gd._fullLayout._insideTickLabelsAutorange).then(function() {
gd._fullLayout._insideTickLabelsAutorange = undefined;
});
}
}
);
}

seq.push(
subroutines.drawData,
Expand All @@ -381,13 +392,12 @@ function plot(gd, data, layout, config) {
// calculated. Would be much better to separate margin calculations from
// component drawing - see https://github.com/plotly/plotly.js/issues/2704
Plots.doAutoMargin,
insideTickLabelsAutorange,
saveRangeInitialForInsideTickLabels,
Plots.previousPromises
);

function saveRangeInitialForInsideTickLabels(gd) {
if(gd._fullLayout._insideTickLabelsAutorangeDone) {
if(gd._fullLayout._insideTickLabelsAutorange) {
if(graphWasEmpty) Axes.saveRangeInitial(gd, true);
}
}
Expand All @@ -403,14 +413,6 @@ function plot(gd, data, layout, config) {
});
}

function insideTickLabelsAutorange(gd) {
var obj = gd._fullLayout._insideTickLabelsAutorange;
if(!obj) return;

relayout(gd, obj);
gd._fullLayout._insideTickLabelsAutorangeDone = true;
}

function emitAfterPlot(gd) {
var fullLayout = gd._fullLayout;

Expand Down Expand Up @@ -1977,6 +1979,12 @@ function addAxRangeSequence(seq, rangesAltered) {
var ax = Axes.getFromId(gd, id);
axIds.push(id);

if((ax.ticklabelposition || '').indexOf('inside') !== -1) {
if(ax._anchorAxis) {
axIds.push(ax._anchorAxis._id);
}
}

if(ax._matchGroup) {
for(var id2 in ax._matchGroup) {
if(!rangesAltered[id2]) {
Expand Down
7 changes: 0 additions & 7 deletions src/plot_api/subroutines.js
Original file line number Diff line number Diff line change
Expand Up @@ -675,13 +675,6 @@ exports.doAutoRangeAndConstraints = function(gd) {
for(var i = 0; i < axList.length; i++) {
ax = axList[i];

if(
gd._fullLayout._insideTickLabelsAutorangeDone &&
((ax._anchorAxis || {}).ticklabelposition || '').indexOf('inside') !== -1
) {
continue;
}

if(!autoRangeDone[ax._id]) {
autoRangeDone[ax._id] = 1;
cleanAxisConstraints(gd, ax);
Expand Down
34 changes: 16 additions & 18 deletions src/plots/cartesian/axes.js
Original file line number Diff line number Diff line change
Expand Up @@ -3187,26 +3187,24 @@ axes.drawLabels = function(gd, ax, opts) {
});
}

function computeFinalTickLabelBoundingBoxes() {
tickLabels.each(function(d, i) {
var thisLabel = selectTickLabel(this);
ax._vals[i].bb = Drawing.bBox(thisLabel.node());
});
}
var anchorAx = ax._anchorAxis;
if(
anchorAx && anchorAx.autorange &&
(ax.ticklabelposition || '').indexOf('inside') !== -1
) {
if(!fullLayout._insideTickLabelsAutorange) {
fullLayout._insideTickLabelsAutorange = {};
}
fullLayout._insideTickLabelsAutorange[anchorAx._name + '.autorange'] = anchorAx.autorange;

if(!gd._fullLayout._insideTickLabelsAutorangeDone) {
var anchorAxisAutorange = (ax._anchorAxis || {}).autorange;
if(
anchorAxisAutorange &&
(ax.ticklabelposition || '').indexOf('inside') !== -1
) {
if(!fullLayout._insideTickLabelsAutorange) {
fullLayout._insideTickLabelsAutorange = {};
seq.push(
function computeFinalTickLabelBoundingBoxes() {
tickLabels.each(function(d, i) {
var thisLabel = selectTickLabel(this);
ax._vals[i].bb = Drawing.bBox(thisLabel.node());
});
}
fullLayout._insideTickLabelsAutorange[ax._anchorAxis._name + '.autorange'] = anchorAxisAutorange;

seq.push(computeFinalTickLabelBoundingBoxes);
}
);
}

var done = Lib.syncOrAsync(seq);
Expand Down

0 comments on commit 445eee4

Please sign in to comment.