diff --git a/module/project/control.php b/module/project/control.php index 5973c5bb3f..646c666921 100644 --- a/module/project/control.php +++ b/module/project/control.php @@ -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(); } diff --git a/module/project/lang/en.php b/module/project/lang/en.php index 281224620f..33cd19a0a9 100644 --- a/module/project/lang/en.php +++ b/module/project/lang/en.php @@ -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(); diff --git a/module/project/lang/zh-cn.php b/module/project/lang/zh-cn.php index 5682955c6c..8304750e66 100644 --- a/module/project/lang/zh-cn.php +++ b/module/project/lang/zh-cn.php @@ -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(); diff --git a/module/project/model.php b/module/project/model.php index e3c4937343..4a6d2cbf9c 100644 --- a/module/project/model.php +++ b/module/project/model.php @@ -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; + } } diff --git a/module/project/view/burn.html.php b/module/project/view/burn.html.php index e8fdbecfab..0cece7e6a6 100644 --- a/module/project/view/burn.html.php +++ b/module/project/view/burn.html.php @@ -17,6 +17,7 @@ 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; ?> diff --git a/module/report/model.php b/module/report/model.php index 0a3f5e5b93..966d2ca469 100644 --- a/module/report/model.php +++ b/module/report/model.php @@ -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 << @@ -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) { $('
' + contents + '
').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 .= ']';