$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
From: jakevoytko_at_[hidden]
Date: 2007-06-10 22:48:57
Author: jakevoytko
Date: 2007-06-10 22:48:56 EDT (Sun, 10 Jun 2007)
New Revision: 4522
URL: http://svn.boost.org/trac/boost/changeset/4522
Log:
Supports an internal document structure for svg_plots, and support for rgb colors and svg constants. Cleaned up some comments.
Text files modified: 
   sandbox/SOC/2007/visualization/boost/svg_plot/svg.hpp                  |    69 +++++----                               
   sandbox/SOC/2007/visualization/boost/svg_plot/svg_instruction.hpp      |     9 +                                       
   sandbox/SOC/2007/visualization/boost/svg_plot/svg_plot.hpp             |   286 +++++++++++++++++++++++---------------- 
   sandbox/SOC/2007/visualization/boost/svg_plot/svg_plot_instruction.hpp |    59 +++++--                                 
   sandbox/SOC/2007/visualization/boost/svg_plot/svg_style.hpp            |   283 ++++++++++++++++++++++++++++++++++++++  
   sandbox/SOC/2007/visualization/boost/svg_plot/svg_tag.hpp              |    91 ++++++-----                             
   6 files changed, 576 insertions(+), 221 deletions(-)
Modified: sandbox/SOC/2007/visualization/boost/svg_plot/svg.hpp
==============================================================================
--- sandbox/SOC/2007/visualization/boost/svg_plot/svg.hpp	(original)
+++ sandbox/SOC/2007/visualization/boost/svg_plot/svg.hpp	2007-06-10 22:48:56 EDT (Sun, 10 Jun 2007)
@@ -10,7 +10,6 @@
 #ifndef _SVG_HPP
 #define _SVG_HPP
 
-
 #include <vector>
 #include <ostream>
 #include <sstream>
@@ -27,8 +26,6 @@
 class svg
 {
 private:
-    g_element document;
-
     std::ostream *s_out;
     
     void _write_header();
@@ -42,15 +39,23 @@
 protected:
     unsigned int x_size;
     unsigned int y_size;
-    void _size(unsigned int, unsigned int);
     
+    g_element document;
+
+    void _size(unsigned int, unsigned int);
+
     void _write();
 
     void _point(double, double);
+    void _point(double, double, g_element&);
+    
     void _line(double, double, double, double);
+    void _line(double, double, double, double, g_element&); 
+    
     void _text(double, double, std::string);
     void _line_color(svg_color);
 
+
 public:
     svg(const std::string&);
     
@@ -84,7 +89,8 @@
     delete s_out;
 }
 
