admin管理员组文章数量:1291217
I want to turn NVD3 charts into PDF documents. Those charts are normally displayed in browser (I can't make a separate instance of each chart for print and for display), I got it all working using PhantomJS, but I have a problem that I can't seem to find a good solution to.
All NVD3 models use transitions, but only some of those transitions are affected by transitionDuration
option. Because of those transitions, I now have to use a timeout before "capturing" the screen in PhantomJS to make a PDF, otherwise resulting document pictures those charts mid-transition. Obviously I'd rather not have to wait.
PhantomJS uses print
media type to render PDFs, so it's very easy to disable any CSS3 animations (using media query), but I can't find any way of turning D3 transitions off (in other words - forcing a default transition duration of 0). I can detect print
media type in JavaScript, but can't find a good way of globally turning off animations in D3/NVD3... That's all I've got and it doesn't really do much:
var chart = nv.models.multiBarChart()
.tooltipContent(tooltip)
.stacked(true)
.showControls(false);
var duration = 1000; // default duration
if(window.matchMedia) {
if(window.matchMedia('print').matches) {
duration = 1; // duration for print
}
}
chart.transitionDuration(duration);
I want to turn NVD3 charts into PDF documents. Those charts are normally displayed in browser (I can't make a separate instance of each chart for print and for display), I got it all working using PhantomJS, but I have a problem that I can't seem to find a good solution to.
All NVD3 models use transitions, but only some of those transitions are affected by transitionDuration
option. Because of those transitions, I now have to use a timeout before "capturing" the screen in PhantomJS to make a PDF, otherwise resulting document pictures those charts mid-transition. Obviously I'd rather not have to wait.
PhantomJS uses print
media type to render PDFs, so it's very easy to disable any CSS3 animations (using media query), but I can't find any way of turning D3 transitions off (in other words - forcing a default transition duration of 0). I can detect print
media type in JavaScript, but can't find a good way of globally turning off animations in D3/NVD3... That's all I've got and it doesn't really do much:
var chart = nv.models.multiBarChart()
.tooltipContent(tooltip)
.stacked(true)
.showControls(false);
var duration = 1000; // default duration
if(window.matchMedia) {
if(window.matchMedia('print').matches) {
duration = 1; // duration for print
}
}
chart.transitionDuration(duration);
Share
Improve this question
asked Mar 23, 2014 at 11:07
jkondratowiczjkondratowicz
1,30115 silver badges21 bronze badges
2
- 1 I'm afraid you'd have to modify the NVD3 source code to take out the transitions. – Lars Kotthoff Commented Mar 23, 2014 at 13:42
- Too bad, I hoped at least D3 itself would provide some kind of a way to disable animations... – jkondratowicz Commented Mar 26, 2014 at 13:22
2 Answers
Reset to default 9As of NVD3 1.7.1 you can use the duration option:
chart.duration(0);
I cannot think of another solution than modify the nvd3 source. If you replace all the ocurrences of
transitionDuration = 250
for
transitionDuration = 0
in nv.d3.js it should work.
本文标签: javascriptHow to change transition duration globally in NVD3Stack Overflow
版权声明:本文标题:javascript - How to change transition duration globally in NVD3? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741438876a2378798.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论