mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-07-07 20:06:39 +02:00
Extract more parameters into chart configuration
This commit is contained in:
parent
e2bd076357
commit
4ef248b973
4 changed files with 62 additions and 59 deletions
|
@ -41,7 +41,17 @@ Chart::Chart (ChartConfig configuration) :
|
|||
with_label_month(configuration.with_label_month),
|
||||
with_label_week(configuration.with_label_week),
|
||||
with_label_weekday(configuration.with_label_weekday),
|
||||
with_label_day(configuration.with_label_day)
|
||||
with_label_day(configuration.with_label_day),
|
||||
with_ids(configuration.with_ids),
|
||||
with_summary(configuration.with_summary),
|
||||
with_holidays(configuration.with_holidays),
|
||||
with_totals(configuration.with_totals),
|
||||
with_internal_axis(configuration.with_internal_axis),
|
||||
show_intervals(configuration.show_intervals),
|
||||
determine_hour_range(configuration.determine_hour_range),
|
||||
minutes_per_char(configuration.minutes_per_char),
|
||||
spacing(configuration.spacing),
|
||||
num_lines(configuration.num_lines)
|
||||
{ }
|
||||
|
||||
std::string Chart::render (
|
||||
|
@ -53,17 +63,7 @@ std::string Chart::render (
|
|||
const Color &color_today,
|
||||
const Color &color_holiday,
|
||||
const Color &color_label,
|
||||
const Color &color_exclusion,
|
||||
const bool show_intervals,
|
||||
const bool determine_hour_range,
|
||||
const bool with_ids,
|
||||
const bool with_summary,
|
||||
const bool with_holidays,
|
||||
const bool with_totals,
|
||||
const bool with_internal_axis,
|
||||
const int minutes_per_char,
|
||||
const int spacing,
|
||||
const int num_lines)
|
||||
const Color &color_exclusion)
|
||||
{
|
||||
// Determine hours shown.
|
||||
auto hour_range = determine_hour_range
|
||||
|
@ -96,8 +96,7 @@ std::string Chart::render (
|
|||
last_hour,
|
||||
color_label,
|
||||
color_today,
|
||||
cell_size,
|
||||
with_totals);
|
||||
cell_size);
|
||||
}
|
||||
|
||||
// For rendering labels on edge detection.
|
||||
|
@ -118,8 +117,7 @@ std::string Chart::render (
|
|||
lines[i].add (std::string (total_width, ' '), 0, Color ());
|
||||
}
|
||||
|
||||
renderExclusionBlocks (lines, day, first_hour, last_hour, exclusions, minutes_per_char, spacing,
|
||||
color_exclusion, color_label, with_internal_axis);
|
||||
renderExclusionBlocks (lines, day, first_hour, last_hour, exclusions, color_exclusion, color_label);
|
||||
|
||||
time_t work = 0;
|
||||
if (!show_intervals)
|
||||
|
@ -127,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, with_ids, minutes_per_char, spacing);
|
||||
renderInterval (lines, day, track, tag_colors, first_hour, interval_work);
|
||||
work += interval_work;
|
||||
}
|
||||
}
|
||||
|
@ -165,7 +163,7 @@ std::string Chart::render (
|
|||
|
||||
out << (with_totals ? renderSubTotal (total_work, std::string (padding_size, ' ')) : "")
|
||||
<< (with_holidays ? renderHolidays (holidays) : "")
|
||||
<< (with_summary ? renderSummary (indent, filter, exclusions, tracked, show_intervals) : "");
|
||||
<< (with_summary ? renderSummary (indent, filter, exclusions, tracked) : "");
|
||||
|
||||
return out.str ();
|
||||
}
|
||||
|
@ -246,8 +244,7 @@ std::string Chart::renderAxis (
|
|||
const int last_hour,
|
||||
const Color &colorLabel,
|
||||
const Color &colorToday,
|
||||
const int cell_size,
|
||||
const bool with_totals)
|
||||
const int cell_size)
|
||||
{
|
||||
std::stringstream out;
|
||||
auto current_hour = Datetime ().hour ();
|
||||
|
@ -395,11 +392,8 @@ void Chart::renderExclusionBlocks (
|
|||
int first_hour,
|
||||
int last_hour,
|
||||
const std::vector<Range> &excluded,
|
||||
const int minutes_per_char,
|
||||
const int spacing,
|
||||
const Color &color_exclusion,
|
||||
const Color &color_label,
|
||||
const bool with_internal_axis)
|
||||
const Color &color_label)
|
||||
{
|
||||
const auto chars_per_hour = 60 / minutes_per_char;
|
||||
const auto cell_width = chars_per_hour + spacing;
|
||||
|
@ -459,10 +453,7 @@ void Chart::renderInterval (
|
|||
const Interval &track,
|
||||
const std::map<std::string, Color> &tag_colors,
|
||||
const int first_hour,
|
||||
time_t &work,
|
||||
const bool with_ids,
|
||||
const int minutes_per_char,
|
||||
const int spacing)
|
||||
time_t &work)
|
||||
{
|
||||
Datetime now;
|
||||
|
||||
|
@ -575,8 +566,7 @@ std::string Chart::renderSummary (
|
|||
const std::string &indent,
|
||||
const Interval &filter,
|
||||
const std::vector<Range> &exclusions,
|
||||
const std::vector<Interval> &tracked,
|
||||
bool blank)
|
||||
const std::vector<Interval> &tracked)
|
||||
{
|
||||
std::stringstream out;
|
||||
time_t total_unavailable = 0;
|
||||
|
@ -591,7 +581,7 @@ std::string Chart::renderSummary (
|
|||
|
||||
time_t total_worked = 0;
|
||||
|
||||
if (!blank)
|
||||
if (!show_intervals)
|
||||
{
|
||||
for (auto &interval : tracked)
|
||||
{
|
||||
|
|
20
src/Chart.h
20
src/Chart.h
|
@ -37,14 +37,14 @@ 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&, bool, bool, bool, bool, bool, bool, bool, int, int, int);
|
||||
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&);
|
||||
|
||||
private:
|
||||
unsigned long getIndentSize ();
|
||||
|
||||
std::pair <int, int> determineHourRange (const Interval&, const std::vector <Interval>&);
|
||||
|
||||
std::string renderAxis (int, int, const Color&, const Color&, int, bool);
|
||||
std::string renderAxis (int, int, const Color&, const Color&, int);
|
||||
|
||||
std::string renderMonth (const Datetime&, const Datetime&);
|
||||
|
||||
|
@ -60,18 +60,28 @@ private:
|
|||
|
||||
std::string renderSubTotal (time_t, const std::string&);
|
||||
|
||||
void renderExclusionBlocks (std::vector<Composite>&, const Datetime&, int, int, const std::vector<Range>&, int, int, const Color&, const Color&, bool);
|
||||
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&, bool, int, int);
|
||||
void renderInterval (std::vector<Composite>&, const Datetime&, const Interval&, const std::map<std::string, Color>&, int, time_t&);
|
||||
|
||||
std::string renderHolidays (const std::map <Datetime, std::string>&);
|
||||
|
||||
std::string renderSummary (const std::string&, const Interval&, const std::vector <Range>&, const std::vector <Interval>&, bool);
|
||||
std::string renderSummary (const std::string&, const Interval&, const std::vector <Range>&, const std::vector <Interval>&);
|
||||
|
||||
const bool with_label_month;
|
||||
const bool with_label_week;
|
||||
const bool with_label_weekday;
|
||||
const bool with_label_day;
|
||||
const bool with_ids;
|
||||
const bool with_summary;
|
||||
const bool with_holidays;
|
||||
const bool with_totals;
|
||||
const bool with_internal_axis;
|
||||
const bool show_intervals;
|
||||
const bool determine_hour_range;
|
||||
const int minutes_per_char;
|
||||
const int spacing;
|
||||
const int num_lines;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -34,6 +34,16 @@ public:
|
|||
bool with_label_week;
|
||||
bool with_label_weekday;
|
||||
bool with_label_day;
|
||||
bool with_ids;
|
||||
bool with_summary;
|
||||
bool with_holidays;
|
||||
bool with_totals;
|
||||
bool with_internal_axis;
|
||||
bool show_intervals;
|
||||
bool determine_hour_range;
|
||||
int minutes_per_char;
|
||||
int spacing;
|
||||
int num_lines;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -119,42 +119,35 @@ int renderChart (
|
|||
Color color_label (with_colors ? rules.get ("theme.colors.label") : "");
|
||||
Color color_exclusion (with_colors ? rules.get ("theme.colors.exclusion") : "");
|
||||
|
||||
const auto determine_hour_range = rules.get ("reports." + type + ".hours") == "auto";
|
||||
|
||||
const bool show_intervals = findHint (cli, ":blank");
|
||||
const bool with_ids = findHint (cli, ":ids");
|
||||
|
||||
const auto with_summary = rules.getBoolean ("reports." + type + ".summary");
|
||||
const auto with_holidays = rules.getBoolean ("reports." + type + ".holidays");
|
||||
const auto with_totals = rules.getBoolean ("reports." + type + ".totals");
|
||||
const auto with_month = rules.getBoolean ("reports." + type + ".month");
|
||||
const auto with_week = rules.getBoolean ("reports." + type + ".week");
|
||||
const auto with_day = rules.getBoolean ("reports." + type + ".day");
|
||||
const auto with_weekday = rules.getBoolean ("reports." + type + ".weekday");
|
||||
|
||||
const auto minutes_per_char = rules.getInteger ("reports." + type + ".cell");
|
||||
|
||||
if (minutes_per_char < 1)
|
||||
throw format ("The value for 'reports.{1}.cell' must be at least 1.", type);
|
||||
|
||||
const auto spacing = rules.getInteger ("reports." + type + ".spacing", 1);
|
||||
const auto num_lines = rules.getInteger ("reports." + type + ".lines", 1);
|
||||
|
||||
if (num_lines < 1)
|
||||
throw format ("Invalid value for 'reports.{1}.lines': '{2}'", type, num_lines);
|
||||
|
||||
auto axis_type = rules.get ("reports." + type + ".axis");
|
||||
const auto with_internal_axis = axis_type == "internal";
|
||||
|
||||
ChartConfig configuration {};
|
||||
configuration.with_label_month = with_month;
|
||||
configuration.with_label_week = with_week;
|
||||
configuration.with_label_weekday = with_weekday;
|
||||
configuration.with_label_day = with_day;
|
||||
configuration.with_label_month = rules.getBoolean ("reports." + type + ".month");
|
||||
configuration.with_label_week = rules.getBoolean ("reports." + type + ".week");
|
||||
configuration.with_label_weekday = rules.getBoolean ("reports." + type + ".weekday");
|
||||
configuration.with_label_day = rules.getBoolean ("reports." + type + ".day");
|
||||
configuration.with_ids = findHint (cli, ":ids");
|
||||
configuration.with_summary = rules.getBoolean ("reports." + type + ".summary");
|
||||
configuration.with_holidays = rules.getBoolean ("reports." + type + ".holidays");
|
||||
configuration.with_totals = rules.getBoolean ("reports." + type + ".totals");
|
||||
configuration.with_internal_axis = rules.get ("reports." + type + ".axis") == "internal";
|
||||
configuration.show_intervals = findHint (cli, ":blank");
|
||||
configuration.determine_hour_range = rules.get ("reports." + type + ".hours") == "auto";
|
||||
configuration.minutes_per_char = minutes_per_char;
|
||||
configuration.spacing = rules.getInteger ("reports." + type + ".spacing", 1);
|
||||
configuration.num_lines = num_lines;
|
||||
|
||||
Chart chart (configuration);
|
||||
|
||||
std::cout << chart.render (filter, tracked, exclusions, holidays, tag_colors, color_today, color_holiday, color_label, color_exclusion, show_intervals, determine_hour_range, with_ids, with_summary, with_holidays, with_totals, with_internal_axis, minutes_per_char, spacing, num_lines);
|
||||
std::cout << chart.render (filter, tracked, exclusions, holidays, tag_colors, color_today, color_holiday, color_label, color_exclusion);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -183,7 +176,7 @@ std::map <Datetime, std::string> createHolidayMap (Rules &rules, Interval &filte
|
|||
<< entry.substr (first_dot + 1, last_dot - first_dot - 1)
|
||||
<< "] "
|
||||
<< rules.get (entry);
|
||||
auto locale = entry.substr (first_dot + 1, last_dot - first_dot - 1);
|
||||
auto locale = entry.substr (first_dot + 1, last_dot - first_dot - 1);
|
||||
mapping[holiday] = out.str ();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue