almende / vis

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

oncontext event on network does not contain `nodes` or `edges` #4164

Closed andrei-gheorghiu closed 5 years ago

andrei-gheorghiu commented 5 years ago

I'm using the network module and I'd like to prevent the default context menu, to build my own. Unlike the one for click event, the oncontext handler param contains an empty array in nodes property when performed on a node and an empty array in edges property when performed on an edge.

Determining whether or not the right-click was performed over a node or an edge becomes tricky when panning or zooming are involved, especially for edges.

Since the nodes and edges properties exist in the event handler params, I'd say this qualifies as a bug, not a feature request. (As the intention to have them there existed by design, but was not followed - by placing the right-clicked node/edge into the appropriate array).

Is there a fix/workaround anywhere in sight?

clayt85 commented 5 years ago

I see the behavior exactly as you report, and agree that this behavior does not seem desirable.

For a workaround, have you tried using the getNodeAt() or getEdgeAt() properties? Within the event handler, this would look like this.getNodeAt(params.pointer.DOM); (where params is the input argument to the event handler callback).

andrei-gheorghiu commented 5 years ago

Perfect.

Thank you.