
class Wale:
    def __init__(self, index):
        self.index = index
        self.trace = dict()

    @property
    def width(self):
        return max(len(row) for row in self.trace.values())

class Trace:
    def __init__(self):
        self.wales = dict()
        self.current_row = 0


def get_parents(g, stitch):
    parents = list()
    for nbor, data in p.g[stitch].items():
        if data.get("relation") == "parent":
            parents.append(nbor)
    return parents

def trace(g):
    stitches = dict()
    for stitch_id, data in p.g.nodes(data=True):
        r = data["row_number"]
        c = data["stitch_number"]
        stitches[r, c] = stitch_id
    items = dict()
    current_row = max(r for (r, _) in stitches.keys())
    for (row, col), stitch_id in stitches.items():
        if row == current_row:
            items[col] = (stitch_id, get_parents(g, stitch_id))
    for i in sorted(items):
        child, parent = items[i]




if __name__=="__main__":
    from yarnover.pattern_builder import PatternBuilder

    p = PatternBuilder("")
    p.co(20).turn().k(20).turn().k(20).turn().k(20).turn().k(20).turn()
    trace(p.g)