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