diff --git a/gyxtp/src/view/small.vue b/gyxtp/src/view/small.vue index 1bbbc9e..fe20d1f 100644 --- a/gyxtp/src/view/small.vue +++ b/gyxtp/src/view/small.vue @@ -538,14 +538,19 @@ export default { let nodes = []; let links = []; + // Step 0: 构建 nodeId -> node.type 的映射,用于快速查找 + const nodeTypeMap = {}; + res.nodes.forEach(node => { + nodeTypeMap[node.id] = node.type; + }); + + // Step 1: 统计每个节点的 totalNum(所有关联边的 data.num 之和) const totalNumMap = {}; // { nodeId: totalNum } - console.log(res.links) res.links.forEach(link => { const from = link.from; const to = link.to; const num = link.num || 0; // 安全取值 - console.log(num) // 无向图:from 和 to 都累加 num totalNumMap[from] = (totalNumMap[from] || 0) + num; @@ -559,20 +564,62 @@ export default { } }); -// Step 2: 生成节点,宽高根据 totalNum 动态计算 + + + // Step 3: 生成边 —— 增加过滤条件:from 和 to 都不能是 author 或 agency + for (let i = 0; i < res.links.length; i++) { + const link = res.links[i]; + const fromNodeId = link.from; + const toNodeId = link.to; + + // 获取 from 和 to 节点的类型 + const fromType = nodeTypeMap[fromNodeId]; + const toType = nodeTypeMap[toNodeId]; + + // 定义要过滤的类型 + const forbiddenTypes = ['author', 'agency']; + + // 如果 from 或 to 是 author 或 agency,跳过这条边 + if (forbiddenTypes.includes(fromType) && forbiddenTypes.includes(toType)) { + continue; + } + + // 否则才添加这条边 + const t_line = { + from: fromNodeId, + to: toNodeId, + text: link.text, + data: { + uuids: link.uuids, + num: link.num + } + }; + links.push(t_line); + } + + //收集所有非孤立节点 + const connectedNodeIds = new Set(); + links.forEach(link => { + connectedNodeIds.add(link.from); + connectedNodeIds.add(link.to); + }); + for (let i = 0; i < res.nodes.length; i++) { const node = res.nodes[i]; - // // 跳过关键词节点且 text 不匹配的情况 - // if (node.type === "keyword" && node.text !== this.getpoinName) { - // continue; - // } + if (!connectedNodeIds.has(node.id)) { + continue; // 跳过孤立节点 + } + // 跳过关键词节点且 text 不匹配的情况 + if (node.type === "keyword" && node.text !== this.getpoinName) { + continue; + } // 获取该节点的总 num 值 const totalNum = totalNumMap[node.id]; // 根据 totalNum 计算尺寸(可调参数) - const baseSize = 150; // 最小尺寸 + const baseSize = 120; // 最小尺寸 const sizePerNum = 40; // 每单位 num 增加的尺寸 const maxSize = 300; // 最大尺寸限制 @@ -582,6 +629,7 @@ export default { const t_data = { id: node.id, + type:node.type, text: node.text, width: width, height: height, @@ -593,23 +641,6 @@ export default { nodes.push(t_data); } -// Step 3: 正常生成边(保持不变) - for (let i = 0; i < res.links.length; i++) { - const link = res.links[i]; - const t_line = { - from: link.from, - to: link.to, - text: link.text, - data: { - uuids: link.uuids, - num: link.num - } - }; - links.push(t_line); - } - - - var data = { nodes:nodes, links:links diff --git a/ruoyi-api/src/main/java/com/ruoyi/api/controller/TestXiaoTuPuController.java b/ruoyi-api/src/main/java/com/ruoyi/api/controller/TestXiaoTuPuController.java index 5777ebb..e4132b4 100644 --- a/ruoyi-api/src/main/java/com/ruoyi/api/controller/TestXiaoTuPuController.java +++ b/ruoyi-api/src/main/java/com/ruoyi/api/controller/TestXiaoTuPuController.java @@ -99,17 +99,19 @@ public class TestXiaoTuPuController extends BaseController { } Integer uuid = Integer.valueOf(String.valueOf(list.get(0).get("uuid"))); - String cypher = "MATCH (center:TestNode)\n" + - "WHERE id(center) = " + uuid + "\n" + - "MATCH path = (center)-[r]-(other:TestNode)\n" + // 直接匹配一条关系 - "WITH r, center AS n, other AS m\n" + - "RETURN DISTINCT n, m, r"; -// String cypher ="MATCH (center:TestNode)\n" + -// "WHERE id(center) = "+uuid+"\n" + -// "MATCH path = (center)-[*1..2]-(other:TestNode)\n" + -// "UNWIND relationships(path) AS r\n" + -// "WITH r, startNode(r) AS n, endNode(r) AS m\n" + +// String cypher = "MATCH (center:TestNode)\n" + +// "WHERE id(center) = " + uuid + "\n" + +// "MATCH path = (center)-[r]-(other:TestNode)\n" + // 直接匹配一条关系 +// "WITH r, center AS n, other AS m\n" + // "RETURN DISTINCT n, m, r"; +// + + String cypher ="MATCH (center:TestNode)\n" + + "WHERE id(center) = "+uuid+"\n" + + "MATCH path = (center)-[*1..2]-(other:TestNode)\n" + + "UNWIND relationships(path) AS r\n" + + "WITH r, startNode(r) AS n, endNode(r) AS m\n" + + "RETURN DISTINCT n, m, r"; HashMap graphNode = neo4jUtil.getGraphNodeAndShip(cypher);