Boost logo

Boost-Commit :

From: jakevoytko_at_[hidden]
Date: 2007-07-14 14:56:39


Author: jakevoytko
Date: 2007-07-14 14:56:38 EDT (Sat, 14 Jul 2007)
New Revision: 7431
URL: http://svn.boost.org/trac/boost/changeset/7431

Log:
Code improvements, shapes, lines between plot points

Added:
   sandbox/SOC/2007/visualization/boost/svg_plot/detail/axis_plot_frame.hpp
Text files modified:
   sandbox/SOC/2007/visualization/boost/svg_plot/detail/svg_plot_instruction.hpp | 4
   sandbox/SOC/2007/visualization/boost/svg_plot/detail/svg_style.hpp | 144 ++--
   sandbox/SOC/2007/visualization/boost/svg_plot/detail/svg_tag.hpp | 468 ++++++-------
   sandbox/SOC/2007/visualization/boost/svg_plot/svg.hpp | 331 +++------
   sandbox/SOC/2007/visualization/boost/svg_plot/svg_1d_plot.hpp | 1276 ++++-----------------------------------
   sandbox/SOC/2007/visualization/boost/svg_plot/svg_2d_plot.hpp | 1055 ++++++++++++--------------------
   sandbox/SOC/2007/visualization/boost/svg_plot/svg_test.cpp | 52 +
   7 files changed, 996 insertions(+), 2334 deletions(-)

