Skip to content

Commit 832590b

Browse files
authored
Merge pull request #4188 from plotly/fix-tiny-zoomboxes
Fix tiny zoombox behavior
2 parents 6c2babd + 61b88e9 commit 832590b

File tree

3 files changed

+72
-14
lines changed

3 files changed

+72
-14
lines changed

src/plots/cartesian/dragbox.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -429,14 +429,7 @@ function makeDragBox(gd, plotinfo, x, y, w, h, ns, ew) {
429429
}
430430

431431
function zoomDone() {
432-
// more strict than dragged, which allows you to come back to where you started
433-
// and still count as dragged
434-
if(Math.min(box.h, box.w) < MINDRAG * 2) {
435-
return removeZoombox(gd);
436-
}
437-
438432
computeZoomUpdates();
439-
440433
removeZoombox(gd);
441434
dragTail();
442435
showDoubleClickNotifier(gd);

test/jasmine/tests/cartesian_interact_test.js

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ describe('zoom box element', function() {
6565
});
6666
});
6767

68-
6968
describe('main plot pan', function() {
7069
var gd, modeBar, relayoutCallback;
7170

@@ -893,7 +892,7 @@ describe('axis zoom/pan and main plot zoom', function() {
893892
cnt++;
894893
// called twice as many times on drag:
895894
// - once per axis during mousemouve
896-
// - once per raxis on mouseup
895+
// - once per axis on mouseup
897896
if(opts.dragged) cnt++;
898897
}
899898
});
@@ -1726,7 +1725,7 @@ describe('axis zoom/pan and main plot zoom', function() {
17261725

17271726
Plotly.plot(gd, [{ type: 'heatmap', z: z() }], {dragmode: 'pan'})
17281727
.then(function() {
1729-
// inspired by https://github.com/plotly/plotly.js/issues/2687<Paste>
1728+
// inspired by https://github.com/plotly/plotly.js/issues/2687
17301729
gd.on('plotly_relayout', function(d) {
17311730
relayoutTracker.unshift(d);
17321731
setTimeout(function() {
@@ -1915,6 +1914,66 @@ describe('axis zoom/pan and main plot zoom', function() {
19151914
.then(done);
19161915
});
19171916
});
1917+
1918+
it('zoomboxes during small drag motions', function(done) {
1919+
var MINDRAG = constants.MINDRAG;
1920+
var eventData = {};
1921+
1922+
function _run(msg, dpos, exp) {
1923+
return function() {
1924+
var node = getDragger('xy', 'nsew');
1925+
var fns = drag.makeFns({node: node, pos0: [200, 200], dpos: dpos});
1926+
1927+
return fns.start().then(function() {
1928+
var zl = d3.select(gd).select('g.zoomlayer');
1929+
var d = zl.select('.zoombox-corners').attr('d');
1930+
if(exp === 'nozoom') {
1931+
expect(d).toBe('M0,0Z', 'blank path | ' + msg);
1932+
} else {
1933+
var actual = (d.match(/Z/g) || []).length;
1934+
if(exp === 'x-zoom' || exp === 'y-zoom') {
1935+
expect(actual).toBe(2, 'two corners | ' + msg);
1936+
} else if(exp === 'xy-zoom') {
1937+
expect(actual).toBe(4, 'four corners | ' + msg);
1938+
} else {
1939+
fail('wrong expectation str.');
1940+
}
1941+
}
1942+
})
1943+
.then(fns.end)
1944+
.then(function() {
1945+
var keys = Object.keys(eventData);
1946+
if(exp === 'nozoom') {
1947+
expect(keys.length).toBe(0, 'no event data | ' + msg);
1948+
} else if(exp === 'x-zoom') {
1949+
expect(keys).withContext('relayout xaxis rng | ' + msg)
1950+
.toEqual(['xaxis.range[0]', 'xaxis.range[1]']);
1951+
} else if(exp === 'y-zoom') {
1952+
expect(keys).withContext('relayout yaxis rng | ' + msg)
1953+
.toEqual(['yaxis.range[0]', 'yaxis.range[1]']);
1954+
} else if(exp === 'xy-zoom') {
1955+
expect(keys.length).toBe(4, 'x and y relayout | ' + msg);
1956+
} else {
1957+
fail('wrong expectation str.');
1958+
}
1959+
eventData = {};
1960+
});
1961+
};
1962+
}
1963+
1964+
Plotly.plot(gd, [{y: [1, 2, 1]}], {width: 400, height: 400})
1965+
.then(function() {
1966+
gd.on('plotly_relayout', function(d) { eventData = d; });
1967+
})
1968+
.then(_run('dx < MINDRAG', [MINDRAG - 2, 0], 'nozoom'))
1969+
.then(_run('dx > MINDRAG', [MINDRAG + 2, 0], 'x-zoom'))
1970+
.then(_run('dy < MINDRAG', [0, MINDRAG - 2], 'nozoom'))
1971+
.then(_run('dy > MINDRAG', [0, MINDRAG + 2], 'y-zoom'))
1972+
.then(_run('(dx,dy) < MINDRAG', [MINDRAG - 2, MINDRAG - 2], 'nozoom'))
1973+
.then(_run('(dx,dy) > MINDRAG', [MINDRAG + 2, MINDRAG + 2], 'xy-zoom'))
1974+
.catch(failTest)
1975+
.then(done);
1976+
});
19181977
});
19191978

19201979
describe('Event data:', function() {

test/jasmine/tests/select_test.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -437,17 +437,23 @@ describe('Click-to-select', function() {
437437
assertSelectedPoints([7, 35]);
438438
return _clickPt(mock14Pts[7], { shiftKey: true });
439439
})
440-
.then(function() {
441-
assertSelectedPoints(35);
442-
drag(LASSO_PATH);
443-
})
444440
.then(function() {
445441
assertSelectedPoints(35);
446442
_clickPt(mock14Pts[35], { shiftKey: true });
447443
return deselectPromise;
448444
})
449445
.then(function() {
450446
assertSelectionCleared();
447+
return _clickPt(mock14Pts[7], { shiftKey: true });
448+
})
449+
.then(function() {
450+
assertSelectedPoints(7);
451+
drag([[110, 100], [300, 300]]);
452+
})
453+
.then(delay(100))
454+
.then(function() {
455+
// persist after zoombox
456+
assertSelectedPoints(7);
451457
})
452458
.catch(failTest)
453459
.then(done);

0 commit comments

Comments
 (0)