@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+77 -11
+2
src/__phutil_library_map__.php
··· 2664 2664 'PhabricatorChartAxis' => 'applications/fact/chart/PhabricatorChartAxis.php', 2665 2665 'PhabricatorChartDataQuery' => 'applications/fact/chart/PhabricatorChartDataQuery.php', 2666 2666 'PhabricatorChartDataset' => 'applications/fact/chart/PhabricatorChartDataset.php', 2667 + 'PhabricatorChartDisplayData' => 'applications/fact/chart/PhabricatorChartDisplayData.php', 2667 2668 'PhabricatorChartEngine' => 'applications/fact/engine/PhabricatorChartEngine.php', 2668 2669 'PhabricatorChartFunction' => 'applications/fact/chart/PhabricatorChartFunction.php', 2669 2670 'PhabricatorChartFunctionArgument' => 'applications/fact/chart/PhabricatorChartFunctionArgument.php', ··· 8681 8682 'PhabricatorChartAxis' => 'Phobject', 8682 8683 'PhabricatorChartDataQuery' => 'Phobject', 8683 8684 'PhabricatorChartDataset' => 'Phobject', 8685 + 'PhabricatorChartDisplayData' => 'Phobject', 8684 8686 'PhabricatorChartEngine' => 'Phobject', 8685 8687 'PhabricatorChartFunction' => 'Phobject', 8686 8688 'PhabricatorChartFunctionArgument' => 'Phobject',
+4 -3
src/applications/fact/chart/PhabricatorChartDataset.php
··· 66 66 ); 67 67 } 68 68 69 - final public function getWireFormat(PhabricatorChartDataQuery $data_query) { 70 - return $this->newWireFormat($data_query); 69 + final public function getChartDisplayData( 70 + PhabricatorChartDataQuery $data_query) { 71 + return $this->newChartDisplayData($data_query); 71 72 } 72 73 73 - abstract protected function newWireFormat( 74 + abstract protected function newChartDisplayData( 74 75 PhabricatorChartDataQuery $data_query); 75 76 76 77
+27
src/applications/fact/chart/PhabricatorChartDisplayData.php
··· 1 + <?php 2 + 3 + final class PhabricatorChartDisplayData 4 + extends Phobject { 5 + 6 + private $wireData; 7 + private $range; 8 + 9 + public function setWireData(array $wire_data) { 10 + $this->wireData = $wire_data; 11 + return $this; 12 + } 13 + 14 + public function getWireData() { 15 + return $this->wireData; 16 + } 17 + 18 + public function setRange(PhabricatorChartInterval $range) { 19 + $this->range = $range; 20 + return $this; 21 + } 22 + 23 + public function getRange() { 24 + return $this->range; 25 + } 26 + 27 + }
+18 -2
src/applications/fact/chart/PhabricatorChartStackedAreaDataset.php
··· 5 5 6 6 const DATASETKEY = 'stacked-area'; 7 7 8 - protected function newWireFormat(PhabricatorChartDataQuery $data_query) { 8 + protected function newChartDisplayData( 9 + PhabricatorChartDataQuery $data_query) { 9 10 $functions = $this->getFunctions(); 10 11 11 12 $function_points = array(); ··· 93 94 ksort($function_points[$function_idx]); 94 95 } 95 96 97 + $range_min = null; 98 + $range_max = null; 99 + 96 100 $series = array(); 97 101 $baseline = array(); 98 102 foreach ($function_points as $function_idx => $points) { ··· 117 121 if (isset($raw_points[$function_idx][$x])) { 118 122 $raw_points[$function_idx][$x]['y1'] = $y1; 119 123 } 124 + 125 + if ($range_min === null) { 126 + $range_min = $y0; 127 + } 128 + $range_min = min($range_min, $y0, $y1); 129 + 130 + if ($range_max === null) { 131 + $range_max = $y1; 132 + } 133 + $range_max = max($range_max, $y0, $y1); 120 134 } 121 135 122 136 $series[] = $bounds; ··· 147 161 'labels' => $wire_labels, 148 162 ); 149 163 150 - return $result; 164 + return id(new PhabricatorChartDisplayData()) 165 + ->setWireData($result) 166 + ->setRange(new PhabricatorChartInterval($range_min, $range_max)); 151 167 } 152 168 153 169
+26 -6
src/applications/fact/engine/PhabricatorChartRenderingEngine.php
··· 145 145 ->setLimit(2000); 146 146 147 147 $wire_datasets = array(); 148 + $ranges = array(); 148 149 foreach ($datasets as $dataset) { 149 - $wire_datasets[] = $dataset->getWireFormat($data_query); 150 + $display_data = $dataset->getChartDisplayData($data_query); 151 + 152 + $ranges[] = $display_data->getRange(); 153 + $wire_datasets[] = $display_data->getWireData(); 150 154 } 151 155 152 - // TODO: Figure these out from the datasets again. 153 - $y_min = -2; 154 - $y_max = 20; 156 + $range = $this->getRange($ranges); 155 157 156 158 $chart_data = array( 157 159 'datasets' => $wire_datasets, 158 160 'xMin' => $domain->getMin(), 159 161 'xMax' => $domain->getMax(), 160 - 'yMin' => $y_min, 161 - 'yMax' => $y_max, 162 + 'yMin' => $range->getMin(), 163 + 'yMax' => $range->getMax(), 162 164 ); 163 165 164 166 return $chart_data; ··· 184 186 } 185 187 186 188 return $domain; 189 + } 190 + 191 + private function getRange(array $ranges) { 192 + $range = PhabricatorChartInterval::newFromIntervalList($ranges); 193 + 194 + // Start the Y axis at 0 unless the chart has negative values. 195 + $min = $range->getMin(); 196 + if ($min === null || $min >= 0) { 197 + $range->setMin(0); 198 + } 199 + 200 + // If there's no maximum value, just pick a plausible default. 201 + $max = $range->getMax(); 202 + if ($max === null) { 203 + $range->setMax($range->getMin() + 100); 204 + } 205 + 206 + return $range; 187 207 } 188 208 189 209 }