`;
// 2. Setup Table
html += `
I. Setup & Conditions
| Observer | ${data.observer} |
| Equipment | ${data.scope} |
| Seeing (1-5) | ${data.seeing} / 5 |
| Transparency | ${data.transparency} |
`;
// 3. Log Table
if (logData.length > 0) {
html += `
II. Observation Entries
`;
let tableHtml = `
| Object ID |
Time (UTC) |
Magnification |
Observation Notes |
`;
logData.forEach(item => {
tableHtml += `
| ${item.id} |
${item.time} |
${item.mag} |
${item.notes} |
`;
});
tableHtml += `
`;
html += tableHtml;
}
// 4. Sketch/Notes Area
html += `
III. Sketch / Further Notes
`;
html += `
`;
container.innerHTML = html;
}
function aolgSwitchTab(tabId) {
document.querySelectorAll('.aolg-tab-btn').forEach(b => b.classList.remove('active'));
document.querySelectorAll('.aolg-content').forEach(c => c.classList.remove('active'));
const idx = tabId === 'builder' ? 0 : 1;
document.querySelectorAll('.aolg-tab-btn')[idx].classList.add('active');
document.getElementById('aolg-' + tabId).classList.add('active');
if (tabId === 'preview') {
aolgRenderReport();
}
}
function aolgLoadExample() {
if(!confirm("Overwrite current data with example observation entries?")) return;
document.getElementById('inp-observer').value = "Dr. M. Chen";
document.getElementById('inp-location').value = "Dark Sky Preserve, Arizona";
document.getElementById('inp-scope').value = "14-inch SCT with Equatorial Mount";
document.getElementById('inp-seeing').value = "4";
document.getElementById('inp-transparency').value = "Magnitude 6.5+";
// Clear and fill log entries
document.getElementById('aolg-log-rows-container').innerHTML = '';
aolgAddLogRow("M31", "01:00", "25x", "Core is bright, dust lanes barely visible, M32/M110 companions seen in same FOV.");
aolgAddLogRow("M57 (Ring)", "02:15", "100x", "Clearly toroidal shape. Faint color noted (greenish).");
aolgAddLogRow("Jupiter", "03:00", "200x", "Four Galilean moons visible. Great Red Spot not visible; equatorial bands sharp.");
aolgRenderReport();
aolgSwitchTab('preview');
}
/* --- PDF Generation --- */
async function aolgGeneratePDF() {
aolgRenderReport(); // Final render check
const logData = aolgGetLogData();
const meta = {
observer: document.getElementById('inp-observer').value || "Observer Name",
date: document.getElementById('inp-date').value || "N/A Date",
location: document.getElementById('inp-location').value || "N/A Location",
scope: document.getElementById('inp-scope').value || "N/A Scope",
seeing: document.getElementById('inp-seeing').value,
transparency: document.getElementById('inp-transparency').value || "N/A"
};
if (logData.length === 0) {
alert("Please add observation entries before generating the PDF.");
return;
}
const { jsPDF } = window.jspdf;
const doc = new jsPDF('p', 'mm', 'a4');
const navy = [30, 58, 138];
let y = 20;
// 1. Header
doc.setFillColor(...navy);
doc.rect(0, 0, 210, 20, 'F');
doc.setTextColor(255, 255, 255);
doc.setFontSize(16);
doc.text(`ASTRONOMY OBSERVATION LOG`, 105, 10, { align: 'center' });
// 2. Metadata Block
y = 30;
doc.setFontSize(10);
doc.setFont("helvetica", "bold");
doc.setTextColor(0, 0, 0);
const metaTable = [
['Observer/Group', data.observer, 'Date', data.date],
['Location', data.location, 'Equipment', data.scope],
['Seeing (1-5)', data.seeing, 'Transparency', data.transparency]
];
doc.autoTable({
startY: y,
body: metaTable,
theme: 'grid',
styles: { fontSize: 9 },
headStyles: { fillColor: [240, 240, 240] },
columnStyles: { 0: { cellWidth: 30, fontStyle: 'bold' }, 2: { cellWidth: 30, fontStyle: 'bold' } }
});
y = doc.lastAutoTable.finalY + 10;
// 3. Log Table
doc.setFontSize(12);
doc.setFont("helvetica", "bold");
doc.setTextColor(...navy);
doc.text("Observation Entries", 14, y);
y += 5;
const tableBody = logData.map(item => [
item.id,
item.time,
item.mag,
item.notes
]);
doc.autoTable({
startY: y,
head: [['Object ID', 'Time (UTC)', 'Magnification', 'Observation Notes']],
body: tableBody,
theme: 'grid',
headStyles: { fillColor: navy, fontSize: 10 },
styles: { fontSize: 9 },
columnStyles: {
0: { cellWidth: 20, fontStyle: 'bold' },
1: { cellWidth: 20 },
2: { cellWidth: 25 },
3: { cellWidth: 'auto', overflow: 'linebreak' }
}
});
y = doc.lastAutoTable.finalY + 10;
// 4. Notes Area
doc.setFontSize(10);
doc.text("Sketch / Further Notes:", 14, y);
doc.setDrawColor(150);
doc.rect(14, y + 2, 182, 50, 'S'); // Box for sketching/notes
doc.save(`AstronomyLog_${meta.date.replace(/\s/g, '_')}.pdf`);
}