-//specify a new stream after the copy
+//I still need to put more thought into whether I want this class
+//copyable or not
 svg::svg(const svg& rhs)
 {
     x_size = rhs.x_size;
@@ -97,11 +103,8 @@
 
 // -----------------------------------------------------------------
 // Processes the svg_instructions
-// This allows the user to easily enter information:
-//
-// my_image<<color(RED)<<line(x1,y1,x2,y2)<<write(); 
-// 
-// is the eventual goal for the interface to the svg object 
+// This allows the user to easily enter information than ordinary
+// method calls, and is more clear that the method supports chaining
 // -----------------------------------------------------------------
 svg& svg::operator<<(const svg_instruction& rhs)
 {
@@ -115,8 +118,9 @@
 }
 
 // -----------------------------------------------------------------
-// Stream operator to eventually stick data together in a stream-
-// like interface
+// Chained stream operators. Each operator overload below will
+// represent a different instruction type, after I rewrite svg's
+// instructions to be more generic.
 // -----------------------------------------------------------------
 svg& svg::operator<<(const svg_point &rhs)
 {
@@ -126,7 +130,7 @@
         _size((unsigned int)rhs.x, (unsigned int)rhs.y);
         break;
     case SVG_POINT:
-        _point(rhs.x, rhs.y);
+        _point(rhs.x, rhs.y, document);
     }
 
     return *this;
@@ -156,7 +160,6 @@
 // -----------------------------------------------------------------
 // Internal function to write the data to a specified stream
 // TODO: allow other streams than a file stream
-// TODO: Make a traversal of the new document structure
 // -----------------------------------------------------------------
 void svg::_write()
 {
@@ -183,14 +186,14 @@
     //Write all visual elements
     for(size_t i=0; i<document.size(); ++i)
     {
-        *s_out<<document[(unsigned int)i].to_string()<<std::endl;
+        document[ (unsigned int)i ].write(*s_out);
     }
 
     //end g tag
 }
 
 // -----------------------------------------------------------------
-// This prints the svg header into the document
+// This prints the svg 1.1 header into the document
 // -----------------------------------------------------------------
 void svg::_write_header()
 {
@@ -213,8 +216,15 @@
 // Writes the information about points to the document
 // Since a point is not visible, we are actually drawing small
 // circles
-// TODO: allow other unit identifiers
+// TODO: allow other unit identifiers, shapes
 // -----------------------------------------------------------------
+
+// this overload has a pointer to a node in the document tree
+void svg::_point(double x, double y, g_element& location)
+{
+    location.children.push_back(new point_element(x, y));
+}
+
 void svg::_point(double x, double y)
 {
     document.children.push_back(new point_element(x, y));
@@ -222,7 +232,6 @@
 
 // -----------------------------------------------------------------
 // Writes the information about lines to the document
-// TODO: allow other unit identifiers
 // TODO: Allow other line thicknesses
 // TODO: Allow other line colors
 // -----------------------------------------------------------------
@@ -231,8 +240,14 @@
     document.children.push_back(new line_element(x1, y1, x2, y2));
 }
 
+void svg::_line(double x1, double y1, double x2, double y2, 
+                g_element& location)
+{
+    location.children.push_back(new line_element(x1, y1, x2, y2));
+}
+
 // -----------------------------------------------------------------
-// Writes the information about lines to the document
+// Writes the information about text to the document
 // TODO: allow different fonts and font sizes
 // -----------------------------------------------------------------
 void svg::_text(double x, double y, std::string text)
@@ -241,23 +256,11 @@
 }
 
 // -----------------------------------------------------------------
-// TODO: Add all of the colors that are supported by the SVG format
-// TODO: Update to account for the tree structure of the document now
+// Hopefully this one will be filld out next week
 // -----------------------------------------------------------------
 void svg::_line_color(svg_color col)
 {
-    switch(col)
-    {
-    case BLACK:
-//        document[SVG_G_STROKE] = "stroke = \"black\"";
-        break;
-    case GRAY:
-//        document[SVG_G_STROKE] = "stroke = \"gray\"";
-        break;
-    case RED:
-//        document[SVG_G_STROKE] = "stroke = \"red\"";
-        break;
-    }
+
 }
 
 
Modified: sandbox/SOC/2007/visualization/boost/svg_plot/svg_instruction.hpp
==============================================================================
--- sandbox/SOC/2007/visualization/boost/svg_plot/svg_instruction.hpp	(original)
+++ sandbox/SOC/2007/visualization/boost/svg_plot/svg_instruction.hpp	2007-06-10 22:48:56 EDT (Sun, 10 Jun 2007)
@@ -13,6 +13,14 @@
 namespace boost {
 namespace svg {
 
+#include "svg_style.hpp"
+
+// -----------------------------------------------------------------
+// IMPORTANT: the contents of this file will likely be completely
+// rewritten when I redo the public interface for svg::svg. I'm
+// focusing on the interface for svg::svg_plot currently
+// -----------------------------------------------------------------
+
 enum instruction_type{SVG_POINT, SVG_WRITE, SVG_SIZE};
 
 // -----------------------------------------------------------------
@@ -65,7 +73,6 @@
 struct svg_stroke_color
 {
     svg_color col;
-
     svg_stroke_color(svg_color _c):col(_c)
     {
 
Modified: sandbox/SOC/2007/visualization/boost/svg_plot/svg_plot.hpp
==============================================================================
--- sandbox/SOC/2007/visualization/boost/svg_plot/svg_plot.hpp	(original)
+++ sandbox/SOC/2007/visualization/boost/svg_plot/svg_plot.hpp	2007-06-10 22:48:56 EDT (Sun, 10 Jun 2007)
@@ -10,7 +10,6 @@
 #ifndef _SVG_PLOT_HPP
 #define _SVG_PLOT_HPP
 
-
 #include <vector>
 #include <ostream>
 #include <sstream>
@@ -23,13 +22,50 @@
 namespace boost {
 namespace svg {
 
+// -----------------------------------------------------------------
+// The following enums define the tree for the document. The reason
+// that they are defined here is so that I can easily refer to them
+// when I'm building data. It's easier to refer to:
+//      document[SVG_PLOT_BACKGROUND].color()
+//
+// than it is to do it any other way I can think of.
+// -----------------------------------------------------------------
+#define SVG_PLOT_DOC_CHILDREN 3
+
+enum svg_plot_doc_structure{SVG_PLOT_BACKGROUND, SVG_PLOT_LEGEND,
+    SVG_PLOT_PLOT};
+
+// -----------------------------------------------------------------
+// The following enums define the children for the legend. This will be
+// incomplete, as the actual definition of the legend is fuzzy.
+// -----------------------------------------------------------------
+
+#define SVG_PLOT_DOC_LEGEND_CHILDREN 3
+
+enum svg_plot_doc_legend_structure{SVG_PLOT_LEGEND_BACKGROUND,
+    SVG_PLOT_LEGEND_POINTS, SVG_PLOT_LEGEND_TEXT};
+
+// -----------------------------------------------------------------
+// The following enums define the tree for the plot itself.
+// -----------------------------------------------------------------
+
+#define SVG_PLOT_DOC_PLOT_CHILDREN 5
+
+enum svg_plot_doc_plot_structure{SVG_PLOT_PLOT_BACKGROUND, SVG_PLOT_PLOT_AXIS, 
+    SVG_PLOT_PLOT_LABELS, SVG_PLOT_PLOT_LINES, SVG_PLOT_PLOT_POINTS};
+
+
+
 class svg_plot: public svg
 {
 private:
     double transform_matrix[3][3];
-    double plot_start, plot_interval;
 
-    double x_min, x_max, y_min, y_max;
+    double x_min, x_max;
+
+    //Still keep track of this for when we have a view window
+    //for the graph
+    double y_window_min, y_window_max; 
     
     //Don't let the user use this without specifying a stream.
     //I can't think of a reasonable default, and I don't think
@@ -37,14 +73,15 @@
     svg_plot();
 
     void _x_scale(double, double);
-    void _y_scale(double, double);
     void _plot_image_size(unsigned int, unsigned int);
-    void _set_start(double);
-    void _set_interval(double);
+
     void _plot_range(std::vector<double>::iterator,
-                std::vector<double>::iterator);
-    
-    void _transform_point(double &x, double &y);
+        std::vector<double>::iterator);
+    void _plot_range(std::vector<double>::iterator,
+        std::vector<double>::iterator,
+        svg_color);
+
+    void _transform_point(double &x);
     void _draw_axis();
     void _line_color(const svg_color&);
 
@@ -55,6 +92,7 @@
     svg_plot& operator<<(const plot_single_val&);
     svg_plot& operator<<(const plot_two_vals&);
     svg_plot& operator<<(const plot_draw_range&);
+    svg_plot& operator<<(const plot_draw_col_range&);
     svg_plot& operator<<(const plot_command&);
     svg_plot& operator<<(const plot_color&);
 };
@@ -65,6 +103,9 @@
 //
 // This performs work for default values so that if the user starts
 // adding data right away, we won't get abnormal results
+//
+// Note: All of the points are going to be on the same line, so
+// there is no sense calculating any aspect of the y value
 // -----------------------------------------------------------------
 svg_plot::svg_plot(const std::string& file): svg(file)
 {
@@ -76,22 +117,39 @@
         }
     }
     
+    //to determine: reasonable default values
     _size(100, 100);
+    
+    y_window_min = 0;
+    y_window_max = 100;
 
-    x_min = y_min = 0;
-    x_max = y_max = 10;
+    x_min = -10;
+    x_max = 10;
 
     transform_matrix[0][0] = transform_matrix[2][2] = transform_matrix[1][1] = 1;
 
     transform_matrix[0][2] = x_size * (-x_min / (x_min - x_max));
-    transform_matrix[1][2] = y_size - y_size*(-y_min / (y_min - y_max));
 
-    //to determine: reasonable default values
+    //build the document tree
+    for(int i=0; i<SVG_PLOT_DOC_CHILDREN; ++i)
+    {
+        document.children.push_back(new g_element());
+    }
+
+    for(int i=0; i<SVG_PLOT_DOC_PLOT_CHILDREN; ++i)
+    {
+        (static_cast<g_element*>
+            (&(document.children[SVG_PLOT_PLOT])))
+                ->children.push_back(new g_element());
+    }
     
-    plot_interval = 1;
-    plot_start = 1;
 }
 
+// -----------------------------------------------------------------
+// The chained stream operators. Each overload below deals with a
+// different instruction type by cases.
+// -----------------------------------------------------------------
+
 svg_plot& svg_plot::operator<<(const plot_two_vals& rhs)
 {
     switch(rhs.i_type)
@@ -99,10 +157,6 @@
     case PLOT_SCALE_X:
         _x_scale(rhs.x1, rhs.x2);
         break;
-
-    case PLOT_SCALE_Y:
-        _y_scale(rhs.x1, rhs.x2);
-        break;
     
     case PLOT_SIZE:
         _plot_image_size((unsigned int)rhs.x1, (unsigned int)rhs.x2);
@@ -114,16 +168,12 @@
 
 svg_plot& svg_plot::operator <<(const plot_single_val& rhs)
 {
-    switch(rhs.i_type)
+/*    switch(rhs.i_type)
     {
-    case PLOT_INTERVAL:
-        _set_interval(rhs.x);
-        break;
-
-    case PLOT_START:
-        _set_start(rhs.x);
+    default:
         break;
     }
+*/
     return (svg_plot&)*this;
 }
 
@@ -139,6 +189,12 @@
     return (svg_plot&)*this;
 }
 
+svg_plot& svg_plot::operator<<(const plot_draw_col_range& rhs)
+{
+    _plot_range(rhs.begin, rhs.end, rhs.fill_color);
+    return (svg_plot&)*this;
+}
+
 svg_plot& svg_plot::operator<<(const plot_color& rhs)
 {
     switch(rhs.i_type)
@@ -151,6 +207,9 @@
     return (svg_plot&)*this;
 }
 
+// -----------------------------------------------------------------
+// Set the scale for x values
+// -----------------------------------------------------------------
 void svg_plot::_x_scale(double x1, double x2)
 {
     x_min = x1;
@@ -165,103 +224,80 @@
     transform_matrix[0][2] = x_size*(-x1 / (x2 - x1));
 }
 
-void svg_plot::_y_scale(double y1, double y2)
-{
-    y_min = y1;
-    y_max = y2;
-
-    if(y2 <= y1)
-        throw "Illegal Argument: Y scale: y2 < y1";
-
-    transform_matrix[1][1] = -1. * y_size / (y2-y1);
-    transform_matrix[1][2] = y_size - y_size * (-y1 / (y2 - y1) );
-}
-
+// -----------------------------------------------------------------
+// set the size of the svg image produced
+// -----------------------------------------------------------------
 void svg_plot::_plot_image_size(unsigned int x, unsigned int y)
 {
     _size(x, y);
     
+    y_window_max = y;
+
     transform_matrix[0][2] = x_size * (-x_min / (x_min - x_max) );
-    transform_matrix[1][2] = y_size - y_size * (-y_min / (y_min - y_max));
 }
 
 // -----------------------------------------------------------------
-// The user needs to set the start value in order for the first
-// point of the plot to render in the right place
+// Actually draw data to the plot. Default color information
 // -----------------------------------------------------------------
-void svg_plot::_set_start(double x)
+void svg_plot::_plot_range(std::vector<double>::iterator begin,
+                            std::vector<double>::iterator end)
 {
-    plot_start = x;
+    double x;
+
+    double i=0;
+
+    double y_point = (y_window_min + y_window_max) / 2.;
+    
+    for(std::vector<double>::iterator b = begin; b!=end; ++b)
+    {
+        x = *b;
+        _transform_point(x);
+        _point(x, y_point, 
+            document.g_tag(SVG_PLOT_PLOT).g_tag(SVG_PLOT_PLOT_POINTS));
+    }
 }
 
 // -----------------------------------------------------------------
-// The user needs to set the interval to make each subsequent
-// node of the plot render in the right place
+// Actually draw data to the plot. Fill color information provided
 // -----------------------------------------------------------------
-void svg_plot::_set_interval(double x)
-{
-    plot_interval = x;
-}
-
 void svg_plot::_plot_range(std::vector<double>::iterator begin,
-                            std::vector<double>::iterator end)
+                            std::vector<double>::iterator end,
+                            svg_color _col)
 {
-    double x, y, x2, y2;
+    double x;
 
     double i=0;
 
-    if(begin+1 == end)
-    {
-        x = plot_start;
-        y = *begin;
+    double y_point = (y_window_min + y_window_max) / 2.;
 
-        _transform_point(x, y);
+    g_element* g_ptr = &(document.g_tag(SVG_PLOT_PLOT).
+        g_tag(SVG_PLOT_PLOT_POINTS));
 
-        _point(x, y);
-    }
-    else
-    {
-        for(std::vector<double>::iterator b = begin; 
-            (b + 1) != end; ++b)
-        {
-            x = plot_start + i;
-            y = *b;
-        
-            x2 = plot_start + (i + 1);
-            y2 = *(b + 1);
+    g_ptr->children.push_back(new g_element);
 
-            _transform_point(x, y);
-            _transform_point(x2, y2);
+    // this sets the current <g> element to the one that will contain
+    // the data that is being pushed back.
+    g_ptr = &(g_ptr->g_tag((int)(g_ptr->size())-1));
 
-            _line(x, y, x2, y2);
+    g_ptr->set_fill_color(_col);
 
-            i += plot_interval;
-        }
-    
-        i=0;
-
-        for(std::vector<double>::iterator b = begin; b!=end; ++b)
-        {
-            x = plot_start + i;
-            y = *b;
-
-            _transform_point(x, y);
-            _point(x, y);
-            i += plot_interval;
-        }
+    for(std::vector<double>::iterator b = begin; b!=end; ++b)
+    {
+        x = *b;
+        _transform_point(x);
+        _point(x, y_point, 
+            *g_ptr);
     }
 }
-
 // -----------------------------------------------------------------
-// This transforms a Cartesian point into a svg point. We don't
-// use the svg coordinate transform because sizing is a harder
+// This transforms a 1-D Cartesian point into a svg point. We don't
+// use the svg-defined coordinate transform because sizing is a harder
 // problem in the svg coordinate transforms, and text would be
 // flipped if were were to mimic the Cartesian system
 // -----------------------------------------------------------------
-void svg_plot::_transform_point(double &x, double &y)
+void svg_plot::_transform_point(double &x)
 {
     x = transform_matrix[0][0] * x + transform_matrix[0][2];
-    y = transform_matrix[1][1] * y + transform_matrix[1][2];
 }
 
 
@@ -270,57 +306,69 @@
 // -----------------------------------------------------------------
 void svg_plot::_draw_axis()
 {
-    //two major axes
-    double x1, y1, x2, y2;
+    // one major axis. We just need to draw a verticle line through
+    // the origin for now. We will make that an option later.
+
+    double x1, x2, y1, y2;
     
-    x1 = x2 = 0;
-    y1 = y_min;
-    y2 = y_max;
+    x1 = x_min;
+    x2 = x_max;
+
+    _transform_point(x2);
+    _transform_point(x1);
+
+    double y_mean = (y_window_min + y_window_max)/2.;
+    double x_mean = (x1 + x2)/2.;
 
-    _transform_point(x1,y1);
-    _transform_point(x2,y2);
+    _line(x1, y_mean, x2, y_mean, 
+        document.g_tag(SVG_PLOT_PLOT).g_tag(SVG_PLOT_PLOT_AXIS));
 
-    _line(x1, y1, x2, y2);
+    //origin
+    _line(x_mean, y_window_min, x_mean, y_window_max, 
+        document.g_tag(SVG_PLOT_PLOT).g_tag(SVG_PLOT_PLOT_AXIS));
 
     y1 = y2 = 0;
     x1 = x_min;
     x2 = x_max;
 
-    _transform_point(x1,y1);
-    _transform_point(x2,y2);
-
-    _line(x1, y1, x2, y2);
-
-    for(double i = x_min; i <= x_max; i += plot_interval)
+    for(double i = 0; i <= x_max; i += 1)
     {
-        y1 = .2;
-        y2 = -.2;
+        y1 = y_mean+5;
+        y2 = y_mean-5;
     
-        x1=x2=i;
+        x1=i;
 
-        _transform_point(x1, y1);
-        _transform_point(x2, y2);
+        _transform_point(x1);
+        _transform_point(x2);
 
-        _line(x1, y1, x2, y2);
+        _line(x1, y1, x1, y2, 
+            document.g_tag(SVG_PLOT_PLOT).g_tag(SVG_PLOT_PLOT_AXIS));
     }
 
-    for(double i = y_min; i <= y_max; i += plot_interval)
+    for(double i = 0; i >= x_min; i -= 1)
     {
-        x1 = .2;
-        x2 = -.2;
+        y1 = y_mean+5;
+        y2 = y_mean-5;
     
-        y1=y2=i;
+        x1=i;
 
-        _transform_point(x1, y1);
-        _transform_point(x2, y2);
+        _transform_point(x1);
 
-        _line(x1, y1, x2, y2);
+        _line(x1, y1, x1, y2,
+            document.g_tag(SVG_PLOT_PLOT).g_tag(SVG_PLOT_PLOT_AXIS));
     }
 }
 
+// -----------------------------------------------------------------
+// Set the line color. This currently gets overwritten by the
+// default for <g> in _plot_range, so this will be fixed, probably
+// by removing the default for <g> in the constructor (ran out of
+// time this week)
+// -----------------------------------------------------------------
 void svg_plot::_line_color(const svg_color& _col)
 {
-    
+    document.g_tag(SVG_PLOT_PLOT).g_tag(SVG_PLOT_PLOT_AXIS)
+        .set_stroke_color(_col);
 }
 
 }
Modified: sandbox/SOC/2007/visualization/boost/svg_plot/svg_plot_instruction.hpp
==============================================================================
--- sandbox/SOC/2007/visualization/boost/svg_plot/svg_plot_instruction.hpp	(original)
+++ sandbox/SOC/2007/visualization/boost/svg_plot/svg_plot_instruction.hpp	2007-06-10 22:48:56 EDT (Sun, 10 Jun 2007)
@@ -16,7 +16,10 @@
 namespace boost {
 namespace svg {
 
-enum plot_inst_type{PLOT_NONE, PLOT_SCALE_X, PLOT_SCALE_Y, PLOT_START, 
+// -----------------------------------------------------------------
+// This allows us to process operations by case in switch statements
+// -----------------------------------------------------------------
+enum plot_inst_type{PLOT_NONE, PLOT_SCALE_X, PLOT_START, 
                 PLOT_SIZE, PLOT_INTERVAL, PLOT_DRAW_AXIS, PLOT_LINE_COLOR};
 
 // -----------------------------------------------------------------
@@ -66,7 +69,7 @@
 };
 
 // -----------------------------------------------------------------
-// plot_scale is to handle commands that take two arguments
+// plot_scale is to handle commands that take two double arguments
 // -----------------------------------------------------------------
 struct plot_two_vals: public plot_instruction
 {
@@ -96,6 +99,9 @@
     }
 };
 
+// -----------------------------------------------------------------
+// For arguments of a color nature
+// -----------------------------------------------------------------
 struct plot_color: public plot_instruction
 {
     svg_color col;
@@ -107,9 +113,6 @@
     }
 };
 
-// -----------------------------------------------------------------
-// This is the instruction that deals with drawing ranges
-// -----------------------------------------------------------------
 struct plot_draw_range: public plot_instruction
 {
     std::vector<double>::iterator begin;
@@ -123,38 +126,49 @@
     }
 };
 
+// -----------------------------------------------------------------
+// fill_color defines the color of the points that are to be drawn
+// -----------------------------------------------------------------
+struct plot_draw_col_range: public plot_draw_range
+{
+    svg_color fill_color;
+
+    plot_draw_col_range(std::vector<double>::iterator _b,
+        std::vector<double>::iterator _e,
+        svg_color_constant _fill_color): 
+            fill_color(svg_color(_fill_color)), plot_draw_range(_b, _e)
+    {
+ 
+    }
+};
 
+// -----------------------------------------------------------------
+// The following functions return the values from the user
+// interface to values that the svg_plot class can understand
+// -----------------------------------------------------------------
 plot_two_vals x_scale(double x1, double x2)
 {
     return plot_two_vals(x1, x2, PLOT_SCALE_X);
 }
 
-plot_two_vals y_scale(double y1, double y2)
-{
-    return plot_two_vals(y1, y2, PLOT_SCALE_Y);
-}
-
 plot_two_vals image_size(int x, int y)
 {
     return plot_two_vals(x, y, PLOT_SIZE);
 }
 
-plot_single_val set_start(double x)
-{
-    return plot_single_val(x, PLOT_START);
-}
-
-plot_single_val set_interval(double x)
-{
-    return plot_single_val(x, PLOT_INTERVAL);
-}
-
 plot_draw_range plot_range(std::vector<double>::iterator begin,
                     std::vector<double>::iterator end)
 {
     return plot_draw_range(begin, end);
 }
 
+plot_draw_col_range plot_range(std::vector<double>::iterator begin,
+                    std::vector<double>::iterator end,
+                    svg_color_constant col)
+{
+    return plot_draw_col_range(begin, end, col);
+}
+
 plot_command draw_axis()
 {
     return plot_command(PLOT_DRAW_AXIS);
@@ -165,6 +179,11 @@
     return plot_color(c, PLOT_LINE_COLOR);
 }
 
+plot_color line_color(svg_color_constant c)
+{
+    return plot_color(constant_to_rgb(c), PLOT_LINE_COLOR);
+}
+
 }
 }
 
