From 210b5f54d572f1e7b1190b768dd4f625950b8c2d Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Fri, 29 Jul 2011 22:30:27 -0400 Subject: [PATCH] [PATCH] Compute the height of a burndown chart Signed-off-by: Paul Beckingham --- ChangeLog | 1 + src/util.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++++ src/util.h | 2 ++ 3 files changed, 50 insertions(+) diff --git a/ChangeLog b/ChangeLog index 265ae7d98..615b5a00d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -169,6 +169,7 @@ + Fixed bug that required the '%YAML' prologue in a YAML import. + Fixed bug that showed the 'due' date, under the heading 'until' date, in the info report (thanks to Michael McCann). + + Fixed burndown chart y-axis height calculation (thanks to Ben Boeckel). ------ old releases ------------------------------ diff --git a/src/util.cpp b/src/util.cpp index 325a148b1..acb208523 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -29,6 +29,7 @@ #include #include +#include #include #include #include @@ -39,6 +40,7 @@ #include #include #include +#include #include #include #include @@ -54,6 +56,12 @@ extern Context context; +//////////////////////////////////////////////////////////////////////////////// +static inline unsigned round_up_to (unsigned n, unsigned target) +{ + return n + target - (n % target); +} + //////////////////////////////////////////////////////////////////////////////// // Uses std::getline, because std::cin eats leading whitespace, and that means // that if a newline is entered, std::cin eats it and never returns from the @@ -437,4 +445,43 @@ int execute(const std::string& executable, std::vector arguments) } } +// Collides with std::numeric_limits methods +#undef max + //////////////////////////////////////////////////////////////////////////////// +unsigned burndown_size (unsigned ntasks) +{ + // Nearest 2 + if (ntasks < 20) + return round_up_to (ntasks, 2); + + // Nearest 10 + if (ntasks < 50) + return round_up_to (ntasks, 10); + + // Nearest 20 + if (ntasks < 100) + return round_up_to (ntasks, 20); + + // Choose the number from here rounded up to the nearest 10% of the next + // highest power of 10 or half of power of 10. + const unsigned count = (unsigned) log10 (std::numeric_limits::max ()); + unsigned half = 500; + unsigned full = 1000; + + // We start at two because we handle 5, 10, 50, and 100 above. + for (unsigned i = 2; i < count; ++i) + { + if (ntasks < half) + return round_up_to (ntasks, half / 10); + + if (ntasks < full) + return round_up_to (ntasks, full / 10); + + half *= 10; + full *= 10; + } + + // Round up to max of unsigned. + return std::numeric_limits::max (); +} diff --git a/src/util.h b/src/util.h index 776d9479f..a2d6cd5e6 100644 --- a/src/util.h +++ b/src/util.h @@ -83,5 +83,7 @@ int execute (const std::string&, std::vector); std::string compressIds (const std::vector &); void combine (std::vector &, const std::vector &); +unsigned burndown_size (unsigned ntasks); + #endif ////////////////////////////////////////////////////////////////////////////////