Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r55406 - sandbox/SOC/2007/visualization/libs/svg_plot/example
From: pbristow_at_[hidden]
Date: 2009-08-04 13:39:56


Author: pbristow
Date: 2009-08-04 13:39:55 EDT (Tue, 04 Aug 2009)
New Revision: 55406
URL: http://svn.boost.org/trac/boost/changeset/55406

Log:
Added more examples. Problem with plotting tan function remains.
Added:
   sandbox/SOC/2007/visualization/libs/svg_plot/example/demo_1d_tick_values.cpp (contents, props changed)
   sandbox/SOC/2007/visualization/libs/svg_plot/example/demo_2d_area_fill.cpp (contents, props changed)
   sandbox/SOC/2007/visualization/libs/svg_plot/example/demo_2d_fonts.cpp (contents, props changed)
   sandbox/SOC/2007/visualization/libs/svg_plot/example/demo_2d_tick_values.cpp (contents, props changed)
   sandbox/SOC/2007/visualization/libs/svg_plot/example/demo_2d_weather.cpp (contents, props changed)
Text files modified:
   sandbox/SOC/2007/visualization/libs/svg_plot/example/2d_area_fill.cpp | 3 +
   sandbox/SOC/2007/visualization/libs/svg_plot/example/demo_svg.cpp | 6 ++--
   sandbox/SOC/2007/visualization/libs/svg_plot/example/svg_colors.cpp | 56 ++++++++++++++++++++++++++++++++-------
   3 files changed, 51 insertions(+), 14 deletions(-)

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 2009-08-04 13:39:55 EDT (Tue, 04 Aug 2009)
@@ -99,7 +99,7 @@
   svg_2d_plot_series& s_sin = my_plot.plot(data_sin, "sin(x)").line_on(true).area_fill(red);
   std::cout << "s_sin.area_fill() " << s_sin.area_fill() << std::endl; // s_sin.area_fill() RGB(255,0,0)
 
- svg_2d_plot_series& s_cos = my_plot.plot(data_cos, "cos(x)").line_on(true).area_fill(blue).shape(square);
+ svg_2d_plot_series& s_cos = my_plot.plot(data_cos, "cos(x)").line_on(true).area_fill(blue).shape(square);
   std::cout << "s_cos.area_fill() " << s_cos.area_fill() << std::endl; // s_cos.area_fill() RGB(0,0,255)
 
   svg_2d_plot_series& s_tan = my_plot.plot(data_tan, "tan(x)").shape(cone).line_on(true).area_fill(blank);
@@ -110,6 +110,7 @@
 
   my_plot.write("./2d_area_fill_1.svg");
 
+
   my_plot.plot(data_sin, "sin(x)").line_on(true).area_fill(green).shape(square).fill_color(red);
   // Note how this overwrites the previously cos fill and tan line.
   // (It also needs a new title).

