diff --git a/src/commands/CmdBurndown.cpp b/src/commands/CmdBurndown.cpp index 9804e503e..481b267a7 100644 --- a/src/commands/CmdBurndown.cpp +++ b/src/commands/CmdBurndown.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -158,6 +159,8 @@ private: void maxima (); void yLabels (std::vector &); void calculateRates (std::vector &); + unsigned round_up_to (unsigned, unsigned); + unsigned burndown_size (unsigned); public: int _width; // Terminal width @@ -964,6 +967,50 @@ void Chart::calculateRates (std::vector & sequence) } } +//////////////////////////////////////////////////////////////////////////////// +unsigned Chart::round_up_to (unsigned n, unsigned target) +{ + return n + target - (n % target); +} + +//////////////////////////////////////////////////////////////////////////////// +unsigned Chart::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 (); +} + //////////////////////////////////////////////////////////////////////////////// CmdBurndownMonthly::CmdBurndownMonthly () {