source: trunk/lib/GnuplotFE.h @ 847

Last change on this file since 847 was 847, checked in by Peter Johansson, 12 years ago

updating copyrights

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