Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/fact/chart/PhabricatorChartDataset.php
12256 views
1
<?php
2
3
abstract class PhabricatorChartDataset
4
extends Phobject {
5
6
private $functions;
7
8
final public function getDatasetTypeKey() {
9
return $this->getPhobjectClassConstant('DATASETKEY', 32);
10
}
11
12
final public function getFunctions() {
13
return $this->functions;
14
}
15
16
final public function setFunctions(array $functions) {
17
assert_instances_of($functions, 'PhabricatorComposeChartFunction');
18
19
$this->functions = $functions;
20
21
return $this;
22
}
23
24
final public static function getAllDatasetTypes() {
25
return id(new PhutilClassMapQuery())
26
->setAncestorClass(__CLASS__)
27
->setUniqueMethod('getDatasetTypeKey')
28
->execute();
29
}
30
31
final public static function newFromDictionary(array $map) {
32
PhutilTypeSpec::checkMap(
33
$map,
34
array(
35
'type' => 'string',
36
'functions' => 'list<wild>',
37
));
38
39
$types = self::getAllDatasetTypes();
40
41
$dataset_type = $map['type'];
42
if (!isset($types[$dataset_type])) {
43
throw new Exception(
44
pht(
45
'Trying to construct a dataset of type "%s", but this type is '.
46
'unknown. Supported types are: %s.',
47
$dataset_type,
48
implode(', ', array_keys($types))));
49
}
50
51
$dataset = id(clone $types[$dataset_type]);
52
53
$functions = array();
54
foreach ($map['functions'] as $map) {
55
$functions[] = PhabricatorChartFunction::newFromDictionary($map);
56
}
57
$dataset->setFunctions($functions);
58
59
return $dataset;
60
}
61
62
final public function getChartDisplayData(
63
PhabricatorChartDataQuery $data_query) {
64
return $this->newChartDisplayData($data_query);
65
}
66
67
abstract protected function newChartDisplayData(
68
PhabricatorChartDataQuery $data_query);
69
70
71
final public function getTabularDisplayData(
72
PhabricatorChartDataQuery $data_query) {
73
$results = array();
74
75
$functions = $this->getFunctions();
76
foreach ($functions as $function) {
77
$datapoints = $function->newDatapoints($data_query);
78
79
$refs = $function->getDataRefs(ipull($datapoints, 'x'));
80
81
foreach ($datapoints as $key => $point) {
82
$x = $point['x'];
83
84
if (isset($refs[$x])) {
85
$xrefs = $refs[$x];
86
} else {
87
$xrefs = array();
88
}
89
90
$datapoints[$key]['refs'] = $xrefs;
91
}
92
93
$results[] = array(
94
'data' => $datapoints,
95
);
96
}
97
98
return id(new PhabricatorChartDisplayData())
99
->setWireData($results);
100
}
101
102
}
103
104