statistio popup comparatore wip
This commit is contained in:
1 parent
e6203c366e
commit
e7973f6302
9 files changed
+1172
-4
No files matched your search
@@ -0,0 +1,140 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire;
|
||||
|
||||
use App\Models\Event;
|
||||
use App\Models\StatistikoEvent;
|
||||
use Filament\Widgets\ChartWidget;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
use Illuminate\Support\HtmlString;
|
||||
|
||||
class StatisticEventChart extends ChartWidget
|
||||
{
|
||||
public Event $record;
|
||||
|
||||
public ?string $filter = 'gls';
|
||||
|
||||
protected bool $hasDeferredFilters = true;
|
||||
|
||||
protected ?string $pollingInterval = null;
|
||||
|
||||
public function getHeading(): string|Htmlable|null
|
||||
{
|
||||
$str = '<div class="flex flex-row gap-4 justify-center bg-gray-300 font-thin">';
|
||||
$str .= '<div>'.$this->record->country->name.' '.$this->record->group->name.'</div>';
|
||||
if ($this->record->home->betsapi_image_id) {
|
||||
$str .= ' <img src="https://assets.b365api.com/images/team/m/'.$this->record->home->betsapi_image_id.'.png" class="h-6">';
|
||||
}
|
||||
$str .= '<div>'.$this->record->home->name.'</div>';
|
||||
$str .= '<div>vs</div>';
|
||||
$str .= '<div>'.$this->record->away->name.'</div>';
|
||||
if ($this->record->away->betsapi_image_id) {
|
||||
$str .= ' <img src="https://assets.b365api.com/images/team/m/'.$this->record->away->betsapi_image_id.'.png" class="h-6">';
|
||||
}
|
||||
$str .= '</div>';
|
||||
|
||||
return new HtmlString($str);
|
||||
}
|
||||
|
||||
protected function getFilters(): ?array
|
||||
{
|
||||
return [
|
||||
'gls' => 'Goals',
|
||||
'crn' => 'Corner',
|
||||
'fls' => 'Committed Fouls',
|
||||
'ofs' => 'Offsides',
|
||||
'crd' => 'Cards',
|
||||
'snt' => 'Shots on target',
|
||||
'tsh' => 'TotalShots',
|
||||
];
|
||||
}
|
||||
|
||||
protected function getData(): array
|
||||
{
|
||||
$activeFilter = $this->filter;
|
||||
|
||||
$res = StatistikoEvent::where('league_id', $this->record['competition_group_id'])
|
||||
->where('home_id', $this->record['home_id'])
|
||||
->where('away_id', $this->record['away_id'])
|
||||
->get();
|
||||
|
||||
switch ($activeFilter) {
|
||||
case 'crn':
|
||||
$h = 'crn_h';
|
||||
$a = 'crn_a';
|
||||
break;
|
||||
case 'fls':
|
||||
$h = 'fls_h';
|
||||
$a = 'fls_a';
|
||||
break;
|
||||
case 'ofs':
|
||||
$h = 'ofs_h';
|
||||
$a = 'ofs_a';
|
||||
break;
|
||||
case 'crd':
|
||||
$h = 'crd_h';
|
||||
$a = 'crd_a';
|
||||
break;
|
||||
case 'snt':
|
||||
$h = 'snt_h';
|
||||
$a = 'snt_a';
|
||||
break;
|
||||
case 'tsh':
|
||||
$h = 'tsh_h';
|
||||
$a = 'tsh_a';
|
||||
break;
|
||||
|
||||
default:
|
||||
$h = 'gls_h';
|
||||
$a = 'gls_a';
|
||||
break;
|
||||
}
|
||||
|
||||
$starttimes = [];
|
||||
$data_home = [];
|
||||
$data_away = [];
|
||||
foreach ($res as $event) {
|
||||
$data_home[] = $event[$h];
|
||||
$data_away[] = $event[$a];
|
||||
$starttimes[] = $event['starttime']->format('d.m.Y');
|
||||
}
|
||||
|
||||
return [
|
||||
'datasets' => [
|
||||
[
|
||||
'label' => $this->record->home->name,
|
||||
'data' => $data_home,
|
||||
'backgroundColor' => '#155dfc',
|
||||
'borderColor' => '#2b7fff',
|
||||
],
|
||||
[
|
||||
'label' => $this->record->away->name,
|
||||
'data' => $data_away,
|
||||
'backgroundColor' => '#00a63e',
|
||||
'borderColor' => '#00c950',
|
||||
],
|
||||
],
|
||||
'labels' => $starttimes,
|
||||
'scales' => $this->getOptions(),
|
||||
];
|
||||
}
|
||||
|
||||
protected function getOptions(): array
|
||||
{
|
||||
return [
|
||||
'scales' => [
|
||||
'y' => [
|
||||
'ticks' => [
|
||||
'precision' => 0, // Forces integers
|
||||
'beginAtZero' => true,
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
protected function getType(): string
|
||||
{
|
||||
return 'line';
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user