touched up the commits-per-month graph

This commit is contained in:
hyung-hwan 2015-02-06 15:52:55 +00:00
parent f86c4dcabe
commit d12de4e0cf

View File

@ -791,68 +791,74 @@ class Code extends Controller
$file = $this->subversion->getHistory ($projectid, $path, SVN_REVISION_HEAD); $file = $this->subversion->getHistory ($projectid, $path, SVN_REVISION_HEAD);
if ($file === FALSE) if ($file === FALSE)
{ {
header($_SERVER['SERVER_PROTOCOL'].' 500 Internal Server Error'); //header($_SERVER['SERVER_PROTOCOL'].' 500 Internal Server Error');
return; //return;
$stats = array ('no-data' => 0);
} }
else
$history = $file['history'];
$history_count = count($history);
$stats = array();
for ($i = 0; $i < $history_count; $i++)
{ {
$h = $history[$i];
if (array_key_exists ('date', $h)) $history = $file['history'];
$history_count = count($history);
$stats = array();
for ($i = 0; $i < $history_count; $i++)
{ {
$date = substr($h['date'], 0, 7); $h = $history[$i];
if (array_key_exists ($date, $stats)) if (array_key_exists ('date', $h))
$stats[$date]++;
else
$stats[$date] = 1;
}
}
ksort ($stats);
$stats_count = count($stats);
$idx = 1;
foreach ($stats as $k => $v)
{
if ($idx == 1)
{
$min_year = substr($k, 0, 4);
$min_month = substr($k, 5, 2);
}
else if ($idx == $stats_count)
{
$max_year = substr($k, 0, 4);
$max_month = substr($k, 5, 2);
}
$idx++;
}
for ($year = $min_year; $year <= $max_year; $year++)
{
$month = ($year == $min_year)? $min_month: 1;
$month_end = ($year == $max_year)? $max_month: 12;
while ($month < $month_end)
{
$date = sprintf ("%04d-%02d", $year, $month);
if (!array_key_exists ($date, $stats))
{ {
// fill the holes $date = substr($h['date'], 0, 7);
$stats[$date] = 0; if (array_key_exists ($date, $stats))
$stats[$date]++;
else
$stats[$date] = 1;
}
}
ksort ($stats);
$stats_count = count($stats);
$idx = 1;
foreach ($stats as $k => $v)
{
if ($idx == 1)
{
$min_year = substr($k, 0, 4);
$min_month = substr($k, 5, 2);
} }
$month++; if ($idx == $stats_count)
{
$max_year = substr($k, 0, 4);
$max_month = substr($k, 5, 2);
}
$idx++;
}
for ($year = $min_year; $year <= $max_year; $year++)
{
$month = ($year == $min_year)? $min_month: 1;
$month_end = ($year == $max_year)? $max_month: 12;
while ($month <= $month_end)
{
$date = sprintf ("%04d-%02d", $year, $month);
if (!array_key_exists ($date, $stats))
{
// fill the holes
$stats[$date] = 0;
}
$month++;
}
} }
} }
ksort ($stats); ksort ($stats);
$stats_count = count($stats); $stats_count = count($stats);
$graph_width = $stats_count * 5; $graph_width = $stats_count * 5;
if ($graph_width < 400) $graph_width = 400; if ($graph_width < 400) $graph_width = 400;
$this->load->library ('PHPGraphLib', array ('width' => $graph_width, 'height' => 150), 'graph'); $this->load->library ('PHPGraphLib', array ('width' => $graph_width, 'height' => 150), 'graph');
@ -864,8 +870,19 @@ class Code extends Controller
$this->graph->setLineColor("red"); $this->graph->setLineColor("red");
$this->graph->setBars(FALSE); $this->graph->setBars(FALSE);
$this->graph->setXValues(TRUE); $this->graph->setXValues(TRUE);
$this->graph->setXValuesInterval(12);
$this->graph->setXValuesHorizontal(TRUE); $this->graph->setXValuesHorizontal(TRUE);
if ($stats_count < 12)
{
if ($stats_count <= 1)
{
$this->graph->setDataPoints(TRUE);
$this->graph->setDataPointColor("red");
}
}
else
{
$this->graph->setXValuesInterval(11);
}
$this->graph->setGrid(FALSE); $this->graph->setGrid(FALSE);
$this->graph->createGraph(); $this->graph->createGraph();
} }