mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-07-07 20:06:39 +02:00
Inject reference datetime (= now) into chart
Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
This commit is contained in:
parent
69de6b4412
commit
42cb7273cd
4 changed files with 14 additions and 14 deletions
|
@ -38,6 +38,7 @@
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
Chart::Chart (ChartConfig configuration) :
|
Chart::Chart (ChartConfig configuration) :
|
||||||
|
reference_datetime(configuration.reference_datetime),
|
||||||
with_label_month(configuration.with_label_month),
|
with_label_month(configuration.with_label_month),
|
||||||
with_label_week(configuration.with_label_week),
|
with_label_week(configuration.with_label_week),
|
||||||
with_label_weekday(configuration.with_label_weekday),
|
with_label_weekday(configuration.with_label_weekday),
|
||||||
|
@ -130,8 +131,7 @@ std::string Chart::render (
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto now = Datetime ();
|
auto color_day = getDayColor (day, holidays);
|
||||||
auto color_day = getDayColor (day, now, holidays);
|
|
||||||
|
|
||||||
auto labelMonth = with_label_month ? renderMonth (previous, day) : "";
|
auto labelMonth = with_label_month ? renderMonth (previous, day) : "";
|
||||||
auto labelWeek = with_label_week ? renderWeek (previous, day) : "";
|
auto labelWeek = with_label_week ? renderWeek (previous, day) : "";
|
||||||
|
@ -207,7 +207,7 @@ std::pair<int, int> Chart::determineHourRange (
|
||||||
Interval clipped = clip (track, day_range);
|
Interval clipped = clip (track, day_range);
|
||||||
if (track.is_open ())
|
if (track.is_open ())
|
||||||
{
|
{
|
||||||
clipped.end = Datetime ();
|
clipped.end = reference_datetime;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (clipped.start.hour () < first_hour)
|
if (clipped.start.hour () < first_hour)
|
||||||
|
@ -225,7 +225,7 @@ std::pair<int, int> Chart::determineHourRange (
|
||||||
|
|
||||||
if (first_hour == 23 && last_hour == 0)
|
if (first_hour == 23 && last_hour == 0)
|
||||||
{
|
{
|
||||||
first_hour = Datetime ().hour ();
|
first_hour = reference_datetime.hour ();
|
||||||
last_hour = std::min (first_hour + 1, 23);
|
last_hour = std::min (first_hour + 1, 23);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -247,7 +247,7 @@ std::string Chart::renderAxis (
|
||||||
const int cell_size)
|
const int cell_size)
|
||||||
{
|
{
|
||||||
std::stringstream out;
|
std::stringstream out;
|
||||||
auto current_hour = Datetime ().hour ();
|
auto current_hour = reference_datetime.hour ();
|
||||||
|
|
||||||
for (int hour = first_hour; hour <= last_hour; hour++)
|
for (int hour = first_hour; hour <= last_hour; hour++)
|
||||||
{
|
{
|
||||||
|
@ -325,10 +325,9 @@ std::string Chart::renderDay (Datetime &day, const Color &color)
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
Color Chart::getDayColor (
|
Color Chart::getDayColor (
|
||||||
const Datetime &day,
|
const Datetime &day,
|
||||||
const Datetime &now,
|
|
||||||
const std::map <Datetime, std::string> &holidays)
|
const std::map <Datetime, std::string> &holidays)
|
||||||
{
|
{
|
||||||
if (day.sameDay (now))
|
if (day.sameDay (reference_datetime))
|
||||||
{
|
{
|
||||||
return color_today;
|
return color_today;
|
||||||
}
|
}
|
||||||
|
@ -452,11 +451,9 @@ void Chart::renderInterval (
|
||||||
const int first_hour,
|
const int first_hour,
|
||||||
time_t &work)
|
time_t &work)
|
||||||
{
|
{
|
||||||
Datetime now;
|
|
||||||
|
|
||||||
// Ignore any track that doesn't overlap with day.
|
// Ignore any track that doesn't overlap with day.
|
||||||
auto day_range = getFullDay (day);
|
auto day_range = getFullDay (day);
|
||||||
if (!day_range.overlaps (track) || (track.is_open () && day > now))
|
if (!day_range.overlaps (track) || (track.is_open () && day > reference_datetime))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -466,9 +463,9 @@ void Chart::renderInterval (
|
||||||
Interval clipped = clip (track, day_range);
|
Interval clipped = clip (track, day_range);
|
||||||
if (track.is_open ())
|
if (track.is_open ())
|
||||||
{
|
{
|
||||||
if (day_range.start.sameDay (now))
|
if (day_range.start.sameDay (reference_datetime))
|
||||||
{
|
{
|
||||||
clipped.end = now;
|
clipped.end = reference_datetime;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -587,7 +584,7 @@ std::string Chart::renderSummary (
|
||||||
Interval clipped = clip (interval, filter);
|
Interval clipped = clip (interval, filter);
|
||||||
if (interval.is_open ())
|
if (interval.is_open ())
|
||||||
{
|
{
|
||||||
clipped.end = Datetime ();
|
clipped.end = reference_datetime;
|
||||||
}
|
}
|
||||||
|
|
||||||
total_worked += clipped.total ();
|
total_worked += clipped.total ();
|
||||||
|
|
|
@ -57,8 +57,9 @@ private:
|
||||||
|
|
||||||
std::pair <int, int> determineHourRange (const Interval&, const std::vector <Interval>&);
|
std::pair <int, int> determineHourRange (const Interval&, const std::vector <Interval>&);
|
||||||
|
|
||||||
Color getDayColor (const Datetime &, const Datetime &, const std::map<Datetime, std::string> &);
|
Color getDayColor (const Datetime&, const std::map <Datetime, std::string>&);
|
||||||
|
|
||||||
|
const Datetime reference_datetime;
|
||||||
const bool with_label_month;
|
const bool with_label_month;
|
||||||
const bool with_label_week;
|
const bool with_label_week;
|
||||||
const bool with_label_weekday;
|
const bool with_label_weekday;
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
class ChartConfig
|
class ChartConfig
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
Datetime reference_datetime;
|
||||||
bool with_label_month;
|
bool with_label_month;
|
||||||
bool with_label_week;
|
bool with_label_week;
|
||||||
bool with_label_weekday;
|
bool with_label_weekday;
|
||||||
|
|
|
@ -124,6 +124,7 @@ int renderChart (
|
||||||
throw format ("Invalid value for 'reports.{1}.lines': '{2}'", type, num_lines);
|
throw format ("Invalid value for 'reports.{1}.lines': '{2}'", type, num_lines);
|
||||||
|
|
||||||
ChartConfig configuration {};
|
ChartConfig configuration {};
|
||||||
|
configuration.reference_datetime = Datetime ();
|
||||||
configuration.with_label_month = rules.getBoolean ("reports." + type + ".month");
|
configuration.with_label_month = rules.getBoolean ("reports." + type + ".month");
|
||||||
configuration.with_label_week = rules.getBoolean ("reports." + type + ".week");
|
configuration.with_label_week = rules.getBoolean ("reports." + type + ".week");
|
||||||
configuration.with_label_weekday = rules.getBoolean ("reports." + type + ".weekday");
|
configuration.with_label_weekday = rules.getBoolean ("reports." + type + ".weekday");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue