1
0
forked from poc/pds

adjusted label position of the x axis bar in hourly production chart

This commit is contained in:
dhanabalan
2025-06-27 15:45:37 +05:30
parent 630b921a37
commit b798cbcbfd

View File

@@ -105,20 +105,39 @@ 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);
$labels = array_map(fn ($hour) => date("g A", strtotime("$hour:00")), $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);
// $orderedData = array_map(function ($value) {
// return ($value == 0 || is_null($value)) ? null : $value;
// }, $orderedData);
$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);
}
return [
'datasets' => [