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 @@ +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 @@ +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); }