2013-03-27 24 views
8

我想知道如果d3的默認動畫已經使用​​作爲回調,或者如果我需要自己做。舉例來說,我已經定義了重複調用重繪功能用於製作動畫從一個域到另一個圖表(這是CoffeeScript的)過渡的自定義補間:d3的轉換和動畫是否使用requestAnimationFrame?

rd = @redraw # a function that takes an argument to redraw the graph 
@svg.transition() 
    .duration(1000) 
    .tween "zoom", -> 
     interp = d3.interpolate(current_dom, target_dom) 
     (t) -> rd interp(t) 

在我所有的其他呼叫重繪,我與​​安排它:

scheduleRedraw: => 
    # Stop a previous request if it hasn't executed yet 
    cancelAnimationFrame(@animRequest) if @animRequest  
    @animRequest = requestAnimationFrame => @redraw 

不過,我想知道如果我需要在這裏做同樣的事情。我一直在看D3的來源,看到​​的唯一參考是在d3 timer class。希望有更多關於d3的知識的人可以幫助回答以下問題:

  • d3計時器是否全局用於所有d3動畫和轉換?
  • 我需要在這裏手動使用​​嗎?如果不是,那麼在使用d3時,是否有任何情況需要我自己使用它?

回答

8

d3's wiki:Transitions:Timer

如果你的瀏覽器支持它,定時器隊列將使用 requestAnimationFrame流體和高效的動畫。