-
Notifications
You must be signed in to change notification settings - Fork 1.5k
VisJS Network - Have ability to select a group of nodes and edges by drawing a circle or rectangle that highlight a particular region #977
Comments
Thanks for your feature request. |
I have created a sample page that have the ability to draw a rectangle using right-mouse click and selecting all the nodes/edges inside it. You can use it to incorporate into the main branch if you'd like. I have put it here: https://github.com/dragonzone/JsSamplerApp, go to "Link Analysis" to view it. |
Hi, Your code seems very much intertwined with other libraries or frameworks. I'm not sure we can merge this into vis. Your application looks cool though :) Regards, Alex |
Yes, I use a variety of JS apis, just for my own references and how to use it. But for the draw selection, it's just using HTML 5 Canvas. If I have time, I'll create another page with just the drawing. |
Could you explain to me the basic outline of what it is you've done? Do you draw on another canvas on top of the network? Regards |
I just reuse the canvas context that is provided by vis.js. Then I added listeners on right-mouse down/move/up, which draws the rectangle outline. Once outline is draws, I grab all the nodes (x, y coord.) and check if they are inside my rectangle. You can check the link-analysis.js to view the source code. BTW, your library is being used on a project that I am working on, which is I am customizing. I add some powerful feature in the example of what is there so far. |
I used one of your demo example and have expanded on it. You can check out the source code here. The only other JS lib. I am using is jQuery. I hope this helps. https://github.com/dragonzone/JsSamplerApp/blob/master/src/main/webapp/network/draw.htm |
I tried pasting into JS Bin, but something is buggy with it, so I'll paste the whole page here, on how to highlight with RIGHT mouse drag. But I think it's better to use the LEFT mouse drag instead. Since vis.js network already use the left-mouse drag to drag the view, I think it's best is to have an icon/button on the network, where user can toggle between the drag view or highlight icon. Below is the working example of highlight nodes using right mouse drag. See if you can add it.
|
Here is the actual example, which I think you can add to part of the vis.js network. Do right mouse click & drag. |
But I've changed this code in our app to handle the left-mouse clicked instead. But we use a toggle button to toggle between the drag view & highlighting. |
Hi Dragon, Looks cool! I think the toggle is indeed the way to go. One thing, why are you not using the afterDrawing event for rendering? Currently your code does not work if the physics are running. Using the render event would solve that. You also do not need to restore the surface or use the internals: network.canvas.frame.canvas; Regards |
Looks cool! |
But think vis.js is lacking the highlight feature, which I notice a few others have, so think about it. |
This code is pretty old, I tweaked it to use your dragStart, dragging, and dragEnd. When dragStart, I disabled the physics, do my drawing. Then when done, dragEnd, puts back the physics. I just added it. ;) |
BTW, We reserved the right-mouse click so we can use the bootstrap context-menu to view the properties & other features of each nodes not visible from the pix. :) |
dragonzone, do you mind sharing your code which uses dragStart/end, and disables physics when selecting? |
Sure, you can get full code at: https://github.com/dragonzone/JsSamplerApp and run it if you want. However, in there, there is a file that handles the logic to calculate and draw the shape (https://github.com/dragonzone/JsSamplerApp/blob/master/src/main/webapp/js/link-analysis-highlight.js). The listeners are register here, https://github.com/dragonzone/JsSamplerApp/blob/master/src/main/webapp/js/link-analysis-listeners.js, starting line 40. I have to tweak the vis.js a little in order for that to work. Here is the modified vis.js (moving the dragging even), https://raw.githubusercontent.com/dragonzone/JsSamplerApp/master/src/main/webapp/js/vis/vis.js. Search for "Andy Do" (my name :)), of course. I had firing of the dragging out side of
Since i need to fire the event regardless. Enjoy! |
Hi ! |
I had the chance to play around with the demo, after adjusting it to latest version of OTOH, I am aware that there are networks that are never still. I'll think about it a bit. |
Hey there, I had to implement this right-click selection too. After playing around with the previous JSFiddle, I made my own version, based on then Since the first version presented here saves the canvas surface once and for all when the selection starts and restores it each time the selection box changes, this made zooming, dragging, animations, hovering (and actually any redraw) resulting in weird unexpected behaviours. With this new version, everything works fine. |
Do a quick highlight of nodes and edges by draw circle, rectangle, or free-hand on the network.
The text was updated successfully, but these errors were encountered: