source: trunk/lib/Graph.h @ 929

Last change on this file since 929 was 929, checked in by Jari Häkkinen, 12 years ago

Changed Colour to Color for consistency.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.5 KB
Line 
1#ifndef _theplu_svndigest_graph_
2#define _theplu_svndigest_graph_
3
4// $Id: Graph.h 929 2009-12-02 08:02:12Z jari $
5
6/*
7  Copyright (C) 2009 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 <config.h>
26
27#include <string>
28#include <vector>
29
30#ifdef HAVE_PLPLOT
31#include <plplot/plstream.h>
32#else
33typedef int PLINT;
34typedef double PLFLT;
35typedef double plstream;
36#endif
37
38namespace theplu {
39namespace svndigest {
40
41  class Graph
42  {
43  public:
44
45    /**
46       \brief Constructor
47
48       \a filename to be defined depending on whether we'll support
49       more output formats than SVG.
50
51       \note The plot legend is created in the destructioe, i.e., when
52       the graph object is destroyed.
53    */
54    explicit Graph(const std::string& filename);
55
56    /**
57       \brief Destructor
58    */
59    ~Graph(void);
60
61    /**
62       \brief Set the pen colour to use in next drawing call
63    */
64    void current_color(unsigned char r, unsigned char g, unsigned char b);
65
66    static bool date_xticks(void);
67
68    /**
69       \brief Plot \a data and use \a lines and \a label to compose
70       the legend label.
71
72       The legend will be a coloured line followed by \a lines
73       followed by \a label.
74
75       The label order in the legend is reverse to the plot order,
76       i.e., the last plotted line will get the top entry in the
77       legend, the second to last plotted line will be the second
78       legend entry, and so on.
79    */
80    void plot(const std::vector<unsigned int>& data, const std::string& label,
81              unsigned int lines);
82
83    /**
84       \brief Function setting the dates.
85
86       The date strings must be in svn format since underlying time
87       conversion are done with the Date class.
88
89       \see Date::svntime(std::string)
90    */
91    static void set_dates(const std::vector<std::string>& date);
92
93    /**
94       \brief Set x-axis tick value format to \a format. The format is
95       only used when dates are used.
96    */
97    void timeformat(const std::string& format);
98
99    static const std::vector<std::string>& xticks(void);
100
101    /**
102       \brief Set max y value in the plot
103
104       The plot area is (xstart,0) to (xend,\a ymax) where xend is
105       either the length of vector to plot (corresponds to latest
106       revision number) or the date of the last revision commit,
107       xstart is 0 or the date of the first commit.
108    */
109    double ymax(double ymax);
110
111  private:
112
113    // Copy constructor not implemented
114    Graph(const Graph&);
115
116    struct legend_data {
117      std::string label;
118      unsigned int lines;
119      PLINT r,g,b;
120    };
121
122    /**
123       \brief Set the pen colour to use in next drawing call
124    */
125    void current_color(const legend_data&);
126    void print_legend(void);
127    unsigned int tick_spacing(const double range) const;
128
129    std::vector<legend_data> legend_;
130    unsigned int plots_; // keep track of number of plots drawn
131    plstream pls_;
132    std::string timeformat_;
133    std::string title_;
134    static std::vector<std::string> xticks_;
135    PLFLT xmin_, xmax_, xrange_, ymin_, ymax_, yrange_;
136  };
137
138}} // end of namespace svndigest and namespace theplu
139
140#endif
Note: See TracBrowser for help on using the repository browser.