Spaces:
Running
Running
File size: 1,503 Bytes
f2e1fb8 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | // 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%";
}
|