source: trunk/lib/Graph.h @ 946

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

Fixes #97. Well, gnuplot is now removed and sub task are defined in other tickets.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.0 KB
Line 
1#ifndef _theplu_svndigest_graph_
2#define _theplu_svndigest_graph_
3
4// $Id: Graph.h 946 2009-12-03 19:10:01Z 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  /**
42     Graph is used to generate plots in svndigest and is a specialized
43     wrapper to the plplot plot library, http://plplot.sourceforge.net/
44
45     Graph allows some axis label manipulation, setting pen colour,
46     and plotting lines.
47
48     Graph supports three graphics formats - portable network graphics
49     (png), scalable vector graphics (svg), and protable document
50     format (pdf) - if the underlying plplot library was built with
51     the appropriate modules. If not, rebuild and reinstall plplot.
52  */
53  class Graph
54  {
55  public:
56
57    /**
58       \brief Constructor
59
60       \a filename to be defined depending on whether we'll support
61       more output formats than SVG.
62
63       \note The plot legend is created in the destructioe, i.e., when
64       the graph object is destroyed.
65    */
66    explicit Graph(const std::string& filename);
67
68    /**
69       \brief Destructor
70    */
71    ~Graph(void);
72
73    /**
74       \brief Set the pen colour to use in next drawing call
75    */
76    void current_color(unsigned char r, unsigned char g, unsigned char b);
77
78    static bool date_xticks(void);
79
80    /**
81       \brief Plot \a data and use \a lines and \a label to compose
82       the legend label.
83
84       The legend will be a coloured line followed by \a lines
85       followed by \a label.
86
87       The label order in the legend is reverse to the plot order,
88       i.e., the last plotted line will get the top entry in the
89       legend, the second to last plotted line will be the second
90       legend entry, and so on.
91    */
92    void plot(const std::vector<unsigned int>& data, const std::string& label,
93              unsigned int lines);
94
95    /**
96       \brief Function setting the dates.
97
98       The date strings must be in svn format since underlying time
99       conversion are done with the Date class.
100
101       \see Date::svntime(std::string)
102    */
103    static void set_dates(const std::vector<std::string>& date);
104
105    /**
106       \brief Set x-axis tick value format to \a format. The format is
107       only used when dates are used.
108    */
109    void timeformat(const std::string& format);
110
111    static const std::vector<std::string>& xticks(void);
112
113    /**
114       \brief Set max y value in the plot
115
116       The plot area is (xstart,0) to (xend,\a ymax) where xend is
117       either the length of vector to plot (corresponds to latest
118       revision number) or the date of the last revision commit,
119       xstart is 0 or the date of the first commit.
120    */
121    double ymax(double ymax);
122
123  private:
124
125    // Copy constructor not implemented
126    Graph(const Graph&);
127
128    struct legend_data {
129      std::string label;
130      unsigned int lines;
131      PLINT r,g,b;
132    };
133
134    /**
135       \brief Set the pen colour to use in next drawing call
136    */
137    void current_color(const legend_data&);
138    void print_legend(void);
139    unsigned int tick_spacing(const double range) const;
140
141    std::vector<legend_data> legend_;
142    unsigned int plots_; // keep track of number of plots drawn
143    plstream pls_;
144    std::string timeformat_;
145    std::string title_;
146    static std::vector<std::string> xticks_;
147    PLFLT xmin_, xmax_, xrange_, ymin_, ymax_, yrange_;
148  };
149
150}} // end of namespace svndigest and namespace theplu
151
152#endif
Note: See TracBrowser for help on using the repository browser.