diff --git a/src/commands/CmdChart.cpp b/src/commands/CmdChart.cpp index 52ef4619..01492166 100644 --- a/src/commands/CmdChart.cpp +++ b/src/commands/CmdChart.cpp @@ -46,7 +46,7 @@ static std::string renderDayName (const std::string&, const Rules&, Date static std::string renderTotal (const std::string&, const Rules&, time_t); static std::string renderSubTotal (const std::string&, const Rules&, int, int, time_t); static void renderExclusionBlocks (const std::string&, const Rules&, std::vector &, Palette&, const Datetime&, int, int, const std::vector &); -static void renderInterval (const std::string&, const Rules&, std::vector &, const Datetime&, const Interval&, Palette&, std::map &, int, time_t&, bool); +static void renderInterval (const std::string&, const Rules&, std::vector &, const Datetime&, const Interval&, std::map &, int, time_t&, bool); std::string renderHolidays (const std::string&, const Rules&, const Interval&); static std::string renderSummary (const std::string&, const Rules&, const std::string&, const Interval&, const std::vector &, const std::vector &, bool); @@ -189,7 +189,7 @@ int renderChart ( for (auto& track : tracked) { time_t interval_work = 0; - renderInterval (type, rules, lines, day, track, palette, tag_colors, first_hour, interval_work, ids); + renderInterval (type, rules, lines, day, track, tag_colors, first_hour, interval_work, ids); work += interval_work; } } @@ -497,7 +497,6 @@ static void renderInterval ( std::vector & lines, const Datetime& day, const Interval& track, - Palette& palette, std::map & tag_colors, int first_hour, time_t& work, @@ -540,13 +539,7 @@ static void renderInterval ( if (end_offset > start_offset) { // Determine color of interval. - Color colorTrack; - if (track.tags ().size ()) - // TODO Instead of using the first tag, look at them all, and choose one - // that has a color defined over any other. - colorTrack = tag_colors [*(track.tags ().begin ())]; - else - colorTrack = palette.next (); + Color colorTrack = intervalColor (track, rules, tag_colors); // Properly format the tags within the space. std::string label; diff --git a/src/helper.cpp b/src/helper.cpp index 3af9b122..a1ca53cb 100644 --- a/src/helper.cpp +++ b/src/helper.cpp @@ -41,11 +41,15 @@ Color intervalColor ( const Interval& interval, const Rules& rules, - Palette& palette) + std::map & tag_colors) { Color c; + std::string first_tag; for (auto& tag : interval.tags ()) { + if (first_tag == "") + first_tag = tag; + std::string name = std::string ("tags.") + tag + ".color"; if (rules.has (name)) c.blend (Color (rules.get (name))); @@ -54,7 +58,10 @@ Color intervalColor ( if (c.nontrivial ()) return c; - return palette.next (); + if (interval.tags ().size ()) + return tag_colors[first_tag]; + + return c; } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/timew.h b/src/timew.h index 858af9a7..5e905e1b 100644 --- a/src/timew.h +++ b/src/timew.h @@ -64,7 +64,7 @@ void initializeExtensions (CLI&, const Rules&, Extensions&); int dispatchCommand (const CLI&, Database&, Rules&, const Extensions&); // helper.cpp -Color intervalColor (const Interval&, const Rules&, Palette&); +Color intervalColor (const Interval&, const Rules&, std::map &); Color tagColor (const Rules&, const std::string&); std::string intervalSummarize (Database&, const Rules&, const Interval&); bool expandIntervalHint (const std::string&, Range&);