From 53adbd33c3196a357c4e72ddbb5e16b02ee9c78b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= Date: Wed, 15 May 2019 16:02:28 -0400 Subject: [PATCH 1/2] add tests for select/lasso range data on non-linear axes --- test/jasmine/tests/select_test.js | 84 +++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/test/jasmine/tests/select_test.js b/test/jasmine/tests/select_test.js index 3710b979cd6..e77fef81367 100644 --- a/test/jasmine/tests/select_test.js +++ b/test/jasmine/tests/select_test.js @@ -1228,6 +1228,90 @@ describe('Test select box and lasso in general:', function() { .then(done); }); + describe('should return correct range data on dragmode *select*', function() { + var specs = [{ + axType: 'linear', + rng: [-0.6208, 0.8375] + }, { + axType: 'log', + rng: [0.2394, 6.8785] + }, { + axType: 'date', + rng: ['2000-01-20 19:48', '2000-04-06 01:48'] + }, { + axType: 'category', + rng: [undefined, undefined] + }, { + axType: 'multicategory', + rng: [undefined, undefined] + }] + + specs.forEach(function(s) { + it('- @flaky on ' + s.axType + ' axes', function(done) { + var gd = createGraphDiv(); + + Plotly.plot(gd, [], { + xaxis: {type: s.axType}, + dragmode: 'select', + width: 400, + height: 400 + }) + .then(function() { + resetEvents(gd); + drag(selectPath); + return selectedPromise; + }) + .then(function() { + expect(selectedData.range.x).toBeCloseToArray(s.rng, 2); + }) + .catch(failTest) + .then(done); + }); + }); + }); + + describe('should return correct range data on dragmode *lasso*', function() { + var specs = [{ + axType: 'linear', + pts: [5.883, 5.941, 6, 6] + }, { + axType: 'log', + pts: [764422.2742, 874312.4580, 1000000, 1000000] + }, { + axType: 'date', + pts: ['2000-12-25 21:36', '2000-12-28 22:48', '2001-01-01', '2001-01-01'] + }, { + axType: 'category', + pts: [undefined, undefined, undefined, undefined] + }, { + axType: 'multicategory', + pts: [undefined, undefined, undefined, undefined] + }] + + specs.forEach(function(s) { + it('- @flaky on ' + s.axType + ' axes', function(done) { + var gd = createGraphDiv(); + + Plotly.plot(gd, [], { + xaxis: {type: s.axType}, + dragmode: 'lasso', + width: 400, + height: 400 + }) + .then(function() { + resetEvents(gd); + drag(lassoPath); + return selectedPromise; + }) + .then(function() { + expect(selectedData.lassoPoints.x).toBeCloseToArray(s.pts, 2); + }) + .catch(failTest) + .then(done); + }); + }); + }); + it('@flaky should have their selection outlines cleared during *axrange* relayout calls', function(done) { var gd = createGraphDiv(); var fig = Lib.extendDeep({}, mock); From ddb560b6538502ff1709d9432fe8e9e7186e0cbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= Date: Wed, 15 May 2019 16:13:59 -0400 Subject: [PATCH 2/2] use p2r to show convert selection range evt data ... and p2d for log axes (until v2 !) --- src/plots/cartesian/select.js | 12 +++++++++--- test/jasmine/tests/select_test.js | 12 ++++++------ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/plots/cartesian/select.js b/src/plots/cartesian/select.js index 5eee4416ef3..ea704fad597 100644 --- a/src/plots/cartesian/select.js +++ b/src/plots/cartesian/select.js @@ -85,9 +85,15 @@ function prepSelect(e, startX, startY, dragOptions, mode) { var searchTraces = determineSearchTraces(gd, dragOptions.xaxes, dragOptions.yaxes, dragOptions.subplot); + // in v2 (once log ranges are fixed), + // we'll be able to p2r here for all axis types + function p2r(ax, v) { + return ax.type === 'log' ? ax.p2d(v) : ax.p2r(v); + } + function axValue(ax) { var index = (ax._id.charAt(0) === 'y') ? 1 : 0; - return function(v) { return ax.p2d(v[index]); }; + return function(v) { return p2r(ax, v[index]); }; } function ascending(a, b) { return a - b; } @@ -107,8 +113,8 @@ function prepSelect(e, startX, startY, dragOptions, mode) { var axLetter = ax._id.charAt(0); ranges[ax._id] = [ - ax.p2d(poly[axLetter + 'min']), - ax.p2d(poly[axLetter + 'max']) + p2r(ax, poly[axLetter + 'min']), + p2r(ax, poly[axLetter + 'max']) ].sort(ascending); } }; diff --git a/test/jasmine/tests/select_test.js b/test/jasmine/tests/select_test.js index e77fef81367..cc2b8f34149 100644 --- a/test/jasmine/tests/select_test.js +++ b/test/jasmine/tests/select_test.js @@ -1240,11 +1240,11 @@ describe('Test select box and lasso in general:', function() { rng: ['2000-01-20 19:48', '2000-04-06 01:48'] }, { axType: 'category', - rng: [undefined, undefined] + rng: [-0.6208, 0.8375] }, { axType: 'multicategory', - rng: [undefined, undefined] - }] + rng: [-0.6208, 0.8375] + }]; specs.forEach(function(s) { it('- @flaky on ' + s.axType + ' axes', function(done) { @@ -1282,11 +1282,11 @@ describe('Test select box and lasso in general:', function() { pts: ['2000-12-25 21:36', '2000-12-28 22:48', '2001-01-01', '2001-01-01'] }, { axType: 'category', - pts: [undefined, undefined, undefined, undefined] + pts: [5.8833, 5.9416, 6, 6] }, { axType: 'multicategory', - pts: [undefined, undefined, undefined, undefined] - }] + pts: [5.8833, 5.9416, 6, 6] + }]; specs.forEach(function(s) { it('- @flaky on ' + s.axType + ' axes', function(done) {