Custom Beeswarm
A custom beeswarm layout arranges 150 French word stems along a horizontal axis by their sentiment trend values, using colored circles from light green to pink based on rank. The D3 v3 code implements a deterministic collision-avoidance algorithm, positioning each circle above or below previously placed neighbors to maintain exact x-coordinates while minimizing vertical displacement. Hovering a circle reveals a tooltip showing the stem, rank, and trend value, with the dataset loaded from a CSV file and rendered as SVG.
AI-generated descriptionThis <a href='http://bl.ocks.org/Kcnarf/c13da7160e8d8f64d467df8988043d1f'>block</a> 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)
In previous blocks (<a href='http://bl.ocks.org/Kcnarf/91c5e84bed1ba6b1541deaa5d5f4f258'>1</a>, <a href='http://bl.ocks.org/Kcnarf/d4a745960538e937dcde13f61e9893f12'>2</a>), I tried the Force Layout.
Now I try to implement my own arrangement algorithm (with the secret objective that it will be faster than using the Force O_° ... and, hopefully, it is).
The resulting arrangement can be used as-is (shown in this example), or can be a good starting point before applying the Force. In this later case, final arrangement with the Force will be obtained faster than with the random default arrangment.
The algorithm is:
- (hyp) circles to draw are ordered (from right to left in this example)
- (init) already arranged circles AAC = [], used for (windowed) collision detection
- loop1 - for each new circle to place Ci:
- retain in AAC only 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 does not overlap others circles in AAC, retain y-position if it is the best till now(best = closest to x-axis, consider absolute value)
- place Ci below Ca
- if Ci does not overlap others circles in AAC, retain y-position if it is 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>