Boost logo

Boost-Commit :

From: pbristow_at_[hidden]
Date: 2008-01-16 12:46:49


Author: pbristow
Date: 2008-01-16 12:46:49 EST (Wed, 16 Jan 2008)
New Revision: 42819
URL: http://svn.boost.org/trac/boost/changeset/42819

Log:
Improvements to layout, now reasonable - but may not be perfect if internal axis gets close to border so vale labels run into labels.
Text files modified:
   sandbox/SOC/2007/visualization/boost/svg_plot/detail/axis_plot_frame.hpp | 25 ++--
   sandbox/SOC/2007/visualization/boost/svg_plot/svg_2d_plot.hpp | 203 ++++++++++++++++++---------------------
   sandbox/SOC/2007/visualization/boost/svg_plot/svg_boxplot.hpp | 14 +-
   sandbox/SOC/2007/visualization/boost/svg_plot/svg_style.hpp | 38 +++++--
   sandbox/SOC/2007/visualization/libs/svg_plot/example/demo_2d_plot.cpp | 66 ++++++------
   5 files changed, 174 insertions(+), 172 deletions(-)

Modified: sandbox/SOC/2007/visualization/boost/svg_plot/detail/axis_plot_frame.hpp
==============================================================================
--- sandbox/SOC/2007/visualization/boost/svg_plot/detail/axis_plot_frame.hpp (original)
+++ sandbox/SOC/2007/visualization/boost/svg_plot/detail/axis_plot_frame.hpp 2008-01-16 12:46:49 EST (Wed, 16 Jan 2008)
@@ -207,7 +207,7 @@
               {
                 y_up += derived().title_info_.style().font_size() * derived().text_margin_;
               }
- if(derived().x_ticks_.major_value_labels_on)
+ if(derived().x_ticks_.major_value_labels_on_ != 0)
               { // If use_x_major_labels then value may be shown beside the major tick.
                 y_down -= derived().x_label_info_.style().font_size() * derived().text_margin_;
               }
@@ -270,7 +270,7 @@
             tick_path.M(x, y_up).L(x, y_down);
             // Leaving current position at the bottom end of the tick.
 
- if(derived().x_ticks_.major_value_labels_on)
+ if(derived().x_ticks_.major_value_labels_on_ != 0)
             { // Show value by the tick as "1.2" or "3.4e+000"...
               std::stringstream label;
               label.precision(derived().x_ticks_.value_precision_);
@@ -290,13 +290,15 @@
               if (derived().x_ticks_.label_rotation_ == upward)
               { //
                 alignment = right_align;
- //y += label.str().size() * derived().x_label_info_.font_size();
+ x -= derived().x_label_info_.style().font_size() * 0.3; // To centre digit and - on tick.
+ //y += label.str().size() * derived().x_label_info_.font_size() * 0.5; // Part digit space.
                 // so the last digit will be by the tick.
               }
               else if((derived().x_ticks_.label_rotation_ == downward)
                 || (derived().x_ticks_.label_rotation_ == downhill))
               { // start from tick and write down.
- y += derived().x_label_value_.style().font_size() * 0.5;
+ y += derived().x_label_value_.style().font_size() * 0.5; // Part digit space.
+ x -= derived().x_label_info_.style().font_size() * 0.3; // To centre digit and - on tick.
                 alignment = left_align;
               }
               else if(derived().x_ticks_.label_rotation_ == horizontal)
@@ -321,7 +323,8 @@
                 if ((derived().x_ticks_.ticks_on_plot_window_on_ != 0) || ((value != 0) && derived().x_axis_.axis_line_on_))
                 { // Avoid a "0" below the X-axis if it would be cut through by any internal vertical Y-axis line.
                   derived().image.get_g_element(detail::PLOT_VALUE_LABELS).text(
- x, y,
+ x, // to centre on tick
+ y,
                     label.str(),
                     derived().x_label_value_.style(),
                     alignment, // center label on the tick.
@@ -1010,7 +1013,7 @@
           // std::string x_label()
           // bool x_label_units_on() //
           // std::string x_label_units() // Show X-axis units text.
- // bool x_major_labels_on()
+ // int x_major_labels_on()
           // svg_color x_label_color()
           // bool axes_on()
           // svg_color x_axis_color()
@@ -1050,7 +1053,7 @@
           //Derived& x_ticks_down_on(bool cmd)
           //Derived& x_label_on(bool cmd)
           //Derived& x_label_units_on(bool cmd)
- //Derived& x_major_labels_on(bool cmd)
+ //Derived& x_major_labels_on(int cmd)
           //Derived& title_on(bool cmd)
           //Derived& x_major_grid_on(bool is)
           //Derived& x_minor_grid_on(bool is)
@@ -1764,15 +1767,15 @@
             return derived().x_axis_.label_units_on_;
           }
 
- Derived& x_major_labels_on(bool cmd)
+ Derived& x_major_labels_on(int cmd)
           {
- derived().x_ticks_.major_value_labels_on = cmd;
+ derived().x_ticks_.major_value_labels_on_ = cmd;
             return derived();
           }
 
- bool x_major_labels_on()
+ int x_major_labels_on()
           {
- return derived().x_ticks_.major_value_labels_on;
+ return derived().x_ticks_.major_value_labels_on_;
           }
 
           Derived& x_major_label_rotation(rotate_style rot)

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 2008-01-16 12:46:49 EST (Wed, 16 Jan 2008)
@@ -281,14 +281,14 @@
         x_label_value_(0, 0, "", x_value_label_style_, center_align, horizontal),
         x_axis_(X, -10., +10., black, 1, 0, true, false, true),
         y_axis_(Y, -10., +10., black, 1, 0, true, false, true),
- // TODO fil in all values.
- x_ticks_(X),// For defaults see ticks_labels_style.
+ // Might fill in all values, but there are rather many for ticks_labels_style,
+ x_ticks_(X),// so for defaults see ticks_labels_style.
         y_ticks_(Y),
         y_label_info_(0, 0, "Y Axis", y_axis_label_style_, center_align, upward),
         y_units_info_(0, 0, " (units)", y_axis_label_style_, center_align, upward),
         y_label_value_(0, 0, "", y_value_label_style_, center_align, upward),
         text_margin_(2.), // for axis label text, as a multiplier of the font size.
- image_border_(yellow, white, 2, 3, true, true),
+ image_border_(yellow, white, 2, 10, true, true), // margin should be about axis label font size.
         plot_window_border_(yellow, svg_color(255, 255, 255), 2, 3, true, false),
         legend_header_(0, 0, "", legend_style_, center_align, horizontal),
         legend_width_(200), // width of legend box (pixels) // TODO isn't this calculated?
@@ -364,11 +364,10 @@
         // (if set a default in plot_window then call to set legend place must to come *after* it.
         // So not set a default? But leaving it as inside is worse?)
 
- //axes_on_ = x_axis_.axis_line_on_ || y_axis_.axis_line_on_;
         x_ticks_on_ = x_ticks_.up_ticks_on_ || x_ticks_.down_ticks_on_;
         y_ticks_on_ = y_ticks_.left_ticks_on_ || y_ticks_.right_ticks_on_;
 
- title_info_.style().font_size(20);
+ // title_info_.style().font_size(20);
       } // svg_2d_plot() default constructor.
 
     private:
@@ -391,6 +390,9 @@
       { // The plot window is used to set a clip path:
         // this ensures that data points and lines (and anything else)
         // outside this window are NOT drawn.
+
+ // All calculation use svg units, pixels by default.
+
         // Start by assuming we can use all the svg image,
         // but reduce by the width of any image border.
         plot_left_ = 0 + image_border_width();
@@ -404,8 +406,9 @@
           plot_top_ += title_font_size() * (text_margin_ + 0.5);
         }
 
- size_legend_box();
+ size_legend_box(); // depending on its contents.
        place_legend_box();
+ // Assume that axis labels are always at bottom and left.
        if(x_axis_.label_on_)
        { // Leave space at bottom for X axis label.
           plot_bottom_ -= x_axis_label_style_.font_size() * (text_margin_);
@@ -415,19 +418,15 @@
           plot_left_ += x_axis_label_style_.font_size() * (text_margin_ - 0.5);
         }
         if(plot_window_on_)
- { // Reduce to allow plot window border.
- // Needed to allow any plot window border rectangle to show OK.
- // A small margin is to prevent it being right on the image border.
- plot_left_ += image_border_.margin_; // pixels.
+ { // Needed to allow any plot window border rectangle to show OK.
+ // A small margin is to prevent it overlapping the image border.
+ // Also allows for axis value labels that mark the min and max
+ // that must extend half a font width beyond the plot window border.
+ plot_left_ += image_border_.margin_;
           plot_right_ -= image_border_.margin_;
           plot_top_ += image_border_.margin_;
           plot_bottom_ -= image_border_.margin_;
         }
- if((!legend_on_) && (x_axis_.label_on_))
- { // Need to avoid rightmost X-axis label running off image.
- // Might need more if a long horizontal label?
- plot_right_ -= text_margin_ * x_value_label_style_.font_size();
- }
         // Check if the axes will intersect.
         // X axis position is determined by the range of Y min and max label values.
         x_axis_position_ = x_intersects_y; // Assume X-axis will intersect Y-axis (range of Y values includes zero).
@@ -462,86 +461,77 @@
         // Check that labels won't collide and advise if they will.
         // Change rotation to avoid collision?
 
- double y_label_length_ = 0.; // SVG units.
+ double y_label_length_ = 0.; // Width of y labels, depending on orientation.
         if (y_ticks_.label_rotation_ == horizontal)
         { // Move plot left edge right to give space for y_value_precision_ digits.
- y_label_length_ += y_axis_label_style_.font_size() * y_ticks_.label_max_chars_ * wh; // SVG units
+ y_label_length_ += y_ticks_.label_max_chars_ * y_axis_label_style_.font_size() * wh; // SVG units
         }
         else if((y_ticks_.label_rotation_ == upward) || (y_ticks_.label_rotation_ == downward))
- { // Only need one char width from Y-axis label.
- y_label_length_ += y_value_label_style_.font_size() * 1.5;
+ { // Only need one char & 1 space width from Y-axis label.
+ y_label_length_ += y_value_label_style_.font_size() * 2 * wh;
         }
         else
         { // Assume some slope 45, so diagonally down from tick,
           // and takes a bit less room.
- y_label_length_ = y_value_label_style_.font_size() * y_ticks_.label_max_chars_ * wh * sin45;
+ y_label_length_ = y_ticks_.label_max_chars_ * y_value_label_style_.font_size() * wh * sin45;
         }
- if (y_ticks_.major_value_labels_on) // && (y_axis_position_ != right) )
- {
- // TODO sort out this unusual case of Y-axis line too close to the axis label.
- //if (abs(x_min_/(x_max_ - x_min_)) < 0.05) // < 5% of range?
- // // Want to do this:
- // //((y_axis_ - plot_left_) < (y_label_length_ - y_major_tick_width_)) )
- // // needs to calculate transform to get into SVG units, but this is changing plot_left_ !!
- //{ // force onto plot window. BUT this only looks right if plot window is on.
- // // because major ticks and label are on the plot window
- // use_y_ticks_on_plot_window_ = true;
- //}
- if (y_ticks_.ticks_on_plot_window_on_ < 0)
- { // Move plot window right to make space for value labels on left,
+
+ if (y_ticks_.major_value_labels_on_ != 0)
+ { // Some value labels.
+ if ((y_ticks_.ticks_on_plot_window_on_ < 0) // On left of plot window.
+ && (y_ticks_.major_value_labels_on_ < 0) ) // & labels on left.
+ { // Contract plot window left edge to right to make space for value labels on left.
             plot_left_ += y_label_length_;
           }
- else if (y_ticks_.ticks_on_plot_window_on_ > 0)
- { // Move plot window right to make space for value labels on right,
- plot_right_ -= y_label_length_;
+ else if ((y_ticks_.ticks_on_plot_window_on_ > 0) // On right of plot window.
+ && (y_ticks_.major_value_labels_on_ > 0) ) // & labels to right.
+ { // Contract plot window right to left to make space for value labels on right.
+ plot_right_ -= y_label_length_;
+ }
+ // else y_ticks_.ticks_on_plot_window_on_ == 0 // On vertical Y-axis line.
+ // Ignore the unusual case of Y-axis line too close to the axis label?
+ // In this case the value labels may overflow the plot window
+ // and collide with the axis label!
+ // User must change to put value label downward, or on other side of the axis line.
+ // using major_value_labels_on(int d)
+ // to set tick value labels to left (<0), none (==0) or right (>0).
+ else
+ { // no labels on plot window (may be on mid-plot Y-axis).
           }
+ } // y_ticks_. major_value_labels_on
+
+ double x_label_length_ = 0; // Work out the longest value label for X-Axis.
+ if (x_ticks_.label_rotation_ == horizontal)
+ { // Only 1 char height & 1 space needed if labels are horizontal.
+ x_label_length_ = 2 * x_value_label_style_.font_size() * wh; // SVG chars
+ }
+ else if ((x_ticks_.label_rotation_ == upward) || (x_ticks_.label_rotation_ == downward))
+ { // ! horizontal so will need more than 2 chars worth.
+ x_label_length_+= x_ticks_.label_max_chars_ * x_value_label_style_.font_size() * wh; // SVG chars.
+ }
+ else
+ { // Assume label is sloping, say 45, so * sin(45) = 0.707.
+ x_label_length_+= x_ticks_.label_max_chars_ * x_value_label_style_.font_size() * wh * sin45; // SVG 'chars'.
         }
 
- if (x_ticks_.major_value_labels_on)
- {
- if ((x_ticks_.ticks_on_plot_window_on_ < 0) || (x_axis_position_ != top) )
- { // Move bottom of plot window up to give space for x value labels.
- double x_label_length_ = 0;
- if(x_ticks_.label_rotation_ == horizontal)
- { // Only 1 char height & 1 space needed if labels are horizontal.
- x_label_length_ = 2; // SVG chars
- }
- else
- { // ! horizontal so will need more than 2
- if ((x_ticks_.label_rotation_ == upward) || (x_ticks_.label_rotation_ == downward))
- { // Need space for longest.
- x_label_length_+= x_ticks_.label_max_chars_ * wh; // SVG chars.
- }
- else
- { // Assume label is sloping, say 45, so * sin(45) = 0.707.
- x_label_length_+= x_ticks_.label_max_chars_ * wh * sin45; // SVG 'chars'.
- }
- }
- x_label_length_ *= x_value_label_style_.font_size(); // Total length in SVG.
+ if (x_ticks_.major_value_labels_on_ != 0)
+ { // Some value labels.
+ if ((x_ticks_.ticks_on_plot_window_on_ < 0) // on bottom of plot window.
+ && (x_ticks_.major_value_labels_on_ < 0) ) // & labels on bottom.
+ { // Contract plot window bottom edge up to make space for x value labels on bottom.
             plot_bottom_ -= x_label_length_; // Move up.
           }
- else if ((x_ticks_.ticks_on_plot_window_on_ > 0) || (x_axis_position_ != bottom) )
+ else if ((x_ticks_.ticks_on_plot_window_on_ > 0) //
+ && (x_ticks_.major_value_labels_on_ > 0) ) // & x labels to top.
           { // Move top of plot window down to give space for x value labels.
- double x_label_length_ = 0;
- if(x_ticks_.label_rotation_ == horizontal)
- { // Only 1 char height & 1 space needed if labels are horizontal.
- x_label_length_ = 2; // SVG chars
- }
- else
- { // ! horizontal so will need more than 2
- if ((x_ticks_.label_rotation_ == upward) || (x_ticks_.label_rotation_ == downward))
- { // Need space for longest.
- x_label_length_+= x_ticks_.label_max_chars_ * wh; // SVG chars.
- }
- else
- { // Assume label is sloping, say 45, so * sin(45) = 0.707.
- x_label_length_+= x_ticks_.label_max_chars_ * wh * sin45; // SVG 'chars'.
- }
- }
- x_label_length_ *= x_value_label_style_.font_size(); // Total length in SVG.
             plot_top_ += x_label_length_; // Move down.
           }
- } // major_value_labels_on
+ else
+ { // no labels on plot window (may be on mid-plot X-axis).
+ }
+ } // x_ticks_. major_value_labels_on
+
+ // Make space for any ticks.
         if(y_ticks_.left_ticks_on_)
         { // Start left of plot to right to give space for biggest of any external left ticks.
           plot_left_ += (std::max)(y_ticks_.major_tick_length_, y_ticks_.minor_tick_length_); // Avoid macro max trap!
@@ -554,17 +544,18 @@
         if (x_axis_.axis_line_on_)
         { // Want a X-axis line, so check if range includes zero, so axes intersect,
           // and x_axis_ is svg coordinate of Y-axis (usually y = 0).
- // If not fix axis to bottom of the plot window
- // and perhaps leave space (and quiggle between) to show this?
- if (x_axis_position_ == bottom) // All definitely > zero.
+ // If not fix axis to bottom of the plot window.
+ if ((x_axis_position_ == bottom) // All definitely > zero.
+ && !(x_ticks_.ticks_on_plot_window_on_ < 0) ) // & not already at bottom.
           { // y_min_ > 0 so X-axis will not intersect Y-axis, so use plot window.
- x_axis_.axis_ = plot_bottom_; // X-axis to bottom,
- //plot_bottom_ -= 2 * y_label_info_.font_size(); // with a space.
+ plot_bottom_ -= x_label_length_; // Move up for the value labels.
+ x_axis_.axis_ = plot_bottom_; // Put X-axis on bottom.
           }
- else if(x_axis_position_ == top) // definitely < zero.
+ else if ((x_axis_position_ == top) // definitely < zero.
+ && !(x_ticks_.ticks_on_plot_window_on_ > 0) ) // & not already at top.
           { // // y_max_ < 0 so X-axis will not intersect Y-axis, so use plot window.
- x_axis_.axis_ = plot_top_; // X-axis to top,
- //plot_top_ += 2 * y_label_info_.font_size(); // with a space.
+ plot_top_ += x_label_length_; // Move down for labels.
+ x_axis_.axis_ = plot_top_; // Put X-axis on top.
           }
           else
           { // y_axis_position_ == y_intersects_x
@@ -667,7 +658,6 @@
           }
         }
 
-
         // Access the paths for the ticks & grids, ready for additions.
         path_element& minor_tick_path = image.get_g_element(detail::PLOT_Y_MINOR_TICKS).path();
         path_element& major_tick_path = image.get_g_element(detail::PLOT_Y_MAJOR_TICKS).path();
@@ -696,13 +686,13 @@
             if (j != 0. || ! x_axis_.axis_line_on_)
             { // Avoid a major tick at y == 0 where there *is* a horizontal X-axis line.
               // (won't be X-axis line for 1-D where the zero tick is always wanted).
- draw_y_minor_ticks(j, minor_tick_path, minor_grid_path);
+ draw_y_minor_tick(j, minor_tick_path, minor_grid_path);
             }
           }
           if ((y != 0. || ! x_axis_.axis_line_on_) || (y_ticks_.ticks_on_plot_window_on_ != 0))
           { // Avoid a major tick at y == 0 where there *is* a horizontal X-axis line.
             // (won't be X-axis line for 1-D where the zero tick is always wanted).
- draw_y_major_ticks(y, major_tick_path, major_grid_path);
+ draw_y_major_tick(y, major_tick_path, major_grid_path);
           }
         }
 
@@ -714,13 +704,13 @@
             if ((j != 0. || ! y_axis_.axis_line_on_) || (y_ticks_.ticks_on_plot_window_on_ != 0))
             { // Avoid a major tick at y == 0 where there *is* a horizontal X-axis line.
               // (won't be X-axis line for 1-D where the zero tick is always wanted).
- draw_y_minor_ticks(j, minor_tick_path, minor_grid_path);
+ draw_y_minor_tick(j, minor_tick_path, minor_grid_path);
             }
           }
           if ((y != 0. || ! x_axis_.axis_line_on_) || (y_ticks_.ticks_on_plot_window_on_ != 0))
           { // Avoid a major tick at y == 0 where there *is* a horizontal X-axis line.
             // (won't be X-axis line for 1-D where the zero tick is always wanted).
- draw_y_major_ticks(y, major_tick_path, major_grid_path);
+ draw_y_major_tick(y, major_tick_path, major_grid_path);
           }
         }
       } // draw_y_axis
@@ -744,8 +734,8 @@
           upward)); // Y label must be drawn vertically.
       } // draw_y_label
 
- void draw_y_major_ticks(double value, path_element& tick_path, path_element& grid_path)
- { // Draw Y axis major ticks, tick value labels & grids.
+ void draw_y_major_tick(double value, path_element& tick_path, path_element& grid_path)
+ { // Draw a Y axis major tick, tick value labels & grids.
         double y(value); // for tick and/or grid.
         transform_y(y); // Cartesian to SVG coordinates.
         if((y < plot_top_) || (y > plot_bottom_))
@@ -756,9 +746,9 @@
         double x_right(image.y_size());
         if(y_ticks_.major_grid_on_)
         { // Draw horizontal major grid line.
- if(!plot_window_on_)
- { // TODO is this right?
- if(y_ticks_.major_value_labels_on)
+ if(!plot_window_on_ != 0)
+ {
+ if(y_ticks_.major_value_labels_on_ < 0)
             { // Start further right to give space for y axis value label.
               y -= y_value_label_style_.font_size() * text_margin_;
             }
@@ -806,7 +796,7 @@
           // leaving x_left at the left most end of any tick.
         }
 
- if(y_ticks_.major_value_labels_on)
+ if(y_ticks_.major_value_labels_on_ != 0)
         { // Label the tick with value, for example "1.2"
           std::stringstream label;
           label.precision(y_ticks_.value_precision_);
@@ -864,10 +854,10 @@
             }
           }
         } // if(use_y_major_labels)
- } // draw_y_major_ticks
+ } // draw_y_major_tick
 
