ZahirJS commited on
Commit
6fc15fa
·
verified ·
1 Parent(s): 65dbbc1

Update process_flow_generator.py

Browse files
Files changed (1) hide show
  1. process_flow_generator.py +16 -16
process_flow_generator.py CHANGED
@@ -4,7 +4,7 @@ from tempfile import NamedTemporaryFile
4
  import os
5
  from graph_generator_utils import add_nodes_and_edges # Reusing common utility
6
 
7
- def generate_process_flow_diagram(json_input: str, base_color: str) -> str:
8
  """
9
  Generates a Process Flow Diagram (Flowchart) from JSON input.
10
 
@@ -52,7 +52,7 @@ def generate_process_flow_diagram(json_input: str, base_color: str) -> str:
52
  }
53
  ],
54
  "connections": [
55
- {"from": "start_node", "to": "step1", "label": "Start"},
56
  {"from": "step1", "to": "decision1", "label": "Continue"},
57
  {"from": "decision1", "to": "path_yes", "label": "Yes"},
58
  {"from": "decision1", "to": "path_no", "label": "No"},
@@ -67,16 +67,8 @@ def generate_process_flow_diagram(json_input: str, base_color: str) -> str:
67
 
68
  data = json.loads(json_input)
69
 
70
- # Determine specific node shapes for flowchart types
71
- node_shapes = {
72
- "process": "box", # Rectangle for processes
73
- "decision": "diamond", # Diamond for decisions
74
- "start": "oval", # Oval for start
75
- "end": "oval", # Oval for end
76
- "io": "parallelogram", # Input/Output
77
- "document": "note", # Document symbol
78
- "default": "box" # Fallback
79
- }
80
 
81
  dot = graphviz.Digraph(
82
  name='ProcessFlowDiagram',
@@ -91,9 +83,18 @@ def generate_process_flow_diagram(json_input: str, base_color: str) -> str:
91
  }
92
  )
93
 
94
- # Ensure base_color is valid, fallback if not
95
- if not isinstance(base_color, str) or not base_color.startswith('#') or len(base_color) != 7:
96
- base_color = '#19191a' # Fallback to default dark if invalid
 
 
 
 
 
 
 
 
 
97
 
98
  # Add all nodes based on JSON structure
99
  all_nodes_data = {}
@@ -109,7 +110,6 @@ def generate_process_flow_diagram(json_input: str, base_color: str) -> str:
109
  shape = node_shapes.get(node_type, "box") # Default to box if type is unknown
110
 
111
  # Use base_color for all nodes for consistent flowchart look
112
- # You can adapt add_nodes_and_edges if you want color gradient per depth for flowcharts too
113
  fill_color_for_node = base_color
114
  font_color_for_node = 'white' if base_color == '#19191a' else 'black' # Keep text readable
115
 
 
4
  import os
5
  from graph_generator_utils import add_nodes_and_edges # Reusing common utility
6
 
7
+ def generate_process_flow_diagram(json_input: str, base_color: str) -> str: # base_color is now correctly used
8
  """
9
  Generates a Process Flow Diagram (Flowchart) from JSON input.
10
 
 
52
  }
53
  ],
54
  "connections": [
55
+ {"from": "start_node", "to": "step1", "label": "Initiate"},
56
  {"from": "step1", "to": "decision1", "label": "Continue"},
57
  {"from": "decision1", "to": "path_yes", "label": "Yes"},
58
  {"from": "decision1", "to": "path_no", "label": "No"},
 
67
 
68
  data = json.loads(json_input)
69
 
70
+ if 'central_node' not in data or 'nodes' not in data:
71
+ raise ValueError("Missing required fields: central_node or nodes")
 
 
 
 
 
 
 
 
72
 
73
  dot = graphviz.Digraph(
74
  name='ProcessFlowDiagram',
 
83
  }
84
  )
85
 
86
+ # This line was REMOVED to ensure the passed base_color is used: base_color = '#19191a'
87
+
88
+ # Determine specific node shapes for flowchart types
89
+ node_shapes = {
90
+ "process": "box", # Rectangle for processes
91
+ "decision": "diamond", # Diamond for decisions
92
+ "start": "oval", # Oval for start
93
+ "end": "oval", # Oval for end
94
+ "io": "parallelogram", # Input/Output
95
+ "document": "note", # Document symbol
96
+ "default": "box" # Fallback
97
+ }
98
 
99
  # Add all nodes based on JSON structure
100
  all_nodes_data = {}
 
110
  shape = node_shapes.get(node_type, "box") # Default to box if type is unknown
111
 
112
  # Use base_color for all nodes for consistent flowchart look
 
113
  fill_color_for_node = base_color
114
  font_color_for_node = 'white' if base_color == '#19191a' else 'black' # Keep text readable
115