788 |
13 Apr 09 |
jari |
1 |
#ifndef _theplu_svndigest_graph_ |
788 |
13 Apr 09 |
jari |
2 |
#define _theplu_svndigest_graph_ |
788 |
13 Apr 09 |
jari |
3 |
|
788 |
13 Apr 09 |
jari |
// $Id$ |
788 |
13 Apr 09 |
jari |
5 |
|
788 |
13 Apr 09 |
jari |
6 |
/* |
902 |
27 Nov 09 |
peter |
Copyright (C) 2009 Jari Häkkinen, Peter Johansson |
1635 |
30 Mar 23 |
peter |
Copyright (C) 2010, 2011, 2023 Peter Johansson |
788 |
13 Apr 09 |
jari |
9 |
|
788 |
13 Apr 09 |
jari |
This file is part of svndigest, http://dev.thep.lu.se/svndigest |
788 |
13 Apr 09 |
jari |
11 |
|
788 |
13 Apr 09 |
jari |
svndigest is free software; you can redistribute it and/or modify it |
788 |
13 Apr 09 |
jari |
under the terms of the GNU General Public License as published by |
788 |
13 Apr 09 |
jari |
the Free Software Foundation; either version 3 of the License, or |
788 |
13 Apr 09 |
jari |
(at your option) any later version. |
788 |
13 Apr 09 |
jari |
16 |
|
788 |
13 Apr 09 |
jari |
svndigest is distributed in the hope that it will be useful, but |
788 |
13 Apr 09 |
jari |
WITHOUT ANY WARRANTY; without even the implied warranty of |
788 |
13 Apr 09 |
jari |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
788 |
13 Apr 09 |
jari |
General Public License for more details. |
788 |
13 Apr 09 |
jari |
21 |
|
788 |
13 Apr 09 |
jari |
You should have received a copy of the GNU General Public License |
788 |
13 Apr 09 |
jari |
along with svndigest. If not, see <http://www.gnu.org/licenses/>. |
788 |
13 Apr 09 |
jari |
24 |
*/ |
788 |
13 Apr 09 |
jari |
25 |
|
902 |
27 Nov 09 |
peter |
26 |
#include <config.h> |
902 |
27 Nov 09 |
peter |
27 |
|
1194 |
03 Oct 10 |
peter |
28 |
#include "Vector.h" |
1194 |
03 Oct 10 |
peter |
29 |
|
1255 |
01 Nov 10 |
peter |
30 |
#include <subversion-1/svn_types.h> |
1255 |
01 Nov 10 |
peter |
31 |
|
1197 |
04 Oct 10 |
peter |
32 |
#include <ctime> |
789 |
13 Apr 09 |
jari |
33 |
#include <string> |
789 |
13 Apr 09 |
jari |
34 |
#include <vector> |
789 |
13 Apr 09 |
jari |
35 |
|
902 |
27 Nov 09 |
peter |
36 |
#ifdef HAVE_PLPLOT |
855 |
19 Nov 09 |
jari |
37 |
#include <plplot/plstream.h> |
902 |
27 Nov 09 |
peter |
38 |
#else |
902 |
27 Nov 09 |
peter |
39 |
typedef int PLINT; |
902 |
27 Nov 09 |
peter |
40 |
typedef double PLFLT; |
902 |
27 Nov 09 |
peter |
41 |
typedef double plstream; |
902 |
27 Nov 09 |
peter |
42 |
#endif |
855 |
19 Nov 09 |
jari |
43 |
|
788 |
13 Apr 09 |
jari |
44 |
namespace theplu { |
788 |
13 Apr 09 |
jari |
45 |
namespace svndigest { |
788 |
13 Apr 09 |
jari |
46 |
|
946 |
03 Dec 09 |
jari |
47 |
/** |
946 |
03 Dec 09 |
jari |
Graph is used to generate plots in svndigest and is a specialized |
946 |
03 Dec 09 |
jari |
wrapper to the plplot plot library, http://plplot.sourceforge.net/ |
946 |
03 Dec 09 |
jari |
50 |
|
946 |
03 Dec 09 |
jari |
Graph allows some axis label manipulation, setting pen colour, |
946 |
03 Dec 09 |
jari |
and plotting lines. |
946 |
03 Dec 09 |
jari |
53 |
|
946 |
03 Dec 09 |
jari |
Graph supports three graphics formats - portable network graphics |
946 |
03 Dec 09 |
jari |
(png), scalable vector graphics (svg), and protable document |
946 |
03 Dec 09 |
jari |
format (pdf) - if the underlying plplot library was built with |
946 |
03 Dec 09 |
jari |
the appropriate modules. If not, rebuild and reinstall plplot. |
946 |
03 Dec 09 |
jari |
58 |
*/ |
1513 |
23 Sep 12 |
peter |
59 |
class Graph |
788 |
13 Apr 09 |
jari |
60 |
{ |
788 |
13 Apr 09 |
jari |
61 |
public: |
788 |
13 Apr 09 |
jari |
62 |
|
788 |
13 Apr 09 |
jari |
63 |
/** |
788 |
13 Apr 09 |
jari |
\brief Constructor |
863 |
20 Nov 09 |
jari |
65 |
|
863 |
20 Nov 09 |
jari |
\a filename to be defined depending on whether we'll support |
863 |
20 Nov 09 |
jari |
more output formats than SVG. |
883 |
24 Nov 09 |
jari |
68 |
|
883 |
24 Nov 09 |
jari |
\note The plot legend is created in the destructioe, i.e., when |
883 |
24 Nov 09 |
jari |
the graph object is destroyed. |
788 |
13 Apr 09 |
jari |
71 |
*/ |
1614 |
15 Feb 23 |
peter |
72 |
Graph(const std::string& filename, const std::string& format, |
1614 |
15 Feb 23 |
peter |
73 |
const std::string& title=""); |
789 |
13 Apr 09 |
jari |
74 |
|
855 |
19 Nov 09 |
jari |
75 |
/** |
855 |
19 Nov 09 |
jari |
\brief Destructor |
855 |
19 Nov 09 |
jari |
77 |
*/ |
855 |
19 Nov 09 |
jari |
78 |
~Graph(void); |
855 |
19 Nov 09 |
jari |
79 |
|
863 |
20 Nov 09 |
jari |
80 |
/** |
863 |
20 Nov 09 |
jari |
\brief Set the pen colour to use in next drawing call |
863 |
20 Nov 09 |
jari |
82 |
*/ |
929 |
02 Dec 09 |
jari |
83 |
void current_color(unsigned char r, unsigned char g, unsigned char b); |
855 |
19 Nov 09 |
jari |
84 |
|
1332 |
27 Jan 11 |
peter |
85 |
/** |
1332 |
27 Jan 11 |
peter |
86 |
*/ |
1332 |
27 Jan 11 |
peter |
87 |
static const std::vector<time_t>& dates(void); |
1332 |
27 Jan 11 |
peter |
88 |
|
916 |
30 Nov 09 |
jari |
89 |
static bool date_xticks(void); |
916 |
30 Nov 09 |
jari |
90 |
|
863 |
20 Nov 09 |
jari |
91 |
/** |
885 |
24 Nov 09 |
jari |
\brief Plot \a data and use \a lines and \a label to compose |
885 |
24 Nov 09 |
jari |
the legend label. |
885 |
24 Nov 09 |
jari |
94 |
|
885 |
24 Nov 09 |
jari |
The legend will be a coloured line followed by \a lines |
885 |
24 Nov 09 |
jari |
followed by \a label. |
885 |
24 Nov 09 |
jari |
97 |
|
885 |
24 Nov 09 |
jari |
The label order in the legend is reverse to the plot order, |
885 |
24 Nov 09 |
jari |
i.e., the last plotted line will get the top entry in the |
885 |
24 Nov 09 |
jari |
legend, the second to last plotted line will be the second |
885 |
24 Nov 09 |
jari |
legend entry, and so on. |
863 |
20 Nov 09 |
jari |
102 |
*/ |
1194 |
03 Oct 10 |
peter |
103 |
void plot(const SumVector& data, const std::string& label, |
883 |
24 Nov 09 |
jari |
104 |
unsigned int lines); |
863 |
20 Nov 09 |
jari |
105 |
|
875 |
23 Nov 09 |
jari |
106 |
/** |
1280 |
06 Nov 10 |
peter |
Sets the right end of xrange to correspond to revision \a rev. |
1280 |
06 Nov 10 |
peter |
108 |
*/ |
1280 |
06 Nov 10 |
peter |
109 |
static void rev_max(svn_revnum_t rev); |
1280 |
06 Nov 10 |
peter |
110 |
|
1280 |
06 Nov 10 |
peter |
111 |
/** |
1287 |
09 Nov 10 |
peter |
Gets the right end of xrange to correspond to revision \a rev. |
1287 |
09 Nov 10 |
peter |
113 |
*/ |
1287 |
09 Nov 10 |
peter |
114 |
static svn_revnum_t rev_max(void); |
1287 |
09 Nov 10 |
peter |
115 |
|
1287 |
09 Nov 10 |
peter |
116 |
/** |
1255 |
01 Nov 10 |
peter |
Sets the left end of xrange to correspond to revision \a rev. |
1255 |
01 Nov 10 |
peter |
118 |
*/ |
1255 |
01 Nov 10 |
peter |
119 |
static void rev_min(svn_revnum_t rev); |
1255 |
01 Nov 10 |
peter |
120 |
|
1255 |
01 Nov 10 |
peter |
121 |
/** |
1287 |
09 Nov 10 |
peter |
Gets the left end of xrange to correspond to revision \a rev. |
1287 |
09 Nov 10 |
peter |
123 |
*/ |
1287 |
09 Nov 10 |
peter |
124 |
static svn_revnum_t rev_min(void); |
1287 |
09 Nov 10 |
peter |
125 |
|
1287 |
09 Nov 10 |
peter |
126 |
/** |
875 |
23 Nov 09 |
jari |
\brief Function setting the dates. |
875 |
23 Nov 09 |
jari |
128 |
|
1197 |
04 Oct 10 |
peter |
The date is given in seconds (since 1/1 1970) |
875 |
23 Nov 09 |
jari |
130 |
*/ |
1197 |
04 Oct 10 |
peter |
131 |
static void set_dates(const std::vector<time_t>& date); |
875 |
23 Nov 09 |
jari |
132 |
|
883 |
24 Nov 09 |
jari |
133 |
/** |
863 |
20 Nov 09 |
jari |
\brief Set max y value in the plot |
863 |
20 Nov 09 |
jari |
135 |
|
863 |
20 Nov 09 |
jari |
The plot area is (xstart,0) to (xend,\a ymax) where xend is |
863 |
20 Nov 09 |
jari |
either the length of vector to plot (corresponds to latest |
863 |
20 Nov 09 |
jari |
revision number) or the date of the last revision commit, |
863 |
20 Nov 09 |
jari |
xstart is 0 or the date of the first commit. |
863 |
20 Nov 09 |
jari |
140 |
*/ |
883 |
24 Nov 09 |
jari |
141 |
double ymax(double ymax); |
855 |
19 Nov 09 |
jari |
142 |
|
855 |
19 Nov 09 |
jari |
143 |
private: |
883 |
24 Nov 09 |
jari |
144 |
|
916 |
30 Nov 09 |
jari |
// Copy constructor not implemented |
916 |
30 Nov 09 |
jari |
146 |
Graph(const Graph&); |
916 |
30 Nov 09 |
jari |
147 |
|
883 |
24 Nov 09 |
jari |
148 |
struct legend_data { |
883 |
24 Nov 09 |
jari |
149 |
std::string label; |
883 |
24 Nov 09 |
jari |
150 |
unsigned int lines; |
883 |
24 Nov 09 |
jari |
151 |
PLINT r,g,b; |
883 |
24 Nov 09 |
jari |
152 |
}; |
883 |
24 Nov 09 |
jari |
153 |
|
883 |
24 Nov 09 |
jari |
154 |
/** |
883 |
24 Nov 09 |
jari |
\brief Set the pen colour to use in next drawing call |
883 |
24 Nov 09 |
jari |
156 |
*/ |
929 |
02 Dec 09 |
jari |
157 |
void current_color(const legend_data&); |
883 |
24 Nov 09 |
jari |
158 |
void print_legend(void); |
1198 |
04 Oct 10 |
peter |
159 |
void staircase(svn_revnum_t rev0, PLFLT y0, svn_revnum_t rev1, PLFLT y1); |
872 |
22 Nov 09 |
jari |
160 |
|
883 |
24 Nov 09 |
jari |
161 |
std::vector<legend_data> legend_; |
863 |
20 Nov 09 |
jari |
162 |
unsigned int plots_; // keep track of number of plots drawn |
855 |
19 Nov 09 |
jari |
163 |
plstream pls_; |
1255 |
01 Nov 10 |
peter |
164 |
static svn_revnum_t rev_min_; |
1280 |
06 Nov 10 |
peter |
165 |
static svn_revnum_t rev_max_; |
875 |
23 Nov 09 |
jari |
166 |
std::string title_; |
1330 |
27 Jan 11 |
peter |
167 |
static std::vector<time_t> dates_; |
883 |
24 Nov 09 |
jari |
168 |
PLFLT xmin_, xmax_, xrange_, ymin_, ymax_, yrange_; |
788 |
13 Apr 09 |
jari |
169 |
}; |
788 |
13 Apr 09 |
jari |
170 |
|
788 |
13 Apr 09 |
jari |
171 |
}} // end of namespace svndigest and namespace theplu |
788 |
13 Apr 09 |
jari |
172 |
|
788 |
13 Apr 09 |
jari |
173 |
#endif |