[Swift-commit] r5784 - usertools/plotter/src/plotter

wozniak at ci.uchicago.edu wozniak at ci.uchicago.edu
Fri May 4 14:51:43 CDT 2012


Author: wozniak
Date: 2012-05-04 14:51:42 -0500 (Fri, 04 May 2012)
New Revision: 5784

Modified:
   usertools/plotter/src/plotter/Lines.java
   usertools/plotter/src/plotter/Util.java
Log:
Support annotations


Modified: usertools/plotter/src/plotter/Lines.java
===================================================================
--- usertools/plotter/src/plotter/Lines.java	2012-05-01 03:53:59 UTC (rev 5783)
+++ usertools/plotter/src/plotter/Lines.java	2012-05-04 19:51:42 UTC (rev 5784)
@@ -13,6 +13,7 @@
 import org.apache.xmlgraphics.java2d.ps.EPSDocumentGraphics2D;
 import org.jfree.chart.ChartFactory;
 import org.jfree.chart.JFreeChart;
+import org.jfree.chart.annotations.XYTextAnnotation;
 import org.jfree.chart.axis.LogarithmicAxis;
 import org.jfree.chart.axis.NumberAxis;
 import org.jfree.chart.plot.PlotOrientation;
@@ -51,6 +52,9 @@
 
   static boolean withLegend = true;
 
+  static List<XYTextAnnotation> notes =
+      new ArrayList<XYTextAnnotation>();
+
   /**
        Args: Lines <properties> <output file> <data file>*
        Reads settings from properties: see scanProperties()
@@ -165,6 +169,7 @@
        PlotOrientation.VERTICAL, withLegend, false, false);
 
     setupPlot(chart, collection);
+
     chart.draw(g2d, rectangle);
 
     try
@@ -235,6 +240,9 @@
     setAxes(plot);
     plot.setRenderer(renderer);
     plot.setBackgroundPaint(Color.WHITE);
+
+    for (XYTextAnnotation note : notes)
+      plot.addAnnotation(note);
   }
 
   static void setAxes(XYPlot plot)
@@ -345,8 +353,28 @@
     tmp = properties.getProperty("axis.y");
     if (tmp != null)
       axis_y_type = tmp;
+    tmp = properties.getProperty("notes");
+    if (tmp != null)
+      loadNotes();
   }
 
+  static void loadNotes()
+  {
+    String s = properties.getProperty("notes");
+    int count = Integer.parseInt(s);
+    for (int i = 0; i < count; i++)
+    {
+      String p = "note."+i;
+      String d = properties.getProperty(p);
+      String[] tokens = d.split("\\s");
+      double x = Double.parseDouble(tokens[0]);
+      double y = Double.parseDouble(tokens[1]);
+      String text = Util.concat(tokens, 2);
+      XYTextAnnotation note = new XYTextAnnotation(text, x, y);
+      notes.add(note);
+    }
+  }
+
   static void load(String propFile)
   {
     try

Modified: usertools/plotter/src/plotter/Util.java
===================================================================
--- usertools/plotter/src/plotter/Util.java	2012-05-01 03:53:59 UTC (rev 5783)
+++ usertools/plotter/src/plotter/Util.java	2012-05-04 19:51:42 UTC (rev 5784)
@@ -1,5 +1,7 @@
 package plotter;
 
+import java.util.List;
+
 /**
  * Plot data helpers.
  * */
@@ -24,6 +26,52 @@
     return sb.toString();
   }
 
+  public static String concat(List<String> tokens)
+  {
+    String[] array = new String[tokens.size()];
+    tokens.toArray(array);
+    return concat(array, 0, " ");
+  }
+
+  public static String concat(String... strings)
+  {
+    return concat(' ', strings);
+  }
+
+  public static String concat(String[] tokens, int start)
+  {
+    return concat(tokens, start, " ");
+  }
+
+  public static String concat(String[] tokens, int start,
+                              String separator)
+  {
+    if (tokens == null)
+      return "null";
+    StringBuilder sb = new StringBuilder();
+    for (int i = start; i < tokens.length; i++)
+    {
+      sb.append(tokens[i]);
+      if (i < tokens.length - 1)
+        sb.append(separator);
+    }
+    return sb.toString();
+  }
+
+  public static String concat(char c, String... strings)
+  {
+    if (strings == null)
+      return "null";
+    StringBuilder sb = new StringBuilder();
+    for (int i = 0; i < strings.length; i++)
+    {
+      sb.append(strings[i]);
+      if (i < strings.length - 1)
+        sb.append(c);
+    }
+    return sb.toString();
+  }
+
   public static void fatal(String s)
   {
     System.err.println(s);




More information about the Swift-commit mailing list