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-18 21:22:18 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-03-18 21:22:18 -0700
commitaed89b8d355915303ba9424ac01be458becc1f77 (patch)
tree30838ac582da6ce8ce13008ecc44e51c0062b2f1 /graphviz.tlv
parentc21cefa8881fbcdbff3206a223cbf58f0e07e5fd (diff)
downloadteliva-aed89b8d355915303ba9424ac01be458becc1f77.tar.gz
graphviz: draft notion of nodes in 'focus'
Now the REPL isn't about deciding what to calculate, but just what nodes
to calculate it for.
Diffstat (limited to 'graphviz.tlv')
-rw-r--r--graphviz.tlv135
1 files changed, 134 insertions, 1 deletions
diff --git a/graphviz.tlv b/graphviz.tlv
index 9a5a776..e2ea160 100644
--- a/graphviz.tlv
+++ b/graphviz.tlv
@@ -165,8 +165,19 @@
     >end
 - __teliva_timestamp: original
   filter:
+    >function filter(h, f)
+    >  result = {}
+    >  for k, v in pairs(h) do
+    >    if f(k, v) then
+    >      result[k] = v
+    >    end
+    >  end
+    >  return result
+    >end
+- __teliva_timestamp: original
+  ifilter:
     >-- only for arrays
-    >function filter(l, f)
+    >function ifilter(l, f)
     >  result = {}
     >  for _, x in ipairs(l) do
     >    if f(x) then
@@ -867,3 +878,125 @@
     >    parse_graph(tokens, graph)
     >  end
     >end
+- __teliva_timestamp:
+    >Fri Mar 18 18:59:24 2022
+  num_nodes:
+    >function num_nodes(Graph)
+    >  local result = 0
+    >  for k, v in pairs(Graph) do
+    >    result = result+1
+    >  end
+    >  return result
+    >end
+- __teliva_timestamp:
+    >Fri Mar 18 19:00:19 2022
+  render_basic_stats:
+    >function render_basic_stats(window)
+    >  window:attrset(curses.A_BOLD)
+    >  window:mvaddstr(1, 1, 'sources: ')
+    >  window:attrset(curses.A_NORMAL)
+    >  local sources = sources(Graph)
+    >  for _, node in ipairs(sources) do
+    >    window:addstr(node)
+    >    window:addstr(' ')
+    >  end
+    >  window:attrset(curses.A_BOLD)
+    >  window:addstr('size: ')
+    >  window:attrset(curses.A_NORMAL)
+    >  window:addstr(tostring(num_nodes(Graph)))
+    >  window:addstr(' nodes')
+    >  window:mvaddstr(3, 0, '')
+    >  local lines, cols = window:getmaxyx()
+    >  for col=1,cols do
+    >    window:addstr('_')
+    >  end
+    >end
+- __teliva_timestamp:
+    >Fri Mar 18 19:01:49 2022
+  main:
+    >function main()
+    >  if #arg == 0 then
+    >    Window:clear()
+    >    print('restart this app with the name of a .dot file')
+    >    Window:refresh()
+    >    while true do Window:getch(); end
+    >  end
+    >  for _, filename in ipairs(arg) do
+    >    read_dot_file(filename, Graph)
+    >  end
+    >  Focus = sources(Graph)
+    >
+    >  while true do
+    >    render(Window)
+    >    update(Window)
+    >  end
+    >end
+- __teliva_timestamp:
+    >Fri Mar 18 19:09:56 2022
+  reachable:
+    >function reachable(graph, node)
+    >  local reached = {}
+    >  local todo = {node}
+    >  while #todo > 0 do
+    >    local curr = table.remove(todo)
+    >    if reached[curr] == nil then
+    >      reached[curr] = true
+    >      local targets = graph[curr]
+    >      if targets then
+    >        for target, _ in pairs(graph[curr]) do
+    >          table.insert(todo, target)
+    >        end
+    >      end
+    >    end
+    >  end
+    >  return reached
+    >end
+- __teliva_timestamp:
+    >Fri Mar 18 20:27:16 2022
+  bold:
+    >function bold(window, text)
+    >  window:attrset(curses.A_BOLD)
+    >  window:addstr(text)
+    >  window:attrset(curses.A_NORMAL)
+    >end
+- __teliva_timestamp:
+    >Fri Mar 18 20:30:39 2022
+  render_queries_on_focus:
+    >function render_queries_on_focus(window)
+    >  local deps = {}
+    >  local needed_by = {}
+    >  for _, node in ipairs(Focus) do
+    >    deps[node] = reachable(Graph, node)
+    >    for dep, _ in pairs(deps[node]) do
+    >      if needed_by[dep] == nil then
+    >        needed_by[dep] = {}
+    >      end
+    >      append(needed_by[dep], {node})
+    >    end
+    >  end
+    >  window:mvaddstr(10, 0, '')
+    >  bold(window, 'universal deps shared by everything in focus: ')
+    >  render_list(window, filter(needed_by, function(node, deps) return #deps == #Focus end))
+    >  for _, node in ipairs(Focus) do
+    >    local y, x = window:getyx()
+    >    window:mvaddstr(y+2, 0, '- '..node)
+    >    bold(window, ' #deps: ')
+    >    window:addstr(num_nodes(deps[node]))
+    >    bold(window, ' overlapping but not universal: ')
+    >    render_list(window, filter(deps[node], function(k, v) return #needed_by[k] > 1 and #needed_by[k] < #Focus end))
+    >    bold(window, ' unique: ')
+    >    render_list(window, filter(deps[node], function(k, v) return #needed_by[k] == 1 end))
+    >  end
+    >end
+- __teliva_timestamp:
+    >Fri Mar 18 20:32:18 2022
+  render_list:
+    >function render_list(window, h)
+    >  window:addstr('(')
+    >  window:addstr(num_nodes(h))
+    >  window:addstr(') ')
+    >  for node, _ in pairs(h) do
+    >    window:addstr(node)
+    >    window:addstr(' ')
+    >  end
+    >end