Acoustic Velocity Converter

${originalValue.toLocaleString()} ${unitLabels[originalUnit]} = ${convertedValue.toLocaleString(undefined, {maximumFractionDigits: 2})} ${unitLabels[targetUnit]}

`; // 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 = unitLabels[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 createVelocityScale(mps); document.getElementById('results').style.display = 'block'; } function createVelocityScale(currentVelocity) { const scale = document.getElementById('velocity-scale'); scale.innerHTML = ''; // Find min and max reference velocities const refValues = Object.values(referenceVelocities); const minVelocity = Math.min(...refValues); const maxVelocity = Math.max(...refValues); // Create scale bar const scaleBar = document.createElement('div'); scaleBar.className = 'scale-bar'; scale.appendChild(scaleBar); // Add reference markers for (const [name, velocity] of Object.entries(referenceVelocities)) { const position = ((velocity - minVelocity) / (maxVelocity - minVelocity)) * 100; const marker = document.createElement('div'); marker.className = 'scale-marker'; marker.style.left = `${position}%`; const label = document.createElement('div'); label.className = 'scale-label'; label.style.left = `${position}%`; label.textContent = name; scale.appendChild(marker); scale.appendChild(label); } // Add current velocity marker if within range if (currentVelocity >= minVelocity && currentVelocity <= maxVelocity) { const position = ((currentVelocity - minVelocity) / (maxVelocity - minVelocity)) * 100; const currentMarker = document.createElement('div'); currentMarker.className = 'scale-marker'; currentMarker.style.left = `${position}%`; currentMarker.style.backgroundColor = '#000'; currentMarker.style.width = '4px'; const currentLabel = document.createElement('div'); currentLabel.className = 'scale-label'; currentLabel.style.left = `${position}%`; currentLabel.textContent = 'Your Value'; currentLabel.style.fontWeight = 'bold'; scale.appendChild(currentMarker); scale.appendChild(currentLabel); } } function generatePDF() { try { const { jsPDF } = window.jspdf; const doc = new jsPDF(); // Title doc.setFontSize(18); doc.text('Acoustic Velocity 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 velocity scale visualization is available in the web version.', 14, yPos); // Save PDF doc.save('Acoustic_Velocity_Conversion_Report.pdf'); } catch (error) { console.error('PDF generation error:', error); alert('PDF generation failed. Please try again or check your internet connection.'); } }
Scroll to Top