Changeset 371


Ignore:
Timestamp:
Jun 19, 2007, 8:54:41 PM (16 years ago)
Author:
Peter Johansson
Message:

fixes #201 plot legend is sorted with respect to contributed lines

Location:
trunk/lib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Stats.cc

    r361 r371  
    187187    double yrange_max=1.03*total.back()+1;
    188188    gp->yrange(yrange_max);
    189     size_t plotno=1;
     189
     190
     191    typedef std::vector<std::pair<std::string, std::vector<u_int> > > vec_type;
     192    vec_type author_cont;
     193    author_cont.reserve(stat->size());
     194    for (MapConstIter_ i= stat->begin(); i != stat->end(); ++i) {
     195      author_cont.push_back(std::make_pair(i->first,
     196                                           accumulated(*stat,i->first)));
     197    }
     198
     199    LessReversed<std::vector<u_int> > lr;
     200    PairSecondCompare<std::string, std::vector<u_int>,
     201      LessReversed<std::vector<u_int> > > compare(lr);
     202    std::sort(author_cont.begin(), author_cont.end(), compare);
     203
     204    size_t plotno=author_cont.size();
    190205    std::stringstream ss;
    191     for (MapConstIter_ i= stat->begin(); i != stat->end(); ++i) {
     206    vec_type::iterator end(author_cont.end());
     207    for (vec_type::iterator i(author_cont.begin()); i!=end; ++i) {
    192208      ss.str("");
    193209      ss << "set key height " << 2*plotno;
    194210      gp->command(ss.str());
    195       std::vector<u_int> x=accumulated(*stat, i->first);
    196211      ss.str("");
    197       ss << x.back() << " " << i->first;
     212      ss << i->second.back() << " " << i->first;
    198213      gp->yrange(yrange_max);
    199214      gp->linetitle(ss.str());
    200215      ss.str("");
    201       ss << "steps " << ++plotno;
     216      ss << "steps " << --plotno+2;
    202217      gp->linestyle(ss.str());
    203       gp->plot(x);
     218      gp->plot(i->second, ss.str());
    204219    }
    205220    ss.str("");
  • trunk/lib/utility.h

    r313 r371  
    144144
    145145
    146   template <class T>
     146  template <typename T>
    147147  std::string match(std::string::const_iterator& first,
    148148                    const std::string::const_iterator& last,
     
    184184  };
    185185
     186
    186187  class not2Char
    187188  {
     
    211212
    212213  ///
     214  /// Functor to be used on contaioners and works as standard less,
     215  /// but on the reversed container.
     216  ///
     217  /// Requirements on T is that has rend and rbegin. T::value_type
     218  /// must be comparable (i.e. have operator<)
     219  ///
     220  template <typename T>
     221  struct LessReversed
     222  {
     223    ///
     224    /// using std::lexicographical_compare on the reversed container
     225    ///
     226    inline bool operator()(const T& x, const T& y) const
     227    { return std::lexicographical_compare(x.rbegin(),x.rend(),
     228                                          y.rbegin(),y.rend()); }
     229  };
     230
     231
     232  ///
    213233  /// @brief Functor comparing pairs using second.
    214234  ///
     
    217237  /// comparison object in generic functions such as the STL sort.
    218238  ///
    219   template <class T1,class T2>
     239  template <typename T1, typename T2>
    220240  struct pair_value_compare
    221241  {
     
    231251  };
    232252
    233   template <class T1,class T2, class T3>
     253 
     254  ///
     255  /// Functor working on pair.second, using a user passed functor.
     256  ///
     257  template <typename T1, typename T2, typename T3>
    234258  struct PairSecondCompare
    235259  {
     
    242266
    243267    ///
    244     /// @return true if x.second<y.second or (x.second==y.second and
    245     /// x.first<y.first)
     268    /// @return compare(x.second, y.second) where compare is a
     269    /// internal comparison functor.
    246270    ///
    247271    inline bool operator()(const std::pair<T1,T2>& x,
     
    253277
    254278  };
    255 
     279 
    256280  ///
    257281  /// Calculating sum of two vectors.
Note: See TracChangeset for help on using the changeset viewer.