Boost logo

Boost-Commit :

From: jakevoytko_at_[hidden]
Date: 2007-07-08 00:56:10


Author: jakevoytko
Date: 2007-07-08 00:56:09 EDT (Sun, 08 Jul 2007)
New Revision: 7387
URL: http://svn.boost.org/trac/boost/changeset/7387

Log:
Bug fixes, Boost.Parameter experiment, sans documentation + unit tests. Not yet tested on GCC

Text files modified:
   sandbox/SOC/2007/visualization/boost/svg_plot/detail/svg_tag.hpp | 82 ++
   sandbox/SOC/2007/visualization/boost/svg_plot/svg.hpp | 36 +
   sandbox/SOC/2007/visualization/boost/svg_plot/svg_1d_plot.hpp | 872 ++++++++++++++++++++++++---------------
   sandbox/SOC/2007/visualization/boost/svg_plot/svg_test.cpp | 94 +--
   4 files changed, 671 insertions(+), 413 deletions(-)

Modified: sandbox/SOC/2007/visualization/boost/svg_plot/detail/svg_tag.hpp
==============================================================================
--- sandbox/SOC/2007/visualization/boost/svg_plot/detail/svg_tag.hpp (original)
+++ sandbox/SOC/2007/visualization/boost/svg_plot/detail/svg_tag.hpp 2007-07-08 00:56:09 EDT (Sun, 08 Jul 2007)
@@ -87,16 +87,47 @@
 }
 
 // -----------------------------------------------------------------
-// The node element of our document tree
+// Represents a single block of text
 // -----------------------------------------------------------------
+class rect_element: public svg_element
+{
+private:
+ double x, y, height, width;
+
+public:
+ rect_element(double, double, double, double);
+ void write(std::ostream&);
+};
+
+rect_element::rect_element(double _x, double _y, double _w, double _h)
+ :x(_x), y(_y), width(_w), height(_h)
+{
+
+}
 
+void rect_element::write(std::ostream& rhs)
+{
+ rhs<<"<rect x=\""<<x<<"\""
+ <<" y=\""<<y<<"\" "
+ <<" width=\""<<width<<"\" "
+ <<" height=\""<<height<<"\"/>"
+ ;
+}
+
+
+// -----------------------------------------------------------------
+// The node element of our document tree
+// -----------------------------------------------------------------
 class g_element: public svg_element
 {
 private:
     boost::ptr_vector<svg_element> children;
+ std::string clip_name;
+
+ bool use_clip;
     
 public:
-
+ g_element();
     svg_element& operator[](unsigned int);
     size_t size();
 
@@ -108,8 +139,16 @@
     void push_back(svg_element*);
 
     void clear();
+
+ void set_use_clip(bool);
+ void set_clip(const std::string&);
 };
 
+g_element::g_element():use_clip(false)
+{
+
+}
+
 svg_element& g_element::operator[](unsigned int i)
 {
     return children[i];
@@ -123,7 +162,9 @@
 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)
@@ -157,6 +198,17 @@
     children.clear();
 }
 
+void g_element::set_use_clip(bool _use)
+{
+ use_clip = _use;
+}
+
+void g_element::set_clip(const std::string& _name)
+{
+ use_clip = true;
+ clip_name = _name;
+}
+
 // -----------------------------------------------------------------
 // Represents a single point
 // -----------------------------------------------------------------
@@ -312,35 +364,31 @@
     return text;
 }
 
-// -----------------------------------------------------------------
-// Represents a single block of text
-// -----------------------------------------------------------------
-class rect_element: public svg_element
+class clip_path_element: public svg_element
 {
 private:
- double x, y, height, width;
+ std::string element_id;
+ rect_element rect;
 
 public:
- rect_element(double, double, double, double);
+ clip_path_element(const std::string&, const rect_element&);
     void write(std::ostream&);
 };
 
-rect_element::rect_element(double _x, double _y, double _w, double _h)
- :x(_x), y(_y), width(_w), height(_h)
+clip_path_element::clip_path_element(const std::string& _id, const rect_element& _rect):
+ element_id(_id), rect(_rect)
 {
     
 }
 
-void rect_element::write(std::ostream& rhs)
+void clip_path_element::write(std::ostream& rhs)
 {
- rhs<<"<rect x=\""<<x<<"\""
- <<" y=\""<<y<<"\" "
- <<" width=\""<<width<<"\" "
- <<" height=\""<<height<<"\"/>"
- ;
-}
+ rhs << "<clip-path id=\"" << element_id << "\">" <<std::endl;
 
+ rect.write(rhs);
 
+ rhs<<std::endl<<"</clip-path>";
+}
 
 }
 }

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-07-08 00:56:09 EDT (Sun, 08 Jul 2007)
@@ -36,11 +36,11 @@
 
 public:
     svg();
-
- virtual ~svg();
 
     svg(const svg&);
     svg& operator=(const svg&);
+
+ virtual ~svg();
 
     svg& image_size(unsigned int, unsigned int);
 
@@ -54,10 +54,14 @@
     svg& line(double, double, double, double, g_element&);
     
     svg& text(double, double, std::string);
+ svg& text(double, double, std::string, g_element&);
 
     svg& rect(double, double, double, double);
     svg& rect(double, double, double, double, g_element&);
 
+ svg& clip_path(const rect_element&, g_element&,
+ const std::string&);
+
     g_element& add_g_element();
     g_element& add_g_element(g_element&);
 
@@ -70,13 +74,16 @@
     unsigned int get_y_size();
 };
 
-// -----------------------------------------------------------------
-// -----------------------------------------------------------------
 svg::svg():x_size(200), y_size(200)
 {
 
 }
 
+svg::svg(const svg& rhs):x_size(rhs.x_size), y_size(rhs.y_size)
+{
+
+}
+
 svg::~svg()
 {
 
@@ -144,7 +151,7 @@
 // -----------------------------------------------------------------
 void svg::_write_header(std::ostream& s_out)
 {
- s_out << "<?xml version=\"1.0\" standalone=\"no\"?>"
+ s_out << "<?xml version=\"1.0\" standalone=\"no\"?>"
            << "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" "
            << "\"http://www.w3.org/graphics/svg/1.1/dtd/svg11.dtd\">"<<std::endl;
 }
@@ -185,8 +192,6 @@
 
 // -----------------------------------------------------------------
 // Writes the information about lines to the document
-// TODO: Allow other line width
-// TODO: Allow other line colors
 // -----------------------------------------------------------------
 svg& svg::line(double x1, double y1, double x2, double y2)
 {
@@ -205,7 +210,6 @@
 
 // -----------------------------------------------------------------
 // Writes the information about text to the document
-// TODO: allow different fonts and font sizes
 // -----------------------------------------------------------------
 svg& svg::text(double x, double y, std::string text)
 {
@@ -214,6 +218,13 @@
     return *this;
 }
 
+svg& svg::text(double x, double y, std::string text, g_element& location)
+{
+ location.push_back(new text_element(x, y, text));
+
+ return *this;
+}
+
 svg& svg::rect(double x1, double y1, double x2, double y2)
 {
     document.push_back(new rect_element(x1, y1, x2, y2));
@@ -229,6 +240,15 @@
     return *this;
 }
 
+svg& svg::clip_path(const rect_element& _rect, g_element& _g,
+ const std::string& _id)
+{
+ document.push_back(new clip_path_element(_id,_rect));
+ _g.set_clip(_id);
+
+ return *this;
+}
+
 g_element& svg::add_g_element()
 {
     return document.add_g_element();

Modified: sandbox/SOC/2007/visualization/boost/svg_plot/svg_1d_plot.hpp
==============================================================================
--- sandbox/SOC/2007/visualization/boost/svg_plot/svg_1d_plot.hpp (original)
+++ sandbox/SOC/2007/visualization/boost/svg_plot/svg_1d_plot.hpp 2007-07-08 00:56:09 EDT (Sun, 08 Jul 2007)
@@ -15,6 +15,13 @@
 #include <sstream>
 #include <iterator>
 
+#define BOOST_PARAMETER_MAX_ARITY 5
+
+#include <boost/parameter/preprocessor.hpp>
+#include <boost/parameter/name.hpp>
+#include <boost/iterator/transform_iterator.hpp>
+#include <boost/bind.hpp>
+
 #include "svg.hpp"
 #include "detail/svg_plot_instruction.hpp"
 
@@ -28,13 +35,51 @@
 // 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_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};
+enum plot_doc_structure{PLOT_BACKGROUND, PLOT_PLOT_BACKGROUND,
+ PLOT_X_MINOR_GRID, PLOT_X_MAJOR_GRID, 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_LEGEND_BACKGROUND, PLOT_LEGEND_POINTS, PLOT_LEGEND_TEXT,
+ PLOT_Y_LABEL, PLOT_X_LABEL, PLOT_TITLE};
+
+#define SVG_PLOT_DOC_CHILDREN 19
+
+// there will be more!
+enum point_shape{circle};
+
+struct plot_point_style
+{
+ point_shape shape;
+ svg_color stroke_color;
+ svg_color fill_color;
+ int size;
+
+ plot_point_style(point_shape _shape, const svg_color& _stroke,
+ const svg_color& _fill, int _size):
+ shape(_shape), stroke_color(_stroke), fill_color(_fill), size(_size)
+ {
+
+ }
+
+ plot_point_style(point_shape _shape, svg_color_constant _stroke,
+ svg_color_constant _fill, int _size):
+ shape(_shape), stroke_color(constant_to_rgb(_stroke)),
+ fill_color(constant_to_rgb(_fill)), size(_size)
+ {
+
+ }
+};
+
+class boost_default_convert
+{
+public:
+ typedef double result_type;
 
-#define SVG_PLOT_DOC_CHILDREN 17
+ double operator()(double a) const
+ {
+ return a;
+ }
+};
 
 // -----------------------------------------------------------------
 // This allows us to store plot state locally in svg_plot. We don't
@@ -46,13 +91,12 @@
 {
     std::vector<double> series;
     std::string title;
- svg_color style;
+ plot_point_style 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),
+ svg_plot_series(std::vector<double> _ctr,
+ const std::string& _title,
+ const plot_point_style& _style):
+ series(_ctr),
                     title(_title),
                     style(_style)
     {
@@ -65,23 +109,24 @@
 protected:
 
     //todo: replace with x_scale, x_shift, since I don't use the full matrix
- double transform_matrix[3][3];
+ double x_scale, x_shift;
+ double y_scale, y_shift;
 
     // stored so as to avoid rewriting style information constantly
     svg image;
 
- 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;
+ int plot_window_x1;
+ int plot_window_x2;
+ int plot_window_y1;
+ int plot_window_y2;
 
     void _transform_point(double &x, double &y);
+ void _transform_x(double &x);
+ void _transform_y(double &y);
     
- // strings having to do with labels
+ // used for text displayed on the graph
     std::string x_label, title;
 
     // axis information. y_axis stored as one point because this is a 1D graph
@@ -90,46 +135,61 @@
     
     double x_major_tick;
 
- unsigned int x_major_tick_length, x_minor_tick_length,
- x_num_minor_ticks, legend_title_font_size;
+ unsigned int x_major_tick_length, x_major_tick_width,
+ x_minor_tick_length, x_minor_tick_width;
+ unsigned int x_num_minor_ticks;
+ unsigned int legend_title_font_size, title_font_size,
+ x_label_font_size;
 
     // Yes/no questions
+ bool x_major_labels_on;
+ bool x_major_grid_on;
+ bool x_minor_grid_on;
+ bool x_label_on;
+
+ bool title_on;
     bool legend_on;
     bool axis_on;
     bool plot_window_on;
- bool x_label_on;
- bool x_major_labels_on;
-
- void _draw_x_label();
 
     // internal helper functions
+ void _clear_all();
     void _clear_legend();
+ void _clear_x_axis();
+ void _clear_y_axis();
+ void _clear_background();
+ void _clear_title();
+ void _clear_points();
+ void _clear_plot_background();
+ void _clear_grids();
+
+ void _draw_x_axis();
+ void _draw_x_minor_ticks(double);
+ void _draw_x_major_ticks(double);
+ void _draw_x_label();
     void _draw_legend_header(int, int, int);
     void _draw_legend();
+ void _draw_axis();
+
 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&);
-
 public:
-
     // constructors
     svg_1d_plot();
- svg_1d_plot(const std::string& file);
+
+ svg_1d_plot(const svg_1d_plot&);
+ svg_1d_plot& operator=(const svg_1d_plot&);
 
     // output
     svg_1d_plot& write(const std::string&);
     svg_1d_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);
+ void svg_1d_plot::plot(const std::vector<double>&,
+ const std::string&,
+ const plot_point_style&);
 
     //setters
 
@@ -140,15 +200,20 @@
     svg_1d_plot& set_legend_title_font_size(unsigned int);
 
     // commands
- 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);
+ svg_1d_plot& set_x_label_on(bool);
+ svg_1d_plot& set_x_major_labels_on(bool);
+ svg_1d_plot& set_x_major_grid_on(bool);
+ svg_1d_plot& set_x_minor_grid_on(bool);
+
+ svg_1d_plot& set_axis_on(bool);
+ svg_1d_plot& set_legend_on(bool);
+ svg_1d_plot& set_plot_window_on(bool);
+ svg_1d_plot& set_title_on(bool);
+
 
     // color information
- svg_1d_plot& set_title_color(svg_color_constant);
- svg_1d_plot& set_title_color(const svg_color&);
+ svg_1d_plot& set_background_border_color(svg_color_constant);
+ svg_1d_plot& set_background_border_color(const svg_color&);
 
     svg_1d_plot& set_background_color(svg_color_constant);
     svg_1d_plot& set_background_color(const svg_color&);
@@ -162,34 +227,45 @@
     svg_1d_plot& set_plot_background_color(svg_color_constant);
     svg_1d_plot& set_plot_background_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_x_axis_color(svg_color_constant);
     svg_1d_plot& set_x_axis_color(const svg_color&);
 
+ svg_1d_plot& set_x_label_color(svg_color_constant);
+ svg_1d_plot& set_x_label_color(const svg_color&);
+
+ svg_1d_plot& set_x_major_grid_color(svg_color_constant);
+ svg_1d_plot& set_x_major_grid_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_1d_plot& set_x_minor_grid_color(svg_color_constant);
+ svg_1d_plot& set_x_minor_grid_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_1d_plot& set_x_scale(double, double);
 
     svg_1d_plot& set_x_axis_width(unsigned int);
-
+ svg_1d_plot& set_x_label(const std::string&);
     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_length(unsigned int);
     svg_1d_plot& set_x_minor_tick_width(unsigned int);
+ svg_1d_plot& set_x_num_minor_ticks(unsigned int);
+ svg_1d_plot& set_x_scale(double, double);
 
     // getters
     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();
+ unsigned int get_title_font_size();
+ std::string get_title();
 
     // commands
     bool get_axis();
@@ -199,11 +275,11 @@
     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_legend_border_color();
     svg_color get_plot_background_color();
+ svg_color get_title_color();
     svg_color get_x_axis_color();
     svg_color get_x_major_tick_color();
     svg_color get_x_minor_tick_color();
@@ -224,32 +300,42 @@
     std::string get_x_label_text();
 };
 
