1
我使用D3的力指向图建立一个模拟疫情仅第一要素。。数据()结合
当传输事件发生时,我想从发射器的圆圈移动到新感染的个体。
问题:仅在创建第一元件和根据所述绑定数据移动。
首先,我收集的坐标:
xyCoords = getPathogen_xyCoords(newInfections);
凡xyCoords如下所示:
{receiverX: newInfections[i].x, receiverY: newInfections[i].y, transmitterX: newInfections[i].infectedBy.x, transmitterY: newInfections[i].infectedBy.y}
然后,我创建的圈子并将其绑定到xyCoords:
d3.select(".svg").append("circle")
.attr("class", "pathogen")
d3.selectAll(".pathogen")
.data(xyCoords)
.attr("cx", function(d) { return d.transmitterX})
.attr("cy", function(d) { return d.transmitterY})
.attr("r", 4)
.style("fill", "green")
最后,该圆被移动:
d3.selectAll(".pathogen")
.transition()
.duration(500)
.attr("cx", function(d) { return d.receiverX})
.attr("cy", function(d) { return d.receiverY});
编辑:游戏已经上涨了几个月,做得相当好!查看http://vax.herokuapp.com!