好的,以下是一个重新生成的拓扑结构,包括节点之间的连接和开销。
HTML代码示例:
<div class="topology">
<div class="node" id="node1">Node 1 ($100)</div>
<div class="node" id="node2">Node 2 ($50)</div>
<div class="node" id="node3">Node 3 ($70)</div>
<div class="node" id="node4">Node 4 ($80)</div>
<div class="node" id="node5">Node 5 ($60)</div>
<div class="link" id="link1"></div>
<div class="link" id="link2"></div>
<div class="link" id="link3"></div>
<div class="link" id="link4"></div>
<div class="link" id="link5"></div>
<div class="link" id="link6"></div>
<div class="cost" id="cost1">$20</div>
<div class="cost" id="cost2">$30</div>
<div class="cost" id="cost3">$40</div>
<div class="cost" id="cost4">$50</div>
<div class="cost" id="cost5">$35</div>
<div class="cost" id="cost6">$25</div>
</div>
CSS代码示例:
.topology {
display: flex;
flex-wrap: wrap;
justify-content: center;
align-items: center;
}
.node {
width: 60px;
height: 60px;
background-color: #ddd;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
position: relative;
z-index: 2;
margin-right: 20px;
}
.link {
position: absolute;
background-color: #333;
width: 2px;
z-index: 1;
}
.cost {
position: absolute;
font-size: 14px;
font-weight: bold;
color: #333;
}
JavaScript代码示例:
var node1 = document.getElementById("node1");
var node2 = document.getElementById("node2");
var node3 = document.getElementById("node3");
var node4 = document.getElementById("node4");
var node5 = document.getElementById("node5");
var link1 = document.getElementById("link1");
var link2 = document.getElementById("link2");
var link3 = document.getElementById("link3");
var link4 = document.getElementById("link4");
var link5 = document.getElementById("link5");
var link6 = document.getElementById("link6");
var cost1 = document.getElementById("cost1");
var cost2 = document.getElementById("cost2");
var cost3 = document.getElementById("cost3");
var cost4 = document.getElementById("cost4");
var cost5 = document.getElementById("cost5");
var cost6 = document.getElementById("cost6");
// Set node positions
node1.style.top = "100px";
node1.style.left = "100px";
node2.style.top = "50px";
node2.style.left = "300px";
node3.style.top = "100px";
node3.style.left = "500px";
node4.style.top = "200px";
node4.style.left = "200px";
node5.style.top = "200px";
node5.style.left = "400px";
// Set link positions and costs
link1.style.top = node1.offsetTop + 30 + "px";
link1.style.left = node1.offsetLeft + 30 + "px";
link2.style.top = node1.offsetTop + 30 + "px";
link2.style.left = node2.offsetLeft + 30 + "px";
link3.style.top = node2.offsetTop + 30 + "px";
link3.style.left = node3.offsetLeft + 30 + "px";
link4.style.top = node2.offsetTop + 30 + "px";
link4.style.left = node4.offsetLeft + 30 + "px";
link5.style.top = node4.offsetTop + 30 + "px";
link5.style.left = node5.offsetLeft + 30 + "px";
link6.style.top = node3.offsetTop + 30 + "px";
link6.style.left = node5.offsetLeft + 30 + "px";
cost1.style.top = node1.offsetTop + 50 + "px";
cost1.style.left = node1.offsetLeft + 110 + "px";
cost2.style.top = node1.offsetTop + 10 + "px";
cost2.style.left = node2.offsetLeft + 140 + "px";
cost3.style.top = node2.offsetTop + 40 + "px";
cost3.style.left = node3.offsetLeft - 40 + "px";
cost4.style.top = node2.offsetTop + 10 + "px";
cost4.style.left = node4.offsetLeft + 140 + "px";
cost5.style.top = node4.offsetTop + 40 + "px";
cost5.style.left = node5.offsetLeft - 40 + "px";
cost6.style.top = node3.offsetTop + 10 + "px";
cost6.style.left = node5.offsetLeft + 140 + "px";
注释:本示例中,我们创建了一个简单的网络拓扑结构,由5个节点和6个链接组成。我们使用flexbox布局将节点和链接居中对齐,并用CSS定义它们的样式。在JavaScript中,我们设置了每个节点的位置,然后通过计算将链接放置在正确的位置,并为每个链接添加正确的开销。最后,我们用CSS定义了开销的样式。