Added: sandbox/SOC/2007/visualization/libs/svg_plot/example/demo_1d_tick_values.cpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/visualization/libs/svg_plot/example/demo_1d_tick_values.cpp 2009-08-04 13:39:55 EDT (Tue, 04 Aug 2009)
@@ -0,0 +1,176 @@
+/*! \file demo_1d_tick_values.cpp
+ \brief Demonstration of some simple 1D tick value label formatting.
+ \details Quickbook markup to include in documentation.
+ \date 19 Jul 2009
+ \author Paul A. Bristow
+*/
+
+// Copyright Paul A Bristow 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 simple 1D settings but tick value formatting.
+// See also demo_1d_plot.cpp for a wider 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_1d_tick_values_1
+
+/*`As ever, we need a few includes to use Boost.Plot and an STL container.
+*/
+//] [demo_1d_tick_values_1]
+
+#include <boost/svg_plot/svg_1d_plot.hpp>
+ using namespace boost::svg;
+ using boost::svg::svg_1d_plot;
+
+ #include <boost/svg_plot/show_1d_settings.hpp>
+// using boost::svg::show_1d_plot_settings - Only needed for showing which settings in use.
+
+#include <iostream>
+ using std::cout;
+ using std::endl;
+ using std::hex;
+ using std::dec;
+ using std::ios_base;
+ using std::fixed;
+ using std::scientific;
+
+#include <iomanip>
+ using std::setprecision;
+ using std::setiosflags;
+
+#include <vector>
+ using std::vector;
+
+int main()
+{
+ //[demo_1d_tick_values_2
+/*`Some fictional data is pushed into an STL container, here vector<double>:*/
+ vector<double> my_data;
+ my_data.push_back(-1.6);
+ my_data.push_back(4.2563);
+ my_data.push_back(0.00333974);
+ my_data.push_back(5.4);
+ my_data.push_back(6.556);
+
+ 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("Demo 1D Tick Values") // Add a string title of the plot.
+ .x_range(-5, 10) // Add a range for the X-axis.
+ .x_label("temp (&#x00B0;C)"); // Add a label for the X-axis, using Unicode degree symbol.
+
+/*`Add the one data series, `my_data` and a description,
+and how the data points are to be marked, a circle with a diameter of 7 pixels.
+*/
+ my_1d_plot.plot(my_data, "1D Values").shape(round).size(7);
+
+/*`If the default size and color are not to your taste, set more options, like:
+*/
+ my_1d_plot.size(500, 150) // Change plot window from the default image size.
+ // Change the X-axis label style:
+ .x_axis_label_color(green)
+ .x_label_font_family("Arial")
+ .x_label_font_size(18)
+
+ // Change the style of the X (major) ticks:
+ .x_ticks_values_color(magenta)
+ //.x_ticks_values_font_family("Times New Roman")
+ .x_ticks_values_font_family("arial")
+ .x_ticks_values_font_size(15)
+
+/*`The format of the tick value labels may not suit your data and its range,
+so we can use the normal `iostream precision` and `ioflags` to change,
+here to reduce the number of digits used from default precision 6 down to a more readable 2,
+reducing the risk of collisions between adjacent values.
+If values are very close to each other (a small range on the axis),
+a higher precision wil be needed to differentiate them).
+We could also prescribe the use of scientific format and force a positive sign:
+By default, any unnecessary spacing-wasting zeros in the exponent field are removed.
+
+If, perversely, the full 1.123456e+012 format is required, the stripping can be switched off with:
+ `my_1d_plot.x_ticks_values_strip_e0s(false);`
+*/
+ // Change the format from the default "-4", "-2", "0" "2", "4" ...
+ // (which makes a 'best guess' at the format)
+ // to "-4.00", "-2.00", ..."+2.00", "4.00"
+ // showing trailing zeros and a leading positive sign.
+ .x_ticks_values_ioflags(ios_base::fixed | std::ios::showpos)
+ .x_ticks_values_precision(1) //
+
+ // One could use ios_base::scientific for e format.
+ //.x_ticks_values_ioflags(ios_base::fixed | std::ios::showpos )
+ //.x_ticks_values_ioflags(std::ios::showpoint | std::ios::showpos)
+ //.x_ticks_values_ioflags(std::ios::scientific)
+ ;
+
+/*`To use all these settings, finally write the plot to file.
+*/
+ my_1d_plot.write("demo_1d_tick_values.svg");
+
+/*`If chosen settings do not have the effect that you expect, it may be helpful to display them.
+
+(All the myriad settings can be displayed with `show_1d_plot_settings(my_1d_plot)`.)
+*/
+ //show_1d_plot_settings(my_1d_plot);
+
+ cout << "my_1d_plot.image_size() " << my_1d_plot.image_size() << endl;
+ cout << "my_1d_plot.image_x_size() " << my_1d_plot.image_x_size() << endl;
+ cout << "my_1d_plot.image_y_size() " << my_1d_plot.image_y_size() << endl;
+
+ cout << "my_1d_plot.x_axis_label_color() " << my_1d_plot.x_axis_label_color() << endl;
+ cout << "my_1d_plot.x_label_font_family() " << my_1d_plot.x_label_font_family() << endl;
+ cout << "my_1d_plot.x_label_font_size() " << my_1d_plot.x_label_font_size() << endl;
+
+ cout << "my_1d_plot.x_ticks_values_font_family() " << my_1d_plot.x_ticks_values_font_family() << endl;
+ cout << "my_1d_plot.x_ticks_values_font_size() " << my_1d_plot.x_ticks_values_font_size() << endl;
+ cout << "my_1d_plot.x_ticks_values_color() " << my_1d_plot.x_ticks_values_color() << endl;
+
+ cout << "my_1d_plot.x_ticks_values_precision() " << my_1d_plot.x_ticks_values_precision() << endl;
+ cout << "my_1d_plot.x_ticks_values_ioflags() " << hex << my_1d_plot.x_ticks_values_ioflags() << endl;
+
+/*`See demo_1d_ticks_values.cpp for full source code.
+*/
+
+//] [demo_1d_tick_values_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_tick_values_output
+
+Output:
+
+utorun "j:\Cpp\SVG\Debug\demo_1d_ticks_values.exe
+my_1d_plot.image_size() 500, 150
+my_1d_plot.image_x_size() 500
+my_1d_plot.image_y_size() 150
+my_1d_plot.x_axis_label_color() RGB(0,128,0)
+my_1d_plot.x_label_font_family() Arial
+my_1d_plot.x_label_font_size() 18
+my_1d_plot.x_ticks_values_font_family() Verdana
+my_1d_plot.x_ticks_values_font_size() 12
+my_1d_plot.x_ticks_values_color() RGB(255,0,255)
+my_1d_plot.x_ticks_values_precision() 1
+my_1d_plot.x_ticks_values_ioflags() 2020
+
+//] [demo_1d_tick_values_output]
+
+*/

Added: sandbox/SOC/2007/visualization/libs/svg_plot/example/demo_2d_area_fill.cpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/visualization/libs/svg_plot/example/demo_2d_area_fill.cpp 2009-08-04 13:39:55 EDT (Tue, 04 Aug 2009)
@@ -0,0 +1,168 @@
+/*! \file 2d_area_fill.cpp
+ \brief Demonstration of area fill below curves.
+ \details Using some trig functions to show how to area fill.
+
+ \date 2009
+ \author Jacob Voytko and Paul A. Bristow
+*/
+
+// Copyright Jacob Voytko 2007
+// Copyright Paul A. Bristow 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)
+
+#include <boost/svg_plot/svg_2d_plot.hpp>
+ using namespace boost::svg; // Needed to get svg colors and others.
+ using boost::svg::svg_2d_plot;
+
+#include <map>
+ using std::map; // STL container for data.
+#include <cmath>
+ using std::sin;
+ using std::cos;
+ using std::tan;
+
+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> data_sin; // Containers for some trig data.
+ map<double, double> data_cos;
+ map<double, double> data_tan;
+
+ double inter = 3.14159265358979 / 8.; // 16 points per cycle of 2 pi.
+ // Problem here if pi is more accurate (adding 3 at end) = 3.141592653589793
+ // tan line - going to infinity and back does not show.
+ // This is because tan is at +infinity or -infinity.
+ // tan is very badly behaved and floating-point is evil!
+
+ for(double i = 0; i <= 10.; i += inter)
+ { //
+ data_sin[i] = my_sin(i);
+ data_cos[i] = my_cos(i);
+ data_tan[i] = my_tan(i);
+
+ cout << i << ' '<< data_tan[i] << endl;
+
+ } // for
+
+ svg_2d_plot my_plot;
+
+ // Size/scale settings.
+ my_plot.size(700, 500)
+ .x_range(-1, 10)
+ .y_range(-75, 75);
+
+ // Text settings.
+ my_plot.title("Plot of 50 * sin(x), cos(x) and tan(x)")
+ .title_font_size(20)
+ .title_color(red)
+ .x_label("x")
+ .y_label("50 * f(x)")
+ .x_major_labels_side(bottom) // X axis label below bottom of plot window (default).
+ .y_major_labels_side(left) // Y axis label to left of plot window (default).
+ .x_major_grid_on(true) // Use grids.
+ .y_major_grid_on(true)
+ .x_major_grid_color(cyan)
+ .y_major_grid_color(cyan)
+ ;
+
+ // Color settings.
+ my_plot.background_color(whitesmoke)
+ .legend_background_color(lightyellow)
+ .legend_border_color(yellow)
+ .plot_background_color(ghostwhite)
+ ;
+ // X axis settings.
+ my_plot.x_major_interval(2)
+ .x_major_tick_length(14)
+ .x_major_tick_width(1)
+ .x_minor_tick_length(7)
+ .x_minor_tick_width(1)
+ .x_num_minor_ticks(3)
+
+ // Y axis settings.
+ .y_major_interval(25)
+ .y_num_minor_ticks(4); // 4 minor ticks between 0 to 25, so mark major 0, minor 5, 10, 15, 20, major 25 ...
+
+ svg_2d_plot_series& s_sin = my_plot.plot(data_sin, "sin(x)").line_on(true).area_fill(red);
+ std::cout << "s_sin.area_fill() " << s_sin.area_fill() << std::endl; // s_sin.area_fill() RGB(255,0,0)
+
+ svg_2d_plot_series& s_cos = my_plot.plot(data_cos, "cos(x)").line_on(true).area_fill(blue).shape(square);
+ std::cout << "s_cos.area_fill() " << s_cos.area_fill() << std::endl; // s_cos.area_fill() RGB(0,0,255)
+
+ svg_2d_plot_series& s_tan = my_plot.plot(data_tan, "tan(x)").shape(cone).line_on(true).area_fill(blank);
+ // Note that svg_color(blank) or svg_color(false) returns a non-color blank, so no fill.
+ std::cout << "s_tan.area_fill() " << s_tan.area_fill() << std::endl; // s_tan.area_fill() blank
+
+ std::cout << my_plot.title() << std::endl; // "Plot of 50 * sin(x), cos(x) and tan(x)"
+
+ my_plot.write("./demo_2d_area_fill_1.svg");
+
+ my_plot.plot(data_sin, "sin(x)").line_on(true).area_fill(green).shape(square).fill_color(red);
+ // Note how this overwrites the previously cos fill and tan line.
+ // (It also needs a new title).
+
+ my_plot.title("sin overwriting cos and tan");
+ std::cout << my_plot.title() << std::endl; // "sin overwriting cos and tan"
+
+ my_plot.write("./demo_2d_area_fill_2.svg");
+
+ return 0;
+} // int main()
+
+/*
+
+Output:
+
+Autorun "j:\Cpp\SVG\Debug\demo_2d_area_fill.exe
+0 0
+0.392699 20.7107
+0.785398 50
+1.1781 120.711
+1.5708 3.09493e+016
+1.9635 -120.711
+2.35619 -50
+2.74889 -20.7107
+3.14159 -1.61554e-013
+3.53429 20.7107
+3.92699 50
+4.31969 120.711
+4.71239 1.08118e+016
+5.10509 -120.711
+5.49779 -50
+5.89049 -20.7107
+6.28319 -3.23109e-013
+6.67588 20.7107
+7.06858 50
+7.46128 120.711
+7.85398 6.02427e+015
+8.24668 -120.711
+8.63938 -50
+9.03208 -20.7107
+9.42478 -3.73641e-013
+9.81748 20.7107
+s_sin.area_fill() RGB(255,0,0)
+s_cos.area_fill() RGB(0,0,255)
+s_tan.area_fill() blank
+Plot of 50 * sin(x), cos(x) and tan(x)
+sin overwriting cos and tan
+
+
+*/

