Merge pull request #432 from danbarretodev/CT7383

Ct7383
1.9.x
Yannick Warnier 10 years ago
commit d82703e01c
  1. 46
      main/gradebook/lib/fe/flatviewtable.class.php
  2. 52
      main/inc/lib/pchart/pChart.class.php
  3. 86
      plugin/dashboard/block_evaluation_graph/block_evaluation_graph.class.php
  4. 15
      plugin/dashboard/block_teacher_graph/block_teacher_graph.class.php

@ -147,8 +147,14 @@ class FlatViewTable extends SortableTable
} else { } else {
// if the image does not exist in the archive/ folder // if the image does not exist in the archive/ folder
// Initialise the graph // Initialise the graph
$angle = -30;
$Test = new pChart(760, 360); $Test = new pChart(760, 360);
// set font of the axes
$Test->setFontProperties(api_get_path(LIBRARY_PATH) . "pchart/fonts/tahoma.ttf", 8);
$Test = $Test->fixHeightByRotation($DataSet->GetData(), $DataSet->GetDataDescription(), $angle);
//which schema of color will be used //which schema of color will be used
$quant_resources = count($data[0]) - 1; $quant_resources = count($data[0]) - 1;
// Adding the color schemma // Adding the color schemma
@ -158,11 +164,9 @@ class FlatViewTable extends SortableTable
$Test->loadColorPalette(api_get_path(LIBRARY_PATH) . "pchart/palette/default.txt"); $Test->loadColorPalette(api_get_path(LIBRARY_PATH) . "pchart/palette/default.txt");
} }
// set font of the axes
$Test->setFontProperties(api_get_path(LIBRARY_PATH) . "pchart/fonts/tahoma.ttf", 8);
$Test->setGraphArea(50, 30, 610, 300); $Test->setGraphArea(50, 30, 610, 300);
$Test->drawFilledRoundedRectangle(7, 7, 780, 330, 5, 240, 240, 240); $Test->drawFilledRoundedRectangle(7, 7, $Test->XSize + 20, $Test->YSize - 30, 5, 240, 240, 240);
//$Test->drawRoundedRectangle(5,5,790,330,5,230,230,230); //$Test->drawRoundedRectangle(5,5,790,330,5,230,230,230);
//background color area & stripe or not //background color area & stripe or not
$Test->drawGraphArea(255, 255, 255, TRUE); $Test->drawGraphArea(255, 255, 255, TRUE);
@ -316,18 +320,35 @@ class FlatViewTable extends SortableTable
// Initialise the graph // Initialise the graph
$chart_size_w = 480; $chart_size_w = 480;
$chart_size_h = 250; $chart_size_h = 250;
$angle = -30;
$Test = new pChart($chart_size_w, $chart_size_h); $Test = new pChart($chart_size_w, $chart_size_h);
// set font of the axes
$Test->setFontProperties(api_get_path(LIBRARY_PATH) . "pchart/fonts/tahoma.ttf", 8);
$Test = $Test->fixHeightByRotation(
$DataSet->GetData(),
$DataSet->GetDataDescription(),
$angle
);
// Adding the color schemma // Adding the color schemma
$Test->loadColorPalette(api_get_path(LIBRARY_PATH) . "pchart/palette/pastel.txt"); $Test->loadColorPalette(api_get_path(LIBRARY_PATH) . "pchart/palette/pastel.txt");
// set font of the axes
$Test->setFontProperties(api_get_path(LIBRARY_PATH) . "pchart/fonts/tahoma.ttf", 8);
$area_graph_w = $chart_size_w - 130; $area_graph_w = $chart_size_w - 130;
$Test->setGraphArea(50, 30, $area_graph_w, $chart_size_h - 50); $Test->setGraphArea(50, 30, $area_graph_w, $chart_size_h - 50);
$Test->drawFilledRoundedRectangle(5, 5, $chart_size_w - 1, $chart_size_h - 20, 5, 240, 240, 240); $Test->drawFilledRoundedRectangle(
5,
5,
$chart_size_w - 1,
$Test->YSize - 20,
5,
240,
240,
240
);
//$Test->drawRoundedRectangle(5,5,790,330,5,230,230,230); //$Test->drawRoundedRectangle(5,5,790,330,5,230,230,230);
//background color area & stripe or not //background color area & stripe or not
$Test->drawGraphArea(255, 255, 255, TRUE); $Test->drawGraphArea(255, 255, 255, TRUE);
@ -341,7 +362,18 @@ class FlatViewTable extends SortableTable
} }
} }
$Test->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_ADDALLSTART0, 150, 150, 150, TRUE, 0, 1, FALSE); $Test->drawScale(
$DataSet->GetData(),
$DataSet->GetDataDescription(),
SCALE_ADDALLSTART0,
150,
150,
150,
TRUE,
0,
1,
FALSE
);
//background grid //background grid
$Test->drawGrid(4, TRUE, 230, 230, 230, 50); $Test->drawGrid(4, TRUE, 230, 230, 230, 50);

