You've already forked Epicnabbo-Catalogus-Updated-Daily
57 lines
1.4 KiB
PHP
57 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Widgets;
|
|
|
|
use App\Models\Article;
|
|
use Filament\Widgets\ChartWidget;
|
|
use Flowframe\Trend\Trend;
|
|
use Flowframe\Trend\TrendValue;
|
|
use Illuminate\Contracts\Support\Htmlable;
|
|
|
|
class ArticlesAggregateChart extends ChartWidget
|
|
{
|
|
protected static ?int $sort = 2;
|
|
|
|
protected ?string $maxHeight = '300px';
|
|
|
|
protected string $color = 'primary';
|
|
|
|
public function getHeading(): string|Htmlable|null
|
|
{
|
|
return __('filament::resources.stats.articles_chart.title');
|
|
}
|
|
|
|
public function getDescription(): string|Htmlable|null
|
|
{
|
|
return __('filament::resources.stats.articles_chart.description');
|
|
}
|
|
|
|
protected function getData(): array
|
|
{
|
|
$data = Trend::model(Article::class)
|
|
->between(
|
|
start: now()->startOfMonth(),
|
|
end: now()->endOfMonth(),
|
|
)
|
|
->perDay()
|
|
->count();
|
|
|
|
$label = __('filament::resources.stats.articles_chart.label');
|
|
|
|
return [
|
|
'datasets' => [
|
|
[
|
|
'label' => $label,
|
|
'data' => $data->map(fn (TrendValue $value) => $value->aggregate),
|
|
],
|
|
],
|
|
'labels' => $data->map(fn (TrendValue $value) => $value->date),
|
|
];
|
|
}
|
|
|
|
protected function getType(): string
|
|
{
|
|
return 'line';
|
|
}
|
|
}
|