From b798cbcbfd4948e0430ef4aa86dcc2693102cbb9 Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Fri, 27 Jun 2025 15:45:37 +0530 Subject: [PATCH] adjusted label position of the x axis bar in hourly production chart --- app/Filament/Widgets/ItemOverview.php | 33 +++++++++++++++++++++------ 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/app/Filament/Widgets/ItemOverview.php b/app/Filament/Widgets/ItemOverview.php index 9d22fa2..34a3398 100644 --- a/app/Filament/Widgets/ItemOverview.php +++ b/app/Filament/Widgets/ItemOverview.php @@ -105,21 +105,40 @@ class ItemOverview extends ChartWidget $data[0] ?? 0, ]; } + // else + // { + // $allHours = array_fill(0, 24, 0); + // $data = array_replace($allHours, $query); + + // $shiftedKeys = array_merge(range(8, 23), range(0, 7)); + // $orderedData = array_map(fn($hour) => $data[$hour], $shiftedKeys); + + // $labels = array_map(fn ($hour) => date("g A", strtotime("$hour:00")), $shiftedKeys); + // } + else { $allHours = array_fill(0, 24, 0); $data = array_replace($allHours, $query); - $shiftedKeys = array_merge(range(8, 23), range(0, 7)); - $orderedData = array_map(fn($hour) => $data[$hour], $shiftedKeys); + $shiftedData = []; + foreach ($data as $hour => $count) { + $nextHour = ($hour + 1) % 24; + $shiftedData[$nextHour] = $count; + } + $shiftedKeys = array_merge(range(9, 23), range(0, 8)); + $orderedData = array_map(fn($hour) => $shiftedData[$hour] ?? 0, $shiftedKeys); - $labels = array_map(fn ($hour) => date("g A", strtotime("$hour:00")), $shiftedKeys); + $labels = array_map(function($hour) { + $prevHour = ($hour - 1 + 24) % 24; + return sprintf("%s", + date("g A", strtotime("$hour:00")), + date("g", strtotime("$prevHour:00")), + date("g A", strtotime("$hour:00")) + ); + }, $shiftedKeys); } - // $orderedData = array_map(function ($value) { - // return ($value == 0 || is_null($value)) ? null : $value; - // }, $orderedData); - return [ 'datasets' => [ [