-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), plot_window_on(false),x_major_tick(1),
- x_minor_tick_length(10), x_num_minor_ticks(4),
- legend_title_font_size(12)
+// see documentation for default settings rationale
+svg_1d_plot::svg_1d_plot(): x_label("X Axis"), x_min(-10), x_max(10),
+ legend_on(false),
+ axis_on(true), plot_window_on(false), x_label_on(false),
+ x_major_grid_on(true), x_minor_grid_on(false),
+ x_major_tick(3), x_minor_tick_length(10),
+ x_major_tick_length(20), x_num_minor_ticks(2),
+ legend_title_font_size(12), x_label_font_size(12),
+ title_font_size(30), x_scale(1.), x_shift(0),
+ y_scale(1.), y_shift(0)
 {
- 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);
+ set_image_size(500, 350);
 
     //build the document tree.. add children of the root node
     for(int i=0; i<SVG_PLOT_DOC_CHILDREN; ++i)
     {
         image.add_g_element();
     }
-}
 
+ // set color defaults
+ image.get_g_element(PLOT_BACKGROUND).set_fill_color(white);
+ image.get_g_element(PLOT_PLOT_BACKGROUND).set_fill_color(white);
+ image.get_g_element(PLOT_LEGEND_BACKGROUND).set_fill_color(white);
+
+ image.get_g_element(PLOT_X_MAJOR_TICKS).set_stroke_width(2);
+ image.get_g_element(PLOT_X_MINOR_TICKS).set_stroke_width(1);
+}
 
