禁用所有D3动画(用于测试) [英] Disabling all D3 animations (for testing)

查看:241
本文介绍了禁用所有D3动画(用于测试)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在寻找D3等同于 jQuery.fx一个。关闭= TRUE

I'm looking for a D3 equivalent to jQuery.fx.off = true.

假设您是使用D3的应用程序编写测试(与摩卡,QUnit等)。该应用程序有一些D3动画(与 .transition())。

Say you are writing tests (with Mocha, QUnit, etc.) for an app that uses D3. The app has some D3 animations (with .transition()).

动画真的不好做检查:

首先,它们是缓慢的。

其次,因为它们是异步的,他们可以很容易引起闪烁测试。理想情况下,你会希望避免的setTimeout / 的setInterval / requestAnimationFrame

Second, because they are asynchronous, they can easily cause flickering tests. Ideally, you'd want to avoid any calls to setTimeout / setInterval / requestAnimationFrame.

有没有一种方法来禁用所有D3的动画,让他们瞬间(理想情况下,同步)跳到结束状态? (也许,如果有不是一种选择,我们可以挂接到 timer.js ?)

Is there a way to disable all D3 animations, so that they instantly (and ideally, synchronously) jump to the end state? (Perhaps if there's not an option, we can hook into timer.js?)

推荐答案

要嘲讽了过渡另一种是同步直接执行他们自己的最终状态,通过做:

An alternative to mocking out transitions is executing them synchronously directly to their final state, by doing:

function flushAllD3Transitions() {
    var now = Date.now;
    Date.now = function() { return Infinity; };
    d3.timer.flush();
    Date.now = now;
 }

另请参阅 D3发行1789

这篇关于禁用所有D3动画(用于测试)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