piggyback
piggyback

Reputation: 9264

Mouseenter in d3

I wrote a graph in d3 that is updated when the mouse touches it (using mouseover), the data are update, however mouseover will continuosly update the graph if the mouse is still on the bar.

So I was looking at the jQuery mouseenter. Is there any possibility to implement mouseenter in d3?

Upvotes: 1

Views: 2005

Answers (2)

user1085665
user1085665

Reputation:

I think the difference between "mouseover" and "mouseenter" is that "mouseover" fires for the element itself and all of its child elements while "mouseenter" only fires for the element itself.

Mouseover: Fires when pointer is moved over the attached element or a child element. Moving the pointer to other child elements will trigger a new event. https://developer.mozilla.org/en-US/docs/DOM/Mozilla_event_reference/mouseover?redirectlocale=en-US&redirectslug=Mozilla_event_reference%2Fmouseover

Mouseenter: Fires when pointer is moved over the attached element. Child elements don't trigger the event. https://developer.mozilla.org/en-US/docs/DOM/Mozilla_event_reference/mouseenter?redirectlocale=en-US&redirectslug=Mozilla_event_reference%2Fmouseenter

So if you want your own "mouseenter", you could do a check like if (this === d3.event.target), followed by a d3.event.stopPropagation(), so you only get the elements the listener was assigned to. Hope this helps.

Upvotes: 0

Venkatesh Nadar
Venkatesh Nadar

Reputation: 142

Add mouseenter event through d3.

d3.select(".class").on("mouseenter", function(){ // do stuff })

Upvotes: 2

Related Questions