1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-07 00:17:21 +08:00

71 lines
2.2 KiB
C#
Raw Normal View History

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