Skip to content

Commit

Permalink
style: adjusting node size and graphical representation based on in-d…
Browse files Browse the repository at this point in the history
…egree and out-degree
  • Loading branch information
zcf0508 committed Aug 2, 2024
1 parent f08ab79 commit 4713960
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/vis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,23 @@ export function getVisData(
const nodes: CustomNode[] = [];
const edges: Edge[] = [];

const inDegreeMap: Record<string, number> = {};
const outDegreeMap: Record<string, number> = {};
graph.edges.forEach((edge) => {
edge.forEach((to) => {
if (to) {
inDegreeMap[to.label] = (inDegreeMap[to.label] || 0) + 1;
}
});
});
graph.edges.forEach((edge, key) => {
outDegreeMap[key.label] = edge.size;
});

graph.nodes.forEach((node) => {
const inDegree = inDegreeMap[node.label] || 0;
const outDegree = outDegreeMap[node.label] || 0;

nodes.push({
id: node.label,
label: node.label,
Expand All @@ -36,6 +52,7 @@ export function getVisData(
group: usedNodes.has(node.label) || node.info?.used?.size
? 'used'
: 'normal',
size: 20 + 1.6 ** ((inDegree * 0.75 + outDegree * 0.25)),
title: `${
filterNodeUserd(node.info?.used).size
? `used by ${Array.from(filterNodeUserd(node.info?.used))?.map(i => `\`${i}\``).join(',')}\n\n`
Expand Down

0 comments on commit 4713960

Please sign in to comment.