Skip to content

Commit

Permalink
make interactions for matched group w/ missing axes work
Browse files Browse the repository at this point in the history
- do not consider 'missing' axes during autorange sync-up operation
- do not attempt to update missing axes on drag and
  other relayout calls that reference missing axes
  • Loading branch information
etpinard committed Jan 29, 2020
1 parent 33078b0 commit df1c59f
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/plot_api/subroutines.js
Original file line number Diff line number Diff line change
Expand Up @@ -670,13 +670,15 @@ exports.doAutoRangeAndConstraints = function(gd) {
var fullLayout = gd._fullLayout;
var axList = Axes.list(gd, '', true);
var matchGroups = fullLayout._axisMatchGroups || [];
var axLookup = {};
var ax;
var axRng;

for(var i = 0; i < axList.length; i++) {
ax = axList[i];
cleanAxisConstraints(gd, ax);
doAutoRange(gd, ax);
axLookup[ax._id] = 1;
}

enforceAxisConstraints(gd);
Expand All @@ -689,6 +691,10 @@ exports.doAutoRangeAndConstraints = function(gd) {

for(id in group) {
ax = Axes.getFromId(gd, id);

// skip over 'missing' axes which do not pass through doAutoRange
if(!axLookup[ax._id]) continue;
// if one axis has autorange false, we're done
if(ax.autorange === false) continue groupLoop;

axRng = Lib.simpleMap(ax.range, ax.r2l);
Expand Down
8 changes: 6 additions & 2 deletions src/plots/cartesian/axes.js
Original file line number Diff line number Diff line change
Expand Up @@ -1669,10 +1669,14 @@ axes.drawOne = function(gd, ax, opts) {
var axId = ax._id;
var axLetter = axId.charAt(0);
var counterLetter = axes.counterLetter(axId);
var mainLinePosition = ax._mainLinePosition;
var mainMirrorPosition = ax._mainMirrorPosition;
var mainPlotinfo = fullLayout._plots[ax._mainSubplot];

// this happens when updating matched group with 'missing' axes
if(!mainPlotinfo) return;

var mainAxLayer = mainPlotinfo[axLetter + 'axislayer'];
var mainLinePosition = ax._mainLinePosition;
var mainMirrorPosition = ax._mainMirrorPosition;

var vals = ax._vals = axes.calcTicks(ax);

Expand Down
53 changes: 53 additions & 0 deletions test/jasmine/tests/cartesian_interact_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1535,6 +1535,59 @@ describe('axis zoom/pan and main plot zoom', function() {
.catch(failTest)
.then(done);
});

it('panning a matching axes with references to *missing* axes', function(done) {
var data = [
// N.B. no traces on subplot xy
{ x: [1, 2, 3], y: [1, 2, 1], xaxis: 'x2', yaxis: 'y2'},
{ x: [1, 2, 3], y: [1, 2, 1], xaxis: 'x3', yaxis: 'y3'},
{ x: [1, 2, 3], y: [1, 2, 1], xaxis: 'x4', yaxis: 'y4'}
];

var layout = {
xaxis: {domain: [0, 0.48]},
xaxis2: {anchor: 'y2', domain: [0.52, 1], matches: 'x'},
xaxis3: {anchor: 'y3', domain: [0, 0.48], matches: 'x'},
xaxis4: {anchor: 'y4', domain: [0.52, 1], matches: 'x'},
yaxis: {domain: [0, 0.48]},
yaxis2: {anchor: 'x2', domain: [0.52, 1], matches: 'y'},
yaxis3: {anchor: 'x3', domain: [0.52, 1], matches: 'y'},
yaxis4: {anchor: 'x4', domain: [0, 0.48], matches: 'y'},
width: 400,
height: 400,
margin: {t: 50, l: 50, b: 50, r: 50},
showlegend: false,
dragmode: 'pan'
};

makePlot(data, layout).then(function() {
assertRanges('base', [
[['xaxis', 'xaxis2', 'xaxis3', 'xaxis4'], [0.8206, 3.179]],
[['yaxis', 'yaxis2', 'yaxis3', 'yaxis4'], [0.9103, 2.0896]]
]);
})
.then(function() {
var drag = makeDragFns('x2y2', 'nsew', 30, 30);
return drag.start().then(function() {
assertRanges('during drag', [
[['xaxis', 'xaxis2', 'xaxis3', 'xaxis4'], [0.329, 2.687], {skipInput: true}],
[['yaxis', 'yaxis2', 'yaxis3', 'yaxis4'], [1.156, 2.335], {skipInput: true}]
]);
})
.then(drag.end);
})
.then(_assert('after drag on x2y2 subplot', [
[['xaxis', 'xaxis2', 'xaxis3', 'xaxis4'], [0.329, 2.687], {dragged: true}],
[['yaxis', 'yaxis2', 'yaxis3', 'yaxis4'], [1.156, 2.335], {dragged: true}]
]))
.then(doDblClick('x3y3', 'nsew'))
.then(_assert('after double-click on x3y3 subplot', [
[['xaxis', 'xaxis2', 'xaxis3', 'xaxis4'], [0.8206, 3.179], {autorange: true}],
[['yaxis', 'yaxis2', 'yaxis3', 'yaxis4'], [0.9103, 2.0896], {autorange: true}]
]))
.catch(failTest)
.then(done);
});
});

describe('redrag behavior', function() {
Expand Down

0 comments on commit df1c59f

Please sign in to comment.