Changeset View
Changeset View
Standalone View
Standalone View
src/applications/fact/chart/PhabricatorAccumulateChartFunction.php
- This file was added.
<?php | |||||
final class PhabricatorAccumulateChartFunction | |||||
extends PhabricatorChartFunction { | |||||
const FUNCTIONKEY = 'accumulate'; | |||||
protected function newArguments() { | |||||
return array( | |||||
$this->newArgument() | |||||
->setName('x') | |||||
->setType('function') | |||||
->setFunctionType('impulse') | |||||
->setIsSourceFunction(true), | |||||
); | |||||
} | |||||
protected function newDatapoints(PhabricatorChartDataQuery $query) { | |||||
$source_function = $this->getSourceFunction(); | |||||
// Use an unconstrained query to pull all the data from the underlying | |||||
// source. We need to accumulate data since the beginning of time to | |||||
// figure out the right Y-intercept -- otherwise, we'll always start at | |||||
// "0" wherever our domain begins. | |||||
$empty_query = new PhabricatorChartDataQuery(); | |||||
$points = $source_function->getDatapoints($empty_query); | |||||
$accumulator = 0; | |||||
foreach ($points as $key => $point) { | |||||
$accumulator += $point['y']; | |||||
$points[$key]['y'] = $accumulator; | |||||
} | |||||
return $query->selectDatapoints($points); | |||||
} | |||||
} |