Added: sandbox/SOC/2007/visualization/libs/svg_plot/example/demo_2d_fonts.cpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/visualization/libs/svg_plot/example/demo_2d_fonts.cpp 2009-08-04 13:39:55 EDT (Tue, 04 Aug 2009)
@@ -0,0 +1,380 @@
+/*! \file demo_2d_fonts.cpp
+ \brief Example of changing font and sizes.
+ \details Creates file demo_2d_fonts.svg
+ \author Paul A. Bristow
+ \date Jul 2009
+ */
+
+// Copyright Paul A. Bristow 2009
+
+// Distributed under the Boost Software License, Version 1.0.
+// For more information, see http://www.boost.org
+
+// An example to demonstrate various fonts and font sizes.
+
+// 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_fonts_1
+
+/*`
+
+The conventional wisdom of sticking to one or two fonts are deliberately broken
+to show various fonts and sizes that are available for SVG plots.
+The result is a graphic designers nightmare!
+
+A font family may or may not be available for a particular internet browser,
+so it is inevitable that the exact appearance of a SVG plot may vary when
+viewed with different browsers. If a font family is not recognised, then
+a default (for that browser) will be used instead.
+
+The font families available for browsers do not seem to be listed,
+but those used below are available on Mozilla Firefox 3.5.
+The example below looks very similar with the Adobe SVG Add-in with Microsoft Internet Explorer 8
+(which does NOT render SVG natively at all), and with Inkscape and Opera.
+
+Mozilla Firefox 3.5 allows one to add font(s), but how these are rendered with SVG is not so clear.
+
+For most purposes the default Font family Verdana looks fine.
+
+The following font families work with Firefox 3.5:
+
+arial", "impact", "courier", "lucida console", "Lucida sans unicode", "verdana", "calibri", "century", "lucida calligraphy", "tahoma", "vivaldi"
+"informal roman", "lucida handwriting", "lucida bright", "helvetica"
+"arial narrow" is narrow, so may be useful to fit a long title or label.
+"arial black" is black!
+
+These do NOT work and are substituted:
+
+"comic sans", "sans" "bauhaus" "brush script" "segeo condensed" = Serif
+
+The narrow, wide, bold and italic features produce rather variable and unpredictable results
+- the rendering may be 'fuzzy' or ill-formed: so these are not recommended. For example,
+
+"Times New Roman Bold" "Times New Roman Italic" are substituted by "Times New Roman"
+
+But to get narrow characters "arial narrow" works well, allowing a longer title or label.
+
+The font sizes are also changes from the defaults. This should change the positioning,
+but the calculations are complex and necessarily approximate.
+Collisions between labels, other value labels and axes are not impossible,
+especially when the tick value labels are not horizontal.
+
+By default, the std::precision is reduced from the default 6 to 3, and unnecessary zeros and signs are stripped.
+
+But it will still often be necessary to change the std::iosflags and std::precision,
+and/or the number of major ticks and/or font size and type to avoid tick value label collisions.
+
+Unicode symbols can be found at http://en.wikipedia.org/wiki/Unicode_symbols.
+The 4 hex digit value needs to be wrapped with prefix &#x and suffix ; like &#xDDDD;
+Rendering of Unicode symbols is not entirely predictable, but usually works well
+to provide a wide range of greek and math symbols.
+
+
+*/
+//] [/demo_2d_fonts_1]
+
+#include <boost/svg_plot/svg_2d_plot.hpp>
+using namespace boost::svg;
+#include <boost/svg_plot/detail/pair.hpp>
+ using boost::svg::detail::operator<<; // Output pair as, for example: 1.23, 4.56
+
+#include <iostream>
+ using std::cout;
+ using std::endl;
+ using std::ios_base;
+ using std::dec;
+ using std::hex;
+#include <map>
+ using std::map; // 2D data container.
+
+ double f(double x)
+ { // A sample function to generate some X, Y pairs.
+ return sqrt(x);
+ }
+
+int main()
+{ // Construct one STL containers for the data series to plot.
+
+ map<double, double> data1; // record number and value.
+
+ for(double i = 0.; i <= 20.; i += 1.)
+ {
+ data1[i] = f(i);
+ }
+
+ try
+ { // try'n'catch blocks are needed to ensure error messages from any exceptions are shown.
+ //[demo_2d_fonts_2
+
+/*` The code below shows plotting the sqrt function
+selecting the range of the axis by a user choice.
+*/
+ {
+ svg_2d_plot my_plot; // Construct a 2D plot.
+
+ my_plot.legend_on(true) // Note chaining.
+ .title("&#x221A; Function ") // Unicode sqrt symbol.
+ .title_font_size(35)
+ .title_font_family("arial black")
+
+ .legend_title("Legend title")
+ .legend_header_font_size(15)
+ .legend_font_family("lucida calligraphy")
+ .legend_color(cyan)
+
+ .x_range(0, +20.)
+ .x_major_interval(2.)
+ .x_num_minor_ticks(4) // MAJOR, minor, minor, minor, minor, MAJOR
+ .x_label("x abcd1234")
+ .x_axis_label_color(green)
+ .x_label_font_family("helvetica")
+ .x_label_font_size(40)
+ .x_ticks_values_color(red) //
+ .x_ticks_values_font_family("Times New Roman")
+ .x_ticks_values_font_size(14)
+ .x_ticks_values_precision(0)
+ .x_ticks_values_ioflags(ios_base::fixed)
+
+ .y_label("sqrt(x) or (&#x221A;x)")
+ .y_range(0., 5.)
+ .y_ticks_values_color(magenta)
+ .y_ticks_values_precision(1)
+ .y_ticks_values_ioflags(ios_base::scientific | ios_base::showpos)
+ .y_ticks_values_font_family("lucida console")
+ .y_ticks_values_font_size(20)
+ //.y_label_font_family("informal roman")
+ .y_label_font_family("Times New roman")
+ .y_label_font_size(40)
+ .y_axis_label_color(blue)
+ ;
+
+ // Add a container of data to the plot, choosing a color.
+ my_plot.plot(data1, "Function (&#x221A;)").stroke_color(red).shape(round).size(3).bezier_on(true).line_color(pink);
+
+ my_plot.write("./demo_2d_fonts_1.svg"); // Write 1st plot to file.
+ // Show some styling, for example for X ticks.
+ cout << "my_plot.x_ticks_values_color() " << my_plot.x_ticks_values_color() << endl;
+ cout << "my_plot.x_ticks_values_font_family() " << my_plot.x_ticks_values_font_family() << endl;
+ cout << "my_plot.x_ticks_values_font_size() " << my_plot.x_ticks_values_font_size() << endl;
+ cout << "my_plot.x_ticks_values_precision() " << my_plot.x_ticks_values_precision() << endl;
+ cout << "my_plot.x_ticks_values_ioflags() 0x" << hex << my_plot.x_ticks_values_ioflags() << dec << endl;
+ }
+
+ // Axis label rotation default is horizontal.
+ {
+ svg_2d_plot my_plot; // Construct another 2D plot to try other variations of font sizes.
+ my_plot.x_range(0, +20.)
+ .y_range(0., 5.)
+ .x_label("X axis label font default size 14")
+ .y_label("Y axis label font default size 14")
+ //.x_label_font_size(10)
+ //.y_label_font_size(10)
+ ;
+ my_plot.plot(data1, "Function (&#x221A;)").stroke_color(red).shape(round).size(10).line_on(false).line_color(green);
+ my_plot.write("./demo_2d_fonts_1.svg"); // Write another plot to file.
+ }
+
+ {
+ svg_2d_plot my_plot; // Construct another 2D plot to try other variations of font sizes.
+ my_plot.x_range(0, +20.)
+ .y_range(0., 5.)
+ .x_label("x (small X axis label font size 10)")
+ .y_label("y (small X axis label font size 10)")
+ .x_label_font_size(10)
+ .y_label_font_size(10);
+ my_plot.plot(data1, "Function (&#x221A;)").stroke_color(red).shape(round).size(10).line_on(false).line_color(green);
+ my_plot.write("./demo_2d_fonts_2.svg"); // Write another plot to file.
+ }
+
+ {
+ svg_2d_plot my_plot; // Construct another 2D plot to try other variations of font sizes.
+ my_plot.x_range(0, +20.)
+ .y_range(0., 5.)
+ .x_label("X axis label 30")
+ .y_label("Y axis label 30")
+ .x_label_font_size(30)
+ .y_label_font_size(30);
+ my_plot.plot(data1, "Function (&#x221A;)").stroke_color(red).shape(round).size(10).line_on(false).line_color(green);
+ my_plot.write("./demo_2d_fonts_3.svg"); // Write another plot to file.
+ }
+
+ {
+ svg_2d_plot my_plot; // Construct another 2D plot to try other variations of font sizes.
+ my_plot.x_range(0, +20.)
+ .y_range(0., 5.)
+ .x_label("x (large tick font size 20)")
+ .y_label("y (large tick font size 20)")
+ .x_label_font_size(10)
+ .y_label_font_size(10)
+ .x_ticks_values_font_size(20)
+ .y_ticks_values_font_size(20)
+
+ ;
+ my_plot.plot(data1, "Function (&#x221A;)").stroke_color(red).shape(round).size(10).line_on(false).line_color(green);
+ my_plot.write("./demo_2d_fonts_4.svg"); // Write another plot to file.
+ }
+
+// Now alter the rotation of the axis labels.
+ {
+ svg_2d_plot my_plot; // Construct another 2D plot to try other variations of font sizes.
+ my_plot.x_range(0, +20.)
+ .y_range(0., 5.)
+ .x_label("X axis label font default size 14")
+ .y_label("Y axis label font default size 14")
+ .x_major_label_rotation(uphill)
+ .y_major_label_rotation(uphill)
+ //.x_label_font_size(10)
+ //.y_label_font_size(10)
+ ;
+ my_plot.plot(data1, "Function (&#x221A;)").stroke_color(red).shape(round).size(10).line_on(false).line_color(green);
+ my_plot.write("./demo_2d_fonts_5.svg"); // Write another plot to file.
+ }
+
+ {
+ svg_2d_plot my_plot; // Construct another 2D plot to try other variations of font sizes.
+ my_plot.x_range(0, +20.)
+ .y_range(0., 5.)
+ .x_label("x (small X axis label font size 10)")
+ .y_label("y (small X axis label font size 10)")
+ .x_label_font_size(10)
+ .y_label_font_size(10)
+ .x_major_label_rotation(uphill)
+ .y_major_label_rotation(uphill)
+ ;
+
+ my_plot.plot(data1, "Function (&#x221A;)").stroke_color(red).shape(round).size(10).line_on(false).line_color(green);
+ my_plot.write("./demo_2d_fonts_6.svg"); // Write another plot to file.
+ }
+
+ {
+ svg_2d_plot my_plot; // Construct another 2D plot to try other variations of font sizes.
+ my_plot.x_range(0, +20.)
+ .y_range(0., 5.)
+ .x_label("X axis label 30")
+ .y_label("Y axis label 30")
+ .x_label_font_size(30)
+ .y_label_font_size(30)
+ .x_major_label_rotation(uphill)
+ .y_major_label_rotation(uphill)
+ ;
+ my_plot.plot(data1, "Function (&#x221A;)").stroke_color(red).shape(round).size(10).line_on(false).line_color(green);
+ my_plot.write("./demo_2d_fonts_7.svg"); // Write another plot to file.
+ }
+
+ {
+ svg_2d_plot my_plot; // Construct another 2D plot to try other variations of font sizes.
+ my_plot.x_range(0, +20.)
+ .y_range(0., 5.)
+ .x_label("x tick size 12, label 14")
+ .y_label("y tick size 12, label 14")
+ .x_label_font_size(14)
+ .y_label_font_size(14)
+ .x_ticks_values_font_size(12)
+ .y_ticks_values_font_size(12)
+ .x_major_label_rotation(uphill)
+ .y_major_label_rotation(uphill)
+ ;
+ my_plot.plot(data1, "Function (&#x221A;)").stroke_color(red).shape(round).size(10).line_on(false).line_color(green);
+ my_plot.write("./demo_2d_fonts_8.svg"); // Write another plot to file.
+ }
+
+ {
+ svg_2d_plot my_plot; // Construct another 2D plot to try other variations of font sizes.
+ my_plot.x_range(0, +20.)
+ .y_range(0., 5.)
+ .x_label("X axis label font default size 14")
+ .y_label("Y axis label font default size 14")
+ .x_major_label_rotation(downward)
+ .y_major_label_rotation(upward)
+ ;
+ my_plot.plot(data1, "Function (&#x221A;)").stroke_color(red).shape(round).size(10).line_on(false).line_color(green);
+ my_plot.write("./demo_2d_fonts_9.svg"); // Write another plot to file.
+ }
+
+ {
+ svg_2d_plot my_plot; // Construct another 2D plot to try other variations of font sizes.
+ my_plot.x_range(0, +20.)
+ .y_range(0., 5.)
+ .x_label("x (small X axis label font size 10)")
+ .y_label("y (small X axis label font size 10)")
+ .x_label_font_size(10)
+ .y_label_font_size(10)
+ .x_major_label_rotation(steepdown)
+ .y_major_label_rotation(steepup)
+ ;
+
+ my_plot.plot(data1, "Function (&#x221A;)").stroke_color(red).shape(round).size(10).line_on(false).line_color(green);
+ my_plot.write("./demo_2d_fonts_10.svg"); // Write another plot to file.
+ }
+
+ {
+ svg_2d_plot my_plot; // Construct another 2D plot to try other variations of font sizes.
+ my_plot.x_range(0, +20.)
+ .y_range(0., 5.)
+ .x_label("X axis label 30")
+ .y_label("Y axis label 30")
+ .x_label_font_size(30)
+ .y_label_font_size(30)
+ .x_major_label_rotation(downhill)
+ .y_major_label_rotation(uphill)
+ ;
+ my_plot.plot(data1, "Function (&#x221A;)").stroke_color(red).shape(round).size(10).line_on(false).line_color(green);
+ my_plot.write("./demo_2d_fonts_11.svg"); // Write another plot to file.
+ }
+
+ {
+ svg_2d_plot my_plot; // Construct another 2D plot to try other variations of font sizes.
+ my_plot.x_range(0, +20.)
+ .y_range(0., 5.)
+ .x_label("x tick size 12, label 14")
+ .y_label("y tick size 12, label 14")
+ .x_label_font_size(14)
+ .y_label_font_size(14)
+ .x_ticks_values_font_size(12)
+ .y_ticks_values_font_size(12)
+ .x_major_label_rotation(slopedownhill)
+ .y_major_label_rotation(slopeup)
+ ;
+ my_plot.plot(data1, "Function (&#x221A;)").stroke_color(red).shape(round).size(10).line_on(false).line_color(green);
+ my_plot.write("./demo_2d_fonts_12.svg"); // Write another plot to file.
+ }
+
+
+
+
+
+ }
+ catch(const std::exception& e)
+ {
+ std::cout <<
+ "\n""Message from thrown exception was:\n " << e.what() << std::endl;
+ }
+
+ return 0;
+} // int main()
+
+
+//] [/demo_2d_fonts_2]
+
+
+//] [demo_2d_fonts_output]
+
+/*`
+
+Output:
+
+Autorun "j:\Cpp\SVG\Debug\demo_2d_fonts.exe"
+my_plot.x_ticks_values_color() RGB(255,0,0)
+my_plot.x_ticks_values_font_family() Verdana
+my_plot.x_ticks_values_font_size() 12
+my_plot.x_ticks_values_precision() 0
+my_plot.x_ticks_values_ioflags() 0x2000
+
+*/
+
+//] [/demo_2d_fonts_output]

