annotate toolboxes/graph_visualisation/lib/lefty/dotty_draw.lefty @ 0:cc4b1211e677 tip

initial commit to HG from Changeset: 646 (e263d8a21543) added further path and more save "camirversion.m"
author Daniel Wolff
date Fri, 19 Aug 2016 13:07:06 +0200
parents
children
rev   line source
Daniel@0 1 #
Daniel@0 2 # dotty_draw: drawing functions and data structures
Daniel@0 3 #
Daniel@0 4 dotty.protogt.drawgraph = function (gt, views) {
Daniel@0 5 local gid, eid, nid, graph;
Daniel@0 6
Daniel@0 7 graph = gt.graph;
Daniel@0 8 gt.drawsgraph (gt, views, graph);
Daniel@0 9 for (gid in graph.graphs)
Daniel@0 10 gt.drawsgraph (gt, views, graph.graphs[gid]);
Daniel@0 11 for (eid in graph.edges)
Daniel@0 12 gt.drawedge (gt, views, graph.edges[eid]);
Daniel@0 13 for (nid in graph.nodes)
Daniel@0 14 gt.drawnode (gt, views, graph.nodes[nid]);
Daniel@0 15 };
Daniel@0 16 dotty.protogt.redrawgraph = function (gt, views) {
Daniel@0 17 local vid;
Daniel@0 18
Daniel@0 19 for (vid in views)
Daniel@0 20 clear (views[vid].canvas);
Daniel@0 21 gt.drawgraph (gt, views);
Daniel@0 22 };
Daniel@0 23 dotty.protogt.setviewsize = function (views, r) {
Daniel@0 24 local vid, vt, w2v, scale, attr;
Daniel@0 25
Daniel@0 26 for (vid in views) {
Daniel@0 27 vt = views[vid];
Daniel@0 28 vt.wrect = copy (r);
Daniel@0 29 if (r[1].x == 0 | r[1].y == 0) {
Daniel@0 30 attr = getwidgetattr (vt.scroll, [0 = 'size';]);
Daniel@0 31 vt.wrect[1] = copy (attr.size);
Daniel@0 32 }
Daniel@0 33 if (vt.type == 'birdseye') {
Daniel@0 34 attr = getwidgetattr (vt.scroll, [0 = 'size';]);
Daniel@0 35 scale.x = (vt.wrect[1].x - vt.wrect[0].x) / attr.size.x;
Daniel@0 36 scale.y = (vt.wrect[1].y - vt.wrect[0].y) / attr.size.y;
Daniel@0 37 if (scale.x > 1 & scale.x > scale.y)
Daniel@0 38 vt.w2v = scale.x;
Daniel@0 39 else if (scale.y > 1)
Daniel@0 40 vt.w2v = scale.y;
Daniel@0 41 else
Daniel@0 42 vt.w2v = 1;
Daniel@0 43 }
Daniel@0 44 w2v = vt.w2v;
Daniel@0 45 vt.vsize = [
Daniel@0 46 'x' = toint ((vt.wrect[1].x - vt.wrect[0].x) / w2v);
Daniel@0 47 'y' = toint ((vt.wrect[1].y - vt.wrect[0].y) / w2v);
Daniel@0 48 ];
Daniel@0 49 setwidgetattr (vt.canvas, [
Daniel@0 50 'window' = vt.wrect;
Daniel@0 51 'viewport' = vt.vsize;
Daniel@0 52 ]);
Daniel@0 53 attr = getwidgetattr (vt.canvas, [0 = 'viewport';]);
Daniel@0 54 vt.vsize = copy (attr.viewport);
Daniel@0 55 }
Daniel@0 56 };
Daniel@0 57 dotty.protogt.setviewscale = function (views, factor) {
Daniel@0 58 local vid, vt, w2v, attr;
Daniel@0 59
Daniel@0 60 for (vid in views) {
Daniel@0 61 vt = views[vid];
Daniel@0 62 if ((w2v = vt.w2v * factor) < 0.01) {
Daniel@0 63 dotty.message (0, 'cannot zoom any closer');
Daniel@0 64 return;
Daniel@0 65 }
Daniel@0 66 vt.w2v = w2v;
Daniel@0 67 vt.vsize = [
Daniel@0 68 'x' = (vt.wrect[1].x - vt.wrect[0].x) / w2v;
Daniel@0 69 'y' = (vt.wrect[1].y - vt.wrect[0].y) / w2v;
Daniel@0 70 ];
Daniel@0 71 setwidgetattr (vt.canvas, ['viewport' = vt.vsize;]);
Daniel@0 72 attr = getwidgetattr (vt.canvas, [0 = 'viewport';]);
Daniel@0 73 vt.vsize = copy (attr.viewport);
Daniel@0 74 }
Daniel@0 75 };
Daniel@0 76 dotty.protogt.setviewcenter = function (views, center) {
Daniel@0 77 local vid, vt, pos;
Daniel@0 78
Daniel@0 79 for (vid in views) {
Daniel@0 80 vt = views[vid];
Daniel@0 81 pos = [
Daniel@0 82 'x' = center.x * vt.vsize.x / (vt.wrect[1].x - vt.wrect[0].x);
Daniel@0 83 'y' = (
Daniel@0 84 (vt.wrect[1].y - center.y) * vt.vsize.y /
Daniel@0 85 (vt.wrect[1].y - vt.wrect[0].y)
Daniel@0 86 );
Daniel@0 87 ];
Daniel@0 88 setwidgetattr (vt.scroll, ['childcenter' = pos;]);
Daniel@0 89 }
Daniel@0 90 };
Daniel@0 91 #
Daniel@0 92 # draw graph components
Daniel@0 93 #
Daniel@0 94 dotty.protogt.drawsgraph = function (gt, views, sgraph) {
Daniel@0 95 sgraph.draw = 1;
Daniel@0 96 if (~sgraph.draws)
Daniel@0 97 return;
Daniel@0 98 gt.execalldraw (gt, views, null, sgraph.draws, [
Daniel@0 99 'fontname' = sgraph.fontname;
Daniel@0 100 'fontsize' = sgraph.fontsize;
Daniel@0 101 'fontcolor' = sgraph.fontcolor;
Daniel@0 102 'drawcolor' = sgraph.drawcolor;
Daniel@0 103 'fillcolor' = sgraph.fillcolor;
Daniel@0 104 ]);
Daniel@0 105 };
Daniel@0 106 dotty.protogt.undrawsgraph = function (gt, views, sgraph) {
Daniel@0 107 sgraph.drawn = 0;
Daniel@0 108 if (~sgraph.draws)
Daniel@0 109 return;
Daniel@0 110 gt.execalldraw (gt, views, null, sgraph.draws, [
Daniel@0 111 'fontname' = sgraph.fontname;
Daniel@0 112 'fontsize' = sgraph.fontsize;
Daniel@0 113 'fontcolor' = sgraph.fontcolor;
Daniel@0 114 'drawcolor' = 0;
Daniel@0 115 'fillcolor' = 0;
Daniel@0 116 ]);
Daniel@0 117 };
Daniel@0 118 dotty.protogt.drawnode = function (gt, views, node) {
Daniel@0 119 local vid;
Daniel@0 120
Daniel@0 121 node.drawn = 1;
Daniel@0 122 if (~node.draws)
Daniel@0 123 return;
Daniel@0 124 gt.execalldraw (gt, views, node, node.draws, [
Daniel@0 125 'fontname' = node.fontname;
Daniel@0 126 'fontsize' = node.fontsize;
Daniel@0 127 'fontcolor' = node.fontcolor;
Daniel@0 128 'drawcolor' = node.drawcolor;
Daniel@0 129 'fillcolor' = node.fillcolor;
Daniel@0 130 ]);
Daniel@0 131 for (vid in views)
Daniel@0 132 setpick (views[vid].canvas, node, node.rect);
Daniel@0 133 };
Daniel@0 134 dotty.protogt.undrawnode = function (gt, views, node) {
Daniel@0 135 local vid;
Daniel@0 136
Daniel@0 137 if (~node.drawn)
Daniel@0 138 return;
Daniel@0 139 node.drawn = 0;
Daniel@0 140 if (~node.pos)
Daniel@0 141 return;
Daniel@0 142 gt.execalldraw (gt, views, node, node.draws, [
Daniel@0 143 'nooverride' = 1;
Daniel@0 144 'fontname' = node.fontname;
Daniel@0 145 'fontsize' = node.fontsize;
Daniel@0 146 'fontcolor' = 0;
Daniel@0 147 'drawcolor' = 0;
Daniel@0 148 'fillcolor' = 0;
Daniel@0 149 ]);
Daniel@0 150 for (vid in views)
Daniel@0 151 clearpick (views[vid].canvas, node);
Daniel@0 152 };
Daniel@0 153 dotty.protogt.movenode = function (gt, node, pos) {
Daniel@0 154 local dp, eid, edge;
Daniel@0 155
Daniel@0 156 dp.x = pos.x - node.pos.x;
Daniel@0 157 dp.y = pos.y - node.pos.y;
Daniel@0 158 gt.undrawnode (gt, gt.views, node);
Daniel@0 159 node.pos.x = pos.x;
Daniel@0 160 node.pos.y = pos.y;
Daniel@0 161 gt.movenodedraw (node.draws, dp);
Daniel@0 162 for (eid in node.edges) {
Daniel@0 163 edge = node.edges[eid];
Daniel@0 164 gt.undrawedge (gt, gt.views, edge);
Daniel@0 165 gt.moveedgedraw (edge.draws, edge.tail.pos, edge.head.pos);
Daniel@0 166 gt.drawedge (gt, gt.views, edge);
Daniel@0 167 }
Daniel@0 168 gt.drawnode (gt, gt.views, node);
Daniel@0 169 };
Daniel@0 170 dotty.protogt.drawedge = function (gt, views, edge) {
Daniel@0 171 local vid, canvas;
Daniel@0 172
Daniel@0 173 edge.drawn = 1;
Daniel@0 174 if (~edge.draws)
Daniel@0 175 return;
Daniel@0 176 gt.execalldraw (gt, views, edge, edge.draws, [
Daniel@0 177 'fontname' = edge.fontname;
Daniel@0 178 'fontsize' = edge.fontsize;
Daniel@0 179 'fontcolor' = edge.fontcolor;
Daniel@0 180 'drawcolor' = edge.drawcolor;
Daniel@0 181 'fillcolor' = edge.fillcolor;
Daniel@0 182 ]);
Daniel@0 183 for (vid in views) {
Daniel@0 184 canvas = views[vid].canvas;
Daniel@0 185 if (gt.edgehandles == 0 | ~edge.draws.ep)
Daniel@0 186 continue;
Daniel@0 187 arc (canvas, edge, edge.draws.ep, ['x' = 5; 'y' = 5;], ['color' = 1;]);
Daniel@0 188 }
Daniel@0 189 };
Daniel@0 190 dotty.protogt.undrawedge = function (gt, views, edge) {
Daniel@0 191 local vid, canvas;
Daniel@0 192
Daniel@0 193 if (~edge.drawn)
Daniel@0 194 return;
Daniel@0 195 edge.drawn = 0;
Daniel@0 196 if (~edge.draws)
Daniel@0 197 return;
Daniel@0 198 gt.execalldraw (gt, views, edge, edge.draws, [
Daniel@0 199 'nooverride' = 1;
Daniel@0 200 'fontname' = edge.fontname;
Daniel@0 201 'fontsize' = edge.fontsize;
Daniel@0 202 'fontcolor' = 0;
Daniel@0 203 'drawcolor' = 0;
Daniel@0 204 'fillcolor' = 0;
Daniel@0 205 ]);
Daniel@0 206 for (vid in views) {
Daniel@0 207 canvas = views[vid].canvas;
Daniel@0 208 if (gt.edgehandles == 0 | ~edge.draws.ep)
Daniel@0 209 continue;
Daniel@0 210 arc (canvas, edge, edge.draws.ep, ['x' = 5; 'y' = 5;], ['color' = 0;]);
Daniel@0 211 clearpick (canvas, edge);
Daniel@0 212 }
Daniel@0 213 };
Daniel@0 214 #
Daniel@0 215 # draw directives
Daniel@0 216 #
Daniel@0 217 dotty.protogt.execalldraw = function (gt, views, obj, draws, gc) {
Daniel@0 218 local vid, vt, did, draw, i, func;
Daniel@0 219
Daniel@0 220 for (vid in views) {
Daniel@0 221 vt = views[vid];
Daniel@0 222 for (did in draws) {
Daniel@0 223 if (did == 'ep')
Daniel@0 224 continue;
Daniel@0 225 draw = draws[did];
Daniel@0 226 for (i = 0; draw[i]; i = i + 1)
Daniel@0 227 if ((func = gt.drawfunc[draw[i].type]))
Daniel@0 228 func (gt, vt.canvas, obj, draw[i], gc);
Daniel@0 229 }
Daniel@0 230 }
Daniel@0 231 };
Daniel@0 232 dotty.protogt.drawfunc.E = function (gt, canvas, obj, data, gc) {
Daniel@0 233 arc (canvas, obj, data.c, data.s, [
Daniel@0 234 'color' = gc.fillcolor; 'style' = gc.style; 'width' = gc.width;
Daniel@0 235 'fill' = 'on';
Daniel@0 236 ]);
Daniel@0 237 arc (canvas, obj, data.c, data.s, [
Daniel@0 238 'color' = gc.drawcolor; 'style' = gc.style; 'width' = gc.width;
Daniel@0 239 ]);
Daniel@0 240 };
Daniel@0 241 dotty.protogt.drawfunc.e = function (gt, canvas, obj, data, gc) {
Daniel@0 242 arc (canvas, obj, data.c, data.s, [
Daniel@0 243 'color' = gc.drawcolor; 'style' = gc.style; 'width' = gc.width;
Daniel@0 244 ]);
Daniel@0 245 };
Daniel@0 246 dotty.protogt.drawfunc.P = function (gt, canvas, obj, data, gc) {
Daniel@0 247 polygon (canvas, obj, data.ps, [
Daniel@0 248 'color' = gc.fillcolor; 'style' = gc.style; 'width' = gc.width;
Daniel@0 249 'fill' = 'on';
Daniel@0 250 ]);
Daniel@0 251 polygon (canvas, obj, data.ps, [
Daniel@0 252 'color' = gc.drawcolor; 'style' = gc.style; 'width' = gc.width;
Daniel@0 253 ]);
Daniel@0 254 };
Daniel@0 255 dotty.protogt.drawfunc.p = function (gt, canvas, obj, data, gc) {
Daniel@0 256 polygon (canvas, obj, data.ps, [
Daniel@0 257 'color' = gc.drawcolor; 'style' = gc.style; 'width' = gc.width;
Daniel@0 258 ]);
Daniel@0 259 };
Daniel@0 260 dotty.protogt.drawfunc.L = function (gt, canvas, obj, data, gc) {
Daniel@0 261 polygon (canvas, obj, data.ps, [
Daniel@0 262 'color' = gc.drawcolor; 'style' = gc.style; 'width' = gc.width;
Daniel@0 263 ]);
Daniel@0 264 };
Daniel@0 265 dotty.protogt.drawfunc.b = function (gt, canvas, obj, data, gc) {
Daniel@0 266 splinegon (canvas, obj, data.ps, [
Daniel@0 267 'color' = gc.fillcolor; 'style' = gc.style; 'width' = gc.width;
Daniel@0 268 'fill' = 'on';
Daniel@0 269 ]);
Daniel@0 270 };
Daniel@0 271 dotty.protogt.drawfunc.B = function (gt, canvas, obj, data, gc) {
Daniel@0 272 splinegon (canvas, obj, data.ps, [
Daniel@0 273 'color' = gc.drawcolor; 'style' = gc.style; 'width' = gc.width;
Daniel@0 274 ]);
Daniel@0 275 };
Daniel@0 276 dotty.protogt.drawfunc.T = function (gt, canvas, obj, data, gc) {
Daniel@0 277 text (canvas, obj, data.p, data.s, gc.fontname, gc.fontsize, data.j, [
Daniel@0 278 'color' = gc.fontcolor; 'style' = gc.style; 'width' = gc.width;
Daniel@0 279 ]);
Daniel@0 280 };
Daniel@0 281 dotty.protogt.drawfunc.C = function (gt, canvas, obj, data, gc) {
Daniel@0 282 if (gc.nooverride ~= 1)
Daniel@0 283 gc.fillcolor = data.fillcolor;
Daniel@0 284 };
Daniel@0 285 dotty.protogt.drawfunc.c = function (gt, canvas, obj, data, gc) {
Daniel@0 286 if (gc.nooverride ~= 1) {
Daniel@0 287 gc.drawcolor = data.drawcolor;
Daniel@0 288 gc.fontcolor = data.drawcolor;
Daniel@0 289 }
Daniel@0 290 };
Daniel@0 291 dotty.protogt.drawfunc.F = function (gt, canvas, obj, data, gc) {
Daniel@0 292 gc.fontname = data.fn;
Daniel@0 293 gc.fontsize = data.fs;
Daniel@0 294 };
Daniel@0 295 dotty.protogt.drawfunc.S = function (gt, canvas, obj, data, gc) {
Daniel@0 296 gc.style = data.style;
Daniel@0 297 gc.width = data.width;
Daniel@0 298 };
Daniel@0 299 dotty.protogt.movenodedraw = function (draws, dp) {
Daniel@0 300 local did, draw, i, j;
Daniel@0 301
Daniel@0 302 for (did in draws) {
Daniel@0 303 if (did == 'ep')
Daniel@0 304 continue;
Daniel@0 305 draw = draws[did];
Daniel@0 306 for (i = 0; draw[i]; i = i + 1) {
Daniel@0 307 if (draw[i].type == 'E' | draw[i].type == 'e') {
Daniel@0 308 draw[i].c.x = draw[i].c.x + dp.x;
Daniel@0 309 draw[i].c.y = draw[i].c.y + dp.y;
Daniel@0 310 } else if (draw[i].type == 'P' | draw[i].type == 'p') {
Daniel@0 311 for (j = 1; draw[i].ps[j]; j = j + 1) {
Daniel@0 312 draw[i].ps[j].x = draw[i].ps[j].x + dp.x;
Daniel@0 313 draw[i].ps[j].y = draw[i].ps[j].y + dp.y;
Daniel@0 314 }
Daniel@0 315 } else if (draw[i].type == 'L' | draw[i].type == 'B') {
Daniel@0 316 for (j = 0; draw[i].ps[j]; j = j + 1) {
Daniel@0 317 draw[i].ps[j].x = draw[i].ps[j].x + dp.x;
Daniel@0 318 draw[i].ps[j].y = draw[i].ps[j].y + dp.y;
Daniel@0 319 }
Daniel@0 320 } else if (draw[i].type == 'T') {
Daniel@0 321 draw[i].p.x = draw[i].p.x + dp.x;
Daniel@0 322 draw[i].p.y = draw[i].p.y + dp.y;
Daniel@0 323 }
Daniel@0 324 }
Daniel@0 325 }
Daniel@0 326 };
Daniel@0 327 dotty.protogt.moveedgedraw = function (draws, tp, hp) {
Daniel@0 328 local draws2, did;
Daniel@0 329
Daniel@0 330 for (did in draws)
Daniel@0 331 draws2[did] = draws[did];
Daniel@0 332 for (did in draws2)
Daniel@0 333 remove (did, draws);
Daniel@0 334 draws[0] = [
Daniel@0 335 0 = [
Daniel@0 336 'type' = 'L';
Daniel@0 337 'n' = 2;
Daniel@0 338 'ps' = [
Daniel@0 339 0 = copy (tp);
Daniel@0 340 1 = copy (hp);
Daniel@0 341 ];
Daniel@0 342 ];
Daniel@0 343 'ep' = ['x' = (tp.x + hp.x) / 2; 'y' = (tp.y + hp.y) / 2;];
Daniel@0 344 ];
Daniel@0 345 };
Daniel@0 346 dotty.protogt.simplenodedraw = function (node, c, s) {
Daniel@0 347 local draws;
Daniel@0 348
Daniel@0 349 if (node.attr.shape == 'ellipse')
Daniel@0 350 draws[0] = [
Daniel@0 351 0 = [
Daniel@0 352 'type' = 'e';
Daniel@0 353 'c' = copy (c);
Daniel@0 354 's' = ['x' = s.x / 2; 'y' = s.y / 2;];
Daniel@0 355 ];
Daniel@0 356 ];
Daniel@0 357 else
Daniel@0 358 draws[0] = [
Daniel@0 359 0 = [
Daniel@0 360 'type' = 'p';
Daniel@0 361 'n' = 5;
Daniel@0 362 'ps' = [
Daniel@0 363 0 = ['x' = c.x - s.x / 2; 'y' = c.y - s.y / 2;];
Daniel@0 364 1 = ['x' = c.x + s.x / 2; 'y' = c.y - s.y / 2;];
Daniel@0 365 2 = ['x' = c.x + s.x / 2; 'y' = c.y + s.y / 2;];
Daniel@0 366 3 = ['x' = c.x - s.x / 2; 'y' = c.y + s.y / 2;];
Daniel@0 367 4 = ['x' = c.x - s.x / 2; 'y' = c.y - s.y / 2;];
Daniel@0 368 ];
Daniel@0 369 ];
Daniel@0 370 ];
Daniel@0 371 return draws;
Daniel@0 372 };
Daniel@0 373 dotty.protogt.simpleedgedraw = function (edge, tp, hp) {
Daniel@0 374 local draws;
Daniel@0 375
Daniel@0 376 draws[0] = [
Daniel@0 377 0 = [
Daniel@0 378 'type' = 'L';
Daniel@0 379 'n' = 2;
Daniel@0 380 'ps' = [
Daniel@0 381 0 = copy (tp);
Daniel@0 382 1 = copy (hp);
Daniel@0 383 ];
Daniel@0 384 ];
Daniel@0 385 'ep' = ['x' = (tp.x + hp.x) / 2; 'y' = (tp.y + hp.y) / 2;];
Daniel@0 386 ];
Daniel@0 387 return draws;
Daniel@0 388 };
Daniel@0 389 #
Daniel@0 390 # utilities
Daniel@0 391 #
Daniel@0 392 dotty.protogt.getcolor = function (views, name) {
Daniel@0 393 local vid, vt, color, t;
Daniel@0 394
Daniel@0 395 for (vid in views) {
Daniel@0 396 vt = views[vid];
Daniel@0 397 if (~(color >= 0)) {
Daniel@0 398 if (~(vt.colors[name] >= 0))
Daniel@0 399 color = (vt.colors[name] = vt.colorn);
Daniel@0 400 else {
Daniel@0 401 color = vt.colors[name];
Daniel@0 402 break;
Daniel@0 403 }
Daniel@0 404 } else if (~(vt.colors[name] >= 0))
Daniel@0 405 vt.colors[name] = color;
Daniel@0 406 else if (vt.colors[name] ~= color)
Daniel@0 407 dotty.message (0, concat ('inconsistent color ids for ', name));
Daniel@0 408 if (setwidgetattr (vt.canvas, ['color' = [color = name;];]) ~= 1) {
Daniel@0 409 t = split (name, ' ');
Daniel@0 410 if (tablesize (t) ~= 3 |
Daniel@0 411 setwidgetattr (vt.canvas, ['color' = [color = [
Daniel@0 412 'h' = ston (t[0]); 's' = ston (t[1]); 'v' = ston (t[2]);
Daniel@0 413 ];];]) ~= 1) {
Daniel@0 414 dotty.message (0, concat ('unknown color ', name, ' using #1'));
Daniel@0 415 return 1;
Daniel@0 416 }
Daniel@0 417 }
Daniel@0 418 vt.colorn = color + 1;
Daniel@0 419 }
Daniel@0 420 return color;
Daniel@0 421 };
Daniel@0 422 dotty.protogt.setbgcolor = function (views, name) {
Daniel@0 423 local vid, vt, t;
Daniel@0 424
Daniel@0 425 for (vid in views) {
Daniel@0 426 vt = views[vid];
Daniel@0 427 if (setwidgetattr (vt.canvas, ['color' = [0 = name;];]) ~= 1) {
Daniel@0 428 t = split (name, ' ');
Daniel@0 429 if (tablesize (t) ~= 3 |
Daniel@0 430 setwidgetattr (vt.canvas, ['color' = [0 = [
Daniel@0 431 'h' = ston (t[0]); 's' = ston (t[1]); 'v' = ston (t[2]);
Daniel@0 432 ];];]) ~= 1) {
Daniel@0 433 dotty.message (0, concat ('unknown bgcolor ', name));
Daniel@0 434 return;
Daniel@0 435 }
Daniel@0 436 }
Daniel@0 437 vt.colors['_bgcolor_'] = name;
Daniel@0 438 }
Daniel@0 439 };
Daniel@0 440 dotty.protogt.unpacksgraphattr = function (gt, sgraph) {
Daniel@0 441 local attr;
Daniel@0 442
Daniel@0 443 attr = sgraph.graphattr;
Daniel@0 444 if (dotty.fontmap[attr.fontname])
Daniel@0 445 sgraph[dotty.keys.fname] = dotty.fontmap[attr.fontname];
Daniel@0 446 else
Daniel@0 447 sgraph[dotty.keys.fname] = attr.fontname;
Daniel@0 448 sgraph[dotty.keys.fsize] = ston (attr.fontsize);
Daniel@0 449 sgraph[dotty.keys.fcolor] = gt.getcolor (gt.views, attr.fontcolor);
Daniel@0 450 if (attr.color)
Daniel@0 451 sgraph[dotty.keys.dcolor] = gt.getcolor (gt.views, attr.color);
Daniel@0 452 else
Daniel@0 453 sgraph[dotty.keys.dcolor] = gt.getcolor (gt.views, 'black');
Daniel@0 454 if (attr.style == 'filled') {
Daniel@0 455 if (attr.fillcolor)
Daniel@0 456 sgraph[dotty.keys.bcolor] = gt.getcolor (gt.views, attr.fillcolor);
Daniel@0 457 else if (attr.color)
Daniel@0 458 sgraph[dotty.keys.bcolor] = gt.getcolor (gt.views, attr.color);
Daniel@0 459 else
Daniel@0 460 sgraph[dotty.keys.bcolor] = gt.getcolor (gt.views, 'lightgrey');
Daniel@0 461 }
Daniel@0 462 };
Daniel@0 463 dotty.protogt.unpacknodeattr = function (gt, node) {
Daniel@0 464 local attr;
Daniel@0 465
Daniel@0 466 attr = node.attr;
Daniel@0 467 if (dotty.fontmap[attr.fontname])
Daniel@0 468 node[dotty.keys.fname] = dotty.fontmap[attr.fontname];
Daniel@0 469 else
Daniel@0 470 node[dotty.keys.fname] = attr.fontname;
Daniel@0 471 node[dotty.keys.fsize] = ston (attr.fontsize);
Daniel@0 472 node[dotty.keys.fcolor] = gt.getcolor (gt.views, attr.fontcolor);
Daniel@0 473 if (attr.color)
Daniel@0 474 node[dotty.keys.dcolor] = gt.getcolor (gt.views, attr.color);
Daniel@0 475 else
Daniel@0 476 node[dotty.keys.dcolor] = gt.getcolor (gt.views, 'black');
Daniel@0 477 if (attr.style == 'filled') {
Daniel@0 478 if (attr.fillcolor)
Daniel@0 479 node[dotty.keys.bcolor] = gt.getcolor (gt.views, attr.fillcolor);
Daniel@0 480 else if (attr.color)
Daniel@0 481 node[dotty.keys.bcolor] = gt.getcolor (gt.views, attr.color);
Daniel@0 482 else
Daniel@0 483 node[dotty.keys.bcolor] = gt.getcolor (gt.views, 'lightgrey');
Daniel@0 484 }
Daniel@0 485 };
Daniel@0 486 dotty.protogt.unpackedgeattr = function (gt, edge) {
Daniel@0 487 local attr;
Daniel@0 488
Daniel@0 489 attr = edge.attr;
Daniel@0 490 if (dotty.fontmap[attr.fontname])
Daniel@0 491 edge[dotty.keys.fname] = dotty.fontmap[attr.fontname];
Daniel@0 492 else
Daniel@0 493 edge[dotty.keys.fname] = attr.fontname;
Daniel@0 494 edge[dotty.keys.fsize] = ston (attr.fontsize);
Daniel@0 495 edge[dotty.keys.fcolor] = gt.getcolor (gt.views, attr.fontcolor);
Daniel@0 496 if (attr.color)
Daniel@0 497 edge[dotty.keys.dcolor] = gt.getcolor (gt.views, attr.color);
Daniel@0 498 else
Daniel@0 499 edge[dotty.keys.dcolor] = gt.getcolor (gt.views, 'black');
Daniel@0 500 if (attr.style == 'filled') {
Daniel@0 501 if (attr.fillcolor)
Daniel@0 502 edge[dotty.keys.bcolor] = gt.getcolor (gt.views, attr.fillcolor);
Daniel@0 503 else if (attr.color)
Daniel@0 504 edge[dotty.keys.bcolor] = gt.getcolor (gt.views, attr.color);
Daniel@0 505 else
Daniel@0 506 edge[dotty.keys.bcolor] = gt.getcolor (gt.views, 'lightgrey');
Daniel@0 507 }
Daniel@0 508 };
Daniel@0 509 dotty.protogt.unpackattr = function (gt) {
Daniel@0 510 local gid, sgraph, nid, node, eid, edge, graph, attr;
Daniel@0 511
Daniel@0 512 graph = gt.graph;
Daniel@0 513 attr = graph.graphattr;
Daniel@0 514 if (dotty.fontmap[attr.fontname])
Daniel@0 515 graph[dotty.keys.fname] = dotty.fontmap[attr.fontname];
Daniel@0 516 else
Daniel@0 517 graph[dotty.keys.fname] = attr.fontname;
Daniel@0 518 graph[dotty.keys.fsize] = ston (attr.fontsize);
Daniel@0 519 graph[dotty.keys.fcolor] = gt.getcolor (gt.views, attr.fontcolor);
Daniel@0 520 if (attr.color)
Daniel@0 521 graph[dotty.keys.dcolor] = gt.getcolor (gt.views, attr.color);
Daniel@0 522 else
Daniel@0 523 graph[dotty.keys.dcolor] = gt.getcolor (gt.views, 'black');
Daniel@0 524 if (attr.style == 'filled') {
Daniel@0 525 if (attr.fillcolor)
Daniel@0 526 graph[dotty.keys.bcolor] = gt.getcolor (gt.views, attr.fillcolor);
Daniel@0 527 else if (attr.color)
Daniel@0 528 graph[dotty.keys.bcolor] = gt.getcolor (gt.views, attr.color);
Daniel@0 529 else
Daniel@0 530 graph[dotty.keys.bcolor] = gt.getcolor (gt.views, 'lightgrey');
Daniel@0 531 }
Daniel@0 532 if (attr.bgcolor & attr.bgcolor ~= '')
Daniel@0 533 gt.setbgcolor (gt.views, attr.bgcolor);
Daniel@0 534 for (gid in graph.graphdict) {
Daniel@0 535 sgraph = graph.graphs[graph.graphdict[gid]];
Daniel@0 536 attr = sgraph.graphattr;
Daniel@0 537 if (dotty.fontmap[attr.fontname])
Daniel@0 538 sgraph[dotty.keys.fname] = dotty.fontmap[attr.fontname];
Daniel@0 539 else
Daniel@0 540 sgraph[dotty.keys.fname] = attr.fontname;
Daniel@0 541 sgraph[dotty.keys.fsize] = ston (attr.fontsize);
Daniel@0 542 sgraph[dotty.keys.fcolor] = gt.getcolor (gt.views, attr.fontcolor);
Daniel@0 543 if (attr.color)
Daniel@0 544 sgraph[dotty.keys.dcolor] = gt.getcolor (gt.views, attr.color);
Daniel@0 545 else
Daniel@0 546 sgraph[dotty.keys.dcolor] = gt.getcolor (gt.views, 'black');
Daniel@0 547 if (attr.style == 'filled') {
Daniel@0 548 if (attr.fillcolor)
Daniel@0 549 sgraph[dotty.keys.bcolor] = gt.getcolor (
Daniel@0 550 gt.views, attr.fillcolor
Daniel@0 551 );
Daniel@0 552 else if (attr.color)
Daniel@0 553 sgraph[dotty.keys.bcolor] = gt.getcolor (gt.views, attr.color);
Daniel@0 554 else
Daniel@0 555 sgraph[dotty.keys.bcolor] = gt.getcolor (gt.views, 'lightgrey');
Daniel@0 556 }
Daniel@0 557 }
Daniel@0 558 for (nid in graph.nodedict) {
Daniel@0 559 node = graph.nodes[graph.nodedict[nid]];
Daniel@0 560 attr = node.attr;
Daniel@0 561 if (dotty.fontmap[attr.fontname])
Daniel@0 562 node[dotty.keys.fname] = dotty.fontmap[attr.fontname];
Daniel@0 563 else
Daniel@0 564 node[dotty.keys.fname] = attr.fontname;
Daniel@0 565 node[dotty.keys.fsize] = ston (attr.fontsize);
Daniel@0 566 node[dotty.keys.fcolor] = gt.getcolor (gt.views, attr.fontcolor);
Daniel@0 567 if (attr.color)
Daniel@0 568 node[dotty.keys.dcolor] = gt.getcolor (gt.views, attr.color);
Daniel@0 569 else
Daniel@0 570 node[dotty.keys.dcolor] = gt.getcolor (gt.views, 'black');
Daniel@0 571 if (attr.style == 'filled') {
Daniel@0 572 if (attr.fillcolor)
Daniel@0 573 node[dotty.keys.bcolor] = gt.getcolor (
Daniel@0 574 gt.views, attr.fillcolor
Daniel@0 575 );
Daniel@0 576 else if (attr.color)
Daniel@0 577 node[dotty.keys.bcolor] = gt.getcolor (gt.views, attr.color);
Daniel@0 578 else
Daniel@0 579 node[dotty.keys.bcolor] = gt.getcolor (gt.views, 'lightgrey');
Daniel@0 580 }
Daniel@0 581 }
Daniel@0 582 for (eid in graph.edges) {
Daniel@0 583 edge = graph.edges[eid];
Daniel@0 584 attr = edge.attr;
Daniel@0 585 if (dotty.fontmap[attr.fontname])
Daniel@0 586 edge[dotty.keys.fname] = dotty.fontmap[attr.fontname];
Daniel@0 587 else
Daniel@0 588 edge[dotty.keys.fname] = attr.fontname;
Daniel@0 589 edge[dotty.keys.fsize] = ston (attr.fontsize);
Daniel@0 590 edge[dotty.keys.fcolor] = gt.getcolor (gt.views, attr.fontcolor);
Daniel@0 591 if (attr.color)
Daniel@0 592 edge[dotty.keys.dcolor] = gt.getcolor (gt.views, attr.color);
Daniel@0 593 else
Daniel@0 594 edge[dotty.keys.dcolor] = gt.getcolor (gt.views, 'black');
Daniel@0 595 }
Daniel@0 596 };