-
-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathclass_diagrams.py
More file actions
159 lines (130 loc) · 3.87 KB
/
class_diagrams.py
File metadata and controls
159 lines (130 loc) · 3.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
r"""
Create MapServer class diagrams
Requires https://graphviz.gitlab.io/_pages/Download/Download_windows.html (tested with graphviz-11.0.0 (64-bit) EXE installer)
For DOT language see http://www.graphviz.org/doc/info/attrs.html
See also https://stackoverflow.com/questions/1494492/graphviz-how-to-go-from-dot-to-a-graph
For Entity Relationship diagram example see https://graphviz.readthedocs.io/en/stable/examples.html#er-py
pip install pydot
# to generate diagrams run the following in PowerShell
C:\VirtualEnvs\mappyfile3\Scripts\activate.ps1
$env:Path = "C:\Program Files\Graphviz\bin;" + $env:Path
# dot -Tpng D:\GitHub\mappyfile\mapfile_classes.dot -o outfile.png
cd D:\GitHub\mappyfile\docs\scripts
python class_diagrams.py
"""
import pydot
FONT = "Lucida Sans"
def add_child(graph, child_id, child_label, parent_id, colour):
"""
http://www.graphviz.org/doc/info/shapes.html#polygon
"""
node = pydot.Node(
child_id,
style="filled",
fillcolor=colour,
label=child_label,
shape="polygon",
fontname=FONT,
)
graph.add_node(node)
graph.add_edge(pydot.Edge(parent_id, node))
def add_children(graph, parent_id, d, level=0):
blue = "#6b6bd1"
white = "#fdfefd"
green = "#33a333"
colours = [blue, white, green] * 3
for class_, children in d.items():
colour = colours[level]
child_label = class_
child_id = parent_id + "_" + class_
add_child(graph, child_id, child_label, parent_id, colour)
add_children(graph, child_id, children, level + 1)
def save_file(graph, fn):
filename = "%s.png" % fn
graph.write_png(filename)
graph.write("%s.dot" % fn)
def layer_children():
return {
"CLASS": {
"LABEL": {"STYLE": {}},
"CONNECTIONOPTIONS": {},
"LEADER": {"STYLE": {}},
"STYLE": {},
"VALIDATION": {},
},
"CLUSTER": {},
"COMPOSITE": {},
"FEATURE": {"POINTS": {}},
"GRID": {},
"IDENTIFY": {},
"JOIN": {},
"METADATA": {},
"PROJECTION": {},
"SCALETOKEN": {"VALUES": {}},
"VALIDATION": {},
}
def map_children():
return {
"MAP": {
"LAYER": layer_children(),
"LEGEND": {"LABEL": {}},
"PROJECTION": {},
"QUERYMAP": {},
"REFERENCE": {},
"SCALEBAR": {"LABEL": {}},
"SYMBOL": {},
"WEB": {"METADATA": {}, "VALIDATION": {}},
}
}
def simple_classes():
return {
"MAP": {
"LAYER": {
"CLASS": {
"STYLE": {},
}
},
"PROJECTION": {},
"SYMBOL": {},
"WEB": {
"METADATA": {},
},
}
}
def very_simple_classes():
return {
"MAP": {
"LAYER": {
"CLASS": {
"STYLE": {},
}
},
"PROJECTION": {},
"WEB": {
"METADATA": {},
},
}
}
def generate_graph(root, classes, fn):
graph = pydot.Dot(graph_type="digraph", rankdir="TB")
node = pydot.Node(
root,
style="filled",
fillcolor="#33a333",
label=root,
fontname=FONT,
shape="polygon",
)
graph.add_node(node)
add_children(graph, root, classes[root])
save_file(graph, fn)
def main():
# pprint.pprint(layer_children)
classes = map_children()
generate_graph(root="LAYER", classes=classes["MAP"], fn="layer_classes")
generate_graph(root="MAP", classes=classes, fn="map_classes")
generate_graph(root="MAP", classes=simple_classes(), fn="simple_classes")
generate_graph(root="MAP", classes=very_simple_classes(), fn="very_simple_classes")
if __name__ == "__main__":
main()
print("Done!")