d3 v5 circle swarm plot dynamically adjust force to account for variable radius size

坚强是说给别人听的谎言 提交于 2021-01-29 19:02:42

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!