From 71ccf8584a568fdf05f6fe78fecbffcba7f480f4 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 21 May 2016 15:48:36 -0500 Subject: [PATCH] CmdChart: Added determineHourRange --- src/commands/CmdChart.cpp | 46 ++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/src/commands/CmdChart.cpp b/src/commands/CmdChart.cpp index 4b116807..bd84cc3f 100644 --- a/src/commands/CmdChart.cpp +++ b/src/commands/CmdChart.cpp @@ -38,6 +38,7 @@ #include int renderChart (const std::string&, Interval&, Rules&, Database&); +static void determineHourRange (const std::string&, const Rules&, 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&); @@ -108,23 +109,7 @@ int renderChart ( // Determine hours shown. int first_hour = 0; int last_hour = 23; - if (! rules.getBoolean ("reports." + type + ".24h")) - { - // Get the extreme time range for the filtered data. - first_hour = 23; - last_hour = 0; - for (auto& track : tracked) - { - if (track.range.start.hour () < first_hour) - first_hour = track.range.start.hour (); - - if (track.range.end.hour () > last_hour) - last_hour = track.range.end.hour (); - } - - first_hour = std::max (first_hour - 1, 0); - last_hour = std::min (last_hour + 1, 23); - } + determineHourRange (type, rules, tracked, first_hour, last_hour); // Render the axis. std::cout << '\n'; @@ -189,6 +174,33 @@ int renderChart ( return 0; } +//////////////////////////////////////////////////////////////////////////////// +static void determineHourRange ( + const std::string& type, + const Rules& rules, + const std::vector & tracked, + int& first_hour, + int& last_hour) +{ + if (! rules.getBoolean ("reports." + type + ".24h")) + { + // Get the extreme time range for the filtered data. + first_hour = 23; + last_hour = 0; + for (auto& track : tracked) + { + if (track.range.start.hour () < first_hour) + first_hour = track.range.start.hour (); + + if (track.range.end.hour () > last_hour) + last_hour = track.range.end.hour (); + } + + first_hour = std::max (first_hour - 1, 0); + last_hour = std::min (last_hour + 1, 23); + } +} + //////////////////////////////////////////////////////////////////////////////// static void renderAxis ( const std::string& type,