Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r51621 - sandbox/SOC/2007/visualization/libs/svg_plot/example
From: pbristow_at_[hidden]
Date: 2009-03-05 11:26:11


Author: pbristow
Date: 2009-03-05 11:26:10 EST (Thu, 05 Mar 2009)
New Revision: 51621
URL: http://svn.boost.org/trac/boost/changeset/51621

Log:
Additional demonstration programs.
Added:
   sandbox/SOC/2007/visualization/libs/svg_plot/example/demo_1d_limits.cpp (contents, props changed)
   sandbox/SOC/2007/visualization/libs/svg_plot/example/demo_1d_x_external.cpp (contents, props changed)
   sandbox/SOC/2007/visualization/libs/svg_plot/example/demo_2d_limits.cpp (contents, props changed)
   sandbox/SOC/2007/visualization/libs/svg_plot/example/demo_boxplot_full.cpp (contents, props changed)
   sandbox/SOC/2007/visualization/libs/svg_plot/example/demo_boxplot_simple.cpp (contents, props changed)
   sandbox/SOC/2007/visualization/libs/svg_plot/example/demo_color.cpp (contents, props changed)
   sandbox/SOC/2007/visualization/libs/svg_plot/example/demo_functions_boxplot.cpp (contents, props changed)
   sandbox/SOC/2007/visualization/libs/svg_plot/example/demo_point_markers.cpp (contents, props changed)
   sandbox/SOC/2007/visualization/libs/svg_plot/example/demo_rounds.cpp (contents, props changed)
   sandbox/SOC/2007/visualization/libs/svg_plot/example/demo_svg.cpp (contents, props changed)
   sandbox/SOC/2007/visualization/libs/svg_plot/example/svg_test_boxplot.cpp (contents, props changed)

Added: sandbox/SOC/2007/visualization/libs/svg_plot/example/demo_1d_limits.cpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/visualization/libs/svg_plot/example/demo_1d_limits.cpp 2009-03-05 11:26:10 EST (Thu, 05 Mar 2009)
@@ -0,0 +1,117 @@
+/*! \file demo_1d_limits.cpp
+ \brief Demonstration of some 1D values including NaN and + and - infinity.
+ \details Quickbook markup to include in documentation.
+ \date 19 Feb 2009
+ \author Paul A. Bristow
+*/
+
+// Copyright Paul A Bristow 2008, 2009
+
+// Use, modification and distribution are subject to the
+// Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt
+// or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+// This file is written to be included from a Quickbook .qbk document.
+// It can be compiled by the C++ compiler, and run. Any output can
+// also be added here as comment or included or pasted in elsewhere.
+// Caution: this file contains Quickbook markup as well as code
+// and comments: don't change any of the special comment markups!
+
+//[demo_1d_limits_1
+/*`As ever, we need a few includes to use Boost.Plot
+*/
+
+#include <boost/svg_plot/svg_1d_plot.hpp>
+ using namespace boost::svg;
+ using boost::svg::svg_1d_plot;
+
+#include <iostream>
+ using std::cout;
+ using std::endl;
+ using std::hex;
+
+#include <vector>
+ using std::vector;
+
+#include <limits>
+ using std::numeric_limits;
+
+//] [demo_1d_limits_1]
+
+int main()
+{
+//[demo_1d_limits_2
+/*`Some fictional data is pushed into an STL container, here vector<double>, including a NaN and + and - infinity:*/
+ vector<double> my_data;
+ my_data.push_back(-1.6);
+ my_data.push_back(2.0);
+ my_data.push_back(4.2563);
+ my_data.push_back(-4.0);
+ my_data.push_back(numeric_limits<double>::infinity());
+ my_data.push_back(-numeric_limits<double>::infinity());
+ my_data.push_back(numeric_limits<double>::quiet_NaN());
+
+ try
+ { // try'n'catch blocks are needed to ensure error messages from any exceptions are shown.
+ svg_1d_plot my_1d_plot; // Construct a plot with all the default constructor values.
+
+ my_1d_plot.title("Default 1D NaN and infinities Demo") // Add a string title of the plot.
+ .x_range(-5, 5) // Add a range for the X-axis.
+ .x_label("length (m)"); // Add a label for the X-axis.
+
+
+/*`Add the one data series, `my_data` and a description, and how the data points are to marked,
+here a circle with a diameter of 5 pixels.
+*/
+ my_1d_plot.plot(my_data, "1D limits").shape(round).size(5);
+
+/*`To put a value label against each data point, switch on the option:
+*/
+ my_1d_plot.x_values_on(true); // Add a label for the X-axis.
+
+/*`To change the default colors (lightgray and whitesmoke) for the 'at limit' point marker
+to something more conspicuous for this demonstration:
+*/
+ my_1d_plot.limit_color(blue);
+ my_1d_plot.limit_fill_color(pink);
+
+/*`To use all these settings, finally write the plot to file.
+*/
+ my_1d_plot.write("demo_1d_limits.svg");
+
+/*`
+[note the +infinity point is marked on the far right of the plot, the -infinity on the far left, but the NaN (Not A Number is at zero).]
+
+To echo the new marker colors chosen:
+*/
+ cout << "limit points stroke color " << my_1d_plot.limit_color() << endl;
+ cout << "limit points fill color " << my_1d_plot.limit_fill_color() << endl;
+
+//] [demo_1d_limits_2]
+ }
+ catch(const std::exception& e)
+ {
+ std::cout <<
+ "\n""Message from thrown exception was:\n " << e.what() << std::endl;
+ }
+ return 0;
+} // int main()
+
+/*
+
+//[demo_1d_limits_output
+
+Output:
+
+demo_1d_limits.cpp
+Linking...
+Embedding manifest...
+Autorun "j:\Cpp\SVG\debug\demo_1d_limits.exe"
+limit points stroke color RGB(0,0,255)
+limit points fill color RGB(255,192,203)
+Build Time 0:04
+//] [demo_1d_limits_output]
+
+*/
+

Added: sandbox/SOC/2007/visualization/libs/svg_plot/example/demo_1d_x_external.cpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/visualization/libs/svg_plot/example/demo_1d_x_external.cpp 2009-03-05 11:26:10 EST (Thu, 05 Mar 2009)
@@ -0,0 +1,92 @@
+/*! \file demo_1d_x_external.cpp
+ \brief 1D plot from two vectors of doubles, showing axis label variation.
+ \author Jacob Voytko and Paul A. Bristow
+ \date 2009
+*/
+
+// Copyright Jacob Voytko 2007
+// Copyright Paul A. Bristow 2009
+
+// Distributed under the Boost Software License, Version 1.0.
+// For more information, see http://www.boost.org
+
+#include <boost/svg_plot/svg_1d_plot.hpp>
+#include <vector>
+
+using std::vector;
+using namespace boost::svg;
+
+//enum x_axis_intersect
+//{ //! \enum x_axis_intersect If and how the X axes intersects Y axis.
+// bottom = -1, //!< X-axis free below bottom of end of Y-axis (case of all Y definitely < 0).
+// x_intersects_y = 0, //!< x_intersects_y when Y values include zero, so X intersects the Y axis.
+// top = +1 //!< X-axis free above top of X-axis (case of all Y definitely > 0).
+// };
+
+//[demo_1d_x_external_1
+
+int main()
+{
+
+/*`Following previous examples, we set up two containers for two data series.
+*/
+ vector<double> dan_times;
+ vector<double> elaine_times;
+
+ dan_times.push_back(3.1);
+ dan_times.push_back(4.2);
+ elaine_times.push_back(2.1);
+ elaine_times.push_back(7.8);
+
+ svg_1d_plot my_plot;
+
+ // Adding some generic settings.
+ my_plot.background_border_color(black)
+ .legend_on(true)
+ .plot_window_on(true)
+ .title("Race Times")
+ .x_range(-1, 10);
+
+/*`We add tastelessly colored grids for bother major and minor ticks, and switch both grids on.
+*/ // Styling grid.
+ my_plot.x_major_grid_color(pink)
+ .x_minor_grid_color(lightgray);
+
+ my_plot.x_major_grid_on(true)
+ .x_minor_grid_on(true);
+
+/*`Also we specify the position of the labelling of the X-axis.
+It can be controlled using values in the enum x_axis_intersect.
+``
+ enum x_axis_intersect
+ { //! \enum x_axis_intersect
+ bottom = -1, // On the bottom of the plot window.
+ x_intersects_y = 0, // On the X axis (in the middle of the plot window).
+ top = +1 // On the top of the plot window.
+ };
+``
+For this example, we choose to show the X axis and tick value labels at the top of the plot window.
+*/
+ my_plot.x_ticks_on_window_or_axis(top); // on top, not on axis.
+
+ // Write to plot.
+ my_plot.plot(dan_times, "Dan").stroke_color(blue);
+ my_plot.plot(elaine_times, "Elaine").stroke_color(orange);
+
+ // Write to file.
+ my_plot.write("./demo_1d_x_external.svg");
+ return 0;
+} // int main()
+
+//] [/demo_1d_x_external_1]
+
+/*
+Output:
+
+Compiling...
+demo_1d_x_external.cpp
+Linking...
+Embedding manifest...
+Autorun "j:\Cpp\SVG\debug\demo_1d_x_external.exe"
+*/
+

