You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
457 lines
17 KiB
457 lines
17 KiB
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>刘邦集团人物关系网络</title>
|
|
<script src="https://d3js.org/d3.v7.min.js"></script>
|
|
<style>
|
|
body {
|
|
margin: 0;
|
|
padding: 0;
|
|
font-family: 'Microsoft YaHei', sans-serif;
|
|
background: linear-gradient(135deg, #0a1a3a, #1a3a6a);
|
|
color: #fff;
|
|
overflow: hidden;
|
|
}
|
|
|
|
#header {
|
|
text-align: center;
|
|
padding: 20px 0;
|
|
background: linear-gradient(90deg, rgba(10,26,58,0.8), rgba(26,58,106,0.8));
|
|
margin-bottom: 20px;
|
|
}
|
|
|
|
#title {
|
|
font-size: 32px;
|
|
font-weight: bold;
|
|
background: linear-gradient(90deg, #f9d423, #f83600);
|
|
-webkit-background-clip: text;
|
|
-webkit-text-fill-color: transparent;
|
|
text-shadow: 0 0 10px rgba(248, 54, 0, 0.3);
|
|
}
|
|
|
|
#container {
|
|
display: flex;
|
|
height: calc(100vh - 100px);
|
|
}
|
|
|
|
#graph {
|
|
flex: 3;
|
|
height: 100%;
|
|
position: relative;
|
|
}
|
|
|
|
#sidebar {
|
|
flex: 1;
|
|
background: rgba(10, 26, 58, 0.7);
|
|
padding: 20px;
|
|
border-left: 1px solid #2a4a7a;
|
|
overflow-y: auto;
|
|
}
|
|
|
|
.node {
|
|
cursor: pointer;
|
|
filter: drop-shadow(0 0 5px rgba(255, 255, 255, 0.3));
|
|
}
|
|
|
|
.node text {
|
|
fill: #fff;
|
|
font-size: 12px;
|
|
text-anchor: middle;
|
|
dominant-baseline: middle;
|
|
pointer-events: none;
|
|
}
|
|
|
|
.link {
|
|
stroke-opacity: 0.6;
|
|
}
|
|
|
|
.link.military {
|
|
stroke: #ff5252;
|
|
}
|
|
|
|
.link.political {
|
|
stroke: #4caf50;
|
|
}
|
|
|
|
.link.family {
|
|
stroke: #ff9800;
|
|
}
|
|
|
|
.legend {
|
|
position: absolute;
|
|
bottom: 20px;
|
|
right: 20px;
|
|
background: rgba(10, 26, 58, 0.8);
|
|
padding: 10px;
|
|
border-radius: 5px;
|
|
border: 1px solid #2a4a7a;
|
|
}
|
|
|
|
.legend-item {
|
|
display: flex;
|
|
align-items: center;
|
|
margin-bottom: 5px;
|
|
}
|
|
|
|
.legend-color {
|
|
width: 20px;
|
|
height: 3px;
|
|
margin-right: 10px;
|
|
}
|
|
|
|
.tooltip {
|
|
position: absolute;
|
|
padding: 10px;
|
|
background: rgba(10, 26, 58, 0.9);
|
|
border: 1px solid #2a4a7a;
|
|
border-radius: 5px;
|
|
pointer-events: none;
|
|
max-width: 300px;
|
|
font-size: 14px;
|
|
z-index: 100;
|
|
}
|
|
|
|
#layout-controls {
|
|
position: absolute;
|
|
top: 20px;
|
|
left: 20px;
|
|
background: rgba(10, 26, 58, 0.8);
|
|
padding: 10px;
|
|
border-radius: 5px;
|
|
border: 1px solid #2a4a7a;
|
|
}
|
|
|
|
button {
|
|
background: #2a4a7a;
|
|
color: #fff;
|
|
border: none;
|
|
padding: 5px 10px;
|
|
margin: 2px;
|
|
border-radius: 3px;
|
|
cursor: pointer;
|
|
}
|
|
|
|
button:hover {
|
|
background: #3a5a8a;
|
|
}
|
|
|
|
.sidebar-title {
|
|
font-size: 18px;
|
|
margin-bottom: 10px;
|
|
border-bottom: 1px solid #2a4a7a;
|
|
padding-bottom: 5px;
|
|
}
|
|
|
|
.sidebar-content {
|
|
font-size: 14px;
|
|
line-height: 1.5;
|
|
}
|
|
|
|
.relationship-list {
|
|
margin-top: 20px;
|
|
}
|
|
|
|
.relationship-item {
|
|
margin-bottom: 10px;
|
|
padding-bottom: 10px;
|
|
border-bottom: 1px dashed #2a4a7a;
|
|
}
|
|
|
|
.relationship-type {
|
|
font-weight: bold;
|
|
color: #4caf50;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div id="header">
|
|
<div id="title">刘邦集团核心人物关系网络</div>
|
|
</div>
|
|
|
|
<div id="container">
|
|
<div id="graph"></div>
|
|
<div id="sidebar">
|
|
<div class="sidebar-title">人物详情</div>
|
|
<div class="sidebar-content" id="node-details">
|
|
点击节点查看人物详细信息
|
|
</div>
|
|
<div class="relationship-list">
|
|
<div class="sidebar-title">关系列表</div>
|
|
<div id="relationship-details"></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="legend">
|
|
<div class="legend-item">
|
|
<div class="legend-color" style="background: #ff5252;"></div>
|
|
<span>军事关系</span>
|
|
</div>
|
|
<div class="legend-item">
|
|
<div class="legend-color" style="background: #4caf50;"></div>
|
|
<span>政治关系</span>
|
|
</div>
|
|
<div class="legend-item">
|
|
<div class="legend-color" style="background: #ff9800;"></div>
|
|
<span>家族关系</span>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="layout-controls">
|
|
<button id="force-layout">力导向布局</button>
|
|
<button id="radial-layout">辐射状布局</button>
|
|
<button id="circular-layout">环形布局</button>
|
|
<button id="grid-layout">网格布局</button>
|
|
</div>
|
|
|
|
<div class="tooltip" id="tooltip"></div>
|
|
|
|
<script>
|
|
const width = document.getElementById('graph').clientWidth;
|
|
const height = document.getElementById('graph').clientHeight;
|
|
|
|
const svg = d3.select("#graph")
|
|
.append("svg")
|
|
.attr("width", width)
|
|
.attr("height", height);
|
|
|
|
const simulation = d3.forceSimulation()
|
|
.force("link", d3.forceLink().id(d => d.id).distance(100))
|
|
.force("charge", d3.forceManyBody().strength(-500))
|
|
.force("center", d3.forceCenter(width / 2, height / 2))
|
|
.force("collision", d3.forceCollide().radius(d => Math.sqrt(d.size) * 10 + 10));
|
|
|
|
const data = {
|
|
nodes: [
|
|
{ id: "1", name: "刘邦", type: "person", size: 174, description: "汉朝开国皇帝,从平民起义到建立汉朝,经历坎坷,重用人才但晚年多疑。" },
|
|
{ id: "2", name: "吕后", type: "person", size: 53, description: "刘邦正妻,汉朝第一位皇后,政治手段强硬,刘邦死后掌握大权。" },
|
|
{ id: "12", name: "项伯", type: "person", size: 42, description: "项羽的叔父,曾在鸿门宴中保护刘邦,对刘邦有救命之恩。" },
|
|
{ id: "8", name: "项庄", type: "person", size: 12, description: "项羽堂弟,鸿门宴中奉命刺杀刘邦的剑客。" },
|
|
{ id: "11", name: "曹无伤", type: "person", size: 10, description: "刘邦部下,背叛刘邦向项羽告密,后被刘邦处死。" },
|
|
{ id: "10", name: "刘仲", type: "person", size: 6, description: "刘邦兄长,因战败被贬为合阳侯。" },
|
|
{ id: "9", name: "列侯宗室", type: "organization", size: 2, description: "汉代贵族集团代表,参与权力斗争。" },
|
|
{ id: "5", name: "刘姓宗室", type: "organization", size: 2, description: "汉朝皇族成员,部分品行不良者被儒术派官员从族籍中除名。" },
|
|
{ id: "6", name: "吕氏家族", type: "organization", size: 4, description: "吕后时期的核心权力集团,掌控朝政。" },
|
|
{ id: "3", name: "刘姓诸侯", type: "organization", size: 6, description: "刘姓诸侯联合铲除吕氏家族势力。" },
|
|
{ id: "13", name: "功臣、列侯、将军", type: "category", size: 1, description: "武官集团,在朝会中按次序站在西侧,面向东方。" }
|
|
],
|
|
links: [
|
|
{ source: "1", target: "2", type: "family", description: "夫妻关系,早期共同创业,后期因刘邦宠幸戚夫人而关系恶化" },
|
|
{ source: "1", target: "12", type: "political", description: "政治盟友,项伯多次在关键时刻帮助刘邦" },
|
|
{ source: "1", target: "8", type: "military", description: "敌对关系,项庄曾在鸿门宴试图刺杀刘邦" },
|
|
{ source: "1", target: "11", type: "military", description: "部下背叛,曹无伤向项羽告密导致鸿门宴危机" },
|
|
{ source: "1", target: "10", type: "family", description: "兄弟关系,刘仲因战败被刘邦贬职" },
|
|
{ source: "1", target: "9", type: "political", description: "统治关系,刘邦依靠列侯宗室巩固政权" },
|
|
{ source: "1", target: "5", type: "family", description: "宗族关系,刘邦依靠刘姓宗室维护统治" },
|
|
{ source: "2", target: "6", type: "family", description: "家族关系,吕后重用吕氏家族成员" },
|
|
{ source: "2", target: "3", type: "political", description: "敌对关系,刘姓诸侯联合反对吕后专权" },
|
|
{ source: "1", target: "13", type: "political", description: "君臣关系,刘邦依靠功臣集团建立汉朝" },
|
|
{ source: "6", target: "3", type: "military", description: "权力斗争,吕氏家族与刘姓诸侯的军事对抗" }
|
|
]
|
|
};
|
|
|
|
const link = svg.append("g")
|
|
.selectAll("line")
|
|
.data(data.links)
|
|
.enter().append("line")
|
|
.attr("class", d => `link ${d.type}`)
|
|
.attr("stroke-width", 2);
|
|
|
|
const node = svg.append("g")
|
|
.selectAll("g")
|
|
.data(data.nodes)
|
|
.enter().append("g")
|
|
.attr("class", "node")
|
|
.call(d3.drag()
|
|
.on("start", dragstarted)
|
|
.on("drag", dragged)
|
|
.on("end", dragended));
|
|
|
|
node.each(function(d) {
|
|
const g = d3.select(this);
|
|
|
|
// 3D node effect
|
|
g.append("circle")
|
|
.attr("r", d => Math.sqrt(d.size) * 3 + 20)
|
|
.attr("fill", d => {
|
|
if (d.type === "person") return "#3498db";
|
|
if (d.type === "organization") return "#e74c3c";
|
|
return "#2ecc71";
|
|
})
|
|
.attr("stroke", "#fff")
|
|
.attr("stroke-width", 2)
|
|
.attr("opacity", 0.9)
|
|
.attr("filter", "url(#glow)");
|
|
|
|
// Gradient effect for 3D
|
|
g.append("circle")
|
|
.attr("r", d => Math.sqrt(d.size) * 3 + 18)
|
|
.attr("fill", "url(#node-gradient)")
|
|
.attr("opacity", 0.6);
|
|
|
|
g.append("text")
|
|
.attr("dy", 4)
|
|
.text(d => d.name);
|
|
});
|
|
|
|
svg.append("defs").append("filter")
|
|
.attr("id", "glow")
|
|
.append("feGaussianBlur")
|
|
.attr("stdDeviation", "2")
|
|
.attr("result", "coloredBlur");
|
|
|
|
svg.append("defs").append("filter")
|
|
.attr("id", "glow-selected")
|
|
.append("feGaussianBlur")
|
|
.attr("stdDeviation", "4")
|
|
.attr("result", "coloredBlur");
|
|
|
|
svg.append("defs").append("radialGradient")
|
|
.attr("id", "node-gradient")
|
|
.attr("cx", "30%")
|
|
.attr("cy", "30%")
|
|
.attr("r", "70%")
|
|
.selectAll("stop")
|
|
.data([
|
|
{offset: "0%", color: "white", opacity: 0.8},
|
|
{offset: "100%", color: "white", opacity: 0}
|
|
])
|
|
.enter().append("stop")
|
|
.attr("offset", d => d.offset)
|
|
.attr("stop-color", d => d.color)
|
|
.attr("stop-opacity", d => d.opacity);
|
|
|
|
simulation
|
|
.nodes(data.nodes)
|
|
.on("tick", ticked);
|
|
|
|
simulation.force("link")
|
|
.links(data.links);
|
|
|
|
function ticked() {
|
|
link
|
|
.attr("x1", d => d.source.x)
|
|
.attr("y1", d => d.source.y)
|
|
.attr("x2", d => d.target.x)
|
|
.attr("y2", d => d.target.y);
|
|
|
|
node
|
|
.attr("transform", d => `translate(${d.x},${d.y})`);
|
|
}
|
|
|
|
function dragstarted(event, d) {
|
|
if (!event.active) simulation.alphaTarget(0.3).restart();
|
|
d.fx = d.x;
|
|
d.fy = d.y;
|
|
}
|
|
|
|
function dragged(event, d) {
|
|
d.fx = event.x;
|
|
d.fy = event.y;
|
|
}
|
|
|
|
function dragended(event, d) {
|
|
if (!event.active) simulation.alphaTarget(0);
|
|
d.fx = null;
|
|
d.fy = null;
|
|
}
|
|
|
|
// Tooltip and interactions
|
|
const tooltip = d3.select("#tooltip");
|
|
|
|
node.on("mouseover", function(event, d) {
|
|
d3.select(this).select("circle").attr("filter", "url(#glow-selected)");
|
|
|
|
tooltip
|
|
.style("left", (event.pageX + 10) + "px")
|
|
.style("top", (event.pageY + 10) + "px")
|
|
.style("opacity", 1)
|
|
.html(`<strong>${d.name}</strong><br>${d.description}`);
|
|
})
|
|
.on("mouseout", function() {
|
|
d3.select(this).select("circle").attr("filter", "url(#glow)");
|
|
tooltip.style("opacity", 0);
|
|
})
|
|
.on("click", function(event, d) {
|
|
// Update sidebar
|
|
d3.select("#node-details").html(`
|
|
<h3>${d.name}</h3>
|
|
<p>${d.description}</p>
|
|
<p><strong>类型:</strong> ${d.type}</p>
|
|
<p><strong>重要性:</strong> ${d.size}</p>
|
|
`);
|
|
|
|
// Update relationships
|
|
const relationships = data.links.filter(l => l.source.id === d.id || l.target.id === d.id);
|
|
const relationshipHtml = relationships.map(r => {
|
|
const otherNodeId = r.source.id === d.id ? r.target.id : r.source.id;
|
|
const otherNode = data.nodes.find(n => n.id === otherNodeId);
|
|
return `
|
|
<div class="relationship-item">
|
|
<div><strong>${otherNode.name}</strong></div>
|
|
<div class="relationship-type">${r.type === "family" ? "家族" : r.type === "political" ? "政治" : "军事"}关系</div>
|
|
<div>${r.description}</div>
|
|
</div>
|
|
`;
|
|
}).join("");
|
|
|
|
d3.select("#relationship-details").html(relationshipHtml || "暂无关系数据");
|
|
});
|
|
|
|
// Layout controls
|
|
d3.select("#force-layout").on("click", function() {
|
|
simulation.force("charge", d3.forceManyBody().strength(-500))
|
|
.force("center", d3.forceCenter(width / 2, height / 2))
|
|
.alphaTarget(0.3)
|
|
.restart();
|
|
});
|
|
|
|
d3.select("#radial-layout").on("click", function() {
|
|
simulation.force("center", null)
|
|
.force("radial", d3.forceRadial(height / 3, width / 2, height / 2))
|
|
.alphaTarget(0.3)
|
|
.restart();
|
|
});
|
|
|
|
d3.select("#circular-layout").on("click", function() {
|
|
const radius = Math.min(width, height) / 3;
|
|
const angle = 2 * Math.PI / data.nodes.length;
|
|
|
|
data.nodes.forEach((d, i) => {
|
|
d.fx = width / 2 + radius * Math.cos(i * angle);
|
|
d.fy = height / 2 + radius * Math.sin(i * angle);
|
|
});
|
|
|
|
simulation.alphaTarget(0.3).restart();
|
|
});
|
|
|
|
d3.select("#grid-layout").on("click", function() {
|
|
const cols = Math.ceil(Math.sqrt(data.nodes.length));
|
|
const cellSize = Math.min(width, height) / (cols + 1);
|
|
|
|
data.nodes.forEach((d, i) => {
|
|
const row = Math.floor(i / cols);
|
|
const col = i % cols;
|
|
d.fx = (col + 1) * cellSize;
|
|
d.fy = (row + 1) * cellSize;
|
|
});
|
|
|
|
simulation.alphaTarget(0.3).restart();
|
|
});
|
|
|
|
// Responsive resize
|
|
window.addEventListener("resize", function() {
|
|
const newWidth = document.getElementById('graph').clientWidth;
|
|
const newHeight = document.getElementById('graph').clientHeight;
|
|
|
|
svg.attr("width", newWidth).attr("height", newHeight);
|
|
simulation.force("center", d3.forceCenter(newWidth / 2, newHeight / 2));
|
|
simulation.alphaTarget(0.3).restart();
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|