Daniel@0: # Daniel@0: # dotty_draw: drawing functions and data structures Daniel@0: # Daniel@0: dotty.protogt.drawgraph = function (gt, views) { Daniel@0: local gid, eid, nid, graph; Daniel@0: Daniel@0: graph = gt.graph; Daniel@0: gt.drawsgraph (gt, views, graph); Daniel@0: for (gid in graph.graphs) Daniel@0: gt.drawsgraph (gt, views, graph.graphs[gid]); Daniel@0: for (eid in graph.edges) Daniel@0: gt.drawedge (gt, views, graph.edges[eid]); Daniel@0: for (nid in graph.nodes) Daniel@0: gt.drawnode (gt, views, graph.nodes[nid]); Daniel@0: }; Daniel@0: dotty.protogt.redrawgraph = function (gt, views) { Daniel@0: local vid; Daniel@0: Daniel@0: for (vid in views) Daniel@0: clear (views[vid].canvas); Daniel@0: gt.drawgraph (gt, views); Daniel@0: }; Daniel@0: dotty.protogt.setviewsize = function (views, r) { Daniel@0: local vid, vt, w2v, scale, attr; Daniel@0: Daniel@0: for (vid in views) { Daniel@0: vt = views[vid]; Daniel@0: vt.wrect = copy (r); Daniel@0: if (r[1].x == 0 | r[1].y == 0) { Daniel@0: attr = getwidgetattr (vt.scroll, [0 = 'size';]); Daniel@0: vt.wrect[1] = copy (attr.size); Daniel@0: } Daniel@0: if (vt.type == 'birdseye') { Daniel@0: attr = getwidgetattr (vt.scroll, [0 = 'size';]); Daniel@0: scale.x = (vt.wrect[1].x - vt.wrect[0].x) / attr.size.x; Daniel@0: scale.y = (vt.wrect[1].y - vt.wrect[0].y) / attr.size.y; Daniel@0: if (scale.x > 1 & scale.x > scale.y) Daniel@0: vt.w2v = scale.x; Daniel@0: else if (scale.y > 1) Daniel@0: vt.w2v = scale.y; Daniel@0: else Daniel@0: vt.w2v = 1; Daniel@0: } Daniel@0: w2v = vt.w2v; Daniel@0: vt.vsize = [ Daniel@0: 'x' = toint ((vt.wrect[1].x - vt.wrect[0].x) / w2v); Daniel@0: 'y' = toint ((vt.wrect[1].y - vt.wrect[0].y) / w2v); Daniel@0: ]; Daniel@0: setwidgetattr (vt.canvas, [ Daniel@0: 'window' = vt.wrect; Daniel@0: 'viewport' = vt.vsize; Daniel@0: ]); Daniel@0: attr = getwidgetattr (vt.canvas, [0 = 'viewport';]); Daniel@0: vt.vsize = copy (attr.viewport); Daniel@0: } Daniel@0: }; Daniel@0: dotty.protogt.setviewscale = function (views, factor) { Daniel@0: local vid, vt, w2v, attr; Daniel@0: Daniel@0: for (vid in views) { Daniel@0: vt = views[vid]; Daniel@0: if ((w2v = vt.w2v * factor) < 0.01) { Daniel@0: dotty.message (0, 'cannot zoom any closer'); Daniel@0: return; Daniel@0: } Daniel@0: vt.w2v = w2v; Daniel@0: vt.vsize = [ Daniel@0: 'x' = (vt.wrect[1].x - vt.wrect[0].x) / w2v; Daniel@0: 'y' = (vt.wrect[1].y - vt.wrect[0].y) / w2v; Daniel@0: ]; Daniel@0: setwidgetattr (vt.canvas, ['viewport' = vt.vsize;]); Daniel@0: attr = getwidgetattr (vt.canvas, [0 = 'viewport';]); Daniel@0: vt.vsize = copy (attr.viewport); Daniel@0: } Daniel@0: }; Daniel@0: dotty.protogt.setviewcenter = function (views, center) { Daniel@0: local vid, vt, pos; Daniel@0: Daniel@0: for (vid in views) { Daniel@0: vt = views[vid]; Daniel@0: pos = [ Daniel@0: 'x' = center.x * vt.vsize.x / (vt.wrect[1].x - vt.wrect[0].x); Daniel@0: 'y' = ( Daniel@0: (vt.wrect[1].y - center.y) * vt.vsize.y / Daniel@0: (vt.wrect[1].y - vt.wrect[0].y) Daniel@0: ); Daniel@0: ]; Daniel@0: setwidgetattr (vt.scroll, ['childcenter' = pos;]); Daniel@0: } Daniel@0: }; Daniel@0: # Daniel@0: # draw graph components Daniel@0: # Daniel@0: dotty.protogt.drawsgraph = function (gt, views, sgraph) { Daniel@0: sgraph.draw = 1; Daniel@0: if (~sgraph.draws) Daniel@0: return; Daniel@0: gt.execalldraw (gt, views, null, sgraph.draws, [ Daniel@0: 'fontname' = sgraph.fontname; Daniel@0: 'fontsize' = sgraph.fontsize; Daniel@0: 'fontcolor' = sgraph.fontcolor; Daniel@0: 'drawcolor' = sgraph.drawcolor; Daniel@0: 'fillcolor' = sgraph.fillcolor; Daniel@0: ]); Daniel@0: }; Daniel@0: dotty.protogt.undrawsgraph = function (gt, views, sgraph) { Daniel@0: sgraph.drawn = 0; Daniel@0: if (~sgraph.draws) Daniel@0: return; Daniel@0: gt.execalldraw (gt, views, null, sgraph.draws, [ Daniel@0: 'fontname' = sgraph.fontname; Daniel@0: 'fontsize' = sgraph.fontsize; Daniel@0: 'fontcolor' = sgraph.fontcolor; Daniel@0: 'drawcolor' = 0; Daniel@0: 'fillcolor' = 0; Daniel@0: ]); Daniel@0: }; Daniel@0: dotty.protogt.drawnode = function (gt, views, node) { Daniel@0: local vid; Daniel@0: Daniel@0: node.drawn = 1; Daniel@0: if (~node.draws) Daniel@0: return; Daniel@0: gt.execalldraw (gt, views, node, node.draws, [ Daniel@0: 'fontname' = node.fontname; Daniel@0: 'fontsize' = node.fontsize; Daniel@0: 'fontcolor' = node.fontcolor; Daniel@0: 'drawcolor' = node.drawcolor; Daniel@0: 'fillcolor' = node.fillcolor; Daniel@0: ]); Daniel@0: for (vid in views) Daniel@0: setpick (views[vid].canvas, node, node.rect); Daniel@0: }; Daniel@0: dotty.protogt.undrawnode = function (gt, views, node) { Daniel@0: local vid; Daniel@0: Daniel@0: if (~node.drawn) Daniel@0: return; Daniel@0: node.drawn = 0; Daniel@0: if (~node.pos) Daniel@0: return; Daniel@0: gt.execalldraw (gt, views, node, node.draws, [ Daniel@0: 'nooverride' = 1; Daniel@0: 'fontname' = node.fontname; Daniel@0: 'fontsize' = node.fontsize; Daniel@0: 'fontcolor' = 0; Daniel@0: 'drawcolor' = 0; Daniel@0: 'fillcolor' = 0; Daniel@0: ]); Daniel@0: for (vid in views) Daniel@0: clearpick (views[vid].canvas, node); Daniel@0: }; Daniel@0: dotty.protogt.movenode = function (gt, node, pos) { Daniel@0: local dp, eid, edge; Daniel@0: Daniel@0: dp.x = pos.x - node.pos.x; Daniel@0: dp.y = pos.y - node.pos.y; Daniel@0: gt.undrawnode (gt, gt.views, node); Daniel@0: node.pos.x = pos.x; Daniel@0: node.pos.y = pos.y; Daniel@0: gt.movenodedraw (node.draws, dp); Daniel@0: for (eid in node.edges) { Daniel@0: edge = node.edges[eid]; Daniel@0: gt.undrawedge (gt, gt.views, edge); Daniel@0: gt.moveedgedraw (edge.draws, edge.tail.pos, edge.head.pos); Daniel@0: gt.drawedge (gt, gt.views, edge); Daniel@0: } Daniel@0: gt.drawnode (gt, gt.views, node); Daniel@0: }; Daniel@0: dotty.protogt.drawedge = function (gt, views, edge) { Daniel@0: local vid, canvas; Daniel@0: Daniel@0: edge.drawn = 1; Daniel@0: if (~edge.draws) Daniel@0: return; Daniel@0: gt.execalldraw (gt, views, edge, edge.draws, [ Daniel@0: 'fontname' = edge.fontname; Daniel@0: 'fontsize' = edge.fontsize; Daniel@0: 'fontcolor' = edge.fontcolor; Daniel@0: 'drawcolor' = edge.drawcolor; Daniel@0: 'fillcolor' = edge.fillcolor; Daniel@0: ]); Daniel@0: for (vid in views) { Daniel@0: canvas = views[vid].canvas; Daniel@0: if (gt.edgehandles == 0 | ~edge.draws.ep) Daniel@0: continue; Daniel@0: arc (canvas, edge, edge.draws.ep, ['x' = 5; 'y' = 5;], ['color' = 1;]); Daniel@0: } Daniel@0: }; Daniel@0: dotty.protogt.undrawedge = function (gt, views, edge) { Daniel@0: local vid, canvas; Daniel@0: Daniel@0: if (~edge.drawn) Daniel@0: return; Daniel@0: edge.drawn = 0; Daniel@0: if (~edge.draws) Daniel@0: return; Daniel@0: gt.execalldraw (gt, views, edge, edge.draws, [ Daniel@0: 'nooverride' = 1; Daniel@0: 'fontname' = edge.fontname; Daniel@0: 'fontsize' = edge.fontsize; Daniel@0: 'fontcolor' = 0; Daniel@0: 'drawcolor' = 0; Daniel@0: 'fillcolor' = 0; Daniel@0: ]); Daniel@0: for (vid in views) { Daniel@0: canvas = views[vid].canvas; Daniel@0: if (gt.edgehandles == 0 | ~edge.draws.ep) Daniel@0: continue; Daniel@0: arc (canvas, edge, edge.draws.ep, ['x' = 5; 'y' = 5;], ['color' = 0;]); Daniel@0: clearpick (canvas, edge); Daniel@0: } Daniel@0: }; Daniel@0: # Daniel@0: # draw directives Daniel@0: # Daniel@0: dotty.protogt.execalldraw = function (gt, views, obj, draws, gc) { Daniel@0: local vid, vt, did, draw, i, func; Daniel@0: Daniel@0: for (vid in views) { Daniel@0: vt = views[vid]; Daniel@0: for (did in draws) { Daniel@0: if (did == 'ep') Daniel@0: continue; Daniel@0: draw = draws[did]; Daniel@0: for (i = 0; draw[i]; i = i + 1) Daniel@0: if ((func = gt.drawfunc[draw[i].type])) Daniel@0: func (gt, vt.canvas, obj, draw[i], gc); Daniel@0: } Daniel@0: } Daniel@0: }; Daniel@0: dotty.protogt.drawfunc.E = function (gt, canvas, obj, data, gc) { Daniel@0: arc (canvas, obj, data.c, data.s, [ Daniel@0: 'color' = gc.fillcolor; 'style' = gc.style; 'width' = gc.width; Daniel@0: 'fill' = 'on'; Daniel@0: ]); Daniel@0: arc (canvas, obj, data.c, data.s, [ Daniel@0: 'color' = gc.drawcolor; 'style' = gc.style; 'width' = gc.width; Daniel@0: ]); Daniel@0: }; Daniel@0: dotty.protogt.drawfunc.e = function (gt, canvas, obj, data, gc) { Daniel@0: arc (canvas, obj, data.c, data.s, [ Daniel@0: 'color' = gc.drawcolor; 'style' = gc.style; 'width' = gc.width; Daniel@0: ]); Daniel@0: }; Daniel@0: dotty.protogt.drawfunc.P = function (gt, canvas, obj, data, gc) { Daniel@0: polygon (canvas, obj, data.ps, [ Daniel@0: 'color' = gc.fillcolor; 'style' = gc.style; 'width' = gc.width; Daniel@0: 'fill' = 'on'; Daniel@0: ]); Daniel@0: polygon (canvas, obj, data.ps, [ Daniel@0: 'color' = gc.drawcolor; 'style' = gc.style; 'width' = gc.width; Daniel@0: ]); Daniel@0: }; Daniel@0: dotty.protogt.drawfunc.p = function (gt, canvas, obj, data, gc) { Daniel@0: polygon (canvas, obj, data.ps, [ Daniel@0: 'color' = gc.drawcolor; 'style' = gc.style; 'width' = gc.width; Daniel@0: ]); Daniel@0: }; Daniel@0: dotty.protogt.drawfunc.L = function (gt, canvas, obj, data, gc) { Daniel@0: polygon (canvas, obj, data.ps, [ Daniel@0: 'color' = gc.drawcolor; 'style' = gc.style; 'width' = gc.width; Daniel@0: ]); Daniel@0: }; Daniel@0: dotty.protogt.drawfunc.b = function (gt, canvas, obj, data, gc) { Daniel@0: splinegon (canvas, obj, data.ps, [ Daniel@0: 'color' = gc.fillcolor; 'style' = gc.style; 'width' = gc.width; Daniel@0: 'fill' = 'on'; Daniel@0: ]); Daniel@0: }; Daniel@0: dotty.protogt.drawfunc.B = function (gt, canvas, obj, data, gc) { Daniel@0: splinegon (canvas, obj, data.ps, [ Daniel@0: 'color' = gc.drawcolor; 'style' = gc.style; 'width' = gc.width; Daniel@0: ]); Daniel@0: }; Daniel@0: dotty.protogt.drawfunc.T = function (gt, canvas, obj, data, gc) { Daniel@0: text (canvas, obj, data.p, data.s, gc.fontname, gc.fontsize, data.j, [ Daniel@0: 'color' = gc.fontcolor; 'style' = gc.style; 'width' = gc.width; Daniel@0: ]); Daniel@0: }; Daniel@0: dotty.protogt.drawfunc.C = function (gt, canvas, obj, data, gc) { Daniel@0: if (gc.nooverride ~= 1) Daniel@0: gc.fillcolor = data.fillcolor; Daniel@0: }; Daniel@0: dotty.protogt.drawfunc.c = function (gt, canvas, obj, data, gc) { Daniel@0: if (gc.nooverride ~= 1) { Daniel@0: gc.drawcolor = data.drawcolor; Daniel@0: gc.fontcolor = data.drawcolor; Daniel@0: } Daniel@0: }; Daniel@0: dotty.protogt.drawfunc.F = function (gt, canvas, obj, data, gc) { Daniel@0: gc.fontname = data.fn; Daniel@0: gc.fontsize = data.fs; Daniel@0: }; Daniel@0: dotty.protogt.drawfunc.S = function (gt, canvas, obj, data, gc) { Daniel@0: gc.style = data.style; Daniel@0: gc.width = data.width; Daniel@0: }; Daniel@0: dotty.protogt.movenodedraw = function (draws, dp) { Daniel@0: local did, draw, i, j; Daniel@0: Daniel@0: for (did in draws) { Daniel@0: if (did == 'ep') Daniel@0: continue; Daniel@0: draw = draws[did]; Daniel@0: for (i = 0; draw[i]; i = i + 1) { Daniel@0: if (draw[i].type == 'E' | draw[i].type == 'e') { Daniel@0: draw[i].c.x = draw[i].c.x + dp.x; Daniel@0: draw[i].c.y = draw[i].c.y + dp.y; Daniel@0: } else if (draw[i].type == 'P' | draw[i].type == 'p') { Daniel@0: for (j = 1; draw[i].ps[j]; j = j + 1) { Daniel@0: draw[i].ps[j].x = draw[i].ps[j].x + dp.x; Daniel@0: draw[i].ps[j].y = draw[i].ps[j].y + dp.y; Daniel@0: } Daniel@0: } else if (draw[i].type == 'L' | draw[i].type == 'B') { Daniel@0: for (j = 0; draw[i].ps[j]; j = j + 1) { Daniel@0: draw[i].ps[j].x = draw[i].ps[j].x + dp.x; Daniel@0: draw[i].ps[j].y = draw[i].ps[j].y + dp.y; Daniel@0: } Daniel@0: } else if (draw[i].type == 'T') { Daniel@0: draw[i].p.x = draw[i].p.x + dp.x; Daniel@0: draw[i].p.y = draw[i].p.y + dp.y; Daniel@0: } Daniel@0: } Daniel@0: } Daniel@0: }; Daniel@0: dotty.protogt.moveedgedraw = function (draws, tp, hp) { Daniel@0: local draws2, did; Daniel@0: Daniel@0: for (did in draws) Daniel@0: draws2[did] = draws[did]; Daniel@0: for (did in draws2) Daniel@0: remove (did, draws); Daniel@0: draws[0] = [ Daniel@0: 0 = [ Daniel@0: 'type' = 'L'; Daniel@0: 'n' = 2; Daniel@0: 'ps' = [ Daniel@0: 0 = copy (tp); Daniel@0: 1 = copy (hp); Daniel@0: ]; Daniel@0: ]; Daniel@0: 'ep' = ['x' = (tp.x + hp.x) / 2; 'y' = (tp.y + hp.y) / 2;]; Daniel@0: ]; Daniel@0: }; Daniel@0: dotty.protogt.simplenodedraw = function (node, c, s) { Daniel@0: local draws; Daniel@0: Daniel@0: if (node.attr.shape == 'ellipse') Daniel@0: draws[0] = [ Daniel@0: 0 = [ Daniel@0: 'type' = 'e'; Daniel@0: 'c' = copy (c); Daniel@0: 's' = ['x' = s.x / 2; 'y' = s.y / 2;]; Daniel@0: ]; Daniel@0: ]; Daniel@0: else Daniel@0: draws[0] = [ Daniel@0: 0 = [ Daniel@0: 'type' = 'p'; Daniel@0: 'n' = 5; Daniel@0: 'ps' = [ Daniel@0: 0 = ['x' = c.x - s.x / 2; 'y' = c.y - s.y / 2;]; Daniel@0: 1 = ['x' = c.x + s.x / 2; 'y' = c.y - s.y / 2;]; Daniel@0: 2 = ['x' = c.x + s.x / 2; 'y' = c.y + s.y / 2;]; Daniel@0: 3 = ['x' = c.x - s.x / 2; 'y' = c.y + s.y / 2;]; Daniel@0: 4 = ['x' = c.x - s.x / 2; 'y' = c.y - s.y / 2;]; Daniel@0: ]; Daniel@0: ]; Daniel@0: ]; Daniel@0: return draws; Daniel@0: }; Daniel@0: dotty.protogt.simpleedgedraw = function (edge, tp, hp) { Daniel@0: local draws; Daniel@0: Daniel@0: draws[0] = [ Daniel@0: 0 = [ Daniel@0: 'type' = 'L'; Daniel@0: 'n' = 2; Daniel@0: 'ps' = [ Daniel@0: 0 = copy (tp); Daniel@0: 1 = copy (hp); Daniel@0: ]; Daniel@0: ]; Daniel@0: 'ep' = ['x' = (tp.x + hp.x) / 2; 'y' = (tp.y + hp.y) / 2;]; Daniel@0: ]; Daniel@0: return draws; Daniel@0: }; Daniel@0: # Daniel@0: # utilities Daniel@0: # Daniel@0: dotty.protogt.getcolor = function (views, name) { Daniel@0: local vid, vt, color, t; Daniel@0: Daniel@0: for (vid in views) { Daniel@0: vt = views[vid]; Daniel@0: if (~(color >= 0)) { Daniel@0: if (~(vt.colors[name] >= 0)) Daniel@0: color = (vt.colors[name] = vt.colorn); Daniel@0: else { Daniel@0: color = vt.colors[name]; Daniel@0: break; Daniel@0: } Daniel@0: } else if (~(vt.colors[name] >= 0)) Daniel@0: vt.colors[name] = color; Daniel@0: else if (vt.colors[name] ~= color) Daniel@0: dotty.message (0, concat ('inconsistent color ids for ', name)); Daniel@0: if (setwidgetattr (vt.canvas, ['color' = [color = name;];]) ~= 1) { Daniel@0: t = split (name, ' '); Daniel@0: if (tablesize (t) ~= 3 | Daniel@0: setwidgetattr (vt.canvas, ['color' = [color = [ Daniel@0: 'h' = ston (t[0]); 's' = ston (t[1]); 'v' = ston (t[2]); Daniel@0: ];];]) ~= 1) { Daniel@0: dotty.message (0, concat ('unknown color ', name, ' using #1')); Daniel@0: return 1; Daniel@0: } Daniel@0: } Daniel@0: vt.colorn = color + 1; Daniel@0: } Daniel@0: return color; Daniel@0: }; Daniel@0: dotty.protogt.setbgcolor = function (views, name) { Daniel@0: local vid, vt, t; Daniel@0: Daniel@0: for (vid in views) { Daniel@0: vt = views[vid]; Daniel@0: if (setwidgetattr (vt.canvas, ['color' = [0 = name;];]) ~= 1) { Daniel@0: t = split (name, ' '); Daniel@0: if (tablesize (t) ~= 3 | Daniel@0: setwidgetattr (vt.canvas, ['color' = [0 = [ Daniel@0: 'h' = ston (t[0]); 's' = ston (t[1]); 'v' = ston (t[2]); Daniel@0: ];];]) ~= 1) { Daniel@0: dotty.message (0, concat ('unknown bgcolor ', name)); Daniel@0: return; Daniel@0: } Daniel@0: } Daniel@0: vt.colors['_bgcolor_'] = name; Daniel@0: } Daniel@0: }; Daniel@0: dotty.protogt.unpacksgraphattr = function (gt, sgraph) { Daniel@0: local attr; Daniel@0: Daniel@0: attr = sgraph.graphattr; Daniel@0: if (dotty.fontmap[attr.fontname]) Daniel@0: sgraph[dotty.keys.fname] = dotty.fontmap[attr.fontname]; Daniel@0: else Daniel@0: sgraph[dotty.keys.fname] = attr.fontname; Daniel@0: sgraph[dotty.keys.fsize] = ston (attr.fontsize); Daniel@0: sgraph[dotty.keys.fcolor] = gt.getcolor (gt.views, attr.fontcolor); Daniel@0: if (attr.color) Daniel@0: sgraph[dotty.keys.dcolor] = gt.getcolor (gt.views, attr.color); Daniel@0: else Daniel@0: sgraph[dotty.keys.dcolor] = gt.getcolor (gt.views, 'black'); Daniel@0: if (attr.style == 'filled') { Daniel@0: if (attr.fillcolor) Daniel@0: sgraph[dotty.keys.bcolor] = gt.getcolor (gt.views, attr.fillcolor); Daniel@0: else if (attr.color) Daniel@0: sgraph[dotty.keys.bcolor] = gt.getcolor (gt.views, attr.color); Daniel@0: else Daniel@0: sgraph[dotty.keys.bcolor] = gt.getcolor (gt.views, 'lightgrey'); Daniel@0: } Daniel@0: }; Daniel@0: dotty.protogt.unpacknodeattr = function (gt, node) { Daniel@0: local attr; Daniel@0: Daniel@0: attr = node.attr; Daniel@0: if (dotty.fontmap[attr.fontname]) Daniel@0: node[dotty.keys.fname] = dotty.fontmap[attr.fontname]; Daniel@0: else Daniel@0: node[dotty.keys.fname] = attr.fontname; Daniel@0: node[dotty.keys.fsize] = ston (attr.fontsize); Daniel@0: node[dotty.keys.fcolor] = gt.getcolor (gt.views, attr.fontcolor); Daniel@0: if (attr.color) Daniel@0: node[dotty.keys.dcolor] = gt.getcolor (gt.views, attr.color); Daniel@0: else Daniel@0: node[dotty.keys.dcolor] = gt.getcolor (gt.views, 'black'); Daniel@0: if (attr.style == 'filled') { Daniel@0: if (attr.fillcolor) Daniel@0: node[dotty.keys.bcolor] = gt.getcolor (gt.views, attr.fillcolor); Daniel@0: else if (attr.color) Daniel@0: node[dotty.keys.bcolor] = gt.getcolor (gt.views, attr.color); Daniel@0: else Daniel@0: node[dotty.keys.bcolor] = gt.getcolor (gt.views, 'lightgrey'); Daniel@0: } Daniel@0: }; Daniel@0: dotty.protogt.unpackedgeattr = function (gt, edge) { Daniel@0: local attr; Daniel@0: Daniel@0: attr = edge.attr; Daniel@0: if (dotty.fontmap[attr.fontname]) Daniel@0: edge[dotty.keys.fname] = dotty.fontmap[attr.fontname]; Daniel@0: else Daniel@0: edge[dotty.keys.fname] = attr.fontname; Daniel@0: edge[dotty.keys.fsize] = ston (attr.fontsize); Daniel@0: edge[dotty.keys.fcolor] = gt.getcolor (gt.views, attr.fontcolor); Daniel@0: if (attr.color) Daniel@0: edge[dotty.keys.dcolor] = gt.getcolor (gt.views, attr.color); Daniel@0: else Daniel@0: edge[dotty.keys.dcolor] = gt.getcolor (gt.views, 'black'); Daniel@0: if (attr.style == 'filled') { Daniel@0: if (attr.fillcolor) Daniel@0: edge[dotty.keys.bcolor] = gt.getcolor (gt.views, attr.fillcolor); Daniel@0: else if (attr.color) Daniel@0: edge[dotty.keys.bcolor] = gt.getcolor (gt.views, attr.color); Daniel@0: else Daniel@0: edge[dotty.keys.bcolor] = gt.getcolor (gt.views, 'lightgrey'); Daniel@0: } Daniel@0: }; Daniel@0: dotty.protogt.unpackattr = function (gt) { Daniel@0: local gid, sgraph, nid, node, eid, edge, graph, attr; Daniel@0: Daniel@0: graph = gt.graph; Daniel@0: attr = graph.graphattr; Daniel@0: if (dotty.fontmap[attr.fontname]) Daniel@0: graph[dotty.keys.fname] = dotty.fontmap[attr.fontname]; Daniel@0: else Daniel@0: graph[dotty.keys.fname] = attr.fontname; Daniel@0: graph[dotty.keys.fsize] = ston (attr.fontsize); Daniel@0: graph[dotty.keys.fcolor] = gt.getcolor (gt.views, attr.fontcolor); Daniel@0: if (attr.color) Daniel@0: graph[dotty.keys.dcolor] = gt.getcolor (gt.views, attr.color); Daniel@0: else Daniel@0: graph[dotty.keys.dcolor] = gt.getcolor (gt.views, 'black'); Daniel@0: if (attr.style == 'filled') { Daniel@0: if (attr.fillcolor) Daniel@0: graph[dotty.keys.bcolor] = gt.getcolor (gt.views, attr.fillcolor); Daniel@0: else if (attr.color) Daniel@0: graph[dotty.keys.bcolor] = gt.getcolor (gt.views, attr.color); Daniel@0: else Daniel@0: graph[dotty.keys.bcolor] = gt.getcolor (gt.views, 'lightgrey'); Daniel@0: } Daniel@0: if (attr.bgcolor & attr.bgcolor ~= '') Daniel@0: gt.setbgcolor (gt.views, attr.bgcolor); Daniel@0: for (gid in graph.graphdict) { Daniel@0: sgraph = graph.graphs[graph.graphdict[gid]]; Daniel@0: attr = sgraph.graphattr; Daniel@0: if (dotty.fontmap[attr.fontname]) Daniel@0: sgraph[dotty.keys.fname] = dotty.fontmap[attr.fontname]; Daniel@0: else Daniel@0: sgraph[dotty.keys.fname] = attr.fontname; Daniel@0: sgraph[dotty.keys.fsize] = ston (attr.fontsize); Daniel@0: sgraph[dotty.keys.fcolor] = gt.getcolor (gt.views, attr.fontcolor); Daniel@0: if (attr.color) Daniel@0: sgraph[dotty.keys.dcolor] = gt.getcolor (gt.views, attr.color); Daniel@0: else Daniel@0: sgraph[dotty.keys.dcolor] = gt.getcolor (gt.views, 'black'); Daniel@0: if (attr.style == 'filled') { Daniel@0: if (attr.fillcolor) Daniel@0: sgraph[dotty.keys.bcolor] = gt.getcolor ( Daniel@0: gt.views, attr.fillcolor Daniel@0: ); Daniel@0: else if (attr.color) Daniel@0: sgraph[dotty.keys.bcolor] = gt.getcolor (gt.views, attr.color); Daniel@0: else Daniel@0: sgraph[dotty.keys.bcolor] = gt.getcolor (gt.views, 'lightgrey'); Daniel@0: } Daniel@0: } Daniel@0: for (nid in graph.nodedict) { Daniel@0: node = graph.nodes[graph.nodedict[nid]]; Daniel@0: attr = node.attr; Daniel@0: if (dotty.fontmap[attr.fontname]) Daniel@0: node[dotty.keys.fname] = dotty.fontmap[attr.fontname]; Daniel@0: else Daniel@0: node[dotty.keys.fname] = attr.fontname; Daniel@0: node[dotty.keys.fsize] = ston (attr.fontsize); Daniel@0: node[dotty.keys.fcolor] = gt.getcolor (gt.views, attr.fontcolor); Daniel@0: if (attr.color) Daniel@0: node[dotty.keys.dcolor] = gt.getcolor (gt.views, attr.color); Daniel@0: else Daniel@0: node[dotty.keys.dcolor] = gt.getcolor (gt.views, 'black'); Daniel@0: if (attr.style == 'filled') { Daniel@0: if (attr.fillcolor) Daniel@0: node[dotty.keys.bcolor] = gt.getcolor ( Daniel@0: gt.views, attr.fillcolor Daniel@0: ); Daniel@0: else if (attr.color) Daniel@0: node[dotty.keys.bcolor] = gt.getcolor (gt.views, attr.color); Daniel@0: else Daniel@0: node[dotty.keys.bcolor] = gt.getcolor (gt.views, 'lightgrey'); Daniel@0: } Daniel@0: } Daniel@0: for (eid in graph.edges) { Daniel@0: edge = graph.edges[eid]; Daniel@0: attr = edge.attr; Daniel@0: if (dotty.fontmap[attr.fontname]) Daniel@0: edge[dotty.keys.fname] = dotty.fontmap[attr.fontname]; Daniel@0: else Daniel@0: edge[dotty.keys.fname] = attr.fontname; Daniel@0: edge[dotty.keys.fsize] = ston (attr.fontsize); Daniel@0: edge[dotty.keys.fcolor] = gt.getcolor (gt.views, attr.fontcolor); Daniel@0: if (attr.color) Daniel@0: edge[dotty.keys.dcolor] = gt.getcolor (gt.views, attr.color); Daniel@0: else Daniel@0: edge[dotty.keys.dcolor] = gt.getcolor (gt.views, 'black'); Daniel@0: } Daniel@0: };