Skip to main content
100%

Scatterplot with Voronoi

✓ Published0🌍 Public
KKcnarf
Last edited Dec 3, 2018
Created on Jun 9, 2016

This interactive scatterplot displays life expectancy versus GDP per capita for countries, colored by region and sized by GDP. It uses a Voronoi partition to identify the nearest data point to the cursor, but limits the interactive area by checking the distance from the pointer to the point. D3 v3’s `d3.geom.voronoi` and a `clipPath` cut off oversized cells, so tooltips appear only when the mouse is close enough to a circle.

AI-generated description

This block is based on Step 3 - Voronoi Scatterplot - Tooltip attached to circle from @NadiehBremer

The Voronoi technics (used to improve interactive experience) is something I like. But I'm quite confused when the mouse is far away from points/subjectsOfMatter. In the original example, this situation arises in the viz's top-left and bottom-right corners.

This block attempts to overcome this issue by:

  • still using the Voronoi partition to identifiy the closest point/subjectOfMmatter when they are close to each others
  • and, checking if the distance from the point to the mouse is close enought (max distance checking)

For the sake of illustration, interactive areas appear in (very) light blue. Voronoï cells and interactive zones would not be rendered in the final viz.

The implementation in this block uses a clipPath on the voronoi layer in order to cut off too large cells (cf. lines 128->142 of script.js). Other ways could be:

  • use JS to determine if the pointer is close enought to display the tooltip (cf. this block)
  • produce adequate path for each limited Voronoï cell (adequate path = path corresponding to (voronoï cell INTERSECT max-distance-from-point circle); cf. this block)

Acknowledgments to:

mit Licensed

Similar vizzes