+// -----------------------------------------------------------------
+// write() has two flavors.. a file and a ostream. The file version
+// opens a stream and calls the stream version. The stream version
+// first clears all unnecessary data from the graph, builds the
+// document tree, and then calls the write function for the root
+// document node, which calls all other nodes through the Visitor
+// pattern
+// -----------------------------------------------------------------
 svg_1d_plot& svg_1d_plot::write(const std::string& _str)
 {
     std::ofstream fout(_str.c_str());
@@ -264,16 +350,29 @@
     return *this;
 }
 
+//refactor a little
 svg_1d_plot& svg_1d_plot::write(std::ostream& s_out)
 {
+ // removes all elements that will show up in a second image drawn
+ _clear_all();
     // 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();
-
+ image.get_g_element(PLOT_BACKGROUND).push_back(
+ new rect_element(0, 0, image.get_x_size(),
+ image.get_y_size()));
+
+ if(title_on)
+ {
+ text_element title(image.get_x_size()/2., title_font_size, title);
+
+ title.set_alignment(center_align);
+ title.set_font_size(title_font_size);
+ image.get_g_element(PLOT_TITLE).push_back(new text_element(title));
+ }
+
     x_axis = (plot_window_y2 + plot_window_y1)/2.;
 
     plot_window_x1 = plot_window_y1 = 0;
@@ -305,12 +404,16 @@
                         (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));
+ // calculate the coordinate transforms
+ x_scale = (plot_window_x2-plot_window_x1)/(x_max-x_min);
+ x_shift = plot_window_x1 - (x_min *(plot_window_x2-plot_window_x1)/(x_max-x_min));
+
+ y_scale = 1.;
+ y_shift = plot_window_y1 - (plot_window_y1-plot_window_y2)/2.;
         
     if(axis_on)
     {
- _draw_x_axis();
+ _draw_axis();
     }
 
     if(legend_on)
@@ -323,13 +426,14 @@
         _draw_x_label();
     }
 
- double x1(0);
- double y1(0);
+ double x1(0), y1(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);
+ g_ptr.set_fill_color(series[i].style.fill_color);
+ g_ptr.set_stroke_color(series[i].style.stroke_color);
 
         for(unsigned int j=0; j<series[i].series.size(); ++j)
         {
@@ -349,58 +453,62 @@
     return (svg_1d_plot&)*this;
 }
 
-template <class iter>
-void plot_range(svg_1d_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_1d_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
+// Parameter names for plot() function
 // -----------------------------------------------------------------
-void svg_1d_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)));
+BOOST_PARAMETER_NAME(my_plot)
+BOOST_PARAMETER_NAME(container)
+BOOST_PARAMETER_NAME(title)
+BOOST_PARAMETER_NAME(point_style)
+BOOST_PARAMETER_NAME(x_functor)
+
+BOOST_PARAMETER_FUNCTION
+(
+ (void),
+ plot,
+ tag,
+ (required
+ (in_out(my_plot), (svg_1d_plot&))
+ (container, *)
+ (title, (const std::string&))
+ )
+ (deduced
+ (optional
+ (point_style, (const plot_point_style&), plot_point_style(circle, white, black, 12))
+ (x_functor, *, boost_default_convert())
+ )
+ )
+)
+{
+ std::vector<double> vect(container.size());
+
+ vect.insert(vect.begin(),
+ boost::make_transform_iterator(container.begin(), x_functor),
+ boost::make_transform_iterator(container.end(), x_functor));
+
+ my_plot.plot(vect, title, point_style);
 }
 
 // -----------------------------------------------------------------
-// Actually draw data to the plot. Fill color information provided
+// Actually draw data to the plot. Default color information
 // -----------------------------------------------------------------
