Skip to main content

Faking Mouse Events in D3

D3 is a great library but one of the challenges I have found is with unit testing anything based on event handlers. In my specific example I was trying to show a tooltip when the user hovered over an element. hoverTargets .on('mouseover', showTooltip(true)) .on('mousemove', positionTooltip) .on('mouseout', closeTooltip); D3 doesn't currently have the ability to trigger a mouse event so in order to test the behaviour I have had to roll my own very simple helper to invoke these events. $.fn.triggerSVGEvent = function(eventName) { var event = document.createEvent('SVGEvents'); event.initEvent(eventName,true,true); this[0].dispatchEvent(event); return $(this); }; This is implemented as jQuery plugin that directly invokes the event as if it had come from the browser. You can use it as below: $point .triggerSVGEvent('mouseover') .triggerSVGEvent('mousemove'); It will probably change over time as I need to do more with it but for now this works as a way to test my tooltip behaviour.

I guess you came to this post by searching similar kind of issues in any of the search engine and hope that this resolved your problem. If you find this tips useful, just drop a line below and share the link to others and who knows they might find it useful too.

Stay tuned to my blogtwitter or facebook to read more articles, tutorials, news, tips & tricks on various technology fields. Also Subscribe to our Newsletter with your Email ID to keep you updated on latest posts. We will send newsletter to your registered email address. We will not share your email address to anybody as we respect privacy.

This article is related to

Development,JavaScript,D3,software-development,testing,unit testing,Visualisation


Popular posts from this blog

MVVMLight and Async

With Windows 8 just around the corner and many developers running for the ship to get up to speed with the new brave world (even those who have frowned at the new Metro interface and possibly wont touch it themselves, still see the value in writing apps / games for the platform to sell).

One of the biggest hurdles I've found and seems reflected in colleagues and peers is the new Async framework, granted to those who have followed the Task framework it's no big shock and a simple evolution, but for those of us who left it in their "Read it Later" pile it is a bitter pill to swallow. That being said however once you have "tested the waters" so to speak will find it's not that different from what we already know it's just another way of tackling the problem of offloading work and marshalling it back for use, but cleaner and easier to read and some notable performance gains by letting the compiler and CLR handle it for us.

Read More from: Original Source

How to create cookies in ASP.NET?

A Cookie is a small amount of text that attached to the requet and response in between browser and the server. This small amount of text can be read by the application whenever user browse the it. Please note that cookie is not a good medium to store the confidential data as it is stored into the user browser.