Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / project / chart / PhabricatorProjectBurndownChartEngine.php
blob16760d515f457728218f57accc4dd91657f2aafd
1 <?php
3 final class PhabricatorProjectBurndownChartEngine
4 extends PhabricatorChartEngine {
6 const CHARTENGINEKEY = 'project.burndown';
8 public function setProjects(array $projects) {
9 assert_instances_of($projects, 'PhabricatorProject');
10 $project_phids = mpull($projects, 'getPHID');
11 return $this->setEngineParameter('projectPHIDs', $project_phids);
14 protected function newChart(PhabricatorFactChart $chart, array $map) {
15 $viewer = $this->getViewer();
17 $map = $map + array(
18 'projectPHIDs' => array(),
21 if ($map['projectPHIDs']) {
22 $projects = id(new PhabricatorProjectQuery())
23 ->setViewer($viewer)
24 ->withPHIDs($map['projectPHIDs'])
25 ->execute();
26 $project_phids = mpull($projects, 'getPHID');
27 } else {
28 $project_phids = array();
31 $functions = array();
32 if ($project_phids) {
33 $open_function = $this->newFunction(
34 array(
35 'accumulate',
36 array(
37 'sum',
38 $this->newFactSum(
39 'tasks.open-count.create.project', $project_phids),
40 $this->newFactSum(
41 'tasks.open-count.status.project', $project_phids),
42 $this->newFactSum(
43 'tasks.open-count.assign.project', $project_phids),
45 ));
47 $closed_function = $this->newFunction(
48 array(
49 'accumulate',
50 $this->newFactSum('tasks.open-count.status.project', $project_phids),
51 ));
52 } else {
53 $open_function = $this->newFunction(
54 array(
55 'accumulate',
56 array(
57 'sum',
58 array('fact', 'tasks.open-count.create'),
59 array('fact', 'tasks.open-count.status'),
61 ));
63 $closed_function = $this->newFunction(
64 array(
65 'accumulate',
66 array('fact', 'tasks.open-count.status'),
67 ));
70 $open_function->getFunctionLabel()
71 ->setKey('open')
72 ->setName(pht('Open Tasks'))
73 ->setColor('rgba(0, 0, 200, 1)')
74 ->setFillColor('rgba(0, 0, 200, 0.15)');
76 $closed_function->getFunctionLabel()
77 ->setKey('closed')
78 ->setName(pht('Closed Tasks'))
79 ->setColor('rgba(0, 200, 0, 1)')
80 ->setFillColor('rgba(0, 200, 0, 0.15)');
82 $datasets = array();
84 $dataset = id(new PhabricatorChartStackedAreaDataset())
85 ->setFunctions(
86 array(
87 $open_function,
88 $closed_function,
90 ->setStacks(
91 array(
92 array('open'),
93 array('closed'),
94 ));
96 $datasets[] = $dataset;
97 $chart->attachDatasets($datasets);
100 private function newFactSum($fact_key, array $phids) {
101 $result = array();
102 $result[] = 'sum';
104 foreach ($phids as $phid) {
105 $result[] = array('fact', $fact_key, $phid);
108 return $result;