|
async function loadCsvData(url) { |
|
const response = await fetch(url); |
|
const csvText = await response.text(); |
|
const cleanedCsvText = csvText.replace(/\r/g, ""); |
|
const lines = cleanedCsvText.split("\n"); |
|
const headers = lines[0].split(","); |
|
|
|
return lines.slice(1).map((line) => { |
|
const data = line.split(","); |
|
return headers.reduce((obj, nextKey, index) => { |
|
obj[nextKey] = data[index]; |
|
return obj; |
|
}, {}); |
|
}); |
|
} |
|
|
|
const csvUrl = "info.csv"; |
|
|
|
|
|
let csvData; |
|
|
|
|
|
loadCsvData(csvUrl).then((data) => { |
|
csvData = data; |
|
}); |
|
|
|
|
|
fetch("mst_data.json") |
|
.then((response) => response.json()) |
|
.then((data) => { |
|
const nodes = new vis.DataSet(data.nodes); |
|
const edges = new vis.DataSet( |
|
data.edges.map((edge) => ({ |
|
from: edge.from, |
|
to: edge.to, |
|
length: edge.length * 1000, |
|
value: 1 / edge.length, |
|
title: 1 - edge.length, |
|
})) |
|
); |
|
|
|
const container = document.getElementById("network"); |
|
const graphData = { nodes: nodes, edges: edges }; |
|
const options = { |
|
width: "100%", |
|
height: "100%", |
|
nodes: { |
|
font: { |
|
size: 40, |
|
}, |
|
}, |
|
edges: { |
|
smooth: false, |
|
chosen: false, |
|
}, |
|
physics: { |
|
barnesHut: { |
|
|
|
|
|
|
|
gravitationalConstant: -100000, |
|
|
|
}, |
|
}, |
|
layout: { |
|
improvedLayout: false, |
|
}, |
|
}; |
|
|
|
const network = new vis.Network(container, graphData, options); |
|
|
|
|
|
network.on("selectNode", function (params) { |
|
if (params.nodes.length > 0) { |
|
const nodeId = params.nodes[0]; |
|
const nodeName = nodes.get(nodeId).label; |
|
|
|
const nodeData = csvData.find((item) => item.name === nodeName); |
|
|
|
|
|
document.getElementById("node-name").textContent = nodeName; |
|
if (nodeData) { |
|
document.getElementById("node-num-files").textContent = |
|
nodeData.num_files; |
|
document.getElementById("node-duration").textContent = |
|
nodeData.total_duration_min; |
|
document.getElementById("node-f0").textContent = nodeData.f0_mean; |
|
} |
|
} |
|
}); |
|
|
|
function zoomToNode() { |
|
const nodeName = document.getElementById("model-name-input").value; |
|
const foundNode = nodes.get({ |
|
filter: function (item) { |
|
return item.label === nodeName; |
|
}, |
|
}); |
|
|
|
if (foundNode.length > 0) { |
|
const nodeId = foundNode[0].id; |
|
network.focus(nodeId, { scale: 1, animation: true }); |
|
network.selectNodes([nodeId]); |
|
document.getElementById("node-name").textContent = nodeName; |
|
} else { |
|
alert("Not found."); |
|
} |
|
} |
|
|
|
document |
|
.getElementById("search-button") |
|
.addEventListener("click", zoomToNode); |
|
|
|
document |
|
.getElementById("model-name-input") |
|
.addEventListener("keyup", function (event) { |
|
if (event.key === "Enter") { |
|
event.preventDefault(); |
|
zoomToNode(); |
|
} |
|
}); |
|
}) |
|
.catch((error) => console.error("Error loading the MST data:", error)); |
|
|