Boost logo

Boost-Commit :

From: pbristow_at_[hidden]
Date: 2008-05-24 12:29:56


Author: pbristow
Date: 2008-05-24 12:29:56 EDT (Sat, 24 May 2008)
New Revision: 45721
URL: http://svn.boost.org/trac/boost/changeset/45721

Log:
New examples
Added:
   sandbox/SOC/2007/visualization/libs/svg_plot/example/demo_2d_values.cpp (contents, props changed)
   sandbox/SOC/2007/visualization/libs/svg_plot/example/demo_svg_tspan.cpp (contents, props changed)

Added: sandbox/SOC/2007/visualization/libs/svg_plot/example/demo_2d_values.cpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/visualization/libs/svg_plot/example/demo_2d_values.cpp 2008-05-24 12:29:56 EDT (Sat, 24 May 2008)
@@ -0,0 +1,204 @@
+// demo_2d_values.hpp
+
+// 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 simplest 2d *default* settings.
+// See also demo_2d_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_2d_values_1
+
+/*`As always, 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;
+ using std::dec;
+ using std::hex;
+
+#include <map>
+ using std::map;
+
+//] [demo_2d_values_1]
+
+int main()
+{
+
+//[demo_2d_values_2
+/*`Some fictional data is pushed into an STL container, here map:*/
+
+ /*`This example uses a single map to demonstrate autoscaling.
+ We create a map to hold our data series.
+ */
+ map<const double, double> my_data;
+ /*`
+ Inserting some fictional values also sorts the data.
+ The index value in [] is the x value.
+ */
+ //my_data[1.1] = 3.2;
+ //my_data[7.3] = 9.1;
+ my_data[2.12] = 2.4394;
+ my_data[5.47] = 5.3861;
+
+ try
+ { // try'n'catch clocks 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 Values Demo") // Add a string title of the plot.
+ .x_range(-5, 10) // 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_2d_plot.plot(my_data, "2d Values").shape(round).size(5).line_on(false);
+
+/*`To put a value label against each data point, switch on the option:
+*/
+ //my_2d_plot.x_values_on(true); // Add a label for the X-axis.
+ //my_2d_plot.y_values_on(true); // Add a label for the X-axis.
+ my_2d_plot.xy_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_2d_plot.x_values_font_size(16) // 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 X values color from default black to red.
+
+ my_2d_plot.y_values_font_size(14) // Change font size for the Y-axis value labels.
+ .y_values_font_family("Arial") // Change font for the Y-axis value labels.
+ .y_values_color(blue); // Change Y color from default black to blue.
+
+/*`The format of the values may also not be ideal,
+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.
+(Obviously the most suitable precision depends on the range of the data points.
+If values are very close to each other, a higher precision will be needed to differentiate them).
+For measurement of typical precision, 2 or 3 decimal places will suffice.
+*/
+ my_2d_plot.x_values_precision(3); // precision label for the X-axis value label.
+ my_2d_plot.y_values_precision(5); // precision label for the Y-axis value label.
+
+/*`We can also prescribe the use of scientific, fixed format and/or force a positive sign:
+*/
+ //my_2d_plot.x_values_ioflags(std::ios::scientific | std::ios::showpos);
+ //my_2d_plot.x_values_ioflags(std::ios::scientific);
+ //my_2d_plot.y_values_ioflags(std::ios::fixed);
+
+/*`By default, any unnecessary spacing-wasting zeros in the exponent field are removed.
+Stripping "e+000" may appear to mean that the normal effect of `scientific` is not working.
+(If, probably perversely, the full 1.123456e+012 format is required,
+the stripping can be switched off with:
+ `my_2d_plot.x_labels_strip_e0s(false);` )
+
+In general, sticking to the default ioflags usually produces the neatest presentation of values.
+*/
+ my_2d_plot.x_plusminus_on(true); // unc label for the X-axis value label.
+ my_2d_plot.x_df_on(true); // df label for the X-axis value label.
+
+ my_2d_plot.y_plusminus_on(true); // unc label for the X-axis value label.
+ my_2d_plot.y_df_on(true); // df label for the X-axis value label.
+
+
+/*`The default value label is horizontal, centered above the data point marker,
+but, depending on the type and density of data points, and the length of the values
+(controlled in turn by the `precision` and `ioflags` in use),
+it is often clearer to use a different orientation.
+This can be controlled in steps of 45 degrees, using an 'enum rotate_style`.
+
+* `leftward` - writing level with the data point but to the left.
+* `rightward` - writing level with the data point but to the right.
+* `uphill` - writing up at 45 degree slope is often a good choice,
+* `upward` - writing vertically up and
+* `backup` - writing to the left are also useful.
+
+(For 1-D plots other directions are less attractive,
+placing the values below the horizontal Y-axis line,
+but for 2-D plots all writing orientations can be useful).
+*/
+ my_2d_plot.x_values_rotation(rightward); // Orientation for the Y-axis value labels.
+ //my_2d_plot.x_values_rotation(horizontal); // Orientation for the X-axis value labels.
+ //my_2d_plot.x_values_rotation(uphill); // Orientation for the X-axis value labels.
+ // my_2d_plot.y_values_rotation(downhill); // Orientation for the Y-axis value labels.
+ //my_2d_plot.x_values_rotation(leftward); // Orientation for the X-axis value labels.
+ //my_2d_plot.y_values_rotation(rightward); // Orientation for the Y-axis value labels.
+
+ // my_2d_plot.x_plusminus_on(true); // Show Uncertainty for X-axis value labels.
+ // my_2d_plot.x_df_on(true); // Show Degrees of freedom (n-1) for X-axis value labels.
+ //my_2d_plot.y_plusminus_on(true); // Uncertainty for X-axis value labels.
+
+
+/*`To use all these settings, finally write the plot to file.
+*/
+ my_2d_plot.write("demo_2d_values.svg");
+
+/*`If chosen settings do not have the expected effect, is may be helpful to display them.
+
+(All settings can be displayed with `show_2d_plot_settings(my_2d_plot)`.)
+*/
+ cout << "my_2d_plot.x_values_font_size() " << my_2d_plot.x_values_font_size() << endl;
+ cout << "my_2d_plot.x_values_font_family() " << my_2d_plot.x_values_font_family() << endl;
+ cout << "my_2d_plot.x_values_color() " << my_2d_plot.x_values_color() << endl;
+ cout << "my_2d_plot.x_values_precision() " << my_2d_plot.x_values_precision() << endl;
+ cout << "my_2d_plot.x_values_ioflags() " << hex << my_2d_plot.x_values_ioflags() << dec << endl;
+
+ cout << "my_2d_plot.y_values_font_size() " << my_2d_plot.y_values_font_size() << endl;
+ cout << "my_2d_plot.y_values_font_family() " << my_2d_plot.y_values_font_family() << endl;
+ cout << "my_2d_plot.y_values_color() " << my_2d_plot.y_values_color() << endl;
+ cout << "my_2d_plot.y_values_precision() " << my_2d_plot.y_values_precision() << endl;
+ cout << " my_2d_plot.y_values_ioflags() " << hex << my_2d_plot.y_values_ioflags() << dec << endl;
+//] [demo_2d_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_2d_values_output
+
+Output:
+
+demo_2d_values.cpp
+Linking...
+Embedding manifest...
+Autorun "j:\Cpp\SVG\debug\demo_2d_values.exe"
+ my_2d_plot.x_values_font_size() 14
+my_2d_plot.x_values_font_family() Times New Roman
+my_2d_plot.x_values_color() RGB(255,0,0)
+my_2d_plot.x_values_precision() 2
+ my_2d_plot.x_values_ioflags() 1020
+Build Time 0:03
+
+
+//] [demo_2d_values_output]
+
+ //my_2d_plot.x_values_rotation(uphill); // Orientation for the X-axis value labels.
+ //my_2d_plot.x_values_rotation(horizontal); // Orientation for the X-axis value labels.
+ //my_2d_plot.x_values_rotation(backup); // Orientation for the X-axis value labels.
+ my_2d_plot.x_values_rotation(downhill); // Orientation for the X-axis value labels.
+
+*/
+

Added: sandbox/SOC/2007/visualization/libs/svg_plot/example/demo_svg_tspan.cpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/visualization/libs/svg_plot/example/demo_svg_tspan.cpp 2008-05-24 12:29:56 EDT (Sat, 24 May 2008)
@@ -0,0 +1,100 @@
+// demo_svg_tspan.cpp
+
+// Copyright Jacob Voytko 2008
+// 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)
+
+// Shows the use of SVG tspan command to control text layout.
+// tspec is needed to continue text
+// changing color, position(next line effect), superscript or subscript.
+
+#ifdef _MSC_VER
+# pragma warning (disable : 4512) // assignment operator could not be generated
+#endif
+
+#include <boost/svg_plot/svg.hpp>
+using namespace boost::svg;
+
+#include <iostream>
+using std::cout;
+using std::endl;
+using std::boolalpha;
+
+int main()
+{
+ svg doc;
+
+ doc.image_size(400, 400);
+
+ text_element& t = doc.text(100, 100, "This ", no_style, center_align, uphill);
+ tspan_element ts = t.tspan("text").dx(10).dy(20.).font_size(40).font_family("Arial").font_weight("bold").fill_color(pink);
+ cout << "dx " << ts.dx() << endl;
+ cout << "dy " << ts.dy() << endl;
+ cout << "tspan text is " << ts.text() << endl;
+ cout << "font is " << ts.font_size() << endl;
+ cout << "font family " << ts.font_family() << endl;
+ cout << "font weight is " << ts.font_weight() << endl;
+ cout << "fill color " << ts.fill_color() << endl; // expect pink == rgb(255,192,203) but get blank!
+ cout << "fill on " << boolalpha << ts.fill_on() << endl;
+
+ //<text x="100" y="100" text-anchor="middle" transform = "rotate(-45 100 100 )" font-size="20">
+ // This
+ // <tspan fill="rgb(255,192,203)" dx="10" dy="20" font-size="40" font-family="Arial" font-weight="bold">
+ // text
+ // </tspan>
+ //</text>
+
+ // shows expected This text with positiona nd color as expected,
+ // BUT doesn't echo fill color????
+
+ // These lines below have no effect on the output svg tspan!
+ //ts.text("green 30 Arial");
+ //ts.dx(1).dy(5.);
+ //ts.style().fill_color(green);
+ //ts.font_size(30);
+ //ts.font_family("Arial");
+ //ts.font_style().font_size(30);
+ //ts.font_style().font_family("Arial");
+
+ // Data is OK in debug here.
+ // So the info is stored OK, but not used on the write.
+
+ // <text x="100" y="100" text-anchor="middle" transform = "rotate(-45 100 100 )" font-size="20">
+ // This
+ // <tspan font-size="20">
+ // text
+ // </tspan>
+ // </text>
+
+ // Only shows "this text"
+ // NO offset and style info added to ts
+ // NO tspan text for "green 30 Arial"
+
+ doc.write("demo_svg_tspan.svg");
+
+ return 0;
+
+} // int main()
+
+/*
+
+demo_svg_tspan.cpp
+Linking...
+Embedding manifest...
+Autorun "j:\Cpp\SVG\debug\demo_tspan.exe"
+dx 10
+dy 20
+tspan text is text
+font is 40
+font family Arial
+font weight is bold
+fill color blank
+fill on false
+Build Time 0:02
+
+
+*/


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