2010-08-29 Sancho Lerena <slerena@artica.es>

* include/pchart_graph.php,
        include/fgraph.php,
        include/functions_fsgraph.php: Minor (but important) changes on 
        graphs: combined wired mode available on flash, improved legends
        on both types, and improved flash wired modes.




git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@3189 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
slerena 2010-08-30 11:52:13 +00:00
parent 64e83fa9e3
commit c9d3188e35
4 changed files with 118 additions and 37 deletions

View File

@ -1,3 +1,11 @@
2010-08-29 Sancho Lerena <slerena@artica.es>
* include/pchart_graph.php,
include/fgraph.php,
include/functions_fsgraph.php: Minor (but important) changes on
graphs: combined wired mode available on flash, improved legends
on both types, and improved flash wired modes.
2010-08-29 Raúl Mateos <raulofpandora@gmail.com> 2010-08-29 Raúl Mateos <raulofpandora@gmail.com>
* godmode/agentes/fields_manager.php: Added code to show text if no * godmode/agentes/fields_manager.php: Added code to show text if no

View File

@ -158,7 +158,7 @@ function graphic_combined_module ($module_list, $weight_list, $period, $width, $
$agent_name = get_agentmodule_agent_name ($agent_module_id); $agent_name = get_agentmodule_agent_name ($agent_module_id);
$agent_id = get_agent_id ($agent_name); $agent_id = get_agent_id ($agent_name);
$module_name = get_agentmodule_name ($agent_module_id); $module_name = get_agentmodule_name ($agent_module_id);
$module_name_list[$i] = $agent_name." / ".substr ($module_name, 0, 20); $module_name_list[$i] = $agent_name." / ".substr ($module_name, 0, 40);
$id_module_type = get_agentmodule_type ($agent_module_id); $id_module_type = get_agentmodule_type ($agent_module_id);
$module_type = get_moduletype_name ($id_module_type); $module_type = get_moduletype_name ($id_module_type);
$uncompressed_module = is_module_uncompressed ($module_type); $uncompressed_module = is_module_uncompressed ($module_type);

View File

@ -134,17 +134,36 @@ function fs_2d_area_chart ($data, $width, $height, $step = 1, $params = '') {
function fs_module_chart ($data, $width, $height, $avg_only = 1, $step = 10, $time_format = 'G:i', $show_events = 0, $show_alerts = 0, $caption = '') { function fs_module_chart ($data, $width, $height, $avg_only = 1, $step = 10, $time_format = 'G:i', $show_events = 0, $show_alerts = 0, $caption = '') {
global $config; global $config;
$graph_type = "MSArea2D"; //MSLine is possible also
// Generate the XML // Generate the XML
$chart = new FusionCharts('MSArea2D', $width, $height); $chart = new FusionCharts($graph_type, $width, $height);
$num_vlines = 0; $num_vlines = 0;
$count = 0; $count = 0;
// NO caption needed (graph avg/max/min stats are in the legend now)
/*
if ($caption != '') { if ($caption != '') {
$chart->setChartParam("caption", $caption); $chart->setChartParam("caption", $caption);
} }
*/
$total_max = 0;
$total_avg = 0;
$total_min = 0;
// Create categories // Create categories
foreach ($data as $value) { foreach ($data as $value) {
$total_avg +=$value["sum"];
if ($avg_only != 1){
if ($value["max"] > $total_max)
$total_max =$value["max"];
if ($value["min"] < $total_min)
$total_min =$value["min"];
}
if ($count++ % $step == 0) { if ($count++ % $step == 0) {
$show_name = '1'; $show_name = '1';
$num_vlines++; $num_vlines++;
@ -154,6 +173,14 @@ function fs_module_chart ($data, $width, $height, $avg_only = 1, $step = 10, $ti
$chart->addCategory(date($time_format, $value['timestamp_bottom']), 'hoverText=' . date ($config['date_format'], $value['timestamp_bottom']) . ';showName=' . $show_name); $chart->addCategory(date($time_format, $value['timestamp_bottom']), 'hoverText=' . date ($config['date_format'], $value['timestamp_bottom']) . ';showName=' . $show_name);
} }
if ($count > 0)
$total_avg = format_for_graph($total_avg / $count);
else
$total_avg = 0;
$total_min = format_for_graph ($total_min);
$total_max = format_for_graph ($total_max);
// Event chart // Event chart
if ($show_events == 1) { if ($show_events == 1) {
$chart->addDataSet(__('Events'), 'alpha=50;showAreaBorder=1;areaBorderColor=#ff7f00;color=#ff7f00'); $chart->addDataSet(__('Events'), 'alpha=50;showAreaBorder=1;areaBorderColor=#ff7f00;color=#ff7f00');
@ -172,7 +199,7 @@ function fs_module_chart ($data, $width, $height, $avg_only = 1, $step = 10, $ti
// Max chart // Max chart
if ($avg_only == 0) { if ($avg_only == 0) {
$chart->addDataSet(__('Max'), 'color=' . $config['graph_color3']); $chart->addDataSet(__('Max')." ($total_max)", 'color=' . $config['graph_color3']);
foreach ($data as $value) { foreach ($data as $value) {
$chart->addChartData($value['max']); $chart->addChartData($value['max']);
} }
@ -180,7 +207,7 @@ function fs_module_chart ($data, $width, $height, $avg_only = 1, $step = 10, $ti
// Avg chart // Avg chart
$empty = 1; $empty = 1;
$chart->addDataSet(__('Avg'), 'color=' . $config['graph_color2']); $chart->addDataSet(__('Avg'). " ($total_avg)", 'color=' . $config['graph_color2']);
foreach ($data as $value) { foreach ($data as $value) {
if ($value['sum'] > 0) { if ($value['sum'] > 0) {
$empty = 0; $empty = 0;
@ -190,13 +217,13 @@ function fs_module_chart ($data, $width, $height, $avg_only = 1, $step = 10, $ti
// Min chart // Min chart
if ($avg_only == 0) { if ($avg_only == 0) {
$chart->addDataSet(__('Min'), 'color=' . $config['graph_color1']); $chart->addDataSet(__('Min'). " ($total_min)", 'color=' . $config['graph_color1']);
foreach ($data as $value) { foreach ($data as $value) {
$chart->addChartData($value['min']); $chart->addChartData($value['min']);
} }
} }
$chart->setChartParams('animation=0;numVDivLines=' . $num_vlines . ';showAlternateVGridColor=1;showNames=1;rotateNames=1;showValues=0;baseFontSize=9;showLimits=0;showAreaBorder=1;areaBorderThickness=1;areaBorderColor=000000' . ($empty == 1 ? ';yAxisMinValue=0;yAxisMaxValue=1' : '')); $chart->setChartParams('animation=0;numVDivLines=' . $num_vlines . ';showShadow=0;showAlternateVGridColor=1;showNames=1;rotateNames=1;lineThickness=0.1;anchorRadius=0.5;showValues=0;baseFontSize=9;showLimits=0;showAreaBorder=1;areaBorderThickness=0.1;areaBorderColor=000000' . ($empty == 1 ? ';yAxisMinValue=0;yAxisMaxValue=1' : ''));
$random_number = rand (); $random_number = rand ();
$div_id = 'chart_div_' . $random_number; $div_id = 'chart_div_' . $random_number;
@ -208,7 +235,7 @@ function fs_module_chart ($data, $width, $height, $avg_only = 1, $step = 10, $ti
$output .= '<script type="text/javascript"> $output .= '<script type="text/javascript">
<!-- <!--
function pie_' . $chart_id . ' () { function pie_' . $chart_id . ' () {
var myChart = new FusionCharts("' . $pre_url . '/include/FusionCharts/FCF_MSArea2D.swf", "' . $chart_id . '", "' . $width. '", "' . $height. '", "0", "1"); var myChart = new FusionCharts("' . $pre_url . '/include/FusionCharts/FCF_'.$graph_type.'.swf", "' . $chart_id . '", "' . $width. '", "' . $height. '", "0", "1");
myChart.setDataXML("' . addslashes($chart->getXML ()) . '"); myChart.setDataXML("' . addslashes($chart->getXML ()) . '");
myChart.addParam("WMode", "Transparent"); myChart.addParam("WMode", "Transparent");
myChart.render("' . $div_id . '"); myChart.render("' . $div_id . '");
@ -235,6 +262,8 @@ function fs_combined_chart ($data, $categories, $sets, $width, $height, $type =
break; break;
case 2: $chart_type = 'MSLine'; case 2: $chart_type = 'MSLine';
break; break;
case 3: $chart_type = 'MSLine';
break;
default: $chart_type = 'StackedArea2D'; default: $chart_type = 'StackedArea2D';
} }
@ -255,18 +284,29 @@ function fs_combined_chart ($data, $categories, $sets, $width, $height, $type =
} }
// Stack charts // Stack charts
$empty = 1; $empty = 1;
$prev = array();
for ($i = 0; $i < sizeof ($data); $i++) { for ($i = 0; $i < sizeof ($data); $i++) {
$chart->addDataSet ($sets[$i]); $chart->addDataSet ($sets[$i]);
foreach ($data[$i] as $value) { foreach ($data[$i] as $indice => $value) {
if ($value > 0) { // Custom code to do the stack lines, because library doesn't do itself
$empty = 0; if ($type == 3){
} if ($i > 0){
$chart->addChartData($value); $prev[$indice] = $prev[$indice] + $value;
} } else {
$prev[$indice] = $value;
}
$myvalue = $prev[$indice];
$chart->addChartData($myvalue);
} else {
$chart->addChartData($value);
}
}
} }
$chart->setChartParams('animation=0;numVDivLines=' . $num_vlines . ';showAlternateVGridColor=1;showNames=1;rotateNames=1;showValues=0;baseFontSize=9;showLimits=0;showAreaBorder=1;areaBorderThickness=1;areaBorderColor=000000' . ($empty == 1 ? ';yAxisMinValue=0;yAxisMaxValue=1' : ''));
$chart->setChartParams('legendAllowDrag=1;legendMarkerCircle=1;animation=0;numVDivLines=' . $num_vlines . ';showShadow=0; showAlternateVGridColor=1;showNames=1;lineThickness=2;anchorRadius=0.7;rotateNames=1;divLineAlpha=30;showValues=0;baseFontSize=9;showLimits=0;showAreaBorder=1;showPlotBorder=1;plotBorderThickness=0;areaBorderThickness=0;areaBorderColor=000000' . ($empty == 1 ? ';yAxisMinValue=0;yAxisMaxValue=1' : ''));
// Return the code // Return the code
return get_chart_code ($chart, $width, $height, 'include/FusionCharts/FCF_' . $chart_type . '.swf'); return get_chart_code ($chart, $width, $height, 'include/FusionCharts/FCF_' . $chart_type . '.swf');

View File

@ -184,20 +184,21 @@ class PchartGraph extends PandoraGraphAbstract {
$this->dataset->AddPoint ($data['min'], "MIN"); $this->dataset->AddPoint ($data['min'], "MIN");
$this->dataset->AddPoint ($data['max'], "MAX"); $this->dataset->AddPoint ($data['max'], "MAX");
} }
$this->legend[1] = __("Min. Value"); $this->legend[1] = __("Min");
$this->legend[0] = __("Avg. Value"); $this->legend[0] = __("Avg");
$this->legend[2] = __("Max. Value"); $this->legend[2] = __("Max");
$this->dataset->SetSerieName (__("Min. Value"), "MIN"); $this->dataset->SetSerieName (__("Min"), "MIN");
$this->dataset->SetSerieName (__("Avg. Value"), "AVG"); $this->dataset->SetSerieName (__("Avg"), "AVG");
$this->dataset->SetSerieName (__("Max. Value"), "MAX"); $this->dataset->SetSerieName (__("Max"), "MAX");
$this->set_colors (); $this->set_colors ();
} }
$this->dataset->SetXAxisFormat ('datetime'); $this->dataset->SetXAxisFormat ('datetime');
$this->graph->setDateFormat ("Y"); $this->graph->setDateFormat ("Y");
$this->dataset->SetYAxisFormat ('metric'); $this->dataset->SetYAxisFormat ('metric');
$this->dataset->AddAllSeries (); $this->dataset->AddAllSeries ();
$this->dataset->SetSerieName (__("Avg. Value"), "AVG");
$this->legend[0] = __("Avg. Value"); $this->dataset->SetSerieName (__("Avg"), "AVG");
$this->legend[0] = __("Avg");
if ($this->palette_path) { if ($this->palette_path) {
$this->graph->loadColorPalette ($this->palette_path); $this->graph->loadColorPalette ($this->palette_path);
@ -278,10 +279,22 @@ class PchartGraph extends PandoraGraphAbstract {
$this->dataset = new pData; $this->dataset = new pData;
$this->graph = new pChart ($this->width, $this->height+5); $this->graph = new pChart ($this->width, $this->height+5);
$graph_items = 0;
// $previo stores values from last series to made the stacked graph // $previo stores values from last series to made the stacked graph
foreach ($this->data as $i => $data) { foreach ($this->data as $i => $data) {
$graph_items++;
$max = 0;
$min = 10000000000000;
$avg = 0;
$count = 0;
foreach ($data as $j => $value) { foreach ($data as $j => $value) {
$count ++;
$avg += $value;
if ($value > $max )
$max = $value;
if ($value < $min )
$min = $value;
// New code for stacked. Due pchart doesnt not support stacked // New code for stacked. Due pchart doesnt not support stacked
// area graph, we "made it", adding to a series the values of the // area graph, we "made it", adding to a series the values of the
// previous one consecutive sum. // previous one consecutive sum.
@ -297,13 +310,22 @@ class PchartGraph extends PandoraGraphAbstract {
else else
$previo[$j] = $previo[$j] + $value; $previo[$j] = $previo[$j] + $value;
} }
if ($count > 0)
$avgdata[$i] = $avg / $count;
else
$avgdata[$i] = 0;
$maxdata[$i] = format_for_graph($max);
$mindata[$i] = format_for_graph($min);
$avgdata[$i] = format_for_graph($avgdata[$i]);
} }
$i = 0;
foreach ($this->legend as $name) { foreach ($this->legend as $name) {
$this->dataset->setSerieName ($name, $name); $legend = $name . " (".__("Max"). ":$maxdata[$i], ".__("Min"). ":$mindata[$i], ". __("Avg"). ": $avgdata[$i])";
$this->dataset->setSerieName ($legend, $name);
$this->dataset->AddSerie ($name); $this->dataset->AddSerie ($name);
$i++;
} }
// Set different colors for combined graphs because need to be // Set different colors for combined graphs because need to be
@ -322,6 +344,11 @@ class PchartGraph extends PandoraGraphAbstract {
$this->dataset->SetYAxisFormat ('metric'); $this->dataset->SetYAxisFormat ('metric');
$this->dataset->AddAllSeries (); $this->dataset->AddAllSeries ();
$this->add_background (); $this->add_background ();
$legend_offset = $this->height - 21 - ($graph_items*15);
$this->graph->setGraphArea (35,10,$this->width-10, $legend_offset);
$this->graph->drawGraphArea (254, 254, 254, false); $this->graph->drawGraphArea (254, 254, 254, false);
@ -366,7 +393,13 @@ class PchartGraph extends PandoraGraphAbstract {
$this->graph->drawFilledCubicCurve ($this->dataset->GetData(), $this->graph->drawFilledCubicCurve ($this->dataset->GetData(),
$this->dataset->GetDataDescription(), 1, 30, true); $this->dataset->GetDataDescription(), 1, 30, true);
} }
$this->add_legend ();
$this->graph->setFontProperties($this->fontpath,7);
$this->graph->drawLegend(15,$legend_offset+29,$this->dataset->GetDataDescription(),92,92,92,50,50,50,45,45,45,0);
// Legend line separator
// $this->graph->drawFilledRoundedRectangle(35, $legend_offset + 30 ,$this->width-35,$legend_offset+30,0,220,220,220);
$this->add_events ($this->legend[0]); $this->add_events ($this->legend[0]);
$this->add_alert_levels (); $this->add_alert_levels ();
@ -548,15 +581,15 @@ class PchartGraph extends PandoraGraphAbstract {
/* This is a tiny watermark */ /* This is a tiny watermark */
if ($this->watermark) { if ($this->watermark) {
if ($this->show_title){ if ($this->show_title){
$this->graph->setFontProperties ($this->fontpath, 6); $this->graph->setFontProperties ($this->fontpath, 7);
$this->graph->drawTextBox ($this->width - 5, 40, $this->graph->drawTextBox ($this->width - 8, 40,
$this->width - 240, 90, 'PandoraFMS', 90, $this->width - 240, 90, 'PANDORA FMS', 90,
214, 214, 214, ALIGN_BOTTOM_LEFT, false); 174, 214, 174, ALIGN_BOTTOM_LEFT, false);
} else { } else {
$this->graph->setFontProperties ($this->fontpath, 6); $this->graph->setFontProperties ($this->fontpath, 7);
$this->graph->drawTextBox ($this->width - 5, 50, $this->graph->drawTextBox ($this->width - 8, 50,
$this->width - 240, 60, 'PandoraFMS', 90, $this->width - 240, 60, 'PANDORA FMS', 90,
214, 214, 214, ALIGN_BOTTOM_LEFT, false); 174, 214, 174, ALIGN_BOTTOM_LEFT, false);
} }
} }
} }