|
|
@@ -235,6 +235,30 @@ function renderGraph() {
|
|
|
.attr('stroke', d => getEdgeStyle(d).color)
|
|
|
.attr('stroke-width', 1.5)
|
|
|
|
|
|
+ // 边的分数标签
|
|
|
+ const linkLabelData = links.filter(d => getEdgeStyle(d).scoreText)
|
|
|
+ const linkLabel = g.append('g')
|
|
|
+ .selectAll('g')
|
|
|
+ .data(linkLabelData)
|
|
|
+ .join('g')
|
|
|
+ .attr('class', 'graph-link-label')
|
|
|
+
|
|
|
+ linkLabel.append('rect')
|
|
|
+ .attr('x', -14)
|
|
|
+ .attr('y', -6)
|
|
|
+ .attr('width', 28)
|
|
|
+ .attr('height', 12)
|
|
|
+ .attr('rx', 2)
|
|
|
+ .attr('fill', '#1d232a')
|
|
|
+ .attr('opacity', 0.9)
|
|
|
+
|
|
|
+ linkLabel.append('text')
|
|
|
+ .attr('text-anchor', 'middle')
|
|
|
+ .attr('dy', '0.35em')
|
|
|
+ .attr('fill', d => getEdgeStyle(d).color)
|
|
|
+ .attr('font-size', '8px')
|
|
|
+ .text(d => getEdgeStyle(d).scoreText)
|
|
|
+
|
|
|
// 节点组
|
|
|
const node = g.append('g')
|
|
|
.selectAll('g')
|
|
|
@@ -299,6 +323,13 @@ function renderGraph() {
|
|
|
.attr('x2', d => d.target.x)
|
|
|
.attr('y2', d => d.target.y)
|
|
|
|
|
|
+ // 分数标签位置(边的中点)
|
|
|
+ linkLabel.attr('transform', d => {
|
|
|
+ const midX = (d.source.x + d.target.x) / 2
|
|
|
+ const midY = (d.source.y + d.target.y) / 2
|
|
|
+ return `translate(${midX},${midY})`
|
|
|
+ })
|
|
|
+
|
|
|
node.attr('transform', d => `translate(${d.x},${d.y})`)
|
|
|
})
|
|
|
}
|