The most read, reads per language with a daily chart, and published content nobody opened, each compared with the period before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
53 lines
1.4 KiB
PHP
53 lines
1.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Filament\Charts;
|
|
|
|
use App\Support\ViewStats;
|
|
use Filament\Widgets\ChartWidget;
|
|
|
|
/**
|
|
* Reads per day, one line per language. Lives outside `Filament/Widgets` so
|
|
* the dashboard does not discover it: it belongs to the statistics page,
|
|
* which says which period to draw.
|
|
*/
|
|
class ViewsByLanguageChart extends ChartWidget
|
|
{
|
|
public int $days = 30;
|
|
|
|
protected int|string|array $columnSpan = 'full';
|
|
|
|
protected ?string $maxHeight = '280px';
|
|
|
|
public function getHeading(): string
|
|
{
|
|
return __('panel.statistics.daily');
|
|
}
|
|
|
|
protected function getType(): string
|
|
{
|
|
return 'line';
|
|
}
|
|
|
|
protected function getData(): array
|
|
{
|
|
$daily = (new ViewStats($this->days))->daily();
|
|
$colors = ['#f59e0b', '#3b82f6', '#10b981', '#ef4444', '#8b5cf6'];
|
|
|
|
return [
|
|
'labels' => $daily['labels'],
|
|
'datasets' => collect($daily['series'])
|
|
->values()
|
|
->map(fn (array $data, int $i) => [
|
|
'label' => config('locales.supported.'.array_keys($daily['series'])[$i].'.native'),
|
|
'data' => $data,
|
|
'borderColor' => $colors[$i % count($colors)],
|
|
'backgroundColor' => $colors[$i % count($colors)],
|
|
'tension' => 0.3,
|
|
])
|
|
->all(),
|
|
];
|
|
}
|
|
}
|