Modified: sandbox/SOC/2007/visualization/boost/svg_plot/svg_style.hpp
==============================================================================
--- sandbox/SOC/2007/visualization/boost/svg_plot/svg_style.hpp	(original)
+++ sandbox/SOC/2007/visualization/boost/svg_plot/svg_style.hpp	2007-06-10 22:48:56 EDT (Sun, 10 Jun 2007)
@@ -1,5 +1,4 @@
-// svg_tag.hpp
-
+// svg_style.hpp 
 // Copyright (C) Jacob Voytko 2007
 //
 // Distributed under the Boost Software License, Version 1.0.
@@ -10,17 +9,262 @@
 #ifndef _SVG_STYLE_HPP
 #define _SVG_STYLE_HPP
 
+#include <map>
+
 namespace boost {
 namespace svg {
 
 // -----------------------------------------------------------------
-// Deals with well-defined colors
+// Deals with colors that have special names. The reason that the
+// underscoring does not match the normal Boost format
+// is that these are the names that are specifically allowed by the
+// SVG standard
 // -----------------------------------------------------------------
-enum svg_color{BLACK, GRAY, RED};
+enum svg_color_constant
+{
+    aliceblue, antiquewhite, aqua, aquamarine, azure, beige, 
+    bisque, black, blanchedalmond, blue, blueviolet, brown, 
+    burlywood, cadetblue, chartreuse, chocolate, coral, 
+    cornflowerblue, cornsilk, crimson, cyan, darkblue, darkcyan, 
+    darkgoldenrod, darkgray, darkgreen, darkgrey, darkkhaki, 
+    darkmagenta, darkolivegreen, darkorange, darkorchid, darkred, 
+    darksalmon, darkseagreen, darkslateblue, darkslategray, 
+    darkslategrey, darkturquoise, darkviolet, deeppink, 
+    deepskyblue, dimgray, dimgrey, dodgerblue, firebrick, 
+    floralwhite, forestgreen, fuchsia, gainsboro, ghostwhite, gold, 
+    goldenrod, gray, grey, green, greenyellow, honeydew, hotpink, 
+    indianred, indigo, ivory, khaki, lavender, lavenderblush, 
+    lawngreen, lemonchiffon, lightblue, lightcoral, lightcyan, 
+    lightgoldenrodyellow, lightgray, lightgreen, lightgrey, 
+    lightpink, lightsalmon, lightseagreen, lightskyblue, 
+    lightslategray, lightslategrey, lightsteelblue, lightyellow, 
+    lime, limegreen, linen, magenta, maroon, mediumaquamarine, 
+    mediumblue, mediumorchid, mediumpurple, mediumseagreen, 
+    mediumslateblue, mediumspringgreen, mediumturquoise, 
+    mediumvioletred, midnightblue, mintcream, mistyrose, moccasin, 
+    navajowhite, navy, oldlace, olive, olivedrab, orange, 
+    orangered, orchid, palegoldenrod, palegreen, paleturquoise, 
+    palevioletred, papayawhip, peachpuff, peru, pink, plum, 
+    powderblue, purple, red, rosybrown, royalblue, saddlebrown, 
+    salmon, sandybrown, seagreen, seashell, sienna, silver, 
+    skyblue, slateblue, slategray, slategrey, snow, springgreen, 
+    steelblue, tan, teal, thistle, tomato, turquoise, violet, 
+    wheat, white, whitesmoke, yellow, yellowgreen
+};
+
 
+void constant_to_rgb(svg_color_constant _c, unsigned char &r, unsigned char &g, 
+            unsigned char &b);
 
 // -----------------------------------------------------------------
-// This is the style information for any <g> tag. 
+// svg_color is the struct that contains information about sRGB
+// colors.
+//
+// For the constructor: the svg standard specifies that numbers
+// outside the normal rgb range are to be accepted, but are rounded
+// to acceptable values.
+// -----------------------------------------------------------------
+struct svg_color
+{
+    unsigned char r, g, b;
+
+    svg_color(int _r, int _g, int _b)
+    {
+        _r = ( _r < 0 ) ? 0 : _r;
+        _g = ( _g < 0 ) ? 0 : _g;
+        _b = ( _b < 0 ) ? 0 : _b;
+
+        r = (unsigned char)(( _r > 255 ) ? 255 : _r);
+        g = (unsigned char)(( _g > 255 ) ? 255 : _g);
+        b = (unsigned char)(( _b > 255 ) ? 255 : _b);
+    }
+
+    svg_color(svg_color_constant _col)
+    {
+        constant_to_rgb(_col, r, g, b);
+    }
+
+    void write(std::ostream& rhs)
+    {
+        rhs << "rgb(" << (unsigned int)r << "," << (unsigned int) g << ","
+            << (unsigned int)b << ")" ;
+    }
+};
+
+// -----------------------------------------------------------------
+// To facilitate quick lookup of the RGB values of constants
+// -----------------------------------------------------------------
+svg_color color_array[] =
+{
+    svg_color(240, 248, 255), // aliceblue
+    svg_color(250, 235, 215), // antiquewhite
+    svg_color(0  , 255, 255), // aqua
+    svg_color(127, 255, 212), // aquamarine
+    svg_color(240, 255, 255), // azure
+    svg_color(245, 245, 220), // beige
+    svg_color(255, 228, 196), // bisque
+    svg_color(0  , 0  , 0  ), // black
+    svg_color(255, 235, 205), // blanchedalmond. Who thinks of these?
+    svg_color(0  , 0  , 255), // blue
+    svg_color(138, 43 , 226), // blueviolet
+    svg_color(165, 42 , 42 ), // brown
+    svg_color(222, 184, 135), // burlywood
+    svg_color(95 , 158, 160), // cadetblue
+    svg_color(127, 255, 0  ), // chartreuse
+    svg_color(210, 105, 30 ), // chocolate
+    svg_color(255, 127, 80 ), // coral
+    svg_color(100, 149, 237), // cornflowerblue
+    svg_color(255, 248, 220), // cornsilk
+    svg_color(220, 20 , 60 ), // crimson
+    svg_color(0  , 255, 255), // cyan
+    svg_color(0  , 0  , 139), // darkblue
+    svg_color(0  , 139, 139), // darkcyan
+    svg_color(184, 134, 11 ), // darkgoldenrod
+    svg_color(169, 169, 169), // darkgray
+    svg_color(0  , 100, 0  ), // darkgreen
+    svg_color(169, 169, 169), // darkgrey
+    svg_color(189, 183, 107), // darkkhaki
+    svg_color(139, 0  , 139), // darkmagenta
+    svg_color(85 , 107, 47 ), // darkolivegreen
+    svg_color(255, 140, 0  ), // darkorange
+    svg_color(153, 50 , 204), // darkorchid
+    svg_color(139, 0  , 0  ), // darkred
+    svg_color(233, 150, 122), // darksalmon
+    svg_color(143, 188, 143), // darkseagreen
+    svg_color(72 , 61 , 139), // darkslateblue
+    svg_color(47 , 79 , 79 ), // darkslategray
+    svg_color(47 , 79 , 79 ), // darkslategrey
+    svg_color(0  , 206, 209), // darkturquoise
+    svg_color(148, 0  , 211), // darkviolet
+    svg_color(255, 20 , 147), // deeppink
+    svg_color(0  , 191, 255), // deepskyblue
+    svg_color(105, 105, 105), // dimgray
+    svg_color(105, 105, 105), // dimgrey
+    svg_color(30 , 144, 255), // dodgerblue
+    svg_color(178, 34 , 34 ), // firebrick
+    svg_color(255, 250, 240), // floralwhite
+    svg_color(34 , 139, 34 ), // forestgreen
+    svg_color(255, 0  , 255), // fuchsia
+    svg_color(220, 220, 220), // gainsboro
+    svg_color(248, 248, 255), // ghostwhite
+    svg_color(255, 215, 0  ), // gold
+    svg_color(218, 165, 32 ), // goldenrod
+    svg_color(128, 128, 128), // gray
+    svg_color(128, 128, 128), // grey
+    svg_color(0  , 128, 0  ), // green
+    svg_color(173, 255, 47 ), // greenyellow
+    svg_color(240, 255, 240), // honeydew
+    svg_color(255, 105, 180), // hotpink
+    svg_color(205, 92 , 92 ), // indianred
+    svg_color(75 , 0  , 130), // indigo
+    svg_color(255, 255, 240), // ivory
+    svg_color(240, 230, 140), // khaki
+    svg_color(230, 230, 250), // lavender
+    svg_color(255, 240, 245), // lavenderblush
+    svg_color(124, 252, 0  ), // lawngreen
+    svg_color(255, 250, 205), // lemonchiffon
+    svg_color(173, 216, 230), // lightblue
+    svg_color(240, 128, 128), // lightcoral
+    svg_color(224, 255, 255), // lightcyan
+    svg_color(250, 250, 210), // lightgoldenrodyellow
+    svg_color(211, 211, 211), // lightgray
+    svg_color(144, 238, 144), // lightgreen
+    svg_color(211, 211, 211), // lightgrey
+    svg_color(255, 182, 193), // lightpink
+    svg_color(255, 160, 122), // lightsalmon
+    svg_color(32 , 178, 170), // lightseagreen
+    svg_color(135, 206, 250), // lightskyblue
+    svg_color(119, 136, 153), // lightslategray
+    svg_color(119, 136, 153), // lightslategrey
+    svg_color(176, 196, 222), // lightsteelblue
+    svg_color(255, 255, 224), // lightyellow
+    svg_color(0  , 255, 0  ), // lime
+    svg_color(50 , 205, 50 ), // limegreen
+    svg_color(250, 240, 230), // linen
+    svg_color(255, 0  , 255), // magenta
+    svg_color(128, 0  , 0  ), // maroon
+    svg_color(102, 205, 170), // mediumaquamarine
+    svg_color(0  , 0  , 205), // mediumblue
+    svg_color(186, 85 , 211), // mediumorchid
+    svg_color(147, 112, 219), // mediumpurple
+    svg_color(60 , 179, 113), // mediumseagreen
+    svg_color(123, 104, 238), // mediumslateblue
+    svg_color(0  , 250, 154), // mediumspringgreen
+    svg_color(72 , 209, 204), // mediumturquoise
+    svg_color(199, 21 , 133), // mediumvioletred
+    svg_color(25 , 25 , 112), // midnightblue
+    svg_color(245, 255, 250), // mintcream
+    svg_color(255, 228, 225), // mistyrose
+    svg_color(255, 228, 181), // moccasin
+    svg_color(255, 222, 173), // navajowhite
+    svg_color(0  , 0  , 128), // navy
+    svg_color(253, 245, 230), // oldlace
+    svg_color(128, 128, 0  ), // olive
+    svg_color(107, 142, 35 ), // olivedrab
+    svg_color(255, 165, 0  ), // orange
+    svg_color(255, 69 , 0  ), // orangered
+    svg_color(218, 122, 214), // orchid
+    svg_color(238, 232, 170), // palegoldenrod
+    svg_color(152, 251, 152), // palegreen
+    svg_color(175, 238, 238), // paleturquose
+    svg_color(219, 112, 147), // palevioletred
+    svg_color(255, 239, 213), // papayawhip
+    svg_color(255, 218, 185), // peachpuff
+    svg_color(205, 133, 63 ), // peru
+    svg_color(255, 192, 203), // pink
+    svg_color(221, 160, 221), // plum
+    svg_color(176, 224, 230), // powderblue
+    svg_color(128, 0  , 128), // purple
+    svg_color(255, 0  , 0  ), // red
+    svg_color(188, 143, 143), // rosybrown
+    svg_color(65 , 105, 225), // royalblue
+    svg_color(139, 69 , 19 ), // saddlebrown
+    svg_color(250, 128, 114), // salmon
+    svg_color(244, 164, 96 ), // sandybrown
+    svg_color(46 , 139, 87 ), // seagreen
+    svg_color(255, 245, 238), // seashell
+    svg_color(160, 82 , 45 ), // sienna
+    svg_color(192, 192, 192), // silver
+    svg_color(135, 206, 235), // skyblue
+    svg_color(106, 90 , 205), // slateblue
+    svg_color(112, 128, 144), // slategray
+    svg_color(112, 128, 144), // slategrey
+    svg_color(255, 250, 250), // snow
+    svg_color(0  , 255, 127), // springgreen
+    svg_color(70 , 130, 180), // steelblue
+    svg_color(210, 180, 140), // tan
+    svg_color(0  , 128, 128), // teal
+    svg_color(216, 191, 216), // thistle
+    svg_color(255, 99 , 71 ), // tomato
+    svg_color(64 , 224, 208), // turquoise
+    svg_color(238, 130, 238), // violet
+    svg_color(245, 222, 179), // wheat
+    svg_color(255, 255, 255), // white
+    svg_color(245, 245, 245), // whitesmoke
+    svg_color(255, 255, 0  ), // yellow
+    svg_color(154, 205, 50 ), // yellowgreen
+};
+
+
+void constant_to_rgb(svg_color_constant _c, unsigned char &r, unsigned char &g, 
+            unsigned char &b)
+{
+    r = color_array[(unsigned int)_c].r;
+    g = color_array[(unsigned int)_c].g;
+    b = color_array[(unsigned int)_c].b;
+}
+
+svg_color constant_to_rgb(svg_color_constant _c)
+{
+    return svg_color(color_array[(unsigned int)_c].r
+        ,color_array[(unsigned int)_c].g
+        ,color_array[(unsigned int)_c].b);
+}
+
+// -----------------------------------------------------------------
+// This is the style information for any <g> tag. This will be
+// expanded to include more data from the SVG standard when the
+// time comes.
 // -----------------------------------------------------------------
 class svg_g_style
 {
@@ -33,17 +277,21 @@
     svg_g_style(const svg_color&, const svg_color&);
     void set_fill_color(const svg_color&);
     void set_stroke_color(const svg_color&);
+    void write(std::ostream&);
 };
 
+
 // -----------------------------------------------------------------
 // These are the defaults that I used in the prototype, and they
 // looked decent enough.
 // -----------------------------------------------------------------
-svg_g_style::svg_g_style():fill_color(svg_color(RED)), stroke_color(svg_color(BLACK))
+svg_g_style::svg_g_style():fill_color(svg_color(255, 0, 0)), 
+    stroke_color(svg_color(0, 0, 0))
 {
 
 }
 
+
 // -----------------------------------------------------------------
 // For changing the defaults for the colors
 // -----------------------------------------------------------------
@@ -53,7 +301,28 @@
 
 }
 
+void svg_g_style::write(std::ostream& rhs)
+{
+    rhs << "stroke=\"";
+    stroke_color.write(rhs);
+    rhs << "\" fill=\"";
+    fill_color.write(rhs);
+    rhs<<"\"";
+}
+
+void svg_g_style::set_stroke_color(const svg_color& rhs)
+{
+    stroke_color = rhs;
+}
+
+void svg_g_style::set_fill_color(const svg_color& rhs)
+{
+    fill_color = rhs;
+}
+
+
 }//svg
 }//boost
 
