Travel Sim Card Data Usage Estimator

Travel Sim Card Data Usage Estimator

Your Trip Details


Daily Usage Levels

Estimated Data Needed

Customize Data Consumption Rates

ActivityData per Hour (MB)

Please enter a valid trip duration.

'; if(usageChart) usageChart.destroy(); return; } let breakdown = {}; let totalMB = 0; usageData.activities.forEach(act => { const select = document.getElementById(`usage-${act.id}`); const hoursPerDay = parseInt(select.value, 10); const activityTotal = act.mbPerHour * hoursPerDay * duration; if (activityTotal > 0) { breakdown[act.name] = activityTotal; totalMB += activityTotal; } }); renderResults(totalMB); updateChart(breakdown); } function renderResults(totalMB) { const totalGB = totalMB / 1024; resultsContent.innerHTML = `

Total Estimated Data

${totalGB.toFixed(2)} GB
`; } function updateChart(breakdown) { const ctx = document.getElementById('usageChart').getContext('2d'); const labels = Object.keys(breakdown); const data = Object.values(breakdown).map(mb => mb / 1024); // Convert to GB for chart if (usageChart) { usageChart.destroy(); } usageChart = new Chart(ctx, { type: 'pie', data: { labels: labels, datasets: [{ label: 'Data Usage (GB)', data: data, backgroundColor: ['#4A148C', '#FF6F00', '#00796B', '#D84315', '#546E7A'], }] }, options: { responsive: true, plugins: { legend: { position: 'top' }, title: { display: true, text: 'Data Consumption by Activity' } } } }); } function renderConfig() { configTbody.innerHTML = usageData.activities.map(act => ` ${act.name} `).join(''); } window.updateConfig = function(element) { const { id } = element.dataset; const value = parseFloat(element.value); if (isNaN(value)) return; const activity = usageData.activities.find(a => a.id === id); if (activity) { activity.mbPerHour = value; estimateData(); } } // --- TAB & NAVIGATION --- window.openTab = function(evt, tabName) { const tabContents = document.getElementsByClassName("tab-content"); Array.from(tabContents).forEach(tab => tab.style.display = "none"); const tabButtons = document.getElementsByClassName("tab-btn"); Array.from(tabButtons).forEach(btn => btn.classList.remove("active")); document.getElementById(tabName).style.display = "block"; if (evt) { evt.currentTarget.classList.add("active"); } else { const btnToActivate = Array.from(tabButtons).find(btn => btn.getAttribute('onclick').includes(`'${tabName}'`)); if (btnToActivate) btnToActivate.classList.add("active"); } updateNavButtons(); } window.navigateTabs = function(direction) { const tabs = Array.from(document.querySelectorAll('.tab-btn')); const activeTabIndex = tabs.findIndex(tab => tab.classList.contains('active')); let newIndex = (direction === 'next') ? (activeTabIndex + 1) % tabs.length : (activeTabIndex - 1 + tabs.length) % tabs.length; tabs[newIndex].click(); } function updateNavButtons() { const tabs = Array.from(document.querySelectorAll('.tab-btn')); const activeTabIndex = tabs.findIndex(tab => tab.classList.contains('active')); document.getElementById('prev-btn').style.visibility = activeTabIndex === 0 ? 'hidden' : 'visible'; document.getElementById('next-btn').style.visibility = activeTabIndex === tabs.length - 1 ? 'hidden' : 'visible'; } // --- PDF DOWNLOAD --- if(downloadPdfBtn) { downloadPdfBtn.addEventListener('click', function() { const { jsPDF } = window.jspdf; const contentToDownload = document.getElementById('results-to-download'); if (!contentToDownload || !document.querySelector('.value')) { console.warn("Please generate an estimate before downloading."); return; } const originalButtonText = downloadPdfBtn.innerHTML; downloadPdfBtn.innerHTML = 'Generating...'; downloadPdfBtn.disabled = true; html2canvas(contentToDownload, { scale: 2, useCORS: true }).then(canvas => { const imgData = canvas.toDataURL('image/png'); const pdf = new jsPDF({ orientation: 'p', unit: 'mm', format: 'a4' }); const pdfWidth = pdf.internal.pageSize.getWidth(); const imgProps = pdf.getImageProperties(imgData); const imgHeight = (imgProps.height * pdfWidth) / imgProps.width; pdf.addImage(imgData, 'PNG', 10, 10, pdfWidth - 20, imgHeight > 0 ? imgHeight - 20 : 0); pdf.save('Data-Usage-Estimate.pdf'); }).catch(err => { console.error("Error generating PDF:", err); }).finally(() => { downloadPdfBtn.innerHTML = originalButtonText; downloadPdfBtn.disabled = false; }); }); } // --- INITIALIZATION --- function initializeTool() { populateControls(); estimateData(); renderConfig(); updateNavButtons(); } initializeTool(); });
Scroll to Top