From 2d8277f4137868e91d620e24d881fc4c63c092f5 Mon Sep 17 00:00:00 2001 From: HoutarouOreki Date: Thu, 26 Jul 2018 17:02:51 +0200 Subject: [PATCH] Plotting the chart 1 --- osu.Game/Overlays/Changelog/ChangelogChart.cs | 54 ++++++++++++++++--- 1 file changed, 46 insertions(+), 8 deletions(-) diff --git a/osu.Game/Overlays/Changelog/ChangelogChart.cs b/osu.Game/Overlays/Changelog/ChangelogChart.cs index d965651e27..0141a3b3e1 100644 --- a/osu.Game/Overlays/Changelog/ChangelogChart.cs +++ b/osu.Game/Overlays/Changelog/ChangelogChart.cs @@ -3,13 +3,16 @@ using osu.Framework.Allocation; using osu.Framework.Graphics; +using osu.Framework.Graphics.Colour; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Sprites; +using osu.Framework.Logging; using osu.Game.Graphics; using osu.Game.Online.API; using osu.Game.Online.API.Requests; using osu.Game.Online.API.Requests.Responses; +using System; namespace osu.Game.Overlays.Changelog { @@ -19,7 +22,7 @@ namespace osu.Game.Overlays.Changelog private const float transition_duration = 300; // why make the child buffered? https://streamable.com/swbdj - private readonly BufferedContainer container; + private readonly Container container; private readonly Box background; private APIAccess api; @@ -27,17 +30,17 @@ namespace osu.Game.Overlays.Changelog { RelativeSizeAxes = Axes.X; AutoSizeAxes = Axes.Y; - Child = container = new BufferedContainer + Child = container = new Container { RelativeSizeAxes = Axes.X, Height = height, Children = new Drawable[] { - background = new Box - { - Colour = OsuColour.Gray(0), - RelativeSizeAxes = Axes.Both, - }, + //background = new Box + //{ + // Colour = OsuColour.Gray(0), + // RelativeSizeAxes = Axes.Both, + //}, new SpriteText { Text = "Graph Placeholder", @@ -63,8 +66,8 @@ namespace osu.Game.Overlays.Changelog { if (!isEmpty(chartInfo)) { - background.Colour = StreamColour.FromStreamName(updateStreamName); container.MoveToY(0, transition_duration, Easing.InOutQuad).FadeIn(transition_duration); + plotChart(chartInfo, StreamColour.FromStreamName(updateStreamName)); } else container.MoveToY(-height, transition_duration, Easing.InOutQuad).FadeOut(transition_duration); @@ -89,5 +92,40 @@ namespace osu.Game.Overlays.Changelog req.Success += res => showChart(res); api.Queue(req); } + + // this could probably be combined with isEmpty, todo + private float getMaxUserCount(APIChangelogChart changelogChartInfo) + { + var maxUserCount = 0l; + foreach (BuildHistory build in changelogChartInfo.BuildHistory) + { + if (build.UserCount > maxUserCount) + maxUserCount = build.UserCount; + } + return maxUserCount; + } + + private void plotChart(APIChangelogChart changelogChartInfo, ColourInfo colour) + { + var maxUserCount = getMaxUserCount(changelogChartInfo); + var currentPos = 0f; + + container.Clear(); + + foreach (BuildHistory build in changelogChartInfo.BuildHistory) + { + container.Add(new Box + { + RelativeSizeAxes = Axes.Y, + Width = Math.Max(container.DrawWidth / changelogChartInfo.BuildHistory.Count, 2), + Height = build.UserCount / maxUserCount, + X = currentPos, + Colour = colour, + Anchor = Anchor.BottomLeft, + Origin = Anchor.BottomLeft, + }); + currentPos += container.DrawWidth / changelogChartInfo.BuildHistory.Count; + } + } } }