Custom Beeswarm III (perf. enhancement)
This example visualizes the distribution of word frequencies from a CSV dataset using a beeswarm plot, where each word is positioned along the x-axis by its rank and vertically adjusted to avoid overlaps. The code uses D3.js v3 and a custom doubly-linked list (implemented in `already_arranged_data.js`) to efficiently check collisions only among nearby circles. Hovering reveals tooltips with details, and the animation updates placements dynamically as the user adjusts parameters via the dat.gui interface.
AI-generated descriptionThis <a href='http://bl.ocks.org/Kcnarf/921b2f038327dd0ca55213e4ce8bcdb1'>block</a> is a continuation of a <a href='http://bl.ocks.org/Kcnarf/9a4ef4e88343202ddaca640e23968067'>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)
Compared to the <a href='http://bl.ocks.org/Kcnarf/9a4ef4e88343202ddaca640e23968067'>previous block</a>, this algorithm is faster, because of:
- less collision checks (use a direct-access doubly-linked list of possible already arranged colliding circles, so that collision checks are restricted to a small area (square with side of 2*radius))
The more data to arrange, the more it is faster. The more circles are big (more possible collisions), the more it is faster.
The algorithm is:
- (hyp) circles to draw are ordered (from right to left in this example)
- (hyp) datum must have an identifier named 'id' (used for direct-access in the doubly-linked list)
- (init) cf. function 'initArrangement'
- 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
- if Ci does not overlap others circles in AAC
- 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
- if Ci does not overlap others circles in AAC
- 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>