Added: sandbox/SOC/2007/visualization/libs/svg_plot/example/demo_2d_limits.cpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/visualization/libs/svg_plot/example/demo_2d_limits.cpp 2009-03-05 11:26:10 EST (Thu, 05 Mar 2009)
@@ -0,0 +1,151 @@
+/*! \file demo_2d_limits.cpp
+ \brief Demonstration of some 2D values including NaN and + and - infinity.
+ \details Quickbook markup to include in documentation.
+ \date 19 Feb 2009
+ \author Paul A. Bristow
+*/
+
+// Copyright Paul A Bristow 2008, 2009
+
+// Use, modification and distribution are subject to the
+// Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt
+// or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+// An example to demonstrate 2D values including NaN and + and - infinity.
+
+// This file is written to be included from a Quickbook .qbk document.
+// It can be compiled by the C++ compiler, and run. Any output can
+// also be added here as comment or included or pasted in elsewhere.
+
+// Caution: this file contains Quickbook markup as well as code
+// and comments: don't change any of the special comment markups!
+
+//[demo_2d_limits_1
+
+/*`As ever, we need a few includes to use Boost.Plot
+*/
+
+#include <boost/svg_plot/svg_2d_plot.hpp>
+ using namespace boost::svg;
+ using boost::svg::svg_2d_plot;
+
+#include <iostream>
+ using std::cout;
+ using std::endl;
+
+#include <map>
+ using std::map;
+
+#include <limits>
+ using std::numeric_limits;
+
+#include <utility>
+ using std::make_pair;
+
+//] [demo_2d_limits_1]
+
+int main()
+{
+
+//[demo_2d_limits_2
+
+ /*`Some fictional data is pushed into an STL container, here map:*/
+
+ map<double, double> my_data;
+ /*`
+ Inserting some fictional values also sorts the data.
+ The map index value in [] is the x value, so mydata[x] = y.
+
+ First some normal valued points, not 'at limits'.
+ */
+ my_data[1.1] = 3.2;
+ my_data[4.3] = 3.1;
+ my_data[0.25] = 1.4;
+/*`
+ Now some values including + and - infinity:
+*/
+ my_data[3] = numeric_limits<double>::quiet_NaN(); // marker at x = 3, y = 0
+ my_data[0.] = numeric_limits<double>::quiet_NaN(); // Marker at 0,0
+ my_data[1.] = numeric_limits<double>::infinity(); // Marker at 1, top
+ my_data[-1] = -numeric_limits<double>::infinity(); // Marker at -1, bottom
+ my_data[+numeric_limits<double>::infinity()] = +1.; // Marker at right, 1
+ my_data[-numeric_limits<double>::infinity()] = -1.; // Marker at left, -1
+ my_data[+numeric_limits<double>::max()] = +2.; // Marker at right, 2
+ my_data[-numeric_limits<double>::max()] = +2.; // Marker at left, 2
+ my_data[-numeric_limits<double>::max() /2] = +3.; // Value near to max, marker left, 3
+ my_data[numeric_limits<double>::infinity()] = numeric_limits<double>::infinity(); // Top right.
+ my_data[-numeric_limits<double>::infinity()] = -numeric_limits<double>::infinity(); // Bottom left.
+
+/*`
+ [caution using map (rather than multimap that allows duplicates) some assignments values overwrite,
+ and so not all display as they do individually.
+ In particular, an X value of quiet_NaN() causes a overwrite of the lowerest value (because NaNs never compare equal).
+ So avoid NaN as an X value.]
+*/
+
+ try
+ { // try'n'catch blocks are needed to ensure error messages from any exceptions are shown.
+ svg_2d_plot my_2d_plot; // Construct a plot with all the default constructor values.
+
+ my_2d_plot.title("Default 2D 'at limits' NaN and infinities Demo") // Add a string title of the plot.
+ .x_range(-5, 5) // Add a range for the X-axis.
+ .y_range(-5, 5) // Add a range for the Y-axis
+ .x_label("time (s)"); // Add a label for the X-axis.
+
+/*`
+Add the one data series, `my_data` and a description, and how the data points are to be marked,
+here a circle with a diameter of 5 pixels.
+*/
+ svg_2d_plot_series& my_series = my_2d_plot.plot(my_data, "2D limits").shape(round).size(5);
+
+/*`
+We can also keep note of the plot series and use this to interrogate how many normal and how many 'at limit' values.
+*/
+ cout << my_series.values_count() << " Normal data values in series." << endl;
+ cout << my_series.limits_count() << " 'At limits' data values in series."<< endl;
+
+/*`To put a value label against each data point, switch on the option:
+*/
+ // my_2d_plot.x_values_on(true).y_values_on(true).x_values_font_size(12).y_values_font_size(12); // Add the X-axis and Y-axis values.
+ // This displays x horizontally and Y downward.
+ my_2d_plot.xy_values_on(true).x_values_font_size(12).y_values_font_size(12); // Add the X-axis and Y-axis values.
+ // This displays X above and Y below.
+
+/*`To change the default colors (lightgray and whitesmoke) for the 'at limit' point marker
+to something more conspicuous for this demonstration:
+*/
+ my_2d_plot.limit_color(blue);
+ my_2d_plot.limit_fill_color(pink);
+
+/*`To use all these settings, finally write the plot to file.
+*/
+ my_2d_plot.write("demo_2d_limits.svg");
+
+/*` Note the +infinity point is marked on the far right of the plot, the -infinity on the far left, but the NaN (Not A Number is at zero).
+
+To echo the new marker colors chosen:
+*/
+ cout << "limit points stroke color " << my_2d_plot.limit_color() << endl;
+ cout << "limit points fill color " << my_2d_plot.limit_fill_color() << endl;
+
+//] [demo_2d_limits_2]
+ }
+ catch(const std::exception& e)
+ {
+ std::cout <<
+ "\n""Message from thrown exception was:\n " << e.what() << std::endl;
+ }
+ return 0;
+} // int main()
+
+/*
+
+//[demo_2d_limits_output
+
+Output:
+
+
+
+*/
+

