Boost logo

Boost-Commit :

From: jakevoytko_at_[hidden]
Date: 2007-07-02 20:42:12


Author: jakevoytko
Date: 2007-07-02 20:42:10 EDT (Mon, 02 Jul 2007)
New Revision: 7342
URL: http://svn.boost.org/trac/boost/changeset/7342

Log:
2D graphs added, get_* methods,

Added:
   sandbox/SOC/2007/visualization/boost/svg_plot/svg_1d_plot.hpp
      - copied, changed from r7186, /sandbox/SOC/2007/visualization/boost/svg_plot/svg_plot.hpp
   sandbox/SOC/2007/visualization/boost/svg_plot/svg_2d_plot.hpp
Removed:
   sandbox/SOC/2007/visualization/boost/svg_plot/svg_plot.hpp
Text files modified:
   sandbox/SOC/2007/visualization/boost/svg_plot/detail/svg_style.hpp | 10
   sandbox/SOC/2007/visualization/boost/svg_plot/svg_1d_plot.hpp | 538 ++++++++++++++++++++++++++-------------
   sandbox/SOC/2007/visualization/boost/svg_plot/svg_test.cpp | 71 +++--
   3 files changed, 403 insertions(+), 216 deletions(-)

Modified: sandbox/SOC/2007/visualization/boost/svg_plot/detail/svg_style.hpp
==============================================================================
--- sandbox/SOC/2007/visualization/boost/svg_plot/detail/svg_style.hpp (original)
+++ sandbox/SOC/2007/visualization/boost/svg_plot/detail/svg_style.hpp 2007-07-02 20:42:10 EDT (Mon, 02 Jul 2007)
@@ -89,6 +89,14 @@
         rhs << "rgb(" << (unsigned int)r << "," << (unsigned int) g << ","
             << (unsigned int)b << ")" ;
     }
+
+ bool operator==(const svg_color& rhs)
+ {
+ if(r == rhs.r && g == rhs.g && b == rhs.b)
+ return true;
+
+ return false;
+ }
 };
 
 // -----------------------------------------------------------------
@@ -203,7 +211,7 @@
     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(218, 112, 214), // orchid
     svg_color(238, 232, 170), // palegoldenrod
     svg_color(152, 251, 152), // palegreen
     svg_color(175, 238, 238), // paleturquose

Copied: sandbox/SOC/2007/visualization/boost/svg_plot/svg_1d_plot.hpp (from r7186, /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_1d_plot.hpp 2007-07-02 20:42:10 EDT (Mon, 02 Jul 2007)
@@ -1,8 +1,4 @@
-
-
-
-
-// svg_plot.hpp
+// svg_1d_plot.hpp
 
 // Copyright (C) Jacob Voytko 2007
 //
@@ -11,8 +7,8 @@
 
 // -----------------------------------------------------------------
 
-#ifndef _SVG_PLOT_HPP
-#define _SVG_PLOT_HPP
+#ifndef _SVG_1D_PLOT_HPP
+#define _SVG_1D_PLOT_HPP
 
 #include <vector>
 #include <ostream>
@@ -34,11 +30,11 @@
 // -----------------------------------------------------------------
 enum plot_doc_structure{PLOT_BACKGROUND, PLOT_LEGEND_BACKGROUND,
     PLOT_LEGEND_POINTS, PLOT_LEGEND_TEXT, PLOT_PLOT_BACKGROUND,
- PLOT_PLOT_AXIS, PLOT_X_MINOR_TICKS, PLOT_X_MAJOR_TICKS,
- PLOT_PLOT_LABELS, PLOT_PLOT_LINES, PLOT_PLOT_POINTS, PLOT_X_LABEL,
- PLOT_TITLE};
+ PLOT_Y_AXIS, PLOT_X_AXIS, PLOT_Y_MINOR_TICKS, PLOT_X_MINOR_TICKS,
+ PLOT_Y_MAJOR_TICKS, PLOT_X_MAJOR_TICKS, PLOT_PLOT_LABELS,
+ PLOT_PLOT_LINES, PLOT_PLOT_POINTS, PLOT_Y_LABEL, PLOT_X_LABEL, PLOT_TITLE};
 
-#define SVG_PLOT_DOC_CHILDREN 13
+#define SVG_PLOT_DOC_CHILDREN 17
 
 // -----------------------------------------------------------------
 // This allows us to store plot state locally in svg_plot. We don't
@@ -64,18 +60,27 @@
     }
 };
 
-class svg_plot
+class svg_1d_plot
 {
-private:
+protected:
+
     //todo: replace with x_scale, x_shift, since I don't use the full matrix
     double transform_matrix[3][3];
 
     // stored so as to avoid rewriting style information constantly
     svg image;
 
- // where we will be storing the data points for transformation
- std::vector<svg_plot_series> series;
+ void _draw_x_axis();
+ void _draw_axis();
+
+
+ // border information for the plot window. Initially will be set to the width
+ // and height of the graph
+ int plot_window_x1, plot_window_x2,
+ plot_window_y1, plot_window_y2;
 
+ void _transform_point(double &x, double &y);
+
     // strings having to do with labels
     std::string x_label, title;
 
@@ -88,11 +93,6 @@
     unsigned int x_major_tick_length, x_minor_tick_length,
                  x_num_minor_ticks, legend_title_font_size;
 
- // border information for the plot window. Initially will be set to the width
- // and height of the graph
- int plot_window_x1, plot_window_x2,
- plot_window_y1, plot_window_y2;
-
     // Yes/no questions
     bool legend_on;
     bool axis_on;
@@ -100,26 +100,28 @@
     bool x_label_on;
     bool x_major_labels_on;
 
+ void _draw_x_label();
+
     // internal helper functions
- void _transform_point(double &x);
     void _clear_legend();
     void _draw_legend_header(int, int, int);
     void _draw_legend();
- void _draw_axis();
- void _draw_x_label();
+private:
+ // where we will be storing the data points for transformation
+ std::vector<svg_plot_series> series;
+
+ svg_1d_plot(const svg_1d_plot&);
+ svg_1d_plot& operator=(const svg_1d_plot&);
 
- svg_plot(const svg_plot&);
-
- svg_plot& operator=(const svg_plot&);
 public:
 
     // constructors
- svg_plot();
- svg_plot(const std::string& file);
+ svg_1d_plot();
+ svg_1d_plot(const std::string& file);
 
     // output
- svg_plot& write(const std::string&);
- svg_plot& write(std::ostream&);
+ svg_1d_plot& write(const std::string&);
+ svg_1d_plot& write(std::ostream&);
 
     
     // plot functions
@@ -132,68 +134,101 @@
     //setters
 
     // misc
- svg_plot& set_image_size(unsigned int, unsigned int);
- svg_plot& set_title(const std::string&);
- svg_plot& set_title_font_size(unsigned int);
- svg_plot& set_legend_title_font_size(unsigned int);
+ svg_1d_plot& set_image_size(unsigned int, unsigned int);
+ svg_1d_plot& set_title(const std::string&);
+ svg_1d_plot& set_title_font_size(unsigned int);
+ svg_1d_plot& set_legend_title_font_size(unsigned int);
 
     // commands
- svg_plot& set_axis(bool);
- svg_plot& set_legend(bool);
- svg_plot& set_plot_window(bool);
- svg_plot& set_x_label(bool);
- svg_plot& set_x_major_labels(bool);
+ svg_1d_plot& set_axis(bool);
+ svg_1d_plot& set_legend(bool);
+ svg_1d_plot& set_plot_window(bool);
+ svg_1d_plot& set_x_label(bool);
+ svg_1d_plot& set_x_major_labels(bool);
 
     // color information
- svg_plot& set_title_color(svg_color_constant);
- svg_plot& set_title_color(const svg_color&);
+ svg_1d_plot& set_title_color(svg_color_constant);
+ svg_1d_plot& set_title_color(const svg_color&);
+
+ svg_1d_plot& set_background_color(svg_color_constant);
+ svg_1d_plot& set_background_color(const svg_color&);
 
- svg_plot& set_background_color(svg_color_constant);
- svg_plot& set_background_color(const svg_color&);
+ svg_1d_plot& set_legend_background_color(svg_color_constant);
+ svg_1d_plot& set_legend_background_color(const svg_color&);
 
- svg_plot& set_legend_background_color(svg_color_constant);
- svg_plot& set_legend_background_color(const svg_color&);
+ svg_1d_plot& set_legend_border_color(svg_color_constant);
+ svg_1d_plot& set_legend_border_color(const svg_color&);
 
- svg_plot& set_plot_background_color(svg_color_constant);
- svg_plot& set_plot_background_color(const svg_color&);
+ svg_1d_plot& set_plot_background_color(svg_color_constant);
+ svg_1d_plot& set_plot_background_color(const svg_color&);
     
- svg_plot& set_x_axis_color(svg_color_constant);
- svg_plot& set_x_axis_color(const svg_color&);
+ svg_1d_plot& set_x_axis_color(svg_color_constant);
+ svg_1d_plot& set_x_axis_color(const svg_color&);
 
- svg_plot& set_x_major_tick_color(svg_color_constant);
- svg_plot& set_x_major_tick_color(const svg_color&);
+ svg_1d_plot& set_x_major_tick_color(svg_color_constant);
+ svg_1d_plot& set_x_major_tick_color(const svg_color&);
 
- svg_plot& set_x_minor_tick_color(svg_color_constant);
- svg_plot& set_x_minor_tick_color(const svg_color&);
+ svg_1d_plot& set_x_minor_tick_color(svg_color_constant);
+ svg_1d_plot& set_x_minor_tick_color(const svg_color&);
 
     // axis information
- svg_plot& set_x_scale(double, double);
+ svg_1d_plot& set_x_scale(double, double);
 
- svg_plot& set_x_axis_width(unsigned int);
+ svg_1d_plot& set_x_axis_width(unsigned int);
 
- svg_plot& set_x_major_tick(double);
- svg_plot& set_x_major_tick_length(unsigned int);
- svg_plot& set_x_minor_tick_length(unsigned int);
- svg_plot& set_x_num_minor_ticks(unsigned int);
- svg_plot& set_x_label_text(const std::string&);
- svg_plot& set_x_major_tick_width(unsigned int);
- svg_plot& set_x_minor_tick_width(unsigned int);
+ svg_1d_plot& set_x_major_tick(double);
+ svg_1d_plot& set_x_major_tick_length(unsigned int);
+ svg_1d_plot& set_x_minor_tick_length(unsigned int);
+ svg_1d_plot& set_x_num_minor_ticks(unsigned int);
+ svg_1d_plot& set_x_label_text(const std::string&);
+ svg_1d_plot& set_x_major_tick_width(unsigned int);
+ svg_1d_plot& set_x_minor_tick_width(unsigned int);
 
     // getters
- const std::string& get_title();
+ unsigned int get_image_x_size();
+ unsigned int get_image_y_size();
+ std::string get_title();
     unsigned int get_title_font_size();
+ unsigned int get_legend_title_font_size();
 
+ // commands
+ bool get_axis();
+ bool get_legend();
+ bool get_plot_window();
+ bool get_x_label();
+ bool get_x_major_labels();
+
+ // color information
+ svg_color get_title_color();
     svg_color get_background_color();
     svg_color get_legend_background_color();
- svg_color get_axis_color();
+ svg_color get_legend_border_color();
+ svg_color get_plot_background_color();
+ svg_color get_x_axis_color();
+ svg_color get_x_major_tick_color();
+ svg_color get_x_minor_tick_color();
 
- unsigned int get_axis_width();
+ // axis information
+ double get_x_min();
+ double get_x_max();
+
+ unsigned int get_x_axis_width();
+
+ double get_x_major_tick();
+ unsigned int get_x_major_tick_length();
+ unsigned int get_x_minor_tick_length();
+ unsigned int get_x_num_minor_ticks();
+ unsigned int get_x_major_tick_width();
+ unsigned int get_x_minor_tick_width();
+
+ std::string get_x_label_text();
 };
 
-svg_plot::svg_plot(): x_label(""), x_min(-10), x_max(10), plot_window_x1(0),
+svg_1d_plot::svg_1d_plot(): x_label(""), x_min(-10), x_max(10), plot_window_x1(0),
                       plot_window_y1(0), plot_window_x2(100),
                       plot_window_y2(100), x_axis(50), legend_on(false),
- axis_on(false), x_minor_tick_length(10),
+ axis_on(false), plot_window_on(false),x_major_tick(1),
+ x_minor_tick_length(10), x_num_minor_ticks(4),
                       legend_title_font_size(12)
 {
     for(int i = 0; i < 3; ++i)
@@ -215,7 +250,21 @@
 }
 
 
