tree = {
const svg = d3.select(DOM.svg(width, height))
const g = svg.selectAll('g')
.data(rawData)
.join(
enter => {
const g = enter
.append("g")
.attr("class",(d,i) => "g_"+i)
.on("click", function(){
clicked()
})
g.append("path")
.attr("class","voronoi")
.attr("id", (d,i) => i )
.attr("d", d => d )
.attr("stroke", "#FFF")
.attr("stroke-width", 1)
.style("fill", "#6ca7ff")
.style("fill-opacity", 1)
return g
},
update => update,
exit => {
}
)
var isClicked = true
function clicked(){
if(isClicked){
g.select(".voronoi")
.transition()
.delay((d,i) => i * 20)
.duration((d,i) => 750 - i * 20)
.attr("stroke", "#666")
.attr("stroke-width", .5)
.style("fill-opacity", .2)
.attr("transform", (d,i) => `translate(${pos[i]})`)
isClicked = false
}else{
g.select(".voronoi")
.transition()
.delay((d,i) => i * 20)
.duration((d,i) => 750 - i * 20)
.attr("stroke", "#fff")
.attr("stroke-width", 1)
.style("fill-opacity", 1)
.attr("transform", (d,i) => `translate(0,0)`)
isClicked = true
}
console.log("click ",isClicked)
}
yield svg.node()
}