Boost logo

Boost-Commit :

From: JakeVoytko_at_[hidden]
Date: 2007-08-19 12:01:55


Author: jakevoytko
Date: 2007-08-19 12:01:50 EDT (Sun, 19 Aug 2007)
New Revision: 38760
URL: http://svn.boost.org/trac/boost/changeset/38760

Log:
Added stylesheets
Added:
   sandbox/SOC/2007/visualization/boost/svg_plot/stylesheet.hpp (contents, props changed)
Text files modified:
   sandbox/SOC/2007/visualization/boost/svg_plot/detail/axis_plot_frame.hpp | 6 +++++
   sandbox/SOC/2007/visualization/boost/svg_plot/detail/svg_style_detail.hpp | 12 +++++++++++
   sandbox/SOC/2007/visualization/boost/svg_plot/svg.hpp | 42 ++++++++++++++++++++++++++++++++++++++-
   sandbox/SOC/2007/visualization/boost/svg_plot/svg_1d_plot.hpp | 12 +++++++++-
   sandbox/SOC/2007/visualization/boost/svg_plot/svg_boxplot.hpp | 9 ++++++-
   sandbox/SOC/2007/visualization/boost/svg_plot/svg_test.cpp | 18 +++++++++++-----
   6 files changed, 87 insertions(+), 12 deletions(-)

Modified: sandbox/SOC/2007/visualization/boost/svg_plot/detail/axis_plot_frame.hpp
==============================================================================
--- sandbox/SOC/2007/visualization/boost/svg_plot/detail/axis_plot_frame.hpp (original)
+++ sandbox/SOC/2007/visualization/boost/svg_plot/detail/axis_plot_frame.hpp 2007-08-19 12:01:50 EDT (Sun, 19 Aug 2007)
@@ -730,6 +730,12 @@
         return derived();
     }
 
+ Derived& load_stylesheet(const std::string& file)
+ {
+ derived().image.load_stylesheet(file);
+ return derived();
+ }
+
     unsigned int get_image_x_size()
     {
         return derived().image.get_x_size();

Modified: sandbox/SOC/2007/visualization/boost/svg_plot/detail/svg_style_detail.hpp
==============================================================================
--- sandbox/SOC/2007/visualization/boost/svg_plot/detail/svg_style_detail.hpp (original)
+++ sandbox/SOC/2007/visualization/boost/svg_plot/detail/svg_style_detail.hpp 2007-08-19 12:01:50 EDT (Sun, 19 Aug 2007)
@@ -9,6 +9,8 @@
 #ifndef _BOOST_SVG_SVG_STYLE_DETAIL_HPP
 #define _BOOST_SVG_SVG_STYLE_DETAIL_HPP
 
+#include <string>
+
 namespace boost{
 namespace svg{
 namespace detail{
@@ -22,7 +24,17 @@
     PLOT_LEGEND_BACKGROUND, PLOT_LEGEND_POINTS, PLOT_LEGEND_TEXT,
     PLOT_TITLE, SVG_PLOT_DOC_CHILDREN};
 
+std::string _document_ids[]=
+{
+ "background", "plotBackground", "yMinorGrid", "yMajorGrid",
+ "xMinorGrid", "xMajorGrid", "yAxis", "xAxis", "yMinorTicks",
+ "xMinorTicks", "yMajorTicks", "xMajorTicks", "plotLabels",
+ "yLabel", "xLabel", "plotLines", "plotPoints", "limitPoints",
+ "legendBackground", "legendPoints", "legendText", "title"
+};
+
 }
+
 }
 }
 #endif

