diff --git a/app/Filament/Widgets/StatsMedianAverage.php b/app/Filament/Widgets/StatsMedianAverage.php index 53a7bb92..4e9d304b 100644 --- a/app/Filament/Widgets/StatsMedianAverage.php +++ b/app/Filament/Widgets/StatsMedianAverage.php @@ -104,19 +104,13 @@ class StatsMedianAverage extends StatsOverviewWidget else $value_away = 0; - // dd($value_home); - if ($data['similar_past_matches'] != 'none') - $fixtotwo = true; - else - $fixtotwo = false; - return [ - Stat::make('Number of events', new HtmlString('
' . $total_home . '
'))->extraAttributes(['x-init' => "animate('number-of-events', $total_home)"]), - Stat::make('Average ' . $statistic_type, self::template('avhome', 'avaway', $home_team, $away_team))->extraAttributes(['x-init' => "animate('avhome', $value_home); animate('avaway', $value_away)"]), - Stat::make('Median ' . $statistic_type, self::template('mehome', 'meaway', $home_team, $away_team))->extraAttributes(['x-init' => "animate('mehome', $median_home); animate('meaway', $median_away)"]), - Stat::make($data['similar_past_matches'] != 'none' ? '1' : 'Win: ' . $data['results']['w'], new HtmlString('
' . $win . '
'))->extraAttributes(['x-init' => "animate('number-of-win', $win, 500, $fixtotwo)"]), - Stat::make($data['similar_past_matches'] != 'none' ? 'X' : 'Draw: ' . $data['results']['d'], new HtmlString('
' . $draw . '
'))->extraAttributes(['x-init' => "animate('number-of-draw', $draw, 500, $fixtotwo)"]), - Stat::make($data['similar_past_matches'] != 'none' ? '2' : 'Lost: ' . $data['results']['l'], new HtmlString('
' . $lost . '
'))->extraAttributes(['x-init' => "animate('number-of-lost', $lost, 500, $fixtotwo)"]), + Stat::make('Number of events', new HtmlString('
' . $total_home . '
'))->extraAttributes(['x-init' => "animate('number-of-events', $total_home, 0)"]), + Stat::make('Average ' . $statistic_type, self::template('avhome', 'avaway', $home_team, $away_team))->extraAttributes(['x-init' => "animate('avhome', $value_home); animate('avaway', $value_away, 0)"]), + Stat::make('Median ' . $statistic_type, self::template('mehome', 'meaway', $home_team, $away_team))->extraAttributes(['x-init' => "animate('mehome', $median_home); animate('meaway', $median_away, 0)"]), + Stat::make($data['similar_past_matches'] != 'none' ? '1' : 'Win: ' . $data['results']['w'], new HtmlString('
' . $win . '
'))->extraAttributes(['x-init' => "animate('number-of-win', $win, 1)"]), + Stat::make($data['similar_past_matches'] != 'none' ? 'X' : 'Draw: ' . $data['results']['d'], new HtmlString('
' . $draw . '
'))->extraAttributes(['x-init' => "animate('number-of-draw', $draw, 1)"]), + Stat::make($data['similar_past_matches'] != 'none' ? '2' : 'Lost: ' . $data['results']['l'], new HtmlString('
' . $lost . '
'))->extraAttributes(['x-init' => "animate('number-of-lost', $lost, 1)"]), ]; } diff --git a/public/js/app/number-animator.js b/public/js/app/number-animator.js index 6b0d57dc..401e315c 100644 --- a/public/js/app/number-animator.js +++ b/public/js/app/number-animator.js @@ -1,4 +1,4 @@ -function animate(element, end, duration = 500, fixtotwo) { +function animate(element, end, fixtotwo) { console.log(element, end); var element = document.getElementById(element); @@ -10,7 +10,7 @@ function animate(element, end, duration = 500, fixtotwo) { const updateCount = (currentTime) => { const elapsedTime = currentTime - startTime; - let progress = elapsedTime / duration; + let progress = elapsedTime / 500; // Clamp progress to ensure it doesn't overshoot if (progress > 1) progress = 1; @@ -21,15 +21,11 @@ function animate(element, end, duration = 500, fixtotwo) { // Calculate current value and round to integer const currentCount = Math.round(end * easedProgress * 100) / 100; - element.innerHTML = currentCount.toFixed(2); - - // if (fixtotwo) { - // console.log("fix2"); - // element.innerHTML = currentCount.toFixed(2); - // } else { - // console.log("fixNone"); - // element.innerHTML = currentCount; - // } + if (fixtotwo) { + element.innerHTML = currentCount.toFixed(2); + } else { + element.innerHTML = currentCount; + } if (progress < 1) { requestAnimationFrame(updateCount);