helper: Added createTagColorMap

This commit is contained in:
Paul Beckingham 2016-04-23 12:48:21 -04:00
parent c9679e21d0
commit 117587e1c5
2 changed files with 21 additions and 0 deletions

View file

@ -538,3 +538,22 @@ std::vector <Range> combineHolidaysAndExclusions (
}
////////////////////////////////////////////////////////////////////////////////
// Extract the tags from a set of intervals, and using a rotating color palette,
// map unique tags to color.
std::map <std::string, Color> createTagColorMap (
const Rules& rules,
Palette& palette,
const std::vector <Interval>& intervals)
{
// TODO Note: tags may have their own defined color.
std::map <std::string, Color> mapping;
for (auto& interval : intervals)
for (auto& tag : interval.tags ())
if (mapping.find (tag) == mapping.end ())
mapping[tag] = palette.next ();
return mapping;
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -33,6 +33,7 @@
#include <Extensions.h>
#include <Interval.h>
#include <Timeline.h>
#include <Palette.h>
#include <Color.h>
// init.cpp
@ -57,6 +58,7 @@ std::vector <Range> addRanges (const Range&, const std::vector <Range>&, const s
std::vector <Range> subtractRanges (const Range&, const std::vector <Range>&, const std::vector <Range>&);
Range overallRangeFromIntervals (const std::vector <Interval>&);
std::vector <Range> combineHolidaysAndExclusions (const Range&, const Rules&, const std::vector <Exclusion>&);
std::map <std::string, Color> createTagColorMap (const Rules&, Palette&, const std::vector <Interval>&);
// utiŀ.cpp
std::string osName ();