|
|
@ -25,7 +25,7 @@ async function drawGraph(url, baseUrl, pathColors, depth, enableDrag, enableLege
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const data = {
|
|
|
|
const data = {
|
|
|
|
nodes: [...neighbours].map(id => ({id})),
|
|
|
|
nodes: [...neighbours].map(id => ({ id })),
|
|
|
|
links: links.filter(l => neighbours.has(l.source) && neighbours.has(l.target)),
|
|
|
|
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;
|
|
|
|
d.fy = d.y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function dragged(event,d) {
|
|
|
|
function dragged(event, d) {
|
|
|
|
d.fx = event.x;
|
|
|
|
d.fx = event.x;
|
|
|
|
d.fy = event.y;
|
|
|
|
d.fy = event.y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function dragended(event,d) {
|
|
|
|
function dragended(event, d) {
|
|
|
|
if (!event.active) simulation.alphaTarget(0);
|
|
|
|
if (!event.active) simulation.alphaTarget(0);
|
|
|
|
d.fx = null;
|
|
|
|
d.fx = null;
|
|
|
|
d.fy = null;
|
|
|
|
d.fy = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const noop = () => {}
|
|
|
|
const noop = () => { }
|
|
|
|
return d3.drag()
|
|
|
|
return d3.drag()
|
|
|
|
.on("start", enableDrag ? dragstarted : noop)
|
|
|
|
.on("start", enableDrag ? dragstarted : noop)
|
|
|
|
.on("drag", enableDrag ? dragged : noop)
|
|
|
|
.on("drag", enableDrag ? dragged : noop)
|
|
|
@ -86,15 +86,15 @@ async function drawGraph(url, baseUrl, pathColors, depth, enableDrag, enableLege
|
|
|
|
|
|
|
|
|
|
|
|
if (enableLegend) {
|
|
|
|
if (enableLegend) {
|
|
|
|
const legend = [
|
|
|
|
const legend = [
|
|
|
|
{"Current": "var(--g-node-active)"},
|
|
|
|
{ "Current": "var(--g-node-active)" },
|
|
|
|
{"Note": "var(--g-node)"},
|
|
|
|
{ "Note": "var(--g-node)" },
|
|
|
|
...pathColors
|
|
|
|
...pathColors
|
|
|
|
]
|
|
|
|
]
|
|
|
|
legend.forEach((legendEntry, i) => {
|
|
|
|
legend.forEach((legendEntry, i) => {
|
|
|
|
const key = Object.keys(legendEntry)[0]
|
|
|
|
const key = Object.keys(legendEntry)[0]
|
|
|
|
const colour = legendEntry[key]
|
|
|
|
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("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("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()
|
|
|
|
.transition()
|
|
|
|
.duration(200)
|
|
|
|
.duration(200)
|
|
|
|
.style("opacity", 1)
|
|
|
|
.style("opacity", 1)
|
|
|
|
}).on("mouseleave", function (_,d) {
|
|
|
|
}).on("mouseleave", function (_, d) {
|
|
|
|
d3.selectAll(".node")
|
|
|
|
d3.selectAll(".node")
|
|
|
|
.transition()
|
|
|
|
.transition()
|
|
|
|
.duration(200)
|
|
|
|
.duration(200)
|
|
|
@ -196,7 +196,7 @@ async function drawGraph(url, baseUrl, pathColors, depth, enableDrag, enableLege
|
|
|
|
svg.call(d3.zoom()
|
|
|
|
svg.call(d3.zoom()
|
|
|
|
.extent([[0, 0], [width, height]])
|
|
|
|
.extent([[0, 0], [width, height]])
|
|
|
|
.scaleExtent([0.25, 4])
|
|
|
|
.scaleExtent([0.25, 4])
|
|
|
|
.on("zoom", ({transform}) => {
|
|
|
|
.on("zoom", ({ transform }) => {
|
|
|
|
link.attr("transform", transform);
|
|
|
|
link.attr("transform", transform);
|
|
|
|
node.attr("transform", transform);
|
|
|
|
node.attr("transform", transform);
|
|
|
|
labels.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("x", d => d.x)
|
|
|
|
.attr("y", d => d.y)
|
|
|
|
.attr("y", d => d.y)
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|