-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)
-{
- series.push_back(svg_plot_series(begin, end, _str, constant_to_rgb(_col)));
+void svg_1d_plot::plot(const std::vector<double>& _ctr,
+ const std::string& _title,
+ const plot_point_style& _style)
+{
+ series.push_back(svg_plot_series(_ctr,
+ _title,
+ _style));
 }
 
 // -----------------------------------------------------------------
 // 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
+// set_image_size()
+// set_title()
+// set_title_font_size()
+// set_legend_title_font_size()
 // -----------------------------------------------------------------
 svg_1d_plot& svg_1d_plot::set_image_size(unsigned int x, unsigned int y)
 {
@@ -411,22 +519,14 @@
 
 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));
+ title = _title;
 
     return *this;
 }
 
 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]));
-
- t_ptr->set_font_size(_size);
+ title_font_size = _size;
 
     return *this;
 }
@@ -441,59 +541,76 @@
 // -----------------------------------------------------------------
 // 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
-//
-//
+// set_axis()
+// set_legend()
+// set_plot_window()
+// set_x_label()
+// set_x_major_labels()
 // -----------------------------------------------------------------
 
-svg_1d_plot& svg_1d_plot::set_axis(bool _cmd)
+svg_1d_plot& svg_1d_plot::set_axis_on(bool _cmd)
 {
     axis_on = _cmd;
     return *this;
 }
 
-svg_1d_plot& svg_1d_plot::set_legend(bool _cmd)
+svg_1d_plot& svg_1d_plot::set_legend_on(bool _cmd)
 {
     legend_on = _cmd;
-
     return *this;
 }
 
-svg_1d_plot& svg_1d_plot::set_plot_window(bool _cmd)
+svg_1d_plot& svg_1d_plot::set_plot_window_on(bool _cmd)
 {
     plot_window_on = _cmd;
-
     return *this;
 }
 
-svg_1d_plot& svg_1d_plot::set_x_label(bool _cmd)
+svg_1d_plot& svg_1d_plot::set_x_label_on(bool _cmd)
 {
     x_label_on = _cmd;
-
     return *this;
 }
 
-svg_1d_plot& svg_1d_plot::set_x_major_labels(bool _cmd)
+svg_1d_plot& svg_1d_plot::set_x_major_labels_on(bool _cmd)
 {
     x_major_labels_on = _cmd;
+ return *this;
+}
+
+svg_1d_plot& svg_1d_plot::set_title_on(bool _cmd)
+{
+ title_on = _cmd;
+ return *this;
+}
 
+svg_1d_plot& svg_1d_plot::set_x_major_grid_on(bool _is)
+{
+ x_major_grid_on = _is;
     return *this;
 }
 
+svg_1d_plot& svg_1d_plot::set_x_minor_grid_on(bool _is)
+{
+ x_minor_grid_on = _is;
+ return *this;
+}
+
+// -----------------------------------------------------------------
+// Color settings: Customization of colors found in the plot
+//
+// set_title_color()
+// set_background_color()
+// set_legend_background_color()
+// set_plot_background_color()
+// set_axis_color()
+// set_x_major_tick_color()
+// set_x_minor_tick_color()
+// -----------------------------------------------------------------
+
 svg_1d_plot& svg_1d_plot::set_title_color(svg_color_constant _col)
 {
     set_title_color(constant_to_rgb(_col));
-
     return *this;
 }
 
@@ -505,94 +622,69 @@
     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_1d_plot& svg_1d_plot::set_background_color(svg_color_constant _col)
 {
     set_background_color(constant_to_rgb(_col));
-
     return *this;
 }
 
 svg_1d_plot& svg_1d_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_1d_plot& svg_1d_plot::set_legend_background_color(svg_color_constant _col)
 {
     set_legend_background_color(constant_to_rgb(_col));
-
     return *this;
 }
 
 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);
-
     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_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_background_border_color(svg_color_constant _col)
+{
+ image.get_g_element(PLOT_BACKGROUND).set_stroke_color(_col);
+ return *this;
+}
+
+svg_1d_plot& svg_1d_plot::set_background_border_color(const svg_color& _col)
+{
+ image.get_g_element(PLOT_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_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_1d_plot& svg_1d_plot::set_x_axis_color(svg_color_constant _col)
 {
     set_x_axis_color(constant_to_rgb(_col));
-
     return *this;
 }
 
@@ -620,6 +712,19 @@
     return *this;
 }
 
+svg_1d_plot& svg_1d_plot::set_x_label_color(const svg_color& _col)
+{
+ image.get_g_element(PLOT_X_LABEL).set_stroke_color(_col);
+ image.get_g_element(PLOT_X_LABEL).set_fill_color(_col);
+ return *this;
+}
+
+svg_1d_plot& svg_1d_plot::set_x_label_color(svg_color_constant _col)
+{
+ set_x_label_color(constant_to_rgb(_col));
+ return *this;
+}
+
 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);
@@ -633,42 +738,46 @@
     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_1d_plot& svg_1d_plot::set_x_major_grid_color(const svg_color& _col)
+{
+ image.get_g_element(PLOT_X_MAJOR_GRID).set_stroke_color(_col);
+ image.get_g_element(PLOT_X_MAJOR_GRID).set_fill_color(_col);
+ return *this;
+}
 
