Skip to content

Selection on choropleth to work even if an invisible trace is present #2099

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 5 commits into from
Oct 18, 2017
Merged
Show file tree
Hide file tree
Changes from 3 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
7 changes: 7 additions & 0 deletions src/plots/cartesian/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ var MINSELECT = constants.MINSELECT;

function getAxId(ax) { return ax._id; }

function visible(searchInfo) {
var cd0 = searchInfo.cd[0];
return cd0 && cd0.trace && cd0.trace.visible === true;
}

module.exports = function prepSelect(e, startX, startY, dragOptions, mode) {
var zoomLayer = dragOptions.gd._fullLayout._zoomlayer,
dragBBox = dragOptions.element.getBoundingClientRect(),
Expand Down Expand Up @@ -190,6 +195,7 @@ module.exports = function prepSelect(e, startX, startY, dragOptions, mode) {
selection = [];
for(i = 0; i < searchTraces.length; i++) {
searchInfo = searchTraces[i];
if(!visible(searchInfo)) continue;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. Does that mean we can 🔪 those visible !== false clauses here, here, here, here and here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great find, indeed these are the only callers, and select check is almost always on the top, except scattermapbox/select/js where it's okay to set the _hasDimmedPts to false anyway:

    trace._hasDimmedPts = false;

    if(!subtypes.hasMarkers(trace)) return [];

Pushing a new commit now

var thisSelection = fillSelectionItem(
searchInfo.selectPoints(searchInfo, poly), searchInfo
);
Expand Down Expand Up @@ -218,6 +224,7 @@ module.exports = function prepSelect(e, startX, startY, dragOptions, mode) {
outlines.remove();
for(i = 0; i < searchTraces.length; i++) {
searchInfo = searchTraces[i];
if(!visible(searchInfo)) continue;
searchInfo.selectPoints(searchInfo, false);
}

Expand Down
6 changes: 6 additions & 0 deletions test/jasmine/tests/select_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,12 @@ describe('Test select box and lasso per trace:', function() {
fig.layout.dragmode = 'select';
fig.layout.geo.scope = 'europe';

// add a trace with no locations which will then make trace invisible, lacking DOM elements
fig.data.push(Lib.extendDeep({}, fig.data[0]));
fig.data[1].text = [];
fig.data[1].locations = [];
fig.data[1].z = [];

Plotly.plot(gd, fig)
.then(function() {
return _run(
Expand Down