Boost logo

Boost-Commit :

From: pbristow_at_[hidden]
Date: 2008-03-05 11:44:33


Author: pbristow
Date: 2008-03-05 11:44:32 EST (Wed, 05 Mar 2008)
New Revision: 43516
URL: http://svn.boost.org/trac/boost/changeset/43516

Log:
Changes to plot line to make area_fill work better. Examples in 2d_area_fill.cpp also enhanced.

area_fill(false) produces a black fill which is counter intuitive but dangerous to change svg_color constructor?
Text files modified:
   sandbox/SOC/2007/visualization/boost/svg_plot/detail/svg_tag.hpp | 1
   sandbox/SOC/2007/visualization/boost/svg_plot/svg_2d_plot.hpp | 82 +++++++++++++++-----------
   sandbox/SOC/2007/visualization/boost/svg_plot/svg_color.hpp | 9 ++
   sandbox/SOC/2007/visualization/boost/svg_plot/svg_style.hpp | 5
   sandbox/SOC/2007/visualization/libs/svg_plot/example/2d_area_fill.cpp | 124 ++++++++++++++++++++++++++-------------
   5 files changed, 137 insertions(+), 84 deletions(-)

Modified: sandbox/SOC/2007/visualization/boost/svg_plot/detail/svg_tag.hpp
==============================================================================
--- sandbox/SOC/2007/visualization/boost/svg_plot/detail/svg_tag.hpp (original)
+++ sandbox/SOC/2007/visualization/boost/svg_plot/detail/svg_tag.hpp 2008-03-05 11:44:32 EST (Wed, 05 Mar 2008)
@@ -1300,7 +1300,6 @@
         o_str << "\"";
 
         write_attributes(o_str); // id & clip_path
-
         style_info_.write(o_str); // fill, stroke, width...
 
         if(!fill)

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-03-05 11:44:32 EST (Wed, 05 Mar 2008)
@@ -14,6 +14,7 @@
 #ifdef _MSC_VER
 #pragma warning(push)
 # pragma warning (disable : 4800) // forcing value to bool 'true' or 'false' (performance warning)
+# pragma warning (disable : 4512) // assignment operator could not be generated
 #endif
 
 #include <boost/iterator/transform_iterator.hpp>