Added: sandbox/SOC/2007/visualization/boost/svg_plot/detail/axis_plot_frame.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/visualization/boost/svg_plot/detail/axis_plot_frame.hpp 2007-07-14 14:56:38 EDT (Sat, 14 Jul 2007)
@@ -0,0 +1,893 @@
+// 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 _BOOST_SVG_AXIS_PLOT_FRAME_HPP
+#define _BOOST_SVG_AXIS_PLOT_FRAME_HPP
+
+#include <string>
+#include "svg_style.hpp"
+#include "detail/svg_tag.hpp"
+
+namespace boost{
+namespace svg{
+
+template <class Derived>
+class axis_plot_frame
+{
+protected:
+ // -----------------------------------------------------------------
+ // 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 _transform_point(double &x, double &y)
+ {
+ x = derived().x_scale* x + derived().x_shift;
+ y = derived().y_scale* y + derived().y_shift;
+ }
+
+ void _transform_x(double &x)
+ {
+ x = derived().x_scale* x + derived().x_shift;
+ }
+
+ void _transform_y(double &y)
+ {
+ y = derived().y_scale* y + derived().y_shift;
+ }
+
+ void _draw_x_minor_ticks(double j)
+ {
+ double x1(0.), y1(0.), y2(derived().image.get_y_size());
+ // draw the grid if needed
+ if(derived().x_minor_grid_on)
+ {
+ _transform_x(x1 = j);
+
+ if(!derived().plot_window_on)
+ {
+ // spacing for labels
+ if(derived().title_on)
+ {
+ y1 += derived().title_font_size * 1.5;
+ }
+
+ if(derived().x_label_on)
+ {
+ y2 -= derived().x_label_font_size * 1.5;
+ }
+ }
+
+ derived().image.get_g_element(PLOT_X_MINOR_GRID).line(x1, y1, x1, y2);
+ }
+
+ y1 = derived().x_axis + derived().x_minor_tick_length/2.;
+ y2 = derived().x_axis - derived().x_minor_tick_length/2.;
+
+ x1=j;
+
+ _transform_x(x1);
+
+ //make sure that we are drawing inside of the allowed window
+ if(x1 < derived().plot_window_x2)
+ {
+ derived().image.get_g_element(PLOT_X_MINOR_TICKS).line(x1, y1, x1, y2);
+ }
+ }
+
+
+ void _draw_x_major_ticks(double i)
+ {
+ double x1(i), y1(0.), y2(derived().image.get_x_size());
+
+ if(derived().x_major_grid_on)
+ {
+ _transform_x(x1 = i);
+
+ if(!derived().plot_window_on)
+ {
+ if(derived().title_on)
+ {
+ y1 += derived().title_font_size * 1.5;
+ }
+
+ if(derived().x_label_on)
+ {
+ y2 -= derived().x_label_font_size * 1.5;
+ }
+ }
+
+ derived().image.get_g_element(PLOT_X_MAJOR_GRID).line(x1, y1, x1, y2);
+ }
+
+ //draw major tick
+ x1=i;
+
+ _transform_x(x1);
+
+ //make sure that we are drawing inside of the allowed window
+ if(x1 < derived().plot_window_x2)
+ {
+ y1 = derived().x_axis + derived().x_major_tick_length/2;
+ y2 = derived().x_axis - derived().x_major_tick_length/2;
+
+ derived().image.get_g_element(PLOT_X_MAJOR_TICKS).line(x1, y1, x1, y2);
+
+
+ if(derived().x_major_labels_on)
+ {
+ std::stringstream fmt;
+ fmt<<i;
+
+ derived().image.get_g_element(PLOT_PLOT_LABELS).text(x1,
+ y1 + (2 + derived().x_major_tick_length/2), fmt.str());
+ }
+ }
+ }
+
+ void _draw_x_axis()
+ {
+ double y1(0.);
+
+ // draw the axis line
+ _transform_y(y1);
+
+ derived().x_axis = y1;
+
+ derived().image.get_g_element(PLOT_X_AXIS).line(derived().plot_window_x1, derived().x_axis,
+ derived().plot_window_x2, derived().x_axis);
+
+ // x_minor_jump is the interval between minor ticks
+ double x_minor_jump = derived().x_major_tick/
+ ((double) (derived().x_num_minor_ticks + 1.) );
+
+ // draw the ticks on the positive side
+ for(double i = 0; i < derived().x_max; i += derived().x_major_tick)
+ {
+ for(double j = i + x_minor_jump;
+ j < i + derived().x_major_tick;
+ j += x_minor_jump)
+ {
+ _draw_x_minor_ticks(j);
+ }
+
+ _draw_x_major_ticks(i);
+ }
+
+ // draw the ticks on the negative side
+ for(double i = 0; i > derived().x_min; i -= derived().x_major_tick)
+ {
+ // draw minor ticks
+ for(double j=i; j>i-derived().x_major_tick; j-=derived().x_major_tick / (derived().x_num_minor_ticks+1))
+ {
+ _draw_x_minor_ticks(j);
+ }
+
+ _draw_x_major_ticks(i);
+ }
+ }
+
+ void _draw_axis()
+ {
+ double x1(0.), y1(0.), y2(derived().image.get_y_size());
+
+ _transform_point(x1, y1);
+
+ y1 = 0.;
+
+ //draw origin. Make sure it is in the window
+ if(x1 > derived().plot_window_x1 && x1 < derived().plot_window_x2)
+ {
+ if(!derived().plot_window_on)
+ {
+ if(derived().title_on)
+ {
+ y1 += derived().title_font_size * 1.5;
+ }
+
+ if(derived().x_label_on)
+ {
+ y2 -= derived().x_label_font_size * 1.5;
+ }
+ }
+
+ derived().image.get_g_element(PLOT_X_AXIS).line(x1, y1, x1, y2);
+ }
+
+ _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 _clear_all()
+ {
+ _clear_legend();
+ _clear_background();
+ _clear_x_axis();
+ _clear_y_axis();
+ _clear_title();
+ _clear_points();
+ _clear_plot_background();
+ _clear_grids();
+ }
+
+ void _clear_background()
+ {
+ derived().image.get_g_element(PLOT_BACKGROUND).clear();
+ }
+
+ void _clear_title()
+ {
+ derived().image.get_g_element(PLOT_TITLE).clear();
+ }
+
+ void _clear_points()
+ {
+ derived().image.get_g_element(PLOT_PLOT_POINTS).clear();
+ }
+
+ void _clear_plot_background()
+ {
+ derived().image.get_g_element(PLOT_PLOT_BACKGROUND).clear();
+ }
+
+ void _clear_legend()
+ {
+ derived().image.get_g_element(PLOT_LEGEND_BACKGROUND).clear();
+ derived().image.get_g_element(PLOT_LEGEND_POINTS).clear();
+ derived().image.get_g_element(PLOT_LEGEND_TEXT).clear();
+ }
+
+ void _clear_x_axis()
+ {
+ derived().image.get_g_element(PLOT_X_AXIS).clear();
+ derived().image.get_g_element(PLOT_X_MINOR_TICKS).clear();
+ derived().image.get_g_element(PLOT_X_MAJOR_TICKS).clear();
+ derived().image.get_g_element(PLOT_X_LABEL).clear();
+ derived().image.get_g_element(PLOT_PLOT_LABELS).clear();
+ }
+
+ void _clear_y_axis()
+ {
+ derived().image.get_g_element(PLOT_Y_AXIS).clear();
+ }
+
+ void _clear_grids()
+ {
+ derived().image.get_g_element(PLOT_X_MAJOR_GRID).clear();
+ derived().image.get_g_element(PLOT_X_MINOR_GRID).clear();
+ }
+
+ void _draw_legend_header(int _x, int _y, int _width)
+ {
+ // 2 added to y argument for padding.
+ text_element legend_header(_x+(_width/2.), _y + derived().legend_title_font_size + 2, "Legend");
+
+ legend_header.set_alignment(center_align);
+ legend_header.set_font_size(derived().legend_title_font_size);
+
+ derived().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
+ // -----------------------------------------------------------------
+ void _draw_legend()
+ {
+ int num_points = (int)(derived().series.size());
+
+ int legend_width(150);
+ int legend_height(25);
+
+ int x_size = derived().image.get_x_size();
+
+ // Figure out how wide the legend should be
+ if(x_size < 200)
+ {
+ legend_width = x_size;
+ }
+
+ unsigned int legend_x_start(derived().plot_window_x2 + 5);
+ unsigned int legend_y_start(derived().plot_window_y1);
+
+ if((unsigned int)(derived().plot_window_x2) >= derived().image.get_x_size())
+ {
+ legend_x_start-=160;
+ legend_y_start+=5;
+ }
+
+ if(derived().title_on)
+ {
+ // -5 removes the padding
+ legend_y_start += (int)(derived().title_font_size * 1.5) - 5;
+ }
+
+ // legend_height = title_spacing + (space per element)(num_elements)
+ // + (end spacing)
+ legend_height = (int)(derived().legend_title_font_size*1.5 + (25 * num_points) + 10);
+
+ g_element* g_ptr = &(derived().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 = &(derived().image.get_g_element(PLOT_LEGEND_POINTS));
+
+ g_element* g_inner_ptr = g_ptr;
+
+ for(unsigned int i=0; i<derived().series.size(); ++i)
+ {
+ g_inner_ptr = &(g_ptr->add_g_element());
+
+ g_inner_ptr->get_style_info().set_fill_color(derived().series[i].point_style.fill_color)
+ .set_stroke_color(derived().series[i].point_style.stroke_color);
+
+ _draw_plot_point(legend_x_start + 25,
+ legend_y_start + derived().legend_title_font_size + 20 + i*25,
+ *g_inner_ptr,
+ derived().series[i].point_style);
+
+ g_inner_ptr = &(derived().image.get_g_element(PLOT_LEGEND_TEXT));
+
+ g_inner_ptr->push_back(new text_element(legend_x_start + 40,
+ legend_y_start + derived().legend_title_font_size + 25 + i*25,
+ derived().series[i].title));
+ }
+ }
+
+ void _draw_title()
+ {
+ if(derived().title_on)
+ {
+ text_element title(derived().image.get_x_size()/2.,
+ derived().title_font_size,
+ derived().title);
+
+ title.set_alignment(center_align);
+ title.set_font_size(derived().title_font_size);
+ derived().image.get_g_element(PLOT_TITLE).push_back(new text_element(title));
+ }
+ }
+
+ void _draw_x_label()
+ {
+ text_element to_use((derived().plot_window_x2 + derived().plot_window_x1) / 2.,
+ derived().image.get_y_size() - 8, derived().x_label);
+
+ to_use.set_font_size(12);
+ to_use.set_alignment(center_align);
+
+ derived().image.get_g_element(PLOT_X_LABEL).push_back(new text_element(to_use));
+ }
+
+ void _draw_plot_point(double _x, double _y,
+ g_element& g_ptr, const plot_point_style& _sty)
+ {
+ if(_x > derived().plot_window_x1
+ && _x < derived().plot_window_x2
+ && _y > derived().plot_window_y1
+ && _y < derived().plot_window_y2)
+ {
+ int size = _sty.size;
+ double half_size = size / 2.;
+
+ switch(_sty.shape)
+ {
+ case circle:
+ g_ptr.circle(_x, _y, half_size);
+ break;
+ case square:
+ g_ptr.rect(_x - half_size, _y - half_size, size, size);
+ break;
+ }
+ }
+ }
+
+private:
+ Derived& derived() { return static_cast<Derived&>(*this); }
+ const Derived& derived()const{return static_cast<const Derived&>(*this); }
+public:
+
+ Derived& set_image_size(unsigned int x, unsigned int y)
+ {
+ derived().image.image_size(x, y);
+ return derived();
+ }
+
+ Derived& set_title(const std::string& _title)
+ {
+ derived().title = _title;
+ return derived();
+ }
+
+ Derived& set_title_font_size(unsigned int _size)
+ {
+ derived().title_font_size = _size;
+ return derived();
+ }
+
+ Derived& set_legend_title_font_size(unsigned int _size)
+ {
+ derived().legend_title_font_size = _size;
+ return derived();
+ }
+
+ // -----------------------------------------------------------------
+ // Commands: Answers to yes or no questions (Example: Show the legend?)
+ //
+ // set_axis()
+ // set_legend()
+ // set_plot_window()
+ // set_x_label()
+ // set_x_major_labels()
+ // -----------------------------------------------------------------
+
+ Derived& set_axis_on(bool _cmd)
+ {
+ derived().axis_on = _cmd;
+ return derived();
+ }
+
+ Derived& set_legend_on(bool _cmd)
+ {
+ derived().legend_on = _cmd;
+ return derived();
+ }
+
+ Derived& set_plot_window_on(bool _cmd)
+ {
+ derived().plot_window_on = _cmd;
+ return derived();
+ }
+
+ Derived& set_x_label_on(bool _cmd)
+ {
+ derived().x_label_on = _cmd;
+ return derived();
+ }
+
+ Derived& set_x_major_labels_on(bool _cmd)
+ {
+ derived().x_major_labels_on = _cmd;
+ return derived();
+ }
+
+ Derived& set_title_on(bool _cmd)
+ {
+ derived().title_on = _cmd;
+ return derived();
+ }
+
+ Derived& set_x_major_grid_on(bool _is)
+ {
+ derived().x_major_grid_on = _is;
+ return derived();
+ }
+
+ Derived& set_x_minor_grid_on(bool _is)
+ {
+ derived().x_minor_grid_on = _is;
+ return derived();
+ }
+
+ // -----------------------------------------------------------------
+ // 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()
+ // -----------------------------------------------------------------
+
+ Derived& set_title_color(svg_color_constant _col)
+ {
+ set_title_color(constant_to_rgb(_col));
+ return derived();
+ }
+
+ Derived& set_title_color(const svg_color& _col)
+ {
+ derived().image.get_g_element(PLOT_TITLE).get_style_info().set_stroke_color(_col);
+ derived().image.get_g_element(PLOT_TITLE).get_style_info().set_fill_color(_col);
+ return derived();
+ }
+
+ Derived& set_background_color(svg_color_constant _col)
+ {
+ set_background_color(constant_to_rgb(_col));
+ return derived();
+ }
+
+ Derived& set_background_color(const svg_color& _col)
+ {
+ derived().image.get_g_element(PLOT_BACKGROUND).get_style_info().set_fill_color(_col);
+ return derived();
+ }
+
+ Derived& set_legend_background_color(svg_color_constant _col)
+ {
+ set_legend_background_color(constant_to_rgb(_col));
+ return derived();
+ }
+
+ Derived& set_legend_background_color(const svg_color& _col)
+ {
+ derived().image.get_g_element(PLOT_LEGEND_BACKGROUND).get_style_info().set_fill_color(_col);
+ return derived();
+ }
+
+ Derived& set_legend_border_color(svg_color_constant _col)
+ {
+ set_legend_border_color(constant_to_rgb(_col));
+ return derived();
+ }
+
+ Derived& set_legend_border_color(const svg_color& _col)
+ {
+ derived().image.get_g_element(PLOT_LEGEND_BACKGROUND).get_style_info().set_stroke_color(_col);
+ return derived();
+ }
+
+ Derived& set_background_border_color(svg_color_constant _col)
+ {
+ derived().image.get_g_element(PLOT_BACKGROUND).get_style_info().set_stroke_color(_col);
+ return derived();
+ }
+
+ Derived& set_background_border_color(const svg_color& _col)
+ {
+ derived().image.get_g_element(PLOT_BACKGROUND).get_style_info().set_stroke_color(_col);
+ return derived();
+ }
+
+ Derived& set_plot_background_color(svg_color_constant _col)
+ {
+ derived().image.get_g_element(PLOT_PLOT_BACKGROUND).get_style_info().set_fill_color(_col);
+ return derived();
+ }
+
+ Derived& set_plot_background_color(const svg_color& _col)
+ {
+ derived().image.get_g_element(PLOT_PLOT_BACKGROUND).get_style_info().set_fill_color(_col);
+ return derived();
+ }
+
+ Derived& set_x_axis_color(svg_color_constant _col)
+ {
+ set_x_axis_color(constant_to_rgb(_col));
+ return derived();
+ }
+
+ Derived& set_x_axis_color(const svg_color& _col)
+ {
+ derived().image.get_g_element(PLOT_X_AXIS).get_style_info()
+ .set_fill_color(_col);
+
+ derived().image.get_g_element(PLOT_X_AXIS).get_style_info()
+ .set_stroke_color(_col);
+
+ return derived();
+ }
+
+ Derived& set_x_major_tick_color(const svg_color& _col)
+ {
+ derived().image.get_g_element(PLOT_X_MAJOR_TICKS).get_style_info().set_stroke_color(_col);
+ derived().image.get_g_element(PLOT_X_MAJOR_TICKS).get_style_info().set_fill_color(_col);
+ return derived();
+ }
+
+ Derived& set_x_major_tick_color(svg_color_constant _col)
+ {
+ set_x_major_tick_color(constant_to_rgb(_col));
+ return derived();
+ }
+
+ Derived& set_x_label_color(const svg_color& _col)
+ {
+ derived().image.get_g_element(PLOT_X_LABEL).get_style_info().set_stroke_color(_col);
+ derived().image.get_g_element(PLOT_X_LABEL).get_style_info().set_fill_color(_col);
+ return derived();
+ }
+
+ Derived& set_x_label_color(svg_color_constant _col)
+ {
+ set_x_label_color(constant_to_rgb(_col));
+ return derived();
+ }
+
+ Derived& set_x_minor_tick_color(const svg_color& _col)
+ {
+ derived().image.get_g_element(PLOT_X_MINOR_TICKS).get_style_info().set_stroke_color(_col);
+ derived().image.get_g_element(PLOT_X_MINOR_TICKS).get_style_info().set_fill_color(_col);
+ return derived();
+ }
+
+ Derived& set_x_minor_tick_color(svg_color_constant _col)
+ {
+ set_x_minor_tick_color(constant_to_rgb(_col));
+ return derived();
+ }
+
+ Derived& set_x_major_grid_color(const svg_color& _col)
+ {
+ derived().image.get_g_element(PLOT_X_MAJOR_GRID).get_style_info().set_stroke_color(_col);
+ derived().image.get_g_element(PLOT_X_MAJOR_GRID).get_style_info().set_fill_color(_col);
+ return derived();
+ }
+
+ Derived& set_x_major_grid_color(svg_color_constant _col)
+ {
+ set_x_major_grid_color(constant_to_rgb(_col));
+ return derived();
+ }
+
+ Derived& set_x_minor_grid_color(const svg_color& _col)
+ {
+ derived().image.get_g_element(PLOT_X_MINOR_GRID).get_style_info().set_stroke_color(_col);
+ derived().image.get_g_element(PLOT_X_MINOR_GRID).get_style_info().set_fill_color(_col);
+ return derived();
+ }
+
+ Derived& set_x_minor_grid_color(svg_color_constant _col)
+ {
+ set_x_minor_grid_color(constant_to_rgb(_col));
+ return derived();
+ }
+
+ // -----------------------------------------------------------------
+ // 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()
+ // -----------------------------------------------------------------
+
+ Derived& set_x_axis_width(unsigned int _width)
+ {
+ derived().image.get_g_element(PLOT_X_AXIS).get_style_info().set_stroke_width(_width);
+ return derived();
+ }
+
+ Derived& set_x_label(const std::string& _str)
+ {
+ derived().x_label = _str;
+ return derived();
+ }
+
+ Derived& set_x_major_tick(double _inter)
+ {
+ derived().x_major_tick = _inter;
+ return derived();
+ }
+
+ Derived& set_x_major_tick_length(unsigned int _length)
+ {
+ derived().x_major_tick_length = _length;
+ return derived();
+ }
+
+ Derived& set_x_major_tick_width(unsigned int _width)
+ {
+ derived().image.get_g_element(PLOT_X_MAJOR_TICKS).get_style_info().set_stroke_width(_width);
+ return derived();
+ }
+
+ Derived& set_x_minor_tick_length(unsigned int _length)
+ {
+ derived().x_minor_tick_length = _length;
+ return derived();
+ }
+
+ Derived& set_x_minor_tick_width(unsigned int _width)
+ {
+ derived().image.get_g_element(PLOT_X_MINOR_TICKS).get_style_info().set_stroke_width(_width);
+ return derived();
+ }
+
+ Derived& set_x_num_minor_ticks(unsigned int _num)
+ {
+ derived().x_num_minor_ticks = _num;
+ return derived();
+ }
+
+ Derived& set_x_scale(double x1, double x2)
+ {
+ if(x2 <= x1)
+ {
+ throw std::runtime_error("Illegal Argument: X scale: x2 < x1");
+ }
+
+ derived().x_min = x1;
+ derived().x_max = x2;
+
+ return derived();
+ }
+
+ unsigned int get_image_x_size()
+ {
+ return derived()image.get_x_size();
+ }
+
+ unsigned int get_image_y_size()
+ {
+ return derived().image.get_x_size();
+ }
+
+ std::string get_title()
+ {
+ return derived().title;
+ }
+
+ unsigned int get_legend_title_font_size()
+ {
+ return derived().legend_title_font_size;
+ }
+
+ // commands
+ bool get_axis()
+ {
+ return derived().axis_on;
+ }
+
+ bool get_legend()
+ {
+ return derived().legend_on;
+ }
+
+ bool get_plot_window()
+ {
+ return derived().plot_window_on;
+ }
+
+ bool get_x_label()
+ {
+ return derived().x_label_on;
+ }
+
+ bool get_x_major_labels()
+ {
+ return derived().x_major_labels_on;
+ }
+
+ // color information
+ svg_color get_title_color()
+ {
+ return derived().image.get_g_element(PLOT_TITLE).get_style_info().get_fill_color();
+ }
+
+ svg_color get_background_color()
+ {
+ return derived().image.get_g_element(PLOT_BACKGROUND).get_style_info().get_fill_color();
+ }
+
+ svg_color get_background_border_color()
+ {
+ return derived().image.get_g_element(PLOT_BACKGROUND).get_style_info().get_stroke_color();
+ }
+
+ svg_color get_legend_background_color()
+ {
+ return derived().image.get_g_element(PLOT_LEGEND_BACKGROUND).get_style_info().get_fill_color();
+ }
+
+ svg_color get_legend_border_color()
+ {
+ return derived().image.get_g_element(PLOT_LEGEND_BACKGROUND).get_style_info().get_stroke_color();
+ }
+
+ svg_color get_plot_background_color()
+ {
+ return derived().image.get_g_element(PLOT_PLOT_BACKGROUND).get_style_info().get_fill_color();
+ }
+
+ svg_color get_x_axis_color()
+ {
+ return derived().image.get_g_element(PLOT_X_AXIS).get_style_info().get_stroke_color();
+ }
+
+ svg_color get_x_label_color()
+ {
+ return derived().image.get_g_element(PLOT_X_LABEL).get_style_info().get_fill_color();
+ }
+
+ svg_color get_x_major_tick_color()
+ {
+ return derived().image.get_g_element(PLOT_X_MAJOR_TICKS).get_style_info().get_stroke_color();
+ }
+
+ svg_color get_x_minor_tick_color()
+ {
+ return derived().image.get_g_element(PLOT_X_MINOR_TICKS).get_style_info().get_stroke_color();
+ }
+
+ svg_color get_x_major_grid_color()
+ {
+ return derived().image.get_g_element(PLOT_X_MAJOR_GRID).get_style_info().get_stroke_color();
+ }
+
+ svg_color get_x_minor_grid_color()
+ {
+ return derived().image.get_g_element(PLOT_X_MINOR_GRID).get_style_info().get_stroke_color();
+ }
+
+ // axis information
+ double get_x_min()
+ {
+ return derived().x_min;
+ }
+
+ double get_x_max()
+ {
+ return derived().x_max;
+ }
+
+ unsigned int get_x_axis_width()
+ {
+ return derived().image.get_g_element(PLOT_X_AXIS).get_style_info().get_stroke_width();
+ }
+
+ double get_x_major_tick()
+ {
+ return derived().x_major_tick;
+ }
+
+ unsigned int get_x_major_tick_length()
+ {
+ return derived().x_major_tick_length;
+ }
+
+ unsigned int get_x_minor_tick_length()
+ {
+ return derived().x_minor_tick_length;
+ }
+
+ unsigned int get_x_num_minor_ticks()
+ {
+ return derived().x_num_minor_ticks;
+ }
+
+ unsigned int get_x_major_tick_width()
+ {
+ return derived().image.get_g_element(PLOT_X_MAJOR_TICKS).get_style_info().get_stroke_width();
+ }
+
+ unsigned int get_x_minor_tick_width()
+ {
+ return derived().image.get_g_element(PLOT_X_MINOR_TICKS).get_style_info().get_stroke_width();
+ }
+
+ std::string get_x_label_text()
+ {
+ return derived().x_label;
+ }
+};
+
+}
+}
+
+#endif

Modified: sandbox/SOC/2007/visualization/boost/svg_plot/detail/svg_plot_instruction.hpp
==============================================================================
--- sandbox/SOC/2007/visualization/boost/svg_plot/detail/svg_plot_instruction.hpp (original)
+++ sandbox/SOC/2007/visualization/boost/svg_plot/detail/svg_plot_instruction.hpp 2007-07-14 14:56:38 EDT (Sat, 14 Jul 2007)
@@ -7,8 +7,8 @@
 
 // -----------------------------------------------------------------
 
-#ifndef _SVG_PLOT_INSTRUCTION_HPP
-#define _SVG_PLOT_INSTRUCTION_HPP
+#ifndef _BOOST_SVG_SVG_PLOT_INSTRUCTION_HPP
+#define _BOOST_SVG_SVG_PLOT_INSTRUCTION_HPP
 
 #include <iterator>
 #include "svg_style.hpp"

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-14 14:56:38 EDT (Sat, 14 Jul 2007)
@@ -6,10 +6,10 @@
 
 // -----------------------------------------------------------------
 
-#ifndef _SVG_STYLE_HPP
-#define _SVG_STYLE_HPP
+#ifndef _BOOST_SVG_SVG_STYLE_HPP
+#define _BOOST_SVG_SVG_STYLE_HPP
 
-#include <map>
+#include <ostream>
 
 namespace boost {
 namespace svg {
@@ -92,10 +92,7 @@
 
     bool operator==(const svg_color& rhs)
     {
- if(r == rhs.r && g == rhs.g && b == rhs.b)
- return true;
-
- return false;
+ return r == rhs.r && g == rhs.g && b == rhs.b;
     }
 };
 
@@ -283,85 +280,96 @@
     unsigned int stroke_width;
     
 public:
- svg_style();
- svg_style(const svg_color&, const svg_color&);
-
- void set_fill_color(const svg_color&);
- void set_stroke_color(const svg_color&);
-
- void set_stroke_width(unsigned int);
- void write(std::ostream&);
-
- svg_color get_fill_color();
- svg_color get_stroke_color();
+ svg_style():fill_color(svg_color(0, 0, 0)),
+ stroke_color(svg_color(0, 0, 0)), stroke_width(0)
+ {
 
- unsigned int get_stroke_width();
-};
+ }
 
-// -----------------------------------------------------------------
-// Black seems to me to be as good a default as any
-// -----------------------------------------------------------------
-svg_style::svg_style():fill_color(svg_color(0, 0, 0)),
- stroke_color(svg_color(0, 0, 0)), stroke_width(0)
-{
+ svg_style(const svg_color& _fill, const svg_color& _stroke,
+ unsigned int _width = 0):
+ fill_color(_fill), stroke_color(_stroke),
+ stroke_width(_width)
+ {
 
-}
+ }
+
+ // setters
+ svg_style& set_fill_color(const svg_color& _col)
+ {
+ fill_color = _col;
+ return *this;
+ }
 
+ svg_style& set_stroke_color(const svg_color& _col)
+ {
+ stroke_color = _col;
+ return *this;
+ }
 
-// -----------------------------------------------------------------
-// For changing the defaults for the colors
-// -----------------------------------------------------------------
-svg_style::svg_style(const svg_color& _fill, const svg_color& _stroke)
-:fill_color(_fill), stroke_color(_stroke), stroke_width(0)
-{
+ svg_style& set_stroke_width(unsigned int _width)
+ {
+ stroke_width = _width;
+ return *this;
+ }
 
-}
+ // getters
+ svg_color get_fill_color() { return svg_color(fill_color); };
+ svg_color get_stroke_color() { return svg_color(stroke_color); };
+ unsigned int get_stroke_width() { return stroke_width; };
 
-void svg_style::set_stroke_color(const svg_color& rhs)
-{
- stroke_color = rhs;
-}
+
+ void svg_style::write(std::ostream& rhs)
+ {
+ rhs << "stroke=\"";
+ stroke_color.write(rhs);
+ rhs << "\" fill=\"";
+ fill_color.write(rhs);
+ rhs<<"\" ";
+
+ if(stroke_width > 0)
+ {
+ rhs << "stroke-width=\""
+ << stroke_width
+ << "\" ";
+ }
+ }
+};
 
-void svg_style::set_fill_color(const svg_color& rhs)
-{
- fill_color = rhs;
-}
+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, SVG_PLOT_DOC_CHILDREN};
 
-void svg_style::set_stroke_width(unsigned int _width)
-{
- stroke_width = _width;
-}
+enum point_shape{none, circle, square, point};
 
-svg_color svg_style::get_fill_color()
+struct plot_point_style
 {
- return svg_color(fill_color);
-}
+ point_shape shape;
+ svg_color stroke_color;
+ svg_color fill_color;
+ int size;
 
-svg_color svg_style::get_stroke_color()
-{
- return svg_color(stroke_color);
-}
+ plot_point_style(const svg_color& _fill,
+ const svg_color& _stroke, int _size = 10, point_shape _shape = circle):
+ fill_color(_fill), stroke_color(_stroke), size(_size), shape(_shape)
+ {
 
-unsigned int svg_style::get_stroke_width()
-{
- return stroke_width;
-}
+ }
+};
 
