Historic Home Renovation Cost Estimator

Historic Home Renovation Cost Estimator

Project Scope

Estimated Renovation Cost

Customize Cost Data

Please enter valid details and select at least one area.

'; if(costBreakdownChart) costBreakdownChart.destroy(); return; } let breakdown = {}; let subtotal = 0; selectedAreas.forEach(areaId => { const area = costData.areas.find(a => a.id === areaId); if (area) { const areaCost = area.costPerSqFt * sqft * condition.multiplier; breakdown[area.name] = areaCost; subtotal += areaCost; } }); const contingency = subtotal * (costData.contingencyPercent / 100); breakdown['Contingency Fund'] = contingency; const totalCost = subtotal + contingency; renderResults(totalCost); updateChart(breakdown); } function renderResults(total) { resultsContent.innerHTML = `

Total Estimated Cost

$${total.toLocaleString('en-US', {maximumFractionDigits: 0})}
Includes a ${costData.contingencyPercent}% contingency fund.
`; } function updateChart(breakdown) { const ctx = document.getElementById('costBreakdownChart').getContext('2d'); const labels = Object.keys(breakdown); const data = Object.values(breakdown); if (costBreakdownChart) { costBreakdownChart.destroy(); } costBreakdownChart = new Chart(ctx, { type: 'pie', data: { labels: labels, datasets: [{ data: data, backgroundColor: ['#5D4037', '#006064', '#78909C', '#8D6E63', '#00838F', '#455A64', '#A1887F', '#0097A7'], }] }, options: { responsive: true, plugins: { legend: { position: 'top' }, title: { display: true, text: 'Cost Breakdown by Area' } } } }); } function renderConfig() { configContainer.innerHTML = `

Area Costs (per sq. ft.)

${costData.areas.map(a => ``).join('')}
AreaCost ($/sqft)
${a.name}

General Assumptions

ItemValue (%)
Contingency Fund
`; } window.updateConfig = function(element) { const { type, id, prop } = element.dataset; const value = parseFloat(element.value); if (isNaN(value)) return; if (type === 'areas') { const item = costData.areas.find(i => i.id === id); if (item) item[prop] = value; } else { costData[prop] = value; } estimateCost(); } // --- TAB & NAVIGATION --- window.openTab = function(evt, tabName) { const tabContents = document.getElementsByClassName("tab-content"); Array.from(tabContents).forEach(tab => tab.style.display = "none"); const tabButtons = document.getElementsByClassName("tab-btn"); Array.from(tabButtons).forEach(btn => btn.classList.remove("active")); document.getElementById(tabName).style.display = "block"; if (evt) { evt.currentTarget.classList.add("active"); } else { const btnToActivate = Array.from(tabButtons).find(btn => btn.getAttribute('onclick').includes(`'${tabName}'`)); if (btnToActivate) btnToActivate.classList.add("active"); } updateNavButtons(); } window.navigateTabs = function(direction) { const tabs = Array.from(document.querySelectorAll('.tab-btn')); const activeTabIndex = tabs.findIndex(tab => tab.classList.contains('active')); let newIndex = (direction === 'next') ? (activeTabIndex + 1) % tabs.length : (activeTabIndex - 1 + tabs.length) % tabs.length; tabs[newIndex].click(); } function updateNavButtons() { const tabs = Array.from(document.querySelectorAll('.tab-btn')); const activeTabIndex = tabs.findIndex(tab => tab.classList.contains('active')); document.getElementById('prev-btn').style.visibility = activeTabIndex === 0 ? 'hidden' : 'visible'; document.getElementById('next-btn').style.visibility = activeTabIndex === tabs.length - 1 ? 'hidden' : 'visible'; } // --- PDF DOWNLOAD --- if(downloadPdfBtn) { downloadPdfBtn.addEventListener('click', function() { const { jsPDF } = window.jspdf; const contentToDownload = document.getElementById('results-to-download'); if (!contentToDownload || !document.querySelector('.value')) { console.warn("Please generate an estimate before downloading."); return; } const originalButtonText = downloadPdfBtn.innerHTML; downloadPdfBtn.innerHTML = 'Generating...'; downloadPdfBtn.disabled = true; html2canvas(contentToDownload, { scale: 2, useCORS: true }).then(canvas => { const imgData = canvas.toDataURL('image/png'); const pdf = new jsPDF({ orientation: 'p', unit: 'mm', format: 'a4' }); const pdfWidth = pdf.internal.pageSize.getWidth(); const imgProps = pdf.getImageProperties(imgData); const imgHeight = (imgProps.height * pdfWidth) / imgProps.width; pdf.addImage(imgData, 'PNG', 10, 10, pdfWidth - 20, imgHeight > 0 ? imgHeight - 20 : 0); pdf.save('Historic-Renovation-Estimate.pdf'); }).catch(err => { console.error("Error generating PDF:", err); }).finally(() => { downloadPdfBtn.innerHTML = originalButtonText; downloadPdfBtn.disabled = false; }); }); } // --- INITIALIZATION --- function initializeTool() { populateControls(); estimateCost(); renderConfig(); updateNavButtons(); } initializeTool(); });
Scroll to Top