From d23d934a759bf5a2c54acb51c2e8664a24ebaad0 Mon Sep 17 00:00:00 2001
From: Hans-Peter Deifel <hpd@hpdeifel.de>
Date: Tue, 11 Oct 2016 11:16:20 +0200
Subject: [PATCH] search: Beautify graphs

Makes the nodes rectangular and adds more information in their
description.
---
 src/Search/Search.hs | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/src/Search/Search.hs b/src/Search/Search.hs
index 8438cf7..9fcbf3a 100644
--- a/src/Search/Search.hs
+++ b/src/Search/Search.hs
@@ -144,13 +144,25 @@ handleLine pstdin state = parseLine pstdin >>= \case
 graph2Dot :: Graph -> Text
 graph2Dot graph =
      "digraph gcfg {\n"
+  <> dotNodes graph
   <> M.foldMapWithKey nodeStr graph
   <> "}"
 
   where
     nodeStr from tos = mconcat $ map (arrow from) $ S.toList tos
-    arrow from to = "  " <> num2str from <> " -> "
-      <> num2str to <> " [label=\"" <> edgeLabel (fst from) <> "\"];\n"
-    num2str (call, state) = T.tail state <> "_" <> call
+    arrow from to = "  " <> nodeId from <> " -> "
+      <> nodeId to <> " [label=\"" <> edgeLabel (fst from) <> "\"];\n"
     edgeLabel txt = T.dropEnd 1 $ T.dropWhileEnd (/='_') $
       T.drop (T.length "OSEKOS_") txt
+
+dotNodes :: Graph -> Text
+dotNodes = foldMap formatNode . M.keys
+  where
+    formatNode (call, state) = nodeId (call,state)
+                            <> " [label=\""
+                            <> "State: " <> state <> "\\n"
+                            <> "Syscall: " <> call
+                            <> "\", shape=box];\n"
+
+nodeId :: Vertex -> Text
+nodeId (call, state) = "node" <> state <> "_" <> call
-- 
GitLab