1 | #ifndef _theplu_svndigest_gnuplotfe_ |
---|
2 | #define _theplu_svndigest_gnuplotfe_ |
---|
3 | |
---|
4 | // $Id: GnuplotFE.h 408 2007-06-29 10:08:19Z jari $ |
---|
5 | |
---|
6 | /* |
---|
7 | Copyright (C) 2006 Jari Häkkinen, Peter Johansson |
---|
8 | Copyright (C) 2007 Peter Johansson |
---|
9 | |
---|
10 | This file is part of svndigest, http://lev.thep.lu.se/trac/svndigest |
---|
11 | |
---|
12 | svndigest is free software; you can redistribute it and/or modify it |
---|
13 | under the terms of the GNU General Public License as published by |
---|
14 | the Free Software Foundation; either version 2 of the License, or |
---|
15 | (at your option) any later version. |
---|
16 | |
---|
17 | svndigest is distributed in the hope that it will be useful, but |
---|
18 | WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
20 | General Public License for more details. |
---|
21 | |
---|
22 | You should have received a copy of the GNU General Public License |
---|
23 | along with this program; if not, write to the Free Software |
---|
24 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
---|
25 | 02111-1307, USA. |
---|
26 | */ |
---|
27 | |
---|
28 | #include "Gnuplot.h" |
---|
29 | #include <string> |
---|
30 | #include <vector> |
---|
31 | |
---|
32 | |
---|
33 | namespace theplu { |
---|
34 | namespace svndigest { |
---|
35 | |
---|
36 | /// |
---|
37 | /// The GnuplotFE class is a front end to the Gnuplot class. This is |
---|
38 | /// a utility class needed to communicate plotting related |
---|
39 | /// information between objects. |
---|
40 | /// |
---|
41 | /// GnuplotFE provides one single global access point to the |
---|
42 | /// underlying gnuplot binary and makes sure that there is only one |
---|
43 | /// point of access to the binary. |
---|
44 | /// |
---|
45 | /// @see Design Patterns (the singleton pattern). |
---|
46 | /// @see Gnuplot |
---|
47 | /// |
---|
48 | class GnuplotFE : public Gnuplot |
---|
49 | { |
---|
50 | public: |
---|
51 | /// |
---|
52 | /// The destructor. |
---|
53 | /// |
---|
54 | ~GnuplotFE(void) { delete instance_; } |
---|
55 | |
---|
56 | /// |
---|
57 | /// @return dates. |
---|
58 | /// |
---|
59 | const std::vector<std::string>& dates(void) const { return date_; } |
---|
60 | |
---|
61 | /// |
---|
62 | /// Plot the data \a y. If a date vector is set with set_dates |
---|
63 | /// function before calling this function, the date vector will be |
---|
64 | /// used as x values using \a format as date format |
---|
65 | /// description. If no date vector is set then the \a y data will |
---|
66 | /// be plot as a function of subversion revision. |
---|
67 | /// |
---|
68 | /// @see Gnuplot documentation for date formats. |
---|
69 | /// |
---|
70 | /// @note \a y may change in this call: In some cases the date and |
---|
71 | /// \a y data vectors may have different length. This is an effect |
---|
72 | /// from subversions treatment of revisions, i.e., subversion |
---|
73 | /// controlled items may have different revisions but still up to |
---|
74 | /// date (at the items last changed revision). The date vector |
---|
75 | /// typically contains all revisions of the repository and thus a |
---|
76 | /// clash of different sized vectors may occur in gnuplot. This |
---|
77 | /// situation is resolved by adding elements to \a y such that the |
---|
78 | /// vector sizes match. The date vector is never expected to be |
---|
79 | /// shorter than \a y vector. |
---|
80 | /// |
---|
81 | void plot(std::vector<u_int>& y,const std::string& format="%y-%b"); |
---|
82 | |
---|
83 | /// |
---|
84 | /// Plot the data \a y as a function of \a x using the Gnuplot |
---|
85 | /// 'replot' command, see plot documentation for information on x |
---|
86 | /// axis data and possible modifications of \a y. |
---|
87 | /// |
---|
88 | void replot(std::vector<u_int>& y); |
---|
89 | |
---|
90 | /// |
---|
91 | /// @throw Re-throws a GnuplotException from Gnuplot. |
---|
92 | /// |
---|
93 | static GnuplotFE* instance(void) |
---|
94 | { if (!instance_) instance_=new GnuplotFE; return instance_; } |
---|
95 | |
---|
96 | /// |
---|
97 | /// sets format of date output. |
---|
98 | /// |
---|
99 | inline void set_date_format(const std::string& format) |
---|
100 | { date_output_format_ = format;} |
---|
101 | |
---|
102 | /// |
---|
103 | /// Function setting the dates. \a format must comply with strings |
---|
104 | /// in date. |
---|
105 | /// |
---|
106 | inline void set_dates(const std::vector<std::string>& date, |
---|
107 | const std::string& format="%Y-%m-%dT%H:%M:%SZ") |
---|
108 | { date_=date; date_input_format_=format; } |
---|
109 | |
---|
110 | /// |
---|
111 | /// Set the upper value for the y axis, the lower values is always |
---|
112 | /// zero. Call this function with an argument 0 (or without an |
---|
113 | /// argument) to cancel the current setting. Negative argument |
---|
114 | /// values are treated as zero value. |
---|
115 | /// |
---|
116 | /// @return Returns the actual set upper value. A zero value is |
---|
117 | /// returned if the current setting was cancelled. |
---|
118 | /// |
---|
119 | /// @see Gnuplot documentation for yrange |
---|
120 | /// |
---|
121 | double yrange(double ymax=0.0); |
---|
122 | |
---|
123 | private: |
---|
124 | /// |
---|
125 | /// @throw Re-throws a GnuplotException from Gnuplot. |
---|
126 | /// |
---|
127 | GnuplotFE(void) {}; |
---|
128 | |
---|
129 | /// |
---|
130 | /// Copy constructor, not implemented. |
---|
131 | /// |
---|
132 | GnuplotFE(const GnuplotFE&); |
---|
133 | |
---|
134 | std::vector<std::string> date_; |
---|
135 | std::string date_input_format_; |
---|
136 | std::string date_output_format_; |
---|
137 | static GnuplotFE* instance_; |
---|
138 | }; |
---|
139 | |
---|
140 | }} // end of namespace svndigest and namespace theplu |
---|
141 | |
---|
142 | #endif |
---|