diff --git a/app/Filament/Widgets/Data/LoadEvents.php b/app/Filament/Widgets/Data/LoadEvents.php index 9f3d0c21..71e08d32 100644 --- a/app/Filament/Widgets/Data/LoadEvents.php +++ b/app/Filament/Widgets/Data/LoadEvents.php @@ -361,6 +361,8 @@ class LoadEvents $label2 = 'Against'; } + self::shortenEnding($labels, $dataset_home, $dataset_away); + $data = [ 'datasets' => [ [ @@ -406,4 +408,34 @@ class LoadEvents return $data; } + + public static function shortenEnding(array &$labels, array &$homes, array &$aways) + { + if (! isset($homes['all'])) { + return; + } + + $count_home = 0; + $count_away = 0; + for ($i = \count($homes) - 1; $i > 0; $i--) { + if ($homes[$i] == null) { + $count_home++; + } else { + break; + } + } + for ($i = \count($aways) - 1; $i > 0; $i--) { + if ($aways[$i] == null) { + $count_away++; + } else { + break; + } + } + + $keeps = count($homes['all']) - min($count_home, $count_away) - 1; + + $homes = array_slice($homes, 0, $keeps); + $aways = array_slice($aways, 0, $keeps); + $labels = array_slice($labels, 0, $keeps); + } }