Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r51795 - in sandbox/SOC/2007/visualization/boost/svg_plot: . detail
From: pbristow_at_[hidden]
Date: 2009-03-16 13:23:17


Author: pbristow
Date: 2009-03-16 13:23:16 EDT (Mon, 16 Mar 2009)
New Revision: 51795
URL: http://svn.boost.org/trac/boost/changeset/51795

Log:
Lines and curves added (but not ideal for adding quadratic curves from 3 points as does not pass through the control point).
Text files modified:
   sandbox/SOC/2007/visualization/boost/svg_plot/detail/axis_plot_frame.hpp | 82 +++++++++++++++++++++++++++++++--------
   sandbox/SOC/2007/visualization/boost/svg_plot/detail/svg_tag.hpp | 71 +++++++++++++++++++++++++++++++---
   sandbox/SOC/2007/visualization/boost/svg_plot/svg_2d_plot.hpp | 1
   3 files changed, 129 insertions(+), 25 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-03-16 13:23:16 EDT (Mon, 16 Mar 2009)
@@ -119,7 +119,7 @@
         // void clear_plot_background();
         // void clear_grids();
         void transform_point(double& x, double& y)
- { //! Scale & shift both X & Y to graph coordinates.
+ { //! Scale & shift both X & Y to graph Cartesian coordinates.
           x = derived().x_scale_ * x + derived().x_shift_;
           y = derived().y_scale_ * y + derived().y_shift_;
           adjust_limits(x, y); // In case either hits max, min, infinity or NaN.
@@ -1760,7 +1760,11 @@
           svg_color limit_color();
           Derived& limit_fill_color(const svg_color&);
           svg_color limit_fill_color();
- Derived& draw_note(double x, double y, std::string note, text_style& tsty = no_style, align_style al = center_align, rotate_style rot = horizontal, const svg_color& = black);
+ Derived& draw_note(double x, double y, std::string note, rotate_style rot = horizontal, align_style al = center_align, const svg_color& = black, text_style& tsty = no_style);
+ Derived& draw_line(double x1, double y1, double x2, double y2, const svg_color& col = black);
+ Derived& draw_plot_line(double x1, double y1, double x2, double y2, const svg_color& col = black);
+ Derived& draw_plot_curve(double x1, double y1, double x2, double y2, double x3, double y3,const svg_color& col = black);
+
 
           //// Stylesheet.
           // Removed for now to avoid compile warning in spirit.
@@ -3757,7 +3761,7 @@
         }
 
         template <class Derived>
- Derived& axis_plot_frame<Derived>::draw_note(double x, double y, std::string note, text_style& tsty/* = no_style*/, align_style al/* = center_align*/, rotate_style rot /*= horizontal*/, const svg_color& col)
+ Derived& axis_plot_frame<Derived>::draw_note(double x, double y, std::string note, rotate_style rot /*= horizontal*/, align_style al/* = center_align*/, const svg_color& col /* black */, text_style& tsty/* = no_style*/)
         { /*! \brief Annotate plot with a text string (perhaps including Unicode), putting note at SVG Coordinates X, Y.
             \details Defaults color black, rotation horizontal and align = center_align
             Using center_align is recommended as it will ensure that will center correctly
@@ -3765,26 +3769,68 @@
             for example Greek or math symbols, taking about 6 characters per symbol)
             because the render engine does the centering.
           */
-
- // g_element* g_ptr = &(derived().image.g(detail::PLOT_NOTES));
- g_element* g = &(derived()).image.g(); // New group
- g->style().fill_color(col);
- g->push_back(new text_element(x, y, note, tsty, al, rot));
-
- //g_ptr->style().fill_color(red);
- //g_ptr->push_back(new text_element(x, y, note, tsty, al, rot));
- //derived().image.g(detail::PLOT_NOTES).text(x, y,
- //gptr.text(x, y,
- // note, // string
- // tsty, // no_style,
- // al, //center_align,
- // rot); // horizontal);
-
+ g_element* g = &(derived()).image.g(); // New group.
+ g->style().fill_color(col); // Set its color
+ g->push_back(new text_element(x, y, note, tsty, al, rot)); // Add to document image.
           // No checks on X or Y - leave to SVG to not draw outside image.
           // Could warn if X and/or Y outside - but even if OK, then text could still stray outside image.
           return derived();
         } // void draw_note()
 
+ template <class Derived>
+ Derived& axis_plot_frame<Derived>::draw_line(double x1, double y1, double x2, double y2, const svg_color& col /* black */)
+ { /*! \brief Annotate plot with a line from SVG Coordinates X1, Y1 to X2, Y2.
+ \details Default color black.
+ */
+ g_element* g = &(derived()).image.g(); // New group.
+ g->style().stroke_color(col);
+ //g->style().width(w); // todo
+ g->push_back(new line_element(x1, y1, x2, y2));
+ // No checks on X or Y - leave to SVG to not draw outside image.
+ // Could warn if X and/or Y outside ?
+ return derived();
+ } // void draw_line()
+
+ template <class Derived>
+ Derived& axis_plot_frame<Derived>::draw_plot_line(double x1, double y1, double x2, double y2, const svg_color& col /* black */)
+ { /*! \brief Annotate plot with a line from user's Cartesian Coordinates X1, Y1 to X2, Y2.
+ \details For example, -10, -10, +10, +10, Default color black.
+ */
+ derived().calculate_plot_window(); // To ensure the scale and shift are setup for transform.
+ // It would be better to store the line (and curve and text) information like plot data series to
+ // ensure that transform works correctly.
+ // This assumes that the notes, lines and curves are the last item before the write.
+ transform_point(x1, y1);
+ transform_point(x2, y2);
+ g_element* g = &(derived()).image.g(); // New group.
+ g->style().stroke_color(col);
+ g->push_back(new line_element(x1, y1, x2, y2));
+ // No checks on X or Y - leave to SVG to not draw outside image.
+ // Actually we want to use clip_path for the plot area.
+ // Could warn if X and/or Y outside ?
+ return derived();
+ } // void draw_plot_line()
+
+ template <class Derived>
+ Derived& axis_plot_frame<Derived>::draw_plot_curve(double x1, double y1, double x2, double y2, double x3, double y3, const svg_color& col /* black */)
+ { /*! \brief Annotate plot with a line from user's Cartesian Coordinates X1, Y1 via X2, Y2 to X3, Y3.
+ \details For example, -10, -10, +10, +10, Default color black.
+ */
+ derived().calculate_plot_window(); // To ensure the scale and shift are setup for transform.
+ // It would be better to store the line (and curve and text) information like plot data series to
+ // ensure that transform works correctly.
+ // This assumes that the notes, lines and curves are the last item before the write.
+ transform_point(x1, y1);
+ transform_point(x2, y2);
+ transform_point(x3, y3);
+ g_element* g = &(derived()).image.g(); // New group.
+ g->style().stroke_color(col);
+ g->push_back(new qurve_element(x1, y1, x2, y2, x3, y3));
+ // No checks on X or Y - leave to SVG to not draw outside image.
+ // Actually we want to use clip_path for the plot area.
+ // Could warn if X and/or Y outside ?
+ return derived();
+ } // void draw_plot_curve
 
       } // detail
     } // svg

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 2009-03-16 13:23:16 EDT (Mon, 16 Mar 2009)
@@ -220,17 +220,19 @@
   // Reminder: Within a literal C string, \" is needed to output a " ;-)
 
   // -----------------------------------------------------------------
- // Represents a line
+ // Represents a straight line
   // -----------------------------------------------------------------
   class line_element: public svg_element
   { /*! \class boost::svg::line_element
- \brief Line from (x1, x2) to (y1, y2).
+ \brief Line from (x1, y1) to (x2, y2).
+ /details Straight line from SVG location (x1, y1) to (x2, y2).
+
     */
   private:
- double x1_; //! Line from (x1_, x2_) to (y1_, y2_)
- double x2_; //! Line from (x1_, x2_) to (y1_, y2_)
- double y1_; //! Line from (x1_, x2_) to (y1_, y2_)
- double y2_; //! Line from (x1_, x2_) to (y1_, y2_)
+ double x1_; //!< Line from (x1_, x2_) to (y1_, y2_)
+ double x2_; //!< Line from (x1_, x2_) to (y1_, y2_)
+ double y1_; //!< Line from (x1_, x2_) to (y1_, y2_)
+ double y2_; //!< Line from (x1_, x2_) to (y1_, y2_)
 
   public:
     line_element(double x1, double y1, double x2, double y2)
@@ -250,13 +252,68 @@
     }
 
     void write(std::ostream& rhs)
- { //! output line from (x1_, x2_) to (y1_, y2_)
+ { //! output line from (x1_, y1_) to (x2_, y2_)
+ //! \brief Write XML SVG command to draw a straight line.
       //! \details \verbatim Example: <line x1="5" y1="185" x2="340" y2="185"/> \endverbatim
       rhs << "<line x1=\"" << x1_ << "\" y1=\"" << y1_
           << "\" x2=\"" << x2_ << "\" y2=\"" << y2_ << "\"/>";
     }
   }; // class line_element
 
