Skip to content

Commit 738c827

Browse files
author
Michael Peters
committed
Fixes for weird edge cases like change points on a closed story, reopening things, etc.
1 parent 7f37b3b commit 738c827

File tree

1 file changed

+29
-18
lines changed

1 file changed

+29
-18
lines changed

src/BurndownData.php

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class BurndownData {
2121
// whether it's open or closed. These values change as we progress through
2222
// time, so that changes to points or status reflect on the graph.
2323
private $task_points = array();
24-
private $task_closed = array();
24+
private $task_statuses = array();
2525

2626
// Project associated with this burndown.
2727
private $project;
@@ -106,10 +106,11 @@ public function __construct($project, $viewer) {
106106
// Build arrays to store current point and closed status of tasks as we
107107
// progress through time, so that these changes reflect on the graph
108108
$this->task_points = array();
109-
$this->task_closed = array();
109+
$this->task_statuses = array();
110110
foreach($this->tasks as $task) {
111111
$this->task_points[$task->getPHID()] = 0;
112-
$this->task_closed[$task->getPHID()] = 0;
112+
$this->task_statuses[$task->getPHID()] = null;
113+
$this->task_in_sprint[$task->getPHID()] = 0;
113114
}
114115

115116
// Now loop through the events and build the data for each day
@@ -137,11 +138,11 @@ public function __construct($project, $viewer) {
137138
break;
138139
case "task-add":
139140
// A task was added to the sprint
140-
$this->addTask($date, $task_phid);
141+
$this->addTaskToSprint($date, $task_phid);
141142
break;
142143
case "task-remove":
143144
// A task was removed from the sprint
144-
$this->removeTask($date, $task_phid);
145+
$this->removeTaskFromSprint($date, $task_phid);
145146
break;
146147
case "close":
147148
// A task was closed, mark it as done
@@ -211,37 +212,45 @@ public function __construct($project, $viewer) {
211212
/**
212213
* These handle the relevant math for adding, removing, closing, etc.
213214
*/
214-
private function addTask($date, $task_phid) {
215+
private function addTaskToSprint($date, $task_phid) {
215216
$this->dates[$date]->tasks_added_today += 1;
216217
$this->dates[$date]->points_added_today += $this->task_points[$task_phid];
218+
$this->task_in_sprint[$task_phid] = 1;
217219
}
218220

219-
private function removeTask($date, $task_phid) {
221+
private function removeTaskFromSprint($date, $task_phid) {
220222
$this->dates[$date]->tasks_added_today -= 1;
221223
$this->dates[$date]->points_added_today -= $this->task_points[$task_phid];
224+
$this->task_in_sprint[$task_phid] = 0;
222225
}
223226

224227
private function closeTask($date, $task_phid) {
225228
$this->dates[$date]->tasks_closed_today += 1;
226229
$this->dates[$date]->points_closed_today += $this->task_points[$task_phid];
227-
$this->task_closed[$task_phid] = 1;
230+
$this->task_statuses[$task_phid] = 'closed';
228231
}
229232

230233
private function reopenTask($date, $task_phid) {
231234
$this->dates[$date]->tasks_closed_today -= 1;
232235
$this->dates[$date]->points_closed_today -= $this->task_points[$task_phid];
233-
$this->task_closed[$task_phid] = 0;
236+
$this->task_statuses[$task_phid] = 'open';
234237
}
235238

236239
private function changePoints($date, $task_phid, $xaction) {
237-
$this->dates[$date]->points_added_today +=
238-
$xaction->getNewValue() - $xaction->getOldValue();
239240
$this->task_points[$task_phid] = $xaction->getNewValue();
240241

241-
// If the task is closed, we also need to adjust the completed points
242-
if ($this->task_closed[$task_phid]) {
243-
$this->dates[$date]->points_closed_today +=
242+
// Only make changes if the task is in the sprint
243+
if ($this->task_in_sprint[$task_phid]) {
244+
245+
// Adjust points for that day
246+
$this->dates[$date]->points_added_today +=
244247
$xaction->getNewValue() - $xaction->getOldValue();
248+
249+
// If the task is closed, adjust completed points as well
250+
if ($this->task_statuses[$task_phid] == 'closed') {
251+
$this->dates[$date]->points_closed_today +=
252+
$xaction->getNewValue() - $xaction->getOldValue();
253+
}
245254
}
246255
}
247256

@@ -258,7 +267,7 @@ public function buildBurnDownChart() {
258267
foreach($this->dates as $key => $date)
259268
{
260269
if ($key != 'before' AND $key != 'after') {
261-
$future = new DateTime($date->getDate()) >= id(new DateTime())->setTime(0,0);
270+
$future = new DateTime($date->getDate()) > id(new DateTime())->setTime(0,0);
262271
}
263272
$data[] = array(
264273
$date->getDate(),
@@ -297,9 +306,11 @@ function drawVisualization() {
297306
seriesType: "line",
298307
lineWidth: 3,
299308
series: {
300-
3: {type: "bars"},
301-
},
302-
colors: ['#f88', '#fb0', '#0df', '#0c0']
309+
0: {color: '#f88'},
310+
1: {color: '#fb0'},
311+
2: {color: '#ccc', lineDashStyle: [8,4]},
312+
3: {type: "bars", color: '#0c0'},
313+
}
303314
});
304315
}
305316

0 commit comments

Comments
 (0)