Upgrade pChart for dashboard plugin, block evaluation graph - refs CT#7408

1.10.x
Daniel Barreto 11 years ago
parent fe6d7d4ee2
commit fa78252a33
  1. 378
      plugin/dashboard/block_evaluation_graph/block_evaluation_graph.class.php

@ -1,9 +1,8 @@
<?php <?php
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
require_once api_get_path(LIBRARY_PATH).'pChart2/class/pData.class.php';
require_once api_get_path(LIBRARY_PATH).'pchart/pData.class.php'; require_once api_get_path(LIBRARY_PATH).'pChart2/class/pDraw.class.php';
require_once api_get_path(LIBRARY_PATH).'pchart/pChart.class.php'; require_once api_get_path(LIBRARY_PATH).'pChart2/class/pCache.class.php';
require_once api_get_path(LIBRARY_PATH).'pchart/pCache.class.php';
require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/be/gradebookitem.class.php'; require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/be/gradebookitem.class.php';
require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/be/evaluation.class.php'; require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/be/evaluation.class.php';
require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/be/result.class.php'; require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/be/result.class.php';
@ -146,96 +145,110 @@ class BlockEvaluationGraph extends Block
$min[] = !empty($evaluation['min']) ? $evaluation['min'] : 0; $min[] = !empty($evaluation['min']) ? $evaluation['min'] : 0;
$avg[] = $evaluation['avg']; $avg[] = $evaluation['avg'];
} }
// Dataset definition // Dataset definition
$data_set = new pData; $dataSet = new pData();
$data_set->AddPoint($max, "Max"); $dataSet->addPoints($min, 'Serie3');
$data_set->AddPoint($avg, "Avg"); $dataSet->addPoints($avg, 'Serie2');
$data_set->AddPoint($min, "Min"); $dataSet->addPoints($max, 'Serie1');
$data_set->AddPoint($items, "Items"); $dataSet->addPoints($items, 'Labels');
$data_set->SetXAxisName(get_lang('EvaluationName'));
$data_set->SetYAxisName(get_lang('Percentage')); $dataSet->setSerieDescription('Serie1', get_lang('Max'));
$data_set->AddAllSeries(); $dataSet->setSerieDescription('Serie2', get_lang('Avg'));
$data_set->RemoveSerie("Items"); $dataSet->setSerieDescription('Serie3', get_lang('Min'));
$data_set->SetAbsciseLabelSerie("Items"); $dataSet->setAbscissa('Labels');
$graph_id = $this->user_id.'StudentEvaluationGraph';
$cache = new pCache(); $dataSet->setAbscissaName(get_lang('EvaluationName'));
// the graph id
$data = $data_set->GetData(); $dataSet->normalize(100, '%');
if ($cache->IsInCache($graph_id, $data)) {
//if we already created the img // Cache definition
$img_file = $cache->GetHash($graph_id, $data); $cachePath = api_get_path(SYS_ARCHIVE_PATH);
} else { $myCache = new pCache(array('CacheFolder' => substr($cachePath, 0, strlen($cachePath) - 1)));
// Initialise the graph $chartHash = $myCache->getHash($dataSet);
$angle = -30; if ($myCache->isInCache($chartHash)) {
$test = new pChart($this->bg_width,$this->bg_height); $imgPath = api_get_path(SYS_ARCHIVE_PATH) . $chartHash;
$test->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf',8); $myCache->saveFromCache($chartHash, $imgPath);
$test = $test->fixHeightByRotation( $imgPath = api_get_path(WEB_ARCHIVE_PATH) . $chartHash;
$data_set->GetData(), } else {
$data_set->GetDataDescription(), /* Create the pChart object */
$angle $widthSize = $this->bg_width;
$heightSize = $this->bg_height;
$fontSize = 8;
$angle = 50;
$myPicture = new pImage($widthSize, $heightSize, $dataSet);
/* Turn of Antialiasing */
$myPicture->Antialias = false;
/* Add a border to the picture */
$myPicture->drawRectangle(0, 0, $widthSize - 1, $heightSize - 1, array('R' => 0, 'G' => 0, 'B' => 0));
/* Set the default font */
$myPicture->setFontProperties(
array(
'FontName' => api_get_path(LIBRARY_PATH) . 'pChart2/fonts/verdana.ttf',
'FontSize' => 10
)
); );
$test->setGraphArea(50, 30, $this->bg_width-75, $this->bg_height - 75);
$test->drawFilledRoundedRectangle( /* Do NOT Write the chart title */
7,
7, /* Define the chart area */
$this->bg_width-20, $myPicture->setGraphArea(50, 30, $widthSize - 20, $heightSize - 100);
$test->YSize - 20,
5, /* Draw the scale */
240, $scaleSettings = array(
240, 'GridR' => 200,
240 'GridG' => 200,
'GridB' => 200,
'DrawSubTicks' => true,
'CycleBackground' => true,
'Mode' => SCALE_MODE_MANUAL,
'ManualScale' => array(
'0' => array(
'Min' => 0,
'Max' => 100,
)
),
'LabelRotation' => $angle,
); );
$test->drawRoundedRectangle( $myPicture->drawScale($scaleSettings);
5,
5, /* Turn on shadow computing */
$this->bg_width-18, $myPicture->setShadow(true, array('X' => 1, 'Y' => 1, 'R' => 0, 'G' => 0, 'B' => 0, 'Alpha' => 10));
$test->YSize - 18,
5, /* Draw the chart */
230, $myPicture->setShadow(true, array('X' => 1, 'Y' => 1, 'R' => 0, 'G' => 0, 'B' => 0, 'Alpha' => 10));
230, $settings = array(
230 'DisplayValues' => true,
'DisplaySize' => $fontSize,
'DisplayR' => 0,
'DisplayG' => 0,
'DisplayB' => 0,
'DisplayOrientation' => ORIENTATION_HORIZONTAL,
'Gradient' => false,
'Surrounding' => 30,
'InnerSurrounding' => 25
); );
$test->drawGraphArea(255,255,255,TRUE); $myPicture->drawStackedBarChart($settings);
$test->setFixedScale(0,100,5);
$test->drawScale( $legendSettings = array(
$data_set->GetData(), 'Mode' => LEGEND_HORIZONTAL,
$data_set->GetDataDescription(), 'Style' => LEGEND_NOBORDER,
SCALE_ADDALL,
150,
150,
150,
TRUE,
$angle,
2,
TRUE
); );
$test->setColorPalette(0,105,221,34); $myPicture->drawLegend($widthSize / 2, 15, $legendSettings);
$test->setColorPalette(1,255,135,30);
$test->setColorPalette(2,255,0,0); /* Render the picture (choose the best way) */
$test->drawGrid(4,TRUE,230,230,230,50);
// Draw the 0 line $myCache->writeToCache($chartHash, $myPicture);
$test->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf',6); $imgPath = api_get_path(SYS_ARCHIVE_PATH) . $chartHash;
$test->drawTreshold(0,143,55,72,TRUE,TRUE); $myCache->saveFromCache($chartHash, $imgPath);
// Draw the bar graph $imgPath = api_get_path(WEB_ARCHIVE_PATH) . $chartHash;
$test->drawOverlayBarGraph($data_set->GetData(),$data_set->GetDataDescription(), 90); }
// Finish the graph if (!empty($imgPath)) {
$test->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf',8); $courses_graph[$course_code] = '<img src="' . $imgPath . '">';
$test->drawLegend($this->bg_width-80,20,$data_set->GetDataDescription(),255,255,255); }
$test->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf',10);
//$test->drawTitle(50,22,$course_code,50,50,50,185);
$test->setColorPalette(0,50,50,50);
$test->setColorPalette(1,50,50,50);
$test->setColorPalette(2,50,50,50);
$test->writeValues($data_set->GetData(),$data_set->GetDataDescription(),array("Min", "Max", "Avg"));
$cache->WriteToCache($graph_id, $data_set->GetData(), $test);
ob_start();
$test->Stroke();
ob_end_clean();
$img_file = $cache->GetHash($graph_id, $data_set->GetData());
}
if (!empty($img_file)) {
$graphs[$course_code] = '<img src="'.api_get_path(WEB_ARCHIVE_PATH).$img_file.'">';
}
} }
} }
} // end for } // end for
@ -273,95 +286,110 @@ class BlockEvaluationGraph extends Block
$min[] = $evaluation['min']; $min[] = $evaluation['min'];
$avg[] = $evaluation['avg']; $avg[] = $evaluation['avg'];
} }
// Dataset definition // Dataset definition
$data_set = new pData; $dataSet = new pData();
$data_set->AddPoint($max, "Max"); $dataSet->addPoints($min, 'Serie3');
$data_set->AddPoint($avg, "Avg"); $dataSet->addPoints($avg, 'Serie2');
$data_set->AddPoint($min, "Min"); $dataSet->addPoints($max, 'Serie1');
$data_set->AddPoint($items, "Items"); $dataSet->addPoints($items, 'Labels');
$data_set->SetXAxisName(get_lang('EvaluationName'));
$data_set->SetYAxisName(get_lang('Percentage')); $dataSet->setSerieDescription('Serie1', get_lang('Max'));
$data_set->AddAllSeries(); $dataSet->setSerieDescription('Serie2', get_lang('Avg'));
$data_set->RemoveSerie("Items"); $dataSet->setSerieDescription('Serie3', get_lang('Min'));
$data_set->SetAbsciseLabelSerie("Items"); $dataSet->setAbscissa('Labels');
$graph_id = $this->user_id.'StudentEvaluationGraph';
$cache = new pCache(); $dataSet->setAbscissaName(get_lang('EvaluationName'));
// the graph id
$data = $data_set->GetData(); $dataSet->normalize(100, '%');
if ($cache->IsInCache($graph_id, $data)) {
//if we already created the img // Cache definition
$img_file = $cache->GetHash($graph_id, $data); $cachePath = api_get_path(SYS_ARCHIVE_PATH);
} else { $myCache = new pCache(array('CacheFolder' => substr($cachePath, 0, strlen($cachePath) - 1)));
// Initialise the graph $chartHash = $myCache->getHash($dataSet);
$angle = -30; if ($myCache->isInCache($chartHash)) {
$test = new pChart($this->bg_width, $this->bg_height); $imgPath = api_get_path(SYS_ARCHIVE_PATH) . $chartHash;
$test->setFontProperties(api_get_path(LIBRARY_PATH) . 'pchart/fonts/tahoma.ttf', 8); $myCache->saveFromCache($chartHash, $imgPath);
$test->fixHeightByRotation( $imgPath = api_get_path(WEB_ARCHIVE_PATH) . $chartHash;
$data_set->GetData(), } else {
$data_set->GetDataDescription(), /* Create the pChart object */
$angle $widthSize = $this->bg_width;
$heightSize = $this->bg_height;
$fontSize = 8;
$angle = 50;
$myPicture = new pImage($widthSize, $heightSize, $dataSet);
/* Turn of Antialiasing */
$myPicture->Antialias = false;
/* Add a border to the picture */
$myPicture->drawRectangle(0, 0, $widthSize - 1, $heightSize - 1, array('R' => 0, 'G' => 0, 'B' => 0));
/* Set the default font */
$myPicture->setFontProperties(
array(
'FontName' => api_get_path(LIBRARY_PATH) . 'pChart2/fonts/verdana.ttf',
'FontSize' => 10
)
); );
$test->setGraphArea(50, 30, $this->bg_width - 75, $this->bg_height - 75);
$test->drawFilledRoundedRectangle( /* Do NOT Write the chart title */
7,
7, /* Define the chart area */
$this->bg_width - 20, $myPicture->setGraphArea(50, 30, $widthSize - 20, $heightSize - 100);
$test->YSize - 20,
5, /* Draw the scale */
240, $scaleSettings = array(
240, 'GridR' => 200,
240 'GridG' => 200,
'GridB' => 200,
'DrawSubTicks' => true,
'CycleBackground' => true,
'Mode' => SCALE_MODE_MANUAL,
'ManualScale' => array(
'0' => array(
'Min' => 0,
'Max' => 100,
)
),
'LabelRotation' => $angle,
); );
$test->drawRoundedRectangle( $myPicture->drawScale($scaleSettings);
5,
5, /* Turn on shadow computing */
$this->bg_width - 18, $myPicture->setShadow(true, array('X' => 1, 'Y' => 1, 'R' => 0, 'G' => 0, 'B' => 0, 'Alpha' => 10));
$test->YSize - 18,
5, /* Draw the chart */
230, $myPicture->setShadow(true, array('X' => 1, 'Y' => 1, 'R' => 0, 'G' => 0, 'B' => 0, 'Alpha' => 10));
230, $settings = array(
230 'DisplayValues' => true,
'DisplaySize' => $fontSize,
'DisplayR' => 0,
'DisplayG' => 0,
'DisplayB' => 0,
'DisplayOrientation' => ORIENTATION_HORIZONTAL,
'Gradient' => false,
'Surrounding' => 30,
'InnerSurrounding' => 25
); );
$test->drawGraphArea(255,255,255,TRUE); $myPicture->drawStackedBarChart($settings);
$test->setFixedScale(0,100,5);
$test->drawScale( $legendSettings = array(
$data_set->GetData(), 'Mode' => LEGEND_HORIZONTAL,
$data_set->GetDataDescription(), 'Style' => LEGEND_NOBORDER,
SCALE_ADDALL,
150,
150,
150,
TRUE,
$angle,
2,
TRUE
); );
$test->setColorPalette(0,105,221,34); $myPicture->drawLegend($widthSize / 2, 15, $legendSettings);
$test->setColorPalette(1,255,135,30);
$test->setColorPalette(2,255,0,0); /* Render the picture (choose the best way) */
$test->drawGrid(4,TRUE,230,230,230,50);
// Draw the 0 line $myCache->writeToCache($chartHash, $myPicture);
$test->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf',6); $imgPath = api_get_path(SYS_ARCHIVE_PATH) . $chartHash;
$test->drawTreshold(0,143,55,72,TRUE,TRUE); $myCache->saveFromCache($chartHash, $imgPath);
// Draw the bar graph $imgPath = api_get_path(WEB_ARCHIVE_PATH) . $chartHash;
$test->drawOverlayBarGraph($data_set->GetData(),$data_set->GetDataDescription(), 100); }
// Finish the graph if (!empty($imgPath)) {
$test->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf',8); $courses_graph[$course_code] = '<img src="' . $imgPath . '">';
$test->drawLegend($this->bg_width-80,20,$data_set->GetDataDescription(),255,255,255); }
$test->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf',10);
$test->setColorPalette(0,50,50,50);
$test->setColorPalette(1,50,50,50);
$test->setColorPalette(2,50,50,50);
$test->writeValues($data_set->GetData(),$data_set->GetDataDescription(),array("Min", "Max", "Avg"));
$cache->WriteToCache($graph_id, $data_set->GetData(), $test);
ob_start();
$test->Stroke();
ob_end_clean();
$img_file = $cache->GetHash($graph_id, $data_set->GetData());
}
if (!empty($img_file)) {
$courses_graph[$course_code] = '<img src="'.api_get_path(WEB_ARCHIVE_PATH).$img_file.'">';
}
} }
} }
} }

Loading…
Cancel
Save