From 1945e71ae1b1f6208a8ffa8376c5358a4850225e Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Fri, 27 Jun 2025 15:24:18 +0530 Subject: [PATCH] chenged label position of the x axis in production order count --- app/Filament/Widgets/ProductionOrderChart.php | 37 ++++++++++++++----- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/app/Filament/Widgets/ProductionOrderChart.php b/app/Filament/Widgets/ProductionOrderChart.php index 90ecd8c..f3dd184 100644 --- a/app/Filament/Widgets/ProductionOrderChart.php +++ b/app/Filament/Widgets/ProductionOrderChart.php @@ -41,7 +41,7 @@ class ProductionOrderChart extends ChartWidget if ($lineType == 'FG Line') { $table = 'quality_validations'; - $dateColumn = 'created_at'; // adjust if your date column is named differently + $dateColumn = 'created_at'; $plantColumn = 'plant_id'; $lineColumn = 'line_id'; $orderColumn = 'production_order'; @@ -127,18 +127,40 @@ class ProductionOrderChart extends ChartWidget $data[0] ?? 0, // Sunday ]; } + // else + // { + // $allHours = array_fill(0, 24, 0); + // $data = array_replace($allHours, $query); + + // $shiftedKeys = array_merge(range(9, 23), range(0, 8)); + // $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, 8)); - $orderedData = array_map(fn($hour) => $data[$hour], $shiftedKeys); + // Shift counts - move each hour's count to the next hour + $shiftedData = []; + foreach ($data as $hour => $count) { + $nextHour = ($hour + 1) % 24; + $shiftedData[$nextHour] = $count; + } - $labels = array_map(fn ($hour) => date("g A", strtotime("$hour:00")), $shiftedKeys); + // Order from 9AM to 8AM next day + $shiftedKeys = array_merge(range(9, 23), range(0, 8)); + $orderedData = array_map(fn($hour) => $shiftedData[$hour] ?? 0, $shiftedKeys); + + // Create labels + $labels = array_map(function($hour) { + return date("g A", strtotime("$hour:00")); + }, $shiftedKeys); } - $orderedData = array_map(function ($value) { + $orderedData = array_map(function ($value) + { return ($value == 0 || is_null($value)) ? null : $value; }, $orderedData); @@ -183,12 +205,9 @@ class ProductionOrderChart extends ChartWidget return [ 'plugins' => [ 'datalabels' => [ - // 'anchor' => 'start', - // 'align' => 'start', - // 'offset' => 1, 'anchor' => 'start', 'align' => 'start', - 'offset' => 8, + 'offset' => -15, 'color' => '#000', 'font' => [ 'weight' => 'bold',