Added: sandbox/SOC/2007/visualization/libs/svg_plot/example/demo_2d_tick_values.cpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/visualization/libs/svg_plot/example/demo_2d_tick_values.cpp 2009-08-04 13:39:55 EDT (Tue, 04 Aug 2009)
@@ -0,0 +1,170 @@
+/*! \file demo_2d_tick_values.cpp
+ \brief Example of changing tick values color, etc
+ \details Creates file demo_2d_tick_values.svg
+ \author Paul A. Bristow
+ \date Jul 2009
+ */
+
+// Copyright Paul A. Bristow 2009
+
+// Distributed under the Boost Software License, Version 1.0.
+// For more information, see http://www.boost.org
+
+// An example to demonstrate options to change the way tick values are labelled.
+
+// 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_tick_values_1
+
+/*`
+An example to demonstrate some options for controlling the layout and color of tick values.
+
+*/
+//] [/demo_2d_tick_values_1]
+
+#include <boost/svg_plot/svg_2d_plot.hpp>
+using namespace boost::svg;
+#include <boost/svg_plot/detail/pair.hpp>
+ using boost::svg::detail::operator<<; // Output pair as, for example: 1.23, 4.56
+
+#include <iostream>
+ using std::cout;
+ using std::endl;
+ using std::ios_base;
+ using std::dec;
+ using std::hex;
+#include <vector>
+ using std::vector; // 1D data container.
+#include <map>
+ using std::map; // 2D data container.
+#include <fstream> // for file streaming, ifstream & ofstream.
+ using std::ifstream;
+#include <string>
+ using std::string;
+ using std::getline;
+#include <sstream>
+ using std::istringstream;
+#include <limits>
+ using std::numeric_limits;
+#include <algorithm>
+ using std::min;
+ using std::max;
+#include <utility>
+ using std::pair;
+#include <ios>
+ using std::noskipws;
+
+ double f(double x)
+ { // A sample function to generate some X, Y pairs.
+ return sqrt(x);
+ }
+
+int main()
+{ // Construct one STL containers for the data series to plot.
+
+
+ map<double, double> data1; // record number and value.
+
+ for(double i = 0.; i <= 20.; i += 1.)
+ {
+ data1[i] = f(i);
+ }
+
+ try
+ { // try'n'catch blocks are needed to ensure error messages from any exceptions are shown.
+
+
+ //[demo_2d_tick_values_2
+
+/*` The code below shows plotting the sqrt function
+selecting the range of the axis by a user choice.
+
+[note Unicode symbols can be found at http://en.wikipedia.org/wiki/Unicode_symbols.
+The 4 hex digit value needs to be wrapped with prefix &#x and suffix ; like &#xDDDD;]
+*/
+
+ /*`
+*/
+ svg_2d_plot my_plot; // Construct a 2D plot.
+
+ my_plot.legend_on(true) // Set title and legend, and X and Y axis range.
+ .title("&#x221A; Function ") // Unicode sqrt symbol.
+ .x_range(0, +20.)
+ .x_major_interval(2.)
+
+ .x_axis_label_color(green)
+ .x_label_font_family("helvetica")
+ .x_label_font_size(30)
+
+ .x_num_minor_ticks(4) // MAJOR, minor, minor, minor, minor, MAJOR
+ .x_ticks_values_color(red) //
+ .x_ticks_values_font_family("Times New Roman")
+ .x_ticks_values_font_size(20)
+ .x_ticks_values_precision(0)
+ .x_ticks_values_ioflags(ios_base::fixed)
+
+ .y_range(0., 5.)
+ .y_ticks_values_color(magenta)
+ .y_ticks_values_precision(1)
+ .y_ticks_values_ioflags(ios_base::scientific | ios_base::showpos)
+
+ // "arial", "impact", "courier", "lucida console", "Lucida sans unicode", "verdana", "calibri", "century", "lucida calligraphy", "tahoma", "vivaldi"
+ // "informal roman", "lucida handwriting", "lucida bright", "helvetica"
+ // "arial narrow" is narrow, so may be useful.
+ // "arial black" is black!
+ // "Times New Roman Bold" "Times New Roman italic" = Times New Roman
+ // "comic sans", "sans" "bauhaus" "brush script" "segeo condensed" = Serif
+
+ .y_ticks_values_font_family("lucida console")
+ .y_ticks_values_font_size(10)
+
+ .y_label_font_family("Times New Roman")
+ .y_label_font_size(30)
+ .y_axis_label_color(blue)
+ ;
+
+ my_plot.x_label("x abcd1234(&#x221A;)").y_label("sqrt(x) "); // Note chaining.
+
+ // Add a container of data to the plot, choosing a color.
+ my_plot.plot(data1, "Function (&#x221A;)").stroke_color(red).shape(round).size(3).bezier_on(true).line_color(pink);
+
+/*`
+
+*/
+ my_plot.write("./demo_2d_tick_values.svg"); // Write the plot to another file.
+
+ // Show the ticks styling:
+ // X ticks.
+ cout << "my_plot.x_ticks_values_color() " << my_plot.x_ticks_values_color() << endl;
+ cout << "my_plot.x_ticks_values_font_family() " << my_plot.x_ticks_values_font_family() << endl;
+ cout << "my_plot.x_ticks_values_font_size() " << my_plot.x_ticks_values_font_size() << endl;
+ cout << "my_plot.x_ticks_values_precision() " << my_plot.x_ticks_values_precision() << endl;
+ cout << "my_plot.x_ticks_values_ioflags() 0x" << hex << my_plot.x_ticks_values_ioflags() << dec << endl;
+ // Y ticks.
+ cout << "my_plot.y_ticks_values_color() " << my_plot.y_ticks_values_color() << endl;
+ cout << "my_plot.y_ticks_values_font_family() " << my_plot.y_ticks_values_font_family() << endl;
+ cout << "my_plot.y_ticks_values_font_size() " << my_plot.y_ticks_values_font_size() << endl;
+ cout << "my_plot.y_ticks_values_color() " << my_plot.y_ticks_values_color() << endl;
+ cout << "my_plot.y_ticks_values_precision() " << my_plot.y_ticks_values_precision() << endl;
+ cout << "my_plot.y_ticks_values_ioflags() 0x" << hex << my_plot.y_ticks_values_ioflags() << dec << endl;
+
+ }
+ catch(const std::exception& e)
+ {
+ std::cout <<
+ "\n""Message from thrown exception was:\n " << e.what() << std::endl;
+ }
+
+ return 0;
+} // int main()
+
+// cout << "my_plot.x_ticks_values_color() " << my_plot.x_ticks_values_color() << endl;
+
+//] [/demo_2d_tick_values_2]
+
+

