Spaces:
Running
Running
gauravlochab
commited on
Commit
·
5ee9210
1
Parent(s):
abbde7d
feat: enhance graph responsiveness and add annotations for clarity
Browse files
app.py
CHANGED
@@ -806,14 +806,15 @@ def create_combined_time_series_graph(df):
|
|
806 |
logger.info("Cumulative APR graph line has been removed as requested")
|
807 |
|
808 |
# Update layout - use simple boolean values everywhere
|
809 |
-
#
|
810 |
fig.update_layout(
|
811 |
title="Babydegen agents",
|
812 |
-
xaxis_title=
|
813 |
-
yaxis_title=
|
814 |
template="plotly_white",
|
815 |
-
height=
|
816 |
-
|
|
|
817 |
legend=dict(
|
818 |
orientation="h",
|
819 |
yanchor="bottom",
|
@@ -822,10 +823,47 @@ def create_combined_time_series_graph(df):
|
|
822 |
x=1,
|
823 |
groupclick="toggleitem"
|
824 |
),
|
825 |
-
margin=dict(r=
|
826 |
hovermode="closest"
|
827 |
)
|
828 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
829 |
# Update y-axis with fixed range of -50 to +100 for psychological effect
|
830 |
fig.update_yaxes(
|
831 |
showgrid=True,
|
@@ -835,7 +873,8 @@ def create_combined_time_series_graph(df):
|
|
835 |
autorange=False, # Disable autoscaling
|
836 |
range=[-50, 100], # Set fixed range from -50 to +100
|
837 |
tickformat=".2f", # Format tick labels with 2 decimal places
|
838 |
-
tickfont=dict(size=
|
|
|
839 |
)
|
840 |
|
841 |
# Update x-axis with better formatting and autoscaling
|
@@ -845,9 +884,10 @@ def create_combined_time_series_graph(df):
|
|
845 |
gridcolor='rgba(0,0,0,0.1)',
|
846 |
# No fixed range - let Plotly autoscale
|
847 |
autorange=True, # Explicitly enable autoscaling
|
848 |
-
tickformat="%b %d
|
849 |
tickangle=-30, # Angle the labels for better readability
|
850 |
-
tickfont=dict(size=
|
|
|
851 |
)
|
852 |
|
853 |
# SIMPLIFIED APPROACH: Do a direct plot without markers for comparison
|
@@ -991,25 +1031,65 @@ def create_combined_time_series_graph(df):
|
|
991 |
# Simplified layout with adjusted y-axis range and increased size
|
992 |
simple_fig.update_layout(
|
993 |
title="Babydegen agents",
|
994 |
-
xaxis_title=
|
995 |
-
yaxis_title=
|
996 |
yaxis=dict(
|
997 |
# No fixed range - let Plotly autoscale
|
998 |
autorange=True, # Explicitly enable autoscaling
|
999 |
tickformat=".2f", # Format tick labels with 2 decimal places
|
1000 |
tickfont=dict(size=12) # Larger font for tick labels
|
1001 |
),
|
1002 |
-
height=
|
1003 |
-
|
1004 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1005 |
)
|
1006 |
|
1007 |
# Apply autoscaling to the x-axis for the fallback graph
|
1008 |
simple_fig.update_xaxes(
|
1009 |
autorange=True, # Explicitly enable autoscaling
|
1010 |
-
tickformat="%b %d,
|
1011 |
tickangle=-30,
|
1012 |
-
tickfont=dict(size=12)
|
|
|
1013 |
)
|
1014 |
|
1015 |
# Add a note about hidden agents if there are more than MAX_VISIBLE_AGENTS
|
@@ -1462,7 +1542,7 @@ def create_visualizations():
|
|
1462 |
|
1463 |
return fig_swaps_chain, fig_bridges_chain, fig_agents_registered, fig_tvl
|
1464 |
|
1465 |
-
# Modify dashboard function to
|
1466 |
def dashboard():
|
1467 |
with gr.Blocks() as demo:
|
1468 |
gr.Markdown("# Average Modius Agent Performance")
|
@@ -1472,8 +1552,9 @@ def dashboard():
|
|
1472 |
with gr.Column():
|
1473 |
refresh_btn = gr.Button("Refresh APR Data")
|
1474 |
|
1475 |
-
# Create container for plotly figure
|
1476 |
-
|
|
|
1477 |
|
1478 |
# Create compact toggle controls at the bottom of the graph
|
1479 |
with gr.Row(visible=True):
|
@@ -1488,10 +1569,21 @@ def dashboard():
|
|
1488 |
with gr.Column(scale=1, min_width=150):
|
1489 |
adjusted_apr_toggle = gr.Checkbox(label="Adjusted APR Moving Average", value=True, elem_id="adjusted_apr_toggle")
|
1490 |
|
1491 |
-
# Add custom CSS for
|
1492 |
gr.HTML("""
|
1493 |
<style>
|
1494 |
-
/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1495 |
#apr_toggle .gr-checkbox {
|
1496 |
accent-color: #e74c3c !important;
|
1497 |
}
|
|
|
806 |
logger.info("Cumulative APR graph line has been removed as requested")
|
807 |
|
808 |
# Update layout - use simple boolean values everywhere
|
809 |
+
# Make chart responsive instead of fixed width
|
810 |
fig.update_layout(
|
811 |
title="Babydegen agents",
|
812 |
+
xaxis_title=None, # Remove x-axis title to use annotation instead
|
813 |
+
yaxis_title=None, # Remove the y-axis title as we'll use annotations instead
|
814 |
template="plotly_white",
|
815 |
+
height=600, # Reduced height for better fit on smaller screens
|
816 |
+
# Removed fixed width to enable responsiveness
|
817 |
+
autosize=True, # Enable auto-sizing for responsiveness
|
818 |
legend=dict(
|
819 |
orientation="h",
|
820 |
yanchor="bottom",
|
|
|
823 |
x=1,
|
824 |
groupclick="toggleitem"
|
825 |
),
|
826 |
+
margin=dict(r=30, l=120, t=40, b=50), # Increased bottom margin for x-axis title
|
827 |
hovermode="closest"
|
828 |
)
|
829 |
|
830 |
+
# Add annotations for y-axis regions
|
831 |
+
fig.add_annotation(
|
832 |
+
x=-0.08, # Position further from the y-axis to avoid overlapping with tick labels
|
833 |
+
y=-25, # Middle of the negative region
|
834 |
+
xref="paper",
|
835 |
+
yref="y",
|
836 |
+
text="Percent drawdown",
|
837 |
+
showarrow=False,
|
838 |
+
font=dict(size=14, family="Arial, sans-serif", color="black", weight="bold"), # Smaller font size
|
839 |
+
textangle=-90, # Rotate text to be vertical
|
840 |
+
align="center"
|
841 |
+
)
|
842 |
+
|
843 |
+
fig.add_annotation(
|
844 |
+
x=-0.08, # Position further from the y-axis to avoid overlapping with tick labels
|
845 |
+
y=50, # Middle of the positive region
|
846 |
+
xref="paper",
|
847 |
+
yref="y",
|
848 |
+
text="Agent APR",
|
849 |
+
showarrow=False,
|
850 |
+
font=dict(size=14, family="Arial, sans-serif", color="black", weight="bold"), # Smaller font size
|
851 |
+
textangle=-90, # Rotate text to be vertical
|
852 |
+
align="center"
|
853 |
+
)
|
854 |
+
|
855 |
+
# Add x-axis title as annotation to match y-axis annotation style
|
856 |
+
fig.add_annotation(
|
857 |
+
x=0.5, # Center of the x-axis
|
858 |
+
y=-0.15, # Below the x-axis
|
859 |
+
xref="paper",
|
860 |
+
yref="paper",
|
861 |
+
text="Date",
|
862 |
+
showarrow=False,
|
863 |
+
font=dict(size=14, family="Arial, sans-serif", color="black", weight="bold"), # Match y-axis font
|
864 |
+
align="center"
|
865 |
+
)
|
866 |
+
|
867 |
# Update y-axis with fixed range of -50 to +100 for psychological effect
|
868 |
fig.update_yaxes(
|
869 |
showgrid=True,
|
|
|
873 |
autorange=False, # Disable autoscaling
|
874 |
range=[-50, 100], # Set fixed range from -50 to +100
|
875 |
tickformat=".2f", # Format tick labels with 2 decimal places
|
876 |
+
tickfont=dict(size=12, family="Arial, sans-serif", color="black", weight="bold"), # Smaller font for tick labels
|
877 |
+
title=None # Remove the built-in axis title since we're using annotations
|
878 |
)
|
879 |
|
880 |
# Update x-axis with better formatting and autoscaling
|
|
|
884 |
gridcolor='rgba(0,0,0,0.1)',
|
885 |
# No fixed range - let Plotly autoscale
|
886 |
autorange=True, # Explicitly enable autoscaling
|
887 |
+
tickformat="%b %d", # Simplified date format without time
|
888 |
tickangle=-30, # Angle the labels for better readability
|
889 |
+
tickfont=dict(size=12, family="Arial, sans-serif", color="black", weight="bold"), # Smaller font for tick labels
|
890 |
+
title=None # Remove built-in title to use annotation instead
|
891 |
)
|
892 |
|
893 |
# SIMPLIFIED APPROACH: Do a direct plot without markers for comparison
|
|
|
1031 |
# Simplified layout with adjusted y-axis range and increased size
|
1032 |
simple_fig.update_layout(
|
1033 |
title="Babydegen agents",
|
1034 |
+
xaxis_title=None, # Remove x-axis title to use annotation instead
|
1035 |
+
yaxis_title=None, # Remove the y-axis title as we'll use annotations instead
|
1036 |
yaxis=dict(
|
1037 |
# No fixed range - let Plotly autoscale
|
1038 |
autorange=True, # Explicitly enable autoscaling
|
1039 |
tickformat=".2f", # Format tick labels with 2 decimal places
|
1040 |
tickfont=dict(size=12) # Larger font for tick labels
|
1041 |
),
|
1042 |
+
height=600, # Reduced height for better fit
|
1043 |
+
# Removed fixed width to enable responsiveness
|
1044 |
+
autosize=True, # Enable auto-sizing for responsiveness
|
1045 |
+
template="plotly_white", # Use a cleaner template
|
1046 |
+
margin=dict(r=30, l=120, t=40, b=50) # Increased bottom margin for x-axis title
|
1047 |
+
)
|
1048 |
+
|
1049 |
+
# Add annotations for y-axis regions in the fallback graph
|
1050 |
+
simple_fig.add_annotation(
|
1051 |
+
x=-0.08, # Position further from the y-axis to avoid overlapping with tick labels
|
1052 |
+
y=-25, # Middle of the negative region
|
1053 |
+
xref="paper",
|
1054 |
+
yref="y",
|
1055 |
+
text="Percent drawdown",
|
1056 |
+
showarrow=False,
|
1057 |
+
font=dict(size=12, family="Arial, sans-serif", color="black"), # Even smaller font for fallback
|
1058 |
+
textangle=-90, # Rotate text to be vertical
|
1059 |
+
align="center"
|
1060 |
+
)
|
1061 |
+
|
1062 |
+
simple_fig.add_annotation(
|
1063 |
+
x=-0.08, # Position further from the y-axis to avoid overlapping with tick labels
|
1064 |
+
y=50, # Middle of the positive region
|
1065 |
+
xref="paper",
|
1066 |
+
yref="y",
|
1067 |
+
text="Agent APR",
|
1068 |
+
showarrow=False,
|
1069 |
+
font=dict(size=12, family="Arial, sans-serif", color="black"), # Even smaller font for fallback
|
1070 |
+
textangle=-90, # Rotate text to be vertical
|
1071 |
+
align="center"
|
1072 |
+
)
|
1073 |
+
|
1074 |
+
# Add x-axis title as annotation to match y-axis annotation style
|
1075 |
+
simple_fig.add_annotation(
|
1076 |
+
x=0.5, # Center of the x-axis
|
1077 |
+
y=-0.15, # Below the x-axis
|
1078 |
+
xref="paper",
|
1079 |
+
yref="paper",
|
1080 |
+
text="Date",
|
1081 |
+
showarrow=False,
|
1082 |
+
font=dict(size=12, family="Arial, sans-serif", color="black"), # Match y-axis font
|
1083 |
+
align="center"
|
1084 |
)
|
1085 |
|
1086 |
# Apply autoscaling to the x-axis for the fallback graph
|
1087 |
simple_fig.update_xaxes(
|
1088 |
autorange=True, # Explicitly enable autoscaling
|
1089 |
+
tickformat="%b %d", # Simplified date format without time
|
1090 |
tickangle=-30,
|
1091 |
+
tickfont=dict(size=12),
|
1092 |
+
title=None # Remove built-in title to use annotation instead
|
1093 |
)
|
1094 |
|
1095 |
# Add a note about hidden agents if there are more than MAX_VISIBLE_AGENTS
|
|
|
1542 |
|
1543 |
return fig_swaps_chain, fig_bridges_chain, fig_agents_registered, fig_tvl
|
1544 |
|
1545 |
+
# Modify dashboard function to make the plot container responsive
|
1546 |
def dashboard():
|
1547 |
with gr.Blocks() as demo:
|
1548 |
gr.Markdown("# Average Modius Agent Performance")
|
|
|
1552 |
with gr.Column():
|
1553 |
refresh_btn = gr.Button("Refresh APR Data")
|
1554 |
|
1555 |
+
# Create container for plotly figure with responsive sizing
|
1556 |
+
with gr.Column():
|
1557 |
+
combined_graph = gr.Plot(label="APR for All Agents", elem_id="responsive_plot")
|
1558 |
|
1559 |
# Create compact toggle controls at the bottom of the graph
|
1560 |
with gr.Row(visible=True):
|
|
|
1569 |
with gr.Column(scale=1, min_width=150):
|
1570 |
adjusted_apr_toggle = gr.Checkbox(label="Adjusted APR Moving Average", value=True, elem_id="adjusted_apr_toggle")
|
1571 |
|
1572 |
+
# Add custom CSS for making the plot responsive
|
1573 |
gr.HTML("""
|
1574 |
<style>
|
1575 |
+
/* Make plot responsive */
|
1576 |
+
#responsive_plot {
|
1577 |
+
width: 100% !important;
|
1578 |
+
max-width: 100% !important;
|
1579 |
+
}
|
1580 |
+
#responsive_plot > div {
|
1581 |
+
width: 100% !important;
|
1582 |
+
height: auto !important;
|
1583 |
+
min-height: 500px !important;
|
1584 |
+
}
|
1585 |
+
|
1586 |
+
/* Existing toggle checkbox styling */
|
1587 |
#apr_toggle .gr-checkbox {
|
1588 |
accent-color: #e74c3c !important;
|
1589 |
}
|