Initial commit
This commit is contained in:
63
app/Filament/Widgets/ResumesChart.php
Normal file
63
app/Filament/Widgets/ResumesChart.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?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';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user