Cleanup, refactoring of stats graph widget.
This commit is contained in:
@@ -23,14 +23,16 @@ namespace OpenRA.Widgets
|
||||
public Func<string> GetValueFormat;
|
||||
public Func<string> GetXAxisValueFormat;
|
||||
public Func<string> GetYAxisValueFormat;
|
||||
public Func<int> GetVisibleNodeCount;
|
||||
public Func<int> GetXAxisSize;
|
||||
public Func<int> GetYAxisSize;
|
||||
public Func<string> GetXAxisLabel;
|
||||
public Func<string> GetYAxisLabel;
|
||||
public Func<bool> GetDisplayYAxisZero;
|
||||
public string ValueFormat = "{0}";
|
||||
public string XAxisValueFormat = "{0}";
|
||||
public string YAxisValueFormat = "{0}";
|
||||
public int VisibleNodeCount = 10;
|
||||
public int XAxisSize = 10;
|
||||
public int YAxisSize = 10;
|
||||
public string XAxisLabel = "";
|
||||
public string YAxisLabel = "";
|
||||
public bool DisplayYAxisZero = true;
|
||||
@@ -41,7 +43,8 @@ namespace OpenRA.Widgets
|
||||
GetValueFormat = () => ValueFormat;
|
||||
GetXAxisValueFormat = () => XAxisValueFormat;
|
||||
GetYAxisValueFormat = () => YAxisValueFormat;
|
||||
GetVisibleNodeCount = () => VisibleNodeCount;
|
||||
GetXAxisSize = () => XAxisSize;
|
||||
GetYAxisSize = () => YAxisSize;
|
||||
GetXAxisLabel = () => XAxisLabel;
|
||||
GetYAxisLabel = () => YAxisLabel;
|
||||
GetDisplayYAxisZero = () => DisplayYAxisZero;
|
||||
@@ -54,14 +57,16 @@ namespace OpenRA.Widgets
|
||||
GetValueFormat = other.GetValueFormat;
|
||||
GetXAxisValueFormat = other.GetXAxisValueFormat;
|
||||
GetYAxisValueFormat = other.GetYAxisValueFormat;
|
||||
GetVisibleNodeCount = other.GetVisibleNodeCount;
|
||||
GetXAxisSize = other.GetXAxisSize;
|
||||
GetYAxisSize = other.GetYAxisSize;
|
||||
GetXAxisLabel = other.GetXAxisLabel;
|
||||
GetYAxisLabel = other.GetYAxisLabel;
|
||||
GetDisplayYAxisZero = other.GetDisplayYAxisZero;
|
||||
ValueFormat = other.ValueFormat;
|
||||
XAxisValueFormat = other.XAxisValueFormat;
|
||||
YAxisValueFormat = other.YAxisValueFormat;
|
||||
VisibleNodeCount = other.VisibleNodeCount;
|
||||
XAxisSize = other.XAxisSize;
|
||||
YAxisSize = other.YAxisSize;
|
||||
XAxisLabel = other.XAxisLabel;
|
||||
YAxisLabel = other.YAxisLabel;
|
||||
DisplayYAxisZero = other.DisplayYAxisZero;
|
||||
@@ -87,29 +92,32 @@ namespace OpenRA.Widgets
|
||||
var tinyBold = Game.Renderer.Fonts["TinyBold"];
|
||||
var bold = Game.Renderer.Fonts["Bold"];
|
||||
|
||||
var visibleNodeCount = GetVisibleNodeCount();
|
||||
var visibleNodeStep = width / visibleNodeCount;
|
||||
var xAxisSize = GetXAxisSize();
|
||||
var yAxisSize = GetYAxisSize();
|
||||
|
||||
var xStep = width / xAxisSize;
|
||||
var yStep = height / yAxisSize;
|
||||
|
||||
var actualNodeCount = GetDataSource().First().Second.Count();
|
||||
var visibleNodeStart = Math.Max(0, actualNodeCount - visibleNodeCount);
|
||||
var visibleNodeEnd = Math.Max(actualNodeCount, visibleNodeCount);
|
||||
var visibleNodeStart = Math.Max(0, actualNodeCount - xAxisSize);
|
||||
var visibleNodeEnd = Math.Max(actualNodeCount, xAxisSize);
|
||||
|
||||
float maxValue = GetDataSource().Select(p => p.Second).SelectMany(d => d).Max();
|
||||
var scale = (100 / maxValue) * 3;
|
||||
|
||||
//todo: make this stuff not draw outside of the RenderBounds
|
||||
for (int n = visibleNodeStart, i = 0; n <= visibleNodeEnd; n++, i++)
|
||||
for (int n = visibleNodeStart, x = 0; n <= visibleNodeEnd; n++, x += xStep)
|
||||
{
|
||||
var x = i * visibleNodeStep;
|
||||
Game.Renderer.LineRenderer.DrawLine(origin + new float2(x, 0), origin + new float2(x, -5), Color.White, Color.White);
|
||||
tinyBold.DrawText(GetXAxisValueFormat().F(n), origin + new float2(x, 2), Color.White);
|
||||
}
|
||||
bold.DrawText(GetXAxisLabel(), origin + new float2(width / 2, 20), Color.White);
|
||||
|
||||
for (var i = (GetDisplayYAxisZero() ? 0f : height / 10); i <= height; i += height / 10)
|
||||
for (var y = (GetDisplayYAxisZero() ? 0f : yStep); y <= height; y += yStep)
|
||||
{
|
||||
var value = i / scale;
|
||||
Game.Renderer.LineRenderer.DrawLine(origin + new float2(width - 5, -i), origin + new float2(width, -i), Color.White, Color.White);
|
||||
tinyBold.DrawText(GetYAxisValueFormat().F(value), origin + new float2(width + 2, -i), Color.White);
|
||||
var value = y / scale;
|
||||
Game.Renderer.LineRenderer.DrawLine(origin + new float2(width - 5, -y), origin + new float2(width, -y), Color.White, Color.White);
|
||||
tinyBold.DrawText(GetYAxisValueFormat().F(value), origin + new float2(width + 2, -y), Color.White);
|
||||
}
|
||||
bold.DrawText(GetYAxisLabel(), origin + new float2(width + 40, -(height / 2)), Color.White);
|
||||
|
||||
@@ -121,16 +129,16 @@ namespace OpenRA.Widgets
|
||||
var color = player.ColorRamp.GetColor(0);
|
||||
if (data.Any())
|
||||
{
|
||||
data = data.Reverse().Take(visibleNodeCount).Reverse();
|
||||
data = data.Reverse().Take(xAxisSize).Reverse();
|
||||
var scaledData = data.Select(d => d * scale);
|
||||
var x = 0f;
|
||||
scaledData.Aggregate((a, b) =>
|
||||
{
|
||||
Game.Renderer.LineRenderer.DrawLine(
|
||||
origin + new float2(x, -a),
|
||||
origin + new float2(x + visibleNodeStep, -b),
|
||||
origin + new float2(x + xStep, -b),
|
||||
color, color);
|
||||
x += visibleNodeStep;
|
||||
x += xStep;
|
||||
return b;
|
||||
});
|
||||
|
||||
|
||||
@@ -873,7 +873,8 @@ Container@OBSERVER_ROOT:
|
||||
ValueFormat:${0}
|
||||
XAxisValueFormat:{0}
|
||||
YAxisValueFormat:${0:F0}
|
||||
VisibleNodeCount:20
|
||||
XAxisSize:20
|
||||
YAxisSize:10
|
||||
XAxisLabel:m
|
||||
YAxisLabel:$
|
||||
DisplayYAxisZero:false
|
||||
|
||||
Reference in New Issue
Block a user