changeset 410:5f58e1af2791

Show nicer units on heap charts. Reviewed-by: neugens Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2012-June/001965.html PR 944
author Roman Kennke <rkennke@redhat.com>
date Thu, 21 Jun 2012 17:25:37 +0200
parents 94b79810528b
children f7b94395448e 05d1331db40e
files client/heapdumper/src/main/java/com/redhat/thermostat/client/heap/chart/CustomTickUnit.java client/heapdumper/src/main/java/com/redhat/thermostat/client/heap/chart/OverviewChart.java
diffstat 2 files changed, 77 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/client/heapdumper/src/main/java/com/redhat/thermostat/client/heap/chart/CustomTickUnit.java	Thu Jun 21 17:25:37 2012 +0200
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2012 Red Hat, Inc.
+ *
+ * This file is part of Thermostat.
+ *
+ * Thermostat is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation; either version 2, or (at your
+ * option) any later version.
+ *
+ * Thermostat is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Thermostat; see the file COPYING.  If not see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * Linking this code with other modules is making a combined work
+ * based on this code.  Thus, the terms and conditions of the GNU
+ * General Public License cover the whole combination.
+ *
+ * As a special exception, the copyright holders of this code give
+ * you permission to link this code with independent modules to
+ * produce an executable, regardless of the license terms of these
+ * independent modules, and to copy and distribute the resulting
+ * executable under terms of your choice, provided that you also
+ * meet, for each linked independent module, the terms and conditions
+ * of the license of that module.  An independent module is a module
+ * which is not derived from or based on this code.  If you modify
+ * this code, you may extend this exception to your version of the
+ * library, but you are not obligated to do so.  If you do not wish
+ * to do so, delete this exception statement from your version.
+ */
+
+package com.redhat.thermostat.client.heap.chart;
+
+import org.jfree.chart.axis.NumberTickUnit;
+
+import com.redhat.thermostat.common.utils.DisplayableValues;
+
+@SuppressWarnings("serial")
+class CustomTickUnit extends NumberTickUnit {
+
+    public CustomTickUnit(double size) {
+        super(size);
+    }
+
+    @Override
+    public String valueToString(double value) {
+        String[] displayable = DisplayableValues.bytes((long) value);
+        return displayable[0] + " " + displayable[1];
+    }
+}
--- a/client/heapdumper/src/main/java/com/redhat/thermostat/client/heap/chart/OverviewChart.java	Thu Jun 21 17:25:01 2012 +0200
+++ b/client/heapdumper/src/main/java/com/redhat/thermostat/client/heap/chart/OverviewChart.java	Thu Jun 21 17:25:37 2012 +0200
@@ -38,10 +38,7 @@
 
 import java.awt.Color;
 import java.awt.GradientPaint;
-import java.awt.Graphics2D;
 import java.awt.Paint;
-import java.awt.geom.Rectangle2D;
-import java.awt.image.BufferedImage;
 import java.util.Date;
 
 import javax.swing.plaf.ColorUIResource;
@@ -49,9 +46,13 @@
 import org.jfree.chart.ChartFactory;
 import org.jfree.chart.JFreeChart;
 import org.jfree.chart.axis.DateAxis;
+import org.jfree.chart.axis.NumberAxis;
+import org.jfree.chart.axis.NumberTickUnit;
+import org.jfree.chart.axis.TickUnits;
 import org.jfree.chart.axis.ValueAxis;
 import org.jfree.chart.plot.XYPlot;
 import org.jfree.chart.renderer.xy.XYDifferenceRenderer;
+import org.jfree.data.RangeType;
 import org.jfree.data.time.Millisecond;
 import org.jfree.data.time.TimeSeries;
 import org.jfree.data.time.TimeSeriesCollection;
@@ -114,7 +115,24 @@
         domainAxis.setUpperMargin(0.0);
         plot.setDomainAxis(domainAxis);
         plot.setForegroundAlpha(0.5f);
-        
+        TickUnits tickUnits = new TickUnits();
+        tickUnits.add(new CustomTickUnit(1.));
+        tickUnits.add(new CustomTickUnit(10.));
+        tickUnits.add(new CustomTickUnit(100.));
+        tickUnits.add(new CustomTickUnit(1000.));
+        tickUnits.add(new CustomTickUnit(10000.));
+        tickUnits.add(new CustomTickUnit(100000.));
+        tickUnits.add(new CustomTickUnit(1000000.));
+        tickUnits.add(new CustomTickUnit(10000000.));
+        tickUnits.add(new CustomTickUnit(100000000.));
+        tickUnits.add(new CustomTickUnit(1000000000.));
+        tickUnits.add(new CustomTickUnit(10000000000.));
+        tickUnits.add(new CustomTickUnit(100000000000.));
+        tickUnits.add(new CustomTickUnit(1000000000000.));
+        NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
+        yAxis.setStandardTickUnits(tickUnits);
+        yAxis.setRangeType(RangeType.POSITIVE);
+        yAxis.setAutoRangeMinimumSize(10);
         return chart;
     }