source: trunk/lib/Graph.h @ 1198

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

plot stairs only when count changes in a revision. refs #475

  • 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 1198 2010-10-04 12:17:57Z peter $
5
6/*
7  Copyright (C) 2009 Jari Häkkinen, Peter Johansson
8  Copyright (C) 2010 Peter Johansson
9
10  This file is part of svndigest, http://dev.thep.lu.se/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 3 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 svndigest. If not, see <http://www.gnu.org/licenses/>.
24*/
25
26#include <config.h>
27
28#include "Vector.h"
29
30#include <ctime>
31#include <string>
32#include <vector>
33
34#ifdef HAVE_PLPLOT
35#include <plplot/plstream.h>
36#else
37typedef int PLINT;
38typedef double PLFLT;
39typedef double plstream;
40#endif
41
42namespace theplu {
43namespace svndigest {
44
45  /**
46     Graph is used to generate plots in svndigest and is a specialized
47     wrapper to the plplot plot library, http://plplot.sourceforge.net/
48
49     Graph allows some axis label manipulation, setting pen colour,
50     and plotting lines.
51
52     Graph supports three graphics formats - portable network graphics
53     (png), scalable vector graphics (svg), and protable document
54     format (pdf) - if the underlying plplot library was built with
55     the appropriate modules. If not, rebuild and reinstall plplot.
56  */
57  class Graph
58  {
59  public:
60
61    /**
62       \brief Constructor
63
64       \a filename to be defined depending on whether we'll support
65       more output formats than SVG.
66
67       \note The plot legend is created in the destructioe, i.e., when
68       the graph object is destroyed.
69    */
70    Graph(const std::string& filename, const std::string& format);
71
72    /**
73       \brief Destructor
74    */
75    ~Graph(void);
76
77    /**
78       \brief Set the pen colour to use in next drawing call
79    */
80    void current_color(unsigned char r, unsigned char g, unsigned char b);
81
82    static bool date_xticks(void);
83
84    /**
85       \brief Plot \a data and use \a lines and \a label to compose
86       the legend label.
87
88       The legend will be a coloured line followed by \a lines
89       followed by \a label.
90
91       The label order in the legend is reverse to the plot order,
92       i.e., the last plotted line will get the top entry in the
93       legend, the second to last plotted line will be the second
94       legend entry, and so on.
95    */
96    void plot(const SumVector& data, const std::string& label,
97              unsigned int lines);
98
99    /**
100       \brief Function setting the dates.
101
102       The date is given in seconds (since 1/1 1970)
103    */
104    static void set_dates(const std::vector<time_t>& date);
105
106    /**
107       \brief Set x-axis tick value format to \a format. The format is
108       only used when dates are used.
109    */
110    void timeformat(const std::string& format);
111
112    static const std::vector<time_t>& xticks(void);
113
114    /**
115       \brief Set max y value in the plot
116
117       The plot area is (xstart,0) to (xend,\a ymax) where xend is
118       either the length of vector to plot (corresponds to latest
119       revision number) or the date of the last revision commit,
120       xstart is 0 or the date of the first commit.
121    */
122    double ymax(double ymax);
123
124  private:
125
126    // Copy constructor not implemented
127    Graph(const Graph&);
128
129    struct legend_data {
130      std::string label;
131      unsigned int lines;
132      PLINT r,g,b;
133    };
134
135    /**
136       \brief Set the pen colour to use in next drawing call
137    */
138    void current_color(const legend_data&);
139    void print_legend(void);
140    void staircase(svn_revnum_t rev0, PLFLT y0, svn_revnum_t rev1, PLFLT y1);
141    unsigned int tick_spacing(const double range) const;
142
143    std::vector<legend_data> legend_;
144    unsigned int plots_; // keep track of number of plots drawn
145    plstream pls_;
146    std::string timeformat_;
147    std::string title_;
148    static std::vector<time_t> xticks_;
149    PLFLT xmin_, xmax_, xrange_, ymin_, ymax_, yrange_;
150  };
151
152}} // end of namespace svndigest and namespace theplu
153
154#endif
Note: See TracBrowser for help on using the repository browser.