mirror of
https://github.com/osukey/osukey.git
synced 2025-07-01 16:29:58 +09:00
Implement UserHistoryGraph component
This commit is contained in:
112
osu.Game.Tests/Visual/Online/TestSceneUserHistoryGraph.cs
Normal file
112
osu.Game.Tests/Visual/Online/TestSceneUserHistoryGraph.cs
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using osu.Game.Overlays.Profile.Sections.Historical;
|
||||||
|
using osu.Game.Overlays.Profile;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using static osu.Game.Users.User;
|
||||||
|
using osu.Game.Overlays;
|
||||||
|
using osu.Framework.Allocation;
|
||||||
|
|
||||||
|
namespace osu.Game.Tests.Visual.Online
|
||||||
|
{
|
||||||
|
public class TestSceneUserHistoryGraph : OsuTestScene
|
||||||
|
{
|
||||||
|
public override IReadOnlyList<Type> RequiredTypes => new[]
|
||||||
|
{
|
||||||
|
typeof(UserHistoryGraph),
|
||||||
|
typeof(UserGraph<,>),
|
||||||
|
};
|
||||||
|
|
||||||
|
[Cached]
|
||||||
|
private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Pink);
|
||||||
|
|
||||||
|
public TestSceneUserHistoryGraph()
|
||||||
|
{
|
||||||
|
UserHistoryGraph graph;
|
||||||
|
|
||||||
|
Add(graph = new UserHistoryGraph("Counter Name")
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.X,
|
||||||
|
Height = 200,
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
});
|
||||||
|
|
||||||
|
var values = new[]
|
||||||
|
{
|
||||||
|
new UserHistoryCount
|
||||||
|
{
|
||||||
|
Date = new DateTime(2000, 1, 1),
|
||||||
|
Count = 10,
|
||||||
|
},
|
||||||
|
new UserHistoryCount
|
||||||
|
{
|
||||||
|
Date = new DateTime(2000, 2, 1),
|
||||||
|
Count = 20,
|
||||||
|
},
|
||||||
|
new UserHistoryCount
|
||||||
|
{
|
||||||
|
Date = new DateTime(2000, 3, 1),
|
||||||
|
Count = 100,
|
||||||
|
},
|
||||||
|
new UserHistoryCount
|
||||||
|
{
|
||||||
|
Date = new DateTime(2000, 4, 1),
|
||||||
|
Count = 15,
|
||||||
|
},
|
||||||
|
new UserHistoryCount
|
||||||
|
{
|
||||||
|
Date = new DateTime(2000, 5, 1),
|
||||||
|
Count = 30,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var moreValues = new[]
|
||||||
|
{
|
||||||
|
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, 7, 1),
|
||||||
|
Count = 20000,
|
||||||
|
},
|
||||||
|
new UserHistoryCount
|
||||||
|
{
|
||||||
|
Date = new DateTime(2010, 8, 1),
|
||||||
|
Count = 30,
|
||||||
|
},
|
||||||
|
new UserHistoryCount
|
||||||
|
{
|
||||||
|
Date = new DateTime(2010, 9, 1),
|
||||||
|
Count = 50,
|
||||||
|
},
|
||||||
|
new UserHistoryCount
|
||||||
|
{
|
||||||
|
Date = new DateTime(2010, 10, 1),
|
||||||
|
Count = 2000,
|
||||||
|
},
|
||||||
|
new UserHistoryCount
|
||||||
|
{
|
||||||
|
Date = new DateTime(2010, 11, 1),
|
||||||
|
Count = 2100,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
AddStep("Set fake values", () => graph.Values = values);
|
||||||
|
AddStep("Set more values", () => graph.Values = moreValues);
|
||||||
|
AddStep("Set null values", () => graph.Values = null);
|
||||||
|
AddStep("Set empty values", () => graph.Values = Array.Empty<UserHistoryCount>());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -29,8 +29,6 @@ namespace osu.Game.Overlays.Profile.Header.Components
|
|||||||
Text = "No recent plays",
|
Text = "No recent plays",
|
||||||
Font = OsuFont.GetFont(size: 12, weight: FontWeight.Regular)
|
Font = OsuFont.GetFont(size: 12, weight: FontWeight.Regular)
|
||||||
});
|
});
|
||||||
|
|
||||||
Graph.Alpha = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void LoadComplete()
|
protected override void LoadComplete()
|
||||||
|
@ -0,0 +1,90 @@
|
|||||||
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using static osu.Game.Users.User;
|
||||||
|
|
||||||
|
namespace osu.Game.Overlays.Profile.Sections.Historical
|
||||||
|
{
|
||||||
|
public class UserHistoryGraph : UserGraph<DateTime, long>
|
||||||
|
{
|
||||||
|
private UserHistoryCount[] values;
|
||||||
|
|
||||||
|
public UserHistoryCount[] Values
|
||||||
|
{
|
||||||
|
get => values;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
values = value;
|
||||||
|
updateValues(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly string tooltipCounterName;
|
||||||
|
|
||||||
|
public UserHistoryGraph(string tooltipCounterName)
|
||||||
|
{
|
||||||
|
this.tooltipCounterName = tooltipCounterName;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateValues(UserHistoryCount[] values)
|
||||||
|
{
|
||||||
|
if (values == null || !values.Any())
|
||||||
|
{
|
||||||
|
Graph.FadeOut(FADE_DURATION, Easing.Out);
|
||||||
|
Data = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Data = values.Select(v => new KeyValuePair<DateTime, long>(v.Date, v.Count)).ToArray();
|
||||||
|
|
||||||
|
if (values.Length > 1)
|
||||||
|
{
|
||||||
|
Graph.DefaultValueCount = Data.Length;
|
||||||
|
Graph.Values = Data.Select(x => (float)x.Value);
|
||||||
|
Graph.FadeIn(FADE_DURATION, Easing.Out);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override object GetTooltipContent()
|
||||||
|
{
|
||||||
|
if (!Data?.Any() ?? true)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return new TooltipDisplayContent
|
||||||
|
{
|
||||||
|
Count = Data[DataIndex].Value.ToString("N0"),
|
||||||
|
Date = Data[DataIndex].Key.ToString("MMMM yyyy")
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override UserGraphTooltip GetTooltip() => new HistoryGraphTooltip(tooltipCounterName);
|
||||||
|
|
||||||
|
private class HistoryGraphTooltip : UserGraphTooltip
|
||||||
|
{
|
||||||
|
public HistoryGraphTooltip(string topText)
|
||||||
|
: base(topText)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool SetContent(object content)
|
||||||
|
{
|
||||||
|
if (!(content is TooltipDisplayContent info))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
Counter.Text = info.Count;
|
||||||
|
BottomText.Text = info.Date;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class TooltipDisplayContent
|
||||||
|
{
|
||||||
|
public string Count;
|
||||||
|
public string Date;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -30,6 +30,7 @@ namespace osu.Game.Overlays.Profile
|
|||||||
Add(Graph = new RankChartLineGraph
|
Add(Graph = new RankChartLineGraph
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
Alpha = 0
|
||||||
});
|
});
|
||||||
|
|
||||||
Graph.OnBallMove += i => DataIndex = i;
|
Graph.OnBallMove += i => DataIndex = i;
|
||||||
|
Reference in New Issue
Block a user