Skip to content

Commit

Permalink
Merge pull request #351 from plotly/restyle-zoom
Browse files Browse the repository at this point in the history
Don't override saved initial ranges on data-updating restyle calls [fixes #346]
  • Loading branch information
etpinard committed Mar 23, 2016
2 parents 4ba05d8 + 5243590 commit bbb8205
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 85 deletions.
13 changes: 5 additions & 8 deletions src/plot_api/plot_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,20 +147,17 @@ Plotly.plot = function(gd, data, layout, config) {
}
else if(graphWasEmpty) makePlotFramework(gd);

// save initial axis range once per graph
if(graphWasEmpty) Plotly.Axes.saveRangeInitial(gd);

var fullLayout = gd._fullLayout;

// prepare the data and find the autorange

// generate calcdata, if we need to
// to force redoing calcdata, just delete it before calling Plotly.plot
var recalc = !gd.calcdata || gd.calcdata.length!==(gd.data||[]).length;
if(recalc) {
doCalcdata(gd);

if(gd._context.doubleClick!==false || gd._context.displayModeBar!==false) {
Plotly.Axes.saveRangeInitial(gd);
}
}
var recalc = !gd.calcdata || gd.calcdata.length !== (gd.data || []).length;
if(recalc) doCalcdata(gd);

// in case it has changed, attach fullData traces to calcdata
for(var i = 0; i < gd.calcdata.length; i++) {
Expand Down
3 changes: 3 additions & 0 deletions test/jasmine/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
"env": {
"browser": true,
"jasmine": true
},
"globals": {
"Promise": true
}
}
196 changes: 119 additions & 77 deletions test/jasmine/tests/click_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var mouseEvent = require('../assets/mouse_event');
var customMatchers = require('../assets/custom_matchers');