-void svg_style::write(std::ostream& rhs)
+struct plot_line_style
 {
- rhs << "stroke=\"";
- stroke_color.write(rhs);
- rhs << "\" fill=\"";
- fill_color.write(rhs);
- rhs<<"\" ";
+ svg_color color;
+ bool line_on;
 
- if(stroke_width > 0)
+ plot_line_style(const svg_color& _col, bool _on):
+ color(_col), line_on(_on)
     {
- rhs << "stroke-width=\""
- << stroke_width
- << "\" ";
     }
-}
+};
 
 }//svg
 }//boost

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-14 14:56:38 EDT (Sat, 14 Jul 2007)
@@ -38,54 +38,16 @@
 
 public:
     virtual void write(std::ostream&) = 0;
- virtual ~svg_element();
 
- void set_stroke_color(const svg_color&);
- void set_fill_color(const svg_color&);
- void set_stroke_width(unsigned int);
-
- svg_color get_stroke_color();
- svg_color get_fill_color();
+ ~svg_element()
+ {
 
- unsigned int get_stroke_width();
+ }
 
+ svg_style& get_style_info(){ return style_info; }
+ const svg_style& get_style_info() const{ return style_info; }
 };
 
-svg_element::~svg_element()
-{
-
-}
-
-void svg_element::set_stroke_color(const svg_color& _col)
-{
- style_info.set_stroke_color(_col);
-}
-
-void svg_element::set_fill_color(const svg_color& _col)
-{
- style_info.set_fill_color(_col);
-}
-
-void svg_element::set_stroke_width(unsigned int _width)
-{
- style_info.set_stroke_width(_width);
-}
-
-svg_color svg_element::get_stroke_color()
-{
- return style_info.get_stroke_color();
-}
-
-svg_color svg_element::get_fill_color()
-{
- return style_info.get_stroke_color();
-}
-
-unsigned int svg_element::get_stroke_width()
-{
- return style_info.get_stroke_width();
-}
-
 // -----------------------------------------------------------------
 // Represents a single block of text
 // -----------------------------------------------------------------