Added: sandbox/SOC/2007/visualization/libs/svg_plot/example/demo_boxplot_full.cpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/visualization/libs/svg_plot/example/demo_boxplot_full.cpp 2009-03-05 11:26:10 EST (Thu, 05 Mar 2009)
@@ -0,0 +1,225 @@
+/*! \file demo_boxplot_full.cpp
+ \brief Demonstration of more options for Boxplots.
+ \details Quickbook markup so can be included in documentation.
+
+ \author Jacob Voytko and Paul A. Bristow
+ \date Feb 2009
+*/
+
+// Copyright Jacob Voytko 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
+// or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+// An example to demonstrate nearly all boxplot options.
+// See also demo_boxplot_simple.cpp and demo_boxplot.cpp for a narrow range of use.
+
+// This file is written to be included from a Quickbook .qbk document.
+// It can be compiled by the C++ compiler, and run. Any output can
+// also be added here as comment or included or pasted in elsewhere.
+
+// Caution: this file contains Quickbook markup as well as code
+// and comments: don't change any of the special comment markups!
+
+//[demo_boxplot_full_1
+
+/*`
+Boxplot is a convenient way of graphically depicting groups of numerical data
+through their five-number summaries.
+Show 1st quartile, median and 3rd quartile as a box,
+minimum and maximum non-outlier values as whiskers,
+and outliers and extreme outliers.
+
+See [@http://en.wikipedia.org/wiki/Boxplot boxplot] and
+
+Some Implementations of the Boxplot
+Michael Frigge, David C. Hoaglin and Boris Iglewicz
+The American Statistician, Vol. 43, No. 1 (Feb., 1989), pp. 50-54
+
+First we need a few includes to use Boost.Plot.
+*/
+
+#include <vector>
+using std::vector;
+#include <cmath>
+using ::sin;
+#include <boost/svg_plot/svg_boxplot.hpp>
+
+#include <boost/array.hpp>
+ using boost::array;
+
+#include <iostream>
+using std::cout;
+using std::endl;
+
+/*`Use two functions, 1/x and sin(x), to simulate distributions.
+*/
+
+double f(double x)
+{ // Effectively 1/x.
+ return 50 / x;
+}
+
+double g(double x)
+{ // Effectively sin(x).
+ return 40 + 25 * sin(x * 50);
+}
+//] [demo_boxplot_full_1]
+
+int main()
+{
+ using namespace boost::svg;
+ try
+ {
+//[demo_boxplot_full_2]
+/*`10 values are computed and stored in two std:: vectors.
+*/
+ std::vector<double> data1;
+ std::vector<double> data2;
+
+ cout.precision(2);
+ for(double i = 0.1; i < 10; i += 0.1)
+ { // Fill our vectors with 100 values:
+ double fv = f(i);
+ double gv = g(i);
+ // cout << i << ' ' << fv << ' ' << gv << endl;
+ data1.push_back(fv);
+ data2.push_back(gv);
+ }
+
+ /*`Other containers, for example array, can be used too:
+ */
+
+ //const boost::array<double, 0> data0;
+ //const boost::array<double, 10> data3 = {20., 30., 40., 45., 47., 50., 55., 60., 70, 80.};
+
+/*`A new boxplot is contructed and very many settings added.
+This is only to show their use and is intended to be visible, if totally tasteless!
+*/
+ svg_boxplot my_boxplot;
+
+ //my_boxplot.plot(data0, "data0"); // Produces warning: "Message from thrown exception was: Data series data0 is empty!"
+
+ //my_boxplot.plot(data3); // Produces warning: "Data series has no title!"
+
+ my_boxplot.background_border_color(darkblue);
+ my_boxplot.background_color(azure);
+
+ my_boxplot // Title and axes labels.
+ .title("Boxplots of 1/x and sin(x) Functions")
+ .x_label("Functions")
+ .y_label("Population Size");
+
+ my_boxplot.y_range(0, 100) // Y-Axis information.
+ .y_minor_tick_length(2)
+ .y_major_interval(20);
+
+/*`Many attributes of boxplots can be changed from the 'builtin' defaults, for example: */
+
+ my_boxplot.whisker_length(25.).box_width(10)
+ .box_fill(lime)
+ .box_border(blue)
+ .box_fill(lightblue)
+ .median_color(red). median_width(2)
+ .axis_color(orange).axis_width(4)
+ .outlier_color(red)
+ .outlier_fill(yellow)
+ .outlier_shape(square)
+ .outlier_size(5)
+ .median_values_on(true)
+ .outlier_values_on(true)
+ .extreme_outlier_values_on(true)
+ .extreme_outlier_color(brown)
+ .extreme_outlier_shape(diamond)
+ .extreme_outlier_size(10)
+ ;
+
+ cout << my_boxplot.outlier_color() << endl; // red
+ cout << my_boxplot.outlier_size() << endl; // size 10
+ cout << my_boxplot.outlier_shape() << endl; // square
+
+ //cout << my_boxplot.outlier_style.size() << endl; // doesn't work???
+
+
+/*` Applies to all boxplots, unless changed for any individual plots, for example, change colors for data1 only:*/
+
+ my_boxplot.plot(data1, "data1")
+ .whisker_length(50.)
+ .min_whisker_width(4).min_whisker_color(red)
+ .max_whisker_width(7).max_whisker_color(green)
+ .box_width(10)
+ .box_fill(yellow)
+ .box_border(magenta)
+ .median_color(blue). median_width(5)
+ .axis_color(lime). axis_width(1)
+ .outlier_color(blue)
+ .outlier_fill(yellow)
+ .outlier_shape(cone)
+ .outlier_size(10)
+ .extreme_outlier_color(red)
+ .extreme_outlier_fill(green)
+ .extreme_outlier_shape(round)
+ .extreme_outlier_size(10)
+ //.extreme_outlier_values_on(true) not implemented.
+;
+
+
+
+ // my_boxplot.plot(data1, "test").box_style().fill_color(pink).stroke_color(green);
+ // Once box_style() has been used to chain box styles, one can no longer chain to other non-box items, which is limiting.
+ // So convenience functions are provided for many (but not all) features like: .box_fill(pink), box_border(green)...
+ // Similar restrictions follow
+ // my_boxplot.plot(data1, "test").box_width(10).whisker_length(5).median_style().stroke_color(purple);
+
+
+/*`Add the two data series containers, and their labels, to the plot.
+*/
+
+ my_boxplot.plot(data1, "[50/x]");
+ my_boxplot.plot(data2, "[sin(x*50)]");
+
+/*
+ cout << "my_boxplot.title " << my_boxplot.title() << endl;
+ cout << "my_boxplot.x_label_text "<< my_boxplot.x_label_text() << endl;
+ cout << "my_boxplot.y_label_text " << my_boxplot.y_label_text() << endl;
+
+ cout << "my_boxplot.background_color " << my_boxplot.background_color() << endl;
+ cout << "my_boxplot.background_border_color " << my_boxplot.background_border_color() << endl;
+ cout << "my_boxplot.plot_background_color " << my_boxplot.plot_background_color() << endl;
+ cout << "my_boxplot.plot_border_color " << my_boxplot.plot_border_color() << endl;
+ */
+
+/*`Finally write the SVG plot to a file.
+*/
+ my_boxplot.write("demo_boxplot_full.svg");
+
+/*`You can view the plot (in all its 'glory') at demo_boxplot_full.svg."
+*/
+
+//] [demo_boxplot_full_2]
+ }
+ catch(const std::exception& e)
+ {
+ std::cout <<
+ "\n""Message from thrown exception was:\n " << e.what() << std::endl;
+ }
+ return 0;
+} // int main()
+
+/*
+
+Output:
+demo_boxplot_full.cpp
+Linking...
+Embedding manifest...
+Autorun "j:\Cpp\SVG\debug\demo_boxplot_full.exe"
+RGB(255,0,0)
+5
+2
+Build Time 0:03
+
+*/
+