-svg_1d_plot& svg_1d_plot::set_x_scale(double x1, double x2)
+svg_1d_plot& svg_1d_plot::set_x_major_grid_color(svg_color_constant _col)
 {
- x_min = x1;
- x_max = x2;
+ set_x_major_grid_color(constant_to_rgb(_col));
+ return *this;
+}
 
- if(x2 <= x1)
- {
- throw "Illegal Argument: X scale: x2 < x1";
- }
+svg_1d_plot& svg_1d_plot::set_x_minor_grid_color(const svg_color& _col)
+{
+ image.get_g_element(PLOT_X_MINOR_GRID).set_stroke_color(_col);
+ image.get_g_element(PLOT_X_MINOR_GRID).set_fill_color(_col);
+ return *this;
+}
 
- return (svg_1d_plot&)*this;
+svg_1d_plot& svg_1d_plot::set_x_minor_grid_color(svg_color_constant _col)
+{
+ set_x_minor_grid_color(constant_to_rgb(_col));
+ return *this;
 }
 
+// -----------------------------------------------------------------
+// Axis information: Settings for customization of axis information
+//
+// set_x_axis_width()
+// set_x_major_tick()
+// set_x_major_tick_length()
+// set_x_major_tick_width()
+// set_x_minor_tick_length()
+// set_x_minor_tick_width()
+// set_x_label_text()
+// set_x_num_minor_ticks()
+// set_x_scale()
+// -----------------------------------------------------------------
+
 svg_1d_plot& svg_1d_plot::set_x_axis_width(unsigned int _width)
 {
     image.get_g_element(PLOT_X_AXIS).set_stroke_width(_width);
@@ -676,10 +785,15 @@
     return *this;
 }
 
+svg_1d_plot& svg_1d_plot::set_x_label(const std::string& _str)
+{
+ x_label = _str;
+ return *this;
+}
+
 svg_1d_plot& svg_1d_plot::set_x_major_tick(double _inter)
 {
     x_major_tick = _inter;
-
     return *this;
 }
 
@@ -689,37 +803,41 @@
     return *this;
 }
 
-svg_1d_plot& svg_1d_plot::set_x_minor_tick_length(unsigned int _length)
+svg_1d_plot& svg_1d_plot::set_x_major_tick_width(unsigned int _width)
 {
- x_minor_tick_length = _length;
+ image.get_g_element(PLOT_X_MAJOR_TICKS).set_stroke_width(_width);
     return *this;
 }
 
-svg_1d_plot& svg_1d_plot::set_x_num_minor_ticks(unsigned int _num)
+svg_1d_plot& svg_1d_plot::set_x_minor_tick_length(unsigned int _length)
 {
- x_num_minor_ticks = _num;
+ x_minor_tick_length = _length;
     return *this;
 }
 
-svg_1d_plot& svg_1d_plot::set_x_label_text(const std::string& _str)
+svg_1d_plot& svg_1d_plot::set_x_minor_tick_width(unsigned int _width)
 {
- x_label = _str;
-
+ image.get_g_element(PLOT_X_MINOR_TICKS).set_stroke_width(_width);
     return *this;
 }
 
-svg_1d_plot& svg_1d_plot::set_x_major_tick_width(unsigned int _width)
+svg_1d_plot& svg_1d_plot::set_x_num_minor_ticks(unsigned int _num)
 {
- image.get_g_element(PLOT_X_MAJOR_TICKS).set_stroke_width(_width);
-
+ x_num_minor_ticks = _num;
     return *this;
 }
 
-svg_1d_plot& svg_1d_plot::set_x_minor_tick_width(unsigned int _width)
+svg_1d_plot& svg_1d_plot::set_x_scale(double x1, double x2)
 {
- image.get_g_element(PLOT_X_MINOR_TICKS).set_stroke_width(_width);
+ x_min = x1;
+ x_max = x2;
 
- return *this;
+ if(x2 <= x1)
+ {
+ throw "Illegal Argument: X scale: x2 < x1";
+ }
+
+ return (svg_1d_plot&)*this;
 }
 
 // -----------------------------------------------------------------
@@ -728,124 +846,180 @@
 // -----------------------------------------------------------------
 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];
+ x = x_scale* x + x_shift;
+ y = y_scale* y + y_shift;
 }
 
-void svg_1d_plot::_draw_x_axis()
+void svg_1d_plot::_transform_x(double &x)
 {
- double y1(0.), y2(0.), x1(0.), toss(0.);
-
- // draw the axis line
- _transform_point(x1, y1);
-
- x_axis = y1;
+ x = x_scale* x + x_shift;
+}
 
- image.line(plot_window_x1, x_axis, plot_window_x2, x_axis,
- image.get_g_element(PLOT_X_AXIS));
+void svg_1d_plot::_transform_y(double &y)
+{
+ y = y_scale* y + y_shift;
+}
 
