|
|
|
@ -422,14 +422,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; |
|
|
|
@ -443,20 +448,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; // 最大尺寸限制 |
|
|
|
|
|
|
|
@ -466,6 +513,7 @@ export default { |
|
|
|
|
|
|
|
const t_data = { |
|
|
|
id: node.id, |
|
|
|
type:node.type, |
|
|
|
text: node.text, |
|
|
|
width: width, |
|
|
|
height: height, |
|
|
|
@ -477,23 +525,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 |
|
|
|
|