ZahirJS commited on
Commit
865a197
·
verified ·
1 Parent(s): ddb42dc

Update wbs_diagram_generator.py

Browse files
Files changed (1) hide show
  1. wbs_diagram_generator.py +4 -15
wbs_diagram_generator.py CHANGED
@@ -2,17 +2,15 @@ import graphviz
2
  import json
3
  from tempfile import NamedTemporaryFile
4
  import os
5
- from graph_generator_utils import add_nodes_and_edges # Reusing common utility
6
 
7
- def generate_wbs_diagram(json_input: str, base_color: str) -> str: # base_color is now correctly used
8
  """
9
  Generates a Work Breakdown Structure (WBS) Diagram from JSON input.
10
 
11
  Args:
12
  json_input (str): A JSON string describing the WBS structure.
13
  It must follow the Expected JSON Format Example below.
14
- base_color (str): The hexadecimal color string (e.g., '#19191a') for the base
15
- color of the nodes, from which a gradient will be generated.
16
 
17
  Returns:
18
  str: The filepath to the generated PNG image file.
@@ -63,7 +61,7 @@ def generate_wbs_diagram(json_input: str, base_color: str) -> str: # base_color
63
  }
64
  )
65
 
66
- # This line was REMOVED to ensure the passed base_color is used: base_color = '#19191a'
67
 
68
  # Project Title node (main node)
69
  dot.node(
@@ -77,7 +75,7 @@ def generate_wbs_diagram(json_input: str, base_color: str) -> str: # base_color
77
  )
78
 
79
  # Logic for color gradient within WBS specific nodes (Phases and Tasks)
80
- # This ensures the gradient works correctly with the passed base_color
81
  def get_gradient_color(depth, base_hex_color, lightening_factor=0.12):
82
  base_r = int(base_hex_color[1:3], 16)
83
  base_g = int(base_hex_color[3:5], 16)
@@ -155,15 +153,6 @@ def generate_wbs_diagram(json_input: str, base_color: str) -> str: # base_color
155
  # Use subgraph to enforce vertical alignment for tasks within a phase
156
  if task_nodes_in_phase: # Only create subgraph if there are tasks
157
  dot.subgraph(name=f'cluster_{phase_id}')
158
- # You would typically add nodes to the subgraph if you want
159
- # specific layout within it. For WBS columnar, just using rank attribute might suffice
160
- # or ensuring proper `ranksep` and `nodesep` at graph level.
161
- # The crucial part for columnar WBS is often setting nodes to the same rank
162
- # or controlling the order. This is implicitly handled by `rankdir=TB`.
163
- # The subgraphs themselves mostly define visual grouping (border) in Graphviz.
164
- # Let's try to ensure vertical flow is emphasized without complex subgraphs that
165
- # might interfere with the main layout engine. The primary connection handles rank.
166
-
167
  # Save to temporary file
168
  with NamedTemporaryFile(delete=False, suffix='.png') as tmp:
169
  dot.render(tmp.name, format='png', cleanup=True)
 
2
  import json
3
  from tempfile import NamedTemporaryFile
4
  import os
5
+ from graph_generator_utils import add_nodes_and_edges
6
 
7
+ def generate_wbs_diagram(json_input: str) -> str: # Removed base_color parameter
8
  """
9
  Generates a Work Breakdown Structure (WBS) Diagram from JSON input.
10
 
11
  Args:
12
  json_input (str): A JSON string describing the WBS structure.
13
  It must follow the Expected JSON Format Example below.
 
 
14
 
15
  Returns:
16
  str: The filepath to the generated PNG image file.
 
61
  }
62
  )
63
 
64
+ base_color = '#19191a' # Hardcoded base color
65
 
66
  # Project Title node (main node)
67
  dot.node(
 
75
  )
76
 
77
  # Logic for color gradient within WBS specific nodes (Phases and Tasks)
78
+ # This ensures the gradient works correctly with the hardcoded base_color
79
  def get_gradient_color(depth, base_hex_color, lightening_factor=0.12):
80
  base_r = int(base_hex_color[1:3], 16)
81
  base_g = int(base_hex_color[3:5], 16)
 
153
  # Use subgraph to enforce vertical alignment for tasks within a phase
154
  if task_nodes_in_phase: # Only create subgraph if there are tasks
155
  dot.subgraph(name=f'cluster_{phase_id}')
 
 
 
 
 
 
 
 
 
156
  # Save to temporary file
157
  with NamedTemporaryFile(delete=False, suffix='.png') as tmp:
158
  dot.render(tmp.name, format='png', cleanup=True)