Added: sandbox/SOC/2007/visualization/libs/svg_plot/example/demo_boxplot_simple.cpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/visualization/libs/svg_plot/example/demo_boxplot_simple.cpp 2009-03-05 11:26:10 EST (Thu, 05 Mar 2009)
@@ -0,0 +1,131 @@
+/*! \file demo_boxplot_simple.cpp
+ \brief An example to demonstrate simplest use of boxplot. See also boxplot_full.cpp for a wider range of use.
+
+ \author Jacob Voytko and Paul A. Bristow
+ \date 2009
+*/
+
+// Copyright Jacob Voytko 2007
+// Copyright Paul A. Bristow 2008, 2009
+
+// Use, modification and distribution are subject to the
+// Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt
+// or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+// This file is written to be included from a Quickbook .qbk document.
+// It can be compiled by the C++ compiler, and run. Any output can
+// also be added here as comment or included or pasted in elsewhere.
+
+// Caution: this file contains Quickbook markup as well as code
+// and comments: don't change any of the special comment markups!
+
+//[boxplot_simple_1
+
+/*`
+Boxplot is a convenient way of graphically depicting groups of numerical data
+through their five-number summaries.
+Show 1st quartile, median and 3rd quartile as a box,
+95% confidence interval as whiskers,
+outliers and extreme outliers.
+
+See [@http://en.wikipedia.org/wiki/Boxplot boxplot] and
+
+Some Implementations of the Boxplot
+Michael Frigge, David C. Hoaglin and Boris Iglewicz
+The American Statistician, Vol. 43, No. 1 (Feb., 1989), pp. 50-54
+
+First we need a few includes to use Boost.Plot.
+*/
+
+#include <vector>
+ using std::vector;
+#include <cmath>
+ using ::sin;
+#include <boost/svg_plot/svg_boxplot.hpp>
+
+#include <iostream>
+ using std::cout;
+ using std::endl;
+
+/*`Use two functions, 1/x and sin(x), to simulate distributions.
+*/
+
+double f(double x)
+{ // Effectively 1/x.
+ return 50 / x;
+}
+
+double g(double x)
+{ // Effectively sin(x).
+ return 40 + 25 * sin(x * 50);
+}
+//] [boxplot_simple_1]
+
+int main()
+{
+ using namespace boost::svg;
+ try
+ {
+//[boxplot_simple_2]
+/*`10 values are computed and stored in two std:: vectors.
+*/
+ std::vector<double> data1;
+ std::vector<double> data2;
+
+ cout.precision(2);
+ for(double i = 0.1; i < 10; i += 0.1)
+ { // Fill our vectors with 100 values:
+ double fv = f(i);
+ double gv = g(i);
+ // cout << i << ' ' << fv << ' ' << gv << endl;
+ data1.push_back(fv);
+ data2.push_back(gv);
+ }
+
+/*`A new boxplot is constructed and a few settings added.
+*/
+ svg_boxplot my_boxplot;
+
+ my_boxplot // Title and axes labels.
+ .title("Boxplots of 1/x and sin(x) Functions")
+ .x_label("Functions")
+ .y_label("Population Size");
+
+ my_boxplot.y_range(0, 100) // Axis information.
+ .y_major_interval(20);
+
+/*`Add the two data series containers, and their labels, to the plot.
+*/
+
+ my_boxplot.plot(data1, "[50 / x]");
+ my_boxplot.plot(data2, "[40 + 25 * sin(x * 50)]");
+
+/*`Finally write the SVG plot to a file.
+*/
+ my_boxplot.write("boxplot_simple.svg");
+/*`You can view the plot at boxplot_simple.svg."
+*/
+
+//] [boxplot_simple_2]
+ }
+ catch(const std::exception& e)
+ {
+ std::cout <<
+ "\n""Message from thrown exception was:\n " << e.what() << std::endl;
+ }
+ return 0;
+} // int main()
+
+/*
+
+Output:
+
+Autorun "j:\Cpp\SVG\debug\demo_boxplot_simple.exe"
+
+Build Time 0:00
+Build log was saved at "file://j:\Cpp\SVG\demo_boxplot_simple\Debug\BuildLog.htm"
+
+
+*/
+

Added: sandbox/SOC/2007/visualization/libs/svg_plot/example/demo_color.cpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/visualization/libs/svg_plot/example/demo_color.cpp 2009-03-05 11:26:10 EST (Thu, 05 Mar 2009)
@@ -0,0 +1,187 @@
+/*! \file demo_color.cpp
+ \brief Demonstration of some SVG color features.
+ \details This produces a sample SVG file.
+ \author Paul A Bristow
+*/
+
+// Copyright Jacob Voytko 2007
+// Copyright Paul A Bristow 2007
+
+// Use, modification and distribution are subject to the
+// Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt
+// or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+// This module is entirely contrived examples of using svg_colors.
+// see also test_svg.cpp for tests using Boost.Test.
+
+#ifdef _MSC_VER
+# pragma warning(disable : 4127) // conditional expression is constant
+# 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
+#endif
+
+#include <boost/svg_plot/svg.hpp>
+ using boost::svg::svg;
+
+#include <boost/svg_plot/svg_1d_plot.hpp>
+ using namespace boost::svg;
+ using boost::svg::svg_1d_plot;
+
+#include <iostream>
+ using std::cout;
+ using std::endl;
+ using std::boolalpha;
+
+#include <vector>
+ using std::vector;
+
+ using namespace std;
+
+int main()
+{
+
+ svg_1d_plot my_colors;
+
+ my_colors.title("Demo SVG colors")
+ .legend_on(true)
+ .legend_title("Legend title")
+ .x_label_on(true)
+ .x_label("axis") // This doesn't show unless .x_label_on() == true!
+ // x_label is far too far below the axis.
+ .x_axis_color(blue)
+ .x_label_color(magenta)
+ .x_range(0., 7.);
+
+ vector<double> my_data;
+ my_data.push_back(1.);
+ my_data.push_back(2.);
+ my_data.push_back(3.);
+
+ my_colors.plot(my_data, "My Data");
+
+ my_colors.write("demo_colors.svg");
+
+
+ {
+ svg_color my_blank(false);
+ cout << "svg_color my_blank(false);" << boolalpha << endl;
+ cout << "my_blank.is_blank is " << my_blank.is_blank << endl;
+ cout << "my_blank.r my_blank.g my_blank.b = "
+ << (unsigned int)my_blank.r << ' '
+ << (unsigned int)my_blank.g << ' '
+ << (unsigned int)my_blank.b << endl;
+ cout << "my_blank " << my_blank << endl;
+ my_blank.write(cout); cout << endl;
+ }
+ {
+ svg_color my_blank(true);
+ cout << "svg_color my_blank(true)" << boolalpha << endl;
+ cout << "my_blank.is_blank is " << my_blank.is_blank << endl;
+ cout << "my_blank.r my_blank.g my_blank.b = "
+ << (unsigned int)my_blank.r << ' '
+ << (unsigned int)my_blank.g << ' '
+ << (unsigned int)my_blank.b << endl;
+ cout << "my_blank " << my_blank << endl; // my_blank RGB(0,0,0) == default color.
+ my_blank.write(cout); cout << endl;
+ }
+ {
+ svg_color my_blank(blank);
+ cout << "svg_color my_blank(blank)" << boolalpha << endl;
+ cout << "my_blank.is_blank is " << my_blank.is_blank << endl;
+ cout << "my_blank.r my_blank.g my_blank.b = "
+ << (unsigned int)my_blank.r << ' '
+ << (unsigned int)my_blank.g << ' '
+ << (unsigned int)my_blank.b << endl;
+ cout << "my_blank " << my_blank << endl; // my_blank RGB(0,0,0) == default color.
+ my_blank.write(cout); cout << endl;
+ }
+
+ svg_color my_red(255, 0, 0); //
+ cout << "red " << red << endl; // Output: red 119 - because red is an enum! Caution!
+ cout << "red " << svg_color(red) << endl; // Output: red RGB(255,0,0)
+ if (my_red == svg_color(red))
+ {
+ cout << "my_red == svg_color(red)" << endl;
+ }
+ if (my_red == red)
+ {
+ cout << "my_red == red" << endl;
+ }
+ if (my_red != black)
+ {
+ cout << "my_red != black" << endl;
+ }
+ if (white != black)
+ {
+ cout << "my_red != black" << endl;
+ }
+
+ svg_color my_color(127, 255, 212); // Specify a 'custom' color, not in the svg colors list.
+ svg_color my_same_color(127, 255, 212);
+ my_color.write(cout); cout << endl;
+ cout << "my_color " << my_color << endl;
+
+ svg_color my_color2(magenta);
+ my_color2.write(cout);
+ cout << endl;
+ cout << "magenta " << magenta << endl; // magenta 85 because magenta is an enum!
+ cout << "magenta " << svg_color(magenta) << endl; // magenta RGB(255,0,255)
+
+ cout << "(my_color == my_color2) is " << (my_color == my_color2) << endl;
+ cout << "(my_color == my_same_color) is "<< (my_color == my_same_color) << endl;
+ svg_color my_blank(blank);
+ cout << "(my_blank == my_blank) is "<< (my_blank == my_blank) << endl;
+ svg_color my_blank2(true);
+ cout << "(my_blank == my_blank2) is "<< (my_blank == my_blank2) << endl;
+
+ my_colors.write("demo_color.svg");
+
+ return 0;
+} // int main()
+
+/*
+
+Output:
+
+Compiling...
+demo_color.cpp
+Linking...
+Embedding manifest...
+Autorun "j:\Cpp\SVG\debug\demo_color.exe"
+svg_color my_blank(false);
+my_blank.is_blank is true
+my_blank.r my_blank.g my_blank.b = 0 0 0
+my_blank blank
+none
+svg_color my_blank(true)
+my_blank.is_blank is false
+my_blank.r my_blank.g my_blank.b = 0 0 0
+my_blank RGB(0,0,0)
+rgb(0,0,0)
+svg_color my_blank(blank)
+my_blank.is_blank is true
+my_blank.r my_blank.g my_blank.b = 255 255 255
+my_blank blank
+none
+red 119
+red RGB(255,0,0)
+my_red == svg_color(red)
+my_red == red
+my_red != black
+my_red != black
+rgb(127,255,212)
+my_color RGB(127,255,212)
+rgb(255,0,255)
+magenta 85
+magenta RGB(255,0,255)
+(my_color == my_color2) is false
+(my_color == my_same_color) is true
+(my_blank == my_blank) is true
+(my_blank == my_blank2) is false
+Build Time 0:03
+
+
+
+*/
+

