diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index b379b3de12..cd0902b634 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,15 @@ +2011-04-13 Sergio Martin + + * include/functions_graph.php + include/graphs/functions_pchart.php + include/graphs/fgraph.php + include/functions_reporting.php + include/pchart_graph.php + include/fgraph.php: Change the slicebar graph + made by Javi to make it more generic and to + use the new pChart library. This graph has been + included into the graphs abstraction too + 2011-04-13 Miguel de Dios * include/graphs/functions_pchart.php: added lost lines of source code to diff --git a/pandora_console/include/fgraph.php b/pandora_console/include/fgraph.php index 9f9061f06c..7dd37c942c 100644 --- a/pandora_console/include/fgraph.php +++ b/pandora_console/include/fgraph.php @@ -2405,20 +2405,6 @@ function graph_custom_sql_graph ($id, $width, $height, $type = 1) { } } -function graph_sla_horizontal ($id, $period, $sla_min, $sla_max, $daysWeek, $time_from, $time_to, $sla_limit, $width, $height) { - global $config; - - $engine = get_graph_engine (); - - $engine->width = $width; - $engine->height = $height; - $engine->fontpath = $config['fontpath']; - $days = json_decode ($daysWeek, true); - $data = get_agentmodule_sla_array ($id, $period, $sla_min, $sla_max, $sla_limit, $days, $time_from, $time_to); - $engine->graph_sla_horizontal ($data); -} - - function myErrorHandler($errno, $errstr, $errfile, $errline) { switch ($errno) { diff --git a/pandora_console/include/functions_graph.php b/pandora_console/include/functions_graph.php index d10d9814f6..be317e0171 100755 --- a/pandora_console/include/functions_graph.php +++ b/pandora_console/include/functions_graph.php @@ -725,4 +725,14 @@ function progress_bar2($progress, $width, $height, $title = '', $mode = 1) { return "" . $title . ""; } + +function graph_sla_slicebar ($id, $period, $sla_min, $sla_max, $daysWeek, $time_from, $time_to, $sla_limit, $width, $height) { + global $config; + + $days = json_decode ($daysWeek, true); + $data = get_agentmodule_sla_array ($id, $period, $sla_min, $sla_max, $sla_limit, $days, $time_from, $time_to); + $colors = array(1 => '#38B800', 2 => '#FFFF00', 3 => '#FF0000', 4 => '#C3C3C3'); + + return slicesbar_graph($data, $width, $height, $colors, $config['fontpath'], $config['round_corner']); +} ?> \ No newline at end of file diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index cfea2ae743..57f741a07c 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -26,6 +26,7 @@ require_once ($config["homedir"]."/include/functions.php"); require_once ($config["homedir"]."/include/functions_db.php"); require_once ($config["homedir"]."/include/functions_agents.php"); include_once ($config["homedir"]."/include/fgraph.php"); +include_once ($config["homedir"]."/include/functions_graph.php"); /** @@ -2117,10 +2118,7 @@ function render_report_html_item ($content, $table, $report, $mini = false) { $data[0] = printSmallFont(get_agentmodule_agent_name ($sla['id_agent_module'])); $data[0] .= "
"; $data[0] .= printSmallFont(get_agentmodule_name ($sla['id_agent_module'])); - $data[1] = ""; + $data[1] = graph_sla_slicebar($sla['id_agent_module'], $content['period'], $sla['sla_min'], $sla['sla_max'], $daysWeek, $content['time_from'], $content['time_to'], $sla['sla_limit'], 550, 25); array_push ($table2->data, $data); } $table->colspan[4][0] = 3; diff --git a/pandora_console/include/graphs/fgraph.php b/pandora_console/include/graphs/fgraph.php index 1fff5de261..a53b31c2b1 100755 --- a/pandora_console/include/graphs/fgraph.php +++ b/pandora_console/include/graphs/fgraph.php @@ -56,6 +56,20 @@ switch($graph_type) { break; } +function slicesbar_graph($chart_data, $width, $height, $colors, $font, $round_corner) { + $graph = array(); + $graph['data'] = $chart_data; + $graph['width'] = $width; + $graph['height'] = $height; + $graph['font'] = $font; + $graph['round_corner'] = $round_corner; + $graph['color'] = $colors; + + $id_graph = serialize_in_temp($graph); + + return ""; +} + function vbar_graph($flash_chart, $chart_data, $width, $height, $color = array(), $legend = array(), $xaxisname = "", $yaxisname = "") { if($flash_chart) { echo fs_2d_column_chart ($chart_data, $width, $height); diff --git a/pandora_console/include/graphs/functions_pchart.php b/pandora_console/include/graphs/functions_pchart.php index 317f941205..0c82729d1e 100755 --- a/pandora_console/include/graphs/functions_pchart.php +++ b/pandora_console/include/graphs/functions_pchart.php @@ -66,6 +66,12 @@ $yaxisname = ''; if(isset($graph['yaxisname'])) { $yaxisname = $graph['yaxisname']; } +if(isset($graph['font'])) { + $font = $graph['font']; +} +if(isset($graph['round_corner'])) { + $round_corner = $graph['round_corner']; +} /* $colors = array(); @@ -146,6 +152,7 @@ switch($graph_type) { } break; + case 'slicebar': case 'polar': case 'radar': case 'pie3d': @@ -153,13 +160,21 @@ switch($graph_type) { break; } -if (($graph_type != 'pie3d') && ($graph_type != 'pie2d')) { - if(!is_array(reset($data_values))) { - $data_values = array($data_values); - if(is_array($colors) && !empty($colors)) { - $colors = array($colors); - } - } +switch($graph_type) { + case 'slicebar': + case 'polar': + case 'radar': + case 'pie3d': + case 'pie2d': + break; + case 'default': + if(!is_array(reset($data_values))) { + $data_values = array($data_values); + if(is_array($colors) && !empty($colors)) { + $colors = array($colors); + } + } + break; } $rgb_color = array(); @@ -206,6 +221,9 @@ switch($graph_type) { case 'pie2d': pch_pie_graph($graph_type, array_values($data), array_keys($data), $width, $height); break; + case 'slicebar': + pch_slicebar_graph($graph_type, $data, $width, $height, $colors, $font, $round_corner); + break; case 'polar': case 'radar': pch_kiviat_graph($graph_type, array_values($data), array_keys($data), $width, $height); @@ -230,6 +248,63 @@ switch($graph_type) { break; } +function pch_slicebar_graph ($graph_type, $data, $width, $height, $colors, $font, $round_corner) { + /* CAT:Slicebar charts */ + + set_time_limit (0); + + // Dataset definition + $myPicture = new pImage($width,$height); + + $myPicture->setFontProperties(array("FontName"=>"../fonts/code.ttf","FontSize"=>8,"R"=>80,"G"=>80,"B"=>80)); + + // Round corners defined in global setup + if ($round_corner != 0) + $radius = ($height > 18) ? 8 : 0; + else + $radius = 0; + + $ratio = $width / count($data); + + /* Color stuff */ + $colorsrgb = array(); + foreach($colors as $key => $col) { + $rgb = html2rgb($col); + $colorsrgb[$key]['R'] = $rgb[0]; + $colorsrgb[$key]['G'] = $rgb[1]; + $colorsrgb[$key]['B'] = $rgb[2]; + } + + $i = 0; + foreach ($data as $d) { + $color = $colorsrgb[$d]; + $myPicture->drawRoundedFilledRectangle ($i, 0, $ratio+$i, + $height, $radius, array('R' => $color['R'], 'G' => $color['G'], 'B' => $color['B'])); + $i+=$ratio; + + + } + + if ($round_corner) { + /* Under this value, the rounded rectangle is painted great */ + if ($ratio <= 16) { + /* Clean a bit of pixels */ + for ($i = 0; $i < 7; $i++) { + $myPicture->drawLine (0, $i, 6 - $i, $i, array('R' => 255, 'G' => 255, 'B' => 255)); + } + $end = $height - 1; + for ($i = 0; $i < 7; $i++) { + $myPicture->drawLine (0, $end - $i, 5 - $i, $end - $i, array('R' => 255, 'G' => 255, 'B' => 255)); + } + } + } + + $myPicture->drawRoundedRectangle (0, 0, $width, + $height - 1, $radius, array('R' => 157, 'G' => 157, 'B' => 157)); + + $myPicture->Stroke (); +} + function pch_pie_graph ($graph_type, $data_values, $legend_values, $width, $height) { /* CAT:Pie charts */ @@ -511,13 +586,11 @@ function pch_vertical_graph ($graph_type, $index, $data, $width, $height, $rgb_c if (isset($size['Height'])) { /* Define the chart area */ - //$myPicture->setGraphArea(40,$size['Height'],$width,$height - 90); - $myPicture->setGraphArea(40,$size['Height'],$width,$height - $margin_bottom); + $myPicture->setGraphArea(40,$size['Height'],$width,$height - 90); } else { /* Define the chart area */ - //$myPicture->setGraphArea(40, 5,$width,$height - 90); - $myPicture->setGraphArea(40, 5,$width,$height - $margin_bottom); + $myPicture->setGraphArea(40, 5,$width,$height - 90); } /* Draw the scale */ diff --git a/pandora_console/include/pchart_graph.php b/pandora_console/include/pchart_graph.php index 41fd5c6b1f..b8e1cd120d 100644 --- a/pandora_console/include/pchart_graph.php +++ b/pandora_console/include/pchart_graph.php @@ -652,76 +652,5 @@ class PchartGraph extends PandoraGraphAbstract { } } - public function graph_sla_horizontal ($data) { - set_time_limit (0); - // Dataset definition - $this->graph = new pChart ($this->width, $this->height); - $this->graph->setFontProperties ($this->fontpath, 8); - - // Round corners defined in global setup - global $config; - if ($config["round_corner"] != 0) - $radius = ($this->height > 18) ? 8 : 0; - else - $radius = 0; - - $ratio = $this->width / count($data); - - /* Color stuff */ - $bgcolor = $this->get_rgb_values ($this->background_color); - $r = hexdec (substr ($this->background_color, 1, 2)); - $g = hexdec (substr ($this->background_color, 3, 2)); - $b = hexdec (substr ($this->background_color, 5, 2)); - $black = '#FFFFFF'; - $colorOK = '#38B800'; - $colorEdge = '#FFFF00'; - $colorWrong = '#FF0000'; - $colorUnknown = '#C3C3C3'; - $color_black = $this->get_rgb_values ($black); - - $i = 0; - foreach ($data as $d) { - switch ($d) { - case 1: - $color = $this->get_rgb_values ($colorOK); - breaK; - case 2: - $color = $this->get_rgb_values ($colorEdge); - break; - case 3: - $color = $this->get_rgb_values ($colorWrong); - break; - case 4: - $color = $this->get_rgb_values ($colorUnknown); - break; - } - $this->graph->drawFilledRoundedRectangle ($i, 0, $ratio+$i, - $this->height, $radius, $color['r'], $color['g'], $color['b']); - $i+=$ratio; - - - } - - if ($config["round_corner"]) { - /* Under this value, the rounded rectangle is painted great */ - if ($ratio <= 16) { - /* Clean a bit of pixels */ - for ($i = 0; $i < 7; $i++) { - $this->graph->drawLine (0, $i, 6 - $i, $i, 255, 255, 255); - } - $end = $this->height - 1; - for ($i = 0; $i < 7; $i++) { - $this->graph->drawLine (0, $end - $i, 5 - $i, $end - $i, 255, 255, 255); - } - } - } - - if ($this->border) { - $this->graph->drawRoundedRectangle (0, 0, $this->width, - $this->height - 1, $radius, 157, 157, 157); - } - - $this->graph->Stroke (); - } } ?>