Navigational Data
- Latitude:
- ${D.latitude}
- Longitude:
- ${D.longitude}
- Course (COG/T):
- ${D.course}°
- Speed (SOG):
- ${D.speed} kts
Weather & Environment
- Wind (Dir/Spd):
- ${D.windDir} at ${D.windSpeed} kts
- Barometer:
- ${D.barometer} hPa
- Air Temp:
- ${D.airTemp} °C
- Sea State (Scale):
- ${D.seaState}
- Cloud Cover:
- ${D.cloudCover}%
Operational Status
- Sails Set:
- ${D.sailsSet}
- Engine Run Time:
- ${D.engineHours} hrs
- Fuel Remaining:
- ${D.fuelRemaining}%
Log Narrative
${D.logNotes || 'No specific notes recorded.'}
`; } // --- Tab Switching --- function svle_showTab(targetId, element) { tabButtons.forEach(btn => btn.classList.remove('svle-active')); document.querySelectorAll('.svle-tab-content').forEach(content => content.classList.remove('active')); if (element) { element.classList.add('svle-active'); } document.getElementById(targetId).classList.add('active'); if (targetId === 'viewer') { svle_renderLogEntry(); } } window.svle_showTab = svle_showTab; // --- PDF Export --- function svle_downloadPDF() { if (typeof jspdf === 'undefined' || typeof jspdf.plugin.autotable === 'undefined') { alert('Error: PDF library not fully loaded for export.'); return; } svle_renderLogEntry(); const D = SVLE_DATA; const { jsPDF } = jspdf; const doc = new jsPDF({ orientation: 'p', unit: 'pt', format: 'a4' }); doc.setFont('sans-serif', 'normal'); const margin = 40; const pageWidth = doc.internal.pageSize.getWidth(); const contentWidth = pageWidth - margin * 2; let yPos = margin; // --- Header --- doc.setFontSize(20); doc.setFont('sans-serif', 'bold'); doc.setTextColor('#1e3a8a'); // Navy doc.text("Voyage Log Entry", pageWidth / 2, yPos, { align: 'center' }); yPos += 25; doc.setFontSize(10); doc.setFont('sans-serif', 'normal'); doc.setTextColor('#4b5563'); doc.text(`Time: ${D.logTime} UTC | Date: ${svle_formatDate(D.logDate)}`, pageWidth / 2, yPos, { align: 'center' }); yPos += 30; // --- Navigational Data --- doc.setFontSize(12); doc.setFont('sans-serif', 'bold'); doc.setTextColor('#1f2937'); doc.text("Navigational & Operational Data:", margin, yPos); yPos += 15; const navOpData = [ ['Latitude:', D.latitude, 'Longitude:', D.longitude], ['Course (COG/T):', `${D.course}°`, 'Speed (SOG/kts):', D.speed], ['Engine Run Time (hrs):', D.engineHours, 'Fuel Remaining (%):', D.fuelRemaining], ['Sails Set:', D.sailsSet, '', ''] ]; doc.autoTable({ body: navOpData, startY: yPos, theme: 'striped', styles: { fontSize: 9, cellPadding: 5 }, headStyles: { fillColor: [240, 248, 255] }, columnStyles: { 0: { fontStyle: 'bold', cellWidth: 100 }, 2: { fontStyle: 'bold', cellWidth: 100 } }, didDrawPage: function(data) { yPos = data.cursor.y; } }); yPos = doc.lastAutoTable.finalY + 20; // --- Weather Data --- doc.setFontSize(12); doc.text("Weather & Environmental Conditions:", margin, yPos); yPos += 15; const weatherData = [ ['Wind Direction (T):', D.windDir, 'Wind Speed (kts):', D.windSpeed], ['Barometer (hPa):', D.barometer, 'Sea State (Scale):', D.seaState], ['Air Temperature (°C):', D.airTemp, 'Cloud Cover (%):', D.cloudCover] ]; doc.autoTable({ body: weatherData, startY: yPos, theme: 'striped', styles: { fontSize: 9, cellPadding: 5 }, columnStyles: { 0: { fontStyle: 'bold', cellWidth: 100 }, 2: { fontStyle: 'bold', cellWidth: 100 } }, didDrawPage: function(data) { yPos = data.cursor.y; } }); yPos = doc.lastAutoTable.finalY + 20; // --- Narrative Notes --- doc.setFontSize(12); doc.text("Narrative / Watch Notes:", margin, yPos); yPos += 15; doc.setFontSize(10); doc.setTextColor('#4b5563'); const noteLines = doc.splitTextToSize(D.logNotes || 'No specific notes recorded.', contentWidth); doc.text(noteLines, margin, yPos); yPos += (noteLines.length * 12) + 20; doc.save(`Voyage_Log_Entry_${D.logDate}.pdf`); } // --- Initialization --- document.addEventListener('DOMContentLoaded', () => { // 1. Set default date document.getElementById('logDate').value = new Date().toISOString().slice(0, 10); // 2. Attach listeners document.getElementById('input-next-btn').addEventListener('click', () => svle_showTab('viewer', document.querySelector('.svle-tab-btn[data-tab="viewer"]'))); document.getElementById('svle-download-pdf').addEventListener('click', svle_downloadPDF); tabButtons.forEach(btn => { btn.addEventListener('click', (e) => svle_showTab(e.target.dataset.tab, e.target)); }); });