Added: sandbox/SOC/2007/visualization/libs/svg_plot/example/demo_2d_weather.cpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/visualization/libs/svg_plot/example/demo_2d_weather.cpp 2009-08-04 13:39:55 EDT (Tue, 04 Aug 2009)
@@ -0,0 +1,441 @@
+/*! \file demo_2d_weather.cpp
+ \brief Example of a histogram of weather data.
+ \details Creates file weather6 to 8.svg
+ \author Paul A. Bristow
+ \date Jul 2009
+ */
+
+// Copyright Paul A. Bristow 2009
+
+// Distributed under the Boost Software License, Version 1.0.
+// For more information, see http://www.boost.org
+
+// An example to demonstrate plotting some weather data from a CSV file (output from Excel)
+// The data was collected from a weather station that stored months of data in its RAM.
+// This data was then downloaded using the EasyWeather 1 software provided and saved in its .csv format.
+
+// 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_weather_1
+
+/*`
+An example to demonstrate plotting some weather data from a CSV file (output from Excel)
+The data was collected from a weather station that stored months of data in its RAM.
+This data was then downloaded using the EasyWeather 1 software provided and saved in its .csv format.
+
+See the source code for various includes to use Boost.Plot, and STL 1D container vector etc.
+
+This data is read and parsed into STL container(s) with some messy code to deal with missing values,
+indicated by the string "---" in the .csv file, which are replaced by quiet_NaN because the svg_plot
+program assumes that these are used for 'missing' values.
+
+Missing values are not used for autoscaling, and are shown by a different symbol at the edges of the plot.
+
+*/
+//] [/demo_2d_weather_1]
+
+#include <boost/svg_plot/svg_2d_plot.hpp>
+using namespace boost::svg;
+#include <boost/svg_plot/detail/pair.hpp>
+ using boost::svg::detail::operator<<; // Output pair as, for example: 1.23, 4.56
+
+#include <iostream>
+ using std::cout;
+ using std::endl;
+ using std::ios_base;
+ using std::dec;
+ using std::hex;
+#include <vector>
+ using std::vector; // 1D data container.
+#include <map>
+ using std::map; // 2D data container.
+#include <fstream> // for file streaming, ifstream & ofstream.
+ using std::ifstream;
+#include <string>
+ using std::string;
+ using std::getline;
+#include <sstream>
+ using std::istringstream;
+#include <limits>
+ using std::numeric_limits;
+#include <algorithm>
+ using std::min;
+ using std::max;
+#include <utility>
+ using std::pair;
+#include <ios>
+ using std::noskipws;
+
+ float getvalue(string s)
+ {
+ if (s == "---")
+ { // missing value, so return NaN
+ return numeric_limits<float>::quiet_NaN();
+ }
+ istringstream is(s); // Read float from string.
+ float v;
+ is >> v;
+ if (is.fail() == true)
+ {
+ return numeric_limits<float>::quiet_NaN();
+ }
+ return v;
+ } // float getvalue(string s)
+
+ int getintvalue(string s)
+ {
+ if (s == "---")
+ { // missing value, so return NaN
+ return numeric_limits<int>::denorm_min();
+ }
+ istringstream is(s); // Read float from string.
+ int i;
+ is >> i;
+ if (is.fail() == true)
+ {
+ return numeric_limits<int>::denorm_min();
+ }
+ return i;
+ } // int getintvalue(string s)
+
+int main()
+{ // Construct two STL containers for the two data series to plot.
+
+ const char comma_or_tab = ','; // separator - assumed comma for .csv file.
+
+ bool diag = false;
+
+ map<double, double> in_temps; // record number and value.
+ map<double, double> out_temps;
+
+ const char* weather("I:\\boost-sandbox\\SOC\\2007\\visualization\\libs\\svg_plot\\example\\EasyWeather7mar09.csv"); // The weather data, comma separated, with one column title line.
+ ifstream fin(weather, ios_base::in);
+ if (fin.is_open())
+ {
+ cout << "Reading weather from " << weather << endl;
+ }
+ else
+ {
+ cout << "Could not open file " << weather << " to read weather data!" << endl;
+ return 0;
+ }
+
+ int readings = 0; // Count of weather data records processed.
+ int plotted = 0; // Count of weather data records plotted.
+ string line; // A single complete weather data record as a string.
+ getline(fin, line);
+ cout << line << endl; // Header line with Column titles.
+ // No,Time,Interval(mi), Indoor Humidity(%), Indoor Temperature(C), Outdoor Humidity(%), Outdoor Temperature(C), Absolute Pressure(hPa),
+ // Wind(m/s), Gust(m/s), Direction, Relative Pressure(hPa), Dewpoint(C), Windchill(C),
+ // Hour Rainfall(mm), 24 hour Rainfall(mm), Week Rainfall(mm), Month Rainfall(mm), Total Rainfall(mm), Wind Level(bft), Gust Level(bft)
+
+ // EastWeather software allows this as an option, convenient when working with a spreadsheet.
+ // Here it is just ignored, assuming that all items are chosen for including in the .csv file.
+
+ do
+ { // Get all the lines of weather data records.
+ getline(fin, line);
+ // cout << line << endl; // Show a sample line of weather readings.
+ // no time int in_h
+ // 1, 28-12-2008 14:10, 30, 57, 17, 68, 4.8, 1025.9, 3.4, 4.8, N, 1006.1, -0.6, 0.2, 0, 2.1, 2.1, 2.1, 2.1, 3, 3
+
+ if (line.size() == 0)
+ {
+ break;
+ }
+
+ readings++;
+
+ char sep; // Expect comma or tab as separator.
+ // Fields in weather data record:
+ int j; // Sequential record number in the weather station data.
+ int day; // Timestamp of the record.
+ int month;
+ int year;
+ int hour;
+ int min;
+ int interval; // between readings (min).
+ float in_humidity;
+ float in_temp;
+ float out_humidity;
+ float out_temp;
+ float pressure;
+ float wind;
+ float gust;
+ char dir; // Single letter, N, S, E, or W.
+ string direction; // May be up to 3 letters, like NNW.
+ float rel_pressure;
+ float dewpoint;
+ float windchill;
+ float rain_hour;
+ float rain_day;
+ float rain_week;
+ float rain_month;
+ float rain_all;
+ int beaufort;
+ int gusty;
+
+ istringstream is(line); // Single comma separated line of data, terminated by newline.
+ is >> noskipws; // Noskipws to allow test of space as separator.
+ is >> j;
+ if (is.fail() == true)
+ {
+ cout << "Failed to read data record number from file " << weather << "!" << endl;
+ break; // To try next line?
+ }
+ is >> sep; // comma separator.
+ if (sep != comma_or_tab)
+ {
+ cout << "Expected " << comma_or_tab << " as separator, but got " << sep << endl;
+ cout << " whole line is " << line << endl;
+ }
+ is >> day; // dd
+ is >> sep; // -
+ if (sep != '-')
+ {
+ cout << "Expected - as separator, but got " << sep << endl;
+ }
+ is >> month; // mm
+ is >> sep; // -
+ if (sep != '-')
+ {
+ cout << "Expected - as separator, but got " << sep << endl;
+ }
+ is >> year; // yyyy
+ is >> sep; // space
+ if (sep != ' ')
+ {
+ cout << "Expected space as separator, but got " << sep << endl;
+ }
+ is >> hour; // hh
+ is >> sep; // :
+ if (sep != ':')
+ {
+ cout << "Expected : as separator, but got " << sep << endl;
+ }
+ is >> min; // mm
+ is >> sep; // ,
+ if (sep != ',')
+ {
+ cout << "Expected , as separator, but got " << sep << endl;
+ }
+
+ is >> interval; // usually 30 minutes
+ is >> sep;
+ if (sep != ',')
+ {
+ cout << "Expected , as separator, but got " << sep << endl;
+ }
+
+ string s;
+ getline(is, s, ',');
+ in_humidity = getvalue(s); // Indoor Humidity(%)
+
+ getline(is, s, ',');
+ in_temp = getvalue(s); // Indoor Temperature (C)
+
+ getline(is, s, ',');
+ out_humidity = getvalue(s); // Indoor Humidity (%)
+
+ getline(is, s, ',');
+ out_temp = getvalue(s); // Outdoor Temperature (C)
+
+ getline(is, s, ',');
+ pressure = getvalue(s); // Absolute Pressure (hPa)
+
+ getline(is, s, ',');
+ wind = getvalue(s); // Wind (m/s)
+ getline(is, s, ',');
+ gust = getvalue(s); // Gust (m/s)
+ do
+ { // Direction may be encoded as N, NW or NNW
+ is >> dir;
+ if ((dir == 'N') || (dir == 'S') || (dir == 'E') || (dir == 'W')
+ || (dir == '-') // "---" used to show no value available.
+ )
+ {
+ direction += dir;
+ }
+ else if (dir == comma_or_tab)
+ {
+ break;
+ }
+ else
+ {
+ cout << "Unexpected (not N, S, E or W) wind direction character " << dir << "!" << endl;
+ break;
+ }
+ } while(true);
+ if (direction == "---")
+ {
+ direction = "?"; // Indicate a missing value (or "" perhaps).
+ }
+
+ getline(is, s, ',');
+ rel_pressure = getvalue(s); // Relative Pressure (hPa)
+ getline(is, s, ',');
+ dewpoint = getvalue(s); // Dewpoint(C)
+
+ getline(is, s, ',');
+ windchill = getvalue(s); // Windchill (C)
+ getline(is, s, ',');
+ rain_hour = getvalue(s); // Hour Rainfall (mm)
+ getline(is, s, ',');
+ rain_day = getvalue(s); // Day Rainfall (mm)
+ getline(is, s, ',');
+ rain_week = getvalue(s); // Week Rainfall (mm)
+ getline(is, s, ',');
+ rain_month = getvalue(s); // Month Rainfall(mm)
+ getline(is, s, ',');
+ rain_all = getvalue(s); // Total Rainfall (mm)
+ getline(is, s, ',');
+ beaufort = getintvalue(s); // Wind Level (Beaufort scale 0 - 12)
+ getline(is, s, ',');
+ gusty = getintvalue(s); // Gust Level(Beaufort scale 0 - 12)
+
+ // line ends with newline, but this is consumed by getline, so no separator.
+
+ //if (diag == true)
+ if (is.fail() == true)
+ {
+ cout << j << endl;
+ cout << day << endl;
+ cout << month << endl;
+ cout << "year " << year << endl;
+ cout << hour << endl;
+ cout << min << endl;
+ cout << interval << endl;
+ cout << in_humidity << endl;
+ cout << in_temp << endl;
+ cout << out_humidity << endl;
+ cout << out_temp << endl;
+ cout << pressure << endl;
+ cout << wind << endl;
+ cout << gust << endl;
+ cout << direction << endl;
+ cout << rel_pressure << endl;
+ cout << dewpoint << endl;
+ cout << windchill << endl;
+ cout << rain_hour << endl;
+ cout << rain_day << endl;
+ cout << rain_week << endl;
+ cout << rain_month << endl;
+ cout << rain_all << endl;
+ cout << "Beaufort scale " << beaufort << endl;
+ cout << "gustiness " << gusty << endl;
+ is.clear();
+ }
+
+ if ((j % 1) == 0)
+ { // Only chose a sub-set of readings (to avoid too many points merging).
+ // Fill the two containers with temperature data:
+ plotted++;
+ in_temps[j] = in_temp;
+ out_temps[j] = out_temp;
+ }
+ }
+ while (line.size() > 0);
+ // Or test is.eof() == true?
+
+ cout << readings << " readings read, of which only " << plotted << " were plotted." << endl;
+
+ try
+ { // try'n'catch blocks are needed to ensure error messages from any exceptions are shown.
+
+
+ //[demo_2d_weather_2
+
+/*` The code below shows plotting just the inside and outside temperatures,
+selecting the range of the axis by a user choice or automatically.
+*/
+
+
+ /*` SVG_plot range_all is another mechanism for handling multiple containers
+ providing a more convenient way to find the minimum of minimums and maximum of maximums.
+It is especially convenient when there are many containers (of the same type),
+and there may be 'missing' data items.
+
+*/
+ {
+ svg_2d_plot my_plot; // Construct a 2D plot.
+
+ my_plot.legend_on(true) // Set title and legend, and X axis range.
+ .title("Temperatures at Long: 2:45:16.2W, Lat:54:17:47.1N")
+ .x_range(0., 2000.)
+ .x_major_interval(500.)
+ .x_ticks_values_color(red)
+ .x_num_minor_ticks(4)
+ .x_axis_label_color(green)
+ .x_ticks_values_precision(0)
+ .x_ticks_values_ioflags(ios_base::fixed)
+ .x_ticks_values_font_family("arial")
+ .x_ticks_values_font_size(20)
+ //.autoscale_check_limits(true) // Is default, but check for NaN, infinity etc.
+ //.xy_autoscale(in_temps) // Autoscale BOTH axes.
+ // Implementation does not (yet) permit use of the container for .x_autoscale(in_temps),
+ // but can ignore the autoscale range thus:
+ .y_range(0., 20.) // User chosen range, over-riding the autoscale.
+ .y_ticks_values_color(magenta)
+ .y_ticks_values_precision(1)
+ .y_ticks_values_ioflags(ios_base::scientific)
+ .y_axis_label_color(blue)
+ ;
+
+ my_plot.x_label("time (hr)").y_label("temp (&#x00B0;C)"); // Note chaining.
+
+ // Add a container of data to the plot, choosing a color.
+ my_plot.plot(in_temps, "Inside (&#x00B0;C)").stroke_color(red).shape(none).size(1).bezier_on(true).line_color(red);
+ //my_plot.plot(out_temps, "Outside (&#x00B0;C)"); // default is black circle, 5 pixel size, with no fill.
+ my_plot.plot(out_temps, "Outside (&#x00B0;C)").stroke_color(blue).shape(point);
+
+/*`Note how the point markers are switch off for the inside temperatures,
+and a bezier line chosen
+but the point markers are set to `round` for the outside temperatures,
+giving an less attractive spotty appearance, but showing the actual data points.
+The default round size is 5 which is a bit big when there are so many points to plot.
+The size also needs to be > 1 to be displayed.
+
+There may be also, by default, too many axis ticks and labels on the X-axis,
+so one can either use autoscale or explicitly set the number of X ticks.
+
+*/
+ my_plot.write("./demo_2d_weather.svg"); // Write the plot to another file.
+
+ // Show the ticks styling
+cout << "my_plot.x_ticks_values_color() " << my_plot.x_ticks_values_color() << endl;
+cout << "my_plot.x_ticks_values_font_family() " << my_plot.x_ticks_values_font_family() << endl;
+cout << "my_plot.x_ticks_values_color() " << my_plot.x_ticks_values_color() << endl;
+cout << "my_plot.x_ticks_values_precision() " << my_plot.x_ticks_values_precision() << endl;
+cout << "my_plot.x_ticks_values_ioflags() " << hex << my_plot.x_ticks_values_ioflags() << dec << endl;
+
+cout << "my_plot.y_ticks_values_color() " << my_plot.y_ticks_values_color() << endl;
+//cout << "my_plot.y_ticks_values_font_family() " << my_plot.y_ticks_values_font_family() << endl;
+cout << "my_plot.y_ticks_values_color() " << my_plot.y_ticks_values_color() << endl;
+cout << "my_plot.y_ticks_values_precision() " << my_plot.y_ticks_values_precision() << endl;
+cout << "my_plot.y_ticks_values_ioflags() " << hex << my_plot.y_ticks_values_ioflags() << dec << endl;
+
+// Show the X, Y styling.
+cout << "my_plot.x_values_color() " << my_plot.x_values_color() << endl;
+cout << "my_plot.x_values_font_family() " << my_plot.x_values_font_family() << endl;
+cout << "my_plot.x_values_color() " << my_plot.x_values_color() << endl;
+cout << "my_plot.x_values_precision() " << my_plot.x_values_precision() << endl;
+cout << "my_plot.x_values_ioflags() " << hex << my_plot.x_values_ioflags() << dec << endl;
+ }
+ }
+ catch(const std::exception& e)
+ {
+ std::cout <<
+ "\n""Message from thrown exception was:\n " << e.what() << std::endl;
+ }
+
+ return 0;
+} // int main()
+
+//] [/demo_2d_weather_2]
+
+