Added: sandbox/SOC/2007/visualization/boost/svg_plot/stylesheet.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/visualization/boost/svg_plot/stylesheet.hpp 2007-08-19 12:01:50 EDT (Sun, 19 Aug 2007)
@@ -0,0 +1,118 @@
+// stylesheet.hpp
+// Copyright (C) Jacob Voytko 2007
+// Distributed under the Boost Software License, Version 1.0.
+// For more information, see http://www.boost.org
+// -----------------------------------------------------------------
+
+#ifndef _BOOST_SVG_STYLESHEET_HPP
+#define _BOOST_SVG_STYLESHEET_HPP
+
+
+#include <boost/spirit/core.hpp>
+#include <boost/spirit/utility/distinct.hpp>
+
+#include <exception>
+#include <string>
+#include <fstream>
+#include <ostream>
+#include <iostream>
+
+namespace boost{
+namespace svg{
+
+// Note: After GSoC, this will use the suggested CSS parser
+// from the W3C CSS 2.1 Standard
+struct css_parse : public ::boost::spirit::grammar<css_parse>
+{
+ template <typename ScannerT>
+ struct definition
+ {
+ definition(css_parse const& /*self*/)
+ {
+ expression
+ = *(class_expression | id_expression | normal_expression)
+ ;
+
+ class_expression
+ = wspace >> ::boost::spirit::ch_p('.')
+ >> *(::boost::spirit::alnum_p) >> wspace >> ::boost::spirit::ch_p('{')
+ >> *statement >> wspace >> ::boost::spirit::ch_p('}')
+ ;
+
+ id_expression
+ = wspace >> ::boost::spirit::ch_p('#')
+ >> *(::boost::spirit::alnum_p) >> wspace >> ::boost::spirit::ch_p('{')
+ >> wspace >> *statement >> wspace >> ::boost::spirit::ch_p('}')
+ ;
+
+ statement
+ = wspace >> identifier >> wspace >>
+ ::boost::spirit::ch_p(':') >> wspace >>
+ identifier >> wspace >>
+ ::boost::spirit::ch_p(';') >> wspace
+ ;
+
+ normal_expression
+ = wspace >> *(::boost::spirit::alnum_p) >> wspace
+ >> ::boost::spirit::ch_p('{') >> wspace
+ >> *statement >> wspace >> ::boost::spirit::ch_p('}') >> wspace
+ ;
+
+ identifier
+ = *(::boost::spirit::chset<>("a-zA-Z0-9#-"));
+ ;
+
+ // whitespace
+ wspace
+ = *(::boost::spirit::chset<>(" \t\n\r"));
+ ;
+ }
+
+ ::boost::spirit::rule<ScannerT> expression, statement, class_expression, wspace,
+ id_expression, normal_expression, identifier;
+
+ ::boost::spirit::rule<ScannerT> const&
+ start() const { return expression; }
+ };
+};
+
+bool validate_stylesheet(std::ifstream& file)
+{
+ css_parse my_css_parser;
+ std::string str, tmp;
+
+ while(getline(file, tmp))
+ {
+ str += tmp;
+ }
+
+ ::boost::spirit::parse_info<> info = ::boost::spirit::
+ parse(str.c_str(), my_css_parser,
+ ::boost::spirit::space_p);
+
+ if (!info.full)
+ {
+ std::cout<<info.stop;
+ return false;
+ }
+
+
+ return true;
+}
+
+bool validate_stylesheet(const std::string& file)
+{
+ std::ifstream f_str(file.c_str());
+
+ if(f_str.fail())
+ {
+ throw std::runtime_error("Failed to open " + file);
+ }
+
+ return validate_stylesheet(f_str);
+}
+
+}
+}
+
+#endif

Modified: sandbox/SOC/2007/visualization/boost/svg_plot/svg.hpp
==============================================================================
--- sandbox/SOC/2007/visualization/boost/svg_plot/svg.hpp (original)
+++ sandbox/SOC/2007/visualization/boost/svg_plot/svg.hpp 2007-08-19 12:01:50 EDT (Sun, 19 Aug 2007)
@@ -10,11 +10,13 @@
 #ifndef _BOOST_SVG_SVG_HPP
 #define _BOOST_SVG_SVG_HPP
 
+#include <string>
 #include <ostream>
 #include <fstream>
 #include <exception>
 #include <vector>
 
+#include "stylesheet.hpp"
 #include "detail/svg_tag.hpp"
 #include "svg_style.hpp"
 
@@ -31,6 +33,8 @@
 
         std::vector<clip_path_element> clip_paths;
 
+ std::string css;
+
 private:
 
     // -----------------------------------------------------------------
@@ -61,16 +65,20 @@
                << "\"http://www.w3.org/graphics/svg/1.1/dtd/svg11.dtd\">"<<std::endl;
     }
 
+ void _write_css(std::ostream& s_out)
+ {
+ s_out << "<defs><style type=\"text/css\"><![CDATA[" << css
+ << "]]></style></defs>" << std::endl;
+ }
+
 public:
 
     svg():x_size(400), y_size(400)
     {
-
     }
 
     svg(const svg& rhs):x_size(rhs.x_size), y_size(rhs.y_size)
     {
-
     }
 
     svg& write(const std::string& _file)
