Skip to main content
100%

Avoidant Tooltip

✓ Published0🌍 Public
Aalexmacy
Last edited Feb 25, 2017
Created on Feb 24, 2017

A tooltip follows the cursor across a grid of thin steelblue lines, dynamically repositioning itself so it never clips at the edges of the 960-by-500 SVG viewport. The black, white-bordered tooltip displays the mouse’s x and y coordinates, fading in and out via d3 transitions. Built with D3 v4, the code attaches mousemove and mouseout listeners to the SVG, calculates adjusted left and top positions based on cursor proximity to the viewport’s center, and uses `d3.event.x` and `d3.event.y`. Clicking the tooltip triggers a brief orange flash overlay.

AI-generated description

This is a quick test of a tooltip that is responsive to the curser and also avoids the edges so that it is always visible. A more practical example can be seen here: Election History w/ Avoidant Tooltip.

If you can manage to click on the tooltip, the screen flashes!

mit Licensed

Similar vizzes