From 220f1368483b7f2d7b50141d74428c17366720dc Mon Sep 17 00:00:00 2001 From: "jason@long.name" Date: Sat, 31 Aug 2013 19:15:59 +0000 Subject: [PATCH] GraphsPane: fix for graph reaching above 100% (issue #31) git-svn-id: https://micropolis.googlecode.com/svn/trunk/micropolis-java@805 d9718cc8-9f43-0410-858b-315f434eb58c --- src/micropolisj/gui/GraphsPane.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/micropolisj/gui/GraphsPane.java b/src/micropolisj/gui/GraphsPane.java index 13d7822..5f41bb9 100644 --- a/src/micropolisj/gui/GraphsPane.java +++ b/src/micropolisj/gui/GraphsPane.java @@ -182,6 +182,17 @@ public class GraphsPane extends JPanel return btn; } + int getHistoryMax() + { + int max = 0; + for (GraphData g : GraphData.values()) { + for (int pos = 0; pos < 240; pos++) { + max = Math.max(max, getHistoryValue(g, pos)); + } + } + return max; + } + int getHistoryValue(GraphData graph, int pos) { assert pos >= 0 && pos < 240; @@ -265,6 +276,7 @@ public class GraphsPane extends JPanel int H = isOneTwenty ? 239 : 119; final HashMap paths = new HashMap(); + double scale = Math.max(256.0, getHistoryMax()); for (GraphData gd : GraphData.values()) { if (dataBtns.get(gd).isSelected()) { @@ -272,7 +284,7 @@ public class GraphsPane extends JPanel Path2D.Double path = new Path2D.Double(); for (int i = 0; i < 120; i++) { double xp = leftEdge + i * x_interval; - double yp = bottomEdge - getHistoryValue(gd,H-i) * (bottomEdge-topEdge) / 256.0; + double yp = bottomEdge - getHistoryValue(gd,H-i) * (bottomEdge-topEdge) / scale; if (i == 0) { path.moveTo(xp, yp); } else {