Spaces:
Running
Running
Update class_diagram_generator.py
Browse files- class_diagram_generator.py +21 -22
class_diagram_generator.py
CHANGED
|
@@ -194,7 +194,10 @@ def generate_class_diagram(json_input: str, output_format: str) -> str:
|
|
| 194 |
dot = graphviz.Digraph(comment='Class Diagram')
|
| 195 |
dot.attr(rankdir='TB', bgcolor='white', pad='0.5', nodesep='0.8', ranksep='1.2', splines='ortho')
|
| 196 |
dot.attr('node', shape='plaintext', fontname='Arial', fontsize='11')
|
| 197 |
-
dot.attr('edge', color='
|
|
|
|
|
|
|
|
|
|
| 198 |
|
| 199 |
classes = data.get('classes', [])
|
| 200 |
relationships = data.get('relationships', [])
|
|
@@ -208,18 +211,16 @@ def generate_class_diagram(json_input: str, output_format: str) -> str:
|
|
| 208 |
if not class_name:
|
| 209 |
continue
|
| 210 |
|
| 211 |
-
html_label = '<TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0" CELLPADDING="5" BGCOLOR="
|
| 212 |
|
| 213 |
if class_type == 'abstract':
|
| 214 |
-
html_label += f'<TR><TD ALIGN="CENTER"><B><<abstract>><BR/>{class_name}</B></TD></TR>'
|
| 215 |
elif class_type == 'interface':
|
| 216 |
-
html_label += f'<TR><TD ALIGN="CENTER"><B><<interface>><BR/>{class_name}</B></TD></TR>'
|
| 217 |
elif class_type == 'enum':
|
| 218 |
-
html_label += f'<TR><TD ALIGN="CENTER"><B><<enumeration>><BR/>{class_name}</B></TD></TR>'
|
| 219 |
else:
|
| 220 |
-
html_label += f'<TR><TD ALIGN="CENTER"><B>{class_name}</B></TD></TR>'
|
| 221 |
-
|
| 222 |
-
html_label += '<HR/>'
|
| 223 |
|
| 224 |
if attributes:
|
| 225 |
for attr in attributes:
|
|
@@ -234,11 +235,9 @@ def generate_class_diagram(json_input: str, output_format: str) -> str:
|
|
| 234 |
if is_static:
|
| 235 |
line = f"<U>{line}</U>"
|
| 236 |
|
| 237 |
-
html_label += f'<TR><TD ALIGN="LEFT">{line}</TD></TR>'
|
| 238 |
else:
|
| 239 |
-
html_label += '<TR><TD ALIGN="LEFT"> </TD></TR>'
|
| 240 |
-
|
| 241 |
-
html_label += '<HR/>'
|
| 242 |
|
| 243 |
if methods:
|
| 244 |
for method in methods:
|
|
@@ -264,13 +263,13 @@ def generate_class_diagram(json_input: str, output_format: str) -> str:
|
|
| 264 |
if is_abstract:
|
| 265 |
line = f"<I>{line}</I>"
|
| 266 |
|
| 267 |
-
html_label += f'<TR><TD ALIGN="LEFT">{line}</TD></TR>'
|
| 268 |
else:
|
| 269 |
-
html_label += '<TR><TD ALIGN="LEFT"> </TD></TR>'
|
| 270 |
|
| 271 |
html_label += '</TABLE>'
|
| 272 |
|
| 273 |
-
dot.node(class_name, f'<{html_label}>')
|
| 274 |
|
| 275 |
for relationship in relationships:
|
| 276 |
from_class = relationship.get('from')
|
|
@@ -284,7 +283,7 @@ def generate_class_diagram(json_input: str, output_format: str) -> str:
|
|
| 284 |
continue
|
| 285 |
|
| 286 |
edge_attrs = {
|
| 287 |
-
'color': '
|
| 288 |
}
|
| 289 |
|
| 290 |
if multiplicity_from:
|
|
@@ -295,28 +294,28 @@ def generate_class_diagram(json_input: str, output_format: str) -> str:
|
|
| 295 |
|
| 296 |
if rel_type == 'inheritance':
|
| 297 |
edge_attrs['arrowhead'] = 'empty'
|
| 298 |
-
edge_attrs['color'] = '
|
| 299 |
elif rel_type == 'composition':
|
| 300 |
edge_attrs['arrowhead'] = 'normal'
|
| 301 |
edge_attrs['arrowtail'] = 'diamond'
|
| 302 |
edge_attrs['dir'] = 'both'
|
| 303 |
-
edge_attrs['color'] = '
|
| 304 |
elif rel_type == 'aggregation':
|
| 305 |
edge_attrs['arrowhead'] = 'normal'
|
| 306 |
edge_attrs['arrowtail'] = 'odiamond'
|
| 307 |
edge_attrs['dir'] = 'both'
|
| 308 |
-
edge_attrs['color'] = '
|
| 309 |
elif rel_type == 'realization':
|
| 310 |
edge_attrs['arrowhead'] = 'empty'
|
| 311 |
edge_attrs['style'] = 'dashed'
|
| 312 |
-
edge_attrs['color'] = '
|
| 313 |
elif rel_type == 'dependency':
|
| 314 |
edge_attrs['arrowhead'] = 'normal'
|
| 315 |
edge_attrs['style'] = 'dashed'
|
| 316 |
-
edge_attrs['color'] = '
|
| 317 |
else:
|
| 318 |
edge_attrs['arrowhead'] = 'normal'
|
| 319 |
-
edge_attrs['color'] = '
|
| 320 |
|
| 321 |
dot.edge(from_class, to_class, **edge_attrs)
|
| 322 |
|
|
|
|
| 194 |
dot = graphviz.Digraph(comment='Class Diagram')
|
| 195 |
dot.attr(rankdir='TB', bgcolor='white', pad='0.5', nodesep='0.8', ranksep='1.2', splines='ortho')
|
| 196 |
dot.attr('node', shape='plaintext', fontname='Arial', fontsize='11')
|
| 197 |
+
dot.attr('edge', color='#4a4a4a', fontname='Arial', fontsize='9', minlen='1')
|
| 198 |
+
|
| 199 |
+
header_color = '#BEBEBE'
|
| 200 |
+
body_color = '#E8E8E8'
|
| 201 |
|
| 202 |
classes = data.get('classes', [])
|
| 203 |
relationships = data.get('relationships', [])
|
|
|
|
| 211 |
if not class_name:
|
| 212 |
continue
|
| 213 |
|
| 214 |
+
html_label = f'<TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0" CELLPADDING="5" STYLE="rounded" BGCOLOR="{body_color}">'
|
| 215 |
|
| 216 |
if class_type == 'abstract':
|
| 217 |
+
html_label += f'<TR><TD ALIGN="CENTER" BGCOLOR="{header_color}"><B><<abstract>><BR/>{class_name}</B></TD></TR>'
|
| 218 |
elif class_type == 'interface':
|
| 219 |
+
html_label += f'<TR><TD ALIGN="CENTER" BGCOLOR="{header_color}"><B><<interface>><BR/>{class_name}</B></TD></TR>'
|
| 220 |
elif class_type == 'enum':
|
| 221 |
+
html_label += f'<TR><TD ALIGN="CENTER" BGCOLOR="{header_color}"><B><<enumeration>><BR/>{class_name}</B></TD></TR>'
|
| 222 |
else:
|
| 223 |
+
html_label += f'<TR><TD ALIGN="CENTER" BGCOLOR="{header_color}"><B>{class_name}</B></TD></TR>'
|
|
|
|
|
|
|
| 224 |
|
| 225 |
if attributes:
|
| 226 |
for attr in attributes:
|
|
|
|
| 235 |
if is_static:
|
| 236 |
line = f"<U>{line}</U>"
|
| 237 |
|
| 238 |
+
html_label += f'<TR><TD ALIGN="LEFT" BGCOLOR="{body_color}">{line}</TD></TR>'
|
| 239 |
else:
|
| 240 |
+
html_label += f'<TR><TD ALIGN="LEFT" BGCOLOR="{body_color}"> </TD></TR>'
|
|
|
|
|
|
|
| 241 |
|
| 242 |
if methods:
|
| 243 |
for method in methods:
|
|
|
|
| 263 |
if is_abstract:
|
| 264 |
line = f"<I>{line}</I>"
|
| 265 |
|
| 266 |
+
html_label += f'<TR><TD ALIGN="LEFT" BGCOLOR="{body_color}">{line}</TD></TR>'
|
| 267 |
else:
|
| 268 |
+
html_label += f'<TR><TD ALIGN="LEFT" BGCOLOR="{body_color}"> </TD></TR>'
|
| 269 |
|
| 270 |
html_label += '</TABLE>'
|
| 271 |
|
| 272 |
+
dot.node(class_name, f'<{html_label}>', style='rounded')
|
| 273 |
|
| 274 |
for relationship in relationships:
|
| 275 |
from_class = relationship.get('from')
|
|
|
|
| 283 |
continue
|
| 284 |
|
| 285 |
edge_attrs = {
|
| 286 |
+
'color': '#4a4a4a'
|
| 287 |
}
|
| 288 |
|
| 289 |
if multiplicity_from:
|
|
|
|
| 294 |
|
| 295 |
if rel_type == 'inheritance':
|
| 296 |
edge_attrs['arrowhead'] = 'empty'
|
| 297 |
+
edge_attrs['color'] = '#4a4a4a'
|
| 298 |
elif rel_type == 'composition':
|
| 299 |
edge_attrs['arrowhead'] = 'normal'
|
| 300 |
edge_attrs['arrowtail'] = 'diamond'
|
| 301 |
edge_attrs['dir'] = 'both'
|
| 302 |
+
edge_attrs['color'] = '#4a4a4a'
|
| 303 |
elif rel_type == 'aggregation':
|
| 304 |
edge_attrs['arrowhead'] = 'normal'
|
| 305 |
edge_attrs['arrowtail'] = 'odiamond'
|
| 306 |
edge_attrs['dir'] = 'both'
|
| 307 |
+
edge_attrs['color'] = '#4a4a4a'
|
| 308 |
elif rel_type == 'realization':
|
| 309 |
edge_attrs['arrowhead'] = 'empty'
|
| 310 |
edge_attrs['style'] = 'dashed'
|
| 311 |
+
edge_attrs['color'] = '#4a4a4a'
|
| 312 |
elif rel_type == 'dependency':
|
| 313 |
edge_attrs['arrowhead'] = 'normal'
|
| 314 |
edge_attrs['style'] = 'dashed'
|
| 315 |
+
edge_attrs['color'] = '#4a4a4a'
|
| 316 |
else:
|
| 317 |
edge_attrs['arrowhead'] = 'normal'
|
| 318 |
+
edge_attrs['color'] = '#4a4a4a'
|
| 319 |
|
| 320 |
dot.edge(from_class, to_class, **edge_attrs)
|
| 321 |
|