thomasp85 / tweenr

Interpolate your data

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

tween_appear not respecting timerange values

sjmgarnier opened this issue · comments

Right now, setting the lower value of timerange doesn't affect the starting point of the tween. E.g.:

library(dplyr)
library(tweenr)

df <- data.frame(time = 0:10, val = 0:10)
tw_df <- tween_appear(df, "time", timerange = c(-1, 11), nframes = 100)

filter(tw_df, time == 0, .frame == 0)

returns

  time val .age .frame
1    0   0    0      0

when it should actually be returning

  time val .age .frame
1    0   0   -1      0

and

tw_df <- tween_appear(df, "time", timerange = c(1, 11), nframes = 100)

filter(tw_df, time == 0, .frame == 0)

returns

  time val .age .frame
1    0   0    0      0

when it should actually be returning

  time val .age .frame
1    0   0    1      0

I believe this can be solved in the tween_appear function by changing:

timepoint <- f * framelength

to

timepoint <- f * framelength + min(timerange)

In addition, I think that:

framelength <- diff(timerange)/nframes

should be changed to:

framelength <- diff(timerange)/(frames-1)

to ensure that the last frame ends exactly on the upper value of timerange.

Of course, I might also have completely missed the point of what the code is intended to do, in which case you can safely ignore all of the above :-)

Thanks - yeah, that's a bug