- void draw_y_minor_ticks(double value, path_element& tick_path, path_element& grid_path)
- {
+ void draw_y_minor_tick(double value, path_element& tick_path, path_element& grid_path)
+ { // Draw a Y-axis minor tick and optional grid.
         double x_left(0.);
         double y(value); // tick position and value label.
         transform_y(y); // to svg.
@@ -876,7 +866,7 @@
         if(y_ticks_.minor_grid_on_)
         { // Draw the minor grid, if wanted.
           if(!plot_window_on_)
- { // TODO now wrong?????
+ {
             if(x_axis_.label_on_)
             {
               x_left += y_value_label_style_.font_size() * text_margin_;
@@ -891,7 +881,7 @@
           if((y >= plot_top_) && (y <= plot_bottom_) && (x_left >= plot_left_) && (x_right <= plot_right_) )
           { // Make sure that we are drawing inside the allowed window.
             // Note comparisons are 'upside-down' - y is increasing downwards!
- grid_path.M(x_left, y).L(x_right, y);
+ grid_path.M(x_left, y).L(x_right, y); // Draw grid line.
           }
           // TODO else just ignore outside plot window?
         }
@@ -908,7 +898,7 @@
         }
         else
         { // Internal style,
- x_left = y_axis_.axis_; // On the Y-axis line.
+ x_left = y_axis_.axis_; // On the Y-axis line itself.
           x_right = y_axis_.axis_;
         }
         if(y_ticks_.left_ticks_on_)
@@ -928,9 +918,8 @@
         else
         {// Do nothing? warn?
           // std::cout << "y minor tick OUTside " << x_left << ' ' << y << ' ' << x_right << std::endl;
-
         }
- } // void draw_y_minor_ticks
+ } // void draw_y_minor_tick
 
       void draw_straight_lines(const svg_2d_plot_series& series)
       { // Straight line between data points (rather than a Bezier curve).
@@ -1254,15 +1243,15 @@
         return x_axis_.label_on_;
       }
 
- svg_2d_plot& y_major_labels_on(bool cmd)
+ svg_2d_plot& y_major_labels_on(int cmd)
       {
- y_ticks_.major_value_labels_on = cmd;
+ y_ticks_.major_value_labels_on_ = cmd;
         return *this;
       }
 
- bool y_major_labels_on()
+ int y_major_labels_on()
       {
- return y_ticks_.major_value_labels_on;
+ return y_ticks_.major_value_labels_on_;
       }
 
       svg_2d_plot& y_major_label_rotation(rotate_style rot)

Modified: sandbox/SOC/2007/visualization/boost/svg_plot/svg_boxplot.hpp
==============================================================================
--- sandbox/SOC/2007/visualization/boost/svg_plot/svg_boxplot.hpp (original)
+++ sandbox/SOC/2007/visualization/boost/svg_plot/svg_boxplot.hpp 2008-01-16 12:46:49 EST (Wed, 16 Jan 2008)
@@ -212,7 +212,7 @@
         y = y * y_scale_ + y_shift_;
     }
 
- void draw_y_minor_ticks(double j, path_element& tick_path)
+ void draw_y_minor_tick(double j, path_element& tick_path)
     {
         double y1(j), x1(plot_left_);
         double y_tick_length = y_minor_tick_length_ / 2.;
@@ -244,7 +244,7 @@
         }
     }
 
