Skip to content
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

Add multiselect #2140

Merged
merged 9 commits into from
Nov 13, 2017
Merged

Add multiselect #2140

merged 9 commits into from
Nov 13, 2017

Conversation

dy
Copy link
Contributor

@dy dy commented Nov 2, 2017

Reproduces #1853

@etpinard
Copy link
Contributor

etpinard commented Nov 2, 2017

Yep, npm run test-jasmine -- --bundleTest=ie9_test.js correctly fails as poly-bool has a few Unit8Array calls:

image

Now, I don't think multi-selections in IE9 is a must. Maybe there's a way to make poly-bool not invoke Unit8Array on load?

@dy
Copy link
Contributor Author

dy commented Nov 2, 2017

@etpinard turns out poly-bool is a huge dependency with redundancy. Replaced it with polybooljs - faster and smaller alternative

dragOptions.polygons.push(currentPolygon);

// we have to keep reference to arrays, therefore just replace items
dragOptions.mergedPolygons.splice.apply(dragOptions.mergedPolygons, [0, dragOptions.mergedPolygons.length].concat(mergedPolygons));
Copy link
Contributor

Choose a reason for hiding this comment

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

What does this do? Could we just use a plain-old for-loop?

var modes = ['lasso', 'select'];

return modes.indexOf(dragmode) !== -1;
return dragmode === 'lasso' || dragmode === 'select';
Copy link
Contributor

Choose a reason for hiding this comment

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

Way better 🐎 . Thanks!

});
};
};

function joinPolygons(list, poly) {
Copy link
Contributor

@etpinard etpinard Nov 3, 2017

Choose a reason for hiding this comment

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

Joining the polygons sounds very reasonable to me. But, some users might expect that selections within selections would remove the inner polygons. Perhaps we'll need to add layout options (e.g. layout.multiselectionmode: 'join' | 'cut').

Any thoughts about this @alexcjohnson @chriddyp @cldougl @monfera ?

Copy link
Member

@cldougl cldougl Nov 3, 2017

Choose a reason for hiding this comment

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

so 'join' mode would always add regions to the selection (and do nothing if a selected region is selected a second time) and 'cut' mode would always remove regions from the selection (and do nothing if the region was not previously selected)?

Copy link
Member

Choose a reason for hiding this comment

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

+1 for a cut mode (after seeing the join in action)

Copy link
Collaborator

Choose a reason for hiding this comment

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

My gut reaction: if you start a new selection inside an existing one, it's purely subtractive, if you start outside the existing ones it's purely additive. Would have to play with it implemented to see if this really feels intuitive though...

Copy link
Contributor Author

@dy dy Nov 3, 2017

Choose a reason for hiding this comment

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

Ok, added subtract selection by holding Alt in e8c18f0

Copy link
Contributor

Choose a reason for hiding this comment

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

My gut reaction: if you start a new selection inside an existing one, it's purely subtractive, if you start outside the existing ones it's purely additive.

+1

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok, added subtract selection by holding Alt in e8c18f0

That is more powerful (as well as easier to code 😅 ), my only concern is whether people will be able to find it. Though I guess if they can find add they can find subtract...

(and I never saw <kbd> before, nice! 🎉 )

Copy link
Contributor

@etpinard etpinard Nov 3, 2017

Choose a reason for hiding this comment

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

Nice solution @dfcreative . The only (potential) problem I can think of is mobile and tablets users complaining no having access to Shift and Alt keys and by consequent multi-selections.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@etpinard good point, we can use @alexcjohnson strategy for that. But I'd wait for persistent selections PR merged first

@chriddyp
Copy link
Member

chriddyp commented Nov 3, 2017

This is so awesome.
multiple-selections

@etpinard
Copy link
Contributor

etpinard commented Nov 3, 2017

But I'd wait for persistent selections PR merged first

Sounds good @dfcreative Looks like everyone is happy with e8c18f0 🎉

Now, would you mind adding a few test cases in https://github.com/plotly/plotly.js/blob/master/test/jasmine/tests/select_test.js to 🔒 down the behavior?

@etpinard etpinard added this to the v1.32.0 milestone Nov 3, 2017
Copy link
Contributor

@etpinard etpinard left a comment

Choose a reason for hiding this comment

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

@dfcreative thanks for adding those test cases! This PR is looking great.

I made a few comments, the most important being the moving most of the new cartesian/dragbox.js logic to cartesian/select.js so that all subplot types can support multi-select.

@@ -168,13 +171,31 @@ module.exports = function dragBox(gd, plotinfo, x, y, w, h, ns, ew) {
else if(isSelectOrLasso(dragModeNow)) {
dragOptions.xaxes = xa;
dragOptions.yaxes = ya;

// take over selection polygons from prev mode, if any
if((e.shiftKey || e.altKey) && (plotinfo.selection && plotinfo.selection.polygons) && !dragOptions.polygons) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be possible to move this block into prepSelect so that all subplot types that support selections can allow multi-select? Right now, only cartesian and gl2d plot types allow it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep

prepSelect(e, startX, startY, dragOptions, dragModeNow);
}
}
};

dragElement.init(dragOptions);

// FIXME: this hack highlights selection once we enter select/lasso mode
if(isSelectOrLasso(gd._fullLayout.dragmode) && plotinfo.selection) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not a big fan of this behavior. @dfcreative is there a particular reason why you added this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not relevant since #2135

@@ -526,6 +547,9 @@ module.exports = function dragBox(gd, plotinfo, x, y, w, h, ns, ew) {
}

updateSubplots([x0, y0, pw - dx, ph - dy]);

if(plotinfo.ondrag) plotinfo.ondrag.call([x0, y0, pw - dx, ph - dy]);
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we need this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed

})
.then(function() {
// sub selection
drag([[219, 143], [219, 183]], {altKey: true});
Copy link
Contributor

Choose a reason for hiding this comment

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

Brilliant tests ✨

Thanks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

:) you're welcome!

@etpinard
Copy link
Contributor

Beautifully done @dfcreative, merge away 💃

@immotus
Copy link

immotus commented Mar 2, 2018

Is there a way to disable multiselect mode and return to the old behaviour when Shift was invoking pan mode?

@dy
Copy link
Contributor Author

dy commented Mar 2, 2018

@PavelGolodoniuc pan mode can be enabled by Ctrl key, is that a case?

@immotus
Copy link

immotus commented Mar 6, 2018

@dfcreative it doesn't seem to be the case. When "Box select" is mode is selected Ctrl key doesn't seem to enable pan. Also our application traditionally used Ctrl key over the plot for a user-defined functionality.

@immotus
Copy link

immotus commented Mar 12, 2018

@dfcreative, @etpinard Can the multiselect mode including Shift/Alt/Ctrl handler be disabled completely in the Box select mode? In our application we do not allow irregular selections in general and thus would like to disable this functionality completely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature something new
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants