From ed14be4e705644e2c05bf60a4a5bed2eca092d7a Mon Sep 17 00:00:00 2001 From: "Paul Gauthier (aider)" Date: Wed, 16 Apr 2025 19:00:18 -0700 Subject: [PATCH] refactor: Use constant for max display cost cap in leaderboard table --- aider/website/_includes/leaderboard_table.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/aider/website/_includes/leaderboard_table.js b/aider/website/_includes/leaderboard_table.js index ff7b13f0f..a71811fa8 100644 --- a/aider/website/_includes/leaderboard_table.js +++ b/aider/website/_includes/leaderboard_table.js @@ -1,6 +1,7 @@ document.addEventListener('DOMContentLoaded', function() { let currentMode = 'view'; // 'view', 'select', 'detail' let selectedRows = new Set(); // Store indices of selected rows + const MAX_DISPLAY_COST_CAP = 50; // Define the constant here const allMainRows = document.querySelectorAll('tr[id^="main-row-"]'); const allDetailsRows = document.querySelectorAll('tr[id^="details-"]'); @@ -219,7 +220,7 @@ document.addEventListener('DOMContentLoaded', function() { // Function to calculate the appropriate max display cost based on visible/selected entries function calculateDisplayMaxCost() { // Get the appropriate set of rows based on the current mode and selection state - let rowsToConsider; + let rowsToConsider; if (currentMode === 'view' && selectedRows.size > 0) { // In view mode with selections, only consider selected rows @@ -242,8 +243,8 @@ document.addEventListener('DOMContentLoaded', function() { } }); - // Cap at 50 if any entries exceed that amount, otherwise use actual max - return maxCost > 50 ? 50 : Math.max(1, maxCost); // Ensure at least 1 to avoid division by zero + // Cap at MAX_DISPLAY_COST_CAP if any entries exceed that amount, otherwise use actual max + return maxCost > MAX_DISPLAY_COST_CAP ? MAX_DISPLAY_COST_CAP : Math.max(1, maxCost); // Ensure at least 1 to avoid division by zero } // Process cost bars with dynamic scale @@ -264,7 +265,7 @@ document.addEventListener('DOMContentLoaded', function() { bar.style.width = Math.max(0, Math.min(100, percent)) + '%'; // Mark bars that exceed the limit (only if our display max is capped at 50) - if (currentMaxDisplayCost === 50 && cost > 50) { + if (currentMaxDisplayCost === MAX_DISPLAY_COST_CAP && cost > MAX_DISPLAY_COST_CAP) { // Create a darker section at the end with diagonal stripes const darkSection = document.createElement('div'); darkSection.className = 'bar-viz dark-section';