- void draw_y_major_ticks(double i, path_element& tick_path)
+ void draw_y_major_tick(double i, path_element& tick_path)
     {
         double y1(i), x1(0.), x2(image.y_size());
 
@@ -290,10 +290,10 @@
                        j < i + y_major_interval_;
                        j += y_minor_jump)
             {
- draw_y_minor_ticks(j, minor_tick_path);
+ draw_y_minor_tick(j, minor_tick_path);
             }
 
- draw_y_major_ticks(i, major_tick_path);
+ draw_y_major_tick(i, major_tick_path);
         }
 
         // Draw the ticks on the negative side.
@@ -302,10 +302,10 @@
             // draw minor ticks
             for(double j=i; j>i-y_major_interval_; j-=y_major_interval_ / (y_num_minor_ticks_+1))
             {
- draw_y_minor_ticks(j, minor_tick_path);
+ draw_y_minor_tick(j, minor_tick_path);
             }
 
- draw_y_major_ticks(i, major_tick_path);
+ draw_y_major_tick(i, major_tick_path);
         }
     }
 
@@ -687,7 +687,7 @@
     return *this;
 }
 
-svg_boxplot& y_major_labels_on(bool cmd)
+svg_boxplot& y_major_labels_on(int cmd)
 {
     use_y_major_labels = cmd;
     return *this;

Modified: sandbox/SOC/2007/visualization/boost/svg_plot/svg_style.hpp
==============================================================================
--- sandbox/SOC/2007/visualization/boost/svg_plot/svg_style.hpp (original)
+++ sandbox/SOC/2007/visualization/boost/svg_plot/svg_style.hpp 2008-01-16 12:46:49 EST (Wed, 16 Jan 2008)
@@ -548,6 +548,9 @@
   dim dim_; // x, y or z
     double min_; // minimum x value (Cartesian units).
     double max_; // maximum x value (Cartesian units).
+ // Note that these duplicate the same named in ticks_labels_style,
+ // but they might have different uses, so are left pro tem.
+ // TODO reconsider the implications of this (largely accidental) decision.
     double axis_; //
     // X-axis (y = 0) transformed into SVG Y coordinates. -1 if not calculated yet.
     // or Y-axis (x = 0) transformed into SVG X coordinates. -1 if not calculated yet.
@@ -564,7 +567,8 @@
     bool axis_line_on_; // Draw a X horizontal or Y vertical axis line.
 
     axis_line_style(dim d = X,
- double min = -10., double max = +10., // defaults.
+ double min = -10., double max = +10., // Defaults.
+ // See also default in ticks_labels_style.
       const svg_color col = black, double width = 1,
       int axis_position = 0, bool label_on = true,
       bool label_units_on = false,
@@ -670,18 +674,19 @@
     bool right_ticks_on_; // Draw ticks right from vertical Y-axis line.
     // Simplest to have all of these although only one pair like up or down is used.
     // Unused are always false.
- bool major_value_labels_on; // Label X values for major ticks.
- rotate_style label_rotation_; // Direction X_axis value labels written.
+ int major_value_labels_on_; // Label values for major ticks.
+ // < 0 means to left or down (default), 0 (false) means none, > 0 means to right (or top)/
+ rotate_style label_rotation_; // Direction axis value labels written.
     bool major_grid_on_; // Draw X grid at major ticks.
     bool minor_grid_on_;// Draw X grid at minor ticks.
     int value_precision_; // precision for tick value labels, usually 3 will suffice.
     int value_ioflags_; // IO formatting flags for the axis.
     bool strip_e0s_; // If redundant zero, + and e are to be stripped.
- rotate_style x_label_rotation_; // Direction X_axis value labels written.
     size_t label_max_chars_; // width (in SVG units) of longest label on axis.
- int ticks_on_plot_window_on_; // Value labels & ticks on the plot window rather than on X or Y-axis.
- // For X-axis -1 = left, 0 = false, +1 = right. Default left.
- // For Y-axis -1 = bottom, 0 = false, +1 = top. Default bottom.
+ int ticks_on_plot_window_on_; // Value labels & ticks on the plot window border
+ // (rather than on X or Y-axis).
+ // For X-axis -1 = left, 0 = false, +1 = right. Default left of plot window.
+ // For Y-axis -1 = bottom, 0 = false, +1 = top. Default bottom of plot window.
 
     ticks_labels_style(dim d = X,
       double max = 10., double min = -10.,
@@ -716,8 +721,7 @@
     right_ticks_on_(false), // Draw ticks right from vertical Y-axis line.
     // Simplest to have all of these although only one pair like up or down is used.
     // Unused are always false.
- major_value_labels_on(true), // Label values for major ticks.
- //label_units_on_(true), // Label axis units.
+ major_value_labels_on_(-1), // Label values side for major ticks left (right or none).
     label_rotation_(horizontal), // Direction axis value labels written.
     major_grid_on_(false), // Draw grid at major ticks.
     minor_grid_on_(false),// Draw grid at minor ticks.
@@ -758,7 +762,7 @@
   size_t longest_label()
   { // Update label_max_chars_ with the longest value label as pixels,
     // return the count of digits etc.
- if(major_value_labels_on)
+ if(major_value_labels_on_ != 0) // ! none
     { // Show values by the tick as "1.2" or "3.4e+000"...
       size_t longest = 0;
       
@@ -824,12 +828,22 @@
     return down_ticks_on_;
   }
 
- ticks_labels_style& use_down_ticks(bool is)
+ ticks_labels_style& use_down_ticks(bool side)
   {
- down_ticks_on_ = is;
+ down_ticks_on_ = side;
     return *this; // Make chainable.
   }
 
+ int major_value_labels_on() const
+ { // Get tick value labels to left (<0), none (==0) or right (>0).
+ return major_value_labels_on_;
+ }
+
+ ticks_labels_style& major_value_labels_on(int is)
+ { // Set tick value labels to left (<0), none (==0) or right (>0).
+ major_value_labels_on_ = is;
+ return *this; // Make chainable.
+ }
 
 }; // class ticks_labels_style
 

Modified: sandbox/SOC/2007/visualization/libs/svg_plot/example/demo_2d_plot.cpp
==============================================================================
--- sandbox/SOC/2007/visualization/libs/svg_plot/example/demo_2d_plot.cpp (original)
+++ sandbox/SOC/2007/visualization/libs/svg_plot/example/demo_2d_plot.cpp 2008-01-16 12:46:49 EST (Wed, 16 Jan 2008)
@@ -90,19 +90,21 @@
   my_plot.title(title)
           .title_font_size(20)
           .x_label(x_label)
- .y_label(y_label);
-
- // Commands.
+ .y_label(y_label)
+ ;
+ // Legend settings.
   my_plot.legend_on(true)
           //.legend_place(outside_bottom)
- .legend_place(outside_right)
+ //.legend_place(outside_right)
           .title_on(true)
           .plot_window_on(true)
           .plot_border_color(magenta)
           .x_label_on(true)
           .y_label_on(true)
- .y_major_labels_on(true)
- .x_major_labels_on(true);
+ .y_major_labels_on(-1)
+ .x_major_labels_on(-1)
+ .legend_title("Function")
+ .legend_title_font_size(16);
 
   // Color settings chosen for visibility rather than taste!
 
@@ -111,10 +113,17 @@
           .legend_background_color(svg_color(lightyellow))
           .legend_border_color(svg_color(yellow))
           .plot_background_color(svg_color(white))
- .plot_border_color(svg_color(blue))
+ .plot_border_color(svg_color(green))
           .plot_border_width(1)
           .title_color(red)
           ;
+ // Options for x and/or y num_minor_ticks.
+ // .y_num_minor_ticks(4) // 0 major, 2,4,6,7,8 minor, 10 major ...
+ // .y_num_minor_ticks(1) // 0 major, 5, minor, 10 major ...
+ // .y_num_minor_ticks(2) // show half points.
+ // .y_num_minor_ticks(3) // show half and quarter points.
+ // .y_num_minor_ticks(4) // 0 major, 2,4,6,7,8 minor, 10 major ...
+ // .y_num_minor_ticks(9) // 0 major, 1,2,3,4,5,6,7,8,9 minor, 10 major ...
 
   // X axis settings.
   my_plot.x_range(xmin, xmax)
@@ -125,53 +134,41 @@
           .x_minor_tick_width(1) // pixels
           .x_num_minor_ticks(4) // plus 1 major = 5 ticks per major step.
           ;
- // Options for x and/or y num_minor_ticks.
- // .y_num_minor_ticks(4) // 0 major, 2,4,6,7,8 minor, 10 major ...
- // .y_num_minor_ticks(1) // 0 major, 5, minor, 10 major ...
- // .y_num_minor_ticks(2) // show half points.
- // .y_num_minor_ticks(3) // show half and quarter points.
- // .y_num_minor_ticks(4) // 0 major, 2,4,6,7,8 minor, 10 major ...
- // .y_num_minor_ticks(9) // 0 major, 1,2,3,4,5,6,7,8,9 minor, 10 major ...
 
   // Y-axis settings.
  my_plot
     .y_range(ymin, ymax)
     .y_major_interval(1.)
+ .y_num_minor_ticks(4) // plus 1 major = 5 ticks per major step.
     .y_major_tick_length(10) // pixels
     .y_major_tick_width(2) // pixels
     .y_minor_tick_length(5) // pixels
     .y_minor_tick_width(1) // pixels
- .y_num_minor_ticks(4); // plus 1 major = 5 ticks per major step.
+ ;
 
   // Very pale blue grid - like old fashioned graph paper.
   my_plot.x_major_grid_color(svg_color(200, 220, 255))
          .x_minor_grid_color(svg_color(240, 240, 255))
          .y_major_grid_color(svg_color(200, 220, 255))
          .y_minor_grid_color(svg_color(240, 240, 255))
- //.y_minor_grid_color(green)
          .y_major_grid_width(2)
- .y_minor_grid_width(1);
-
- // - but nothing shows - until you make .major_grid_on(true)!
- my_plot.x_major_grid_on(true)
- .x_minor_grid_on(true)
- .y_major_grid_on(true)
- .y_minor_grid_on(true);
-
- my_plot.x_ticks_down_on(true);
- my_plot.y_ticks_left_on(true);
- //my_plot.x_ticks_on_plot_window_on(true); // default false
- //my_plot.y_ticks_on_plot_window_on(true);
+ .y_minor_grid_width(1)
+ .x_major_grid_on(true) // But nothing shows - until you make .major_grid_on(true)!
+ .x_minor_grid_on(true)
+ .y_major_grid_on(true)
+ .y_minor_grid_on(true);
+
+ my_plot.x_ticks_down_on(true); // X-axis.
+ my_plot.y_ticks_left_on(true); // Y-axis.
+ my_plot.x_ticks_on_plot_window_on(0); // default on axes, if possible.
+ my_plot.y_ticks_on_plot_window_on(0);
 
   my_plot.y_value_ioflags(ios::dec | ios::fixed).y_value_precision(1);
   my_plot.x_value_ioflags(ios::dec | ios::scientific).x_value_precision(2);
   // my_plot.x_value_ioflags(ios::dec).x_value_precision(2);
 
- // Legend settings
- my_plot.legend_title("Function");
- my_plot.legend_title_font_size(16);
   my_plot.y_major_label_rotation(uphill);
- my_plot.x_major_label_rotation(downward); // slope
+ my_plot.x_major_label_rotation(downward); // sloping.
    //my_plot.y_major_label_rotation(horizontal); // defaults.
    //my_plot.x_major_label_rotation(horizontal);
 
@@ -189,7 +186,6 @@
 
 int main()
 {
-
   // boost::array or anything in boost such that pair_type has
   // std and boost as associated namespaces.
   typedef ::std::pair< ::boost::array<int, 1>, int> pair_type;
@@ -208,10 +204,10 @@
     data3[i] = h(i);
   }
 
- //Demonstrate/test plots with various range of x and y, some *not* including zero.
+ // Demonstrate/test plots with various range of x and y, some *not* including zero.
 
    plot("Plot of Mathematical Functions", "./demo_2d_plot_XYPM.svg", "X-axis", -10., +10., "Y-axis", -10., +10.); // Both X & Y include zero.
- plot("Plot of Mathematical Functions", "./demo_2d_plot_XP.svg", "X-axis", +1., +10., "Y-axis", -10., 10.); // X all > 0
+ plot("Plot of Mathematical Functions", "./demo_2d_plot_XP.svg", "X-axis", +1., +10., "Y-axis", -10., 10.); // X all > 0
    plot("Plot of Mathematical Functions", "./demo_2d_plot_XN.svg", "X-axis", -10., -1., "Y-axis", -10., 10.); // x all < 0
    plot("Plot of Mathematical Functions", "./demo_2d_plot_YP.svg", "X-axis", -1., +10., "Y-axis", +1., +10.); // Y all > 0
    plot("Plot of Mathematical Functions", "./demo_2d_plot_YN.svg", "X-axis", -1., +10., "Y-axis", -10., -1.); // y all < 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