Changeset View
Changeset View
Standalone View
Standalone View
src/applications/fact/chart/PhabricatorConstantChartFunction.php
<?php | <?php | ||||
final class PhabricatorConstantChartFunction | final class PhabricatorConstantChartFunction | ||||
extends PhabricatorChartFunction { | extends PhabricatorChartFunction { | ||||
const FUNCTIONKEY = 'constant'; | const FUNCTIONKEY = 'constant'; | ||||
private $value; | private $value; | ||||
protected function newArguments(array $arguments) { | protected function newArguments() { | ||||
if (count($arguments) !== 1) { | return array( | ||||
throw new Exception( | $this->newArgument() | ||||
pht( | ->setName('n') | ||||
'Chart function "constant(...)" expects one argument, got %s. '. | ->setType('number'), | ||||
'Pass a constant.', | ); | ||||
count($arguments))); | |||||
} | |||||
if (!is_int($arguments[0])) { | |||||
throw new Exception( | |||||
pht( | |||||
'First argument for "fact(...)" is invalid: expected int, '. | |||||
'got %s.', | |||||
phutil_describe_type($arguments[0]))); | |||||
} | |||||
$this->value = $arguments[0]; | |||||
} | } | ||||
public function getDatapoints(PhabricatorChartDataQuery $query) { | public function getDatapoints(PhabricatorChartDataQuery $query) { | ||||
$x_min = $query->getMinimumValue(); | $x_min = $query->getMinimumValue(); | ||||
$x_max = $query->getMaximumValue(); | $x_max = $query->getMaximumValue(); | ||||
$value = $this->getArgument('n'); | |||||
$points = array(); | $points = array(); | ||||
$steps = $this->newLinearSteps($x_min, $x_max, 2); | $steps = $this->newLinearSteps($x_min, $x_max, 2); | ||||
foreach ($steps as $step) { | foreach ($steps as $step) { | ||||
$points[] = array( | $points[] = array( | ||||
'x' => $step, | 'x' => $step, | ||||
'y' => $this->value, | 'y' => $value, | ||||
); | ); | ||||
} | } | ||||
return $points; | return $points; | ||||
} | } | ||||
public function hasDomain() { | public function hasDomain() { | ||||
return false; | return false; | ||||
} | } | ||||
} | } |