Skip to content
Permalink
Browse files

cleaned up the gantt chart generation to make sure multi-page charts …

…worked

Resolves http://bugs.web2project.net/view.php?id=1257 and a bunch of
others
  • Loading branch information...
caseysoftware committed Jun 15, 2014
1 parent 7bf84b1 commit c7c31631172062124c55107df92b88847ea68e61
Showing with 28 additions and 23 deletions.
  1. +2 −2 classes/w2p/Output/GanttRenderer.class.php
  2. +13 −0 includes/cleanup_functions.php
  3. +13 −21 modules/tasks/gantt_pdf.php
@@ -182,7 +182,7 @@ public function addBar(array $columnValues, $caption = '', $height = '0.6',
$this->rowMap[$identifier] = $this->rowCount;
$bar->progress->Set(min(($progress / 100), 1));
$bar->title->SetFont(FF_CUSTOM, FS_NORMAL, 9);
$bar->title->SetFont(FF_CUSTOM, FS_NORMAL, 10);
$bar->title->SetColor(bestColor('#ffffff', '#' . $barcolor, '#000000'));
$bar->SetFillColor('#' . $barcolor);
$bar->SetPattern(BAND_SOLID, '#' . $barcolor);
@@ -230,7 +230,7 @@ public function addMilestone(array $columnValues, $start,
$tStartObj = new w2p_Utilities_Date($start);
$bar = new MileStone($this->rowCount++, $columnValues, $start, $tStartObj->format($this->df));
$bar->title->SetFont(FF_CUSTOM, FS_NORMAL, 9);
$bar->title->SetFont(FF_CUSTOM, FS_NORMAL, 10);
$bar->title->SetColor($color);
$bar->mark->SetType(MARK_DIAMOND);
$bar->mark->SetWidth(10);
@@ -146,6 +146,19 @@ function smart_slice($arr, $showNoMilestones, $notUsed, $day_diff)
return $gtask_sliced ;
}
function dumb_slice( $gantt_arr, $length = 25 )
{
$sliced_array = array();
$pages = (int) count($gantt_arr) / $length;
for ( $i = 0; $i <= $pages; $i++ ) {
$sliced_array[] = array_slice($gantt_arr, $i * $length, $length);
}
return $sliced_array;
}
/**
*
* END OF GANTT PDF UTILITY FUNCTIONS
@@ -104,10 +104,11 @@
}
$width = 1600;
$start_date = w2PgetParam($_GET, 'start_date', $start_min);
$end_date = w2PgetParam($_GET, 'end_date', $end_max);
$s1 = ($start_date) ? new w2p_Utilities_Date($start_date) : new w2p_Utilities_Date();
$e1 = ($end_date) ? new w2p_Utilities_Date($end_date) : new w2p_Utilities_Date();
$gantt_start_date = w2PgetParam($_GET, 'start_date', $start_min);
$gantt_end_date = w2PgetParam($_GET, 'end_date', $end_max);
$s1 = ($gantt_start_date) ? new w2p_Utilities_Date($gantt_start_date) : new w2p_Utilities_Date();
$e1 = ($gantt_end_date) ? new w2p_Utilities_Date($gantt_end_date) : new w2p_Utilities_Date();
//consider critical (concerning end date) tasks as well
if ($caller != 'todo') {
@@ -122,22 +123,12 @@
* Prepare Gantt_chart loop
*/
$gtask_sliced = array() ;
$gtask_sliced = smart_slice( $gantt_arr, $showNoMilestones, $printpdfhr, $e1->dateDiff($s1) );
$gtask_sliced = dumb_slice($gantt_arr, 30);// smart_slice( $gantt_arr, $showNoMilestones, $printpdfhr, $e1->dateDiff($s1) );
$page = 0 ; // Numbering of output files
$outpfiles = array(); // array of output files to be returned to caller
$taskcount = 0 ;
// Create task_index array
$ctflag = false ;
if ( count( $gtask_sliced ) > 1 ) {
$gantt_arr_count = count($gantt_arr);
for ( $i = 0; $i < $gantt_arr_count; $i++ ) {
$task_index[$gantt_arr[$i][0]['task_id']] = $i+1 ;
}
$ctflag = true;
}
foreach ($gtask_sliced as $gts) {
if (!$start_date || !$end_date) {
if (!$gantt_start_date || !$gantt_end_date) {
// find out DateRange from gant_arr
$d_start = new w2p_Utilities_Date();
$d_end = new w2p_Utilities_Date();
@@ -181,12 +172,12 @@
$columnSizes = array(180, 135, 40, 75, 75);
} else {
$columnNames = array('Task name', $field, 'Start', 'Finish');
$columnSizes = array(250, 60, 80, 80);
$columnSizes = array(250, 60, 90, 90);
}
}
$gantt->setColumnHeaders($columnNames, $columnSizes);
$gantt->setProperties(array('showhgrid' => true));
$gantt->setDateRange($start_date, $end_date);
$gantt->setDateRange($gantt_start_date, $gantt_end_date);
reset($projects);
foreach ($projects as $p) {
@@ -347,7 +338,8 @@
}
unset($gts);
$filename = W2P_BASE_DIR."/files/temp/GanttPNG_".md5(time()).".png";
$filename = W2P_BASE_DIR."/files/temp/GanttPNG_".md5(time())."_$page.png";
// Prepare Gantt image and store in $filename
$gantt->render(true, $filename);
$outpfiles[] = $filename;
@@ -400,9 +392,9 @@
$pdf->ezColumnsStart(array('num' =>1, 'gap' =>0));
$pdf->ezImage( $gf, 20, 765, 'width', 'left'); // No pad, width = 800px, resize = 'none' (will go to next page if image height > remaining page space)
if ($showNoMilestones == '1') {
$pdf->ezImage( $gpdfkeyNM, 0, 765, 'width', 'left');
$pdf->ezImage( $gpdfkeyNM, 0, 500, 'width', 'center');
} else {
$pdf->ezImage( $gpdfkey, 0, 765, 'width', 'left');
$pdf->ezImage( $gpdfkey, 0, 500, 'width', 'center');
}
$pdf->ezColumnsStop();
}

0 comments on commit c7c3163

Please sign in to comment.
You can’t perform that action at this time.