-#endif
\ No newline at end of file
+
+#endif
Modified: sandbox/SOC/2007/visualization/boost/svg_plot/svg_tag.hpp
==============================================================================
--- sandbox/SOC/2007/visualization/boost/svg_plot/svg_tag.hpp	(original)
+++ sandbox/SOC/2007/visualization/boost/svg_plot/svg_tag.hpp	2007-06-10 22:48:56 EDT (Sun, 10 Jun 2007)
@@ -13,6 +13,7 @@
 #include <sstream>
 #include <string>
 #include <boost/ptr_container/ptr_container.hpp>
+#include <boost/noncopyable.hpp>
 
 #include "svg_style.hpp"
 
@@ -29,32 +30,34 @@
 // -----------------------------------------------------------------
 // The base class for all leaf elements
 // -----------------------------------------------------------------
-
-class svg_element : boost::noncopyable
+    
+class svg_element
 {
 public:
-    virtual std::string to_string()=0;
+    virtual void write(std::ostream&) = 0;
 };
 
 // -----------------------------------------------------------------
 // The node element of our document tree
 // -----------------------------------------------------------------
 
-class g_element
+class g_element: public svg_element
 {
 private: 
-    svg_g_style styleInfo;
+    svg_g_style style_info;
 
 public:
-    //public allows me to skip dozens of add_point, add_line, etc methods
-    //or polymorphic checks. Also allows the root element of the node
-    //to act as a makeshift DOM
-    boost::ptr_vector<svg_element> children;    
+    boost::ptr_vector<svg_element> children;
     
     svg_element& operator[](unsigned int);
     size_t size();
     
-    void set_line_color(const svg_color&);
+    void set_stroke_color(const svg_color&);
+    void set_fill_color(const svg_color&);
+
+    void write(std::ostream&);
+
+    g_element& g_tag(int);
 };
 
 svg_element& g_element::operator[](unsigned int i)
