Changeset 133 for trunk/lib


Ignore:
Timestamp:
Aug 2, 2006, 9:52:39 PM (15 years ago)
Author:
Jari Häkkinen
Message:

Fixes ticket:31. Changed GnuplotFE plot and replot to make sure that data vectors have the same length.

Location:
trunk/lib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/GnuplotFE.cc

    r84 r133  
    2525#include "Gnuplot.h"
    2626
     27#include <cassert>
    2728#include <string>
    2829#include <sstream>
     
    3637
    3738
    38   void GnuplotFE::plot(const std::vector<u_int>& y, const std::string& format)
     39  void GnuplotFE::plot(std::vector<u_int>& y, const std::string& format)
    3940  {
    4041    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      }
    4148      command(std::string("set xdata time"));
    4249      command("set timefmt '" + date_input_format_ + "'");
     
    5057
    5158
    52   void GnuplotFE::replot(const std::vector<u_int>& y)
     59  void GnuplotFE::replot(std::vector<u_int>& y)
    5360  {
    5461    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      }
    5568      command(std::string("set xdata time"));
    5669      Gnuplot::replot(y,date_);
  • trunk/lib/GnuplotFE.h

    r123 r133  
    6060
    6161    ///
     62    /// Plot the data \a y. If a date vector is set with set_dates
     63    /// function before calling this function, the date vector will be
     64    /// used as x values using \a format as date format
     65    /// description. If no date vector is set then the \a y data will
     66    /// be plot as a function of subversion revision.
    6267    ///
     68    /// @see Gnuplot documentation for date formats.
    6369    ///
    64     void plot(const std::vector<u_int>& y,const std::string& format="%y-%b");
     70    /// @note \a y may change in this call: In some cases the date and
     71    /// \a y data vectors may have different length. This is an effect
     72    /// from subversions treatment of revisions, i.e., subversion
     73    /// controlled items may have different revisions but still up to
     74    /// date (at the items last changed revision). The date vector
     75    /// typically contains all revisions of the repository and thus a
     76    /// clash of different sized vectors may occur in gnuplot. This
     77    /// situation is resolved by adding elements to \a y such that the
     78    /// vector sizes match. The date vector is never expected to be
     79    /// shorter than \a y vector.
     80    ///
     81    void plot(std::vector<u_int>& y,const std::string& format="%y-%b");
    6582
    6683    ///
     84    /// Plot the data \a y as a function of \a x using the Gnuplot
     85    /// 'replot' command, see plot documentation for information on x
     86    /// axis data and possible modifications of \a y.
    6787    ///
    68     ///
    69     void replot(const std::vector<u_int>& y);
     88    void replot(std::vector<u_int>& y);
    7089
    7190    ///
Note: See TracChangeset for help on using the changeset viewer.