我一直在使用D3的动力布局,以创建向中间力量做了一个分组气泡图,就像这样:D3增加力量单个节点
var forceStrength = 0.03;
var center = { x: widthBubbles/2, y: heightBubbles/2 };
var simulation = d3.forceSimulation()
.velocityDecay(0.2)
.force('x', d3.forceX().strength(forceStrength).x(center.x))
.force('y', d3.forceY().strength(forceStrength).y(center.y))
.force('charge', d3.forceManyBody().strength(charge))
.on('tick', ticked);
function charge(d) {
return -forceStrength * Math.pow(d.r, 2.0);
}
function ticked() {
bubbles
.attr('cx', function (d) { return d.x; })
.attr('cy', function (d) { return d.y; });
}
我的图表看起来类似于这样:Gates Foundation Educational Spending
我希望能够在单个节点上单击时施加一个力,以便点击的节点将移动到另一个区域。在D3的文档中,有一些称为“定位力”的东西,根据文档打算用于多个节点:
虽然这些力可用于定位各个节点,但它们主要用于适用于所有(或大多数)节点的全球力量。
所以我的问题是如果有一种方法可以将力量应用于D3中的单身节点。
这可能只是[*“碰撞检测丢失后切换(d3v4)”*](/ q/41479452)中讨论的解决方案的特例。 – altocumulus
它可能是相似的,但我的问题是如何改变只有一个节点的力量。 – martin36