Login | Register
My pages Projects Community openCollabNet

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

Project highlights: Architectural Overview

joist
Discussion topic

Back to topic list

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

Author commitlogger at hocus dot collab dot net
Full name commitlogger at hocus dot collab dot net
Date 2000-04-07 13:44:54 PDT
Message User: dlr
  Date: 00/04/07 13:44:54

  Modified: java/org/joist/util/graph GraphLayout.java HTMLGraph.java
                        Makefile TestGraph.java
  Log:
  Working pixel- and percent-based layouts (including scaling!).
  
  Revision Changes Path
  1.2 +25 -3 joist/java/org/joist​/util/graph/GraphLay​out.java
  
  Index: GraphLayout.java
  ====================​====================​====================​=======
  RCS file: /cvs/joist/java/org/​joist/util/graph/Gra​phLayout.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- GraphLayout.java 2000/04/06 18:23:22 1.1
  +++ GraphLayout.java 2000/04/07 20:44:53 1.2
  @@ -31,20 +31,42 @@
        */
       public GraphLayout ()
       {
  - super();
  + super(PERCENT);
  + this.width = 80;
  + // TODO: this.height = ?;
       dataLayout = new Layout();
       }
   
       /**
  - * Constructs a GraphLayout object with the given metric.
  + * Constructs a GraphLayout object with the specified properties.
        *
        * @param metric The metric by which to judge other certain other layout
        * parameters.
  + * @param width The graph width.
  + * @param height The graph height.
  + */
  + public GraphLayout (int metric, int width, int height)
  + {
  + super(metric);
  + this.width = width;
  + this.height = height;
  + this.dataLayout = new Layout();
  + }
  +
  + /**
  + * Constructs a GraphLayout object with the specified properties.
  + *
  + * @param metric The metric by which to judge other certain other layout
  + * parameters.
  + * @param width The graph width.
  + * @param height The graph height.
        * @param dataLayout The layout for this graph's data.
        */
  - public GraphLayout (int metric, Layout dataLayout)
  + public GraphLayout (int metric, int width, int height, Layout dataLayout)
       {
       super(metric);
  + this.width = width;
  + this.height = height;
       this.dataLayout = dataLayout;
       }
   
  
  
  
  1.3 +49 -15 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.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- HTMLGraph.java 2000/04/06 18:23:22 1.2
  +++ HTMLGraph.java 2000/04/07 20:44:53 1.3
  @@ -53,6 +53,7 @@
       if (data != null)
       {
           StringBuffer buf = new StringBuffer(2048);
  + Layout dataLayout = graphLayout.getDataLayout();
   
           // Start the graph.
           buf.append("<table>");
  @@ -60,6 +61,7 @@
           // Set the graph title.
           if (title != null && title.length() > 0)
           {
  + // TODO: Handle vertical orientation (via rowspan?).
           buf.append("<tr><td align=\"center\" colspan=\"2\"><b>");
           buf.append(title);
           buf.append("</b​></td></tr​>");
  @@ -70,15 +72,33 @@
           if (orientation == null) orientation = defaultOrientation;
           if (colorScheme == null) colorScheme = defaultColorScheme;
   
  + // Determine scale factor for graph data values.
  + float scaleFactor = 1;
  + int graphWidth = graphLayout.getWidth();
  + if (graphLayout.getMetric() == Layout.PIXEL &&
  + dataLayout.getMetric() == Layout.PIXEL)
  + {
  + // Find largest value.
  + int largestValue = 0;
  + for (Enumeration values = data.elements();
  + values.hasMoreElements(); )
  + {
  + int value = ((Integer)values.nex​tElement()).intValue​();
  + if (value > largestValue) largestValue = value;
  + }
  +
  + // Generate scale factor based on largest data value.
  + if (largestValue > graphWidth)
  + scaleFactor = (float)graphWidth / largestValue;
  + }
  +
           // Iterate data set, adding header and data.
           for (Enumeration keys = data.keys(); keys.hasMoreElements(); )
           {
           Object key = keys.nextElement();
           Object value = data.get(key);
  -
  - buf.append("<tr>");
   
  - // Crunch numbers.
  + // Assure that we have numeric data.
           int numericData = 0;
           try { numericData = Integer.parseInt(val​ue.toString()); }
           catch (NumberFormatException e)
  @@ -86,16 +106,18 @@
               log.exception(e);
               throw e;
           }
  - // TODO: Use a scale factor to handle variable width percent-
  - // based layouts.
  +
  + // Scale numeric data value appropriately.
  + int scaledNumericData = (int)(numericData * scaleFactor);
   
  - Layout dataLayout = graphLayout.getDataLayout();
  + // Add a new row to the graph.
  + buf.append("<tr>");
   
           // Generate graph layout based on orientation.
           switch (orientation.getSpacial())
           {
           case Orientation.VERTICAL:
  - // TODO: Implement
  + // TODO: Implement vertical orientation.
               log.debug("create: VERTICAL orientation not yet " +
                     "implemented");
               break;
  @@ -107,22 +129,33 @@
               buf.append("</b​></td>");
   
               // Data display.
  - buf.append("<td align=\"left\" valign=\"center\">");
  - buf.append("<table");
  - if (dataLayout.getMetric() == Layout.PERCENT)
  + buf.append("<td align=\"left\" valign=\"center\" ");
  + buf.append("width=\​"100%\">");
  + buf.append("<table width=\"");
  + switch (dataLayout.getMetric())
               {
  - buf.append(" width=\"").append(numericData);
  - buf.append("%\"");
  + case Layout.PIXEL:
  + buf.append(scaledNumericData);
  + break;
  + case Layout.PERCENT:
  + buf.append("100%");
  + break;
  + default:
  + log.debug("Unhandled layout");
  + break;
               }
  - buf.append("><​tr><td width=\"").append(numericData);
  + buf.append("\">​<tr><td width=\"");
  + buf.append(scaledNumericData);
               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(numericDa​ta).append("</td​></tr></t​able>");
  + buf.append("\">​&nbsp;</td>​<td>&nbsp;​").append(numericDat​a);
  + if (dataLayout.getMetric() == Layout.PERCENT)
  + buf.append('%');
  + buf.append("</td​></tr></t​able>");
               buf.append("</td>");
               break;
   
  @@ -131,6 +164,7 @@
               break;
           }
   
  + // End the graph row.
           buf.append("</tr>");
           }
   
  
  
  
  1.2 +2 -1 joist/java/org/joist​/util/graph/Makefile​
  
  Index: Makefile
  ====================​====================​====================​=======
  RCS file: /cvs/joist/java/org/​joist/util/graph/Mak​efile,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Makefile 2000/04/06 18:23:22 1.1
  +++ Makefile 2000/04/07 20:44:53 1.2
  @@ -1,6 +1,7 @@
   SOURCES= \
       Graph.java \
       GraphLayout.java \
  - HTMLGraph.java
  + HTMLGraph.java \
  + TestGraph.java
   
   include ../../../../Makefile.config
  
  
  
  1.2 +9 -8 joist/java/org/joist​/util/graph/TestGrap​h.java
  
  Index: TestGraph.java
  ====================​====================​====================​=======
  RCS file: /cvs/joist/java/org/​joist/util/graph/Tes​tGraph.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestGraph.java 2000/04/06 18:23:22 1.1
  +++ TestGraph.java 2000/04/07 20:44:53 1.2
  @@ -1,5 +1,3 @@
  -/* TestGraph.java: -*- Java -*- */
  -
   package org.joist.util.graph;
   
   import java.util.Hashtable;
  @@ -11,8 +9,8 @@
   import org.joist.util.graph.*;
   
   /**
  - * Generates HTML-based graphs.
  - * Long Description (in HTML).
  + * Test the generation of graphs.
  + *
    * @author Daniel L. Rall
    * @version 1.0 (2000.04.2)
    */
  @@ -24,12 +22,15 @@
       data.put("Java", new Integer(700));
       data.put("C", new Integer(600));
   
  - int layout = Layout.PERCENT;
  - GraphLayout graphLayout = new GraphLayout(layout, new Layout(layout));
  + GraphLayout graphLayout = new GraphLayout(Layout.PIXEL,
  + 400, 400,
  + new Layout(Layout.PIXEL));
       Orientation orient = new Orientation(Orientat​ion.HORIZONTAL);
  - HTMLGraph graph = new HTMLGraph(data, "Skills list", null, orient,
  - null);
  + HTMLGraph graph = new HTMLGraph(data, "Skills list", graphLayout,
  + orient, null);
   
       System.out.println(g​raph.toString());
       }
   }
  +
  +

« 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 GraphLayout.java HTMLGraph.java Makefile TestGraph.java commitlogger at hocus dot collab dot net commitlogger at hocus dot collab dot net 2000-04-07 13:44:54 PDT
Messages per page: