Update radial_diagram_generator.py
Browse files
radial_diagram_generator.py
CHANGED
|
@@ -4,7 +4,7 @@ from tempfile import NamedTemporaryFile
|
|
| 4 |
import os
|
| 5 |
from graph_generator_utils import add_nodes_and_edges
|
| 6 |
|
| 7 |
-
def generate_radial_diagram(json_input: str) -> str:
|
| 8 |
"""
|
| 9 |
Generates a radial (center-expanded) diagram from JSON input.
|
| 10 |
|
|
@@ -94,7 +94,6 @@ def generate_radial_diagram(json_input: str) -> str: # Removed base_color parame
|
|
| 94 |
|
| 95 |
base_color = '#19191a' # Hardcoded base color
|
| 96 |
|
| 97 |
-
# Central node styling (rounded box, dark color)
|
| 98 |
dot.node(
|
| 99 |
'central',
|
| 100 |
data['central_node'],
|
|
@@ -105,14 +104,11 @@ def generate_radial_diagram(json_input: str) -> str: # Removed base_color parame
|
|
| 105 |
fontsize='16' # Larger font for central node
|
| 106 |
)
|
| 107 |
|
| 108 |
-
# Add child nodes and edges recursively starting from depth 1
|
| 109 |
-
# The add_nodes_and_edges function will handle styling consistent with other graphs
|
| 110 |
add_nodes_and_edges(dot, 'central', data.get('nodes', []), current_depth=1, base_color=base_color)
|
| 111 |
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
return tmp.name + '.png'
|
| 116 |
|
| 117 |
except json.JSONDecodeError:
|
| 118 |
return "Error: Invalid JSON format"
|
|
|
|
| 4 |
import os
|
| 5 |
from graph_generator_utils import add_nodes_and_edges
|
| 6 |
|
| 7 |
+
def generate_radial_diagram(json_input: str, output_format: str) -> str:
|
| 8 |
"""
|
| 9 |
Generates a radial (center-expanded) diagram from JSON input.
|
| 10 |
|
|
|
|
| 94 |
|
| 95 |
base_color = '#19191a' # Hardcoded base color
|
| 96 |
|
|
|
|
| 97 |
dot.node(
|
| 98 |
'central',
|
| 99 |
data['central_node'],
|
|
|
|
| 104 |
fontsize='16' # Larger font for central node
|
| 105 |
)
|
| 106 |
|
|
|
|
|
|
|
| 107 |
add_nodes_and_edges(dot, 'central', data.get('nodes', []), current_depth=1, base_color=base_color)
|
| 108 |
|
| 109 |
+
with NamedTemporaryFile(delete=False, suffix=f'.{output_format}') as tmp:
|
| 110 |
+
dot.render(tmp.name, format=output_format, cleanup=True)
|
| 111 |
+
return f"{tmp.name}.{output_format}"
|
|
|
|
| 112 |
|
| 113 |
except json.JSONDecodeError:
|
| 114 |
return "Error: Invalid JSON format"
|