tween_appear not respecting timerange values
sjmgarnier opened this issue · comments
Simon Garnier commented
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 :-)
Thomas Lin Pedersen commented
Thanks - yeah, that's a bug