Skip to content

Commit d9f4641

Browse files
committed
remove autorange duplication for matching axes
1 parent 13acf8a commit d9f4641

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

src/plot_api/subroutines.js

+20-2
Original file line numberDiff line numberDiff line change
@@ -670,10 +670,28 @@ exports.doAutoRangeAndConstraints = function(gd) {
670670
var axList = Axes.list(gd, '', true);
671671
var ax;
672672

673+
var autoRangeDone = {};
674+
673675
for(var i = 0; i < axList.length; i++) {
674676
ax = axList[i];
675-
cleanAxisConstraints(gd, ax);
676-
doAutoRange(gd, ax);
677+
if(!autoRangeDone[ax._id]) {
678+
autoRangeDone[ax._id] = 1;
679+
cleanAxisConstraints(gd, ax);
680+
doAutoRange(gd, ax);
681+
682+
// For matching axes, just propagate this autorange to the group.
683+
// The extra arg to doAutoRange avoids recalculating the range,
684+
// since doAutoRange by itself accounts for all matching axes. but
685+
// there are other side-effects of doAutoRange that we still want.
686+
var matchGroup = ax._matchGroup;
687+
if(matchGroup) {
688+
for(var id2 in matchGroup) {
689+
var ax2 = Axes.getFromId(gd, id2);
690+
doAutoRange(gd, ax2, ax.range);
691+
autoRangeDone[id2] = 1;
692+
}
693+
}
694+
}
677695
}
678696

679697
enforceAxisConstraints(gd);

src/plots/cartesian/autorange.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,6 @@ function concatExtremes(gd, ax, noMatch) {
245245
_concat(fullLayout.shapes || [], ax._shapeIndices || []);
246246

247247
// Include the extremes from other matched axes with this one
248-
// TODO: find a way to only do this calculation once, rather than
249-
// repeating it for every axis in the matched group
250248
if(ax._matchGroup && !noMatch) {
251249
for(var axId2 in ax._matchGroup) {
252250
if(axId2 !== ax._id) {
@@ -269,11 +267,11 @@ function concatExtremes(gd, ax, noMatch) {
269267
return {min: minArray, max: maxArray};
270268
}
271269

272-
function doAutoRange(gd, ax) {
270+
function doAutoRange(gd, ax, presetRange) {
273271
ax.setScale();
274272

275273
if(ax.autorange) {
276-
ax.range = getAutoRange(gd, ax);
274+
ax.range = presetRange ? presetRange.slice() : getAutoRange(gd, ax);
277275

278276
ax._r = ax.range.slice();
279277
ax._rl = Lib.simpleMap(ax._r, ax.r2l);

0 commit comments

Comments
 (0)