Skip to content

Commit c5f9e74

Browse files
committed
fix partial ax-range relayout calls for matching axes
... moreovwe, boast relayout perf for non-autorange matching axis groups.
1 parent 8c09944 commit c5f9e74

File tree

3 files changed

+80
-9
lines changed

3 files changed

+80
-9
lines changed

src/plot_api/plot_api.js

+18-8
Original file line numberDiff line numberDiff line change
@@ -1932,25 +1932,35 @@ exports.relayout = relayout;
19321932
// Optimization mostly for large splom traces where
19331933
// Plots.supplyDefaults can take > 100ms
19341934
function axRangeSupplyDefaultsByPass(gd, flags, specs) {
1935-
var k;
1935+
var fullLayout = gd._fullLayout;
1936+
var axisMatchGroups = fullLayout._axisMatchGroups || [];
19361937

19371938
if(!flags.axrange) return false;
19381939

1939-
for(k in flags) {
1940+
for(var k in flags) {
19401941
if(k !== 'axrange' && flags[k]) return false;
19411942
}
19421943

1943-
for(k in specs.rangesAltered) {
1944-
var axName = Axes.id2name(k);
1944+
for(var axId in specs.rangesAltered) {
1945+
var axName = Axes.id2name(axId);
19451946
var axIn = gd.layout[axName];
1946-
var axOut = gd._fullLayout[axName];
1947+
var axOut = fullLayout[axName];
19471948
axOut.autorange = axIn.autorange;
19481949
axOut.range = axIn.range.slice();
19491950
axOut.cleanRange();
1950-
}
19511951

1952-
// no need to consider matching axes here,
1953-
// if we keep block in doAutoRangeAndConstraints
1952+
for(var i = 0; i < axisMatchGroups.length; i++) {
1953+
var group = axisMatchGroups[i];
1954+
if(group[axId]) {
1955+
for(var axId2 in group) {
1956+
var ax2 = fullLayout[Axes.id2name(axId2)];
1957+
ax2.autorange = axOut.autorange;
1958+
ax2.range = axOut.range.slice();
1959+
ax2._input.range = axOut.range.slice();
1960+
}
1961+
}
1962+
}
1963+
}
19541964

19551965
return true;
19561966
}

src/plot_api/subroutines.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -710,14 +710,15 @@ exports.doAutoRangeAndConstraints = function(gd) {
710710

711711
enforceAxisConstraints(gd);
712712

713-
// TODO bypass this when matching axes aren't autoranged?
713+
groupLoop:
714714
for(var j = 0; j < matchGroups.length; j++) {
715715
var group = matchGroups[j];
716716
var rng = null;
717717
var id;
718718

719719
for(id in group) {
720720
ax = Axes.getFromId(gd, id);
721+
if(ax.autorange === false) continue groupLoop;
721722

722723
if(rng) {
723724
if(rng[0] < rng[1]) {

test/jasmine/tests/axes_test.js

+60
Original file line numberDiff line numberDiff line change
@@ -1192,6 +1192,66 @@ describe('Test axes', function() {
11921192
});
11931193
});
11941194

1195+
describe('matching axes relayout calls', function() {
1196+
var gd;
1197+
1198+
beforeEach(function() {
1199+
gd = createGraphDiv();
1200+
});
1201+
1202+
afterEach(destroyGraphDiv);
1203+
1204+
function assertRanges(msg, exp) {
1205+
exp.forEach(function(expi) {
1206+
var axNames = expi[0];
1207+
var rng = expi[1];
1208+
var autorng = expi[2];
1209+
1210+
axNames.forEach(function(n) {
1211+
var msgi = n + ' - ' + msg;
1212+
expect(gd._fullLayout[n].range).toBeCloseToArray(rng, 1.5, msgi + ' |range');
1213+
expect(gd._fullLayout[n].autorange).toBe(autorng, msgi + ' |autorange');
1214+
});
1215+
});
1216+
}
1217+
1218+
it('should auto-range according to all matching trace data', function(done) {
1219+
Plotly.plot(gd, [
1220+
{ y: [1, 2, 1] },
1221+
{ y: [2, 1, 2, 3], xaxis: 'x2' },
1222+
{ y: [0, 1], xaxis: 'x3' }
1223+
], {
1224+
xaxis: {domain: [0, 0.2]},
1225+
xaxis2: {matches: 'x', domain: [0.3, 0.6]},
1226+
xaxis3: {matches: 'x', domain: [0.65, 1]},
1227+
width: 800,
1228+
height: 500,
1229+
})
1230+
.then(function() {
1231+
assertRanges('base (autoranged)', [
1232+
[['xaxis', 'xaxis2', 'xaxis3'], [-0.245, 3.245], true],
1233+
[['yaxis'], [-0.211, 3.211], true]
1234+
]);
1235+
})
1236+
.then(function() { return Plotly.relayout(gd, 'xaxis.range', [-1, 4]); })
1237+
.then(function() {
1238+
assertRanges('set range', [
1239+
[['xaxis', 'xaxis2', 'xaxis3'], [-1, 4], false],
1240+
[['yaxis'], [-0.211, 3.211], true]
1241+
]);
1242+
})
1243+
.then(function() { return Plotly.relayout(gd, 'xaxis2.autorange', true); })
1244+
.then(function() {
1245+
assertRanges('back to autorange', [
1246+
[['xaxis', 'xaxis2', 'xaxis3'], [-0.245, 3.245], true],
1247+
[['yaxis'], [-0.211, 3.211], true]
1248+
]);
1249+
})
1250+
.catch(failTest)
1251+
.then(done);
1252+
});
1253+
});
1254+
11951255
describe('categoryorder', function() {
11961256

11971257
var gd;

0 commit comments

Comments
 (0)