71 lines
1.8 KiB
PHP
71 lines
1.8 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;
|
|
|
|
public ?string $header;
|
|
|
|
protected ?array $options = [
|
|
'plugins' => [
|
|
'legend' => [
|
|
'display' => false,
|
|
],
|
|
'tooltip' => [
|
|
'callbacks' => [
|
|
'label' => RawJs::make(<<<'JS'
|
|
function(context) {
|
|
let label = context.dataset.label || '';
|
|
|
|
if (label) {
|
|
label += ': ';
|
|
}
|
|
if (context.parsed.y !== null) {
|
|
label += new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format(context.parsed.y);
|
|
}
|
|
return label;
|
|
}
|
|
JS),
|
|
],
|
|
],
|
|
],
|
|
'interaction' => [
|
|
'intersect' => false,
|
|
],
|
|
];
|
|
|
|
public function getDescription(): ?string
|
|
{
|
|
return 'Events Moving Average';
|
|
}
|
|
|
|
protected function getData(): array
|
|
{
|
|
$this->heading = HelperStatisticType::get($this->filters);
|
|
|
|
$data = LoadEvents::load($this->filters);
|
|
|
|
if ($data) {
|
|
HelperMoveingAverage::get($data);
|
|
}
|
|
|
|
return $data;
|
|
}
|
|
|
|
protected function getType(): string
|
|
{
|
|
return 'line';
|
|
}
|
|
}
|