+ // Represents a curve (quadratic)
+ class qurve_element: public svg_element
+ { /*! \class boost::svg::qurve_element
+ \brief Quadratic Bezier curved line from (x1, y1) control point (x2, y2) to (x3, y3).
+ \details Note x2 is the Bezier control point - the curve will \b not pass thru this point.
+ */
+ private:
+ double x1_; //!< Quadratic curved line from (x1_, y1_) control point (x2_, y2_) to (y3_, y3_)
+ double x2_; //!< Quadratic curved line from (x1_, y1_) control point (x2_, y2_) to (y3_, y3_)
+ double y1_; //!< Quadratic curved line from (x1_, y1_) control point (x2_, y2_) to (y3_, y3_)
+ double y2_; //!< Quadratic curved line from (x1_, y1_) control point (x2_, y2_) to (y3_, y3_)
+ double x3_; //!< Quadratic curved line from (x1_, y1_) control point (x2_, y2_) to (y3_, y3_)
+ double y3_; //!< Quadratic curved line from (x1_, y1_) control point (x2_, y2_) to (y3_, y3_)
+
+ public:
+ // bool fill; now inherited from parent svg class.
+ qurve_element(double x1, double y1, double x2, double y2, double x3, double y3)
+ : x1_(x1), y1_(y1), x2_(x2), y2_(y2), x3_(x3), y3_(y3)
+ {
+ }
+
+ qurve_element(double x1, double y1,
+ double x2, double y2, // Control point - will not pass thru this point.
+ double x3, double y3,
+ const svg_style& style_info,
+ const std::string& id_name="",
+ const std::string& class_name="",
+ const std::string& clip_name = "")
+ : x1_(x1), y1_(y1), x2_(x2), y2_(y2), x3_(x3), y3_(y3),
+ svg_element(style_info, id_name, class_name, clip_name)
+ {
+ }
+
+ void write(std::ostream& o_str)
+ { /*! output quadratic curved line from (x1_, y1_) control point (x2_, y2_) to (x3_, y3_)
+ \details
+ \verbatim Example:
+ \endverbatim
+ */
+ o_str << "<path d=\"M" << x1_ << "," << y1_
+ << " Q" << x2_ << "," << y2_ << " " // Control point - will not pass thru this point.
+ //<< x1_ << "," << y1_ << " "
+ //<< x2_ << "," << y2_ << " "
+ << x3_ << "," << y3_
+ <<"\"";
+ if(style_info_.fill_on() == false)
+ {
+ o_str << " fill = \"none\"";
+ }
+ o_str<<"/>";
+ // Perhaps
+ }
+ }; // class qurve_element
+
   class rect_element : public svg_element
   { /*! \class boost::svg::rect_element
         \brief Rectangle from top left coordinate, width and height.

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 2009-03-16 13:23:16 EDT (Mon, 16 Mar 2009)
@@ -615,6 +615,7 @@
       void transform_pair(std::pair<double, double>& pt)
       { //! Transform both x and y from Cartesian to SVG coordinates.
         //! SVG image is 0, 0 at top left, Cartesian at bottom left.
+ // scale and shift are set in calculate_plot_window().
         transform_point(pt.first, pt.second);
       }
       void calculate_plot_window()


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