Skip to content

Commit 445eee4

Browse files
committed
fixup autorange on interactions
1 parent 7b22175 commit 445eee4

File tree

4 files changed

+35
-40
lines changed

4 files changed

+35
-40
lines changed

src/components/modebar/buttons.js

-4
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,6 @@ function handleCartesian(gd, ev) {
249249
var astr = button.getAttribute('data-attr');
250250
var val = button.getAttribute('data-val') || true;
251251
var fullLayout = gd._fullLayout;
252-
if(val === 'auto') {
253-
fullLayout._insideTickLabelsAutorangeDone = false;
254-
}
255-
256252
var aobj = {};
257253
var axList = axisIds.list(gd, null, true);
258254
var allSpikesEnabled = fullLayout._cartesianSpikesEnabled;

src/plot_api/plot_api.js

+19-11
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,18 @@ function plot(gd, data, layout, config) {
367367
if(hasCartesian) seq.push(positionAndAutorange);
368368

369369
seq.push(subroutines.layoutStyles);
370-
if(hasCartesian) seq.push(drawAxes);
370+
if(hasCartesian) {
371+
seq.push(
372+
drawAxes,
373+
function insideTickLabelsAutorange(gd) {
374+
if(gd._fullLayout._insideTickLabelsAutorange) {
375+
relayout(gd, gd._fullLayout._insideTickLabelsAutorange).then(function() {
376+
gd._fullLayout._insideTickLabelsAutorange = undefined;
377+
});
378+
}
379+
}
380+
);
381+
}
371382

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

389399
function saveRangeInitialForInsideTickLabels(gd) {
390-
if(gd._fullLayout._insideTickLabelsAutorangeDone) {
400+
if(gd._fullLayout._insideTickLabelsAutorange) {
391401
if(graphWasEmpty) Axes.saveRangeInitial(gd, true);
392402
}
393403
}
@@ -403,14 +413,6 @@ function plot(gd, data, layout, config) {
403413
});
404414
}
405415

406-
function insideTickLabelsAutorange(gd) {
407-
var obj = gd._fullLayout._insideTickLabelsAutorange;
408-
if(!obj) return;
409-
410-
relayout(gd, obj);
411-
gd._fullLayout._insideTickLabelsAutorangeDone = true;
412-
}
413-
414416
function emitAfterPlot(gd) {
415417
var fullLayout = gd._fullLayout;
416418

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

1982+
if((ax.ticklabelposition || '').indexOf('inside') !== -1) {
1983+
if(ax._anchorAxis) {
1984+
axIds.push(ax._anchorAxis._id);
1985+
}
1986+
}
1987+
19801988
if(ax._matchGroup) {
19811989
for(var id2 in ax._matchGroup) {
19821990
if(!rangesAltered[id2]) {

src/plot_api/subroutines.js

-7
Original file line numberDiff line numberDiff line change
@@ -675,13 +675,6 @@ exports.doAutoRangeAndConstraints = function(gd) {
675675
for(var i = 0; i < axList.length; i++) {
676676
ax = axList[i];
677677

678-
if(
679-
gd._fullLayout._insideTickLabelsAutorangeDone &&
680-
((ax._anchorAxis || {}).ticklabelposition || '').indexOf('inside') !== -1
681-
) {
682-
continue;
683-
}
684-
685678
if(!autoRangeDone[ax._id]) {
686679
autoRangeDone[ax._id] = 1;
687680
cleanAxisConstraints(gd, ax);

src/plots/cartesian/axes.js

+16-18
Original file line numberDiff line numberDiff line change
@@ -3187,26 +3187,24 @@ axes.drawLabels = function(gd, ax, opts) {
31873187
});
31883188
}
31893189

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

3197-
if(!gd._fullLayout._insideTickLabelsAutorangeDone) {
3198-
var anchorAxisAutorange = (ax._anchorAxis || {}).autorange;
3199-
if(
3200-
anchorAxisAutorange &&
3201-
(ax.ticklabelposition || '').indexOf('inside') !== -1
3202-
) {
3203-
if(!fullLayout._insideTickLabelsAutorange) {
3204-
fullLayout._insideTickLabelsAutorange = {};
3200+
seq.push(
3201+
function computeFinalTickLabelBoundingBoxes() {
3202+
tickLabels.each(function(d, i) {
3203+
var thisLabel = selectTickLabel(this);
3204+
ax._vals[i].bb = Drawing.bBox(thisLabel.node());
3205+
});
32053206
}
3206-
fullLayout._insideTickLabelsAutorange[ax._anchorAxis._name + '.autorange'] = anchorAxisAutorange;
3207-
3208-
seq.push(computeFinalTickLabelBoundingBoxes);
3209-
}
3207+
);
32103208
}
32113209

32123210
var done = Lib.syncOrAsync(seq);

0 commit comments

Comments
 (0)