Laravel 13 + Filament 5 admin panel and REST API for a non-profit developer collective, backed by the Pireon OAuth identity server. The public site is a separate, server-rendered application consuming /api/public/v1. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
76 lines
1.9 KiB
PHP
76 lines
1.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Filament\Widgets;
|
|
|
|
use App\Models\Repository;
|
|
use Filament\Widgets\ChartWidget;
|
|
|
|
class LanguagesChart extends ChartWidget
|
|
{
|
|
protected static ?int $sort = 4;
|
|
|
|
public function getHeading(): string
|
|
{
|
|
return __('panel.widgets.languages_chart');
|
|
}
|
|
|
|
protected function getData(): array
|
|
{
|
|
$languages = Repository::query()
|
|
->publiclyVisible()
|
|
->whereNotNull('primary_language')
|
|
->groupBy('primary_language')
|
|
->selectRaw('primary_language, COUNT(*) as count')
|
|
->orderByDesc('count')
|
|
->limit(10)
|
|
->get();
|
|
|
|
return [
|
|
'datasets' => [
|
|
[
|
|
'label' => __('panel.widgets.languages.repositories'),
|
|
'data' => $languages->pluck('count')->toArray(),
|
|
'backgroundColor' => [
|
|
'#3b82f6',
|
|
'#10b981',
|
|
'#f59e0b',
|
|
'#ef4444',
|
|
'#8b5cf6',
|
|
'#ec4899',
|
|
'#14b8a6',
|
|
'#f97316',
|
|
'#6366f1',
|
|
'#06b6d4',
|
|
],
|
|
'borderColor' => '#fff',
|
|
'borderWidth' => 2,
|
|
],
|
|
],
|
|
'labels' => $languages->pluck('primary_language')->map(fn ($lang) => ucfirst($lang ?? 'Other'))->toArray(),
|
|
];
|
|
}
|
|
|
|
protected function getType(): string
|
|
{
|
|
return 'doughnut';
|
|
}
|
|
|
|
protected function getOptions(): array
|
|
{
|
|
return [
|
|
'plugins' => [
|
|
'legend' => [
|
|
'position' => 'bottom',
|
|
],
|
|
],
|
|
];
|
|
}
|
|
|
|
public static function canView(): bool
|
|
{
|
|
return auth()->user()?->can('projects.view_any') ?? false;
|
|
}
|
|
}
|