* finish task #963.

This commit is contained in:
wangyidong
2012-12-14 05:53:35 +00:00
parent 152b5921b2
commit d0041a5abb
4 changed files with 95 additions and 36 deletions
+1
View File
@@ -2,6 +2,7 @@
$config->project = new stdclass();
$config->project->defaultWorkhours = 7;
$config->project->orderBy = 'isDone, `order`, status';
$config->project->maxBurnDay = '30';
global $lang, $app;
$app->loadLang('task');
+28 -5
View File
@@ -647,7 +647,9 @@ class project extends control
public function burn($projectID = 0)
{
$this->loadModel('report');
$project = $this->commonAction($projectID);
$project = $this->commonAction($projectID);
$projectInfo = $this->project->getByID($projectID);
$maxDays = $this->config->project->maxBurnDay;
/* Header and position. */
$header['title'] = $project->name . $this->lang->colon . $this->lang->project->burn;
@@ -659,11 +661,32 @@ class project extends control
//$charts = $this->report->createJSChart('line', $dataXML, 700, 350);
/* Create charts by flot. */
$sets = $this->project->getBurnDataFlot($project->id);
$count = $sets['count'];
unset($sets['count']);
$sets = $this->project->getBurnDataFlot($project->id);
$count = count($sets);
$dataJSON = $this->report->createSingleJSON($sets);
$charts = $this->report->createJSChartFlot($project->name, $dataJSON, $count, 700, 350);
$limitJSON = '[]';
$reflineJSON = '[]';
$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);
$reflineJSON = "[[$beginMicTime, $firstBurn->value], [$endMicTime, 0]]";
}
elseif($count <= $maxDays)
{
$limitJSON = "[[$beginMicTime, 0], [$maxDayMicTime, 0]]";
}
$flotJSON['data'] = $dataJSON;
$flotJSON['limit'] = $limitJSON;
$flotJSON['refline'] = $reflineJSON;
$charts = $this->report->createJSChartFlot($project->name, $flotJSON, $count, 900, 400);
/* Assign. */
$this->view->header = $header;
+26 -19
View File
@@ -1060,30 +1060,37 @@ class projectModel extends model
{
/* Get project and burn counts. */
$project = $this->getById($projectID);
$burnCounts = $this->dao->select('count(*) AS counts')->from(TABLE_BURN)->where('project')->eq($projectID)->fetch('counts');
/* If the burnCounts > $itemCounts, get the latest $itemCounts records. */
$sql = $this->dao->select('date AS name, `left` AS value')->from(TABLE_BURN)->where('project')->eq((int)$projectID);
if($burnCounts > $itemCounts)
{
$sets = $sql->orderBy('date DESC')->limit($itemCounts)->fetchAll('name');
$sets = array_reverse($sets);
}
else
{
/* The burnCounts < itemCounts, after getting from the db, padding left dates. */
$sets = $sql->orderBy('date ASC')->fetchAll('name');
$sets = $this->processBurnData($sets, $itemCounts, $project->begin, $project->end);
}
$sets = $this->dao->select('date AS name, `left` AS value')->from(TABLE_BURN)->where('project')->eq((int)$projectID)->orderBy('date DESC')->fetchAll('name');
$count = 0;
foreach($sets as $set)
$count = 0;
$burnData = array();
foreach($sets as $date => $set)
{
$set->name = (string)strtotime("$set->name UTC") . '000';
$count ++;
if($count > $itemCounts) break;
if($date > $project->end) continue;
$set->name = $this->getMicTime($set->name);
$burnData[$date] = $set;
$count++;
}
$sets['count'] = $count;
return $sets;
$burnData = array_reverse($burnData);
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';
}
/**
+40 -12
View File
@@ -77,12 +77,18 @@ $chartID.render("$divID");
EOT;
}
public function createJSChartFlot($projectName, $dataJSON, $count, $width = 'auto', $height = 500)
public function createJSChartFlot($projectName, $flotJSON, $count, $width = 'auto', $height = 500)
{
$this->app->loadLang('project');
$jsRoot = $this->app->getWebRoot() . 'js/';
$width = $width . 'px';
$height = $height . 'px';
$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'];
$reflineJSON = $flotJSON['refline'];
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>
@@ -91,7 +97,9 @@ return <<<EOT
<script type="text/javascript">
$(function ()
{
var data = [{data: $dataJSON}];
var data = $dataJSON;
var limit = $limitJSON;
var refline = $reflineJSON;
function showTooltip(x, y, contents)
{
$('<div id="tooltip">' + contents + '</div>').css
@@ -106,7 +114,8 @@ $(function ()
opacity: 0.80
}).appendTo("body").fadeIn(200);
}
if($count < 20)
if($count < $maxDays)
{
var options = {
series: {lines:{show: true, lineWidth: 2}, points: {show: true},hoverable: true},
@@ -121,18 +130,37 @@ $(function ()
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", ticks:20, minTickSize:[1, "day"]},
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)
var placeholder = $("#placeholder");
$("#placeholder").bind("plotselected", function (event, ranges)
{
plot = $.plot(placeholder, data, $.extend(true, {}, options, {xaxis: { min: ranges.xaxis.from, max: ranges.xaxis.to } }));
});
var plot = $.plot(placeholder, data, options);
var plot = $.plot(placeholder, [
{
data:data,
lines: {show: true},
points: {show: true}
},
{
data:refline,
color: "rgb(200, 200, 200)",
hoverable: false,
lines: {show: true, lineWidth:0.1, lineType:'dashed'},
points: {show: false}
},
{
data:limit,
lines: {show: false},
points: {show: false}
}
], options);
var previousPoint = null;
$("#placeholder").bind("plothover", function (event, pos, item)
placeholder.bind("plothover", function(event, pos, item)
{
$("#x").text(pos.x.toFixed(2));
$("#y").text(pos.y.toFixed(2));
@@ -192,7 +220,7 @@ EOT;
$data = '[';
foreach($sets as $set)
{
$data .= " [$set->name, $set->value],";
$data .= "[$set->name, $set->value],";
}
$data = rtrim($data, ',');
$data .= ']';