initial commit
This commit is contained in:
24
src/Graphviz.tsx
Normal file
24
src/Graphviz.tsx
Normal file
@@ -0,0 +1,24 @@
|
||||
export function graphToDot(g) {
|
||||
// Directed graph, use neato layout so we can use pos attributes
|
||||
const lines = [];
|
||||
lines.push('digraph G {');
|
||||
lines.push(' graph [splines=true, overlap=false, rankdir=LR];');
|
||||
lines.push(' node [shape=rectangle, style=filled, fillcolor="white", fontsize=12];');
|
||||
|
||||
// nodes
|
||||
for (const n of g.nodes) {
|
||||
const attrs = [];
|
||||
attrs.push(`label=\"${n.label}\"`);
|
||||
attrs.push(`id=\"${n.id}\"`)
|
||||
lines.push(` \"${n.id}\" [${attrs.join(', ')}];`);
|
||||
}
|
||||
|
||||
// edges
|
||||
for (const e of g.edges) {
|
||||
lines.push(` \"${e.from}\" -> \"${e.to}\";`);
|
||||
}
|
||||
|
||||
// close
|
||||
lines.push('}');
|
||||
return lines.join('\n');
|
||||
}
|
||||
Reference in New Issue
Block a user