source: trunk/lib/GnuplotFE.cc @ 589

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

Replace u_int with unsigned int.

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