#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) {
$filter = get_parameter('filter');
$output = '';
hd($filter, true);
$output .= '<h1>grafica</h1>';
$output = event_print_graph($filter);
echo $output;
return;
}

View File

@ -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 = '<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 .= '</div>';
echo $graph;
return $graph;
}

View File

@ -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 = [];

View File

@ -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.
@ -3503,6 +3502,10 @@ $(document).ready( function() {
click_button_remove_tag("without");
});
$("#button-events_form_search_bt").click(function(){
show_events_graph();
});
//Autorefresh in fullscreen
var pure = '<?php echo $pure; ?>';
@ -3737,8 +3740,6 @@ function show_events_graph(){
$('#events-graph')
.empty()
.html(data);
console.log('success');
console.log(data);
}
});
}