Spaces:
Running
Running
Update ui_generators.py
Browse files- ui_generators.py +35 -49
ui_generators.py
CHANGED
@@ -325,33 +325,34 @@ def run_follower_stats_tab_display(token_state):
|
|
325 |
def create_analytics_plot_panel(plot_label_str, plot_id_str):
|
326 |
"""
|
327 |
Creates an individual plot panel with its plot component and action buttons.
|
328 |
-
|
329 |
Returns the panel (Column), plot component, and button components.
|
330 |
"""
|
331 |
# Values for BOMB_ICON, EXPLORE_ICON, FORMULA_ICON should be sourced from where they are defined,
|
332 |
# e.g., imported from config or passed as arguments if they vary.
|
333 |
-
# For consistency with app.py, let's assume they are globally accessible or correctly imported.
|
334 |
-
# If not, replace "BOMB_ICON", "EXPLORE_ICON", "FORMULA_ICON" with their actual string values like "�".
|
335 |
-
# This function will use string literals for icons if not found in global scope,
|
336 |
-
# but it's better practice to ensure they are consistently defined.
|
337 |
try:
|
338 |
-
|
|
|
|
|
|
|
339 |
except ImportError:
|
340 |
-
logging.warning("Icons BOMB_ICON, EXPLORE_ICON, FORMULA_ICON not found in config, using defaults.")
|
341 |
BOMB_ICON = "💣"
|
342 |
EXPLORE_ICON = "🧭"
|
343 |
FORMULA_ICON = "ƒ"
|
344 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
345 |
|
346 |
-
|
347 |
-
|
348 |
-
plot_component = gr.Plot(label=plot_label_str, scale=8, show_label=True) # Ensure plot label is shown
|
349 |
-
with gr.Column(scale=2, min_width=100):
|
350 |
-
bomb_button = gr.Button(BOMB_ICON, variant="secondary", size="sm", elem_id=f"bomb_{plot_id_str}")
|
351 |
-
explore_button = gr.Button(EXPLORE_ICON, variant="secondary", size="sm", elem_id=f"explore_{plot_id_str}")
|
352 |
-
formula_button = gr.Button(FORMULA_ICON, variant="secondary", size="sm", elem_id=f"formula_{plot_id_str}")
|
353 |
-
logging.debug(f"Created analytics panel for: {plot_label_str} (ID: {plot_id_str}) using original structure.")
|
354 |
-
return panel_col, plot_component, bomb_button, explore_button, formula_button
|
355 |
|
356 |
|
357 |
def build_analytics_tab_plot_area(plot_configs):
|
@@ -363,56 +364,44 @@ def build_analytics_tab_plot_area(plot_configs):
|
|
363 |
- plot_ui_objects (dict): Dictionary of plot UI objects.
|
364 |
- section_titles_map (dict): Dictionary mapping section names to their gr.Markdown title components.
|
365 |
"""
|
366 |
-
logging.info(f"Building plot area for {len(plot_configs)} analytics plots with interleaved section titles.")
|
367 |
plot_ui_objects = {}
|
368 |
section_titles_map = {}
|
369 |
|
370 |
-
last_rendered_section = None
|
371 |
|
372 |
idx = 0
|
373 |
while idx < len(plot_configs):
|
374 |
current_plot_config = plot_configs[idx]
|
375 |
current_section_name = current_plot_config["section"]
|
376 |
|
377 |
-
# If this plot belongs to a new section, display the section title
|
378 |
if current_section_name != last_rendered_section:
|
379 |
if current_section_name not in section_titles_map:
|
380 |
-
# Create the Markdown component for this section title if it doesn't exist
|
381 |
-
# This call to gr.Markdown() places it in the current layout flow.
|
382 |
section_md_component = gr.Markdown(f"### {current_section_name}", visible=True)
|
383 |
section_titles_map[current_section_name] = section_md_component
|
384 |
logging.debug(f"Rendered and stored Markdown for section: {current_section_name}")
|
385 |
else:
|
386 |
-
#
|
387 |
-
#
|
388 |
-
|
389 |
-
|
390 |
-
# previous rendering doesn't automatically carry to this new layout position.
|
391 |
-
# However, since we are iterating and creating if not exists, this branch might be less common
|
392 |
-
# if plot_configs are typically ordered by section.
|
393 |
-
# For safety, ensure it's visible.
|
394 |
-
section_titles_map[current_section_name].visible = True # Ensure it's visible
|
395 |
-
# section_titles_map[current_section_name] # Re-introduce to layout - often implicit
|
396 |
-
logging.debug(f"Re-using Markdown for section: {current_section_name}")
|
397 |
-
|
398 |
last_rendered_section = current_section_name
|
399 |
|
400 |
-
#
|
401 |
-
with gr.Row(equal_height=False):
|
402 |
# --- Process the first plot in the row (config1) ---
|
403 |
config1 = plot_configs[idx]
|
404 |
-
#
|
405 |
if config1["section"] != current_section_name:
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
|
414 |
panel_col1, plot_comp1, bomb_btn1, explore_btn1, formula_btn1 = \
|
415 |
-
create_analytics_plot_panel(config1["label"], config1["id"])
|
416 |
plot_ui_objects[config1["id"]] = {
|
417 |
"plot_component": plot_comp1, "bomb_button": bomb_btn1,
|
418 |
"explore_button": explore_btn1, "formula_button": formula_btn1,
|
@@ -425,10 +414,9 @@ def build_analytics_tab_plot_area(plot_configs):
|
|
425 |
# --- Process the second plot in the row (config2), if applicable ---
|
426 |
if idx < len(plot_configs):
|
427 |
config2 = plot_configs[idx]
|
428 |
-
|
429 |
-
if config2["section"] == current_section_name:
|
430 |
panel_col2, plot_comp2, bomb_btn2, explore_btn2, formula_btn2 = \
|
431 |
-
create_analytics_plot_panel(config2["label"], config2["id"])
|
432 |
plot_ui_objects[config2["id"]] = {
|
433 |
"plot_component": plot_comp2, "bomb_button": bomb_btn2,
|
434 |
"explore_button": explore_btn2, "formula_button": formula_btn2,
|
@@ -437,8 +425,6 @@ def build_analytics_tab_plot_area(plot_configs):
|
|
437 |
}
|
438 |
logging.debug(f"Created UI panel for plot_id: {config2['id']} in same row, section {config2['section']}")
|
439 |
idx += 1
|
440 |
-
# If config2 is in a different section, the outer while loop will handle its title
|
441 |
-
# before creating its panel in a new row.
|
442 |
|
443 |
logging.info(f"Finished building plot area. Total plot objects: {len(plot_ui_objects)}. Section titles created: {len(section_titles_map)}")
|
444 |
if len(plot_ui_objects) != len(plot_configs):
|
|
|
325 |
def create_analytics_plot_panel(plot_label_str, plot_id_str):
|
326 |
"""
|
327 |
Creates an individual plot panel with its plot component and action buttons.
|
328 |
+
Plot title and action buttons are on the same row.
|
329 |
Returns the panel (Column), plot component, and button components.
|
330 |
"""
|
331 |
# Values for BOMB_ICON, EXPLORE_ICON, FORMULA_ICON should be sourced from where they are defined,
|
332 |
# e.g., imported from config or passed as arguments if they vary.
|
|
|
|
|
|
|
|
|
333 |
try:
|
334 |
+
# Assuming these are defined in your config.py and imported in app.py,
|
335 |
+
# they might not be directly available here unless explicitly passed or re-imported.
|
336 |
+
# For robustness, using string literals if not found.
|
337 |
+
from config import BOMB_ICON, EXPLORE_ICON, FORMULA_ICON
|
338 |
except ImportError:
|
339 |
+
logging.warning("Icons BOMB_ICON, EXPLORE_ICON, FORMULA_ICON not found in config for ui_generators, using defaults.")
|
340 |
BOMB_ICON = "💣"
|
341 |
EXPLORE_ICON = "🧭"
|
342 |
FORMULA_ICON = "ƒ"
|
343 |
|
344 |
+
with gr.Column(visible=True) as panel_component: # Main container for this plot
|
345 |
+
with gr.Row(variant="compact", vertical_align="center"): # Ensure vertical alignment for title and buttons
|
346 |
+
gr.Markdown(f"#### {plot_label_str}", scale=3) # Plot title, give it more space
|
347 |
+
with gr.Row(elem_classes="plot-actions", scale=1, min_width=120): # Action buttons container, adjust scale/min_width as needed
|
348 |
+
bomb_button = gr.Button(value=BOMB_ICON, variant="secondary", size="sm", min_width=30, elem_id=f"bomb_btn_{plot_id_str}")
|
349 |
+
formula_button = gr.Button(value=FORMULA_ICON, variant="secondary", size="sm", min_width=30, elem_id=f"formula_btn_{plot_id_str}")
|
350 |
+
explore_button = gr.Button(value=EXPLORE_ICON, variant="secondary", size="sm", min_width=30, elem_id=f"explore_btn_{plot_id_str}")
|
351 |
+
|
352 |
+
plot_component = gr.Plot(label=plot_label_str, show_label=False) # Label is shown in Markdown above
|
353 |
|
354 |
+
logging.debug(f"Created analytics panel (styled) for: {plot_label_str} (ID: {plot_id_str})")
|
355 |
+
return panel_component, plot_component, bomb_button, explore_button, formula_button
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
356 |
|
357 |
|
358 |
def build_analytics_tab_plot_area(plot_configs):
|
|
|
364 |
- plot_ui_objects (dict): Dictionary of plot UI objects.
|
365 |
- section_titles_map (dict): Dictionary mapping section names to their gr.Markdown title components.
|
366 |
"""
|
367 |
+
logging.info(f"Building plot area for {len(plot_configs)} analytics plots with interleaved section titles and styled panels.")
|
368 |
plot_ui_objects = {}
|
369 |
section_titles_map = {}
|
370 |
|
371 |
+
last_rendered_section = None
|
372 |
|
373 |
idx = 0
|
374 |
while idx < len(plot_configs):
|
375 |
current_plot_config = plot_configs[idx]
|
376 |
current_section_name = current_plot_config["section"]
|
377 |
|
|
|
378 |
if current_section_name != last_rendered_section:
|
379 |
if current_section_name not in section_titles_map:
|
|
|
|
|
380 |
section_md_component = gr.Markdown(f"### {current_section_name}", visible=True)
|
381 |
section_titles_map[current_section_name] = section_md_component
|
382 |
logging.debug(f"Rendered and stored Markdown for section: {current_section_name}")
|
383 |
else:
|
384 |
+
# This case handles if a section name appears non-contiguously, ensure its component is made visible.
|
385 |
+
# The component itself is already created.
|
386 |
+
section_titles_map[current_section_name].visible = True
|
387 |
+
logging.debug(f"Ensuring visibility for existing Markdown for section: {current_section_name}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
388 |
last_rendered_section = current_section_name
|
389 |
|
390 |
+
with gr.Row(equal_height=False): # Row for one or two plots
|
|
|
391 |
# --- Process the first plot in the row (config1) ---
|
392 |
config1 = plot_configs[idx]
|
393 |
+
# Safety check, though current_section_name should match config1["section"] here
|
394 |
if config1["section"] != current_section_name:
|
395 |
+
logging.warning(f"Plot {config1['id']} section mismatch. Expected {current_section_name}, got {config1['section']}. Re-evaluating title.")
|
396 |
+
# This indicates a potential issue in plot_configs order or logic, but try to recover title
|
397 |
+
if config1["section"] not in section_titles_map:
|
398 |
+
sec_md = gr.Markdown(f"### {config1['section']}", visible=True)
|
399 |
+
section_titles_map[config1["section"]] = sec_md
|
400 |
+
last_rendered_section = config1["section"]
|
401 |
+
|
402 |
|
403 |
panel_col1, plot_comp1, bomb_btn1, explore_btn1, formula_btn1 = \
|
404 |
+
create_analytics_plot_panel(config1["label"], config1["id"]) # Use the styled panel creator
|
405 |
plot_ui_objects[config1["id"]] = {
|
406 |
"plot_component": plot_comp1, "bomb_button": bomb_btn1,
|
407 |
"explore_button": explore_btn1, "formula_button": formula_btn1,
|
|
|
414 |
# --- Process the second plot in the row (config2), if applicable ---
|
415 |
if idx < len(plot_configs):
|
416 |
config2 = plot_configs[idx]
|
417 |
+
if config2["section"] == current_section_name: # Must be in the same section for the same row
|
|
|
418 |
panel_col2, plot_comp2, bomb_btn2, explore_btn2, formula_btn2 = \
|
419 |
+
create_analytics_plot_panel(config2["label"], config2["id"]) # Use the styled panel creator
|
420 |
plot_ui_objects[config2["id"]] = {
|
421 |
"plot_component": plot_comp2, "bomb_button": bomb_btn2,
|
422 |
"explore_button": explore_btn2, "formula_button": formula_btn2,
|
|
|
425 |
}
|
426 |
logging.debug(f"Created UI panel for plot_id: {config2['id']} in same row, section {config2['section']}")
|
427 |
idx += 1
|
|
|
|
|
428 |
|
429 |
logging.info(f"Finished building plot area. Total plot objects: {len(plot_ui_objects)}. Section titles created: {len(section_titles_map)}")
|
430 |
if len(plot_ui_objects) != len(plot_configs):
|