source: trunk/lib/GnuplotFE.cc @ 847

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

updating copyrights

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.1 KB
Line 
1// $Id: GnuplotFE.cc 847 2009-11-17 01:38:52Z peter $
2
3/*
4  Copyright (C) 2006 Jari Häkkinen
5  Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
6
7  This file is part of svndigest, http://dev.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 3 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 svndigest. If not, see <http://www.gnu.org/licenses/>.
21*/
22
23#include "GnuplotFE.h"
24#include "Gnuplot.h"
25
26#include <cassert>
27#include <string>
28#include <sstream>
29
30
31namespace theplu {
32namespace svndigest {
33
34
35  GnuplotFE* GnuplotFE::instance_=NULL;
36
37
38  void GnuplotFE::plot(std::vector<unsigned int>& y, const std::string& format)
39  {
40    if (!date_.empty()) {
41      assert(date_.size()>=y.size());
42      if (date_.size()!=y.size()) {
43        y.reserve(date_.size());
44        for (size_t i=y.size(); i<date_.size(); ++i)
45          y.push_back(*y.rbegin());
46      }
47      command(std::string("set xdata time"));
48      command("set timefmt '" + date_input_format_ + "'");
49      command("set format x '" + format + "'");
50      Gnuplot::plot(y,date_);
51      command(std::string("set xdata"));
52    }
53    else
54      Gnuplot::plot(y);
55  }
56
57
58  void GnuplotFE::replot(std::vector<unsigned int>& y)
59  {
60    if (!date_.empty()) {
61      assert(date_.size()>=y.size());
62      if (date_.size()!=y.size()) {
63        y.reserve(date_.size());
64        for (size_t i=y.size(); i<date_.size(); ++i)
65          y.push_back(*y.rbegin());
66      }
67      command(std::string("set xdata time"));
68      Gnuplot::replot(y,date_);
69      command(std::string("set xdata"));
70    }
71    else
72      Gnuplot::replot(y);
73  }
74
75
76  double GnuplotFE::yrange(double ymax)
77  {
78    if (ymax<0)
79      ymax=0;
80    std::ostringstream cmd;
81    cmd << "set yrang[0:";
82    if (ymax)
83      cmd << ymax;
84    cmd << "]";
85
86    command(cmd.str());
87    return ymax;
88  }
89
90
91}} // end of namespace svndigest and namespace theplu
Note: See TracBrowser for help on using the repository browser.