Spaces:
Running
Running
openhands openhands commited on
Commit ·
f1798d2
1
Parent(s): d731ad4
Fix font consistency and remove code duplication in visualizations.py
Browse files- Remove duplicated branding code (OPENHANDS_LOGO_PATH, URL_ANNOTATION,
get_openhands_logo_images, add_branding_to_figure) - now imported from
leaderboard_transformer.py
- Fix STANDARD_FONT to use FONT_FAMILY_SHORT constant instead of hardcoded 'Outfit'
- All charts now consistently use Arial font from constants.py
Co-authored-by: openhands <openhands@all-hands.dev>
- visualizations.py +8 -92
visualizations.py
CHANGED
|
@@ -10,8 +10,12 @@ import base64
|
|
| 10 |
import aliases
|
| 11 |
from constants import FONT_FAMILY, FONT_FAMILY_SHORT
|
| 12 |
|
| 13 |
-
# Import
|
| 14 |
-
from leaderboard_transformer import
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
from ui_components import get_svg_as_data_uri
|
| 16 |
from constants import MARK_BY_DEFAULT
|
| 17 |
|
|
@@ -36,101 +40,13 @@ STANDARD_LAYOUT = dict(
|
|
| 36 |
margin=dict(b=80), # Extra margin for logo and URL
|
| 37 |
)
|
| 38 |
|
| 39 |
-
# Standard font for annotations
|
| 40 |
STANDARD_FONT = dict(
|
| 41 |
size=10,
|
| 42 |
color='#0D0D0F', # neutral-950
|
| 43 |
-
family=
|
| 44 |
)
|
| 45 |
|
| 46 |
-
# OpenHands branding constants
|
| 47 |
-
OPENHANDS_LOGO_PATH_LIGHT = "assets/openhands_logo_color_forwhite.png"
|
| 48 |
-
OPENHANDS_LOGO_PATH_DARK = "assets/openhands_logo_color_forblack.png"
|
| 49 |
-
OPENHANDS_URL = "https://index.openhands.dev"
|
| 50 |
-
|
| 51 |
-
# URL annotation for bottom right of charts
|
| 52 |
-
URL_ANNOTATION = dict(
|
| 53 |
-
text=OPENHANDS_URL,
|
| 54 |
-
xref="paper",
|
| 55 |
-
yref="paper",
|
| 56 |
-
x=1,
|
| 57 |
-
y=-0.15,
|
| 58 |
-
xanchor="right",
|
| 59 |
-
yanchor="bottom",
|
| 60 |
-
showarrow=False,
|
| 61 |
-
font=dict(
|
| 62 |
-
family="Outfit, ui-sans-serif, sans-serif",
|
| 63 |
-
size=14,
|
| 64 |
-
color="#82889B", # neutral-400
|
| 65 |
-
),
|
| 66 |
-
)
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
def get_openhands_logo_images():
|
| 70 |
-
"""Get both light and dark mode OpenHands logos as Plotly image dicts.
|
| 71 |
-
|
| 72 |
-
Returns two images - one for light mode (forwhite) and one for dark mode (forblack).
|
| 73 |
-
CSS is used to show/hide the appropriate logo based on the current mode.
|
| 74 |
-
"""
|
| 75 |
-
images = []
|
| 76 |
-
|
| 77 |
-
# Light mode logo (visible in light mode, hidden in dark mode)
|
| 78 |
-
if os.path.exists(OPENHANDS_LOGO_PATH_LIGHT):
|
| 79 |
-
try:
|
| 80 |
-
with open(OPENHANDS_LOGO_PATH_LIGHT, "rb") as f:
|
| 81 |
-
logo_data = base64.b64encode(f.read()).decode('utf-8')
|
| 82 |
-
images.append(dict(
|
| 83 |
-
source=f"data:image/png;openhands=lightlogo;base64,{logo_data}",
|
| 84 |
-
xref="paper",
|
| 85 |
-
yref="paper",
|
| 86 |
-
x=0,
|
| 87 |
-
y=-0.15,
|
| 88 |
-
sizex=0.15,
|
| 89 |
-
sizey=0.15,
|
| 90 |
-
xanchor="left",
|
| 91 |
-
yanchor="bottom",
|
| 92 |
-
))
|
| 93 |
-
except Exception:
|
| 94 |
-
pass
|
| 95 |
-
|
| 96 |
-
# Dark mode logo (hidden in light mode, visible in dark mode)
|
| 97 |
-
if os.path.exists(OPENHANDS_LOGO_PATH_DARK):
|
| 98 |
-
try:
|
| 99 |
-
with open(OPENHANDS_LOGO_PATH_DARK, "rb") as f:
|
| 100 |
-
logo_data = base64.b64encode(f.read()).decode('utf-8')
|
| 101 |
-
images.append(dict(
|
| 102 |
-
source=f"data:image/png;openhands=darklogo;base64,{logo_data}",
|
| 103 |
-
xref="paper",
|
| 104 |
-
yref="paper",
|
| 105 |
-
x=0,
|
| 106 |
-
y=-0.15,
|
| 107 |
-
sizex=0.15,
|
| 108 |
-
sizey=0.15,
|
| 109 |
-
xanchor="left",
|
| 110 |
-
yanchor="bottom",
|
| 111 |
-
))
|
| 112 |
-
except Exception:
|
| 113 |
-
pass
|
| 114 |
-
|
| 115 |
-
return images
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
def add_branding_to_figure(fig: go.Figure) -> go.Figure:
|
| 119 |
-
"""Add OpenHands logo and URL to a Plotly figure."""
|
| 120 |
-
# Add both light and dark mode logo images
|
| 121 |
-
logo_images = get_openhands_logo_images()
|
| 122 |
-
if logo_images:
|
| 123 |
-
existing_images = list(fig.layout.images) if fig.layout.images else []
|
| 124 |
-
existing_images.extend(logo_images)
|
| 125 |
-
fig.update_layout(images=existing_images)
|
| 126 |
-
|
| 127 |
-
# Add URL annotation
|
| 128 |
-
existing_annotations = list(fig.layout.annotations) if fig.layout.annotations else []
|
| 129 |
-
existing_annotations.append(URL_ANNOTATION)
|
| 130 |
-
fig.update_layout(annotations=existing_annotations)
|
| 131 |
-
|
| 132 |
-
return fig
|
| 133 |
-
|
| 134 |
|
| 135 |
def create_evolution_over_time_chart(df: pd.DataFrame, mark_by: str = None) -> go.Figure:
|
| 136 |
"""
|
|
|
|
| 10 |
import aliases
|
| 11 |
from constants import FONT_FAMILY, FONT_FAMILY_SHORT
|
| 12 |
|
| 13 |
+
# Import shared utilities from leaderboard_transformer
|
| 14 |
+
from leaderboard_transformer import (
|
| 15 |
+
get_company_from_model,
|
| 16 |
+
get_marker_icon,
|
| 17 |
+
add_branding_to_figure,
|
| 18 |
+
)
|
| 19 |
from ui_components import get_svg_as_data_uri
|
| 20 |
from constants import MARK_BY_DEFAULT
|
| 21 |
|
|
|
|
| 40 |
margin=dict(b=80), # Extra margin for logo and URL
|
| 41 |
)
|
| 42 |
|
| 43 |
+
# Standard font for annotations - uses constants for consistency
|
| 44 |
STANDARD_FONT = dict(
|
| 45 |
size=10,
|
| 46 |
color='#0D0D0F', # neutral-950
|
| 47 |
+
family=FONT_FAMILY_SHORT
|
| 48 |
)
|
| 49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
def create_evolution_over_time_chart(df: pd.DataFrame, mark_by: str = None) -> go.Figure:
|
| 52 |
"""
|