Changeset View
Changeset View
Standalone View
Standalone View
src/applications/fact/chart/PhabricatorChartFunction.php
<?php | <?php | ||||
abstract class PhabricatorChartFunction | abstract class PhabricatorChartFunction | ||||
extends Phobject { | extends Phobject { | ||||
private $xAxis; | |||||
private $yAxis; | |||||
epriestley: The axis stuff will come back at some point, it just isn't used right now. | |||||
private $argumentParser; | private $argumentParser; | ||||
private $sourceFunction; | |||||
final public function getFunctionKey() { | final public function getFunctionKey() { | ||||
return $this->getPhobjectClassConstant('FUNCTIONKEY', 32); | return $this->getPhobjectClassConstant('FUNCTIONKEY', 32); | ||||
} | } | ||||
final public static function getAllFunctions() { | final public static function getAllFunctions() { | ||||
return id(new PhutilClassMapQuery()) | return id(new PhutilClassMapQuery()) | ||||
->setAncestorClass(__CLASS__) | ->setAncestorClass(__CLASS__) | ||||
Show All 20 Lines | final public function setArguments(array $arguments) { | ||||
foreach ($specs as $spec) { | foreach ($specs as $spec) { | ||||
$parser->addArgument($spec); | $parser->addArgument($spec); | ||||
} | } | ||||
$parser->setHaveAllArguments(true); | $parser->setHaveAllArguments(true); | ||||
$parser->parseArguments(); | $parser->parseArguments(); | ||||
$source_argument = $parser->getSourceFunctionArgument(); | |||||
if ($source_argument) { | |||||
$source_function = $this->getArgument($source_argument->getName()); | |||||
$this->setSourceFunction($source_function); | |||||
} | |||||
return $this; | return $this; | ||||
} | } | ||||
abstract protected function newArguments(); | public function getSubfunctions() { | ||||
$result = array(); | |||||
$result[] = $this; | |||||
final protected function newArgument() { | foreach ($this->getFunctionArguments() as $argument) { | ||||
return new PhabricatorChartFunctionArgument(); | foreach ($argument->getSubfunctions() as $subfunction) { | ||||
$result[] = $subfunction; | |||||
} | |||||
} | } | ||||
final protected function getArgument($key) { | return $result; | ||||
return $this->getArgumentParser()->getArgumentValue($key); | |||||
} | } | ||||
final protected function getArgumentParser() { | public function getFunctionArguments() { | ||||
if (!$this->argumentParser) { | $results = array(); | ||||
$parser = id(new PhabricatorChartFunctionArgumentParser()) | |||||
->setFunction($this); | |||||
$this->argumentParser = $parser; | $parser = $this->getArgumentParser(); | ||||
} | foreach ($parser->getAllArguments() as $argument) { | ||||
return $this->argumentParser; | if ($argument->getType() !== 'function') { | ||||
continue; | |||||
} | } | ||||
public function loadData() { | $name = $argument->getName(); | ||||
return; | $value = $this->getArgument($name); | ||||
} | |||||
protected function setSourceFunction(PhabricatorChartFunction $source) { | if (!is_array($value)) { | ||||
$this->sourceFunction = $source; | $results[] = $value; | ||||
return $this; | } else { | ||||
foreach ($value as $arg_value) { | |||||
$results[] = $arg_value; | |||||
} | } | ||||
protected function getSourceFunction() { | |||||
return $this->sourceFunction; | |||||
} | } | ||||
final public function setXAxis(PhabricatorChartAxis $x_axis) { | |||||
$this->xAxis = $x_axis; | |||||
return $this; | |||||
} | } | ||||
final public function getXAxis() { | return $results; | ||||
return $this->xAxis; | |||||
} | } | ||||
final public function setYAxis(PhabricatorChartAxis $y_axis) { | public function newDatapoints(PhabricatorChartDataQuery $query) { | ||||
$this->yAxis = $y_axis; | $xv = $this->newInputValues($query); | ||||
return $this; | |||||
} | |||||
final public function getYAxis() { | if ($xv === null) { | ||||
return $this->yAxis; | $xv = $this->newDefaultInputValues($query); | ||||
} | } | ||||
protected function canEvaluateFunction() { | $xv = $query->selectInputValues($xv); | ||||
return false; | |||||
} | $n = count($xv); | ||||
$yv = $this->evaluateFunction($xv); | |||||
protected function evaluateFunction($x) { | $points = array(); | ||||
throw new PhutilMethodNotImplementedException(); | for ($ii = 0; $ii < $n; $ii++) { | ||||
$y = $yv[$ii]; | |||||
if ($y === null) { | |||||
continue; | |||||
} | } | ||||
public function hasDomain() { | $points[] = array( | ||||
if ($this->canEvaluateFunction()) { | 'x' => $xv[$ii], | ||||
return false; | 'y' => $y, | ||||
); | |||||
} | } | ||||
throw new PhutilMethodNotImplementedException(); | return $points; | ||||
} | } | ||||
public function getDatapoints(PhabricatorChartDataQuery $query) { | abstract protected function newArguments(); | ||||
if ($this->canEvaluateFunction()) { | |||||
$points = $this->newSourceDatapoints($query); | final protected function newArgument() { | ||||
foreach ($points as $key => $point) { | return new PhabricatorChartFunctionArgument(); | ||||
$y = $point['y']; | |||||
$y = $this->evaluateFunction($y); | |||||
$points[$key]['y'] = $y; | |||||
} | } | ||||
return $points; | final protected function getArgument($key) { | ||||
return $this->getArgumentParser()->getArgumentValue($key); | |||||
} | } | ||||
return $this->newDatapoints($query); | final protected function getArgumentParser() { | ||||
if (!$this->argumentParser) { | |||||
$parser = id(new PhabricatorChartFunctionArgumentParser()) | |||||
->setFunction($this); | |||||
$this->argumentParser = $parser; | |||||
} | |||||
return $this->argumentParser; | |||||
} | } | ||||
protected function newDatapoints(PhabricatorChartDataQuery $query) { | abstract public function evaluateFunction(array $xv); | ||||
throw new PhutilMethodNotImplementedException(); | |||||
public function getDomain() { | |||||
return null; | |||||
} | } | ||||
protected function newSourceDatapoints(PhabricatorChartDataQuery $query) { | public function newInputValues(PhabricatorChartDataQuery $query) { | ||||
$source = $this->getSourceFunction(); | return null; | ||||
if ($source) { | |||||
return $source->getDatapoints($query); | |||||
} | } | ||||
return $this->newDefaultDatapoints($query); | public function loadData() { | ||||
return; | |||||
} | } | ||||
protected function newDefaultDatapoints(PhabricatorChartDataQuery $query) { | protected function newDefaultInputValues(PhabricatorChartDataQuery $query) { | ||||
$x_min = $query->getMinimumValue(); | $x_min = $query->getMinimumValue(); | ||||
$x_max = $query->getMaximumValue(); | $x_max = $query->getMaximumValue(); | ||||
$limit = $query->getLimit(); | $limit = $query->getLimit(); | ||||
$points = array(); | return $this->newLinearSteps($x_min, $x_max, $limit); | ||||
$steps = $this->newLinearSteps($x_min, $x_max, $limit); | |||||
foreach ($steps as $step) { | |||||
$points[] = array( | |||||
'x' => $step, | |||||
'y' => $step, | |||||
); | |||||
} | |||||
return $points; | |||||
} | } | ||||
protected function newLinearSteps($src, $dst, $count) { | protected function newLinearSteps($src, $dst, $count) { | ||||
$count = (int)$count; | $count = (int)$count; | ||||
$src = (int)$src; | $src = (int)$src; | ||||
$dst = (int)$dst; | $dst = (int)$dst; | ||||
if ($count === 0) { | if ($count === 0) { | ||||
Show All 34 Lines | protected function newLinearSteps($src, $dst, $count) { | ||||
$steps = array_values($steps); | $steps = array_values($steps); | ||||
if ($is_reversed) { | if ($is_reversed) { | ||||
$steps = array_reverse($steps); | $steps = array_reverse($steps); | ||||
} | } | ||||
return $steps; | return $steps; | ||||
} | } | ||||
} | } |
The axis stuff will come back at some point, it just isn't used right now.