Skip to main content
100%

Custom Beeswarm II (perf. enhancement)

✓ Published0🌍 Public
KKcnarf
Last edited Dec 3, 2018
Created on May 25, 2016

This interactive beeswarm chart visualizes the distribution of 150 French word stems along a horizontal axis, with the y-position optimized to avoid overlapping circles while preserving exact x-coordinates. The D3.js v3 and SVG implementation animates circle placement using an efficient collision-detection algorithm that estimates candidate positions against already-placed neighbors, skipping checks when a better placement is found. Circles are colored along a lightgreen-to-pink scale by rank, and hovering reveals tooltips with stem, rank, and trend data from an external CSV. The code includes dat.gui controls to adjust point density and radius.

AI-generated description

This <a href='http://bl.ocks.org/Kcnarf/9a4ef4e88343202ddaca640e23968067'>block</a> is a continuation of a <a href='http://bl.ocks.org/Kcnarf/c13da7160e8d8f64d467df8988043d1f'>previous one</a>.

This sequel experiments a way to vizualise the distribution of things (whatever it is) in a horizontal way (ie. along the x-axis), where constraints/objectives are:

  • to maintain the exact position of each datum (represented by a circle) along the x-axis
  • to be able to hover each circle to show related datum (handle overlapping)
<hr/>

Compared to the <a href='http://bl.ocks.org/Kcnarf/c13da7160e8d8f64d467df8988043d1f'>previous block</a>, this algorithm is ~2 times faster, because:

  • computing possible colliders is faster
  • when placing a new circle, collision detection (which iterates over already drawn circles) is executed if and only if the new tested placement is better than the one already found (gain is ~40%)
  • collision detection is faster (now stoping at first collision)

The algorithm is:

  • loop1 - for each new circle to place Ci:
  • find already drawn circles susceptible to overlap (close enought to Ci, distance from Ci <= 2*r)
  • if AAC is empty
    • place Ci on the x-axis (Ci.y = 0), push Ci in AAC, continue loop1
  • loop2 - for each Ca in AAC:
    • place Ci above Ca
    • if Ci is a better placement than the already tested (best = closest to x-axis, consider absolute value)
      • if Ci does not overlap others circles in AAC
        • retain y-position as the best till now
    • place Ci below Ca
    • if Ci is a better placement than the already tested
      • if Ci does not overlap others circles in AAC
        • retain y-position as the best till now
  • place Ci at best y-position, add Ci to AAC

Acknowledgments to:

  • <a href='https://d3js.org/'>D3.js</a> (v3.5.5)
  • <a href='http://blockbuilder.org'>blockbuilder.org</a>
  • <a href='http://workshop.chromeexperiments.com/'>dat.gui</a>
mit Licensed

Similar vizzes