@@ -95,143 +57,46 @@
     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();
-
- void write(std::ostream&);
-
- g_element& g_tag(int);
- g_element& add_g_element();
-
- 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];
-}
-
-size_t g_element::size()
-{
- return children.size();
-}
-
-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)
+ rect_element(double _x, double _y, double _w, double _h)
+ :x(_x), y(_y), width(_w), height(_h)
     {
- children[i].write(rhs);
+
     }
 
- rhs << "</g>" << std::endl;
-
-}
-
-g_element& g_element::g_tag(int i)
-{
- return *(static_cast<g_element*>(&children[i]));
-}
-
-//returns a reference to the node created
-g_element& g_element::add_g_element()
-{
- children.push_back(new g_element);
- return *(static_cast<g_element*>(&children[children.size()-1]));
-}
-
-void g_element::push_back(svg_element* _g)
-{
- children.push_back(_g);
-}
-
-void g_element::clear()
-{
- 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;
-}
+ void write(std::ostream& rhs)
+ {
+ rhs<<"<rect x=\""<<x<<"\""
+ <<" y=\""<<y<<"\" "
+ <<" width=\""<<width<<"\" "
+ <<" height=\""<<height<<"\"/>"
+ ;
+ }
+};
 
 // -----------------------------------------------------------------
 // Represents a single point
 // -----------------------------------------------------------------
-class point_element: public svg_element
+class circle_element: public svg_element
 {
 private:
- double x, y;
+ double x, y, radius;
 
 public:
- point_element(double, double);
- void write(std::ostream&);
-};
-
-point_element::point_element(double _x, double _y):x(_x), y(_y)
-{
-
-}
-
-void point_element::write(std::ostream& rhs)
-{
- rhs<<"<circle cx=\""<<x<<"\" cy=\""<<y<<"\" r=\"5\"/>";
+ circle_element(double _x, double _y, double _radius = 5):x(_x), y(_y),
+ radius(_radius)
+ {
+
+ }
 
-}
+ void write(std::ostream& rhs)
+ {
+ rhs<<"<circle cx=\""
+ <<x<<"\" cy=\""
+ <<y<<"\" r=\""
+ <<radius<<"\"/>";
+ }
+};
 
 // -----------------------------------------------------------------
 // Represents a line
@@ -242,22 +107,19 @@
     double x1, x2, y1, y2, y;
 
 public:
- line_element(double, double, double, double);
- void write(std::ostream&);
-};
-
-line_element::line_element(double _x1, double _y1, double _x2,
- double _y2):x1(_x1), y1(_y1),
- x2(_x2), y2(_y2)
-{
-
-}
+ line_element::line_element(double _x1, double _y1, double _x2,
+ double _y2):x1(_x1), y1(_y1),
+ x2(_x2), y2(_y2)
+ {
+
+ }
 
-void line_element::write(std::ostream& rhs)
-{
- rhs<<"<line x1=\""<<x1<<"\" y1=\""<<y1<<"\" x2=\""<<x2<<"\" y2=\""
- <<y2<<"\"/>";
-}
+ void line_element::write(std::ostream& rhs)
+ {
+ rhs<<"<line x1=\""<<x1<<"\" y1=\""<<y1<<"\" x2=\""<<x2<<"\" y2=\""
+ <<y2<<"\"/>";
+ }
+};
 
 // -----------------------------------------------------------------
 // Represents a single block of text
@@ -273,18 +135,11 @@
     text_style alignment;
 
 public:
- text_element(double, double, std::string);
- void write(std::ostream&);
-
- void set_font_size(unsigned int);
-
     void set_alignment(text_style _a)
     {
         alignment = _a;
     }
 
- std::string get_text();
-
     int get_font_size()
     {
         return font_size;
@@ -299,99 +154,212 @@
     {
         y = _y;
     }
-};
 
-text_element::text_element(double _x, double _y, std::string _text)
+ text_element(double _x, double _y, std::string _text)
             :x(_x), y(_y), text(_text), alignment(left_align), font_size(12)
-{
-
-}
+ {
+
+ }
+
+ void write(std::ostream& rhs)
+ {
+ std::string align;
+
+ switch(alignment)
+ {
+ case left_align:
+ align = "start";
+ break;
+
+ case right_align:
+ align = "end";
+ break;
+
+ case center_align:
+ align = "middle";
+ break;
+
+ default:
+ align = "";
+ break;
+ }
+
+ rhs << "<text x=\"" << x << "\""
+ <<" y=\""<<y<<"\" ";
+
+ if(align != "")
+ {
+ rhs << "text-anchor=\""<<align<<"\" ";
+ }
+
+ rhs <<" font-family=\"verdana\"";
+
+ if(font_size == 0)
+ {
+ rhs <<" font-size=\"12\">";
+ }
+
+ else
+ {
+ rhs <<" font-size=\""<<font_size<<"\">";
+ }
 
-void text_element::write(std::ostream& rhs)
+ rhs << text
+ <<" </text>";
+ }
+
+ void set_font_size(unsigned int _size)
+ {
+ font_size = _size;
+ }
+
+ std::string get_text()
+ {
+ return text;
+ }
+};
+
+class clip_path_element: public svg_element
 {
- std::string align;
+private:
+ std::string element_id;
+ rect_element rect;
 
- switch(alignment)
+public:
+
+ clip_path_element(const std::string& _id, const rect_element& _rect):
+ element_id(_id), rect(_rect)
     {
- case left_align:
- align = "start";
- break;
+
+ }
 
- case right_align:
- align = "end";
- break;
+ void write(std::ostream& rhs)
+ {
+ rhs << "<clip-path id=\"" << element_id << "\">" <<std::endl;
 
- case center_align:
- align = "middle";
- break;
+ rect.write(rhs);
 
- default:
- align = "";
- break;
+ rhs<<std::endl<<"</clip-path>";
     }
+};
+
 
- rhs << "<text x=\"" << x << "\""
- <<" y=\""<<y<<"\" ";
+// -----------------------------------------------------------------
+// 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;
     
- if(align != "")
+public:
+
+ g_element():use_clip(false)
+ {
+
+ }
+
+ svg_element& operator[](unsigned int i)
     {
- rhs << "text-anchor=\""<<align<<"\" ";
+ return children[i];
     }
 
- rhs <<" font-family=\"verdana\"";
+ size_t size()
+ {
+ return children.size();
+ }
 
- if(font_size == 0)
+ void write(std::ostream& rhs)
     {
- rhs <<" font-size=\"12\">";
+ rhs << "<g ";
+
+ style_info.write(rhs);
+
+ rhs<< " >" << std::endl;
+
+ for(unsigned int i=0; i<children.size(); ++i)
+ {
+ children[i].write(rhs);
+ }
+
+ rhs << "</g>" << std::endl;
+
     }
 
- else
+ g_element& g_tag(int i)
     {
- rhs <<" font-size=\""<<font_size<<"\">";
+ return *(static_cast<g_element*>(&children[i]));
     }
 
- rhs << text
- <<" </text>";
-}
+ //returns a reference to the node created
+ g_element& add_g_element()
+ {
+ children.push_back(new g_element);
+ return *(static_cast<g_element*>(&children[children.size()-1]));
+ }
 
-void text_element::set_font_size(unsigned int _size)
-{
- font_size = _size;
-}
+ void push_back(svg_element* _g)
+ {
+ children.push_back(_g);
+ }
 
-std::string text_element::get_text()
-{
- return text;
-}
+ void clear()
+ {
+ children.clear();
+ }
 
-class clip_path_element: public svg_element
-{
-private:
- std::string element_id;
- rect_element rect;
+ void set_use_clip(bool _use)
+ {
+ use_clip = _use;
+ }
+
+ void set_clip(const std::string& _name)
+ {
+ use_clip = true;
+ clip_name = _name;
+ }
 
-public:
- clip_path_element(const std::string&, const rect_element&);
- void write(std::ostream&);
-};
+ g_element& circle(double x, double y, double radius = 5.)
+ {
+ children.push_back(new circle_element(x, y, radius));
+ return *this;
+ }
 
-clip_path_element::clip_path_element(const std::string& _id, const rect_element& _rect):
- element_id(_id), rect(_rect)
-{
-
-}
+ g_element& text(double x, double y, std::string text)
+ {
+ children.push_back(new text_element(x, y, text));
+ return *this;
+ }
 
-void clip_path_element::write(std::ostream& rhs)
-{
- rhs << "<clip-path id=\"" << element_id << "\">" <<std::endl;
+ g_element& add_g_element(g_element& _g)
+ {
+ return _g.add_g_element();
+ }
 
- rect.write(rhs);
+ g_element& get_g_element(int i, g_element& _g)
+ {
+ return _g.g_tag(i);
+ }
 
- rhs<<std::endl<<"</clip-path>";
-}
+ g_element& rect(double x1, double y1, double x2, double y2)
+ {
+ children.push_back(new rect_element(x1, y1, x2, y2));
+
+ return *this;
+ }
+
+ g_element& line(double x1, double y1, double x2, double y2)
+ {
+ children.push_back(new line_element(x1, y1, x2, y2));
+
+ return *this;
+ }
+};
 
 }
 }
 
 #endif
-

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-14 14:56:38 EDT (Sat, 14 Jul 2007)
@@ -7,14 +7,12 @@
 
 // -----------------------------------------------------------------
 
-#ifndef _SVG_HPP
-#define _SVG_HPP
+#ifndef _BOOST_SVG_SVG_HPP
+#define _BOOST_SVG_SVG_HPP
 
-#include <vector>
 #include <ostream>
-#include <sstream>
-#include <iostream>
 #include <fstream>
+#include <exception>
 
 #include "detail/svg_tag.hpp"
 #include "detail/svg_style.hpp"
@@ -24,260 +22,163 @@
 
 class svg
 {
-private:
- void _write_header(std::ostream&);
- void _write_document(std::ostream&);
-
 protected:
     unsigned int x_size;
     unsigned int y_size;
     
     g_element document;
 
-public:
- svg();
-
- svg(const svg&);
- svg& operator=(const svg&);
-
- virtual ~svg();
-
- svg& image_size(unsigned int, unsigned int);
-
- svg& write(std::string);
- svg& write(std::ostream&);
-
- svg& point(double, double);
- svg& point(double, double, g_element&);
-
- svg& line(double, double, double, double);
- 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&);
-
- g_element& get_g_element(int i);
- g_element& svg::get_g_element(int, g_element&);
-
- friend std::ostream& operator<<(std::ostream&, const svg&);
-
- unsigned int get_x_size();
- unsigned int get_y_size();
-};
-
-svg::svg():x_size(200), y_size(200)
-{
-
-}
+private:
 
-svg::svg(const svg& rhs):x_size(rhs.x_size), y_size(rhs.y_size)
-{
-
-}
+ // -----------------------------------------------------------------
+ // Internal function to write all of the data to the svg document
+ // -----------------------------------------------------------------
+ void _write_document(std::ostream& s_out)
+ {
+ //Write color information
 
-svg::~svg()
-{
+ //Write all visual elements
+ for(size_t i=0; i<document.size(); ++i)
+ {
+ document[ (unsigned int)i ].write(s_out);
+ }
 
-}
+ //end g tag
+ }
 