-svg_plot& svg_plot::write(const std::string& _str)
+svg_1d_plot& svg_1d_plot::write(const std::string& _str)
+{
+ std::ofstream fout(_str.c_str());
+
+ if(fout.fail())
+ {
+ throw "Failed to open "+_str;
+ }
+
+ svg_1d_plot::write(fout);
+
+ return *this;
+}
+
+svg_1d_plot& svg_1d_plot::write(std::ostream& s_out)
 {
     // Hold off drawing the legend until the very end.. it's
     // easier to draw the size that it needs at the end than
@@ -238,7 +287,7 @@
         plot_window_y1+=5;
         plot_window_y2-=5;
 
- if(axis_on)
+ if(legend_on)
         {
             plot_window_x2 -= 155;
         }
@@ -261,7 +310,7 @@
         
     if(axis_on)
     {
- _draw_axis();
+ _draw_x_axis();
     }
 
     if(legend_on)
@@ -275,7 +324,7 @@
     }
 
     double x1(0);
-
+ double y1(0);
     //draw points
     for(unsigned int i=0; i<series.size(); ++i)
     {
@@ -286,7 +335,7 @@
         {
             x1 = series[i].series[j];
 
- _transform_point(x1);
+ _transform_point(x1, y1);
             
             if(x1 > plot_window_x1 && x1 < plot_window_x2)
             {
@@ -295,30 +344,13 @@
         }
     }
 
- image.write(_str);
-
- return *this;
-}
-
-svg_plot& svg_plot::write(std::ostream& s_out)
-{
- if(legend_on)
- {
- _draw_legend();
- }
-
- if(axis_on)
- {
- _draw_axis();
- }
-
     image.write(s_out);
     
- return (svg_plot&)*this;
+ return (svg_1d_plot&)*this;
 }
 
 template <class iter>
-void plot_range(svg_plot& _cont, iter _begin, iter _end, std::string _str)
+void plot_range(svg_1d_plot& _cont, iter _begin, iter _end, std::string _str)
 {
     std::vector<double> vect(_begin, _end);
 
@@ -326,7 +358,7 @@
 }
 
 template <class iter>
