<?php
namespace App\Filament\Widgets;
use App\Models\punto;
use Flowframe\Trend\Trend;
use Flowframe\Trend\TrendValue;
use Filament\Widgets\ChartWidget;
class NewPuntoChart extends ChartWidget
{
protected static ?string $heading = 'Puntos Noroeste';
protected static ?int $sort = 2;
public $chartData;
protected $listeners = ["fromFilterChanged"];
public function fromFilterChanged($newFilter){
$this->chartData = $newFilter;
logger("Received");
logger($this->chartData);
}
protected function getFilters(): ?array
{
return [
'today' => 'Today',
'week' => 'Last week',
'month' => 'Last month',
'year' => 'This year',
];
}
protected function getData(): array
{
$trend = Trend::model(punto::class)
->dateColumn('date')->between(
start: now()->startOfYear(),
end: now()->endOfYear(),
)
->perMonth()
->count();
return [
'datasets' => [
[
'label' => 'Puntos',
'data' => $trend->map(fn(TrendValue $value) => $value->aggregate),
],
],
'labels' => $trend->map(fn(TrendValue $value) =>$value->date)
];
}
protected function getType(): string
{
return 'bar';
}
}