@ -586,6 +586,7 @@
/* Horizontal Axis */ /* Horizontal Axis */
$XPos = $this->GArea_X1 + $this->GAreaXOffset; $XPos = $this->GArea_X1 + $this->GAreaXOffset;
$ID = 1; $YMax = NULL; $ID = 1; $YMax = NULL;
$maxTextHeight = 0;
foreach ( $Data as $Key => $Values ) foreach ( $Data as $Key => $Values )
{ {
if ( $ID % $SkipLabels == 0 ) if ( $ID % $SkipLabels == 0 )
@ -607,6 +608,10 @@
$TextWidth = abs($Position[2])+abs($Position[0]); $TextWidth = abs($Position[2])+abs($Position[0]);
$TextHeight = abs($Position[1])+abs($Position[3]); $TextHeight = abs($Position[1])+abs($Position[3]);
// Save max text height
if ($maxTextHeight < $TextHeight) {
$maxTextHeight = $TextHeight;
}
if ( $Angle == 0 ) if ( $Angle == 0 )
{ {
$YPos = $this->GArea_Y2+18; $YPos = $this->GArea_Y2+18;
@ -614,7 +619,9 @@
} }
else else
{ {
$YPos = $this->GArea_Y2+10+$TextHeight; $YPos = $this->GArea_Y2+10;
// If rotation is top down, then add TextHeight;
$YPos = (sin($Angle) < 0) ? $YPos + $TextHeight : $YPos;
if ( $Angle <= 90 ) if ( $Angle <= 90 )
imagettftext($this->Picture,$this->FontSize,$Angle,floor($XPos)-$TextWidth+5,$YPos,$C_TextColor,$this->FontName,$Value); imagettftext($this->Picture,$this->FontSize,$Angle,floor($XPos)-$TextWidth+5,$YPos,$C_TextColor,$this->FontName,$Value);
else else
@ -633,7 +640,7 @@
$Position = imageftbbox($this->FontSize,90,$this->FontName,$DataDescription["Axis"]["X"]); $Position = imageftbbox($this->FontSize,90,$this->FontName,$DataDescription["Axis"]["X"]);
$TextWidth = abs($Position[2])+abs($Position[0]); $TextWidth = abs($Position[2])+abs($Position[0]);
$TextLeft = (($this->GArea_X2 - $this->GArea_X1) / 2) + $this->GArea_X1 + ($TextWidth/2); $TextLeft = (($this->GArea_X2 - $this->GArea_X1) / 2) + $this->GArea_X1 + ($TextWidth/2);
imagettftext($this->Picture,$this->FontSize,0,$TextLeft,$YMax+$this->FontSize+5,$C_TextColor,$this->FontName,$DataDescription["Axis"]["X"]); imagettftext($this->Picture,$this->FontSize,0,$TextLeft,$YMax+$this->FontSize+5+$maxTextHeight,$C_TextColor,$this->FontName,$DataDescription["Axis"]["X"]);
} }
} }
@ -3555,6 +3562,47 @@
return(TRUE); return(TRUE);
return(FALSE); return(FALSE);
} }
/**
* Return a new pChart object fixing its height by legend rotations
* Must be set fonts before call this method
* @param array $data
* @param array $dataDescription
* @param float $angle
* @return pChart
*/
function fixHeightByRotation ($data, $dataDescription, $angle)
{
$maxTextHeight = 0;
foreach ($data as $key => $values) {
// Get legend value
$value = $data[$key][$dataDescription["Position"]];
if ($dataDescription["Format"]["X"] == "number") {
$value = $value.$dataDescription["Unit"]["X"];
} elseif ($dataDescription["Format"]["X"] == "time") {
$value = $this->ToTime($value);
} elseif ($dataDescription["Format"]["X"] == "date") {
$value = $this->ToDate($value);
} elseif ($dataDescription["Format"]["X"] == "metric") {
$value = $this->ToMetric($value);
} elseif ($dataDescription["Format"]["X"] == "currency") {
$value = $this->ToCurrency($value);
}
// Get positions array from label generated
$Position = imageftbbox($this->FontSize, $angle, $this->FontName, $value);
$TextHeight = abs($Position[1]) + abs($Position[3]);
// Save max height
if ($maxTextHeight < $TextHeight) {
$maxTextHeight = $TextHeight;
}
}
$this->YSize += $maxTextHeight;
$pChart = new pChart($this->XSize, $this->YSize);
// set font of the axes
$pChart->setFontProperties($this->FontName, $this->FontSize);
return $pChart;
}
} }
function RaiseFatal($Message) function RaiseFatal($Message)

