Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the XAxis of LineGraphWidget not being updated properly #17182

Merged
merged 2 commits into from Oct 6, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 17 additions & 10 deletions OpenRA.Mods.Common/Widgets/LineGraphWidget.cs
Expand Up @@ -89,14 +89,21 @@ protected LineGraphWidget(LineGraphWidget other)

public override void Draw()
{
if (GetSeries == null || !GetSeries().Any()
|| GetLabelFont == null || GetLabelFont() == null)
if (GetSeries == null || GetLabelFont == null)
return;

var series = GetSeries();
if (!series.Any())
return;

var font = GetLabelFont();
if (font == null)
return;

var cr = Game.Renderer.RgbaColorRenderer;
var rect = RenderBounds;

var labelFont = Game.Renderer.Fonts[GetLabelFont()];
var labelFont = Game.Renderer.Fonts[font];
var axisFont = Game.Renderer.Fonts[GetAxisFont()];

var xAxisSize = GetXAxisSize();
Expand All @@ -110,8 +117,8 @@ public override void Draw()
var graphBottomOffset = Padding * 2 + xAxisLabelSize.Y + xAxisPointLabelHeight;
var height = rect.Height - (graphBottomOffset + Padding);

var maxValue = GetSeries().Select(p => p.Points).SelectMany(d => d).Concat(new[] { 0f }).Max();
var longestName = GetSeries().Select(s => s.Key).OrderByDescending(s => s.Length).FirstOrDefault() ?? "";
var maxValue = series.Select(p => p.Points).SelectMany(d => d).Concat(new[] { 0f }).Max();
var longestName = series.Select(s => s.Key).OrderByDescending(s => s.Length).FirstOrDefault() ?? "";

var scale = 200 / Math.Max(5000, (float)Math.Ceiling(maxValue / 1000) * 1000);

Expand All @@ -127,7 +134,7 @@ public override void Draw()
var xStep = width / xAxisSize;
var yStep = height / yAxisSize;

var pointCount = GetSeries().First().Points.Count();
var pointCount = series.Max(s => s.Points.Count());
var pointStart = Math.Max(0, pointCount - xAxisSize);
var pointEnd = Math.Max(pointCount, xAxisSize);

Expand All @@ -136,11 +143,11 @@ public override void Draw()
var origin = new float2(rect.Left, rect.Bottom);

var keyOffset = 0;
foreach (var series in GetSeries())
foreach (var s in series)
{
var key = series.Key;
var color = series.Color;
var points = series.Points;
var key = s.Key;
var color = s.Color;
var points = s.Points;
if (points.Any())
{
points = points.Reverse().Take(xAxisSize).Reverse();
Expand Down