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

78 lines
2.1 KiB
PHP

<?php
namespace App\Filament\Widgets;
use App\Filament\Widgets\Data\HelperStatisticType;
use App\Filament\Widgets\Data\LoadEvents;
use Filament\Support\RawJs;
use Filament\Widgets\ChartWidget;
use Livewire\Attributes\Reactive;
class ChartEvent extends ChartWidget
{
#[Reactive]
public ?array $filters = [];
protected ?string $heading = 'Events';
protected ?string $pollingInterval = null;
protected bool $isCollapsible = true;
protected $f;
protected function getData(): array
{
$data = LoadEvents::load($this->filters);
$this->description = ucfirst(HelperStatisticType::get($this->filters));
if (isset($data['description'])) {
$this->description .= $data['description'];
}
return $data;
}
protected function getType(): string
{
return 'line';
}
protected function getOptions(): RawJs
{
return RawJs::make(<<<'JS'
{
interaction: {
intersect: false,
},
plugins: {
tooltip: {
callbacks: {
label: (context) => {
return [' '+context.parsed.y, ' '+context.dataset.playing_date[context.dataIndex], ' '+context.dataset.events[context.dataIndex], ' '+context.dataset.results_per_event[context.dataIndex]];
},
}
}
},
scales: {
x: {
title: {
display: true,
text: 'Days since today'
}
},
y: {
beginAtZero:true,
ticks: {
callback: function(value, index, ticks) {
return value % 1 === 0 ? value : '';
}
}
},
},
}
JS);
}
}