2012-03-01 17:41:02 +01:00
|
|
|
<?PHP
|
|
|
|
|
|
|
|
// Copyright (c) 2007-2008 Sancho Lerena, slerena@gmail.com
|
|
|
|
// Copyright (c) 2008 Esteban Sanchez, estebans@artica.es
|
2023-06-23 23:44:33 +02:00
|
|
|
// Copyright (c) 2007-2021 Artica, info@pandorafms.com
|
2012-03-01 17:41:02 +01:00
|
|
|
// 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.
|
2019-01-30 16:18:44 +01:00
|
|
|
// JQuery 1.6.1 library addition
|
2012-03-01 17:41:02 +01:00
|
|
|
global $config;
|
|
|
|
|
2012-03-05 20:25:02 +01:00
|
|
|
|
2020-06-12 13:14:58 +02:00
|
|
|
function include_javascript_dependencies_flot_graph($return=false, $mobile=false)
|
2019-01-30 16:18:44 +01:00
|
|
|
{
|
|
|
|
global $config;
|
|
|
|
|
|
|
|
static $is_include_javascript = false;
|
|
|
|
|
|
|
|
if (!$is_include_javascript) {
|
|
|
|
$is_include_javascript = true;
|
|
|
|
|
|
|
|
$metaconsole_hack = '';
|
2019-08-08 15:18:15 +02:00
|
|
|
if (is_metaconsole()) {
|
2019-01-30 16:18:44 +01:00
|
|
|
$metaconsole_hack = '../../';
|
|
|
|
}
|
|
|
|
|
2020-06-12 13:14:58 +02:00
|
|
|
$output = '';
|
|
|
|
|
|
|
|
if ($mobile === true) {
|
|
|
|
$output .= '
|
|
|
|
<script language="javascript" type="text/javascript" src="'.ui_get_full_url($metaconsole_hack.'/mobile/include/javascript/jquery.js').'"></script>
|
2022-02-07 12:29:57 +01:00
|
|
|
<script language="javascript" type="text/javascript" src="'.ui_get_full_url($metaconsole_hack.'/mobile/include/javascript/jquery.mobile-1.5.0-rc1.js').'"></script>';
|
2020-06-12 13:14:58 +02:00
|
|
|
}
|
|
|
|
|
2023-05-03 11:01:28 +02:00
|
|
|
$output .= '
|
|
|
|
<script type="text/javascript">
|
|
|
|
var phpTimezone = "'.date_default_timezone_get().'";
|
|
|
|
var configHomeurl = "'.$config['homeurl'].'";
|
|
|
|
</script>';
|
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
// NOTE: jquery.flot.threshold is not te original file. Is patched to allow multiple thresholds and filled area
|
2020-06-12 13:14:58 +02:00
|
|
|
$output .= '
|
2019-01-30 16:18:44 +01:00
|
|
|
<!--[if lte IE 8]><script language="javascript" type="text/javascript" src="'.ui_get_full_url($metaconsole_hack.'/include/graphs/flot/excanvas.js').'"></script><![endif]-->
|
2023-05-03 11:01:28 +02:00
|
|
|
<script language="javascript" type="text/javascript" src="'.ui_get_full_url($metaconsole_hack.'/include/javascript/timezone/src/date.js').'"></script>
|
2019-01-30 16:18:44 +01:00
|
|
|
<script language="javascript" type="text/javascript" src="'.ui_get_full_url($metaconsole_hack.'/include/graphs/flot/jquery.flot.min.js').'"></script>
|
|
|
|
<script language="javascript" type="text/javascript" src="'.ui_get_full_url($metaconsole_hack.'/include/graphs/flot/jquery.flot.time.js').'"></script>
|
|
|
|
<script language="javascript" type="text/javascript" src="'.ui_get_full_url($metaconsole_hack.'/include/graphs/flot/jquery.flot.pie.js').'"></script>
|
|
|
|
<script language="javascript" type="text/javascript" src="'.ui_get_full_url($metaconsole_hack.'/include/graphs/flot/jquery.flot.crosshair.min.js').'"></script>
|
|
|
|
<script language="javascript" type="text/javascript" src="'.ui_get_full_url($metaconsole_hack.'/include/graphs/flot/jquery.flot.stack.min.js').'"></script>
|
|
|
|
<script language="javascript" type="text/javascript" src="'.ui_get_full_url($metaconsole_hack.'/include/graphs/flot/jquery.flot.selection.min.js').'"></script>
|
|
|
|
<script language="javascript" type="text/javascript" src="'.ui_get_full_url($metaconsole_hack.'/include/graphs/flot/jquery.flot.resize.min.js').'"></script>
|
|
|
|
<script language="javascript" type="text/javascript" src="'.ui_get_full_url($metaconsole_hack.'/include/graphs/flot/jquery.flot.threshold.js').'"></script>
|
|
|
|
<script language="javascript" type="text/javascript" src="'.ui_get_full_url($metaconsole_hack.'/include/graphs/flot/jquery.flot.threshold.multiple.js').'"></script>
|
|
|
|
<script language="javascript" type="text/javascript" src="'.ui_get_full_url($metaconsole_hack.'/include/graphs/flot/jquery.flot.symbol.min.js').'"></script>
|
|
|
|
<script language="javascript" type="text/javascript" src="'.ui_get_full_url($metaconsole_hack.'/include/graphs/flot/jquery.flot.exportdata.pandora.js').'"></script>
|
|
|
|
<script language="javascript" type="text/javascript" src="'.ui_get_full_url($metaconsole_hack.'/include/graphs/flot/jquery.flot.axislabels.js').'"></script>
|
2023-03-24 12:53:48 +01:00
|
|
|
<script language="javascript" type="text/javascript" src="'.ui_get_full_url($metaconsole_hack.'/include/graphs/flot/pandora.flot.js').'?v='.$config['current_package'].'"></script>';
|
2022-12-13 09:10:13 +01:00
|
|
|
|
|
|
|
// Chartjs.
|
|
|
|
$output .= '<script language="javascript" type="text/javascript" src="'.ui_get_full_url($metaconsole_hack.'/include/graphs/chartjs/chart.js').'"></script>';
|
2022-12-16 10:38:37 +01:00
|
|
|
$output .= '<script language="javascript" type="text/javascript" src="'.ui_get_full_url($metaconsole_hack.'/include/graphs/chartjs/chartjs-plugin-datalabels.min.js').'"></script>';
|
2022-12-13 09:10:13 +01:00
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
$output .= "
|
2013-03-15 15:35:52 +01:00
|
|
|
<script type='text/javascript'>
|
2019-01-30 16:18:44 +01:00
|
|
|
var precision_graph = ".$config['graph_precision'].";
|
2018-04-27 13:51:13 +02:00
|
|
|
function pieHover(event, pos, obj)
|
2013-03-15 15:35:52 +01:00
|
|
|
{
|
|
|
|
if (!obj)
|
|
|
|
return;
|
|
|
|
percent = parseFloat(obj.series.percent).toFixed(2);
|
|
|
|
$('#hover').html('<span style=\'font-weight: bold; color: '+obj.series.color+'\'>'+obj.series.label+' ('+percent+'%)</span>');
|
|
|
|
$('.legendLabel').each(function() {
|
2013-07-17 13:12:37 +02:00
|
|
|
if ($(this).html() == obj.series.label) {
|
2013-03-15 15:35:52 +01:00
|
|
|
$(this).css('font-weight','bold');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$(this).css('font-weight','');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2018-04-27 13:51:13 +02:00
|
|
|
|
|
|
|
function pieClick(event, pos, obj)
|
2013-03-15 15:35:52 +01:00
|
|
|
{
|
|
|
|
if (!obj)
|
|
|
|
return;
|
|
|
|
percent = parseFloat(obj.series.percent).toFixed(2);
|
2013-04-10 09:57:54 +02:00
|
|
|
alert(''+obj.series.label+': '+obj.series.data[0][1]+' ('+percent+'%)');
|
2013-03-15 15:35:52 +01:00
|
|
|
}
|
2020-09-21 15:13:07 +02:00
|
|
|
</script>";
|
2018-04-27 13:51:13 +02:00
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
if (!$return) {
|
|
|
|
echo $output;
|
|
|
|
}
|
2018-04-27 13:51:13 +02:00
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
return $output;
|
|
|
|
}
|
2012-03-05 20:25:02 +01:00
|
|
|
}
|
2012-03-01 17:41:02 +01:00
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
|
2019-05-09 16:26:38 +02:00
|
|
|
/**
|
|
|
|
* Function create container for print charts.
|
|
|
|
*
|
|
|
|
* @param integer $agent_module_id Id module.
|
|
|
|
* @param array $array_data Data.
|
|
|
|
* @param array $legend Legend.
|
|
|
|
* @param array $series_type Series.
|
|
|
|
* @param array $color Color.
|
|
|
|
* @param array $date_array Date.
|
|
|
|
* @param array $data_module_graph Data module.
|
|
|
|
* @param array $params Params.
|
|
|
|
* @param string $water_mark Water.
|
|
|
|
* @param array $array_events_alerts Events array.
|
|
|
|
*
|
|
|
|
* @return string Return graphs.
|
|
|
|
*/
|
2019-01-30 16:18:44 +01:00
|
|
|
function flot_area_graph(
|
|
|
|
$agent_module_id,
|
|
|
|
$array_data,
|
|
|
|
$legend,
|
|
|
|
$series_type,
|
|
|
|
$color,
|
|
|
|
$date_array,
|
|
|
|
$data_module_graph,
|
|
|
|
$params,
|
|
|
|
$water_mark,
|
|
|
|
$array_events_alerts
|
|
|
|
) {
|
|
|
|
global $config;
|
2021-08-16 16:32:20 +02:00
|
|
|
global $is_mobile;
|
2019-01-30 16:18:44 +01:00
|
|
|
|
2019-05-09 16:26:38 +02:00
|
|
|
// Get a unique identifier to graph.
|
2019-01-30 16:18:44 +01:00
|
|
|
$graph_id = uniqid('graph_');
|
|
|
|
|
|
|
|
$background_style = '';
|
|
|
|
switch ($params['backgroundColor']) {
|
|
|
|
case 'white':
|
|
|
|
$background_style = ' background: #fff; ';
|
|
|
|
$params['grid_color'] = '#C1C1C1';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'black':
|
|
|
|
$background_style = ' background: #000; ';
|
|
|
|
$params['grid_color'] = '#BDBDBD';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'transparent':
|
|
|
|
$background_style = '';
|
|
|
|
$params['grid_color'] = '#A4A4A4';
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
$background_style = 'background-color: '.$params['backgroundColor'];
|
|
|
|
$params['grid_color'] = '#C1C1C1';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-01-17 10:22:30 +01:00
|
|
|
if (($config['style'] === 'pandora_black' && !is_metaconsole()) && ($params['pdf'] === false || $params['pdf'] === null) && (isset($is_mobile) === false || $is_mobile === false)
|
2021-06-10 10:19:11 +02:00
|
|
|
) {
|
2021-04-09 11:52:28 +02:00
|
|
|
$background_style = '#222';
|
|
|
|
$params['grid_color'] = '#fff';
|
|
|
|
$params['backgroundColor'] = '#222';
|
|
|
|
$params['legend_color'] = '#fff';
|
2021-06-10 10:19:11 +02:00
|
|
|
} else if ($params['pdf']) {
|
|
|
|
$params['legend_color'] = '#000';
|
2021-04-09 11:52:28 +02:00
|
|
|
}
|
|
|
|
|
2019-05-09 16:26:38 +02:00
|
|
|
// Parent layer.
|
2020-06-25 15:18:33 +02:00
|
|
|
if (strpos($params['width'], '%') === false) {
|
|
|
|
$width = 'width: '.$params['width'].'px;';
|
|
|
|
} else {
|
|
|
|
$width = 'width: '.$params['width'].';';
|
|
|
|
}
|
|
|
|
|
|
|
|
$return = "<div class='parent_graph' style='".$width.$background_style."'>";
|
2019-05-09 16:26:38 +02:00
|
|
|
|
2020-01-15 14:28:43 +01:00
|
|
|
if ($params['title'] === true && empty($params['title']) === false) {
|
2021-03-11 15:40:23 +01:00
|
|
|
$return .= '<p class="center">'.$params['title'].'</p>';
|
2019-05-09 16:26:38 +02:00
|
|
|
}
|
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
// Set some containers to legend, graph, timestamp tooltip, etc.
|
|
|
|
if ($params['show_legend']) {
|
2021-07-08 10:03:57 +02:00
|
|
|
$return .= '<p id="legend_'.$graph_id.'" class="legend_background" style="text-align:left; width: '.$params['width'].'px;"></p>';
|
2019-01-30 16:18:44 +01:00
|
|
|
}
|
|
|
|
|
2020-03-26 12:29:38 +01:00
|
|
|
if (isset($params['graph_combined']) === true && $params['graph_combined']
|
|
|
|
&& (isset($params['from_interface']) === false || !$params['from_interface'])
|
2019-01-30 16:18:44 +01:00
|
|
|
) {
|
2020-03-26 12:29:38 +01:00
|
|
|
if (isset($params['threshold_data']) === true
|
|
|
|
&& is_array($params['threshold_data']) === true
|
2019-05-09 16:26:38 +02:00
|
|
|
) {
|
2019-01-30 16:18:44 +01:00
|
|
|
$yellow_threshold = $params['threshold_data']['yellow_threshold'];
|
|
|
|
$red_threshold = $params['threshold_data']['red_threshold'];
|
|
|
|
$yellow_up = $params['threshold_data']['yellow_up'];
|
|
|
|
$red_up = $params['threshold_data']['red_up'];
|
|
|
|
$yellow_inverse = $params['threshold_data']['yellow_inverse'];
|
|
|
|
$red_inverse = $params['threshold_data']['red_inverse'];
|
|
|
|
} else {
|
|
|
|
$yellow_up = 0;
|
|
|
|
$red_up = 0;
|
|
|
|
$yellow_inverse = false;
|
|
|
|
$red_inverse = false;
|
|
|
|
}
|
2020-03-26 12:29:38 +01:00
|
|
|
} else if (isset($params['combined']) === false || !$params['combined']) {
|
2019-01-30 16:18:44 +01:00
|
|
|
$yellow_threshold = $data_module_graph['w_min'];
|
|
|
|
$red_threshold = $data_module_graph['c_min'];
|
2019-05-09 16:26:38 +02:00
|
|
|
// Get other required module datas to draw warning and critical.
|
2019-01-30 16:18:44 +01:00
|
|
|
if ($agent_module_id == 0) {
|
|
|
|
$yellow_up = 0;
|
|
|
|
$red_up = 0;
|
|
|
|
$yellow_inverse = false;
|
|
|
|
$red_inverse = false;
|
|
|
|
} else {
|
|
|
|
$yellow_up = $data_module_graph['w_max'];
|
|
|
|
$red_up = $data_module_graph['c_max'];
|
|
|
|
$yellow_inverse = !($data_module_graph['w_inv'] == 0);
|
|
|
|
$red_inverse = !($data_module_graph['c_inv'] == 0);
|
|
|
|
}
|
2020-03-26 12:29:38 +01:00
|
|
|
} else if (isset($params['from_interface']) === true
|
2019-05-09 16:26:38 +02:00
|
|
|
&& $params['from_interface']
|
|
|
|
) {
|
2020-03-26 12:29:38 +01:00
|
|
|
if (isset($params['threshold_data']) === true
|
2019-05-09 16:26:38 +02:00
|
|
|
&& is_array($params['threshold_data'])
|
|
|
|
) {
|
2019-01-30 16:18:44 +01:00
|
|
|
$yellow_threshold = $params['threshold_data']['yellow_threshold'];
|
|
|
|
$red_threshold = $params['threshold_data']['red_threshold'];
|
|
|
|
$yellow_up = $params['threshold_data']['yellow_up'];
|
|
|
|
$red_up = $params['threshold_data']['red_up'];
|
|
|
|
$yellow_inverse = $params['threshold_data']['yellow_inverse'];
|
|
|
|
$red_inverse = $params['threshold_data']['red_inverse'];
|
|
|
|
} else {
|
|
|
|
$yellow_up = 0;
|
|
|
|
$red_up = 0;
|
|
|
|
$yellow_inverse = false;
|
|
|
|
$red_inverse = false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$yellow_up = 0;
|
|
|
|
$red_up = 0;
|
|
|
|
$yellow_inverse = false;
|
|
|
|
$red_inverse = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($params['menu']) {
|
|
|
|
$return .= menu_graph(
|
|
|
|
$yellow_threshold,
|
|
|
|
$red_threshold,
|
|
|
|
$yellow_up,
|
|
|
|
$red_up,
|
|
|
|
$yellow_inverse,
|
|
|
|
$red_inverse,
|
|
|
|
$graph_id,
|
|
|
|
$params
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-05-09 16:26:38 +02:00
|
|
|
$return .= html_print_input_hidden(
|
|
|
|
'line_width_graph',
|
|
|
|
$config['custom_graph_width'],
|
|
|
|
true
|
|
|
|
);
|
2020-06-15 16:14:34 +02:00
|
|
|
$return .= "<div id='timestamp_$graph_id'
|
|
|
|
class='timestamp_graph'
|
|
|
|
style='font-size:".$params['font_size']."pt;
|
|
|
|
display:none; position:absolute;
|
|
|
|
background:#fff; border: solid 1px #aaa;
|
2021-04-09 11:52:28 +02:00
|
|
|
padding: 2px; z-index:1000; color: #000;
|
2020-06-15 16:14:34 +02:00
|
|
|
'></div>";
|
2019-01-30 16:18:44 +01:00
|
|
|
$return .= "<div id='$graph_id' class='";
|
2018-02-16 13:41:31 +01:00
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
if ($params['type'] == 'area_simple') {
|
|
|
|
$return .= 'noresizevc ';
|
|
|
|
}
|
2018-06-08 08:58:18 +02:00
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
$return .= 'graph'.$params['adapt_key']."'
|
|
|
|
style=' width: ".$params['width'].'px;
|
|
|
|
height: '.$params['height']."px;'></div>";
|
2018-02-16 13:41:31 +01:00
|
|
|
|
2023-04-04 14:30:43 +02:00
|
|
|
$legend_top = 10;
|
|
|
|
if (empty($params['show_legend']) === false) {
|
|
|
|
$legend_top = (int) $params['height'];
|
|
|
|
}
|
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
if ($params['menu']) {
|
|
|
|
$params['height'] = 100;
|
|
|
|
} else {
|
|
|
|
$params['height'] = 1;
|
|
|
|
}
|
2018-02-23 14:31:00 +01:00
|
|
|
|
2020-12-09 14:05:40 +01:00
|
|
|
if ((bool) $params['vconsole'] === false) {
|
|
|
|
$return .= '<div id="overview_'.$graph_id.'" class="overview_graph" style="margin:0px; margin-top:30px; margin-bottom:50px; width:'.$params['width'].'px; height: 200px;"></div>';
|
2019-01-30 16:18:44 +01:00
|
|
|
|
2020-12-09 14:05:40 +01:00
|
|
|
if ($water_mark != '' && (bool) $params['dashboard'] === false) {
|
2023-04-04 14:30:43 +02:00
|
|
|
$return .= '<div id="watermark_'.$graph_id.'" style="position:absolute; bottom: '.$legend_top.'px; left: calc(100% - 100px);">';
|
2020-12-09 14:05:40 +01:00
|
|
|
$return .= '<img id="watermark_image_'.$graph_id.'" src="'.$water_mark['url'].'">';
|
|
|
|
$return .= '</div>';
|
2020-03-26 12:29:38 +01:00
|
|
|
}
|
2019-01-30 16:18:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($series_type as $k => $v) {
|
|
|
|
$series_type_unique['data_'.$graph_id.'_'.$k] = $v;
|
|
|
|
}
|
|
|
|
|
2020-09-15 11:13:41 +02:00
|
|
|
// Store data series in javascript format.
|
|
|
|
$extra_width = (int) ($params['width'] / 3);
|
|
|
|
$return .= "<div id='extra_$graph_id'
|
|
|
|
style='font-size: ".$params['font_size'].'pt;
|
|
|
|
display:none; position:absolute; overflow: auto;
|
|
|
|
max-height: '.($params['height'] + 50).'px;
|
|
|
|
width: '.$extra_width."px;
|
|
|
|
background:#fff; padding: 2px 2px 2px 2px;
|
|
|
|
border: solid #000 1px;'></div>";
|
|
|
|
|
|
|
|
// Trick to get translated string from javascript.
|
|
|
|
$return .= html_print_input_hidden('unknown_text', __('Unknown'), true);
|
2019-01-30 16:18:44 +01:00
|
|
|
|
2019-05-09 16:26:38 +02:00
|
|
|
$values = json_encode($array_data);
|
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
$legend = json_encode($legend);
|
|
|
|
$series_type = json_encode($series_type);
|
|
|
|
$color = json_encode($color);
|
|
|
|
$date_array = json_encode($date_array);
|
|
|
|
$data_module_graph = json_encode($data_module_graph);
|
|
|
|
$params = json_encode($params);
|
|
|
|
$array_events_alerts = json_encode($array_events_alerts);
|
|
|
|
|
2019-05-09 16:26:38 +02:00
|
|
|
// Javascript code.
|
2019-01-30 16:18:44 +01:00
|
|
|
if ($font_size == '') {
|
|
|
|
$font_size = '\'\'';
|
|
|
|
}
|
|
|
|
|
|
|
|
$return .= "<script type='text/javascript'>";
|
2019-06-24 17:17:50 +02:00
|
|
|
|
|
|
|
$return .= "pandoraFlotArea(\n";
|
|
|
|
$return .= "'".$graph_id."', \n";
|
|
|
|
$return .= $values.", \n";
|
|
|
|
$return .= $legend.", \n";
|
|
|
|
$return .= $series_type.", \n";
|
|
|
|
$return .= $color.", \n";
|
|
|
|
$return .= $date_array.", \n";
|
|
|
|
$return .= $data_module_graph.", \n";
|
|
|
|
$return .= $params.", \n";
|
|
|
|
$return .= $array_events_alerts."\n";
|
|
|
|
$return .= ');';
|
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
$return .= '</script>';
|
|
|
|
|
2019-05-09 16:26:38 +02:00
|
|
|
// Parent layer.
|
2019-01-30 16:18:44 +01:00
|
|
|
$return .= '</div>';
|
|
|
|
|
|
|
|
return $return;
|
2018-02-16 13:41:31 +01:00
|
|
|
}
|
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
|
2018-02-16 13:41:31 +01:00
|
|
|
function menu_graph(
|
2019-01-30 16:18:44 +01:00
|
|
|
$yellow_threshold,
|
|
|
|
$red_threshold,
|
|
|
|
$yellow_up,
|
|
|
|
$red_up,
|
|
|
|
$yellow_inverse,
|
|
|
|
$red_inverse,
|
|
|
|
$graph_id,
|
|
|
|
$params
|
|
|
|
) {
|
2021-03-11 15:40:23 +01:00
|
|
|
global $config;
|
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
$return = '';
|
|
|
|
$threshold = false;
|
|
|
|
if ($yellow_threshold != $yellow_up || $red_threshold != $red_up) {
|
|
|
|
$threshold = true;
|
|
|
|
}
|
|
|
|
|
2020-10-28 12:50:15 +01:00
|
|
|
$return .= "<div id='general_menu_$graph_id' class='menu_graph'>";
|
2020-03-26 12:29:38 +01:00
|
|
|
$return .= "<div id='menu_$graph_id' "."style='display: none; ".'text-align: center;'.'position: relative;'."border-bottom: 0px;'>
|
2023-03-06 15:44:32 +01:00
|
|
|
<a href='javascript:'><img id='menu_cancelzoom_$graph_id' class='main_menu_icon invert_filter' src='".$params['homeurl'].'images/disable.svg'."' alt='".__('Cancel zoom')."' title='".__('Cancel zoom')."'></a>";
|
2020-03-26 12:29:38 +01:00
|
|
|
if ($threshold) {
|
2021-03-11 15:40:23 +01:00
|
|
|
$return .= " <a href='javascript:'><img id='menu_threshold_$graph_id' src='".$params['homeurl'].'images/chart_curve_threshold.png'."' alt='".__('Warning and Critical thresholds')."' title='".__('Warning and Critical thresholds')."'></a>";
|
2019-01-30 16:18:44 +01:00
|
|
|
}
|
|
|
|
|
2020-03-26 12:29:38 +01:00
|
|
|
if ($params['show_overview']) {
|
|
|
|
$return .= " <a href='javascript:'>
|
2021-03-11 15:40:23 +01:00
|
|
|
<img id='menu_overview_$graph_id' class='menu_overview' src='".$params['homeurl'].'images/chart_curve_overview.png'."' alt='".__('Overview graph')."' title='".__('Overview graph')."'></a>";
|
2020-03-26 12:29:38 +01:00
|
|
|
}
|
2018-02-27 16:28:00 +01:00
|
|
|
|
2020-03-26 12:29:38 +01:00
|
|
|
// Export buttons.
|
2021-04-23 08:58:23 +02:00
|
|
|
if ($params['show_export_csv'] && enterprise_installed() === true) {
|
2023-03-06 15:44:32 +01:00
|
|
|
$return .= "<a href='javascript:'><img id='menu_export_csv_$graph_id' class='main_menu_icon invert_filter' src='".$params['homeurl'].'images/file-csv.svg'."' alt='".__('Export to CSV')."' title='".__('Export to CSV')."'></a>";
|
2019-01-30 16:18:44 +01:00
|
|
|
}
|
|
|
|
|
2020-03-26 12:29:38 +01:00
|
|
|
$return .= '</div>';
|
|
|
|
$return .= '</div>';
|
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
return $return;
|
2018-02-16 13:41:31 +01:00
|
|
|
}
|
|
|
|
|
2012-03-01 17:41:02 +01:00
|
|
|
|
2020-10-09 12:05:57 +02:00
|
|
|
/**
|
|
|
|
* Pie chart.
|
|
|
|
*
|
|
|
|
* @param array $values Values.
|
|
|
|
* @param array $labels Labels.
|
|
|
|
* @param integer $width Width.
|
|
|
|
* @param integer $height Height.
|
|
|
|
* @param boolean $water_mark Water mark.
|
|
|
|
* @param string $font Font.
|
|
|
|
* @param integer $font_size Font Size.
|
|
|
|
* @param string $legend_position Psition Legend.
|
|
|
|
* @param string $colors Array Colors.
|
|
|
|
* @param boolean $hide_labels Hide labels.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2019-01-30 16:18:44 +01:00
|
|
|
function flot_pie_chart(
|
|
|
|
$values,
|
|
|
|
$labels,
|
|
|
|
$width,
|
|
|
|
$height,
|
|
|
|
$water_mark,
|
|
|
|
$font='',
|
|
|
|
$font_size=8,
|
|
|
|
$legend_position='',
|
|
|
|
$colors='',
|
|
|
|
$hide_labels=false
|
|
|
|
) {
|
2020-10-09 12:05:57 +02:00
|
|
|
$series = count($values);
|
|
|
|
|
|
|
|
if (($series !== count($labels)) || ($series === 0)) {
|
2019-01-30 16:18:44 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$graph_id = uniqid('graph_');
|
|
|
|
|
|
|
|
switch ($legend_position) {
|
|
|
|
case 'bottom':
|
|
|
|
$height = ($height + (count($values) * 24));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'right':
|
|
|
|
default:
|
2020-10-09 12:05:57 +02:00
|
|
|
// TODO FOR TOP OR LEFT OR RIGHT.
|
2019-01-30 16:18:44 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-10-09 12:05:57 +02:00
|
|
|
$return = "<div id='".$graph_id."' class='graph' style='width: ".$width.'px; height: '.$height."px;'></div>";
|
2019-01-30 16:18:44 +01:00
|
|
|
|
|
|
|
if ($water_mark != '') {
|
2021-03-11 15:40:23 +01:00
|
|
|
$return .= "<div id='watermark_$graph_id' class='invisible absolute'><img id='watermark_image_$graph_id' src='$water_mark'></div>";
|
2019-01-30 16:18:44 +01:00
|
|
|
$water_mark = 'true';
|
|
|
|
} else {
|
|
|
|
$water_mark = 'false';
|
|
|
|
}
|
|
|
|
|
|
|
|
$separator = ';;::;;';
|
|
|
|
|
|
|
|
$labels = implode($separator, $labels);
|
|
|
|
$values = implode($separator, $values);
|
2020-10-09 12:05:57 +02:00
|
|
|
if (empty($colors) === false) {
|
2019-01-30 16:18:44 +01:00
|
|
|
$colors = implode($separator, $colors);
|
|
|
|
}
|
|
|
|
|
|
|
|
$return .= "<script type='text/javascript'>";
|
2020-10-09 12:05:57 +02:00
|
|
|
$return .= "pandoraFlotPie(
|
|
|
|
'$graph_id',
|
|
|
|
'$values',
|
|
|
|
'$labels',
|
|
|
|
'$series',
|
|
|
|
'$width',
|
|
|
|
$font_size,
|
|
|
|
$water_mark,
|
|
|
|
'$separator',
|
|
|
|
'$legend_position',
|
|
|
|
'$height',
|
|
|
|
'$colors',
|
|
|
|
".json_encode($hide_labels).')';
|
2019-01-30 16:18:44 +01:00
|
|
|
$return .= '</script>';
|
2018-10-11 12:57:48 +02:00
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
return $return;
|
2012-03-01 17:41:02 +01:00
|
|
|
}
|
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
|
2015-11-04 17:42:45 +01:00
|
|
|
// Prints a FLOT pie chart
|
2019-01-30 16:18:44 +01:00
|
|
|
function flot_custom_pie_chart(
|
|
|
|
$graph_values,
|
|
|
|
$width,
|
|
|
|
$height,
|
|
|
|
$colors,
|
|
|
|
$module_name_list,
|
|
|
|
$long_index,
|
|
|
|
$no_data,
|
|
|
|
$xaxisname,
|
|
|
|
$yaxisname,
|
|
|
|
$water_mark,
|
|
|
|
$fontpath,
|
|
|
|
$font_size,
|
|
|
|
$unit,
|
|
|
|
$ttl,
|
|
|
|
$homeurl,
|
|
|
|
$background_color,
|
2021-06-10 10:19:11 +02:00
|
|
|
$legend_position,
|
|
|
|
$pdf
|
2019-01-30 16:18:44 +01:00
|
|
|
) {
|
|
|
|
global $config;
|
2021-04-09 11:52:28 +02:00
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
// TODO
|
2021-06-10 10:19:11 +02:00
|
|
|
// include_javascript_dependencies_flot_graph();.
|
2019-01-30 16:18:44 +01:00
|
|
|
$total_modules = $graph_values['total_modules'];
|
|
|
|
unset($graph_values['total_modules']);
|
|
|
|
|
|
|
|
foreach ($graph_values as $label => $value) {
|
|
|
|
if ($value['value']) {
|
|
|
|
if ($value['value'] > 1000000) {
|
2022-10-26 18:25:16 +02:00
|
|
|
$legendvalue = sprintf('%sM', remove_right_zeros(number_format(($value['value'] / 1000000), $config['graph_precision'], $config['decimal_separator'], $config['thousand_separator'])));
|
2019-01-30 16:18:44 +01:00
|
|
|
} else if ($value['value'] > 1000) {
|
2022-10-26 18:25:16 +02:00
|
|
|
$legendvalue = sprintf('%sK', remove_right_zeros(number_format(($value['value'] / 1000), $config['graph_precision'], $config['decimal_separator'], $config['thousand_separator'])));
|
2019-01-30 16:18:44 +01:00
|
|
|
} else {
|
2022-10-26 18:25:16 +02:00
|
|
|
$legendvalue = remove_right_zeros(number_format($value['value'], $config['graph_precision'], $config['decimal_separator'], $config['thousand_separator']));
|
2019-01-30 16:18:44 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$legendvalue = __('No data');
|
|
|
|
}
|
|
|
|
|
|
|
|
$values[] = $value['value'];
|
|
|
|
$legend[] = $label.': '.$legendvalue.' '.$value['unit'];
|
|
|
|
$labels[] = $label;
|
|
|
|
}
|
|
|
|
|
|
|
|
$graph_id = uniqid('graph_');
|
|
|
|
|
|
|
|
$return = "<div id='$graph_id' class='graph noresizevc' style='width: ".$width.'px; height: '.$height."px;'></div>";
|
|
|
|
|
|
|
|
if ($water_mark != '') {
|
2021-03-11 15:40:23 +01:00
|
|
|
$return .= "<div id='watermark_$graph_id' class='invisible absolute'><img id='watermark_image_$graph_id' src='".$water_mark['url']."'></div>";
|
2019-01-30 16:18:44 +01:00
|
|
|
$water_mark = 'true';
|
|
|
|
} else {
|
|
|
|
$water_mark = 'false';
|
|
|
|
}
|
|
|
|
|
|
|
|
$separator = ';;::;;';
|
|
|
|
|
|
|
|
$labels = implode($separator, $labels);
|
|
|
|
$legend = implode($separator, $legend);
|
|
|
|
$values = implode($separator, $values);
|
|
|
|
if (!empty($colors)) {
|
|
|
|
foreach ($colors as $color) {
|
|
|
|
$temp_colors[] = $color['color'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$colors = implode($separator, $temp_colors);
|
|
|
|
|
|
|
|
$return .= "<script type='text/javascript'>";
|
|
|
|
$return .= "pandoraFlotPieCustom('$graph_id', '$values', '$labels',
|
2016-09-08 15:44:36 +02:00
|
|
|
'$width', $font_size, '$fontpath', $water_mark,
|
2017-10-09 12:03:19 +02:00
|
|
|
'$separator', '$legend_position', '$height', '$colors','$legend','$background_color')";
|
2019-01-30 16:18:44 +01:00
|
|
|
$return .= '</script>';
|
|
|
|
|
|
|
|
return $return;
|
2015-11-04 17:42:45 +01:00
|
|
|
}
|
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
|
2021-06-10 10:19:11 +02:00
|
|
|
// Returns a 3D column chart.
|
|
|
|
function flot_hcolumn_chart($graph_data, $width, $height, $water_mark, $font='', $font_size=7, $background_color='white', $tick_color='white', $val_min=null, $val_max=null, $pdf=false)
|
2019-01-30 16:18:44 +01:00
|
|
|
{
|
|
|
|
global $config;
|
2017-11-08 16:41:23 +01:00
|
|
|
|
2021-06-10 10:19:11 +02:00
|
|
|
// Include_javascript_dependencies_flot_graph().
|
2019-01-30 16:18:44 +01:00
|
|
|
$return = '';
|
|
|
|
|
|
|
|
$stacked_str = '';
|
|
|
|
$multicolor = true;
|
|
|
|
|
2021-06-10 10:19:11 +02:00
|
|
|
// Get a unique identifier to graph.
|
2019-01-30 16:18:44 +01:00
|
|
|
$graph_id = uniqid('graph_');
|
|
|
|
$graph_id2 = uniqid('graph_');
|
|
|
|
|
|
|
|
// Set some containers to legend, graph, timestamp tooltip, etc.
|
|
|
|
$return .= "<div id='$graph_id' class='graph' style='width: ".$width.'px; height: '.$height."px; padding-left: 20px;'></div>";
|
2021-03-11 15:40:23 +01:00
|
|
|
$return .= "<div id='value_$graph_id' class='flot_container'></div>";
|
2019-01-30 16:18:44 +01:00
|
|
|
|
|
|
|
if ($water_mark != '') {
|
2021-03-11 15:40:23 +01:00
|
|
|
$return .= "<div id='watermark_$graph_id' class='invisible absolute'><img id='watermark_image_$graph_id' src='$water_mark'></div>";
|
2019-01-30 16:18:44 +01:00
|
|
|
$watermark = 'true';
|
|
|
|
} else {
|
|
|
|
$watermark = 'false';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set a weird separator to serialize and unserialize passing data
|
2021-06-10 10:19:11 +02:00
|
|
|
// from php to javascript.
|
2019-01-30 16:18:44 +01:00
|
|
|
$separator = ';;::;;';
|
|
|
|
$separator2 = ':,:,,,:,:';
|
|
|
|
|
2021-06-10 10:19:11 +02:00
|
|
|
// Transform data from our format to library format.
|
2019-01-30 16:18:44 +01:00
|
|
|
$labels = [];
|
|
|
|
$a = [];
|
|
|
|
$vars = [];
|
|
|
|
|
|
|
|
$max = (PHP_INT_MIN + 1);
|
|
|
|
$min = (PHP_INT_MAX - 1);
|
|
|
|
$i = count($graph_data);
|
|
|
|
$data = [];
|
|
|
|
|
|
|
|
foreach ($graph_data as $label => $values) {
|
|
|
|
$labels[] = io_safe_output($label);
|
|
|
|
$i--;
|
|
|
|
|
|
|
|
foreach ($values as $key => $value) {
|
|
|
|
$jsvar = 'data_'.$graph_id.'_'.$key;
|
|
|
|
|
|
|
|
$data[$jsvar][] = $value;
|
|
|
|
|
|
|
|
if ($value > $max) {
|
|
|
|
$max = $value;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($value < $min) {
|
|
|
|
$min = $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!is_numeric($val_min)) {
|
|
|
|
$val_min = $min;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!is_numeric($val_max)) {
|
|
|
|
$val_max = $max;
|
|
|
|
}
|
|
|
|
|
2021-06-10 10:19:11 +02:00
|
|
|
// Store serialized data to use it from javascript.
|
2019-01-30 16:18:44 +01:00
|
|
|
$labels = implode($separator, $labels);
|
|
|
|
|
2021-06-10 10:19:11 +02:00
|
|
|
// Store data series in javascript format.
|
2019-01-30 16:18:44 +01:00
|
|
|
$jsvars = '';
|
|
|
|
$jsseries = [];
|
|
|
|
|
|
|
|
$i = 0;
|
|
|
|
|
|
|
|
$values2 = [];
|
|
|
|
|
|
|
|
foreach ($data as $jsvar => $values) {
|
|
|
|
$values2[] = implode($separator, $values);
|
|
|
|
}
|
|
|
|
|
|
|
|
$values = implode($separator2, $values2);
|
|
|
|
|
|
|
|
$jsseries = implode(',', $jsseries);
|
|
|
|
|
2021-06-10 10:19:11 +02:00
|
|
|
// Javascript code.
|
2019-01-30 16:18:44 +01:00
|
|
|
$return .= "<script type='text/javascript'>";
|
2020-01-24 15:13:42 +01:00
|
|
|
$return .= "pandoraFlotHBars('$graph_id', '$values', '$labels', $max, '$water_mark', '$separator', '$separator2', '$font', $font_size, '$background_color', '$tick_color', $val_min, $val_max)";
|
2019-01-30 16:18:44 +01:00
|
|
|
$return .= '</script>';
|
|
|
|
|
|
|
|
return $return;
|
2012-03-01 17:41:02 +01:00
|
|
|
}
|
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
|
2020-03-26 12:29:38 +01:00
|
|
|
/**
|
|
|
|
* Draw html graph vertical bars.
|
|
|
|
*
|
|
|
|
* @param array $options Settings draw chart.
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
function flot_vcolumn_chart(array $options)
|
2019-01-30 16:18:44 +01:00
|
|
|
{
|
|
|
|
global $config;
|
|
|
|
|
|
|
|
$stacked_str = '';
|
|
|
|
$multicolor = false;
|
|
|
|
|
2020-03-26 12:29:38 +01:00
|
|
|
// Get a unique identifier to graph.
|
|
|
|
$graphId = uniqid('graph_');
|
2019-01-30 16:18:44 +01:00
|
|
|
|
2020-03-26 12:29:38 +01:00
|
|
|
// Div draw chart.
|
|
|
|
$style = 'width: 100%; height: 100%;';
|
|
|
|
if (isset($options['generals']['pdf']['width']) === true
|
|
|
|
&& isset($options['generals']['pdf']['height']) === true
|
|
|
|
) {
|
|
|
|
$style = 'width:'.$options['generals']['pdf']['width'].'px;';
|
|
|
|
$style .= 'height:'.$options['generals']['pdf']['height'].'px;';
|
2019-01-30 16:18:44 +01:00
|
|
|
}
|
|
|
|
|
2022-07-12 16:18:17 +02:00
|
|
|
if ($options['agent_view'] === true) {
|
|
|
|
$style = 'width: 95%; height: 85px';
|
|
|
|
}
|
|
|
|
|
2020-03-26 12:29:38 +01:00
|
|
|
$class = '';
|
|
|
|
if ($options['generals']['rotate'] === true) {
|
|
|
|
$class = 'bars-graph-rotate';
|
2019-01-30 16:18:44 +01:00
|
|
|
}
|
|
|
|
|
2020-03-26 12:29:38 +01:00
|
|
|
$return .= '<div id="'.$graphId.'" class="'.$class.'" style="'.$style.'">';
|
|
|
|
$return .= '</div>';
|
2019-01-30 16:18:44 +01:00
|
|
|
|
2020-03-26 12:29:38 +01:00
|
|
|
// Set some containers to legend, graph, timestamp tooltip, etc.
|
2021-03-11 15:40:23 +01:00
|
|
|
$return .= '<div id="value_'.$graphId.'" class="invisible"></div>';
|
2019-01-30 16:18:44 +01:00
|
|
|
|
2020-03-26 12:29:38 +01:00
|
|
|
// Add id to options.
|
|
|
|
$options['graphId'] = $graphId;
|
2021-04-09 11:29:26 +02:00
|
|
|
|
|
|
|
// If pandora_black theme its enabled then change grid colors.
|
2020-03-26 12:29:38 +01:00
|
|
|
$settings = base64_encode(json_encode($options));
|
2019-01-30 16:18:44 +01:00
|
|
|
|
2020-03-26 12:29:38 +01:00
|
|
|
// Javascript code.
|
|
|
|
$return .= '<script type="text/javascript">';
|
|
|
|
$return .= 'pandoraFlotVBars(\''.$settings.'\')';
|
2019-01-30 16:18:44 +01:00
|
|
|
$return .= '</script>';
|
|
|
|
|
|
|
|
return $return;
|
2012-03-01 17:41:02 +01:00
|
|
|
}
|
|
|
|
|
2018-10-19 10:04:26 +02:00
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
function flot_slicesbar_graph(
|
|
|
|
$graph_data,
|
|
|
|
$period,
|
|
|
|
$width,
|
|
|
|
$height,
|
|
|
|
$legend,
|
|
|
|
$colors,
|
|
|
|
$fontpath,
|
|
|
|
$round_corner,
|
|
|
|
$homeurl,
|
|
|
|
$watermark='',
|
|
|
|
$adapt_key='',
|
|
|
|
$stat_win=false,
|
|
|
|
$id_agent=0,
|
|
|
|
$full_legend_date=[],
|
|
|
|
$not_interactive=0,
|
|
|
|
$ttl=1,
|
2020-03-26 12:29:38 +01:00
|
|
|
$sizeForTicks=false,
|
2020-01-27 11:52:13 +01:00
|
|
|
$show=true,
|
2020-03-24 10:12:14 +01:00
|
|
|
$date_to=false,
|
|
|
|
$server_id=''
|
2019-01-30 16:18:44 +01:00
|
|
|
) {
|
|
|
|
global $config;
|
|
|
|
|
|
|
|
if ($ttl == 2) {
|
2023-03-14 13:26:21 +01:00
|
|
|
$tokem_config = uniqid('slicebar');
|
2019-01-30 16:18:44 +01:00
|
|
|
$params = [
|
2023-03-14 13:26:21 +01:00
|
|
|
'tokem_config' => $tokem_config,
|
2019-12-12 14:01:11 +01:00
|
|
|
'period' => $period,
|
|
|
|
'width' => $width,
|
|
|
|
'height' => $height,
|
|
|
|
'legend' => $legend,
|
|
|
|
'colors' => $colors,
|
|
|
|
'fontpath' => $fontpath,
|
|
|
|
'round_corner' => $round_corner,
|
|
|
|
'homeurl' => $homeurl,
|
|
|
|
'watermark' => $watermark,
|
|
|
|
'adapt_key' => $adapt_key,
|
|
|
|
'stat_win' => $stat_win,
|
|
|
|
'id_agent' => $id_agent,
|
|
|
|
'full_legend_date' => $full_legend_date,
|
|
|
|
'not_interactive' => $not_interactive,
|
|
|
|
'ttl' => 1,
|
2020-03-26 12:29:38 +01:00
|
|
|
'sizeForTicks' => $sizeForTicks,
|
2019-12-12 14:01:11 +01:00
|
|
|
'show' => $show,
|
|
|
|
'return_img_base_64' => true,
|
2020-01-27 11:52:13 +01:00
|
|
|
'date_to' => $date_to,
|
2020-06-08 14:14:35 +02:00
|
|
|
'server_id' => $server_id,
|
2019-01-30 16:18:44 +01:00
|
|
|
];
|
2023-06-21 18:15:18 +02:00
|
|
|
|
2023-05-26 11:57:51 +02:00
|
|
|
update_check_config_token($tokem_config, json_encode($graph_data));
|
|
|
|
$_SESSION['slicebar'] = $tokem_config;
|
|
|
|
$_SESSION['slicebar_value'] = json_encode($graph_data);
|
2022-01-12 19:43:33 +01:00
|
|
|
$graph = '<img src="data:image/png;base64,';
|
2019-12-12 14:01:11 +01:00
|
|
|
$graph .= generator_chart_to_pdf('slicebar', $params);
|
|
|
|
$graph .= '" />';
|
|
|
|
|
|
|
|
return $graph;
|
2019-01-30 16:18:44 +01:00
|
|
|
}
|
|
|
|
|
2020-03-26 12:29:38 +01:00
|
|
|
// Get a unique identifier to graph.
|
2019-01-30 16:18:44 +01:00
|
|
|
$graph_id = uniqid('graph_');
|
|
|
|
|
|
|
|
// Set some containers to legend, graph, timestamp tooltip, etc.
|
2021-08-12 14:24:16 +02:00
|
|
|
if (is_numeric($height) === true) {
|
|
|
|
$height = ((int) $height + 15);
|
|
|
|
}
|
2019-01-30 16:18:44 +01:00
|
|
|
|
2020-10-28 12:50:15 +01:00
|
|
|
$style = 'width:'.$width.'%;';
|
2021-08-12 14:24:16 +02:00
|
|
|
|
2021-06-28 12:03:25 +02:00
|
|
|
// Fixed height size.
|
2021-08-12 14:24:16 +02:00
|
|
|
if (empty($height) === true) {
|
|
|
|
$style .= 'height: 100%;';
|
|
|
|
} else {
|
|
|
|
if (is_numeric($height) === true) {
|
|
|
|
$style .= 'height: '.$height.'px;';
|
|
|
|
} else {
|
|
|
|
$style .= 'height: '.$height.';';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-28 12:50:15 +01:00
|
|
|
$return = "<div id='".$graph_id."' class='noresizevc graph ".$adapt_key."' style='".$style."'></div>";
|
|
|
|
|
2021-03-11 15:40:23 +01:00
|
|
|
$return .= "<div id='value_".$graph_id."' class='flot_container'></div>";
|
2019-01-30 16:18:44 +01:00
|
|
|
|
2020-03-26 12:29:38 +01:00
|
|
|
// Set a weird separator to serialize and unserialize
|
|
|
|
// passing data from php to javascript.
|
2019-01-30 16:18:44 +01:00
|
|
|
$separator = ';;::;;';
|
|
|
|
$separator2 = ':,:,,,:,:';
|
|
|
|
|
2020-03-26 12:29:38 +01:00
|
|
|
// Transform data from our format to library format.
|
2019-01-30 16:18:44 +01:00
|
|
|
$vars = [];
|
|
|
|
|
|
|
|
$datacolor = [];
|
|
|
|
|
2021-06-25 12:56:03 +02:00
|
|
|
$fontsize = ((int) $config['font_size'] + 2);
|
2019-01-30 16:18:44 +01:00
|
|
|
$fontpath = $config['fontpath'];
|
|
|
|
|
2021-03-11 15:40:23 +01:00
|
|
|
$return .= '<div id="extra_'.$graph_id.'" class="slicebar-box-hover-styles invisible" style="font-size:'.$fontsize.'"></div>';
|
2019-01-30 16:18:44 +01:00
|
|
|
|
|
|
|
$maxticks = (int) 20;
|
2020-03-26 12:29:38 +01:00
|
|
|
if ($sizeForTicks === false) {
|
2020-06-08 14:14:35 +02:00
|
|
|
$maxticks = (int) 12;
|
2020-03-26 12:29:38 +01:00
|
|
|
} else if ($sizeForTicks < 300) {
|
|
|
|
$maxticks = (int) 3;
|
|
|
|
} else if ($sizeForTicks < 600) {
|
|
|
|
$maxticks = (int) 6;
|
|
|
|
} else if ($sizeForTicks < 900) {
|
|
|
|
$maxticks = (int) 9;
|
|
|
|
}
|
|
|
|
|
|
|
|
$intervaltick = ($period / $maxticks);
|
2019-01-30 16:18:44 +01:00
|
|
|
|
2020-03-26 12:29:38 +01:00
|
|
|
$maxticks_aux = $maxticks;
|
2019-01-30 16:18:44 +01:00
|
|
|
|
|
|
|
while (1) {
|
2020-03-26 12:29:38 +01:00
|
|
|
if ($maxticks_aux <= $maxticks) {
|
2019-01-30 16:18:44 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
$intervaltick *= 2;
|
|
|
|
|
2020-03-26 12:29:38 +01:00
|
|
|
$maxticks_aux /= 2;
|
2019-01-30 16:18:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$intervaltick = (int) $intervaltick;
|
|
|
|
|
2020-03-26 12:29:38 +01:00
|
|
|
$i = count($graph_data);
|
2019-01-30 16:18:44 +01:00
|
|
|
foreach ($graph_data as $label => $values) {
|
|
|
|
$i--;
|
|
|
|
|
|
|
|
foreach ($values as $key => $value) {
|
|
|
|
$jsvar = 'd_'.$graph_id.'_'.$i;
|
|
|
|
if ($key == 'data') {
|
|
|
|
$datacolor[$jsvar] = $colors[$value];
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$data[$jsvar][] = $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-11 09:04:13 +02:00
|
|
|
// Store serialized data to use it from javascript.
|
2019-01-30 16:18:44 +01:00
|
|
|
$datacolor = implode($separator, $datacolor);
|
|
|
|
if (is_array($legend)) {
|
|
|
|
$legend = io_safe_output(implode($separator, $legend));
|
|
|
|
}
|
2018-10-19 10:04:26 +02:00
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
if (!empty($full_legend_date) && count($full_legend_date) > 0) {
|
|
|
|
$full_legend_date = io_safe_output(implode($separator, $full_legend_date));
|
|
|
|
} else {
|
|
|
|
$full_legend_date = false;
|
|
|
|
}
|
|
|
|
|
2023-03-08 15:45:18 +01:00
|
|
|
if (!$date_to || $date_to === '1') {
|
2020-01-27 11:52:13 +01:00
|
|
|
$date_to = get_system_time();
|
|
|
|
}
|
|
|
|
|
|
|
|
$datelimit = (($date_to - $period));
|
2019-01-30 16:18:44 +01:00
|
|
|
|
|
|
|
$i = 0;
|
|
|
|
$values2 = [];
|
|
|
|
foreach ($data as $jsvar => $values) {
|
|
|
|
$values2[] = implode($separator, $values);
|
2021-11-19 10:51:46 +01:00
|
|
|
$i++;
|
2019-01-30 16:18:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$values = implode($separator2, $values2);
|
|
|
|
|
2019-10-11 09:04:13 +02:00
|
|
|
// Javascript code.
|
2019-01-30 16:18:44 +01:00
|
|
|
$return .= "<script type='text/javascript'>";
|
|
|
|
$return .= "//<![CDATA[\n";
|
2020-06-08 14:14:35 +02:00
|
|
|
$return .= "pandoraFlotSlicebar(
|
|
|
|
'$graph_id',
|
|
|
|
'$values',
|
|
|
|
'$datacolor',
|
|
|
|
'$legend',
|
|
|
|
$intervaltick,
|
|
|
|
'$fontpath',
|
|
|
|
$fontsize,
|
|
|
|
'$separator',
|
|
|
|
'$separator2',
|
|
|
|
$id_agent,
|
|
|
|
'$full_legend_date',
|
|
|
|
$not_interactive,
|
|
|
|
'$show',
|
|
|
|
$datelimit,
|
|
|
|
'$server_id'
|
|
|
|
)";
|
2019-01-30 16:18:44 +01:00
|
|
|
$return .= "\n//]]>";
|
|
|
|
$return .= '</script>';
|
|
|
|
|
|
|
|
return $return;
|
2012-03-01 17:41:02 +01:00
|
|
|
}
|