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 @@ -2669,6 +2669,7 @@ 'PhabricatorChartFunctionArgument' => 'applications/fact/chart/PhabricatorChartFunctionArgument.php', 'PhabricatorChartFunctionArgumentParser' => 'applications/fact/chart/PhabricatorChartFunctionArgumentParser.php', 'PhabricatorChartFunctionLabel' => 'applications/fact/chart/PhabricatorChartFunctionLabel.php', + 'PhabricatorChartInterval' => 'applications/fact/chart/PhabricatorChartInterval.php', 'PhabricatorChartRenderingEngine' => 'applications/fact/engine/PhabricatorChartRenderingEngine.php', 'PhabricatorChartStackedAreaDataset' => 'applications/fact/chart/PhabricatorChartStackedAreaDataset.php', 'PhabricatorChatLogApplication' => 'applications/chatlog/application/PhabricatorChatLogApplication.php', @@ -8685,6 +8686,7 @@ 'PhabricatorChartFunctionArgument' => 'Phobject', 'PhabricatorChartFunctionArgumentParser' => 'Phobject', 'PhabricatorChartFunctionLabel' => 'Phobject', + 'PhabricatorChartInterval' => 'Phobject', 'PhabricatorChartRenderingEngine' => 'Phobject', 'PhabricatorChartStackedAreaDataset' => 'PhabricatorChartDataset', 'PhabricatorChatLogApplication' => 'PhabricatorApplication', diff --git a/src/applications/fact/chart/PhabricatorChartInterval.php b/src/applications/fact/chart/PhabricatorChartInterval.php new file mode 100644 --- /dev/null +++ b/src/applications/fact/chart/PhabricatorChartInterval.php @@ -0,0 +1,62 @@ +min = $min; + $this->max = $max; + } + + public static function newFromIntervalList(array $intervals) { + $min = null; + $max = null; + foreach ($intervals as $interval) { + if ($interval === null) { + continue; + } + + $interval_min = $interval->getMin(); + if ($interval_min !== null) { + if ($min === null) { + $min = $interval_min; + } else { + $min = min($min, $interval_min); + } + } + + $interval_max = $interval->getMax(); + if ($interval_max !== null) { + if ($max === null) { + $max = $interval_max; + } else { + $max = max($max, $interval_max); + } + } + } + + return new self($min, $max); + } + + public function setMin($min) { + $this->min = $min; + return $this; + } + + public function getMin() { + return $this->min; + } + + public function setMax($max) { + $this->max = $max; + return $this; + } + + public function getMax() { + return $this->max; + } + +} 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 @@ -73,10 +73,10 @@ } public function getDomain() { - return array( - head_key($this->map), - last_key($this->map), - ); + $min = head_key($this->map); + $max = last_key($this->map); + + return new PhabricatorChartInterval($min, $max); } public function newInputValues(PhabricatorChartDataQuery $query) { diff --git a/src/applications/fact/chart/PhabricatorHigherOrderChartFunction.php b/src/applications/fact/chart/PhabricatorHigherOrderChartFunction.php --- a/src/applications/fact/chart/PhabricatorHigherOrderChartFunction.php +++ b/src/applications/fact/chart/PhabricatorHigherOrderChartFunction.php @@ -4,37 +4,12 @@ extends PhabricatorChartFunction { public function getDomain() { - $minv = array(); - $maxv = array(); + $domains = array(); foreach ($this->getFunctionArguments() as $function) { - $domain = $function->getDomain(); - if ($domain !== null) { - list($min, $max) = $domain; - if ($min !== null) { - $minv[] = $min; - } - if ($max !== null) { - $maxv[] = $max; - } - } - } - - if (!$minv && !$maxv) { - return null; - } - - $min = null; - $max = null; - - if ($minv) { - $min = min($minv); - } - - if ($maxv) { - $max = max($maxv); + $domains[] = $function->getDomain(); } - return array($min, $max); + return PhabricatorChartInterval::newFromIntervalList($domains); } public function newInputValues(PhabricatorChartDataQuery $query) { diff --git a/src/applications/fact/engine/PhabricatorChartRenderingEngine.php b/src/applications/fact/engine/PhabricatorChartRenderingEngine.php --- a/src/applications/fact/engine/PhabricatorChartRenderingEngine.php +++ b/src/applications/fact/engine/PhabricatorChartRenderingEngine.php @@ -133,15 +133,15 @@ $subfunction->loadData(); } - list($domain_min, $domain_max) = $this->getDomain($functions); + $domain = $this->getDomain($functions); $axis = id(new PhabricatorChartAxis()) - ->setMinimumValue($domain_min) - ->setMaximumValue($domain_max); + ->setMinimumValue($domain->getMin()) + ->setMaximumValue($domain->getMax()); $data_query = id(new PhabricatorChartDataQuery()) - ->setMinimumValue($domain_min) - ->setMaximumValue($domain_max) + ->setMinimumValue($domain->getMin()) + ->setMaximumValue($domain->getMax()) ->setLimit(2000); $wire_datasets = array(); @@ -155,8 +155,8 @@ $chart_data = array( 'datasets' => $wire_datasets, - 'xMin' => $domain_min, - 'xMax' => $domain_max, + 'xMin' => $domain->getMin(), + 'xMax' => $domain->getMax(), 'yMin' => $y_min, 'yMax' => $y_max, ); @@ -165,46 +165,25 @@ } private function getDomain(array $functions) { - $domain_min_list = null; - $domain_max_list = null; - + $domains = array(); foreach ($functions as $function) { - $domain = $function->getDomain(); - - list($function_min, $function_max) = $domain; - - if ($function_min !== null) { - $domain_min_list[] = $function_min; - } - - if ($function_max !== null) { - $domain_max_list[] = $function_max; - } + $domains[] = $function->getDomain(); } - $domain_min = null; - $domain_max = null; - - if ($domain_min_list) { - $domain_min = min($domain_min_list); - } - - if ($domain_max_list) { - $domain_max = max($domain_max_list); - } + $domain = PhabricatorChartInterval::newFromIntervalList($domains); // If we don't have any domain data from the actual functions, pick a // plausible domain automatically. - if ($domain_max === null) { - $domain_max = PhabricatorTime::getNow(); + if ($domain->getMax() === null) { + $domain->setMax(PhabricatorTime::getNow()); } - if ($domain_min === null) { - $domain_min = $domain_max - phutil_units('365 days in seconds'); + if ($domain->getMin() === null) { + $domain->setMin($domain->getMax() - phutil_units('365 days in seconds')); } - return array($domain_min, $domain_max); + return $domain; } }