Added: sandbox/SOC/2007/visualization/libs/svg_plot/example/demo_functions_boxplot.cpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/visualization/libs/svg_plot/example/demo_functions_boxplot.cpp 2009-03-05 11:26:10 EST (Thu, 05 Mar 2009)
@@ -0,0 +1,58 @@
+/*! \file demo_functions_boxplot.cpp
+
+ \brief Boxplot of two functions.
+
+ \author Jacob Voytko
+
+ \date 2007
+*/
+
+#include "svg_1d_plot.hpp"
+#include "svg_boxplot.hpp"
+
+#include <vector>
+#include <cmath>
+#include <iostream>
+
+using std::multimap;
+using std::vector;
+
+double h(double x)
+{
+ return 50 / (x);
+}
+
+double f(double x)
+{
+ return 40 + 25 * sin(x * 50);
+}
+
+using std::cout;
+using std::cin;
+
+int main()
+{
+ using namespace boost::svg;
+ std::vector<double> data1, data2;
+
+ svg_boxplot my_plot;
+ svg_1d_plot my_1d_plot;
+
+ //my_1d_plot.load_stylesheet(".\style.css");
+
+ my_1d_plot.background_border_color(black)
+ .title("Boxplots of Common Functions");
+
+ for(double i=.1; i < 10; i+=.1)
+ {
+ data1.push_back(h(i));
+ data2.push_back(f(i));
+ }
+
+ my_1d_plot.plot(data1, "[50 / x]");
+ my_1d_plot.plot(data2, "[40 + 25 * sin(50x)]");
+
+ my_1d_plot.write(".\1d_test.svg");
+
+ return 0;
+} // int main()

Added: sandbox/SOC/2007/visualization/libs/svg_plot/example/demo_point_markers.cpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/visualization/libs/svg_plot/example/demo_point_markers.cpp 2009-03-05 11:26:10 EST (Thu, 05 Mar 2009)
@@ -0,0 +1,129 @@
+/*! \file demo_point_markers.cpp
+ \brief Demonstration of some marking data point options.
+ \details Includes Quickbook markup.
+ \author Paul A Bristow
+*/
+
+// Copyright Jacob Voytko 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
+// or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+// An example to demonstrate some of the point plot markers available.
+
+// This file is written to be included from a Quickbook .qbk document.
+// It can be compiled by the C++ compiler, and run. Any output can
+// also be added here as comment or included or pasted in elsewhere.
+
+// Caution: this file contains Quickbook markup as well as code
+// and comments: don't change any of the special comment markups!
+
+//[demo_point_markers_1
+
+/*`As ever, we need a few includes to use Boost.Plot
+*/
+
+#include <boost/svg_plot/svg_1d_plot.hpp>
+ using namespace boost::svg;
+ using boost::svg::svg_1d_plot;
+
+#include <iostream>
+ using std::cout;
+ using std::endl;
+ using std::hex;
+
+#include <vector>
+ using std::vector;
+
+#include <limits>
+ using std::numeric_limits;
+
+//] [demo_point_markers_1]
+
+int main()
+{
+ vector<double> my_data;
+ my_data.push_back(-9.);
+ my_data.push_back(1.23);
+ my_data.push_back(numeric_limits<double>::infinity());
+ my_data.push_back(numeric_limits<double>::quiet_NaN());
+
+//[demo_point_markers_2
+
+ try
+ { // try'n'catch clocks are needed to ensure error messages from any exceptions are shown.
+ svg_1d_plot my_1d_plot; // Construct a plot with all the default constructor values.
+
+ my_1d_plot.title("Demo point markers Demo") // Add a string title of the plot.
+ .x_label("length (m)"); // Add a label for the X-axis.
+
+/*`Add the one data series, `my_data` and a description, and how the data points are to marked,
+here a circle with a diameter of 5 pixels.
+*/
+ my_1d_plot.plot(my_data, "1D Values").shape(diamond).size(10);
+
+ // TODO want to display ALL the possible markers - to check they all work too.
+
+/*`To put a value label against each data point, switch on the option:
+*/
+ my_1d_plot.x_values_on(true); // Add a label for the X-axis.
+
+/*`If the default size and color are not to your taste, set more options, like:
+*/
+ my_1d_plot.x_values_font_size(14) // Change font size for the X-axis value labels.
+ .x_values_font_family("Times New Roman") // Change font for the X-axis value labels.
+ .x_values_color(red); // Change color from default black to red.
+
+ /*` The 'at limit' values (infinity or NaN) markers can be customised, for example:
+ */
+ my_1d_plot.limit_color(red).limit_fill_color(green);
+
+ /*`To use all these settings, finally write the plot to file.
+*/
+ my_1d_plot.write("demo_point_markers.svg");
+
+/*`If chosen settings do not have the expected effect, is may be helpful to display them.
+
+(All settings can be displayed with `show_1d_plot_settings(my_1d_plot)`.)
+*/
+ cout << "my_1d_plot.x_values_font_size() " << my_1d_plot.x_values_font_size() << endl;
+ cout << "my_1d_plot.x_values_font_family() " << my_1d_plot.x_values_font_family() << endl;
+ cout << "my_1d_plot.x_values_color() " << my_1d_plot.x_values_color() << endl;
+ cout << "my_1d_plot.x_values_precision() " << my_1d_plot.x_values_precision() << endl;
+ cout << "my_1d_plot.x_values_ioflags() " << hex << my_1d_plot.x_values_ioflags() << endl;
+
+ cout << "limit points stroke color " << my_1d_plot.limit_color() << endl;
+ cout << "limit points fill color " << my_1d_plot.limit_fill_color() << endl;
+
+//] [demo_point_markers_2]
+ }
+ catch(const std::exception& e)
+ {
+ std::cout <<
+ "\n""Message from thrown exception was:\n " << e.what() << std::endl;
+ }
+ return 0;
+} // int main()
+
+/*
+
+//[demo_point_markers_output
+
+Output:
+
+Compiling...
+demo_point_markers.cpp
+Linking...
+Embedding manifest...
+Autorun "j:\Cpp\SVG\debug\demo_point_markers.exe"
+my_1d_plot.x_values_font_size() 14
+my_1d_plot.x_values_font_family() Times New Roman
+my_1d_plot.x_values_color() RGB(255,0,0)
+my_1d_plot.x_values_precision() 3
+my_1d_plot.x_values_ioflags() 200
+Build Time 0:02
+*/
+

