@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3final class PhabricatorProjectBurndownChartEngine
4 extends PhabricatorChartEngine {
5
6 const CHARTENGINEKEY = 'project.burndown';
7
8 /**
9 * @param array<PhabricatorProject> $projects
10 */
11 public function setProjects(array $projects) {
12 assert_instances_of($projects, PhabricatorProject::class);
13 $project_phids = mpull($projects, 'getPHID');
14 return $this->setEngineParameter('projectPHIDs', $project_phids);
15 }
16
17 protected function newChart(PhabricatorFactChart $chart, array $map) {
18 $viewer = $this->getViewer();
19
20 $map = $map + array(
21 'projectPHIDs' => array(),
22 );
23
24 if ($map['projectPHIDs']) {
25 $projects = id(new PhabricatorProjectQuery())
26 ->setViewer($viewer)
27 ->withPHIDs($map['projectPHIDs'])
28 ->execute();
29 $project_phids = mpull($projects, 'getPHID');
30 } else {
31 $project_phids = array();
32 }
33
34 $functions = array();
35 if ($project_phids) {
36 $open_function = $this->newFunction(
37 array(
38 'accumulate',
39 array(
40 'sum',
41 $this->newFactSum(
42 'tasks.open-count.create.project', $project_phids),
43 $this->newFactSum(
44 'tasks.open-count.status.project', $project_phids),
45 $this->newFactSum(
46 'tasks.open-count.assign.project', $project_phids),
47 ),
48 ));
49
50 $closed_function = $this->newFunction(
51 array(
52 'accumulate',
53 $this->newFactSum('tasks.open-count.status.project', $project_phids),
54 ));
55 } else {
56 $open_function = $this->newFunction(
57 array(
58 'accumulate',
59 array(
60 'sum',
61 array('fact', 'tasks.open-count.create'),
62 array('fact', 'tasks.open-count.status'),
63 ),
64 ));
65
66 $closed_function = $this->newFunction(
67 array(
68 'accumulate',
69 array('fact', 'tasks.open-count.status'),
70 ));
71 }
72
73 $open_function->getFunctionLabel()
74 ->setKey('open')
75 ->setName(pht('Open Tasks'))
76 ->setColor('rgba(41, 128, 185, 1)')
77 ->setFillColor('rgba(41, 128, 185, 0.15)');
78
79 $closed_function->getFunctionLabel()
80 ->setKey('closed')
81 ->setName(pht('Closed Tasks'))
82 ->setColor('rgba(0, 200, 0, 1)')
83 ->setFillColor('rgba(0, 200, 0, 0.15)');
84
85 $datasets = array();
86
87 $dataset = id(new PhabricatorChartStackedAreaDataset())
88 ->setFunctions(
89 array(
90 $open_function,
91 $closed_function,
92 ))
93 ->setStacks(
94 array(
95 array('open'),
96 array('closed'),
97 ));
98
99 $datasets[] = $dataset;
100 $chart->attachDatasets($datasets);
101 }
102
103 /**
104 * @param string $fact_key The key of the new fact sum
105 * (e.g. "tasks.open-count.assign.project")
106 * @param array<string> $phids Project PHIDs
107 * @return array
108 */
109 private function newFactSum($fact_key, array $phids) {
110 $result = array();
111 $result[] = 'sum';
112
113 foreach ($phids as $phid) {
114 $result[] = array('fact', $fact_key, $phid);
115 }
116
117 return $result;
118 }
119
120}