// Handles cluster naming event import { nameCluster } from './cluster_naming.js'; import { updateScatter } from './plotting.js'; export async function handleNamingEvent() { const progressBar = document.getElementById("progress-bar"); const progressBarInner = document.getElementById("progress-bar-inner"); progressBar.style.display = "block"; progressBarInner.style.width = "0%"; const text = document.getElementById("input").value; // Reconstruct clusters from textarea (split by triple newlines) const clustered = text.split(/\n{3,}/).map(group => group.split('\n').filter(line => line && !line.startsWith('##')) ); const k = clustered.length; const clusterNames = []; for (let c = 0; c < k; ++c) { progressBarInner.style.width = `${Math.round(((c + 1) / k) * 100)}%`; const name = await nameCluster(clustered[c]); clusterNames.push(name || `Cluster ${c + 1}`); // Update UMAP scatter plot legend with new cluster names if (window.traces && window.traces[c]) { window.traces[c].name = clusterNames[c]; } } // Update textarea with cluster names as markdown headers document.getElementById("input").value = clustered.map((g, i) => `## ${clusterNames[i]}\n${g.join("\n")}` ).join("\n\n\n"); // Update UMAP scatter plot if traces are available if (window.traces) { updateScatter(window.traces, k); } progressBarInner.style.width = "100%"; }