source: trunk/lib/Graph.h @ 875

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

Fixes #403. Dates or revisions are used for x-axis.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.4 KB
Line 
1#ifndef _theplu_svndigest_graph_
2#define _theplu_svndigest_graph_
3
4// $Id: Graph.h 875 2009-11-23 18:49:49Z jari $
5
6/*
7  Copyright (C) 2009 Jari Häkkinen
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 <string>
26#include <vector>
27
28#include <plplot/plstream.h>
29
30namespace theplu {
31namespace svndigest {
32
33  class Graph
34  {
35  public:
36
37    /**
38       \brief Constructor
39
40       \a filename to be defined depending on whether we'll support
41       more output formats than SVG.
42    */
43    Graph(const std::string& filename);
44
45    /**
46       \brief Destructor
47    */
48    ~Graph(void);
49
50    static bool date_xticks(void);
51
52    /**
53       \brief Set the pen colour to use in next drawing call
54    */
55    void current_colour(unsigned char r, unsigned char g, unsigned char b);
56
57    /**
58       \brief Plot \a data using \a format for x-axis values when
59       dates are used.
60    */
61    void plot(const std::vector<unsigned int>& data,
62              const std::string& format="%y-%b");
63
64
65    /**
66       \brief Function setting the dates.
67
68       The date strings must be in svn format since underlying time
69       conversion are done with the Date class.
70
71       \see Date::svntime(std::string)
72    */
73    static void set_dates(const std::vector<std::string>& date);
74
75    static const std::vector<std::string>& xticks(void);
76
77    /**
78       \brief Set max y value in the plot
79
80       The plot area is (xstart,0) to (xend,\a ymax) where xend is
81       either the length of vector to plot (corresponds to latest
82       revision number) or the date of the last revision commit,
83       xstart is 0 or the date of the first commit.
84    */
85    double yrange(double ymax=0.0);
86
87  private:
88    unsigned int tick_spacing(const double range) const;
89
90    unsigned int plots_; // keep track of number of plots drawn
91    plstream pls_;
92    std::string title_;
93    static std::vector<std::string> xticks_;
94    double yrange_;
95  };
96
97}} // end of namespace svndigest and namespace theplu
98
99#endif
Note: See TracBrowser for help on using the repository browser.