@@ -67,11 +70,37 @@
     return children.size();
 }
 
-void set_line_color(const svg_color& rhs)
+void g_element::write(std::ostream& rhs)
+{
+    rhs << "<g ";
+    style_info.write(rhs);
+    rhs<< " >" << std::endl;
+    
+    for(unsigned int i=0; i<children.size(); ++i)
+    {
+        children[i].write(rhs);
+    }
+
+    rhs << "</g>" << std::endl;
+
+}
+
+g_element& g_element::g_tag(int i)
+{
+    return *(static_cast<g_element*>(&children[i]));
+}
+
+void g_element::set_stroke_color(const svg_color& _col)
 {
+    style_info.set_stroke_color(_col);
+}
 
+void g_element::set_fill_color(const svg_color& _col)
+{
+    style_info.set_fill_color(_col);
 }
 
+
 // -----------------------------------------------------------------
 // Represents a single point
 // -----------------------------------------------------------------
@@ -82,7 +111,7 @@
 
 public:
     point_element(double, double);
-    std::string to_string();
+    void write(std::ostream&);
 };
 
 point_element::point_element(double _x, double _y):x(_x), y(_y)
@@ -90,16 +119,10 @@
     
 }
 
-std::string point_element::to_string()
+void point_element::write(std::ostream& rhs)
 {
-    std::stringstream fmt;
-
-    fmt<<"<circle cx=\""<<x<<"\" cy=\""<<y<<"\" r=\"5\" fill=\"red\" />";
-    
-    std::string to_ret;
-    std::getline(fmt, to_ret);
+    rhs<<"<circle cx=\""<<x<<"\" cy=\""<<y<<"\" r=\"5\"/>";
 
-    return to_ret;
 }
 
 // -----------------------------------------------------------------
