These are chat archives for oxyplot/oxyplot

15th
Feb 2016
Geert van Horrik
@GeertvanHorrik
Feb 15 2016 09:20
@objorke that's what I thought. But I was thinking of a simple extension method that draws an invisible (transparent) series for the right values (so the axis will be correct). After that I can simply increase the values with a simple timer to fake an animation. Will post the extension method once it's done.
Geert van Horrik
@GeertvanHorrik
Feb 15 2016 15:32
Here is the extension method, but it doesn't seem the InvalidatePlot(true) actually causes a redraw (On Windows 10 at least, need to check other platforms):
public static async void AnimateSeries(this PlotModel plotModel, ItemsSeries series, double? minimumValue = null, TimeSpan duration = default(TimeSpan), double animationFrameDurationInMs = 15)
{
    Argument.IsNotNull(() => plotModel);
    Argument.IsNotNull(() => series);

    if (minimumValue == null)
    {
        var axis = plotModel.DefaultYAxis;
        if (axis != null)
        {
            minimumValue = axis.Minimum;
        }
        else
        {
            minimumValue = 0d;
        }
    }

    if (duration == default(TimeSpan))
    {
        duration = TimeSpan.FromMilliseconds(300);
    }

    var animationDuration = TimeSpan.FromMilliseconds(animationFrameDurationInMs);
    var animationFrames = duration.TotalMilliseconds / animationFrameDurationInMs;

    var valuesToAnimate = new List<Tuple<double, double, double>>();

    var items = series.ItemsSource.Cast<object>().ToList();

    foreach (var point in items)
    {
        var measurePoint = point as MeasurePoint;
        if (measurePoint != null)
        {
            var delta = measurePoint.Y - minimumValue.Value;
            var animationStep = delta / animationFrames;

            valuesToAnimate.Add(new Tuple<double, double, double>(minimumValue.Value, animationStep, measurePoint.Y));

            measurePoint.Y = minimumValue.Value;
        }
    }

    // First frame animation
    await Task.Delay(animationDuration);

    for (var i = 0; i < animationFrames; i++)
    {
        Log.Debug("Animating frame '{0}'", i + 1);

        for (int j = 0; j < items.Count; j++)
        {
            var measurePoint = items[j] as MeasurePoint;
            if (measurePoint != null)
            {
                var animationInfo = valuesToAnimate[j];

                var oldY = measurePoint.Y;

                if (i < animationFrames - 1)
                {
                    measurePoint.Y += animationInfo.Item2;
                }
                else
                {
                    measurePoint.Y = animationInfo.Item3;
                }

                var newY = measurePoint.Y;

                //Log.Debug("  Animated Y from '{0}' => '{1}'", oldY, newY);
            }
        }

        plotModel.InvalidatePlot(true);
        await Task.Delay(animationDuration);
    }
Geert van Horrik
@GeertvanHorrik
Feb 15 2016 16:57
oxyplot_animations.gif
Wrote an example app, will PR this
Johan Larsson
@JohanLarsson
Feb 15 2016 17:01
nice
Alberto Rodríguez
@beto-rodriguez
Feb 15 2016 17:11
@GeertvanHorrik interesting, this could work when you have small data, I think performance won't we nice, also it would be much harder for an sp line.
Geert van Horrik
@GeertvanHorrik
Feb 15 2016 17:11
probably, but as @objorke said: this won't be part of OxyPlot itself, but it might help some users that want to add simple animations to their graphs. This is all extension methods so it can be useful out of the box.
Geert van Horrik
@GeertvanHorrik
Feb 15 2016 19:27
Note that each type of series require their own animations (LineSeries would probably need to be animated from left => right, etc). But for now bar series can be animated easily.