'; $output .= " "; if (!$return) echo $output; return $output; } } /////////////////////////////// ////////// 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(), $yellow_threshold = 0, $red_threshold = 0, $adapt_key= '', $force_integer = false, $series_suffix_str = '', $menu = true, $background_color = 'white') { 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, $yellow_threshold, $red_threshold, $adapt_key, $force_integer, $series_suffix_str, $menu, $background_color); } function flot_area_simple_graph($chart_data, $width, $height, $color, $legend, $long_index, $homeurl = '', $unit = '', $water_mark = '', $serie_types = array(), $chart_extra_data = array(), $yellow_threshold = 0, $red_threshold = 0, $adapt_key= '', $force_integer = false, $series_suffix_str = '', $menu = true, $background_color = 'white') { 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, $yellow_threshold, $red_threshold, $adapt_key, $force_integer, $series_suffix_str, $menu, $background_color); } function flot_line_stacked_graph($chart_data, $width, $height, $color, $legend, $long_index, $homeurl = '', $unit = '', $water_mark = '', $serie_types = array(), $chart_extra_data = array(), $yellow_threshold = 0, $red_threshold = 0, $adapt_key= '', $force_integer = false, $series_suffix_str = '', $menu = true, $background_color = 'white') { 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, $yellow_threshold, $red_threshold, $adapt_key, $force_integer, $series_suffix_str, $menu, $background_color); } function flot_line_simple_graph($chart_data, $width, $height, $color, $legend, $long_index, $homeurl = '', $unit = '', $water_mark = '', $serie_types = array(), $chart_extra_data = array(), $yellow_threshold = 0, $red_threshold = 0, $adapt_key= '', $force_integer = false, $series_suffix_str = '', $menu = true, $background_color = 'white') { 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, $yellow_threshold, $red_threshold, $adapt_key, $force_integer, $series_suffix_str, $menu, $background_color); } function flot_area_graph($chart_data, $width, $height, $color, $legend, $long_index, $homeurl, $unit, $type, $water_mark, $serie_types, $chart_extra_data, $yellow_threshold, $red_threshold, $adapt_key, $force_integer, $series_suffix_str = '', $menu = true, $background_color = 'white') { global $config; include_javascript_dependencies_flot_graph(); $font_size = '7'; $menu = (int)$menu; // Get a unique identifier to graph $graph_id = uniqid('graph_'); $background_style = ''; switch ($background_color) { default: case 'white': $background_style = ' background: #fff; '; break; case 'black': $background_style = ' background: #000; '; break; case 'transparent': $background_style = ''; break; } // Parent layer $return = "
"; // Set some containers to legend, graph, timestamp tooltip, etc. $return .= "

