Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r51425 - in sandbox/SOC/2007/visualization/boost/svg_plot: . detail
From: pbristow_at_[hidden]
Date: 2009-02-24 05:34:04


Author: pbristow
Date: 2009-02-24 05:34:04 EST (Tue, 24 Feb 2009)
New Revision: 51425
URL: http://svn.boost.org/trac/boost/changeset/51425

Log:
Added prefix, separator and suffix, and also series_count get functions.
Text files modified:
   sandbox/SOC/2007/visualization/boost/svg_plot/detail/axis_plot_frame.hpp | 30 ++++++++++++++++++------------
   sandbox/SOC/2007/visualization/boost/svg_plot/svg_1d_plot.hpp | 24 ++++++++++++++++++------
   sandbox/SOC/2007/visualization/boost/svg_plot/svg_style.hpp | 18 +++++++++++++++---
   3 files changed, 51 insertions(+), 21 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 2009-02-24 05:34:04 EST (Tue, 24 Feb 2009)
@@ -1119,10 +1119,16 @@
 
           void draw_plot_point_values(double x, double y, g_element& x_g_ptr, g_element& y_g_ptr, const value_style& x_sty, const value_style& y_sty, double vx, double vy)
           { //! Write the \b pair of data point's X and Y values as a string, for example: "1.23, 3.45".
+ //! X value_style is used to provide the prefix and separator, and Y value_style to provide the suffix.
+ // draw_plot_point_values is only when both x and Y pairs are wanted.
             using std::string;
             using std::stringstream;
             std::string label_xv = sv(vx, x_sty); //! Also strip unnecessary e, + and leading exponent zeros, if required.
             std::string label_yv = sv(vy, y_sty);
+ if (x_sty.prefix_ != "")
+ { // Want a prefix like "["
+ label_xv = x_sty.prefix_ + label_xv;
+ }
             std::string label_xu;
             std::string label_yu;
             std::string label_xdf;
@@ -1198,10 +1204,6 @@
             // value and uncertainty, and degrees of freedom estimate.
             // So the coding complexity is judged with it (even if it may not always work right yet ;-)
 
- string prefix = "[";
- string separator = ""; // or = ", "; // between x and y, if any (none if only X or only Y, or Y below X)
- string suffix = "]";
-
             // Unclear how to get this uncertainty information into this function,
             // so these are purely imaginary for now.
             // Might template so can use an uncertain type instead of double?
@@ -1212,15 +1214,14 @@
 
             // Tasteless colors and font changes are purely proof of concept.
 
- int fx = static_cast<int>(y_sty.values_text_style_.font_size() * 0.8);
+ int fx = static_cast<int>(y_sty.values_text_style_.font_size() * 0.8);
            // X value (and optional uncertainty & df).
             text_element& t = x_g_ptr.text(x, y, label_xv, x_sty.values_text_style_, al, rot);
            // Optionally, show uncertainty as 95% confidence plus minus: 2.1 +-0.012 (23)
- // TODO comma separator ? might want inside brackets [], or another separator?
 
- string pm = "&#x00A0;&#x00B1;"; // Unicode space plusminus glyph.
+ string pm = "&#x00A0;&#x00B1;"; //! Unicode space plusminus glyph.
             // Spaces seem to get lost, so use 00A0 as an explicit space glyph.
- // Layout seems to vary with font Times New Roman leaves no space after.
+ // Layout seems to vary with font - Times New Roman leaves no space after.
             if (x_sty.plusminus_on_)
             { // Uncertainty estimate usually 95% confidence interval + or - 2 standard deviation.
               label_xu = sv(ux, x_sty, true);
@@ -1234,17 +1235,17 @@
               //label.flags(sty.value_ioflags_); // Leave at default.
               label << "&#x00A0;(" << dfx << ")"; // "123.5"
               label_xdf = label.str();
- t.tspan(label_xdf + separator).fill_color(brown).font_size(fx);
+ t.tspan(label_xdf).fill_color(brown).font_size(fx);
             }
- // if there is a separator, put values on the same line, else as below put below the marker.
+ // If there is a separator, put values on the same line, else as below put below the marker.
             double line = 0.0;
- if (separator == "")
+ if (x_sty.separator_ == "")
             {
               line = y_sty.values_text_style_.font_size() * 2.2; // Put Y value on 'newline' below point marker.
             }
             else
             {
- t.tspan(separator).fill_color(brown).font_size(fx);
+ t.tspan(x_sty.separator_).fill_color(brown).font_size(fx);
             }
 
             // Problem here if orientation is changed?
@@ -1268,6 +1269,11 @@
               label_ydf = label.str();
               ty.tspan(label_ydf).fill_color(lime).font_size(fy);
             }
