Skip to content

Commit bae5143

Browse files
committed
style: format code and improve text position grid layout in main.py
1 parent c6579e8 commit bae5143

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

main.py

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -164,23 +164,23 @@
164164
+ "Actionability: %{customdata[1]}<br>"
165165
+ "Business Value: %{customdata[2]}<br>"
166166
)
167-
167+
168168
# Improve text display with wrapping and better visibility
169169
# Don't set textposition here as we'll handle it individually for each point
170-
170+
171171
# Add text wrapping for better readability and prevent overlap
172172
# Create a list of wrapped text labels and assign different positions to prevent overlap
173173
wrapped_labels = []
174174
text_positions = []
175-
175+
176176
# First, wrap the text labels
177177
for name in plot_df["Name"]:
178178
# Split long names into multiple lines (max 15 chars per line)
179179
if len(name) > 15:
180180
words = name.split()
181181
lines = []
182182
current_line = ""
183-
183+
184184
for word in words:
185185
if len(current_line + " " + word) > 15 and current_line:
186186
lines.append(current_line)
@@ -190,38 +190,43 @@
190190
current_line += " " + word
191191
else:
192192
current_line = word
193-
193+
194194
if current_line: # Add the last line
195195
lines.append(current_line)
196-
196+
197197
wrapped_labels.append("<br>".join(lines))
198198
else:
199199
wrapped_labels.append(name)
200-
200+
201201
# Create a grid-based positioning system to prevent overlap
202202
# Define possible text positions
203203
positions = [
204-
"top center", "top right", "top left",
205-
"bottom center", "bottom right", "bottom left",
206-
"middle right", "middle left"
204+
"top center",
205+
"top right",
206+
"top left",
207+
"bottom center",
208+
"bottom right",
209+
"bottom left",
210+
"middle right",
211+
"middle left",
207212
]
208-
213+
209214
# Group points that are close to each other
210215
# This is a simplified approach - we'll use a grid-based system
211216
grid_size = 0.5 # Size of each grid cell
212217
grid = {} # Dictionary to store points in each grid cell
213-
218+
214219
for i, row in plot_df.iterrows():
215220
# Calculate grid position
216221
grid_x = int(row["Feasibility_jitter"] / grid_size)
217222
grid_y = int(row["Actionability_jitter"] / grid_size)
218223
grid_key = (grid_x, grid_y)
219-
224+
220225
# Add point to grid
221226
if grid_key not in grid:
222227
grid[grid_key] = []
223228
grid[grid_key].append(i)
224-
229+
225230
# Assign positions to avoid overlap
226231
for grid_key, indices in grid.items():
227232
if len(indices) == 1:
@@ -235,11 +240,11 @@
235240
text_positions[point_idx] = positions[position_idx]
236241
else:
237242
text_positions.append(positions[position_idx])
238-
243+
239244
# Ensure we have a position for each point
240245
while len(text_positions) < len(plot_df):
241246
text_positions.append("top center")
242-
247+
243248
# Update the text with wrapped labels and positions
244249
fig.update_traces(
245250
text=wrapped_labels,
@@ -314,7 +319,7 @@
314319
font_size=12,
315320
font_family="Arial",
316321
bordercolor="#DFE2E6",
317-
namelength=-1 # Show the full label name
322+
namelength=-1, # Show the full label name
318323
),
319324
# Add some margin to ensure text labels have room
320325
margin=dict(l=50, r=50, t=50, b=50),

0 commit comments

Comments
 (0)