linea21-modules
[ class tree: linea21-modules ] [ index: linea21-modules ] [ all elements ]

Source for file graph.php

Documentation is available at graph.php

  1. <?php
  2. /**
  3.  * @package linea21.modules
  4.  * @subpackage dashboard
  5.  * @author linea21 <info@linea21.com>
  6.  * @version $id SVN
  7.  * @access public
  8.  * @license http://opensource.org/licenses/gpl-3.0.html
  9.  */
  10.  
  11.  
  12. /**
  13.  * Warning : If a trailing whitespace is present in any embedded file (for example, a plugin file), this graph won't display
  14.  */
  15.  
  16. include_once("../config/define.php");
  17. //////////// Check Inclusion de pages ////////////
  18. if (!class_exists('auth')){
  19.     include_once("../lib/lib_common.php");
  20.     ReloadIndex('admin');
  21. }
  22. ////////////
  23.  
  24. $scale_id=$_GET['scale_id'];
  25. $id=$_GET['id'];
  26.  
  27. if(isset($_GET['type'])) {
  28.     $type $_GET['type'];
  29. else {
  30.     $type 'auto';
  31. }
  32.  
  33.  
  34. include_once("../class/class.sdi.php");
  35. include_once(SQL.".inc.php");
  36.  
  37. if(isset($_GET['display'])) {
  38.     generateGraphic($id$scale_id'SCP'$typetrue);
  39. }
  40.  
  41.  
  42. /**
  43.  *
  44.  * @param integer $id 
  45.  * @param integer $scale_id 
  46.  * @param string $type 
  47.  * @param string $workingpath 
  48.  */
  49. function generateGraphic($id$scale_id$status$type 'auto'$display false$workingpath ''{
  50.  
  51.     global $sql_object;
  52.  
  53.     // we get values
  54.     $req_sdiav=SQL_getAllValue($status$scale_id$id'ASC');
  55.     $value $sql_object->DBSelect($req_sdiav);
  56.     $req_sdii=SQL_getInfoSdi($id);
  57.     $result_sdii $sql_object->DBSelect($req_sdii);
  58.  
  59.     $unit=$result_sdii[0]['sdii_unit'];
  60.     $full_title=formatText($result_sdii[0]['sdii_name']);
  61.     $title=cutText($full_title500);
  62.     
  63.     // visualization type
  64.     if($type == 'auto'{
  65.         $type $result_sdii[0]['sdii_detail_viz'];
  66.     }
  67.  
  68.     $is_null_threshold true// is the threshold null or not? to know if we display it
  69.     for ($i=0$i<count($value)$i++{
  70.         $ydata[$i]=$value[$i]['sdiv_value'];
  71.         // setting $threshold_value
  72.         // By default initial value
  73.         $ydata2[$i]=$result_sdii[0]['sdii_threshold_value'];
  74.         // if set, we get it from the table
  75.         if(!is_null($value[$i]['sdiv_threshold'])) {
  76.             $ydata2[$i]=$value[$i]['sdiv_threshold'];
  77.         }
  78.         // if at least one numeric value is there test is false
  79.         if(is_numeric($ydata2[$i])) $is_null_threshold false;
  80.  
  81.         list($day$month$year)=explode('-',$value[$i]['date_p']);
  82.         $months[$i$day '-' .$month'-'substr($year22);
  83.     }
  84.  
  85.  
  86.     /* pChart library inclusions */
  87.     include_once("../class/system/pChart/class/pData.class.php");
  88.     include_once("../class/system/pChart/class/pDraw.class.php");
  89.     include_once("../class/system/pChart/class/pImage.class.php");
  90.  
  91.     /* Create and populate the pData object */
  92.     $MyData new pData();
  93.     //  $MyData->loadPalette("../class/system/pChart/palettes/blind.color",TRUE);
  94.     $MyData->setAxisName(0,$unit);
  95.     $MyData->addPoints($ydata,$full_title);
  96.     $MyData->addPoints($ydata2,"thresholds");
  97.     $MyData->addPoints($months,"Dates");
  98.     $MyData->setSerieDescription($full_title,$unit);
  99.     $MyData->setAbscissa("Dates");
  100.  
  101.     /* Create the pChart object */
  102.     $myPicture new pImage(500,350,$MyData);
  103.     /* Turn of Antialiasing */
  104.     $myPicture->Antialias TRUE;
  105.     /* Add a border to the picture */
  106.     // $myPicture->drawRectangle(0,0,499,349,array("R"=>180,"G"=>180,"B"=>180));
  107.     /* Set the default font */
  108.     $myPicture->setFontProperties(array("FontName"=>"../class/system/pChart/fonts/verdana.ttf","FontSize"=>7,"R"=>80,"G"=>80,"B"=>80));
  109.     /* Define the chart area */
  110.     $myPicture->setGraphArea(50,20,480,300);
  111.  
  112.  
  113.     /* Draw the scale */
  114.     $scaleSettings array(
  115.             // grid settings
  116.             "GridR"=>160,"GridG"=>160,"GridB"=>160,"GridTicks"=>1"DrawSubTicks"=>TRUE,
  117.             // axis settings
  118.             "AxisR"=>80,"AxisG"=>80,"AxisB"=>80,
  119.             "CycleBackground"=>TRUE'LabelRotation'=>50,
  120.             "DrawArrows"=>FALSE);
  121.     $myPicture->drawScale($scaleSettings);
  122.  
  123.  
  124.  
  125.     /* Draw the chart */
  126.     $myPicture->setShadow(TRUE,array("X"=>1,"Y"=>1,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10))/* Turn on shadow computing */
  127.     $settings array(
  128.             "InnerBorderR"=>80"InnerBorderG"=>80"InnerBorderB"=>80,
  129.             "BorderR"=>80"BorderG"=>80"BorderB"=>80,
  130.             // color and gradient settings
  131.             "DisplayColor"=>DISPLAY_MANUAL,
  132.             "Gradient"=>TRUE,"GradientStartR"=>207,"GradientStartG"=>228,"GradientStartB"=>252,
  133.             "GradientEndR"=>146"GradientEndG"=>174"GradientEndB"=>206,"GradientAlpha"=>100,
  134.             // label settings
  135.             "DisplayValues"=>FALSE"DisplayPos"=>LABEL_POS_OUTSIDE,"DisplayR"=>115,"DisplayG"=>115,"DisplayB"=>115,"DisplayOrientation"=>ORIENTATION_AUTO,
  136.             "DisplayShadow"=>FALSE,
  137.             "Draw0Line"=>FALSE,
  138.             //"Rounded"=>TRUE, // not working with gradient
  139.             "Surrounding"=>-30,
  140.             "InnerSurrounding"=>0);
  141.  
  142.     /* Write the chart legend */
  143.     //$myPicture->drawLegend(50,5,array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_HORIZONTAL));
  144.  
  145.  
  146.  
  147.  
  148.     switch ($type{
  149.         case 'line':
  150.             $MyData->setSerieDrawable($full_title,TRUE);
  151.             $MyData->setSerieDrawable("thresholds",FALSE);
  152.  
  153.             $thresholdsSettings array("R"=>254,"G"=>148,"B"=>64);
  154.             $MyData->setPalette("thresholds",$thresholdsSettings);
  155.             $valuesSettings array("R"=>36,"G"=>47,"B"=>74);
  156.             $MyData->setPalette($full_title,$valuesSettings);
  157.  
  158.             //$MyData->setSerieWeight($full_title, 0.5); // will draw a 1px curve - not nice with drawSplineChart
  159.             //$myPicture->drawLineChart($settings);
  160.             $myPicture->drawSplineChart($settings);
  161.             $myPicture->drawPlotChart($settings);
  162.  
  163.             /* Draw the line and plot chart */
  164.             $myPicture->setShadow(FALSE)/* Turn off shadow computing */
  165.  
  166.             // if at least one threshold is there we display the serie on graph
  167.             if(!$is_null_threshold{
  168.                 $MyData->setSerieDrawable("thresholds",TRUE);
  169.             }
  170.             $MyData->setSerieDrawable($full_title,FALSE);
  171.             $myPicture->drawSplineChart();
  172.             // $myPicture->drawLineChart($settings);
  173.             // $myPicture->drawPlotChart();
  174.  
  175.             break;
  176.         case 'area':
  177.             $MyData->setSerieDrawable($full_title,TRUE);
  178.             $MyData->setSerieDrawable("thresholds",FALSE);
  179.                 
  180.             $thresholdsSettings array("R"=>254,"G"=>148,"B"=>64);
  181.             $MyData->setPalette("thresholds",$thresholdsSettings);
  182.             $valuesSettings array("R"=>207,"G"=>228,"B"=>252);
  183.             $MyData->setPalette($full_title,$valuesSettings);
  184.  
  185.  
  186.             $myPicture->drawAreaChart($settings);
  187.  
  188.             /* Draw the line and plot chart */
  189.             $myPicture->setShadow(FALSE)/* Turn off shadow computing */
  190.  
  191.             // if at least one threshold is there we display the serie on graph
  192.             if(!$is_null_threshold{
  193.                 $MyData->setSerieDrawable("thresholds",TRUE);
  194.             }
  195.             $MyData->setSerieDrawable($full_title,FALSE);
  196.             //$myPicture->drawSplineChart();
  197.             $myPicture->drawLineChart();
  198.             $myPicture->drawPlotChart();
  199.  
  200.             break;
  201.         default// 'column' type
  202.             $MyData->setSerieDrawable($full_title,TRUE);
  203.             $MyData->setSerieDrawable("thresholds",FALSE);
  204.  
  205.             $thresholdsSettings array("R"=>254,"G"=>148,"B"=>64);
  206.             $MyData->setPalette("thresholds",$thresholdsSettings);
  207.             $valuesSettings array("R"=>207,"G"=>228,"B"=>252);
  208.             $MyData->setPalette($full_title,$valuesSettings);
  209.  
  210.             $myPicture->drawBarChart($settings);
  211.  
  212.             /* Draw the line and plot chart */
  213.             $myPicture->setShadow(FALSE)/* Turn off shadow computing */
  214.  
  215.             // if at least one threshold is there we display the serie on graph
  216.             if(!$is_null_threshold{
  217.                 $MyData->setSerieDrawable("thresholds",TRUE);
  218.             }
  219.             $MyData->setSerieDrawable($full_title,FALSE);
  220.             $myPicture->drawSplineChart();
  221.             $myPicture->drawPlotChart();
  222.             break;
  223.     }
  224.  
  225.     if($display == true{
  226.         /* Render the picture - display it */
  227.         $myPicture->autoOutput("simple.png");
  228.     else {
  229.         /* Save the picture */
  230.         if(!file_exists($workingpath)) mkdir($workingpath);
  231.         $myPicture->render($workingpath.'/'.$id.'_'.$scale_id.'.png');
  232.     }
  233.     
  234.     return true;
  235.  
  236. }
  237.  
  238. ?>

Documentation generated on Thu, 20 Mar 2014 16:48:00 +0100 by phpDocumentor 1.4.1