Skip to content

Commit

Permalink
Fix printer counters history chart (#16386)
Browse files Browse the repository at this point in the history
  • Loading branch information
cedric-anne authored Jan 22, 2024
1 parent 3d7a240 commit 6449a92
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/PrinterLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,22 @@ public function showMetrics(Printer $printer)
$labels[] = $fmt->format($date);
unset($metrics['id'], $metrics['date'], $metrics['printers_id']);

// Keep values if at least 1 label is greater than 0
$valuesum = array_sum($metrics);
foreach ($metrics as $key => $value) {
$label = $this->getLabelFor($key);
if ($label && $value > 0) {
if ($label && $valuesum > 0) {
$series[$key]['name'] = $label;
$series[$key]['data'][] = $value;
}
}
}

// If the metric has a value of 0 for all dates, remove it from the data set
foreach ($series as $key => $value) {
if (array_sum($value['data']) == 0) {
unset($series[$key]);
}
}
$bar_conf = [
'data' => [
'labels' => $labels,
Expand Down

0 comments on commit 6449a92

Please sign in to comment.