Changeset View
Changeset View
Standalone View
Standalone View
src/applications/fact/controller/PhabricatorFactChartController.php
Show All 24 Lines | public function handleRequest(AphrontRequest $request) { | ||||
$points = array(); | $points = array(); | ||||
$sum = 0; | $sum = 0; | ||||
foreach ($data as $key => $row) { | foreach ($data as $key => $row) { | ||||
$sum += (int)$row['valueX']; | $sum += (int)$row['valueX']; | ||||
$points[(int)$row['epoch']] = $sum; | $points[(int)$row['epoch']] = $sum; | ||||
} | } | ||||
if (!$points) { | if (!$points) { | ||||
// NOTE: Raphael crashes Safari if you hand it series with no points. | throw new Exception('No data to show!'); | ||||
throw new Exception(pht('No data to show!')); | |||||
} | } | ||||
// Limit amount of data passed to browser. | // Limit amount of data passed to browser. | ||||
$count = count($points); | $count = count($points); | ||||
$limit = 2000; | $limit = 2000; | ||||
if ($count > $limit) { | if ($count > $limit) { | ||||
$i = 0; | $i = 0; | ||||
$every = ceil($count / $limit); | $every = ceil($count / $limit); | ||||
foreach ($points as $epoch => $sum) { | foreach ($points as $epoch => $sum) { | ||||
$i++; | $i++; | ||||
if ($i % $every && $i != $count) { | if ($i % $every && $i != $count) { | ||||
unset($points[$epoch]); | unset($points[$epoch]); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
$x = array_keys($points); | $x = array_keys($points); | ||||
$y = array_values($points); | $y = array_values($points); | ||||
$id = celerity_generate_unique_node_id(); | $id = celerity_generate_unique_node_id(); | ||||
$chart = phutil_tag( | $chart = phutil_tag( | ||||
'div', | 'div', | ||||
array( | array( | ||||
'id' => $id, | 'id' => $id, | ||||
'style' => 'border: 1px solid #6f6f6f; '. | 'style' => 'background: #ffffff; '. | ||||
'margin: 1em 2em; '. | 'height: 480px; ', | ||||
'background: #ffffff; '. | |||||
'height: 400px; ', | |||||
), | ), | ||||
''); | ''); | ||||
require_celerity_resource('raphael-core'); | require_celerity_resource('d3'); | ||||
require_celerity_resource('raphael-g'); | |||||
require_celerity_resource('raphael-g-line'); | |||||
Javelin::initBehavior('line-chart', array( | Javelin::initBehavior('line-chart', array( | ||||
'hardpoint' => $id, | 'hardpoint' => $id, | ||||
'x' => array($x), | 'x' => array($x), | ||||
'y' => array($y), | 'y' => array($y), | ||||
'xformat' => 'epoch', | 'xformat' => 'epoch', | ||||
'colors' => array('#0000ff'), | 'colors' => array('#0000ff'), | ||||
)); | )); | ||||
$panel = new PHUIObjectBoxView(); | $box = id(new PHUIObjectBoxView()) | ||||
$panel->setHeaderText(pht('Count of %s', $spec->getName())); | ->setHeaderText(pht('Count of %s', $spec->getName())) | ||||
$panel->appendChild($chart); | ->appendChild($chart); | ||||
$crumbs = $this->buildApplicationCrumbs(); | $crumbs = $this->buildApplicationCrumbs(); | ||||
$crumbs->addTextCrumb(pht('Chart')); | $crumbs->addTextCrumb(pht('Chart')); | ||||
return $this->buildApplicationPage( | return $this->buildApplicationPage( | ||||
array( | array( | ||||
$crumbs, | $crumbs, | ||||
$panel, | $box, | ||||
), | ), | ||||
array( | array( | ||||
'title' => pht('Chart'), | 'title' => pht('Chart'), | ||||
)); | )); | ||||
} | } | ||||
} | } |