source: trunk/lib/GnuplotFE.cc @ 796

Last change on this file since 796 was 768, checked in by Peter Johansson, 13 years ago

Merged patch release 0.6.7 to trunk. Delta 0.6.7 - 0.6.6

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