Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/Graph.cc
r872 r875 22 22 #include "Graph.h" 23 23 24 #include "Date.h" 25 24 26 #include <cmath> 25 27 … … 30 32 31 33 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) 33 35 { 34 36 // we use colour map 0 position 0 for background colour … … 59 61 60 62 61 void Graph::plot(const std::vector<unsigned int>& x)63 void Graph::plot(const std::vector<unsigned int>& y, const std::string& format) 62 64 { 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 64 69 if (!plots_) { 65 70 // draw plot frame, x and y ticks only for the first plot 66 71 pls_.scol0a(2,0,0,0,1.0); 67 72 pls_.col0(2); 73 74 if (date_xticks()) 75 pls_.timefmt(format.c_str()); 76 68 77 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 71 82 pls_.col0(1); 72 83 } 73 84 ++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]); 77 94 } 95 } 96 97 98 void Graph::set_dates(const std::vector<std::string>& date) 99 { 100 xticks_=date; 78 101 } 79 102 -
trunk/lib/Graph.h
r872 r875 56 56 57 57 /** 58 \brief Plot \a data 58 \brief Plot \a data using \a format for x-axis values when 59 dates are used. 59 60 */ 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); 61 74 62 75 static const std::vector<std::string>& xticks(void); … … 77 90 unsigned int plots_; // keep track of number of plots drawn 78 91 plstream pls_; 92 std::string title_; 79 93 static std::vector<std::string> xticks_; 80 94 double yrange_;
Note: See TracChangeset
for help on using the changeset viewer.