Changeset 60 for trunk/lib/Gnuplot.cc


Ignore:
Timestamp:
Jan 16, 2006, 11:03:04 AM (16 years ago)
Author:
Peter Johansson
Message:

plotting vs date rather than revision

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Gnuplot.cc

    r39 r60  
    44
    55#include <cstdio>
    6 #include <fstream>
    7 #include <vector>
    86#include <unistd.h>
     7#include <string>
    98
     9#include <iostream>
    1010
    1111namespace theplu {
     
    5757  }
    5858
     59 
     60  void Gnuplot::date_plot(const std::vector<double>& y,
     61                          const std::string& format)
     62  {
     63    command(std::string("set xdata time"));
     64    command("set timefmt '" + date_input_format_ + "'");
     65    command("set format x '" + format + "'");
     66    plot(y,date_,"plot");
     67  }
     68
     69
     70  void Gnuplot::date_replot(const std::vector<double>& y,
     71                            const std::string& format)
     72  {
     73    // Peter is this working, really?
     74    //command(std::string("set xdata time"));
     75    //command("set format x '" + format + "'");
     76    plot(y,date_,"replot");
     77  }
     78
    5979
    6080  void Gnuplot::tokenizer(const std::string& in,
     
    81101
    82102
    83   void Gnuplot::plot(const std::vector<double>& y, const std::vector<double>& x,
    84                      const std::string& plotcmd)
    85   {
    86     char name[]="/tmp/svnstatXXXXXX";
    87     if (mkstemp(name) == -1)
    88       throw GnuplotException(std::string("Failed to get unique filename: ") +
    89                              name);
    90     std::ofstream tmp(name);
    91     if (tmp.bad())
    92       throw GnuplotException(std::string("Failed to create file: ") + name);
    93     for (std::vector<double>::size_type i=0; i<y.size(); ++i)
    94       if (x.empty())
    95         tmp << y[i] << '\n';
    96       else
    97         tmp << x[i] << '\t' << y[i] << '\n';
    98     tmp.close();
    99     std::string cmdstring(plotcmd + " '" + name + "' title '" + linetitle_ +
    100                           "' with " + linestyle_ + "\n");
    101     command(cmdstring);
    102 
    103     // need to keep track of created files since the gnuplot command
    104     // is not executed until pclose on MacOSX, shouldn't the fflush
    105     // fix this in the command() member function?
    106     tempfiles_.push_back(name);
    107   }
    108 
    109 
    110103}} // end of namespace svnstat and namespace theplu
Note: See TracChangeset for help on using the changeset viewer.