document.addEventListener('DOMContentLoaded', function() { // Sample data - in a real app, this would come from an API const nodes = Array.from({length: 25}, (_, i) => ({ id: `NODE-${1000 + i}`, name: `Node ${i + 1}`, uptime: Math.floor(Math.random() * 20) + 80 + Math.random(), // 80-100% performance: Math.floor(Math.random() * 20) + 80 + Math.random(), // 80-100% score: Math.floor(Math.random() * 20) + 80 + Math.random(), // 80-100 status: Math.random() > 0.1 ? 'active' : 'inactive', lastUpdated: new Date(Date.now() - Math.floor(Math.random() * 86400000)) // within 24 hours })).sort((a, b) => b.score - a.score); // Chart data const performanceChartData = { labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul'], datasets: [ { label: 'Average Score', data: [72, 75, 78, 82, 85, 87, 89], borderColor: '#6366f1', backgroundColor: 'rgba(99, 102, 241, 0.1)', tension: 0.4, fill: true }, { label: 'Network Uptime %', data: [92, 93, 94, 95, 96, 97, 98], borderColor: '#10b981', backgroundColor: 'rgba(16, 185, 129, 0.1)', tension: 0.4, fill: true } ] }; // Initialize chart const ctx = document.getElementById('performance-chart').getContext('2d'); const performanceChart = new Chart(ctx, { type: 'line', data: performanceChartData, options: { responsive: true, maintainAspectRatio: false, plugins: { legend: { position: 'top', labels: { color: '#6b7280', font: { family: 'Inter' } } } }, scales: { y: { beginAtZero: false, min: 60, max: 100, grid: { color: 'rgba(209, 213, 219, 0.2)' }, ticks: { color: '#6b7280' } }, x: { grid: { display: false }, ticks: { color: '#6b7280' } } } } }); // Pagination variables let currentPage = 1; const rowsPerPage = 10; const totalPages = Math.ceil(nodes.length / rowsPerPage); // DOM elements const leaderboardBody = document.getElementById('leaderboard-body'); const prevBtn = document.getElementById('prev-btn'); const nextBtn = document.getElementById('next-btn'); const showingCount = document.getElementById('showing-count'); const totalCount = document.getElementById('total-count'); const refreshBtn = document.getElementById('refresh-btn'); // Update count display totalCount.textContent = nodes.length; // Render table rows function renderTableRows() { leaderboardBody.innerHTML = ''; const startIndex = (currentPage - 1) * rowsPerPage; const endIndex = Math.min(startIndex + rowsPerPage, nodes.length); for (let i = startIndex; i < endIndex; i++) { const node = nodes[i]; const row = document.createElement('tr'); row.className = `table-row-hover ${i % 2 === 0 ? 'bg-gray-50 dark:bg-gray-800' : 'bg-white dark:bg-gray-800'}`; row.innerHTML = `