mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-30 02:32:42 +01:00
Automatically select the range for charts in a general way
Summary: Ref T13279. Replace the hard-coded default range with a range computed by examining the chart data. Instead of having a "Dataset" return a blob of wire data, "Dataset" now returns a structure with raw wire data plus a range. I expect to add more structured data here in future changes (tooltip/hover event data, maybe function labels). Test Plan: {F6439101} Reviewers: amckinley Reviewed By: amckinley Subscribers: yelirekim Maniphest Tasks: T13279 Differential Revision: https://secure.phabricator.com/D20503
This commit is contained in:
parent
e90360c289
commit
493a6b72c1
5 changed files with 77 additions and 11 deletions
|
@ -2664,6 +2664,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorChartAxis' => 'applications/fact/chart/PhabricatorChartAxis.php',
|
'PhabricatorChartAxis' => 'applications/fact/chart/PhabricatorChartAxis.php',
|
||||||
'PhabricatorChartDataQuery' => 'applications/fact/chart/PhabricatorChartDataQuery.php',
|
'PhabricatorChartDataQuery' => 'applications/fact/chart/PhabricatorChartDataQuery.php',
|
||||||
'PhabricatorChartDataset' => 'applications/fact/chart/PhabricatorChartDataset.php',
|
'PhabricatorChartDataset' => 'applications/fact/chart/PhabricatorChartDataset.php',
|
||||||
|
'PhabricatorChartDisplayData' => 'applications/fact/chart/PhabricatorChartDisplayData.php',
|
||||||
'PhabricatorChartEngine' => 'applications/fact/engine/PhabricatorChartEngine.php',
|
'PhabricatorChartEngine' => 'applications/fact/engine/PhabricatorChartEngine.php',
|
||||||
'PhabricatorChartFunction' => 'applications/fact/chart/PhabricatorChartFunction.php',
|
'PhabricatorChartFunction' => 'applications/fact/chart/PhabricatorChartFunction.php',
|
||||||
'PhabricatorChartFunctionArgument' => 'applications/fact/chart/PhabricatorChartFunctionArgument.php',
|
'PhabricatorChartFunctionArgument' => 'applications/fact/chart/PhabricatorChartFunctionArgument.php',
|
||||||
|
@ -8681,6 +8682,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorChartAxis' => 'Phobject',
|
'PhabricatorChartAxis' => 'Phobject',
|
||||||
'PhabricatorChartDataQuery' => 'Phobject',
|
'PhabricatorChartDataQuery' => 'Phobject',
|
||||||
'PhabricatorChartDataset' => 'Phobject',
|
'PhabricatorChartDataset' => 'Phobject',
|
||||||
|
'PhabricatorChartDisplayData' => 'Phobject',
|
||||||
'PhabricatorChartEngine' => 'Phobject',
|
'PhabricatorChartEngine' => 'Phobject',
|
||||||
'PhabricatorChartFunction' => 'Phobject',
|
'PhabricatorChartFunction' => 'Phobject',
|
||||||
'PhabricatorChartFunctionArgument' => 'Phobject',
|
'PhabricatorChartFunctionArgument' => 'Phobject',
|
||||||
|
|
|
@ -66,11 +66,12 @@ abstract class PhabricatorChartDataset
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
final public function getWireFormat(PhabricatorChartDataQuery $data_query) {
|
final public function getChartDisplayData(
|
||||||
return $this->newWireFormat($data_query);
|
PhabricatorChartDataQuery $data_query) {
|
||||||
|
return $this->newChartDisplayData($data_query);
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract protected function newWireFormat(
|
abstract protected function newChartDisplayData(
|
||||||
PhabricatorChartDataQuery $data_query);
|
PhabricatorChartDataQuery $data_query);
|
||||||
|
|
||||||
|
|
||||||
|
|
27
src/applications/fact/chart/PhabricatorChartDisplayData.php
Normal file
27
src/applications/fact/chart/PhabricatorChartDisplayData.php
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
final class PhabricatorChartDisplayData
|
||||||
|
extends Phobject {
|
||||||
|
|
||||||
|
private $wireData;
|
||||||
|
private $range;
|
||||||
|
|
||||||
|
public function setWireData(array $wire_data) {
|
||||||
|
$this->wireData = $wire_data;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getWireData() {
|
||||||
|
return $this->wireData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setRange(PhabricatorChartInterval $range) {
|
||||||
|
$this->range = $range;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getRange() {
|
||||||
|
return $this->range;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -5,7 +5,8 @@ final class PhabricatorChartStackedAreaDataset
|
||||||
|
|
||||||
const DATASETKEY = 'stacked-area';
|
const DATASETKEY = 'stacked-area';
|
||||||
|
|
||||||
protected function newWireFormat(PhabricatorChartDataQuery $data_query) {
|
protected function newChartDisplayData(
|
||||||
|
PhabricatorChartDataQuery $data_query) {
|
||||||
$functions = $this->getFunctions();
|
$functions = $this->getFunctions();
|
||||||
|
|
||||||
$function_points = array();
|
$function_points = array();
|
||||||
|
@ -93,6 +94,9 @@ final class PhabricatorChartStackedAreaDataset
|
||||||
ksort($function_points[$function_idx]);
|
ksort($function_points[$function_idx]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$range_min = null;
|
||||||
|
$range_max = null;
|
||||||
|
|
||||||
$series = array();
|
$series = array();
|
||||||
$baseline = array();
|
$baseline = array();
|
||||||
foreach ($function_points as $function_idx => $points) {
|
foreach ($function_points as $function_idx => $points) {
|
||||||
|
@ -117,6 +121,16 @@ final class PhabricatorChartStackedAreaDataset
|
||||||
if (isset($raw_points[$function_idx][$x])) {
|
if (isset($raw_points[$function_idx][$x])) {
|
||||||
$raw_points[$function_idx][$x]['y1'] = $y1;
|
$raw_points[$function_idx][$x]['y1'] = $y1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($range_min === null) {
|
||||||
|
$range_min = $y0;
|
||||||
|
}
|
||||||
|
$range_min = min($range_min, $y0, $y1);
|
||||||
|
|
||||||
|
if ($range_max === null) {
|
||||||
|
$range_max = $y1;
|
||||||
|
}
|
||||||
|
$range_max = max($range_max, $y0, $y1);
|
||||||
}
|
}
|
||||||
|
|
||||||
$series[] = $bounds;
|
$series[] = $bounds;
|
||||||
|
@ -147,7 +161,9 @@ final class PhabricatorChartStackedAreaDataset
|
||||||
'labels' => $wire_labels,
|
'labels' => $wire_labels,
|
||||||
);
|
);
|
||||||
|
|
||||||
return $result;
|
return id(new PhabricatorChartDisplayData())
|
||||||
|
->setWireData($result)
|
||||||
|
->setRange(new PhabricatorChartInterval($range_min, $range_max));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -145,20 +145,22 @@ final class PhabricatorChartRenderingEngine
|
||||||
->setLimit(2000);
|
->setLimit(2000);
|
||||||
|
|
||||||
$wire_datasets = array();
|
$wire_datasets = array();
|
||||||
|
$ranges = array();
|
||||||
foreach ($datasets as $dataset) {
|
foreach ($datasets as $dataset) {
|
||||||
$wire_datasets[] = $dataset->getWireFormat($data_query);
|
$display_data = $dataset->getChartDisplayData($data_query);
|
||||||
|
|
||||||
|
$ranges[] = $display_data->getRange();
|
||||||
|
$wire_datasets[] = $display_data->getWireData();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Figure these out from the datasets again.
|
$range = $this->getRange($ranges);
|
||||||
$y_min = -2;
|
|
||||||
$y_max = 20;
|
|
||||||
|
|
||||||
$chart_data = array(
|
$chart_data = array(
|
||||||
'datasets' => $wire_datasets,
|
'datasets' => $wire_datasets,
|
||||||
'xMin' => $domain->getMin(),
|
'xMin' => $domain->getMin(),
|
||||||
'xMax' => $domain->getMax(),
|
'xMax' => $domain->getMax(),
|
||||||
'yMin' => $y_min,
|
'yMin' => $range->getMin(),
|
||||||
'yMax' => $y_max,
|
'yMax' => $range->getMax(),
|
||||||
);
|
);
|
||||||
|
|
||||||
return $chart_data;
|
return $chart_data;
|
||||||
|
@ -186,4 +188,22 @@ final class PhabricatorChartRenderingEngine
|
||||||
return $domain;
|
return $domain;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getRange(array $ranges) {
|
||||||
|
$range = PhabricatorChartInterval::newFromIntervalList($ranges);
|
||||||
|
|
||||||
|
// Start the Y axis at 0 unless the chart has negative values.
|
||||||
|
$min = $range->getMin();
|
||||||
|
if ($min === null || $min >= 0) {
|
||||||
|
$range->setMin(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If there's no maximum value, just pick a plausible default.
|
||||||
|
$max = $range->getMax();
|
||||||
|
if ($max === null) {
|
||||||
|
$range->setMax($range->getMin() + 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $range;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue