Boost logo

Boost-Commit :

From: JakeVoytko_at_[hidden]
Date: 2007-10-17 00:55:11


Author: jakevoytko
Date: 2007-10-17 00:55:10 EDT (Wed, 17 Oct 2007)
New Revision: 40105
URL: http://svn.boost.org/trac/boost/changeset/40105

Log:
Added labels for y axis information
Text files modified:
   sandbox/SOC/2007/visualization/boost/svg_plot/svg_2d_plot.hpp | 52 ++++++++++++++++++++++++++-------------
   sandbox/SOC/2007/visualization/boost/svg_plot/svg_test.cpp | 31 +++++++++++------------
   2 files changed, 49 insertions(+), 34 deletions(-)

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 2007-10-17 00:55:10 EDT (Wed, 17 Oct 2007)
@@ -115,6 +115,7 @@
 
     text_element title_info;
     text_element x_label_info;
+ text_element y_label_info;
 
     // border information for the plot window. Initially will be set to the width
     // and height of the graph
@@ -154,9 +155,6 @@
     // where we will be storing the data points for transformation
     std::vector<svg_2d_plot_series> series;
 
- // strings having to do with labels
- std::string y_label;
-
     std::string plot_window_clip;
 
     // axis information
@@ -169,7 +167,6 @@
 
     bool use_y_label;
     bool use_y_major_labels;
-
     
     void _draw_y_minor_ticks(double j, path_element& tick_path,
                              path_element& grid_path)
@@ -268,7 +265,7 @@
             
             tick_path.M(x1, y1).L(x2, y1);
 
- if(use_y_major_labels && i != 0)
+ if(use_y_major_labels)
             {
                 std::stringstream fmt;
                 fmt<<i;
@@ -283,8 +280,18 @@
                     x1 += (2 + y_major_length/2);
                 }
 
- image.get_g_element(detail::PLOT_PLOT_LABELS).text(x1,
- y1, fmt.str());
+ if(!use_y_external_style && i != 0)
+ {
+ image.get_g_element(detail::PLOT_PLOT_LABELS).text(x1,
+ y1, fmt.str());
+ }
+
+ if(use_y_external_style)
+ {
+ image.get_g_element(detail::PLOT_PLOT_LABELS).text(x1 + 12,
+ y1, fmt.str(), 12, center_align, -90);
+
+ }
             }
         }
     }
@@ -354,17 +361,12 @@
 
     void _draw_y_label()
     {
- /* text_element to_use((plot_x2 + plot_x1) / 2., image.get_y_size() - 8, x_label);
-
- to_use.font_size(12);
- to_use.alignment(center_align);
-
- image.get_g_element(PLOT_X_LABEL).stroke_color(white);
- image.get_g_element(PLOT_X_LABEL).fill_color(white);
+ image.get_g_element(detail::PLOT_Y_LABEL).style().stroke_color(black);
 
-
- image.get_g_element(PLOT_X_LABEL).push_back(new text_element(to_use));
- */
+ image.get_g_element(detail::PLOT_Y_LABEL).push_back(new
+ text_element(12, (plot_y2 + plot_y1)/2.,
+ y_label_info.text(),
+ 12, center_align, -90));
     }
 
     
@@ -615,6 +617,8 @@
                                      plot_x2 - plot_x1 - 2, plot_y2 - plot_y1 - 2),
                         plot_window_clip);
 
+ image.get_g_element(detail::PLOT_PLOT_POINTS).clip_id(plot_window_clip);
+
         if(use_axis)
         {
             _draw_y_axis();
@@ -631,6 +635,11 @@
             _draw_x_label();
         }
 
+ if(use_y_label)
+ {
+ _draw_y_label();
+ }
+
         // Draw lines between non-limit points
 
         _draw_plot_lines();
@@ -683,6 +692,7 @@
 
 svg_2d_plot(): title_info(0, 0, "Plot of data", 30),
                       x_label_info(0, 0, "X Axis", 12),
+ y_label_info(0, 0, "Y Axis", 12),
                       x_min(-10), x_max(10),
                       y_min(-10), y_max(10),
                       x_major(3), x_num_minor(2),
@@ -868,7 +878,7 @@
 
 svg_2d_plot& y_name(const std::string& _str)
 {
- y_label = _str;
+ y_label_info.text(_str);
     return *this;
 }
 
@@ -886,6 +896,12 @@
     return *this;
 }
 
+svg_2d_plot& y_label_on(bool _cmd)
+{
+ use_y_label = _cmd;
+ return *this;
+}
+
 svg_2d_plot& axis_external_style(bool _is)
 {
     use_x_external_style = _is;

Modified: sandbox/SOC/2007/visualization/boost/svg_plot/svg_test.cpp
==============================================================================
--- sandbox/SOC/2007/visualization/boost/svg_plot/svg_test.cpp (original)
+++ sandbox/SOC/2007/visualization/boost/svg_plot/svg_test.cpp 2007-10-17 00:55:10 EDT (Wed, 17 Oct 2007)
@@ -1,12 +1,9 @@
-#include "svg_1d_plot.hpp"
+#include "svg_2d_plot.hpp"
 #include "svg_boxplot.hpp"
-
-#include <vector>
+#include <map>
 #include <cmath>
-#include <iostream>
 
 using std::multimap;
-using std::vector;
 
 double h(double x)
 {
@@ -24,26 +21,28 @@
 int main()
 {
     using namespace boost::svg;
- std::vector<double> data1, data2;
+ std::multimap<double, double> data1;
 
     svg_boxplot my_plot;
- svg_1d_plot my_1d_plot;
-
- my_1d_plot.load_stylesheet("D:\\style.css");
+ svg_2d_plot my_2d_plot;
 
- my_1d_plot.background_border_color(black)
- .title("Boxplots of Common Functions");
+ my_2d_plot.background_border_color(black)
+ .title("Y axis label experiment")
+ .y_major_labels_on(true)
+ .y_label_on(true)
+ .x_label_on(true)
+ .x_major_labels_on(true)
+ .plot_window_on(true)
+ .y_external_style_on(true);
     
     for(double i=.1; i < 10; i+=.1)
     {
- data1.push_back(h(i));
- data2.push_back(f(i));
+ data1.insert(std::pair<double, double>(i, h(i)));
     }
 
- my_1d_plot.plot(data1, "[50 / x]");
- my_1d_plot.plot(data2, "[40 + 25 * sin(50x)]");
+ my_2d_plot.plot(data1, "[50 / x]");
 
- my_1d_plot.write("D:\\1d_test.svg");
+ my_2d_plot.write("D:\\axislabel_test.svg");
 
     return 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