Update synoptic_chart_generator.py
Browse files
synoptic_chart_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_synoptic_chart(json_input: str) -> str:
|
| 8 |
"""
|
| 9 |
Generates a synoptic chart (horizontal flowchart) from JSON input.
|
| 10 |
|
|
@@ -119,9 +119,8 @@ def generate_synoptic_chart(json_input: str) -> str: # Removed base_color parame
|
|
| 119 |
}
|
| 120 |
)
|
| 121 |
|
| 122 |
-
base_color = '#19191a'
|
| 123 |
|
| 124 |
-
# Central node styling (rounded box, dark color)
|
| 125 |
dot.node(
|
| 126 |
'central',
|
| 127 |
data['central_node'],
|
|
@@ -132,13 +131,11 @@ def generate_synoptic_chart(json_input: str) -> str: # Removed base_color parame
|
|
| 132 |
fontsize='16' # Larger font for central node
|
| 133 |
)
|
| 134 |
|
| 135 |
-
# Add child nodes and edges recursively starting from depth 1
|
| 136 |
add_nodes_and_edges(dot, 'central', data.get('nodes', []), current_depth=1, base_color=base_color)
|
| 137 |
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
return tmp.name + '.png'
|
| 142 |
|
| 143 |
except json.JSONDecodeError:
|
| 144 |
return "Error: Invalid JSON format"
|
|
|
|
| 4 |
import os
|
| 5 |
from graph_generator_utils import add_nodes_and_edges
|
| 6 |
|
| 7 |
+
def generate_synoptic_chart(json_input: str, output_format: str) -> str:
|
| 8 |
"""
|
| 9 |
Generates a synoptic chart (horizontal flowchart) from JSON input.
|
| 10 |
|
|
|
|
| 119 |
}
|
| 120 |
)
|
| 121 |
|
| 122 |
+
base_color = '#19191a'
|
| 123 |
|
|
|
|
| 124 |
dot.node(
|
| 125 |
'central',
|
| 126 |
data['central_node'],
|
|
|
|
| 131 |
fontsize='16' # Larger font for central node
|
| 132 |
)
|
| 133 |
|
|
|
|
| 134 |
add_nodes_and_edges(dot, 'central', data.get('nodes', []), current_depth=1, base_color=base_color)
|
| 135 |
|
| 136 |
+
with NamedTemporaryFile(delete=False, suffix=f'.{output_format}') as tmp:
|
| 137 |
+
dot.render(tmp.name, format=output_format, cleanup=True)
|
| 138 |
+
return f"{tmp.name}.{output_format}"
|
|
|
|
| 139 |
|
| 140 |
except json.JSONDecodeError:
|
| 141 |
return "Error: Invalid JSON format"
|