+ if (y_sty.prefix_ != "")
+ { // Want a suffix like "]"
+ ty.tspan(y_sty.suffix_).fill_color(lime).font_size(fy);
+ }
+
           } // void draw_plot_point_values(double x, double y, g_element& g_ptr, double value)
 
           void clear_all()

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 2009-02-24 05:34:04 EST (Tue, 24 Feb 2009)
@@ -73,13 +73,13 @@
 */
 
 public:
- std::vector<double> series; // Normal 'OK to plot' data values.
- std::vector<double> series_limits; // 'limit' values: too big, too small or NaN.
+ std::vector<double> series; //<! Normal 'OK to plot' data values.
+ std::vector<double> series_limits; //!< 'limit' values: too big, too small or NaN.
 
- std::string title_; // title of data series (to show on legend).
- plot_point_style point_style_; // circle, square...
- plot_point_style limit_point_style_; // Default is cone pointing down.
- plot_line_style line_style_; // No line style for 1-D, only for 2-D.
+ std::string title_; //!< title of data series (to show on legend).
+ plot_point_style point_style_; //!< circle, square...
+ plot_point_style limit_point_style_; //!< Default is cone pointing down.
+ plot_line_style line_style_; //!< No line style for 1-D, only for 2-D.
 
   // Constructor svg_1d_plot_series.
   template <class T> // T an STL container: array, vector<double>, set, map ...
@@ -108,6 +108,8 @@
   double line_width();
   bool line_on();
   bool bezier_on();
+ size_t series_count();
+ size_t series_limits_count();
 
 }; // class svg_1d_plot_series
 
@@ -224,6 +226,16 @@
   return line_style_.bezier_on_;
 }
 
+size_t svg_1d_plot_series::series_count()
+{ //! Number of normal 'OK to plot' data values in data series.
+ return series.size();
+}
+
+size_t svg_1d_plot_series::series_limits_count()
+{ //! Number of 'at limit' values: too big, too small or NaN data values in data series.
+ return series_limits.size();
+}
+
 // End Definitions of svg_plot_series Public Member Functions.
 
 class svg_1d_plot : public detail::axis_plot_frame<svg_1d_plot>

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 2009-02-24 05:34:04 EST (Tue, 24 Feb 2009)
@@ -528,6 +528,11 @@
      \brief Data series point value label information, text, color, orientation, (uncertainty & df).
      \details For example, to output: 5.123 +- 0.01 (19).
      Uncertainty and degrees of freedom estimate not yet implemented.
+ Prefix, separator and suffix allow X and Y values to be together on one line like
+ [1.23+- 0.01 (3), 4.56 +-0.2 (10)]
+ Used in draw_plot_point_values (note plural) where X value_style is used
+ to provide the prefix and separator, and Y value_style to provide the suffix.
+ Prefix, separator and suffix are ignored when X or Y are shown separately using draw_plot_point_value.
   */
 public:
   //private: // ??
@@ -544,11 +549,16 @@
       http://en.wikipedia.org/wiki/Plus-minus_sign
     */
   bool df_on_; //!< If a degrees of freedom estimate is to be appended.
+ std::string prefix_; //!< Prefix to data point value, default none, but typically "[".
+ std::string separator_; //!< Separator between x and y values, if both on same line (none if only X or only Y, or Y below X).
+ std::string suffix_; //!< Suffix to data point value, default none, but typically "]".
+
   public:
     value_style(); //!< Default style for a data point value label.
     value_style( //!< Set style for a data point value label.
       rotate_style r, int p, std::ios_base::fmtflags f, bool s,
- text_style ts, const svg_color& scol /* = black */, svg_color fcol, bool pm /*= false*/, bool df /*= false*/);
+ text_style ts, const svg_color& scol /* = black */, svg_color fcol, bool pm /*= false*/, bool df /*= false*/,
+ std::string pre /* = "" */, std::string sep /* = ", " */, std::string suf /* = "" */);
 
 }; // class value_style
 
@@ -572,10 +582,12 @@
     }
 
     value_style::value_style(rotate_style r, int p, std::ios_base::fmtflags f, bool s,
- text_style ts, const svg_color& scol = black, svg_color fcol = black, bool pm = false, bool df = false)
+ text_style ts, const svg_color& scol = black, svg_color fcol = black, bool pm = false, bool df = false,
+ std::string pre = "", std::string sep = ", ", std::string suf = "")
     :
     value_label_rotation_(r), value_precision_(p), value_ioflags_(f), strip_e0s_(s),
- values_text_style_(ts), stroke_color_(scol), fill_color_(fcol), plusminus_on_(pm), df_on_(df)
+ values_text_style_(ts), stroke_color_(scol), fill_color_(fcol), plusminus_on_(pm), df_on_(df),
+ prefix_(pre), separator_(sep), suffix_(suf)
     { // Constructor.
     }
 


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