From 09cae778c52172af465b1a9cc5c775bf29a2a8a1 Mon Sep 17 00:00:00 2001 From: miguel angel rasteu Date: Wed, 4 Oct 2023 16:28:40 +0200 Subject: [PATCH] #12153 Create event list graph --- pandora_console/include/ajax/events.php | 4 +- pandora_console/include/functions_events.php | 40 ++++++++++++++------ pandora_console/include/graphs/fgraph.php | 6 +++ pandora_console/operation/events/events.php | 11 +++--- 4 files changed, 41 insertions(+), 20 deletions(-) diff --git a/pandora_console/include/ajax/events.php b/pandora_console/include/ajax/events.php index 1e9d744739..fbab653bf7 100644 --- a/pandora_console/include/ajax/events.php +++ b/pandora_console/include/ajax/events.php @@ -2764,9 +2764,7 @@ if ($draw_row_response_info === true) { if ((bool) $draw_events_graph === true) { $filter = get_parameter('filter'); - $output = ''; - hd($filter, true); - $output .= '

grafica

'; + $output = event_print_graph($filter); echo $output; return; } \ No newline at end of file diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index edefd1c187..76439fd8c4 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -6207,13 +6207,14 @@ function event_get_counter_extraId(array $event, ?array $filters) function event_print_graph( $filter, - $start_utimestamp, - $end_utimestamp, - $graph_width, - $graph_height, + $graph_height=100, ) { global $config; - $num_data = 10; + $events = events_get_all(['te.id_evento', 'te.timestamp', 'te.utimestamp'], $filter, null, null, 'te.utimestamp', true); + $start_utimestamp = $events[0]['utimestamp']; + $end_utimestamp = $events[array_key_last($events)]['utimestamp']; + $num_data = count($events); + $num_intervals = ($num_data > 75) ? 75 : $num_data; $period = ($end_utimestamp - $start_utimestamp); @@ -6256,12 +6257,26 @@ function event_print_graph( $chart = []; $labels = []; $color = []; - $currentutimestamp = $start_utimestamp; - for ($i = 0; $i < $num_intervals; $i++,$currentutimestamp += $interval_length) { - $labels[] = date($chart_time_format, $currentutimestamp); + $count = 0; + $control_timestamp = $start_utimestamp; + $data_events = []; + foreach ($events as $event) { + if ($event['utimestamp'] === $control_timestamp) { + $count++; + } else { + $control_timestamp = $event['utimestamp']; + $count = 1; + } + + $data_events[$control_timestamp] = $count; + } + + $data_events = array_reverse($data_events, true); + foreach ($data_events as $utimestamp => $count) { + $labels[] = date($chart_time_format, $utimestamp); $chart[] = [ - 'y' => 1, - 'x' => date($chart_time_format, $currentutimestamp), + 'y' => $count, + 'x' => date($chart_time_format, $utimestamp), ]; $color[] = '#82b92f'; } @@ -6276,6 +6291,7 @@ function event_print_graph( 'waterMark' => $water_mark, 'legend' => ['display' => false], 'colors' => $color, + 'border' => false, 'scales' => [ 'x' => [ 'grid' => ['display' => false], @@ -6287,9 +6303,9 @@ function event_print_graph( 'labels' => $labels, ]; - $graph = '
'; + $graph = '
'; $graph .= vbar_graph($chart, $options); $graph .= '
'; - echo $graph; + return $graph; } diff --git a/pandora_console/include/graphs/fgraph.php b/pandora_console/include/graphs/fgraph.php index 494ec9c010..d7f3e3ed7b 100644 --- a/pandora_console/include/graphs/fgraph.php +++ b/pandora_console/include/graphs/fgraph.php @@ -1187,6 +1187,12 @@ function get_build_setup_charts($type, $options, $data) ) { $colors = $options['colors']; $borders = $options['colors']; + if (isset($options['border']) === true && (bool) $options['border'] === false) { + $borders = []; + foreach ($colors as $color) { + $borders[] = 'rgba(0, 0, 0, 0)'; + } + } } else { // Colors. $defaultColor = []; diff --git a/pandora_console/operation/events/events.php b/pandora_console/operation/events/events.php index 076d48e60a..febdb33156 100644 --- a/pandora_console/operation/events/events.php +++ b/pandora_console/operation/events/events.php @@ -2728,8 +2728,8 @@ try { $graph_div = html_print_div( [ 'id' => 'events-graph', - 'class' => 'mrgn_top_10px mrg_btt_60 invisible', - 'style' => 'text-align: left;'.$graph_background, + 'class' => 'invisible', + 'style' => 'margin-bottom: 10px; text-align: left;'.$graph_background, ], true ); @@ -2750,7 +2750,6 @@ try { true ); - hd(get_parameter('filter'), true); // Print datatable. @@ -3502,6 +3501,10 @@ $(document).ready( function() { $("#button-remove_without").click(function() { click_button_remove_tag("without"); }); + + $("#button-events_form_search_bt").click(function(){ + show_events_graph(); + }); //Autorefresh in fullscreen @@ -3737,8 +3740,6 @@ function show_events_graph(){ $('#events-graph') .empty() .html(data); - console.log('success'); - console.log(data); } }); }