Spaces:
Running
Running
Update timeline_generator.py
Browse files- timeline_generator.py +9 -31
timeline_generator.py
CHANGED
|
@@ -102,37 +102,15 @@ def generate_timeline_diagram(json_input: str, output_format: str) -> str:
|
|
| 102 |
else:
|
| 103 |
full_label = event_label
|
| 104 |
|
| 105 |
-
# Calculate color
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
# Convert base_color hex to RGB for interpolation
|
| 110 |
-
if not isinstance(base_color, str) or not base_color.startswith('#') or len(base_color) != 7:
|
| 111 |
-
base_color_safe = '#19191a' # Fallback to default dark if invalid
|
| 112 |
else:
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
base_r = int(base_color_safe[1:3], 16)
|
| 116 |
-
base_g = int(base_color_safe[3:5], 16)
|
| 117 |
-
base_b = int(base_color_safe[5:7], 16)
|
| 118 |
-
|
| 119 |
-
# Calculate current node color by blending towards white
|
| 120 |
-
current_r = base_r + int((255 - base_r) * current_depth * lightening_factor)
|
| 121 |
-
current_g = base_g + int((255 - base_g) * current_depth * lightening_factor)
|
| 122 |
-
current_b = base_b + int((255 - base_b) * current_depth * lightening_factor)
|
| 123 |
-
|
| 124 |
-
# Clamp values to 255 to stay within valid RGB range
|
| 125 |
-
current_r = min(255, current_r)
|
| 126 |
-
current_g = min(255, current_g)
|
| 127 |
-
current_b = min(255, current_b)
|
| 128 |
-
|
| 129 |
-
node_color = f'#{current_r:02x}{current_g:02x}{current_b:02x}'
|
| 130 |
-
|
| 131 |
-
# Font color: white for dark nodes, black for very light nodes for readability
|
| 132 |
-
font_color = 'white' if current_depth * lightening_factor < 0.6 else 'black'
|
| 133 |
|
| 134 |
-
|
| 135 |
-
|
| 136 |
|
| 137 |
# Calculate position for serpentine layout
|
| 138 |
row = i // events_per_row
|
|
@@ -152,7 +130,7 @@ def generate_timeline_diagram(json_input: str, output_format: str) -> str:
|
|
| 152 |
style='filled,rounded',
|
| 153 |
fillcolor=node_color,
|
| 154 |
fontcolor=font_color,
|
| 155 |
-
fontsize=
|
| 156 |
width='2.5',
|
| 157 |
height='1.2',
|
| 158 |
pos=f"{visual_col * 4.5},{-row * 3}!" # Increased spacing for serpentine layout
|
|
@@ -166,7 +144,7 @@ def generate_timeline_diagram(json_input: str, output_format: str) -> str:
|
|
| 166 |
dot.edge(
|
| 167 |
current_event_id,
|
| 168 |
next_event_id,
|
| 169 |
-
color='#
|
| 170 |
arrowsize='0.8',
|
| 171 |
penwidth='2'
|
| 172 |
)
|
|
|
|
| 102 |
else:
|
| 103 |
full_label = event_label
|
| 104 |
|
| 105 |
+
# Calculate color opacity based on position in timeline
|
| 106 |
+
if total_events == 1:
|
| 107 |
+
opacity = 'FF'
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
else:
|
| 109 |
+
opacity_value = int(255 * (1.0 - (i * 0.7 / (total_events - 1))))
|
| 110 |
+
opacity = format(opacity_value, '02x')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
|
| 112 |
+
node_color = f"{base_color}{opacity}"
|
| 113 |
+
font_color = 'white' if i < total_events * 0.7 else 'black'
|
| 114 |
|
| 115 |
# Calculate position for serpentine layout
|
| 116 |
row = i // events_per_row
|
|
|
|
| 130 |
style='filled,rounded',
|
| 131 |
fillcolor=node_color,
|
| 132 |
fontcolor=font_color,
|
| 133 |
+
fontsize='12',
|
| 134 |
width='2.5',
|
| 135 |
height='1.2',
|
| 136 |
pos=f"{visual_col * 4.5},{-row * 3}!" # Increased spacing for serpentine layout
|
|
|
|
| 144 |
dot.edge(
|
| 145 |
current_event_id,
|
| 146 |
next_event_id,
|
| 147 |
+
color='#666666',
|
| 148 |
arrowsize='0.8',
|
| 149 |
penwidth='2'
|
| 150 |
)
|