From fa98cfa9e5e32ed52f2538ddce1179e252fcfbfc Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Fri, 16 Jun 2017 14:47:14 +0800 Subject: [PATCH] Handle max==min in LineGraph. --- osu.Game/Graphics/UserInterface/LineGraph.cs | 12 +++++++++--- osu.Game/Users/Profile/RankChart.cs | 19 ++++++++----------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/LineGraph.cs b/osu.Game/Graphics/UserInterface/LineGraph.cs index 02e8a8329a..28b62ff957 100644 --- a/osu.Game/Graphics/UserInterface/LineGraph.cs +++ b/osu.Game/Graphics/UserInterface/LineGraph.cs @@ -23,8 +23,8 @@ namespace osu.Game.Graphics.UserInterface /// public float? MinValue { get; set; } - public float? ActualMaxValue { get; private set; } - public float? ActualMinValue { get; private set; } + public float ActualMaxValue { get; private set; } = float.NaN; + public float ActualMinValue { get; private set; } = float.NaN; private const double transform_duration = 500; @@ -87,10 +87,16 @@ namespace osu.Game.Graphics.UserInterface for (int i = 0; i < values.Length; i++) { float x = (i + count - values.Length) / (float)(count - 1) * DrawWidth - 1; - float y = (max - values[i]) / (max - min) * DrawHeight - 1; + float y = GetYPosition(values[i]) * DrawHeight - 1; // the -1 is for inner offset in path (actually -PathWidth) path.AddVertex(new Vector2(x, y)); } } + + protected float GetYPosition(float value) + { + if (ActualMaxValue == ActualMinValue) return 0; + return (ActualMaxValue - value) / (ActualMaxValue - ActualMinValue); + } } } diff --git a/osu.Game/Users/Profile/RankChart.cs b/osu.Game/Users/Profile/RankChart.cs index fde7379628..8581635cd7 100644 --- a/osu.Game/Users/Profile/RankChart.cs +++ b/osu.Game/Users/Profile/RankChart.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using System.Diagnostics; using System.Linq; using OpenTK; using osu.Framework.Allocation; @@ -93,9 +92,12 @@ namespace osu.Game.Users.Profile { graph.Colour = colours.Yellow; - // use logarithmic coordinates - graph.Values = ranks.Select(x => -(float)Math.Log(x)); - graph.ResetBall(); + if (user.Statistics.Rank > 0) + { + // use logarithmic coordinates + graph.Values = ranks.Select(x => -(float)Math.Log(x)); + graph.ResetBall(); + } } public override bool Invalidate(Invalidation invalidation = Invalidation.All, Drawable source = null, bool shallPropagate = true) @@ -136,9 +138,7 @@ namespace osu.Game.Users.Profile public void ResetBall() { - Trace.Assert(ActualMaxValue.HasValue); - Trace.Assert(ActualMinValue.HasValue); - ball.MoveTo(new Vector2(1, ((ActualMaxValue - Values.Last()) / (ActualMaxValue - ActualMinValue)).Value), ballShown ? transform_duration : 0, EasingTypes.OutQuint); + ball.MoveTo(new Vector2(1, GetYPosition(Values.Last())), ballShown ? transform_duration : 0, EasingTypes.OutQuint); ball.Show(); BallRelease(); ballShown = true; @@ -155,10 +155,7 @@ namespace osu.Game.Users.Profile if (index >= count - values.Count) { int i = index + values.Count - count; - float value = values[i]; - Trace.Assert(ActualMaxValue.HasValue); - Trace.Assert(ActualMinValue.HasValue); - float y = ((ActualMaxValue - value) / (ActualMaxValue - ActualMinValue)).Value; + float y = GetYPosition(values[i]); if (Math.Abs(y * DrawHeight - position.Y) <= 8f) { ball.MoveTo(new Vector2(index / (float)(count - 1), y), transform_duration, EasingTypes.OutQuint);