- // draw the ticks on the positive side
- for(double i = 0; i < x_max; i += x_major_tick)
+void svg_1d_plot::_draw_x_minor_ticks(double j)
+{
+ double x1(0.), y1(0.), y2(image.get_y_size());
+ // draw the grid if needed
+ if(x_minor_grid_on)
     {
- //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.;
- y2 = x_axis - x_minor_tick_length/2.;
-
- x1=j;
+ _transform_x(x1 = j);
 
- _transform_point(x1, toss);
+ if(!plot_window_on)
+ {
+ // spacing for labels
+ if(title_on)
+ {
+ y1 += title_font_size * 1.5;
+ }
 
- //make sure that we are drawing inside of the allowed window
- if(x1 < plot_window_x2)
+ if(x_label_on)
             {
- image.line(x1, y1, x1, y2,
- image.get_g_element(PLOT_X_MINOR_TICKS));
+ y2 -= x_label_font_size * 1.5;
             }
         }
 
- //draw major tick
- x1=i;
+ image.line(x1, y1, x1, y2,
+ image.get_g_element(PLOT_X_MINOR_GRID));
+ }
 
- _transform_point(x1, toss);
+ y1 = x_axis + x_minor_tick_length/2.;
+ y2 = x_axis - x_minor_tick_length/2.;
 
- //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));
+ x1=j;
 
-
- if(x_major_labels_on)
+ _transform_x(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));
+ }
+}
+
+
+void svg_1d_plot::_draw_x_major_ticks(double i)
+{
+ double x1(i), y1(0.), y2(image.get_x_size());
+
+ if(x_major_grid_on)
+ {
+ _transform_x(x1 = i);
+
+ if(!plot_window_on)
+ {
+ if(title_on)
             {
- std::stringstream fmt;
- fmt<<i;
+ y1 += title_font_size * 1.5;
+ }
 
- image.text(x1, y1 + (2 + x_major_tick_length/2), fmt.str());
+ if(x_label_on)
+ {
+ y2 -= x_label_font_size * 1.5;
             }
         }
+
+ image.line(x1, y1, x1, y2,
+ image.get_g_element(PLOT_X_MAJOR_GRID));
     }
 
- // draw the ticks on the negative side
- for(double i = 0; i > x_min; i -= x_major_tick)
+ //draw major tick
+ x1=i;
+
+ _transform_x(x1);
+
+ //make sure that we are drawing inside of the allowed window
+ if(x1 < plot_window_x2)
     {
- // 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_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));
+
+
+ if(x_major_labels_on)
         {
- y1 = x_axis + x_minor_tick_length/2.;
- y2 = x_axis - x_minor_tick_length/2.;
+ std::stringstream fmt;
+ fmt<<i;
 
- x1=j;
+ image.text(x1, y1 + (2 + x_major_tick_length/2), fmt.str(),
+ image.get_g_element(PLOT_PLOT_LABELS));
+ }
+ }
+}
 
- _transform_point(x1, toss);
+void svg_1d_plot::_draw_x_axis()
+{
+ double y1(0.);
 
- //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));
- }
- }
+ // draw the axis line
+ _transform_y(y1);
 
- //draw the major tick
- y1 = x_axis+x_major_tick_length/2.;
- y2 = x_axis-x_major_tick_length/2.;
-
- x1=i;
+ x_axis = y1;
 
- _transform_point(x1, toss);
+ image.line(plot_window_x1, x_axis, plot_window_x2, x_axis,
+ image.get_g_element(PLOT_X_AXIS));
+
+ // x_minor_jump is the interval between minor ticks
+ double x_minor_jump = x_major_tick/
+ ((double) (x_num_minor_ticks + 1.) );
 
- if(x1 > plot_window_x1)
+ // draw the ticks on the positive side
+ for(double i = 0; i < x_max; i += x_major_tick)
+ {
+ for(double j=i+x_minor_jump; j<i+x_major_tick; j+=x_minor_jump)
         {
- image.line(x1, y1, x1, y2,
- image.get_g_element(PLOT_X_MAJOR_TICKS));
+ _draw_x_minor_ticks(j);
+ }
 
- if(x_major_labels_on)
- {
- std::stringstream fmt;
- fmt<<i;
+ _draw_x_major_ticks(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 > 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))
+ {
+ _draw_x_minor_ticks(j);
         }
+
+ _draw_x_major_ticks(i);
     }
 }
 
 //refactor
 void svg_1d_plot::_draw_axis()
 {
- double x1(0.), y1(0.);
+ double x1(0.), y1(0.), y2(image.get_y_size());
 
     _transform_point(x1, y1);
     
+ y1 = 0.;
+
     //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,
+ if(!plot_window_on)
+ {
+ if(title_on)
+ {
+ y1 += title_font_size * 1.5;
+ }
+
+ if(x_label_on)
+ {
+ y2 -= x_label_font_size * 1.5;
+ }
+ }
+
+ image.line(x1, y1, x1, y2,
             image.get_g_element(PLOT_X_AXIS));
     }
 
@@ -858,26 +1032,69 @@
 // has and has not changed, just erase the contents of the legend
 // in the document and start over.
 // -----------------------------------------------------------------
