`;
// Simple Bar Chart
html += ``;
reportDisplayEl.innerHTML = html;
}
// PDF Download
function stlbDownloadPDF() {
const reportDisplayElement = document.getElementById('stlb-load-report-display');
if (!reportDisplayElement || reportDisplayElement.innerHTML.includes("Input team members and tasks")) {
alert("Please balance the load first.");
return;
}
let pdfHTML = `
`;
} else {
pdfHTML += `
`
}
// Get structured content from the display to ensure PDF matches what user sees
// Clone the report display, remove the chart for simpler PDF rendering if it's too complex, or try to include
const reportClone = reportDisplayElement.cloneNode(true);
// The chart might render if its simple divs, html2pdf will try
// Let's keep the chart for now and see.
pdfHTML += reportClone.innerHTML;
const pdfContainer = document.getElementById('stlb-report-content-for-pdf');
if(!pdfContainer) return;
pdfContainer.innerHTML = pdfHTML;
// Apply critical styles from CSS variables if html2pdf doesn't pick them up perfectly
pdfContainer.querySelectorAll('.stlb-chart-bar').forEach(bar => {
if(bar.classList.contains('max-load')) {
bar.style.backgroundColor = getComputedStyle(document.documentElement).getPropertyValue('--primary-color');
} else {
bar.style.backgroundColor = getComputedStyle(document.documentElement).getPropertyValue('--accent-color');
}
bar.style.color = 'white'; // Ensure text on bar is visible
});
const opt = {
margin: [0.6, 0.5, 0.6, 0.5], filename: 'Task_Load_Balance_Report.pdf',
image: { type: 'jpeg', quality: 0.98 },
html2canvas: { scale: 2, useCORS: true, logging: false, scrollX: 0, scrollY: 0, windowWidth: pdfContainer.scrollWidth + 50 }, // Add some width for PDF rendering
jsPDF: { unit: 'in', format: 'letter', orientation: 'portrait' },
pagebreak: { mode: ['avoid-all', 'css', 'legacy'] }
};
html2pdf().from(pdfContainer).set(opt).save().then(() => {
pdfContainer.innerHTML = '';
}).catch(err => {
console.error("Error generating PDF:", err);
pdfContainer.innerHTML = '';
alert("An error occurred while generating the PDF. Check console for details.");
});
}
Load Distribution Chart:
`; const maxLoadVal = Math.max(...memberLoads.map(ml => ml.totalEffort), 0); // Ensure maxLoadVal is not 0 to avoid division by zero if all loads are 0 const chartScaleFactor = maxLoadVal > 0 ? (100 / maxLoadVal) : 0; // Percentage for max bar width memberLoads.forEach(member => { const barWidth = member.totalEffort * chartScaleFactor; const isMax = member.totalEffort === maxLoadVal && maxLoadVal > 0; html += ``; }); html += `Task Load Balancing Report
`; pdfHTML += `Team Members (${stlbMembers.length})
- `;
stlbMembers.forEach(m => pdfHTML += `
- ${m.name} `); pdfHTML += `
Input Tasks (${stlbTasks.length})
`; if(stlbTasks.length > 0){ pdfHTML += `| Task Name | Estimated Effort |
|---|---|
| ${task.name} | ${task.effort} |
No tasks were input.
