Changeset 883
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/Graph.cc
r882 r883 25 25 26 26 #include <cmath> 27 #include <iostream> 28 #include <sstream> 27 29 28 30 namespace theplu { … … 32 34 33 35 Graph::Graph(const std::string& filename) 34 : plots_(0), pls_(1,1,"svg",filename.c_str()), title_(filename) 36 : plots_(0), pls_(1,1,"svg",filename.c_str()), timeformat_("%y-%b"), 37 title_(filename), xmin_(0.0), xmax_(0.0), ymin_(0.0), ymax_(0.0) 35 38 { 39 legend_.reserve(20); 36 40 // we use colour map 0 position 0 for background colour 37 41 pls_.scolbga(230,230,230,1); … … 44 48 Graph::~Graph(void) 45 49 { 50 print_legend(); 46 51 } 47 52 … … 53 58 54 59 60 void Graph::current_colour(const legend_data& legend) 61 { 62 // we use colour map 0 position 1 for current colour 63 pls_.scol0a(1,legend.r,legend.g,legend.b,1.0); 64 } 65 66 55 67 void Graph::current_colour(unsigned char r, unsigned char g, unsigned char b) 56 68 { 57 69 // we use colour map 0 position 1 for current colour 58 70 pls_.scol0a(1,r,g,b,1.0); 59 pls_.col0(1);60 71 } 61 72 62 73 63 void Graph::plot(const std::vector<unsigned int>& y, const std::string& l egend,64 const std::string& timeformat)74 void Graph::plot(const std::vector<unsigned int>& y, const std::string& label, 75 unsigned int lines) 65 76 { 66 unsigned int xmin= date_xticks() ? Date(xticks_.front()).seconds() : 0; 67 unsigned int xmax= date_xticks() ? Date(xticks_.back()).seconds() : y.size(); 68 pls_.wind(xmin, xmax, 0, ymax_); 77 if (!plots_) { 78 xmin_= date_xticks() ? Date(xticks_.front()).seconds() : 0; 79 xmax_= date_xticks() ? Date(xticks_.back()).seconds() : y.size(); 80 xrange_=xmax_-xmin_; 81 yrange_=ymax_-ymin_; 82 pls_.wind(xmin_, xmax_, ymin_, ymax_); 69 83 70 if (!plots_) {71 84 // draw plot frame, x and y ticks only for the first plot 72 85 pls_.scol0a(2,0,0,0,1.0); … … 74 87 75 88 if (date_xticks()) 76 pls_.timefmt(timeformat .c_str());89 pls_.timefmt(timeformat_.c_str()); 77 90 78 unsigned int ytickspacing=tick_spacing(ymax_ );79 unsigned int xtickspacing=tick_spacing(xmax -xmin);91 unsigned int ytickspacing=tick_spacing(ymax_-ymin_); 92 unsigned int xtickspacing=tick_spacing(xmax_-xmin_); 80 93 pls_.box("bcnstd", xtickspacing, 1, "bcnstv", ytickspacing, 2); 81 94 pls_.lab("Date", "Number of lines", title_.c_str()); … … 83 96 ++plots_; 84 97 85 print_legend(xmin,0,xmax,ymax_,legend);86 98 pls_.col0(1); 87 99 for (unsigned int i=1; i<y.size(); ++i) { … … 95 107 pls_.join(x0, y[i] , x1, y[i]); 96 108 } 109 110 legend_data legend; 111 legend.label=label; 112 legend.lines=lines; 113 pls_.gcol0(1,legend.r,legend.g,legend.b); 114 legend_.push_back(legend); 97 115 } 98 116 99 117 100 void Graph::print_legend(PLFLT xmin, PLFLT ymin, PLFLT xmax, PLFLT ymax, 101 const std::string& legend) 118 void Graph::print_legend(void) 102 119 { 103 PLFLT xrange=(xmax-xmin); 104 PLFLT length=0.05*xrange; 105 PLFLT dx=0.01*xrange; 106 PLFLT x=4*dx+xmin+length; 107 PLFLT yrange=(ymax-ymin); 108 PLFLT dy=0.001*yrange; 109 PLFLT y=(1.-0.05*plots_)*yrange; 110 pls_.col0(1); 111 pls_.join(x-dx, y-3*dy, x-dx-length, y-3*dy); 112 pls_.col0(2); 113 pls_.ptex(x, y, 0, 0, 0, legend.c_str()); 120 PLFLT line_length=0.05*xrange_; 121 PLFLT x=xmin_+1.7*line_length; 122 unsigned char characteristic=log10(ymax_); 123 PLFLT legend_lines_length=0.016*xrange_*(characteristic+1); 124 PLFLT dx=0.005*xrange_; 125 PLFLT dy=0.003*yrange_; 126 unsigned int row=0; 127 for (std::vector<legend_data>::const_iterator i=legend_.begin(); 128 i!=legend_.end(); i++, ++row) { 129 PLFLT y=(0.95-0.04*row)*yrange_; 130 current_colour(*i); 131 pls_.col0(1); 132 pls_.join(x-line_length, y-dy, x, y-dy); 133 std::stringstream ss; 134 ss << i->lines; 135 pls_.col0(2); 136 pls_.ptex(x+legend_lines_length+dx*2, y, 0, 0, 0, i->label.c_str()); 137 pls_.ptex(x+legend_lines_length+dx , y, 0, 0, 1, ss.str().c_str()); 138 } 114 139 } 115 140 … … 131 156 132 157 158 void Graph::timeformat(const std::string& format) 159 { 160 timeformat_=format; 161 } 162 163 133 164 const std::vector<std::string>& Graph::xticks(void) 134 165 { -
trunk/lib/Graph.h
r882 r883 40 40 \a filename to be defined depending on whether we'll support 41 41 more output formats than SVG. 42 43 \note The plot legend is created in the destructioe, i.e., when 44 the graph object is destroyed. 42 45 */ 43 46 explicit Graph(const std::string& filename); … … 59 62 dates are used. 60 63 */ 61 void plot(const std::vector<unsigned int>& data, const std::string& l egend,62 const std::string& timeformat="%y-%b");64 void plot(const std::vector<unsigned int>& data, const std::string& label, 65 unsigned int lines); 63 66 64 67 /** … … 72 75 static void set_dates(const std::vector<std::string>& date); 73 76 77 /** 78 \brief Set x-axis tick value format to \a format. The format is 79 only used when dates are used. 80 */ 81 void timeformat(const std::string& format); 82 74 83 static const std::vector<std::string>& xticks(void); 75 84 … … 82 91 xstart is 0 or the date of the first commit. 83 92 */ 84 double ymax(double ymax =0.0);93 double ymax(double ymax); 85 94 86 95 private: 87 void print_legend(PLFLT xmin, PLFLT ymin, PLFLT xmax, PLFLT ymax, 88 const std::string& legend); 96 97 struct legend_data { 98 std::string label; 99 unsigned int lines; 100 PLINT r,g,b; 101 }; 102 103 /** 104 \brief Set the pen colour to use in next drawing call 105 */ 106 void current_colour(const legend_data&); 107 void print_legend(void); 89 108 unsigned int tick_spacing(const double range) const; 90 109 110 std::vector<legend_data> legend_; 91 111 unsigned int plots_; // keep track of number of plots drawn 92 112 plstream pls_; 113 std::string timeformat_; 93 114 std::string title_; 94 115 static std::vector<std::string> xticks_; 95 double ymax_;116 PLFLT xmin_, xmax_, xrange_, ymin_, ymax_, yrange_; 96 117 }; 97 118 -
trunk/lib/Stats.cc
r882 r883 387 387 388 388 size_t plotno=author_cont.size(); 389 std::stringstream ss;390 389 vec_type::iterator end(author_cont.end()); 391 390 for (vec_type::iterator i(author_cont.begin()); i!=end; ++i) { 392 ss.str("");393 ss << get_back(*stat, i->first) << " " << i->first;394 391 // the RGB values below must be replaced ... seg fault will 395 392 // happen! plotno will probably become unused when below row is 396 393 // removed or fixed. 397 394 gp.current_colour(25*plotno,255-25*plotno,75); 398 gp.plot(i->second, ss.str()); 399 } 400 ss.str(""); 401 ss << get_back(*stat, "all") << " total"; 395 gp.plot(i->second, i->first, get_back(*stat, i->first)); 396 } 402 397 gp.current_colour(255,0,0); 403 gp.plot(total, ss.str());398 gp.plot(total, "total", get_back(*stat, "all")); 404 399 405 400 return filename; … … 413 408 double yrange_max=1.03*total.back()+1; 414 409 gp.ymax(yrange_max); 415 std::stringstream ss;416 410 417 ss.str("");418 411 std::vector<unsigned int> x(get_vector(code_stats(), "all")); 419 ss << x.back() << " code";420 412 gp.current_colour(255,255,0); 421 gp.plot(x, ss.str()); 422 423 ss.str(""); 413 gp.plot(x, "code", x.back()); 414 424 415 x = get_vector(comment_or_copy_stats(), "all"); 425 ss << x.back() << " comment";426 416 gp.current_colour(0,0,255); 427 gp.plot(x, ss.str()); 428 429 ss.str(""); 417 gp.plot(x, "comment", x.back()); 418 430 419 x = get_vector(other_stats(), "all"); 431 ss << x.back() << " other";432 420 gp.current_colour(0,255,0); 433 gp.plot(x, ss.str()); 434 435 ss.str(""); 436 ss << total.back() << " total"; 421 gp.plot(x, "other", x.back()); 422 437 423 gp.current_colour(255,0,0); 438 gp.plot(total, ss.str());424 gp.plot(total, "total", total.back()); 439 425 } 440 426
Note: See TracChangeset
for help on using the changeset viewer.