From d0041a5abbe95fb9dbbcb7fb8014124c57b66c54 Mon Sep 17 00:00:00 2001 From: wangyidong Date: Fri, 14 Dec 2012 05:53:35 +0000 Subject: [PATCH] * finish task #963. --- module/project/config.php | 1 + module/project/control.php | 33 ++++++++++++++++++++---- module/project/model.php | 45 +++++++++++++++++++-------------- module/report/model.php | 52 +++++++++++++++++++++++++++++--------- 4 files changed, 95 insertions(+), 36 deletions(-) diff --git a/module/project/config.php b/module/project/config.php index ba10ec8c99..024e6882c6 100644 --- a/module/project/config.php +++ b/module/project/config.php @@ -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'); diff --git a/module/project/control.php b/module/project/control.php index 327293f663..5905f24b70 100644 --- a/module/project/control.php +++ b/module/project/control.php @@ -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; diff --git a/module/project/model.php b/module/project/model.php index 9e33bd33dd..f2f9f517ca 100644 --- a/module/project/model.php +++ b/module/project/model.php @@ -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'; } /** diff --git a/module/report/model.php b/module/report/model.php index 3eadea83f6..20c8815433 100644 --- a/module/report/model.php +++ b/module/report/model.php @@ -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 << @@ -91,7 +97,9 @@ return << $(function () { - var data = [{data: $dataJSON}]; + var data = $dataJSON; + var limit = $limitJSON; + var refline = $reflineJSON; function showTooltip(x, y, contents) { $('
' + contents + '
').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 .= ']';