"; $return .= ""; $return .= "
"; if ($menu) { $height = 100; } else { $height = 1; } $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 $legend2 = array(); $labels = array(); $a = array(); $vars = array(); $serie_types2 = array(); $colors = array(); $index = array_keys(reset($chart_data)); foreach ($index as $serie_key) { 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; } if (!isset($legend[$key])) { $legend2[$jsvar] = 'null'; } else { $legend2[$jsvar] = $legend[$key]; } } } // 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) { $threshold = false; if ($yellow_threshold != 0 || $red_threshold != 0) { $threshold = true; } $nbuttons = 2; if ($threshold) { $nbuttons++; } $menu_width = 25 * $nbuttons + 15; $return .= ""; } $extra_width = (int)($width / 3); $return .= ""; // Process extra data $events = array(); $event_ids = array(); $alerts = array(); $alert_ids = array(); $legend_events = ''; $legend_alerts = ''; if (empty($chart_extra_data)) { $chart_extra_data = array(); } 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); if (!empty($long_index)) { $labels_long = implode($separator, $long_index); } else { $labels_long = $labels; } if (!empty($legend)) { $legend = io_safe_output(implode($separator,$legend)); } $serie_types = implode($separator, $serie_types2); $colors = implode($separator, $colors); // transform into string to pass to javascript if ($force_integer) { $force_integer = 'true'; } else { $force_integer = 'false'; } // Trick to get translated string from javascript $return .= html_print_input_hidden('unknown_text', __('Unknown'), true); // Javascript code $return .= ""; // Parent layer $return .= "
"; return $return; } /////////////////////////////// /////////////////////////////// /////////////////////////////// // Prints a FLOT pie chart function flot_pie_chart ($values, $labels, $width, $height, $water_mark, $font = '', $font_size = 8, $legend_position = '', $colors = '') { include_javascript_dependencies_flot_graph(); $series = sizeof($values); if (($series != sizeof ($labels)) || ($series == 0) ) { return; } $graph_id = uniqid('graph_'); switch ($legend_position) { case 'bottom': $height = $height + (count($values) * 24); break; case 'right': default: //TODO FOR TOP OR LEFT OR RIGHT break; } $return = "
"; if ($water_mark != '') { $return .= ""; $water_mark = 'true'; } else { $water_mark = 'false'; } $separator = ';;::;;'; $labels = implode($separator, $labels); $values = implode($separator, $values); if (!empty($colors)) { $colors = implode($separator, $colors); } $return .= ""; return $return; } // Returns a 3D column chart function flot_hcolumn_chart ($graph_data, $width, $height, $water_mark) { global $config; include_javascript_dependencies_flot_graph(); $return = ''; $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); $data = array(); 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 .= "
$value
"; if ($value > $max) { $max = $value; } } } // Store serialized data to use it from javascript $labels = implode($separator,$labels); // Store data series in javascript format $jsvars = ''; $jsseries = array(); $i = 0; $values2 = array(); foreach ($data as $jsvar => $values) { $values2[] = implode($separator,$values); } $values = implode($separator2, $values2); $jsseries = implode(',', $jsseries); // Javascript code $return .= ""; return $return; } // Returns a 3D column chart function flot_vcolumn_chart ($graph_data, $width, $height, $color, $legend, $long_index, $homeurl, $unit, $water_mark, $homedir, $reduce_data_columns, $adapt_key) { global $config; include_javascript_dependencies_flot_graph(); $stacked_str = ''; $multicolor = false; // Get a unique identifier to graph $graph_id = uniqid('graph_'); $graph_id2 = uniqid('graph_'); if ($width != 'auto') { $width = $width . "px"; } // Set some containers to legend, graph, timestamp tooltip, etc. $return .= "
"; $return .= ""; if ($water_mark != '') { $return .= ""; $watermark = 'true'; } else { $watermark = 'false'; } $colors = array(); $index = array_keys(reset($graph_data)); foreach ($index as $serie_key) { if (isset($color[$serie_key])) { $colors[] = $color[$serie_key]['color']; } else { $colors[] = ''; } } // 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 .= "
$value
"; if ($value > $max) { $max = $value; } } } // Store serialized data to use it from javascript $labels = implode($separator,$labels); $colors = implode($separator, $colors); // Store data series in javascript format $jsvars = ''; $jsseries = array(); $i = 0; $values2 = array(); foreach ($data as $jsvar => $values) { $values2[] = implode($separator,$values); } $values = implode($separator2, $values2); $jsseries = implode(',', $jsseries); // Javascript code $return .= ""; return $return; } function flot_slicesbar_graph ($graph_data, $period, $width, $height, $legend, $colors, $fontpath, $round_corner, $homeurl, $watermark = '', $adapt_key = '') { global $config; include_javascript_dependencies_flot_graph(); $height+= 20; $stacked_str = 'stack: stack,'; // Get a unique identifier to graph $graph_id = uniqid('graph_'); // Set some containers to legend, graph, timestamp tooltip, etc. $return = "
"; $return .= ""; // 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(); $datacolor = array(); $max = 0; $i = count($graph_data); $intervaltick = $period / $i; $leg_max_length = 0; foreach ($legend as $l) { if (strlen($l) > $leg_max_length) { $leg_max_length = strlen($l); } } $fontsize = 7; $extra_height = 15; $return .= ""; $maxticks = (int) ($width / ($fontsize * $leg_max_length)); $i_aux = $i; while(1) { if ($i_aux <= $maxticks ) { break; } $intervaltick*= 2; $i_aux /= 2; } $intervaltick = (int) $intervaltick; $acumulate = 0; $c = 0; $acumulate_data = array(); foreach ($graph_data as $label => $values) { $labels[] = io_safe_output($label); $i--; foreach ($values as $key => $value) { $jsvar = "d_".$graph_id."_".$i; if ($key == 'data') { $datacolor[$jsvar] = $colors[$value]; continue; } $data[$jsvar][] = $value; $acumulate_data[$c] = $acumulate; $acumulate += $value; $c++; //$return .= "
$value
"; if ($value > $max) { $max = $value; } } } // Store serialized data to use it from javascript $labels = implode($separator,$labels); $datacolor = implode($separator,$datacolor); $legend = io_safe_output(implode($separator,$legend)); $acumulate_data = io_safe_output(implode($separator,$acumulate_data)); // Store data series in javascript format $jsvars = ''; $jsseries = array(); $date = get_system_time (); $datelimit = ($date - $period) * 1000; $i = 0; $values2 = array(); foreach ($data as $jsvar => $values) { $values2[] = implode($separator,$values); $i ++; } $values = implode($separator2, $values2); // Javascript code $return .= ""; return $return; } ?>