Download script.js from DoubleupDonny/mindsight-analytics-dashboard: direct link, hf CLI and curl.
- Browser
- Download file 4.54 kB
-
https://huggingface.co/spaces/DoubleupDonny/mindsight-analytics-dashboard/resolve/main/script.js
- Command line
-
hf download hf://spaces/DoubleupDonny/mindsight-analytics-dashboard/script.js
-
curl -L -o script.js https://huggingface.co/spaces/DoubleupDonny/mindsight-analytics-dashboard/resolve/main/script.js
4.54 kB
| // Shared functionality | |
| document.addEventListener('DOMContentLoaded', async () => { | |
| // Fetch real data from API | |
| const timeframe = document.querySelector('select').value; | |
| const data = await fetchDashboardData(timeframe); | |
| updateDashboard(data); | |
| // Initialize tooltips | |
| const tooltips = document.querySelectorAll('[data-tooltip]'); | |
| tooltips.forEach(tooltip => { | |
| tooltip.addEventListener('mouseenter', () => { | |
| const tooltipText = tooltip.getAttribute('data-tooltip'); | |
| const tooltipElement = document.createElement('div'); | |
| tooltipElement.className = 'tooltip-element absolute bg-gray-900 text-white text-sm px-2 py-1 rounded'; | |
| tooltipElement.textContent = tooltipText; | |
| tooltip.appendChild(tooltipElement); | |
| setTimeout(() => { | |
| tooltipElement.classList.add('opacity-0'); | |
| setTimeout(() => tooltipElement.remove(), 300); | |
| }, 2000); | |
| }); | |
| }); | |
| // Smooth scrolling for anchor links | |
| document.querySelectorAll('a[href^="#"]').forEach(anchor => { | |
| anchor.addEventListener('click', function (e) { | |
| e.preventDefault(); | |
| document.querySelector(this.getAttribute('href')).scrollIntoView({ | |
| behavior: 'smooth' | |
| }); | |
| }); | |
| }); | |
| }); | |
| // Data fetching functions | |
| async function fetchDashboardData(timeframe = '30d') { | |
| try { | |
| const response = await fetch(`/api/dashboard?timeframe=${timeframe}`); | |
| if (!response.ok) throw new Error('Network response was not ok'); | |
| return await response.json(); | |
| } catch (error) { | |
| console.error('Error fetching dashboard data:', error); | |
| console.error('Error fetching dashboard data:', error); | |
| // Fallback to mock data if API fails | |
| return { | |
| topCategories: [ | |
| { name: 'AI Development', value: 38 }, | |
| { name: 'Scientific Research', value: 28 }, | |
| { name: 'Business Strategy', value: 15 }, | |
| { name: 'Creative Arts', value: 10 }, | |
| { name: 'Technical Solutions', value: 7 }, | |
| { name: 'Other', value: 2 } | |
| ], | |
| revenueOpportunities: [ | |
| { name: 'AI Consulting Services', value: 1850000 }, | |
| { name: 'Premium API Access', value: 1200000 }, | |
| { name: 'Custom Model Training', value: 2200000 }, | |
| { name: 'Enterprise Solutions', value: 3100000 } | |
| ] | |
| }; | |
| } | |
| } | |
| // Update dashboard with live data | |
| function updateDashboard(data) { | |
| // Update top categories chart | |
| const topPieChart = Chart.getChart('topPieChart'); | |
| topPieChart.data.datasets[0].data = data.topCategories.map(c => c.value); | |
| topPieChart.update(); | |
| // Update revenue opportunities | |
| const revenueContainer = document.querySelector('.grid-cols-4'); | |
| if (revenueContainer && data.revenueOpportunities) { | |
| // Clear existing metrics | |
| revenueContainer.innerHTML = ''; | |
| // Add new metrics | |
| data.revenueOpportunities.forEach(opp => { | |
| const metricCard = document.createElement('div'); | |
| metricCard.className = 'bg-white p-6 rounded-xl shadow-sm border border-gray-100'; | |
| metricCard.innerHTML = ` | |
| <div class="flex justify-between items-start"> | |
| <div> | |
| <p class="text-gray-500">${opp.name}</p> | |
| <h3 class="text-2xl font-bold text-gray-800 mt-1">${formatNumber(opp.value)}</h3> | |
| </div> | |
| <div class="bg-indigo-100 p-2 rounded-lg"> | |
| <i data-feather="dollar-sign" class="text-indigo-600 w-5 h-5"></i> | |
| </div> | |
| </div> | |
| <p class="text-green-500 text-sm mt-2 flex items-center"> | |
| <i data-feather="trending-up" class="w-4 h-4 mr-1"></i> | |
| Potential revenue | |
| </p> | |
| `; | |
| revenueContainer.appendChild(metricCard); | |
| }); | |
| // Refresh feather icons | |
| feather.replace(); | |
| } | |
| } | |
| // Utility function to format numbers | |
| function formatNumber(num, decimals = 1) { | |
| if (num >= 1000000000) { | |
| return (num / 1000000000).toFixed(1) + 'B'; | |
| } | |
| if (num >= 1000000) { | |
| return (num / 1000000).toFixed(1) + 'M'; | |
| } | |
| if (num >= 1000) { | |
| return (num / 1000).toFixed(1) + 'K'; | |
| } | |
| return num.toString(); | |
| } |