tcldot.3tcl 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530
  1. .TH tcldot 3tcl "Tcl Extensions"
  2. .SH NAME
  3. tcldot \- graph manipulation in tcl
  4. .SH SYNOPSIS
  5. #!/usr/local/bin/tclsh
  6. .br
  7. package require \fBTcldot\fR
  8. .SH USAGE
  9. Requires the dynamic loading facilities of tcl7.6 or later.
  10. .SH INTRODUCTION
  11. .B tcldot
  12. is a tcl dynamically loaded extension that incorporates
  13. the directed graph facilities of
  14. .B dot(1),
  15. and the undirected graph facilities of
  16. .B neato(1),
  17. into tcl and provides a set of commands to control those
  18. facilities.
  19. .B tcldot
  20. converts
  21. .B dot
  22. and
  23. .B neato
  24. from batch processing tools to an interpreted and, if needed, interactive set
  25. of graph manipulation facilities.
  26. .SH COMMANDS
  27. .B tcldot
  28. initially adds only three commands to tcl, namely
  29. .B dotnew,
  30. .B dotread,
  31. and
  32. .B dotstring.
  33. These commands return a handle for the graph that has just been created
  34. and that handle can then be used as a command for further actions on the graph.
  35. All other "commands" are of the form:
  36. .IP
  37. .I handle
  38. .B <method>
  39. .I parameters
  40. .PP
  41. Many of the methods return further
  42. handles of graphs, nodes of edges, which are themselves registered as commands.
  43. The methods are described in detail below, but in summary:
  44. .PP
  45. Graph methods are:
  46. .IP
  47. .B "addedge, addnode, addsubgraph, countedges, countnodes, layout, listattributes, listedgeattributes, listnodeattributes, listedges, listnodes, listnodesrev, listsubgraphs, render, rendergd, queryattributes, queryedgeattributes, querynodeattributes, queryattributevalues, queryedgeattributevalues, querynodeattributevalues, setattributes, setedgeattributes, setnodeattributes, showname, write."
  48. .PP
  49. Node methods are:
  50. .IP
  51. .B "addedge, listattributes, listedges, listinedges, listoutedges, queryattributes, queryattributevalues, setattributes, showname."
  52. .PP
  53. Edge methods are:
  54. .IP
  55. .B "delete, listattributes, listnodes, queryattributes, queryattributevalues, setattributes, showname."
  56. .TP
  57. \fBdotnew\fR \fIgraphType ?attributeName attributeValue? ?...?\fR
  58. creates a new empty graph and returns its
  59. .I graphHandle.
  60. .I graphType
  61. can be any supported by
  62. .B dot(1)
  63. namely: "graph," "digraph," "graphstrict," or "digraphstrict."
  64. (In digraphs edges have a direction from tail to head. "Strict" graphs
  65. or digraphs collapse multiple edges between the same pair of
  66. nodes into a single edge.)
  67. Following the mandatory
  68. .I graphType
  69. parameter the
  70. .B dotnew
  71. command will accept an arbitrary number of attribute name/value pairs
  72. for the graph.
  73. Certain special graph attributes and permitted values are described in
  74. .B dot(1),
  75. but the programmer can arbitrarily invent and assign values
  76. to additional attributes beyond these.
  77. In
  78. .B dot
  79. the attribute name is separated from the value by an "=" character.
  80. In
  81. .B tcldot
  82. the "=" has been replaced by a " " (space) to be more consistent
  83. with
  84. .B tcl
  85. syntax.
  86. e.g.
  87. .nf
  88. set g [dotnew digraph rankdir LR]
  89. .fi
  90. .TP
  91. \fBdotread\fR \fIfileHandle\fR
  92. reads in a dot-language description of a graph from a previously opened
  93. file identified by the
  94. .I fileHandle.
  95. The command returns the
  96. .I graphHandle
  97. of the newly read graph. e.g.
  98. .nf
  99. set f [open test.dot r]
  100. set g [dotread $f]
  101. .fi
  102. .TP
  103. \fBdotstring\fR \fIstring\fR
  104. reads in a dot-language description of a graph from a Tcl string;
  105. The command returns the
  106. .I graphHandle
  107. of the newly read graph. e.g.
  108. .nf
  109. set g [dotstring $dotsyntaxstring]
  110. .fi
  111. .TP
  112. \fIgraphHandle\fR \fBaddnode\fR \fI?nodeName? ?attributeName attributeValue? ?...?\fR
  113. creates a new node in the graph whose handle is
  114. .I graphHandle
  115. and returns its
  116. .I nodeHandle.
  117. The handle of a node is a string like: "node0" where the integer value is
  118. different for each node.
  119. There can be an arbitrary number of attribute name/value pairs
  120. for the node.
  121. Certain special node attributes and permitted values are described in
  122. .B dot(1),
  123. but the programmer can arbitrarily invent and assign values
  124. to additional attributes beyond these.
  125. e.g.
  126. .nf
  127. set n [$g addnode "N" label "Top\\nNode" shape triangle eggs easyover]
  128. .fi
  129. A possible cause of confusion in
  130. .B tcldot
  131. is the distinction between handles, names, labels, and variables.
  132. The distinction is primarily in who owns them.
  133. Handles are owned by tcldot and are guaranteed to be unique within
  134. one interpreter session. Typically handles are assigned to variables,
  135. like "n" above, for manipulation within a tcl script.
  136. Variables are owned by the programmer.
  137. Names are owned by the application that is using the
  138. graph, typically names are important when reading in a graph from
  139. an external program or file. Labels are the text that is displayed with
  140. the node
  141. (or edge) when the graph is displayed, labels are meaningful to the
  142. reader of the graph. Only the handles and variables are essential to
  143. .B tcldot's
  144. ability to manipulate abstract graphs. If a name is not specified then
  145. it defaults to the string representation of the handle, if a label is
  146. not specified then it defaults to the name.
  147. .TP
  148. \fIgraphHandle\fR \fBaddedge\fR \fItailNode headNode ?attributeName attributeValue? ?...?\fR
  149. creates a new edge in the graph whose handle is
  150. .I graphHandle
  151. and returns its
  152. .B edgeHandle.
  153. .I tailNode
  154. and
  155. .I headNode
  156. can be specified either by their
  157. .I nodeHandle
  158. or by their
  159. .I nodeName.
  160. e.g.
  161. .nf
  162. set n [$g addnode]
  163. set m [$g addnode]
  164. $g addedge $n $m label "NM"
  165. $g addnode N
  166. $g addnode M
  167. $g addedge N M label "NM"
  168. .fi
  169. The argument is recognized as a handle if possible and so it is best
  170. to avoid names like "node6" for nodes. If there is potential for conflict then use
  171. .B findnode
  172. to translate explicitly from names to handles.
  173. e.g.
  174. .nf
  175. $g addnode "node6"
  176. $g addnode "node99"
  177. $g addedge [$g findnode "node6"] [$g findnode "node99"]
  178. .fi
  179. There can be an arbitrary number of attribute name/value pairs
  180. for the edge.
  181. Certain special edge attributes and permitted values are described in
  182. .B dot(1),
  183. but the programmer can arbitrarily invent and assign values
  184. to additional attributes beyond these.
  185. .TP
  186. \fIgraphHandle\fR \fBaddsubgraph\fR \fI?graphName? ?attributeName attributeValue? ?...?\fR
  187. creates a new subgraph in the graph and returns its
  188. .I graphHandle.
  189. If the
  190. .I graphName
  191. is omitted then the name of the subgraph defaults to it's
  192. .I graphHandle.
  193. There can be an arbitrary number of attribute name/value pairs
  194. for the subgraph.
  195. Certain special graph attributes and permitted values are described in
  196. .B dot(1),
  197. but the programmer can arbitrarily invent and assign values
  198. to additional attributes beyond these.
  199. e.g.
  200. .nf
  201. set sg [$g addsubgraph dinglefactor 6]
  202. .fi
  203. Clusters, as described in
  204. .B dot(1),
  205. are created by giving the subgraph a name that begins with the string:
  206. "cluster". Cluster can be labelled by using the \fIlabel\fR attibute.
  207. e.g.
  208. .nf
  209. set cg [$g addsubgraph cluster_A label dongle dinglefactor 6]
  210. .fi
  211. .TP
  212. \fInodeHandle\fR \fBaddedge\fR \fIheadNode ?attributeName attributeValue? ?...?\fR
  213. creates a new edge from the tail node identified by tha
  214. .I nodeHandle
  215. to the
  216. .I headNode
  217. which can be specified either by
  218. .I nodeHandle
  219. or by
  220. .I nodeName
  221. (with preference to recognizing the argument as a handle).
  222. The graph in which this is drawn is the graph in which both nodes are
  223. members.
  224. There can be an arbitrary number of attribute name/value pairs
  225. for the edge.
  226. These edge attributes and permitted values are described in
  227. .B dot(1).
  228. e.g.
  229. .nf
  230. [$g addnode] addedge [$g addnode] label "NM"
  231. .fi
  232. .TP
  233. \fIgraphHandle\fR \fBdelete\fR
  234. .TP
  235. \fInodeHandle\fR \fBdelete\fR
  236. .TP
  237. \fIedgeHandle\fR \fBdelete\fR
  238. Delete all data structures associated with the graph, node or edge
  239. from the internal storage of the interpreter. Deletion of a node also
  240. results in the the deletion of all subtending edges on that node.
  241. Deletion of a graph also results in the deletion of all nodes and
  242. subgraphs within that graph (and hence all edges too). The return from
  243. these delete commands is a null string.
  244. .TP
  245. \fIgraphHandle\fR \fBcountnodes\fR
  246. .TP
  247. \fIgraphHandle\fR \fBcountedges\fR
  248. Returns the number of nodes, or edges, in the graph.
  249. .TP
  250. \fIgraphHandle\fR \fBlistedges\fR
  251. .TP
  252. \fIgraphHandle\fR \fBlistnodes\fR
  253. .TP
  254. \fIgraphHandle\fR \fBlistnodesrev\fR
  255. .TP
  256. \fIgraphHandle\fR \fBlistsubgraphs\fR
  257. .TP
  258. \fInodeHandle\fR \fBlistedges\fR
  259. .TP
  260. \fInodeHandle\fR \fBlistinedges\fR
  261. .TP
  262. \fInodeHandle\fR \fBlistoutedges\fR
  263. .TP
  264. \fIedgeHandle\fR \fBlistnodes\fR
  265. Each return a list of handles of graphs, nodes or edges, as appropriate.
  266. .TP
  267. \fIgraphHandle\fR \fBfindnode\fR \fInodeName\fR
  268. .TP
  269. \fIgraphHandle\fR \fBfindedge\fR \fItailnodeName headNodeName\fR
  270. .TP
  271. \fInodeHandle\fR \fBfindedge\fR \fInodeName\fR
  272. Each return the handle of the item if found, or an error if none are found.
  273. For non-strict graphs when there are multiple edges between two nodes
  274. .B findedge
  275. will return an arbitrary edge from the set.
  276. .TP
  277. \fIgraphHandle\fR \fBshowname\fR
  278. .TP
  279. \fInodeHandle\fR \fBshowname\fR
  280. .TP
  281. \fIedgeHandle\fR \fBshowname\fR
  282. Each return the name of the item. Edge names are of the form:
  283. "a\->b" where "a" and "b" are the names of the nodes and the connector
  284. "\->" indicates the tail-to-head direction of the edge. In undirected
  285. graphs the connector "\-\-" is used.
  286. .TP
  287. \fIgraphHandle\fR \fBsetnodeattributes\fR \fIattributeName attributeValue ?...?\fR
  288. .TP
  289. \fIgraphHandle\fR \fBsetedgeattributes\fR \fIattributeName attributeValue ?...?\fR
  290. Set one or more default attribute name/values that are to apply to
  291. all nodes (edges) unless overridden by subgraphs or per-node
  292. (per-edge) attributes.
  293. .TP
  294. \fIgraphHandle\fR \fBlistnodeattributes\fR
  295. .TP
  296. \fIgraphHandle\fR \fBlistedgeattributes\fR
  297. Return a list of attribute names.
  298. .TP
  299. \fIgraphHandle\fR \fBquerynodeattributes\fR \fIattributeName ?...?\fR
  300. .TP
  301. \fIgraphHandle\fR \fBqueryedgeattributes\fR \fIattributeName ?...?\fR
  302. Return a list of default attribute value, one value for each of the
  303. attribute names provided with the command.
  304. .TP
  305. \fIgraphHandle\fR \fBquerynodeattributes\fR \fIattributeName ?...?\fR
  306. .TP
  307. \fIgraphHandle\fR \fBqueryedgeattributes\fR \fIattributeName ?...?\fR
  308. Return a list of pairs of attrinute name and default attribute value,
  309. one pair for each of the attribute names provided with the command.
  310. .TP
  311. \fIgraphHandle\fR \fBsetattributes\fR \fIattributeName attributeValue ?...?\fR
  312. .TP
  313. \fInodeHandle\fR \fBsetattributes\fR \fIattributeName attributeValue ?...?\fR
  314. .TP
  315. \fIedgeHandle\fR \fBsetattributes\fR \fIattributeName attributeValue ?...?\fR
  316. Set one or more attribute name/value pairs for a specific graph, node,
  317. or edge instance.
  318. .TP
  319. \fIgraphHandle\fR \fBlistattributes\fR
  320. .TP
  321. \fInodeHandle\fR \fBlistattributes\fR
  322. .TP
  323. \fIedgeHandle\fR \fBlistattributes\fR
  324. Return a list of attribute names (attribute values are provided by
  325. .B queryattribute
  326. .TP
  327. \fIgraphHandle\fR \fBqueryattributes\fR \fIattributeName ?...?\fR
  328. .TP
  329. \fInodeHandle\fR \fBqueryattributes\fR \fIattributeName ?...?\fR
  330. .TP
  331. \fIedgeHandle\fR \fBqueryattributes\fR \fIattributeName ?...?\fR
  332. Return a list of attribute value, one value for each of the
  333. attribute names provided with the command.
  334. .TP
  335. \fIgraphHandle\fR \fBqueryattributevalues\fR \fIattributeName ?...?\fR
  336. .TP
  337. \fInodeHandle\fR \fBqueryattributevalues\fR \fIattributeName ?...?\fR
  338. .TP
  339. \fIedgeHandle\fR \fBqueryattributevalues\fR \fIattributeName ?...?\fR
  340. Return a list of pairs or attribute name and attribute value,
  341. one value for each of the attribute names provided with the command.
  342. .TP
  343. \fIgraphHandle\fR \fBlayout ?dot|neato|circo|twopi|fdp|nop?\fR
  344. Annotate the graph with layout information. This commands takes an
  345. abstract graph add shape and position information to it according to
  346. the layout engine's rules of eye-pleasing graph layout. If the layout engine is
  347. unspecified then it defaults to \fBdot\fR for directed graphs, and \fBneato\fR otherwise.
  348. If the \fBnop\fR engine is specified then layout information from the input graph is used.
  349. The result of the layout is stored
  350. as additional attributes name/value pairs in the graph, node and edges.
  351. These attributes are intended to be interpreted by subsequent
  352. .I write
  353. or
  354. .I render
  355. commands.
  356. .TP
  357. \fIgraphHandle\fR \fBwrite\fR \fIfileHandle format ?dot|neato|circo|twopi|fdp|nop?\fR
  358. Write a graph to the open file represented by
  359. .I fileHandle
  360. in a specific
  361. .I format.
  362. Possible
  363. .I formats
  364. are: "ps" "mif" "plain" "dot" "gif" "ismap"
  365. If the layout hasn't been already done, then it will be done as part
  366. of this operation using the same rules for selecting the layout engine
  367. as for the layout command.
  368. .TP
  369. \fIgraphHandle\fR \fBrendergd\fR \fIgdHandle\fR
  370. Generates a rendering of a graph to a new
  371. or existing gifImage structure (see
  372. .B gdTcl(1)
  373. ). Returns the
  374. .I gdHandle
  375. of the image.
  376. If the layout hasn't been already done, then it will be done as part
  377. of this operation using the same rules for selecting the layout engine
  378. as for the layout command.
  379. .TP
  380. \fIgraphHandle\fR \fBrender\fR \fI?canvas ?dot|neato|circo|twopi|fdp|nop??\fR
  381. If no \fIcanvas\fR argument is provided then \fBrender\fR
  382. returns a string of commands which, when evaluated, will render the
  383. graph to a
  384. .B Tk
  385. canvas whose
  386. .I canvasHandle
  387. is available in variable
  388. .B $c
  389. If a \fIcanvas\fR argument is provided then \fBrender\fR
  390. produces a set of commands for \fIcanvas\fR instead of $c.
  391. If the layout hasn't been already done, then it will be done as part
  392. of this operation using the same rules for selecting the layout engine
  393. as for the layout command.
  394. .nf
  395. #!/usr/local/bin/wish
  396. package require Tcldot
  397. set c [canvas .c]
  398. pack $c
  399. set g [dotnew digraph rankdir LR]
  400. $g setnodeattribute style filled color white
  401. [$g addnode Hello] addedge [$g addnode World!]
  402. $g layout
  403. if {[info exists debug]} {
  404. puts [$g render] ;# see what render produces
  405. }
  406. eval [$g render]
  407. .fi
  408. .B Render
  409. generates a series of canvas commands for each graph element, for example
  410. a node typically consist of two items on the canvas, one for the shape
  411. and the other for the label. The canvas items are automatically
  412. .I tagged
  413. (See
  414. .B canvas(n)
  415. ) by the commands generated by render. The tags take one of two forms:
  416. text items are tagged with 0<handle> and
  417. shapes and lines are rendered with 1<handle>.
  418. The tagging can be used to recognize when a user wants to interact with
  419. a graph element using the mouse. See the script in
  420. .I examples/disp
  421. of the tcldot distribution for a demonstration of this facility.
  422. .SH BUGS
  423. Still batch-oriented. It would be nice if the layout was maintained incrementally.
  424. (The intent is to address this limitation in graphviz_2_0.)
  425. .SH AUTHOR
  426. John Ellson ([email protected])
  427. .SH ACKNOWLEDGEMENTS
  428. John Ousterhout, of course, for
  429. .B tcl
  430. and
  431. .B tk.
  432. Steven North and Eleftherios Koutsofios for
  433. .B dot.
  434. Karl Lehenbauer and Mark Diekhans of NeoSoft
  435. for the handles.c code which was derived from tclXhandles.c.
  436. Tom Boutell of the Quest Center at Cold Spring Harbor Labs for the gif drawing routines.
  437. Spencer Thomas of the University of Michigan for gdTcl.c.
  438. Dayatra Shands for coding much of the initial implementation of
  439. .B tcldot.
  440. .SH KEYWORDS
  441. graph, tcl, tk, dot, neato.