|
|
|
@ -25,7 +25,7 @@ async function drawGraph(url, baseUrl, pathColors, depth, enableDrag, enableLege
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const data = {
|
|
|
|
|
nodes: [...neighbours].map(id => ({id})),
|
|
|
|
|
nodes: [...neighbours].map(id => ({ id })),
|
|
|
|
|
links: links.filter(l => neighbours.has(l.source) && neighbours.has(l.target)),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -52,18 +52,18 @@ async function drawGraph(url, baseUrl, pathColors, depth, enableDrag, enableLege
|
|
|
|
|
d.fy = d.y;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function dragged(event,d) {
|
|
|
|
|
function dragged(event, d) {
|
|
|
|
|
d.fx = event.x;
|
|
|
|
|
d.fy = event.y;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function dragended(event,d) {
|
|
|
|
|
function dragended(event, d) {
|
|
|
|
|
if (!event.active) simulation.alphaTarget(0);
|
|
|
|
|
d.fx = null;
|
|
|
|
|
d.fy = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const noop = () => {}
|
|
|
|
|
const noop = () => { }
|
|
|
|
|
return d3.drag()
|
|
|
|
|
.on("start", enableDrag ? dragstarted : noop)
|
|
|
|
|
.on("drag", enableDrag ? dragged : noop)
|
|
|
|
@ -86,15 +86,15 @@ async function drawGraph(url, baseUrl, pathColors, depth, enableDrag, enableLege
|
|
|
|
|
|
|
|
|
|
if (enableLegend) {
|
|
|
|
|
const legend = [
|
|
|
|
|
{"Current": "var(--g-node-active)"},
|
|
|
|
|
{"Note": "var(--g-node)"},
|
|
|
|
|
{ "Current": "var(--g-node-active)" },
|
|
|
|
|
{ "Note": "var(--g-node)" },
|
|
|
|
|
...pathColors
|
|
|
|
|
]
|
|
|
|
|
legend.forEach((legendEntry, i) => {
|
|
|
|
|
const key = Object.keys(legendEntry)[0]
|
|
|
|
|
const colour = legendEntry[key]
|
|
|
|
|
svg.append("circle").attr("cx", -width/2 + 20).attr("cy", height/2 - 30 * (i+1)).attr("r", 6).style("fill", colour)
|
|
|
|
|
svg.append("text").attr("x", -width/2 + 40).attr("y", height/2 - 30 * (i+1)).text(key).style("font-size", "15px").attr("alignment-baseline","middle")
|
|
|
|
|
svg.append("circle").attr("cx", -width / 2 + 20).attr("cy", height / 2 - 30 * (i + 1)).attr("r", 6).style("fill", colour)
|
|
|
|
|
svg.append("text").attr("x", -width / 2 + 40).attr("y", height / 2 - 30 * (i + 1)).text(key).style("font-size", "15px").attr("alignment-baseline", "middle")
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -159,7 +159,7 @@ async function drawGraph(url, baseUrl, pathColors, depth, enableDrag, enableLege
|
|
|
|
|
.transition()
|
|
|
|
|
.duration(200)
|
|
|
|
|
.style("opacity", 1)
|
|
|
|
|
}).on("mouseleave", function (_,d) {
|
|
|
|
|
}).on("mouseleave", function (_, d) {
|
|
|
|
|
d3.selectAll(".node")
|
|
|
|
|
.transition()
|
|
|
|
|
.duration(200)
|
|
|
|
@ -196,7 +196,7 @@ async function drawGraph(url, baseUrl, pathColors, depth, enableDrag, enableLege
|
|
|
|
|
svg.call(d3.zoom()
|
|
|
|
|
.extent([[0, 0], [width, height]])
|
|
|
|
|
.scaleExtent([0.25, 4])
|
|
|
|
|
.on("zoom", ({transform}) => {
|
|
|
|
|
.on("zoom", ({ transform }) => {
|
|
|
|
|
link.attr("transform", transform);
|
|
|
|
|
node.attr("transform", transform);
|
|
|
|
|
labels.attr("transform", transform);
|
|
|
|
@ -217,5 +217,4 @@ async function drawGraph(url, baseUrl, pathColors, depth, enableDrag, enableLege
|
|
|
|
|
.attr("x", d => d.x)
|
|
|
|
|
.attr("y", d => d.y)
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|