Changeset View
Changeset View
Standalone View
Standalone View
src/applications/fact/chart/PhabricatorSinChartFunction.php
<?php | <?php | ||||
final class PhabricatorSinChartFunction | final class PhabricatorSinChartFunction | ||||
extends PhabricatorChartFunction { | extends PhabricatorChartFunction { | ||||
const FUNCTIONKEY = 'sin'; | const FUNCTIONKEY = 'sin'; | ||||
private $argument; | protected function newArguments() { | ||||
return array( | |||||
protected function newArguments(array $arguments) { | $this->newArgument() | ||||
if (count($arguments) !== 1) { | ->setName('x') | ||||
throw new Exception( | ->setType('function'), | ||||
pht( | ); | ||||
'Chart function "sin(..)" expects one argument, got %s.', | |||||
count($arguments))); | |||||
} | |||||
$argument = $arguments[0]; | |||||
if (!($argument instanceof PhabricatorChartFunction)) { | |||||
throw new Exception( | |||||
pht( | |||||
'Argument to chart function should be a function, got %s.', | |||||
phutil_describe_type($argument))); | |||||
} | } | ||||
$this->argument = $argument; | protected function assignArguments(array $arguments) { | ||||
$this->argument = $arguments[0]; | |||||
} | } | ||||
public function getDatapoints(PhabricatorChartDataQuery $query) { | public function getDatapoints(PhabricatorChartDataQuery $query) { | ||||
$points = $this->argument->getDatapoints($query); | $points = $this->getArgument('x')->getDatapoints($query); | ||||
foreach ($points as $key => $point) { | foreach ($points as $key => $point) { | ||||
$points[$key]['y'] = sin(deg2rad($points[$key]['y'])); | $points[$key]['y'] = sin(deg2rad($points[$key]['y'])); | ||||
} | } | ||||
return $points; | return $points; | ||||
} | } | ||||
public function hasDomain() { | public function hasDomain() { | ||||
return false; | return false; | ||||
} | } | ||||
} | } |