added proper width for production chart

This commit is contained in:
dhanabalan
2025-04-22 10:26:09 +05:30
parent 5533a441c0
commit c8487a91ea

View File

@@ -6,33 +6,30 @@ use Filament\Widgets\ChartWidget;
class ItemOverview extends ChartWidget class ItemOverview extends ChartWidget
{ {
protected static ?string $heading = 'Chart'; protected static ?string $heading = 'Hourly Production';
protected int|string|array $columnSpan = 'full'; // protected int|string|array $columnSpan = 'full';
protected int|string|array $columnSpan = 12;
protected $listeners = ['filtersUpdated' => '$refresh']; protected static ?string $maxHeight = '300px';
// public $plantId;
// public $lineId; protected $listeners = ['filtersUpdated' => '$refresh'];
protected function getData(): array protected function getData(): array
{ {
$activeFilter = $this->filter; $activeFilter = $this->filter;
// $selectPlant = session('select_plant');
// $selectLine = session('select_line');
// $selectedPlant = session('selected_plant');
// $selectedLine = session('selected_line');
$selectedPlant = session('selected_plant') ?? session('select_plant'); $selectedPlant = session('selected_plant') ?? session('select_plant');
$selectedLine = session('selected_line') ?? session('select_line'); $selectedLine = session('selected_line') ?? session('select_line');
if (!$selectedPlant || !$selectedLine) { if (!$selectedPlant || !$selectedLine)
return [ {
'datasets' => [], return [
'labels' => [], 'datasets' => [],
]; 'labels' => [],
} ];
}
if ($activeFilter === 'yesterday') { if ($activeFilter === 'yesterday') {
$startDate = now()->subDay()->startOfDay(); $startDate = now()->subDay()->startOfDay();
@@ -47,8 +44,6 @@ class ItemOverview extends ChartWidget
else if ($activeFilter === 'this_month') { else if ($activeFilter === 'this_month') {
$startDate = now()->startOfMonth(); $startDate = now()->startOfMonth();
$endDate = now()->endOfMonth(); $endDate = now()->endOfMonth();
// Group records into weeks
$groupBy = "FLOOR((EXTRACT(DAY FROM production_quantities.created_at) - 1) / 7) + 1"; $groupBy = "FLOOR((EXTRACT(DAY FROM production_quantities.created_at) - 1) / 7) + 1";
} }
else else
@@ -111,8 +106,9 @@ class ItemOverview extends ChartWidget
$data[6] ?? 0, // Saturday $data[6] ?? 0, // Saturday
$data[0] ?? 0, // Sunday (move to last) $data[0] ?? 0, // Sunday (move to last)
]; ];
}
} else { else
{
// Hourly data (same as before) // Hourly data (same as before)
$allHours = array_fill(0, 24, 0); $allHours = array_fill(0, 24, 0);
$data = array_replace($allHours, $query); $data = array_replace($allHours, $query);
@@ -150,17 +146,42 @@ class ItemOverview extends ChartWidget
return 'line'; return 'line';
} }
// protected function getContent(): string
// {
// return '<div style="height: 100%;">' . $this->chart->render() . '</div>';
// }
// protected function getContent(): string
// {
// return <<<HTML
// <div id="chart-container" style="height: 100vh; width: 100%;">
// {$this->chart->render()}
// </div>
// HTML;
// }
protected function getOptions(): array protected function getOptions(): array
{ {
return [ return [
'scales' => [ 'scales' => [
'y' => [ 'y' => [
'beginAtZero' => true, //Start Y-axis from 0 'beginAtZero' => true,
'ticks' => [ 'ticks' => [
'stepSize' => 0.5, 'stepSize' => 0.5,
], ],
], ],
], ],
// 'scales' => [
// 'y' => [
// 'beginAtZero' => true, //Start Y-axis from 0
// 'ticks' => [
// 'stepSize' => 0.5,
// ],
// ],
// ],
]; ];
} }
@@ -173,7 +194,4 @@ class ItemOverview extends ChartWidget
'this_month'=> 'This Month', 'this_month'=> 'This Month',
]; ];
} }
} }