问题
I have a swarm plot that shows ranges from 0
to 1
on a linear x axis and size via the SVG circle's radius attribute. Snippet below:
<script src="https://d3js.org/d3.v5.min.js"></script>
I have had modest success by setting the strength
to a low value and forceCollide
to a high value:
var simulation = d3.forceSimulation(data)
.force("x", d3.forceX(function(d) {
return xScale(d.pequity);
}).strength(0.01))
.force("y", d3.forceY(function(d) {
return 100;
}).strength(0.01))
.force("collide", d3.forceCollide(10).iterations(1))
.stop();
However there are many instances where the circles are all lumped together.
My intended goal is to have each circle stand apart (not overlapping), but at the same time I want the circles to be placed closed together. I imagine this would entail variable force settings, not sure how small circles next to big circles should be handled (and vice versa).
Question
How can I adjust my force logic to account for variable radius sizes in my swarm circles such that each circle is close but not engulfed by another circle?
来源:https://stackoverflow.com/questions/63627257/d3-v5-circle-swarm-plot-dynamically-adjust-force-to-account-for-variable-radius