// title: convert arrays to graphviz dot format // author: julian.rohrhuber // description: // Displays a tree from nested arrays for graphviz // code: ( var labels = "", links = "", i = 0; var doDict = { |x, func| if(x.isKindOf(Dictionary)) { x.keysValuesDo { |key, val| func.value(val, i, key) } } { x.do(func) } }; var addNode = { |i, j, key, label = ""| labels = labels ++ "\n% [label=\"%\"]".format(i, label); links = links ++ "\n% -> %".format(j, i); if(key.notNil) { links = links ++ " [label=\"%\"; fontname=Courier]".format(key) }; }; f = { |coll| var j = i, str; doDict.(coll, { |x, k, key| i = i + 1; if(x.isCollection) { addNode.(i, j, key, ""); f.(x); } { addNode.(i, j, key, x.cs); } }); str = "\n\ndigraph {\n" ++ labels ++ "\n" ++ links ++ "\n}"; }; ) f.([1, 2, 3, [2, 3, [1, 2, 3]]];); f.([1, 2, 3, [2, (a: 3, b: [9, 2], c: { 2 + 3 }), [1, 2, 3]]];);