@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 a "sin()" function to charts

Summary:
Depends on D20443. Ref T13279. This is probably not terribly useful on its own, but is mostly a function which takes another function as an argument, and a step toward more useful functions like arithmetic and drawing a picture of an owl.

The only structural change here is that functions now read data parameters (domain, sample limit) using a more tailored "ChartDataQuery" instead of reading the actual axis. Mostly, I want a more cohesive representation of query state that can be easily passed to sub-functions, as here.

Test Plan: {F6382432}

Reviewers: amckinley

Reviewed By: amckinley

Subscribers: yelirekim

Maniphest Tasks: T13279

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

+116 -25
+4
src/__phutil_library_map__.php
··· 2650 2650 'PhabricatorChangesetCachePurger' => 'applications/cache/purger/PhabricatorChangesetCachePurger.php', 2651 2651 'PhabricatorChangesetResponse' => 'infrastructure/diff/PhabricatorChangesetResponse.php', 2652 2652 'PhabricatorChartAxis' => 'applications/fact/chart/PhabricatorChartAxis.php', 2653 + 'PhabricatorChartDataQuery' => 'applications/fact/chart/PhabricatorChartDataQuery.php', 2653 2654 'PhabricatorChartFunction' => 'applications/fact/chart/PhabricatorChartFunction.php', 2654 2655 'PhabricatorChatLogApplication' => 'applications/chatlog/application/PhabricatorChatLogApplication.php', 2655 2656 'PhabricatorChatLogChannel' => 'applications/chatlog/storage/PhabricatorChatLogChannel.php', ··· 4564 4565 'PhabricatorShortSite' => 'aphront/site/PhabricatorShortSite.php', 4565 4566 'PhabricatorShowFiletreeSetting' => 'applications/settings/setting/PhabricatorShowFiletreeSetting.php', 4566 4567 'PhabricatorSimpleEditType' => 'applications/transactions/edittype/PhabricatorSimpleEditType.php', 4568 + 'PhabricatorSinChartFunction' => 'applications/fact/chart/PhabricatorSinChartFunction.php', 4567 4569 'PhabricatorSite' => 'aphront/site/PhabricatorSite.php', 4568 4570 'PhabricatorSlackAuthProvider' => 'applications/auth/provider/PhabricatorSlackAuthProvider.php', 4569 4571 'PhabricatorSlowvoteApplication' => 'applications/slowvote/application/PhabricatorSlowvoteApplication.php', ··· 8625 8627 'PhabricatorChangesetCachePurger' => 'PhabricatorCachePurger', 8626 8628 'PhabricatorChangesetResponse' => 'AphrontProxyResponse', 8627 8629 'PhabricatorChartAxis' => 'Phobject', 8630 + 'PhabricatorChartDataQuery' => 'Phobject', 8628 8631 'PhabricatorChartFunction' => 'Phobject', 8629 8632 'PhabricatorChatLogApplication' => 'PhabricatorApplication', 8630 8633 'PhabricatorChatLogChannel' => array( ··· 10860 10863 'PhabricatorShortSite' => 'PhabricatorSite', 10861 10864 'PhabricatorShowFiletreeSetting' => 'PhabricatorSelectSetting', 10862 10865 'PhabricatorSimpleEditType' => 'PhabricatorEditType', 10866 + 'PhabricatorSinChartFunction' => 'PhabricatorChartFunction', 10863 10867 'PhabricatorSite' => 'AphrontSite', 10864 10868 'PhabricatorSlackAuthProvider' => 'PhabricatorOAuth2AuthProvider', 10865 10869 'PhabricatorSlowvoteApplication' => 'PhabricatorApplication',
+37
src/applications/fact/chart/PhabricatorChartDataQuery.php
··· 1 + <?php 2 + 3 + final class PhabricatorChartDataQuery 4 + extends Phobject { 5 + 6 + private $limit; 7 + private $minimumValue; 8 + private $maximumValue; 9 + 10 + public function setMinimumValue($minimum_value) { 11 + $this->minimumValue = $minimum_value; 12 + return $this; 13 + } 14 + 15 + public function getMinimumValue() { 16 + return $this->minimumValue; 17 + } 18 + 19 + public function setMaximumValue($maximum_value) { 20 + $this->maximumValue = $maximum_value; 21 + return $this; 22 + } 23 + 24 + public function getMaximumValue() { 25 + return $this->maximumValue; 26 + } 27 + 28 + public function setLimit($limit) { 29 + $this->limit = $limit; 30 + return $this; 31 + } 32 + 33 + public function getLimit() { 34 + return $this->limit; 35 + } 36 + 37 + }
+3 -4
src/applications/fact/chart/PhabricatorConstantChartFunction.php
··· 27 27 $this->value = $arguments[0]; 28 28 } 29 29 30 - public function getDatapoints($limit) { 31 - $axis = $this->getXAxis(); 32 - $x_min = $axis->getMinimumValue(); 33 - $x_max = $axis->getMaximumValue(); 30 + public function getDatapoints(PhabricatorChartDataQuery $query) { 31 + $x_min = $query->getMinimumValue(); 32 + $x_max = $query->getMaximumValue(); 34 33 35 34 $points = array(); 36 35 $steps = $this->newLinearSteps($x_min, $x_max, 2);
+14 -12
src/applications/fact/chart/PhabricatorFactChartFunction.php
··· 77 77 $this->datapoints = $points; 78 78 } 79 79 80 - public function getDatapoints($limit) { 80 + public function getDatapoints(PhabricatorChartDataQuery $query) { 81 81 $points = $this->datapoints; 82 82 if (!$points) { 83 83 return array(); 84 84 } 85 85 86 - $axis = $this->getXAxis(); 87 - $x_min = $axis->getMinimumValue(); 88 - $x_max = $axis->getMaximumValue(); 86 + $x_min = $query->getMinimumValue(); 87 + $x_max = $query->getMaximumValue(); 88 + $limit = $query->getLimit(); 89 89 90 90 if ($x_min !== null) { 91 91 foreach ($points as $key => $point) { ··· 104 104 } 105 105 106 106 // If we have too many data points, throw away some of the data. 107 - $count = count($points); 108 - if ($count > $limit) { 109 - $ii = 0; 110 - $every = ceil($count / $limit); 111 - foreach ($points as $key => $point) { 112 - $ii++; 113 - if (($ii % $every) && ($ii != $count)) { 114 - unset($points[$key]); 107 + if ($limit !== null) { 108 + $count = count($points); 109 + if ($count > $limit) { 110 + $ii = 0; 111 + $every = ceil($count / $limit); 112 + foreach ($points as $key => $point) { 113 + $ii++; 114 + if (($ii % $every) && ($ii != $count)) { 115 + unset($points[$key]); 116 + } 115 117 } 116 118 } 117 119 }
+44
src/applications/fact/chart/PhabricatorSinChartFunction.php
··· 1 + <?php 2 + 3 + final class PhabricatorSinChartFunction 4 + extends PhabricatorChartFunction { 5 + 6 + const FUNCTIONKEY = 'sin'; 7 + 8 + private $argument; 9 + 10 + protected function newArguments(array $arguments) { 11 + if (count($arguments) !== 1) { 12 + throw new Exception( 13 + pht( 14 + 'Chart function "sin(..)" expects one argument, got %s.', 15 + count($arguments))); 16 + } 17 + 18 + $argument = $arguments[0]; 19 + 20 + if (!($argument instanceof PhabricatorChartFunction)) { 21 + throw new Exception( 22 + pht( 23 + 'Argument to chart function should be a function, got %s.', 24 + phutil_describe_type($argument))); 25 + } 26 + 27 + $this->argument = $argument; 28 + } 29 + 30 + public function getDatapoints(PhabricatorChartDataQuery $query) { 31 + $points = $this->argument->getDatapoints($query); 32 + 33 + foreach ($points as $key => $point) { 34 + $points[$key]['y'] = sin(deg2rad($points[$key]['y'])); 35 + } 36 + 37 + return $points; 38 + } 39 + 40 + public function hasDomain() { 41 + return false; 42 + } 43 + 44 + }
+4 -4
src/applications/fact/chart/PhabricatorXChartFunction.php
··· 14 14 } 15 15 } 16 16 17 - public function getDatapoints($limit) { 18 - $axis = $this->getXAxis(); 19 - $x_min = $axis->getMinimumValue(); 20 - $x_max = $axis->getMaximumValue(); 17 + public function getDatapoints(PhabricatorChartDataQuery $query) { 18 + $x_min = $query->getMinimumValue(); 19 + $x_max = $query->getMaximumValue(); 20 + $limit = $query->getLimit(); 21 21 22 22 $points = array(); 23 23 $steps = $this->newLinearSteps($x_min, $x_max, $limit);
+10 -5
src/applications/fact/controller/PhabricatorFactChartController.php
··· 20 20 $functions[] = id(new PhabricatorFactChartFunction()) 21 21 ->setArguments(array('tasks.open-count.create')); 22 22 23 - $functions[] = id(new PhabricatorConstantChartFunction()) 24 - ->setArguments(array(256)); 25 - 26 - $functions[] = id(new PhabricatorXChartFunction()) 23 + $x_function = id(new PhabricatorXChartFunction()) 27 24 ->setArguments(array()); 25 + 26 + $functions[] = id(new PhabricatorSinChartFunction()) 27 + ->setArguments(array($x_function)); 28 28 29 29 list($domain_min, $domain_max) = $this->getDomain($functions); 30 30 ··· 32 32 ->setMinimumValue($domain_min) 33 33 ->setMaximumValue($domain_max); 34 34 35 + $data_query = id(new PhabricatorChartDataQuery()) 36 + ->setMinimumValue($domain_min) 37 + ->setMaximumValue($domain_max) 38 + ->setLimit(2000); 39 + 35 40 $datasets = array(); 36 41 foreach ($functions as $function) { 37 42 $function->setXAxis($axis); 38 43 39 44 $function->loadData(); 40 45 41 - $points = $function->getDatapoints(2000); 46 + $points = $function->getDatapoints($data_query); 42 47 43 48 $x = array(); 44 49 $y = array();