`;
document.getElementById('analyzed-text-output').innerHTML = analysisResults.sentenceDetails.map(s =>
`${s.text}`
).join(' ');
const ctx = document.getElementById('variation-chart').getContext('2d');
if (variationChart) variationChart.destroy();
variationChart = new Chart(ctx, { type: 'bar', data: {
labels: ['Short', 'Medium', 'Long'],
datasets: [{
label: '# of Sentences',
data: [analysisResults.shortCount, analysisResults.mediumCount, analysisResults.longCount],
backgroundColor: ['#dbeafe', '#dcfce7', '#fee2e2'],
borderColor: ['#bfdbfe', '#bbf7d0', '#fecaca'],
borderWidth: 1
}]
}, options: { responsive: true, maintainAspectRatio: false, plugins: { legend: { display: false } } } });
}
// --- PDF GENERATION ---
async function generatePdfReport() {
downloadPdfBtn.disabled = true;
downloadPdfBtn.textContent = 'Generating...';
const reportHtml = `
`;
const pdfTemplate = document.getElementById('pdf-template');
pdfTemplate.innerHTML = reportHtml;
pdfTemplate.classList.remove('invisible');
new Chart(document.getElementById('pdf-variation-chart'), { type: 'bar', data: variationChart.data, options: { ...variationChart.options, animation: { duration: 0 }, maintainAspectRatio: false } });
try {
const { jsPDF } = window.jspdf;
const canvas = await html2canvas(pdfTemplate.querySelector('.pdf-page'), { scale: 2 });
const imgData = canvas.toDataURL('image/png');
const pdf = new jsPDF({ orientation: 'p', unit: 'pt', format: 'a4' });
const pdfWidth = pdf.internal.pageSize.getWidth();
const pdfHeight = (canvas.height * pdfWidth) / canvas.width;
pdf.addImage(imgData, 'PNG', 0, 0, pdfWidth, pdfHeight);
pdf.save('Sentence_Analysis_Report.pdf');
} catch (e) { console.error('PDF Generation Error:', e); } finally {
downloadPdfBtn.disabled = false;
downloadPdfBtn.textContent = 'Download Analysis Report';
pdfTemplate.classList.add('invisible');
pdfTemplate.innerHTML = '';
}
}
// --- EVENT LISTENERS ---
analyzeBtn.addEventListener('click', runAnalysis);
downloadPdfBtn.addEventListener('click', generatePdfReport);
// --- INITIALIZATION ---
// No tabs
});
Writing Analysis Report
Generated on: ${new Date().toLocaleDateString()}
SENTENCES
${analysisResults.sentenceCount}
AVG. LENGTH
${analysisResults.avgSentenceLength}
READABILITY
${analysisResults.readability}
Sentence Length Distribution
Analyzed Text
${analysisResults.sentenceDetails.map(s => `${s.text}`).join(' ')}
