I’m curious how Mike Bostock was able to create a vertical line that follows your mouse cursor in such a smooth way. If you look here http://square.github.com/cubism/ , you can see what I’m talking about.
Take a look at a quick example I just made here: http://jsfiddle.net/zbfUq/
There are many times where the line in my example actually disappears. Is there some sort of position interpolation he is doing to create a smooth translation between two points that are not being recorded? If so, anyone know how to do something like that?
I’m guessing he’s using a d3.js
transition, see https://github.com/mbostock/d3/wiki/Transitions, to basically animate the line (and values) from the current line position to where the mouse cursor currently is. You can tell he isn’t trying to just follow the mouse curse because if you move the cursor quickly you can see the line lag behind a bit, this is the animation time of the transition.I put together a quick example of how this is done in d3.js at http://jsfiddle.net/2N2rt/4/. I didn’t play around with it much so I’m sure you can get it even smoother, but this seemed pretty good.
Also keep in mind that
svgelements tend to animate a lot more smoothly thanDOMelements. Here’s a puresvgexample ( http://jsfiddle.net/2N2rt/10/ ).Again, this is just a quick example but hopefully it gives you some ideas.