robinhood / spark

A simple Android sparkline chart view.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Request] New animation

kojimasuki opened this issue · comments

First of all thank you for developing this lib!

I'm trying to reproduce the heart rate "spark" in the gif below.

Any plans to implement an animation like this? Have you seen anything similiar? Or maybe if you could point me in the right direction on how to implement this. I don't even know where to start.

Thank you!

ezgif-3-107271d80a

Check out the interface SparkAnimator which allows you to bring whatever Animator you want to your SparkView.

Hi @kojimasuki, this effect should be achievable with Spark. I'm not sure where your data is coming from, but assuming you get a callback with the new heart rate value every time it updates:

interface HeartRateCallback {
  void onHearRateUpdated(float heartRate);
}

I'd recommend storing the heartRate into a list of size, say 100. The first 100 values will fill up this list, then each value after that will push out the earliest value. Each time you get a new value, set this list on your SparkAdapter, and call sparkAdapter.notifyDataSetChanged(). This will trigger a redraw of your data. This should result in something close to the animation above.

And as @naturalwarren said, you can look into setting a custom SparkAnimator to have more control over how the sparkline animates each time you call notifyDataSetChanged(). By default it will just redraw the new sparkline immediately, but you could do a translation between the old path and the new path to make it a little less jerky. But I'd guess that the default behavior is pretty close to the above effect, so try that out first.

Hope that helps!

Thanks for the help.

I just removed the line below from the default LineSparkAnimator and it worked perfectly! This could maybe turn into a config variable (redraw line every update yes/no)?

linePath.reset();