Skip to content

Commit

Permalink
make more readable
Browse files Browse the repository at this point in the history
  • Loading branch information
crowlKats committed Dec 9, 2024
1 parent 6fc672a commit 5560a81
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions frontend/routes/package/(_islands)/DependencyGraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -182,18 +182,32 @@ export function groupDependencies(
function createDigraph(dependencies: DependencyGraphItem[]) {
const groupedDependencies = groupDependencies(dependencies);

return `digraph "dependencies" {
graph [rankdir="LR"]
node [fontname="Courier", shape="box", style="filled,rounded"]
const nodesWithNoParent = new Set(
Object.keys(groupedDependencies).map(Number),
);

${
groupedDependencies.map(({ children, dependency, size }, index) => {
const depsGraph = groupedDependencies.map(
({ children, dependency, size }, index) => {
return [
` ${index} ${renderDependency(dependency, size)}`,
...children.map((child) => ` ${index} -> ${child}`),
...children.map((child) => {
nodesWithNoParent.delete(child);
return ` ${index} -> ${child}`;
}),
].filter(Boolean).join("\n");
}).join("\n")
},
).join("\n");

return `digraph "dependencies" {
graph [rankdir="LR", concentrate=true]
node [fontname="Courier", shape="box", style="filled,rounded"]
{
rank=same
${Array.from(nodesWithNoParent).join("; ")}
}
${depsGraph}
}`;
}

Expand Down Expand Up @@ -308,7 +322,9 @@ function useDigraph(dependencies: DependencyGraphItem[]) {
if (ref.current && viz.value) {
const digraph = createDigraph(dependencies);

svg.current = viz.value.renderSVGElement(digraph);
svg.current = viz.value.renderSVGElement(digraph, {
engine: "dot",
});
ref.current.prepend(svg.current);

center();
Expand Down

0 comments on commit 5560a81

Please sign in to comment.