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