Move color definitions into configuration

This commit is contained in:
Thomas Lauf 2019-03-04 10:17:58 +01:00
parent 4ef248b973
commit 58c392b0b9
4 changed files with 26 additions and 18 deletions

View file

@ -51,19 +51,19 @@ Chart::Chart (ChartConfig configuration) :
determine_hour_range(configuration.determine_hour_range),
minutes_per_char(configuration.minutes_per_char),
spacing(configuration.spacing),
num_lines(configuration.num_lines)
num_lines(configuration.num_lines),
color_today(configuration.color_today),
color_holiday(configuration.color_holiday),
color_label(configuration.color_label),
color_exclusion(configuration.color_exclusion),
tag_colors(configuration.tag_colors)
{ }
std::string Chart::render (
const Interval &filter,
const std::vector<Interval> &tracked,
const std::vector<Range> &exclusions,
const std::map<Datetime, std::string> &holidays,
const std::map<std::string, Color> &tag_colors,
const Color &color_today,
const Color &color_holiday,
const Color &color_label,
const Color &color_exclusion)
const std::map<Datetime, std::string> &holidays)
{
// Determine hours shown.
auto hour_range = determine_hour_range
@ -125,7 +125,7 @@ std::string Chart::render (
for (auto &track : tracked)
{
time_t interval_work = 0;
renderInterval (lines, day, track, tag_colors, first_hour, interval_work);
renderInterval (lines, day, track, first_hour, interval_work);
work += interval_work;
}
}
@ -451,7 +451,6 @@ void Chart::renderInterval (
std::vector<Composite> &lines,
const Datetime &day,
const Interval &track,
const std::map<std::string, Color> &tag_colors,
const int first_hour,
time_t &work)
{

View file

@ -37,7 +37,7 @@ class Chart
public:
explicit Chart (ChartConfig configuration);
std::string render (const Interval&, const std::vector <Interval>&, const std::vector <Range>&, const std::map <Datetime, std::string>&, const std::map <std::string, Color>&, const Color&, const Color&, const Color&, const Color&);
std::string render (const Interval&, const std::vector <Interval>&, const std::vector <Range>&, const std::map <Datetime, std::string>&);
private:
unsigned long getIndentSize ();
@ -62,7 +62,7 @@ private:
void renderExclusionBlocks (std::vector<Composite>&, const Datetime&, int, int, const std::vector<Range>&, const Color&, const Color&);
void renderInterval (std::vector<Composite>&, const Datetime&, const Interval&, const std::map<std::string, Color>&, int, time_t&);
void renderInterval (std::vector<Composite>&, const Datetime&, const Interval&, int, time_t&);
std::string renderHolidays (const std::map <Datetime, std::string>&);
@ -82,6 +82,11 @@ private:
const int minutes_per_char;
const int spacing;
const int num_lines;
const Color color_today;
const Color color_holiday;
const Color color_label;
const Color color_exclusion;
const std::map<std::string, Color> tag_colors;
};
#endif

View file

@ -44,6 +44,11 @@ public:
int minutes_per_char;
int spacing;
int num_lines;
Color color_today;
Color color_holiday;
Color color_label;
Color color_exclusion;
std::map<std::string, Color> tag_colors;
};
#endif

View file

@ -111,14 +111,8 @@ int renderChart (
// Map tags to colors.
auto palette = createPalette (rules);
auto tag_colors = createTagColorMap (rules, palette, tracked);
auto with_colors = rules.getBoolean ("color");
Color color_today (with_colors ? rules.get ("theme.colors.today") : "");
Color color_holiday (with_colors ? rules.get ("theme.colors.holiday") : "");
Color color_label (with_colors ? rules.get ("theme.colors.label") : "");
Color color_exclusion (with_colors ? rules.get ("theme.colors.exclusion") : "");
const auto minutes_per_char = rules.getInteger ("reports." + type + ".cell");
if (minutes_per_char < 1)
@ -144,10 +138,15 @@ int renderChart (
configuration.minutes_per_char = minutes_per_char;
configuration.spacing = rules.getInteger ("reports." + type + ".spacing", 1);
configuration.num_lines = num_lines;
configuration.color_today = (with_colors ? Color (rules.get ("theme.colors.today")) : Color (""));
configuration.color_holiday = (with_colors ? Color (rules.get ("theme.colors.holiday")) : Color (""));
configuration.color_label = (with_colors ? Color (rules.get ("theme.colors.label")) : Color (""));
configuration.color_exclusion = (with_colors ? Color (rules.get ("theme.colors.exclusion")) : Color (""));
configuration.tag_colors = createTagColorMap (rules, palette, tracked);
Chart chart (configuration);
std::cout << chart.render (filter, tracked, exclusions, holidays, tag_colors, color_today, color_holiday, color_label, color_exclusion);
std::cout << chart.render (filter, tracked, exclusions, holidays);
return 0;
}