diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 2a02ca3619..6950841fbf 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,15 @@ +2011-04-07 Miguel de Dios + + * include/functions_graph.php: added call to paint the other graphs. + + * include/graphs/functions_pchart.php: added stack area graph, and fixed + typo in the call to line graph. + + * include/graphs/functions_fsgraph.php: added line graph and area graph. + + * include/graphs/fgraph.php: added function "stacked_area_graph" and + "line_graph". + 2011-04-07 Miguel de Dios * include/graphs/fgraph.php: changed the img tag to autoclose. diff --git a/pandora_console/include/functions_graph.php b/pandora_console/include/functions_graph.php index fe1ae6ef6e..4b3968ff4d 100755 --- a/pandora_console/include/functions_graph.php +++ b/pandora_console/include/functions_graph.php @@ -603,11 +603,6 @@ function graphic_combined_module2 ($module_list, $weight_list, $period, $width, //////////////////////////////////////////////////////////////////////////// switch ($stacked) { case 0: - /*$color = array( - 0 => array('alpha' => 50), - 1 => array('alpha' => 50), - 2 => array('alpha' => 50) - );*/ $color = null; return area_graph($config['flash_charts'], $graph_values, $width, $height, $color, $module_name_list, $long_index); @@ -615,16 +610,19 @@ function graphic_combined_module2 ($module_list, $weight_list, $period, $width, break; default: case 1: - //TODO - $chart_type = 'StackedArea2D'; + $color = null; + return stacked_area_graph($config['flash_charts'], $graph_values, $width, $height, + $color, $module_name_list, $long_index); break; case 2: - $chart_type = 'MSLine'; - //TODO + $color = null; + return line_graph($config['flash_charts'], $graph_values, $width, $height, + $color, $module_name_list, $long_index); break; case 3: - $chart_type = 'MSLine'; - //TODO + $color = null; + return line_graph($config['flash_charts'], $graph_values, $width, $height, + $color, $module_name_list, $long_index); break; } diff --git a/pandora_console/include/graphs/fgraph.php b/pandora_console/include/graphs/fgraph.php index c86a57384d..f745764df3 100755 --- a/pandora_console/include/graphs/fgraph.php +++ b/pandora_console/include/graphs/fgraph.php @@ -63,6 +63,88 @@ function area_graph($flash_chart, $chart_data, $width, $height, $color,$legend, } } +function stacked_area_graph($flash_chart, $chart_data, $width, $height, $color, $legend, $long_index) { + + if($flash_chart) { + return fs_stacked_graph($chart_data, $width, $height, $color, $legend, $long_index); + } + else { + $id_graph = uniqid(); + + $temp_data = array(); + if (isset($legend)) { + $temp_legend = array(); + } + if (isset($color)) { + $temp_color = array(); + } + //Stack the data + foreach ($chart_data as $val_x => $graphs) { + $prev_val = 0; + $key = 1000; + foreach ($graphs as $graph => $val_y) { + $chart_data[$val_x][$graph] += $prev_val; + $prev_val = $chart_data[$val_x][$graph]; + $temp_data[$val_x][$key] = $chart_data[$val_x][$graph]; + if (isset($color)) { + $temp_color[$key] = $color[$graph]; + } + if (isset($legend)) { + $temp_legend[$key] = $legend[$graph]; + } + $key--; + } + ksort($temp_data[$val_x]); + } + + $chart_data = $temp_data; + if (isset($legend)) { + $legend = $temp_legend; + ksort($legend); + } + if (isset($color)) { + $color = $temp_color; + ksort($color); + } + + + $graph = array(); + $graph['data'] = $chart_data; + $graph['width'] = $width; + $graph['height'] = $height; + $graph['color'] = $color; + $graph['legend'] = $legend; + + serialize_in_temp($graph, $id_graph); + + return ""; + } +} + + +function line_graph($flash_chart, $chart_data, $width, $height, $color, $legend, $long_index) { + $flash_chart = 1; + + if($flash_chart) { + return fs_line_graph($chart_data, $width, $height, $color, $legend, $long_index); + } + else { + $id_graph = uniqid(); + + + $graph = array(); + $graph['data'] = $chart_data; + $graph['width'] = $width; + $graph['height'] = $height; + $graph['color'] = $color; + $graph['legend'] = $legend; + + serialize_in_temp($graph, $id_graph); + + return ""; + } +} + function hbar_graph($flash_chart, $chart_data, $width, $height) { if($flash_chart) { echo fs_hbar_chart (array_values($chart_data), array_keys($chart_data), $width, $height); diff --git a/pandora_console/include/graphs/functions_fsgraph.php b/pandora_console/include/graphs/functions_fsgraph.php index f390310c7c..e8eb5529fd 100755 --- a/pandora_console/include/graphs/functions_fsgraph.php +++ b/pandora_console/include/graphs/functions_fsgraph.php @@ -26,6 +26,314 @@ if (!class_exists("FusionCharts")) { /////////////////////////////// /////////////////////////////// /////////////////////////////// +function fs_stacked_graph($chart_data, $width, $height, $color, $legend, $long_index) { + global $config; + + $graph_type = "StackedArea2D"; + + $chart = new FusionCharts($graph_type, $width, $height); + + + $pixels_between_xdata = 25; + $max_xdata_display = round($width / $pixels_between_xdata); + $ndata = count($chart_data); + if($max_xdata_display > $ndata) { + $xdata_display = $ndata; + } + else { + $xdata_display = $max_xdata_display; + } + + $step = round($ndata/$xdata_display); + + + if(is_array(reset($chart_data))) { + $data2 = array(); + $count = 0; + foreach($chart_data as $i =>$values) { +// $count = 0; +// $step = 10; +// $num_vlines = 0; +// +// if ($count++ % $step == 0) { +// $show_name = '1'; +// $num_vlines++; +// } +// else { +// $show_name = '0'; +// } + + $count++; + $show_name = '0'; + if (($count % $step) == 0) { + $show_name = '1'; + } + + if (isset($long_index[$i])) { + $chart->addCategory($i, //''); + 'hoverText=' . $long_index[$i] . + ';showName=' . $show_name); + } + + $c = 0; + foreach($values as $i2 => $value) { + $data2[$i2][$i] = $value; + $c++; + } + } + $data = $data2; + } + else { + $data = array($chart_data); + } + + $a = 0; + + $empty = 1; + foreach ($data as $i => $value) { + + $legend_text = ''; + if (isset($legend[$i])) { + $legend_text = $legend[$i]; + } + + $alpha = ''; + $areaBorderColor = ''; + $color = ''; + $showAreaBorder = 1; //0 old default + if (isset($color[$i])) { + if (!isset($color[$i]['border'])) { + $showAreaBorder = 1; + } + + if (isset($color[$i]['alpha'])) { + $alpha = 'alpha=' . $color[$i]['alpha'] . ';'; + } + + if (isset($color[$i]['border'])) { + $areaBorderColor = 'areaBorderColor=' . $color[$i]['border'] . ';'; + } + + if (isset($color[$i]['color'])) { + $color = 'color=#' . $color[$i]['color']; + } + } + + $chart->addDataSet($legend_text, $alpha . + 'showAreaBorder=' . $showAreaBorder . ';' . + $areaBorderColor . + $color); + + $count = 0; + $step = 10; + $num_vlines = 0; + + foreach ($value as $i2 => $v) { + if ($count++ % $step == 0) { + $show_name = '1'; + $num_vlines++; + } + else { + $show_name = '0'; + } + + $empty = 0; + + if ($a < 3) { + $a++; +// $chart->addCategory(date('G:i', $i2), //''); +// 'hoverText=' . date (html_entity_decode ($config['date_format'], ENT_QUOTES, "UTF-8"), $i2) . +// ';showName=' . $show_name); + } + + //Add data + $chart->addChartData($v); + } + } + + $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 = uniqid(); + + $div_id = 'chart_div_' . $random_number; + $chart_id = 'chart_' . $random_number; + + $pre_url = ($config["homeurl"] == "/") ? '' : $config["homeurl"]; + + $output = '
'; + $output .= ''; + $output .= ''; + + return $output; +} + +function fs_line_graph($chart_data, $width, $height, $color, $legend, $long_index) { + global $config; + + $graph_type = "MSLine"; + + $chart = new FusionCharts($graph_type, $width, $height); + + + $pixels_between_xdata = 25; + $max_xdata_display = round($width / $pixels_between_xdata); + $ndata = count($chart_data); + if($max_xdata_display > $ndata) { + $xdata_display = $ndata; + } + else { + $xdata_display = $max_xdata_display; + } + + $step = round($ndata/$xdata_display); + + + if(is_array(reset($chart_data))) { + $data2 = array(); + $count = 0; + foreach($chart_data as $i =>$values) { +// $count = 0; +// $step = 10; +// $num_vlines = 0; +// +// if ($count++ % $step == 0) { +// $show_name = '1'; +// $num_vlines++; +// } +// else { +// $show_name = '0'; +// } + + $count++; + $show_name = '0'; + if (($count % $step) == 0) { + $show_name = '1'; + } + + if (isset($long_index[$i])) { + $chart->addCategory($i, //''); + 'hoverText=' . $long_index[$i] . + ';showName=' . $show_name); + } + + $c = 0; + foreach($values as $i2 => $value) { + $data2[$i2][$i] = $value; + $c++; + } + } + $data = $data2; + } + else { + $data = array($chart_data); + } + + $a = 0; + + $empty = 1; + foreach ($data as $i => $value) { + + $legend_text = ''; + if (isset($legend[$i])) { + $legend_text = $legend[$i]; + } + + $alpha = ''; + $areaBorderColor = ''; + $color = ''; + $showAreaBorder = 1; //0 old default + if (isset($color[$i])) { + if (!isset($color[$i]['border'])) { + $showAreaBorder = 1; + } + + if (isset($color[$i]['alpha'])) { + $alpha = 'alpha=' . $color[$i]['alpha'] . ';'; + } + + if (isset($color[$i]['border'])) { + $areaBorderColor = 'areaBorderColor=' . $color[$i]['border'] . ';'; + } + + if (isset($color[$i]['color'])) { + $color = 'color=#' . $color[$i]['color']; + } + } + + $chart->addDataSet($legend_text, $alpha . + 'showAreaBorder=' . $showAreaBorder . ';' . + $areaBorderColor . + $color); + + $count = 0; + $step = 10; + $num_vlines = 0; + + foreach ($value as $i2 => $v) { + if ($count++ % $step == 0) { + $show_name = '1'; + $num_vlines++; + } + else { + $show_name = '0'; + } + + $empty = 0; + + if ($a < 3) { + $a++; +// $chart->addCategory(date('G:i', $i2), //''); +// 'hoverText=' . date (html_entity_decode ($config['date_format'], ENT_QUOTES, "UTF-8"), $i2) . +// ';showName=' . $show_name); + } + + //Add data + $chart->addChartData($v); + } + } + + $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 = uniqid(); + + $div_id = 'chart_div_' . $random_number; + $chart_id = 'chart_' . $random_number; + + $pre_url = ($config["homeurl"] == "/") ? '' : $config["homeurl"]; + + $output = '
'; + $output .= ''; + $output .= ''; + + return $output; +} + function fs_area_graph($chart_data, $width, $height, $color, $legend, $long_index) { global $config; diff --git a/pandora_console/include/graphs/functions_pchart.php b/pandora_console/include/graphs/functions_pchart.php index 0aba9bc0c6..125351b2f1 100755 --- a/pandora_console/include/graphs/functions_pchart.php +++ b/pandora_console/include/graphs/functions_pchart.php @@ -144,8 +144,9 @@ switch($graph_type) { case 'vbar': pch_bar_graph($graph_type, $data_keys, $data_values, $width, $height, $rgb_color, $xaxisname, $yaxisname); break; + case 'stacked_area': case 'area': - case 'spline': + case 'line': pch_vertical_graph($graph_type, $data_keys, $data_values, $width, $height, $rgb_color, $xaxisname, $yaxisname, false, $legend); break; case 'threshold': @@ -432,8 +433,17 @@ function pch_vertical_graph ($graph_type, $index, $data, $width, $height, $rgb_c /* Turn on shadow computing */ //$myPicture->setShadow(TRUE,array("X"=>0,"Y"=>1,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10)); + switch ($graph_type) { + case 'stacked_area': + $ForceTransparency = "-1"; + break; + default: + $ForceTransparency = "50"; + break; + } + /* Draw the chart */ - $settings = array("ForceTransparency"=>"50", // + $settings = array("ForceTransparency"=> $ForceTransparency, // "Gradient"=>TRUE, "GradientMode"=>GRADIENT_EFFECT_CAN, "DisplayValues"=>$show_values, @@ -443,6 +453,7 @@ function pch_vertical_graph ($graph_type, $index, $data, $width, $height, $rgb_c "DisplayG"=>100,"DisplayB"=>100,"DisplayShadow"=>TRUE,"Surrounding"=>5,"AroundZero"=>FALSE); switch($graph_type) { + case "stacked_area": case "area": $myPicture->drawAreaChart($settings); break;