Debian Codegraph @

tclpkg/tcldot/examples/structs.tcl

raw
1 #!/bin/sh
2 # next line is a comment in tcl \
3 exec wish "$0" ${1+"$@"}
4
5 package require Tkspline
6 package require Tcldot
7
8 ######################################################################
9 # first lets see what it looks like from a gv-syntax input:
10 set s {
11 digraph structs {
12 node [shape=record];
13 struct1 [shape=record,label="<f0> left|<f1> middle|<f2> right"];
14 struct2 [shape=record,label="<f0> one|<f1> two"];
15 struct3 [shape=record,label="hello\nworld |{ b |{c|<here> d|e}| f}| g | h"];
16 struct1:f1 -> struct2:f0;
17 struct1:f2 -> struct3:here;
18 }
19 }
20 set g [dotstring $s]
21 eval [$g render [canvas .c]]
22 pack .c
23
24
25 ######################################################################
26 # take a look at what is in the graph
27 proc putsobj {obj} {
28 puts "[format {%-7s} $obj] [$obj showname]"
29 foreach a [$obj listattributes] {
30 puts " $a=[$obj queryattribute $a]"
31 }
32 }
33
34 foreach n [$g listnodes] {
35 putsobj $n
36 }
37 foreach n [$g listnodes] {
38 foreach e [$n listoutedges] {
39 putsobj $e
40 }
41 }
42
43 ######################################################################
44 # show how the same effect can be achieved from tcl input
45
46
47 set structs [dotnew digraph structs]
48 $structs setnodeattributes shape record
49 $structs addnode struct1 label "<f0> left|<f1> middle|<f2> right"
50 $structs addnode struct2 label "<f0> one|<f1> two"
51 $structs addnode struct3 label "hello\nworld |{ b |{c|<here> d|e}| f}| g | h"
52 $structs addedge struct1 struct2 tailport :f1 headport :f0
53 $structs addedge struct1 struct3 tailport :f2 headport :here
54
55 toplevel .t
56 eval [$structs render [canvas .t.c]]
57 pack .t.c