Path: blob/master/src/applications/fact/chart/PhabricatorChartDataset.php
12256 views
<?php12abstract class PhabricatorChartDataset3extends Phobject {45private $functions;67final public function getDatasetTypeKey() {8return $this->getPhobjectClassConstant('DATASETKEY', 32);9}1011final public function getFunctions() {12return $this->functions;13}1415final public function setFunctions(array $functions) {16assert_instances_of($functions, 'PhabricatorComposeChartFunction');1718$this->functions = $functions;1920return $this;21}2223final public static function getAllDatasetTypes() {24return id(new PhutilClassMapQuery())25->setAncestorClass(__CLASS__)26->setUniqueMethod('getDatasetTypeKey')27->execute();28}2930final public static function newFromDictionary(array $map) {31PhutilTypeSpec::checkMap(32$map,33array(34'type' => 'string',35'functions' => 'list<wild>',36));3738$types = self::getAllDatasetTypes();3940$dataset_type = $map['type'];41if (!isset($types[$dataset_type])) {42throw new Exception(43pht(44'Trying to construct a dataset of type "%s", but this type is '.45'unknown. Supported types are: %s.',46$dataset_type,47implode(', ', array_keys($types))));48}4950$dataset = id(clone $types[$dataset_type]);5152$functions = array();53foreach ($map['functions'] as $map) {54$functions[] = PhabricatorChartFunction::newFromDictionary($map);55}56$dataset->setFunctions($functions);5758return $dataset;59}6061final public function getChartDisplayData(62PhabricatorChartDataQuery $data_query) {63return $this->newChartDisplayData($data_query);64}6566abstract protected function newChartDisplayData(67PhabricatorChartDataQuery $data_query);686970final public function getTabularDisplayData(71PhabricatorChartDataQuery $data_query) {72$results = array();7374$functions = $this->getFunctions();75foreach ($functions as $function) {76$datapoints = $function->newDatapoints($data_query);7778$refs = $function->getDataRefs(ipull($datapoints, 'x'));7980foreach ($datapoints as $key => $point) {81$x = $point['x'];8283if (isset($refs[$x])) {84$xrefs = $refs[$x];85} else {86$xrefs = array();87}8889$datapoints[$key]['refs'] = $xrefs;90}9192$results[] = array(93'data' => $datapoints,94);95}9697return id(new PhabricatorChartDisplayData())98->setWireData($results);99}100101}102103104