Hi,
I'm using RStudio, an R language IDE, for developing an htmlwidget with d3. I'm trying to port my code to d3 v4, and I'm facing a curious problem: transitions don't work anymore. They work fine with d3 v3 in RStudio or with d3 v4 in a browser, but not with d3 v4 in RStudio.
After a bit of digging, it seems that the problem comes from the toolkit used by RStudio (GWT 2.7.0 as far as I can tell, but I don't know what kind and version of browser it is. The user agent displayed in the "about" dialog is currently "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/538.1 (KHTML, like Gecko) RStudio Safari/538.1 Qt/5.4.0").
There seems to be an inconsistency in the results returned by performance.now
and requestAnimationFrame
:
> performance.now()
26015828.386478003
> requestAnimationFrame(function(timestamp) {console.log(timestamp)})
1
1472136450436.1724
If I understand correctly, It seems that performance.now()
returns an high precision timestamp, whereas requestAnimationFrame
gives a number of milliseconds since epoch.
Due to this inconsistency, timers and transitions created by d3 don't work at all.
I've found a quick and dirty workaround inspired by this link. Adding the following code in d3-timer.js
just before the now()
function definition seems to work :
if (typeof performance === "object" && clock == performance && typeof requestAnimationFrame === "function") {
requestAnimationFrame(function(timestamp){
if (timestamp > 1e12) {
clock = Date;
setFrame = function(f) { requestAnimationFrame(function() { f(clock.now()); }); }
}
})
}
I could generate a pull request for this if you wish, but I'm really not sure the code quality is good enough, neither that this kind of workaround would really have a place in d3
code. Or there may be a better solution.
Sorry for this quite long issue, and thanks a lot for this awesome library and the no less awesome documentation and examples !