Skip to content

sankey: implement node grouping via mouse selection #3712

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 8 commits into from
Apr 8, 2019

Conversation

antoinerg
Copy link
Contributor

@antoinerg antoinerg commented Apr 2, 2019

Closes #3582

Peek 2019-03-14 17-08

  • Add a home button to ungroup all groups (not seen in the above GIF)
  • Add jasmine tests

@etpinard etpinard added this to the v1.47.0 milestone Apr 2, 2019
if(node.partOfGroup) continue; // Those are invisible

// TODO: decide on selection criteria, using centroid for now
var pos = [(node.x0 + node.x1) / 2, (node.y0 + node.y1) / 2];
Copy link
Contributor

Choose a reason for hiding this comment

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

Voting 👍 on centroid.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok 👍 I 🔪 the TODO in 20d8c92

Maybe we should add a visual cue to let the user know a given node is now part of a selection 🤔 This could also be added later on.

};

dragOptions[i].prepFn = function(e, startX, startY) {
prepSelect(e, startX, startY, dragOptions[i], dragMode);
Copy link
Contributor

Choose a reason for hiding this comment

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

... and I guess prepSelect does the right thing when dragmode isn't select nor lasso?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ahh. This is tricky actually for sankey, dragmode values zoom and pan don't really make sense. I'm not sure if we can do anything about it in v1. Would it be ok to have zoom and pan correspond to the current "drag-on-nodes" behaviour?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would it be ok to have zoom and pan correspond to the current "drag-on-nodes" behavior?

Yes, I think it would be OK. I will return early in subplotUpdateFx when dragMode is either zoom or pan.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in aa17f1b

@@ -284,6 +286,8 @@ function prepSelect(e, startX, startY, dragOptions, mode) {
dragOptions.mergedPolygons.length = 0;
[].push.apply(dragOptions.mergedPolygons, mergedPolygons);
}

doneFnCompleted(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 like this solution a lot. Very clean 🥇

@etpinard
Copy link
Contributor

etpinard commented Apr 2, 2019

Looking good @antoinerg - some minor comments, but you're for sure on the right track 🏎️

icon: Icons.home,
click: function(gd) {
Registry.call('restyle', gd, {
'node.groups': [[]],
Copy link
Contributor

@etpinard etpinard Apr 4, 2019

Choose a reason for hiding this comment

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

As we discussed in person, it might be better to restyle back to the "initial" view rather than to just remove all the groups.

To do so:

  • stash the 'initial' node.(x|y) and groups in fullData[i] (see mapbox example)
  • call restyle with the values in that stash each in the modebar button handler (see example)

Copy link
Contributor

@etpinard etpinard Apr 8, 2019

Choose a reason for hiding this comment

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

@antoinerg let me know if you need help implementing 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.

call restyle with the values in that stash each in the modebar button handler (see example)

I don't think I can reuse resetView because it does a relayout whereas we need a restyle.

Copy link
Contributor

Choose a reason for hiding this comment

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

Right, no need to use resetView() found in modebar/buttons.js, but you should try to replicate the same pattern.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in commit 506da4c! Let me know if it is satisfactory.

I will now write Jasmine tests for the reset button. Is there anything else you would like me to add?

Copy link
Contributor

Choose a reason for hiding this comment

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

I will now write Jasmine tests for the reset button. Is there anything else you would like me to add?

Nop, once that jasmine test is in, this one will be good to go!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in f8a4073

@antoinerg antoinerg force-pushed the sankey-selection2 branch from 1f0282b to 506da4c Compare April 8, 2019 19:39
@etpinard
Copy link
Contributor

etpinard commented Apr 8, 2019

Excellent!

You might not feel that way @antoinerg as this PR didn't add that many lines to src/, but I think this is your best PR to date. Reusing stuff, following our existing patterns and writing good interaction tests are all difficult things that not many past plotly.js devs have even attempted.

Well-earned 💃

@antoinerg antoinerg merged commit 8fd2133 into master Apr 8, 2019
@antoinerg antoinerg deleted the sankey-selection2 branch April 8, 2019 22:48
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.

2 participants