@ -166,14 +166,49 @@ class BlockEvaluationGraph extends Block
$img_file = $cache->GetHash($graph_id, $data); $img_file = $cache->GetHash($graph_id, $data);
} else { } else {
// Initialise the graph // Initialise the graph
$angle = -30;
$test = new pChart($this->bg_width,$this->bg_height); $test = new pChart($this->bg_width,$this->bg_height);
$test->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf',8); $test->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf',8);
$test->setGraphArea(50,30,$this->bg_width-75,$this->bg_height-75); $test = $test->fixHeightByRotation(
$test->drawFilledRoundedRectangle(7,7,$this->bg_width-20,$this->bg_height-20,5,240,240,240); $data_set->GetData(),
$test->drawRoundedRectangle(5,5,$this->bg_width-18,$this->bg_height-18,5,230,230,230); $data_set->GetDataDescription(),
$test->drawGraphArea(255,255,255,TRUE); $angle
$test->setFixedScale(0,100,5); );
$test->drawScale($data_set->GetData(),$data_set->GetDataDescription(),SCALE_ADDALL,150,150,150,TRUE,0,2,TRUE); $test->setGraphArea(50, 30, $this->bg_width-75, $test->YSize - 75);
$test->drawFilledRoundedRectangle(
7,
7,
$this->bg_width-20,
$test->YSize - 20,
5,
240,
240,
240
);
$test->drawRoundedRectangle(
5,
5,
$this->bg_width-18,
$test->YSize - 18,
5,
230,
230,
230
);
$test->drawGraphArea(255,255,255,TRUE);
$test->setFixedScale(0,100,5);
$test->drawScale(
$data_set->GetData(),
$data_set->GetDataDescription(),
SCALE_ADDALL,
150,
150,
150,
TRUE,
$angle,
2,
TRUE
);
$test->setColorPalette(0,105,221,34); $test->setColorPalette(0,105,221,34);
$test->setColorPalette(1,255,135,30); $test->setColorPalette(1,255,135,30);
$test->setColorPalette(2,255,0,0); $test->setColorPalette(2,255,0,0);
@ -258,14 +293,45 @@ class BlockEvaluationGraph extends Block
$img_file = $cache->GetHash($graph_id, $data); $img_file = $cache->GetHash($graph_id, $data);
} else { } else {
// Initialise the graph // Initialise the graph
$angle = -30;
$test = new pChart($this->bg_width,$this->bg_height); $test = new pChart($this->bg_width,$this->bg_height);
$test->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf',8); $test->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf',8);
$test->setGraphArea(50,30,$this->bg_width-75,$this->bg_height-75); $test->fixHeightByRotation($data_set->GetData(), $data_set->GetDataDescription(), $angle);
$test->drawFilledRoundedRectangle(7,7,$this->bg_width-20,$this->bg_height-20,5,240,240,240); $test->setGraphArea(50, 30, $this->bg_width-75, $test->YSize-75);
$test->drawRoundedRectangle(5,5,$this->bg_width-18,$this->bg_height-18,5,230,230,230); $test->drawFilledRoundedRectangle(
7,
7,
$this->bg_width-20,
$test->YSize-20,
5,
240,
240,
240
);
$test->drawRoundedRectangle(
5,
5,
$this->bg_width-18,
$test->YSize-18,
5,
230,
230,
230
);
$test->drawGraphArea(255,255,255,TRUE); $test->drawGraphArea(255,255,255,TRUE);
$test->setFixedScale(0,100,5); $test->setFixedScale(0,100,5);
$test->drawScale($data_set->GetData(),$data_set->GetDataDescription(),SCALE_ADDALL,150,150,150,TRUE,0,2,TRUE); $test->drawScale(
$data_set->GetData(),
$data_set->GetDataDescription(),
SCALE_ADDALL,
150,
150,
150,
TRUE,
$angle,
2,
TRUE
);
$test->setColorPalette(0,105,221,34); $test->setColorPalette(0,105,221,34);
$test->setColorPalette(1,255,135,30); $test->setColorPalette(1,255,135,30);
$test->setColorPalette(2,255,0,0); $test->setColorPalette(2,255,0,0);

@ -144,13 +144,26 @@ class BlockTeacherGraph extends Block
// Initializing the graph // Initializing the graph
$bg_width = 440; $bg_width = 440;
$bg_height = 350; $bg_height = 350;
$angle = -30;
$test = new pChart($bg_width+10,$bg_height+20); $test = new pChart($bg_width+10,$bg_height+20);
$test->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf',8); $test->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf',8);
$test = $test->fixHeightByRotation($data_set->GetData(), $data_set->GetDataDescription(), $angle);
$test->setGraphArea(65,30,$bg_width-70,$bg_height-50); $test->setGraphArea(65,30,$bg_width-70,$bg_height-50);
$test->drawFilledRoundedRectangle(7,7,$bg_width,$bg_height,5,240,240,240); $test->drawFilledRoundedRectangle(7,7,$bg_width,$bg_height,5,240,240,240);
$test->drawRoundedRectangle(5,5,$bg_width+2,$bg_height+2,5,230,230,230); $test->drawRoundedRectangle(5,5,$bg_width+2,$bg_height+2,5,230,230,230);
$test->drawGraphArea(255,255,255,TRUE); $test->drawGraphArea(255,255,255,TRUE);
$test->drawScale($data_set->GetData(),$data_set->GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2,TRUE); $test->drawScale(
$data_set->GetData(),
$data_set->GetDataDescription(),
SCALE_NORMAL,
150,
150,
150,
TRUE,
$angle,
2,
TRUE
);
$test->drawGrid(4,TRUE,230,230,230,50); $test->drawGrid(4,TRUE,230,230,230,50);
// Drawing lines // Drawing lines

Loading…
Cancel
Save