Added: sandbox/SOC/2007/visualization/libs/svg_plot/example/demo_rounds.cpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/visualization/libs/svg_plot/example/demo_rounds.cpp 2009-03-05 11:26:10 EST (Thu, 05 Mar 2009)
@@ -0,0 +1,174 @@
+/*! \file demo_rounds.cpp
+ \brief Demonstration of rounding algorithm used for autoscaling.
+ \details
+ \author Paul A Bristow
+*/// demo_rounds.cpp
+
+// Copyright Paul A. Bristow 2006.
+
+// Use, modification and distribution are subject to the
+// Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt
+// or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#include <boost/svg_plot/detail/auto_axes.hpp>
+
+namespace boost
+{
+ namespace svg
+ {
+ // Demonstrate these functions.
+ double roundup10(double value); // 2, 5, 10
+ double rounddown10(double value);
+ double roundup5(double value); // 5, 10
+ double rounddown5(double value);
+ double roundup2(double value);
+ double rounddown2(double value); // 2, 4, 6, 8
+ } // namespace svg
+} // namespace boost
+
+
+#include <iostream>
+ using std::cout;
+ using std::endl;
+
+int main()
+{
+
+ using namespace boost::svg;
+
+ double r = roundup10(0.99);
+
+ cout << r << endl;
+
+ cout << "decimal roundup10" << endl;
+ cout << roundup10(0.99) << endl; // 1
+ cout << roundup10(9.4) << endl; // 10
+ cout << roundup10(0.000094) << endl; // 0.0001
+ cout << roundup10(5.1) << endl; // 1
+ cout << roundup10(4.9) << endl; // 10
+ cout << roundup10(0.000049) << endl; // 0.0001
+ cout << roundup10(4999.) << endl; // 5000
+ cout << roundup10(49.) << endl; // 40
+ cout << roundup10(1.2) << endl; // 2
+ cout << roundup10(0.0012) << endl; // 0.002
+ cout << roundup10(99.) << endl; // 100
+ cout << roundup10(101.) << endl; // 200
+ cout << roundup10(2.1) << endl; // 5
+ cout << roundup10(2.1) << endl; // 5
+ cout << rounddown10(1.9) << endl; // 1
+
+ cout << roundup2(1.1) << endl; // 2
+ cout << roundup2(0.9) << endl; // 1
+ cout << roundup2(2.1) << endl; // 2
+ cout << roundup2(3.1) << endl; // 4
+ cout << roundup2(4.1) << endl; // 4
+ cout << roundup2(5.1) << endl; // 6
+ cout << roundup2(7.1) << endl; // 8
+ cout << roundup2(1.1e-3) << endl; // 0.0011 - 0.002
+ cout << roundup2(0.9e-3) << endl; // 0.001
+ cout << roundup2(2.1e-3) << endl; // 0.004
+ cout << roundup2(3.1e-3) << endl; // 0.004
+ cout << roundup2(4.1e-3) << endl; //
+ cout << roundup2(7.1e-3) << endl; //
+ cout << roundup2(1.1e+3) << endl; // 2000
+ cout << roundup2(0.9e+3) << endl; //
+ cout << roundup2(2.1e+3) << endl; //
+ cout << roundup2(3.1e+3) << endl; //
+ cout << roundup2(4.1e+3) << endl; //
+ cout << roundup2(7.1e+3) << endl; //
+ cout << rounddown2(2.1) << endl; // 2
+ cout << rounddown2(4.1) << endl; // 2
+
+ cout << "5 & 10 roundup10 " << endl;
+ cout << roundup5(1.1) << endl; // 5
+ cout << roundup5(0.9) << endl; // 1
+ cout << roundup5(2.1) << endl; // 5
+ cout << roundup5(3.1) << endl; // 5
+ cout << roundup5(4.1) << endl; // 5
+ cout << roundup5(5.1) << endl; // 10
+ cout << roundup5(7.1) << endl; // 10
+ cout << roundup5(1.1e-3) << endl; //
+ cout << roundup5(0.9e-3) << endl; //
+ cout << roundup5(2.1e-3) << endl; //
+ cout << roundup5(3.1e-3) << endl; //
+ cout << roundup5(4.1e-3) << endl; //
+ cout << roundup5(7.1e-3) << endl; // 0.01
+ cout << roundup5(1.1e+3) << endl; // 5000
+ cout << roundup5(0.9e+3) << endl; // 1000
+ cout << roundup5(2.1e+3) << endl; // 5000
+ cout << roundup5(3.1e+3) << endl; // 5000
+ cout << roundup5(4.1e+3) << endl; // 5000
+ cout << roundup5(7.1e+3) << endl; // 10000
+ cout << rounddown5(4.1) << endl; // 5
+ cout << rounddown5(5.1) << endl; // 5
+
+return 0;
+
+} // int main()
+
+/*
+
+Autorun "j:\Cpp\SVG\debug\demo_rounds.exe"
+decimal roundup10
+1
+10
+0.0001
+10
+5
+5e-005
+5000
+50
+2
+0.002
+100
+200
+5
+binary roundup10
+2
+1
+4
+4
+6
+6
+8
+0.002
+0.001
+0.004
+0.004
+0.006
+0.008
+2000
+1000
+4000
+4000
+6000
+8000
+5
+1
+5
+5
+5
+10
+10
+0.005
+0.001
+0.005
+0.005
+0.005
+0.01
+5000
+1000
+5000
+5000
+5000
+10000
+5
+1
+2
+4
+5
+5
+
+
+*/

