【发布时间】:2015-06-28 18:17:00
【问题描述】:
我尝试了一些方法,例如 mbostock 提出的d3 Node Labeling。但它不起作用,我的文本仍然没有随着节点移动,它们是静态的。
(使用 CoffeeScript 编码)
vis = d3.select(selection).append("svg")
.attr("width", width)
.attr("height", height)
linksG = vis.append("g").attr("class", "links")
nodesG = vis.append("g").attr("class", "nodes")
labelG = vis.append("g").attr("class", "labels")
nodeP = nodesG.selectAll("circle.node")
.data(curNodesDataP)
nodeP.enter().append("circle")
.attr("class", "node")
.attr("r", 15)
.style("fill", (d) -> nodeColors(d.id))
.style("stroke", (d) -> strokeFor(d))
.style("stroke-width", 1.0)
.call(force.drag)
text = labelG.selectAll("text")
.data(curNodesDataP)
text.enter().append("text")
.attr("dx", 12)
.attr("dy", ".35em")
.text((d) -> d.id)
困扰了好几天了,怎么修呢?谢谢!
--zzchengp>
【问题讨论】:
-
您没有使用您链接到的问题中的方法。
-
我是coffeescript和d3的新手,不过我觉得程序片段和那个是一样的(同样的圆圈和文字操作)。
-
不,您没有对
text和circle元素进行分组。我建议仔细查看您链接到的问题及其生成的 DOM 结构。
标签: javascript d3.js coffeescript