source: trunk/lib/GnuplotFE.cc @ 149

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

Changed svnstat to svndigest.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.1 KB
Line 
1// $Id: GnuplotFE.cc 149 2006-08-12 09:11:46Z jari $
2
3/*
4  Copyright (C) 2006 Jari Häkkinen
5
6  This file is part of svndigest, http://lev.thep.lu.se/trac/svndigest
7
8  svndigest is free software; you can redistribute it and/or modify it
9  under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.
12
13  svndigest is distributed in the hope that it will be useful, but
14  WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21  02111-1307, USA.
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<u_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<u_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.