$bar = new GanttBar($row++, array($name, $startdate->format($df), $enddate->format($df), $actual_enddate->format($df)), $start, $actual_end, $cap, 0.6); $bar->progress->Set(min($progress / 100, 1)); if (is_file(TTF_DIR . "FreeSans.ttf")) { $bar->title->SetFont(FF_CUSTOM, FS_NORMAL, 9); } $bar->SetFillColor('#' . $p['project_color_identifier']); $bar->SetPattern(BAND_SOLID, '#' . $p['project_color_identifier']); //adding captions $bar->caption = new TextProperty($caption); $bar->caption->Align('left', 'center'); $bar->caption->SetFont(FF_CUSTOM, FS_NORMAL, 8); // gray out templates, completes, on ice, on hold if ($p['project_status'] != '3' || $p['project_status'] == '7') { $bar->caption->SetColor('darkgray'); $bar->title->SetColor('darkgray'); $bar->SetColor('darkgray'); $bar->SetFillColor('gray'); //$bar->SetPattern(BAND_SOLID,'gray'); $bar->progress->SetFillColor('darkgray'); $bar->progress->SetPattern(BAND_SOLID, 'darkgray', 98); } $graph->Add($bar); // If showAllGant checkbox is checked if ($showAllGantt) { // insert tasks into Gantt Chart // select for tasks for each project $q->addTable('tasks', 't'); $q->addQuery('DISTINCT t.task_id, t.task_name, t.task_start_date, t.task_end_date' . ', t.task_milestone, t.task_dynamic'); $q->addJoin('projects', 'p', 'p.project_id = t.task_project'); $q->addWhere('p.project_id = ' . $p['project_id']); $q->addOrder($sortTasksByName ? 't.task_name' : 't.task_end_date ASC');
/** * creates the image for the gantt chart * * @param $_params array containing projectdata, start- and enddate * @param $_filename filename for the image, if empty image gets printed to browser * @author Lars Kneschke / Bettina Gille * @returns nothing - writes image to disk */ function show_graph($params, $_filename = '') { $modernJPGraph = false; // no gd support if (!function_exists('imagecopyresampled')) { return false; } DEFINE("TTF_DIR", PHPGW_SERVER_ROOT . "/projects/ttf-bitstream-vera-1.10/"); if (file_exists(PHPGW_SERVER_ROOT . '/../jpgraph/src/jpgraph.php')) { include PHPGW_SERVER_ROOT . '/../jpgraph/src/jpgraph.php'; include PHPGW_SERVER_ROOT . '/../jpgraph/src/jpgraph_gantt.php'; } else { include PHPGW_SERVER_ROOT . '/projects/inc/jpgraph-1.5.2/src/jpgraph.php'; include PHPGW_SERVER_ROOT . '/projects/inc/jpgraph-1.5.2/src/jpgraph_gantt.php'; } //_debug_array($params); $project_array = $params['project_array']; $sdate = $params['sdate']; $edate = $params['edate']; $showMilestones = $params['showMilestones']; $showResources = $params['showResources']; $bocalendar = CreateObject('calendar.bocalendar'); $this->graph = CreateObject('phpgwapi.gdgraph', $this->debug); $bolink = CreateObject('infolog.bolink'); //$this->boprojects->order = 'parent'; $this->boprojects->limit = False; $this->boprojects->html_output = False; if (is_array($project_array)) { $projects = array(); foreach ($project_array as $pro) { $project = $this->boprojects->list_projects(array('action' => 'mainsubsorted', 'project_id' => $pro, 'mstones_stat' => True)); if (is_array($project)) { $i = count($projects); for ($k = 0; $k < count($project); $k++) { $projects[$i + $k] = $project[$k]; } } } } if (is_array($projects)) { $modernJPGraph = version_compare('1.13', JPG_VERSION); $sdate = $sdate + 60 * 60 * $GLOBALS['phpgw_info']['user']['preferences']['common']['tz_offset']; $sdateout = $GLOBALS['phpgw']->common->show_date($sdate, $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']); $edate = $edate + 60 * 60 * $GLOBALS['phpgw_info']['user']['preferences']['common']['tz_offset']; $edateout = $GLOBALS['phpgw']->common->show_date($edate, $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']); # $this->graph->title = lang('Gantt chart from %1 to %2',$sdateout,$edateout); // Standard calls to create a new graph if ($modernJPGraph) { $graph = new GanttGraph(940, -1, "auto"); } else { $graph = new GanttGraph(-1, -1, "auto"); } $graph->SetShadow(); $graph->SetBox(); $duration = $edate - $sdate; if ($duration < 5958000) { $graph->ShowHeaders(GANTT_HYEAR | GANTT_HMONTH | GANTT_HDAY | GANTT_HWEEK); if ($modernJPGraph) { $graph->scale->week->SetStyle(WEEKSTYLE_FIRSTDAYWNBR); } else { $graph->scale->week->SetStyle(WEEKSTYLE_FIRSTDAY); } } elseif ($duration < 13820400) { $graph->scale->week->SetStyle(WEEKSTYLE_FIRSTDAY); $graph->ShowHeaders(GANTT_HYEAR | GANTT_HMONTH | GANTT_HWEEK); } else { $graph->ShowHeaders(GANTT_HYEAR | GANTT_HMONTH); } // For the week we choose to show the start date of the week // the default is to show week number (according to ISO 8601) #$graph->scale->SetDateLocale('de_DE'); // Change the scale font $graph->scale->week->SetFont(FF_VERA, FS_NORMAL, 8); $graph->scale->year->SetFont(FF_VERA, FS_BOLD, 10); // Titles for chart $graph->title->Set(lang('project overview')); $graph->subtitle->Set(lang('from %1 to %2', $sdateout, $edateout)); $graph->title->SetFont(FF_VERA, FS_BOLD, 12); $graph->subtitle->SetFont(FF_VERA, FS_BOLD, 10); // set the start and end date // add one day to the end is needed internaly by jpgraph $graph->SetDateRange(date('Y-m-d 00:00:00', $sdate), date('Y-m-d', $edate + 86400)); foreach ($projects as $pro) { $ptime_pro = $this->boprojects->return_value('ptime', $pro[project_id]); $acc = $this->boprojects->get_budget(array('project_id' => $pro[project_id], 'ptime' => $ptime_pro)); if ($ptime_pro > 0) { $finnishedPercent = 100 / $ptime_pro * $acc[uhours_jobs_wminutes]; } else { $finnishedPercent = 0; } $previous = ''; if ($pro['previous'] > 0) { $previous = $this->boprojects->read_single_project($pro['previous']); $spro[] = array('title' => str_repeat(' ', $spro['level']) . '[!]' . $previous['title'], 'extracolor' => 'darkorange', 'sdate' => $previous['sdate'], 'edate' => $previous['edate'], 'pro_id' => $previous['project_id'], 'f_sdate' => $pro['sdate']); $color_legend['previous'] = array('title' => '[!]' . lang('previous project'), 'extracolor' => 'darkorange'); } // add a empty row before new project if ($pro['level'] == 0 && $counter > 0) { $counter++; } $spro = array('title' => $pro['title'], 'sdate' => $pro['sdate'], 'edate' => $pro['edate'] ? $pro['edate'] : mktime(0, 0, 0, date('m'), date('d'), date('Y')), 'color' => $pro['level'], 'pro_id' => $pro['project_id'], 'previous' => $pro['previous']); // convert title to iso-8859-1 $spro[title] = $this->botranslation->convert($spro[title], $this->displayCharset, 'iso-8859-1'); if ($spro[edate] < $sdate) { continue; } if ($spro[edate] > $edate) { $spro[edate] = $edate; } if ($spro[sdate] < $sdate) { $spro[sdate] = $sdate; } $bar = new GanttBar($counter, $spro[title], date('Y-m-d', $spro[sdate]), date('Y-m-d', $spro[edate]), round($finnishedPercent) . '%', 0.5); // mark beginn of new project bold if ($pro['level'] == 0) { $bar->title->SetFont(FF_VERA, FS_BOLD, 9); #$bar->title->SetColor("#9999FF"); $bar->SetPattern(BAND_SOLID, "#9999FF"); } else { // For illustration lets make each bar be red with yellow diagonal stripes $bar->SetPattern(BAND_SOLID, "#ccccFF"); #$bar->title->SetColor("#ccccFF"); } // To indicate progress each bar can have a smaller bar within // For illustrative purpose just set the progress to 50% for each bar $bar->progress->SetHeight(0.2); $bar->SetColor('#777777'); if ($finnishedPercent > 100) { $bar->progress->Set(1); #$bar->progress->SetPattern(GANTT_SOLID,"darkred",98); $bar->caption->SetColor("red"); } else { $bar->progress->Set($finnishedPercent / 100); #$bar->progress->SetPattern(GANTT_SOLID,"darkgreen",98); } $bar->caption->SetFont(FF_VERA, FS_NORMAL, 8); // ... and add the bar to the gantt chart $graphs['bars'][] = $bar; #$graph->Add($bar); $counter++; // check for Resources if ($showResources == 'true') { $linkedObjects = $bolink->get_links('projects', $pro[project_id]); $projectACL = $this->boprojects->get_acl_for_project($pro[project_id]); if (is_array($projectACL)) { // if beginn foreach ($projectACL as $accountID) { #_debug_array($projectData); $accountData = CreateObject('phpgwapi.accounts', $accountID); $accountData->read_repository(); $accountName = $GLOBALS['phpgw']->common->display_fullname($accountData->data['account_lid'], $accountData->data['firstname'], $accountData->data['lastname']); $calData = array('syear' => date('Y', $sdate), 'smonth' => date('m', $sdate), 'sday' => date('d', $sdate), 'eyear' => date('Y', $edate), 'emonth' => date('m', $edate), 'eday' => date('d', $edate), 'owner' => array($accountID)); $calEntries = $bocalendar->store_to_cache($calData); $bocalendar->remove_doubles_in_cache(date('Y', $sdate) . date('m', $sdate) . date('d', $sdate), date('Y', $edate) . date('m', $edate) . date('d', $edate)); $calEntries = $bocalendar->cached_events; #_debug_array($calEntries); if (is_array($calEntries) && count($calEntries)) { #_debug_array($calEntries); foreach ($calEntries as $calDayDate => $calDayEntries) { foreach ($calDayEntries as $calDayEntry) { if ($calDayEntry['recur_type']) { $bocalendar->set_recur_date($calDayEntry, $calDayDate); } #_debug_array($calDayEntry); if (!$bocalendar->rejected_no_show($calDayEntry)) { $startDate = date('Y-m-d H:i:s', mktime($calDayEntry['start']['hour'], $calDayEntry['start']['min'], $calDayEntry['start']['sec'], $calDayEntry['start']['month'], $calDayEntry['start']['mday'], $calDayEntry['start']['year'])); $endDate = date('Y-m-d H:i:s', mktime($calDayEntry['end']['hour'], $calDayEntry['end']['min'], $calDayEntry['end']['sec'], $calDayEntry['end']['month'], $calDayEntry['end']['mday'], $calDayEntry['end']['year'])); #$endDate = $startDate+1000; #_debug_array($startDate); $bar = new GanttBar($counter, str_repeat(' ', $pro['level'] + 1) . $accountName, $startDate, $endDate, '', 0.5); $bar->SetPattern(BAND_SOLID, "#DDDDDD"); $bar->SetColor('#CCCCCC'); #$bar->SetShadow(true,"darkgray"); if (count($projectLinks = $bolink->get_links('calendar', $calDayEntry['id'], 'projects'))) { $projectLinks = array_flip($projectLinks); #_debug_array($projectLinks); if (isset($projectLinks[$pro[project_id]])) { $bar->SetPattern(BAND_SOLID, "#33FF33"); $bar->SetColor('#33FF33'); } } $graphs['bars'][] = $bar; #$graph->Add($bar); } else { print "rejected<br>"; } } } $counter++; } } } // if end } // check for milstones if (is_array($pro['mstones']) && $showMilestones == 'true') { $msColor = "#999999"; foreach ($pro['mstones'] as $ms) { if ($sdate < $ms['edate'] && $ms['edate'] <= $edate) { $ms[title] = $this->botranslation->convert($ms[title], $this->displayCharset, 'iso-8859-1'); $msData = array('title' => $ms['title'], 'extracolor' => 'yellow', 'edate' => $ms['edate'], 'pro_id' => $pro['project_id']); // Create a milestone mark $ms = new MileStone($counter, str_repeat(' ', $pro['level'] + 1) . lang('Milestone'), date('Y-m-d', $msData['edate']), $msData['title']); $ms->caption->SetFont(FF_VERA, FS_NORMAL, 8); $ms->title->SetFont(FF_VERA, FS_NORMAL, 8); $ms->mark->SetColor($msColor); $ms->mark->SetFillColor('#EEEEEE'); $graphs['ms'][$counter] = $ms; // Create a vertical line to emphasize the milestone $vl = new GanttVLine(date('Y-m-d', $msData[edate]), '', $msColor, 2); $vl->SetDayOffset(0.5); // Center the line in the day $graphs['vl'][$counter] = $vl; $counter++; } } } } // add the vertical lines if (is_array($graphs['vl'])) { foreach ($graphs['vl'] as $graphCounter => $graphPointer) { $graph->Add($graphPointer); } } // add the milestones if (is_array($graphs['ms'])) { foreach ($graphs['ms'] as $graphCounter => $graphPointer) { $graph->Add($graphPointer); } } // add the resources if (is_array($graphs['bars'])) { foreach ($graphs['bars'] as $graphCounter => $graphPointer) { $graph->Add($graphPointer); } } #$graph->Stroke(PHPGW_SERVER_ROOT . SEP . 'phpgwapi' . SEP . 'images' . SEP . 'draw_tmp.png'); $graph->Stroke($_filename); } }
public function addBar(array $columnValues, $caption = '', $height = '0.6', $barcolor = 'FFFFFF', $active = true, $progress = 0) { foreach ($columnValues as $name => $value) { switch ($name) { case 'start_date': $start = $value; $startDate = new CDate($value); $rowValues[] = $startDate->format($this->df); break; case 'end_date': $endDate = new CDate($value); $rowValues[] = $endDate->format($this->df); break; case 'actual_end': $actual_end = $value; $actual_endDate = new CDate($value); $rowValues[] = $actual_endDate->format($this->df); break; case 'project_name': case 'task_name': default: $rowValues[] = $value; } } $bar = new GanttBar($this->rowCount++, $rowValues, $start, $actual_end, $caption, $height); $bar->progress->Set(min($progress / 100, 1)); $bar->title->SetFont(FF_CUSTOM, FS_NORMAL, 9); $bar->title->SetColor(bestColor('#ffffff', '#' . $barcolor, '#000000')); $bar->SetFillColor('#' . $barcolor); $bar->SetPattern(BAND_SOLID, '#' . $barcolor); if (0.1 == $height) { $bar->rightMark->Show(); $bar->rightMark->SetType(MARK_RIGHTTRIANGLE); $bar->rightMark->SetWidth(3); $bar->rightMark->SetColor('black'); $bar->rightMark->SetFillColor('black'); $bar->leftMark->Show(); $bar->leftMark->SetType(MARK_LEFTTRIANGLE); $bar->leftMark->SetWidth(3); $bar->leftMark->SetColor('black'); $bar->leftMark->SetFillColor('black'); $bar->SetPattern(BAND_SOLID, 'black'); } //adding captions $bar->caption = new TextProperty($caption); $bar->caption->Align('left', 'center'); if (is_file(TTF_DIR . 'FreeSans.ttf')) { $bar->caption->SetFont(FF_CUSTOM, FS_NORMAL, 8); } // gray out templates, completes, on ice, on hold if (!$active) { $bar->caption->SetColor('darkgray'); $bar->title->SetColor('darkgray'); $bar->SetColor('darkgray'); $bar->SetFillColor('gray'); $bar->progress->SetFillColor('darkgray'); $bar->progress->SetPattern(BAND_SOLID, 'darkgray', 98); } $this->graph->Add($bar); }
$graph->scale->month->SetFontColor("white"); $graph->scale->month->SetBackgroundColor("blue"); // 0 % vertical label margin $graph->SetLabelVMarginFactor(1); // 1=default value // Format the bar for the first activity // ($row,$title,$startdate,$enddate) $activity1 = new GanttBar(0, "Activity 1", "2001-12-21", "2001-12-26", ""); // Yellow diagonal line pattern on a red background $activity1->SetPattern(BAND_RDIAG, "yellow"); $activity1->SetFillColor("red"); // Format the bar for the first activity // ($row,$title,$startdate,$enddate) $break1 = new GanttBar(0, '', "2001-12-27", "2001-12-30", ""); $break1->SetBreakStyle(true, 'dotted', 2); $break1->SetColor('red'); $graph->Add($break1); // Format the bar for the second activity // ($row,$title,$startdate,$enddate) $activity2 = new GanttBar(0, "", "2001-12-31", "2002-01-2", "[BO]"); // ADjust font for caption $activity2->caption->SetFont(FF_ARIAL, FS_BOLD); $activity2->caption->SetColor("darkred"); // Yellow diagonal line pattern on a red background $activity2->SetPattern(BAND_RDIAG, "yellow"); $activity2->SetFillColor("red"); // Finally add the bar to the graph $graph->Add($activity1); $graph->Add($activity2); // ... and display it $graph->Stroke();