78 lines
2.0 KiB
PHP
78 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Widgets;
|
|
|
|
use App\Filament\Widgets\Data\HelperMoveingAverage;
|
|
use App\Filament\Widgets\Data\LoadPlayer;
|
|
use Filament\Support\RawJs;
|
|
use Filament\Widgets\ChartWidget;
|
|
use Livewire\Attributes\Reactive;
|
|
|
|
class ChartPlayerMoAv extends ChartWidget
|
|
{
|
|
#[Reactive]
|
|
public ?array $filters = [];
|
|
|
|
protected ?string $pollingInterval = null;
|
|
|
|
protected bool $isCollapsible = true;
|
|
|
|
protected ?string $heading = 'Player';
|
|
|
|
protected function getData(): array
|
|
{
|
|
$data = LoadPlayer::load($this->filters);
|
|
|
|
if ($data) {
|
|
$this->description = 'Moving Average '.$data['player_name'];
|
|
|
|
HelperMoveingAverage::get($data);
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|