From ec9e380d3340bda227b8bbacae9c570397ef678d Mon Sep 17 00:00:00 2001 From: salam Date: Mon, 25 May 2026 13:05:11 +0200 Subject: [PATCH] wip tooltip with events --- .../Widgets/ChartMovingAverageEvent.php | 42 ++++++++++++------- app/Filament/Widgets/ChartPunctualEvent.php | 42 ++++++++++++------- app/Filament/Widgets/ChartPunctualPlayer.php | 5 +++ app/Filament/Widgets/Data/LoadEvents.php | 20 +++++++-- 4 files changed, 73 insertions(+), 36 deletions(-) diff --git a/app/Filament/Widgets/ChartMovingAverageEvent.php b/app/Filament/Widgets/ChartMovingAverageEvent.php index 9bcf61b0..94e301d1 100644 --- a/app/Filament/Widgets/ChartMovingAverageEvent.php +++ b/app/Filament/Widgets/ChartMovingAverageEvent.php @@ -5,6 +5,7 @@ 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; @@ -14,22 +15,6 @@ class ChartMovingAverageEvent extends ChartWidget protected ?string $pollingInterval = null; - protected ?array $options = [ - 'plugins' => [ - 'legend' => [ - 'display' => true, - ], - ], - 'interaction' => [ - 'intersect' => false, - ], - 'scales' => [ - 'y' => [ - 'beginAtZero' => true, - ], - ], - ]; - protected function getData(): array { $this->heading = 'Events '.HelperStatisticType::get($this->filters); @@ -49,4 +34,29 @@ class ChartMovingAverageEvent extends ChartWidget { 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); + } } diff --git a/app/Filament/Widgets/ChartPunctualEvent.php b/app/Filament/Widgets/ChartPunctualEvent.php index accd1ae5..95946689 100644 --- a/app/Filament/Widgets/ChartPunctualEvent.php +++ b/app/Filament/Widgets/ChartPunctualEvent.php @@ -4,6 +4,7 @@ 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 Filament\Widgets\Concerns\InteractsWithPageFilters; @@ -13,22 +14,6 @@ class ChartPunctualEvent extends ChartWidget protected ?string $pollingInterval = null; - protected ?array $options = [ - 'plugins' => [ - 'legend' => [ - 'display' => true, - ], - ], - 'interaction' => [ - 'intersect' => false, - ], - 'scales' => [ - 'y' => [ - 'beginAtZero' => true, - ], - ], - ]; - protected function getData(): array { $this->heading = 'Events '.HelperStatisticType::get($this->filters); @@ -46,4 +31,29 @@ class ChartPunctualEvent extends ChartWidget { 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); + } } diff --git a/app/Filament/Widgets/ChartPunctualPlayer.php b/app/Filament/Widgets/ChartPunctualPlayer.php index 34ee67e3..5d6d15c2 100644 --- a/app/Filament/Widgets/ChartPunctualPlayer.php +++ b/app/Filament/Widgets/ChartPunctualPlayer.php @@ -24,6 +24,11 @@ class ChartPunctualPlayer extends ChartWidget 'interaction' => [ 'intersect' => false, ], + 'callbacks' => [ + 'label' => 'function(context) { + return " Count: " + context.raw; + }', + ], ]; public function getDescription(): ?string diff --git a/app/Filament/Widgets/Data/LoadEvents.php b/app/Filament/Widgets/Data/LoadEvents.php index 1c5bf804..ecf7c7e3 100644 --- a/app/Filament/Widgets/Data/LoadEvents.php +++ b/app/Filament/Widgets/Data/LoadEvents.php @@ -76,7 +76,9 @@ class LoadEvents /** * STATTISTIC DATA */ - $res = StatistikoEvent::where('league_id', $league_id) + $res = StatistikoEvent::with('home') + ->with('away') + ->where('league_id', $league_id) ->where(function ($query) use ($team_id, $team_position) { switch ($team_position) { case 'home': @@ -104,9 +106,17 @@ class LoadEvents $dataset_home = []; $dataset_away = []; $labels = []; + $events = []; $labels_since = []; $results = ['w' => 0, 'd' => 0, 'l' => 0]; + /** + * IF WITH PLAYER + */ + // $res = StatisticFixtures::with('home')->with('away')->where('id', (int) $match_id)->first(); + // $event = $res->home->name.' vs '.$res->away->name; + // dd($event); + foreach ($res as $value) { $labels[] = $value['starttime']->format('d.M.y'); @@ -286,6 +296,7 @@ class LoadEvents } } if (isset($val_home) && isset($val_away)) { + $events[] = $value->home->name.' vs '.$value->away->name; $dataset_home[] = $val_home; $dataset_away[] = $val_away; } @@ -294,15 +305,16 @@ class LoadEvents $data = [ 'datasets' => [ [ - 'label' => 'Home', + 'label' => 'In Favor', + 'events' => $events, 'data' => $dataset_home, 'fill' => false, 'tension' => 0.5, 'borderColor' => '#36A2EB', ], [ - // 'label' => 'Away '.HelperStatisticType::get($filter), - 'label' => 'Away', + 'label' => 'Against', + 'events' => $events, 'data' => $dataset_away, 'fill' => false, 'tension' => 0.5,