export function renderWorstTenAnalysisChart( analysisData, containerId, tableContainerId, ) { // Pulizia del contenitore del grafico const chartContainer = document.querySelector(`#${containerId}`); if (chartContainer) { chartContainer.innerHTML = ""; } else { console.error(`Contenitore del grafico non trovato: #${containerId}`); return; } // Validazione dei dati if (!Array.isArray(analysisData) || analysisData.length === 0) { chartContainer.innerHTML = '

No failed tests to display.

'; const tableContainer = document.querySelector(`#${tableContainerId}`); if (tableContainer) { tableContainer.innerHTML = '

No failed tests to display.

'; } return; } const labels = analysisData.map((item) => item.name || "Unknown"); const data = analysisData.map((item) => parseInt(item.failCount, 10) || 0); console.log("Dati per il grafico Worst Analysis:", { labels, data }); // Verifica se ci sono dati validi da visualizzare const hasValidData = analysisData.some((item) => item.failCount > 0); if (!hasValidData) { chartContainer.innerHTML = '

No failed tests to display.

'; const tableContainer = document.querySelector(`#${tableContainerId}`); if (tableContainer) { tableContainer.innerHTML = '

No failed tests to display.

'; } return; } // Configurazione del grafico a barre orizzontali const options = { series: [ { name: "Failed Tests", data: data, }, ], chart: { type: "bar", height: 400, toolbar: { show: true, tools: { download: true, selection: false, zoom: false, zoomin: false, zoomout: false, pan: false, reset: false, }, }, }, plotOptions: { bar: { horizontal: true, barHeight: "80%", }, }, dataLabels: { enabled: false, }, xaxis: { categories: labels, title: { text: "Number of Failed Tests", }, }, yaxis: { title: { text: "Analysis", }, }, colors: ["#FF4D4D"], fill: { opacity: 1, }, tooltip: { y: { formatter: function (val) { return val + " failed tests"; }, }, }, }; // Render del grafico const chart = new ApexCharts(chartContainer, options); chart.render(); // Genera una tabella per i dati const tableHTML = ` ${analysisData .map( (item) => ` `, ) .join("")}
Analysis Failed Tests
${item.name || "Unknown"} ${parseInt(item.failCount, 10) || 0}
`; // Riprova a trovare il contenitore della tabella con un ritardo const renderTable = () => { const tableContainer = document.querySelector(`#${tableContainerId}`); if (tableContainer) { tableContainer.innerHTML = tableHTML; } else { console.error( `Contenitore della tabella non trovato: #${tableContainerId}`, ); } }; // Prova immediatamente e riprova dopo un breve ritardo renderTable(); setTimeout(renderTable, 100); }