From 83e9f3d68807b7aba012b672420436b465877538 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 11 Jun 2016 14:05:08 -0400 Subject: [PATCH] CmdChart: Fixed bug determineHourRange was not properly clipping intervals to days --- src/commands/CmdChart.cpp | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/src/commands/CmdChart.cpp b/src/commands/CmdChart.cpp index 31ece99a..169861d5 100644 --- a/src/commands/CmdChart.cpp +++ b/src/commands/CmdChart.cpp @@ -38,7 +38,7 @@ #include int renderChart (const CLI&, const std::string&, Interval&, Rules&, Database&); -static void determineHourRange (const std::string&, const Rules&, const std::vector &, int&, int&); +static void determineHourRange (const std::string&, const Rules&, const Interval&, const std::vector &, int&, int&); static void renderAxis (const std::string&, const Rules&, Palette&, const std::string&, int, int); static std::string renderMonth (const std::string&, const Rules&, const Datetime&, const Datetime&); static std::string renderDayName (const std::string&, const Rules&, Datetime&, Color&, Color&); @@ -127,7 +127,7 @@ int renderChart ( // Determine hours shown. int first_hour = 0; int last_hour = 23; - determineHourRange (type, rules, tracked, first_hour, last_hour); + determineHourRange (type, rules, filter, tracked, first_hour, last_hour); // Render the axis. std::cout << '\n'; @@ -213,6 +213,7 @@ int renderChart ( static void determineHourRange ( const std::string& type, const Rules& rules, + const Interval& filter, const std::vector & tracked, int& first_hour, int& last_hour) @@ -229,14 +230,26 @@ static void determineHourRange ( // Get the extreme time range for the filtered data. first_hour = 23; last_hour = 0; - for (auto& track : tracked) + for (Datetime day = filter.range.start; day < filter.range.end; day++) { - if (track.range.start.hour () < first_hour) - first_hour = track.range.start.hour (); + auto day_range = getFullDay (day); - if (! track.range.is_open () && - track.range.end.hour () > last_hour) - last_hour = track.range.end.hour (); + for (auto& track : tracked) + { + if (day_range.overlap (track.range)) + { + Interval clipped = clip (track, day_range); + if (track.range.is_open ()) + clipped.range.end = Datetime (); + + if (clipped.range.start.hour () < first_hour) + first_hour = clipped.range.start.hour (); + + if (! clipped.range.is_open () && + clipped.range.end.hour () > last_hour) + last_hour = clipped.range.end.hour (); + } + } } first_hour = std::max (first_hour - 1, 0);