Radioactivity Unit Converter
Conversion Results
| Unit | Value |
|---|
Activity Level Comparison
1 Bq = 1 disintegration per second
`; // Populate table const tableBody = document.getElementById('result-table-body'); tableBody.innerHTML = ''; for (const [unit, value] of Object.entries(allConversions)) { const row = document.createElement('tr'); const cell1 = document.createElement('td'); cell1.textContent = unit; row.appendChild(cell1); const cell2 = document.createElement('td'); cell2.textContent = value.toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 }); row.appendChild(cell2); tableBody.appendChild(row); } // Create visualization createActivityComparison(bq); document.getElementById('results').style.display = 'block'; } function createActivityComparison(currentActivity) { const comparison = document.getElementById('activity-comparison'); comparison.innerHTML = ''; // Add title const title = document.createElement('div'); title.className = 'comparison-title'; title.textContent = 'Activity Level Comparison'; comparison.appendChild(title); // Find max activity for scaling const maxActivity = Math.max(...Object.values(referenceActivities), currentActivity); // Add reference activities for (const [name, activity] of Object.entries(referenceActivities)) { const barHeight = (activity / maxActivity) * 150; const barGroup = document.createElement('div'); barGroup.className = 'activity-bar-container'; const bar = document.createElement('div'); bar.className = 'activity-bar'; bar.style.height = `${barHeight}px`; const valueLabel = document.createElement('div'); valueLabel.className = 'activity-value'; valueLabel.textContent = activity.toExponential(2) + ' Bq'; const nameLabel = document.createElement('div'); nameLabel.className = 'activity-label'; nameLabel.textContent = name; barGroup.appendChild(valueLabel); barGroup.appendChild(bar); barGroup.appendChild(nameLabel); comparison.appendChild(barGroup); } // Add current activity if different from references if (!Object.values(referenceActivities).includes(currentActivity)) { const barHeight = (currentActivity / maxActivity) * 150; const barGroup = document.createElement('div'); barGroup.className = 'activity-bar-container'; const bar = document.createElement('div'); bar.className = 'activity-bar'; bar.style.height = `${barHeight}px`; bar.style.backgroundColor = '#e74a3b'; const valueLabel = document.createElement('div'); valueLabel.className = 'activity-value'; valueLabel.textContent = currentActivity.toExponential(2) + ' Bq'; const nameLabel = document.createElement('div'); nameLabel.className = 'activity-label'; nameLabel.textContent = 'Your Activity'; barGroup.appendChild(valueLabel); barGroup.appendChild(bar); barGroup.appendChild(nameLabel); comparison.appendChild(barGroup); } } function generatePDF() { try { const { jsPDF } = window.jspdf; const doc = new jsPDF(); // Title doc.setFontSize(18); doc.text('Radioactivity Conversion Report', 105, 15, { align: 'center' }); // Date doc.setFontSize(10); doc.text(`Generated: ${new Date().toLocaleString()}`, 105, 22, { align: 'center' }); // Add conversion result doc.setFontSize(14); const resultText = document.getElementById('result-values').textContent; doc.text(resultText, 14, 40); // Add table data doc.setFontSize(12); const table = document.getElementById('result-table-body'); const rows = table.querySelectorAll('tr'); let yPos = 60; rows.forEach(row => { const cells = row.querySelectorAll('td'); doc.text(`${cells[0].textContent}: ${cells[1].textContent}`, 20, yPos); yPos += 7; }); // Add note about visualization yPos += 10; doc.text('Note: The activity comparison visualization is available in the web version.', 14, yPos); // Save PDF doc.save('Radioactivity_Conversion_Report.pdf'); } catch (error) { console.error('PDF generation error:', error); alert('PDF generation failed. Please try again or check your internet connection.'); } }