'; /////////////////////////////// ////////// AREA GRAPHS //////// /////////////////////////////// function flot_area_stacked_graph($chart_data, $width, $height, $color, $legend, $long_index, $homeurl = '', $unit = '', $water_mark = '', $serie_types = array(), $chart_extra_data = array()) { global $config; return flot_area_graph($chart_data, $width, $height, $color, $legend, $long_index, $homeurl, $unit, 'area_stacked', $water_mark, $serie_types, $chart_extra_data); } function flot_area_simple_graph($chart_data, $width, $height, $color, $legend, $long_index, $homeurl = '', $unit = '', $water_mark = '', $serie_types = array(), $chart_extra_data = array()) { global $config; return flot_area_graph($chart_data, $width, $height, $color, $legend, $long_index, $homeurl, $unit, 'area_simple', $water_mark, $serie_types, $chart_extra_data); } function flot_line_stacked_graph($chart_data, $width, $height, $color, $legend, $long_index, $homeurl = '', $unit = '', $water_mark = '', $serie_types = array(), $chart_extra_data = array()) { global $config; return flot_area_graph($chart_data, $width, $height, $color, $legend, $long_index, $homeurl, $unit, 'line_stacked', $water_mark, $serie_types, $chart_extra_data); } function flot_line_simple_graph($chart_data, $width, $height, $color, $legend, $long_index, $homeurl = '', $unit = '', $water_mark = '', $serie_types = array(), $chart_extra_data = array()) { global $config; return flot_area_graph($chart_data, $width, $height, $color, $legend, $long_index, $homeurl, $unit, 'line_simple', $water_mark, $serie_types, $chart_extra_data); } function flot_area_graph($chart_data, $width, $height, $color, $legend, $long_index, $homeurl, $unit, $type, $water_mark, $serie_types, $chart_extra_data) { global $config; $menu = true; $font_size = '7'; // Get a unique identifier to graph $graph_id = uniqid('graph_'); // Set some containers to legend, graph, timestamp tooltip, etc. $return = "
"; $return .= ""; $return .= ""; $return .= ""; if($water_mark != '') { $return .= ""; $watermark = 'true'; } else { $watermark = 'false'; } // Set a weird separator to serialize and unserialize passing data from php to javascript $separator = ';;::;;'; $separator2 = ':,:,,,:,:'; // Transform data from our format to library format $labels = array(); $a = array(); $vars = array(); $serie_types2 = array(); $colors = array(); foreach($legend as $serie_key => $serie) { if(isset($color[$serie_key])) { $colors[] = $color[$serie_key]['color']; } else { $colors[] = ''; } } foreach($chart_data as $label => $values) { $labels[] = io_safe_output($label); foreach($values as $key => $value) { $jsvar = "data_".$graph_id."_".$key; if(!isset($serie_types[$key])) { $serie_types2[$jsvar] = 'line'; } else { $serie_types2[$jsvar] = $serie_types[$key]; } if($serie_types2[$jsvar] == 'points' && $value == 0) { $data[$jsvar][] = 'null'; } else { $data[$jsvar][] = $value; } } } // Store data series in javascript format $jsvars = ''; $jsseries = array(); $values2 = array(); $i = 0; $max_x = 0; foreach($data as $jsvar => $values) { $n_values = count($values); if($n_values > $max_x) { $max_x = $n_values; } $values2[] = implode($separator,$values); $i ++; } $values = implode($separator2, $values2); // Max is "n-1" because start with 0 $max_x--; if($menu) { $return .= " "; } $extra_height = $height - 50; $extra_width = (int)($width / 3); $return .= ""; // Process extra data $events = array(); $event_ids = array(); $alerts = array(); $alert_ids = array(); $legend_events = ''; $legend_alerts = ''; foreach($chart_extra_data as $i => $data) { switch($i) { case 'legend_alerts': $legend_alerts = $data; break; case 'legend_events': $legend_events = $data; break; default: if(isset($data['events'])) { $event_ids[] = $i; $events[$i] = $data['events']; } if(isset($data['alerts'])) { $alert_ids[] = $i; $alerts[$i] = $data['alerts']; } break; } } // Store serialized data to use it from javascript $events = implode($separator,$events); $event_ids = implode($separator,$event_ids); $alerts = implode($separator,$alerts); $alert_ids = implode($separator,$alert_ids); $labels = implode($separator,$labels); $labels_long = implode($separator,$long_index); $legend = io_safe_output(implode($separator,$legend)); $serie_types = implode($separator, $serie_types2); $colors = implode($separator, $colors); // Javascript code $return .= ""; return $return; } /////////////////////////////// /////////////////////////////// /////////////////////////////// // Prints a FLOT pie chart function flot_pie_chart ($values, $labels, $width, $height, $water_mark, $font = '', $font_size = 8) { $series = sizeof($values); if (($series != sizeof ($labels)) || ($series == 0) ){ return; } $graph_id = uniqid('graph_'); $return = ""; if($water_mark != '') { $return .= ""; $water_mark = 'true'; } else { $water_mark = 'false'; } $separator = ';;::;;'; $labels = implode($separator,$labels); $values = implode($separator,$values); $return .= ""; return $return; } // Returns a 3D column chart function flot_hcolumn_chart ($graph_data, $width, $height, $water_mark) { global $config; $stacked_str = ''; $multicolor = true; // Get a unique identifier to graph $graph_id = uniqid('graph_'); $graph_id2 = uniqid('graph_'); // Set some containers to legend, graph, timestamp tooltip, etc. $return .= ""; $return .= ""; if($water_mark != '') { $return .= ""; $watermark = 'true'; } else { $watermark = 'false'; } // Set a weird separator to serialize and unserialize passing data from php to javascript $separator = ';;::;;'; $separator2 = ':,:,,,:,:'; // Transform data from our format to library format $labels = array(); $a = array(); $vars = array(); $max = 0; $i = count($graph_data); foreach($graph_data as $label => $values) { $labels[] = io_safe_output($label); $i--; foreach($values as $key => $value) { $jsvar = "data_".$graph_id."_".$key; if($multicolor) { for($j = count($graph_data) - 1; $j>=0; $j--) { if($j == $i) { $data[$jsvar.$i][$j] = $value; } else { $data[$jsvar.$i][$j] = 0; } } } else { $data[$jsvar][] = $value; } $return .= "