From 1dd6314ebc0dce2bac0afa7e194620308d01a099 Mon Sep 17 00:00:00 2001 From: Lim Ding Wen Date: Thu, 11 Nov 2021 01:36:14 +0800 Subject: [PATCH 1/3] SummaryColors: Add colors to summary Signed-off-by: Lim Ding Wen --- doc/man1/timew-summary.1.adoc | 4 ++++ src/commands/CmdSummary.cpp | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/doc/man1/timew-summary.1.adoc b/doc/man1/timew-summary.1.adoc index b610cc778..13113c5ed 100644 --- a/doc/man1/timew-summary.1.adoc +++ b/doc/man1/timew-summary.1.adoc @@ -22,6 +22,10 @@ The ':ids' hint adds an 'ID' column to the summary report output for interval mo Determines whether relevant holidays are shown beneath the report. Default value is 'yes'. +**tags.**____**.color**:: +Assigns a specific foreground and background color to a tag. +Examples of valid colors include 'white', 'gray8', 'black on yellow', and 'rgb345'. + == SEE ALSO **timew-day**(1), **timew-lengthen**(1), diff --git a/src/commands/CmdSummary.cpp b/src/commands/CmdSummary.cpp index 0d45d05fa..432ce67bb 100644 --- a/src/commands/CmdSummary.cpp +++ b/src/commands/CmdSummary.cpp @@ -155,7 +155,7 @@ int CmdSummary ( table.set (row, 3, format ("@{1}", track.id), colorID); } - table.set (row, (ids ? 4 : 3), tags); + table.set (row, (ids ? 4 : 3), tags, intervalColor(track.tags(), tag_colors)); if (show_annotation) { From 403f4eeb9546332f01d6b3f4ab39ba8bddb86e70 Mon Sep 17 00:00:00 2001 From: Lim Ding Wen Date: Thu, 11 Nov 2021 02:34:26 +0800 Subject: [PATCH 2/3] SummaryColors: Handle tags with no user-set colors Signed-off-by: Lim Ding Wen --- src/Chart.cpp | 2 +- src/commands/CmdSummary.cpp | 6 ++---- src/helper.cpp | 20 ++++++++++++++++++-- src/timew.h | 3 ++- 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/Chart.cpp b/src/Chart.cpp index 7368db79e..e3b7d87cc 100644 --- a/src/Chart.cpp +++ b/src/Chart.cpp @@ -470,7 +470,7 @@ void Chart::renderInterval ( if (end_offset > start_offset) { // Determine color of interval. - Color colorTrack = intervalColor (track.tags (), tag_colors); + Color colorTrack = chartIntervalColor (track.tags (), tag_colors); // Properly format the tags within the space. std::string label; diff --git a/src/commands/CmdSummary.cpp b/src/commands/CmdSummary.cpp index 432ce67bb..2f6856e53 100644 --- a/src/commands/CmdSummary.cpp +++ b/src/commands/CmdSummary.cpp @@ -75,9 +75,7 @@ int CmdSummary ( } // Map tags to colors. - auto palette = createPalette (rules); - auto tag_colors = createTagColorMap (rules, palette, tracked); - Color colorID (rules.getBoolean ("color") ? rules.get ("theme.colors.ids") : ""); + Color colorID (rules.getBoolean("color") ? rules.get ("theme.colors.ids") : ""); auto ids = findHint (cli, ":ids"); auto show_annotation = findHint (cli, ":annotations"); @@ -155,7 +153,7 @@ int CmdSummary ( table.set (row, 3, format ("@{1}", track.id), colorID); } - table.set (row, (ids ? 4 : 3), tags, intervalColor(track.tags(), tag_colors)); + table.set (row, (ids ? 4 : 3), tags, summaryIntervalColor(rules, track.tags())); if (show_annotation) { diff --git a/src/helper.cpp b/src/helper.cpp index dcc002ef6..167ffd506 100644 --- a/src/helper.cpp +++ b/src/helper.cpp @@ -38,8 +38,24 @@ #include //////////////////////////////////////////////////////////////////////////////// -// Select a color to represent the interval. -Color intervalColor ( +// Select a color to represent the interval in a summary report. +Color summaryIntervalColor ( + const Rules& rules, + const std::set & tags) +{ + Color c; + + for (auto& tag : tags) + { + c.blend (tagColor (rules, tag)); + } + + return c; +} + +//////////////////////////////////////////////////////////////////////////////// +// Select a color to represent the interval on a chart. +Color chartIntervalColor ( const std::set & tags, const std::map & tag_colors) { diff --git a/src/timew.h b/src/timew.h index edc616cb4..722f1e1c5 100644 --- a/src/timew.h +++ b/src/timew.h @@ -69,7 +69,8 @@ void initializeExtensions (CLI&, const Rules&, Extensions&); int dispatchCommand (const CLI&, Database&, Journal&, Rules&, const Extensions&); // helper.cpp -Color intervalColor (const std::set &, const std::map &); +Color summaryIntervalColor (const Rules&, const std::set &); +Color chartIntervalColor (const std::set &, const std::map &); Color tagColor (const Rules&, const std::string&); std::string intervalSummarize (const Rules&, const Interval&); bool expandIntervalHint (const std::string&, Range&); From fbbf99bcd34f76f9c3178c4d634282925ad18a49 Mon Sep 17 00:00:00 2001 From: Lim Ding Wen Date: Thu, 11 Nov 2021 10:46:13 +0800 Subject: [PATCH 3/3] SummaryColors: Fix formatting Signed-off-by: Lim Ding Wen --- src/commands/CmdSummary.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/commands/CmdSummary.cpp b/src/commands/CmdSummary.cpp index 2f6856e53..ef5a5c5eb 100644 --- a/src/commands/CmdSummary.cpp +++ b/src/commands/CmdSummary.cpp @@ -75,7 +75,7 @@ int CmdSummary ( } // Map tags to colors. - Color colorID (rules.getBoolean("color") ? rules.get ("theme.colors.ids") : ""); + Color colorID (rules.getBoolean ("color") ? rules.get ("theme.colors.ids") : ""); auto ids = findHint (cli, ":ids"); auto show_annotation = findHint (cli, ":annotations"); @@ -153,7 +153,7 @@ int CmdSummary ( table.set (row, 3, format ("@{1}", track.id), colorID); } - table.set (row, (ids ? 4 : 3), tags, summaryIntervalColor(rules, track.tags())); + table.set (row, (ids ? 4 : 3), tags, summaryIntervalColor (rules, track.tags ())); if (show_annotation) {