Real Estate Price Trends Viewer

Real Estate Price Trends Viewer

Analyze simulated market trends for various property types.

Trend Analysis

No results to display. Please perform a search first.

No trend data found for the selected criteria.

'; dynamicChartContainer.innerHTML = ''; if (resultLocationSpan) resultLocationSpan.textContent = "N/A"; if (resultPropertyTypeSpan) resultPropertyTypeSpan.textContent = "N/A"; if (resultTimePeriodSpan) resultTimePeriodSpan.textContent = "N/A"; if (noResultsMessage) { noResultsMessage.textContent = "No trend data found for the selected criteria. Try a different search (e.g., 'New York', 'Residential', 'Last 3 Years')."; noResultsMessage.classList.remove('hidden'); } if (resultsDataContainer) resultsDataContainer.classList.add('hidden'); // Hide data section, show main message } // --- PDF Generation --- async function generateAndDownloadPdf() { if (typeof jspdf === 'undefined' || typeof html2canvas === 'undefined') { console.error("jsPDF or html2canvas library is not loaded."); alert("Error: PDF generation library not loaded. Please try again later."); return; } const { jsPDF } = jspdf; const pdf = new jsPDF({ orientation: 'p', unit: 'pt', format: 'a4' }); const contentToPrint = document.getElementById('resultsDataContainer'); if (!contentToPrint) { console.error("Results content area not found for PDF generation."); alert("Error: Could not find content to generate PDF."); return; } // Temporarily remove "no-print" elements for PDF generation const elementsToHide = contentToPrint.querySelectorAll('.no-print-in-pdf'); // A specific class if needed for finer control elementsToHide.forEach(el => el.style.display = 'none'); const pdfTitle = `Real Estate Price Trends: ${resultLocationSpan.textContent || 'N/A'}`; const filename = `RealEstateTrends_${(resultLocationSpan.textContent || 'Report').replace(/[^a-z0-9]/gi, '_')}.pdf`; try { // Add title pdf.setFontSize(18); pdf.text(pdfTitle, 40, 40); // Add summary pdf.setFontSize(12); pdf.text(`Property Type: ${resultPropertyTypeSpan.textContent || 'N/A'}`, 40, 60); pdf.text(`Time Period: ${(resultTimePeriodSpan.textContent || 'N/A').replace(/_/g, ' ')}`, 40, 75); // Use html2canvas to render table and chart const canvasOptions = { scale: 2, // Higher scale for better quality useCORS: true, // If images/external resources were used backgroundColor: '#ffffff' // Ensure background is white }; const tableElement = resultsTableContainer.querySelector('table'); let yPos = 100; if (tableElement) { const tableCanvas = await html2canvas(tableElement, canvasOptions); const tableImgData = tableCanvas.toDataURL('image/png'); const imgPropsTable = pdf.getImageProperties(tableImgData); const pdfWidth = pdf.internal.pageSize.getWidth() - 80; // 40pt margin on each side const pdfHeightTable = (imgPropsTable.height * pdfWidth) / imgPropsTable.width; if (yPos + pdfHeightTable > pdf.internal.pageSize.getHeight() - 40) { pdf.addPage(); yPos = 40; } pdf.addImage(tableImgData, 'PNG', 40, yPos, pdfWidth, pdfHeightTable); yPos += pdfHeightTable + 20; // Add some space } const chartElement = document.getElementById('dynamicChart'); if (chartElement && chartElement.children.length > 0) { // Check if chart has content pdf.setFontSize(14); if (yPos + 20 > pdf.internal.pageSize.getHeight() - 100) { // Check if space for chart title + chart pdf.addPage(); yPos = 40; } pdf.text("Price Trend Chart (Simulated)", 40, yPos); yPos += 15; const chartCanvas = await html2canvas(chartElement, canvasOptions); const chartImgData = chartCanvas.toDataURL('image/png'); const imgPropsChart = pdf.getImageProperties(chartImgData); const pdfWidthChart = pdf.internal.pageSize.getWidth() - 80; const pdfHeightChart = (imgPropsChart.height * pdfWidthChart) / imgPropsChart.width; if (yPos + pdfHeightChart > pdf.internal.pageSize.getHeight() - 40) { pdf.addPage(); yPos = 40; } pdf.addImage(chartImgData, 'PNG', 40, yPos, pdfWidthChart, pdfHeightChart); } pdf.save(filename); } catch (error) { console.error("Error generating PDF:", error); alert("An error occurred while generating the PDF. Please check the console for details."); } finally { // Restore display of "no-print" elements elementsToHide.forEach(el => el.style.display = ''); } }
Scroll to Top