Changeset 919


Ignore:
Timestamp:
Dec 1, 2009, 12:03:31 AM (11 years ago)
Author:
Jari Häkkinen
Message:

Addresses #75. Colours are dynamically assigned to authors. Removed white from the colour map.

Location:
trunk
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Colours.cc

    r916 r919  
    3131
    3232  Colours::Colours(void)
    33     : colour_map_(14)
     33    : colour_map_(13), next_colour_(colour_map_.begin())
     34
    3435  {
    3536    colour_map_[ 0].label="green";
     
    5960    colour_map_[12].label="black";
    6061    colour_map_[12].r=  0; colour_map_[12].g=  0; colour_map_[12].b=  0;
    61     colour_map_[13].label="white";
    62     colour_map_[13].r=255; colour_map_[13].g=255; colour_map_[13].b=255;
    63 
    64     // temporary until proper configuration is implemented
    65     std::vector<colour>::iterator i=colour_map_.begin();
    66     author_map_["jari"]=i++;
    67     author_map_["peter"]=i++;
    6862  }
    6963
    7064
    7165  void Colours::get_colour(const std::string& label, unsigned char& r,
    72                            unsigned char& g, unsigned char& b) const
     66                           unsigned char& g, unsigned char& b)
    7367  {
    74     r=g=b=0;
    7568    std::map<std::string,std::vector<colour>::iterator>::const_iterator i;
    76     if ((i=author_map_.find(label)) == author_map_.end())
    77       // no colour defined for label
    78       return;
    79     r=i->second->r; g=i->second->g; b=i->second->b;
     69    if ((i=author_map_.find(label)) == author_map_.end()) {
     70      // no colour defined for label, set colour for label
     71      author_map_[label]=next_colour_++;
     72      if (next_colour_==colour_map_.end())
     73        // end of colour map reach, start over
     74        next_colour_=colour_map_.begin();
     75    }
     76    r=author_map_[label]->r;
     77    g=author_map_[label]->g;
     78    b=author_map_[label]->b;
    8079  }
    8180
  • trunk/lib/Colours.h

    r916 r919  
    3030namespace svndigest {
    3131
     32  /**
     33     The author-colour mapping is provided by the Colours class.
     34
     35     Colours use the singleton design pattern.
     36   */
    3237  class Colours
    3338  {
    3439  public:
    3540
     41    /**
     42       \brief Get RGB colour for \a label
     43
     44       If \a label has no assigned colour, the next unused colour is
     45       automatically assigned to \a label. The number of available
     46       unique colours is low, when all colours are used mapped with a
     47       \a label once, the colours are reused.
     48
     49       \see To be written. If a specific colour is to be assigned for
     50       a label, use function TBA.
     51     */
    3652    void get_colour(const std::string& label, unsigned char& r,
    37                     unsigned char& g, unsigned char& b) const;
     53                    unsigned char& g, unsigned char& b);
    3854
     55    /**
     56       \brief Get an instance of Colour
     57     */
    3958    static Colours& instance(void);
    4059
     
    5776    };
    5877
     78    std::map<std::string, std::vector<colour>::iterator> author_map_;
     79    std::vector<colour> colour_map_;
    5980    static Colours* instance_;
    60     std::vector<colour> colour_map_;
    61     std::map<std::string, std::vector<colour>::iterator> author_map_;
     81    std::vector<colour>::iterator next_colour_;
    6282  };
    6383
  • trunk/test/Makefile.am

    r912 r919  
    2222check_SCRIPTS = svn_update.sh
    2323
    24 check_PROGRAMS = cache_partial_test \
     24check_PROGRAMS = cache_partial_test colour_test \
    2525  config_test copyright_test date_test \
    2626  parser_test stats_test trac_test utility_test
     
    5454
    5555cache_partial_test_SOURCES = cache_partial_test.cc
     56colour_test_SOURCES = colour_test.cc
    5657config_test_SOURCES = config_test.cc
    5758copyright_test_SOURCES = copyright_test.cc
Note: See TracChangeset for help on using the changeset viewer.