mirror of
https://github.com/osukey/osukey.git
synced 2025-07-01 08:20:00 +09:00
Handle constant graphs better
This commit is contained in:
@ -69,6 +69,20 @@ namespace osu.Game.Tests.Visual.Online
|
|||||||
AddAssert("Section is visible", () => section.Alpha == 1);
|
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]
|
[Test]
|
||||||
public void TestFilledValues()
|
public void TestFilledValues()
|
||||||
{
|
{
|
||||||
@ -117,10 +131,32 @@ namespace osu.Game.Tests.Visual.Online
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private static readonly User user_with_filled_values = new User
|
private static readonly User user_with_constant_values = new User
|
||||||
{
|
{
|
||||||
Id = 5,
|
Id = 5,
|
||||||
MonthlyPlaycounts = new[]
|
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, 5, 1), Count = 1000 },
|
||||||
new UserHistoryCount { Date = new DateTime(2010, 6, 1), Count = 20 },
|
new UserHistoryCount { Date = new DateTime(2010, 6, 1), Count = 20 },
|
||||||
@ -134,7 +170,7 @@ namespace osu.Game.Tests.Visual.Online
|
|||||||
|
|
||||||
private static readonly User user_with_missing_values = new User
|
private static readonly User user_with_missing_values = new User
|
||||||
{
|
{
|
||||||
Id = 6,
|
Id = 8,
|
||||||
MonthlyPlaycounts = new[]
|
MonthlyPlaycounts = new[]
|
||||||
{
|
{
|
||||||
new UserHistoryCount { Date = new DateTime(2020, 1, 1), Count = 100 },
|
new UserHistoryCount { Date = new DateTime(2020, 1, 1), Count = 100 },
|
||||||
|
@ -119,7 +119,11 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
|
|
||||||
protected float GetYPosition(float value)
|
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);
|
return (ActualMaxValue - value) / (ActualMaxValue - ActualMinValue);
|
||||||
}
|
}
|
||||||
|
@ -124,8 +124,16 @@ namespace osu.Game.Overlays.Profile.Sections.Historical
|
|||||||
if (currentTick < min)
|
if (currentTick < min)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
float y = -Interpolation.ValueAt(currentTick, 0, 1f, min, max);
|
float y;
|
||||||
addRowTick(y, currentTick);
|
// 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user