Skip to content

Scattergeo selection fixups #2827

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/traces/scattergeo/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
if(traceOut.fill !== 'none') {
handleFillColorDefaults(traceIn, traceOut, defaultColor, coerce);
}

Lib.coerceSelectionMarkerOpacity(traceOut, coerce);
};

function handleLonLatLocDefaults(traceIn, traceOut, coerce) {
Expand Down
5 changes: 5 additions & 0 deletions src/traces/scattergeo/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
'use strict';

var subtypes = require('../scatter/subtypes');
var BADNUM = require('../../constants/numerical').BADNUM;

module.exports = function selectPoints(searchInfo, polygon) {
var cd = searchInfo.cd;
Expand All @@ -30,6 +31,10 @@ module.exports = function selectPoints(searchInfo, polygon) {
for(i = 0; i < cd.length; i++) {
di = cd[i];
lonlat = di.lonlat;

// some projection types can't handle BADNUMs
if(lonlat[0] === BADNUM) continue;

x = xa.c2p(lonlat);
y = ya.c2p(lonlat);

Expand Down
Binary file modified test/image/baselines/geo_point-selection.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 37 additions & 4 deletions test/jasmine/tests/select_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -895,9 +895,9 @@ describe('@flaky Test select box and lasso per trace:', function() {
keys.forEach(function(k, j) {
var msgFull = msg + 'selected pt ' + i + ' - ' + k + ' val';

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

function assertNodeOpacity(exp) {
var traces = d3.select(gd).selectAll('.scatterlayer > .trace');
expect(traces.size()).toBe(Object.keys(exp).length, 'correct # of trace <g>');

traces.each(function(_, i) {
d3.select(this).selectAll('path.point').each(function(_, j) {
expect(Number(this.style.opacity))
.toBe(exp[i][j], 'node opacity - trace ' + i + ' pt ' + j);
});
});
}

var fig = {
data: [{
type: 'scattergeo',
lon: [10, 20, 30],
lat: [10, 20, 30]
lon: [10, 20, 30, null],
lat: [10, 20, 30, null]
}, {
type: 'scattergeo',
lon: [-10, -20, -30],
Expand All @@ -1177,6 +1189,7 @@ describe('@flaky Test select box and lasso per trace:', function() {
function() {
assertPoints([[10, 10], [20, 20], [-10, 10], [-20, 20]]);
assertSelectedPoints({0: [0, 1], 1: [0, 1]});
assertNodeOpacity({0: [1, 1, 0.2], 1: [1, 1, 0.2]});
assertRanges([[-28.13, 61.88], [28.13, -50.64]]);
},
null, BOXEVENTS, 'scattergeo select'
Expand All @@ -1191,13 +1204,33 @@ describe('@flaky Test select box and lasso per trace:', function() {
function() {
assertPoints([[-10, 10], [-20, 20], [-30, 30]]);
assertSelectedPoints({0: [], 1: [0, 1, 2]});
assertNodeOpacity({0: [0.2, 0.2, 0.2], 1: [1, 1, 1]});
assertLassoPoints([
[-56.25, 61.88], [-56.24, 5.63], [0, 5.63], [0, 61.88], [-56.25, 61.88]
]);
},
null, LASSOEVENTS, 'scattergeo lasso'
);
})
.then(function() {
// some projection types can't handle BADNUM during c2p,
// make they are skipped here
return Plotly.relayout(gd, 'geo.projection.type', 'robinson');
})
.then(function() {
return _run(
[[300, 200], [300, 300], [400, 300], [400, 200], [300, 200]],
function() {
assertPoints([[-10, 10], [-20, 20], [-30, 30]]);
assertSelectedPoints({0: [], 1: [0, 1, 2]});
assertNodeOpacity({0: [0.2, 0.2, 0.2], 1: [1, 1, 1]});
assertLassoPoints([
[-67.40, 55.07], [-56.33, 4.968], [0, 4.968], [0, 55.07], [-67.40, 55.07]
]);
},
null, LASSOEVENTS, 'scattergeo lasso (on robinson projection)'
);
})
.then(function() {
// make sure selection handlers don't get called in 'pan' dragmode
return Plotly.relayout(gd, 'dragmode', 'pan');
Expand Down