@@ -112,7 +135,7 @@
 
 public:
     line_element(double, double, double, double);
-    std::string to_string();
+    void write(std::ostream&);
 };
 
 line_element::line_element(double _x1, double _y1, double _x2,
@@ -122,17 +145,10 @@
     
 }
 
-std::string line_element::to_string()
+void line_element::write(std::ostream& rhs)
 {
-    std::stringstream fmt;
-
-    fmt<<"<line stroke=\"black\" x1=\""<<x1<<"\" y1=\""<<y1<<"\" x2=\""<<x2<<"\" y2=\""
+    rhs<<"<line x1=\""<<x1<<"\" y1=\""<<y1<<"\" x2=\""<<x2<<"\" y2=\""
         <<y2<<"\"/>";
-    
-    std::string to_ret;
-    std::getline(fmt, to_ret);
-
-    return to_ret;
 }
 
 // -----------------------------------------------------------------
@@ -146,7 +162,7 @@
 
 public:
     text_element(double, double, std::string);
-    std::string to_string();
+    void write(std::ostream&);
 };
 
 text_element::text_element(double _x, double _y, std::string _text)
@@ -155,20 +171,13 @@
     
 }
 
-std::string text_element::to_string()
+void text_element::write(std::ostream& rhs)
 {
-    std::stringstream fmt;
-    std::string to_write;
-
-    fmt<<"<text x=\""<<x<<"\""
+    rhs<<"<text x=\""<<x<<"\""
                 <<" y=\""<<y<<"\" "
-                <<" font-family=\"Veranda\" font-size=\"12\" fill=\"black\">"
+                <<" font-family=\"Veranda\" font-size=\"12\" stroke=\"black\">"
                 << text
                 <<" </text>";
-
-    getline(fmt, to_write);
-
-    return to_write;
 }