Skip to content

Commit

Permalink
node shapes to indicate --to and --from
Browse files Browse the repository at this point in the history
  • Loading branch information
kim-em committed Oct 29, 2024
1 parent 6e19e75 commit fe586e6
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions ImportGraph/Cli.lean
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,24 @@ def asDotGraph
(unused : NameSet := {})
(header := "import_graph")
(markedPackage : Option Name := none)
(directDeps : NameSet := {}) :
(directDeps : NameSet := {})
(from_ to : NameSet := {}):
String := Id.run do

let mut lines := #[s!"digraph \"{header}\" " ++ "{"]
for (n, is) in graph do
let shape := if from_.contains n then "invhouse" else if to.contains n then "house" else "ellipse"
if markedPackage.isSome ∧ directDeps.contains n then
-- note: `fillcolor` defaults to `color` if not specified
let fill := if unused.contains n then "#e0e0e0" else "white"
lines := lines.push s!" \"{n}\" [style=filled, fontcolor=\"#4b762d\", color=\"#71b144\", fillcolor=\"{fill}\", penwidth=2];"
lines := lines.push s!" \"{n}\" [style=filled, fontcolor=\"#4b762d\", color=\"#71b144\", fillcolor=\"{fill}\", penwidth=2, shape={shape}];"
else if unused.contains n then
lines := lines.push s!" \"{n}\" [style=filled, fillcolor=\"#e0e0e0\"];"
lines := lines.push s!" \"{n}\" [style=filled, fillcolor=\"#e0e0e0\", shape={shape}];"
else if isInModule markedPackage n then
-- mark node
lines := lines.push s!" \"{n}\" [style=filled, fillcolor=\"#96ec5b\"];"
lines := lines.push s!" \"{n}\" [style=filled, fillcolor=\"#96ec5b\", shape={shape}];"
else
lines := lines.push s!" \"{n}\";"
lines := lines.push s!" \"{n}\" [shape={shape}];"
-- Then add edges
for i in is do
if isInModule markedPackage n then
Expand Down Expand Up @@ -148,6 +150,7 @@ def importGraphCLI (args : Cli.Parsed) : IO UInt32 := do
let mut outFiles : Std.HashMap String String := {}
if extensions.contains "dot" then
let dotFile := asDotGraph graph (unused := unused) (markedPackage := markedPackage) (directDeps := directDeps)
(to := NameSet.ofArray to) (from_ := NameSet.ofArray (from?.getD #[]))
outFiles := outFiles.insert "dot" dotFile
if extensions.contains "gexf" then
-- filter out the top node as it makes the graph less pretty
Expand Down

0 comments on commit fe586e6

Please sign in to comment.