Changeset 875 for trunk/lib


Ignore:
Timestamp:
Nov 23, 2009, 7:49:49 PM (12 years ago)
Author:
Jari Häkkinen
Message:

Fixes #403. Dates or revisions are used for x-axis.

Location:
trunk/lib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Graph.cc

    r872 r875  
    2222#include "Graph.h"
    2323
     24#include "Date.h"
     25
    2426#include <cmath>
    2527
     
    3032
    3133  Graph::Graph(const std::string& filename)
    32     : plots_(0), pls_(1,1,"svg",filename.c_str())
     34    : plots_(0), pls_(1,1,"svg",filename.c_str()), title_(filename)
    3335  {
    3436    // we use colour map 0 position 0 for background colour
     
    5961
    6062
    61   void Graph::plot(const std::vector<unsigned int>& x)
     63  void Graph::plot(const std::vector<unsigned int>& y, const std::string& format)
    6264  {
    63     pls_.wind(0, x.size(), 0, yrange_);
     65    unsigned int xmin= date_xticks() ? Date(xticks_.front()).seconds() : 0;
     66    unsigned int xmax= date_xticks() ? Date(xticks_.back()).seconds() : y.size();
     67    pls_.wind(xmin, xmax, 0, yrange_);
     68
    6469    if (!plots_) {
    6570      // draw plot frame, x and y ticks only for the first plot
    6671      pls_.scol0a(2,0,0,0,1.0);
    6772      pls_.col0(2);
     73
     74      if (date_xticks())
     75        pls_.timefmt(format.c_str());
     76
    6877      unsigned int ytickspacing=tick_spacing(yrange_);
    69       unsigned int xtickspacing=tick_spacing(x.size());
    70       pls_.box("bcnstv", xtickspacing, 1, "bcnstv", ytickspacing, 1);
     78      unsigned int xtickspacing=tick_spacing(xmax-xmin);
     79      pls_.box("bcnstd", xtickspacing, 1, "bcnstv", ytickspacing, 2);
     80      pls_.lab("Date", "Number of lines", title_.c_str());
     81
    7182      pls_.col0(1);
    7283    }
    7384    ++plots_;
    74     for (unsigned int i=1; i<x.size(); ++i) {
    75       pls_.join(i-1,x[i-1],i-1,x[i]);
    76       pls_.join(i-1,x[i],i,x[i]);
     85    for (unsigned int i=1; i<y.size(); ++i) {
     86      PLFLT x0=i-1;
     87      PLFLT x1=i;
     88      if (date_xticks()) {
     89        x0=Date(xticks_[i-1]).seconds();
     90        x1=Date(xticks_[i]).seconds();
     91      }
     92      pls_.join(x0, y[i-1], x0, y[i]);
     93      pls_.join(x0, y[i]  , x1, y[i]);
    7794    }
     95  }
     96
     97
     98  void Graph::set_dates(const std::vector<std::string>& date)
     99  {
     100    xticks_=date;
    78101  }
    79102
  • trunk/lib/Graph.h

    r872 r875  
    5656
    5757    /**
    58        \brief Plot \a data
     58       \brief Plot \a data using \a format for x-axis values when
     59       dates are used.
    5960    */
    60     void plot(const std::vector<unsigned int>& data);
     61    void plot(const std::vector<unsigned int>& data,
     62              const std::string& format="%y-%b");
     63
     64
     65    /**
     66       \brief Function setting the dates.
     67
     68       The date strings must be in svn format since underlying time
     69       conversion are done with the Date class.
     70
     71       \see Date::svntime(std::string)
     72    */
     73    static void set_dates(const std::vector<std::string>& date);
    6174
    6275    static const std::vector<std::string>& xticks(void);
     
    7790    unsigned int plots_; // keep track of number of plots drawn
    7891    plstream pls_;
     92    std::string title_;
    7993    static std::vector<std::string> xticks_;
    8094    double yrange_;
Note: See TracChangeset for help on using the changeset viewer.