diff --git a/osu.Game/Graphics/UserInterface/LineGraph.cs b/osu.Game/Graphics/UserInterface/LineGraph.cs new file mode 100644 index 0000000000..36c63eb13c --- /dev/null +++ b/osu.Game/Graphics/UserInterface/LineGraph.cs @@ -0,0 +1,62 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System; +using System.Collections.Generic; +using System.Linq; +using OpenTK; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Lines; + +namespace osu.Game.Graphics.UserInterface +{ + public class LineGraph : Container + { + /// + /// Manually set the max value, otherwise will be used. + /// + public float? MaxValue { get; set; } + + /// + /// Manually set the min value, otherwise will be used. + /// + public float? MinValue { get; set; } + + private const float transform_duration = 250; + + /// + /// Hold an empty area if values are less. + /// + public int DefaultValueCount; + + private Path path; + + /// + /// A list of floats decides position of each line node. + /// + public IEnumerable Values + { + set + { + path?.Expire(); + Path localPath = new Path { RelativeSizeAxes = Axes.Both }; //capture a copy to avoid potential change + Add(path = localPath); + + var values = value.ToArray(); + int count = Math.Max(values.Length, DefaultValueCount); + + float max = values.Max(), min = values.Min(); + if (MaxValue > max) max = MaxValue.Value; + if (MinValue < min) min = MinValue.Value; + + for (int i = 0; i < values.Length; i++) + { + float x = (i + count - values.Length) / (float)(count - 1); + float y = (max - values[i]) / (max - min); + Scheduler.AddDelayed(() => localPath.AddVertex(new Vector2(x, y)), x * transform_duration); + } + } + } + } +} diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 88ce5e59dc..0fe30c0abc 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -80,6 +80,7 @@ +