Skip to content

Commit 8901528

Browse files
committed
report coords in input-data space in pt event data
1 parent 9e69900 commit 8901528

File tree

5 files changed

+74
-15
lines changed

5 files changed

+74
-15
lines changed

src/traces/bar/select.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ var DESELECTDIM = require('../../constants/interactions').DESELECTDIM;
1212

1313
module.exports = function selectPoints(searchInfo, polygon) {
1414
var cd = searchInfo.cd;
15+
var xa = searchInfo.xaxis;
16+
var ya = searchInfo.yaxis;
1517
var selection = [];
1618
var trace = cd[0].trace;
1719
var node3 = cd[0].node3;
@@ -31,8 +33,8 @@ module.exports = function selectPoints(searchInfo, polygon) {
3133
if(polygon.contains(di.ct)) {
3234
selection.push({
3335
pointNumber: i,
34-
x: di.x,
35-
y: di.y
36+
x: xa.c2d(di.x),
37+
y: ya.c2d(di.y)
3638
});
3739
di.dim = 0;
3840
} else {

src/traces/box/select.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ module.exports = function selectPoints(searchInfo, polygon) {
3838
if(polygon.contains([x, y])) {
3939
selection.push({
4040
pointNumber: pt.i,
41-
x: pt.x,
42-
y: pt.y
41+
x: xa.c2d(pt.x),
42+
y: ya.c2d(pt.y)
4343
});
4444
pt.dim = 0;
4545
} else {

src/traces/scatter/select.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ module.exports = function selectPoints(searchInfo, polygon) {
4242
if(polygon.contains([x, y])) {
4343
selection.push({
4444
pointNumber: i,
45-
x: di.x,
46-
y: di.y
45+
x: xa.c2d(di.x),
46+
y: ya.c2d(di.y)
4747
});
4848
di.dim = 0;
4949
}

src/traces/scattergl/select.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ module.exports = function selectPoints(searchInfo, polygon) {
4141
if(polygon.contains([x, y])) {
4242
selection.push({
4343
pointNumber: i,
44-
x: di.x,
45-
y: di.y
44+
x: xa.c2d(di.x),
45+
y: ya.c2d(di.y)
4646
});
4747
di.dim = 0;
4848
}

test/jasmine/tests/select_test.js

+64-7
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,63 @@ describe('Test select box and lasso per trace:', function() {
809809
.then(done);
810810
});
811811

812+
it('should work for date/category traces', function(done) {
813+
var assertPoints = makeAssertPoints(['curveNumber', 'x', 'y']);
814+
815+
var fig = {
816+
data: [{
817+
x: ['2017-01-01', '2017-02-01', '2017-03-01'],
818+
y: ['a', 'b', 'c']
819+
}, {
820+
type: 'bar',
821+
x: ['2017-01-01', '2017-02-02', '2017-03-01'],
822+
y: ['a', 'b', 'c']
823+
}],
824+
layout: {
825+
dragmode: 'lasso',
826+
width: 400,
827+
height: 400
828+
}
829+
};
830+
addInvisible(fig);
831+
832+
var x0 = 100;
833+
var y0 = 100;
834+
var x1 = 250;
835+
var y1 = 250;
836+
837+
Plotly.plot(gd, fig)
838+
.then(function() {
839+
return _run(
840+
[[x0, y0], [x1, y0], [x1, y1], [x0, y1], [x0, y0]],
841+
function() {
842+
assertPoints([
843+
[0, '2017-02-01', 'b'],
844+
[1, '2017-02-02', 'b']
845+
]);
846+
},
847+
null, LASSOEVENTS, 'date/category lasso'
848+
);
849+
})
850+
.then(function() {
851+
return Plotly.relayout(gd, 'dragmode', 'select');
852+
})
853+
.then(function() {
854+
return _run(
855+
[[x0, y0], [x1, y1]],
856+
function() {
857+
assertPoints([
858+
[0, '2017-02-01', 'b'],
859+
[1, '2017-02-02', 'b']
860+
]);
861+
},
862+
null, BOXEVENTS, 'date/category select'
863+
);
864+
})
865+
.catch(fail)
866+
.then(done);
867+
});
868+
812869
it('should work for histogram traces', function(done) {
813870
var assertPoints = makeAssertPoints(['curveNumber', 'x', 'y']);
814871
var assertRanges = makeAssertRanges();
@@ -856,7 +913,7 @@ describe('Test select box and lasso per trace:', function() {
856913
});
857914

858915
it('should work for box traces', function(done) {
859-
var assertPoints = makeAssertPoints(['curveNumber', 'y']);
916+
var assertPoints = makeAssertPoints(['curveNumber', 'y', 'x']);
860917
var assertRanges = makeAssertRanges();
861918
var assertLassoPoints = makeAssertLassoPoints();
862919

@@ -875,9 +932,9 @@ describe('Test select box and lasso per trace:', function() {
875932
[[200, 200], [400, 200], [400, 350], [200, 350], [200, 200]],
876933
function() {
877934
assertPoints([
878-
[0, 0.2], [0, 0.3], [0, 0.5], [0, 0.7],
879-
[1, 0.2], [1, 0.5], [1, 0.7], [1, 0.7],
880-
[2, 0.3], [2, 0.6], [2, 0.6]
935+
[0, 0.2, 'day 2'], [0, 0.3, 'day 2'], [0, 0.5, 'day 2'], [0, 0.7, 'day 2'],
936+
[1, 0.2, 'day 2'], [1, 0.5, 'day 2'], [1, 0.7, 'day 2'], [1, 0.7, 'day 2'],
937+
[2, 0.3, 'day 1'], [2, 0.6, 'day 1'], [2, 0.6, 'day 1']
881938
]);
882939
assertLassoPoints([
883940
['day 1', 'day 2', 'day 2', 'day 1', 'day 1'],
@@ -895,9 +952,9 @@ describe('Test select box and lasso per trace:', function() {
895952
[[200, 200], [400, 350]],
896953
function() {
897954
assertPoints([
898-
[0, 0.2], [0, 0.3], [0, 0.5], [0, 0.7],
899-
[1, 0.2], [1, 0.5], [1, 0.7], [1, 0.7],
900-
[2, 0.3], [2, 0.6], [2, 0.6]
955+
[0, 0.2, 'day 2'], [0, 0.3, 'day 2'], [0, 0.5, 'day 2'], [0, 0.7, 'day 2'],
956+
[1, 0.2, 'day 2'], [1, 0.5, 'day 2'], [1, 0.7, 'day 2'], [1, 0.7, 'day 2'],
957+
[2, 0.3, 'day 1'], [2, 0.6, 'day 1'], [2, 0.6, 'day 1']
901958
]);
902959
assertRanges([['day 1', 'day 2'], [0.1875, 0.71]]);
903960
},

0 commit comments

Comments
 (0)