How to get current mouse position when i click on canvas? #217

Closed
crapthings opened this Issue Jul 13, 2014 · 2 comments

Comments

Projects
None yet
2 participants

Template.home.events
'dblclick .network-frame canvas': (e, t) ->
console.log e
nodes.add([
{ id: Random.id(), label: 'wtf', x: e.clientX, y: e.clientY }
])

i want to add node while i double click mouse.

but the node always added way far from current click point.

Member

AlexDM0 commented Jul 13, 2014

Hi,

The position of the mouse cursor and the x y position of the nodes are
not the same. There is a function in the documentation to transform
the coordinates either way. I'm on my phone now so I can't look this
up right now. It's in the docs, something like DOMtoCanvas and
CanvasToDOM.

Regards,

Alex

Member

AlexDM0 commented Jul 14, 2014

You could also use the datamanipulation for this:
http://visjs.org/docs/network.html#Data_manipulation

@AlexDM0 AlexDM0 added the Network label Jul 14, 2014

@AlexDM0 AlexDM0 closed this Jul 15, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment