#12153 Create event list graph

This commit is contained in:
miguel angel rasteu 2023-10-04 16:28:40 +02:00
parent 874cb9c52a
commit 09cae778c5
4 changed files with 41 additions and 20 deletions

View File

@ -2764,9 +2764,7 @@ if ($draw_row_response_info === true) {
if ((bool) $draw_events_graph === true) { if ((bool) $draw_events_graph === true) {
$filter = get_parameter('filter'); $filter = get_parameter('filter');
$output = ''; $output = event_print_graph($filter);
hd($filter, true);
$output .= '<h1>grafica</h1>';
echo $output; echo $output;
return; return;
} }

View File

@ -6207,13 +6207,14 @@ function event_get_counter_extraId(array $event, ?array $filters)
function event_print_graph( function event_print_graph(
$filter, $filter,
$start_utimestamp, $graph_height=100,
$end_utimestamp,
$graph_width,
$graph_height,
) { ) {
global $config; 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; $num_intervals = ($num_data > 75) ? 75 : $num_data;
$period = ($end_utimestamp - $start_utimestamp); $period = ($end_utimestamp - $start_utimestamp);
@ -6256,12 +6257,26 @@ function event_print_graph(
$chart = []; $chart = [];
$labels = []; $labels = [];
$color = []; $color = [];
$currentutimestamp = $start_utimestamp; $count = 0;
for ($i = 0; $i < $num_intervals; $i++,$currentutimestamp += $interval_length) { $control_timestamp = $start_utimestamp;
$labels[] = date($chart_time_format, $currentutimestamp); $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[] = [ $chart[] = [
'y' => 1, 'y' => $count,
'x' => date($chart_time_format, $currentutimestamp), 'x' => date($chart_time_format, $utimestamp),
]; ];
$color[] = '#82b92f'; $color[] = '#82b92f';
} }
@ -6276,6 +6291,7 @@ function event_print_graph(
'waterMark' => $water_mark, 'waterMark' => $water_mark,
'legend' => ['display' => false], 'legend' => ['display' => false],
'colors' => $color, 'colors' => $color,
'border' => false,
'scales' => [ 'scales' => [
'x' => [ 'x' => [
'grid' => ['display' => false], 'grid' => ['display' => false],
@ -6287,9 +6303,9 @@ function event_print_graph(
'labels' => $labels, 'labels' => $labels,
]; ];
$graph = '<div style="width:100%; height: '.$graph_height.'px; margin-bottom: 10px;margin-top: 50px;">'; $graph = '<div style="width:100%; height: '.$graph_height.'px;">';
$graph .= vbar_graph($chart, $options); $graph .= vbar_graph($chart, $options);
$graph .= '</div>'; $graph .= '</div>';
echo $graph; return $graph;
} }

View File

@ -1187,6 +1187,12 @@ function get_build_setup_charts($type, $options, $data)
) { ) {
$colors = $options['colors']; $colors = $options['colors'];
$borders = $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 { } else {
// Colors. // Colors.
$defaultColor = []; $defaultColor = [];

View File

@ -2728,8 +2728,8 @@ try {
$graph_div = html_print_div( $graph_div = html_print_div(
[ [
'id' => 'events-graph', 'id' => 'events-graph',
'class' => 'mrgn_top_10px mrg_btt_60 invisible', 'class' => 'invisible',
'style' => 'text-align: left;'.$graph_background, 'style' => 'margin-bottom: 10px; text-align: left;'.$graph_background,
], ],
true true
); );
@ -2750,7 +2750,6 @@ try {
true true
); );
hd(get_parameter('filter'), true);
// Print datatable. // Print datatable.
@ -3502,6 +3501,10 @@ $(document).ready( function() {
$("#button-remove_without").click(function() { $("#button-remove_without").click(function() {
click_button_remove_tag("without"); click_button_remove_tag("without");
}); });
$("#button-events_form_search_bt").click(function(){
show_events_graph();
});
//Autorefresh in fullscreen //Autorefresh in fullscreen
@ -3737,8 +3740,6 @@ function show_events_graph(){
$('#events-graph') $('#events-graph')
.empty() .empty()
.html(data); .html(data);
console.log('success');
console.log(data);
} }
}); });
} }