Skip to content

Commit e1ecd18

Browse files
authored
Merge pull request #2827 from plotly/scattergeo-select-fixups
Scattergeo selection fixups
2 parents 24b2912 + 1783631 commit e1ecd18

File tree

4 files changed

+44
-4
lines changed

4 files changed

+44
-4
lines changed

src/traces/scattergeo/defaults.js

+2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
5252
if(traceOut.fill !== 'none') {
5353
handleFillColorDefaults(traceIn, traceOut, defaultColor, coerce);
5454
}
55+
56+
Lib.coerceSelectionMarkerOpacity(traceOut, coerce);
5557
};
5658

5759
function handleLonLatLocDefaults(traceIn, traceOut, coerce) {

src/traces/scattergeo/select.js

+5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
'use strict';
1010

1111
var subtypes = require('../scatter/subtypes');
12+
var BADNUM = require('../../constants/numerical').BADNUM;
1213

1314
module.exports = function selectPoints(searchInfo, polygon) {
1415
var cd = searchInfo.cd;
@@ -30,6 +31,10 @@ module.exports = function selectPoints(searchInfo, polygon) {
3031
for(i = 0; i < cd.length; i++) {
3132
di = cd[i];
3233
lonlat = di.lonlat;
34+
35+
// some projection types can't handle BADNUMs
36+
if(lonlat[0] === BADNUM) continue;
37+
3338
x = xa.c2p(lonlat);
3439
y = ya.c2p(lonlat);
3540

57 Bytes
Loading

test/jasmine/tests/select_test.js

+37-4
Original file line numberDiff line numberDiff line change
@@ -895,9 +895,9 @@ describe('@flaky Test select box and lasso per trace:', function() {
895895
keys.forEach(function(k, j) {
896896
var msgFull = msg + 'selected pt ' + i + ' - ' + k + ' val';
897897

898-
if(typeof e[j] === 'number') {
898+
if(typeof p[k] === 'number' && typeof e[j] === 'number') {
899899
expect(p[k]).toBeCloseTo(e[j], 1, msgFull);
900-
} else if(Array.isArray(e[j])) {
900+
} else if(Array.isArray(p[k]) && Array.isArray(e[j])) {
901901
expect(p[k]).toBeCloseToArray(e[j], 1, msgFull);
902902
} else {
903903
expect(p[k]).toBe(e[j], msgFull);
@@ -1151,11 +1151,23 @@ describe('@flaky Test select box and lasso per trace:', function() {
11511151
var assertRanges = makeAssertRanges('geo');
11521152
var assertLassoPoints = makeAssertLassoPoints('geo');
11531153

1154+
function assertNodeOpacity(exp) {
1155+
var traces = d3.select(gd).selectAll('.scatterlayer > .trace');
1156+
expect(traces.size()).toBe(Object.keys(exp).length, 'correct # of trace <g>');
1157+
1158+
traces.each(function(_, i) {
1159+
d3.select(this).selectAll('path.point').each(function(_, j) {
1160+
expect(Number(this.style.opacity))
1161+
.toBe(exp[i][j], 'node opacity - trace ' + i + ' pt ' + j);
1162+
});
1163+
});
1164+
}
1165+
11541166
var fig = {
11551167
data: [{
11561168
type: 'scattergeo',
1157-
lon: [10, 20, 30],
1158-
lat: [10, 20, 30]
1169+
lon: [10, 20, 30, null],
1170+
lat: [10, 20, 30, null]
11591171
}, {
11601172
type: 'scattergeo',
11611173
lon: [-10, -20, -30],
@@ -1177,6 +1189,7 @@ describe('@flaky Test select box and lasso per trace:', function() {
11771189
function() {
11781190
assertPoints([[10, 10], [20, 20], [-10, 10], [-20, 20]]);
11791191
assertSelectedPoints({0: [0, 1], 1: [0, 1]});
1192+
assertNodeOpacity({0: [1, 1, 0.2], 1: [1, 1, 0.2]});
11801193
assertRanges([[-28.13, 61.88], [28.13, -50.64]]);
11811194
},
11821195
null, BOXEVENTS, 'scattergeo select'
@@ -1191,13 +1204,33 @@ describe('@flaky Test select box and lasso per trace:', function() {
11911204
function() {
11921205
assertPoints([[-10, 10], [-20, 20], [-30, 30]]);
11931206
assertSelectedPoints({0: [], 1: [0, 1, 2]});
1207+
assertNodeOpacity({0: [0.2, 0.2, 0.2], 1: [1, 1, 1]});
11941208
assertLassoPoints([
11951209
[-56.25, 61.88], [-56.24, 5.63], [0, 5.63], [0, 61.88], [-56.25, 61.88]
11961210
]);
11971211
},
11981212
null, LASSOEVENTS, 'scattergeo lasso'
11991213
);
12001214
})
1215+
.then(function() {
1216+
// some projection types can't handle BADNUM during c2p,
1217+
// make they are skipped here
1218+
return Plotly.relayout(gd, 'geo.projection.type', 'robinson');
1219+
})
1220+
.then(function() {
1221+
return _run(
1222+
[[300, 200], [300, 300], [400, 300], [400, 200], [300, 200]],
1223+
function() {
1224+
assertPoints([[-10, 10], [-20, 20], [-30, 30]]);
1225+
assertSelectedPoints({0: [], 1: [0, 1, 2]});
1226+
assertNodeOpacity({0: [0.2, 0.2, 0.2], 1: [1, 1, 1]});
1227+
assertLassoPoints([
1228+
[-67.40, 55.07], [-56.33, 4.968], [0, 4.968], [0, 55.07], [-67.40, 55.07]
1229+
]);
1230+
},
1231+
null, LASSOEVENTS, 'scattergeo lasso (on robinson projection)'
1232+
);
1233+
})
12011234
.then(function() {
12021235
// make sure selection handlers don't get called in 'pan' dragmode
12031236
return Plotly.relayout(gd, 'dragmode', 'pan');

0 commit comments

Comments
 (0)