Baqer Naqvi
Baqer Naqvi

Reputation: 6514

vis.js: Capture edge click event

I know we can register node click event in vis.js but I want to listen edge click event. I have gone through documentation but could not be any helpful. I was wondering If It Is even possible?

Upvotes: 1

Views: 3534

Answers (2)

Umer Khalid Butt
Umer Khalid Butt

Reputation: 115

You can hook the following event in your vis.js network configuration to perform any action when an Edge is selected:

selectEdge:function(obj){
console.log(obj);
}

You can read more about this configuration here:

Cheers !

Upvotes: 1

pgoldweic
pgoldweic

Reputation: 467

Essentially you can use the same method that you do with nodes. For example:

network.on("click"), function(params) {
    if (params.edges.length > 0) {// if some edge is selected
        // do something with the array of edge ids (params.edges)
        // alternatively, you could call network.getSelectedEdges()
        // to obtain the same array of edge ids
    }
} 

Note that you can do the same with nodes by selecting params.nodes in the above code instead of params.edges. If this answer helps you out, please mark it as an answer to the question.

Upvotes: 0

Related Questions