-svg& svg::write(std::string _file)
-{
- std::ofstream fout(_file.c_str());
-
- if(fout.fail())
+ // -----------------------------------------------------------------
+ // This prints the svg 1.1 header into the document
+ // -----------------------------------------------------------------
+ void _write_header(std::ostream& s_out)
     {
- throw "Unable to open file "+_file;
+ 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;
     }
 
- _write_header(fout);
-
- //begin svg tag
- fout<<"<svg width=\""<<x_size<<"\" height =\""
- <<y_size<<"\" version=\"1.1\""
- <<" xmlns=\"http://www.w3.org/2000/svg\">"<<std::endl;
-
- _write_document(fout);
-
- //close off svg tag
- fout<<"</svg>";
-
- return *this;
-}
-
-svg& svg::write(std::ostream& s_out)
-{
- _write_header(s_out);
-
- //begin svg tag
- s_out<<"<svg width=\""<<x_size<<"\" height =\""
- <<y_size<<"\" version=\"1.1\""
- <<" xmlns=\"http://www.w3.org/2000/svg\">"<<std::endl;
-
- _write_document(s_out);
-
- //close off svg tag
- s_out<<"</svg>";
+public:
 
- return *this;
-}
+ svg::svg():x_size(200), y_size(200)
+ {
 
-// -----------------------------------------------------------------
-// Internal function to write all of the data to the svg document
-// -----------------------------------------------------------------
-void svg::_write_document(std::ostream& s_out)
-{
- //Write color information
+ }
 
- //Write all visual elements
- for(size_t i=0; i<document.size(); ++i)
+ svg::svg(const svg& rhs):x_size(rhs.x_size), y_size(rhs.y_size)
     {
- document[ (unsigned int)i ].write(s_out);
+
     }
 
- //end g tag
-}
-
-// -----------------------------------------------------------------
-// This prints the svg 1.1 header into the document
-// -----------------------------------------------------------------
-void svg::_write_header(std::ostream& s_out)
-{
- 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;
-}
-
-// -----------------------------------------------------------------
-// Writes the information about the size of the file to the document
-// TODO: allow other unit identifiers
-// -----------------------------------------------------------------
-svg& svg::image_size(unsigned int x, unsigned int y)
-{
- x_size = x;
- y_size = y;
-
- return *this;
-}
+ svg::~svg()
+ {
 
-// -----------------------------------------------------------------
-// Writes the information about points to the document
-// Since a point is not visible, we are actually drawing small
-// circles
-// TODO: allow other unit identifiers, shapes
-// -----------------------------------------------------------------
+ }
 
-// this overload has a pointer to a node in the document tree
-svg& svg::point(double x, double y, g_element& location)
-{
- location.push_back(new point_element(x, y));
+ svg& write(const std::string& _file)
+ {
+ std::ofstream f_out(_file.c_str());
+
+ if(f_out.fail())
+ {
+ throw std::runtime_error("Unable to open file "+_file);
+ }
 
- return *this;
-}
+ write(f_out);
 
-svg& svg::point(double x, double y)
-{
- document.push_back(new point_element(x, y));
+ return *this;
+ }
 
- return *this;
-}
+ svg& write(std::ostream& _s_out)
+ {
 
-// -----------------------------------------------------------------
-// Writes the information about lines to the document
-// -----------------------------------------------------------------
-svg& svg::line(double x1, double y1, double x2, double y2)
-{
- document.push_back(new line_element(x1, y1, x2, y2));
+ _write_header(_s_out);
 
- return *this;
-}
+ //begin svg tag
+ _s_out<<"<svg width=\""<<x_size<<"\" height =\""
+ <<y_size<<"\" version=\"1.1\""
+ <<" xmlns=\"http://www.w3.org/2000/svg\">"<<std::endl;
 
-svg& svg::line(double x1, double y1, double x2, double y2,
- g_element& location)
-{
- location.push_back(new line_element(x1, y1, x2, y2));
+ _write_document(_s_out);
 
- return *this;
-}
+ //close off svg tag
+ _s_out<<"</svg>";
 
-// -----------------------------------------------------------------
-// Writes the information about text to the document
-// -----------------------------------------------------------------
-svg& svg::text(double x, double y, std::string text)
-{
- document.push_back(new text_element(x, y, text));
+ return *this;
+ }
 
- return *this;
-}
+ // -----------------------------------------------------------------
+ // Writes the information about the size of the file to the document
+ // TODO: allow other unit identifiers
+ // -----------------------------------------------------------------
+ svg& image_size(unsigned int x, unsigned int y)
+ {
+ x_size = x;
+ y_size = y;
 
-svg& svg::text(double x, double y, std::string text, g_element& location)
-{
- location.push_back(new text_element(x, y, text));
+ return *this;
+ }
 
- return *this;
-}
+ svg& circle(double x, double y, int radius = 5)
+ {
+ document.push_back(new circle_element(x, y, radius));
+ return *this;
+ }
 
-svg& svg::rect(double x1, double y1, double x2, double y2)
-{
- document.push_back(new rect_element(x1, y1, x2, y2));
+ // -----------------------------------------------------------------
+ // Writes the information about lines to the document
+ // -----------------------------------------------------------------
+ svg& line(double x1, double y1, double x2, double y2)
+ {
+ document.push_back(new line_element(x1, y1, x2, y2));
 
- return *this;
-}
+ return *this;
+ }
 
-svg& svg::rect(double x1, double y1, double x2, double y2,
- g_element& location)
-{
- location.push_back(new rect_element(x1, y1, x2, y2));
+ // -----------------------------------------------------------------
+ // Writes the information about text to the document
+ // -----------------------------------------------------------------
+ svg& text(double x, double y, std::string text)
+ {
+ document.push_back(new text_element(x, y, text));
 
- return *this;
-}
+ 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);
+ svg& rect(double x1, double y1, double x2, double y2)
+ {
+ document.push_back(new rect_element(x1, y1, x2, y2));
 
- return *this;
-}
+ return *this;
+ }
 
-g_element& svg::add_g_element()
-{
- return document.add_g_element();
-}
+ 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);
 
-g_element& svg::add_g_element(g_element& _g)
-{
- return _g.add_g_element();
-}
+ return *this;
+ }
 
-g_element& svg::get_g_element(int i)
-{
- return document.g_tag(i);
-}
+ g_element& add_g_element()
+ {
+ return document.add_g_element();
+ }
 
-g_element& svg::get_g_element(int i, g_element& _g)
-{
- return _g.g_tag(i);
-}
+ g_element& get_g_element(int i)
+ {
+ return document.g_tag(i);
+ }
 
-unsigned int svg::get_x_size()
-{
- return x_size;
-}
+ unsigned int get_x_size()
+ {
+ return x_size;
+ }
 
-unsigned int svg::get_y_size()
-{
- return y_size;
-}
+ unsigned int get_y_size()
+ {
+ return y_size;
+ }
+}; // end class svg
 
 }
 }

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-14 14:56:38 EDT (Sat, 14 Jul 2007)
@@ -7,15 +7,17 @@
 
 // -----------------------------------------------------------------
 
-#ifndef _SVG_1D_PLOT_HPP
-#define _SVG_1D_PLOT_HPP
+#ifndef _BOOST_SVG_SVG_1D_PLOT_HPP
+#define _BOOST_SVG_SVG_1D_PLOT_HPP
 
 #include <vector>
 #include <ostream>
 #include <sstream>
-#include <iterator>
+#include <fstream>
+#include <string>
+#include <exception>
 
-#define BOOST_PARAMETER_MAX_ARITY 7
+#define BOOST_PARAMETER_MAX_ARITY 10
 
 #include <boost/parameter/preprocessor.hpp>
 #include <boost/parameter/name.hpp>
@@ -23,53 +25,24 @@
 #include <boost/bind.hpp>
 
 #include "svg.hpp"
-#include "detail/svg_plot_instruction.hpp"
-
+#include "detail/svg_style.hpp"
+#include "detail/axis_plot_frame.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
+// This functor allows any data convertible to doubles to be plotted
 // -----------------------------------------------------------------
-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(const svg_color& _fill,
- const svg_color& _stroke):
- fill_color(_fill), stroke_color(_stroke)
- {
-
- }
-};
-
 class boost_default_convert
 {
 public:
     typedef double result_type;
 
- double operator()(double a) const
+ template <class T>
+ double operator()(T val) const
     {
- return a;
+ return (double)val;
     }
 };
 
@@ -83,56 +56,44 @@
 {
     std::vector<double> series;
     std::string title;
- plot_point_style style;
+ plot_point_style point_style;
 
- svg_plot_series(std::vector<double> _ctr,
- const std::string& _title,
+ svg_plot_series(std::vector<double> _ctr, const std::string& _title,
                     const plot_point_style& _style):
- series(_ctr),
- title(_title),
- style(_style)
+ series(_ctr), title(_title), point_style(_style)
     {
-
     }
 };
 
-class svg_1d_plot
+class svg_1d_plot: public axis_plot_frame<svg_1d_plot>
 {
 protected:
-
- //todo: replace with x_scale, x_shift, since I don't use the full matrix
- double x_scale, x_shift;
- double y_scale, y_shift;
-
     // stored so as to avoid rewriting style information constantly
     svg image;
 
- // border information for the plot window. Initially will be set to the width
- // and height of the graph
- 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);
+ // border information for the plot window. Initially will be set
+ // to the width and height of the graph
+ int plot_window_x1, plot_window_y1,
+ plot_window_x2, plot_window_y2;
+
+ // axis information
+ unsigned int x_major_tick_length, x_major_tick_width,
+ x_minor_tick_length, x_minor_tick_width,
+ x_label_font_size, x_num_minor_ticks,
+
+ // misc information
+ legend_title_font_size, title_font_size;
     
     // 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
+ // double 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_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;
@@ -144,163 +105,67 @@
     bool axis_on;
     bool plot_window_on;
 
- // 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:
+ friend class axis_plot_frame<svg_1d_plot>;
+
     // where we will be storing the data points for transformation
     std::vector<svg_plot_series> series;
 
-public:
- // constructors
- svg_1d_plot();
-
- 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 svg_1d_plot::plot(const std::vector<double>&,
- const std::string&,
- const plot_point_style&);
-
- //setters
-
- // misc
- 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_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);
+ double x_scale, x_shift;
+ double y_scale, y_shift;
 
+
+ void _calculate_transform()
+ {
+ 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));
 
- // color information
- svg_1d_plot& set_background_border_color(svg_color_constant);
- svg_1d_plot& set_background_border_color(const svg_color&);
+ y_scale = 1.;
+ y_shift = plot_window_y1 - (plot_window_y1-plot_window_y2)/2.;
+ }
 
