source: trunk/lib/Graph.h @ 1194

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

refs #475. First version using Sparse Vector class. This change is obviously quite invasive and thus the size of this commit is larger than what is preferred. I've tried to limit as much as possible and left optimization and style issues behind with a note 'FIXME'.

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