Vis.js: how to access the network inside an event handler?

1.5k views Asked by At

I'd like to use vis.js for displaying and editing a graph (hence storing its nodes, edges and options). To implement this, I need to save changes of the network (=graph) on various events. On of them is rearranging via drag and drop.

Now, there's an on method which supports the dragEnd event meaning I can do stuff like

network.on("dragEnd",saveToTiddlerAfterDragging);

However what's passed to the handler is this object:

{
  nodes: [Array of selected nodeIds],
  edges: [Array of selected edgeIds],
  event: [Object] original _ event,
  pointer: {
    DOM: {x:pointer_x, y:pointer_y},
    canvas: {x:canvas_x, y:canvas_y}
  }
}

Seems like there's no reference of the network itself. So how to access it? I'd like to define saveToTiddlerAfterDragging in another scope than network itself.

1

There are 1 answers

0
YakovL On BEST ANSWER

Ok, while reading docs and writing the question, I wild-guessed that the network is actually this in the event handler context. Not sure if it's true for all the event handlers but works with the dragEnd one.