- svg_1d_plot& set_background_color(svg_color_constant);
- svg_1d_plot& set_background_color(const svg_color&);
+ void _calculate_plot_window()
+ {
+ x_axis = (plot_window_y2 + plot_window_y1)/2.;
 
- svg_1d_plot& set_legend_background_color(svg_color_constant);
- svg_1d_plot& set_legend_background_color(const svg_color&);
+ plot_window_x1 = plot_window_y1 = 0;
+ plot_window_x2 = image.get_x_size();
+ plot_window_y2 = image.get_y_size();
 
- svg_1d_plot& set_legend_border_color(svg_color_constant);
- svg_1d_plot& set_legend_border_color(const svg_color&);
+ if(plot_window_on)
+ {
+ plot_window_x1+=5;
+ plot_window_x2-=5;
+ plot_window_y1+=5;
+ plot_window_y2-=5;
 
- 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&);
+ if(legend_on)
+ {
+ plot_window_x2 -= 155;
+ }
 
- svg_1d_plot& set_x_axis_color(svg_color_constant);
- svg_1d_plot& set_x_axis_color(const svg_color&);
+ if(x_label_on)
+ {
+ plot_window_y2 -= 20;
+ }
 
- svg_1d_plot& set_x_label_color(svg_color_constant);
- svg_1d_plot& set_x_label_color(const svg_color&);
+ //for the title. Will take into account font size soon
+ plot_window_y1 +=40;
 
- 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_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_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();
- unsigned int get_legend_title_font_size();
- unsigned int get_title_font_size();
- std::string get_title();
-
- // 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_background_color();
- svg_color get_background_border_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_label_color();
- svg_color get_x_major_tick_color();
- svg_color get_x_minor_tick_color();
- svg_color get_x_major_grid_color();
- svg_color get_x_minor_grid_color();
-
- // 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();
+ 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));
+ }
+ }
 
- std::string get_x_label_text();
-};
+public:
 
 // 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),
+svg_1d_plot(): x_label("X Axis"), x_min(-10), x_max(10),
+ legend_on(false), title_on(true),
                       axis_on(true), plot_window_on(false), x_label_on(false),
- x_major_grid_on(true), x_minor_grid_on(false),
+ x_major_grid_on(false), 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),
@@ -316,12 +181,20 @@
     }
 
     // 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_BACKGROUND)
+ .get_style_info().set_fill_color(white);
+
+ image.get_g_element(PLOT_PLOT_BACKGROUND)
+ .get_style_info().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);
+ image.get_g_element(PLOT_LEGEND_BACKGROUND)
+ .get_style_info().set_fill_color(white);
+
+ image.get_g_element(PLOT_X_MAJOR_TICKS)
+ .get_style_info().set_stroke_width(2);
+
+ image.get_g_element(PLOT_X_MINOR_TICKS)
+ .get_style_info().set_stroke_width(1);
 }
 
 // -----------------------------------------------------------------
@@ -332,13 +205,13 @@
 // document node, which calls all other nodes through the Visitor
 // pattern
 // -----------------------------------------------------------------
-svg_1d_plot& svg_1d_plot::write(const std::string& _str)
+svg_1d_plot& write(const std::string& _str)
 {
     std::ofstream fout(_str.c_str());
 
     if(fout.fail())
     {
- throw "Failed to open "+_str;
+ throw std::runtime_error("Failed to open "+_str);
     }
 
     svg_1d_plot::write(fout);
@@ -347,66 +220,20 @@
 }
 
 //refactor a little
-svg_1d_plot& svg_1d_plot::write(std::ostream& s_out)
+svg_1d_plot& write(std::ostream& s_out)
 {
- // removes all elements that will show up in a second image drawn
+ // removes all elements that will show up in a subsequent draw
     _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
 
+ // draw background
     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 my_title(image.get_x_size()/2., title_font_size, title);
-
- my_title.set_alignment(center_align);
- my_title.set_font_size(title_font_size);
- image.get_g_element(PLOT_TITLE).push_back(new text_element(my_title));
- }
-
- 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(legend_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;
+ _draw_title();
+ _calculate_plot_window();
+ _calculate_transform();
 
- 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));
- }
-
- // 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_axis();
@@ -422,43 +249,73 @@
         _draw_x_label();
     }
 
- double x1(0), y1(0);
+ double x(0), y(0);
 
+ _transform_y(y);
+
     //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.fill_color);
- g_ptr.set_stroke_color(series[i].style.stroke_color);
+
+ g_ptr.get_style_info().set_fill_color(series[i].point_style.fill_color);
+ g_ptr.get_style_info().set_stroke_color(series[i].point_style.stroke_color);
 
         for(unsigned int j=0; j<series[i].series.size(); ++j)
         {
- x1 = series[i].series[j];
-
- _transform_point(x1, y1);
-
- if(x1 > plot_window_x1 && x1 < plot_window_x2)
- {
- image.point(x1, x_axis, g_ptr);
- }
+ x = series[i].series[j];
+ _transform_x(x);
+ _draw_plot_point(x, y, g_ptr, series[i].point_style);
         }
     }
 
     image.write(s_out);
-
+
     return (svg_1d_plot&)*this;
 }
 
 // -----------------------------------------------------------------
+// Actually draw data to the plot. Default color information
+// -----------------------------------------------------------------
+void 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()
+// set_title()
+// set_title_font_size()
+// set_legend_title_font_size()
+// -----------------------------------------------------------------
+
+}; // end svg_1d_plot
+
+// -----------------------------------------------------------------
 // Parameter names for plot() function
 // -----------------------------------------------------------------
+
+#ifndef BOOST_SVG_BOOST_PARAMETER_NAMES
+#define BOOST_SVG_BOOST_PARAMETER_NAMES
+
 BOOST_PARAMETER_NAME(my_plot)
 BOOST_PARAMETER_NAME(container)
 BOOST_PARAMETER_NAME(title)
 BOOST_PARAMETER_NAME(stroke_color)
 BOOST_PARAMETER_NAME(fill_color)
+BOOST_PARAMETER_NAME(point_style)
+BOOST_PARAMETER_NAME(size)
 BOOST_PARAMETER_NAME(x_functor)
 
+#endif
+
 BOOST_PARAMETER_FUNCTION
 (
     (void),
@@ -471,6 +328,8 @@
     )
     (optional
         (stroke_color, (const svg_color&), svg_color(white))
+ (point_style, (point_shape), circle)
+ (size, (int), 10)
     )
     (deduced
         (optional
@@ -486,860 +345,8 @@
         boost::make_transform_iterator(container.begin(), x_functor),
         boost::make_transform_iterator(container.end(), x_functor));
 
- my_plot.plot(vect, title, plot_point_style(fill_color, stroke_color));
-}
-
-// -----------------------------------------------------------------
-// Actually draw data to the plot. Default color information
-// -----------------------------------------------------------------
-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()
-// 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)
-{
- image.image_size(x, y);
-
- return *this;
-}
-
-svg_1d_plot& svg_1d_plot::set_title(const std::string& _title)
-{
- title = _title;
-
- return *this;
-}
-
-svg_1d_plot& svg_1d_plot::set_title_font_size(unsigned int _size)
-{
- title_font_size = _size;
-
- return *this;
-}
-
-svg_1d_plot& svg_1d_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()
-// set_legend()
-// set_plot_window()
-// set_x_label()
-// set_x_major_labels()
-// -----------------------------------------------------------------
-
-svg_1d_plot& svg_1d_plot::set_axis_on(bool _cmd)
-{
- axis_on = _cmd;
- return *this;
-}
-
-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_on(bool _cmd)
-{
- plot_window_on = _cmd;
- return *this;
-}
-
-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_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;
-}
-
-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);
-
- return *this;
-}
-
-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);
- 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;
-}
-
-svg_1d_plot& svg_1d_plot::set_x_axis_color(const svg_color& _col)
-{
- image.get_g_element(PLOT_X_AXIS)
- .set_fill_color(_col);
-
- image.get_g_element(PLOT_X_AXIS)
- .set_stroke_color(_col);
-
- return *this;
-}
-
-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_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_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);
- image.get_g_element(PLOT_X_MINOR_TICKS).set_fill_color(_col);
- return *this;
-}
-
-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;
-}
-
-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_major_grid_color(svg_color_constant _col)
-{
- set_x_major_grid_color(constant_to_rgb(_col));
- return *this;
-}
-
-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;
-}
-
-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);
-
- 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;
-}
-
-svg_1d_plot& svg_1d_plot::set_x_major_tick_length(unsigned int _length)
-{
- x_major_tick_length = _length;
- return *this;
-}
-
-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_1d_plot& svg_1d_plot::set_x_minor_tick_length(unsigned int _length)
-{
- x_minor_tick_length = _length;
- return *this;
-}
-
-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);
- return *this;
-}
-
-svg_1d_plot& svg_1d_plot::set_x_num_minor_ticks(unsigned int _num)
-{
- x_num_minor_ticks = _num;
- return *this;
-}
-
-svg_1d_plot& svg_1d_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_1d_plot&)*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_1d_plot::_transform_point(double &x, double &y)
-{
- x = x_scale* x + x_shift;
- y = y_scale* y + y_shift;
-}
-
-void svg_1d_plot::_transform_x(double &x)
-{
- x = x_scale* x + x_shift;
-}
-
-void svg_1d_plot::_transform_y(double &y)
-{
- y = y_scale* y + y_shift;
-}
-
-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)
- {
- _transform_x(x1 = j);
-
- if(!plot_window_on)
- {
- // spacing for labels
- 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_MINOR_GRID));
- }
-
- y1 = x_axis + x_minor_tick_length/2.;
- y2 = x_axis - x_minor_tick_length/2.;
-
- x1=j;
-
- _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)
- {
- 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_MAJOR_GRID));
- }
-
- //draw major tick
- x1=i;
-
- _transform_x(x1);
-
- //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));
-
-
- if(x_major_labels_on)
- {
- std::stringstream fmt;
- fmt<<i;
-
- image.text(x1, y1 + (2 + x_major_tick_length/2), fmt.str(),
- image.get_g_element(PLOT_PLOT_LABELS));
- }
- }
-}
-
-void svg_1d_plot::_draw_x_axis()
-{
- double y1(0.);
-
- // draw the axis line
- _transform_y(y1);
-
- x_axis = y1;
-
- 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.) );
-
- // 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)
- {
- _draw_x_minor_ticks(j);
- }
-
- _draw_x_major_ticks(i);
- }
-
- // 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.), 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)
- {
- 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));
- }
-
- _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_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()
-{
- image.get_g_element(PLOT_LEGEND_BACKGROUND).clear();
- image.get_g_element(PLOT_LEGEND_POINTS).clear();
- image.get_g_element(PLOT_LEGEND_TEXT).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();
-}
-
-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();
-}
-
-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");
-
- 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
-// -----------------------------------------------------------------
-void svg_1d_plot::_draw_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;
- }
-
- 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);
-
- 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.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));
- }
-}
-
-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);
-
- to_use.set_font_size(12);
- to_use.set_alignment(center_align);
-
- image.get_g_element(PLOT_X_LABEL).push_back(new text_element(to_use));
-}
-
-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_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 image.get_g_element(PLOT_TITLE).get_fill_color();
-}
-
-svg_color svg_1d_plot::get_background_color()
-{
- return image.get_g_element(PLOT_BACKGROUND).get_fill_color();
-}
-
-svg_color svg_1d_plot::get_background_border_color()
-{
- return image.get_g_element(PLOT_BACKGROUND).get_stroke_color();
-}
-
-svg_color svg_1d_plot::get_legend_background_color()
-{
- return image.get_g_element(PLOT_LEGEND_BACKGROUND).get_fill_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_label_color()
-{
- return image.get_g_element(PLOT_X_LABEL).get_fill_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();
-}
-
-svg_color svg_1d_plot::get_x_major_grid_color()
-{
- return image.get_g_element(PLOT_X_MAJOR_GRID).get_stroke_color();
-}
-
-svg_color svg_1d_plot::get_x_minor_grid_color()
-{
- return image.get_g_element(PLOT_X_MINOR_GRID).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_X_MINOR_TICKS).get_stroke_width();
-}
-
-std::string svg_1d_plot::get_x_label_text()
-{
- return x_label;
+ my_plot.plot(vect, title,
+ plot_point_style(fill_color, stroke_color, size, point_style));
 }
 
 
