Mercurial > projects > dil
annotate trunk/src/docgen/graphutils/dotwriter.d @ 452:f658ec4a15dd
Simple docgen ui util, some fixes.
author | Jari-Matti M?kel? <jmjm@iki.fi> |
---|---|
date | Wed, 24 Oct 2007 22:31:38 +0300 |
parents | 3f44c38bf870 |
children | 4e5b35df3060 |
rev | line source |
---|---|
395
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
1 /** |
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
2 * Author: Aziz Köksal & Jari-Matti Mäkelä |
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
3 * License: GPL3 |
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
4 */ |
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
5 module docgen.graphutils.dotwriter; |
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
6 import docgen.graphutils.writer; |
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
7 |
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
8 import tango.io.FileConduit : FileConduit; |
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
9 import tango.io.Print: Print; |
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
10 import tango.text.convert.Layout : Layout; |
449
757bd048482c
Depgraph test + minor modifications.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
448
diff
changeset
|
11 import tango.io.FilePath; |
395
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
12 |
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
13 /** |
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
14 * Creates a graph rule file for the dot utility. |
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
15 */ |
451
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
449
diff
changeset
|
16 class DotWriter : AbstractGraphWriter { |
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
449
diff
changeset
|
17 this(GraphWriterFactory factory, DocumentWriter writer) { |
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
449
diff
changeset
|
18 super(factory, writer); |
395
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
19 } |
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
20 |
451
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
449
diff
changeset
|
21 void generateGraph(Vertex[] vertices, Edge[] edges, OutputStream imageFile) { |
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
449
diff
changeset
|
22 auto image = new Print!(char)(new Layout!(char), imageFile); |
395
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
23 |
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
24 Vertex[][char[]] verticesByPckgName; |
452
f658ec4a15dd
Simple docgen ui util, some fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
451
diff
changeset
|
25 if (factory.options.graph.groupByFullPackageName) |
395
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
26 foreach (module_; vertices) |
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
27 verticesByPckgName[module_.name] ~= module_; // FIXME: is it name or loc? |
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
28 |
452
f658ec4a15dd
Simple docgen ui util, some fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
451
diff
changeset
|
29 if (factory.options.graph.highlightCyclicVertices || |
f658ec4a15dd
Simple docgen ui util, some fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
451
diff
changeset
|
30 factory.options.graph.highlightCyclicEdges) |
395
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
31 findCycles(vertices, edges); |
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
32 |
451
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
449
diff
changeset
|
33 if (cast(FileConduit)imageFile.conduit) { |
395
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
34 // name of the .dot file |
451
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
449
diff
changeset
|
35 char[] fn = (cast(FileConduit)imageFile.conduit).toUtf8(); |
449
757bd048482c
Depgraph test + minor modifications.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
448
diff
changeset
|
36 fn = FilePath(fn).file; |
395
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
37 |
451
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
449
diff
changeset
|
38 fn = fn[0..$-4]; |
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
449
diff
changeset
|
39 |
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
449
diff
changeset
|
40 writer.addGraphics(fn); |
395
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
41 } |
451
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
449
diff
changeset
|
42 |
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
449
diff
changeset
|
43 image("Digraph ModuleDependencies {\n"); |
395
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
44 |
452
f658ec4a15dd
Simple docgen ui util, some fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
451
diff
changeset
|
45 if (factory.options.graph.highlightCyclicVertices) |
395
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
46 foreach (module_; vertices) |
451
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
449
diff
changeset
|
47 image.format( |
395
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
48 ` n{0} [label="{1}"{2}];`\n, |
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
49 module_.id, |
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
50 module_.name, |
451
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
449
diff
changeset
|
51 (module_.isCyclic ? ",style=filled,fillcolor=" ~ factory.options.graph.nodeColor : "") |
395
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
52 ); |
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
53 else |
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
54 foreach (i, module_; vertices) |
451
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
449
diff
changeset
|
55 image.format(` n{0} [label="{1}"];`, i, module_.name); |
395
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
56 |
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
57 foreach (edge; edges) |
451
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
449
diff
changeset
|
58 image.format( |
395
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
59 ` n{0} -> n{1}{2};`\n, |
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
60 edge.outgoing.id, |
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
61 edge.incoming.id, |
451
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
449
diff
changeset
|
62 (edge.isCyclic ? "[color=" ~ factory.options.graph.cyclicNodeColor ~ "]" : "") |
395
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
63 ); |
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
64 |
452
f658ec4a15dd
Simple docgen ui util, some fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
451
diff
changeset
|
65 if (factory.options.graph.groupByFullPackageName) |
395
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
66 foreach (packageName, vertices; verticesByPckgName) { |
451
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
449
diff
changeset
|
67 image.format( |
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
449
diff
changeset
|
68 ` subgraph "cluster_{0}" {{`\n` label="{0}";color=` |
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
449
diff
changeset
|
69 ~ factory.options.graph.clusterColor ~ `;`\n` `, |
395
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
70 packageName, |
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
71 packageName |
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
72 ); |
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
73 |
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
74 foreach (module_; vertices) |
451
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
449
diff
changeset
|
75 image.format(`n{0};`, module_.id); |
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
449
diff
changeset
|
76 image("\n }\n"); |
395
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
77 } |
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
78 |
451
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
449
diff
changeset
|
79 image("}"); |
395
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
80 } |
452
f658ec4a15dd
Simple docgen ui util, some fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
451
diff
changeset
|
81 } |