Geopolitical Events Tracker

Geopolitical Events Tracker

${event.description}

`; eventListContainer.appendChild(eventItem); }); } function filterEvents() { const start = new Date(startDateInput.value); const end = new Date(endDateInput.value); const selectedType = eventTypeSelect.value; const filtered = allEvents.filter(event => { const eventDate = new Date(event.date); const isInDateRange = eventDate >= start && eventDate <= end; const isOfType = selectedType === 'all' || event.type === selectedType; return isInDateRange && isOfType; }); renderEvents(filtered); } filterEventsButton.addEventListener('click', filterEvents); downloadPdfButton.addEventListener('click', function() { const { jsPDF } = window.jspdf; const doc = new jsPDF(); doc.setFontSize(22); doc.text(toolTitle.textContent, doc.internal.pageSize.getWidth() / 2, 20, { align: 'center' }); doc.setFontSize(12); doc.text(`Filtered by:`, 15, 35); doc.text(`Start Date: ${startDateInput.value}`, 15, 42); doc.text(`End Date: ${endDateInput.value}`, 15, 49); doc.text(`Event Type: ${eventTypeSelect.options[eventTypeSelect.selectedIndex].text}`, 15, 56); const eventsForPdf = []; const eventItems = eventListContainer.querySelectorAll('.event-item'); if (eventItems.length === 0) { doc.text("No events to display.", doc.internal.pageSize.getWidth() / 2, 70, { align: 'center' }); } else { eventItems.forEach(item => { const name = item.querySelector('strong').textContent; const date = item.querySelector('.event-date').textContent.replace('Date: ', ''); const type = item.querySelector('.event-type').textContent.replace('Type: ', ''); const description = item.querySelector('.event-description').textContent; eventsForPdf.push([date, name, type, description]); }); doc.autoTable({ startY: 70, head: [['Date', 'Event Name', 'Type', 'Description']], body: eventsForPdf, theme: 'grid', styles: { font: 'helvetica', fontSize: 9, cellPadding: 3, overflow: 'linebreak', halign: 'left', valign: 'middle' }, headStyles: { fillColor: [52, 152, 219], /* Consistent with tool's blue */ textColor: [255, 255, 255], fontStyle: 'bold' }, alternateRowStyles: { fillColor: [236, 240, 241] /* Consistent with event item background */ }, didDrawPage: function (data) { // Footer for page numbers let str = "Page " + doc.internal.getNumberOfPages(); doc.setFontSize(10); doc.text(str, data.settings.margin.left, doc.internal.pageSize.height - 10); } }); } doc.save('Geopolitical_Events_Tracker.pdf'); }); // Initial render of all events filterEvents(); });
Scroll to Top