@@ -1347,4 +354,3 @@
 }
 
 #endif
-

Modified: sandbox/SOC/2007/visualization/boost/svg_plot/svg_2d_plot.hpp
==============================================================================
--- sandbox/SOC/2007/visualization/boost/svg_plot/svg_2d_plot.hpp (original)
+++ sandbox/SOC/2007/visualization/boost/svg_plot/svg_2d_plot.hpp 2007-07-14 14:56:38 EDT (Sat, 14 Jul 2007)
@@ -7,17 +7,28 @@
 
 // -----------------------------------------------------------------
 
-#ifndef _SVG_2D_PLOT_HPP
-#define _SVG_2D_PLOT_HPP
+#ifndef _BOOST_SVG_SVG_2D_PLOT_HPP
+#define _BOOST_SVG_SVG_2D_PLOT_HPP
+
+#define BOOST_PARAMETER_MAX_ARITY 10
 
 #include <map>
-#include <ostream>
+#include <string>
 #include <sstream>
+#include <utility>
+#include <ostream>
 #include <iterator>
+#include <exception>
 
-#include "svg_1d_plot.hpp"
-#include "detail/svg_plot_instruction.hpp"
+#include <boost/parameter/preprocessor.hpp>
+#include <boost/parameter/name.hpp>
+#include <boost/iterator/transform_iterator.hpp>
+#include <boost/bind.hpp>
 
+#include "detail/svg_style.hpp"
+#include "detail/axis_plot_frame.hpp"
+
+#include "svg.hpp"
 
 namespace boost {
 namespace svg {
@@ -26,23 +37,67 @@
 {
     std::multimap<double, double> series;
     std::string title;
- svg_color style;
+ plot_point_style point_style;
+ plot_line_style line_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):
+ const plot_point_style& _point,
+ const plot_line_style& _line):
                        series(_begin,_end),
                        title(_title),
- style(_style)
+ point_style(_point),
+ line_style(_line)
     {
 
     }
 };
 
-class svg_2d_plot: public svg_1d_plot
+class svg_2d_plot: public axis_plot_frame<svg_2d_plot>
 {
 private:
+ friend axis_plot_frame<svg_2d_plot>;
+
+ double x_scale, x_shift;
+ double y_scale, y_shift;
+
+ // stored so as to avoid rewriting style information constantly
+ svg image;
+
+ // border information for the plot window. Initially will be set to the width
+ // and height of the graph
+ int plot_window_x1;
+ int plot_window_x2;
+ int plot_window_y1;
+ int plot_window_y2;
+
+ // 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
+ double x_min, x_max;
+ double x_axis;
+
+ double x_major_tick;
+
+ 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;
+
     // where we will be storing the data points for transformation
     std::vector<svg_2d_plot_series> series;
 
@@ -60,170 +115,155 @@
     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();
+ void _draw_y_axis()
+ {
+ double x1(0.), x2(0.), y1(0.), y2(0.);
 
- // output
- svg_2d_plot& write(const std::string&);
- svg_2d_plot& write(std::ostream&);
+ // draw the axis line
+ _transform_x(x1 );
 
-
- // 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);
+ y_axis = x1;
 
- // setters
+ image.get_g_element(PLOT_Y_AXIS).line(y_axis, plot_window_y1, y_axis, plot_window_y2);
 
- // Methods from the public interface of svg_1d_plot are
- // wrapped here so that we may correctly use chaining
+ // 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.;
 
- // 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);
+ y1=j;
 
- // commands
- svg_2d_plot& set_axis(bool);
- svg_2d_plot& set_legend(bool);
- svg_2d_plot& set_plot_window(bool);
+ _transform_y(y1);
 
- svg_2d_plot& set_x_label(bool);
- svg_2d_plot& set_x_major_labels(bool);
+ //make sure that we are drawing inside of the allowed window
+ if(y1 > plot_window_y1)
+ {
+ image.get_g_element(PLOT_Y_MINOR_TICKS).line(x1, y1, x2, y1);
+ }
+ }
 
- svg_2d_plot& set_y_label(bool);
- svg_2d_plot& set_y_major_labels(bool);
+ //draw major tick
+ y1=i;
+ _transform_point(x1, y1);
+ _transform_point(x2, y2);
 
- // color information
- svg_2d_plot& set_title_color(svg_color_constant);
- svg_2d_plot& set_title_color(const svg_color&);
+ //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;
 
- svg_2d_plot& set_background_color(svg_color_constant);
- svg_2d_plot& set_background_color(const svg_color&);
+ image.get_g_element(PLOT_Y_MAJOR_TICKS).line(x1, y1, x2, y1);
+
+ if(y_major_labels_on && i != 0)
+ {
+ std::stringstream fmt;
+ fmt<<i;
 
- svg_2d_plot& set_legend_background_color(svg_color_constant);
- svg_2d_plot& set_legend_background_color(const svg_color&);
+ image.text(x1, y1 + (2 + x_major_tick_length/2), fmt.str());
+ }
+ }
+ }
 
- svg_2d_plot& set_legend_border_color(svg_color_constant);
- svg_2d_plot& set_legend_border_color(const svg_color&);
+ // 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.;
 
- 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&);
+ y1=j;
 
- svg_2d_plot& set_y_axis_color(svg_color_constant);
- svg_2d_plot& set_y_axis_color(const svg_color&);
+ _transform_y(y1);
 
- svg_2d_plot& set_x_major_tick_color(svg_color_constant);
- svg_2d_plot& set_x_major_tick_color(const svg_color&);
+ //make sure that we are drawing inside of the allowed window
+ if(y1 < plot_window_y2)
+ {
+ image.get_g_element(PLOT_Y_MINOR_TICKS).line(x1, y1, x2, y1);
+ }
+ }
 
- svg_2d_plot& set_y_major_tick_color(svg_color_constant);
- svg_2d_plot& set_y_major_tick_color(const svg_color&);
+ //draw major tick
+ y1=i;
+ _transform_point(x1, y1);
+ _transform_point(x2, y2);
 
- svg_2d_plot& set_x_minor_tick_color(svg_color_constant);
- svg_2d_plot& set_x_minor_tick_color(const svg_color&);
+ //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;
 
- svg_2d_plot& set_y_minor_tick_color(svg_color_constant);
- svg_2d_plot& set_y_minor_tick_color(const svg_color&);
+ image.get_g_element(PLOT_Y_MAJOR_TICKS).line(x1, y1, x2, y1);
+
+ if(y_major_labels_on && i != 0)
+ {
+ std::stringstream fmt;
+ fmt<<i;
 
- // axis information
- svg_2d_plot& set_x_scale(double, double);
- svg_2d_plot& set_y_scale(double, double);
+ image.text(x1, y1 + (2 + x_major_tick_length/2), fmt.str());
+ }
+ }
+ }
 
- 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();
+ void _draw_axis()
+ {
+ _draw_y_axis();
+ _draw_x_axis();
+ }
 
- unsigned int get_axis_width();
-};
+ void _draw_y_label()
+ {
+ /* text_element to_use((plot_window_x2 + plot_window_x1) / 2., image.get_y_size() - 8, x_label);
 
-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()
-{
+ 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);
 
 
-svg_2d_plot& svg_2d_plot::write(const std::string& _str)
-{
- std::ofstream fout(_str.c_str());
+ image.get_g_element(PLOT_X_LABEL).push_back(new text_element(to_use));
+ */
+ }
 
- if(fout.fail())
+
+ void _calculate_transform()
     {
- throw "Failure opening "+_str;
+ 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 = -(plot_window_y2-plot_window_y1)/(y_max-y_min);
+ y_shift = plot_window_y1 -
+ (y_max *(plot_window_y1-plot_window_y2)/(y_max-y_min));
     }
 
- write(fout);
-
- return *this;
-}
-
-svg_2d_plot& svg_2d_plot::write(std::ostream& s_out)
-{
+ void _calculate_plot_window()
+ {
         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;
+ 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(legend_on)
- {
- plot_window_x2 -= 155;
- }
 
         if(x_label_on)
         {
- plot_window_y2 -= 20;
+ plot_window_y2 -= (int)(x_label_font_size * 1.5);
         }
 
         if(y_label_on)
@@ -231,19 +271,133 @@
             plot_window_x1 += 20;
         }
 
- //for the title. Will take into account font size soon
- plot_window_y1 +=40;
+ if(title_on)
+ {
+ plot_window_y1 += (int)(title_font_size * 1.5);
+ }
+
+ 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;
+ }
+
+ 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));
+ }
+ }
+
+ void _draw_plot_lines()
+ {
+ double prev_x, prev_y;
+
+ for(unsigned int i = 0; i < series.size(); ++i)
+ {
+ g_element& g_ptr = image.get_g_element(PLOT_PLOT_LINES).add_g_element();
+
+ g_ptr.get_style_info().set_stroke_color(series[i].line_style.color)
+ .set_fill_color(series[i].line_style.color);
+
+ if(series[i].series.size() > 1)
+ {
+ std::multimap<double, double>::const_iterator j = series[i].series.begin();
+ prev_x = (*j).first;
+ prev_y = (*j).second;
+
+ _transform_x(prev_x);
+ _transform_y(prev_y);
+
+ ++j;
+
+ for(; j != series[i].series.end(); ++j)
+ {
+ double temp_x((*j).first);
+ double temp_y((*j).second);
+
+ _transform_x(temp_x);
+ _transform_y(temp_y);
+
+ g_ptr.push_back(
+ new line_element(prev_x, prev_y,
+ temp_x, temp_y));
+
+ prev_x = temp_x;
+ prev_y = temp_y;
+ }
+ }
+ }
+ }
+
+public:
+
+svg_2d_plot(): x_label(""), title("Plot of data"), y_label(""), x_min(-10), x_max(10),
+ y_min(-10), y_max(10),
+ x_major_tick(3), x_num_minor_ticks(2),
+ y_major_tick(3), y_label_on(false),
+ x_minor_tick_length(10), x_major_tick_length(20),
+ x_major_tick_width(2), x_minor_tick_width(1),
+ y_minor_tick_length(10), y_num_minor_ticks(2),
+ y_major_tick_length(20), legend_title_font_size(12),
+ title_font_size(30), x_label_font_size(12),
+ x_major_labels_on(true), x_major_grid_on(false),
+ x_minor_grid_on(false), x_label_on(false),
+ title_on(true), legend_on(false), axis_on(true),
+ plot_window_on(false), y_major_labels_on(false)
+
+{
+ 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).get_style_info().set_fill_color(white);
+ image.get_g_element(PLOT_PLOT_BACKGROUND).get_style_info().set_fill_color(white);
+ image.get_g_element(PLOT_LEGEND_BACKGROUND).get_style_info().set_fill_color(white);
+
+ image.get_g_element(PLOT_X_MAJOR_TICKS).get_style_info().set_stroke_width(2);
+ image.get_g_element(PLOT_X_MINOR_TICKS).get_style_info().set_stroke_width(1);
+}
+
+
+svg_2d_plot& write(const std::string& _str)
+{
+ std::ofstream fout(_str.c_str());
 
- 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));
+ if(fout.fail())
+ {
+ throw std::runtime_error("Unable to open "+_str);
     }
 
