我设置的节点被固定固定节点不被固定(D3力向图)
let link = svg.append("g")
.attr("class", "links")
.selectAll("line")
.data(graph.links)
.enter().append("line")
.attr("stroke-width", () => 4)
let node = svg.append('g')
.attr("class", "nodes")
.selectAll(".node")
.data(graph.nodes)
.enter().append("g")
.attr("class", "node")
.call(
d3.drag()
.on("start", Node.dragstarted)
.on("drag", Node.dragged)
.on("end", Node.dragended))
node.append("title")
.text(d => d.country)
node.append('image')
.attr('xlink:href', d => 'https://rawgit.com/hjnilsson/country-flags/master/svg/' + d.code + '.svg')
.attr('height', d => 2.5 * (area[d.code]||5))
.attr('width', d => 4 * (area[d.code])||5)
simulation
.nodes(graph.nodes.map(c => {
if(latlong[c.code] === undefined) {
console.log(c,'missing lat/long data')
return c
}
c.x = (+latlong[c.code][0])
c.y = (+latlong[c.code][1])
c.fixed = true
return c
}))
.on("tick", ticked)
这并不正确显示在比没有x和y值明显不同的位置的图像,但..固定属性不起作用。
这里是我的代码:codepen
如果有谁还知道如何设置画布了,这样什么事都逃不过了顶部或底部我会很感激这一点。
你为什么要设置'c.fixed = TRUE'财产? – bumbeishvili
这是这篇文章的主要内容。我有像'{foo:'bar',baz:'bam'...}'这样的节点的数据。我在那里设置它也有x,y坐标,并且是固定的,因此节点不会移动。我是否在这样分配时做了一些微妙的错误?看到[这里的答案](http://stackoverflow.com/questions/17656502/d3js-create-a-force-layout-with-fixed-nodes) –
预期的行为是什么? – thedude