mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-07-07 20:06:39 +02:00
Extract rules from renderInterval
- Simplify interval coloring (extract rules from helper::intervalColor) - Add a default color for intervals without tags
This commit is contained in:
parent
c5f8583355
commit
6cd1d7c804
3 changed files with 20 additions and 24 deletions
|
@ -1,6 +1,6 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright 2016 - 2018, Thomas Lauf, Paul Beckingham, Federico Hernandez.
|
||||
// Copyright 2016 - 2019, Thomas Lauf, Paul Beckingham, Federico Hernandez.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -45,8 +45,8 @@ static std::string renderDay (Datetime&, const Color&);
|
|||
static std::string renderTotal (time_t);
|
||||
static std::string renderSubTotal (time_t, unsigned long);
|
||||
static void renderExclusionBlocks (std::vector<Composite>&, const Datetime&, int, int, const std::vector<Range>&, int, int, const std::string&, const Color&, const Color&);
|
||||
static void renderInterval (const Rules&, std::vector<Composite>&, const Datetime&, const Interval&, std::map<std::string, Color>&, int, time_t&, bool, int, int);
|
||||
std::string renderHolidays (const std::map <Datetime, std::string>&);
|
||||
static void renderInterval (std::vector<Composite>&, const Datetime&, const Interval&, std::map<std::string, Color>&, int, time_t&, bool, int, int);
|
||||
std::string renderHolidays (const std::map <Datetime, std::string>&);
|
||||
static std::string renderSummary (const std::string&, const Interval&, const std::vector <Range>&, const std::vector <Interval>&, bool);
|
||||
|
||||
unsigned long getIndentSize (const std::string &type, const Rules &rules);
|
||||
|
@ -220,7 +220,7 @@ int renderChart (
|
|||
for (auto& track : tracked)
|
||||
{
|
||||
time_t interval_work = 0;
|
||||
renderInterval (rules, lines, day, track, tag_colors, first_hour, interval_work, ids, minutes_per_char, spacing);
|
||||
renderInterval (lines, day, track, tag_colors, first_hour, interval_work, ids, minutes_per_char, spacing);
|
||||
work += interval_work;
|
||||
}
|
||||
}
|
||||
|
@ -572,7 +572,6 @@ static void renderExclusionBlocks (
|
|||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
static void renderInterval (
|
||||
const Rules& rules,
|
||||
std::vector <Composite>& lines,
|
||||
const Datetime& day,
|
||||
const Interval& track,
|
||||
|
@ -626,7 +625,7 @@ static void renderInterval (
|
|||
if (end_offset > start_offset)
|
||||
{
|
||||
// Determine color of interval.
|
||||
Color colorTrack = intervalColor (track, rules, tag_colors);
|
||||
Color colorTrack = intervalColor (track.tags (), tag_colors);
|
||||
|
||||
// Properly format the tags within the space.
|
||||
std::string label;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright 2016 - 2018, Thomas Lauf, Paul Beckingham, Federico Hernandez.
|
||||
// Copyright 2016 - 2019, Thomas Lauf, Paul Beckingham, Federico Hernandez.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -39,27 +39,20 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Select a color to represent the interval.
|
||||
Color intervalColor (
|
||||
const Interval& interval,
|
||||
const Rules& rules,
|
||||
const std::set <std::string>& tags,
|
||||
std::map <std::string, Color>& tag_colors)
|
||||
{
|
||||
Color c;
|
||||
std::string first_tag;
|
||||
for (auto& tag : interval.tags ())
|
||||
if (tags.empty ())
|
||||
{
|
||||
if (first_tag.empty ())
|
||||
first_tag = tag;
|
||||
|
||||
std::string name = std::string ("tags.") + tag + ".color";
|
||||
if (rules.has (name))
|
||||
c.blend (Color (rules.get (name)));
|
||||
return tag_colors[""];
|
||||
}
|
||||
|
||||
if (c.nontrivial ())
|
||||
return c;
|
||||
Color c;
|
||||
|
||||
if (! interval.tags ().empty ())
|
||||
return tag_colors[first_tag];
|
||||
for (auto& tag : tags)
|
||||
{
|
||||
c.blend (tag_colors[tag]);
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
@ -368,6 +361,10 @@ std::map <std::string, Color> createTagColorMap (
|
|||
const std::vector <Interval>& intervals)
|
||||
{
|
||||
std::map <std::string, Color> mapping;
|
||||
|
||||
// Add a color for intervals without tags
|
||||
mapping[""] = palette.next ();
|
||||
|
||||
for (auto& interval : intervals)
|
||||
{
|
||||
for (auto& tag : interval.tags ())
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright 2015 - 2016, Paul Beckingham, Federico Hernandez.
|
||||
// Copyright 2016 - 2019, Paul Beckingham, Federico Hernandez.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -68,7 +68,7 @@ void initializeExtensions (CLI&, const Rules&, Extensions&);
|
|||
int dispatchCommand (const CLI&, Database&, Rules&, const Extensions&);
|
||||
|
||||
// helper.cpp
|
||||
Color intervalColor (const Interval&, const Rules&, std::map <std::string, Color>&);
|
||||
Color intervalColor (const std::set <std::string>&, std::map <std::string, Color>&);
|
||||
Color tagColor (const Rules&, const std::string&);
|
||||
std::string intervalSummarize (Database&, const Rules&, const Interval&);
|
||||
bool expandIntervalHint (const std::string&, Range&);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue