I have a visualization that is essentially a series of stacked bar charts, each of which contains several panels. For example, here are three such bar charts, each with four panels.
I have managed to implement pan/zoom functionality that is coordinated across the charts. This is what it looks like if I zoom into the third panel from the last image, for example. The zoom behavior is called from an invisible rectangle that is placed over each chart.
My problem is that I want to enable tooltip functionality based on the location of the user's cursor within a plot. Since the zoom-rectangles are placed on top of the charts, however, no mouse events are registered for any SVG elements in the actual charts themselves.
Des anyone know a way around this?
There are two possible methods of creating tooltips in D3. js. The first method is by creating the SVG <title> tags as a descendant of an interactable element. The second approach is to use mouseover , mosueleave , and mousemove events to dynamically move and change the visibility of a tooltip.
I was following Mike Bostock's example, and like you placing a rect
across my whole chart and then calling the zoom behaviour on that, and like you found that it was consuming all the pointer events.
I found an example here that seemed to be achieving what I wanted, and I found that if I scrap the rect
and just call the zoom behaviour on the svg
element directly, I still get pointer events for the child elements.
I'm a noob here, I don't really understand why this works. I also guess this might have its own ramifications e.g. I guess this stops you limiting the area of your graphic in which mouse events cause a zoom. You may notice that the example I linked creates a sub-svg
; I don't know, but perhaps this is to solve that problem.
In your css put the style ponter-events:none for your zooming rectangles. That way the cursor events will be sensed by the elements blow.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With