@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add chart functions "x()" and "constant(3)"

Summary:
Depends on D20442. Ref T13279. Add basic support for drawing chart functions that are not based on Facts first-party ETL datasets. Some general goals:

- This might be useful to draw a line like "goal" or "profitability".
- This might be useful to pull data from an external source.
- For composable functions like "add" or "subtract", which are useful in manipulating ETL datasets, these value functions will make testing easier.

Test Plan:
Added a `constant(256)` function:

{F6382408}

Reviewers: amckinley

Reviewed By: amckinley

Subscribers: yelirekim

Maniphest Tasks: T13279

Differential Revision: https://secure.phabricator.com/D20443

+155 -3
+4
src/__phutil_library_map__.php
··· 2802 2802 'PhabricatorConpherenceWidgetVisibleSetting' => 'applications/settings/setting/PhabricatorConpherenceWidgetVisibleSetting.php', 2803 2803 'PhabricatorConsoleApplication' => 'applications/console/application/PhabricatorConsoleApplication.php', 2804 2804 'PhabricatorConsoleContentSource' => 'infrastructure/contentsource/PhabricatorConsoleContentSource.php', 2805 + 'PhabricatorConstantChartFunction' => 'applications/fact/chart/PhabricatorConstantChartFunction.php', 2805 2806 'PhabricatorContactNumbersSettingsPanel' => 'applications/settings/panel/PhabricatorContactNumbersSettingsPanel.php', 2806 2807 'PhabricatorContentSource' => 'infrastructure/contentsource/PhabricatorContentSource.php', 2807 2808 'PhabricatorContentSourceModule' => 'infrastructure/contentsource/PhabricatorContentSourceModule.php', ··· 4935 4936 'PhabricatorWorkingCopyDiscoveryTestCase' => 'applications/repository/engine/__tests__/PhabricatorWorkingCopyDiscoveryTestCase.php', 4936 4937 'PhabricatorWorkingCopyPullTestCase' => 'applications/repository/engine/__tests__/PhabricatorWorkingCopyPullTestCase.php', 4937 4938 'PhabricatorWorkingCopyTestCase' => 'applications/repository/engine/__tests__/PhabricatorWorkingCopyTestCase.php', 4939 + 'PhabricatorXChartFunction' => 'applications/fact/chart/PhabricatorXChartFunction.php', 4938 4940 'PhabricatorXHPASTDAO' => 'applications/phpast/storage/PhabricatorXHPASTDAO.php', 4939 4941 'PhabricatorXHPASTParseTree' => 'applications/phpast/storage/PhabricatorXHPASTParseTree.php', 4940 4942 'PhabricatorXHPASTViewController' => 'applications/phpast/controller/PhabricatorXHPASTViewController.php', ··· 8790 8792 'PhabricatorConpherenceWidgetVisibleSetting' => 'PhabricatorInternalSetting', 8791 8793 'PhabricatorConsoleApplication' => 'PhabricatorApplication', 8792 8794 'PhabricatorConsoleContentSource' => 'PhabricatorContentSource', 8795 + 'PhabricatorConstantChartFunction' => 'PhabricatorChartFunction', 8793 8796 'PhabricatorContactNumbersSettingsPanel' => 'PhabricatorSettingsPanel', 8794 8797 'PhabricatorContentSource' => 'Phobject', 8795 8798 'PhabricatorContentSourceModule' => 'PhabricatorConfigModule', ··· 11288 11291 'PhabricatorWorkingCopyDiscoveryTestCase' => 'PhabricatorWorkingCopyTestCase', 11289 11292 'PhabricatorWorkingCopyPullTestCase' => 'PhabricatorWorkingCopyTestCase', 11290 11293 'PhabricatorWorkingCopyTestCase' => 'PhabricatorTestCase', 11294 + 'PhabricatorXChartFunction' => 'PhabricatorChartFunction', 11291 11295 'PhabricatorXHPASTDAO' => 'PhabricatorLiskDAO', 11292 11296 'PhabricatorXHPASTParseTree' => 'PhabricatorXHPASTDAO', 11293 11297 'PhabricatorXHPASTViewController' => 'PhabricatorController',
+53
src/applications/fact/chart/PhabricatorChartFunction.php
··· 25 25 26 26 abstract protected function newArguments(array $arguments); 27 27 28 + public function loadData() { 29 + return; 30 + } 31 + 28 32 final public function setXAxis(PhabricatorChartAxis $x_axis) { 29 33 $this->xAxis = $x_axis; 30 34 return $this; ··· 41 45 42 46 final public function getYAxis() { 43 47 return $this->yAxis; 48 + } 49 + 50 + protected function newLinearSteps($src, $dst, $count) { 51 + $count = (int)$count; 52 + $src = (int)$src; 53 + $dst = (int)$dst; 54 + 55 + if ($count === 0) { 56 + throw new Exception( 57 + pht('Can not generate zero linear steps between two values!')); 58 + } 59 + 60 + if ($src === $dst) { 61 + return array($src); 62 + } 63 + 64 + if ($count === 1) { 65 + return array($src); 66 + } 67 + 68 + $is_reversed = ($src > $dst); 69 + if ($is_reversed) { 70 + $min = (double)$dst; 71 + $max = (double)$src; 72 + } else { 73 + $min = (double)$src; 74 + $max = (double)$dst; 75 + } 76 + 77 + $step = (double)($max - $min) / (double)($count - 1); 78 + 79 + $steps = array(); 80 + for ($cursor = $min; $cursor <= $max; $cursor += $step) { 81 + $x = (int)round($cursor); 82 + 83 + if (isset($steps[$x])) { 84 + continue; 85 + } 86 + 87 + $steps[$x] = $x; 88 + } 89 + 90 + $steps = array_values($steps); 91 + 92 + if ($is_reversed) { 93 + $steps = array_reverse($steps); 94 + } 95 + 96 + return $steps; 44 97 } 45 98 46 99 }
+51
src/applications/fact/chart/PhabricatorConstantChartFunction.php
··· 1 + <?php 2 + 3 + final class PhabricatorConstantChartFunction 4 + extends PhabricatorChartFunction { 5 + 6 + const FUNCTIONKEY = 'constant'; 7 + 8 + private $value; 9 + 10 + protected function newArguments(array $arguments) { 11 + if (count($arguments) !== 1) { 12 + throw new Exception( 13 + pht( 14 + 'Chart function "constant(...)" expects one argument, got %s. '. 15 + 'Pass a constant.', 16 + count($arguments))); 17 + } 18 + 19 + if (!is_int($arguments[0])) { 20 + throw new Exception( 21 + pht( 22 + 'First argument for "fact(...)" is invalid: expected int, '. 23 + 'got %s.', 24 + phutil_describe_type($arguments[0]))); 25 + } 26 + 27 + $this->value = $arguments[0]; 28 + } 29 + 30 + public function getDatapoints($limit) { 31 + $axis = $this->getXAxis(); 32 + $x_min = $axis->getMinimumValue(); 33 + $x_max = $axis->getMaximumValue(); 34 + 35 + $points = array(); 36 + $steps = $this->newLinearSteps($x_min, $x_max, 2); 37 + foreach ($steps as $step) { 38 + $points[] = array( 39 + 'x' => $step, 40 + 'y' => $this->value, 41 + ); 42 + } 43 + 44 + return $points; 45 + } 46 + 47 + public function hasDomain() { 48 + return false; 49 + } 50 + 51 + }
+38
src/applications/fact/chart/PhabricatorXChartFunction.php
··· 1 + <?php 2 + 3 + final class PhabricatorXChartFunction 4 + extends PhabricatorChartFunction { 5 + 6 + const FUNCTIONKEY = 'x'; 7 + 8 + protected function newArguments(array $arguments) { 9 + if (count($arguments) !== 0) { 10 + throw new Exception( 11 + pht( 12 + 'Chart function "x()" expects zero arguments, got %s.', 13 + count($arguments))); 14 + } 15 + } 16 + 17 + public function getDatapoints($limit) { 18 + $axis = $this->getXAxis(); 19 + $x_min = $axis->getMinimumValue(); 20 + $x_max = $axis->getMaximumValue(); 21 + 22 + $points = array(); 23 + $steps = $this->newLinearSteps($x_min, $x_max, $limit); 24 + foreach ($steps as $step) { 25 + $points[] = array( 26 + 'x' => $step, 27 + 'y' => $step, 28 + ); 29 + } 30 + 31 + return $points; 32 + } 33 + 34 + public function hasDomain() { 35 + return false; 36 + } 37 + 38 + }
+9 -3
src/applications/fact/controller/PhabricatorFactChartController.php
··· 20 20 $functions[] = id(new PhabricatorFactChartFunction()) 21 21 ->setArguments(array('tasks.open-count.create')); 22 22 23 - if ($is_chart_mode) { 24 - return $this->newChartResponse(); 25 - } 23 + $functions[] = id(new PhabricatorConstantChartFunction()) 24 + ->setArguments(array(256)); 25 + 26 + $functions[] = id(new PhabricatorXChartFunction()) 27 + ->setArguments(array()); 26 28 27 29 list($domain_min, $domain_max) = $this->getDomain($functions); 28 30 ··· 72 74 'yMin' => $y_min, 73 75 'yMax' => $y_max, 74 76 ); 77 + 78 + if ($is_chart_mode) { 79 + return $this->newChartResponse(); 80 + } 75 81 76 82 return id(new AphrontAjaxResponse())->setContent($chart_data); 77 83 }