Handle max==min in LineGraph.

This commit is contained in:
Huo Yaoyuan 2017-06-16 14:47:14 +08:00
parent 9e3935a732
commit fa98cfa9e5
2 changed files with 17 additions and 14 deletions

View File

@ -23,8 +23,8 @@ namespace osu.Game.Graphics.UserInterface
/// </summary>
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);
}
}
}

View File

@ -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);