Spaces:
Running
Running
Download index.html from patpie/excel-wizard-analyzer: direct link, hf CLI and curl.
- Browser
- Download file 40.6 kB
-
https://huggingface.co/spaces/patpie/excel-wizard-analyzer/resolve/main/index.html
- Command line
-
hf download hf://spaces/patpie/excel-wizard-analyzer/index.html
-
curl -L -o index.html https://huggingface.co/spaces/patpie/excel-wizard-analyzer/resolve/main/index.html
40.6 kB
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Excel Wizard Analyzer</title> | |
| <script src="https://cdn.tailwindcss.com"></script> | |
| <script src="https://unpkg.com/xlsx/dist/xlsx.full.min.js"></script> | |
| <script src="https://unpkg.com/feather-icons"></script> | |
| <script src="https://cdn.jsdelivr.net/npm/chart.js"></script> | |
| <script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-datalabels@2.0.0"></script> | |
| <script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script> | |
| <style> | |
| .dropzone { | |
| border: 2px dashed #94a3b8; | |
| border-radius: 0.5rem; | |
| transition: all 0.3s ease; | |
| } | |
| .dropzone-active { | |
| border-color: #6366f1; | |
| background-color: #e0e7ff; | |
| } | |
| #dataTable { | |
| overflow-x: auto; | |
| } | |
| .error-message { | |
| animation: shake 0.5s; | |
| } | |
| @keyframes shake { | |
| 0%, 100% { transform: translateX(0); } | |
| 20%, 60% { transform: translateX(-5px); } | |
| 40%, 80% { transform: translateX(5px); } | |
| } | |
| </style> | |
| </head> | |
| <body class="bg-gray-50 min-h-screen"> | |
| <div class="container mx-auto px-4 py-12"> | |
| <!-- Header --> | |
| <header class="text-center mb-12"> | |
| <h1 class="text-4xl font-bold text-indigo-700 mb-2">Excel Wizard Analyzer <span class="text-purple-500">🔮</span></h1> | |
| <p class="text-lg text-gray-600">Upload your Excel file and let the magic happen!</p> | |
| </header> | |
| <!-- Main Content --> | |
| <div class="max-w-4xl mx-auto bg-white rounded-xl shadow-md overflow-hidden p-6"> | |
| <!-- File Drop Zone --> | |
| <div id="dropzone" class="dropzone p-8 text-center cursor-pointer mb-8"> | |
| <div class="flex flex-col items-center justify-center"> | |
| <i data-feather="upload" class="w-12 h-12 text-indigo-500 mb-4"></i> | |
| <h2 class="text-xl font-semibold text-gray-700 mb-2">Drag & Drop your Excel file here</h2> | |
| <p class="text-gray-500 mb-4">or click to browse files</p> | |
| <input type="file" id="fileInput" accept=".xlsx, .xls, .csv" class="hidden" /> | |
| <button id="browseBtn" class="px-4 py-2 bg-indigo-600 text-white rounded-lg hover:bg-indigo-700 transition"> | |
| Browse Files | |
| </button> | |
| </div> | |
| </div> | |
| <!-- Error Message --> | |
| <div id="errorMessage" class="hidden bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded relative mb-8"> | |
| <strong class="font-bold">Oops!</strong> | |
| <span id="errorText" class="block sm:inline">Something went wrong.</span> | |
| <span class="absolute top-0 bottom-0 right-0 px-4 py-3"> | |
| <i data-feather="x" class="cursor-pointer" onclick="document.getElementById('errorMessage').classList.add('hidden')"></i> | |
| </span> | |
| </div> | |
| <!-- File Info --> | |
| <div id="fileInfo" class="hidden mb-8 p-4 bg-blue-50 rounded-lg"> | |
| <div class="flex items-center"> | |
| <div class="flex-shrink-0"> | |
| <i data-feather="file-text" class="w-6 h-6 text-blue-600"></i> | |
| </div> | |
| <div class="ml-3"> | |
| <h3 class="text-sm font-medium text-blue-800" id="fileName">File: example.xlsx</h3> | |
| <div class="mt-1 text-sm text-blue-700"> | |
| <p id="fileDetails">Size: 2.5MB • Sheets: 3</p> | |
| </div> | |
| </div> | |
| <div class="ml-auto"> | |
| <button onclick="resetFile()" class="text-blue-600 hover:text-blue-800 text-sm font-medium"> | |
| Change File | |
| </button> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- Analysis Options --> | |
| <div id="analysisOptions" class="hidden mb-8"> | |
| <h3 class="text-lg font-medium text-gray-700 mb-4">Analysis Options</h3> | |
| <div class="grid grid-cols-1 md:grid-cols-3 gap-4"> | |
| <button id="analyzeBtn" class="px-4 py-3 bg-indigo-600 text-white rounded-lg hover:bg-indigo-700 transition flex items-center justify-center"> | |
| <i data-feather="activity" class="mr-2"></i> Analyze Data | |
| </button> | |
| <button id="previewBtn" class="px-4 py-3 bg-white border border-indigo-600 text-indigo-600 rounded-lg hover:bg-indigo-50 transition flex items-center justify-center"> | |
| <i data-feather="eye" class="mr-2"></i> Preview Data | |
| </button> | |
| <button id="visualizeBtn" class="px-4 py-3 bg-purple-600 text-white rounded-lg hover:bg-purple-700 transition flex items-center justify-center"> | |
| <i data-feather="image" class="mr-2"></i> Visualize Data | |
| </button> | |
| </div> | |
| </div> | |
| <!-- Loading Indicator --> | |
| <div id="loadingIndicator" class="hidden flex flex-col items-center justify-center py-8"> | |
| <div class="animate-spin rounded-full h-12 w-12 border-t-2 border-b-2 border-indigo-500 mb-4"></div> | |
| <p class="text-gray-600">Analyzing your file...</p> | |
| </div> | |
| <!-- Results Section --> | |
| <div id="resultsSection" class="hidden"> | |
| <h3 class="text-lg font-medium text-gray-700 mb-4">Analysis Results</h3> | |
| <div class="mb-6"> | |
| <div class="flex items-center mb-2"> | |
| <i data-feather="info" class="w-5 h-5 text-indigo-500 mr-2"></i> | |
| <h4 class="font-medium">File Summary</h4> | |
| </div> | |
| <div id="fileSummary" class="bg-gray-50 p-4 rounded-lg"> | |
| <!-- Summary will be inserted here --> | |
| </div> | |
| </div> | |
| <div class="mb-6"> | |
| <div class="flex items-center justify-between mb-4"> | |
| <div class="flex items-center"> | |
| <i data-feather="bar-chart-2" class="w-5 h-5 text-indigo-500 mr-2"></i> | |
| <h4 class="font-medium">Data Visualizations</h4> | |
| </div> | |
| <div class="flex space-x-2"> | |
| <select id="chartType" class="text-sm border rounded px-2 py-1"> | |
| <option value="bar">Bar Chart</option> | |
| <option value="pie">Pie Chart</option> | |
| <option value="line">Line Chart</option> | |
| </select> | |
| <select id="filterField" class="text-sm border rounded px-2 py-1"> | |
| <option value="age">Age</option> | |
| <option value="gender">Gender</option> | |
| <option value="booth">Booth</option> | |
| </select> | |
| </div> | |
| </div> | |
| <div class="grid grid-cols-1 md:grid-cols-2 gap-6"> | |
| <div class="bg-white p-4 rounded-lg shadow-sm"> | |
| <h5 class="text-sm font-medium mb-3">Distribution by Selected Field</h5> | |
| <div id="mainChart" class="h-64"></div> | |
| </div> | |
| <div class="bg-white p-4 rounded-lg shadow-sm"> | |
| <h5 class="text-sm font-medium mb-3">Gender Distribution</h5> | |
| <div id="genderChart" class="h-64"></div> | |
| </div> | |
| </div> | |
| <div class="mt-6 grid grid-cols-1 md:grid-cols-3 gap-4"> | |
| <div class="bg-white p-4 rounded-lg shadow-sm"> | |
| <h5 class="text-sm font-medium mb-3">Age Groups</h5> | |
| <div id="ageChart" class="h-48"></div> | |
| </div> | |
| <div class="bg-white p-4 rounded-lg shadow-sm"> | |
| <h5 class="text-sm font-medium mb-3">Booth Analysis</h5> | |
| <div id="boothChart" class="h-48"></div> | |
| </div> | |
| <div class="bg-white p-4 rounded-lg shadow-sm"> | |
| <h5 class="text-sm font-medium mb-3">Other Metrics</h5> | |
| <div id="otherChart" class="h-48"></div> | |
| </div> | |
| </div> | |
| </div> | |
| <div> | |
| <div class="flex items-center mb-2"> | |
| <i data-feather="alert-triangle" class="w-5 h-5 text-indigo-500 mr-2"></i> | |
| <h4 class="font-medium">Potential Issues</h4> | |
| </div> | |
| <div id="dataIssues" class="bg-gray-50 p-4 rounded-lg"> | |
| <!-- Issues will be inserted here --> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- Data Visualization --> | |
| <div id="dataVisualization" class="hidden bg-white p-6 rounded-xl shadow-sm mb-8"> | |
| <div class="flex items-center justify-between mb-6"> | |
| <h3 class="text-xl font-semibold text-gray-800">Data Visualizations</h3> | |
| <div class="flex space-x-2"> | |
| <select id="visualizationType" class="border rounded-md px-3 py-2 text-sm"> | |
| <option value="bar">Bar Chart</option> | |
| <option value="line">Line Chart</option> | |
| <option value="pie">Pie Chart</option> | |
| <option value="scatter">Scatter Plot</option> | |
| </select> | |
| <button onclick="generateVisualization()" class="px-4 py-2 bg-indigo-600 text-white rounded-md hover:bg-indigo-700 text-sm"> | |
| Generate | |
| </button> | |
| <button onclick="closeVisualization()" class="px-4 py-2 bg-gray-200 text-gray-700 rounded-md hover:bg-gray-300 text-sm"> | |
| Close | |
| </button> | |
| </div> | |
| </div> | |
| <div id="visualizationContainer" class="w-full h-96 bg-gray-50 rounded-lg flex items-center justify-center"> | |
| <p class="text-gray-500">Select visualization options and click Generate</p> | |
| </div> | |
| </div> | |
| <!-- Data Preview --> | |
| <div id="dataPreview" class="hidden"> | |
| <div class="flex items-center justify-between mb-4"> | |
| <h3 class="text-lg font-medium text-gray-700">Data Preview</h3> | |
| <div class="flex space-x-2"> | |
| <button id="exportBtn" class="px-3 py-1 bg-green-600 text-white rounded-lg hover:bg-green-700 transition text-sm flex items-center"> | |
| <i data-feather="download" class="w-4 h-4 mr-1"></i> Export | |
| </button> | |
| <button onclick="closePreview()" class="px-3 py-1 bg-gray-200 text-gray-700 rounded-lg hover:bg-gray-300 transition text-sm flex items-center"> | |
| <i data-feather="x" class="w-4 h-4 mr-1"></i> Close | |
| </button> | |
| </div> | |
| </div> | |
| <div id="dataTable" class="border rounded-lg overflow-auto"> | |
| <!-- Table will be inserted here --> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <script> | |
| // Initialize feather icons | |
| document.addEventListener('DOMContentLoaded', function() { | |
| feather.replace(); | |
| window.visualizationGenerated = false; | |
| // Setup dropzone | |
| const dropzone = document.getElementById('dropzone'); | |
| const fileInput = document.getElementById('fileInput'); | |
| const browseBtn = document.getElementById('browseBtn'); | |
| browseBtn.addEventListener('click', function() { | |
| fileInput.click(); | |
| }); | |
| fileInput.addEventListener('change', function(e) { | |
| if (e.target.files.length) { | |
| handleFile(e.target.files[0]); | |
| } | |
| }); | |
| ['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => { | |
| dropzone.addEventListener(eventName, preventDefaults, false); | |
| }); | |
| function preventDefaults(e) { | |
| e.preventDefault(); | |
| e.stopPropagation(); | |
| } | |
| ['dragenter', 'dragover'].forEach(eventName => { | |
| dropzone.addEventListener(eventName, highlight, false); | |
| }); | |
| ['dragleave', 'drop'].forEach(eventName => { | |
| dropzone.addEventListener(eventName, unhighlight, false); | |
| }); | |
| function highlight() { | |
| dropzone.classList.add('dropzone-active'); | |
| } | |
| function unhighlight() { | |
| dropzone.classList.remove('dropzone-active'); | |
| } | |
| dropzone.addEventListener('drop', function(e) { | |
| const dt = e.dataTransfer; | |
| const file = dt.files[0]; | |
| handleFile(file); | |
| }); | |
| }); | |
| function handleFile(file) { | |
| const errorMessage = document.getElementById('errorMessage'); | |
| const errorText = document.getElementById('errorText'); | |
| // Check file type | |
| if (!file.name.match(/\.(xlsx|xls|csv)$/i)) { | |
| errorText.textContent = 'Please upload an Excel file (.xlsx, .xls) or CSV file.'; | |
| errorMessage.classList.remove('hidden'); | |
| return; | |
| } | |
| // Update file info | |
| document.getElementById('fileName').textContent = 'File: ' + file.name; | |
| document.getElementById('fileDetails').textContent = 'Size: ' + formatFileSize(file.size); | |
| document.getElementById('fileInfo').classList.remove('hidden'); | |
| document.getElementById('analysisOptions').classList.remove('hidden'); | |
| // Parse and store file for analysis | |
| const reader = new FileReader(); | |
| reader.onload = function(e) { | |
| const data = new Uint8Array(e.target.result); | |
| const workbook = XLSX.read(data, { type: 'array' }); | |
| window.workbook = workbook; | |
| window.sheetData = XLSX.utils.sheet_to_json(workbook.Sheets[workbook.SheetNames[0]]); | |
| }; | |
| reader.readAsArrayBuffer(file); | |
| } | |
| function formatFileSize(bytes) { | |
| if (bytes === 0) return '0 Bytes'; | |
| const k = 1024; | |
| const sizes = ['Bytes', 'KB', 'MB', 'GB']; | |
| const i = Math.floor(Math.log(bytes) / Math.log(k)); | |
| return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i]; | |
| } | |
| function resetFile() { | |
| document.getElementById('fileInput').value = ''; | |
| document.getElementById('fileInfo').classList.add('hidden'); | |
| document.getElementById('analysisOptions').classList.add('hidden'); | |
| document.getElementById('resultsSection').classList.add('hidden'); | |
| document.getElementById('dataPreview').classList.add('hidden'); | |
| delete window.currentFile; | |
| } | |
| function closePreview() { | |
| document.getElementById('dataPreview').classList.add('hidden'); | |
| } | |
| document.getElementById('analyzeBtn').addEventListener('click', function() { | |
| if (!window.sheetData || window.sheetData.length === 0) return; | |
| const loadingIndicator = document.getElementById('loadingIndicator'); | |
| const resultsSection = document.getElementById('resultsSection'); | |
| loadingIndicator.classList.remove('hidden'); | |
| resultsSection.classList.add('hidden'); | |
| // Process data in background to prevent UI freeze | |
| setTimeout(() => { | |
| try { | |
| const analysis = analyzeData(window.sheetData); | |
| loadingIndicator.classList.add('hidden'); | |
| showAnalysisResults(analysis); | |
| } catch (error) { | |
| loadingIndicator.classList.add('hidden'); | |
| const errorMessage = document.getElementById('errorMessage'); | |
| document.getElementById('errorText').textContent = 'Error analyzing data: ' + error.message; | |
| errorMessage.classList.remove('hidden'); | |
| } | |
| }, 100); | |
| }); | |
| function analyzeData(data) { | |
| if (!data || data.length === 0) throw new Error('No data to analyze'); | |
| const numericColumns = []; | |
| const textColumns = []; | |
| const dateColumns = []; | |
| const emptyCells = { count: 0, columns: {} }; | |
| const columnStats = {}; | |
| // First pass - determine column types and collect basic stats | |
| Object.keys(data[0]).forEach(col => { | |
| let isNumeric = true; | |
| let isDate = true; | |
| let hasValues = false; | |
| for (let row of data) { | |
| const val = row[col]; | |
| if (val === undefined || val === null || val === '') { | |
| emptyCells.count++; | |
| emptyCells.columns[col] = (emptyCells.columns[col] || 0) + 1; | |
| continue; | |
| } | |
| hasValues = true; | |
| if (isNumeric && isNaN(Number(val))) isNumeric = false; | |
| if (isDate && isNaN(Date.parse(val))) isDate = false; | |
| } | |
| if (hasValues) { | |
| if (isNumeric) numericColumns.push(col); | |
| else if (isDate) dateColumns.push(col); | |
| else textColumns.push(col); | |
| } | |
| columnStats[col] = { type: isNumeric ? 'numeric' : isDate ? 'date' : 'text', empty: emptyCells.columns[col] || 0 }; | |
| }); | |
| // Second pass - calculate actual statistics | |
| const analysis = { | |
| recordCount: data.length, | |
| columnCount: Object.keys(data[0]).length, | |
| numericColumns, | |
| textColumns, | |
| dateColumns, | |
| emptyCells, | |
| columnStats, | |
| columnUniqueness: calculateUniqueness(data), | |
| potentialIssues: findPotentialIssues(data, columnStats) | |
| }; | |
| return analysis; | |
| } | |
| function calculateUniqueness(data) { | |
| const uniqueness = {}; | |
| Object.keys(data[0]).forEach(col => { | |
| const uniqueValues = new Set(); | |
| data.forEach(row => uniqueValues.add(row[col])); | |
| uniqueness[col] = { | |
| uniqueCount: uniqueValues.size, | |
| uniquenessRatio: uniqueValues.size / data.length | |
| }; | |
| }); | |
| return uniqueness; | |
| } | |
| function findPotentialIssues(data, columnStats) { | |
| const issues = []; | |
| // Check for empty columns | |
| Object.entries(columnStats).forEach(([col, stats]) => { | |
| if (stats.empty / data.length > 0.5) { | |
| issues.push({ | |
| type: 'missing_data', | |
| column: col, | |
| severity: 'high', | |
| message: `Column "${col}" has more than 50% empty values` | |
| }); | |
| } | |
| }); | |
| // Check for duplicate rows | |
| const rowHashes = data.map(row => JSON.stringify(row)); | |
| const uniqueHashes = new Set(rowHashes); | |
| if (uniqueHashes.size < data.length) { | |
| const duplicateCount = data.length - uniqueHashes.size; | |
| issues.push({ | |
| type: 'duplicates', | |
| severity: 'medium', | |
| message: `${duplicateCount} potential duplicate rows found` | |
| }); | |
| } | |
| return issues; | |
| } | |
| // Visualization functions | |
| function generateVisualization() { | |
| if (!window.sheetData || window.sheetData.length === 0) return; | |
| const type = document.getElementById('visualizationType').value; | |
| const container = document.getElementById('visualizationContainer'); | |
| container.innerHTML = '<canvas id="dynamicChart"></canvas>'; | |
| const ctx = container.querySelector('canvas').getContext('2d'); | |
| const firstColumn = Object.keys(window.sheetData[0])[0]; | |
| const secondColumn = Object.keys(window.sheetData[0])[1] || firstColumn; | |
| // Prepare data | |
| const labels = window.sheetData.map(row => row[firstColumn] || 'N/A').slice(0, 20); | |
| const values = window.sheetData.map(row => { | |
| const val = row[secondColumn]; | |
| return isNaN(val) ? 0 : Number(val); | |
| }).slice(0, 20); | |
| new Chart(ctx, { | |
| type: type, | |
| data: { | |
| labels: labels, | |
| datasets: [{ | |
| label: secondColumn, | |
| data: values, | |
| backgroundColor: type === 'pie' || type === 'doughnut' | |
| ? generatePieColors(values.length) | |
| : 'rgba(99, 102, 241, 0.8)', | |
| borderColor: '#4f46e5', | |
| borderWidth: 1 | |
| }] | |
| }, | |
| options: { | |
| responsive: true, | |
| maintainAspectRatio: false, | |
| plugins: { | |
| title: { | |
| display: true, | |
| text: `${firstColumn} vs ${secondColumn}`, | |
| font: { size: 16 } | |
| }, | |
| legend: { | |
| position: type === 'pie' || type === 'doughnut' ? 'right' : 'top' | |
| } | |
| }, | |
| scales: type !== 'pie' && type !== 'doughnut' ? { | |
| y: { beginAtZero: true } | |
| } : {} | |
| } | |
| }); | |
| } | |
| function generatePieColors(count) { | |
| const colors = []; | |
| for (let i = 0; i < count; i++) { | |
| const hue = (i * 360 / count) % 360; | |
| colors.push(`hsla(${hue}, 70%, 60%, 0.8)`); | |
| } | |
| return colors; | |
| } | |
| function closeVisualization() { | |
| document.getElementById('dataVisualization').classList.add('hidden'); | |
| } | |
| document.getElementById('visualizeBtn').addEventListener('click', function() { | |
| document.getElementById('dataVisualization').classList.remove('hidden'); | |
| if (!window.visualizationGenerated) { | |
| generateVisualization(); | |
| window.visualizationGenerated = true; | |
| } | |
| }); | |
| document.getElementById('previewBtn').addEventListener('click', function() { | |
| if (!window.sheetData || window.sheetData.length === 0) return; | |
| const dataPreview = document.getElementById('dataPreview'); | |
| const dataTable = document.getElementById('dataTable'); | |
| // Display first 50 rows of actual data | |
| const previewData = window.sheetData.slice(0, 50); | |
| const columns = Object.keys(window.sheetData[0]); | |
| // Build header | |
| let tableHTML = `<table class="min-w-full divide-y divide-gray-200"> | |
| <thead class="bg-gray-50"> | |
| <tr>`; | |
| columns.forEach(col => { | |
| tableHTML += `<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">${col}</th>`; | |
| }); | |
| tableHTML += `</tr></thead><tbody class="bg-white divide-y divide-gray-200">`; | |
| // Build rows | |
| previewData.forEach(row => { | |
| tableHTML += '<tr>'; | |
| columns.forEach(col => { | |
| const val = row[col]; | |
| tableHTML += `<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${val !== undefined ? val : ''}</td>`; | |
| }); | |
| tableHTML += '</tr>'; | |
| }); | |
| tableHTML += '</tbody></table>'; | |
| dataTable.innerHTML = tableHTML; | |
| dataPreview.classList.remove('hidden'); | |
| }); | |
| function initializeCharts(analysis) { | |
| // Find columns suitable for visualization | |
| const chartableColumns = analysis.textColumns.filter(col => | |
| analysis.columnUniqueness[col].uniqueCount > 1 && | |
| analysis.columnUniqueness[col].uniqueCount < 20 | |
| ); | |
| // Generate chart data for all suitable columns | |
| const chartData = {}; | |
| chartableColumns.forEach(col => { | |
| const counts = {}; | |
| window.sheetData.forEach(row => { | |
| const val = row[col] || 'Unknown'; | |
| counts[val] = (counts[val] || 0) + 1; | |
| }); | |
| chartData[col] = counts; | |
| }); | |
| // Clear previous charts | |
| ['mainChart', 'genderChart', 'ageChart', 'boothChart'].forEach(id => { | |
| if (window[id]) window[id].destroy(); | |
| }); | |
| // Main interactive chart | |
| const mainChartCtx = document.getElementById('mainChart').getContext('2d'); | |
| const firstChartCol = chartableColumns.length > 0 ? chartableColumns[0] : null; | |
| if (firstChartCol) { | |
| const labels = Object.keys(chartData[firstChartCol]); | |
| const values = Object.values(chartData[firstChartCol]); | |
| window.mainChart = new Chart(mainChartCtx, { | |
| type: 'bar', | |
| data: { | |
| labels: labels, | |
| datasets: [{ | |
| label: 'Count', | |
| data: values, | |
| backgroundColor: createGradient(mainChartCtx, '#6366f1', '#a855f7'), | |
| borderColor: '#4f46e5', | |
| borderWidth: 2, | |
| borderRadius: 6, | |
| hoverBackgroundColor: '#ec4899' | |
| }] | |
| }, | |
| options: { | |
| responsive: true, | |
| maintainAspectRatio: false, | |
| plugins: { | |
| legend: { display: false }, | |
| tooltip: { | |
| backgroundColor: '#1e293b', | |
| titleFont: { size: 14, weight: 'bold' }, | |
| bodyFont: { size: 12 }, | |
| padding: 12, | |
| cornerRadius: 8, | |
| displayColors: false | |
| } | |
| }, | |
| scales: { | |
| y: { | |
| beginAtZero: true, | |
| grid: { color: '#e2e8f0' } | |
| }, | |
| x: { | |
| grid: { display: false } | |
| } | |
| }, | |
| animation: { | |
| duration: 1000, | |
| easing: 'easeOutQuart' | |
| } | |
| } | |
| }); | |
| // Update filter dropdown | |
| const filterField = document.getElementById('filterField'); | |
| filterField.innerHTML = ''; | |
| chartableColumns.forEach(col => { | |
| const option = document.createElement('option'); | |
| option.value = col; | |
| option.textContent = col; | |
| filterField.appendChild(option); | |
| }); | |
| filterField.value = firstChartCol; | |
| } | |
| // Create animated donut chart | |
| const genderChartCtx = document.getElementById('genderChart').getContext('2d'); | |
| const genderData = chartableColumns.length > 0 ? chartData[chartableColumns[0]] : { 'Data': 1 }; | |
| window.genderChart = new Chart(genderChartCtx, { | |
| type: 'doughnut', | |
| data: { | |
| labels: Object.keys(genderData), | |
| datasets: [{ | |
| data: Object.values(genderData), | |
| backgroundColor: generateColors(Object.keys(genderData).length), | |
| borderWidth: 0, | |
| hoverOffset: 20 | |
| }] | |
| }, | |
| options: { | |
| responsive: true, | |
| maintainAspectRatio: false, | |
| cutout: '70%', | |
| plugins: { | |
| legend: { | |
| position: 'bottom', | |
| labels: { | |
| padding: 20, | |
| usePointStyle: true, | |
| pointStyle: 'circle' | |
| } | |
| }, | |
| tooltip: { | |
| backgroundColor: '#1e293b', | |
| titleFont: { size: 14, weight: 'bold' }, | |
| bodyFont: { size: 12 }, | |
| padding: 12, | |
| cornerRadius: 8 | |
| } | |
| }, | |
| animation: { | |
| animateScale: true, | |
| animateRotate: true | |
| } | |
| } | |
| }); | |
| // Create bubble chart for numeric data | |
| const ageChartCtx = document.getElementById('ageChart').getContext('2d'); | |
| if (analysis.numericColumns.length > 0) { | |
| const numericCol = analysis.numericColumns[0]; | |
| const values = window.sheetData.map(row => row[numericCol]).filter(val => !isNaN(val)); | |
| window.ageChart = new Chart(ageChartCtx, { | |
| type: 'bubble', | |
| data: { | |
| datasets: [{ | |
| label: numericCol, | |
| data: values.map(val => ({ | |
| x: Math.random() * 100, | |
| y: Math.random() * 100, | |
| r: Math.min(20, val / (Math.max(...values) / 20)) | |
| })), | |
| backgroundColor: createGradient(ageChartCtx, '#6366f1', '#ec4899'), | |
| borderColor: '#4f46e5', | |
| borderWidth: 1 | |
| }] | |
| }, | |
| options: { | |
| responsive: true, | |
| maintainAspectRatio: false, | |
| plugins: { | |
| legend: { display: false }, | |
| tooltip: { | |
| callbacks: { | |
| label: ctx => `${numericCol}: ${values[ctx.dataIndex]}` | |
| } | |
| } | |
| }, | |
| scales: { | |
| x: { display: false }, | |
| y: { display: false } | |
| } | |
| } | |
| }); | |
| } | |
| // Create radar chart for categorical data | |
| const boothChartCtx = document.getElementById('boothChart').getContext('2d'); | |
| if (chartableColumns.length > 1) { | |
| const col1 = chartableColumns[0]; | |
| const col2 = chartableColumns[1]; | |
| const combinedData = {}; | |
| window.sheetData.forEach(row => { | |
| const val1 = row[col1] || 'Unknown'; | |
| const val2 = row[col2] || 'Unknown'; | |
| const key = `${val1} x ${val2}`; | |
| combinedData[key] = (combinedData[key] || 0) + 1; | |
| }); | |
| const topCombinations = Object.entries(combinedData) | |
| .sort((a, b) => b[1] - a[1]) | |
| .slice(0, 6); | |
| window.boothChart = new Chart(boothChartCtx, { | |
| type: 'radar', | |
| data: { | |
| labels: topCombinations.map(c => c[0]), | |
| datasets: [{ | |
| label: 'Combination Frequency', | |
| data: topCombinations.map(c => c[1]), | |
| backgroundColor: 'rgba(99, 102, 241, 0.2)', | |
| borderColor: '#6366f1', | |
| borderWidth: 2, | |
| pointBackgroundColor: '#6366f1', | |
| pointRadius: 4, | |
| pointHoverRadius: 6 | |
| }] | |
| }, | |
| options: { | |
| responsive: true, | |
| maintainAspectRatio: false, | |
| plugins: { | |
| legend: { display: false } | |
| }, | |
| scales: { | |
| r: { | |
| angleLines: { color: '#e2e8f0' }, | |
| grid: { color: '#e2e8f0' }, | |
| pointLabels: { | |
| font: { size: 10 }, | |
| padding: 10 | |
| }, | |
| ticks: { | |
| display: false, | |
| stepSize: Math.ceil(Math.max(...topCombinations.map(c => c[1])) / 5) | |
| } | |
| } | |
| } | |
| } | |
| }); | |
| } | |
| // Helper functions | |
| function createGradient(ctx, color1, color2) { | |
| const gradient = ctx.createLinearGradient(0, 0, 0, 400); | |
| gradient.addColorStop(0, color1); | |
| gradient.addColorStop(1, color2); | |
| return gradient; | |
| } | |
| function generateColors(count) { | |
| const colors = []; | |
| const hueStep = 360 / count; | |
| for (let i = 0; i < count; i++) { | |
| colors.push(`hsl(${i * hueStep}, 70%, 60%)`); | |
| } | |
| return colors; | |
| } | |
| // Interactive chart updates | |
| document.getElementById('filterField').addEventListener('change', function() { | |
| const field = this.value; | |
| const counts = {}; | |
| window.sheetData.forEach(row => { | |
| const val = row[field] || 'Unknown'; | |
| counts[val] = (counts[val] || 0) + 1; | |
| }); | |
| // Animate update | |
| anime({ | |
| targets: window.mainChart.data.datasets[0], | |
| data: Object.values(counts), | |
| easing: 'easeOutQuart', | |
| duration: 800, | |
| update: function() { | |
| window.mainChart.data.labels = Object.keys(counts); | |
| window.mainChart.update(); | |
| } | |
| }); | |
| }); | |
| document.getElementById('chartType').addEventListener('change', function() { | |
| anime({ | |
| targets: window.mainChart, | |
| opacity: [1, 0], | |
| duration: 300, | |
| easing: 'linear', | |
| complete: () => { | |
| window.mainChart.config.type = this.value; | |
| window.mainChart.update(); | |
| anime({ | |
| targets: window.mainChart, | |
| opacity: [0, 1], | |
| duration: 300, | |
| easing: 'linear' | |
| }); | |
| } | |
| }); | |
| }); | |
| } | |
| function showAnalysisResults(analysis) { | |
| const fileSummary = document.getElementById('fileSummary'); | |
| const dataIssues = document.getElementById('dataIssues'); | |
| const resultsSection = document.getElementById('resultsSection'); | |
| // Show file summary | |
| fileSummary.innerHTML = ` | |
| <div class="grid grid-cols-2 md:grid-cols-4 gap-4"> | |
| <div class="p-3 bg-white rounded-lg shadow-sm"> | |
| <p class="text-sm text-gray-500">Total Records</p> | |
| <p class="text-xl font-bold text-indigo-600">${analysis.recordCount}</p> | |
| </div> | |
| <div class="p-3 bg-white rounded-lg shadow-sm"> | |
| <p class="text-sm text-gray-500">Columns</p> | |
| <p class="text-xl font-bold text-indigo-600">${analysis.columnCount}</p> | |
| </div> | |
| <div class="p-3 bg-white rounded-lg shadow-sm"> | |
| <p class="text-sm text-gray-500">Numeric Columns</p> | |
| <p class="text-xl font-bold text-indigo-600">${analysis.numericColumns.length}</p> | |
| </div> | |
| <div class="p-3 bg-white rounded-lg shadow-sm"> | |
| <p class="text-sm text-gray-500">Empty Cells</p> | |
| <p class="text-xl font-bold text-indigo-600">${analysis.emptyCells.count}</p> | |
| </div> | |
| </div> | |
| `; | |
| // Show data issues | |
| if (analysis.potentialIssues.length > 0) { | |
| let issuesHTML = '<div class="space-y-3">'; | |
| analysis.potentialIssues.forEach(issue => { | |
| issuesHTML += ` | |
| <div class="flex items-start"> | |
| <i data-feather="alert-circle" class="w-4 h-4 ${issue.severity === 'high' ? 'text-red-500' : 'text-yellow-500'} mt-1 mr-2"></i> | |
| <div> | |
| <p class="font-medium">${issue.message}</p> | |
| ${issue.column ? `<p class="text-sm text-gray-600">Column: ${issue.column}</p>` : ''} | |
| </div> | |
| </div> | |
| `; | |
| }); | |
| issuesHTML += '</div>'; | |
| dataIssues.innerHTML = issuesHTML; | |
| } else { | |
| dataIssues.innerHTML = '<p class="text-gray-600">No significant issues found in the data.</p>'; | |
| } | |
| // Initialize charts with real data | |
| initializeCharts(analysis); | |
| resultsSection.classList.remove('hidden'); | |
| feather.replace(); | |
| } | |
| document.getElementById('exportBtn').addEventListener('click', function() { | |
| alert('In a real application, this would export the data to CSV or Excel format.'); | |
| }); | |
| </script> | |
| </body> | |
| </html> | |