Login | Register
My pages Projects Community openCollabNet

Discussions > cvs > CVS update: joist/java/org/joist/util/graph Graph.java GraphLayout.java TestGraph.java Makefile HTMLGraph.java

Project highlights: Architectural Overview

joist
Discussion topic

Back to topic list

CVS update: joist/java/org/joist/util/graph Graph.java GraphLayout.java TestGraph.java Makefile HTMLGraph.java

Author commitlogger at hocus dot collab dot net
Full name commitlogger at hocus dot collab dot net
Date 2000-04-06 11:23:23 PDT
Message User: dlr
  Date: 00/04/06 11:23:23

  Modified: java/org/joist/util Makefile
               java/org/joist/util/graph HTMLGraph.java
  Added: java/org/joist/util Layout.java
               java/org/joist/util/graph Graph.java GraphLayout.java
                        TestGraph.java Makefile
  Log:
  Pixel-based layout is now functional. Percentage-baed layout is almost there.
  
  Revision Changes Path
  1.3 +3 -0 joist/java/org/joist​/util/Makefile
  
  Index: Makefile
  ====================​====================​====================​=======
  RCS file: /cvs/joist/java/org/​joist/util/Makefile,​v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Makefile 2000/01/30 13:00:38 1.2
  +++ Makefile 2000/04/06 18:23:22 1.3
  @@ -1,11 +1,14 @@
   SOURCES= \
  + ColorScheme.java \
       Counter.java \
       CurrencyString.java \
       DateDisplay.java \
       EscapedString.java \
       FormToContext.java \
  + Layout.java \
       LinkEncoder.java \
       ListElement.java \
  + Orientation.java \
       PasswordGenerator.java \
       QuotedString.java \
       URL.java
  
  
  
  1.1 joist/java/org/joist​/util/Layout.java
  
  Index: Layout.java
  ====================​====================​====================​=======
  package org.joist.util;
  
  import java.io.Serializable;
  
  /**
   * Generic orientation description.
   *
   * @author Daniel L. Rall
   * @version 1.0 (2000.04. 2)
   */
  public class Layout implements Serializable
  {
      public static final int DEFAULT = 1;
      public static final int PIXEL = 1;
      public static final int PERCENT = 2;
  
      /** The spacial Layout (i.e. VERTICAL, HORIZONTAL, etc.) */
      private int metric;
  
      /**
       * Default constructor.
       * Creates a new Layout with default properties.
       */
      public Layout ()
      {
      metric = DEFAULT;
      }
  
      /**
       * Constructs a Layout object with the given metric.
       *
       * @param metric The metric by which to judge other certain other layout
       * parameters.
       */
      public Layout (int metric)
      {
      this.metric = metric;
      }
  
      /**
       * Gets the spacial Layout.
       *
       * @return The metric by which to judge other certain other layout
       * parameters.
       */
      public int getMetric () { return metric; }
  }
  
  
  
  
  1.2 +51 -35 joist/java/org/joist​/util/graph/HTMLGrap​h.java
  
  Index: HTMLGraph.java
  ====================​====================​====================​=======
  RCS file: /cvs/joist/java/org/​joist/util/graph/HTM​LGraph.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- HTMLGraph.java 2000/04/03 04:14:55 1.1
  +++ HTMLGraph.java 2000/04/06 18:23:22 1.2
  @@ -1,58 +1,58 @@
  -/* HTMLGraph.java: -*- Java -*- */
  -
   package org.joist.util.graph;
   
   import java.io.Serializable;
   import java.util.Hashtable;
   import java.util.Enumeration;
  +import java.awt.Color;
   
   import org.webmacro.util.*;
   
  -import org.joist.util.Orientation;
  -import org.joist.util.ColorScheme;
  +import org.joist.util.*;
   
   /**
    * Generates HTML-based graphs.
  - * Long Description (in HTML).
  + *
    * @author Daniel L. Rall
    * @version 1.0 (2000.04.2)
    */
  -public class HTMLGraph implements Serializable
  +public class HTMLGraph implements Graph
   {
       /** Default graph orientation. */
       protected static Orientation defaultOrientation = new Orientation();
   
  + /** Default graph layout. */
  + protected static GraphLayout defaultGraphLayout = new GraphLayout();
  +
       /** Default graph color scheme. */
       protected static ColorScheme defaultColorScheme = new ColorScheme();
   
  + /** The graph itself. */
  + protected String html;
  +
       /** Logging mechanism. */
       private static Log log = new Log("htmGrph", "HTMLGraph");
   
       /**
  - * Default constructor.
  - * Creates a new HTMLGraph with default properties.
  - */
  - private HTMLGraph ()
  - {
  - }
  -
  - /**
  - * Acts as a factory to create graphs as an HTML table.
  + * Creates an HTML table representation of a graph.
        *
  - * @param orientation
  - * @param data
  - * @return The graph as HTML.
  + * @param data The data to graph.
  + * @param title The title for the graph.
  + * @param graphLayout The graph's physcial layout.
  + * @param orientation The orientation (vertical, horizontal, etc.).
  + * @return The HTML-based graph.
        */
  - public static String create (Hashtable data,
  - String title,
  - Orientation orientation,
  - ColorScheme colorScheme)
  + public HTMLGraph (Hashtable data,
  + String title,
  + GraphLayout graphLayout,
  + Orientation orientation,
  + ColorScheme colorScheme)
  + throws NumberFormatException
       {
  - String graph = null;
  + html = null;
   
       if (data != null)
       {
  - StringBuffer buf = new StringBuffer();
  + StringBuffer buf = new StringBuffer(2048);
   
           // Start the graph.
           buf.append("<table>");
  @@ -66,6 +66,7 @@
           }
   
           // Make sure we have graph meta data.
  + if (graphLayout == null) graphLayout = defaultGraphLayout;
           if (orientation == null) orientation = defaultOrientation;
           if (colorScheme == null) colorScheme = defaultColorScheme;
   
  @@ -78,11 +79,18 @@
           buf.append("<tr>");
   
           // Crunch numbers.
  - int numeric = 0;
  - try { numeric = Integer.parseInt(val​ue.toString()); }
  - catch (NumberFormatException e) { log.exception(e); }
  - // TODO: Use a scale factor.
  + int numericData = 0;
  + try { numericData = Integer.parseInt(val​ue.toString()); }
  + catch (NumberFormatException e)
  + {
  + log.exception(e);
  + throw e;
  + }
  + // TODO: Use a scale factor to handle variable width percent-
  + // based layouts.
   
  + Layout dataLayout = graphLayout.getDataLayout();
  +
           // Generate graph layout based on orientation.
           switch (orientation.getSpacial())
           {
  @@ -100,13 +108,21 @@
   
               // Data display.
               buf.append("<td align=\"left\" valign=\"center\">");
  - buf.append("<tabl​e><tr><t​d width=\"");
  - buf.append(numeric).append("\" color=\"#");
  + buf.append("<table");
  + if (dataLayout.getMetric() == Layout.PERCENT)
  + {
  + buf.append(" width=\"").append(numericData);
  + buf.append("%\"");
  + }
  + buf.append("><​tr><td width=\"").append(numericData);
  + if (dataLayout.getMetric() == Layout.PERCENT)
  + buf.append('%');
  + buf.append("\" color=\"#");
               buf.append(getWebCol​or(colorScheme.getBa​ckground()));
               buf.append("\" bgcolor=\"#");
               buf.append(getWebCol​or(colorScheme.getFo​reground()));
               buf.append("\">​&nbsp;</td>​<td>&nbsp;​");
  - buf.append(numeric).​append("</td>​</tr></table​>");
  + buf.append(numericDa​ta).append("</td​></tr></t​able>");
               buf.append("</td>");
               break;
   
  @@ -121,19 +137,19 @@
           // End the graph.
           buf.append("</table>");
   
  - graph = buf.toString();
  + html = buf.toString();
       }
  -
  - return graph;
       }
   
  + public String toString () { return html; }
  +
       /**
        * Gets the red green blue integer representation of a color as hex.
        *
        * @param c Color to transform into hex.
        * @return Hex value of a color as a string.
        */
  - protected static String getWebColor (java.awt.Color c)
  + protected static String getWebColor (Color c)
       {
       // Integer.toHexString() returns an 8 digit number. Web browsers seem
       // to like 6 digits. Dropping the first two renders the desired color
  
  
  
  1.1 joist/java/org/joist​/util/graph/Graph.ja​va
  
  Index: Graph.java
  ====================​====================​====================​=======
  package org.joist.util.graph;
  
  import java.io.Serializable;
  import java.util.Hashtable;
  
  import org.joist.util.*;
  
  /**
   * Generic graph API.
   *
   * @author <a href="mailto:dlr@fin​emaltcoding.com">​Daniel L. Rall</a>
   * @version 1.0 (2000.04.3)
   */
  public interface Graph extends Serializable {}
  
  
  
  1.1 joist/java/org/joist​/util/graph/GraphLay​out.java
  
  Index: GraphLayout.java
  ====================​====================​====================​=======
  package org.joist.util.graph;
  
  import org.joist.util.Layout;
  
  /**
   * The layout for the graph and data.
   *
   * @author Daniel L. Rall
   * @version 1.0 (2000.04. 2)
   */
  public class GraphLayout extends Layout
  {
      /**
       * The height of the graph.
       */
      protected int height;
  
      /**
       * The width of the graph.
       */
      protected int width;
  
      /**
       * The layout for bars on the graph which display the data visually.
       */
      protected Layout dataLayout;
  
      /**
       * Default constructor.
       * Creates a new GraphLayout with default properties.
       */
      public GraphLayout ()
      {
      super();
      dataLayout = new Layout();
      }
  
      /**
       * Constructs a GraphLayout object with the given metric.
       *
       * @param metric The metric by which to judge other certain other layout
       * parameters.
       * @param dataLayout The layout for this graph's data.
       */
      public GraphLayout (int metric, Layout dataLayout)
      {
      super(metric);
      this.dataLayout = dataLayout;
      }
  
      /**
       * Gets the spacial GraphLayout.
       *
       * @return The layout.
       */
      public Layout getDataLayout () { return dataLayout; }
  
      /**
       * Returns the height of the graph.
       *
       * @return The height of the graph.
       */
      public int getHeight () { return height; }
  
      /**
       * Returns the width of the graph.
       *
       * @return The width of the graph.
       */
      public int getWidth () { return width; }
  }
  
  
  
  
  1.1 joist/java/org/joist​/util/graph/TestGrap​h.java
  
  Index: TestGraph.java
  ====================​====================​====================​=======
  /* TestGraph.java: -*- Java -*- */
  
  package org.joist.util.graph;
  
  import java.util.Hashtable;
  import java.util.Enumeration;
  
  import org.webmacro.util.*;
  
  import org.joist.util.*;
  import org.joist.util.graph.*;
  
  /**
   * Generates HTML-based graphs.
   * Long Description (in HTML).
   * @author Daniel L. Rall
   * @version 1.0 (2000.04.2)
   */
  public class TestGraph
  {
      public static void main(String[] args)
      {
      Hashtable data = new Hashtable();
      data.put("Java", new Integer(700));
      data.put("C", new Integer(600));
  
      int layout = Layout.PERCENT;
      GraphLayout graphLayout = new GraphLayout(layout, new Layout(layout));
      Orientation orient = new Orientation(Orientat​ion.HORIZONTAL);
      HTMLGraph graph = new HTMLGraph(data, "Skills list", null, orient,
                      null);
  
      System.out.println(g​raph.toString());
      }
  }
  
  
  
  1.1 joist/java/org/joist​/util/graph/Makefile​
  
  Index: Makefile
  ====================​====================​====================​=======
  SOURCES= \
      Graph.java \
      GraphLayout.java \
      HTMLGraph.java
  
  include ../../../../Makefile.config

« Previous message in topic | 1 of 1 | Next message in topic »

Messages

Show all messages in topic

CVS update: joist/java/org/joist/util/graph Graph.java GraphLayout.java TestGraph.java Makefile HTMLGraph.java commitlogger at hocus dot collab dot net commitlogger at hocus dot collab dot net 2000-04-06 11:23:23 PDT
Messages per page: