|
|
|
@ -983,39 +983,56 @@ export default { |
|
|
|
}) |
|
|
|
}, |
|
|
|
onNodeClick(nodeObject, $event) { |
|
|
|
console.log(nodeObject.id) |
|
|
|
console.log('Clicked node:', nodeObject.id); |
|
|
|
const graphInstance = this.$refs.graphRef.getInstance(); |
|
|
|
let node = graphInstance.getNodeById(nodeObject.id) |
|
|
|
let relinks = graphInstance.getLinesByNode(node); |
|
|
|
|
|
|
|
// let links = graphInstance.getLinks(); |
|
|
|
// |
|
|
|
// for (let i=0;i<links.length;i++){ |
|
|
|
// graphInstance.getLinks()[i].lineWidth = 1 |
|
|
|
// } |
|
|
|
|
|
|
|
if (this.lastNodeL.id==node.id){ |
|
|
|
console.log("ss11111111") |
|
|
|
for (let i=0;i<relinks.length;i++){ |
|
|
|
console.log(graphInstance.getLinesByNode(node)[i].lineWidth) |
|
|
|
if (graphInstance.getLinesByNode(node)[i].lineWidth == 10){ |
|
|
|
graphInstance.getLinesByNode(node)[i].lineWidth = 1 |
|
|
|
}else { |
|
|
|
graphInstance.getLinesByNode(node)[i].lineWidth = 10 |
|
|
|
|
|
|
|
// 清除所有边的高亮 |
|
|
|
const allLines = graphInstance.getLines(); |
|
|
|
allLines.forEach(line => { |
|
|
|
line.lineWidth = 1; |
|
|
|
}); |
|
|
|
|
|
|
|
// 获取起始节点 |
|
|
|
const startNode = graphInstance.getNodeById(nodeObject.id); |
|
|
|
if (!startNode) return; |
|
|
|
|
|
|
|
// 存储需要高亮的所有边(去重) |
|
|
|
const highlightLines = new Set(); |
|
|
|
|
|
|
|
// BFS 遍历所有下级节点(包括自己) |
|
|
|
const queue = [startNode]; |
|
|
|
const visited = new Set([startNode.id]); // 防止环导致无限循环 |
|
|
|
|
|
|
|
while (queue.length > 0) { |
|
|
|
const currentNode = queue.shift(); |
|
|
|
|
|
|
|
// 获取当前节点的所有出边(即从该节点出发的边) |
|
|
|
const outEdges = graphInstance.getLinesByNode(currentNode).filter(line => line.from === currentNode.id); |
|
|
|
|
|
|
|
for (const edge of outEdges) { |
|
|
|
highlightLines.add(edge); |
|
|
|
|
|
|
|
const childNodeId = edge.to; |
|
|
|
if (!visited.has(childNodeId)) { |
|
|
|
const childNode = graphInstance.getNodeById(childNodeId); |
|
|
|
if (childNode) { |
|
|
|
visited.add(childNodeId); |
|
|
|
queue.push(childNode); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return |
|
|
|
} |
|
|
|
if (this.lastNodeL!=""){ |
|
|
|
let a = graphInstance.getLinesByNode(this.lastNodeL); |
|
|
|
for (let i=0;i<a.length;i++){ |
|
|
|
graphInstance.getLinesByNode(this.lastNodeL)[i].lineWidth = 1 |
|
|
|
} |
|
|
|
} |
|
|
|
for (let i=0;i<relinks.length;i++){ |
|
|
|
graphInstance.getLinesByNode(node)[i].lineWidth = 10 |
|
|
|
} |
|
|
|
this.lastNodeL = node |
|
|
|
|
|
|
|
// 高亮所有收集到的边 |
|
|
|
highlightLines.forEach(line => { |
|
|
|
line.lineWidth = 10; |
|
|
|
}); |
|
|
|
|
|
|
|
// 可选:记录最后点击的节点(用于 UI 反馈) |
|
|
|
this.lastNodeL = startNode; |
|
|
|
|
|
|
|
// 强制刷新图表(如果框架需要) |
|
|
|
// graphInstance.refresh && graphInstance.refresh(); |
|
|
|
} |
|
|
|
}, |
|
|
|
created() { |
|
|
|
|