-
Notifications
You must be signed in to change notification settings - Fork 51
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
Component | Graph: Multiple node selection #395
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@reb-dev Awesome feature!
Quick look at the code, looks good. I'm not sure if the nodes selected by the brush need to have their own "selected" state (blue outline), or can they just look like a regular selection? If you think we need to keep the "brushed" state, let's add it to the node _state as well. I'm currently working on a feature that will allow users specify their own node rendering functions and they'll need to implement these states in their code too.
Also I don't think the brush needs to remain visible after selection. To me it looks a bit off, that the node outline is outside of the brush rectangle.

(Sorry, instead of quote reply I accidentally edited @rokotyan's comment. Reverting it back -Qian)
@@ -116,7 +120,11 @@ export class Graph< | |||
} | |||
|
|||
public get selectedNode (): GraphNode<N, L> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@reb-dev I agree with your comment regarding marking the selectedNode
things as deprecated. You can use this jsdoc tag: https://jsdoc.app/tags-deprecated
@reb-dev Missed some of your comments
|
@reb-dev This is great! In terms of trigger key: Agreed on making it configurable, but I think we could have a separate task for that and keep this PR small? |
@rokotyan @lee00678 thanks for the feedback! I guess my thought process for keeping the brush was that there should be some indicator of the draggable range besides the highlighted nodes, because in its current state you can select anywhere within the brush area and drag the nodes. But I agree it would look better without it. I'll adjust it so that the only the nodes can drag, not the area itself. |
I thought about this, but what about the case when users provide Right now multi-dragging can only occur while the trigger key is pressed, but if we want the above functionality then I'll need to change that so that selected nodes can always be draggable as a unit regardless of how the nodes are selected (through brushing or config property). I'm not opposed to this, but I have some concerns:
|
@lee00678 Sounds good to me, I'll hold off on adding that. |
5e9cb4a
to
abdbf0e
Compare
abdbf0e
to
72ce873
Compare
Changes since original PR:
I've also updated the video in the description above. |
This PR introduces brushing to the Graph component to allow users to select and drag multiple nodes at once.
How it works:
Brushing mode is active when the shift key is pressed. This allows for panning, zooming and single-node dragging behavior to function independently and without interference from this new functionality. The crosshair cursor on hover indicates that the brush is able to use.
When making a selection, drag the brush over a region to group those nodes. The nodes within the selection range will be highlighted. Upon release of the mouse, the nodes within the selection can be dragged as a group.
If the shift key is released during any point, the selection resets and the brush is inactive until is it is enabled again.
Video example showcasing zooming, panning, single-node dragging and multi-node dragging in various sequences:
Screen.Recording.2024-06-06.at.10.28.23.AM.mov
New Config Properties
disableBrush
- to disable this behavioronNodeSelectionBrush(nodes: GraphNode<N,L>[], event: D3BrushEvent)
- callback when the brush area is being selectedonNodeSelectionDrag(nodes: GraphNode<N,L>[], event: D3DragEvent)
- callback for the dragging of the selectionCSS Variables
Ideally we should be able to add more customization options here, I just wanted to keep it simple while we ensure the functionality is stable.
Other Addition:
selectedNodeIds
Although not directly related to this feature, being able to manually provide multiple
selectedNodeId
values has been requested, so I've added it. Note thatselectedNodeId
is still a valid config property but in the future we should probably deprecate it in favor of this one.