我正在尝试更新树形图中的元素:
drawTreeMap = (data) ->
margin =
top: 0
right: 0
bottom: 0
left: 0
width = window.innerWidth
height = window.innerHeight
color = d3.scale.category20c()
treemap = d3.layout.treemap().size([width, height]).sticky(true).value((d) -> d.size)
div = d3.select("body").append("div")
.style("position", "relative")
.style("width", (width + margin.left + margin.right) + "px")
.style("height", (height + margin.top + margin.bottom) + "px")
.style("left", margin.left + "px")
.style("top", margin.top + "px")
node = div.datum(data).selectAll(".node")
.data(treemap.nodes)
node.enter()
.append("div")
.attr("class", "node")
.call(position)
.style("background", (d) -> (if d.children then color(d.name) else null))
.on "click", ->
el = d3.select(this)
data = el[0][0].__data__
while (data.parent.parent)
data = data.parent
console.log("updated to data:")
console.log(data)
drawTreeMap(data)
#updateTreemap(div, treemap, data)
node.exit()
.remove()
node.transition().duration(1500).call position
data
是我希望它在console.log
声明中的内容,但树形图没有得到更新。大多数代码直接来自树形图示例。