mirror of
https://github.com/ppy/osu.git
synced 2025-02-15 23:03:02 +08:00
Encapsulate base graph further
This commit is contained in:
parent
2b0bdd1db5
commit
9edddbaf46
@ -39,27 +39,29 @@ namespace osu.Game.Overlays.Profile.Header.Components
|
|||||||
|
|
||||||
private void updateStatistics(UserStatistics statistics)
|
private void updateStatistics(UserStatistics statistics)
|
||||||
{
|
{
|
||||||
placeholder.FadeIn(FADE_DURATION, Easing.Out);
|
int[] userRanks = statistics?.RankHistory?.Data;
|
||||||
|
|
||||||
if (statistics?.Ranks.Global == null)
|
if (userRanks == null)
|
||||||
{
|
{
|
||||||
Graph.FadeOut(FADE_DURATION, Easing.Out);
|
|
||||||
Data = null;
|
Data = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int[] userRanks = statistics.RankHistory?.Data ?? new[] { statistics.Ranks.Global.Value };
|
|
||||||
Data = userRanks.Select((x, index) => new KeyValuePair<int, int>(index, x)).Where(x => x.Value != 0).ToArray();
|
Data = userRanks.Select((x, index) => new KeyValuePair<int, int>(index, x)).Where(x => x.Value != 0).ToArray();
|
||||||
|
|
||||||
if (Data.Length > 1)
|
|
||||||
{
|
|
||||||
placeholder.FadeOut(FADE_DURATION, Easing.Out);
|
|
||||||
|
|
||||||
Graph.DefaultValueCount = Data.Length;
|
|
||||||
Graph.Values = Data.Select(x => -MathF.Log(x.Value));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Graph.FadeTo(Data.Length > 1 ? 1 : 0, FADE_DURATION, Easing.Out);
|
protected override float GetDataPointHeight(int rank) => -MathF.Log(rank);
|
||||||
|
|
||||||
|
protected override void ShowGraph()
|
||||||
|
{
|
||||||
|
base.ShowGraph();
|
||||||
|
placeholder.FadeOut(FADE_DURATION, Easing.Out);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void HideGraph()
|
||||||
|
{
|
||||||
|
base.HideGraph();
|
||||||
|
placeholder.FadeIn(FADE_DURATION, Easing.Out);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override object GetTooltipContent(int index, int rank)
|
protected override object GetTooltipContent(int index, int rank)
|
||||||
|
@ -4,43 +4,27 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using osu.Framework.Graphics;
|
|
||||||
using static osu.Game.Users.User;
|
using static osu.Game.Users.User;
|
||||||
|
|
||||||
namespace osu.Game.Overlays.Profile.Sections.Historical
|
namespace osu.Game.Overlays.Profile.Sections.Historical
|
||||||
{
|
{
|
||||||
public abstract class UserHistoryGraph : UserGraph<DateTime, long>
|
public abstract class UserHistoryGraph : UserGraph<DateTime, long>
|
||||||
{
|
{
|
||||||
private UserHistoryCount[] values;
|
|
||||||
|
|
||||||
public UserHistoryCount[] Values
|
public UserHistoryCount[] Values
|
||||||
{
|
{
|
||||||
get => values;
|
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
values = value;
|
if (value == null)
|
||||||
updateValues(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateValues(UserHistoryCount[] values)
|
|
||||||
{
|
{
|
||||||
if (values == null || !values.Any())
|
|
||||||
{
|
|
||||||
Graph.FadeOut(FADE_DURATION, Easing.Out);
|
|
||||||
Data = null;
|
Data = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Data = values.Select(v => new KeyValuePair<DateTime, long>(v.Date, v.Count)).ToArray();
|
Data = value.Select(v => new KeyValuePair<DateTime, long>(v.Date, v.Count)).ToArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (values.Length > 1)
|
protected override float GetDataPointHeight(long playCount) => playCount;
|
||||||
{
|
|
||||||
Graph.DefaultValueCount = Data.Length;
|
|
||||||
Graph.Values = Data.Select(x => (float)x.Value);
|
|
||||||
Graph.FadeIn(FADE_DURATION, Easing.Out);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override object GetTooltipContent(DateTime date, long playCount)
|
protected override object GetTooltipContent(DateTime date, long playCount)
|
||||||
{
|
{
|
||||||
|
@ -21,54 +21,83 @@ namespace osu.Game.Overlays.Profile
|
|||||||
{
|
{
|
||||||
protected const float FADE_DURATION = 150;
|
protected const float FADE_DURATION = 150;
|
||||||
|
|
||||||
protected readonly UserLineGraph Graph;
|
private readonly UserLineGraph graph;
|
||||||
protected KeyValuePair<TKey, TValue>[] Data;
|
private KeyValuePair<TKey, TValue>[] data;
|
||||||
private int dataIndex;
|
private int dataIndex;
|
||||||
|
|
||||||
protected UserGraph()
|
protected UserGraph()
|
||||||
{
|
{
|
||||||
Add(Graph = new UserLineGraph
|
data = Array.Empty<KeyValuePair<TKey, TValue>>();
|
||||||
|
|
||||||
|
Add(graph = new UserLineGraph
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
Alpha = 0
|
Alpha = 0
|
||||||
});
|
});
|
||||||
|
|
||||||
Graph.OnBallMove += i => dataIndex = i;
|
graph.OnBallMove += i => dataIndex = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(OsuColour colours)
|
private void load(OsuColour colours)
|
||||||
{
|
{
|
||||||
Graph.LineColour = colours.Yellow;
|
graph.LineColour = colours.Yellow;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override bool OnHover(HoverEvent e)
|
protected override bool OnHover(HoverEvent e)
|
||||||
{
|
{
|
||||||
if (Data?.Length > 1)
|
if (data.Length <= 1)
|
||||||
{
|
return base.OnHover(e);
|
||||||
Graph.UpdateBallPosition(e.MousePosition.X);
|
|
||||||
Graph.ShowBar();
|
graph.UpdateBallPosition(e.MousePosition.X);
|
||||||
}
|
graph.ShowBar();
|
||||||
|
|
||||||
return base.OnHover(e);
|
return base.OnHover(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override bool OnMouseMove(MouseMoveEvent e)
|
protected override bool OnMouseMove(MouseMoveEvent e)
|
||||||
{
|
{
|
||||||
if (Data?.Length > 1)
|
if (data.Length > 1)
|
||||||
Graph.UpdateBallPosition(e.MousePosition.X);
|
graph.UpdateBallPosition(e.MousePosition.X);
|
||||||
|
|
||||||
return base.OnMouseMove(e);
|
return base.OnMouseMove(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnHoverLost(HoverLostEvent e)
|
protected override void OnHoverLost(HoverLostEvent e)
|
||||||
{
|
{
|
||||||
if (Data?.Length > 1)
|
if (data.Length > 1)
|
||||||
Graph.HideBar();
|
graph.HideBar();
|
||||||
|
|
||||||
base.OnHoverLost(e);
|
base.OnHoverLost(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected KeyValuePair<TKey, TValue>[] Data
|
||||||
|
{
|
||||||
|
set
|
||||||
|
{
|
||||||
|
value ??= Array.Empty<KeyValuePair<TKey, TValue>>();
|
||||||
|
data = value;
|
||||||
|
redrawGraph();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void redrawGraph()
|
||||||
|
{
|
||||||
|
if (data.Length == 0)
|
||||||
|
{
|
||||||
|
HideGraph();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
graph.DefaultValueCount = data.Length;
|
||||||
|
graph.Values = data.Select(pair => GetDataPointHeight(pair.Value)).ToArray();
|
||||||
|
ShowGraph();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract float GetDataPointHeight(TValue value);
|
||||||
|
protected virtual void ShowGraph() => graph.FadeIn(FADE_DURATION, Easing.Out);
|
||||||
|
protected virtual void HideGraph() => graph.FadeOut(FADE_DURATION, Easing.Out);
|
||||||
|
|
||||||
public ITooltip GetCustomTooltip() => GetTooltip();
|
public ITooltip GetCustomTooltip() => GetTooltip();
|
||||||
|
|
||||||
protected abstract UserGraphTooltip GetTooltip();
|
protected abstract UserGraphTooltip GetTooltip();
|
||||||
@ -77,10 +106,10 @@ namespace osu.Game.Overlays.Profile
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (Data == null || Data.Length == 0)
|
if (data.Length == 0)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
var (key, value) = Data[dataIndex];
|
var (key, value) = data[dataIndex];
|
||||||
return GetTooltipContent(key, value);
|
return GetTooltipContent(key, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user