almende / vis

⚠️ This project is not maintained anymore! Please go to https://github.com/visjs
7.86k stars 1.48k forks source link

Calling an event as a function? #4258

Open jeandav opened 5 years ago

jeandav commented 5 years ago

I want to create a function which will deselect the selected nodes in the network. I tried network.deselectNode();, however, I can't figure out how to trigger an event from a function.

asiby commented 5 years ago

Did you try the following approach?

  1. Call getSelectedNodes() to get an array of selected node ids in the form: [nodeId1, nodeId2, ...]
  2. Find and remove the nodeId that you want to deselect using the approach of your choice.
  3. Call unselectAll()
  4. Use setSelection() to select the object having their id in the array.

I haven't tried this myself. I just came up with it based on what I found in the documentation.

The setSelecton() accepts an option object that looking like this ...

{
  unselectAll: Boolean,
  highlightEdges: Boolean
}

Again, I haven't tested it, but if you set unselectAll to true, maybe you will not need to call the unselectAll() function at step 3.