mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
[PATCH] Compute the height of a burndown chart
Signed-off-by: Paul Beckingham <paul@beckingham.net>
This commit is contained in:
parent
402bac02a6
commit
210b5f54d5
3 changed files with 50 additions and 0 deletions
|
@ -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 ------------------------------
|
||||
|
||||
|
|
47
src/util.cpp
47
src/util.cpp
|
@ -29,6 +29,7 @@
|
|||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
@ -39,6 +40,7 @@
|
|||
#include <sys/wait.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
@ -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<std::string> 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<unsigned>::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<unsigned>::max ();
|
||||
}
|
||||
|
|
|
@ -83,5 +83,7 @@ int execute (const std::string&, std::vector<std::string>);
|
|||
std::string compressIds (const std::vector <int>&);
|
||||
void combine (std::vector <int>&, const std::vector <int>&);
|
||||
|
||||
unsigned burndown_size (unsigned ntasks);
|
||||
|
||||
#endif
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue