diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 60bd546527..0ca2d32514 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,14 @@ +2011-04-01 Sergio Martin + + * include/graphs/functions_pchart.php + include/graphs/pChart/pDraw.class.php + include/graphs/fgraph.php + include/graphs/functions_utils.php: Changed the send data method + from sessions to files with serialize functions. Creation of a + utils functions file. Improvement of the pChart library adding + attributes to avoid ticks and grids when the data under the + xaxis is empty. + 2011-04-01 Juan Manuel Ramon * operation/gis_maps/render_view.php: Fixed bad sql query sintax. diff --git a/pandora_console/include/graphs/fgraph.php b/pandora_console/include/graphs/fgraph.php index f1fa657c57..68d08e8815 100755 --- a/pandora_console/include/graphs/fgraph.php +++ b/pandora_console/include/graphs/fgraph.php @@ -1,8 +1,5 @@ // This program is free software; you can redistribute it and/or @@ -14,13 +11,25 @@ // GNU General Public License for more details. include_once('functions_fsgraph.php'); +include_once('functions_utils.php'); -function vbar_graph($flash_chart, $chart_data, $width, $height) { +function vbar_graph($flash_chart, $chart_data, $width, $height, $color, $legend) { if($flash_chart) { echo fs_2d_column_chart ($chart_data, $width, $height); } else { - echo ""; + $id_graph = uniqid(); + + $graph = array(); + $graph['data'] = $chart_data; + $graph['width'] = $width; + $graph['height'] = $height; + $graph['color'] = $color; + $graph['legend'] = $legend; + + $id_graph = serialize_in_temp($graph); + + echo ""; } } diff --git a/pandora_console/include/graphs/functions_pchart.php b/pandora_console/include/graphs/functions_pchart.php index 8e2f8e52f7..3bbac7cfbf 100755 --- a/pandora_console/include/graphs/functions_pchart.php +++ b/pandora_console/include/graphs/functions_pchart.php @@ -13,8 +13,9 @@ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -include_once("../functions.php"); -include_once("../functions_html.php"); +include_once('functions_utils.php'); +include_once('../functions.php'); +include_once('../functions_html.php'); /* pChart library inclusions */ include_once("pChart/pData.class.php"); @@ -36,10 +37,7 @@ $legend = json_decode(safe_output(get_parameter('legend')), true); $id_graph = get_parameter('id_graph', false); if ($id_graph) { - session_start(); - $graph = $_SESSION['graph_session'][$id_graph]; - unset($_SESSION['graph_session'][$id_graph]); - session_write_close(); + $graph = unserialize_in_temp($id_graph, false); if (isset($graph)) { $data = $graph['data']; @@ -68,13 +66,6 @@ if ($id_graph) { $rgb_color[$i]['alpha'] = $color['alpha']; } -// $graph['avg_only'] = $avg_only; -// $graph['resolution'] = $resolution; -// $graph['time_format'] = $time_format; -// $graph['show_events'] = $show_events; -// $graph['show_alerts'] = $show_alerts; -// $graph['caption'] = $caption; -// $graph['baseline'] = $baseline; } } @@ -157,8 +148,7 @@ function pch_pie_graph ($graph_type, $data_values, $legend_values, $width, $heig $myPicture = new pImage($width,$height,$MyData,TRUE); /* Set the default font properties */ - //$myPicture->setFontProperties(array("FontName"=>"pChart/fonts/verdana.ttf","FontSize"=>8,"R"=>80,"G"=>80,"B"=>80)); - $myPicture->setFontProperties(array("FontName"=>"pChart/fonts/code.ttf","FontSize"=>8,"R"=>80,"G"=>80,"B"=>80)); + $myPicture->setFontProperties(array("FontName"=>"../fonts/code.ttf","FontSize"=>8,"R"=>80,"G"=>80,"B"=>80)); /* Create the pPie object */ $PieChart = new pPie($myPicture,$MyData); @@ -199,7 +189,7 @@ function pch_radar_graph ($graph_type, $data_values, $legend_values, $width, $he $myPicture = new pImage($width,$height,$MyData,TRUE); /* Set the default font properties */ - $myPicture->setFontProperties(array("FontName"=>"pChart/fonts/code.ttf","FontSize"=>8,"R"=>80,"G"=>80,"B"=>80)); + $myPicture->setFontProperties(array("FontName"=>"../fonts/code.ttf","FontSize"=>8,"R"=>80,"G"=>80,"B"=>80)); /* Create the pRadar object */ $SplitChart = new pRadar(); @@ -210,11 +200,11 @@ function pch_radar_graph ($graph_type, $data_values, $legend_values, $width, $he /* Draw an AA pie chart */ switch($graph_type) { case "radar": - $Options = array("SkipLabels"=>0,"LabelPos"=>RADAR_LABELS_HORIZONTAL, "LabelMiddle"=>FALSE,"Layout"=>RADAR_LAYOUT_STAR,"BackgroundGradient"=>array("StartR"=>255,"StartG"=>255,"StartB"=>255,"StartAlpha"=>100,"EndR"=>207,"EndG"=>227,"EndB"=>125,"EndAlpha"=>50), "FontName"=>"pChart/fonts/pf_arma_five.ttf","FontSize"=>6); + $Options = array("SkipLabels"=>0,"LabelPos"=>RADAR_LABELS_HORIZONTAL, "LabelMiddle"=>FALSE,"Layout"=>RADAR_LAYOUT_STAR,"BackgroundGradient"=>array("StartR"=>255,"StartG"=>255,"StartB"=>255,"StartAlpha"=>100,"EndR"=>207,"EndG"=>227,"EndB"=>125,"EndAlpha"=>50), "FontName"=>"../fonts/code.ttf","FontSize"=>6); $SplitChart->drawRadar($myPicture,$MyData,$Options); break; case "polar": - $Options = array("Layout"=>RADAR_LAYOUT_CIRCLE,"BackgroundGradient"=>array("StartR"=>255,"StartG"=>255,"StartB"=>255,"StartAlpha"=>100,"EndR"=>207,"EndG"=>227,"EndB"=>125,"EndAlpha"=>50), "FontName"=>"pChart/fonts/pf_arma_five.ttf","FontSize"=>6); + $Options = array("Layout"=>RADAR_LAYOUT_CIRCLE,"BackgroundGradient"=>array("StartR"=>255,"StartG"=>255,"StartB"=>255,"StartAlpha"=>100,"EndR"=>207,"EndG"=>227,"EndB"=>125,"EndAlpha"=>50), "FontName"=>"../fonts/code.ttf","FontSize"=>6); $SplitChart->drawRadar($myPicture,$MyData,$Options); break; } @@ -224,7 +214,7 @@ function pch_radar_graph ($graph_type, $data_values, $legend_values, $width, $he } /* TOFIX */ -function pch_vbar_graph ($graph_type, $index, $data, $width, $height, $rgb_color = false, $xaxisname = "", $yaxisname = "", $show_values = false, $show_legend = true) { +function pch_bar_graph ($graph_type, $index, $data, $width, $height, $rgb_color = false, $xaxisname = "", $yaxisname = "", $show_values = false, $show_legend = true) { /* CAT: Vertical Bar Chart */ if(is_array($data[0])) { $data2 = array(); @@ -244,11 +234,19 @@ function pch_vbar_graph ($graph_type, $index, $data, $width, $height, $rgb_color /* Create and populate the pData object */ $MyData = new pData(); foreach($data as $i => $values) { - $MyData->addPoints($values,$i); - $MyData->setPalette($i, array("R" => $rgb_color[$i]['color']["R"], "G" => $rgb_color[$i]['color']["G"], "B" => $rgb_color[$i]['color']["B"], "Alpha" => $rgb_color[$i]['alpha'])); + $MyData->addPoints($values,"bar"); + if($rgb_color !== false) { + $MyData->setPalette($i, + array("R" => $rgb_color[$i]['color']["R"], + "G" => $rgb_color[$i]['color']["G"], + "B" => $rgb_color[$i]['color']["B"], + "BorderR" => $rgb_color[$i]['border']["R"], + "BorderG" => $rgb_color[$i]['border']["G"], + "BorderB" => $rgb_color[$i]['border']["B"], + "Alpha" => $rgb_color[$i]['alpha'])); + } } - //$MyData->addPoints($data,"Yaxis"); $MyData->setAxisName(0,$yaxisname); $MyData->addPoints($index,"Xaxis"); $MyData->setSerieDescription("Xaxis", $xaxisname); @@ -264,13 +262,15 @@ function pch_vbar_graph ($graph_type, $index, $data, $width, $height, $rgb_color //$myPicture->drawRectangle(0,0,$width,$height,array("R"=>0,"G"=>0,"B"=>0)); /* Set the default font */ - $myPicture->setFontProperties(array("FontName"=>"pChart/fonts/code.ttf","FontSize"=>7)); + $myPicture->setFontProperties(array("FontName"=>"../fonts/code.ttf","FontSize"=>10)); /* Define the chart area */ $myPicture->setGraphArea(30,20,$width,$height-100); /* Draw the scale */ - $scaleSettings = array("GridR"=>200,"GridG"=>200,"GridB"=>200,"DrawSubTicks"=>TRUE,"CycleBackground"=>TRUE, "Mode"=>SCALE_MODE_START0, "XMargin" => 40, "LabelRotation" => 90); + // TODO: AvoidTickWhenEmpty = FALSE When the distance between two ticks will be less than 50 px + // TODO: AvoidTickWhenEmpty = TRUE When the distance between two ticks will be greater than 50 px + $scaleSettings = array("AvoidTickWhenEmpty" => FALSE, "AvoidGridWhenEmpty" => FALSE, "GridR"=>200,"GridG"=>200,"GridB"=>200,"DrawSubTicks"=>TRUE,"CycleBackground"=>TRUE, "Mode"=>SCALE_MODE_START0, "XMargin" => 40, "LabelRotation" => 90); $myPicture->drawScale($scaleSettings); if($show_legend) { @@ -289,7 +289,7 @@ function pch_vbar_graph ($graph_type, $index, $data, $width, $height, $rgb_color $myPicture->drawBarChart($settings); break; } - + /* Render the picture */ $myPicture->stroke(); } @@ -329,19 +329,17 @@ function pch_vertical_graph ($graph_type, $index, $data, $width, $height, $rgb_c $point_id = $i; } - if ($i == 'alert') { - $values[100] = 100; - } - $MyData->addPoints($values,$point_id); - $MyData->setPalette($point_id, - array("R" => $rgb_color[$i]['color']["R"], - "G" => $rgb_color[$i]['color']["G"], - "B" => $rgb_color[$i]['color']["B"], - "BorderR" => $rgb_color[$i]['border']["R"], - "BorderG" => $rgb_color[$i]['border']["G"], - "BorderB" => $rgb_color[$i]['border']["B"], - "Alpha" => $rgb_color[$i]['alpha'])); + if($rgb_color !== false) { + $MyData->setPalette($point_id, + array("R" => $rgb_color[$i]['color']["R"], + "G" => $rgb_color[$i]['color']["G"], + "B" => $rgb_color[$i]['color']["B"], + "BorderR" => $rgb_color[$i]['border']["R"], + "BorderG" => $rgb_color[$i]['border']["G"], + "BorderB" => $rgb_color[$i]['border']["B"], + "Alpha" => $rgb_color[$i]['alpha'])); + } } //$MyData->addPoints($data,"Yaxis"); @@ -360,7 +358,7 @@ function pch_vertical_graph ($graph_type, $index, $data, $width, $height, $rgb_c //$myPicture->drawRectangle(0,0,$width,$height,array("R"=>0,"G"=>0,"B"=>0)); /* Set the default font */ - $myPicture->setFontProperties(array("FontName"=>"pChart/fonts/code.ttf","FontSize"=>7)); + $myPicture->setFontProperties(array("FontName"=>"../fonts/code.ttf","FontSize"=>7)); /* Define the chart area */ $myPicture->setGraphArea(30,20,$width,$height-100); @@ -371,7 +369,6 @@ function pch_vertical_graph ($graph_type, $index, $data, $width, $height, $rgb_c if(isset($legend)) { /* Write the chart legend */ - //$myPicture->drawLegend($height/2,$width/1.8,array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_HORIZONTAL)); $myPicture->drawLegend($height/2,$height-20,array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_HORIZONTAL)); } @@ -420,7 +417,7 @@ function pch_threshold_graph ($graph_type, $index, $data, $width, $height, $xaxi $myPicture->drawRectangle(0,0,699,229,array("R"=>200,"G"=>200,"B"=>200)); /* Write the picture title */ - $myPicture->setFontProperties(array("FontName"=>"pChart/fonts/code.ttf","FontSize"=>11)); + $myPicture->setFontProperties(array("FontName"=>"../fonts/code.ttf","FontSize"=>11)); $myPicture->drawText(60,35,$title,array("FontSize"=>20,"Align"=>TEXT_ALIGN_BOTTOMLEFT)); /* Do some cosmetic and draw the chart */ @@ -428,7 +425,7 @@ function pch_threshold_graph ($graph_type, $index, $data, $width, $height, $xaxi $myPicture->drawFilledRectangle(60,40,670,190,array("R"=>255,"G"=>255,"B"=>255,"Surrounding"=>-200,"Alpha"=>10)); $myPicture->drawScale(array("GridR"=>180,"GridG"=>180,"GridB"=>180, "Mode" => SCALE_MODE_START0)); $myPicture->setShadow(TRUE,array("X"=>2,"Y"=>2,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10)); - $myPicture->setFontProperties(array("FontName"=>"pChart/fonts/code.ttf","FontSize"=>6)); + $myPicture->setFontProperties(array("FontName"=>"../fonts/code.ttf","FontSize"=>6)); $settings = array("Gradient"=>TRUE,"GradientMode"=>GRADIENT_EFFECT_CAN,"DisplayValues"=>$show_values,"DisplayZeroValues"=>FALSE,"DisplayR"=>100,"DisplayG"=>100,"DisplayB"=>100,"DisplayShadow"=>TRUE,"Surrounding"=>5,"AroundZero"=>FALSE); $myPicture->drawSplineChart($settings); $myPicture->setShadow(FALSE); @@ -462,7 +459,7 @@ function pch_horizontal_graph ($graph_type, $index, $data, $width, $height, $xax //$myPicture->drawRectangle(0,0,$width,$height,array("R"=>0,"G"=>0,"B"=>0)); /* Set the default font */ - $myPicture->setFontProperties(array("FontName"=>"pChart/fonts/code.ttf","FontSize"=>7)); + $myPicture->setFontProperties(array("FontName"=>"../fonts/code.ttf","FontSize"=>7)); /* Define the chart area */ $myPicture->setGraphArea(75,20,$width,$height); diff --git a/pandora_console/include/graphs/functions_utils.php b/pandora_console/include/graphs/functions_utils.php new file mode 100644 index 0000000000..a04159fb8a --- /dev/null +++ b/pandora_console/include/graphs/functions_utils.php @@ -0,0 +1,60 @@ + + +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; version 2 +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +function serialize_in_temp($array = array(), $serial_id = null) { + $json = json_encode($array); + + if($serial_id === null) { + $serial_id = uniqid(); + } + + $file_path = sys_get_temp_dir()."/pandora_serialize_".$serial_id; + + if(file_put_contents($file_path, $json) === false) { + return false; + } + + return $serial_id; +} + +function unserialize_in_temp($serial_id = null, $delete = true) { + if($serial_id === null) { + return false; + } + + $file_path = sys_get_temp_dir()."/pandora_serialize_".$serial_id; + + $content = file_get_contents($file_path); + + if($content === false) { + return false; + } + + $array = json_decode($content, true); + + if($delete) { + unlink($file_path); + } + + return $array; +} + +function delete_unserialize_in_temp($serial_id = null) { + if($serial_id === null) { + return false; + } + + $file_path = sys_get_temp_dir()."/pandora_serialize_".$serial_id; + + return unlink($file_path); +} +?> diff --git a/pandora_console/include/graphs/pChart/pDraw.class.php b/pandora_console/include/graphs/pChart/pDraw.class.php index 2a6f54c08c..addcf0fb7d 100755 --- a/pandora_console/include/graphs/pChart/pDraw.class.php +++ b/pandora_console/include/graphs/pChart/pDraw.class.php @@ -1707,6 +1707,7 @@ $OuterTickWidth = isset($Format["OuterTickWidth"]) ? $Format["OuterTickWidth"] : 2; $DrawXLines = isset($Format["DrawXLines"]) ? $Format["DrawXLines"] : TRUE; $DrawYLines = isset($Format["DrawYLines"]) ? $Format["DrawYLines"] : ALL; + $AvoidGridWhenEmpty = isset($Format["AvoidGridWhenEmpty"]) ? $Format["AvoidGridWhenEmpty"] : FALSE; $GridTicks = isset($Format["GridTicks"]) ? $Format["GridTicks"] : 4; $GridR = isset($Format["GridR"]) ? $Format["GridR"] : 255; $GridG = isset($Format["GridG"]) ? $Format["GridG"] : 255; @@ -1716,6 +1717,7 @@ $AxisGo = isset($Format["AxisG"]) ? $Format["AxisG"] : 0; $AxisBo = isset($Format["AxisB"]) ? $Format["AxisB"] : 0; $AxisAlpha = isset($Format["AxisAlpha"]) ? $Format["AxisAlpha"] : 100; + $AvoidTickWhenEmpty = isset($Format["AvoidTickWhenEmpty"]) ? $Format["AvoidTickWhenEmpty"] : FALSE; $TickRo = isset($Format["TickR"]) ? $Format["TickR"] : 0; $TickGo = isset($Format["TickG"]) ? $Format["TickG"] : 0; $TickBo = isset($Format["TickB"]) ? $Format["TickB"] : 0; @@ -1978,8 +1980,16 @@ } else { - if ( $DrawXLines && ($XPos != $this->GraphAreaX1 && $XPos != $this->GraphAreaX2) ) { $this->drawLine($XPos,$this->GraphAreaY1+$FloatingOffset,$XPos,$this->GraphAreaY2-$FloatingOffset,array("R"=>$GridR,"G"=>$GridG,"B"=>$GridB,"Alpha"=>$GridAlpha,"Ticks"=>$GridTicks)); } - if ( $InnerTickWidth !=0 || $OuterTickWidth != 0 ) { $this->drawLine($XPos,$YPos-$InnerTickWidth,$XPos,$YPos+$OuterTickWidth,array("R"=>$TickR,"G"=>$TickG,"B"=>$TickB,"Alpha"=>$TickAlpha)); } + if ( $DrawXLines && ($XPos != $this->GraphAreaX1 && $XPos != $this->GraphAreaX2) ) { + if($Data["Series"][$Abscissa]["Data"][$i] != "" || $AvoidGridWhenEmpty) { + $this->drawLine($XPos,$this->GraphAreaY1+$FloatingOffset,$XPos,$this->GraphAreaY2-$FloatingOffset,array("R"=>$GridR,"G"=>$GridG,"B"=>$GridB,"Alpha"=>$GridAlpha,"Ticks"=>$GridTicks)); + } + } + if ( $InnerTickWidth !=0 || $OuterTickWidth != 0 ) { + if($Data["Series"][$Abscissa]["Data"][$i] != "" || $AvoidTickWhenEmpty) { + $this->drawLine($XPos,$YPos-$InnerTickWidth,$XPos,$YPos+$OuterTickWidth,array("R"=>$TickR,"G"=>$TickG,"B"=>$TickB,"Alpha"=>$TickAlpha)); + } + } } }