Files
nuhodds_fi4/app/Filament/Widgets/ChartPlayer.php
T
2026-06-03 09:57:29 +02:00

94 lines
3.2 KiB
PHP

<?php
namespace App\Filament\Widgets;
use App\Filament\Widgets\Data\HelperStatisticType;
use App\Filament\Widgets\Data\LoadPlayer;
use Filament\Support\RawJs;
use Filament\Widgets\ChartWidget;
use Illuminate\Support\HtmlString;
use Livewire\Attributes\Reactive;
class ChartPlayer extends ChartWidget
{
#[Reactive]
public ?array $filters = [];
public ?string $player = 'Player';
public ?string $type = '';
protected ?string $pollingInterval = null;
// protected bool $isCollapsible = true;
public function getHeading(): HtmlString
{
return new HtmlString('
<span class="flex justify-between">
<span class="text-primary-600 font-bold flex flex-row gap-2">
<svg viewBox="0 0 15 15" version="1.1" id="soccer" class="h-5 w-5"
xmlns="http://www.w3.org/2000/svg" fill="currentColor">
<g id="SVGRepo_bgCarrier" stroke-width="0"></g>
<g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g>
<g id="SVGRepo_iconCarrier">
<path d="M11,1.5C11,2.3284,10.3284,3,9.5,3S8,2.3284,8,1.5S8.6716,0,9.5,0S11,0.6716,11,1.5z M11,11c-0.5523,0-1,0.4477-1,1
s0.4477,1,1,1s1-0.4477,1-1S11.5523,11,11,11z M12.84,6.09l-1.91-1.91l0,0C10.8399,4.0675,10.7041,4.0014,10.56,4H3.5
C3.2239,4,3,4.2239,3,4.5S3.2239,5,3.5,5h2.7L3,11.3l0,0c-0.0138,0.066-0.0138,0.134,0,0.2c-0.058,0.2761,0.1189,0.547,0.395,0.605
C3.6711,12.163,3.942,11.9861,4,11.71l0,0L5,10h2l-1.93,4.24l0,0C5.0228,14.3184,4.9986,14.4085,5,14.5
c-0.0552,0.2761,0.1239,0.5448,0.4,0.6c0.2761,0.0552,0.5448-0.1239,0.6-0.4l0,0l4.7-9.38l1.44,1.48
c0.211,0.1782,0.5264,0.1516,0.7046-0.0593C13.0037,6.5523,13.0018,6.2761,12.84,6.09z"></path>
</g>
</svg>
'.$this->player.'
</span>
<span>'.$this->type.'</span>
</span>
');
}
protected function getData(): array
{
$data = LoadPlayer::load($this->filters);
if ($data) {
$this->player = $data['player_name'] ?? '';
$this->type = ucfirst(HelperStatisticType::get($this->filters));
}
return $data;
}
protected function getType(): string
{
return 'line';
}
protected function getOptions(): RawJs
{
return RawJs::make(<<<'JS'
{
interaction: {
intersect: false,
},
scales: {
x: {
title: {
display: true,
text: 'Days since today'
}
},
y: {
beginAtZero:true,
ticks: {
callback: function(value, index, ticks) {
return value % 1 === 0 ? value : '';
}
}
},
},
}
JS);
}
}