Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add colors to summary #463

Merged
merged 3 commits into from
Nov 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/man1/timew-summary.1.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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.**__<tag>__**.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),
Expand Down
2 changes: 1 addition & 1 deletion src/Chart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 1 addition & 3 deletions src/commands/CmdSummary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ 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") : "");

auto ids = findHint (cli, ":ids");
Expand Down Expand Up @@ -155,7 +153,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, summaryIntervalColor (rules, track.tags ()));

if (show_annotation)
{
Expand Down
20 changes: 18 additions & 2 deletions src/helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,24 @@
#include <vector>

////////////////////////////////////////////////////////////////////////////////
// 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 <std::string>& 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 <std::string>& tags,
const std::map <std::string, Color>& tag_colors)
{
Expand Down
3 changes: 2 additions & 1 deletion src/timew.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <std::string>&, const std::map <std::string, Color>&);
Color summaryIntervalColor (const Rules&, const std::set <std::string>&);
Color chartIntervalColor (const std::set <std::string>&, const std::map <std::string, Color>&);
Color tagColor (const Rules&, const std::string&);
std::string intervalSummarize (const Rules&, const Interval&);
bool expandIntervalHint (const std::string&, Range&);
Expand Down