2020-02-08 05:10:17 +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.
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2020-03-21 21:35:04 +08:00
|
|
|
|
using JetBrains.Annotations;
|
2020-02-08 05:10:17 +08:00
|
|
|
|
using static osu.Game.Users.User;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Profile.Sections.Historical
|
|
|
|
|
{
|
2020-03-10 05:50:12 +08:00
|
|
|
|
public class UserHistoryGraph : UserGraph<DateTime, long>
|
2020-02-08 05:10:17 +08:00
|
|
|
|
{
|
2021-04-13 02:51:04 +08:00
|
|
|
|
private readonly string tooltipCounterName;
|
|
|
|
|
|
2020-03-21 21:35:04 +08:00
|
|
|
|
[CanBeNull]
|
2020-02-08 05:10:17 +08:00
|
|
|
|
public UserHistoryCount[] Values
|
|
|
|
|
{
|
2020-03-10 00:20:06 +08:00
|
|
|
|
set => Data = value?.Select(v => new KeyValuePair<DateTime, long>(v.Date, v.Count)).ToArray();
|
2020-02-08 05:10:17 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-13 02:51:04 +08:00
|
|
|
|
public UserHistoryGraph(string tooltipCounterName)
|
|
|
|
|
{
|
|
|
|
|
this.tooltipCounterName = tooltipCounterName;
|
|
|
|
|
}
|
2020-03-10 05:50:12 +08:00
|
|
|
|
|
2020-02-13 03:19:20 +08:00
|
|
|
|
protected override float GetDataPointHeight(long playCount) => playCount;
|
|
|
|
|
|
2021-04-13 02:51:04 +08:00
|
|
|
|
protected override UserGraphTooltip GetTooltip() => new HistoryGraphTooltip(tooltipCounterName);
|
2020-03-10 05:50:12 +08:00
|
|
|
|
|
2020-02-13 02:15:37 +08:00
|
|
|
|
protected override object GetTooltipContent(DateTime date, long playCount)
|
2020-02-08 05:10:17 +08:00
|
|
|
|
{
|
|
|
|
|
return new TooltipDisplayContent
|
|
|
|
|
{
|
2021-04-13 12:59:13 +08:00
|
|
|
|
Name = tooltipCounterName,
|
2020-02-13 02:15:37 +08:00
|
|
|
|
Count = playCount.ToString("N0"),
|
|
|
|
|
Date = date.ToString("MMMM yyyy")
|
2020-02-08 05:10:17 +08:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-10 05:50:12 +08:00
|
|
|
|
protected class HistoryGraphTooltip : UserGraphTooltip
|
2020-02-08 05:10:17 +08:00
|
|
|
|
{
|
2021-04-13 12:59:13 +08:00
|
|
|
|
private readonly string tooltipCounterName;
|
|
|
|
|
|
2020-03-10 05:50:12 +08:00
|
|
|
|
public HistoryGraphTooltip(string tooltipCounterName)
|
|
|
|
|
: base(tooltipCounterName)
|
|
|
|
|
{
|
2021-04-13 12:59:13 +08:00
|
|
|
|
this.tooltipCounterName = tooltipCounterName;
|
2020-03-10 05:50:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-02-08 05:10:17 +08:00
|
|
|
|
public override bool SetContent(object content)
|
|
|
|
|
{
|
2021-04-13 12:59:13 +08:00
|
|
|
|
if (!(content is TooltipDisplayContent info) || info.Name != tooltipCounterName)
|
2020-02-08 05:10:17 +08:00
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
Counter.Text = info.Count;
|
|
|
|
|
BottomText.Text = info.Date;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class TooltipDisplayContent
|
|
|
|
|
{
|
2021-04-13 12:59:13 +08:00
|
|
|
|
public string Name;
|
2020-02-08 05:10:17 +08:00
|
|
|
|
public string Count;
|
|
|
|
|
public string Date;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|