describe('click interactions', function() {
describe('Test click interactions:', function() {
var mock = require('@mocks/14.json'),
gd;

Expand All @@ -26,12 +26,15 @@ describe('click interactions', function() {
mouseEvent('mouseup', x, y);
}

function doubleClick(x, y, cb) {
click(x, y);
setTimeout(function() {
function doubleClick(x, y) {
return new Promise(function(resolve) {
click(x, y);
cb();
}, DBLCLICKDELAY / 2);

setTimeout(function() {
click(x, y);
resolve();
}, DBLCLICKDELAY / 2);
});
}

describe('click events', function() {
Expand Down Expand Up @@ -87,7 +90,7 @@ describe('click interactions', function() {
});

it('should return null', function(done) {
doubleClick(pointPos[0], pointPos[1], function() {
doubleClick(pointPos[0], pointPos[1]).then(function() {
expect(futureData).toBe(null);
done();
});
Expand All @@ -113,9 +116,11 @@ describe('click interactions', function() {
'yaxis.range[1]': zoomRangeY[1]
};

beforeEach(function() {
beforeAll(function() {
jasmine.addMatchers(customMatchers);
});

beforeEach(function() {
gd = createGraphDiv();
mockCopy = Lib.extendDeep({}, mock);
});
Expand All @@ -139,12 +144,12 @@ describe('click interactions', function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(zoomRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(zoomRangeY);

doubleClick(blankPos[0], blankPos[1], function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(autoRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(autoRangeY);
return doubleClick(blankPos[0], blankPos[1]);
}).then(function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(autoRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(autoRangeY);

done();
});
done();
});
});
});
Expand All @@ -156,17 +161,17 @@ describe('click interactions', function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(setRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(setRangeY);

Plotly.relayout(gd, update).then(function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(zoomRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(zoomRangeY);
return Plotly.relayout(gd, update);
}).then(function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(zoomRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(zoomRangeY);

doubleClick(blankPos[0], blankPos[1], function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(setRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(setRangeY);
return doubleClick(blankPos[0], blankPos[1]);
}).then(function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(setRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(setRangeY);

done();
});
});
done();
});
});

Expand All @@ -177,17 +182,54 @@ describe('click interactions', function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(setRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(setRangeY);

doubleClick(blankPos[0], blankPos[1], function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(autoRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(autoRangeY);
return doubleClick(blankPos[0], blankPos[1]);
}).then(function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(autoRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(autoRangeY);

doubleClick(blankPos[0], blankPos[1], function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(setRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(setRangeY);
return doubleClick(blankPos[0], blankPos[1]);
}).then(function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(setRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(setRangeY);

done();
});
});
done();
});
});

it('when set to \'reset+autorange\' (the default) should follow updated auto ranges', function(done) {
var updateData = {
x: [[1e-4, 0, 1e3]],
y: [[30, 0, 30]]
};

var newAutoRangeX = [-4.482371794871794, 3.4823717948717943],
newAutoRangeY = [-0.8892256657741471, 1.6689872212461876];

Plotly.plot(gd, mockCopy.data, mockCopy.layout).then(function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(autoRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(autoRangeY);

return Plotly.relayout(gd, update);
}).then(function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(zoomRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(zoomRangeY);

return Plotly.restyle(gd, updateData);
}).then(function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(zoomRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(zoomRangeY);

return doubleClick(blankPos[0], blankPos[1]);
}).then(function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(newAutoRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(newAutoRangeY);

return doubleClick(blankPos[0], blankPos[1]);
}).then(function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(newAutoRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(newAutoRangeY);

done();
});
});

Expand All @@ -196,17 +238,17 @@ describe('click interactions', function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(autoRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(autoRangeY);

Plotly.relayout(gd, update).then(function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(zoomRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(zoomRangeY);
return Plotly.relayout(gd, update);
}).then(function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(zoomRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(zoomRangeY);

doubleClick(blankPos[0], blankPos[1], function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(autoRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(autoRangeY);
return doubleClick(blankPos[0], blankPos[1]);
}).then(function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(autoRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(autoRangeY);

done();
});
});
done();
});
});

Expand All @@ -217,17 +259,17 @@ describe('click interactions', function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(setRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(setRangeY);

Plotly.relayout(gd, update).then(function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(zoomRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(zoomRangeY);
return Plotly.relayout(gd, update);
}).then(function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(zoomRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(zoomRangeY);

doubleClick(blankPos[0], blankPos[1], function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(setRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(setRangeY);
return doubleClick(blankPos[0], blankPos[1]);
}).then(function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(setRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(setRangeY);

done();
});
});
done();
});
});

Expand All @@ -238,12 +280,12 @@ describe('click interactions', function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(setRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(setRangeY);

doubleClick(blankPos[0], blankPos[1], function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(setRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(setRangeY);
return doubleClick(blankPos[0], blankPos[1]);
}).then(function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(setRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(setRangeY);

done();
});
done();
});
});

Expand All @@ -252,17 +294,17 @@ describe('click interactions', function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(autoRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(autoRangeY);

Plotly.relayout(gd, update).then(function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(zoomRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(zoomRangeY);
return Plotly.relayout(gd, update);
}).then(function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(zoomRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(zoomRangeY);

doubleClick(blankPos[0], blankPos[1], function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(autoRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(autoRangeY);
return doubleClick(blankPos[0], blankPos[1]);
}).then(function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(autoRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(autoRangeY);

done();
});
});
done();
});
});

Expand All @@ -273,17 +315,17 @@ describe('click interactions', function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(setRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(setRangeY);

Plotly.relayout(gd, update).then(function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(zoomRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(zoomRangeY);
return Plotly.relayout(gd, update);
}).then(function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(zoomRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(zoomRangeY);

doubleClick(blankPos[0], blankPos[1], function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(autoRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(autoRangeY);
return doubleClick(blankPos[0], blankPos[1]);
}).then(function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(autoRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(autoRangeY);

done();
});
});
done();
});
});

Expand All @@ -294,12 +336,12 @@ describe('click interactions', function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(setRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(setRangeY);

doubleClick(blankPos[0], blankPos[1], function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(autoRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(autoRangeY);
return doubleClick(blankPos[0], blankPos[1]);
}).then(function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(autoRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(autoRangeY);

done();
});
done();
});
});

Expand Down

0 comments on commit bbb8205

Please sign in to comment.