1 | // $Id: GnuplotFE.cc 685 2008-08-04 14:53:58Z peter $ |
---|
2 | |
---|
3 | /* |
---|
4 | Copyright (C) 2006 Jari Häkkinen |
---|
5 | Copyright (C) 2007 Peter Johansson |
---|
6 | Copyright (C) 2008 Jari Häkkinen |
---|
7 | |
---|
8 | This file is part of svndigest, http://dev.thep.lu.se/svndigest |
---|
9 | |
---|
10 | svndigest is free software; you can redistribute it and/or modify it |
---|
11 | under the terms of the GNU General Public License as published by |
---|
12 | the Free Software Foundation; either version 2 of the License, or |
---|
13 | (at your option) any later version. |
---|
14 | |
---|
15 | svndigest is distributed in the hope that it will be useful, but |
---|
16 | WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
18 | General Public License for more details. |
---|
19 | |
---|
20 | You should have received a copy of the GNU General Public License |
---|
21 | along with this program; if not, write to the Free Software |
---|
22 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
---|
23 | 02111-1307, USA. |
---|
24 | */ |
---|
25 | |
---|
26 | #include "GnuplotFE.h" |
---|
27 | #include "Gnuplot.h" |
---|
28 | |
---|
29 | #include <cassert> |
---|
30 | #include <string> |
---|
31 | #include <sstream> |
---|
32 | |
---|
33 | |
---|
34 | namespace theplu { |
---|
35 | namespace svndigest { |
---|
36 | |
---|
37 | |
---|
38 | GnuplotFE* GnuplotFE::instance_=NULL; |
---|
39 | |
---|
40 | |
---|
41 | void GnuplotFE::plot(std::vector<unsigned int>& y, const std::string& format) |
---|
42 | { |
---|
43 | if (!date_.empty()) { |
---|
44 | assert(date_.size()>=y.size()); |
---|
45 | if (date_.size()!=y.size()) { |
---|
46 | y.reserve(date_.size()); |
---|
47 | for (size_t i=y.size(); i<date_.size(); ++i) |
---|
48 | y.push_back(*y.rbegin()); |
---|
49 | } |
---|
50 | command(std::string("set xdata time")); |
---|
51 | command("set timefmt '" + date_input_format_ + "'"); |
---|
52 | command("set format x '" + format + "'"); |
---|
53 | Gnuplot::plot(y,date_); |
---|
54 | command(std::string("set xdata")); |
---|
55 | } |
---|
56 | else |
---|
57 | Gnuplot::plot(y); |
---|
58 | } |
---|
59 | |
---|
60 | |
---|
61 | void GnuplotFE::replot(std::vector<unsigned int>& y) |
---|
62 | { |
---|
63 | if (!date_.empty()) { |
---|
64 | assert(date_.size()>=y.size()); |
---|
65 | if (date_.size()!=y.size()) { |
---|
66 | y.reserve(date_.size()); |
---|
67 | for (size_t i=y.size(); i<date_.size(); ++i) |
---|
68 | y.push_back(*y.rbegin()); |
---|
69 | } |
---|
70 | command(std::string("set xdata time")); |
---|
71 | Gnuplot::replot(y,date_); |
---|
72 | command(std::string("set xdata")); |
---|
73 | } |
---|
74 | else |
---|
75 | Gnuplot::replot(y); |
---|
76 | } |
---|
77 | |
---|
78 | |
---|
79 | double GnuplotFE::yrange(double ymax) |
---|
80 | { |
---|
81 | if (ymax<0) |
---|
82 | ymax=0; |
---|
83 | std::ostringstream cmd; |
---|
84 | cmd << "set yrang[0:"; |
---|
85 | if (ymax) |
---|
86 | cmd << ymax; |
---|
87 | cmd << "]"; |
---|
88 | |
---|
89 | command(cmd.str()); |
---|
90 | return ymax; |
---|
91 | } |
---|
92 | |
---|
93 | |
---|
94 | }} // end of namespace svndigest and namespace theplu |
---|