mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-07-07 20:06:39 +02:00
Make Chart::render return a string instead of writing to std::cout
This commit is contained in:
parent
365ae27e49
commit
c562f3fc81
3 changed files with 29 additions and 25 deletions
|
@ -36,7 +36,7 @@
|
||||||
#include <timew.h>
|
#include <timew.h>
|
||||||
#include <Chart.h>
|
#include <Chart.h>
|
||||||
|
|
||||||
void Chart::render (
|
std::string Chart::render (
|
||||||
const Interval &filter,
|
const Interval &filter,
|
||||||
const std::vector<Interval> &tracked,
|
const std::vector<Interval> &tracked,
|
||||||
const std::vector<Range> &exclusions,
|
const std::vector<Range> &exclusions,
|
||||||
|
@ -78,19 +78,21 @@ void Chart::render (
|
||||||
const auto indent = std::string (indent_size, ' ');
|
const auto indent = std::string (indent_size, ' ');
|
||||||
const auto padding_size = indent_size + ((last_hour - first_hour + 1) * (cell_size)) + 1;
|
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.
|
// Render the axis.
|
||||||
if (!with_internal_axis)
|
if (!with_internal_axis)
|
||||||
{
|
{
|
||||||
std::cout << indent
|
out << indent
|
||||||
<< Chart::renderAxis (
|
<< Chart::renderAxis (
|
||||||
first_hour,
|
first_hour,
|
||||||
last_hour,
|
last_hour,
|
||||||
color_label,
|
color_label,
|
||||||
color_today,
|
color_today,
|
||||||
cell_size,
|
cell_size,
|
||||||
with_totals);
|
with_totals);
|
||||||
}
|
}
|
||||||
|
|
||||||
// For rendering labels on edge detection.
|
// For rendering labels on edge detection.
|
||||||
|
@ -135,32 +137,34 @@ void Chart::render (
|
||||||
auto labelWeekday = with_weekday ? Chart::renderWeekday (day, color_day) : "";
|
auto labelWeekday = with_weekday ? Chart::renderWeekday (day, color_day) : "";
|
||||||
auto labelDay = with_day ? Chart::renderDay (day, color_day) : "";
|
auto labelDay = with_day ? Chart::renderDay (day, color_day) : "";
|
||||||
|
|
||||||
std::cout << labelMonth
|
out << labelMonth
|
||||||
<< labelWeek
|
<< labelWeek
|
||||||
<< labelWeekday
|
<< labelWeekday
|
||||||
<< labelDay
|
<< labelDay
|
||||||
<< lines[0].str ();
|
<< lines[0].str ();
|
||||||
|
|
||||||
if (lines.size () > 1)
|
if (lines.size () > 1)
|
||||||
{
|
{
|
||||||
for (unsigned int i = 1; i < lines.size (); ++i)
|
for (unsigned int i = 1; i < lines.size (); ++i)
|
||||||
{
|
{
|
||||||
std::cout << "\n"
|
out << "\n"
|
||||||
<< indent
|
<< indent
|
||||||
<< lines[i].str ();
|
<< lines[i].str ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << (with_totals ? Chart::renderTotal (work) : "")
|
out << (with_totals ? Chart::renderTotal (work) : "")
|
||||||
<< '\n';
|
<< '\n';
|
||||||
|
|
||||||
previous = day;
|
previous = day;
|
||||||
total_work += work;
|
total_work += work;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << (with_totals ? Chart::renderSubTotal (total_work, std::string (padding_size, ' ')) : "")
|
out << (with_totals ? Chart::renderSubTotal (total_work, std::string (padding_size, ' ')) : "")
|
||||||
<< (with_holidays ? Chart::renderHolidays (holidays) : "")
|
<< (with_holidays ? Chart::renderHolidays (holidays) : "")
|
||||||
<< (with_summary ? Chart::renderSummary (indent, filter, exclusions, tracked, show_intervals) : "");
|
<< (with_summary ? Chart::renderSummary (indent, filter, exclusions, tracked, show_intervals) : "");
|
||||||
|
|
||||||
|
return out.str ();
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -36,7 +36,7 @@ class Chart
|
||||||
public:
|
public:
|
||||||
Chart() = default;
|
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);
|
static unsigned long getIndentSize (bool, bool, bool, bool);
|
||||||
|
|
||||||
|
|
|
@ -145,7 +145,7 @@ int renderChart (
|
||||||
auto axis_type = rules.get ("reports." + type + ".axis");
|
auto axis_type = rules.get ("reports." + type + ".axis");
|
||||||
const auto with_internal_axis = axis_type == "internal";
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue