about summary refs log tree commit diff stats
path: root/graphviz.tlv
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-03-19 21:13:55 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-03-19 21:13:55 -0700
commitc7d3037e9db38a8391c2e3bc4c93eaaeaf7a6b46 (patch)
tree9e19b1c1f994f08897c1a5bf9e58ca9d1213d926 /graphviz.tlv
parentfddbe08fc896e09d0fec2773977341d72103ff90 (diff)
downloadteliva-c7d3037e9db38a8391c2e3bc4c93eaaeaf7a6b46.tar.gz
graphviz: show topology in multiple lines
Diffstat (limited to 'graphviz.tlv')
-rw-r--r--graphviz.tlv81
1 files changed, 69 insertions, 12 deletions
diff --git a/graphviz.tlv b/graphviz.tlv
index 5d8594a..0bdd67b 100644
--- a/graphviz.tlv
+++ b/graphviz.tlv
@@ -581,6 +581,17 @@
     >  end
     >end
 - __teliva_timestamp: original
+  sep:
+    >-- horizontal separator
+    >function sep(window)
+    >  local y, _ = window:getyx()
+    >  window:mvaddstr(y+1, 0, '')
+    >  local _, cols = window:getmaxyx()
+    >  for col=1,cols do
+    >    window:addstr('_')
+    >  end
+    >end
+- __teliva_timestamp: original
   render:
     >function render(window)
     >  window:clear()
@@ -1241,12 +1252,7 @@
     >    window:addstr(node)
     >    window:addstr(' ')
     >  end
-    >  y, _ = window:getyx()
-    >  window:mvaddstr(y+1, 0, '')
-    >  local lines, cols = window:getmaxyx()
-    >  for col=1,cols do
-    >    window:addstr('_')
-    >  end
+    >  sep(window)
     >end
 - __teliva_timestamp:
     >Sat Mar 19 16:33:19 2022
@@ -1261,12 +1267,7 @@
     >    window:addstr(node)
     >    window:addstr(' ')
     >  end
-    >  local y, x = window:getyx()
-    >  window:mvaddstr(y+1, 0, '')
-    >  local lines, cols = window:getmaxyx()
-    >  for col=1,cols do
-    >    window:addstr('_')
-    >  end
+    >  sep(window)
     >end
 - __teliva_timestamp:
     >Sat Mar 19 16:35:34 2022
@@ -1308,3 +1309,59 @@
     >    end
     >  end
     >end
+- __teliva_timestamp:
+    >Sat Mar 19 21:05:05 2022
+  toposort:
+    >-- stable sort of nodes in a graph
+    >-- nodes always occur before all their dependencies
+    >-- disconnected nodes are in alphabetical order
+    >function toposort(graph)
+    >  -- non-map variables are arrays
+    >  -- result = leaves in graph
+    >  -- candidates = non-leaves
+    >  local inResultMap = {}
+    >  local candidatesMap = nodes(graph)
+    >  local leavesMap = filter(candidatesMap, function(k, v) return graph[k] == nil end)
+    >  local leaves = to_array(leavesMap)
+    >  table.sort(leaves)
+    >  union(inResultMap, leavesMap)
+    >  local result = {leaves}
+    >  subtract(candidatesMap, leavesMap)
+    >
+    >  function in_result(x, _) return inResultMap[x] end
+    >  function all_deps_in_result(k, _) return all(graph[k], in_result) end
+    >  while true do
+    >    local oldcount = count(candidatesMap)
+    >    if oldcount == 0 then break end
+    >    local inducteesMap = filter(candidatesMap, all_deps_in_result)
+    >    local inductees = to_array(inducteesMap)
+    >    table.sort(inductees)
+    >    union(inResultMap, inducteesMap)
+    >    table.insert(result, 1, inductees)
+    >    subtract(candidatesMap, inducteesMap)
+    >    if oldcount == count(candidatesMap) then
+    >      error('toposort: graph is not connected')
+    >    end
+    >  end
+    >  return result
+    >end
+- __teliva_timestamp:
+    >Sat Mar 19 21:05:57 2022
+  render_basic_stats:
+    >function render_basic_stats(window)
+    >  bold(window, tostring(#Nodes)..' nodes:')
+    >  local i = 1
+    >  for _, stratum in ipairs(Nodes) do
+    >    window:addstr('\n  ')
+    >    for _, node in ipairs(stratum) do
+    >      window:attrset(curses.A_REVERSE)
+    >      window:addstr(i)
+    >      window:attrset(curses.A_NORMAL)
+    >      window:addstr(' ')
+    >      window:addstr(node)
+    >      window:addstr(' ')
+    >      i = i+1
+    >    end
+    >  end
+    >  sep(window)
+    >end