Skip to content

Commit 3c327e6

Browse files
committed
add scattergeo lasso/select
- with test support.
1 parent dcbd8e9 commit 3c327e6

File tree

3 files changed

+115
-1
lines changed

3 files changed

+115
-1
lines changed

src/traces/scattergeo/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@ ScatterGeo.calc = require('./calc');
1818
ScatterGeo.plot = require('./plot');
1919
ScatterGeo.hoverPoints = require('./hover');
2020
ScatterGeo.eventData = require('./event_data');
21+
ScatterGeo.selectPoints = require('./select');
2122

2223
ScatterGeo.moduleType = 'trace';
2324
ScatterGeo.name = 'scattergeo';
2425
ScatterGeo.basePlotModule = require('../../plots/geo');
25-
ScatterGeo.categories = ['geo', 'symbols', 'markerColorscale', 'showLegend'];
26+
ScatterGeo.categories = ['geo', 'symbols', 'markerColorscale', 'showLegend', 'scatter-like'];
2627
ScatterGeo.meta = {
2728
hrName: 'scatter_geo',
2829
description: [

src/traces/scattergeo/select.js

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/**
2+
* Copyright 2012-2017, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
'use strict';
10+
11+
var subtypes = require('../scatter/subtypes');
12+
var DESELECTDIM = require('../../constants/interactions').DESELECTDIM;
13+
14+
module.exports = function selectPoints(searchInfo, polygon) {
15+
var cd = searchInfo.cd;
16+
var xa = searchInfo.xaxis;
17+
var ya = searchInfo.yaxis;
18+
var selection = [];
19+
var trace = cd[0].trace;
20+
var node3 = cd[0].node3;
21+
22+
var di, lonlat, x, y, i;
23+
24+
var hasOnlyLines = (!subtypes.hasMarkers(trace) && !subtypes.hasText(trace));
25+
if(trace.visible !== true || hasOnlyLines) return;
26+
27+
var marker = trace.marker;
28+
var opacity = Array.isArray(marker.opacity) ? 1 : marker.opacity;
29+
30+
if(polygon === false) {
31+
for(i = 0; i < cd.length; i++) {
32+
cd[i].dim = 0;
33+
}
34+
} else {
35+
for(i = 0; i < cd.length; i++) {
36+
di = cd[i];
37+
lonlat = di.lonlat;
38+
x = xa.c2p(lonlat);
39+
y = ya.c2p(lonlat);
40+
41+
if(polygon.contains([x, y])) {
42+
selection.push({
43+
pointNumber: i,
44+
lon: lonlat[0],
45+
lat: lonlat[1]
46+
});
47+
di.dim = 0;
48+
} else {
49+
di.dim = 1;
50+
}
51+
}
52+
}
53+
54+
node3.selectAll('path.point').style('opacity', function(d) {
55+
return ((d.mo + 1 || opacity + 1) - 1) * (d.dim ? DESELECTDIM : 1);
56+
});
57+
58+
node3.selectAll('text').style('opacity', function(d) {
59+
return d.dim ? DESELECTDIM : 1;
60+
});
61+
62+
return selection;
63+
};

test/jasmine/tests/select_test.js

+50
Original file line numberDiff line numberDiff line change
@@ -653,4 +653,54 @@ describe('Test select box and lasso per trace:', function() {
653653
.catch(fail)
654654
.then(done);
655655
}, LONG_TIMEOUT_INTERVAL);
656+
657+
it('should work on scattergeo traces', function(done) {
658+
gd = createGraphDiv();
659+
660+
var assertPoints = makeAssertPoints(['lon', 'lat']);
661+
var assertRanges = makeAssertRanges('geo');
662+
var assertLassoPoints = makeAssertLassoPoints('geo');
663+
664+
Plotly.plot(gd, [{
665+
type: 'scattergeo',
666+
lon: [10, 20, 30],
667+
lat: [10, 20, 30]
668+
}, {
669+
type: 'scattergeo',
670+
lon: [-10, -20, -30],
671+
lat: [10, 20, 30]
672+
}], {
673+
showlegend: false,
674+
dragmode: 'select',
675+
width: 800,
676+
height: 600
677+
})
678+
.then(function() {
679+
return _run([[350, 200], [450, 400]], function() {
680+
assertPoints([[10, 10], [20, 20], [-10, 10], [-20, 20]]);
681+
assertRanges([[-28.13, 61.88], [28.13, -50.64]]);
682+
});
683+
})
684+
.then(function() {
685+
return Plotly.relayout(gd, 'dragmode', 'lasso');
686+
})
687+
.then(function() {
688+
return _run([[300, 200], [300, 300], [400, 300], [400, 200], [300, 200]], function() {
689+
assertPoints([[-10, 10], [-20, 20], [-30, 30]]);
690+
assertLassoPoints([
691+
[-56.25, 61.88], [-56.24, 5.63], [0, 5.63], [0, 61.88], [-56.25, 61.88]
692+
]);
693+
});
694+
})
695+
.then(function() {
696+
// make selection handlers don't get called in 'pan' dragmode
697+
return Plotly.relayout(gd, 'dragmode', 'pan');
698+
})
699+
.then(function() {
700+
return _runNoSelect([[370, 120], [500, 200]]);
701+
})
702+
.catch(fail)
703+
.then(done);
704+
}, LONG_TIMEOUT_INTERVAL);
705+
656706
});

0 commit comments

Comments
 (0)