1<?PHP 2 3// Copyright (c) 2007-2008 Sancho Lerena, slerena@gmail.com 4// Copyright (c) 2008 Esteban Sanchez, estebans@artica.es 5// Copyright (c) 2007-2011 Artica, info@artica.es 6 7// This program is free software; you can redistribute it and/or 8// modify it under the terms of the GNU Lesser General Public License 9// (LGPL) as published by the Free Software Foundation; version 2 10 11// This program is distributed in the hope that it will be useful, 12// but WITHOUT ANY WARRANTY; without even the implied warranty of 13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14// GNU Lesser General Public License for more details. 15 16//JQuery 1.6.1 library addition 17 18global $config; 19 20 21function include_javascript_dependencies_flot_graph($return = false) { 22 global $config; 23 24 static $is_include_javascript = false; 25 26 if (!$is_include_javascript) { 27 $is_include_javascript = true; 28 29 $metaconsole_hack = ''; 30 if (defined('METACONSOLE')) { 31 $metaconsole_hack = '../../'; 32 } 33 34 // NOTE: jquery.flot.threshold is not te original file. Is patched to allow multiple thresholds and filled area 35 $output = ' 36 <!--[if lte IE 8]><script language="javascript" type="text/javascript" src="' . ui_get_full_url($metaconsole_hack . '/include/graphs/flot/excanvas.js') . '"></script><![endif]--> 37 <script language="javascript" type="text/javascript" src="'. 38 ui_get_full_url($metaconsole_hack . '/include/graphs/flot/jquery.flot.min.js') .'"></script> 39 <script language="javascript" type="text/javascript" src="'. 40 ui_get_full_url($metaconsole_hack . '/include/graphs/flot/jquery.flot.pie.js') .'"></script> 41 <script language="javascript" type="text/javascript" src="'. 42 ui_get_full_url($metaconsole_hack . '/include/graphs/flot/jquery.flot.crosshair.min.js') .'"></script> 43 <script language="javascript" type="text/javascript" src="'. 44 ui_get_full_url($metaconsole_hack . '/include/graphs/flot/jquery.flot.stack.min.js') .'"></script> 45 <script language="javascript" type="text/javascript" src="'. 46 ui_get_full_url($metaconsole_hack . '/include/graphs/flot/jquery.flot.selection.min.js') .'"></script> 47 <script language="javascript" type="text/javascript" src="'. 48 ui_get_full_url($metaconsole_hack . '/include/graphs/flot/jquery.flot.resize.min.js') .'"></script> 49 <script language="javascript" type="text/javascript" src="'. 50 ui_get_full_url($metaconsole_hack . '/include/graphs/flot/jquery.flot.threshold.js') .'"></script> 51 <script language="javascript" type="text/javascript" src="'. 52 ui_get_full_url($metaconsole_hack . '/include/graphs/flot/jquery.flot.symbol.min.js') .'"></script> 53 <script language="javascript" type="text/javascript" src="'. 54 ui_get_full_url($metaconsole_hack . '/include/graphs/flot/pandora.flot.js') .'"></script>'; 55 $output .= " 56 <script type='text/javascript'> 57 function pieHover(event, pos, obj) 58 { 59 if (!obj) 60 return; 61 percent = parseFloat(obj.series.percent).toFixed(2); 62 $('#hover').html('<span style=\'font-weight: bold; color: '+obj.series.color+'\'>'+obj.series.label+' ('+percent+'%)</span>'); 63 $('.legendLabel').each(function() { 64 if ($(this).html() == obj.series.label) { 65 $(this).css('font-weight','bold'); 66 } 67 else { 68 $(this).css('font-weight',''); 69 } 70 }); 71 } 72 73 function pieClick(event, pos, obj) 74 { 75 if (!obj) 76 return; 77 percent = parseFloat(obj.series.percent).toFixed(2); 78 alert(''+obj.series.label+': '+obj.series.data[0][1]+' ('+percent+'%)'); 79 } 80 </script>"; 81 82 if (!$return) 83 echo $output; 84 85 return $output; 86 } 87} 88 89/////////////////////////////// 90////////// AREA GRAPHS //////// 91/////////////////////////////// 92function flot_area_stacked_graph($chart_data, $width, $height, $color, 93 $legend, $long_index, $homeurl = '', $unit = '', $water_mark = '', 94 $serie_types = array(), $chart_extra_data = array(), 95 $yellow_threshold = 0, $red_threshold = 0, $adapt_key= '', 96 $force_integer = false, $series_suffix_str = '', $menu = true, 97 $background_color = 'white', $dashboard = false, $vconsole = false, $agent_module_id = 0) { 98 99 global $config; 100 101 return flot_area_graph($chart_data, $width, $height, $color, 102 $legend, $long_index, $homeurl, $unit, 'area_stacked', 103 $water_mark, $serie_types, $chart_extra_data, $yellow_threshold, 104 $red_threshold, $adapt_key, $force_integer, $series_suffix_str, 105 $menu, $background_color, $dashboard, $vconsole, $agent_module_id); 106} 107 108function flot_area_simple_graph($chart_data, $width, $height, $color, 109 $legend, $long_index, $homeurl = '', $unit = '', $water_mark = '', 110 $serie_types = array(), $chart_extra_data = array(), 111 $yellow_threshold = 0, $red_threshold = 0, $adapt_key= '', 112 $force_integer = false, $series_suffix_str = '', $menu = true, 113 $background_color = 'white', $dashboard = false, $vconsole = false, $agent_module_id = 0) { 114 115 global $config; 116 117 return flot_area_graph($chart_data, $width, $height, $color, 118 $legend, $long_index, $homeurl, $unit, 'area_simple', 119 $water_mark, $serie_types, $chart_extra_data, $yellow_threshold, 120 $red_threshold, $adapt_key, $force_integer, $series_suffix_str, 121 $menu, $background_color, $dashboard, $vconsole, $agent_module_id); 122} 123 124function flot_line_stacked_graph($chart_data, $width, $height, $color, 125 $legend, $long_index, $homeurl = '', $unit = '', $water_mark = '', 126 $serie_types = array(), $chart_extra_data = array(), 127 $yellow_threshold = 0, $red_threshold = 0, $adapt_key= '', 128 $force_integer = false, $series_suffix_str = '', $menu = true, 129 $background_color = 'white', $dashboard = false, $vconsole = false, $agent_module_id = 0) { 130 131 global $config; 132 133 return flot_area_graph($chart_data, $width, $height, $color, 134 $legend, $long_index, $homeurl, $unit, 'line_stacked', 135 $water_mark, $serie_types, $chart_extra_data, $yellow_threshold, 136 $red_threshold, $adapt_key, $force_integer, $series_suffix_str, 137 $menu, $background_color, $dashboard, $vconsole, $agent_module_id); 138} 139 140function flot_line_simple_graph($chart_data, $width, $height, $color, 141 $legend, $long_index, $homeurl = '', $unit = '', $water_mark = '', 142 $serie_types = array(), $chart_extra_data = array(), 143 $yellow_threshold = 0, $red_threshold = 0, $adapt_key= '', 144 $force_integer = false, $series_suffix_str = '', $menu = true, 145 $background_color = 'white', $dashboard = false, $vconsole = false, $agent_module_id = 0) { 146 147 global $config; 148 149 return flot_area_graph($chart_data, $width, $height, $color, 150 $legend, $long_index, $homeurl, $unit, 'line_simple', 151 $water_mark, $serie_types, $chart_extra_data, $yellow_threshold, 152 $red_threshold, $adapt_key, $force_integer, $series_suffix_str, 153 $menu, $background_color, $dashboard, $vconsole); 154} 155 156function flot_area_graph($chart_data, $width, $height, $color, $legend, 157 $long_index, $homeurl, $unit, $type, $water_mark, $serie_types, 158 $chart_extra_data, $yellow_threshold, $red_threshold, $adapt_key, 159 $force_integer, $series_suffix_str = '', $menu = true, 160 $background_color = 'white', $dashboard = false, $vconsole = false, $agent_module_id = 0) { 161 162 global $config; 163 164 165 include_javascript_dependencies_flot_graph(); 166 167 $font_size = '7'; 168 169 $menu = (int)$menu; 170 171 // Get a unique identifier to graph 172 $graph_id = uniqid('graph_'); 173 174 $background_style = ''; 175 switch ($background_color) { 176 default: 177 case 'white': 178 $background_style = ' background: #fff; '; 179 break; 180 case 'black': 181 $background_style = ' background: #000; '; 182 break; 183 case 'transparent': 184 $background_style = ''; 185 break; 186 } 187 188 // Parent layer 189 $return = "<div class='parent_graph' style='width: " . $width . "px; " . $background_style . "'>"; 190 // Set some containers to legend, graph, timestamp tooltip, etc. 191 $return .= "<p id='legend_$graph_id' class='legend_graph' style='font-size:".$font_size."pt'></p>"; 192 193 194 // Get other required module datas to draw warning and critical 195 if ($agent_module_id == 0) { 196 $yellow_up = 0; 197 $red_up = 0; 198 $yellow_inverse = false; 199 $red_inverse = false; 200 } else { 201 $module_data = db_get_row_sql ('SELECT * FROM tagente_modulo WHERE id_agente_modulo = ' . $agent_module_id); 202 $yellow_up = $module_data['max_warning']; 203 $red_up = $module_data['max_critical']; 204 $yellow_inverse = !($module_data['warning_inverse'] == 0); 205 $red_inverse = !($module_data['critical_inverse'] == 0); 206 } 207 208 if ($menu) { 209 $threshold = false; 210 if ($yellow_threshold != $yellow_up || $red_threshold != $red_up) { 211 $threshold = true; 212 } 213 214 $nbuttons = 3; 215 216 if ($threshold) { 217 $nbuttons++; 218 } 219 $return .= html_print_input_hidden ('lineWidhtGraph', $config['custom_graph_width'],true); 220 $menu_width = 25 * $nbuttons + 15; 221 if ( $dashboard == false AND $vconsole == false) { 222 $return .= "<div id='menu_$graph_id' class='menu_graph' " . 223 "style='display: none; " . 224 "text-align: center; " . 225 "width: " . $menu_width . "px; ". 226 "border: solid 1px #666; ". 227 "border-bottom: 0px; " . 228 "padding: 4px 4px 4px 4px;margin-bottom:5px;'> 229 <a href='javascript:'><img id='menu_cancelzoom_$graph_id' src='".$homeurl."images/zoom_cross_grey.disabled.png' alt='".__('Cancel zoom')."' title='".__('Cancel zoom')."'></a>"; 230 if ($threshold) { 231 $return .= " <a href='javascript:'><img id='menu_threshold_$graph_id' src='".$homeurl."images/chart_curve_threshold.png' alt='".__('Warning and Critical thresholds')."' title='".__('Warning and Critical thresholds')."'></a>"; 232 } 233 $return .= " <a href='javascript:'> 234 <img id='menu_overview_$graph_id' class='menu_overview' src='" . $homeurl . "images/chart_curve_overview.png' alt='" . __('Overview graph') . "' title='".__('Overview graph')."'></a>"; 235 236 // Export buttons 237 $return .= " <a href='javascript:'><img id='menu_export_csv_$graph_id' src='".$homeurl."images/csv_grey.png' alt='".__('Export to CSV')."' title='".__('Export to CSV')."'></a>"; 238 // Button disabled. This feature works, but seems that is not useful enough to the final users. 239 //$return .= " <a href='javascript:'><img id='menu_export_json_$graph_id' src='".$homeurl."images/json.png' alt='".__('Export to JSON')."' title='".__('Export to JSON')."'></a>"; 240 241 $return .= "</div>"; 242 } 243 } 244 $return .= "<div id='timestamp_$graph_id' class='timestamp_graph' style='font-size:".$font_size."pt;display:none; position:absolute; background:#fff; border: solid 1px #aaa; padding: 2px; z-index:1000;'></div>"; 245 $return .= "<div id='$graph_id' class='graph $adapt_key' style='width: ".$width."px; height: ".$height."px;'></div>"; 246 if ($menu) { 247 $height = 100; 248 } 249 else { 250 $height = 1; 251 } 252 if ( $dashboard == false AND $vconsole == false ) 253 $return .= "<div id='overview_$graph_id' class='overview_graph' style='visibility: hidden; margin-left:0px; margin-top:20px; width: ".$width."px; height: ".$height ."px;'></div>"; 254 255 if ($water_mark != '') { 256 $return .= "<div id='watermark_$graph_id' style='display:none; position:absolute;'><img id='watermark_image_$graph_id' src='$water_mark'></div>"; 257 $watermark = 'true'; 258 } 259 else { 260 $watermark = 'false'; 261 } 262 263 // Set a weird separator to serialize and unserialize passing data from php to javascript 264 $separator = ';;::;;'; 265 $separator2 = ':,:,,,:,:'; 266 267 // Transform data from our format to library format 268 $legend2 = array(); 269 $labels = array(); 270 $a = array(); 271 $vars = array(); 272 $serie_types2 = array(); 273 274 $colors = array(); 275 276 $index = array_keys(reset($chart_data)); 277 foreach ($index as $serie_key) { 278 if (isset($color[$serie_key])) { 279 $colors[] = $color[$serie_key]['color']; 280 } 281 else { 282 $colors[] = ''; 283 } 284 } 285 286 foreach ($chart_data as $label => $values) { 287 $labels[] = io_safe_output($label); 288 289 foreach($values as $key => $value) { 290 $jsvar = "data_" . $graph_id . "_" . $key; 291 292 293 if (!isset($serie_types[$key])) { 294 switch ($type) { 295 case 'line_simple': 296 case 'line_stacked': 297 $serie_types2[$jsvar] = 'line'; 298 break; 299 case 'area_simple': 300 case 'area_stacked': 301 default: 302 $serie_types2[$jsvar] = 'area'; 303 break; 304 } 305 } 306 else { 307 $serie_types2[$jsvar] = $serie_types[$key]; 308 } 309 310 311 if ($serie_types2[$jsvar] == 'points' && $value == 0) { 312 $data[$jsvar][] = 'null'; 313 } 314 else { 315 $data[$jsvar][] = $value; 316 } 317 318 if (!isset($legend[$key])) { 319 $legend2[$jsvar] = 'null'; 320 } 321 else { 322 $legend2[$jsvar] = $legend[$key]; 323 } 324 } 325 } 326 327 // Store data series in javascript format 328 $jsvars = ''; 329 $jsseries = array(); 330 $values2 = array(); 331 $i = 0; 332 $max_x = 0; 333 foreach ($data as $jsvar => $values) { 334 $n_values = count($values); 335 if ($n_values > $max_x) { 336 $max_x = $n_values; 337 } 338 339 $values2[] = implode($separator,$values); 340 $i ++; 341 } 342 343 $values = implode($separator2, $values2); 344 345 // Max is "n-1" because start with 0 346 $max_x--; 347 348 $extra_width = (int)($width / 3); 349 350 $return .= "<div id='extra_$graph_id' style='font-size: " . $font_size . "pt; display:none; position:absolute; overflow: auto; max-height: ".($height+50)."px; width: ".$extra_width."px; background:#fff; padding: 2px 2px 2px 2px; border: solid #000 1px;'></div>"; 351 352 // Process extra data 353 $events = array(); 354 $event_ids = array(); 355 $alerts = array(); 356 $alert_ids = array(); 357 $legend_events = ''; 358 $legend_alerts = ''; 359 360 if (empty($chart_extra_data)) { 361 $chart_extra_data = array(); 362 } 363 364 foreach ($chart_extra_data as $i => $data) { 365 switch ($i) { 366 case 'legend_alerts': 367 $legend_alerts = $data; 368 break; 369 case 'legend_events': 370 $legend_events = $data; 371 break; 372 default: 373 if (isset($data['events'])) { 374 $event_ids[] = $i; 375 $events[$i] = $data['events']; 376 } 377 if (isset($data['alerts'])) { 378 $alert_ids[] = $i; 379 $alerts[$i] = $data['alerts']; 380 } 381 break; 382 } 383 } 384 385 // Store serialized data to use it from javascript 386 $events = implode($separator,$events); 387 $event_ids = implode($separator,$event_ids); 388 $alerts = implode($separator,$alerts); 389 $alert_ids = implode($separator,$alert_ids); 390 $labels = implode($separator,$labels); 391 if (!empty($long_index)) { 392 $labels_long = implode($separator, $long_index); 393 } 394 else { 395 $labels_long = $labels; 396 } 397 if (!empty($legend)) { 398 $legend = io_safe_output(implode($separator, $legend)); 399 } 400 $serie_types = implode($separator, $serie_types2); 401 $colors = implode($separator, $colors); 402 403 // transform into string to pass to javascript 404 if ($force_integer) { 405 $force_integer = 'true'; 406 } 407 else { 408 $force_integer = 'false'; 409 } 410 411 // Trick to get translated string from javascript 412 $return .= html_print_input_hidden('unknown_text', __('Unknown'), 413 true); 414 415 // Javascript code 416 $return .= "<script type='text/javascript'>"; 417 $return .= "//<![CDATA[\n"; 418 $return .= "pandoraFlotArea(" . 419 "'$graph_id', \n" . 420 "'$values', \n" . 421 "'$labels', \n" . 422 "'$labels_long', \n" . 423 "'$legend', \n" . 424 "'$colors', \n" . 425 "'$type', \n" . 426 "'$serie_types', \n" . 427 "$watermark, \n" . 428 "$width, \n" . 429 "$max_x, \n" . 430 "'" . $homeurl . "', \n" . 431 "'$unit', \n" . 432 "$font_size, \n" . 433 "$menu, \n" . 434 "'$events', \n" . 435 "'$event_ids', \n" . 436 "'$legend_events', \n" . 437 "'$alerts', \n" . 438 "'$alert_ids', \n" . 439 "'$legend_alerts', \n" . 440 "'$yellow_threshold', \n" . 441 "'$red_threshold', \n" . 442 "$force_integer, \n" . 443 "'$separator', \n" . 444 "'$separator2', \n" . 445 "'$yellow_up', \n" . 446 "'$red_up', \n" . 447 "'$yellow_inverse', \n" . 448 "'$red_inverse', \n" . 449 "'$series_suffix_str', 450 '$vconsole');"; 451 $return .= "\n//]]>"; 452 $return .= "</script>"; 453 454 // Parent layer 455 $return .= "</div>"; 456 457 return $return; 458} 459 460/////////////////////////////// 461/////////////////////////////// 462/////////////////////////////// 463 464// Prints a FLOT pie chart 465function flot_pie_chart ($values, $labels, $width, $height, $water_mark, 466 $font = '', $font_size = 8, $legend_position = '', $colors = '') { 467 468 include_javascript_dependencies_flot_graph(); 469 470 $series = sizeof($values); 471 if (($series != sizeof ($labels)) || ($series == 0) ) { 472 return; 473 } 474 475 $graph_id = uniqid('graph_'); 476 477 switch ($legend_position) { 478 case 'bottom': 479 $height = $height + (count($values) * 24); 480 break; 481 case 'right': 482 default: 483 //TODO FOR TOP OR LEFT OR RIGHT 484 break; 485 } 486 487 $return = "<div id='$graph_id' class='graph' style='width: ".$width."px; height: ".$height."px;'></div>"; 488 489 if ($water_mark != '') { 490 $return .= "<div id='watermark_$graph_id' style='display:none; position:absolute;'><img id='watermark_image_$graph_id' src='$water_mark'></div>"; 491 $water_mark = 'true'; 492 } 493 else { 494 $water_mark = 'false'; 495 } 496 497 $separator = ';;::;;'; 498 499 $labels = implode($separator, $labels); 500 $values = implode($separator, $values); 501 if (!empty($colors)) { 502 $colors = implode($separator, $colors); 503 } 504 505 $return .= "<script type='text/javascript'>"; 506 507 $return .= "pandoraFlotPie('$graph_id', '$values', '$labels', 508 '$series', '$width', $font_size, $water_mark, 509 '$separator', '$legend_position', '$height', '$colors')"; 510 511 $return .= "</script>"; 512 513 return $return; 514} 515 516// Prints a FLOT pie chart 517function flot_custom_pie_chart ($flash_charts, $graph_values, 518 $width, $height, $colors, $module_name_list, $long_index, 519 $no_data,$xaxisname, $yaxisname, $water_mark, $fontpath, $font_size, 520 $unit, $ttl, $homeurl, $background_color, $legend_position) { 521 522 523 ///TODO 524 include_javascript_dependencies_flot_graph(); 525 526 $total_modules = $graph_values['total_modules']; 527 unset($graph_values['total_modules']); 528 529 foreach ($graph_values as $label => $value) { 530 if ($value['value']) { 531 if ($value['value'] > 1000000) 532 $legendvalue = sprintf("%sM", number_format($value['value'] / 1000000, 2)); 533 else if ($value['value'] > 1000) 534 $legendvalue = sprintf("%sK", number_format($value['value'] / 1000, 2)); 535 else 536 $legendvalue = $value['value']; 537 } 538 else 539 $legendvalue = __('No data'); 540 $values[] = $value['value']; 541 $legend[] = $label .": " . $legendvalue . " " .$value['unit']; 542 $labels[] = $label; 543 } 544 545 $graph_id = uniqid('graph_'); 546 547 $return = "<div id='$graph_id' class='graph' style='width: ".$width."px; height: ".$height."px;'></div>"; 548 549 if ($water_mark != '') { 550 $return .= "<div id='watermark_$graph_id' style='display:none; position:absolute;'><img id='watermark_image_$graph_id' src='".$water_mark["url"]."'></div>"; 551 $water_mark = 'true'; 552 } 553 else { 554 $water_mark = 'false'; 555 } 556 557 $separator = ';;::;;'; 558 559 $labels = implode($separator, $labels); 560 $legend = implode($separator, $legend); 561 $values = implode($separator, $values); 562 if (!empty($colors)) { 563 foreach ($colors as $color) { 564 $temp_colors[] = $color['color']; 565 } 566 } 567 $colors = implode($separator, $temp_colors); 568 569 $return .= "<script type='text/javascript'>"; 570 571 $return .= "pandoraFlotPieCustom('$graph_id', '$values', '$labels', 572 '$width', $font_size, $water_mark, 573 '$separator', '$legend_position', '$height', '$colors','$legend')"; 574 575 $return .= "</script>"; 576 577 return $return; 578} 579 580// Returns a 3D column chart 581function flot_hcolumn_chart ($graph_data, $width, $height, $water_mark) { 582 global $config; 583 584 include_javascript_dependencies_flot_graph(); 585 586 $return = ''; 587 588 $stacked_str = ''; 589 $multicolor = true; 590 591 // Get a unique identifier to graph 592 $graph_id = uniqid('graph_'); 593 $graph_id2 = uniqid('graph_'); 594 595 // Set some containers to legend, graph, timestamp tooltip, etc. 596 $return .= "<div id='$graph_id' class='graph' style='width: ".$width."px; height: ".$height."px; padding-left: 20px;'></div>"; 597 $return .= "<div id='value_$graph_id' style='display:none; position:absolute; background:#fff; border: solid 1px #aaa; padding: 2px'></div>"; 598 599 if ($water_mark != '') { 600 $return .= "<div id='watermark_$graph_id' style='display:none; position:absolute;'><img id='watermark_image_$graph_id' src='$water_mark'></div>"; 601 $watermark = 'true'; 602 } 603 else { 604 $watermark = 'false'; 605 } 606 607 // Set a weird separator to serialize and unserialize passing data 608 // from php to javascript 609 $separator = ';;::;;'; 610 $separator2 = ':,:,,,:,:'; 611 612 // Transform data from our format to library format 613 $labels = array(); 614 $a = array(); 615 $vars = array(); 616 617 $max = 0; 618 $i = count($graph_data); 619 $data = array(); 620 621 foreach ($graph_data as $label => $values) { 622 $labels[] = io_safe_output($label); 623 $i--; 624 625 foreach ($values as $key => $value) { 626 $jsvar = "data_" . $graph_id . "_" . $key; 627 628 $data[$jsvar][] = $value; 629 630 631 if ($value > $max) { 632 $max = $value; 633 } 634 } 635 } 636 637 638 // Store serialized data to use it from javascript 639 $labels = implode($separator,$labels); 640 641 // Store data series in javascript format 642 $jsvars = ''; 643 $jsseries = array(); 644 645 $i = 0; 646 647 $values2 = array(); 648 649 foreach ($data as $jsvar => $values) { 650 $values2[] = implode($separator,$values); 651 } 652 653 $values = implode($separator2, $values2); 654 655 $jsseries = implode(',', $jsseries); 656 657 658 // Javascript code 659 $return .= "<script type='text/javascript'>"; 660 661 $return .= "pandoraFlotHBars('$graph_id', '$values', '$labels', 662 false, $max, '$water_mark', '$separator', '$separator2')"; 663 664 $return .= "</script>"; 665 666 return $return; 667} 668 669// Returns a 3D column chart 670function flot_vcolumn_chart ($graph_data, $width, $height, $color, $legend, $long_index, $homeurl, $unit, $water_mark, $homedir) { 671 global $config; 672 673 include_javascript_dependencies_flot_graph(); 674 675 $stacked_str = ''; 676 $multicolor = false; 677 678 // Get a unique identifier to graph 679 $graph_id = uniqid('graph_'); 680 $graph_id2 = uniqid('graph_'); 681 682 if ($width != 'auto') { 683 $width = $width . "px"; 684 } 685 686 // Set some containers to legend, graph, timestamp tooltip, etc. 687 $return .= "<div id='$graph_id' class='graph $adapt_key' style='width: ".$width."; height: ".$height."px; padding-left: 20px;'></div>"; 688 $return .= "<div id='value_$graph_id' style='display:none; position:absolute; background:#fff; border: solid 1px #aaa; padding: 2px'></div>"; 689 690 if ($water_mark != '') { 691 $return .= "<div id='watermark_$graph_id' style='display:none; position:absolute;'><img id='watermark_image_$graph_id' src='$water_mark'></div>"; 692 $watermark = 'true'; 693 } 694 else { 695 $watermark = 'false'; 696 } 697 698 $colors = array(); 699 $index = array_keys(reset($graph_data)); 700 701 foreach ($index as $serie_key) { 702 if (isset($color[$serie_key])) { 703 $colors[] = $color[$serie_key]['color']; 704 } 705 else { 706 $colors[] = ''; 707 } 708 } 709 710 // Set a weird separator to serialize and unserialize passing data from php to javascript 711 $separator = ';;::;;'; 712 $separator2 = ':,:,,,:,:'; 713 714 // Transform data from our format to library format 715 $labels = array(); 716 $a = array(); 717 $vars = array(); 718 719 $max = 0; 720 $i = count($graph_data); 721 foreach ($graph_data as $label => $values) { 722 $labels[] = io_safe_output($label); 723 $i--; 724 725 foreach ($values as $key => $value) { 726 $jsvar = "data_" . $graph_id . "_" . $key; 727 728 $data[$jsvar][] = $value; 729 730 731 if ($value > $max) { 732 $max = $value; 733 } 734 } 735 } 736 737 // Store serialized data to use it from javascript 738 $labels = implode($separator,$labels); 739 $colors = implode($separator, $colors); 740 741 // Store data series in javascript format 742 $jsvars = ''; 743 $jsseries = array(); 744 745 $i = 0; 746 747 $values2 = array(); 748 749 foreach ($data as $jsvar => $values) { 750 $values2[] = implode($separator,$values); 751 } 752 753 $values = implode($separator2, $values2); 754 755 $jsseries = implode(',', $jsseries); 756 757 // Javascript code 758 $return .= "<script type='text/javascript'>"; 759 760 $return .= "pandoraFlotVBars('$graph_id', '$values', '$labels', '$labels', '$legend', '$colors', false, $max, '$water_mark', '$separator', '$separator2')"; 761 762 $return .= "</script>"; 763 764 return $return; 765} 766 767function flot_slicesbar_graph ($graph_data, $period, $width, $height, $legend, $colors, $fontpath, $round_corner, $homeurl, $watermark = '', $adapt_key = '', $stat_win = false) { 768 global $config; 769 770 include_javascript_dependencies_flot_graph(); 771 772 $height+= 20; 773 774 $stacked_str = 'stack: stack,'; 775 776 // Get a unique identifier to graph 777 $graph_id = uniqid('graph_'); 778 779 // Set some containers to legend, graph, timestamp tooltip, etc. 780 if ($stat_win) { 781 $return = "<div id='$graph_id' class='graph $adapt_key' style='width: ".$width."px; height: ".$height."px; display: inline-block;'></div>"; 782 } 783 else { 784 $return = "<div id='$graph_id' class='graph $adapt_key' style='width: ".$width."px; height: ".$height."px;'></div>"; 785 } 786 $return .= "<div id='value_$graph_id' style='display:none; position:absolute; background:#fff; border: solid 1px #aaa; padding: 2px'></div>"; 787 788 // Set a weird separator to serialize and unserialize passing data from php to javascript 789 $separator = ';;::;;'; 790 $separator2 = ':,:,,,:,:'; 791 792 // Transform data from our format to library format 793 $labels = array(); 794 $a = array(); 795 $vars = array(); 796 797 $datacolor = array(); 798 799 $max = 0; 800 801 $i = count($graph_data); 802 803 $intervaltick = $period / $i; 804 805 $leg_max_length = 0; 806 foreach ($legend as $l) { 807 if (strlen($l) > $leg_max_length) { 808 $leg_max_length = strlen($l); 809 } 810 } 811 812 $fontsize = 7; 813 814 $extra_height = 15; 815 if (defined("METACONSOLE")) 816 $extra_height = 20; 817 818 $return .= "<div id='extra_$graph_id' style='font-size: ".$fontsize."pt; display:none; position:absolute; overflow: auto; height: ".$extra_height."px; background:#fff; padding: 2px 2px 2px 2px; border: solid #000 1px;'></div>"; 819 820 $maxticks = (int) ($width / ($fontsize * $leg_max_length)); 821 822 $i_aux = $i; 823 while(1) { 824 if ($i_aux <= $maxticks ) { 825 break; 826 } 827 828 $intervaltick*= 2; 829 830 $i_aux /= 2; 831 } 832 833 $intervaltick = (int) $intervaltick; 834 $acumulate = 0; 835 $c = 0; 836 $acumulate_data = array(); 837 foreach ($graph_data as $label => $values) { 838 $labels[] = io_safe_output($label); 839 $i--; 840 841 foreach ($values as $key => $value) { 842 $jsvar = "d_".$graph_id."_".$i; 843 if ($key == 'data') { 844 $datacolor[$jsvar] = $colors[$value]; 845 continue; 846 } 847 $data[$jsvar][] = $value; 848 849 $acumulate_data[$c] = $acumulate; 850 $acumulate += $value; 851 $c++; 852 853 //$return .= "<div id='value_".$i."_$graph_id' class='values_$graph_id' style='color: #000; position:absolute;'>$value</div>"; 854 if ($value > $max) { 855 $max = $value; 856 } 857 } 858 } 859 860 // Store serialized data to use it from javascript 861 $labels = implode($separator,$labels); 862 $datacolor = implode($separator,$datacolor); 863 $legend = io_safe_output(implode($separator,$legend)); 864 $acumulate_data = io_safe_output(implode($separator,$acumulate_data)); 865 866 // Store data series in javascript format 867 $jsvars = ''; 868 $jsseries = array(); 869 870 $date = get_system_time (); 871 $datelimit = ($date - $period) * 1000; 872 873 $i = 0; 874 875 $values2 = array(); 876 877 foreach ($data as $jsvar => $values) { 878 $values2[] = implode($separator,$values); 879 $i ++; 880 } 881 882 $values = implode($separator2, $values2); 883 884 // Javascript code 885 $return .= "<script type='text/javascript'>"; 886 $return .= "//<![CDATA[\n"; 887 $return .= "pandoraFlotSlicebar('$graph_id', '$values', '$datacolor', '$labels', '$legend', '$acumulate_data', $intervaltick, false, $max, '$separator', '$separator2')"; 888 $return .= "\n//]]>"; 889 $return .= "</script>"; 890 891 return $return; 892} 893?> 894