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