2020-11-14 23:48:47 +08:00
|
|
|
|
// 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.
|
|
|
|
|
|
2020-11-15 00:17:01 +08:00
|
|
|
|
using System.Collections.Generic;
|
2020-11-24 12:10:11 +08:00
|
|
|
|
using System.Linq;
|
2020-11-14 23:48:47 +08:00
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2021-07-17 22:20:37 +08:00
|
|
|
|
using osu.Framework.Localisation;
|
2021-11-04 17:02:44 +08:00
|
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
2020-11-14 23:48:47 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Profile.Sections.Historical
|
|
|
|
|
{
|
|
|
|
|
public abstract partial class ChartProfileSubsection : ProfileSubsection
|
|
|
|
|
{
|
2022-12-30 20:17:59 +08:00
|
|
|
|
private ProfileLineChart chart = null!;
|
2020-11-14 23:48:47 +08:00
|
|
|
|
|
2021-04-13 02:51:04 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Text describing the value being plotted on the graph, which will be displayed as a prefix to the value in the history graph tooltip.
|
|
|
|
|
/// </summary>
|
2021-07-17 22:20:37 +08:00
|
|
|
|
protected abstract LocalisableString GraphCounterName { get; }
|
2021-04-13 02:51:04 +08:00
|
|
|
|
|
2022-12-30 21:56:19 +08:00
|
|
|
|
protected ChartProfileSubsection(Bindable<UserProfile?> userProfile, LocalisableString headerText)
|
|
|
|
|
: base(userProfile, headerText)
|
2020-11-14 23:48:47 +08:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override Drawable CreateContent() => new Container
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Padding = new MarginPadding
|
|
|
|
|
{
|
|
|
|
|
Top = 10,
|
|
|
|
|
Left = 20,
|
|
|
|
|
Right = 40
|
|
|
|
|
},
|
2021-04-13 02:51:04 +08:00
|
|
|
|
Child = chart = new ProfileLineChart(GraphCounterName)
|
2020-11-14 23:48:47 +08:00
|
|
|
|
};
|
|
|
|
|
|
2020-11-22 07:13:35 +08:00
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
2022-12-30 21:56:19 +08:00
|
|
|
|
UserProfile.BindValueChanged(onUserChanged, true);
|
2020-11-22 07:13:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-12-30 21:56:19 +08:00
|
|
|
|
private void onUserChanged(ValueChangedEvent<UserProfile?> e)
|
2020-11-14 23:48:47 +08:00
|
|
|
|
{
|
2022-12-30 21:56:19 +08:00
|
|
|
|
var values = GetValues(e.NewValue?.User);
|
2020-11-14 23:48:47 +08:00
|
|
|
|
|
2020-11-24 12:12:04 +08:00
|
|
|
|
if (values == null || values.Length <= 1)
|
2020-11-14 23:48:47 +08:00
|
|
|
|
{
|
2020-11-24 12:12:04 +08:00
|
|
|
|
Hide();
|
2020-11-22 07:25:12 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
2020-11-15 00:17:01 +08:00
|
|
|
|
|
2020-11-24 12:12:04 +08:00
|
|
|
|
chart.Values = fillZeroValues(values);
|
|
|
|
|
Show();
|
2020-11-22 07:25:12 +08:00
|
|
|
|
}
|
2020-11-15 00:17:01 +08:00
|
|
|
|
|
2020-11-24 12:10:11 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Add entries for any missing months (filled with zero values).
|
|
|
|
|
/// </summary>
|
2021-11-04 17:02:44 +08:00
|
|
|
|
private APIUserHistoryCount[] fillZeroValues(APIUserHistoryCount[] historyEntries)
|
2020-11-22 07:25:12 +08:00
|
|
|
|
{
|
2021-11-04 17:02:44 +08:00
|
|
|
|
var filledHistoryEntries = new List<APIUserHistoryCount>();
|
2020-11-15 00:17:01 +08:00
|
|
|
|
|
2020-11-24 12:10:11 +08:00
|
|
|
|
foreach (var entry in historyEntries)
|
2020-11-22 07:25:12 +08:00
|
|
|
|
{
|
2020-11-24 12:10:11 +08:00
|
|
|
|
var lastFilled = filledHistoryEntries.LastOrDefault();
|
|
|
|
|
|
|
|
|
|
while (lastFilled?.Date.AddMonths(1) < entry.Date)
|
2020-11-15 00:17:01 +08:00
|
|
|
|
{
|
2021-11-04 17:02:44 +08:00
|
|
|
|
filledHistoryEntries.Add(lastFilled = new APIUserHistoryCount
|
2020-11-22 07:25:12 +08:00
|
|
|
|
{
|
|
|
|
|
Count = 0,
|
2020-11-24 12:10:11 +08:00
|
|
|
|
Date = lastFilled.Date.AddMonths(1)
|
2020-11-22 07:25:12 +08:00
|
|
|
|
});
|
2020-11-15 00:17:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-11-24 12:10:11 +08:00
|
|
|
|
filledHistoryEntries.Add(entry);
|
2020-11-14 23:48:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-11-24 12:10:11 +08:00
|
|
|
|
return filledHistoryEntries.ToArray();
|
2020-11-14 23:48:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-12-30 20:17:59 +08:00
|
|
|
|
protected abstract APIUserHistoryCount[]? GetValues(APIUser? user);
|
2020-11-14 23:48:47 +08:00
|
|
|
|
}
|
|
|
|
|
}
|