mirror of
https://github.com/ppy/osu
synced 2025-01-16 02:51:20 +00:00
Handle max==min in LineGraph.
This commit is contained in:
parent
9e3935a732
commit
fa98cfa9e5
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user