Make UserHistoryGraph non-abstract

This commit is contained in:
Andrei Zavatski 2020-03-10 00:50:12 +03:00
parent f6461dc5f8
commit 2f441baeac
4 changed files with 24 additions and 22 deletions

View File

@ -25,14 +25,15 @@ namespace osu.Game.Tests.Visual.Online
public TestSceneUserHistoryGraph() public TestSceneUserHistoryGraph()
{ {
TestGraph graph; UserHistoryGraph graph;
Add(graph = new TestGraph Add(graph = new UserHistoryGraph
{ {
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
Height = 200, Height = 200,
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,
TooltipCounterName = "Test"
}); });
var values = new[] var values = new[]
@ -60,15 +61,5 @@ namespace osu.Game.Tests.Visual.Online
AddStep("Set null values", () => graph.Values = null); AddStep("Set null values", () => graph.Values = null);
AddStep("Set empty values", () => graph.Values = Array.Empty<UserHistoryCount>()); AddStep("Set empty values", () => graph.Values = Array.Empty<UserHistoryCount>());
} }
private class TestGraph : UserHistoryGraph
{
protected override UserGraphTooltip GetTooltip() => new TestTooltip();
private class TestTooltip : HistoryGraphTooltip
{
protected override string TooltipCounterName => "Test Counter";
}
}
} }
} }

View File

@ -74,7 +74,10 @@ namespace osu.Game.Overlays.Profile.Header.Components
private class RankGraphTooltip : UserGraphTooltip private class RankGraphTooltip : UserGraphTooltip
{ {
protected override string TooltipCounterName => @"Global Ranking"; public RankGraphTooltip()
: base(@"Global Ranking")
{
}
public override bool SetContent(object content) public override bool SetContent(object content)
{ {

View File

@ -8,15 +8,22 @@ using static osu.Game.Users.User;
namespace osu.Game.Overlays.Profile.Sections.Historical namespace osu.Game.Overlays.Profile.Sections.Historical
{ {
public abstract class UserHistoryGraph : UserGraph<DateTime, long> public class UserHistoryGraph : UserGraph<DateTime, long>
{ {
public UserHistoryCount[] Values public UserHistoryCount[] Values
{ {
set => Data = value?.Select(v => new KeyValuePair<DateTime, long>(v.Date, v.Count)).ToArray(); set => Data = value?.Select(v => new KeyValuePair<DateTime, long>(v.Date, v.Count)).ToArray();
} }
/// <summary>
/// Text describing the value being plotted on the graph, which will be displayed as a prefix to the value in the <see cref="HistoryGraphTooltip"/>
/// </summary>
public string TooltipCounterName { get; set; } = @"Plays";
protected override float GetDataPointHeight(long playCount) => playCount; protected override float GetDataPointHeight(long playCount) => playCount;
protected override UserGraphTooltip GetTooltip() => new HistoryGraphTooltip(TooltipCounterName);
protected override object GetTooltipContent(DateTime date, long playCount) protected override object GetTooltipContent(DateTime date, long playCount)
{ {
return new TooltipDisplayContent return new TooltipDisplayContent
@ -26,8 +33,13 @@ namespace osu.Game.Overlays.Profile.Sections.Historical
}; };
} }
protected abstract class HistoryGraphTooltip : UserGraphTooltip protected class HistoryGraphTooltip : UserGraphTooltip
{ {
public HistoryGraphTooltip(string tooltipCounterName)
: base(tooltipCounterName)
{
}
public override bool SetContent(object content) public override bool SetContent(object content)
{ {
if (!(content is TooltipDisplayContent info)) if (!(content is TooltipDisplayContent info))

View File

@ -197,12 +197,7 @@ namespace osu.Game.Overlays.Profile
protected readonly OsuSpriteText Counter, BottomText; protected readonly OsuSpriteText Counter, BottomText;
private readonly Box background; private readonly Box background;
/// <summary> protected UserGraphTooltip(string tooltipCounterName)
/// Text which will be shown near the <see cref="Counter"/>.
/// </summary>
protected abstract string TooltipCounterName { get; }
protected UserGraphTooltip()
{ {
AutoSizeAxes = Axes.Both; AutoSizeAxes = Axes.Both;
Masking = true; Masking = true;
@ -225,12 +220,13 @@ namespace osu.Game.Overlays.Profile
{ {
AutoSizeAxes = Axes.Both, AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal, Direction = FillDirection.Horizontal,
Spacing = new Vector2(3, 0),
Children = new Drawable[] Children = new Drawable[]
{ {
new OsuSpriteText new OsuSpriteText
{ {
Font = OsuFont.GetFont(size: 12, weight: FontWeight.Bold), Font = OsuFont.GetFont(size: 12, weight: FontWeight.Bold),
Text = $"{TooltipCounterName} " Text = tooltipCounterName
}, },
Counter = new OsuSpriteText Counter = new OsuSpriteText
{ {