Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14118182
D20444.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
8 KB
Referenced Files
None
Subscribers
None
D20444.diff
View Options
diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -2650,6 +2650,7 @@
'PhabricatorChangesetCachePurger' => 'applications/cache/purger/PhabricatorChangesetCachePurger.php',
'PhabricatorChangesetResponse' => 'infrastructure/diff/PhabricatorChangesetResponse.php',
'PhabricatorChartAxis' => 'applications/fact/chart/PhabricatorChartAxis.php',
+ 'PhabricatorChartDataQuery' => 'applications/fact/chart/PhabricatorChartDataQuery.php',
'PhabricatorChartFunction' => 'applications/fact/chart/PhabricatorChartFunction.php',
'PhabricatorChatLogApplication' => 'applications/chatlog/application/PhabricatorChatLogApplication.php',
'PhabricatorChatLogChannel' => 'applications/chatlog/storage/PhabricatorChatLogChannel.php',
@@ -4564,6 +4565,7 @@
'PhabricatorShortSite' => 'aphront/site/PhabricatorShortSite.php',
'PhabricatorShowFiletreeSetting' => 'applications/settings/setting/PhabricatorShowFiletreeSetting.php',
'PhabricatorSimpleEditType' => 'applications/transactions/edittype/PhabricatorSimpleEditType.php',
+ 'PhabricatorSinChartFunction' => 'applications/fact/chart/PhabricatorSinChartFunction.php',
'PhabricatorSite' => 'aphront/site/PhabricatorSite.php',
'PhabricatorSlackAuthProvider' => 'applications/auth/provider/PhabricatorSlackAuthProvider.php',
'PhabricatorSlowvoteApplication' => 'applications/slowvote/application/PhabricatorSlowvoteApplication.php',
@@ -8625,6 +8627,7 @@
'PhabricatorChangesetCachePurger' => 'PhabricatorCachePurger',
'PhabricatorChangesetResponse' => 'AphrontProxyResponse',
'PhabricatorChartAxis' => 'Phobject',
+ 'PhabricatorChartDataQuery' => 'Phobject',
'PhabricatorChartFunction' => 'Phobject',
'PhabricatorChatLogApplication' => 'PhabricatorApplication',
'PhabricatorChatLogChannel' => array(
@@ -10860,6 +10863,7 @@
'PhabricatorShortSite' => 'PhabricatorSite',
'PhabricatorShowFiletreeSetting' => 'PhabricatorSelectSetting',
'PhabricatorSimpleEditType' => 'PhabricatorEditType',
+ 'PhabricatorSinChartFunction' => 'PhabricatorChartFunction',
'PhabricatorSite' => 'AphrontSite',
'PhabricatorSlackAuthProvider' => 'PhabricatorOAuth2AuthProvider',
'PhabricatorSlowvoteApplication' => 'PhabricatorApplication',
diff --git a/src/applications/fact/chart/PhabricatorChartDataQuery.php b/src/applications/fact/chart/PhabricatorChartDataQuery.php
new file mode 100644
--- /dev/null
+++ b/src/applications/fact/chart/PhabricatorChartDataQuery.php
@@ -0,0 +1,37 @@
+<?php
+
+final class PhabricatorChartDataQuery
+ extends Phobject {
+
+ private $limit;
+ private $minimumValue;
+ private $maximumValue;
+
+ public function setMinimumValue($minimum_value) {
+ $this->minimumValue = $minimum_value;
+ return $this;
+ }
+
+ public function getMinimumValue() {
+ return $this->minimumValue;
+ }
+
+ public function setMaximumValue($maximum_value) {
+ $this->maximumValue = $maximum_value;
+ return $this;
+ }
+
+ public function getMaximumValue() {
+ return $this->maximumValue;
+ }
+
+ public function setLimit($limit) {
+ $this->limit = $limit;
+ return $this;
+ }
+
+ public function getLimit() {
+ return $this->limit;
+ }
+
+}
diff --git a/src/applications/fact/chart/PhabricatorConstantChartFunction.php b/src/applications/fact/chart/PhabricatorConstantChartFunction.php
--- a/src/applications/fact/chart/PhabricatorConstantChartFunction.php
+++ b/src/applications/fact/chart/PhabricatorConstantChartFunction.php
@@ -27,10 +27,9 @@
$this->value = $arguments[0];
}
- public function getDatapoints($limit) {
- $axis = $this->getXAxis();
- $x_min = $axis->getMinimumValue();
- $x_max = $axis->getMaximumValue();
+ public function getDatapoints(PhabricatorChartDataQuery $query) {
+ $x_min = $query->getMinimumValue();
+ $x_max = $query->getMaximumValue();
$points = array();
$steps = $this->newLinearSteps($x_min, $x_max, 2);
diff --git a/src/applications/fact/chart/PhabricatorFactChartFunction.php b/src/applications/fact/chart/PhabricatorFactChartFunction.php
--- a/src/applications/fact/chart/PhabricatorFactChartFunction.php
+++ b/src/applications/fact/chart/PhabricatorFactChartFunction.php
@@ -77,15 +77,15 @@
$this->datapoints = $points;
}
- public function getDatapoints($limit) {
+ public function getDatapoints(PhabricatorChartDataQuery $query) {
$points = $this->datapoints;
if (!$points) {
return array();
}
- $axis = $this->getXAxis();
- $x_min = $axis->getMinimumValue();
- $x_max = $axis->getMaximumValue();
+ $x_min = $query->getMinimumValue();
+ $x_max = $query->getMaximumValue();
+ $limit = $query->getLimit();
if ($x_min !== null) {
foreach ($points as $key => $point) {
@@ -104,14 +104,16 @@
}
// If we have too many data points, throw away some of the data.
- $count = count($points);
- if ($count > $limit) {
- $ii = 0;
- $every = ceil($count / $limit);
- foreach ($points as $key => $point) {
- $ii++;
- if (($ii % $every) && ($ii != $count)) {
- unset($points[$key]);
+ if ($limit !== null) {
+ $count = count($points);
+ if ($count > $limit) {
+ $ii = 0;
+ $every = ceil($count / $limit);
+ foreach ($points as $key => $point) {
+ $ii++;
+ if (($ii % $every) && ($ii != $count)) {
+ unset($points[$key]);
+ }
}
}
}
diff --git a/src/applications/fact/chart/PhabricatorSinChartFunction.php b/src/applications/fact/chart/PhabricatorSinChartFunction.php
new file mode 100644
--- /dev/null
+++ b/src/applications/fact/chart/PhabricatorSinChartFunction.php
@@ -0,0 +1,44 @@
+<?php
+
+final class PhabricatorSinChartFunction
+ extends PhabricatorChartFunction {
+
+ const FUNCTIONKEY = 'sin';
+
+ private $argument;
+
+ protected function newArguments(array $arguments) {
+ if (count($arguments) !== 1) {
+ throw new Exception(
+ 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;
+ }
+
+ public function getDatapoints(PhabricatorChartDataQuery $query) {
+ $points = $this->argument->getDatapoints($query);
+
+ foreach ($points as $key => $point) {
+ $points[$key]['y'] = sin(deg2rad($points[$key]['y']));
+ }
+
+ return $points;
+ }
+
+ public function hasDomain() {
+ return false;
+ }
+
+}
diff --git a/src/applications/fact/chart/PhabricatorXChartFunction.php b/src/applications/fact/chart/PhabricatorXChartFunction.php
--- a/src/applications/fact/chart/PhabricatorXChartFunction.php
+++ b/src/applications/fact/chart/PhabricatorXChartFunction.php
@@ -14,10 +14,10 @@
}
}
- public function getDatapoints($limit) {
- $axis = $this->getXAxis();
- $x_min = $axis->getMinimumValue();
- $x_max = $axis->getMaximumValue();
+ public function getDatapoints(PhabricatorChartDataQuery $query) {
+ $x_min = $query->getMinimumValue();
+ $x_max = $query->getMaximumValue();
+ $limit = $query->getLimit();
$points = array();
$steps = $this->newLinearSteps($x_min, $x_max, $limit);
diff --git a/src/applications/fact/controller/PhabricatorFactChartController.php b/src/applications/fact/controller/PhabricatorFactChartController.php
--- a/src/applications/fact/controller/PhabricatorFactChartController.php
+++ b/src/applications/fact/controller/PhabricatorFactChartController.php
@@ -20,25 +20,30 @@
$functions[] = id(new PhabricatorFactChartFunction())
->setArguments(array('tasks.open-count.create'));
- $functions[] = id(new PhabricatorConstantChartFunction())
- ->setArguments(array(256));
-
- $functions[] = id(new PhabricatorXChartFunction())
+ $x_function = id(new PhabricatorXChartFunction())
->setArguments(array());
+ $functions[] = id(new PhabricatorSinChartFunction())
+ ->setArguments(array($x_function));
+
list($domain_min, $domain_max) = $this->getDomain($functions);
$axis = id(new PhabricatorChartAxis())
->setMinimumValue($domain_min)
->setMaximumValue($domain_max);
+ $data_query = id(new PhabricatorChartDataQuery())
+ ->setMinimumValue($domain_min)
+ ->setMaximumValue($domain_max)
+ ->setLimit(2000);
+
$datasets = array();
foreach ($functions as $function) {
$function->setXAxis($axis);
$function->loadData();
- $points = $function->getDatapoints(2000);
+ $points = $function->getDatapoints($data_query);
$x = array();
$y = array();
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Nov 29, 10:24 PM (4 h, 37 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6807019
Default Alt Text
D20444.diff (8 KB)
Attached To
Mode
D20444: Add a "sin()" function to charts
Attached
Detach File
Event Timeline
Log In to Comment