d3でそれを行うネイティブな方法はわかりません。アニメーション化する
HTMLコード:しかし、あなたは簡単にD3のプロトタイプを増強することによってアニメーションをスキップするD3セレクタAPIを変更することができ
<svg width="200" height="200">
<rect x="1" y="1" width="0" height="100" />
</svg>
アニメーションとD3-増強コード:
function animate(color){
d3.selectAll("rect")
.attr("width", 0).attr("fill", "white")
.transition().duration(1000)
.attr("width", 100).attr("fill", color)
}
function augment(){
// add a duration function to the selection prototype
d3.selection.prototype.duration = function(){ return this }
// hack the transition function of d3's select API
d3.selection.prototype.transition = function(){ return this }
}
animate("red")
console.log("normal animation done")
setTimeout(function(){
augment()
console.log("d3 hacked!")
animate("green")
console.log("animation skipped")
}, 1200)
注意!このハックは完全な解決策として機能しない場合があります。 d3.selection.prototype
で利用できないほかのアプリケーションで使用する他のtransition().*
関数でこのソリューションを拡張することもできます。 d3でサポートされている他の形式のアニメーションも考えられます。たぶん私が気付いていない<selection>.transition()
以上があります。
[ 'd3.timer.flush()'](https://github.com/mbostock/d3/wiki/Transitions#wiki- d3_timer_flush)が役に立ちます。 –