64 lines
1.5 KiB
PHP
64 lines
1.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Filament\Widgets;
|
|
|
|
use App\Models\Resume;
|
|
use Filament\Widgets\ChartWidget;
|
|
use Flowframe\Trend\Trend;
|
|
use Flowframe\Trend\TrendValue;
|
|
|
|
final class ResumesChart extends ChartWidget
|
|
{
|
|
protected static ?string $heading = 'Created resumes per month';
|
|
|
|
/** @return array<string, mixed> */
|
|
protected function getData(): array
|
|
{
|
|
$data = Trend::model(Resume::class)
|
|
->between(
|
|
start: now()->startOfYear(),
|
|
end: now()->endOfYear()
|
|
)
|
|
->perMonth()
|
|
->count();
|
|
|
|
return [
|
|
'datasets' => [
|
|
[
|
|
'label' => 'New resumes',
|
|
'data' => $data->map(fn (TrendValue $value) => $value->aggregate),
|
|
],
|
|
],
|
|
'labels' => $data->map(fn (TrendValue $value) => $value->date),
|
|
];
|
|
}
|
|
|
|
/** @return array<string, mixed> */
|
|
protected function getOptions(): array
|
|
{
|
|
return [
|
|
'plugins' => [
|
|
'legend' => [
|
|
'display' => false,
|
|
],
|
|
],
|
|
'scales' => [
|
|
'y' => [
|
|
'ticks' => [
|
|
'stepSize' => 1, // Ensure consistent steps
|
|
'precision' => 0, // No decimal places
|
|
],
|
|
'beginAtZero' => true,
|
|
],
|
|
],
|
|
];
|
|
}
|
|
|
|
protected function getType(): string
|
|
{
|
|
return 'line';
|
|
}
|
|
}
|