Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15410244
D20443.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
7 KB
Referenced Files
None
Subscribers
None
D20443.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
@@ -2802,6 +2802,7 @@
'PhabricatorConpherenceWidgetVisibleSetting' => 'applications/settings/setting/PhabricatorConpherenceWidgetVisibleSetting.php',
'PhabricatorConsoleApplication' => 'applications/console/application/PhabricatorConsoleApplication.php',
'PhabricatorConsoleContentSource' => 'infrastructure/contentsource/PhabricatorConsoleContentSource.php',
+ 'PhabricatorConstantChartFunction' => 'applications/fact/chart/PhabricatorConstantChartFunction.php',
'PhabricatorContactNumbersSettingsPanel' => 'applications/settings/panel/PhabricatorContactNumbersSettingsPanel.php',
'PhabricatorContentSource' => 'infrastructure/contentsource/PhabricatorContentSource.php',
'PhabricatorContentSourceModule' => 'infrastructure/contentsource/PhabricatorContentSourceModule.php',
@@ -4935,6 +4936,7 @@
'PhabricatorWorkingCopyDiscoveryTestCase' => 'applications/repository/engine/__tests__/PhabricatorWorkingCopyDiscoveryTestCase.php',
'PhabricatorWorkingCopyPullTestCase' => 'applications/repository/engine/__tests__/PhabricatorWorkingCopyPullTestCase.php',
'PhabricatorWorkingCopyTestCase' => 'applications/repository/engine/__tests__/PhabricatorWorkingCopyTestCase.php',
+ 'PhabricatorXChartFunction' => 'applications/fact/chart/PhabricatorXChartFunction.php',
'PhabricatorXHPASTDAO' => 'applications/phpast/storage/PhabricatorXHPASTDAO.php',
'PhabricatorXHPASTParseTree' => 'applications/phpast/storage/PhabricatorXHPASTParseTree.php',
'PhabricatorXHPASTViewController' => 'applications/phpast/controller/PhabricatorXHPASTViewController.php',
@@ -8790,6 +8792,7 @@
'PhabricatorConpherenceWidgetVisibleSetting' => 'PhabricatorInternalSetting',
'PhabricatorConsoleApplication' => 'PhabricatorApplication',
'PhabricatorConsoleContentSource' => 'PhabricatorContentSource',
+ 'PhabricatorConstantChartFunction' => 'PhabricatorChartFunction',
'PhabricatorContactNumbersSettingsPanel' => 'PhabricatorSettingsPanel',
'PhabricatorContentSource' => 'Phobject',
'PhabricatorContentSourceModule' => 'PhabricatorConfigModule',
@@ -11288,6 +11291,7 @@
'PhabricatorWorkingCopyDiscoveryTestCase' => 'PhabricatorWorkingCopyTestCase',
'PhabricatorWorkingCopyPullTestCase' => 'PhabricatorWorkingCopyTestCase',
'PhabricatorWorkingCopyTestCase' => 'PhabricatorTestCase',
+ 'PhabricatorXChartFunction' => 'PhabricatorChartFunction',
'PhabricatorXHPASTDAO' => 'PhabricatorLiskDAO',
'PhabricatorXHPASTParseTree' => 'PhabricatorXHPASTDAO',
'PhabricatorXHPASTViewController' => 'PhabricatorController',
diff --git a/src/applications/fact/chart/PhabricatorChartFunction.php b/src/applications/fact/chart/PhabricatorChartFunction.php
--- a/src/applications/fact/chart/PhabricatorChartFunction.php
+++ b/src/applications/fact/chart/PhabricatorChartFunction.php
@@ -25,6 +25,10 @@
abstract protected function newArguments(array $arguments);
+ public function loadData() {
+ return;
+ }
+
final public function setXAxis(PhabricatorChartAxis $x_axis) {
$this->xAxis = $x_axis;
return $this;
@@ -43,4 +47,53 @@
return $this->yAxis;
}
+ protected function newLinearSteps($src, $dst, $count) {
+ $count = (int)$count;
+ $src = (int)$src;
+ $dst = (int)$dst;
+
+ if ($count === 0) {
+ throw new Exception(
+ pht('Can not generate zero linear steps between two values!'));
+ }
+
+ if ($src === $dst) {
+ return array($src);
+ }
+
+ if ($count === 1) {
+ return array($src);
+ }
+
+ $is_reversed = ($src > $dst);
+ if ($is_reversed) {
+ $min = (double)$dst;
+ $max = (double)$src;
+ } else {
+ $min = (double)$src;
+ $max = (double)$dst;
+ }
+
+ $step = (double)($max - $min) / (double)($count - 1);
+
+ $steps = array();
+ for ($cursor = $min; $cursor <= $max; $cursor += $step) {
+ $x = (int)round($cursor);
+
+ if (isset($steps[$x])) {
+ continue;
+ }
+
+ $steps[$x] = $x;
+ }
+
+ $steps = array_values($steps);
+
+ if ($is_reversed) {
+ $steps = array_reverse($steps);
+ }
+
+ return $steps;
+ }
+
}
diff --git a/src/applications/fact/chart/PhabricatorConstantChartFunction.php b/src/applications/fact/chart/PhabricatorConstantChartFunction.php
new file mode 100644
--- /dev/null
+++ b/src/applications/fact/chart/PhabricatorConstantChartFunction.php
@@ -0,0 +1,51 @@
+<?php
+
+final class PhabricatorConstantChartFunction
+ extends PhabricatorChartFunction {
+
+ const FUNCTIONKEY = 'constant';
+
+ private $value;
+
+ protected function newArguments(array $arguments) {
+ if (count($arguments) !== 1) {
+ throw new Exception(
+ pht(
+ 'Chart function "constant(...)" expects one argument, got %s. '.
+ 'Pass a constant.',
+ count($arguments)));
+ }
+
+ if (!is_int($arguments[0])) {
+ throw new Exception(
+ pht(
+ 'First argument for "fact(...)" is invalid: expected int, '.
+ 'got %s.',
+ phutil_describe_type($arguments[0])));
+ }
+
+ $this->value = $arguments[0];
+ }
+
+ public function getDatapoints($limit) {
+ $axis = $this->getXAxis();
+ $x_min = $axis->getMinimumValue();
+ $x_max = $axis->getMaximumValue();
+
+ $points = array();
+ $steps = $this->newLinearSteps($x_min, $x_max, 2);
+ foreach ($steps as $step) {
+ $points[] = array(
+ 'x' => $step,
+ 'y' => $this->value,
+ );
+ }
+
+ return $points;
+ }
+
+ public function hasDomain() {
+ return false;
+ }
+
+}
diff --git a/src/applications/fact/chart/PhabricatorXChartFunction.php b/src/applications/fact/chart/PhabricatorXChartFunction.php
new file mode 100644
--- /dev/null
+++ b/src/applications/fact/chart/PhabricatorXChartFunction.php
@@ -0,0 +1,38 @@
+<?php
+
+final class PhabricatorXChartFunction
+ extends PhabricatorChartFunction {
+
+ const FUNCTIONKEY = 'x';
+
+ protected function newArguments(array $arguments) {
+ if (count($arguments) !== 0) {
+ throw new Exception(
+ pht(
+ 'Chart function "x()" expects zero arguments, got %s.',
+ count($arguments)));
+ }
+ }
+
+ public function getDatapoints($limit) {
+ $axis = $this->getXAxis();
+ $x_min = $axis->getMinimumValue();
+ $x_max = $axis->getMaximumValue();
+
+ $points = array();
+ $steps = $this->newLinearSteps($x_min, $x_max, $limit);
+ foreach ($steps as $step) {
+ $points[] = array(
+ 'x' => $step,
+ 'y' => $step,
+ );
+ }
+
+ return $points;
+ }
+
+ public function hasDomain() {
+ return false;
+ }
+
+}
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,9 +20,11 @@
$functions[] = id(new PhabricatorFactChartFunction())
->setArguments(array('tasks.open-count.create'));
- if ($is_chart_mode) {
- return $this->newChartResponse();
- }
+ $functions[] = id(new PhabricatorConstantChartFunction())
+ ->setArguments(array(256));
+
+ $functions[] = id(new PhabricatorXChartFunction())
+ ->setArguments(array());
list($domain_min, $domain_max) = $this->getDomain($functions);
@@ -73,6 +75,10 @@
'yMax' => $y_max,
);
+ if ($is_chart_mode) {
+ return $this->newChartResponse();
+ }
+
return id(new AphrontAjaxResponse())->setContent($chart_data);
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Mar 20, 6:56 AM (4 d, 14 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7651974
Default Alt Text
D20443.diff (7 KB)
Attached To
Mode
D20443: Add chart functions "x()" and "constant(3)"
Attached
Detach File
Event Timeline
Log In to Comment