|
Boost-Commit : |
From: jakevoytko_at_[hidden]
Date: 2007-07-08 22:18:05
Author: jakevoytko
Date: 2007-07-08 22:18:04 EDT (Sun, 08 Jul 2007)
New Revision: 7393
URL: http://svn.boost.org/trac/boost/changeset/7393
Log:
Added tests, modified documentation, and continued to touch up svg_1d_plot.hpp
Added:
sandbox/SOC/2007/visualization/libs/svg_plot/test/test_color_peristance.cpp
sandbox/SOC/2007/visualization/libs/svg_plot/test/test_output_consistency.cpp
Text files modified:
sandbox/SOC/2007/visualization/boost/svg_plot/svg_1d_plot.hpp | 8 ++++----
sandbox/SOC/2007/visualization/libs/svg_plot/doc/svg_plot.qbk | 14 +++++++++-----
sandbox/SOC/2007/visualization/libs/svg_plot/doc/svg_plot.xml | 37 ++++++++++++++++++++++---------------
sandbox/SOC/2007/visualization/libs/svg_plot/test/Jamfile.v2 | 3 ++-
sandbox/SOC/2007/visualization/libs/svg_plot/test/test_color_constant.cpp | 2 +-
5 files changed, 38 insertions(+), 26 deletions(-)
Modified: sandbox/SOC/2007/visualization/boost/svg_plot/svg_1d_plot.hpp
==============================================================================
--- sandbox/SOC/2007/visualization/boost/svg_plot/svg_1d_plot.hpp (original)
+++ sandbox/SOC/2007/visualization/boost/svg_plot/svg_1d_plot.hpp 2007-07-08 22:18:04 EDT (Sun, 08 Jul 2007)
@@ -362,11 +362,11 @@
if(title_on)
{
- text_element title(image.get_x_size()/2., title_font_size, title);
+ text_element my_title(image.get_x_size()/2., title_font_size, title);
- title.set_alignment(center_align);
- title.set_font_size(title_font_size);
- image.get_g_element(PLOT_TITLE).push_back(new text_element(title));
+ my_title.set_alignment(center_align);
+ my_title.set_font_size(title_font_size);
+ image.get_g_element(PLOT_TITLE).push_back(new text_element(my_title));
}
x_axis = (plot_window_y2 + plot_window_y1)/2.;
Modified: sandbox/SOC/2007/visualization/libs/svg_plot/doc/svg_plot.qbk
==============================================================================
--- sandbox/SOC/2007/visualization/libs/svg_plot/doc/svg_plot.qbk (original)
+++ sandbox/SOC/2007/visualization/libs/svg_plot/doc/svg_plot.qbk 2007-07-08 22:18:04 EDT (Sun, 08 Jul 2007)
@@ -9,6 +9,8 @@
[@http://www.boost.org/LICENSE_1_0.txt])
]
]
+
+
[section:preface Preface]
Normally, the first task when dealing with numerical data is to plot it. Humans have a fantastic capacity for visual understanding, and merely looking at data oganized in one, two, or three dimensions allows us to see relations not otherwise visible in a list of numbers. Computers, however, deal with information numerically, and C++ and the STL do not offer a way to bridge that gap. This library allows the user to easily plot data stored in STL containers with (hopefully!) minimal intervention.
[endsect]
@@ -112,6 +114,8 @@
return 0;
}
``
+
+[$my_file.svg]
[endsect]
[section:tutorial_simple_exam Basic Example Breakdown]
Let's examine what this does.
@@ -360,18 +364,18 @@
[h3 Using fill and stroke colors]
``
-plot(my_plot, my_data, "Lions", _fill_color = red, _stroke_color = black);
+plot(my_plot, my_data, "Lions", _fill_color = svg_color(red), _stroke_color = svg_color(black));
``
This has the same effect as the following:
``
-plot(my_plot, my_data, "Lions", red, black);
+plot(my_plot, my_data, "Lions", svg_color(red), svg_color(black));
``
and also the same effect as:
``
-plot(my_plot, my_data, "Lions", _stroke_color = black, _fill_color = red);
+plot(my_plot, my_data, "Lions", _stroke_color = svg_color(black), _fill_color = svg_color(red));
``
Since _fill_color is a deduced parameter, when two svg_colors are used in the same function call, they are always inferred in the following order: (fill, stroke).
@@ -379,8 +383,8 @@
[h3 Using all parameters]
``
plot(my_plot, my_data, "Lions",
- _fill_color = red,
- _stroke_color = black,
+ _fill_color = svg_color(red),
+ _stroke_color = svg_color(black),
_x_functor = my_functor());
``
Modified: sandbox/SOC/2007/visualization/libs/svg_plot/doc/svg_plot.xml
==============================================================================
--- sandbox/SOC/2007/visualization/libs/svg_plot/doc/svg_plot.xml (original)
+++ sandbox/SOC/2007/visualization/libs/svg_plot/doc/svg_plot.xml 2007-07-08 22:18:04 EDT (Sun, 08 Jul 2007)
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE library PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN" "http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">
-<article id="svg_plot" name="SVG_Plot" dirname="svg_plot" last-revision="$Date: 2007/07/08 20:44:43 $"
+<article id="svg_plot" name="SVG_Plot" dirname="svg_plot" last-revision="$Date: 2007/07/09 02:11:43 $"
xmlns:xi="http://www.w3.org/2001/XInclude">
<articleinfo>
<author>
@@ -68,11 +68,6 @@
with design or implementation, either leave them here or email me at jakevoytko
(at) gmail (dot) com
</para>
- <para>
- This page will hold examples of what I have implemented thus far, and what
- my program will be capable of in the future. More complete documentation will
- be live in a few days on my personal website.
- </para>
</section>
<section id="svg_plot.color">
<title> Colors</title>
@@ -98,6 +93,11 @@
that correctly implements the SVG format.
</para>
<para>
+ It is important to note that any integer value is accepted by the SVG standard,
+ but negative values are rounded to 0, and positive values > 255 are rounded
+ down to 255.
+ </para>
+ <para>
Constants are defined in an enum, svg_color_constant, in alphabetical order.
This facilitates quick lookup of their RGB values quickly in an array.
</para>
@@ -135,15 +135,15 @@
</para>
<itemizedlist>
<listitem>
- You need a svg_plot of some form
+ You need a one or two dimensional svg_plot
</listitem>
<listitem>
You need to call the write() command
</listitem>
</itemizedlist>
<para>
- That's it! However, just doing this won't give you anything useful. Let's
- take a minimal example:
+ That's it! However, just doing this won't give you anything useful. The following
+ can be considered a minimal example:
</para>
<section id="svg_plot.tutorial.tutorial_basic.tutorial_code_simple">
<title> Simple program</title>
@@ -177,6 +177,13 @@
<phrase role="special">}</phrase>
</programlisting>
</para>
+ <para>
+ <inlinemediaobject><imageobject><imagedata fileref="my_file.svg"></imagedata></imageobject>
+ <textobject>
+ <phrase>my_file</phrase>
+ </textobject>
+ </inlinemediaobject>
+ </para>
</section>
<section id="svg_plot.tutorial.tutorial_basic.tutorial_simple_exam">
<title> Basic Example Breakdown</title>
@@ -218,7 +225,7 @@
</programlisting>
</para>
<para>
- You also may have seen it used this way:
+ You have also seen it used to print to the console:
<programlisting>
<phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special"><<</phrase> <phrase role="string">"Hello"</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">name</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
</programlisting>
@@ -588,7 +595,7 @@
<para>
<programlisting>
-<phrase role="identifier">plot</phrase><phrase role="special">(</phrase><phrase role="identifier">my_plot</phrase><phrase role="special">,</phrase> <phrase role="identifier">my_data</phrase><phrase role="special">,</phrase> <phrase role="string">"Lions"</phrase><phrase role="special">,</phrase> <phrase role="identifier">_fill_color</phrase> <phrase role="special">=</phrase> <phrase role="identifier">red</phrase><phrase role="special">,</phrase> <phrase role="identifier">_stroke_color</phrase> <phrase role="special">=</phrase> <phrase role="identifier">black</phrase><phrase role="special">);</phrase>
+<phrase role="identifier">plot</phrase><phrase role="special">(</phrase><phrase role="identifier">my_plot</phrase><phrase role="special">,</phrase> <phrase role="identifier">my_data</phrase><phrase role="special">,</phrase> <phrase role="string">"Lions"</phrase><phrase role="special">,</phrase> <phrase role="identifier">_fill_color</phrase> <phrase role="special">=</phrase> <phrase role="identifier">svg_color</phrase><phrase role="special">(</phrase><phrase role="identifier">red</phrase><phrase role="special">),</phrase> <phrase role="identifier">_stroke_color</phrase> <phrase role="special">=</phrase> <phrase role="identifier">svg_color</phrase><phrase role="special">(</phrase><phrase role="identifier">black</phrase><phrase role="special">));</phrase>
</programlisting>
</para>
<para>
@@ -597,13 +604,13 @@
<para>
<programlisting>
-<phrase role="identifier">plot</phrase><phrase role="special">(</phrase><phrase role="identifier">my_plot</phrase><phrase role="special">,</phrase> <phrase role="identifier">my_data</phrase><phrase role="special">,</phrase> <phrase role="string">"Lions"</phrase><phrase role="special">,</phrase> <phrase role="identifier">red</phrase><phrase role="special">,</phrase> <phrase role="identifier">black</phrase><phrase role="special">);</phrase>
+<phrase role="identifier">plot</phrase><phrase role="special">(</phrase><phrase role="identifier">my_plot</phrase><phrase role="special">,</phrase> <phrase role="identifier">my_data</phrase><phrase role="special">,</phrase> <phrase role="string">"Lions"</phrase><phrase role="special">,</phrase> <phrase role="identifier">svg_color</phrase><phrase role="special">(</phrase><phrase role="identifier">red</phrase><phrase role="special">),</phrase> <phrase role="identifier">svg_color</phrase><phrase role="special">(</phrase><phrase role="identifier">black</phrase><phrase role="special">));</phrase>
</programlisting>
</para>
<para>
and also the same effect as:
<programlisting>
-<phrase role="identifier">plot</phrase><phrase role="special">(</phrase><phrase role="identifier">my_plot</phrase><phrase role="special">,</phrase> <phrase role="identifier">my_data</phrase><phrase role="special">,</phrase> <phrase role="string">"Lions"</phrase><phrase role="special">,</phrase> <phrase role="identifier">_stroke_color</phrase> <phrase role="special">=</phrase> <phrase role="identifier">black</phrase><phrase role="special">,</phrase> <phrase role="identifier">_fill_color</phrase> <phrase role="special">=</phrase> <phrase role="identifier">red</phrase><phrase role="special">);</phrase>
+<phrase role="identifier">plot</phrase><phrase role="special">(</phrase><phrase role="identifier">my_plot</phrase><phrase role="special">,</phrase> <phrase role="identifier">my_data</phrase><phrase role="special">,</phrase> <phrase role="string">"Lions"</phrase><phrase role="special">,</phrase> <phrase role="identifier">_stroke_color</phrase> <phrase role="special">=</phrase> <phrase role="identifier">svg_color</phrase><phrase role="special">(</phrase><phrase role="identifier">black</phrase><phrase role="special">),</phrase> <phrase role="identifier">_fill_color</phrase> <phrase role="special">=</phrase> <phrase role="identifier">svg_color</phrase><phrase role="special">(</phrase><phrase role="identifier">red</phrase><phrase role="special">));</phrase>
</programlisting>
</para>
<para>
@@ -619,8 +626,8 @@
<programlisting>
<phrase role="identifier">plot</phrase><phrase role="special">(</phrase><phrase role="identifier">my_plot</phrase><phrase role="special">,</phrase> <phrase role="identifier">my_data</phrase><phrase role="special">,</phrase> <phrase role="string">"Lions"</phrase><phrase role="special">,</phrase>
- <phrase role="identifier">_fill_color</phrase> <phrase role="special">=</phrase> <phrase role="identifier">red</phrase><phrase role="special">,</phrase>
- <phrase role="identifier">_stroke_color</phrase> <phrase role="special">=</phrase> <phrase role="identifier">black</phrase><phrase role="special">,</phrase>
+ <phrase role="identifier">_fill_color</phrase> <phrase role="special">=</phrase> <phrase role="identifier">svg_color</phrase><phrase role="special">(</phrase><phrase role="identifier">red</phrase><phrase role="special">),</phrase>
+ <phrase role="identifier">_stroke_color</phrase> <phrase role="special">=</phrase> <phrase role="identifier">svg_color</phrase><phrase role="special">(</phrase><phrase role="identifier">black</phrase><phrase role="special">),</phrase>
<phrase role="identifier">_x_functor</phrase> <phrase role="special">=</phrase> <phrase role="identifier">my_functor</phrase><phrase role="special">());</phrase>
</programlisting>
</para>
Modified: sandbox/SOC/2007/visualization/libs/svg_plot/test/Jamfile.v2
==============================================================================
--- sandbox/SOC/2007/visualization/libs/svg_plot/test/Jamfile.v2 (original)
+++ sandbox/SOC/2007/visualization/libs/svg_plot/test/Jamfile.v2 2007-07-08 22:18:04 EDT (Sun, 08 Jul 2007)
@@ -11,4 +11,5 @@
;
run test_color_constant.cpp ;
-
+run test_color_persistance.cpp ;
+run test_color_consistency.cpp ;
Modified: sandbox/SOC/2007/visualization/libs/svg_plot/test/test_color_constant.cpp
==============================================================================
--- sandbox/SOC/2007/visualization/libs/svg_plot/test/test_color_constant.cpp (original)
+++ sandbox/SOC/2007/visualization/libs/svg_plot/test/test_color_constant.cpp 2007-07-08 22:18:04 EDT (Sun, 08 Jul 2007)
@@ -145,7 +145,7 @@
BOOST_CHECK(constant_to_rgb(springgreen) == svg_color( 0, 255, 127));
BOOST_CHECK(constant_to_rgb(steelblue) == svg_color( 70, 130, 180));
- //need to specify boost::svg becuase tan is also a math function
+ //need to specify boost::svg because tan is also a math function
BOOST_CHECK(constant_to_rgb(boost::svg::tan) == svg_color(210, 180, 140));
BOOST_CHECK(constant_to_rgb(teal) == svg_color( 0, 128, 128));
Added: sandbox/SOC/2007/visualization/libs/svg_plot/test/test_color_peristance.cpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/visualization/libs/svg_plot/test/test_color_peristance.cpp 2007-07-08 22:18:04 EDT (Sun, 08 Jul 2007)
@@ -0,0 +1,70 @@
+#include <boost/test/included/test_exec_monitor.hpp>
+
+#include "../../../boost/svg_plot/svg_1d_plot.hpp"
+
+using namespace boost::unit_test;
+using namespace boost::svg;
+using namespace boost;
+
+// test to make sure that changes to colors in one section don't change
+// colors in another section. Logically, writing different color options
+// forwards and backwards checks for all possible overwrites
+int test_main(int, char* [])
+{
+ svg_1d_plot test_plot;
+ test_plot.set_background_color(svg_color(0, 0, 1))
+ .set_background_border_color(svg_color(0, 0, 2))
+ .set_legend_background_color(svg_color(0, 0, 3))
+ .set_legend_border_color(svg_color(0, 0, 4))
+ .set_plot_background_color(svg_color(0, 0, 5))
+ .set_title_color(svg_color(0, 0, 6))
+ .set_x_axis_color(svg_color(0, 0, 7))
+ .set_x_label_color(svg_color(0, 0, 8))
+ .set_x_major_grid_color(svg_color(0, 0, 9))
+ .set_x_minor_grid_color(svg_color(0, 0, 10))
+ .set_x_major_tick_color(svg_color(0, 0, 11))
+ .set_x_minor_tick_color(svg_color(0, 0, 12));
+
+ BOOST_CHECK(test_plot.get_background_color() == svg_color(0, 0, 1));
+ BOOST_CHECK(test_plot.get_background_border_color()
+ == svg_color(0, 0, 2));
+ BOOST_CHECK(test_plot.get_legend_background_color() == svg_color(0, 0, 3));
+ BOOST_CHECK(test_plot.get_legend_border_color() == svg_color(0, 0, 4));
+ BOOST_CHECK(test_plot.get_plot_background_color() == svg_color(0, 0, 5));
+ BOOST_CHECK(test_plot.get_title_color() == svg_color(0, 0, 6));
+ BOOST_CHECK(test_plot.get_x_axis_color() == svg_color(0, 0, 7));
+ BOOST_CHECK(test_plot.get_x_label_color() == svg_color(0, 0, 8));
+ BOOST_CHECK(test_plot.get_x_major_grid_color() == svg_color(0, 0, 9));
+ BOOST_CHECK(test_plot.get_x_minor_grid_color() == svg_color(0, 0, 10));
+ BOOST_CHECK(test_plot.get_x_major_tick_color() == svg_color(0, 0, 11));
+ BOOST_CHECK(test_plot.get_x_minor_tick_color() == svg_color(0, 0, 12));
+
+ test_plot.set_x_minor_tick_color(svg_color(0, 0, 12))
+ .set_x_major_tick_color(svg_color(0, 0, 11))
+ .set_x_minor_grid_color(svg_color(0, 0, 10))
+ .set_x_major_grid_color(svg_color(0, 0, 9))
+ .set_x_label_color(svg_color(0, 0, 8))
+ .set_x_axis_color(svg_color(0, 0, 7))
+ .set_title_color(svg_color(0, 0, 6))
+ .set_plot_background_color(svg_color(0, 0, 5))
+ .set_legend_border_color(svg_color(0, 0, 4))
+ .set_legend_background_color(svg_color(0, 0, 3))
+ .set_background_border_color(svg_color(0, 0, 2))
+ .set_background_color(svg_color(0, 0, 1));
+
+ BOOST_CHECK(test_plot.get_background_color() == svg_color(0, 0, 1));
+ BOOST_CHECK(test_plot.get_background_border_color()
+ == svg_color(0, 0, 2));
+ BOOST_CHECK(test_plot.get_legend_background_color() == svg_color(0, 0, 3));
+ BOOST_CHECK(test_plot.get_legend_border_color() == svg_color(0, 0, 4));
+ BOOST_CHECK(test_plot.get_plot_background_color() == svg_color(0, 0, 5));
+ BOOST_CHECK(test_plot.get_title_color() == svg_color(0, 0, 6));
+ BOOST_CHECK(test_plot.get_x_axis_color() == svg_color(0, 0, 7));
+ BOOST_CHECK(test_plot.get_x_label_color() == svg_color(0, 0, 8));
+ BOOST_CHECK(test_plot.get_x_major_grid_color() == svg_color(0, 0, 9));
+ BOOST_CHECK(test_plot.get_x_minor_grid_color() == svg_color(0, 0, 10));
+ BOOST_CHECK(test_plot.get_x_major_tick_color() == svg_color(0, 0, 11));
+ BOOST_CHECK(test_plot.get_x_minor_tick_color() == svg_color(0, 0, 12));
+
+ return 0;
+}
Added: sandbox/SOC/2007/visualization/libs/svg_plot/test/test_output_consistency.cpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/visualization/libs/svg_plot/test/test_output_consistency.cpp 2007-07-08 22:18:04 EDT (Sun, 08 Jul 2007)
@@ -0,0 +1,90 @@
+#include <boost/test/included/test_exec_monitor.hpp>
+
+#include "../../../boost/svg_plot/svg_1d_plot.hpp"
+
+#include <sstream>
+#include <vector>
+
+using namespace boost::unit_test;
+using namespace boost::svg;
+using namespace boost;
+using std::stringstream;
+using std::vector;
+
+double f(int x)
+{
+ return 2.*x;
+}
+
+double g(int x)
+{
+ return 1.5*x;
+}
+
+double h(int x)
+{
+ return -1*x+3;
+}
+
+// test to make sure that the output is consistent
+int test_main(int, char* [])
+{
+ stringstream test1, test2;
+ vector<double> data1, data2, data3;
+ svg_1d_plot my_plot;
+
+ for(int i = 0; i < 10; ++i)
+ {
+ data1.push_back(f(i));
+ data2.push_back(g(i));
+ data3.push_back(h(i));
+ }
+
+ // size/scale settings
+ my_plot.set_image_size(500, 350)
+ .set_x_scale(-3, 10);
+
+ // Text settings
+ my_plot.set_title("Oh My!")
+ .set_title_font_size(29)
+ .set_x_label("Time in Months");
+
+// command settings
+ my_plot.set_axis_on(true)
+ .set_legend_on(true)
+ .set_plot_window_on(true)
+ .set_x_label_on(true)
+ .set_x_major_labels_on(true);
+
+ // color settings
+ my_plot.set_background_color(svg_color(67, 111, 69))
+ .set_legend_background_color(svg_color(207, 202,167))
+ .set_plot_background_color(svg_color(136, 188, 126))
+ .set_title_color(white)
+ .set_x_axis_color(black)
+ .set_x_major_tick_color(black)
+ .set_legend_border_color(svg_color(102, 102, 84))
+ .set_x_minor_tick_color(black);
+
+//axis settings
+ my_plot.set_x_major_tick(2)
+ .set_x_num_minor_ticks(3)
+ .set_x_major_tick_length(14)
+ .set_x_minor_tick_length(7)
+ .set_x_major_tick_width(1)
+ .set_x_minor_tick_width(1);
+
+ //legend settings
+ my_plot.set_legend_title_font_size(15);
+
+ plot(my_plot, data2, "Lions", blue);
+ plot(my_plot, data1, "Tigers", purple);
+ plot(my_plot, data3, "Bears", red);
+
+ my_plot.write(test1);
+ my_plot.write(test2);
+
+ BOOST_CHECK(test1.str() == test2.str());
+
+ return 0;
+}
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk