Skip to content

Commit d872f73

Browse files
committed
add demo dot files and image files.
1 parent 18c2e60 commit d872f73

14 files changed

+79
-14
lines changed

.dir-locals.el

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
;;; -*- encoding:utf-8 -*- ---
2+
((nil
3+
(org-link-file-path-type . relative)
4+
(toc-org-max-depth . 3)))

dot.org

+39-14
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,16 @@
1717
- [[#preparation][Preparation]]
1818
- [[#language-presentation][Language presentation]]
1919
- [[#global-variables][global variables]]
20+
- [[#the-encode-stream][the encode stream]]
21+
- [[#the-indent-level][the indent level]]
22+
- [[#the-default-size-for-indent-tab][the default size for indent tab]]
2023
- [[#how-to-render-a-dot-s-expression][how to render a dot s-expression]]
2124
- [[#how-to-format-a-dot-s-expression][how to format a dot s-expression]]
2225
- [[#graph][graph]]
2326
- [[#stmt-list][stmt-list]]
2427
- [[#stmt][stmt]]
2528
- [[#node-statement][node statement]]
29+
- [[#node-id][node id]]
2630
- [[#edge-statement][edge statement]]
2731
- [[#attribute-statement][attribute statement]]
2832
- [[#attribute][attribute]]
@@ -53,10 +57,10 @@ We will use a lisp style to present the [[https://www.graphviz.org/doc/info/lang
5357
graph : [ strict ] (graph | digraph) [ ID ] '{' stmt_list '}'
5458
stmt_list : [ stmt [ ';' ] stmt_list ]
5559
stmt : node_stmt
56-
| edge_stmt
57-
| attr_stmt
58-
| ID '=' ID
59-
| subgraph
60+
| edge_stmt
61+
| attr_stmt
62+
| ID '=' ID
63+
| subgraph
6064
attr_stmt : (graph | node | edge) attr_list
6165
attr_list : '[' [ a_list ] ']' [ attr_list ]
6266
a_list : ID '=' ID [ (';' | ',') ] [ a_list ]
@@ -65,7 +69,7 @@ edgeRHS : edgeop (node_id | subgraph) [ edgeRHS ]
6569
node_stmt : node_id [ attr_list ]
6670
node_id : ID [ port ]
6771
port : ':' ID [ ':' compass_pt ]
68-
| ':' compass_pt
72+
| ':' compass_pt
6973
subgraph : [ subgraph [ ID ] ] '{' stmt_list '}'
7074
compass_pt : (n | ne | e | se | s | sw | w | nw | c | _)
7175
#+end_src
@@ -101,6 +105,7 @@ for example svg, ps, gif, png, or jpg.
101105
:name (pathname-name file-name) :type "dot")))
102106
(with-open-file (stream dot-file-name :direction :output :if-exists :supersede
103107
:if-does-not-exist :create)
108+
(format stream "// This file is generated automatically by s-dot.~%~%")
104109
(format-s-dot statement-list :graph-type graph-type :id id :stream stream))
105110
(uiop:run-program (format nil "~a -o ~a ~a~a ~a"
106111
dot-exe file-name dot-output-format-switch
@@ -111,9 +116,10 @@ for example svg, ps, gif, png, or jpg.
111116
We will provide a helpful routine to render a dot s-expression and open it in Emacs.
112117
#+BEGIN_SRC lisp :load dev
113118
(defmacro render-and-open-s-dot (file-name &rest left-args)
114-
`(progn
115-
(render-s-dot ,file-name ,@left-args)
116-
(swank:eval-in-emacs `(find-file ,,file-name) t)))
119+
(let ((real-file-name (gensym "file-name")))
120+
`(let ((,real-file-name (namestring ,file-name)))
121+
(render-s-dot ,real-file-name ,@left-args)
122+
(swank:eval-in-emacs `(find-file ,,real-file-name) t))))
117123
#+END_SRC
118124

119125

@@ -193,9 +199,12 @@ There are many different kinds of statements,let's recogize them one by one.
193199
If a statement starts without a known keyword, then it's a node statement,for example
194200
#+BEGIN_SRC lisp :load no
195201
(render-and-open-s-dot
196-
"/tmp/node1.pdf"
202+
(merge-pathnames
203+
#p"images/node1.png"
204+
(asdf:component-pathname (asdf:find-system :dot)))
197205
'((node1 (:label "nice node") (:shape :box) (:fontname "Arial") (:fontcolor "#AA0000"))))
198206
#+END_SRC
207+
file:./images/node1.png
199208

200209
#+BEGIN_SRC lisp
201210
(defun format-node-stmt (stmt)
@@ -228,7 +237,9 @@ In a s-expression, it's a list that starts with an ~edgeop~ and an ~attr_list~ a
228237
the rest are a list of ~node id~, for example
229238
#+BEGIN_SRC lisp :load no
230239
(render-and-open-s-dot
231-
"/tmp/edge1.pdf"
240+
(merge-pathnames
241+
#p"images/edge1.png"
242+
(asdf:component-pathname (asdf:find-system :dot)))
232243
'((:-> ((arrowhead :diamond)
233244
(color "#FF0000")
234245
(headlabel "head\nlabel")
@@ -240,6 +251,7 @@ the rest are a list of ~node id~, for example
240251
node2
241252
node3)))
242253
#+END_SRC
254+
file:./images/edge1.png
243255

244256
#+BEGIN_SRC lisp
245257
(defun format-edge-stmt (stmt)
@@ -260,7 +272,9 @@ In a dot s-expression, it starts with keyword ~:graph~, ~:node~, ~:edge~ , and t
260272
in the list is the ~attr_list~(ref:attr-list),for example:
261273
#+begin_src lisp :load no
262274
(render-and-open-s-dot
263-
"/tmp/node2.pdf"
275+
(merge-pathnames
276+
#p"images/node2.png"
277+
(asdf:component-pathname (asdf:find-system :dot)))
264278
'((:node
265279
(:fillcolor "#AAFFAA")
266280
(:shape :circle)
@@ -269,6 +283,7 @@ in the list is the ~attr_list~(ref:attr-list),for example:
269283
(:fontsize 16))
270284
(node1 (:id "a")(:label :test))))
271285
#+end_src
286+
file:./images/node2.png
272287

273288
#+BEGIN_SRC lisp
274289
(defun format-attr-stmt (stmt)
@@ -280,10 +295,13 @@ a single attribute can be applied to global environment in a statement,
280295
in a dot s-expression, it looks like this:
281296
#+BEGIN_SRC lisp :load no
282297
(render-and-open-s-dot
283-
"/tmp/attr.pdf"
298+
(merge-pathnames
299+
#p"images/attr.png"
300+
(asdf:component-pathname (asdf:find-system :dot)))
284301
'((= :compound t)
285302
(node1 (:id :test)(:label :test))))
286303
#+END_SRC
304+
file:./images/attr.png
287305

288306
#+BEGIN_SRC lisp
289307
(defun format-attribute (stmt)
@@ -298,12 +316,16 @@ It a subgraph's name starts with "cluster", then it has a special meaning.
298316
in a dot s-expression, it looks like this:
299317
#+BEGIN_SRC lisp
300318
(render-and-open-s-dot
301-
"/tmp/subgraph.pdf"
319+
(merge-pathnames
320+
#p"images/cluster1.png"
321+
(asdf:component-pathname (asdf:find-system :dot)))
302322
'((:subgraph cluster_1
303323
(node1 (:id :test)(:label :test))
304324
(node2 (:id :test2)(:label :test2))
305325
(:-> nil node1 node2))))
306326
#+END_SRC
327+
file:./images/cluster1.png
328+
307329
#+BEGIN_SRC lisp
308330
(defun format-subgraph-stmt (stmt)
309331
(let ((id (second stmt))
@@ -339,9 +361,12 @@ compass_pt : (n | ne | e | se | s | sw | w | nw | c | _)
339361
In a dot s-expression, it looks like this:
340362
#+BEGIN_SRC lisp :load no
341363
(render-and-open-s-dot
342-
"/tmp/port.pdf"
364+
(merge-pathnames
365+
#p"images/port.png"
366+
(asdf:component-pathname (asdf:find-system :dot)))
343367
'((:-> nil (node1 :e) node2)))
344368
#+END_SRC
369+
file:./images/port.png
345370

346371
#+BEGIN_SRC lisp
347372
(defun format-port (port)

images/attr.dot

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// This file is generated automatically by s-dot.
2+
3+
digraph {
4+
compound = true;
5+
node1 [id = test, label = test];
6+
}

images/attr.png

2.65 KB
Loading

images/cluster1.dot

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// This file is generated automatically by s-dot.
2+
3+
digraph {
4+
subgraph cluster_1{
5+
node1 [id = test, label = test];
6+
node2 [id = test2, label = test2];
7+
node1 -> node2;
8+
};
9+
}

images/cluster1.png

6 KB
Loading

images/edge1.dot

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// This file is generated automatically by s-dot.
2+
3+
digraph {
4+
node1 -> node2 -> node3 [arrowhead = diamond, color = "#FF0000", headlabel = "headnlabel", label = "red edge", labelfontname = "Arial", fontname = "courier", arrowsize = 2];
5+
}

images/edge1.png

15.8 KB
Loading

images/node1.dot

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// This file is generated automatically by s-dot.
2+
3+
digraph {
4+
node1 [label = "nice node", shape = box, fontname = "Arial", fontcolor = "#AA0000"];
5+
}

images/node1.png

1.68 KB
Loading

images/node2.dot

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// This file is generated automatically by s-dot.
2+
3+
digraph {
4+
node [fillcolor = "#AAFFAA", shape = circle, color = "#0000AA", style = filled, fontsize = 16];
5+
node1 [id = "a", label = test];
6+
}

images/node2.png

3.13 KB
Loading

images/port.dot

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// This file is generated automatically by s-dot.
2+
3+
digraph {
4+
node1 : e -> node2;
5+
}

images/port.png

7.45 KB
Loading

0 commit comments

Comments
 (0)