- 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));
+ write(fout);
+
+ return *this;
+}
+
+svg_2d_plot& write(std::ostream& s_out)
+{
+ _clear_all();
 
- 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));
+ // draw background
+ image.get_g_element(PLOT_BACKGROUND).push_back(
+ new rect_element(0, 0, image.get_x_size(),
+ image.get_y_size()));
+
+ _draw_title();
+ _calculate_plot_window();
+ _calculate_transform();
 
     if(axis_on)
     {
@@ -261,12 +415,19 @@
         _draw_x_label();
     }
 
- //draw points
+ // draw lines
+
+ _draw_plot_lines();
+
+ // 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);
+
+ g_ptr.get_style_info()
+ .set_fill_color(series[i].point_style.fill_color)
+ .set_stroke_color(series[i].point_style.stroke_color);
 
         for(std::multimap<double,double>::const_iterator j = series[i].series.begin();
             j!=series[i].series.end(); ++j)
@@ -276,11 +437,7 @@
 
             _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);
- }
+ _draw_plot_point(x, y, g_ptr, series[i].point_style);
         }
     }
 
@@ -289,42 +446,16 @@
     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)
+void plot(std::multimap<double, double> cont,
+ const std::string& _str,
+ const plot_point_style& point_style,
+ const plot_line_style& line_style)
 {
- series.push_back(svg_2d_plot_series(begin, end, _str, constant_to_rgb(_col)));
+ series.push_back(svg_2d_plot_series(cont.begin(), cont.end(),
+ _str, point_style, line_style));
 }
 
 // -----------------------------------------------------------------
@@ -342,117 +473,43 @@
 //
 // 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_axis_on(): Whether or not the axis will show
 //
-// set_legend(): Whether or not the legend will show
+// set_legend_on(): Whether or not the legend will show
 //
-// set_plot_window(): Whether or not the plot will be full screen or
+// set_plot_window_on(): Whether or not the plot will be full screen or
 // in its own contained window
 //
-// set_x_label(): Wrapper for 1d function
+// set_x_label_on(): Wrapper for 1d function
 //
-// set_y_label(): Sets the label for the y-axis
+// set_y_label_on(): Sets the label for the y-axis
 //
-// set_x_major_labels(): Wrapper for 1d function
+// set_x_major_labels_on(): Wrapper for 1d function
 //
-// set_y_major_labels(): Determines whether or not y axis major labels
+// set_y_major_labels_on(): 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)
+svg_2d_plot& set_y_label_on(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)
+svg_2d_plot& set_y_major_labels_on(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
 //
@@ -476,142 +533,46 @@
 //
 // 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)
+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)
+svg_2d_plot& set_y_axis_color(const svg_color& _col)
 {
     image.get_g_element(PLOT_Y_AXIS)
- .set_fill_color(_col);
+ .get_style_info().set_fill_color(_col);
 
     image.get_g_element(PLOT_Y_AXIS)
- .set_stroke_color(_col);
+ .get_style_info().set_stroke_color(_col);
 
     return *this;
 }
 
-svg_2d_plot& svg_2d_plot::set_x_major_tick_color(svg_color_constant _col)
+svg_2d_plot& set_y_major_tick_color(const svg_color& _col)
 {
- svg_1d_plot::set_x_major_tick_color(constant_to_rgb(_col));
-
+ image.get_g_element(PLOT_Y_MAJOR_TICKS).get_style_info().set_stroke_color(_col);
+ image.get_g_element(PLOT_Y_MAJOR_TICKS).get_style_info().set_fill_color(_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)
+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_2d_plot& set_y_minor_tick_color(const svg_color& _col)
 {
- svg_1d_plot::set_x_minor_tick_color(_col);
+ image.get_g_element(PLOT_Y_MINOR_TICKS).get_style_info().set_stroke_color(_col);
+ image.get_g_element(PLOT_Y_MINOR_TICKS).get_style_info().set_fill_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)
+svg_2d_plot& set_y_minor_tick_color(svg_color_constant _col)
 {
     set_y_minor_tick_color(constant_to_rgb(_col));
     return *this;
@@ -633,7 +594,7 @@
 // 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_label(): Labelling for the x-axis
 //
 // set_x_major_tick_width(): Stroke width for major ticks
 //
@@ -642,337 +603,141 @@
 // 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)
+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";
+ throw std::runtime_error("Illegal Argument: X scale: x2 < x1");
     }
 
     return *this;
 }
 
-svg_2d_plot& svg_2d_plot::set_y_axis_width(unsigned int _width)
+svg_2d_plot& set_y_axis_width(unsigned int _width)
 {
- image.get_g_element(PLOT_Y_AXIS).set_stroke_width(_width);
+ image.get_g_element(PLOT_Y_AXIS).get_style_info().set_stroke_width(_width);
 
     return *this;
 }
 
-svg_2d_plot& svg_2d_plot::set_y_major_tick(double _inter)
+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)
+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)
+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)
+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)
+svg_2d_plot& set_y_label(const std::string& _str)
 {
     y_label = _str;
 
     return *this;
 }
 
-svg_2d_plot& svg_2d_plot::set_y_major_tick_width(unsigned int _width)
+svg_2d_plot& set_y_major_tick_width(unsigned int _width)
 {
- image.get_g_element(PLOT_Y_MAJOR_TICKS).set_stroke_width(_width);
+ image.get_g_element(PLOT_Y_MAJOR_TICKS).get_style_info().set_stroke_width(_width);
 
     return *this;
 }
 
-svg_2d_plot& svg_2d_plot::set_y_minor_tick_width(unsigned int _width)
+svg_2d_plot& set_y_minor_tick_width(unsigned int _width)
 {
- image.get_g_element(PLOT_Y_MINOR_TICKS).set_stroke_width(_width);
+ image.get_g_element(PLOT_Y_MINOR_TICKS).get_style_info().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()
+class boost_default_2d_convert
 {
- _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);
+public:
+ typedef std::pair<double, double> result_type;
 
- if((unsigned int)(plot_window_x2) >= image.get_x_size())
+ template <class T, class U>
+ std::pair<double, double> operator()(const std::pair<T, U>& a) const
     {
- legend_x_start-=160;
- legend_y_start+=5;
+ return std::pair<double, double>((double)(a.first), (double)(a.second));
     }
+};
 
- // 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));
+#ifndef BOOST_SVG_BOOST_PARAMETER_NAMES
+#define BOOST_SVG_BOOST_PARAMETER_NAMES
 
- 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));
- }
+BOOST_PARAMETER_NAME(my_plot)
+BOOST_PARAMETER_NAME(container)
+BOOST_PARAMETER_NAME(title)
+BOOST_PARAMETER_NAME(stroke_color)
+BOOST_PARAMETER_NAME(fill_color)
+BOOST_PARAMETER_NAME(point_style)
+BOOST_PARAMETER_NAME(x_functor)
+BOOST_PARAMETER_NAME(size)
+#endif
+
+BOOST_PARAMETER_NAME(line_on)
+BOOST_PARAMETER_NAME(line_color)
+
+BOOST_PARAMETER_FUNCTION
+(
+ (void),
+ plot_2d,
+ tag,
+ (required
+ (in_out(my_plot), (svg_2d_plot&))
+ (container, *)
+ (title, (const std::string&))
+ )
+ (optional
+ (stroke_color, (const svg_color&), svg_color(white))
+ (point_style, (point_shape), circle)
+ (size, (int), 10)
+ (line_on, (bool), true)
+ (line_color, (const svg_color&), svg_color(black))
+ )
+ (deduced
+ (optional
+ (fill_color, (const svg_color&), svg_color(black))
+ (x_functor, *, boost_default_2d_convert())
+ )
+ )
+)
+{
+ std::multimap<double, double> cont;
+
+ cont.insert(
+ boost::make_transform_iterator(container.begin(), x_functor),
+ boost::make_transform_iterator(container.end(), x_functor));
+
+ my_plot.plot(cont, title,
+ plot_point_style(fill_color, stroke_color, size, point_style),
+ plot_line_style(line_color, line_on));
 }
 
-
 }
 }
 
-#endif
\ No newline at end of file
+#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-14 14:56:38 EDT (Sat, 14 Jul 2007)
@@ -1,14 +1,12 @@
 #include <vector>
 #include <cmath>
-#include <boost/array.hpp>
-#include <boost/bind.hpp>
 #include <map>
 
+#include "svg_2d_plot.hpp"
 #include "svg_1d_plot.hpp"
 
 using std::multimap;
-using std::deque;
-using boost::array;
+using std::vector;
 using namespace boost::svg;
 
 double f(double x)
@@ -40,36 +38,52 @@
 
 int main()
 {
- std::vector<double> data1;
- std::vector<int> data2;
+ std::map<double, double> data1;
+ std::map<double, double> data2;
+ std::vector<double> data3;
 
- svg_1d_plot my_plot;
+ svg_2d_plot my_2d_plot;
+ svg_1d_plot my_1d_plot;
 
- for(double i=0; i<10; ++i)
+ for(double i=0; i<10; i+=1)
     {
- data1.push_back(f(i));
- data2.push_back((int)i-5);
+ data1[i - 5.] = f(i);
+ data2[i] = i - 5.;
+ data3.push_back(h(i) - 10.);
     }
 
     // size/scale settings
- my_plot.set_image_size(500, 350);
+ my_2d_plot.set_image_size(500, 350);
 
- my_plot.set_title("Hello, operator")
- .set_plot_window_on(false)
+ my_2d_plot.set_title("Hello, operator")
+ .set_plot_window_on(true)
            .set_legend_on(true);
 
- my_plot.set_title_on(true)
+ my_2d_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);
 
- my_plot.set_x_label_color(orange);
+ my_1d_plot.set_image_size(500, 350);
 
- plot(my_plot, data1, "sqrt(x)", plot_point_style(circle, black, blue, 12));
- plot(my_plot, data2, "Not sqrt(x)", dConvert());
+ my_1d_plot.set_title("Hello, operator")
+ .set_plot_window_on(true)
+ .set_legend_on(true);
+
+ my_1d_plot.set_title_on(true)
+ .set_x_label_on(true)
+ .set_x_label("sqrt(x)")
+ .set_x_major_grid_on(false);
+
+ plot_2d(my_2d_plot, data1, "sqrt(x)");
+
+ plot_2d(my_2d_plot, data2, "Not sqrt(x)",
+ _size = 10);
+
+ plot(my_1d_plot, data3, "1D Plot");
 
- my_plot.write("./test.svg");
+ my_1d_plot.write("D:/test1d.svg");
+ my_2d_plot.write("D:/test2d.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