* @version $Id$ * @access public * @license http://opensource.org/licenses/gpl-3.0.html */ /** * Warning : If a trailing whitespace is present in any embedded file (for example, a plugin file), this graph won't display */ include_once("../config/define.php"); include_once("../languages/fr/lang_dashboard.utf-8.php"); // CAUTION : do not Turn on output buffering to prevent error on PDF / Word exports // ob_start(); use CpChart\Data; use CpChart\Draw; use CpChart\Image; //////////// Check Inclusion de pages //////////// if (!class_exists('auth')){ include_once("../lib/lib_common.php"); ReloadIndex('admin'); } //////////// // necessary because the file can be called with URL parameters or using a function (exports) if(isset($_GET['scale_id'])) $scale_id=$_GET['scale_id']; if(isset($_GET['id'])) $id=$_GET['id']; if(isset($_GET['type'])) { $type = $_GET['type']; } else { $type = 'auto'; } // getting chart sizes from config file list($width, $height) = explode('x', CHART_DEFAULT_SIZE); // getting width and height if passed to url if(isset($_GET['w'])) { $width = $_GET['w']; isset($_GET['h']) ? $height = $_GET['h'] : $height = round($width/1.4); } include_once("../class/class.sdi.php"); include_once(SQL.".inc.php"); // if display is passed to url we display it now if(isset($_GET['display'])) { generateGraphic($id, $scale_id, 'SCP', $type, true, $width, $height); } /** * * @param integer $id * @param integer $scale_id * @param string $type * @param string $workingpath */ function generateGraphic($id, $scale_id, $status, $type, $display, $width, $height, $workingpath ='') { global $sql_object; $data = $sql_object->DBSelect(SQL_getInfoSdi($id)); if($data[0]['sdii_value_type'] == 'unique' ) { return getSinglevalueGraphic($id, $scale_id, $status, $type, $display, $width, $height, $workingpath); } else { return getMultivaluesGraphic($id, $scale_id, $status, $type, $display, $width, $height, $workingpath); } } function getMultivaluesGraphic($id, $scale_id, $status, $type, $display, $width, $height, $workingpath ='') { global $sql_object; global $lang; // we get values $req_sdiav=SQL_getAllValue($status, $scale_id, $id, 'ASC'); $value = $sql_object->DBSelect($req_sdiav); $req_sdii=SQL_getInfoSdi($id); $result_sdii = $sql_object->DBSelect($req_sdii); $unit=$result_sdii[0]['sdii_unit']; $full_title=formatText($result_sdii[0]['sdii_name']); $title=cutText($full_title, 50, 0); // visualization type if($type == 'auto') { $type = $result_sdii[0]['sdii_detail_viz']; } $scaleMinVal = $scaleMaxVal = 0; $a_labels = []; $stacked_data = []; $thresholds = []; $meandata = []; // used only if $result_sdii[0]['sdii_multiple_type'] == 'mean' // we get all distinct labels for ($i=0; $iadding " . $val['value'] . " to " . $a_labels[$k]. " array

"; $is_set = true; } } // if label is not found we set VOID value if($is_set === false) { // we define the key as the array is not defined yet if(!isset($stacked_data[$a_labels[$k]])) { $stacked_data[$a_labels[$k]] = array(); } array_push($stacked_data[$a_labels[$k]], VOID); } //echo "
---------------
"; } } /* print_r($a_labels); echo "

"; print_r($thresholds); echo "

"; print_r($meandata); echo "

"; print_r($stacked_data); echo "

"; var_dump($stacked_data); exit; */ /* Create and populate the pData object */ $MyData = new Data(); // ability for user to specify a palette for each individual indicator $palette = override('../dashboard/palettes/'.$id. '.color'); if(file_exists($palette)) { $MyData->loadPalette($palette, TRUE); } else { $MyData->loadPalette(override('../dashboard/palettes/default.color'), TRUE); } // we loop on labels for ($k=0; $k'; $MyData->addPoints($stacked_data[$a_labels[$k]], $a_labels[$k]); } $MyData->setAxisName(0,$unit); $MyData->addPoints($months,"Labels"); $MyData->setSerieDescription("Labels","Months"); $MyData->setAbscissa("Labels"); /* Create the pChart object */ $myPicture = new Image($width, $height, $MyData); /* Set the default font properties */ $myPicture->setFontProperties(array("FontName"=>"../lib/fonts/verdana.ttf","FontSize"=>8,"R"=>120,"G"=>120,"B"=>120)); /* Draw the scale and the chart */ $size = $myPicture->getLegendSize(array("Style"=>LEGEND_ROUND,"Mode"=>LEGEND_VERTICAL)); $myPicture->setGraphArea($size["Width"] + 80, 20, $width - 20, $height - 50); //$myPicture->drawScale(array("DrawSubTicks"=>TRUE,"Mode"=>SCALE_MODE_ADDALL_START0)); /* Draw the scale */ // we define $scaleMinVal / $scaleMaxVal based on data foreach ($stacked_data as $k => $v) { if($result_sdii[0]['sdii_multiple_type'] == 'sum') $tmpPos = array_sum($v); // only if stacked chart else $tmpPos = max($v); $tmpNeg = min($v); if($tmpNeg < $scaleMinVal) $scaleMinVal = $tmpNeg; // we define the min value to set scale boundaries if($tmpPos > $scaleMaxVal) $scaleMaxVal = $tmpPos; // we define the max value to set scale boundaries } if($scaleMinVal < 0) $scaleMinVal = floor($scaleMinVal/10)*10; else $scaleMinVal = 0; if(max($thresholds) > $scaleMaxVal) $scaleMaxVal = max($thresholds); if(min($thresholds) < $scaleMinVal) $scaleMinVal = min($thresholds); $AxisBoundaries = array(0=>array("Min"=> $scaleMinVal,"Max"=> ceil($scaleMaxVal * 1.1 /10)*10 ) ); $scaleSettings = array( // grid settings "GridR" => 180, "GridG" => 180, "GridB" => 180, "GridTicks" => 1, "DrawSubTicks" => false, // ne pas afficher les entre ticks "Mode" => SCALE_MODE_MANUAL, // SCALE_MODE_ADDALL // SCALE_MODE_FLOATING does not display all values because is not able to calculate sum values "ManualScale" => $AxisBoundaries, // axis color "AxisR" => 200, "AxisG" => 200, "AxisB" => 200, "CycleBackground" => true, // background color 2 "BackgroundR2" => 240, "BackgroundG2" => 240, "BackgroundB2" => 240, 'LabelRotation' => 50, "DrawArrows" => FALSE, "GridAlpha" => 30, "TickAlpha" => 40 ); $myPicture->drawScale($scaleSettings); $myPicture->setShadow(FALSE); $settings = array("Surrounding" => -15, "InnerSurrounding" => 15, "Rounded" => false, // "Interleave" =>.5, "DisplayValues" => true, "DisplayR" => 80, "DisplayG" => 80, "DisplayB" => 80, ); if($result_sdii[0]['sdii_multiple_type'] == 'sum') { $myPicture->drawStackedBarChart($settings); } else { /* $MyData = new Data(); foreach ($stacked_data as $k => $v) { $MyData->addPoints($v,$k); } */ if($type == 'column') $myPicture->drawBarChart($settings); if($type == 'line') $myPicture->drawSplineChart($settings); if($type == 'area') $myPicture->drawAreaChart($settings); } // print_r($meandata); //exit; if($result_sdii[0]['sdii_multiple_type'] == 'mean') { $MyData->addPoints($meandata,_t('dashboard', 'multivalue_mean')); $meanSettings = array("R"=>1,"G"=>1,"B"=>1); $MyData->setPalette(_t('dashboard', 'multivalue_mean'), $meanSettings); $MyData->setSerieDrawable(_t('dashboard', 'multivalue_mean'),TRUE); for ($k=0; $ksetSerieDrawable($a_labels[$k],FALSE); } $MyData->setSerieTicks(_t('dashboard', 'multivalue_mean'),3); $MyData->setSerieWeight(_t('dashboard', 'multivalue_mean'), 0.2); // $MyData->setSerieDrawable($meandata,FALSE); $myPicture->drawSplineChart(); $myPicture->drawPlotChart(); } // We display threshold if(count($thresholds) > 0) { $thresholdsSettings = array("R"=>254,"G"=>148,"B"=>64); $MyData->addPoints($thresholds,_t('dashboard', 'threshold_value')); $MyData->setPalette(_t('dashboard', 'threshold_value'), $thresholdsSettings); // $MyData->setSerieWeight(_t('dashboard', 'threshold_value'), 0.2); $MyData->setSerieDrawable(_t('dashboard', 'threshold_value'), TRUE); $MyData->setSerieDrawable(_t('dashboard', 'multivalue_mean'), FALSE); // we loop on labels for ($k = 0; $k < count($a_labels); $k++) { $MyData->setSerieDrawable($a_labels[$k], FALSE); } } $myPicture->drawSplineChart(); $myPicture->drawPlotChart(); /* Make sure all series are drawable before writing the legend */ $MyData->drawAll(); if(count($thresholds) == 0) $MyData->setSerieDrawable(_t('dashboard', 'threshold_value'), FALSE); if($result_sdii[0]['sdii_multiple_type'] != 'mean') $MyData->setSerieDrawable(_t('dashboard', 'multivalue_mean'),FALSE); /* Write a label */ // $myPicture->writeLabel(array("Frontend #1","Frontend #2","Frontend #3"),2,array("DrawVerticalLine"=>TRUE)); /* Write the chart legend */ $myPicture->drawLegend(20, $height - ($size["Height"] + 50),array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_VERTICAL,"Style"=>LEGEND_ROUND, "Alpha"=>20, "")); /* Render the picture (choose the best way) */ if($display == true) { /* Render the picture - display it */ $myPicture->autoOutput("simple.png"); } else { /* Save the picture */ if(!file_exists($workingpath)) mkdir($workingpath); $myPicture->render($workingpath.'/'.$id.'_'.$scale_id.'.png'); } } function getSinglevalueGraphic($id, $scale_id, $status, $type, $display, $width, $height, $workingpath) { global $sql_object; // we get values $req_sdiav=SQL_getAllValue($status, $scale_id, $id, 'ASC'); $value = $sql_object->DBSelect($req_sdiav); $req_sdii=SQL_getInfoSdi($id); $result_sdii = $sql_object->DBSelect($req_sdii); $unit=$result_sdii[0]['sdii_unit']; $full_title=formatText($result_sdii[0]['sdii_name']); $title=cutText($full_title, 50, 0); // visualization type if($type == 'auto') { $type = $result_sdii[0]['sdii_detail_viz']; } $thresholds = array(); for ($i=0; $iloadPalette("../lib/vendor/pChart-php7/palettes/blind.color",TRUE); $MyData->setAxisName(0,$unit); $MyData->addPoints($ydata,$full_title); $MyData->addPoints($thresholds,_t('dashboard', 'threshold_value')); $MyData->addPoints($months,"Dates"); $MyData->setSerieDescription($full_title,$unit); $MyData->setAbscissa("Dates"); /* Create the pChart object */ $myPicture = new Image($width,$height,$MyData); /* Turn of Antialiasing */ $myPicture->Antialias = TRUE; /* Add a border to the picture */ // $myPicture->drawRectangle(0,0,499,349,array("R"=>180,"G"=>180,"B"=>180)); /* Set the default font */ $myPicture->setFontProperties(array("FontName"=>"../lib/fonts/verdana.ttf","FontSize"=>8,"R"=>120,"G"=>120,"B"=>120)); /* Define the chart area */ $myPicture->setGraphArea(50,20,$width-20,$height-50); // we define $scaleMinVal / $scaleMaxVal based on data $scaleMinVal = $scaleMaxVal = 0; $scaleMaxVal = max($ydata); if( min($ydata) < 0) $scaleMinVal = min($ydata); if(max($thresholds) > $scaleMaxVal) $scaleMaxVal = max($thresholds); if(min($thresholds) < $scaleMinVal) $scaleMinVal = min($thresholds); $AxisBoundaries = array(0=>array("Min"=> $scaleMinVal,"Max"=> ceil($scaleMaxVal * 1.1 /10)*10 ) ); /* Draw the scale */ $scaleSettings = array( // grid settings "GridR" => 180, "GridG" => 180, "GridB" => 180, "GridTicks" => 1, "DrawSubTicks" => false, // ne pas afficher les entre ticks "Mode" => SCALE_MODE_MANUAL, // SCALE_MODE_FLOATING // SCALE_MODE_ADDALL prevent "non-numeric input" error with pChart-php7 see aroune line 2005 in /class/pDraw.class.php "ManualScale" => $AxisBoundaries, // axis color "AxisR" => 200, "AxisG" => 200, "AxisB" => 200, "CycleBackground" => true, // background color 2 "BackgroundR2" => 240, "BackgroundG2" => 240, "BackgroundB2" => 240, 'LabelRotation' => 50, "DrawArrows" => FALSE, "GridAlpha" => 30, "TickAlpha" => 40 ); $myPicture->drawScale($scaleSettings); /* Draw the chart */ $myPicture->setShadow(TRUE,array("X"=>1,"Y"=>1,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10)); /* Turn on shadow computing */ $settings = array( //"InnerBorderR"=>80, "InnerBorderG"=>80, "InnerBorderB"=>80, //"BorderR"=>210, "BorderG"=>210, "BorderB"=>210, // color and gradient settings // "Rounded"=>true, "DisplayColor"=> DISPLAY_MANUAL, "DisplayR"=> 98, "DisplayG"=> 194,"DisplayB" => 204, // "Gradient"=>TRUE,"GradientStartR"=>207,"GradientStartG"=>228,"GradientStartB"=>252, "Gradient"=>FALSE, // label settings "DisplayValues"=>FALSE, "DisplayPos"=>LABEL_POS_OUTSIDE,"DisplayR"=>115,"DisplayG"=>115,"DisplayB"=>115,"DisplayOrientation"=>ORIENTATION_AUTO, "DisplayShadow"=>FALSE, "Draw0Line"=>FALSE, //"Rounded"=>TRUE, // not working with gradient "Surrounding"=>-30, "InnerSurrounding"=>0); /* Write the chart legend */ //$myPicture->drawLegend(50,5,array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_HORIZONTAL)); switch ($type) { case 'line': $MyData->setSerieDrawable($full_title,TRUE); $MyData->setSerieDrawable(_t('dashboard', 'threshold_value'),FALSE); // $thresholdsSettings = array("R"=>254,"G"=>148,"B"=>64); // Hexa : #FE9440 list($r, $g, $b) = sscanf($result_sdii[0]['sdii_tcolor'], "#%02x%02x%02x"); // convert hexadecimal to RGB $thresholdsSettings = array("R"=>$r,"G"=>$g,"B"=>$b); $MyData->setPalette(_t('dashboard', 'threshold_value'),$thresholdsSettings); // $valuesSettings = array("R"=>36,"G"=>47,"B"=>74); // bleu foncé // $valuesSettings = array("R"=>74,"G"=>192,"B"=>242); // bleu clair Hexa : #4AC0F2 list($r, $g, $b) = sscanf($result_sdii[0]['sdii_mcolor'], "#%02x%02x%02x"); // convert hexadecimal to RGB $valuesSettings = array("R"=>$r,"G"=>$g,"B"=>$b); $MyData->setPalette($full_title,$valuesSettings); /** * Do not activate because it creates aliasing $MyData->setSerieTicks(_t('dashboard', 'threshold_value'),4); $MyData->setSerieWeight(_t('dashboard', 'threshold_value'), 0.5); $MyData->setSerieWeight($full_title, 1); */ //$MyData->setSerieWeight($full_title, 0.5); // will draw a 1px curve - not nice with drawSplineChart //$myPicture->drawLineChart($settings); $myPicture->drawSplineChart($settings); $myPicture->drawPlotChart($settings); /* Draw the line and plot chart */ $myPicture->setShadow(FALSE); /* Turn off shadow computing */ $MyData->setSerieDrawable(_t('dashboard', 'threshold_value'),TRUE); $MyData->setSerieDrawable($full_title,FALSE); $myPicture->drawSplineChart(); // $myPicture->drawLineChart($settings); // $myPicture->drawPlotChart(); break; case 'area': $MyData->setSerieDrawable($full_title,TRUE); $MyData->setSerieDrawable(_t('dashboard', 'threshold_value'),FALSE); // $thresholdsSettings = array("R"=>254,"G"=>148,"B"=>64); list($r, $g, $b) = sscanf($result_sdii[0]['sdii_tcolor'], "#%02x%02x%02x"); // convert hexadecimal to RGB $thresholdsSettings = array("R"=>$r,"G"=>$g,"B"=>$b); $MyData->setPalette(_t('dashboard', 'threshold_value'),$thresholdsSettings); // $valuesSettings = array("R"=>137,"G"=>214,"B"=>244, "Alpha"=>100); // bleu clair list($r, $g, $b) = sscanf($result_sdii[0]['sdii_mcolor'], "#%02x%02x%02x"); // convert hexadecimal to RGB $valuesSettings = array("R"=>$r,"G"=>$g,"B"=>$b); $MyData->setPalette($full_title,$valuesSettings); // il faut utiliser les seuils pour choisir la couleur de remplissage list($r, $g, $b) = sscanf($result_sdii[0]['sdii_mcolor'], "#%02x%02x%02x"); // convert hexadecimal to RGB //$Threshold[0] = array("Min"=>-9999,"Max"=>99999999999,"R"=>$r,"G"=>$g,"B"=>$b,"Alpha"=>80); $Threshold[0] = array("Min"=>-9999,"Max"=>99999999999,"R"=>137,"G"=>214,"B"=>244,"Alpha"=>80); $myPicture->drawAreaChart(array("Threshold"=>$Threshold)); /* Draw the line and plot chart */ $myPicture->setShadow(FALSE); /* Turn off shadow computing */ $MyData->setSerieDrawable(_t('dashboard', 'threshold_value'),TRUE); $MyData->setSerieDrawable($full_title,FALSE); $myPicture->drawSplineChart(); //$myPicture->drawLineChart(); $myPicture->drawPlotChart(); break; default: // 'column' type $MyData->setSerieDrawable($full_title,TRUE); $MyData->setSerieDrawable(_t('dashboard', 'threshold_value'),FALSE); // $thresholdsSettings = array("R"=>254,"G"=>148,"B"=>64); list($r, $g, $b) = sscanf($result_sdii[0]['sdii_tcolor'], "#%02x%02x%02x"); // convert hexadecimal to RGB $thresholdsSettings = array("R"=>$r,"G"=>$g,"B"=>$b); $MyData->setPalette(_t('dashboard', 'threshold_value'),$thresholdsSettings); // $valuesSettings = array("R"=>207,"G"=>228,"B"=>252); // $valuesSettings = array("R"=>98,"G"=>194,"B"=>204); # azur // $valuesSettings = array("R"=>74,"G"=>192,"B"=>242, "Alpha"=> 100); // bleu clair // $valuesSettings = array("R"=>137,"G"=>214,"B"=>244, "Alpha"=> 100); // bleu clair list($r, $g, $b) = sscanf($result_sdii[0]['sdii_mcolor'], "#%02x%02x%02x"); // convert hexadecimal to RGB $valuesSettings = array("R"=>$r,"G"=>$g,"B"=>$b, "Alpha"=> 90); $MyData->setPalette($full_title,$valuesSettings); $myPicture->drawBarChart($settings); /* Draw the line and plot chart */ $myPicture->setShadow(FALSE); /* Turn off shadow computing */ $MyData->setSerieDrawable(_t('dashboard', 'threshold_value'),TRUE); $MyData->setSerieDrawable($full_title,FALSE); $myPicture->drawSplineChart(); $myPicture->drawPlotChart(); break; } if($display == true) { /* Render the picture - display it */ $myPicture->autoOutput("simple.png"); } else { /* Save the picture */ if(!file_exists($workingpath)) mkdir($workingpath); $myPicture->render($workingpath.'/'.$id.'_'.$scale_id.'.png'); } return true; } ?>