Spaces:
Sleeping
Sleeping
Delete app.js
Browse files
app.js
DELETED
|
@@ -1,533 +0,0 @@
|
|
| 1 |
-
// Portfolio Application JavaScript
|
| 2 |
-
|
| 3 |
-
// Application Data
|
| 4 |
-
const portfolioData = {
|
| 5 |
-
sampleUrls: [
|
| 6 |
-
"https://example.com",
|
| 7 |
-
"https://news.bbc.com",
|
| 8 |
-
"https://github.com",
|
| 9 |
-
"https://stackoverflow.com",
|
| 10 |
-
"https://amazon.com"
|
| 11 |
-
],
|
| 12 |
-
demoResults: {
|
| 13 |
-
"https://example.com": "OTHER",
|
| 14 |
-
"https://news.bbc.com": "NEWS/BLOG",
|
| 15 |
-
"https://github.com": "OTHER",
|
| 16 |
-
"https://stackoverflow.com": "OTHER",
|
| 17 |
-
"https://amazon.com": "E-COMMERCE"
|
| 18 |
-
},
|
| 19 |
-
sampleText: "The latest developments in artificial intelligence and machine learning are revolutionizing industries across the globe. From healthcare to finance, companies are implementing AI solutions to improve efficiency and decision-making. However, these advancements also raise important questions about ethics, privacy, and the future of work.",
|
| 20 |
-
sampleData: [
|
| 21 |
-
{ month: 'Jan', sales: 4000, visitors: 2400, conversion: 6.0 },
|
| 22 |
-
{ month: 'Feb', sales: 3000, visitors: 1398, conversion: 4.7 },
|
| 23 |
-
{ month: 'Mar', sales: 2000, visitors: 9800, conversion: 2.0 },
|
| 24 |
-
{ month: 'Apr', sales: 2780, visitors: 3908, conversion: 7.1 },
|
| 25 |
-
{ month: 'May', sales: 1890, visitors: 4800, conversion: 3.9 },
|
| 26 |
-
{ month: 'Jun', sales: 2390, visitors: 3800, conversion: 6.3 }
|
| 27 |
-
]
|
| 28 |
-
};
|
| 29 |
-
|
| 30 |
-
// Tab Navigation
|
| 31 |
-
function initTabs() {
|
| 32 |
-
const tabBtns = document.querySelectorAll('.tab-btn');
|
| 33 |
-
const tabContents = document.querySelectorAll('.tab-content');
|
| 34 |
-
|
| 35 |
-
tabBtns.forEach(btn => {
|
| 36 |
-
btn.addEventListener('click', () => {
|
| 37 |
-
const targetTab = btn.dataset.tab;
|
| 38 |
-
|
| 39 |
-
// Remove active class from all buttons and contents
|
| 40 |
-
tabBtns.forEach(b => b.classList.remove('active'));
|
| 41 |
-
tabContents.forEach(c => c.classList.remove('active'));
|
| 42 |
-
|
| 43 |
-
// Add active class to clicked button and corresponding content
|
| 44 |
-
btn.classList.add('active');
|
| 45 |
-
document.getElementById(targetTab).classList.add('active');
|
| 46 |
-
});
|
| 47 |
-
});
|
| 48 |
-
}
|
| 49 |
-
|
| 50 |
-
// Web Scraping Tab Functions
|
| 51 |
-
function initScrapingTab() {
|
| 52 |
-
const urlsInput = document.getElementById('urls-input');
|
| 53 |
-
const sampleUrlsBtn = document.getElementById('sample-urls-btn');
|
| 54 |
-
const startScrapingBtn = document.getElementById('start-scraping-btn');
|
| 55 |
-
const progressSection = document.getElementById('scraping-progress');
|
| 56 |
-
const resultsSection = document.getElementById('scraping-results');
|
| 57 |
-
const resultsContainer = document.getElementById('results-container');
|
| 58 |
-
const exportBtn = document.getElementById('export-results-btn');
|
| 59 |
-
|
| 60 |
-
let scrapingResults = {};
|
| 61 |
-
|
| 62 |
-
sampleUrlsBtn.addEventListener('click', () => {
|
| 63 |
-
urlsInput.value = portfolioData.sampleUrls.join('\n');
|
| 64 |
-
});
|
| 65 |
-
|
| 66 |
-
startScrapingBtn.addEventListener('click', () => {
|
| 67 |
-
const urls = urlsInput.value.trim().split('\n').filter(url => url.trim());
|
| 68 |
-
|
| 69 |
-
if (urls.length === 0) {
|
| 70 |
-
alert('Please enter at least one URL to scrape.');
|
| 71 |
-
return;
|
| 72 |
-
}
|
| 73 |
-
|
| 74 |
-
startScrapingProcess(urls);
|
| 75 |
-
});
|
| 76 |
-
|
| 77 |
-
exportBtn.addEventListener('click', () => {
|
| 78 |
-
const dataStr = JSON.stringify(scrapingResults, null, 2);
|
| 79 |
-
const dataBlob = new Blob([dataStr], { type: 'application/json' });
|
| 80 |
-
const url = URL.createObjectURL(dataBlob);
|
| 81 |
-
const link = document.createElement('a');
|
| 82 |
-
link.href = url;
|
| 83 |
-
link.download = 'scraping_results.json';
|
| 84 |
-
link.click();
|
| 85 |
-
URL.revokeObjectURL(url);
|
| 86 |
-
});
|
| 87 |
-
|
| 88 |
-
function startScrapingProcess(urls) {
|
| 89 |
-
// Reset and show progress
|
| 90 |
-
progressSection.classList.remove('hidden');
|
| 91 |
-
resultsSection.classList.add('hidden');
|
| 92 |
-
scrapingResults = {};
|
| 93 |
-
|
| 94 |
-
const progressFill = document.getElementById('progress-fill');
|
| 95 |
-
const progressText = document.getElementById('progress-text');
|
| 96 |
-
|
| 97 |
-
let currentIndex = 0;
|
| 98 |
-
const totalUrls = urls.length;
|
| 99 |
-
|
| 100 |
-
function processNextUrl() {
|
| 101 |
-
if (currentIndex >= totalUrls) {
|
| 102 |
-
// Complete
|
| 103 |
-
progressText.textContent = 'Classification complete!';
|
| 104 |
-
setTimeout(() => {
|
| 105 |
-
progressSection.classList.add('hidden');
|
| 106 |
-
displayResults();
|
| 107 |
-
}, 1000);
|
| 108 |
-
return;
|
| 109 |
-
}
|
| 110 |
-
|
| 111 |
-
const currentUrl = urls[currentIndex].trim();
|
| 112 |
-
const progress = ((currentIndex + 1) / totalUrls) * 100;
|
| 113 |
-
|
| 114 |
-
progressFill.style.width = `${progress}%`;
|
| 115 |
-
progressText.textContent = `Processing: ${currentUrl} (${currentIndex + 1}/${totalUrls})`;
|
| 116 |
-
|
| 117 |
-
// Simulate processing time
|
| 118 |
-
setTimeout(() => {
|
| 119 |
-
// Get classification result (use demo data if available, otherwise simulate)
|
| 120 |
-
const classification = portfolioData.demoResults[currentUrl] || simulateClassification(currentUrl);
|
| 121 |
-
scrapingResults[currentUrl] = classification;
|
| 122 |
-
|
| 123 |
-
currentIndex++;
|
| 124 |
-
processNextUrl();
|
| 125 |
-
}, 1000 + Math.random() * 1500); // Random delay between 1-2.5s
|
| 126 |
-
}
|
| 127 |
-
|
| 128 |
-
processNextUrl();
|
| 129 |
-
}
|
| 130 |
-
|
| 131 |
-
function simulateClassification(url) {
|
| 132 |
-
const classifications = ['NEWS/BLOG', 'E-COMMERCE', 'OTHER', 'SOCIAL MEDIA', 'EDUCATIONAL'];
|
| 133 |
-
return classifications[Math.floor(Math.random() * classifications.length)];
|
| 134 |
-
}
|
| 135 |
-
|
| 136 |
-
function displayResults() {
|
| 137 |
-
resultsContainer.innerHTML = '';
|
| 138 |
-
|
| 139 |
-
Object.entries(scrapingResults).forEach(([url, classification]) => {
|
| 140 |
-
const resultItem = document.createElement('div');
|
| 141 |
-
resultItem.className = 'result-item';
|
| 142 |
-
|
| 143 |
-
resultItem.innerHTML = `
|
| 144 |
-
<a href="${url}" target="_blank" class="result-url">${url}</a>
|
| 145 |
-
<span class="result-classification">${classification}</span>
|
| 146 |
-
`;
|
| 147 |
-
|
| 148 |
-
resultsContainer.appendChild(resultItem);
|
| 149 |
-
});
|
| 150 |
-
|
| 151 |
-
resultsSection.classList.remove('hidden');
|
| 152 |
-
}
|
| 153 |
-
}
|
| 154 |
-
|
| 155 |
-
// Computer Vision Tab Functions
|
| 156 |
-
function initCVTab() {
|
| 157 |
-
const imageUpload = document.getElementById('image-upload');
|
| 158 |
-
const processBtn = document.getElementById('process-image-btn');
|
| 159 |
-
const cvMode = document.getElementById('cv-mode');
|
| 160 |
-
const cvResults = document.getElementById('cv-results');
|
| 161 |
-
const originalImage = document.getElementById('original-image');
|
| 162 |
-
const processedResult = document.getElementById('processed-result');
|
| 163 |
-
|
| 164 |
-
let uploadedImageData = null;
|
| 165 |
-
|
| 166 |
-
imageUpload.addEventListener('change', (e) => {
|
| 167 |
-
const file = e.target.files[0];
|
| 168 |
-
if (file) {
|
| 169 |
-
const reader = new FileReader();
|
| 170 |
-
reader.onload = (e) => {
|
| 171 |
-
uploadedImageData = e.target.result;
|
| 172 |
-
originalImage.src = uploadedImageData;
|
| 173 |
-
processBtn.disabled = false;
|
| 174 |
-
};
|
| 175 |
-
reader.readAsDataURL(file);
|
| 176 |
-
}
|
| 177 |
-
});
|
| 178 |
-
|
| 179 |
-
processBtn.addEventListener('click', () => {
|
| 180 |
-
if (!uploadedImageData) return;
|
| 181 |
-
|
| 182 |
-
processBtn.textContent = 'Processing...';
|
| 183 |
-
processBtn.classList.add('loading');
|
| 184 |
-
processBtn.disabled = true;
|
| 185 |
-
|
| 186 |
-
// Simulate processing
|
| 187 |
-
setTimeout(() => {
|
| 188 |
-
const mode = cvMode.value;
|
| 189 |
-
displayCVResults(mode);
|
| 190 |
-
|
| 191 |
-
processBtn.textContent = 'Process Image';
|
| 192 |
-
processBtn.classList.remove('loading');
|
| 193 |
-
processBtn.disabled = false;
|
| 194 |
-
}, 2000);
|
| 195 |
-
});
|
| 196 |
-
|
| 197 |
-
function displayCVResults(mode) {
|
| 198 |
-
let resultHTML = '';
|
| 199 |
-
|
| 200 |
-
switch (mode) {
|
| 201 |
-
case 'face-detection':
|
| 202 |
-
resultHTML = `
|
| 203 |
-
<div class="face-detection-result">
|
| 204 |
-
<h4>Face Detection Results</h4>
|
| 205 |
-
<p><strong>Faces detected:</strong> ${Math.floor(Math.random() * 3) + 1}</p>
|
| 206 |
-
<p><strong>Confidence:</strong> ${(Math.random() * 0.3 + 0.7).toFixed(2)}</p>
|
| 207 |
-
<p><strong>Processing time:</strong> ${(Math.random() * 2 + 0.5).toFixed(1)}s</p>
|
| 208 |
-
<div class="status success">✓ Detection Complete</div>
|
| 209 |
-
</div>
|
| 210 |
-
`;
|
| 211 |
-
break;
|
| 212 |
-
case 'edge-detection':
|
| 213 |
-
resultHTML = `
|
| 214 |
-
<div class="face-detection-result">
|
| 215 |
-
<h4>Edge Detection Results</h4>
|
| 216 |
-
<p><strong>Edges detected:</strong> ${Math.floor(Math.random() * 1000) + 500}</p>
|
| 217 |
-
<p><strong>Algorithm:</strong> Canny Edge Detection</p>
|
| 218 |
-
<p><strong>Threshold:</strong> Low: 50, High: 150</p>
|
| 219 |
-
<div class="status success">✓ Edge Detection Complete</div>
|
| 220 |
-
</div>
|
| 221 |
-
`;
|
| 222 |
-
break;
|
| 223 |
-
case 'color-analysis':
|
| 224 |
-
resultHTML = `
|
| 225 |
-
<div class="face-detection-result">
|
| 226 |
-
<h4>Color Analysis Results</h4>
|
| 227 |
-
<p><strong>Dominant colors:</strong> 5 detected</p>
|
| 228 |
-
<p><strong>Color space:</strong> RGB</p>
|
| 229 |
-
<p><strong>Brightness:</strong> ${Math.floor(Math.random() * 100)}%</p>
|
| 230 |
-
<div class="status success">✓ Analysis Complete</div>
|
| 231 |
-
</div>
|
| 232 |
-
`;
|
| 233 |
-
break;
|
| 234 |
-
}
|
| 235 |
-
|
| 236 |
-
processedResult.innerHTML = resultHTML;
|
| 237 |
-
cvResults.classList.remove('hidden');
|
| 238 |
-
}
|
| 239 |
-
}
|
| 240 |
-
|
| 241 |
-
// Text Analysis Tab Functions
|
| 242 |
-
function initTextTab() {
|
| 243 |
-
const textInput = document.getElementById('text-input');
|
| 244 |
-
const sampleTextBtn = document.getElementById('sample-text-btn');
|
| 245 |
-
const analyzeBtn = document.getElementById('analyze-text-btn');
|
| 246 |
-
const analysisType = document.getElementById('analysis-type');
|
| 247 |
-
const textResults = document.getElementById('text-results');
|
| 248 |
-
const textOutput = document.getElementById('text-analysis-output');
|
| 249 |
-
|
| 250 |
-
sampleTextBtn.addEventListener('click', () => {
|
| 251 |
-
textInput.value = portfolioData.sampleText;
|
| 252 |
-
});
|
| 253 |
-
|
| 254 |
-
analyzeBtn.addEventListener('click', () => {
|
| 255 |
-
const text = textInput.value.trim();
|
| 256 |
-
|
| 257 |
-
if (!text) {
|
| 258 |
-
alert('Please enter text to analyze.');
|
| 259 |
-
return;
|
| 260 |
-
}
|
| 261 |
-
|
| 262 |
-
analyzeBtn.textContent = 'Analyzing...';
|
| 263 |
-
analyzeBtn.classList.add('loading');
|
| 264 |
-
analyzeBtn.disabled = true;
|
| 265 |
-
|
| 266 |
-
// Simulate analysis
|
| 267 |
-
setTimeout(() => {
|
| 268 |
-
const type = analysisType.value;
|
| 269 |
-
displayTextResults(text, type);
|
| 270 |
-
|
| 271 |
-
analyzeBtn.textContent = 'Analyze Text';
|
| 272 |
-
analyzeBtn.classList.remove('loading');
|
| 273 |
-
analyzeBtn.disabled = false;
|
| 274 |
-
}, 1500);
|
| 275 |
-
});
|
| 276 |
-
|
| 277 |
-
function displayTextResults(text, type) {
|
| 278 |
-
let resultHTML = '';
|
| 279 |
-
|
| 280 |
-
switch (type) {
|
| 281 |
-
case 'sentiment':
|
| 282 |
-
const sentiments = ['positive', 'negative', 'neutral'];
|
| 283 |
-
const sentiment = sentiments[Math.floor(Math.random() * sentiments.length)];
|
| 284 |
-
const confidence = (Math.random() * 0.4 + 0.6).toFixed(2);
|
| 285 |
-
|
| 286 |
-
resultHTML = `
|
| 287 |
-
<div class="analysis-result sentiment-${sentiment}">
|
| 288 |
-
<h4>Sentiment Analysis</h4>
|
| 289 |
-
<p><strong>Sentiment:</strong> ${sentiment.toUpperCase()}</p>
|
| 290 |
-
<p><strong>Confidence:</strong> ${confidence}</p>
|
| 291 |
-
<p><strong>Text length:</strong> ${text.length} characters</p>
|
| 292 |
-
<p><strong>Words:</strong> ${text.split(' ').length}</p>
|
| 293 |
-
</div>
|
| 294 |
-
`;
|
| 295 |
-
break;
|
| 296 |
-
|
| 297 |
-
case 'classification':
|
| 298 |
-
const categories = ['Technology', 'Business', 'Science', 'Education', 'General'];
|
| 299 |
-
const category = categories[Math.floor(Math.random() * categories.length)];
|
| 300 |
-
|
| 301 |
-
resultHTML = `
|
| 302 |
-
<div class="analysis-result">
|
| 303 |
-
<h4>Text Classification</h4>
|
| 304 |
-
<p><strong>Category:</strong> ${category}</p>
|
| 305 |
-
<p><strong>Confidence:</strong> ${(Math.random() * 0.3 + 0.7).toFixed(2)}</p>
|
| 306 |
-
<p><strong>Model:</strong> Fine-tuned Mistral 7B</p>
|
| 307 |
-
</div>
|
| 308 |
-
`;
|
| 309 |
-
break;
|
| 310 |
-
|
| 311 |
-
case 'summary':
|
| 312 |
-
const summaryLength = Math.min(text.length / 3, 150);
|
| 313 |
-
const summary = text.substring(0, summaryLength) + '...';
|
| 314 |
-
|
| 315 |
-
resultHTML = `
|
| 316 |
-
<div class="analysis-result">
|
| 317 |
-
<h4>Text Summarization</h4>
|
| 318 |
-
<p><strong>Summary:</strong></p>
|
| 319 |
-
<p>${summary}</p>
|
| 320 |
-
<p><strong>Compression ratio:</strong> ${(summaryLength / text.length * 100).toFixed(1)}%</p>
|
| 321 |
-
</div>
|
| 322 |
-
`;
|
| 323 |
-
break;
|
| 324 |
-
|
| 325 |
-
case 'keywords':
|
| 326 |
-
const keywords = ['artificial intelligence', 'machine learning', 'efficiency', 'decision-making', 'technology', 'innovation'];
|
| 327 |
-
const selectedKeywords = keywords.sort(() => 0.5 - Math.random()).slice(0, 4);
|
| 328 |
-
|
| 329 |
-
resultHTML = `
|
| 330 |
-
<div class="analysis-result">
|
| 331 |
-
<h4>Keyword Extraction</h4>
|
| 332 |
-
<p><strong>Key terms identified:</strong></p>
|
| 333 |
-
<div class="tech-grid">
|
| 334 |
-
${selectedKeywords.map(keyword => `<span class="tech-tag">${keyword}</span>`).join('')}
|
| 335 |
-
</div>
|
| 336 |
-
<p><strong>Keywords found:</strong> ${selectedKeywords.length}</p>
|
| 337 |
-
</div>
|
| 338 |
-
`;
|
| 339 |
-
break;
|
| 340 |
-
}
|
| 341 |
-
|
| 342 |
-
textOutput.innerHTML = resultHTML;
|
| 343 |
-
textResults.classList.remove('hidden');
|
| 344 |
-
}
|
| 345 |
-
}
|
| 346 |
-
|
| 347 |
-
// Data Visualization Tab Functions
|
| 348 |
-
function initDataVizTab() {
|
| 349 |
-
const csvUpload = document.getElementById('csv-upload');
|
| 350 |
-
const sampleDataBtn = document.getElementById('sample-data-btn');
|
| 351 |
-
const generateChartBtn = document.getElementById('generate-chart-btn');
|
| 352 |
-
const chartType = document.getElementById('chart-type');
|
| 353 |
-
const dataPreview = document.getElementById('data-preview');
|
| 354 |
-
const chartContainer = document.getElementById('chart-container');
|
| 355 |
-
const dataTable = document.getElementById('data-table');
|
| 356 |
-
|
| 357 |
-
let currentData = null;
|
| 358 |
-
let chart = null;
|
| 359 |
-
|
| 360 |
-
sampleDataBtn.addEventListener('click', () => {
|
| 361 |
-
currentData = portfolioData.sampleData;
|
| 362 |
-
displayDataPreview();
|
| 363 |
-
generateChartBtn.disabled = false;
|
| 364 |
-
});
|
| 365 |
-
|
| 366 |
-
csvUpload.addEventListener('change', (e) => {
|
| 367 |
-
const file = e.target.files[0];
|
| 368 |
-
if (file) {
|
| 369 |
-
const reader = new FileReader();
|
| 370 |
-
reader.onload = (e) => {
|
| 371 |
-
try {
|
| 372 |
-
const csv = e.target.result;
|
| 373 |
-
currentData = parseCSV(csv);
|
| 374 |
-
displayDataPreview();
|
| 375 |
-
generateChartBtn.disabled = false;
|
| 376 |
-
} catch (error) {
|
| 377 |
-
alert('Error parsing CSV file. Please check the format.');
|
| 378 |
-
}
|
| 379 |
-
};
|
| 380 |
-
reader.readAsText(file);
|
| 381 |
-
}
|
| 382 |
-
});
|
| 383 |
-
|
| 384 |
-
generateChartBtn.addEventListener('click', () => {
|
| 385 |
-
if (!currentData) return;
|
| 386 |
-
|
| 387 |
-
generateVisualization();
|
| 388 |
-
});
|
| 389 |
-
|
| 390 |
-
chartType.addEventListener('change', () => {
|
| 391 |
-
if (currentData && chart) {
|
| 392 |
-
generateVisualization();
|
| 393 |
-
}
|
| 394 |
-
});
|
| 395 |
-
|
| 396 |
-
function parseCSV(csv) {
|
| 397 |
-
const lines = csv.split('\n').filter(line => line.trim());
|
| 398 |
-
const headers = lines[0].split(',');
|
| 399 |
-
|
| 400 |
-
return lines.slice(1).map(line => {
|
| 401 |
-
const values = line.split(',');
|
| 402 |
-
const obj = {};
|
| 403 |
-
headers.forEach((header, index) => {
|
| 404 |
-
const value = values[index]?.trim();
|
| 405 |
-
obj[header.trim()] = isNaN(value) ? value : parseFloat(value);
|
| 406 |
-
});
|
| 407 |
-
return obj;
|
| 408 |
-
});
|
| 409 |
-
}
|
| 410 |
-
|
| 411 |
-
function displayDataPreview() {
|
| 412 |
-
if (!currentData || currentData.length === 0) return;
|
| 413 |
-
|
| 414 |
-
const headers = Object.keys(currentData[0]);
|
| 415 |
-
const previewData = currentData.slice(0, 5); // Show first 5 rows
|
| 416 |
-
|
| 417 |
-
let tableHTML = `
|
| 418 |
-
<div class="data-table">
|
| 419 |
-
<table>
|
| 420 |
-
<thead>
|
| 421 |
-
<tr>${headers.map(h => `<th>${h}</th>`).join('')}</tr>
|
| 422 |
-
</thead>
|
| 423 |
-
<tbody>
|
| 424 |
-
${previewData.map(row =>
|
| 425 |
-
`<tr>${headers.map(h => `<td>${row[h]}</td>`).join('')}</tr>`
|
| 426 |
-
).join('')}
|
| 427 |
-
</tbody>
|
| 428 |
-
</table>
|
| 429 |
-
</div>
|
| 430 |
-
<p><strong>Total rows:</strong> ${currentData.length}</p>
|
| 431 |
-
`;
|
| 432 |
-
|
| 433 |
-
dataTable.innerHTML = tableHTML;
|
| 434 |
-
dataPreview.classList.remove('hidden');
|
| 435 |
-
}
|
| 436 |
-
|
| 437 |
-
function generateVisualization() {
|
| 438 |
-
const type = chartType.value;
|
| 439 |
-
const canvas = document.getElementById('data-chart');
|
| 440 |
-
|
| 441 |
-
// Destroy existing chart
|
| 442 |
-
if (chart) {
|
| 443 |
-
chart.destroy();
|
| 444 |
-
}
|
| 445 |
-
|
| 446 |
-
// Prepare data based on sample dataset structure
|
| 447 |
-
const labels = currentData.map(item => item.month || item[Object.keys(item)[0]]);
|
| 448 |
-
const datasets = [];
|
| 449 |
-
|
| 450 |
-
// Get numeric columns
|
| 451 |
-
const numericColumns = Object.keys(currentData[0]).filter(key =>
|
| 452 |
-
key !== 'month' && typeof currentData[0][key] === 'number'
|
| 453 |
-
);
|
| 454 |
-
|
| 455 |
-
const colors = ['#1FB8CD', '#FFC185', '#B4413C', '#ECEBD5', '#5D878F'];
|
| 456 |
-
|
| 457 |
-
if (type === 'pie') {
|
| 458 |
-
// Use first numeric column for pie chart
|
| 459 |
-
const column = numericColumns[0];
|
| 460 |
-
datasets.push({
|
| 461 |
-
data: currentData.map(item => item[column]),
|
| 462 |
-
backgroundColor: colors.slice(0, currentData.length),
|
| 463 |
-
borderWidth: 1
|
| 464 |
-
});
|
| 465 |
-
} else {
|
| 466 |
-
// Line, bar, scatter charts
|
| 467 |
-
numericColumns.forEach((column, index) => {
|
| 468 |
-
datasets.push({
|
| 469 |
-
label: column.charAt(0).toUpperCase() + column.slice(1),
|
| 470 |
-
data: currentData.map(item => item[column]),
|
| 471 |
-
backgroundColor: colors[index % colors.length],
|
| 472 |
-
borderColor: colors[index % colors.length],
|
| 473 |
-
borderWidth: 2,
|
| 474 |
-
fill: type === 'line' ? false : true
|
| 475 |
-
});
|
| 476 |
-
});
|
| 477 |
-
}
|
| 478 |
-
|
| 479 |
-
chart = new Chart(canvas, {
|
| 480 |
-
type: type,
|
| 481 |
-
data: {
|
| 482 |
-
labels: labels,
|
| 483 |
-
datasets: datasets
|
| 484 |
-
},
|
| 485 |
-
options: {
|
| 486 |
-
responsive: true,
|
| 487 |
-
maintainAspectRatio: false,
|
| 488 |
-
plugins: {
|
| 489 |
-
title: {
|
| 490 |
-
display: true,
|
| 491 |
-
text: 'Data Visualization'
|
| 492 |
-
},
|
| 493 |
-
legend: {
|
| 494 |
-
display: type !== 'pie'
|
| 495 |
-
}
|
| 496 |
-
},
|
| 497 |
-
scales: type === 'pie' ? {} : {
|
| 498 |
-
y: {
|
| 499 |
-
beginAtZero: true
|
| 500 |
-
}
|
| 501 |
-
}
|
| 502 |
-
}
|
| 503 |
-
});
|
| 504 |
-
|
| 505 |
-
chartContainer.classList.remove('hidden');
|
| 506 |
-
}
|
| 507 |
-
}
|
| 508 |
-
|
| 509 |
-
// Initialize Application
|
| 510 |
-
document.addEventListener('DOMContentLoaded', () => {
|
| 511 |
-
initTabs();
|
| 512 |
-
initScrapingTab();
|
| 513 |
-
initCVTab();
|
| 514 |
-
initTextTab();
|
| 515 |
-
initDataVizTab();
|
| 516 |
-
});
|
| 517 |
-
|
| 518 |
-
// Utility Functions
|
| 519 |
-
function sleep(ms) {
|
| 520 |
-
return new Promise(resolve => setTimeout(resolve, ms));
|
| 521 |
-
}
|
| 522 |
-
|
| 523 |
-
function formatBytes(bytes, decimals = 2) {
|
| 524 |
-
if (bytes === 0) return '0 Bytes';
|
| 525 |
-
|
| 526 |
-
const k = 1024;
|
| 527 |
-
const dm = decimals < 0 ? 0 : decimals;
|
| 528 |
-
const sizes = ['Bytes', 'KB', 'MB', 'GB'];
|
| 529 |
-
|
| 530 |
-
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
| 531 |
-
|
| 532 |
-
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
|
| 533 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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