Spaces:
Running
Running
remova mais funções desnecessarias
Browse files831 unmodified lines832833834835836835836838839837840838839843844845840847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901841842843844904905845846847848240 unmodified lines1089109010911152115310921093109411561095109611591160116111621163116411651166116711681169117011711172117310971175117611771178117911801181118211831184118511861187118810981099110011901191110111021193119411951196119711981199120012011202120312041205120612071208120912101211110311041105110611071108110911101111121312141112111311141216121712181219122012211222122312241225122612271228122912301115111611171232123312341235123612371238123912401241124212431244124512461247124812491250125112521118111911201121112211231124125412551125112611271128831 unmodified lines }; reader.readAsArrayBuffer(file); } // Analyze column types (date, number, text) // Simplified column type analysis function analyzeColumnTypes() { console.log('Analyzing column types for auto chart generation...');columnTypes = []; columnTypes = []; if (columns.length === 0 || rawData.length === 0) return; // Check first 20 rows to determine type const sampleRows = rawData.slice(0, Math.min(20, rawData.length)); columns.forEach((col, colIndex) => { let dateCount = 0; let numberCount = 0; let emptyCount = 0; sampleRows.forEach(row => { const value = row[colIndex]; if (value === null || value === undefined || value === '') { emptyCount++; return; } // Check if it's a date (Excel date or string date) if (value instanceof Date) { dateCount++; } else if (typeof value === 'string') { // Try to parse as date const dateFormats = [ 'YYYY-MM-DD', 'MM/DD/YYYY', 'DD/MM/YYYY', 'YYYY/MM/DD', 'DD-MM-YYYY', 'MM-DD-YYYY' ]; for (const format of dateFormats) { if (moment(value, format, true).isValid()) { dateCount++; return; } } // Check if it's a number if (!isNaN(value) && value.trim() !== '') { numberCount++; } } else if (typeof value === 'number') { // Excel stores dates as numbers (days since 1900) // If the number is between 0 and 100,000, it might be a date if (value > 0 && value < 100000) { dateCount++; } else { numberCount++; } } }); // Determine the most likely type const total = sampleRows.length - emptyCount; if (total === 0) { columnTypes[colIndex] = 'text'; } else if (dateCount / total > 0.7) { columnTypes[colIndex] = 'date'; } else if (numberCount / total > 0.7) { columnTypes[colIndex] = 'number'; } else { columnTypes[colIndex] = 'text'; } // Default to text for simplicity columnTypes[colIndex] = 'text'; }); } // Format file size// Format file size function formatFileSize(bytes) { if (bytes === 0) return '0 Bytes'; const k = 1024;240 unmodified lines columnStats.appendChild(row); }); } // Initialize multiselect component // Simplified multiselect init function initMultiselect(id) { const container = document.getElementById(id); const selectedContainer = container.querySelector('.multiselect-selected'); const input = container.querySelector('.multiselect-input'); const dropdown = container.querySelector('.dropdown-content'); const optionsContainer = container.querySelector('.multiselect-options'); // Toggle dropdown on input focus input.addEventListener('focus', function() { dropdown.classList.remove('hidden'); input.placeholder = 'Type to search...'; }); // Close dropdown when clicking outside document.addEventListener('click', function(e) { if (!container.contains(e.target)) { dropdown.classList.add('hidden'); input.placeholder = 'Select columns...'; } }); // Search within options input.addEventListener('input', function(e) { const searchTerm = e.target.value.toLowerCase(); const options = optionsContainer.querySelectorAll('.multiselect-option-item'); options.forEach(option => { const text = option.textContent.toLowerCase(); if (text.includes(searchTerm)) { option.classList.remove('hidden'); } else { option.classList.add('hidden'); } }); }); input.addEventListener('focus', () => dropdown.classList.remove('hidden')); input.addEventListener('blur', () => dropdown.classList.add('hidden')); } // Update multiselect options // Simplified update multiselect options function updateMultiselectOptions(id, options) { const container = document.getElementById(id); const optionsContainer = container.querySelector('.multiselect-options'); optionsContainer.innerHTML = ''; options.forEach((option, index) => { const optionItem = document.createElement('div'); optionItem.className = 'multiselect-option-item px-4 py-2 hover:bg-gray-700 cursor-pointer flex justify-between items-center'; optionItem.innerHTML = ` <span>${option}</span> <span class="text-xs ${getTypeColorClass(columnTypes[index])}">${columnTypes[index]}</span> `; optionItem.dataset.value = index; optionItem.addEventListener('click', function() { addSelectedOption(id, option, index); }); optionsContainer.appendChild(optionItem); }); const optionsContainer = document.querySelector(`#${id} .multiselect-options`); optionsContainer.innerHTML = options.map((option, index) => ` <div class="multiselect-option-item px-4 py-2 hover:bg-gray-700 cursor-pointer" data-value="${index}" onclick="addSelectedOption('${id}', '${option}', ${index})"> ${option} </div> `).join(''); } // Add selected option to multiselect
// Simplified add selected option function addSelectedOption(id, option, index) { const container = document.getElementById(id); const selectedContainer = container.querySelector('.multiselect-selected'); // Check if option is already selected const existingOption = selectedContainer.querySelector(`[data-value="${index}"]`); if (existingOption) return; // Create selected option tag const selectedOption = document.createElement('div'); selectedOption.className = 'multiselect-option bg-indigo-900 text-indigo-100 flex items-center'; selectedOption.dataset.value = index; selectedOption.dataset.type = columnTypes[index]; const optionText = document.createElement('span'); optionText.textContent = option; const selectedContainer = document.querySelector(`#${id} .multiselect-selected`); if (selectedContainer.querySelector(`[data-value="${index}"]`)) return; const typeBadge = document.createElement('span'); typeBadge.className = `ml-2 text-xs ${getTypeColorClass(columnTypes[index])}`; typeBadge.textContent = columnTypes[index]; const removeButton = document.createElement('span'); removeButton.className = 'multiselect-option-remove ml-2'; removeButton.innerHTML = '×'; removeButton.addEventListener('click', function(e) { e.stopPropagation(); selectedOption.remove(); }); selectedOption.appendChild(optionText); selectedOption.appendChild(typeBadge); selectedOption.appendChild(removeButton); selectedContainer.appendChild(selectedOption); // Clear input and hide dropdown container.querySelector('.multiselect-input').value = ''; container.querySelector('.dropdown-content').classList.add('hidden'); selectedContainer.innerHTML += ` <div class="multiselect-option bg-indigo-900 text-indigo-100 p-1 m-1 rounded"> ${option} <span class="ml-2 cursor-pointer" onclick="this.parentNode.remove()">×</span> </div> `; } // Get selected options from multiselect// Get selected options from multiselect function getSelectedOptions(id) { const container = document.getElementById(id); const selectedOptions = container.querySelectorAll('.multiselect-selected [data-value]');index.html+28-158