@@ -50,6 +51,11 @@
     // -----------------------------------------------------------------
     class svg_2d_plot_series
     {
+ //protected: // TODO this causes trouble.
+
+ friend svg_2d_plot_series;
+ friend void draw_straight_lines(const svg_2d_plot_series&);
+
     public:
       // 2-D Data series points to plot.
       std::multimap<double, double> series; // Normal 'OK to plot' data values.
@@ -63,6 +69,7 @@
       plot_point_style point_style_;
       plot_point_style limit_point_style_;
       plot_line_style line_style_;
+ public:
 
       template <class T>
       svg_2d_plot_series(T begin, T end, // of data series.
@@ -79,18 +86,19 @@
 
       { // Constructor.
         for(T i = begin; i != end; ++i)
- { // Sort into normal and limited series.
+ { // Sort data points into normal and limited series.
           if(detail::pair_is_limit(*i))
           { // Either x and/or y is at limit.
             series_limits.insert(*i);
           }
           else
- { // normal data values for both x and y.
+ { // Normal data values for both x and y.
             series.insert(*i);
           }
         }
       } // svg_2d_plot_series
 
+
       // Set functions for the plot series.
       svg_2d_plot_series& fill_color(const svg_color& col_)
       { // Point fill color.
@@ -125,6 +133,8 @@
       svg_2d_plot_series& area_fill(const svg_color& col_)
       {
         line_style_.area_fill_ = col_;
+ // Note that area_fill(true) will produce a *blank* color, and so NO FILL.
+ // area_fill(false) will produce the default non-blank color (black?).
         return *this;
       }
 
@@ -146,7 +156,7 @@
         return *this;
       }
 
- // Get functions for the plot series.
+ // Get functions for the plot series.
       plot_line_style line_style()
       {
         return line_style_;
@@ -192,6 +202,7 @@
     class svg_2d_plot : public detail::axis_plot_frame<svg_2d_plot>
     { // See also svg_1d_plot.hpp for 1-D version.
      friend void show_plot_settings(svg_2d_plot&);
+ friend svg_2d_plot_series;
 
     private:
       // Member data names conventionally end with _,
@@ -287,7 +298,7 @@
     public: // of class svg_2d_plot: public detail::axis_plot_frame<svg_2d_plot>
 
       svg_2d_plot() // Constructor, including all the very many default plot options,
- // some which use some or all of the class defaults.
+ // some of which use some or all of the class defaults.
         :
       // TODO check that *all* options are initialized here.
       // See documentation for default settings rationale.
@@ -384,7 +395,7 @@
         // Grids.
         // Default color & width for grid, used or not.
         image.g(PLOT_X_MAJOR_GRID).style().stroke_width(x_ticks_.major_grid_width_).stroke_color(svg_color(200, 220, 255));
- BOOST_ASSERT(image.g(PLOT_X_MAJOR_GRID).style().stroke_color() == svg_color(200, 220, 255));
+ // BOOST_ASSERT(image.g(PLOT_X_MAJOR_GRID).style().stroke_color() == svg_color(200, 220, 255));
         image.g(PLOT_X_MINOR_GRID).style().stroke_width(x_ticks_.minor_grid_width_).stroke_color(svg_color(200, 220, 255));
         image.g(PLOT_Y_MAJOR_GRID).style().stroke_width(y_ticks_.major_grid_width_).stroke_color(svg_color(200, 220, 255));
         image.g(PLOT_Y_MINOR_GRID).style().stroke_width(y_ticks_.minor_grid_width_).stroke_color(svg_color(200, 220, 255));
@@ -719,7 +730,7 @@
             image.g(detail::PLOT_Y_AXIS).line(plot_left_, plot_top_, plot_left_, plot_bottom_);
           }
           else if (y_axis_position_ == right)
- {// Draw on the lright of plot window.
+ {// Draw on the right of plot window.
             image.g(detail::PLOT_Y_AXIS).line(plot_right_, plot_top_, plot_right_, plot_bottom_);
           }
           else
@@ -836,32 +847,31 @@
         if((y < plot_top_ - 0.01) || (y > plot_bottom_ + 0.01))
           // Allow a bit extra to allow for round-off errors.
         { // tick value is way outside plot window, so nothing to do.
- // std::cout << y << std::endl;
           return;
         }
         double x_left(0.); // Left end of tick.
         double x_right(image.y_size()); // Right end of tick.
- if(y_ticks_.major_grid_on_)
- { // Draw horizontal major grid line.
- if(!plot_window_on_ != 0)
+ if(y_ticks_.major_grid_on_ == true)
+ { // Draw horizontal major Y grid line.
+ if(!plot_window_on_ == true)
           {
- if(y_ticks_.major_value_labels_side_ < 0)
+ if(y_ticks_.major_value_labels_side_ < 0) // left
             { // Start further right to give space for y axis value label.
               y -= y_value_label_style_.font_size() * text_margin_;
             }
 
- if(y_ticks_.left_ticks_on_)
- { // And similarly for left ticks.
+ if(y_ticks_.left_ticks_on_ == true)
+ { // And similarly space for left ticks.
               y -= y_ticks_.major_tick_length_;
             }
           }
           else
           { // plot_window_on_ to use full width of plot window.
- x_left = plot_left_ + plot_window_border_.width_; // Don't write over border.
+ x_left = plot_left_ + plot_window_border_.width_; // Don't write over either border.
             x_right = plot_right_ - plot_window_border_.width_;
- grid_path.M(x_left, y).L(x_right, y); // Horizontal grid line.
           }
- } // y_major_grid_on
+ grid_path.M(x_left, y).L(x_right, y); // Horizontal grid line.
+ } // y_major_grid_on
 
         // Draw major ticks & value label, if necessary.
         double y_tick_length = y_ticks_.major_tick_length_;
@@ -1067,11 +1077,14 @@
             x_right = plot_right_ - plot_window_border_.width_; // Ensure just *inside* window?
           }
           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.
+ { // Make sure that we are drawing inside the allowed plot window.
             // Note comparisons are 'upside-down' - y is increasing downwards!
             grid_path.M(x_left, y).L(x_right, y); // Draw grid line.
           }
- // TODO else just ignore outside plot window?
+ else
+ {
+ // Just ignore outside plot window
+ }
         } // y_minor_grid
 
         // Draw y minor ticks.
@@ -1120,13 +1133,13 @@
         g_element& g_ptr = image.g(detail::PLOT_DATA_LINES).g();
         g_ptr.clip_id(plot_window_clip_);
         g_ptr.style().stroke_color(series.line_style_.color_);
- g_ptr.style().fill_color(series.line_style_.area_fill_);
+ //g_ptr.style().fill_color(series.line_style_.area_fill_); // Now set in path below
         g_ptr.style().stroke_width(series.line_style_.width_);
         path_element& path = g_ptr.path();
         path.style().fill_color(series.line_style_.area_fill_);
 
         bool is_fill = !series.line_style_.area_fill_.blank;
- path.fill = is_fill; // Ensure includes a fill="none".
+ path.fill = is_fill; // Ensure includes a fill="none" if no fill.
 
         if(series.series.size() > 1)
         { // Need at least two points for a line ;-)
@@ -1136,21 +1149,21 @@
           // we first have to move from the X-axis (y = 0) to the first point,
           // and again at the end after the last point.
           prev_x = (*j).first;
- prev_y = 0.;
+ prev_y = 0.; // X-axis.
           transform_point(prev_x, prev_y);
           if(is_fill)
           { // Move to 1st point.
- path.style().fill_color(series.line_style_.area_fill_);
+ //path.style().fill_color(series.line_style_.area_fill_); // Duplicates so no longer needed?
             path.M(prev_x, prev_y);
           }
           transform_y(prev_y = (*j).second);
           if(is_fill)
- { // fill wanted.
- path.style().fill_color(series.line_style_.area_fill_); // TODO why again?
+ { // Area fill wanted.
+ // path.style().fill_color(series.line_style_.area_fill_); // Duplicates so no longer needed?
             path.L(prev_x, prev_y); // Line from X-axis to 1st point.
           }
           else
- { // fill == blank
+ { // Area fill == blank
             path.M(prev_x, prev_y);
           }
           ++j; // so now refers to 2nd point to plot.
@@ -1160,20 +1173,19 @@
             temp_x = (*j).first;
             temp_y = (*j).second;
             transform_point(temp_x, temp_y);
- path.L(temp_x, temp_y); // line to next point.
-
- if(is_fill)
- {
- path.M(temp_x, temp_y);
- }
+ path.L(temp_x, temp_y); // Line to next point.
+ //if(is_fill) // This seems to stop area-fill and is not needed anyway.
+ //{
+ // //path.M(temp_x, temp_y);
+ //}
             prev_x = temp_x;
             prev_y = temp_y;
- } // for j
+ } // for j'th point
 
           if(is_fill)
- { // fill wanted.
- transform_y(temp_y = 0.); // X-axis line.
- path.L(temp_x, temp_y).z(); // Close path with Z to terminate line.
+ { // Area fill wanted.
+ transform_y(temp_y = 0.); // X-axis line coordinate.
+ path.L(temp_x, temp_y).z(); // Draw line to X-axis & closepath with Z.
           }
         }
       } // draw_straight_lines

Modified: sandbox/SOC/2007/visualization/boost/svg_plot/svg_color.hpp
==============================================================================
--- sandbox/SOC/2007/visualization/boost/svg_plot/svg_color.hpp (original)
+++ sandbox/SOC/2007/visualization/boost/svg_plot/svg_color.hpp 2008-03-05 11:44:32 EST (Wed, 05 Mar 2008)
@@ -95,11 +95,16 @@
         b = (unsigned char)(( blue > 255 ) ? 255 : blue);
     }
 
- svg_color(bool is) : blank(is)
+ svg_color(bool is_blank) : blank(is_blank)
     { // Permits blank (=true) as a (non-)color.
+ // svg_color(true) returns blank (and color value as below).
+ // svg_color(false) returns color values below and NOT blank.
+ // So plot.area_fill(true) will be a blank == no fill!
+ // So plot.area_fill(false) will be a default(black) fill!
+ // This is somewhat counter-intuitive!
       r = 0; // Safer to assign *some* value to rgb? zero, or 255?
       g = 0; // rather than leaving them random?
- b = 0;
+ b = 0; // Default 'blank' color 0,0,0 is black.
     }
 
     svg_color(svg_color_constant col) : blank(false)

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-03-05 11:44:32 EST (Wed, 05 Mar 2008)
@@ -1,7 +1,7 @@
 // svg_style.hpp
 
 // Copyright Jacob Voytko 2007
-// Copyright Paul A. Bristow 2007
+// Copyright Paul A. Bristow 2008
 // Use, modification and distribution are subject to the
 // Boost Software License, Version 1.0.
 // (See accompanying file LICENSE_1_0.txt
@@ -13,7 +13,6 @@
 // svg style information is fill, stroke, width, line & bezier curve.
 // This module provides struct plot_point_style & struct plot_line_style
 // and class svg_style holding the styles.
-
 // http://www.w3.org/TR/SVG11/styling.html
 
 #include "svg_color.hpp"
@@ -819,7 +818,7 @@
       { // Range too small to display.
         throw std::runtime_error("Axis ticks & labels range too small!" );
       }
- }
+ } // ticks_labels_style constructor.
 
   double label_length(double value)
   { // Find the length of label for a value.

Modified: sandbox/SOC/2007/visualization/libs/svg_plot/example/2d_area_fill.cpp
==============================================================================
--- sandbox/SOC/2007/visualization/libs/svg_plot/example/2d_area_fill.cpp (original)
+++ sandbox/SOC/2007/visualization/libs/svg_plot/example/2d_area_fill.cpp 2008-03-05 11:44:32 EST (Wed, 05 Mar 2008)
@@ -4,36 +4,47 @@
 // For more information, see http://www.boost.org
 // -----------------------------------------------------------------
 
-#ifdef _MSC_VER
-# pragma warning (disable : 4180) // qualifier applied to function type has no meaning; ignored
-# pragma warning (disable : 4503) // decorated name length exceeded, name was truncated
-# pragma warning (disable : 4512) // assignment operator could not be generated
-# pragma warning (disable : 4224) // nonstandard extension used : formal parameter 'function_ptr' was previously defined as a type
-# pragma warning (disable : 4127) // conditional expression is constant
-#endif
-
 #include <boost/svg_plot/svg_2d_plot.hpp>
-#include <map>
-#include <cmath>
+ using namespace boost::svg; // Needed to get svg colors and others.
+ using boost::svg::svg_2d_plot;
 
-using std::map;
-using namespace boost::svg;
+#include <map>
+ using std::map;
+#include <cmath>
+ using ::sin;
+ using ::cos;
+ using ::tan;
 
-double f(double x)
+double my_sin(double x)
 {
         return 50. * sin(x);
 }
 
+double my_cos(double x)
+{
+ return 50. * cos(x);
+}
+
+
+double my_tan(double x)
+{
+ return 50. * tan(x);
+}
+
 int main()
 {
- map<double, double> data1;
+ map<double, double> data_sin;
+ map<double, double> data_cos;
+ map<double, double> data_tan;
         
- double inter = 3.14159265 / 8.;
+ double inter = 3.14159265 / 8.; // 16 points per cycle of 2 pi.
 
- for(double i=0; i<=10.; i+=inter)
- {
- data1[i] = f(i);
- }
+ for(double i = 0; i <= 10.; i+=inter)
+ { // Just 10 data points for each function.
+ data_sin[i] = my_sin(i);
+ data_cos[i] = my_cos(i);
+ data_tan[i] = my_tan(i);
+ } // for
 
         svg_2d_plot my_plot;
 
@@ -41,29 +52,32 @@
         my_plot.image_size(700, 500)
                .x_range(-1, 10)
                .y_range(-75, 75);
-
 
         // Text settings.
- my_plot.title("Plot of 50 * sin(x)")
- .title_font_size(29)
- .x_label("X Axis Units")
- .y_major_value_labels_side(true)
- .y_major_grid_on(true);
-
+ my_plot.title("Plot of 50 * sin(x), cos(x) and tan(x)")
+ .title_font_size(20)
+ .x_label("x")
+ .y_label("50 * f(x)")
+ .x_major_value_labels_side(bottom)
+ .y_major_value_labels_side(left)
+ .x_major_grid_on(true)
+ .y_major_grid_on(true)
+ .x_major_grid_color(cyan)
+ .y_major_grid_color(cyan)
+ ;
         // Commands.
         my_plot.plot_window_on(true)
                .x_label_on(true)
- .x_major_value_labels_side(true);
+ ;
         
         // Color settings.
- my_plot.background_color(svg_color(67, 111, 69))
- .legend_background_color(svg_color(207, 202,167))
- .legend_border_color(svg_color(102, 102, 84))
- .plot_background_color(svg_color(136, 188, 126))
- .title_color(white)
- .y_major_grid_color(black);
-
- //X axis settings.
+ my_plot.background_color(whitesmoke)
+ .legend_background_color(lightyellow)
+ .legend_border_color(yellow)
+ .plot_background_color(ghostwhite)
+ .title_color(red)
+ ;
+ // X axis settings.
         my_plot.x_major_interval(2)
                .x_major_tick_length(14)
                .x_major_tick_width(1)
@@ -71,16 +85,40 @@
                .x_minor_tick_width(1)
                .x_num_minor_ticks(3)
         
- //Y axis settings.
+ // Y axis settings.
                .y_major_interval(25)
                .y_num_minor_ticks(5);
-
- //legend settings
- my_plot.legend_title_font_size(15);
         
- my_plot.plot(data1, "Sqrt(x)").area_fill(red);
-
- my_plot.write("./2d_area_fill.svg");
+ //svg_2d_plot_series& s1 = my_plot.plot(data1, "Sqrt(x)").area_fill(red);
+ // my_plot.write("./2d_area_fill.svg");
+ // std::cout << s1.area_fill() << std::endl;
+
+ svg_2d_plot_series& s_sin = my_plot.plot(data_sin, "sin(x)").area_fill(red);
+ std::cout << s_sin.area_fill() << std::endl;
+ svg_2d_plot_series& s_cos = my_plot.plot(data_cos, "cos(x)").area_fill(blue).shape(square);
+ // svg_2d_plot_series& s_cos = my_plot.plot(data_cos, "cos(x)").area_fill(true).shape(square);
+ // Note that svg_color(bool = true) returns a non-color blank, so no fill.
+ std::cout << s_cos.area_fill() << std::endl;
+ svg_2d_plot_series& s_tan = my_plot.plot(data_tan, "tan(x)").shape(cone);
+ std::cout << s_tan.area_fill() << std::endl;
+ my_plot.write("./2d_no_area_fill.svg");
 
         return 0;
-}
+} // int main()
+
+/*
+
+Output:
+
+Compiling...
+2d_area_fill.cpp
+Linking...
+Embedding manifest...
+Autorun "j:\Cpp\SVG\debug\2d_area_fill.exe"
+RGB(255,0,0)
+blank
+blank
+Build Time 0:03
+
+
+*/


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