Modified: sandbox/SOC/2007/visualization/libs/svg_plot/example/demo_svg.cpp
==============================================================================
--- sandbox/SOC/2007/visualization/libs/svg_plot/example/demo_svg.cpp (original)
+++ sandbox/SOC/2007/visualization/libs/svg_plot/example/demo_svg.cpp 2009-08-04 13:39:55 EDT (Tue, 04 Aug 2009)
@@ -105,7 +105,7 @@
   // background
 
   // g_element& a1 =
- my_svg.g(); // Add first (zeroth) new element,
+ my_svg.add_g_element(); // Add first (zeroth) new element,
 
   cout << "my_svg.document_size() " << my_svg.document_size() << endl;
 
@@ -229,7 +229,7 @@
   //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,
+ //my_svg.add_g_element(); // Add 2nd new element,
 
   // This line aborts:
   //polyline_element& pl = g1.polyline(); // 'empty' line.
@@ -293,7 +293,7 @@
   cout << g1.id() << endl; // Output: element 1
   cout << "my_svg.document_size() " << my_svg.document_size() << endl; // 8 ???
 
- cout << "my_svg.g().size() " << my_svg.g().size() << endl; // 0
+ cout << "my_svg.add_g_element().size() " << my_svg.add_g_element().size() << endl; // 0
 
 
   my_svg.write("demo_svg.svg");