+void svg_1d_plot::_clear_all()
+{
+ _clear_legend();
+ _clear_background();
+ _clear_x_axis();
+ _clear_y_axis();
+ _clear_title();
+ _clear_points();
+ _clear_plot_background();
+ _clear_grids();
+}
+
+void svg_1d_plot::_clear_background()
+{
+ image.get_g_element(PLOT_BACKGROUND).clear();
+}
+
+void svg_1d_plot::_clear_title()
+{
+ image.get_g_element(PLOT_TITLE).clear();
+}
+
+void svg_1d_plot::_clear_points()
+{
+ image.get_g_element(PLOT_PLOT_POINTS).clear();
+}
+
+void svg_1d_plot::_clear_plot_background()
+{
+ image.get_g_element(PLOT_PLOT_BACKGROUND).clear();
+}
+
 void svg_1d_plot::_clear_legend()
 {
- g_element* g_ptr = &(image.get_g_element(PLOT_LEGEND_POINTS));
+ image.get_g_element(PLOT_LEGEND_BACKGROUND).clear();
+ image.get_g_element(PLOT_LEGEND_POINTS).clear();
+ image.get_g_element(PLOT_LEGEND_TEXT).clear();
+}
 
- g_ptr->clear();
+void svg_1d_plot::_clear_x_axis()
+{
+ image.get_g_element(PLOT_X_AXIS).clear();
+ image.get_g_element(PLOT_X_MINOR_TICKS).clear();
+ image.get_g_element(PLOT_X_MAJOR_TICKS).clear();
+ image.get_g_element(PLOT_X_LABEL).clear();
+ image.get_g_element(PLOT_PLOT_LABELS).clear();
+}
 
- g_ptr = &(image.get_g_element(PLOT_LEGEND_TEXT));
- g_ptr->clear();
+void svg_1d_plot::_clear_y_axis()
+{
+ image.get_g_element(PLOT_Y_AXIS).clear();
+}
+
+void svg_1d_plot::_clear_grids()
+{
+ image.get_g_element(PLOT_X_MAJOR_GRID).clear();
+ image.get_g_element(PLOT_X_MINOR_GRID).clear();
 }
 
-// -----------------------------------------------------------------
-// Factored out to make _draw_legend() cleaner
-//
-// This function has some "magic" values that could be removed
-// or abstracted
-// -----------------------------------------------------------------
 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");
+ 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);
@@ -890,14 +1107,9 @@
 // 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_1d_plot::_draw_legend()
 {
- _clear_legend();
-
     int num_points = (int)(series.size());
 
     int legend_width(150);
@@ -919,12 +1131,17 @@
         legend_x_start-=160;
         legend_y_start+=5;
     }
+
+ if(title_on)
+ {
+ // -5 removes the padding
+ legend_y_start += (int)(title_font_size * 1.5) - 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,
@@ -942,12 +1159,14 @@
     {
         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->set_fill_color(series[i].style.fill_color);
+ g_inner_ptr->set_stroke_color(series[i].style.stroke_color);
 
         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 = &(image.get_g_element(PLOT_LEGEND_TEXT));
+
         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));
@@ -956,15 +1175,12 @@
 
 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);
+ 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));
 }
 

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-08 00:56:09 EDT (Sun, 08 Jul 2007)
@@ -1,9 +1,10 @@
-#include <map>
+#include <vector>
 #include <cmath>
 #include <boost/array.hpp>
+#include <boost/bind.hpp>
+#include <map>
 
 #include "svg_1d_plot.hpp"
-#include "svg_2d_plot.hpp"
 
 using std::multimap;
 using std::deque;
@@ -25,77 +26,50 @@
     return 2*x;
 }
 
-int main()
+
+class dConvert
 {
+public:
+ typedef double result_type;
 
- double start = 0, finish = 10;
+ double operator()(int a) const
+ {
+ return (double)a;
+ }
+};
 
- multimap<double, double> data;
+int main()
+{
+ std::vector<double> data1;
+ std::vector<int> data2;
 
- svg_2d_plot my_plot;
+ svg_1d_plot my_plot;
 
     for(double i=0; i<10; ++i)
     {
- data.insert(std::pair<double,double>(i,f(i)));
+ data1.push_back(f(i));
+ data2.push_back((int)i-5);
     }
 
     // size/scale settings
- my_plot.set_image_size(500, 350)
- .set_x_scale(-1, 10)
- .set_y_scale(-1, 5);
-
- // Text settings
- my_plot.set_title("2D Graph Test")
- .set_title_font_size(29)
- .set_x_label_text("Time in Months");
-
- // command settings
- my_plot.set_axis(true)
- .set_legend(true)
- .set_plot_window(true)
- .set_x_label(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_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(2)
- .set_x_major_tick_length(14)
- .set_x_minor_tick_length(7)
- .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);
+ my_plot.set_image_size(500, 350);
+
+ my_plot.set_title("Hello, operator")
+ .set_plot_window_on(false)
+ .set_legend_on(true);
+
+ my_plot.set_title_on(true)
+ .set_x_label_on(true)
+ .set_x_label("sqrt(x)")
+ .set_background_border_color(yellow)
+ .set_x_major_grid_on(false);
 
- //legend settings
- my_plot.set_legend_title_font_size(15);
+ my_plot.set_x_label_color(orange);
 
- plot_range(my_plot, data.begin(), data.end(), "sqrt(x)", blue);
+ plot(my_plot, data1, "sqrt(x)", plot_point_style(circle, black, blue, 12));
+ plot(my_plot, data2, "Not sqrt(x)", dConvert());
 
     my_plot.write("D:/test.svg");
 
     return 0;
-}
-
+}
\ No newline at end of file


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