Skip to content
Permalink
Browse files

Make Chart::render return a string instead of writing to std::cout

  • Loading branch information...
lauft committed Jan 28, 2019
1 parent 365ae27 commit c562f3fc81ad1ede7b268f564430c238a819bcde
Showing with 29 additions and 25 deletions.
  1. +27 −23 src/Chart.cpp
  2. +1 −1 src/Chart.h
  3. +1 −1 src/commands/CmdChart.cpp
@@ -36,7 +36,7 @@
#include <timew.h>
#include <Chart.h>

void Chart::render (
std::string Chart::render (
const Interval &filter,
const std::vector<Interval> &tracked,
const std::vector<Range> &exclusions,
@@ -78,19 +78,21 @@ void Chart::render (
const auto indent = std::string (indent_size, ' ');
const auto padding_size = indent_size + ((last_hour - first_hour + 1) * (cell_size)) + 1;

std::cout << '\n';
std::stringstream out;

out << '\n';

// Render the axis.
if (!with_internal_axis)
{
std::cout << indent
<< Chart::renderAxis (
first_hour,
last_hour,
color_label,
color_today,
cell_size,
with_totals);
out << indent
<< Chart::renderAxis (
first_hour,
last_hour,
color_label,
color_today,
cell_size,
with_totals);
}

// For rendering labels on edge detection.
@@ -135,32 +137,34 @@ void Chart::render (
auto labelWeekday = with_weekday ? Chart::renderWeekday (day, color_day) : "";
auto labelDay = with_day ? Chart::renderDay (day, color_day) : "";

std::cout << labelMonth
<< labelWeek
<< labelWeekday
<< labelDay
<< lines[0].str ();
out << labelMonth
<< labelWeek
<< labelWeekday
<< labelDay
<< lines[0].str ();

if (lines.size () > 1)
{
for (unsigned int i = 1; i < lines.size (); ++i)
{
std::cout << "\n"
<< indent
<< lines[i].str ();
out << "\n"
<< indent
<< lines[i].str ();
}
}

std::cout << (with_totals ? Chart::renderTotal (work) : "")
<< '\n';
out << (with_totals ? Chart::renderTotal (work) : "")
<< '\n';

previous = day;
total_work += work;
}

std::cout << (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 ? Chart::renderSubTotal (total_work, std::string (padding_size, ' ')) : "")
<< (with_holidays ? Chart::renderHolidays (holidays) : "")
<< (with_summary ? Chart::renderSummary (indent, filter, exclusions, tracked, show_intervals) : "");

return out.str ();
}

////////////////////////////////////////////////////////////////////////////////
@@ -36,7 +36,7 @@ class Chart
public:
Chart() = default;

static void 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, bool, bool, bool, bool, int, int, int);
static 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, bool, bool, bool, bool, int, int, int);

static unsigned long getIndentSize (bool, bool, bool, bool);

@@ -145,7 +145,7 @@ int renderChart (
auto axis_type = rules.get ("reports." + type + ".axis");
const auto with_internal_axis = axis_type == "internal";

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);
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;
}

0 comments on commit c562f3f

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.