From 49f25ba7d70e02dbc363f62d53348ca2092c7686 Mon Sep 17 00:00:00 2001 From: Thomas Lauf Date: Tue, 29 Jan 2019 08:04:51 +0100 Subject: [PATCH] Make functions of Chart member functions --- src/Chart.cpp | 22 +++++++++++----------- src/Chart.h | 30 +++++++++++++++--------------- src/commands/CmdChart.cpp | 4 +++- 3 files changed, 29 insertions(+), 27 deletions(-) diff --git a/src/Chart.cpp b/src/Chart.cpp index a3c661ee..878b1d32 100644 --- a/src/Chart.cpp +++ b/src/Chart.cpp @@ -86,7 +86,7 @@ std::string Chart::render ( if (!with_internal_axis) { out << indent - << Chart::renderAxis ( + << renderAxis ( first_hour, last_hour, color_label, @@ -114,7 +114,7 @@ std::string Chart::render ( lines[i].add (std::string (total_width, ' '), 0, Color ()); } - Chart::renderExclusionBlocks (lines, day, first_hour, last_hour, exclusions, minutes_per_char, spacing, + renderExclusionBlocks (lines, day, first_hour, last_hour, exclusions, minutes_per_char, spacing, color_exclusion, color_label, with_internal_axis); time_t work = 0; @@ -123,7 +123,7 @@ std::string Chart::render ( for (auto &track : tracked) { time_t interval_work = 0; - Chart::renderInterval (lines, day, track, tag_colors, first_hour, interval_work, with_ids, minutes_per_char, + renderInterval (lines, day, track, tag_colors, first_hour, interval_work, with_ids, minutes_per_char, spacing); work += interval_work; } @@ -132,10 +132,10 @@ std::string Chart::render ( auto now = Datetime (); auto color_day = getDayColor (day, now, holidays, color_today, color_holiday); - auto labelMonth = with_month ? Chart::renderMonth (previous, day) : ""; - auto labelWeek = with_week ? Chart::renderWeek (previous, day) : ""; - auto labelWeekday = with_weekday ? Chart::renderWeekday (day, color_day) : ""; - auto labelDay = with_day ? Chart::renderDay (day, color_day) : ""; + auto labelMonth = with_month ? renderMonth (previous, day) : ""; + auto labelWeek = with_week ? renderWeek (previous, day) : ""; + auto labelWeekday = with_weekday ? renderWeekday (day, color_day) : ""; + auto labelDay = with_day ? renderDay (day, color_day) : ""; out << labelMonth << labelWeek @@ -153,16 +153,16 @@ std::string Chart::render ( } } - out << (with_totals ? Chart::renderTotal (work) : "") + out << (with_totals ? renderTotal (work) : "") << '\n'; previous = day; total_work += work; } - out << (with_totals ? Chart::renderSubTotal (total_work, std::string (padding_size, ' ')) : "") - << (with_holidays ? Chart::renderHolidays (holidays) : "") - << (with_summary ? Chart::renderSummary (indent, filter, exclusions, tracked, show_intervals) : ""); + out << (with_totals ? renderSubTotal (total_work, std::string (padding_size, ' ')) : "") + << (with_holidays ? renderHolidays (holidays) : "") + << (with_summary ? renderSummary (indent, filter, exclusions, tracked, show_intervals) : ""); return out.str (); } diff --git a/src/Chart.h b/src/Chart.h index 3ffda3a0..aeb522b4 100644 --- a/src/Chart.h +++ b/src/Chart.h @@ -36,35 +36,35 @@ class Chart public: Chart() = default; - static std::string render (const Interval&, const std::vector &, const std::vector &, const std::map &, const std::map &, const Color&, const Color&, const Color&, const Color&, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, int, int, int); + std::string render (const Interval&, const std::vector &, const std::vector &, const std::map &, const std::map &, const Color&, const Color&, const Color&, const Color&, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, int, int, int); - static unsigned long getIndentSize (bool, bool, bool, bool); + unsigned long getIndentSize (bool, bool, bool, bool); - static std::pair determineHourRange (const Interval&, const std::vector &); + std::pair determineHourRange (const Interval&, const std::vector &); - static std::string renderAxis (int, int, const Color&, const Color&, int, bool); + std::string renderAxis (int, int, const Color&, const Color&, int, bool); - static std::string renderMonth (const Datetime&, const Datetime&); + std::string renderMonth (const Datetime&, const Datetime&); - static std::string renderWeek (const Datetime&, const Datetime&); + std::string renderWeek (const Datetime&, const Datetime&); - static std::string renderWeekday (Datetime&, const Color&); + std::string renderWeekday (Datetime&, const Color&); - static std::string renderDay (Datetime&, const Color&); + std::string renderDay (Datetime&, const Color&); - static Color getDayColor (const Datetime&, const Datetime&, const std::map &, const Color&, const Color&); + Color getDayColor (const Datetime&, const Datetime&, const std::map &, const Color&, const Color&); - static std::string renderTotal (time_t); + std::string renderTotal (time_t); - static std::string renderSubTotal (time_t, const std::string&); + std::string renderSubTotal (time_t, const std::string&); - static void renderExclusionBlocks (std::vector&, const Datetime&, int, int, const std::vector&, int, int, const Color&, const Color&, bool); + void renderExclusionBlocks (std::vector&, const Datetime&, int, int, const std::vector&, int, int, const Color&, const Color&, bool); - static void renderInterval (std::vector&, const Datetime&, const Interval&, const std::map&, int, time_t&, bool, int, int); + void renderInterval (std::vector&, const Datetime&, const Interval&, const std::map&, int, time_t&, bool, int, int); - static std::string renderHolidays (const std::map &); + std::string renderHolidays (const std::map &); - static std::string renderSummary (const std::string&, const Interval&, const std::vector &, const std::vector &, bool); + std::string renderSummary (const std::string&, const Interval&, const std::vector &, const std::vector &, bool); }; #endif diff --git a/src/commands/CmdChart.cpp b/src/commands/CmdChart.cpp index 0e15d8ba..c34c2190 100644 --- a/src/commands/CmdChart.cpp +++ b/src/commands/CmdChart.cpp @@ -145,7 +145,9 @@ int renderChart ( auto axis_type = rules.get ("reports." + type + ".axis"); const auto with_internal_axis = axis_type == "internal"; - 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_month, with_week, with_day, with_weekday, with_internal_axis, minutes_per_char, spacing, num_lines); + Chart chart; + + 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_month, with_week, with_day, with_weekday, with_internal_axis, minutes_per_char, spacing, num_lines); return 0; }