0
示例代码更新:重构D3 V3馅饼版本4意外行为
var updateChart = function(dataset) {
arcs = arcs.data(donut(dataset), d => d.data.label);
arcs.exit().remove();
arcs.enter().append("path")
.attr("stroke", "white")
.attr("stroke-width", 0.8)
.attr("fill", function(d, i) {
return color(i);
}).attr("d", arc);
arcs.transition()
.duration(duration)
.attrTween("d", arcTween);
sliceLabel = sliceLabel.data(donut(dataset), d => d.data.label);
sliceLabel.exit().remove();
sliceLabel.enter()
.append("text")
.attr("class", "arcLabel")
.attr("transform", function(d) {
return "translate(" + (arc.centroid(d)) + ")";
})
.attr("text-anchor", "middle")
.style("fill-opacity", function(d) {
if (d.value === 0) {
return 1e-6;
} else {
return 1;
}
})
.text(function(d) {
return d.data.label;
});
sliceLabel.transition()
.duration(duration)
.attr("transform", function(d) {
return "translate(" + (arc.centroid(d)) + ")";
})
.style("fill-opacity", function(d) {
if (d.value === 0) {
return 1e-6;
} else {
return 1;
}
});
我有一个馅饼,我重构为4版本,我得到它没有错误运行,但它不再删除片段。除了为了让它运行而必须做出的改变之外,它与第3版完全一样。
仅供参考,这里有三种版本的工作之一: version 3
谢谢。我只是看着那个!诚实! – keepTrackOfYourStack