@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
at upstream/main 138 lines 3.5 kB view raw
1<?php 2 3final class PhabricatorProjectActivityChartEngine 4 extends PhabricatorChartEngine { 5 6 const CHARTENGINEKEY = 'project.activity'; 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 $project_phid = head($project_phids); 35 36 $functions = array(); 37 $stacks = array(); 38 39 $function = $this->newFunction( 40 array( 41 'accumulate', 42 array( 43 'compose', 44 array('fact', 'tasks.open-count.assign.project', $project_phid), 45 array('min', 0), 46 ), 47 )); 48 49 $function->getFunctionLabel() 50 ->setKey('moved-in') 51 ->setName(pht('Tasks Moved Into Project')) 52 ->setColor('rgba(182, 126, 200, 1)') 53 ->setFillColor('rgba(182, 126, 200, 0.15)'); 54 55 $functions[] = $function; 56 57 $function = $this->newFunction( 58 array( 59 'accumulate', 60 array( 61 'compose', 62 array('fact', 'tasks.open-count.status.project', $project_phid), 63 array('min', 0), 64 ), 65 )); 66 67 $function->getFunctionLabel() 68 ->setKey('reopened') 69 ->setName(pht('Tasks Reopened')) 70 ->setColor('rgba(128, 128, 200, 1)') 71 ->setFillColor('rgba(128, 128, 200, 0.15)'); 72 73 $functions[] = $function; 74 75 $function = $this->newFunction( 76 array( 77 'accumulate', 78 array('fact', 'tasks.open-count.create.project', $project_phid), 79 )); 80 81 $function->getFunctionLabel() 82 ->setKey('created') 83 ->setName(pht('Tasks Created')) 84 ->setColor('rgba(41, 128, 185, 1)') 85 ->setFillColor('rgba(41, 128, 185, 0.15)'); 86 87 $functions[] = $function; 88 89 $function = $this->newFunction( 90 array( 91 'accumulate', 92 array( 93 'compose', 94 array('fact', 'tasks.open-count.status.project', $project_phid), 95 array('max', 0), 96 ), 97 )); 98 99 $function->getFunctionLabel() 100 ->setKey('closed') 101 ->setName(pht('Tasks Closed')) 102 ->setColor('rgba(0, 200, 0, 1)') 103 ->setFillColor('rgba(0, 200, 0, 0.15)'); 104 105 $functions[] = $function; 106 107 $function = $this->newFunction( 108 array( 109 'accumulate', 110 array( 111 'compose', 112 array('fact', 'tasks.open-count.assign.project', $project_phid), 113 array('max', 0), 114 ), 115 )); 116 117 $function->getFunctionLabel() 118 ->setKey('moved-out') 119 ->setName(pht('Tasks Moved Out of Project')) 120 ->setColor('rgba(128, 200, 128, 1)') 121 ->setFillColor('rgba(128, 200, 128, 0.15)'); 122 123 $functions[] = $function; 124 125 $stacks[] = array('created', 'reopened', 'moved-in'); 126 $stacks[] = array('closed', 'moved-out'); 127 128 $datasets = array(); 129 130 $dataset = id(new PhabricatorChartStackedAreaDataset()) 131 ->setFunctions($functions) 132 ->setStacks($stacks); 133 134 $datasets[] = $dataset; 135 $chart->attachDatasets($datasets); 136 } 137 138}