~nch/glue

a32fb30abbc8c27d27549e60d03ecd891f1e69e9 — nc 1 year, 2 months ago b356382
use pandas instead of my bespoke tables for now
1 files changed, 11 insertions(+), 12 deletions(-)

M dataflow.py
M dataflow.py => dataflow.py +11 -12
@@ 1,9 1,9 @@
from dataclasses import dataclass
from typing import *
from table import Table
import pandas as pd

nodes = Table({'id': [], 'value': []}, columns=['id', 'value'])
edges = Table({'from': [], 'to': []}, columns=['from', 'to'])
nodes = pd.DataFrame(columns=['id', 'value'])
edges = pd.DataFrame(columns=['from', 'to'])

class Id(int):
    pass


@@ 11,27 11,26 @@ class Id(int):
def node(val):
    global nodes
    i = len(nodes)
    nodes = nodes.append((i, val))
    nodes = nodes.append({'id': i, 'value': val}, ignore_index=True)
    return Id(i)

def edge(*args):
    global edges
    for a, b in zip(args, args[1:]):
        edges = edges.append((a, b))
        edges = edges.append({'from': a, 'to': b}, ignore_index=True)

def render_graph():
    from graphviz import Digraph
    import os
    dot = Digraph()
    node_names = {}

    for id_, n in nodes.tuples():
        nn = n + f'<{id_}>'
        node_names[id_] = nn
        dot.node(nn)
    for _, r in nodes.iterrows():
        id_, n = r
        dot.node(str(id_), label=str(n))

    for from_, to in edges.tuples():
        dot.edge(node_names[from_], node_names[to])
    for _, r in edges.iterrows():
        from_, to = r
        dot.edge(str(from_), str(to))

    dot.render('test', format='png', view=True)