* finish task #1623.

This commit is contained in:
wyd621
2013-08-01 00:27:04 +08:00
parent 65beb4ef18
commit e259c31486
6 changed files with 95 additions and 55 deletions
+46 -21
View File
@@ -662,11 +662,12 @@ class project extends control
/**
* Browse burndown chart of a project.
*
* @param int $projectID
* @param int $projectID
* @param string $type
* @access public
* @return void
*/
public function burn($projectID = 0)
public function burn($projectID = 0, $type = 'noweekend')
{
$this->loadModel('report');
$project = $this->commonAction($projectID);
@@ -678,38 +679,61 @@ class project extends control
$position[] = html::a($this->createLink('project', 'browse', "projectID=$projectID"), $project->name);
$position[] = $this->lang->project->burn;
/* Create charts by flash. */
//$dataXML = $this->report->createSingleXML($this->project->getBurnData($project->id), $this->lang->project->charts->burn->graph, $this->lang->report->singleColor);
//$charts = $this->report->createJSChart('line', $dataXML, 700, 350);
/* Get date list. */
if($projectInfo->days <= $maxDays)
{
$dateList = $this->project->getDateList($projectInfo->begin, $projectInfo->end, $type);
}
else
{
$today = date('Y-m-d');
if($today > $projectInfo->end)
{
$begin = $projectInfo->begin;
$end = date('Y-m-d', strtotime($projectInfo->begin) + 30 * 24 * 3600);
}
else
{
$endDays = helper::diffDate($projectInfo->end, $today);
$endDays = $endDays > 15 ? 15 : $endDays;
$beginDays = $endDays > 15 ? 15 : (30 - $endDays);
/* Create charts by flot. */
$sets = $this->project->getBurnDataFlot($project->id);
$count = count($sets);
$dataJSON = $this->report->createSingleJSON($sets);
$begin = date('Y-m-d', strtotime("-$beginDays days"));
$begin = $begin > $projectInfo->begin ? $begin : $projectInfo->begin;
$end = date('Y-m-d', strtotime("+$endDays days"));
$end = $end > $projectInfo->end ? $projectInfo->end : $end;
}
$dateList = $this->project->getDateList($begin, $end, $type);
}
$limitJSON = '[]';
$baselineJSON = '[]';
$beginMicTime = $this->project->getMicTime($projectInfo->begin);
$endMicTime = $this->project->getMicTime($projectInfo->end);
$maxDayMicTime = $this->project->getMicTime(strtotime($projectInfo->begin) + $maxDays * 24 * 3600);
$minDayMicTime = $this->project->getMicTime(time() - $maxDays * 24 * 3600);
if($projectInfo->days <= $maxDays)
{
$limitJSON = "[[$beginMicTime, 0], [$endMicTime, 0]]";
$firstBurn = reset($sets);
$firstTime = isset($firstBurn->value) ? $firstBurn->value : 0;
$baselineJSON = "[[$beginMicTime, $firstTime], [$endMicTime, 0]]";
$days = count($dateList) - 1;
$rate = $firstTime / $days;
$baselineJSON = '[';
foreach($dateList as $i => $date) $baselineJSON .='[' . $i . ',' . ($days - $i) * $rate . '],';
$baselineJSON = rtrim($baselineJSON, ',') . ']';
}
elseif($count <= $maxDays)
else
{
$limitJSON = "[[$beginMicTime, 0], [$maxDayMicTime, 0]]";
$limitJSON = '[';
foreach($dateList as $i => $date) $limitJSON .= "[$i, 0],";
$limitJSON = rtrim($limitJSON, ',') . ']';
}
$flotJSON['data'] = $dataJSON;
$flotJSON['limit'] = $limitJSON;
$flotJSON['baseline'] = $baselineJSON;
$sets = $this->project->getBurnDataFlot($project->id, $maxDays);
$charts = $this->report->createJSChartFlot($project->name, $flotJSON, $count, 900, 400);
$flotJSON['data'] = $this->report->createSingleJSON($sets, $dateList);
$flotJSON['limit'] = $limitJSON;
$flotJSON['baseline'] = $baselineJSON;
$flotJSON['dateList'] = json_encode($dateList);
$flotJSON['ticks'] = json_encode(array_keys($dateList));
$charts = $this->report->createJSChartFlot($project->name, $flotJSON, 900, 400);
/* Assign. */
$this->view->title = $title;
@@ -717,6 +741,7 @@ class project extends control
$this->view->tabID = 'burn';
$this->view->charts = $charts;
$this->view->projectID = $projectID;
$this->view->type = $type;
$this->display();
}
+2
View File
@@ -194,6 +194,8 @@ $lang->project->linkStory = 'Link story';
$lang->project->createTask = 'Create task';
$lang->project->goback = 'Go back(Automatically after 5 seconds)';
$lang->project->linkProduct = 'Select product to link...';
$lang->project->withWeekend = 'Show weekend';
$lang->project->noWeekend = 'Remove weekend';
/* Report. */
$lang->project->charts = new stdclass();
+2
View File
@@ -194,6 +194,8 @@ $lang->project->linkStory = '关联需求';
$lang->project->createTask = '添加任务';
$lang->project->goback = '返回项目首页(5秒后将自动跳转)';
$lang->project->linkProduct = '选择产品关联...';
$lang->project->withWeekend = '显示周末';
$lang->project->noWeekend = '去除周末';
/* 统计。*/
$lang->project->charts = new stdclass();
+34 -14
View File
@@ -1303,7 +1303,6 @@ class projectModel extends model
if($count > $itemCounts) break;
if($date > $project->end) continue;
$set->name = $this->getMicTime($set->name);
$burnData[$date] = $set;
$count++;
}
@@ -1312,19 +1311,6 @@ class projectModel extends model
return $burnData;
}
/**
* Get microsecond from date.
*
* @param string|int $date
* @access public
* @return void
*/
public function getMicTime($date)
{
if(is_numeric($date)) return (string)$date . '000';
return (string)strtotime("$date UTC") . '000';
}
/**
* Process burndown datas when the sets is smaller than the itemCounts.
*
@@ -1495,4 +1481,38 @@ class projectModel extends model
if($extra != '') $link = helper::createLink($module, $method, "projectID=%s&type=$extra");
return $link;
}
/**
* Get no weekend date
*
* @param string $begin
* @param string $end
* @param string $type
* @access public
* @return array
*/
public function getDateList($begin, $end, $type)
{
$dateList = array();
$date = $begin;
while($date <= $end)
{
$timestamp = strtotime($date);
if($type == 'noweekend')
{
$weekDay = date('w', $timestamp);
if($weekDay == 6 or $weekDay == 0)
{
$date = date('Y-m-d', $timestamp + 24 * 3600);
continue;
}
}
$dateList[] = $date;
$date = date('Y-m-d', $timestamp + 24 * 3600);
}
return $dateList;
}
}
+1
View File
@@ -17,6 +17,7 @@
<?php
echo $charts;
common::printLink('project', 'computeBurn', 'reload=yes', $lang->project->computeBurn, 'hiddenwin');
echo html::a(inlink('burn', "projectID=$projectID&type=" . ($type == 'noweekend' ? 'withweekend' : 'noweekend')), ($type == 'noweekend' ? $lang->project->withWeekend : $lang->project->noWeekend));
echo $lang->project->howToUpdateBurn;
?>
</div>
+10 -20
View File
@@ -77,18 +77,18 @@ $chartID.render("$divID");
EOT;
}
public function createJSChartFlot($projectName, $flotJSON, $count, $width = 'auto', $height = 500)
public function createJSChartFlot($projectName, $flotJSON, $width = 'auto', $height = 500)
{
$this->app->loadLang('project');
$this->app->loadConfig('project');
$jsRoot = $this->app->getWebRoot() . 'js/';
$width = $width . 'px';
$height = $height . 'px';
$maxDays = $this->config->project->maxBurnDay;
$dataJSON = $flotJSON['data'];
$limitJSON = $flotJSON['limit'];
$baselineJSON = $flotJSON['baseline'];
$dateListJSON = $flotJSON['dateList'];
$ticksJSON = $flotJSON['ticks'];
return <<<EOT
<!--[if lte IE 8]><script language="javascript" type="text/javascript" src="{$jsRoot}jquery/flot/excanvas.min.js"></script><![endif]-->
<script language="javascript" type="text/javascript" src="{$jsRoot}jquery/flot/jquery.flot.min.js"></script>
@@ -100,6 +100,8 @@ $(function ()
var data = $dataJSON;
var limit = $limitJSON;
var baseline = $baselineJSON;
var dateList = $dateListJSON;
var ticks = $ticksJSON;
function showTooltip(x, y, contents)
{
$('<div id="tooltip">' + contents + '</div>').css
@@ -113,26 +115,14 @@ $(function ()
'background-color': '#fee',
opacity: 0.80
}).appendTo("body").fadeIn(200);
}
}
if($count < $maxDays)
{
var options = {
series: {lines:{show: true, lineWidth: 2}, points: {show: true},hoverable: true},
legend: {noColumns: 1},
grid: { hoverable: true, clickable: true },
xaxis: {mode: "time", timeformat: "%m-%d", tickSize:[1, "day"]},
xaxis: { ticks:ticks, tickFormatter: function(val) {tick = new Date(dateList[val]);;if(dateList[val] != undefined){return (tick.getMonth() + 1) + '-' + tick.getDate()}else{return ''}}},
yaxis: {mode: null, min: 0, minTickSize: [1, "day"]}};
}
else
{
var options = {
series: {lines:{show: true, lineWidth: 5}, points: {show: true},hoverable: true},
legend: {noColumns: 1},
grid: { hoverable: true, clickable: true },
xaxis: {mode: "time", timeformat: "%m-%d", ticks:$maxDays, minTickSize:[1, "day"]},
yaxis: {mode: null, min: 0, minTickSize: [1, "day"]}};
}
var placeholder = $("#placeholder");
$("#placeholder").bind("plotselected", function (event, ranges)
@@ -216,12 +206,12 @@ EOT;
return $data;
}
public function createSingleJSON($sets)
public function createSingleJSON($sets, $dateList)
{
$data = '[';
foreach($sets as $set)
foreach($dateList as $i => $date)
{
$data .= "[$set->name, $set->value],";
if(isset($sets[$date]))$data .= "[$i, {$sets[$date]->value}],";
}
$data = rtrim($data, ',');
$data .= ']';