Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reset updates object on every zoomDone #3028

Merged
merged 1 commit into from
Sep 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/plots/cartesian/dragbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ function makeDragBox(gd, plotinfo, x, y, w, h, ns, ew) {
var editX, editY;
// graph-wide optimization flags
var hasScatterGl, hasOnlyLargeSploms, hasSplom, hasSVG;
// collected changes to be made to the plot by relayout at the end
var updates;

function recomputeAxisLists() {
xa0 = plotinfo.xaxis;
Expand Down Expand Up @@ -291,9 +293,6 @@ function makeDragBox(gd, plotinfo, x, y, w, h, ns, ew) {
// zoom takes over minDrag, so it also has to take over gd._dragged
var zoomDragged;

// collected changes to be made to the plot by relayout at the end
var updates = {};

function zoomPrep(e, startX, startY) {
var dragBBox = dragger.getBoundingClientRect();
x0 = startX - dragBBox.left;
Expand Down Expand Up @@ -386,6 +385,8 @@ function makeDragBox(gd, plotinfo, x, y, w, h, ns, ew) {
}

function zoomDone() {
updates = {};
Copy link
Contributor Author

@etpinard etpinard Sep 19, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that the same updates object is also "reset" in

// Draw ticks and annotations (and other components) when ranges change.
// Also records the ranges that have changed for use by update at the end.
function ticksAndAnnotations(ns, ew) {
var activeAxIds = [],
i;
function pushActiveAxIds(axList) {
for(i = 0; i < axList.length; i++) {
if(!axList[i].fixedrange) activeAxIds.push(axList[i]._id);
}
}
if(editX) {
pushActiveAxIds(xaxes);
pushActiveAxIds(links.xaxes);
}
if(editY) {
pushActiveAxIds(yaxes);
pushActiveAxIds(links.yaxes);
}
updates = {};
for(i = 0; i < activeAxIds.length; i++) {
var axId = activeAxIds[i];
doTicksSingle(gd, axId, true);
var ax = getFromId(gd, axId);
updates[ax._name + '.range[0]'] = ax.range[0];
updates[ax._name + '.range[1]'] = ax.range[1];
}
function redrawObjs(objArray, method, shortCircuit) {
for(i = 0; i < objArray.length; i++) {
var obji = objArray[i];
if((ew && activeAxIds.indexOf(obji.xref) !== -1) ||
(ns && activeAxIds.indexOf(obji.yref) !== -1)) {
method(gd, i);
// once is enough for images (which doesn't use the `i` arg anyway)
if(shortCircuit) return;
}
}
}
// annotations and shapes 'draw' method is slow,
// use the finer-grained 'drawOne' method instead
redrawObjs(gd._fullLayout.annotations || [], Registry.getComponentMethod('annotations', 'drawOne'));
redrawObjs(gd._fullLayout.shapes || [], Registry.getComponentMethod('shapes', 'drawOne'));
redrawObjs(gd._fullLayout.images || [], Registry.getComponentMethod('images', 'draw'), true);
}

which is called on pan and scroll.


// more strict than dragged, which allows you to come back to where you started
// and still count as dragged
if(Math.min(box.h, box.w) < MINDRAG * 2) {
Expand Down Expand Up @@ -936,6 +937,7 @@ function zoomAxRanges(axList, r0Fraction, r1Fraction, updates, linkedAxes) {
axi.l2r(axRangeLinear0 + axRangeLinearSpan * r0Fraction),
axi.l2r(axRangeLinear0 + axRangeLinearSpan * r1Fraction)
];

updates[axi._name + '.range[0]'] = axi.range[0];
updates[axi._name + '.range[1]'] = axi.range[1];
}
Expand Down
19 changes: 19 additions & 0 deletions test/jasmine/tests/cartesian_interact_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,25 @@ describe('axis zoom/pan and main plot zoom', function() {
.catch(failTest)
.then(done);
});

it('handles xy, x-only and y-only zoombox updates', function(done) {
function _assert(msg, xrng, yrng) {
expect(gd.layout.xaxis.range).toBeCloseToArray(xrng, 2, 'xrng - ' + msg);
expect(gd.layout.yaxis.range).toBeCloseToArray(yrng, 2, 'yrng - ' + msg);
}

Plotly.plot(gd, [{ y: [1, 2, 1] }])
.then(doDrag('xy', 'nsew', 50, 50))
.then(function() { _assert('after xy drag', [1, 1.208], [1.287, 1.5]); })
.then(doDblClick('xy', 'nsew'))
.then(doDrag('xy', 'nsew', 50, 0))
.then(function() { _assert('after x-only drag', [1, 1.208], [0.926, 2.073]); })
.then(doDblClick('xy', 'nsew'))
.then(doDrag('xy', 'nsew', 0, 50))
.then(function() { _assert('after y-only drag', [-0.128, 2.128], [1.287, 1.5]); })
.catch(failTest)
.then(done);
});
});

describe('Event data:', function() {
Expand Down