Added: sandbox/SOC/2007/visualization/libs/svg_plot/example/demo_svg.cpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/visualization/libs/svg_plot/example/demo_svg.cpp 2009-03-05 11:26:10 EST (Thu, 05 Mar 2009)
@@ -0,0 +1,309 @@
+/*! \file demo_svg.cpp
+ \brief Demonstration of a few facets of using the SVG interface directly.
+ \details This only demonstrates a very few of the possible features because most users will only need to use the plot interfaces.
+ But this might provide a little guidance for producing other diagrams and drawings.
+ This module is to demonstrate features of the svg class.
+ It is entirely contrived and has no other conceivable use!
+ \author Paul A. Bristow
+ \date 20 Feb 2009
+*/
+// Copyright Paul A Bristow 2007
+
+// Use, modification and distribution are subject to the
+// Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt
+// or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+
+#ifdef _MSC_VER
+#pragma warning(disable : 4267) // '=' : conversion from 'size_t' to 'unsigned int'
+#pragma warning(disable : 4172) //
+#pragma warning(disable : 4510) // 'boost::array<T,N>' : default constructor could not be generated
+#pragma warning(disable : 4512) // 'boost::array<T,N>' : assignment operator could not be generated
+#pragma warning(disable : 4610) // class 'boost::array<T,N>' can never be instantiated - user defined constructor required
+#pragma warning(disable : 4189) // local variable is initialized but not referenced
+#endif
+
+#include <boost/svg_plot/svg.hpp>
+ using boost::svg::svg;
+ using boost::svg::g_element;
+ using boost::svg::rect_element;
+
+#include <boost/svg_plot/svg_fwd.hpp>
+
+ using namespace boost::svg;
+ // Is most convenient because otherwise all the colors used must be specified thus
+ using boost::svg::black;
+ using boost::svg::white;
+ using boost::svg::red;
+ // ... which may get tedious!
+
+#include <iostream>
+ using std::cout;
+ using std::endl;
+ using std::boolalpha;
+
+#include <vector>
+ using std::vector;
+
+#include <string>
+ using std::string;
+
+#include <boost/array.hpp>
+ using boost::array;
+
+void symb(array<const poly_path_point, 6> shape, const poly_path_point position, const poly_path_point size, g_element& g)
+{
+ vector<poly_path_point> shaped;
+ for(array<const poly_path_point, 6>::iterator i = shape.begin(); i != shape.end(); ++i)
+ {
+ poly_path_point p = (*i);
+ p.x *= size.x;
+ p.y *= size.y;
+ p.x += position.x;
+ p.y += position.y;
+ std::cout << p << endl;
+ shaped.push_back(p);
+ }
+ cout << endl;
+ // Can't return ref to shape because goes out of scope :-(
+ g.push_back(new polygon_element(shaped, true) );
+ return;
+} // vector<poly_path_point>& symb
+
+int main()
+{
+ svg my_svg;
+ // Check default and change image size.
+ cout << "my_svg.x_size() = " << my_svg.x_size() << ", my_svg.y_size() = " << my_svg.y_size() << endl;
+ // my_svg.x_size() = 400, my_svg.y_size() = 400
+ my_svg.size(500, 600);
+ cout << "my_svg.x_size() = " << my_svg.x_size() << ", my_svg.y_size() = " << my_svg.y_size() << endl;
+ // my_svg.x_size() = 500, my_svg.y_size() = 600
+
+ boost::svg::text_element t;
+ t.textstyle().font_family("arial");
+ cout << t.textstyle().font_family() << endl; // arial
+
+ my_svg.license("permits", "permits", "permits", "permits");
+ my_svg.license_on(true);
+ cout << boolalpha << "my_svg.license_on() " << my_svg.license_on() << endl;
+
+ my_svg.boost_license_on(true);
+ cout << "my_svg.boost_license_on() " << my_svg.boost_license_on() << endl;
+
+ my_svg.image_filename("demo_svg");
+ cout << "my_svg.image_filename() " << my_svg.image_filename() << endl;
+
+ // Default background color is black, rgb(0,0,0)
+ // Draw background. detail::PLOT_BACKGROUND == 0
+ // my_svg.g(0).push_back(new rect_element(0, 0, my_svg.x_size(), my_svg.y_size() ) );
+ // background
+
+ // g_element& a1 =
+ my_svg.g(); // Add first (zeroth) new element,
+ g_element& g0 = my_svg.g(0); // so index is zero.
+ my_svg.g(0).push_back(new rect_element(0, 0, my_svg.x_size(), my_svg.y_size() ) ); // border to image.
+ cout << "my_svg.document_size() = number of g_elements = " << my_svg.document_size() << endl;
+ g0.id("element 0");
+ cout << g0.id() << endl;
+ cout << "fill color = " << g0.style().fill_color() << endl; // fill color = RGB(0,0,0) == black
+ cout << "fill on " << boolalpha << g0.style().fill_on() << endl; // false
+ cout << "stroke color = " << g0.style().stroke_color() << endl; // stroke color = RGB(0,0,0)
+ cout << "stroke on " << boolalpha << g0.style().stroke_on() << endl; // stroke on false
+ cout << "stroke width " << boolalpha << g0.style().stroke_width() << endl; //
+ g0.style().stroke_on(true); // stroke on true
+ g0.style().stroke_color(red); //
+ g0.style().stroke_width(5);
+ cout << "width = " << g0.style().stroke_width() << endl;
+ g0.style().fill_on(true); // stroke on true
+ g0.style().fill_color(azure); //
+ cout << "fill color = " << g0.style().fill_color() << endl; // fill color = RGB(0,0,0) == black
+ cout << "fill on " << boolalpha << g0.style().fill_on() << endl; // false
+ cout << "stroke color = " << g0.style().stroke_color() << endl; // stroke color = RGB(0,0,0)
+ cout << "stroke on " << boolalpha << g0.style().stroke_on() << endl; // stroke on false
+ cout << "width on " << boolalpha << g0.style().width_on() << endl;
+ g0.style().stroke_on(true); // stroke on true
+ //<g stroke="rgb(255,0,0)" fill="rgb(255,255,255)" stroke-width="10"><rect x="0" y="0" width="500" height="600"/></g>
+
+ g_element& g2 = my_svg.g(0); // should be g0 == g2 but no operator==, yet.
+
+ rect_element r(20, 20, 50, 50);
+ cout << r << endl; // rect(20, 20, 50, 50)
+
+ g0.push_back(new line_element(100, 50, 50, 100) ); // red border width 10 white fill.
+ // <g stroke="rgb(255,0,0)" fill="rgb(0,0,255)" stroke-width="10"><line x1="100" y1="50" x2="50" y2="100"/></g>
+ g0.push_back(new rect_element(20, 20, 50, 50) ); //
+ g0.push_back(new polygon_element(30, 40, true) );
+ g0.push_back(new circle_element(100, 200, 10) ); //
+ g0.push_back(new ellipse_element(300, 300, 5, 3) ); //
+ my_svg.ellipse(300, 300, 50, 30); // has similar effect, but since not in group, is black stroke & fill.
+
+ //Note: my_svg.line(100, 50, 50, 100); // only generates <line x1="100" y1="50" x2="50" y2="100"/>
+ // which doesn't show anything!
+ // Because is lacking stroke-width and stroke (color), whereas
+ // <line stroke-width="5" stroke="red" x1="100" y1="300" x2="300" y2="100"/>
+
+ poly_path_point p0(100, 200);
+ cout << p0 << endl; // Ouptuts: (100, 200)
+
+ path_element my_path;
+ my_path.M(1, 2).L(3, 4).L(5, 6).z();
+ path_element& my_path2 = my_svg.g(0).path();
+ path_element& my_path0 = g0.path();
+ my_path2.M(1, 2).L(3, 6).L(5, 4).z(); // <path d="M1,2 L3,4 L5,6 Z " />
+ path_element& path = g0.path(); // OK
+
+ polygon_element& pp = g0.polygon(); // 'empty' polygon.
+ polygon_element& ppp(pp); // copy constructor.
+ pp.P(400, 500); // Add a single vertex.
+ pp.P(200, 300).P(100, 400).P(100, 100); // add several vertices.
+
+ my_svg.triangle(400, 20, 300, 100, 450, 50, false);
+ my_svg.triangle(200, 20, 350, 100, 250, 100);
+ my_svg.rhombus(10, 500, 10, 550, 450, 550, 300, 500, true);
+ my_svg.pentagon(100, 10, 120, 10, 130, 30, 110, 50, 110, 30, true);
+ my_svg.hexagon(300, 10, 420, 10, 330, 130, 350, 150, 210, 30, 250, 60, true);
+
+ array<const poly_path_point, 12> hexagram =
+ { // six point star 6/2 ("Star of David")
+ poly_path_point(0., -4.), poly_path_point(+1., -2.),
+ poly_path_point(+3., -2.), poly_path_point(+2, 0),
+ poly_path_point(+3, +2), poly_path_point(+1, +2),
+ poly_path_point(0, 4), poly_path_point(-1, +2),
+ poly_path_point(-3, +2), poly_path_point(-2, 0),
+ poly_path_point(-3, -2), poly_path_point(-1, -2)
+ };
+
+ vector<poly_path_point> star;
+ poly_path_point offset(300., 300);
+ poly_path_point size(50., 50);
+ for(array<const poly_path_point, 12>::iterator i = hexagram.begin(); i != hexagram.end(); ++i)
+ {
+ poly_path_point p = (*i);
+ p.write(std::cout);
+ p.x *= size.x;
+ p.y *= size.y;
+ p.x += offset.x;
+ p.y += offset.y;
+ star.push_back(p);
+ }
+ cout << endl;
+
+ for(vector<poly_path_point>::iterator i = star.begin(); i != star.end(); ++i)
+ {
+ poly_path_point p = (*i);
+ p.write(std::cout);
+ }
+ cout << endl;
+
+ g0.push_back(new polygon_element(star, true) );
+
+ vector<poly_path_point> my_p;
+ my_p.push_back(poly_path_point(10, 20));
+ my_p.push_back(poly_path_point(70, 80));
+ my_p.push_back(poly_path_point(50, 60));
+ my_p.push_back(poly_path_point(90, 100));
+ my_p.push_back(poly_path_point(30, 40));
+ my_p.push_back(poly_path_point(110, 120));
+
+ for(vector<poly_path_point>::iterator i = my_p.begin(); i != my_p.end(); ++i)
+ {
+ poly_path_point p = (*i);
+ p.write(std::cout);
+ }
+ cout << endl;
+
+ g0.push_back(new polygon_element(my_p, true) );
+ my_svg.polygon(my_p, true); // 'filled' polygon.
+
+ //polygon_element& my_poly = my_svg.polygon(10, 20, true);
+ //my_poly.p(100, 100); // just one point
+ //my_poly.p(200, 100).p(300, 200).p(400,300); // <polygon points=" 11,22 33,44 55,66"/>
+ //my_svg.g(); // Add 2nd new element,
+ g_element& g1 = my_svg.g(1); // so index is now one.
+ g1.id("element 1");
+ cout << g1.id() << endl; // Output: element 1
+
+ // This line aborts:
+ //polyline_element& pl = g1.polyline(); // 'empty' line.
+ // my_poly.P(123.456789, 123.456789); // just one point
+ // my_poly.P(123.456789, 123.456789, 12., 34.); // just one point
+ //pl.P(234.5679, 123.456789).P(300.5678, 200.12345).P(400,400); // <polyline points=" 100,100 200,100 300,100 400,0" fill = "none"/>
+
+ // 5-point Star (values from from http://www.w3.org/TR/SVG/shapes.html#PolygonElement)
+ vector<poly_path_point> star_5;
+ // Push_back the 10 path points.
+ star_5.push_back(poly_path_point(350, 75));
+ star_5.push_back(poly_path_point(379, 161));
+ star_5.push_back(poly_path_point(469, 161));
+ star_5.push_back(poly_path_point(397, 215));
+ star_5.push_back(poly_path_point(423, 301));
+ star_5.push_back(poly_path_point(350, 250));
+ star_5.push_back(poly_path_point(277, 301));
+ star_5.push_back(poly_path_point(303, 215));
+ star_5.push_back(poly_path_point(231, 161));
+ star_5.push_back(poly_path_point(321, 161));
+
+ //g0.polygon(star_5, true);
+ polygon_element pstar(star_5, true); // OK - construct from vector
+ g0.push_back(new polygon_element(star_5, true) );
+
+ // Hexagon
+
+ //cout.precision(17);
+ //double pi = 3.14159265359;
+ //cout << cos(pi/6) << endl; // == cos(30)
+ // == 0.86602540378442139;
+
+ array<const poly_path_point, 6> hexup =
+ { // Regular point up hexagon!
+ poly_path_point(0, -1),
+ poly_path_point(0.86602540378442139, -0.5),
+ poly_path_point(0.86602540378442139, +0.5),
+ poly_path_point(0., +1.),
+ poly_path_point(-0.86602540378442139, +0.5),
+ poly_path_point(-0.86602540378442139, -0.5)
+ };
+
+ for(array<const poly_path_point, 6>::iterator i = hexup.begin(); i != hexup.end(); ++i)
+ {
+ cout << (*i) << endl;
+ }
+ cout << endl;
+
+ //g0.push_back(new polygon_element(hex, true) );
+
+ {
+ symb(hexup, poly_path_point(75., 450.), poly_path_point(10., 10.), g0); // OK construct from array of consts
+ }
+
+ my_svg.write("demo_svg.svg");
+
+ return 0;
+} // int main()
+
+/*
+
+ svg my_svg;
+ my_svg .write("demo_svg.svg");
+
+?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/graphics/svg/1.1/dtd/svg11.dtd">
+<svg width="400" height ="400" version="1.1" xmlns="http://www.w3.org/2000/svg">
+<!-- SVG plot written using Boost.Plot program (Creator Jacob Voytko) -->
+<!-- Use, modification and distribution of Boost.Plot subject to the -->
+<!-- Boost Software License, Version 1.0.-->
+<!-- (See accompanying file LICENSE_1_0.txt -->
+<!-- or copy at http://www.boost.org/LICENSE_1_0.txt) -->
+
+<!-- File test_svg.svg -->
+</svg>
+
+
+
+
+
+
+
+
+*/

