2011-04-07 Miguel de Dios <miguel.dedios@artica.es>
* 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". git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4178 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
767f76832c
commit
985b94ca1e
|
@ -1,3 +1,15 @@
|
|||
2011-04-07 Miguel de Dios <miguel.dedios@artica.es>
|
||||
|
||||
* 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 <miguel.dedios@artica.es>
|
||||
|
||||
* include/graphs/fgraph.php: changed the img tag to autoclose.
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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 "<img src='http://127.0.0.1/pandora_console/include/graphs/functions_pchart.php?graph_type=stacked_area&id_graph=" . $id_graph . "' />";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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 "<img src='http://127.0.0.1/pandora_console/include/graphs/functions_pchart.php?graph_type=line&id_graph=" . $id_graph . "' />";
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
|
|
@ -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 = '<div id="' . $div_id. '" style="z-index:1;"></div>';
|
||||
$output .= '<script language="JavaScript" src="' . $pre_url . '/include/FusionCharts/FusionCharts.js"></script>';
|
||||
$output .= '<script type="text/javascript">
|
||||
<!--
|
||||
function pie_' . $chart_id . ' () {
|
||||
var myChart = new FusionCharts("' . $pre_url . '/include/FusionCharts/FCF_'.$graph_type.'.swf", "' . $chart_id . '", "' . $width. '", "' . $height. '", "0", "1");
|
||||
myChart.setDataXML("' . addslashes($chart->getXML ()) . '");
|
||||
myChart.addParam("WMode", "Transparent");
|
||||
myChart.render("' . $div_id . '");
|
||||
}
|
||||
pie_' . $chart_id . ' ();
|
||||
-->
|
||||
</script>';
|
||||
|
||||
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 = '<div id="' . $div_id. '" style="z-index:1;"></div>';
|
||||
$output .= '<script language="JavaScript" src="' . $pre_url . '/include/FusionCharts/FusionCharts.js"></script>';
|
||||
$output .= '<script type="text/javascript">
|
||||
<!--
|
||||
function pie_' . $chart_id . ' () {
|
||||
var myChart = new FusionCharts("' . $pre_url . '/include/FusionCharts/FCF_'.$graph_type.'.swf", "' . $chart_id . '", "' . $width. '", "' . $height. '", "0", "1");
|
||||
myChart.setDataXML("' . addslashes($chart->getXML ()) . '");
|
||||
myChart.addParam("WMode", "Transparent");
|
||||
myChart.render("' . $div_id . '");
|
||||
}
|
||||
pie_' . $chart_id . ' ();
|
||||
-->
|
||||
</script>';
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
function fs_area_graph($chart_data, $width, $height, $color, $legend, $long_index) {
|
||||
global $config;
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue