feat: add BrentPriceResource with 30-day line chart widget
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
40
app/Filament/Widgets/BrentPriceChartWidget.php
Normal file
40
app/Filament/Widgets/BrentPriceChartWidget.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets;
|
||||
|
||||
use App\Models\BrentPrice;
|
||||
use Filament\Widgets\ChartWidget;
|
||||
|
||||
class BrentPriceChartWidget extends ChartWidget
|
||||
{
|
||||
protected ?string $heading = 'Brent Crude — Last 30 Days (USD/barrel)';
|
||||
|
||||
protected ?string $pollingInterval = null;
|
||||
|
||||
protected function getData(): array
|
||||
{
|
||||
$prices = BrentPrice::orderBy('date')
|
||||
->where('date', '>=', now()->subDays(30)->toDateString())
|
||||
->get();
|
||||
|
||||
return [
|
||||
'datasets' => [
|
||||
[
|
||||
'label' => 'USD/barrel',
|
||||
'data' => $prices->pluck('price_usd')->map(fn ($p) => (float) $p)->toArray(),
|
||||
'borderColor' => '#f59e0b',
|
||||
'fill' => false,
|
||||
'tension' => 0.3,
|
||||
],
|
||||
],
|
||||
'labels' => $prices->pluck('date')
|
||||
->map(fn ($d) => $d->format('d M'))
|
||||
->toArray(),
|
||||
];
|
||||
}
|
||||
|
||||
protected function getType(): string
|
||||
{
|
||||
return 'line';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user