Added: sandbox/SOC/2007/visualization/libs/svg_plot/example/svg_test_boxplot.cpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/visualization/libs/svg_plot/example/svg_test_boxplot.cpp 2009-03-05 11:26:10 EST (Thu, 05 Mar 2009)
@@ -0,0 +1,71 @@
+/*! \file svg_test_boxplot.cpp
+ \brief Tests for svg boxplot.
+ \details
+
+ \author Jacob Voytko and Paul A. Bristow
+*/
+
+// Copyright Jacob Voytko 2007
+// Copyright Paul A. Bristow 2007
+
+// Use, modification and distribution are subject to the
+// Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt
+// or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#include <boost/svg_plot/svg_1d_plot.hpp>
+#include <boost/svg_plot/svg_boxplot.hpp>
+
+#include <vector>
+using std::vector;
+#include <map>
+using std::multimap;
+#include <cmath>
+using ::sin;
+#include <iostream>
+using std::cout;
+using std::endl;
+
+double h(double x)
+{
+ return 50 / (x);
+}
+
+double f(double x)
+{
+ return 40 + 25 * sin(x * 50);
+}
+
+int main()
+{
+ using namespace boost::svg;
+ std::vector<double> data1, data2;
+
+ for(double i=.1; i < 10; i+=.1)
+ { // Fill the vectors with some data.
+ data1.push_back(h(i));
+ data2.push_back(f(i));
+ }
+
+ svg_1d_plot my_1d_plot;
+ my_1d_plot.background_border_color(black)
+ .title("1D plots of Common Functions");
+ my_1d_plot.plot(data1, "[50 / x]");
+ my_1d_plot.plot(data2, "[40 + 25 * sin(50x)]");
+
+ my_1d_plot.write("./svg_test_1d.svg");
+
+ // Now plot the same data using boxplot.
+ svg_boxplot my_box_plot;
+ my_box_plot.background_border_color(black)
+ .title("Boxplots of Common Functions");
+
+ my_box_plot.plot(data1, "[50 / x]");
+ my_box_plot.plot(data2, "[40 + 25 * sin(50x)]");
+ my_box_plot.y_autoscale(data1); // Compute autoscale values for the plot.
+
+
+ my_box_plot.write("./svg_test_boxplot.svg");
+ return 0;
+} // int main()
+


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