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;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using static osu.Game.Users.User;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Profile.Sections.Historical
|
|
|
|
|
{
|
2020-02-09 05:36:41 +08:00
|
|
|
|
public abstract class UserHistoryGraph : UserGraph<DateTime, long>
|
2020-02-08 05:10:17 +08:00
|
|
|
|
{
|
|
|
|
|
private UserHistoryCount[] values;
|
|
|
|
|
|
|
|
|
|
public UserHistoryCount[] Values
|
|
|
|
|
{
|
|
|
|
|
get => values;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
values = value;
|
|
|
|
|
updateValues(value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
|
{
|
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-02-09 05:36:41 +08:00
|
|
|
|
protected abstract class HistoryGraphTooltip : UserGraphTooltip
|
2020-02-08 05:10:17 +08:00
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|