|
Boost-Commit : |
From: pbristow_at_[hidden]
Date: 2008-01-29 11:17:45
Author: pbristow
Date: 2008-01-29 11:17:44 EST (Tue, 29 Jan 2008)
New Revision: 43011
URL: http://svn.boost.org/trac/boost/changeset/43011
Log:
Adjustment to legend placing and axis labels are now relative to plot window. Seems OK for various tests including JM math 2
Text files modified:
sandbox/SOC/2007/visualization/boost/svg_plot/detail/axis_plot_frame.hpp | 124 ++++++++++++++++++++++-----------------
sandbox/SOC/2007/visualization/boost/svg_plot/svg.hpp | 50 ++++++++--------
sandbox/SOC/2007/visualization/boost/svg_plot/svg_1d_plot.hpp | 16 ++--
sandbox/SOC/2007/visualization/boost/svg_plot/svg_2d_plot.hpp | 79 +++++++++++++++++-------
sandbox/SOC/2007/visualization/boost/svg_plot/svg_style.hpp | 26 +++----
sandbox/SOC/2007/visualization/libs/svg_plot/example/math_special_functions.cpp | 2
6 files changed, 169 insertions(+), 128 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-29 11:17:44 EST (Tue, 29 Jan 2008)
@@ -49,7 +49,8 @@
outside_left = 1, // Outside
outside_right = +2, // Default for outside.
outside_top = +3,
- outside_bottom = +4
+ outside_bottom = +4,
+ somewhere = +5 // legend_top_left(x, y)
};
namespace detail
@@ -378,7 +379,6 @@
throw std::runtime_error("X-tick Y value wrong!");
}
-
if(derived().x_ticks_.ticks_on_window_or_axis_ != 0)
{ // External to plot window style bottom or top.
// Always want all values including "0", if labeling external to plot window.
@@ -412,23 +412,33 @@
void draw_x_axis()
{ // Draw horizontal X-axis line & plot window line to hold.
if(derived().x_axis_.axis_line_on_)
- {
+ { // Want an X-axis line.
double xleft = derived().plot_left_;
double xright = derived().plot_right_;
if (derived().x_axis_position_ == x_intersects_y)
{ // Draw the horizontal X-axis line the full width of the plot window,
// perhaps including an addition in lieu of a major tick.
- if (derived().y_ticks_.left_ticks_on_ && (derived().x_ticks_.ticks_on_window_or_axis_ != 0))
- { // Extend the horizontal line left in lieu of longest tick.
- xleft -= (std::max)(derived().y_ticks_.minor_tick_length_, derived().y_ticks_.major_tick_length_);
+ if (derived().y_ticks_.left_ticks_on_)
+ {
+ if (derived().y_ticks_.ticks_on_window_or_axis_ < 0) // left
+ { // Extend the horizontal line left in lieu of longest tick.
+ xleft -= (std::max)(derived().y_ticks_.minor_tick_length_, derived().y_ticks_.major_tick_length_);
+ }
+ }
+ else if (derived().y_ticks_.right_ticks_on_)
+ {
+ if (derived().y_ticks_.ticks_on_window_or_axis_ > 0) // right
+ { // Extend the horizontal line right in lieu of longest tick.
+ xright += (std::max)(derived().y_ticks_.minor_tick_length_, derived().y_ticks_.major_tick_length_);
+ }
}
double y = derived().x_axis_.axis_; // y = 0, (provided y range includes zero).
derived().image.g(PLOT_X_AXIS).line(xleft, y, xright, y);
- if (derived().x_ticks_.ticks_on_window_or_axis_ < 0)
+ if (derived().x_ticks_.ticks_on_window_or_axis_ < 0) // bottom
{ // Draw a vertical line holding the ticks on the top of plot window.
derived().image.g(PLOT_X_AXIS).line(xleft, derived().plot_bottom_, xright, derived().plot_bottom_);
}
- else if (derived().x_ticks_.ticks_on_window_or_axis_ > 0)
+ else if (derived().x_ticks_.ticks_on_window_or_axis_ > 0) // top
{// Draw a vertical line holding the ticks on the bottom of plot window.
derived().image.g(PLOT_X_AXIS).line(xleft, derived().plot_top_, xright, derived().plot_top_);
}
@@ -528,11 +538,11 @@
{ // Calculate how big the legend box needs to be.
// Store in legend_width_ and legend_height_
if(derived().legend_on_ == false)
- { // No legend, so set values to show legend positions invalid.
- derived().legend_left_ = -1.;
- derived().legend_right_ = -1.;
- derived().legend_top_ = -1.;
- derived().legend_bottom_ = -1.;
+ { // No legend, so set values to show legend positions invalid?
+ //derived().legend_left_ = -1.;
+ //derived().legend_right_ = -1.;
+ //derived().legend_top_ = -1.;
+ //derived().legend_bottom_ = -1.;
derived().legend_height_ = 0.;
derived().legend_width_ = 0.;
return;
@@ -604,28 +614,31 @@
double spacing = derived().y_axis_label_style_.font_size() * 1.; // Around any legend box - beyond any border.
switch (derived().legend_place_)
{
- case nowhere:
- return;
+ case nowhere:
+ return; // Actually places it at (0, 0), probably overwriting the plot.
+ case somewhere:
+ // Assume legend_top_left will place it somewhere where there is nothing else.
+ //derived().legend_left_; set by legend_top_left
+ //derived().legend_top_;
+ derived().legend_bottom_ = derived().legend_top_ + derived().legend_height_;
+ derived().legend_right_ = derived().legend_left_ + derived().legend_width_;
+ break;
case inside:
derived().outside_legend_on_ = false;
if (derived().legend_left_ == -1)
{ // Legend box position NOT been set by legend_top_left.
- // Default inside position is top left of plot window.
- derived().legend_left_ = derived().plot_left_;
- derived().legend_right_ = derived().plot_left_ + derived().legend_width_;
- derived().plot_left_ = derived().legend_right_;
- derived().legend_top_ = derived().plot_top_; // Level with top of plot window.
- if (derived().title_on_)
- {
- derived().legend_top_ += derived().title_font_size() * 2.; // below title.
- }
- derived().legend_bottom_ = derived().legend_top_ + derived().legend_height_;
- }
- else
- { // Legend position has been specified by legend_top_left.
+ // Default inside position is top left level with plot window.
+ derived().legend_left_ = derived().image_border_.width_ + derived().image_border_.margin_; // left image edge + space.
+ derived().plot_left_ += derived().legend_width_ + spacing; // Push plot window right same amount to make room,
+ derived().legend_right_ = derived().legend_left_ + derived().legend_width_;
+ derived().legend_top_ = derived().plot_top_; // Level with top of plot window.
+ derived().legend_bottom_ = derived().legend_top_ + derived().legend_height_;
+ }
+ else
+ { // Legend position has been specified by legend_top_left.
break;
- }
- break;
+ }
+ break;
// If outside then reserve space for legend by reducing plot window.
case outside_right: // Default legend position is outside_right,
// so that it isn't too close to the image edge or the plot window.
@@ -635,16 +648,13 @@
derived().legend_top_ = derived().plot_top_; // Level with top of plot window.
derived().legend_bottom_ = derived().legend_top_ + derived().legend_height_;
break;
- // TODO other positions untested.
case outside_left:
- derived().legend_left_ = derived().plot_left_ + spacing; // left edge + space.
- derived().plot_left_ += derived().legend_width_ + spacing; // Push plot window right to make room,
- // derived().legend_left_ += derived().y_label_font_size() * spacing;
+ derived().plot_left_ += derived().legend_width_ + spacing /2 ; // Push plot window right same amount to make room,
+ derived().legend_left_ = derived().image_border_.width_ + derived().image_border_.margin_; // left image edge + space.
derived().legend_right_ = derived().legend_left_ + derived().legend_width_;
derived().legend_top_ = derived().plot_top_; // Level with top of plot window.
- derived().legend_top_ += spacing;
derived().legend_bottom_ = derived().legend_top_ + derived().legend_height_;
- break;
+ break;
case outside_top:
// Centered.
derived().legend_left_ = derived().image.x_size() / 2. - derived().legend_width_ / 2; // Center.
@@ -656,12 +666,13 @@
break;
case outside_bottom:
// Centered.
+ derived().legend_bottom_ = derived().image.y_size();
+ derived().legend_bottom_ -= (derived().image_border_.width_ + derived().image_border_.margin_); // up
+ derived().legend_top_ = derived().legend_bottom_ - derived().legend_height_;
derived().legend_left_ = derived().image.x_size()/ 2. - derived().legend_width_ / 2; // Center.
derived().legend_right_ = derived().legend_left_ + derived().legend_width_;
- derived().plot_bottom_ -= derived().legend_height_;
- derived().plot_bottom_ -= spacing;
- derived().legend_top_ = derived().plot_bottom_;
- derived().legend_bottom_ = derived().legend_top_ + derived().legend_height_;
+ derived().plot_bottom_ = derived().legend_top_;
+ derived().plot_bottom_ -= 2 * spacing;
break;
} // switch
@@ -797,37 +808,40 @@
void draw_x_label()
{
- // color is set in constructor.
- //image.g(detail::PLOT_X_LABEL).style().stroke_color(black);
- // and using x_label_color(color)
+ // X-label color is set in constructor thus:
+ // image.g(detail::PLOT_X_LABEL).style().stroke_color(black);
+ // and changed using x_label_color(color);
std::string label = derived().x_label_info_.text(); // x_axis_ label, and optional units.
if (derived().x_axis_.label_units_on_ && (derived().x_units_info_.text() != ""))
{ // Append the units, if any, use providing brackets () if required.
label += derived().x_units_info_.text();
}
- // Simplest to start from the bottom of the image.
- // and move up to give enough space for the X-axis label.
- double y = derived().image.y_size(); // bottom edge of image.
- if (derived().image_border_.border_on_)
- {
- y -= derived().image_border_.width_; // Allow space for border.
- y -= derived().image_border_.margin_; // Allow a margin.
- y -= derived().x_axis_label_style_.font_size() / 2; // Allow a half font too.
+ double y = derived().plot_bottom_;
+ y += derived().x_ticks_.value_label_style_.font_size() * 2.; // Shift down to suit.
+ if (derived().x_ticks_.ticks_on_window_or_axis_ < 0)
+ { // Ticks & value labels below X-axis.
+ if (derived().x_ticks_.major_value_labels_side_ < 0)
+ { // Shift down to allow for any value labels.
+ y += derived().x_ticks_.label_max_space_;
+ }
+ if (derived().x_ticks_.down_ticks_on_)
+ { // Shift down for biggest of any ticks.
+ y += (std::max)(derived().x_ticks_.minor_tick_length_, derived().x_ticks_.major_tick_length_);
+ }
}
+
derived().image.g(PLOT_X_LABEL).push_back(new text_element(
( // x position relative to the x-axis which is middle of plot window.
derived().plot_right_ + derived().plot_left_) / 2, // x coordinate - middle.
- y, // Up from image bottom edge.
+ y, // Down from plot window.
label,
derived().x_label_info_.style(),
center_align, horizontal)
);
} // void draw_x_label()
- // TODO split into adjust_limit(double& x) and call twice?,
- // and TODO use to check 1-D for limit values too?
void adjust_limits(double& x, double& y)
{ // If value reaches limit of max, min, infinity,
// use the appropriate plot min or max.
@@ -1542,7 +1556,7 @@
// Bottom right is controlled by contents, so cannot set it.
if((x < 0) || (x > derived().image.x_size()) || (y < 0) || (y > derived().image.y_size()))
{
- throw std::runtime_error("Illegal legend box position.");
+ throw std::runtime_error("Legend box position outside image!");
}
derived().legend_left_ = x;
derived().legend_top_ = y;
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 2008-01-29 11:17:44 EST (Tue, 29 Jan 2008)
@@ -17,7 +17,7 @@
#include <exception>
#include <vector>
-#include "stylesheet.hpp" // TODO better to be called svg_stylesheet.hpp?
+//#include "stylesheet.hpp" // TODO better to be called svg_stylesheet.hpp?
#include "detail/svg_tag.hpp" // element class definitions.
#include "svg_style.hpp"
//#include "svg_fwd.hpp"
@@ -650,30 +650,30 @@
//// Load stylesheet
//// -------------------------------------------------------------
- void load_stylesheet(const std::string& input)
- { // Load a stylesheet into string css from an input file.
- std::ifstream if_str(input.c_str());
-
- if(if_str.fail())
- {
- throw std::runtime_error("Error opening file " + input);
- }
- if(!validate_stylesheet(if_str))
- {
- throw std::runtime_error("Error loading stylesheet!");
- }
-
- if_str.clear();
- if_str.seekg(0);
-
- std::string tmp;
- css = "";
-
- while(std::getline(if_str, tmp))
- {
- css += tmp;
- }
- } // svg& load_stylesheet
+ //void load_stylesheet(const std::string& input)
+ //{ // Load a stylesheet into string css from an input file.
+ // std::ifstream if_str(input.c_str());
+
+ // if(if_str.fail())
+ // {
+ // throw std::runtime_error("Error opening file " + input);
+ // }
+ // if(!validate_stylesheet(if_str))
+ // {
+ // throw std::runtime_error("Error loading stylesheet!");
+ // }
+
+ // if_str.clear();
+ // if_str.seekg(0);
+
+ // std::string tmp;
+ // css = "";
+
+ // while(std::getline(if_str, tmp))
+ // {
+ // css += tmp;
+ // }
+ //} // svg& load_stylesheet
}; // class svg
} // namespace 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 2008-01-29 11:17:44 EST (Tue, 29 Jan 2008)
@@ -392,18 +392,18 @@
// Calculate the number of chars of the longest value label.
x_ticks_.longest_label();
- double x_label_length_ = 0; // Work out the longest value label for X-Axis.
+ x_ticks_.label_max_space_ = 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
+ x_ticks_.label_max_space_ = 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_width_ * x_value_label_style_.font_size() * wh; // SVG chars.
+ x_ticks_.label_max_space_+= x_ticks_.label_max_length_ * 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_width_ * x_value_label_style_.font_size() * wh * sin45; // SVG 'chars'.
+ x_ticks_.label_max_space_+= x_ticks_.label_max_length_ * x_value_label_style_.font_size() * wh * sin45; // SVG 'chars'.
}
if (x_ticks_.major_value_labels_side_ != 0)
@@ -411,12 +411,12 @@
if ((x_ticks_.ticks_on_window_or_axis_ < 0) // on bottom of plot window.
&& (x_ticks_.major_value_labels_side_ < 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.
+ plot_bottom_ -= x_ticks_.label_max_space_; // Move up.
}
else if ((x_ticks_.ticks_on_window_or_axis_ > 0) //
&& (x_ticks_.major_value_labels_side_ > 0) ) // & x labels to top.
{ // Move top of plot window down to give space for x value labels.
- plot_top_ += x_label_length_; // Move down.
+ plot_top_ += x_ticks_.label_max_space_; // Move down.
}
else
{ // no labels on plot window (may be on mid-plot X-axis).
@@ -435,13 +435,13 @@
if ((x_axis_position_ == bottom) // All definitely > zero.
&& !(x_ticks_.ticks_on_window_or_axis_ < 0) ) // & not already at bottom.
{ // y_min_ > 0 so X-axis will not intersect Y-axis, so use plot window.
- plot_bottom_ -= x_label_length_; // Move up for the value labels.
+ plot_bottom_ -= x_ticks_.label_max_space_; // Move up for the value labels.
x_axis_.axis_ = plot_bottom_; // Put X-axis on bottom.
}
else if ((x_axis_position_ == top) // definitely < zero.
&& !(x_ticks_.ticks_on_window_or_axis_ > 0) ) // & not already at top.
{ // // y_max_ < 0 so X-axis will not intersect Y-axis, so use plot window.
- plot_top_ += x_label_length_; // Move down for labels.
+ plot_top_ += x_ticks_.label_max_space_; // Move down for labels.
x_axis_.axis_ = plot_top_; // Put X-axis on top.
}
else
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-29 11:17:44 EST (Tue, 29 Jan 2008)
@@ -450,25 +450,25 @@
y_ticks_.min_ = y_axis_.min_;
// Calculate the number of chars of the longest value labels.
- x_ticks_.longest_label(); // Updates label_max_width_
+ x_ticks_.longest_label(); // Updates label_max_length_
y_ticks_.longest_label();
// Check that labels won't collide and advise if they will.
// Change rotation to avoid collision?
- double y_label_length_ = 0.; // Width of y labels, depending on orientation.
+ y_ticks_.label_max_space_ = 0.; // Space for 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_ticks_.label_max_width_; // SVG units.
+ y_ticks_.label_max_space_ += y_ticks_.label_max_length_; // SVG units.
}
else if((y_ticks_.label_rotation_ == upward) || (y_ticks_.label_rotation_ == downward))
{ // Only need one char & 1 space width from Y-axis label.
- y_label_length_ += 2 * y_value_label_style_.font_size() * wh;
+ y_ticks_.label_max_space_ += 2 * y_value_label_style_.font_size() * wh;
}
else
{ // Assume some slope 45, so diagonally down from tick,
// and takes a bit less room.
- y_label_length_ = y_ticks_.label_max_width_ * sin45;
+ y_ticks_.label_max_space_ = y_ticks_.label_max_length_ * sin45;
}
if (y_ticks_.major_value_labels_side_ != 0)
@@ -476,12 +476,12 @@
if ((y_ticks_.ticks_on_window_or_axis_ < 0) // On left of plot window.
&& (y_ticks_.major_value_labels_side_ < 0) ) // & labels on left.
{ // Contract plot window left edge to right to make space for value labels on left.
- plot_left_ += y_label_length_;
+ plot_left_ += y_ticks_.label_max_space_;
}
else if ((y_ticks_.ticks_on_window_or_axis_ > 0) // On right of plot window.
&& (y_ticks_.major_value_labels_side_ > 0) ) // & labels to right.
{ // Contract plot window right to left to make space for value labels on right.
- plot_right_ -= y_label_length_;
+ plot_right_ -= y_ticks_.label_max_space_;
}
else
{ // y_ticks_.ticks_on_window_or_axis_ == 0
@@ -495,18 +495,18 @@
}
} // y_ticks_. major_value_labels_side
- double x_label_length_ = 0; // Work out the longest value label for X-Axis.
+ x_ticks_.label_max_space_ = 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; // 2 SVG chars
+ x_ticks_.label_max_space_ = 2 * x_value_label_style_.font_size() * wh; // 2 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_width_ ; // SVG chars.
+ x_ticks_.label_max_space_ += x_ticks_.label_max_length_ ; // SVG chars.
}
else
{ // Assume label is sloping, say 45, so * sin(45) = 0.707.
- x_label_length_+= x_ticks_.label_max_width_ * sin45; // SVG 'chars'.
+ x_ticks_.label_max_space_ += x_ticks_.label_max_length_ * sin45; // SVG 'chars'.
}
if (x_ticks_.major_value_labels_side_ != 0)
@@ -514,12 +514,12 @@
if ((x_ticks_.ticks_on_window_or_axis_ < 0) // on bottom of plot window.
&& (x_ticks_.major_value_labels_side_ < 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.
+ plot_bottom_ -= x_ticks_.label_max_space_; // Move up.
}
else if ((x_ticks_.ticks_on_window_or_axis_ > 0) //
&& (x_ticks_.major_value_labels_side_ > 0) ) // & x labels to top.
{ // Move top of plot window down to give space for x value labels.
- plot_top_ += x_label_length_; // Move down.
+ plot_top_ += x_ticks_.label_max_space_; // Move down.
}
else
{ // no labels on plot window (may be on mid-plot X-axis).
@@ -544,13 +544,13 @@
if ((x_axis_position_ == bottom) // All Y values definitely > zero.
&& !(x_ticks_.ticks_on_window_or_axis_ < 0) ) // & not already at bottom.
{ // y_min_ > 0 so X-axis will not intersect Y-axis, so use plot window.
- plot_bottom_ -= x_label_length_; // Move up for the value labels.
+ plot_bottom_ -= x_ticks_.label_max_space_; // Move up for the value labels.
x_axis_.axis_ = plot_bottom_; // Put X-axis on bottom.
}
else if ((x_axis_position_ == top) // All Y values definitely < zero.
&& !(x_ticks_.ticks_on_window_or_axis_ > 0) ) // & not already at top.
{ // // y_max_ < 0 so X-axis will not intersect Y-axis, so use plot window.
- plot_top_ += x_label_length_; // Move down for labels.
+ plot_top_ += x_ticks_.label_max_space_; // Move down for labels.
x_axis_.axis_ = plot_top_; // Put X-axis on top.
}
else
@@ -635,15 +635,29 @@
// Perhaps to left or right of plot window if X values do not include zero.
if (y_axis_.axis_line_on_)
- {
+ { // Want a Y-axis line.
if (y_axis_position_ == y_intersects_x)
{ // Draw the vertical Y-axis line at cartesian x = 0).
double ybottom = plot_bottom_;
- if (x_ticks_.down_ticks_on_ && (y_ticks_.ticks_on_window_or_axis_ != 0) && (x_axis_position_ == x_intersects_y) )
- { // Extend the vertical line down in lieu of longest tick.
- ybottom += (std::max)(x_ticks_.minor_tick_length_, x_ticks_.major_tick_length_);// Avoid macro max trap!
+ double ytop = plot_top_;
+ if (x_axis_position_ == x_intersects_y)
+ {
+ if (x_ticks_.down_ticks_on_)
+ {
+ if (x_ticks_.ticks_on_window_or_axis_ < 0) // at bottom
+ { // Extend the vertical line down in lieu of longest tick.
+ ybottom += (std::max)(x_ticks_.minor_tick_length_, x_ticks_.major_tick_length_);// Avoid macro max trap!
+ }
+ }
+ else if (x_ticks_.up_ticks_on_)
+ {
+ if (x_ticks_.ticks_on_window_or_axis_ > 0) // at top
+ { // Extend the vertical line up in lieu of longest tick.
+ ytop += (std::max)(x_ticks_.minor_tick_length_, x_ticks_.major_tick_length_);// Avoid macro max trap!
+ }
+ }
}
- image.g(detail::PLOT_Y_AXIS).line(x, plot_top_, x, ybottom);
+ image.g(detail::PLOT_Y_AXIS).line(x, ytop, x, ybottom);
// <g id="yAxis" stroke="rgb(0,0,0)"><line x1="70.5" y1="53" x2="70.5" y2="357"/>
if (y_ticks_.ticks_on_window_or_axis_ < 0) //(y_axis_position_ == left)
{ // Draw vertical line holding the ticks on the left of plot window.
@@ -734,22 +748,39 @@
} // draw_y_axis
void draw_y_label()
- { // Draw vertical y_axis_ label, and optional units.
+ { // Draw vertical y_axis_ label, and optional y units.
+ // Y-label color is set in constructor thus:
+ // image.g(detail::PLOT_Y_LABEL).style().stroke_color(black);
+ // and changed using y_label_color(color);
+
std::string label = y_label_info_.text();
if (y_axis_.label_units_on_ && (y_units_info_.text() != ""))
{ // Append the units, user must provide any ()s, if wanted.
label += y_units_info_.text() ;
}
- double y = image_border_.width_ + image_border_.margin_ + y_axis_label_style_.font_size();
+ double x = plot_left_;
+ x -= y_axis_label_style_.font_size() * 0.7; // Shift left to suit.
+ if (y_ticks_.ticks_on_window_or_axis_ < 0)
+ { // Ticks & value labels to left of Y-axis.
+ if (y_ticks_.down_ticks_on_)
+ { // Shift left for biggest of any ticks.
+ x -= (std::max)(y_ticks_.minor_tick_length_, y_ticks_.major_tick_length_);
+ }
+ if (y_ticks_.major_value_labels_side_ < 0)
+ { // Shift left to allow for any value labels.
+ x -= y_ticks_.label_max_space_;
+ }
+ }
+
image.g(detail::PLOT_Y_LABEL).push_back(new
- text_element(y,
- // shift over one char height to right from left edge of image.
+ text_element(x,
(plot_bottom_ + plot_top_) / 2., // center on the plot window.
label, // "Y-Axis" for example.
y_axis_label_style_,
center_align, // One might want it to left or right_align?
upward)); // Y label must be drawn vertically.
+
} // draw_y_label
void draw_y_major_tick(double value, path_element& tick_path, path_element& grid_path)
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-29 11:17:44 EST (Tue, 29 Jan 2008)
@@ -741,11 +741,12 @@
int value_precision_; // precision for tick value labels, usually 3 will suffice.
std::ios_base::fmtflags value_ioflags_; // IO formatting flags for the axis default std::ios::dec.
bool strip_e0s_; // If redundant zero, + and e are to be stripped.
- double label_max_width_; // width (in SVG units) of longest label on axis.
+ double label_max_length_; // width (in SVG units) of longest value label text on axis.
+ double label_max_space_; // Space needed for value label adjusted for rotation.
int ticks_on_window_or_axis_; // 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 -1 to left of plot window.
- // For Y-axis -1 = bottom, 0 = false, +1 = top. Default -1 below bottom of plot window.
+ // For Y-axis -1 = left, 0 = false, +1 = right. Default -1 to left of plot window.
+ // For X-axis -1 = bottom, 0 = false, +1 = top. Default -1 below bottom of plot window.
const text_style& value_label_style_;
ticks_labels_style(dim d = X,
@@ -791,7 +792,9 @@
value_ioflags_(std::ios::dec), // IO formatting flags for the axis.
// Note that ALL the flags are set, overwriting any defaults, so std::dec is wise.
strip_e0s_(true), // strip superflous zeros and signs.
- label_max_width_(0.), // width (estimated in SVG units) of longest label on axis.
+ label_max_length_(0.), // length (estimated in SVG units) of longest label on axis.
+ label_max_space_(0.), // Space (estimated in SVG units) of longest label on axis
+ // adjusted for rotation.
ticks_on_window_or_axis_(-1) // Value labels & ticks on the plot window
// rather than on X or Y-axis.
// Default -1 means left or bottom.
@@ -805,7 +808,6 @@
throw std::runtime_error("Axis ticks & labels range too small!" );
}
}
-
double label_length(double value)
{ // Find the length of label for a value.
@@ -828,7 +830,7 @@
} // double label_length
double longest_label()
- { // Update label_max_width_ with the longest value label as pixels,
+ { // Update label_max_length_ with the longest value label as pixels,
// return the count of digits etc.
if(major_value_labels_side_ != 0) // ! none
{ // Show values by the tick as "1.2" or "3.4e+000"...
@@ -869,12 +871,12 @@
}
}
} // for v
- label_max_width_ = longest;
+ label_max_length_ = longest;
return longest;
}
else
{
- label_max_width_ = 0;
+ label_max_length_ = 0;
return 0;
}
} // longest_label()
@@ -922,7 +924,7 @@
svg_color stroke_; // box line stroke color.
svg_color fill_; // box fill color.
double width_; // plot border rectangle width.
- double margin_; // Marginal (pixels) space around the box (nside or out).
+ double margin_; // Marginal (pixels) space around the box (inside or out).
bool border_on_; // Display the border.
bool fill_on_; // Color fill the box.
@@ -1006,12 +1008,6 @@
return *this; // Make chainable.
}
-
-
-
-
-
-
}; // class box_style
const std::string strip_e0s(std::string s);
Modified: sandbox/SOC/2007/visualization/libs/svg_plot/example/math_special_functions.cpp
==============================================================================
--- sandbox/SOC/2007/visualization/libs/svg_plot/example/math_special_functions.cpp (original)
+++ sandbox/SOC/2007/visualization/libs/svg_plot/example/math_special_functions.cpp 2008-01-29 11:17:44 EST (Tue, 29 Jan 2008)
@@ -18,7 +18,7 @@
# pragma warning (disable : 4503) // decorated name length exceeded, name was truncated
# pragma warning (disable : 4180) // qualifier applied to function type has no meaning; ignored
# pragma warning (disable : 4267) // conversion from 'size_t' to 'const unsigned int', possible loss of data
-# pragma warning (disable : 4172) // returning address of local variable or temporary
+//# pragma warning (disable : 4172) // returning address of local variable or temporary
#endif
#include <boost/math/special_functions.hpp>
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