Skip to content

Commit

Permalink
feat(insight): adjust edge strength for different types
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Jan 17, 2024
1 parent 48cf751 commit 470151b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
22 changes: 20 additions & 2 deletions plugins/insight/client/index.vue
Expand Up @@ -90,8 +90,26 @@ const svgAttrs = computed(() => {
}
})
const forceLink = d3.forceLink<Node, Link>(links.value).id(node => node.uid)
const forceManyBody = d3.forceManyBody<Node>().strength(-200)
function weight(link: Link) {
return link.type === 'solid' ? 1 : 0.2
}
function degree(node: Node) {
let count = 0
for (const link of links.value) {
if (link.source !== node && link.target !== node) continue
count += weight(link)
}
return count
}
const forceLink = d3.forceLink<Node, Link>(links.value)
.id(node => node.uid)
.strength((link) => {
return weight(link) / Math.min(degree(link.source), degree(link.target))
})
const forceManyBody = d3.forceManyBody<Node>()
const forceX = d3.forceX<Node>()
const forceY = d3.forceY<Node>()
Expand Down
4 changes: 2 additions & 2 deletions plugins/insight/client/link.vue
Expand Up @@ -12,8 +12,8 @@
<line
:x1="link.source.x"
:y1="link.source.y"
:x2="link.target.x"
:y2="link.target.y"
:x2="arrow.x0"
:y2="arrow.y0"
:class="link.type"
/>
<line
Expand Down

0 comments on commit 470151b

Please sign in to comment.