-void plot_range(svg_plot& _cont, iter _begin, iter _end, std::string _str,
+void plot_range(svg_1d_plot& _cont, iter _begin, iter _end, std::string _str,
                       svg_color_constant _col)
 {
     std::vector<double> vect(_begin, _end);
@@ -337,7 +369,7 @@
 // -----------------------------------------------------------------
 // Actually draw data to the plot. Default color information
 // -----------------------------------------------------------------
-void svg_plot::plot_range(std::vector<double>::const_iterator begin,
+void svg_1d_plot::plot_range(std::vector<double>::const_iterator begin,
                             std::vector<double>::const_iterator end,
                             const std::string& _str)
 {
@@ -347,7 +379,7 @@
 // -----------------------------------------------------------------
 // Actually draw data to the plot. Fill color information provided
 // -----------------------------------------------------------------
-void svg_plot::plot_range(std::vector<double>::const_iterator begin,
+void svg_1d_plot::plot_range(std::vector<double>::const_iterator begin,
                             std::vector<double>::const_iterator end,
                             const std::string& _str,
                             svg_color_constant _col)
@@ -370,25 +402,26 @@
 //
 // set_legend_title_font_size(): As above
 // -----------------------------------------------------------------
-svg_plot& svg_plot::set_image_size(unsigned int x, unsigned int y)
+svg_1d_plot& svg_1d_plot::set_image_size(unsigned int x, unsigned int y)
 {
     image.image_size(x, y);
     
     return *this;
 }
 
-svg_plot& svg_plot::set_title(const std::string& _title)
+svg_1d_plot& svg_1d_plot::set_title(const std::string& _title)
 {
     text_element title(image.get_x_size()/2., 30, _title);
 
     title.set_alignment(center_align);
 
+ // problem here
     image.get_g_element(PLOT_TITLE).push_back(new text_element(title));
 
     return *this;
 }
 
-svg_plot& svg_plot::set_title_font_size(unsigned int _size)
+svg_1d_plot& svg_1d_plot::set_title_font_size(unsigned int _size)
 {
     text_element* t_ptr = static_cast<text_element*>(
                     &(image.get_g_element(PLOT_TITLE)[0]));
@@ -398,7 +431,7 @@
     return *this;
 }
 
-svg_plot& svg_plot::set_legend_title_font_size(unsigned int _size)
+svg_1d_plot& svg_1d_plot::set_legend_title_font_size(unsigned int _size)
 {
     legend_title_font_size = _size;
 
@@ -423,48 +456,48 @@
 //
 // -----------------------------------------------------------------
 
-svg_plot& svg_plot::set_axis(bool _cmd)
+svg_1d_plot& svg_1d_plot::set_axis(bool _cmd)
 {
     axis_on = _cmd;
- return (svg_plot&)*this;
+ return *this;
 }
 
-svg_plot& svg_plot::set_legend(bool _cmd)
+svg_1d_plot& svg_1d_plot::set_legend(bool _cmd)
 {
     legend_on = _cmd;
 
- return (svg_plot&)*this;
+ return *this;
 }
 
-svg_plot& svg_plot::set_plot_window(bool _cmd)
+svg_1d_plot& svg_1d_plot::set_plot_window(bool _cmd)
 {
     plot_window_on = _cmd;
 
- return (svg_plot&)*this;
+ return *this;
 }
 
-svg_plot& svg_plot::set_x_label(bool _cmd)
+svg_1d_plot& svg_1d_plot::set_x_label(bool _cmd)
 {
     x_label_on = _cmd;
 
     return *this;
 }
 
-svg_plot& svg_plot::set_x_major_labels(bool _cmd)
+svg_1d_plot& svg_1d_plot::set_x_major_labels(bool _cmd)
 {
     x_major_labels_on = _cmd;
 
     return *this;
 }
 
-svg_plot& svg_plot::set_title_color(svg_color_constant _col)
+svg_1d_plot& svg_1d_plot::set_title_color(svg_color_constant _col)
 {
     set_title_color(constant_to_rgb(_col));
 
     return *this;
 }
 
-svg_plot& svg_plot::set_title_color(const svg_color& _col)
+svg_1d_plot& svg_1d_plot::set_title_color(const svg_color& _col)
 {
     image.get_g_element(PLOT_TITLE).set_stroke_color(_col);
     image.get_g_element(PLOT_TITLE).set_fill_color(_col);
@@ -495,14 +528,14 @@
 //
 // set_x_minor_tick_color(): As above, but for minor ticks
 // -----------------------------------------------------------------
-svg_plot& svg_plot::set_background_color(svg_color_constant _col)
+svg_1d_plot& svg_1d_plot::set_background_color(svg_color_constant _col)
 {
     set_background_color(constant_to_rgb(_col));
 
     return *this;
 }
 
-svg_plot& svg_plot::set_background_color(const svg_color& _col)
+svg_1d_plot& svg_1d_plot::set_background_color(const svg_color& _col)
 {
     image.get_g_element(PLOT_BACKGROUND).set_fill_color(_col);
 
@@ -514,75 +547,87 @@
     return *this;
 }
 
-svg_plot& svg_plot::set_legend_background_color(svg_color_constant _col)
+svg_1d_plot& svg_1d_plot::set_legend_background_color(svg_color_constant _col)
 {
     set_legend_background_color(constant_to_rgb(_col));
 
- return (svg_plot&)*this;
+ return *this;
 }
 
-svg_plot& svg_plot::set_legend_background_color(const svg_color& _col)
+svg_1d_plot& svg_1d_plot::set_legend_background_color(const svg_color& _col)
 {
- image.get_g_element(PLOT_LEGEND_BACKGROUND)
- .set_fill_color(_col);
+ image.get_g_element(PLOT_LEGEND_BACKGROUND).set_fill_color(_col);
+
+ return *this;
+}
+
+svg_1d_plot& svg_1d_plot::set_legend_border_color(svg_color_constant _col)
+{
+ set_legend_border_color(constant_to_rgb(_col));
 
     return *this;
 }
 
-svg_plot& svg_plot::set_plot_background_color(svg_color_constant _col)
+svg_1d_plot& svg_1d_plot::set_legend_border_color(const svg_color& _col)
+{
+ image.get_g_element(PLOT_LEGEND_BACKGROUND).set_stroke_color(_col);
+
+ return *this;
+}
+
+svg_1d_plot& svg_1d_plot::set_plot_background_color(svg_color_constant _col)
 {
     image.get_g_element(PLOT_PLOT_BACKGROUND).set_fill_color(_col);
 
     return *this;
 }
 
-svg_plot& svg_plot::set_plot_background_color(const svg_color& _col)
+svg_1d_plot& svg_1d_plot::set_plot_background_color(const svg_color& _col)
 {
     image.get_g_element(PLOT_PLOT_BACKGROUND).set_fill_color(_col);
 
     return *this;
 }
 
-svg_plot& svg_plot::set_x_axis_color(svg_color_constant _col)
+svg_1d_plot& svg_1d_plot::set_x_axis_color(svg_color_constant _col)
 {
     set_x_axis_color(constant_to_rgb(_col));
 
- return (svg_plot&)*this;
+ return *this;
 }
 
-svg_plot& svg_plot::set_x_axis_color(const svg_color& _col)
+svg_1d_plot& svg_1d_plot::set_x_axis_color(const svg_color& _col)
 {
- image.get_g_element(PLOT_PLOT_AXIS)
+ image.get_g_element(PLOT_X_AXIS)
             .set_fill_color(_col);
 
- image.get_g_element(PLOT_PLOT_AXIS)
+ image.get_g_element(PLOT_X_AXIS)
             .set_stroke_color(_col);
 
     return *this;
 }
 
-svg_plot& svg_plot::set_x_major_tick_color(const svg_color& _col)
+svg_1d_plot& svg_1d_plot::set_x_major_tick_color(const svg_color& _col)
 {
     image.get_g_element(PLOT_X_MAJOR_TICKS).set_stroke_color(_col);
     image.get_g_element(PLOT_X_MAJOR_TICKS).set_fill_color(_col);
     return *this;
 }
 
-svg_plot& svg_plot::set_x_major_tick_color(svg_color_constant _col)
+svg_1d_plot& svg_1d_plot::set_x_major_tick_color(svg_color_constant _col)
 {
     set_x_major_tick_color(constant_to_rgb(_col));
     return *this;
 }
 
-svg_plot& svg_plot::set_x_minor_tick_color(const svg_color& _col)
+svg_1d_plot& svg_1d_plot::set_x_minor_tick_color(const svg_color& _col)
 {
     image.get_g_element(PLOT_X_MINOR_TICKS).set_stroke_color(_col);
     image.get_g_element(PLOT_X_MINOR_TICKS).set_fill_color(_col);
     return *this;
 }
 
-
-svg_plot& svg_plot::set_x_minor_tick_color(svg_color_constant _col)
+svg_1d_plot& svg_1d_plot::set_x_minor_tick_color(svg_color_constant _col)
 {
     set_x_minor_tick_color(constant_to_rgb(_col));
     return *this;
@@ -611,7 +656,7 @@
 // set_x_minor_tick_width(): Stroke width for minor ticks
 // -----------------------------------------------------------------
 
-svg_plot& svg_plot::set_x_scale(double x1, double x2)
+svg_1d_plot& svg_1d_plot::set_x_scale(double x1, double x2)
 {
     x_min = x1;
     x_max = x2;
@@ -621,56 +666,56 @@
         throw "Illegal Argument: X scale: x2 < x1";
     }
 
- return (svg_plot&)*this;
+ return (svg_1d_plot&)*this;
 }
 
-svg_plot& svg_plot::set_x_axis_width(unsigned int _width)
+svg_1d_plot& svg_1d_plot::set_x_axis_width(unsigned int _width)
 {
- image.get_g_element(PLOT_PLOT_AXIS).set_stroke_width(_width);
+ image.get_g_element(PLOT_X_AXIS).set_stroke_width(_width);
 
     return *this;
 }
 
-svg_plot& svg_plot::set_x_major_tick(double _inter)
+svg_1d_plot& svg_1d_plot::set_x_major_tick(double _inter)
 {
     x_major_tick = _inter;
 
     return *this;
 }
 
-svg_plot& svg_plot::set_x_major_tick_length(unsigned int _length)
+svg_1d_plot& svg_1d_plot::set_x_major_tick_length(unsigned int _length)
 {
     x_major_tick_length = _length;
     return *this;
 }
 
-svg_plot& svg_plot::set_x_minor_tick_length(unsigned int _length)
+svg_1d_plot& svg_1d_plot::set_x_minor_tick_length(unsigned int _length)
 {
     x_minor_tick_length = _length;
     return *this;
 }
 
-svg_plot& svg_plot::set_x_num_minor_ticks(unsigned int _num)
+svg_1d_plot& svg_1d_plot::set_x_num_minor_ticks(unsigned int _num)
 {
     x_num_minor_ticks = _num;
     return *this;
 }
 
-svg_plot& svg_plot::set_x_label_text(const std::string& _str)
+svg_1d_plot& svg_1d_plot::set_x_label_text(const std::string& _str)
 {
     x_label = _str;
 
     return *this;
 }
 
-svg_plot& svg_plot::set_x_major_tick_width(unsigned int _width)
+svg_1d_plot& svg_1d_plot::set_x_major_tick_width(unsigned int _width)
 {
     image.get_g_element(PLOT_X_MAJOR_TICKS).set_stroke_width(_width);
 
     return *this;
 }
 
-svg_plot& svg_plot::set_x_minor_tick_width(unsigned int _width)
+svg_1d_plot& svg_1d_plot::set_x_minor_tick_width(unsigned int _width)
 {
     image.get_g_element(PLOT_X_MINOR_TICKS).set_stroke_width(_width);
 
@@ -681,34 +726,28 @@
 // We don't use the SVG coordinate transform because then text would
 // be flipped. I'm considering using it to scale the image for resizes
 // -----------------------------------------------------------------
-void svg_plot::_transform_point(double &x)
+void svg_1d_plot::_transform_point(double &x, double &y)
 {
     x = transform_matrix[0][0] * x + transform_matrix[0][2];
+ y = transform_matrix[1][1] * y + transform_matrix[1][2];
 }
 
-//refactor
-void svg_plot::_draw_axis()
+void svg_1d_plot::_draw_x_axis()
 {
- // one major axis. We just need to draw a vertical line through
- // the origin for now. We will make that an option later.
- double x1, y1, y2;
-
- x_axis = (plot_window_y1 + plot_window_y2) / 2.;
+ double y1(0.), y2(0.), x1(0.), toss(0.);
 
- image.line(plot_window_x1, x_axis, plot_window_x2, x_axis,
- image.get_g_element(PLOT_PLOT_AXIS));
+ // draw the axis line
+ _transform_point(x1, y1);
 
- x1 = 0;
+ x_axis = y1;
 
- _transform_point(x1);
-
- image.line(x1, plot_window_y1, x1, plot_window_y2,
- image.get_g_element(PLOT_PLOT_AXIS));
-
- int major_tick_len = x_major_tick_length/2;
+ image.line(plot_window_x1, x_axis, plot_window_x2, x_axis,
+ image.get_g_element(PLOT_X_AXIS));
 
+ // draw the ticks on the positive side
     for(double i = 0; i < x_max; i += x_major_tick)
     {
+ //draw minor ticks
         for(double j=i; j<i+x_major_tick; j+=x_major_tick / (x_num_minor_ticks+1))
         {
             y1 = x_axis + x_minor_tick_length/2.;
@@ -716,7 +755,7 @@
 
             x1=j;
 
- _transform_point(x1);
+ _transform_point(x1, toss);
 
             //make sure that we are drawing inside of the allowed window
             if(x1 < plot_window_x2)
@@ -726,16 +765,17 @@
             }
         }
 
- y1 = x_axis + x_major_tick_length/2;
- y2 = x_axis - x_major_tick_length/2;
-
+ //draw major tick
         x1=i;
 
- _transform_point(x1);
+ _transform_point(x1, toss);
 
         //make sure that we are drawing inside of the allowed window
         if(x1 < plot_window_x2)
         {
+ y1 = x_axis + x_major_tick_length/2;
+ y2 = x_axis - x_major_tick_length/2;
+
             image.line(x1, y1, x1, y2,
                 image.get_g_element(PLOT_X_MAJOR_TICKS));
 
@@ -750,8 +790,10 @@
         }
     }
 
+ // draw the ticks on the negative side
     for(double i = 0; i > x_min; i -= x_major_tick)
     {
+ // draw minor ticks
         for(double j=i; j>i-x_major_tick; j-=x_major_tick / (x_num_minor_ticks+1))
         {
             y1 = x_axis + x_minor_tick_length/2.;
@@ -759,7 +801,7 @@
 
             x1=j;
 
- _transform_point(x1);
+ _transform_point(x1, toss);
 
             //make sure that we are drawing inside of the allowed window
             if(x1 > plot_window_x1)
@@ -768,12 +810,14 @@
                     image.get_g_element(PLOT_X_MINOR_TICKS));
             }
         }
- y1 = x_axis+major_tick_len;
- y2 = x_axis-major_tick_len;
+
+ //draw the major tick
+ y1 = x_axis+x_major_tick_length/2.;
+ y2 = x_axis-x_major_tick_length/2.;
     
         x1=i;
 
- _transform_point(x1);
+ _transform_point(x1, toss);
 
         if(x1 > plot_window_x1)
         {
@@ -791,13 +835,30 @@
     }
 }
 
+//refactor
+void svg_1d_plot::_draw_axis()
+{
+ double x1(0.), y1(0.);
+
+ _transform_point(x1, y1);
+
+ //draw origin. Make sure it is in the window
+ if(x1 > plot_window_x1 && x1 < plot_window_x2)
+ {
+ image.line(x1, plot_window_y1, x1, plot_window_y2,
+ image.get_g_element(PLOT_X_AXIS));
+ }
+
+ _draw_x_axis();
+}
+
 // -----------------------------------------------------------------
 // When writing to multiple documents, the contents of the plot
 // may change significantly between. Rather than figuring out what
 // has and has not changed, just erase the contents of the legend
 // in the document and start over.
 // -----------------------------------------------------------------
-void svg_plot::_clear_legend()
+void svg_1d_plot::_clear_legend()
 {
     g_element* g_ptr = &(image.get_g_element(PLOT_LEGEND_POINTS));
 
@@ -813,7 +874,7 @@
 // This function has some "magic" values that could be removed
 // or abstracted
 // -----------------------------------------------------------------
-void svg_plot::_draw_legend_header(int _x, int _y, int _width)
+void svg_1d_plot::_draw_legend_header(int _x, int _y, int _width)
 {
     // 2 added to y argument for padding.
     text_element legend_header(_x+(_width/2), _y + legend_title_font_size + 2, "Legend");
@@ -833,7 +894,7 @@
 // The legend will soon be a percentage of the window, which will
 // remove some of the magic values
 // -----------------------------------------------------------------
-void svg_plot::_draw_legend()
+void svg_1d_plot::_draw_legend()
 {
     _clear_legend();
 
@@ -850,16 +911,20 @@
        legend_width = (int)x_size;
     }
 
- int legend_x_start(plot_window_x2 + 5);
- int legend_y_start(plot_window_y1);
+ unsigned int legend_x_start(plot_window_x2 + 5);
+ unsigned int legend_y_start(plot_window_y1);
 
+ if((unsigned int)(plot_window_x2) >= image.get_x_size())
+ {
+ legend_x_start-=160;
+ legend_y_start+=5;
+ }
     // legend_height = title_spacing + (space per element)(num_elements)
     // + (end spacing)
     legend_height = (int)(legend_title_font_size*1.5 + (25 * num_points) + 10);
 
     // TODO: Figure out how tall the legend should be
 
- image.get_g_element(PLOT_LEGEND_BACKGROUND).set_stroke_color(svg_color(102, 102, 84));
     g_element* g_ptr = &(image.get_g_element(PLOT_LEGEND_BACKGROUND));
 
     g_ptr->push_back(new rect_element(legend_x_start,
@@ -889,7 +954,7 @@
     }
 }
 
-void svg_plot::_draw_x_label()
+void svg_1d_plot::_draw_x_label()
 {
     text_element to_use((plot_window_x2 + plot_window_x1) / 2., image.get_y_size() - 8, x_label);
 
@@ -903,39 +968,142 @@
     image.get_g_element(PLOT_X_LABEL).push_back(new text_element(to_use));
 }
 
-const std::string& svg_plot::get_title()
+unsigned int svg_1d_plot::get_image_x_size()
+{
+ return image.get_x_size();
+}
+
+unsigned int svg_1d_plot::get_image_y_size()
+{
+ return image.get_x_size();
+}
+
+std::string svg_1d_plot::get_title()
 {
     return title;
 }
 
-unsigned int svg_plot::get_title_font_size()
+unsigned int svg_1d_plot::get_legend_title_font_size()
+{
+ return legend_title_font_size;
+}
+
+ // commands
+bool svg_1d_plot::get_axis()
+{
+ return axis_on;
+}
+
+bool svg_1d_plot::get_legend()
+{
+ return legend_on;
+}
+
+bool svg_1d_plot::get_plot_window()
+{
+ return plot_window_on;
+}
+
+bool svg_1d_plot::get_x_label()
+{
+ return x_label_on;
+}
+
+bool svg_1d_plot::get_x_major_labels()
+{
+ return x_major_labels_on;
+}
+
+// color information
+svg_color svg_1d_plot::get_title_color()
 {
- return (static_cast<text_element*>(
- &(image.get_g_element(PLOT_TITLE)[0])))->get_font_size();
- return 0;
+ return image.get_g_element(PLOT_TITLE).get_fill_color();
 }
 
-svg_color svg_plot::get_background_color()
+svg_color svg_1d_plot::get_background_color()
 {
     return image.get_g_element(PLOT_BACKGROUND).get_fill_color();
- return svg_color(0,0,0);
 }
 
-svg_color svg_plot::get_legend_background_color()
+svg_color svg_1d_plot::get_legend_background_color()
 {
     return image.get_g_element(PLOT_LEGEND_BACKGROUND).get_fill_color();
- return svg_color(0,0,0);
 }
 
-svg_color svg_plot::get_axis_color()
+svg_color svg_1d_plot::get_legend_border_color()
+{
+ return image.get_g_element(PLOT_LEGEND_BACKGROUND).get_stroke_color();
+}
+
+svg_color svg_1d_plot::get_plot_background_color()
+{
+ return image.get_g_element(PLOT_PLOT_BACKGROUND).get_fill_color();
+}
+
+svg_color svg_1d_plot::get_x_axis_color()
+{
+ return image.get_g_element(PLOT_X_AXIS).get_stroke_color();
+}
+
+svg_color svg_1d_plot::get_x_major_tick_color()
+{
+ return image.get_g_element(PLOT_X_MAJOR_TICKS).get_stroke_color();
+}
+
+svg_color svg_1d_plot::get_x_minor_tick_color()
+{
+ return image.get_g_element(PLOT_X_MINOR_TICKS).get_stroke_color();
+}
+
+// axis information
+double svg_1d_plot::get_x_min()
+{
+ return x_min;
+}
+
+double svg_1d_plot::get_x_max()
+{
+ return x_max;
+}
+
+unsigned int svg_1d_plot::get_x_axis_width()
+{
+ return image.get_g_element(PLOT_X_AXIS).get_stroke_width();
+}
+
+double svg_1d_plot::get_x_major_tick()
+{
+ return x_major_tick;
+}
+
+unsigned int svg_1d_plot::get_x_major_tick_length()
+{
+ return x_major_tick_length;
+}
+
+unsigned int svg_1d_plot::get_x_minor_tick_length()
+{
+ return x_minor_tick_length;
+}
+
+unsigned int svg_1d_plot::get_x_num_minor_ticks()
+{
+ return x_num_minor_ticks;
+}
+
+unsigned int svg_1d_plot::get_x_major_tick_width()
+{
+ return image.get_g_element(PLOT_X_MAJOR_TICKS).get_stroke_width();
+}
+
+unsigned int svg_1d_plot::get_x_minor_tick_width()
 {
- return image.get_g_element(PLOT_PLOT_AXIS).get_stroke_color();
- return svg_color(0,0,0);
+ return image.get_g_element(PLOT_X_MINOR_TICKS).get_stroke_width();
 }
 
-unsigned int svg_plot::get_axis_width()
+std::string svg_1d_plot::get_x_label_text()
 {
- return image.get_g_element(PLOT_PLOT_AXIS).get_stroke_width();
+ return x_label;
 }
 
 

Added: sandbox/SOC/2007/visualization/boost/svg_plot/svg_2d_plot.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/visualization/boost/svg_plot/svg_2d_plot.hpp 2007-07-02 20:42:10 EDT (Mon, 02 Jul 2007)
@@ -0,0 +1,978 @@
+// svg_1d_plot.hpp
+
+// Copyright (C) Jacob Voytko 2007
+//
+// Distributed under the Boost Software License, Version 1.0.
+// For more information, see http://www.boost.org
+
+// -----------------------------------------------------------------
+
+#ifndef _SVG_2D_PLOT_HPP
+#define _SVG_2D_PLOT_HPP
+
+#include <map>
+#include <ostream>
+#include <sstream>
+#include <iterator>
+
+#include "svg_1d_plot.hpp"
+#include "detail/svg_plot_instruction.hpp"
+
+
+namespace boost {
+namespace svg {
+
+struct svg_2d_plot_series
+{
+ std::multimap<double, double> series;
+ std::string title;
+ svg_color style;
+
+ svg_2d_plot_series(std::multimap<double, double>::const_iterator _begin,
+ std::multimap<double, double>::const_iterator _end,
+ std::string _title,
+ const svg_color& _style):
+ series(_begin,_end),
+ title(_title),
+ style(_style)
+ {
+
+ }
+};
+
+class svg_2d_plot: public svg_1d_plot
+{
+private:
+ // where we will be storing the data points for transformation
+ std::vector<svg_2d_plot_series> series;
+
+ // strings having to do with labels
+ std::string y_label;
+
+ // axis information
+ double y_min, y_max;
+
+ double y_major_tick, y_axis;
+
+ unsigned int y_major_tick_length, y_minor_tick_length,
+ y_num_minor_ticks;
+
+ bool y_label_on;
+ bool y_major_labels_on;
+
+ void _draw_y_axis();
+ void _draw_axis();
+ void _draw_y_label();
+ void _draw_legend();
+
+ svg_2d_plot(const svg_2d_plot&);
+ svg_2d_plot& operator=(const svg_2d_plot&);
+
+public:
+
+ // constructors
+ svg_2d_plot();
+
+ // output
+ svg_2d_plot& write(const std::string&);
+ svg_2d_plot& write(std::ostream&);
+
+
+ // plot functions
+ void plot_range(std::multimap<double,double>::const_iterator,
+ std::multimap<double,double>::const_iterator, const std::string&);
+
+ void plot_range(std::multimap<double,double>::const_iterator,
+ std::multimap<double,double>::const_iterator, const std::string&,
+ svg_color_constant);
+
+ // setters
+
+ // Methods from the public interface of svg_1d_plot are
+ // wrapped here so that we may correctly use chaining
+
+ // misc
+ svg_2d_plot& set_image_size(unsigned int, unsigned int);
+ svg_2d_plot& set_title(const std::string&);
+ svg_2d_plot& set_title_font_size(unsigned int);
+ svg_2d_plot& set_legend_title_font_size(unsigned int);
+
+ // commands
+ svg_2d_plot& set_axis(bool);
+ svg_2d_plot& set_legend(bool);
+ svg_2d_plot& set_plot_window(bool);
+
+ svg_2d_plot& set_x_label(bool);
+ svg_2d_plot& set_x_major_labels(bool);
+
+ svg_2d_plot& set_y_label(bool);
+ svg_2d_plot& set_y_major_labels(bool);
+
+ // color information
+ svg_2d_plot& set_title_color(svg_color_constant);
+ svg_2d_plot& set_title_color(const svg_color&);
+
+ svg_2d_plot& set_background_color(svg_color_constant);
+ svg_2d_plot& set_background_color(const svg_color&);
+
+ svg_2d_plot& set_legend_background_color(svg_color_constant);
+ svg_2d_plot& set_legend_background_color(const svg_color&);
+
+ svg_2d_plot& set_legend_border_color(svg_color_constant);
+ svg_2d_plot& set_legend_border_color(const svg_color&);
+
+ svg_2d_plot& set_plot_background_color(svg_color_constant);
+ svg_2d_plot& set_plot_background_color(const svg_color&);
+
+ svg_2d_plot& set_x_axis_color(svg_color_constant);
+ svg_2d_plot& set_x_axis_color(const svg_color&);
+
+ svg_2d_plot& set_y_axis_color(svg_color_constant);
+ svg_2d_plot& set_y_axis_color(const svg_color&);
+
+ svg_2d_plot& set_x_major_tick_color(svg_color_constant);
+ svg_2d_plot& set_x_major_tick_color(const svg_color&);
+
+ svg_2d_plot& set_y_major_tick_color(svg_color_constant);
+ svg_2d_plot& set_y_major_tick_color(const svg_color&);
+
+ svg_2d_plot& set_x_minor_tick_color(svg_color_constant);
+ svg_2d_plot& set_x_minor_tick_color(const svg_color&);
+
+ svg_2d_plot& set_y_minor_tick_color(svg_color_constant);
+ svg_2d_plot& set_y_minor_tick_color(const svg_color&);
+
+ // axis information
+ svg_2d_plot& set_x_scale(double, double);
+ svg_2d_plot& set_y_scale(double, double);
+
+ svg_2d_plot& set_x_axis_width(unsigned int);
+ svg_2d_plot& set_y_axis_width(unsigned int);
+
+ svg_2d_plot& set_x_major_tick(double);
+ svg_2d_plot& set_x_major_tick_length(unsigned int);
+ svg_2d_plot& set_x_minor_tick_length(unsigned int);
+ svg_2d_plot& set_x_num_minor_ticks(unsigned int);
+ svg_2d_plot& set_x_label_text(const std::string&);
+ svg_2d_plot& set_x_major_tick_width(unsigned int);
+ svg_2d_plot& set_x_minor_tick_width(unsigned int);
+
+ svg_2d_plot& set_y_major_tick(double);
+ svg_2d_plot& set_y_major_tick_length(unsigned int);
+ svg_2d_plot& set_y_minor_tick_length(unsigned int);
+ svg_2d_plot& set_y_num_minor_ticks(unsigned int);
+ svg_2d_plot& set_y_label_text(const std::string&);
+ svg_2d_plot& set_y_major_tick_width(unsigned int);
+ svg_2d_plot& set_y_minor_tick_width(unsigned int);
+
+ // getters
+ const std::string& get_title();
+ unsigned int get_title_font_size();
+
+ svg_color get_background_color();
+ svg_color get_legend_background_color();
+ svg_color get_axis_color();
+
+ unsigned int get_axis_width();
+};
+
+svg_2d_plot::svg_2d_plot(): y_label(""), y_min(-10), y_max(10),
+ y_major_tick(1), y_label_on(false),
+ y_minor_tick_length(10), y_num_minor_ticks(4),
+ svg_1d_plot()
+{
+
+}
+
+
+svg_2d_plot& svg_2d_plot::write(const std::string& _str)
+{
+ std::ofstream fout(_str.c_str());
+
+ if(fout.fail())
+ {
+ throw "Failure opening "+_str;
+ }
+
+ write(fout);
+
+ return *this;
+}
+
+svg_2d_plot& svg_2d_plot::write(std::ostream& s_out)
+{
+ int x_size = image.get_x_size();
+ int y_size = image.get_y_size();
+
+ plot_window_x1 = plot_window_y1 = 0;
+ plot_window_x2 = image.get_x_size();
+ plot_window_y2 = image.get_y_size();
+
+ if(plot_window_on)
+ {
+ // give the plot window a natural bit of padding
+ plot_window_x1+=5;
+ plot_window_x2-=5;
+ plot_window_y1+=5;
+ plot_window_y2-=5;
+
+ if(legend_on)
+ {
+ plot_window_x2 -= 155;
+ }
+
+ if(x_label_on)
+ {
+ plot_window_y2 -= 20;
+ }
+
+ if(y_label_on)
+ {
+ plot_window_x1 += 20;
+ }
+
+ //for the title. Will take into account font size soon
+ plot_window_y1 +=40;
+
+ image.get_g_element(PLOT_PLOT_BACKGROUND).push_back(
+ new rect_element(plot_window_x1, plot_window_y1,
+ (plot_window_x2-plot_window_x1), plot_window_y2-plot_window_y1));
+ }
+
+ transform_matrix[0][0] = (plot_window_x2-plot_window_x1)/(x_max-x_min);
+ transform_matrix[0][2] = plot_window_x1 - (x_min *(plot_window_x2-plot_window_x1)/(x_max-x_min));
+
+ transform_matrix[1][1] = -(plot_window_y2-plot_window_y1)/(y_max-y_min);
+ transform_matrix[1][2] = plot_window_y1 - (y_max *(plot_window_y1-plot_window_y2)/(y_max-y_min));
+
+ if(axis_on)
+ {
+ _draw_y_axis();
+ _draw_x_axis();
+ }
+
+ if(legend_on)
+ {
+ _draw_legend();
+ }
+
+ if(x_label_on)
+ {
+ _draw_x_label();
+ }
+
+ //draw points
+ double x(0.), y(0.);
+ for(unsigned int i=0; i<series.size(); ++i)
+ {
+ g_element& g_ptr = image.get_g_element(PLOT_PLOT_POINTS).add_g_element();
+ g_ptr.set_fill_color(series[i].style);
+
+ for(std::multimap<double,double>::const_iterator j = series[i].series.begin();
+ j!=series[i].series.end(); ++j)
+ {
+ x = j->first;
+ y = j->second;
+
+ _transform_point(x, y);
+
+ if(x > plot_window_x1 && x < plot_window_x2
+ && y > plot_window_y1 && y < plot_window_y2)
+ {
+ image.point(x, y, g_ptr);
+ }
+ }
+ }
+
+ image.write(s_out);
+
+ return *this;
+}
+
+template <class iter>
+void plot_range(svg_2d_plot& _cont, iter _begin, iter _end, std::string _str)
+{
+ std::multimap<double, double> mult(_begin, _end);
+
+ _cont.plot_range(mult.begin(), mult.end(), _str);
+}
+
+template <class iter>
+void plot_range(svg_2d_plot& _cont, iter _begin, iter _end, std::string _str,
+ svg_color_constant _col)
+{
+ std::multimap<double, double> vect(_begin, _end);
+
+ _cont.plot_range(vect.begin(), vect.end(), _str, _col);
+}
+
+// -----------------------------------------------------------------
+// Actually draw data to the plot. Default color information
+// -----------------------------------------------------------------
+void svg_2d_plot::plot_range(std::multimap<double, double>::const_iterator begin,
+ std::multimap<double, double>::const_iterator end,
+ const std::string& _str)
+{
+ series.push_back(svg_2d_plot_series(begin, end, _str, svg_color(0,0,0)));
+}
+
+// -----------------------------------------------------------------
+// Actually draw data to the plot. Fill color information provided
+// -----------------------------------------------------------------
+void svg_2d_plot::plot_range(std::multimap<double, double>::const_iterator begin,
+ std::multimap<double, double>::const_iterator end,
+ const std::string& _str,
+ svg_color_constant _col)
+{
+ series.push_back(svg_2d_plot_series(begin, end, _str, constant_to_rgb(_col)));
+}
+
+// -----------------------------------------------------------------
+// Miscellaneous setter methods: those with no clear, definable home
+// in another category
+//
+// set_image_size(): sets image size in pixels. (x,y) corresponds
+// to point at lower right of graph
+//
+// set_title(): adds the text _title to the top of the screen
+//
+// set_title_font_size(): uses an internal variable to save state, to
+// avoid crashes when the title hasn't been
+// set yet
+//
+// set_legend_title_font_size(): As above
+// -----------------------------------------------------------------
+svg_2d_plot& svg_2d_plot::set_image_size(unsigned int x, unsigned int y)
+{
+ svg_1d_plot::set_image_size(x, y);
+
+ return *this;
+}
+
+svg_2d_plot& svg_2d_plot::set_title(const std::string& _title)
+{
+ svg_1d_plot::set_title(_title);
+
+ return *this;
+}
+
+svg_2d_plot& svg_2d_plot::set_title_font_size(unsigned int _size)
+{
+ svg_1d_plot::set_title_font_size(_size);
+
+ return *this;
+}
+
+svg_2d_plot& svg_2d_plot::set_legend_title_font_size(unsigned int _size)
+{
+ svg_1d_plot::set_legend_title_font_size(_size);
+
+ return *this;
+}
+
+// -----------------------------------------------------------------
+// Commands: Answers to yes or no questions (Example: Show the legend?)
+//
+// set_axis(): Whether or not the axis will show
+//
+// set_legend(): Whether or not the legend will show
+//
+// set_plot_window(): Whether or not the plot will be full screen or
+// in its own contained window
+//
+// set_x_label(): Wrapper for 1d function
+//
+// set_y_label(): Sets the label for the y-axis
+//
+// set_x_major_labels(): Wrapper for 1d function
+//
+// set_y_major_labels(): Determines whether or not y axis major labels
+// will be shown
+// -----------------------------------------------------------------
+
+svg_2d_plot& svg_2d_plot::set_axis(bool _cmd)
+{
+ svg_1d_plot::set_axis(_cmd);
+
+ return *this;
+}
+
+svg_2d_plot& svg_2d_plot::set_legend(bool _cmd)
+{
+ svg_1d_plot::set_legend(_cmd);
+
+ return *this;
+}
+
+svg_2d_plot& svg_2d_plot::set_plot_window(bool _cmd)
+{
+ svg_1d_plot::set_plot_window(_cmd);
+
+ return *this;
+}
+
+svg_2d_plot& svg_2d_plot::set_x_label(bool _cmd)
+{
+ svg_1d_plot::set_x_label(_cmd);
+
+ return *this;
+}
+
+svg_2d_plot& svg_2d_plot::set_y_label(bool _cmd)
+{
+ y_label_on = _cmd;
+
+ return *this;
+}
+
+svg_2d_plot& svg_2d_plot::set_x_major_labels(bool _cmd)
+{
+ svg_1d_plot::set_x_major_labels(_cmd);
+
+ return *this;
+}
+
+svg_2d_plot& svg_2d_plot::set_y_major_labels(bool _cmd)
+{
+ y_major_labels_on = _cmd;
+
+ return *this;
+}
+
+svg_2d_plot& svg_2d_plot::set_title_color(svg_color_constant _col)
+{
+ svg_1d_plot::set_title_color(constant_to_rgb(_col));
+
+ return *this;
+}
+
+svg_2d_plot& svg_2d_plot::set_title_color(const svg_color& _col)
+{
+ svg_1d_plot::set_title_color(_col);
+
+ return *this;
+}
+
+// -----------------------------------------------------------------
+// Color settings: Customization of colors found in the plot
+//
+// set_title_color(): Sets the color of the plot title
+//
+// set_background_color(): Sets the color of the background. This is
+// not the same as the plot window background
+//
+// set_legend_background_color():
+// Sets the background color of the legend
+//
+// set_plot_background_color():
+// Sets the background color of the plot area.
+// If plot_window_on is not set true, this
+// does not show
+//
+// set_axis_color(): Color of the x axis + origin
+//
+// set_x_major_tick_color(): Sets the color of the major ticks on
+// the x-axis
+//
+// set_x_minor_tick_color(): As above, but for minor ticks
+// -----------------------------------------------------------------
+svg_2d_plot& svg_2d_plot::set_background_color(svg_color_constant _col)
+{
+ svg_1d_plot::set_background_color(constant_to_rgb(_col));
+
+ return *this;
+}
+
+svg_2d_plot& svg_2d_plot::set_background_color(const svg_color& _col)
+{
+ svg_1d_plot::set_background_color(_col);
+
+ return *this;
+}
+
+svg_2d_plot& svg_2d_plot::set_legend_background_color(svg_color_constant _col)
+{
+ svg_1d_plot::set_legend_background_color(constant_to_rgb(_col));
+
+ return *this;
+}
+
+svg_2d_plot& svg_2d_plot::set_legend_background_color(const svg_color& _col)
+{
+ svg_1d_plot::set_legend_background_color(_col);
+
+ return *this;
+}
+
+svg_2d_plot& svg_2d_plot::set_legend_border_color(svg_color_constant _col)
+{
+ svg_1d_plot::set_legend_border_color(constant_to_rgb(_col));
+
+ return *this;
+}
+
+svg_2d_plot& svg_2d_plot::set_legend_border_color(const svg_color& _col)
+{
+ svg_1d_plot::set_legend_border_color(_col);
+
+ return *this;
+}
+
+svg_2d_plot& svg_2d_plot::set_plot_background_color(svg_color_constant _col)
+{
+ svg_1d_plot::set_plot_background_color(constant_to_rgb(_col));
+
+ return *this;
+}
+
+svg_2d_plot& svg_2d_plot::set_plot_background_color(const svg_color& _col)
+{
+ svg_1d_plot::set_plot_background_color(_col);
+
+ return *this;
+}
+
+svg_2d_plot& svg_2d_plot::set_x_axis_color(svg_color_constant _col)
+{
+ svg_1d_plot::set_x_axis_color(constant_to_rgb(_col));
+
+ return (svg_2d_plot&)*this;
+}
+
+svg_2d_plot& svg_2d_plot::set_x_axis_color(const svg_color& _col)
+{
+ svg_1d_plot::set_x_axis_color(_col);
+
+ return *this;
+}
+
+svg_2d_plot& svg_2d_plot::set_y_axis_color(svg_color_constant _col)
+{
+ set_y_axis_color(constant_to_rgb(_col));
+
+ return (svg_2d_plot&)*this;
+}
+
+svg_2d_plot& svg_2d_plot::set_y_axis_color(const svg_color& _col)
+{
+ image.get_g_element(PLOT_Y_AXIS)
+ .set_fill_color(_col);
+
+ image.get_g_element(PLOT_Y_AXIS)
+ .set_stroke_color(_col);
+
+ return *this;
+}
+
+svg_2d_plot& svg_2d_plot::set_x_major_tick_color(svg_color_constant _col)
+{
+ svg_1d_plot::set_x_major_tick_color(constant_to_rgb(_col));
+
+ return *this;
+}
+
+svg_2d_plot& svg_2d_plot::set_x_major_tick_color(const svg_color& _col)
+{
+ svg_1d_plot::set_x_major_tick_color(_col);
+
+ return *this;
+}
+
+svg_2d_plot& svg_2d_plot::set_y_major_tick_color(const svg_color& _col)
+{
+ image.get_g_element(PLOT_Y_MAJOR_TICKS).set_stroke_color(_col);
+ image.get_g_element(PLOT_Y_MAJOR_TICKS).set_fill_color(_col);
+ return *this;
+}
+
+svg_2d_plot& svg_2d_plot::set_y_major_tick_color(svg_color_constant _col)
+{
+ set_y_major_tick_color(constant_to_rgb(_col));
+ return *this;
+}
+
+svg_2d_plot& svg_2d_plot::set_x_minor_tick_color(svg_color_constant _col)
+{
+ svg_1d_plot::set_x_minor_tick_color(constant_to_rgb(_col));
+
+ return *this;
+}
+
+svg_2d_plot& svg_2d_plot::set_x_minor_tick_color(const svg_color& _col)
+{
+ svg_1d_plot::set_x_minor_tick_color(_col);
+ return *this;
+}
+
+svg_2d_plot& svg_2d_plot::set_y_minor_tick_color(const svg_color& _col)
+{
+ image.get_g_element(PLOT_Y_MINOR_TICKS).set_stroke_color(_col);
+ image.get_g_element(PLOT_Y_MINOR_TICKS).set_fill_color(_col);
+ return *this;
+}
+
+svg_2d_plot& svg_2d_plot::set_y_minor_tick_color(svg_color_constant _col)
+{
+ set_y_minor_tick_color(constant_to_rgb(_col));
+ return *this;
+}
+
+// -----------------------------------------------------------------
+// Axis information: Settings for customization of axis information
+//
+// set_x_scale(): sets the left and right max values for the x axis
+//
+// set_x_axis_width(): The width of the x axis
+//
+// set_x_major_tick(): The distance between the ticks of the x_axis
+//
+// set_x_major_tick_length(): How long each tick will be
+//
+// set_x_minor_tick_length(): How long each tick will be
+//
+// set_x_num_minor_ticks(): The number of minor ticks between each
+// major tick
+//
+// set_x_label_text(): Labelling for the x-axis
+//
+// set_x_major_tick_width(): Stroke width for major ticks
+//
+// set_x_minor_tick_width(): Stroke width for minor ticks
+//
+// All functions defined for x above are also defined for y
+// -----------------------------------------------------------------
+
+// x functions
+svg_2d_plot& svg_2d_plot::set_x_scale(double x1, double x2)
+{
+ svg_1d_plot::set_x_scale(x1, x2);
+
+ return *this;
+}
+
+svg_2d_plot& svg_2d_plot::set_x_axis_width(unsigned int _width)
+{
+ svg_1d_plot::set_x_axis_width(_width);
+
+ return *this;
+}
+
+svg_2d_plot& svg_2d_plot::set_x_major_tick(double _inter)
+{
+ svg_1d_plot::set_x_major_tick(_inter);
+
+ return *this;
+}
+
+svg_2d_plot& svg_2d_plot::set_x_major_tick_length(unsigned int _length)
+{
+ svg_1d_plot::set_x_major_tick_length(_length);
+ return *this;
+}
+
+svg_2d_plot& svg_2d_plot::set_x_minor_tick_length(unsigned int _length)
+{
+ svg_1d_plot::set_x_minor_tick_length(_length);
+ return *this;
+}
+
+svg_2d_plot& svg_2d_plot::set_x_num_minor_ticks(unsigned int _num)
+{
+ svg_1d_plot::set_x_num_minor_ticks(_num);
+ return *this;
+}
+
+svg_2d_plot& svg_2d_plot::set_x_label_text(const std::string& _str)
+{
+ svg_1d_plot::set_x_label_text(_str);
+
+ return *this;
+}
+
+svg_2d_plot& svg_2d_plot::set_x_major_tick_width(unsigned int _width)
+{
+ svg_1d_plot::set_x_major_tick_width(_width);
+
+ return *this;
+}
+
+svg_2d_plot& svg_2d_plot::set_x_minor_tick_width(unsigned int _width)
+{
+ svg_1d_plot::set_x_minor_tick_width(_width);
+
+ return *this;
+}
+
+//y functions
+
+svg_2d_plot& svg_2d_plot::set_y_scale(double y1, double y2)
+{
+ y_min = y1;
+ y_max = y2;
+
+ if(y2 <= y1)
+ {
+ throw "Illegal Argument: X scale: x2 < x1";
+ }
+
+ return *this;
+}
+
+svg_2d_plot& svg_2d_plot::set_y_axis_width(unsigned int _width)
+{
+ image.get_g_element(PLOT_Y_AXIS).set_stroke_width(_width);
+
+ return *this;
+}
+
+svg_2d_plot& svg_2d_plot::set_y_major_tick(double _inter)
+{
+ y_major_tick = _inter;
+
+ return *this;
+}
+
+svg_2d_plot& svg_2d_plot::set_y_major_tick_length(unsigned int _length)
+{
+ y_major_tick_length = _length;
+ return *this;
+}
+
+svg_2d_plot& svg_2d_plot::set_y_minor_tick_length(unsigned int _length)
+{
+ y_minor_tick_length = _length;
+ return *this;
+}
+
+svg_2d_plot& svg_2d_plot::set_y_num_minor_ticks(unsigned int _num)
+{
+ y_num_minor_ticks = _num;
+ return *this;
+}
+
+svg_2d_plot& svg_2d_plot::set_y_label_text(const std::string& _str)
+{
+ y_label = _str;
+
+ return *this;
+}
+
+svg_2d_plot& svg_2d_plot::set_y_major_tick_width(unsigned int _width)
+{
+ image.get_g_element(PLOT_Y_MAJOR_TICKS).set_stroke_width(_width);
+
+ return *this;
+}
+
+svg_2d_plot& svg_2d_plot::set_y_minor_tick_width(unsigned int _width)
+{
+ image.get_g_element(PLOT_Y_MINOR_TICKS).set_stroke_width(_width);
+
+ return *this;
+}
+
+void svg_2d_plot::_draw_y_axis()
+{
+ double x1(0.), x2(0.), y1(0.), y2(0.), toss(0.);
+
+ // draw the axis line
+ _transform_point(x1, y1);
+
+ y_axis = x1;
+
+ image.line(y_axis, plot_window_y1, y_axis, plot_window_y2,
+ image.get_g_element(PLOT_Y_AXIS));
+
+ // draw the ticks on the positive side
+ for(double i = 0; i < y_max; i += y_major_tick)
+ {
+ //draw minor ticks
+ for(double j=i+(y_major_tick / (y_num_minor_ticks+1));
+ j<i+y_major_tick;
+ j+=y_major_tick / (y_num_minor_ticks+1))
+ {
+ x1 = y_axis + y_minor_tick_length/2.;
+ x2 = y_axis - y_minor_tick_length/2.;
+
+ y1=j;
+
+ _transform_point(toss, y1);
+
+ //make sure that we are drawing inside of the allowed window
+ if(y1 > plot_window_y1)
+ {
+ image.line(x1, y1, x2, y1,
+ image.get_g_element(PLOT_Y_MINOR_TICKS));
+ }
+ }
+
+ //draw major tick
+ y1=i;
+ _transform_point(x1, y1);
+ _transform_point(x2, y2);
+
+ //make sure that we are drawing inside of the allowed window
+ if(y1 > plot_window_y1)
+ {
+ x1 = y_axis + y_major_tick_length/2;
+ x2 = y_axis - y_major_tick_length/2;
+
+ image.line(x1, y1, x2, y1,
+ image.get_g_element(PLOT_Y_MAJOR_TICKS));
+
+ if(y_major_labels_on && i != 0)
+ {
+ std::stringstream fmt;
+ fmt<<i;
+
+ image.text(x1, y1 + (2 + x_major_tick_length/2), fmt.str());
+ }
+ }
+ }
+
+ // draw the ticks on the negative side
+ for(double i = 0; i > y_min; i -= y_major_tick)
+ {
+ //draw minor ticks
+ for(double j=i-(y_major_tick / (y_num_minor_ticks+1));
+ j>i-y_major_tick;
+ j-=y_major_tick / (y_num_minor_ticks+1))
+ {
+ x1 = y_axis + y_minor_tick_length/2.;
+ x2 = y_axis - y_minor_tick_length/2.;
+
+ y1=j;
+
+ _transform_point(toss, y1);
+
+ //make sure that we are drawing inside of the allowed window
+ if(y1 < plot_window_y2)
+ {
+ image.line(x1, y1, x2, y1,
+ image.get_g_element(PLOT_Y_MINOR_TICKS));
+ }
+ }
+
+ //draw major tick
+ y1=i;
+ _transform_point(x1, y1);
+ _transform_point(x2, y2);
+
+ //make sure that we are drawing inside of the allowed window
+ if(y1 < plot_window_y2)
+ {
+ x1 = y_axis + y_major_tick_length/2;
+ x2 = y_axis - y_major_tick_length/2;
+
+ image.line(x1, y1, x2, y1,
+ image.get_g_element(PLOT_Y_MAJOR_TICKS));
+
+ if(y_major_labels_on && i != 0)
+ {
+ std::stringstream fmt;
+ fmt<<i;
+
+ image.text(x1, y1 + (2 + x_major_tick_length/2), fmt.str());
+ }
+ }
+ }
+
+}
+
+//refactor
+void svg_2d_plot::_draw_axis()
+{
+ _draw_y_axis();
+ _draw_x_axis();
+}
+
+void svg_2d_plot::_draw_y_label()
+{
+/* text_element to_use((plot_window_x2 + plot_window_x1) / 2., image.get_y_size() - 8, x_label);
+
+ to_use.set_font_size(12);
+ to_use.set_alignment(center_align);
+
+ image.get_g_element(PLOT_X_LABEL).set_stroke_color(white);
+ image.get_g_element(PLOT_X_LABEL).set_fill_color(white);
+
+
+ image.get_g_element(PLOT_X_LABEL).push_back(new text_element(to_use));
+*/
+}
+
+// -----------------------------------------------------------------
+// Important note: there are a lot of magic numbers that are temporary
+// fill-ins for the time when the legend system is more configurable.
+// This will happen bit-by-bit, as I give the user options to change
+// these values
+//
+// The legend will soon be a percentage of the window, which will
+// remove some of the magic values
+// -----------------------------------------------------------------
+void svg_2d_plot::_draw_legend()
+{
+ _clear_legend();
+
+ int num_points = (int)(series.size());
+
+ int legend_width(150);
+ int legend_height(25);
+
+ int x_size = image.get_x_size();
+
+ // Figure out how wide the legend should be
+ if(x_size < 200)
+ {
+ legend_width = (int)x_size;
+ }
+
+ unsigned int legend_x_start(plot_window_x2 + 5);
+ unsigned int legend_y_start(plot_window_y1);
+
+ if((unsigned int)(plot_window_x2) >= image.get_x_size())
+ {
+ legend_x_start-=160;
+ legend_y_start+=5;
+ }
+
+ // legend_height = title_spacing + (space per element)(num_elements)
+ // + (end spacing)
+ legend_height = (int)(legend_title_font_size*1.5 + (25 * num_points) + 10);
+
+ // TODO: Figure out how tall the legend should be
+
+ g_element* g_ptr = &(image.get_g_element(PLOT_LEGEND_BACKGROUND));
+
+ g_ptr->push_back(new rect_element(legend_x_start,
+ legend_y_start,
+ legend_width,
+ legend_height));
+
+ _draw_legend_header(legend_x_start, legend_y_start, legend_width);
+
+ g_ptr = &(image.get_g_element(PLOT_LEGEND_POINTS));
+
+ g_element* g_inner_ptr = g_ptr;
+
+ for(unsigned int i=0; i<series.size(); ++i)
+ {
+ g_inner_ptr = &(g_ptr->add_g_element());
+
+ g_inner_ptr->set_fill_color(series[i].style);
+ g_inner_ptr->set_stroke_color(series[i].style);
+
+ g_inner_ptr->push_back(new point_element(legend_x_start + 25,
+ legend_y_start + legend_title_font_size + 20 + i*25));
+
+ g_inner_ptr->push_back(new text_element(legend_x_start + 40,
+ legend_y_start + legend_title_font_size + 25 + i*25,
+ series[i].title));
+ }
+}
+
+
+}
+}
+
+#endif
\ No newline at end of file

Deleted: sandbox/SOC/2007/visualization/boost/svg_plot/svg_plot.hpp
==============================================================================
--- sandbox/SOC/2007/visualization/boost/svg_plot/svg_plot.hpp 2007-07-02 20:42:10 EDT (Mon, 02 Jul 2007)
+++ (empty file)
@@ -1,946 +0,0 @@
-
-
-
-
-// svg_plot.hpp
-
-// Copyright (C) Jacob Voytko 2007
-//
-// Distributed under the Boost Software License, Version 1.0.
-// For more information, see http://www.boost.org
-
-// -----------------------------------------------------------------
-
-#ifndef _SVG_PLOT_HPP
-#define _SVG_PLOT_HPP
-
-#include <vector>
-#include <ostream>
-#include <sstream>
-#include <iterator>
-
-#include "svg.hpp"
-#include "detail/svg_plot_instruction.hpp"
-
-
-namespace boost {
-namespace svg {
-
-// -----------------------------------------------------------------
-// This is the base level of the "tree" for the SVG document. It is
-// flattened in order to facilitate using other image formats in the
-// future that don't have the benefit of a document tree. It also
-// greatly simplifies the logic of the methods below
-// -----------------------------------------------------------------
-enum plot_doc_structure{PLOT_BACKGROUND, PLOT_LEGEND_BACKGROUND,
- PLOT_LEGEND_POINTS, PLOT_LEGEND_TEXT, PLOT_PLOT_BACKGROUND,
- PLOT_PLOT_AXIS, PLOT_X_MINOR_TICKS, PLOT_X_MAJOR_TICKS,
- PLOT_PLOT_LABELS, PLOT_PLOT_LINES, PLOT_PLOT_POINTS, PLOT_X_LABEL,
- PLOT_TITLE};
-
-#define SVG_PLOT_DOC_CHILDREN 13
-
-// -----------------------------------------------------------------
-// This allows us to store plot state locally in svg_plot. We don't
-// store it in "svg" because transforming the points after they are
-// written to the document would be difficult. We store the Cartesian
-// coordinates locally and transform them before we write them.
-// -----------------------------------------------------------------
-struct svg_plot_series
-{
- std::vector<double> series;
- std::string title;
- svg_color style;
-
- svg_plot_series(std::vector<double>::const_iterator _begin,
- std::vector<double>::const_iterator _end,
- std::string _title,
- const svg_color& _style):
- series(_begin,_end),
- title(_title),
- style(_style)
- {
-
- }
-};
-
-class svg_plot
-{
-private:
- //todo: replace with x_scale, x_shift, since I don't use the full matrix
- double transform_matrix[3][3];
-
- // stored so as to avoid rewriting style information constantly
- svg image;
-
- // where we will be storing the data points for transformation
- std::vector<svg_plot_series> series;
-
- // strings having to do with labels
- std::string x_label, title;
-
- // axis information. y_axis stored as one point because this is a 1D graph
- double x_min, x_max;
- double x_axis;
-
- double x_major_tick;
-
- unsigned int x_major_tick_length, x_minor_tick_length,
- x_num_minor_ticks, legend_title_font_size;
-
- // border information for the plot window. Initially will be set to the width
- // and height of the graph
- int plot_window_x1, plot_window_x2,
- plot_window_y1, plot_window_y2;
-
- // Yes/no questions
- bool legend_on;
- bool axis_on;
- bool plot_window_on;
- bool x_label_on;
- bool x_major_labels_on;
-
- // internal helper functions
- void _transform_point(double &x);
- void _clear_legend();
- void _draw_legend_header(int, int, int);
- void _draw_legend();
- void _draw_axis();
- void _draw_x_label();
-
- svg_plot(const svg_plot&);
-
- svg_plot& operator=(const svg_plot&);
-public:
-
- // constructors
- svg_plot();
- svg_plot(const std::string& file);
-
- // output
- svg_plot& write(const std::string&);
- svg_plot& write(std::ostream&);
-
-
- // plot functions
- void plot_range(std::vector<double>::const_iterator,
- std::vector<double>::const_iterator, const std::string&);
-
- void plot_range(std::vector<double>::const_iterator,
- std::vector<double>::const_iterator, const std::string&, svg_color_constant);
-
- //setters
-
- // misc
- svg_plot& set_image_size(unsigned int, unsigned int);
- svg_plot& set_title(const std::string&);
- svg_plot& set_title_font_size(unsigned int);
- svg_plot& set_legend_title_font_size(unsigned int);
-
- // commands
- svg_plot& set_axis(bool);
- svg_plot& set_legend(bool);
- svg_plot& set_plot_window(bool);
- svg_plot& set_x_label(bool);
- svg_plot& set_x_major_labels(bool);
-
- // color information
- svg_plot& set_title_color(svg_color_constant);
- svg_plot& set_title_color(const svg_color&);
-
- svg_plot& set_background_color(svg_color_constant);
- svg_plot& set_background_color(const svg_color&);
-
- svg_plot& set_legend_background_color(svg_color_constant);
- svg_plot& set_legend_background_color(const svg_color&);
-
- svg_plot& set_plot_background_color(svg_color_constant);
- svg_plot& set_plot_background_color(const svg_color&);
-
- svg_plot& set_x_axis_color(svg_color_constant);
- svg_plot& set_x_axis_color(const svg_color&);
-
- svg_plot& set_x_major_tick_color(svg_color_constant);
- svg_plot& set_x_major_tick_color(const svg_color&);
-
- svg_plot& set_x_minor_tick_color(svg_color_constant);
- svg_plot& set_x_minor_tick_color(const svg_color&);
-
- // axis information
- svg_plot& set_x_scale(double, double);
-
- svg_plot& set_x_axis_width(unsigned int);
-
- svg_plot& set_x_major_tick(double);
- svg_plot& set_x_major_tick_length(unsigned int);
- svg_plot& set_x_minor_tick_length(unsigned int);
- svg_plot& set_x_num_minor_ticks(unsigned int);
- svg_plot& set_x_label_text(const std::string&);
- svg_plot& set_x_major_tick_width(unsigned int);
- svg_plot& set_x_minor_tick_width(unsigned int);
-
- // getters
- const std::string& get_title();
- unsigned int get_title_font_size();
-
- svg_color get_background_color();
- svg_color get_legend_background_color();
- svg_color get_axis_color();
-
- unsigned int get_axis_width();
-};
-
-svg_plot::svg_plot(): x_label(""), x_min(-10), x_max(10), plot_window_x1(0),
- plot_window_y1(0), plot_window_x2(100),
- plot_window_y2(100), x_axis(50), legend_on(false),
- axis_on(false), x_minor_tick_length(10),
- legend_title_font_size(12)
-{
- for(int i = 0; i < 3; ++i)
- {
- for(int j = 0; j < 3; ++j)
- {
- transform_matrix[i][j] = 0;
- }
- }
-
- //to determine: reasonable default values
- set_image_size(100, 100);
-
- //build the document tree.. add children of the root node
- for(int i=0; i<SVG_PLOT_DOC_CHILDREN; ++i)
- {
- image.add_g_element();
- }
-}
-
-
-svg_plot& svg_plot::write(const std::string& _str)
-{
- // Hold off drawing the legend until the very end.. it's
- // easier to draw the size that it needs at the end than
- // it is to
- // Don't bother with re-adding things if we don't need to
-
- int x_size = image.get_x_size();
- int y_size = image.get_y_size();
-
- x_axis = (plot_window_y2 + plot_window_y1)/2.;
-
- plot_window_x1 = plot_window_y1 = 0;
- plot_window_x2 = image.get_x_size();
- plot_window_y2 = image.get_y_size();
-
- if(plot_window_on)
- {
- plot_window_x1+=5;
- plot_window_x2-=5;
- plot_window_y1+=5;
- plot_window_y2-=5;
-
- if(axis_on)
- {
- plot_window_x2 -= 155;
- }
-
- if(x_label_on)
- {
- plot_window_y2 -= 20;
- }
-
- //for the title. Will take into account font size soon
- plot_window_y1 +=40;
-
- image.get_g_element(PLOT_PLOT_BACKGROUND).push_back(
- new rect_element(plot_window_x1, plot_window_y1,
- (plot_window_x2-plot_window_x1), plot_window_y2-plot_window_y1));
- }
-
- transform_matrix[0][0] = (plot_window_x2-plot_window_x1)/(x_max-x_min);
- transform_matrix[0][2] = plot_window_x1 - (x_min *(plot_window_x2-plot_window_x1)/(x_max-x_min));
-
- if(axis_on)
- {
- _draw_axis();
- }
-
- if(legend_on)
- {
- _draw_legend();
- }
-
- if(x_label_on)
- {
- _draw_x_label();
- }
-
- double x1(0);
-
- //draw points
- for(unsigned int i=0; i<series.size(); ++i)
- {
- g_element& g_ptr = image.get_g_element(PLOT_PLOT_POINTS).add_g_element();
- g_ptr.set_fill_color(series[i].style);
-
- for(unsigned int j=0; j<series[i].series.size(); ++j)
- {
- x1 = series[i].series[j];
-
- _transform_point(x1);
-
- if(x1 > plot_window_x1 && x1 < plot_window_x2)
- {
- image.point(x1, x_axis, g_ptr);
- }
- }
- }
-
- image.write(_str);
-
- return *this;
-}
-
-svg_plot& svg_plot::write(std::ostream& s_out)
-{
- if(legend_on)
- {
- _draw_legend();
- }
-
- if(axis_on)
- {
- _draw_axis();
- }
-
- image.write(s_out);
-
- return (svg_plot&)*this;
-}
-
-template <class iter>
-void plot_range(svg_plot& _cont, iter _begin, iter _end, std::string _str)
-{
- std::vector<double> vect(_begin, _end);
-
- _cont.plot_range(vect.begin(), vect.end(), _str);
-}
-
-template <class iter>
-void plot_range(svg_plot& _cont, iter _begin, iter _end, std::string _str,
- svg_color_constant _col)
-{
- std::vector<double> vect(_begin, _end);
-
- _cont.plot_range(vect.begin(), vect.end(), _str, _col);
-}
-
-// -----------------------------------------------------------------
-// Actually draw data to the plot. Default color information
-// -----------------------------------------------------------------
-void svg_plot::plot_range(std::vector<double>::const_iterator begin,
- std::vector<double>::const_iterator end,
- const std::string& _str)
-{
- series.push_back(svg_plot_series(begin, end, _str, svg_color(0,0,0)));
-}
-
-// -----------------------------------------------------------------
-// Actually draw data to the plot. Fill color information provided
-// -----------------------------------------------------------------
-void svg_plot::plot_range(std::vector<double>::const_iterator begin,
- std::vector<double>::const_iterator end,
- const std::string& _str,
- svg_color_constant _col)
-{
- series.push_back(svg_plot_series(begin, end, _str, constant_to_rgb(_col)));
-}
-
-// -----------------------------------------------------------------
-// Miscellaneous setter methods: those with no clear, definable home
-// in another category
-//
-// set_image_size(): sets image size in pixels. (x,y) corresponds
-// to point at lower right of graph
-//
-// set_title(): adds the text _title to the top of the screen
-//
-// set_title_font_size(): uses an internal variable to save state, to
-// avoid crashes when the title hasn't been
-// set yet
-//
-// set_legend_title_font_size(): As above
-// -----------------------------------------------------------------
-svg_plot& svg_plot::set_image_size(unsigned int x, unsigned int y)
-{
- image.image_size(x, y);
-
- return *this;
-}
-
-svg_plot& svg_plot::set_title(const std::string& _title)
-{
- text_element title(image.get_x_size()/2., 30, _title);
-
- title.set_alignment(center_align);
-
- image.get_g_element(PLOT_TITLE).push_back(new text_element(title));
-
- return *this;
-}
-
-svg_plot& svg_plot::set_title_font_size(unsigned int _size)
-{
- text_element* t_ptr = static_cast<text_element*>(
- &(image.get_g_element(PLOT_TITLE)[0]));
-
- t_ptr->set_font_size(_size);
-
- return *this;
-}
-
-svg_plot& svg_plot::set_legend_title_font_size(unsigned int _size)
-{
- legend_title_font_size = _size;
-
- return *this;
-}
-
-// -----------------------------------------------------------------
-// Commands: Answers to yes or no questions (Example: Show the legend?)
-//
-// set_axis(): Whether or not the axis will show
-//
-// set_legend(): Whether or not the legend will show
-//
-// set_plot_window(): Whether or not the plot will be full screen or
-// in its own contained window
-//
-// set_x_label(): Whether or not the label for the X axis will show
-//
-// set_x_major_labels(): Whether or not the major ticks will have labels
-// on the x-axis
-//
-//
-// -----------------------------------------------------------------
-
-svg_plot& svg_plot::set_axis(bool _cmd)
-{
- axis_on = _cmd;
- return (svg_plot&)*this;
-}
-
-svg_plot& svg_plot::set_legend(bool _cmd)
-{
- legend_on = _cmd;
-
- return (svg_plot&)*this;
-}
-
-svg_plot& svg_plot::set_plot_window(bool _cmd)
-{
- plot_window_on = _cmd;
-
- return (svg_plot&)*this;
-}
-
-svg_plot& svg_plot::set_x_label(bool _cmd)
-{
- x_label_on = _cmd;
-
- return *this;
-}
-
-svg_plot& svg_plot::set_x_major_labels(bool _cmd)
-{
- x_major_labels_on = _cmd;
-
- return *this;
-}
-
-svg_plot& svg_plot::set_title_color(svg_color_constant _col)
-{
- set_title_color(constant_to_rgb(_col));
-
- return *this;
-}
-
-svg_plot& svg_plot::set_title_color(const svg_color& _col)
-{
- image.get_g_element(PLOT_TITLE).set_stroke_color(_col);
- image.get_g_element(PLOT_TITLE).set_fill_color(_col);
-
- return *this;
-}
-
-// -----------------------------------------------------------------
-// Color settings: Customization of colors found in the plot
-//
-// set_title_color(): Sets the color of the plot title
-//
-// set_background_color(): Sets the color of the background. This is
-// not the same as the plot window background
-//
-// set_legend_background_color():
-// Sets the background color of the legend
-//
-// set_plot_background_color():
-// Sets the background color of the plot area.
-// If plot_window_on is not set true, this
-// does not show
-//
-// set_axis_color(): Color of the x axis + origin
-//
-// set_x_major_tick_color(): Sets the color of the major ticks on
-// the x-axis
-//
-// set_x_minor_tick_color(): As above, but for minor ticks
-// -----------------------------------------------------------------
-svg_plot& svg_plot::set_background_color(svg_color_constant _col)
-{
- set_background_color(constant_to_rgb(_col));
-
- return *this;
-}
-
-svg_plot& svg_plot::set_background_color(const svg_color& _col)
-{
- image.get_g_element(PLOT_BACKGROUND).set_fill_color(_col);
-
- image.get_g_element(PLOT_BACKGROUND).clear();
- image.get_g_element(PLOT_BACKGROUND).push_back(
- new rect_element(0, 0, image.get_x_size(),
- image.get_y_size()));
-
- return *this;
-}
-
-svg_plot& svg_plot::set_legend_background_color(svg_color_constant _col)
-{
- set_legend_background_color(constant_to_rgb(_col));
-
- return (svg_plot&)*this;
-}
-
-svg_plot& svg_plot::set_legend_background_color(const svg_color& _col)
-{
- image.get_g_element(PLOT_LEGEND_BACKGROUND)
- .set_fill_color(_col);
-
- return *this;
-}
-
-svg_plot& svg_plot::set_plot_background_color(svg_color_constant _col)
-{
- image.get_g_element(PLOT_PLOT_BACKGROUND).set_fill_color(_col);
-
- return *this;
-}
-
-svg_plot& svg_plot::set_plot_background_color(const svg_color& _col)
-{
- image.get_g_element(PLOT_PLOT_BACKGROUND).set_fill_color(_col);
-
- return *this;
-}
-
-svg_plot& svg_plot::set_x_axis_color(svg_color_constant _col)
-{
- set_x_axis_color(constant_to_rgb(_col));
-
- return (svg_plot&)*this;
-}
-
-svg_plot& svg_plot::set_x_axis_color(const svg_color& _col)
-{
- image.get_g_element(PLOT_PLOT_AXIS)
- .set_fill_color(_col);
-
- image.get_g_element(PLOT_PLOT_AXIS)
- .set_stroke_color(_col);
-
- return *this;
-}
-
-svg_plot& svg_plot::set_x_major_tick_color(const svg_color& _col)
-{
- image.get_g_element(PLOT_X_MAJOR_TICKS).set_stroke_color(_col);
- image.get_g_element(PLOT_X_MAJOR_TICKS).set_fill_color(_col);
- return *this;
-}
-
-svg_plot& svg_plot::set_x_major_tick_color(svg_color_constant _col)
-{
- set_x_major_tick_color(constant_to_rgb(_col));
- return *this;
-}
-
-svg_plot& svg_plot::set_x_minor_tick_color(const svg_color& _col)
-{
- image.get_g_element(PLOT_X_MINOR_TICKS).set_stroke_color(_col);
- image.get_g_element(PLOT_X_MINOR_TICKS).set_fill_color(_col);
- return *this;
-}
-
-
-svg_plot& svg_plot::set_x_minor_tick_color(svg_color_constant _col)
-{
- set_x_minor_tick_color(constant_to_rgb(_col));
- return *this;
-}
-
-// -----------------------------------------------------------------
-// Axis information: Settings for customization of axis information
-//
-// set_x_scale(): sets the left and right max values for the x axis
-//
-// set_x_axis_width(): The width of the x axis
-//
-// set_x_major_tick(): The distance between the ticks of the x_axis
-//
-// set_x_major_tick_length(): How long each tick will be
-//
-// set_x_minor_tick_length(): How long each tick will be
-//
-// set_x_num_minor_ticks(): The number of minor ticks between each
-// major tick
-//
-// set_x_label_text(): Labelling for the x-axis
-//
-// set_x_major_tick_width(): Stroke width for major ticks
-//
-// set_x_minor_tick_width(): Stroke width for minor ticks
-// -----------------------------------------------------------------
-
-svg_plot& svg_plot::set_x_scale(double x1, double x2)
-{
- x_min = x1;
- x_max = x2;
-
- if(x2 <= x1)
- {
- throw "Illegal Argument: X scale: x2 < x1";
- }
-
- return (svg_plot&)*this;
-}
-
-svg_plot& svg_plot::set_x_axis_width(unsigned int _width)
-{
- image.get_g_element(PLOT_PLOT_AXIS).set_stroke_width(_width);
-
- return *this;
-}
-
-svg_plot& svg_plot::set_x_major_tick(double _inter)
-{
- x_major_tick = _inter;
-
- return *this;
-}
-
-svg_plot& svg_plot::set_x_major_tick_length(unsigned int _length)
-{
- x_major_tick_length = _length;
- return *this;
-}
-
-svg_plot& svg_plot::set_x_minor_tick_length(unsigned int _length)
-{
- x_minor_tick_length = _length;
- return *this;
-}
-
-svg_plot& svg_plot::set_x_num_minor_ticks(unsigned int _num)
-{
- x_num_minor_ticks = _num;
- return *this;
-}
-
-svg_plot& svg_plot::set_x_label_text(const std::string& _str)
-{
- x_label = _str;
-
- return *this;
-}
-
-svg_plot& svg_plot::set_x_major_tick_width(unsigned int _width)
-{
- image.get_g_element(PLOT_X_MAJOR_TICKS).set_stroke_width(_width);
-
- return *this;
-}
-
-svg_plot& svg_plot::set_x_minor_tick_width(unsigned int _width)
-{
- image.get_g_element(PLOT_X_MINOR_TICKS).set_stroke_width(_width);
-
- return *this;
-}
-
-// -----------------------------------------------------------------
-// We don't use the SVG coordinate transform because then text would
-// be flipped. I'm considering using it to scale the image for resizes
-// -----------------------------------------------------------------
-void svg_plot::_transform_point(double &x)
-{
- x = transform_matrix[0][0] * x + transform_matrix[0][2];
-}
-
-//refactor
-void svg_plot::_draw_axis()
-{
- // one major axis. We just need to draw a vertical line through
- // the origin for now. We will make that an option later.
- double x1, y1, y2;
-
- x_axis = (plot_window_y1 + plot_window_y2) / 2.;
-
- image.line(plot_window_x1, x_axis, plot_window_x2, x_axis,
- image.get_g_element(PLOT_PLOT_AXIS));
-
- x1 = 0;
-
- _transform_point(x1);
-
- image.line(x1, plot_window_y1, x1, plot_window_y2,
- image.get_g_element(PLOT_PLOT_AXIS));
-
- int major_tick_len = x_major_tick_length/2;
-
- for(double i = 0; i < x_max; i += x_major_tick)
- {
- for(double j=i; j<i+x_major_tick; j+=x_major_tick / (x_num_minor_ticks+1))
- {
- y1 = x_axis + x_minor_tick_length/2.;
- y2 = x_axis - x_minor_tick_length/2.;
-
- x1=j;
-
- _transform_point(x1);
-
- //make sure that we are drawing inside of the allowed window
- if(x1 < plot_window_x2)
- {
- image.line(x1, y1, x1, y2,
- image.get_g_element(PLOT_X_MINOR_TICKS));
- }
- }
-
- y1 = x_axis + x_major_tick_length/2;
- y2 = x_axis - x_major_tick_length/2;
-
- x1=i;
-
- _transform_point(x1);
-
- //make sure that we are drawing inside of the allowed window
- if(x1 < plot_window_x2)
- {
- image.line(x1, y1, x1, y2,
- image.get_g_element(PLOT_X_MAJOR_TICKS));
-
-
- if(x_major_labels_on)
- {
- std::stringstream fmt;
- fmt<<i;
-
- image.text(x1, y1 + (2 + x_major_tick_length/2), fmt.str());
- }
- }
- }
-
- for(double i = 0; i > x_min; i -= x_major_tick)
- {
- for(double j=i; j>i-x_major_tick; j-=x_major_tick / (x_num_minor_ticks+1))
- {
- y1 = x_axis + x_minor_tick_length/2.;
- y2 = x_axis - x_minor_tick_length/2.;
-
- x1=j;
-
- _transform_point(x1);
-
- //make sure that we are drawing inside of the allowed window
- if(x1 > plot_window_x1)
- {
- image.line(x1, y1, x1, y2,
- image.get_g_element(PLOT_X_MINOR_TICKS));
- }
- }
- y1 = x_axis+major_tick_len;
- y2 = x_axis-major_tick_len;
-
- x1=i;
-
- _transform_point(x1);
-
- if(x1 > plot_window_x1)
- {
- image.line(x1, y1, x1, y2,
- image.get_g_element(PLOT_X_MAJOR_TICKS));
-
- if(x_major_labels_on)
- {
- std::stringstream fmt;
- fmt<<i;
-
- image.text(x1, y1 + (2 + x_major_tick_length/2), fmt.str());
- }
- }
- }
-}
-
-// -----------------------------------------------------------------
-// When writing to multiple documents, the contents of the plot
-// may change significantly between. Rather than figuring out what
-// has and has not changed, just erase the contents of the legend
-// in the document and start over.
-// -----------------------------------------------------------------
-void svg_plot::_clear_legend()
-{
- g_element* g_ptr = &(image.get_g_element(PLOT_LEGEND_POINTS));
-
- g_ptr->clear();
-
- g_ptr = &(image.get_g_element(PLOT_LEGEND_TEXT));
- g_ptr->clear();
-}
-
-// -----------------------------------------------------------------
-// Factored out to make _draw_legend() cleaner
-//
-// This function has some "magic" values that could be removed
-// or abstracted
-// -----------------------------------------------------------------
-void svg_plot::_draw_legend_header(int _x, int _y, int _width)
-{
- // 2 added to y argument for padding.
- text_element legend_header(_x+(_width/2), _y + legend_title_font_size + 2, "Legend");
-
- legend_header.set_alignment(center_align);
- legend_header.set_font_size(legend_title_font_size);
-
- image.get_g_element(PLOT_LEGEND_TEXT).push_back(new text_element(legend_header));
-}
-
-// -----------------------------------------------------------------
-// Important note: there are a lot of magic numbers that are temporary
-// fill-ins for the time when the legend system is more configurable.
-// This will happen bit-by-bit, as I give the user options to change
-// these values
-//
-// The legend will soon be a percentage of the window, which will
-// remove some of the magic values
-// -----------------------------------------------------------------
-void svg_plot::_draw_legend()
-{
- _clear_legend();
-
- int num_points = (int)(series.size());
-
- int legend_width(150);
- int legend_height(25);
-
- int x_size = image.get_x_size();
-
- // Figure out how wide the legend should be
- if(x_size < 200)
- {
- legend_width = (int)x_size;
- }
-
- int legend_x_start(plot_window_x2 + 5);
- int legend_y_start(plot_window_y1);
-
- // legend_height = title_spacing + (space per element)(num_elements)
- // + (end spacing)
- legend_height = (int)(legend_title_font_size*1.5 + (25 * num_points) + 10);
-
- // TODO: Figure out how tall the legend should be
-
- image.get_g_element(PLOT_LEGEND_BACKGROUND).set_stroke_color(svg_color(102, 102, 84));
- g_element* g_ptr = &(image.get_g_element(PLOT_LEGEND_BACKGROUND));
-
- g_ptr->push_back(new rect_element(legend_x_start,
- legend_y_start,
- legend_width,
- legend_height));
-
- _draw_legend_header(legend_x_start, legend_y_start, legend_width);
-
- g_ptr = &(image.get_g_element(PLOT_LEGEND_POINTS));
-
- g_element* g_inner_ptr = g_ptr;
-
- for(unsigned int i=0; i<series.size(); ++i)
- {
- g_inner_ptr = &(g_ptr->add_g_element());
-
- g_inner_ptr->set_fill_color(series[i].style);
- g_inner_ptr->set_stroke_color(series[i].style);
-
- g_inner_ptr->push_back(new point_element(legend_x_start + 25,
- legend_y_start + legend_title_font_size + 20 + i*25));
-
- g_inner_ptr->push_back(new text_element(legend_x_start + 40,
- legend_y_start + legend_title_font_size + 25 + i*25,
- series[i].title));
- }
-}
-
-void svg_plot::_draw_x_label()
-{
- text_element to_use((plot_window_x2 + plot_window_x1) / 2., image.get_y_size() - 8, x_label);
-
- to_use.set_font_size(12);
- to_use.set_alignment(center_align);
-
- image.get_g_element(PLOT_X_LABEL).set_stroke_color(white);
- image.get_g_element(PLOT_X_LABEL).set_fill_color(white);
-
-
- image.get_g_element(PLOT_X_LABEL).push_back(new text_element(to_use));
-}
-
-const std::string& svg_plot::get_title()
-{
- return title;
-}
-
-unsigned int svg_plot::get_title_font_size()
-{
- return (static_cast<text_element*>(
- &(image.get_g_element(PLOT_TITLE)[0])))->get_font_size();
- return 0;
-}
-
-svg_color svg_plot::get_background_color()
-{
- return image.get_g_element(PLOT_BACKGROUND).get_fill_color();
- return svg_color(0,0,0);
-}
-
-svg_color svg_plot::get_legend_background_color()
-{
- return image.get_g_element(PLOT_LEGEND_BACKGROUND).get_fill_color();
- return svg_color(0,0,0);
-}
-
-svg_color svg_plot::get_axis_color()
-{
- return image.get_g_element(PLOT_PLOT_AXIS).get_stroke_color();
- return svg_color(0,0,0);
-}
-
-unsigned int svg_plot::get_axis_width()
-{
- return image.get_g_element(PLOT_PLOT_AXIS).get_stroke_width();
-}
-
-
-}
-}
-
-#endif
-

Modified: sandbox/SOC/2007/visualization/boost/svg_plot/svg_test.cpp
==============================================================================
--- sandbox/SOC/2007/visualization/boost/svg_plot/svg_test.cpp (original)
+++ sandbox/SOC/2007/visualization/boost/svg_plot/svg_test.cpp 2007-07-02 20:42:10 EDT (Mon, 02 Jul 2007)
@@ -1,16 +1,18 @@
-#include <vector>
-#include <deque>
+#include <map>
 #include <cmath>
 #include <boost/array.hpp>
 
-#include "svg_plot.hpp"
+#include "svg_1d_plot.hpp"
+#include "svg_2d_plot.hpp"
 
+using std::multimap;
+using std::deque;
+using boost::array;
 using namespace boost::svg;
-using namespace std;
 
 double f(double x)
 {
- return (x*x)/2.;
+ return sqrt(x);
 }
 
 double g(double x)
@@ -25,30 +27,25 @@
 
 int main()
 {
- double start = 0, finish = 10;
 
- vector<double> data1;
- deque<double> data2;
- boost::array<double, 10> data3;
-
- double inter = 3.1415926535 / 1.;
-
- int j=0;
- for(double i = start; i <= finish; i += inter, ++j)
+ double start = 0, finish = 10;
+
+ multimap<double, double> data;
+
+ svg_2d_plot my_plot;
+
+ for(double i=0; i<10; ++i)
     {
- data1.push_back(f(i));
- data2.push_back(g(i));
- data3[j] = h(i);
+ data.insert(std::pair<double,double>(i,f(i)));
     }
 
- svg_plot my_plot;
-
     // size/scale settings
     my_plot.set_image_size(500, 350)
- .set_x_scale(-3, 10);
+ .set_x_scale(-1, 10)
+ .set_y_scale(-1, 5);
 
     // Text settings
- my_plot.set_title("Oh My!")
+ my_plot.set_title("2D Graph Test")
            .set_title_font_size(29)
            .set_x_label_text("Time in Months");
 
@@ -57,33 +54,47 @@
            .set_legend(true)
            .set_plot_window(true)
            .set_x_label(true)
- .set_x_major_labels(true);
+ .set_x_major_labels(true)
+ .set_y_major_labels(true);
 
     // color settings
     my_plot.set_background_color(svg_color(67, 111, 69))
            .set_legend_background_color(svg_color(207, 202,167))
            .set_plot_background_color(svg_color(136, 188, 126))
            .set_title_color(white)
+
            .set_x_axis_color(black)
+ .set_y_axis_color(black)
+
            .set_x_major_tick_color(black)
- .set_x_minor_tick_color(black);
+ .set_y_major_tick_color(black)
+
+ .set_legend_border_color(svg_color(102, 102, 84))
+
+ .set_x_minor_tick_color(black)
+ .set_y_minor_tick_color(black);
 
     //axis settings
     my_plot.set_x_major_tick(2)
- .set_x_num_minor_ticks(3)
+ .set_x_num_minor_ticks(2)
            .set_x_major_tick_length(14)
            .set_x_minor_tick_length(7)
- .set_x_major_tick_width(1)
- .set_x_minor_tick_width(1);
+ .set_x_major_tick_width(2)
+ .set_x_minor_tick_width(1)
+
+ .set_y_major_tick(3)
+ .set_y_num_minor_ticks(2)
+ .set_y_major_tick_length(20)
+ .set_y_minor_tick_length(10)
+ .set_y_major_tick_width(2)
+ .set_y_minor_tick_width(1);
 
     //legend settings
     my_plot.set_legend_title_font_size(15);
 
- plot_range(my_plot, data2.begin(), data2.end(), "Lions", blue);
- plot_range(my_plot, data1.begin(), data1.end(), "Tigers", purple);
- plot_range(my_plot, data3.begin(), data3.end(), "Bears", red);
+ plot_range(my_plot, data.begin(), data.end(), "sqrt(x)", blue);
 
- my_plot.write("./test.svg");
+ my_plot.write("D:/test.svg");
 
     return 0;
 }


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk