Files
nuhodds_fi4/app/Filament/Widgets/ChartPlayer.php
T
2026-06-02 15:39:50 +02:00

81 lines
2.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 Livewire\Attributes\Reactive;
class ChartPlayer extends ChartWidget
{
#[Reactive]
public ?array $filters = [];
protected ?string $pollingInterval = null;
protected bool $isCollapsible = true;
protected static ?bool $isCollapsed = true;
protected ?string $heading = 'Player';
protected function getData(): array
{
$data = LoadPlayer::load($this->filters);
if ($data) {
$this->description = ucfirst(HelperStatisticType::get($this->filters));
if ($data['player_name']) {
$this->description .= ' '.$data['player_name'];
}
}
return $data;
}
protected function getType(): string
{
return 'line';
}
protected function getOptions(): RawJs
{
return RawJs::make(<<<'JS'
{
interaction: {
intersect: false,
},
plugins: {
tooltip: {
callbacks: {
afterLabel: (context) => {
let event = context.dataset.events[context.dataIndex] || '';
let date = context.dataset.dates[context.dataIndex] || '';
return event+' '+ date;
},
}
}
},
scales: {
x: {
title: {
display: true,
text: 'Days since today'
}
},
y: {
beginAtZero:true,
ticks: {
callback: function(value, index, ticks) {
return value % 1 === 0 ? value : '';
}
}
},
},
}
JS);
}
}