Modified: sandbox/SOC/2007/visualization/libs/svg_plot/example/svg_colors.cpp
==============================================================================
--- sandbox/SOC/2007/visualization/libs/svg_plot/example/svg_colors.cpp (original)
+++ sandbox/SOC/2007/visualization/libs/svg_plot/example/svg_colors.cpp 2009-08-04 13:39:55 EDT (Tue, 04 Aug 2009)
@@ -30,28 +30,64 @@
 #include <boost/svg_plot/svg_1d_plot.hpp>
 using namespace boost::svg;
 
+#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::blue;
+ using boost::svg::white;
+ using boost::svg::red;
+ using boost::svg::yellow;
+ // ... which may get tedious!
+
+#include <iostream>
+ using std::cout;
+ using std::endl;
+ using std::boolalpha;
+
+
 int main()
 {
+ svg my_svg;
+ my_svg.x_size(300);
+ my_svg.y_size(200);
+
   svg& rect(double x1, double y1, double width, double height);
- svg my_image;
- my_image.x_size(100);
- my_image.y_size(200);
-
- my_image.g(); // Add first (zeroth) new element,
- g_element& g0 = my_image.g(0); // so index is zero.
- g0.push_back(new rect_element(0, 0, my_image.x_size(), my_image.y_size() ) ); // border to all image.
+
+ my_svg.add_g_element(); // Add first (zeroth) new element,
+ g_element& g0 = my_svg.g(0); // so index is zero.
+ cout << "my_svg.document_size() = number of g_elements = " << my_svg.document_size() << endl;
+ g0.id("group element 0");
+ cout << "group element " << g0.id() << endl;
+
+ g0.push_back(new rect_element(0, 0, my_svg.x_size(), my_svg.y_size() ) ); // border to all image.
 
   // Create a small test rectangle.
   g0.style().fill_color(azure);
   g0.style().fill_on(true);
- g0.style().stroke_color(yellow);
+ g0.style().stroke_color(blue);
   g0.push_back(new rect_element(20, 20, 10, 10) ); // border to rectangle.
- g0.text(490, 100, "my color", no_style, right_align); // SVG name of color to the right.
+ //g0.text(50, 50, "my color", no_style, right_align); // SVG name of color to the right.
+
+ my_svg.add_g_element();
+ g_element& g1 = my_svg.g(1); // so index is now one.
+
+ g1.id("group element 1");
+ cout << "my_svg.document_size() = number of g_elements = " << my_svg.document_size() << endl;
+ g1.id("group element 0");
+ cout << "group element " << g0.id() << endl;
+
+ g1.style().fill_color(black);
+ g1.style().fill_on(false);
+ g1.style().stroke_color(red);
+
+ text_style big_font;
+ big_font.font_size(30);
+ g1.push_back(new text_element(100, 50, "my color", big_font, center_align)); // SVG name of color to the right.
  
   // The need to repeat down the page for all the colors. TODO
   // Need a 'reverse lookup' of the enum colors as "azure" :-((
 
- my_image.write("./svg_colors.svg");
+ my_svg.write("./svg_colors.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