@@ -97,6 +105,8 @@
                         <<y_size<<"\" version=\"1.1\""
                         <<" xmlns=\"http://www.w3.org/2000/svg\">"<<std::endl;
 
+ _write_css(_s_out);
+
         _write_document(_s_out);
 
         //close off svg tag
@@ -185,6 +195,34 @@
     {
         return y_size;
     }
+
+ svg& load_stylesheet(const std::string& input)
+ {
+ std::ifstream if_str(input.c_str());
+
+ if(if_str.fail())
+ {
+ throw std::runtime_error("Error opening file " + input);
+ }
+
+ if(!validate_stylesheet(if_str))
+ {
+ throw std::runtime_error("Error loading stylesheet");
+ }
+
+ if_str.clear();
+ if_str.seekg(0);
+
+ std::string tmp;
+
+ css = "";
+ while(std::getline(if_str, tmp))
+ {
+ css += tmp;
+ }
+
+ return *this;
+ }
 }; // end class svg
 
 }

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-08-19 12:01:50 EDT (Sun, 19 Aug 2007)
@@ -78,8 +78,6 @@
 # pragma warning(pop)
 #endif
 
-
-
 // -----------------------------------------------------------------
 // This allows us to store plot state locally in svg_plot. We don't
 // store it in "svg" because transforming the points after they are
@@ -320,6 +318,14 @@
         }
     }
 
+ void _set_ids()
+ {
+ for(int i=0; i<detail::SVG_PLOT_DOC_CHILDREN; ++i)
+ {
+ image.get_g_element(i).id(detail::_document_ids[i]);
+ }
+ }
+
 public:
 
 // see documentation for default settings rationale
@@ -366,6 +372,8 @@
 
     image.get_g_element(detail::PLOT_X_MINOR_TICKS)
         .style().stroke_width(1);
+
+ _set_ids();
 }
 
 // -----------------------------------------------------------------

Modified: sandbox/SOC/2007/visualization/boost/svg_plot/svg_boxplot.hpp
==============================================================================
--- sandbox/SOC/2007/visualization/boost/svg_plot/svg_boxplot.hpp (original)
+++ sandbox/SOC/2007/visualization/boost/svg_plot/svg_boxplot.hpp 2007-08-19 12:01:50 EDT (Sun, 19 Aug 2007)
@@ -626,6 +626,11 @@
     image.get_g_element(boxplot::MILD_OUTLIERS).style().stroke_color(black).fill_color(black);
 }
 
+svg_boxplot& load_stylesheet(const std::string& file)
+{
+ image.load_stylesheet(file);
+ return *this;
+}
 
 svg_boxplot& write(const std::string& _str)
 {
@@ -674,9 +679,9 @@
     return *this;
 }
 
-svg_boxplot& y_major_labels_on(bool _cmd)
+svg_boxplot& x_labels_on(bool _cmd)
 {
- use_y_major_labels = _cmd;
+ use_x_major_labels = _cmd;
     return *this;
 }
 

Modified: sandbox/SOC/2007/visualization/boost/svg_plot/svg_test.cpp
==============================================================================
--- sandbox/SOC/2007/visualization/boost/svg_plot/svg_test.cpp (original)
+++ sandbox/SOC/2007/visualization/boost/svg_plot/svg_test.cpp 2007-08-19 12:01:50 EDT (Sun, 19 Aug 2007)
@@ -1,7 +1,9 @@
+#include "svg_1d_plot.hpp"
 #include "svg_boxplot.hpp"
 
 #include <vector>
 #include <cmath>
+#include <iostream>
 
 using std::multimap;
 using std::vector;
@@ -16,16 +18,20 @@
     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("D:\\style.css");
 
- my_plot.background_border_color(black)
- .y_range(0, 150)
- .y_major_interval(20)
+ my_1d_plot.background_border_color(black)
            .title("Boxplots of Common Functions");
     
     for(double i=.1; i < 10; i+=.1)
@@ -34,10 +40,10 @@
         data2.push_back(f(i));
     }
 
- my_plot.plot(data1, "[50 / x]");
- my_plot.plot(data2, "[40 + 25 * sin(50x)]");
+ my_1d_plot.plot(data1, "[50 / x]");
+ my_1d_plot.plot(data2, "[40 + 25 * sin(50x)]");
 
- my_plot.write("D:\\boxplot_test.svg");
+ my_1d_plot.write("D:\\1d_test.svg");
 
     return 0;
 }


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk