* finish the task #520.

This commit is contained in:
shiyangyangwork@yahoo.cn
2011-09-18 00:20:26 +00:00
parent 64686c942a
commit 1e4caf287b
3 changed files with 139 additions and 3 deletions

View File

@@ -416,9 +416,13 @@ class project extends control
$position[] = html::a($this->createLink('project', 'browse', "projectID=$projectID"), $project->name);
$position[] = $this->lang->project->burn;
/* Create charts. */
$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);
/* 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);
/* Create charts by flot. */
$dataXML= $this->report->createSingleXMLFlot($this->project->getBurnDataFlot($project->id));
$charts = $this->report->createJSChartFlot($project->name, $dataXML, 700, 350);
/* Assign. */
$this->view->header = $header;

View File

@@ -287,8 +287,13 @@ class projectModel extends model
{
if($i <= $counts and $project->status == 'doing')
{
/* By flash.*/
$dataXML = $this->report->createSingleXML($this->getBurnData($project->id), $this->lang->project->charts->burn->graph, $this->lang->report->singleColor);
$charts[$project->id] = $this->report->createJSChart('line', $dataXML, 'auto', 210);
/* By flot.*/
//$dataXML = $this->report->createSingleXMLFlot($this->getBurnData($project->id));
//$charts[$project->id] = $this->report->createJSChartFlot($project->name, $dataXML, 'auto', 210);
}
}
else
@@ -740,6 +745,53 @@ class projectModel extends model
return $sets;
}
public function getBurnDataFlot($projectID = 0, $itemCounts = 30)
{
/* 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');
$current = helper::today();
if($project->end != '0000-00-00')
{
$period = helper::diffDate($project->end, $project->begin) + 1;
$counts = $period > $itemCounts ? $itemCounts : $period;
}
else
{
$counts = $itemCounts;
}
for($i = 0; $i < $counts - $burnCounts; $i ++)
{
if(helper::diffDate($current, $project->end) > 0) break;
if(!isset($sets[$current]))
{
$sets[$current]->name = $current;
$sets[$current]->value = '';
}
$nextDay = date(DT_DATE1, strtotime('next day', strtotime($current)));
$current = $nextDay;
}
}
foreach($sets as $set)
{
$set->name = (string)strtotime("$set->name UTC") . '000';
}
return $sets;
}
/**
* Get taskes by search.
*

View File

@@ -77,6 +77,74 @@ $chartID.render("$divID");
EOT;
}
public function createJSChartFlot($projectName, $dataXML, $width = 'auto', $height = 500)
{
$this->app->loadLang('project');
$jsRoot = $this->app->getWebRoot() . 'js/';
$width = $width . 'px';
$height = $height . 'px';
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.js"></script>
<script language="javascript" type="text/javascript" src="{$jsRoot}jquery/flot/jquery.flot.js"></script>
<h1>$projectName {$this->lang->project->burn}</h1>
<div id="placeholder" style="width:$width;height:$height;margin:0 auto"></div>
<script type="text/javascript">
$(function ()
{
var data = [{data: $dataXML},];
function showTooltip(x, y, contents)
{
$('<div id="tooltip">' + contents + '</div>').css
({
position: 'absolute',
display: 'none',
top: y + 5,
left: x + 5,
border: '1px solid #fdd',
padding: '2px',
'background-color': '#fee',
opacity: 0.80
}).appendTo("body").fadeIn(200);
}
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"]},
yaxis: {min: 0, minTickSize: 1}};
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 previousPoint = null;
$("#placeholder").bind("plothover", function (event, pos, item)
{
$("#x").text(pos.x.toFixed(2));
$("#y").text(pos.y.toFixed(2));
if (item)
{
if (previousPoint != item.dataIndex)
{
previousPoint = item.dataIndex;
$("#tooltip").remove();
var x = item.datapoint[0].toFixed(2), y = item.datapoint[1].toFixed(2);
showTooltip(item.pageX, item.pageY, y);
}
}
});
});
</script>
EOT;
}
/**
* Create xml data of single charts.
*
@@ -109,6 +177,18 @@ EOT;
return $data;
}
public function createSingleXMLFlot($sets)
{
$data = '[';
foreach($sets as $set)
{
$data .= " [$set->name, $set->value],";
}
$data = rtrim($data, ',');
$data .= ']';
return $data;
}
/**
* Create the js code to render chart.
*