vega / vega

A visualization grammar.

Home Page:https://vega.github.io/vega

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support for getTotalLength()

Giammaria opened this issue · comments

Has there been any thought into adding an expression similar to getTotalLength() for calculating the entire length of a path? This could be helpful for calculating dashArray to be used in conjunction with dashOffset and timers to create animated paths. Not entirely sure if this would be possible due to dependencies, but figured I'd ask.

Here is a basic example where I'm explicitly providing the static dashArray to create this effect. It would be nice if there was a way to have the total path length be calculated.

I think adding new methods to the expression language is easy and we should do it if there is a good use case.

Thanks @domoritz. Here's another resource breaking down the implementation. In conjunction with timers, I can see a use case where this new Vega expression with dashOffset and dashArray could all be used to animate path changes over time, providing another avenue for storytelling with time-series data. While I imagine implementing the expression in SVG would be relatively straightforward, I'm less sure about the level of effort involved to add the equivalent functionality in canvas.

In general, expression functions that are stand alone should be easy to add but anything that interacts with marks and rendering will be trickier to get right.