Upgrade pChart for MySpace grapher method, set Scale mode for my progress chart - ref CT#7408

1.10.x
Daniel Barreto 11 years ago
parent a39ff66c2d
commit fe6d7d4ee2
  1. 3
      main/inc/lib/tracking.lib.php
  2. 3
      main/mySpace/access_details.php
  3. 192
      main/mySpace/myspace.lib.php

@ -4671,7 +4671,8 @@ class Tracking
"GridB" => 200, "GridB" => 200,
"DrawSubTicks" => true, "DrawSubTicks" => true,
"CycleBackground" => true, "CycleBackground" => true,
'LabelRotation' => $angle 'LabelRotation' => $angle,
'Mode' => SCALE_MODE_ADDALL_START0,
); );
$myPicture->drawScale($scaleSettings); $myPicture->drawScale($scaleSettings);

@ -21,9 +21,6 @@ $language_file = array ('registration', 'index', 'tracking');
require_once '../inc/global.inc.php'; require_once '../inc/global.inc.php';
// including additional libraries // including additional libraries
require_once api_get_path(LIBRARY_PATH).'pchart/pData.class.php';
require_once api_get_path(LIBRARY_PATH).'pchart/pChart.class.php';
require_once api_get_path(LIBRARY_PATH).'pchart/pCache.class.php';
require_once 'myspace.lib.php'; require_once 'myspace.lib.php';
api_block_anonymous_users(); api_block_anonymous_users();

@ -2782,9 +2782,9 @@ function convert_to_string($sql_result){
* @return string * @return string
*/ */
function grapher($sql_result, $start_date, $end_date, $type = "") { function grapher($sql_result, $start_date, $end_date, $type = "") {
require_once api_get_path(LIBRARY_PATH).'pchart/pData.class.php'; require_once api_get_path(LIBRARY_PATH) . 'pChart2/class/pData.class.php';
require_once api_get_path(LIBRARY_PATH).'pchart/pChart.class.php'; require_once api_get_path(LIBRARY_PATH) . 'pChart2/class/pDraw.class.php';
require_once api_get_path(LIBRARY_PATH).'pchart/pCache.class.php'; require_once api_get_path(LIBRARY_PATH) . 'pChart2/class/pCache.class.php';
if (empty($start_date)) { $start_date =""; } if (empty($start_date)) { $start_date =""; }
if (empty($end_date)) { $end_date =""; } if (empty($end_date)) { $end_date =""; }
@ -2811,7 +2811,6 @@ function grapher($sql_result, $start_date, $end_date, $type = "") {
} }
$i++; $i++;
} }
switch ($type) { switch ($type) {
case 'day': case 'day':
$main_date = $main_day; $main_date = $main_day;
@ -2831,76 +2830,139 @@ function grapher($sql_result, $start_date, $end_date, $type = "") {
$main_date = $main_date[$labels]; $main_date = $main_date[$labels];
} }
$data_set = new pData(); /* Create and populate the pData object */
$data_set->AddPoint($main_date, 'Q'); $myData = new pData();
$myData->addPoints($main_date, 'Serie1');
if (count($main_date)!= 1) { if (count($main_date)!= 1) {
$data_set->AddPoint($labels, 'Date'); $myData->addPoints($labels, 'Labels');
} $myData->setSerieDescription('Labels', 'Months');
$data_set->AddAllSeries(); $myData->setAbscissa('Labels');
$data_set->RemoveSerie('Date'); }
$data_set->SetAbsciseLabelSerie('Date'); $myData->setSerieWeight('Serie1', 1);
$data_set->SetYAxisName(get_lang('Minutes', '')); $myData->setSerieDescription('Serie1', get_lang('MyResults'));
$graph_id = api_get_user_id().'AccessDetails'.api_get_course_id().$start_date.$end_date.$type; $myData->setAxisName(0, get_lang('Minutes'));
$data_set->AddAllSeries(); // @TODO: Define a custom pallete
$myData->loadPalette(api_get_path(LIBRARY_PATH) . 'pChart2/palettes/evening.color', true);
// Cache definition
$cachePath = api_get_path(SYS_ARCHIVE_PATH);
$myCache = new pCache(array('CacheFolder' => substr($cachePath, 0, strlen($cachePath) - 1)));
$chartHash = $myCache->getHash($myData);
if ($myCache->isInCache($chartHash)) {
//if we already created the img
$imgPath = api_get_path(SYS_ARCHIVE_PATH) . $chartHash;
$myCache->saveFromCache($chartHash, $imgPath);
$imgPath = api_get_path(WEB_ARCHIVE_PATH) . $chartHash;
} else {
/* Define width, height and angle */
$mainWidth = 760;
$mainHeight = 230;
$angle = 50;
/* Create the pChart object */
$myPicture = new pImage($mainWidth, $mainHeight, $myData);
/* Turn of Antialiasing */
$myPicture->Antialias = false;
/* Draw the background */
$Settings = array("R" => 255, "G" => 255, "B" => 255);
$myPicture->drawFilledRectangle(0, 0, $mainWidth, $mainHeight, $Settings);
/* Add a border to the picture */
$myPicture->drawRectangle(
0,
0,
$mainWidth - 1,
$mainHeight - 1,
array("R" => 0, "G" => 0, "B" => 0)
);
$cache = new pCache(); /* Set the default font */
// the graph id $myPicture->setFontProperties(
$data = $data_set->GetData(); array(
"FontName" => api_get_path(LIBRARY_PATH) . "pChart2/fonts/verdana.ttf",
"FontSize" => 10)
);
/* Write the chart title */
$myPicture->drawText(
$mainWidth / 2,
30,
get_lang('ExercisesInTimeProgressChart'),
array(
"FontSize" => 12,
"Align" => TEXT_ALIGN_BOTTOMMIDDLE
)
);
if ($cache->IsInCache($graph_id, $data_set->GetData())) { /* Set the default font */
//if (0) { $myPicture->setFontProperties(
//if we already created the img array(
// echo 'in cache'; "FontName" => api_get_path(LIBRARY_PATH) . "pChart2/fonts/verdana.ttf",
$img_file = $cache->GetHash($graph_id, $data_set->GetData()); "FontSize" => 8
} else { )
// if the image does not exist in the archive/ folder );
// Initialise the graph
$test = new pChart(760, 230);
//which schema of color will be used
$quant_resources = count($data[0]) - 1;
// Adding the color schemma
$test->loadColorPalette(api_get_path(LIBRARY_PATH).'pchart/palette/default.txt');
$test->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf', 8);
$test->setGraphArea(70, 30, 680, 200);
$test->drawFilledRoundedRectangle(7, 7, 693, 223, 5, 240, 240, 240);
$test->drawRoundedRectangle(5, 5, 695, 225, 5, 230, 230, 230);
$test->drawGraphArea(255, 255, 255, TRUE);
$test->drawScale($data_set->GetData(), $data_set->GetDataDescription(), SCALE_START0, 150, 150, 150, TRUE, 0, 0);
$test->drawGrid(4, TRUE, 230, 230, 230, 50);
$test->setLineStyle(2);
// Draw the 0 line
$test->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf', 6);
$test->drawTreshold(0, 143, 55, 72, TRUE, TRUE);
if (count($main_date) == 1) { /* Define the chart area */
//Draw a graph $myPicture->setGraphArea(50, 40, $mainWidth - 40, $mainHeight - 80);
echo '<strong>'.$labels.'</strong><br/>';
$test->drawBarGraph($data_set->GetData(), $data_set->GetDataDescription(), TRUE); /* Draw the scale */
} else { $scaleSettings = array(
//Draw the line graph 'XMargin' => 10,
$test->drawLineGraph($data_set->GetData(), $data_set->GetDataDescription()); 'YMargin' => 10,
$test->drawPlotGraph($data_set->GetData(), $data_set->GetDataDescription(), 3, 2, 255, 255, 255); 'Floating' => true,
} 'GridR' => 200,
'GridG' => 200,
'GridB' => 200,
'DrawSubTicks' => true,
'CycleBackground' => true,
'LabelRotation' => $angle,
'Mode' => SCALE_MODE_ADDALL_START0,
);
$myPicture->drawScale($scaleSettings);
/* Turn on Antialiasing */
$myPicture->Antialias = true;
/* Enable shadow computing */
$myPicture->setShadow(
true,
array("X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10)
);
/* Draw the line chart */
$myPicture->setFontProperties(
array(
"FontName" => api_get_path(LIBRARY_PATH) . "pChart2/fonts/verdana.ttf",
"FontSize" => 10
)
);
$myPicture->drawSplineChart();
$myPicture->drawPlotChart(
array(
"DisplayValues" => true,
"PlotBorder" => true,
"BorderSize" => 1,
"Surrounding" => -60,
"BorderAlpha" => 80
)
);
// Finish the graph /* Do NOT Write the chart legend */
$test->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf', 8);
$test->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf', 10);
$test->drawTitle(60, 22, get_lang('AccessDetails'), 50, 50, 50, 585);
//------------------ /* Write and save into cache */
//echo 'not in cache'; $myCache->writeToCache($chartHash, $myPicture);
$cache->WriteToCache($graph_id, $data_set->GetData(), $test); $imgPath = api_get_path(SYS_ARCHIVE_PATH) . $chartHash;
ob_start(); $myCache->saveFromCache($chartHash, $imgPath);
$test->Stroke(); $imgPath = api_get_path(WEB_ARCHIVE_PATH) . $chartHash;
ob_end_clean();
$img_file = $cache->GetHash($graph_id, $data_set->GetData());
} }
$foo_img = '<img src="'.api_get_path(WEB_ARCHIVE_PATH).$img_file.'">'; $html = '<img src="' . $imgPath . '">';
return $foo_img;
return $html;
} else { } else {
$foo_img = api_convert_encoding('<div id="messages" class="warning-message">'.get_lang('GraphicNotAvailable').'</div>','UTF-8'); $foo_img = api_convert_encoding('<div id="messages" class="warning-message">'.get_lang('GraphicNotAvailable').'</div>','UTF-8');
return $foo_img; return $foo_img;
} }

Loading…
Cancel
Save