diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 097bb1bb76..146303c1a5 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -2669,6 +2669,7 @@ phutil_register_library_map(array( '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 @@ phutil_register_library_map(array( '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 index 0000000000..9432d5be76 --- /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 index ae2ba52472..dbb886dd3e 100644 --- a/src/applications/fact/chart/PhabricatorFactChartFunction.php +++ b/src/applications/fact/chart/PhabricatorFactChartFunction.php @@ -73,10 +73,10 @@ final class PhabricatorFactChartFunction } 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 index aef8f948be..ab160bd10f 100644 --- a/src/applications/fact/chart/PhabricatorHigherOrderChartFunction.php +++ b/src/applications/fact/chart/PhabricatorHigherOrderChartFunction.php @@ -4,37 +4,12 @@ abstract class PhabricatorHigherOrderChartFunction 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; - } - } + $domains[] = $function->getDomain(); } - if (!$minv && !$maxv) { - return null; - } - - $min = null; - $max = null; - - if ($minv) { - $min = min($minv); - } - - if ($maxv) { - $max = max($maxv); - } - - 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 index b89e8da861..c7bf263080 100644 --- a/src/applications/fact/engine/PhabricatorChartRenderingEngine.php +++ b/src/applications/fact/engine/PhabricatorChartRenderingEngine.php @@ -133,15 +133,15 @@ final class PhabricatorChartRenderingEngine $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 @@ final class PhabricatorChartRenderingEngine $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 @@ final class PhabricatorChartRenderingEngine } 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; } }