mirror of https://github.com/ppy/osu
Handle constant graphs better
This commit is contained in:
parent
8347ecf494
commit
5701b32bae
|
@ -69,6 +69,20 @@ public void TestTwoValues()
|
|||
AddAssert("Section is visible", () => section.Alpha == 1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestConstantValues()
|
||||
{
|
||||
AddStep("Load user", () => user.Value = user_with_constant_values);
|
||||
AddAssert("Section is visible", () => section.Alpha == 1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestConstantZeroValues()
|
||||
{
|
||||
AddStep("Load user", () => user.Value = user_with_zero_values);
|
||||
AddAssert("Section is visible", () => section.Alpha == 1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestFilledValues()
|
||||
{
|
||||
|
@ -117,10 +131,32 @@ public void TestMissingValues()
|
|||
}
|
||||
};
|
||||
|
||||
private static readonly User user_with_filled_values = new User
|
||||
private static readonly User user_with_constant_values = new User
|
||||
{
|
||||
Id = 5,
|
||||
MonthlyPlaycounts = new[]
|
||||
{
|
||||
new UserHistoryCount { Date = new DateTime(2010, 5, 1), Count = 5 },
|
||||
new UserHistoryCount { Date = new DateTime(2010, 6, 1), Count = 5 },
|
||||
new UserHistoryCount { Date = new DateTime(2010, 7, 1), Count = 5 }
|
||||
}
|
||||
};
|
||||
|
||||
private static readonly User user_with_zero_values = new User
|
||||
{
|
||||
Id = 6,
|
||||
MonthlyPlaycounts = new[]
|
||||
{
|
||||
new UserHistoryCount { Date = new DateTime(2010, 5, 1), Count = 0 },
|
||||
new UserHistoryCount { Date = new DateTime(2010, 6, 1), Count = 0 },
|
||||
new UserHistoryCount { Date = new DateTime(2010, 7, 1), Count = 0 }
|
||||
}
|
||||
};
|
||||
|
||||
private static readonly User user_with_filled_values = new User
|
||||
{
|
||||
Id = 7,
|
||||
MonthlyPlaycounts = new[]
|
||||
{
|
||||
new UserHistoryCount { Date = new DateTime(2010, 5, 1), Count = 1000 },
|
||||
new UserHistoryCount { Date = new DateTime(2010, 6, 1), Count = 20 },
|
||||
|
@ -134,7 +170,7 @@ public void TestMissingValues()
|
|||
|
||||
private static readonly User user_with_missing_values = new User
|
||||
{
|
||||
Id = 6,
|
||||
Id = 8,
|
||||
MonthlyPlaycounts = new[]
|
||||
{
|
||||
new UserHistoryCount { Date = new DateTime(2020, 1, 1), Count = 100 },
|
||||
|
|
|
@ -119,7 +119,11 @@ private void applyPath()
|
|||
|
||||
protected float GetYPosition(float value)
|
||||
{
|
||||
if (ActualMaxValue == ActualMinValue) return 0;
|
||||
if (ActualMaxValue == ActualMinValue)
|
||||
// show line at top if the only value on the graph is positive,
|
||||
// and at bottom if the only value on the graph is zero or negative.
|
||||
// just kind of makes most sense intuitively.
|
||||
return value > 1 ? 0 : 1;
|
||||
|
||||
return (ActualMaxValue - value) / (ActualMaxValue - ActualMinValue);
|
||||
}
|
||||
|
|
|
@ -124,8 +124,16 @@ private void createRowTicks()
|
|||
if (currentTick < min)
|
||||
continue;
|
||||
|
||||
float y = -Interpolation.ValueAt(currentTick, 0, 1f, min, max);
|
||||
addRowTick(y, currentTick);
|
||||
float y;
|
||||
// special-case the min == max case to match LineGraph.
|
||||
// lerp isn't really well-defined over a zero interval anyway.
|
||||
if (min == max)
|
||||
y = currentTick > 1 ? 1 : 0;
|
||||
else
|
||||
y = Interpolation.ValueAt(currentTick, 0, 1f, min, max);
|
||||
|
||||
// y axis is inverted in graph-like coordinates.
|
||||
addRowTick(-y, currentTick);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue