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

Fix tiny zoombox behavior #4188

Merged
merged 3 commits into from
Sep 13, 2019
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
7 changes: 0 additions & 7 deletions src/plots/cartesian/dragbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -429,14 +429,7 @@ function makeDragBox(gd, plotinfo, x, y, w, h, ns, ew) {
}

function zoomDone() {
// 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) {
return removeZoombox(gd);
}

computeZoomUpdates();

removeZoombox(gd);
dragTail();
showDoubleClickNotifier(gd);
Expand Down
65 changes: 62 additions & 3 deletions test/jasmine/tests/cartesian_interact_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ describe('zoom box element', function() {
});
});


describe('main plot pan', function() {
var gd, modeBar, relayoutCallback;

Expand Down Expand Up @@ -893,7 +892,7 @@ describe('axis zoom/pan and main plot zoom', function() {
cnt++;
// called twice as many times on drag:
// - once per axis during mousemouve
// - once per raxis on mouseup
// - once per axis on mouseup
if(opts.dragged) cnt++;
}
});
Expand Down Expand Up @@ -1726,7 +1725,7 @@ describe('axis zoom/pan and main plot zoom', function() {

Plotly.plot(gd, [{ type: 'heatmap', z: z() }], {dragmode: 'pan'})
.then(function() {
// inspired by https://github.com/plotly/plotly.js/issues/2687<Paste>
// inspired by https://github.com/plotly/plotly.js/issues/2687
gd.on('plotly_relayout', function(d) {
relayoutTracker.unshift(d);
setTimeout(function() {
Expand Down Expand Up @@ -1915,6 +1914,66 @@ describe('axis zoom/pan and main plot zoom', function() {
.then(done);
});
});

it('zoomboxes during small drag motions', function(done) {
var MINDRAG = constants.MINDRAG;
var eventData = {};

function _run(msg, dpos, exp) {
return function() {
var node = getDragger('xy', 'nsew');
var fns = drag.makeFns({node: node, pos0: [200, 200], dpos: dpos});

return fns.start().then(function() {
var zl = d3.select(gd).select('g.zoomlayer');
var d = zl.select('.zoombox-corners').attr('d');
if(exp === 'nozoom') {
expect(d).toBe('M0,0Z', 'blank path | ' + msg);
} else {
var actual = (d.match(/Z/g) || []).length;
if(exp === 'x-zoom' || exp === 'y-zoom') {
expect(actual).toBe(2, 'two corners | ' + msg);
} else if(exp === 'xy-zoom') {
expect(actual).toBe(4, 'four corners | ' + msg);
} else {
fail('wrong expectation str.');
}
}
})
.then(fns.end)
.then(function() {
var keys = Object.keys(eventData);
if(exp === 'nozoom') {
expect(keys.length).toBe(0, 'no event data | ' + msg);
} else if(exp === 'x-zoom') {
expect(keys).withContext('relayout xaxis rng | ' + msg)
.toEqual(['xaxis.range[0]', 'xaxis.range[1]']);
} else if(exp === 'y-zoom') {
expect(keys).withContext('relayout yaxis rng | ' + msg)
.toEqual(['yaxis.range[0]', 'yaxis.range[1]']);
} else if(exp === 'xy-zoom') {
expect(keys.length).toBe(4, 'x and y relayout | ' + msg);
} else {
fail('wrong expectation str.');
}
eventData = {};
});
};
}

Plotly.plot(gd, [{y: [1, 2, 1]}], {width: 400, height: 400})
.then(function() {
gd.on('plotly_relayout', function(d) { eventData = d; });
})
.then(_run('dx < MINDRAG', [MINDRAG - 2, 0], 'nozoom'))
.then(_run('dx > MINDRAG', [MINDRAG + 2, 0], 'x-zoom'))
.then(_run('dy < MINDRAG', [0, MINDRAG - 2], 'nozoom'))
.then(_run('dy > MINDRAG', [0, MINDRAG + 2], 'y-zoom'))
.then(_run('(dx,dy) < MINDRAG', [MINDRAG - 2, MINDRAG - 2], 'nozoom'))
.then(_run('(dx,dy) > MINDRAG', [MINDRAG + 2, MINDRAG + 2], 'xy-zoom'))
.catch(failTest)
.then(done);
});
});

describe('Event data:', function() {
Expand Down
14 changes: 10 additions & 4 deletions test/jasmine/tests/select_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -437,17 +437,23 @@ describe('Click-to-select', function() {
assertSelectedPoints([7, 35]);
return _clickPt(mock14Pts[7], { shiftKey: true });
})
.then(function() {
assertSelectedPoints(35);
drag(LASSO_PATH);
})
.then(function() {
assertSelectedPoints(35);
_clickPt(mock14Pts[35], { shiftKey: true });
return deselectPromise;
})
.then(function() {
assertSelectionCleared();
return _clickPt(mock14Pts[7], { shiftKey: true });
})
.then(function() {
assertSelectedPoints(7);
drag([[110, 100], [300, 300]]);
})
.then(delay(100))
.then(function() {
// persist after zoombox
assertSelectedPoints(7);
})
.catch(failTest)
.then(done);
Expand Down