2011-04-12 Sergio Martin <sergio.martin@artica.es>

* include/graphs/functions_fsgraph.php
	include/graphs/functions_gd.php
	include/graphs/images_graphs
	include/graphs/images_graphs/outlimits.png
	include/graphs/fgraph.php: Added new file with sd functions
	of two graphs, histogram and progress bar. Added folder with
	graph abstraction default images. Clean code



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4190 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
zarzuelo 2011-04-12 10:04:41 +00:00
parent 6045e90116
commit bbb91fa5fc
5 changed files with 222 additions and 13 deletions

View File

@ -1,3 +1,13 @@
2011-04-12 Sergio Martin <sergio.martin@artica.es>
* include/graphs/functions_fsgraph.php
include/graphs/functions_gd.php
include/graphs/images_graphs
include/graphs/images_graphs/outlimits.png
include/graphs/fgraph.php: Added new file with sd functions
of two graphs, histogram and progress bar. Added folder with
graph abstraction default images. Clean code
2011-04-12 Junichi Satoh <junichi@rworks.jp>
* godmode/uses/configure_profile.php: Fixed $name twice encoding.

View File

@ -10,8 +10,48 @@
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
include_once('functions_fsgraph.php');
include_once('functions_utils.php');
// If is called from index
if(file_exists('include/functions.php')) {
include_once('include/functions.php');
include_once('include/graphs/functions_fsgraph.php');
include_once('include/graphs/functions_utils.php');
} // If is called through url
else if(file_exists('../functions.php')) {
include_once('../functions.php');
include_once('../functions_html.php');
include_once('functions_fsgraph.php');
include_once('functions_gd.php');
include_once('functions_utils.php');
}
$graph_type = get_parameter('graph_type', '');
switch($graph_type) {
case 'histogram':
$width = get_parameter('width');
$height = get_parameter('height');
$font = get_parameter('font');
$data = json_decode(safe_output(get_parameter('data')), true);
$max = get_parameter('max');
$title = get_parameter('title');
$mode = get_parameter ('mode', 1);
gd_histogram ($width, $height, $mode, $data, $max, $font, $title);
break;
case 'progressbar':
$width = get_parameter('width');
$height = get_parameter('height');
$progress = get_parameter('progress');
$out_of_lim_str = get_parameter('out_of_lim_str', false);
$out_of_lim_image = get_parameter('out_of_lim_image', false);
$font = get_parameter('font');
$title = get_parameter('title');
gd_progress_bar ($width, $height, $progress, $title, $font, $out_of_lim_str, $out_of_lim_image);
break;
}
function vbar_graph($flash_chart, $chart_data, $width, $height, $color = array(), $legend = array(), $xaxisname = "", $yaxisname = "") {
if($flash_chart) {
@ -42,7 +82,7 @@ function threshold_graph($flash_chart, $chart_data, $width, $height) {
}
}
function area_graph($flash_chart, $chart_data, $width, $height, $color, $legend, $long_index, $no_data_image) {
function area_graph($flash_chart, $chart_data, $width, $height, $color, $legend, $long_index, $no_data_image, $xaxisname = "", $yaxisname = "") {
if (empty($chart_data)) {
return '<img src="' . $no_data_image . '" />';
}
@ -59,7 +99,9 @@ function area_graph($flash_chart, $chart_data, $width, $height, $color, $legend,
$graph['height'] = $height;
$graph['color'] = $color;
$graph['legend'] = $legend;
$graph['xaxisname'] = $xaxisname;
$graph['yaxisname'] = $yaxisname;
serialize_in_temp($graph, $id_graph);
return "<img src='include/graphs/functions_pchart.php?graph_type=area&id_graph=" . $id_graph . "'>";
@ -91,7 +133,7 @@ function stacked_area_graph($flash_chart, $chart_data, $width, $height, $color,
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 stacked_line_graph($flash_chart, $chart_data, $width, $height, $color, $legend, $long_index, $no_data_image) {

View File

@ -1,9 +1,5 @@
<?PHP
// INTEGRIA IMS v2.0
// http://www.integriaims.com
// ===========================================================
// Copyright (c) 2007-2008 Sancho Lerena, slerena@gmail.com
// Copyright (c) 2008 Esteban Sanchez, estebans@artica.es
// Copyright (c) 2007-2011 Artica, info@artica.es
@ -333,7 +329,7 @@ function fs_line_graph($chart_data, $width, $height, $color, $legend, $long_inde
function fs_area_graph($chart_data, $width, $height, $color, $legend, $long_index) {
global $config;
$graph_type = "MSArea2D"; //MSLine is possible also
$chart = new FusionCharts($graph_type, $width, $height);
@ -350,7 +346,6 @@ function fs_area_graph($chart_data, $width, $height, $color, $legend, $long_inde
$step = round($ndata/$xdata_display);
if(is_array(reset($chart_data))) {
$data2 = array();
$count = 0;
@ -392,10 +387,9 @@ function fs_area_graph($chart_data, $width, $height, $color, $legend, $long_inde
}
$a = 0;
$empty = 1;
foreach ($data as $i => $value) {
$legend_text = '';
if (isset($legend[$i])) {
$legend_text = $legend[$i];

View File

@ -0,0 +1,163 @@
<?PHP
// ===========================================================
// Copyright (c) 2011-2011 Artica, info@artica.es
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public License
// (LGPL) 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 Lesser General Public License for more details.
function gd_histogram ($width, $height, $mode, $data, $max_value, $font, $title) {
// $title is for future use
$nvalues = count($data);
Header("Content-type: image/png");
$image = imagecreate($width,$height);
$white = ImageColorAllocate($image,255,255,255);
imagecolortransparent ($image, $white);
$black = ImageColorAllocate($image,0,0,0);
$red = ImageColorAllocate($image,255,60,75);
$blue = ImageColorAllocate($image,75,60,255);
$green = ImageColorAllocate($image,0,120,0);
$magent = ImageColorAllocate($image,179,0,255);
$yellow = ImageColorAllocate($image,204,255,0);
$colors = array($blue, $red, $green, $magent, $yellow);
$margin_up = 2;
if ($mode != 2) {
$size_per = ($max_value / ($width-40));
} else {
$size_per = ($max_value / ($width));
}
if ($mode == 0) // with strips
$rectangle_height = ($height - 10 - 2 - $margin_up ) / $nvalues;
else
$rectangle_height = ($height - 2 - $margin_up ) / $nvalues;
if ($size_per == 0)
$size_per = 1;
if ($mode != 2) {
$leftmargin = 40;
}
else {
$leftmargin = 1;
}
$c = 0;
foreach($data as $label => $value) {
ImageFilledRectangle($image, $leftmargin, $margin_up, ($value/$size_per)+$leftmargin, $margin_up+$rectangle_height -1 , $colors[$c]);
if ($mode != 2) {
ImageTTFText($image, 7, 0, 0, $margin_up+8, $black, $font, $label);
}
$margin_up += $rectangle_height + 1;
$c++;
if(!isset($colors[$c])) {
$c = 0;
}
}
if ($mode == 0) { // With strips
// Draw limits
$risk_low = ($config_risk_low / $size_per) + 40;
$risk_med = ($config_risk_med / $size_per) + 40;
$risk_high = ($config_risk_high / $size_per) + 40;
imageline($image, $risk_low, 0, $risk_low , $height, $grey);
imageline($image, $risk_med , 0, $risk_med , $height, $grey);
imageline($image, $risk_high, 0, $risk_high , $height, $grey);
ImageTTFText($image, 7, 0, $risk_low-20, $height, $grey, $font, "Low");
ImageTTFText($image, 7, 0, $risk_med-20, $height, $grey, $font, "Med.");
ImageTTFText($image, 7, 0, $risk_high-25, $height, $grey, $font, "High");
}
imagePNG($image);
imagedestroy($image);
}
// ***************************************************************************
// Draw a dynamic progress bar using GDlib directly
// ***************************************************************************
function gd_progress_bar ($width, $height, $progress, $title, $font, $out_of_lim_str, $out_of_lim_image) {
if($out_of_lim_str === false) {
$out_of_lim_str = "Out of limits";
}
if($out_of_lim_image === false) {
$out_of_lim_image = "images_graphs/outlimits.png";
}
// Copied from the PHP manual:
// http://us3.php.net/manual/en/function.imagefilledrectangle.php
// With some adds from sdonie at lgc dot com
// Get from official documentation PHP.net website. Thanks guys :-)
function drawRating($rating, $width, $height, $font, $out_of_lim_str) {
global $config;
global $REMOTE_ADDR;
if ($width == 0) {
$width = 150;
}
if ($height == 0) {
$height = 20;
}
//$rating = $_GET['rating'];
$ratingbar = (($rating/100)*$width)-2;
$image = imagecreate($width,$height);
//colors
$back = ImageColorAllocate($image,255,255,255);
imagecolortransparent ($image, $back);
$border = ImageColorAllocate($image,174,174,174);
$text = ImageColorAllocate($image,74,74,74);
$red = ImageColorAllocate($image,255,60,75);
$green = ImageColorAllocate($image,50,205,50);
$fill = ImageColorAllocate($image,44,81,120);
ImageFilledRectangle($image,0,0,$width-1,$height-1,$back);
if ($rating > 100)
ImageFilledRectangle($image,1,1,$ratingbar,$height-1,$red);
elseif ($rating == 100)
ImageFilledRectangle($image,1,1,$ratingbar,$height-1,$green);
else
ImageFilledRectangle($image,1,1,$ratingbar,$height-1,$fill);
ImageRectangle($image,0,0,$width-1,$height-1,$border);
if ($rating > 50)
if ($rating > 100)
ImageTTFText($image, 8, 0, ($width/4), ($height/2)+($height/5), $back, $font, $out_of_lim_str);
else
ImageTTFText($image, 8, 0, ($width/2)-($width/10), ($height/2)+($height/5), $back, $font, $rating."%");
else
ImageTTFText($image, 8, 0, ($width/2)-($width/10), ($height/2)+($height/5), $text, $font, $rating."%");
imagePNG($image);
imagedestroy($image);
}
Header("Content-type: image/png");
if ($progress > 100 || $progress < 0) {
// HACK: This report a static image... will increase render in about 200% :-) useful for
// high number of realtime statusbar images creation (in main all agents view, for example
$imgPng = imageCreateFromPng($out_of_lim_image);
imageAlphaBlending($imgPng, true);
imageSaveAlpha($imgPng, true);
imagePng($imgPng);
} else
drawRating($progress, $width, $height, $font, $out_of_lim_str);
}
?>

Binary file not shown.

After

Width:  |  Height:  |  Size: 321 B