예제 #1
0
 /**
  * Generates an histogram
  * @param    array    list of exercise names
  * @param    array    my results 0 to 100
  * @param    array    average scores 0-100
  * @return string
  */
 static function generate_session_exercise_graph($names, $my_results, $average)
 {
     /* Create and populate the pData object */
     $myData = new pData();
     $myData->addPoints($names, 'Labels');
     $myData->addPoints($my_results, 'Serie1');
     $myData->addPoints($average, 'Serie2');
     $myData->setSerieWeight('Serie1', 1);
     $myData->setSerieTicks('Serie2', 4);
     $myData->setSerieDescription('Labels', 'Months');
     $myData->setAbscissa('Labels');
     $myData->setSerieDescription('Serie1', get_lang('MyResults'));
     $myData->setSerieDescription('Serie2', get_lang('AverageScore'));
     $myData->setAxisUnit(0, '%');
     $myData->loadPalette(api_get_path(SYS_CODE_PATH) . 'palettes/pchart/default.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 = 860;
         $mainHeight = 500;
         $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));
         /* Set the default font */
         $myPicture->setFontProperties(array('FontName' => api_get_path(SYS_FONTS_PATH) . 'opensans/OpenSans-Regular.ttf', 'FontSize' => 10));
         /* Write the chart title */
         $myPicture->drawText($mainWidth / 2, 30, get_lang('ExercisesInTimeProgressChart'), array('FontSize' => 12, 'Align' => TEXT_ALIGN_BOTTOMMIDDLE));
         /* Set the default font */
         $myPicture->setFontProperties(array('FontName' => api_get_path(SYS_FONTS_PATH) . 'opensans/OpenSans-Regular.ttf', 'FontSize' => 6));
         /* Define the chart area */
         $myPicture->setGraphArea(60, 60, $mainWidth - 60, $mainHeight - 150);
         /* Draw the scale */
         $scaleSettings = array('XMargin' => 10, 'YMargin' => 10, '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(SYS_FONTS_PATH) . 'opensans/OpenSans-Regular.ttf', 'FontSize' => 10));
         $myPicture->drawSplineChart();
         $myPicture->drawPlotChart(array('DisplayValues' => true, 'PlotBorder' => true, 'BorderSize' => 1, 'Surrounding' => -60, 'BorderAlpha' => 80));
         /* Write the chart legend */
         $myPicture->drawLegend($mainWidth / 2 + 50, 50, array('Style' => LEGEND_BOX, 'Mode' => LEGEND_HORIZONTAL, 'FontR' => 0, 'FontG' => 0, 'FontB' => 0, 'R' => 220, 'G' => 220, 'B' => 220, 'Alpha' => 100));
         $myCache->writeToCache($chartHash, $myPicture);
         $imgPath = api_get_path(SYS_ARCHIVE_PATH) . $chartHash;
         $myCache->saveFromCache($chartHash, $imgPath);
         $imgPath = api_get_path(WEB_ARCHIVE_PATH) . $chartHash;
     }
     $html = '<img src="' . $imgPath . '">';
     return $html;
 }