Files
nuhodds_fi4/app/Filament/Widgets/ChartMovingAverageEvent.php
T
2026-05-25 13:05:11 +02:00

63 lines
1.5 KiB
PHP

<?php
namespace App\Filament\Widgets;
use App\Filament\Widgets\Data\HelperMoveingAverage;
use App\Filament\Widgets\Data\HelperStatisticType;
use App\Filament\Widgets\Data\LoadEvents;
use Filament\Support\RawJs;
use Filament\Widgets\ChartWidget;
use Filament\Widgets\Concerns\InteractsWithPageFilters;
class ChartMovingAverageEvent extends ChartWidget
{
use InteractsWithPageFilters;
protected ?string $pollingInterval = null;
protected function getData(): array
{
$this->heading = 'Events '.HelperStatisticType::get($this->filters);
$data = LoadEvents::load($this->filters);
if ($data) {
HelperMoveingAverage::get($data);
$this->description = 'Moving Average '.$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.events[context.dataIndex]];
},
}
},
},
scales: {
y: {
beginAtZero:true,
},
},
}
JS);
}
}