openhands openhands commited on
Commit
88a8840
·
1 Parent(s): 1f75b60

Fix icon positioning for date-based charts

Browse files

Use data coordinates (xref='x', yref='y') for date axes instead of
domain coordinates. This matches the previous behavior where icons
were positioned using actual x/y values.

- Date charts: use data coordinates with sizex in milliseconds
- Log charts: continue using domain coordinates (0-1 range)

Co-authored-by: openhands <openhands@all-hands.dev>

Files changed (1) hide show
  1. leaderboard_transformer.py +39 -27
leaderboard_transformer.py CHANGED
@@ -458,34 +458,46 @@ def create_scatter_chart(
458
  encoded_logo = base64.b64encode(f.read()).decode('utf-8')
459
  logo_uri = f"data:image/svg+xml;base64,{encoded_logo}"
460
 
461
- # Convert to domain coordinates (0-1 range)
462
- if x_type == "log" and x_val > 0:
463
- log_x = np.log10(x_val)
464
- domain_x = (log_x - x_range_log[0]) / (x_range_log[1] - x_range_log[0])
465
- elif x_type == "date":
466
- total_range = (max_x - min_x).total_seconds() if max_x != min_x else 1
467
- domain_x = ((x_val - min_x).total_seconds() / total_range) if total_range else 0.5
 
 
 
 
 
 
 
468
  else:
469
- domain_x = 0.5
470
-
471
- domain_y = (y_val - y_range[0]) / (y_range[1] - y_range[0]) if (y_range[1] - y_range[0]) > 0 else 0.5
472
-
473
- # Clamp to valid range
474
- domain_x = max(0, min(1, domain_x))
475
- domain_y = max(0, min(1, domain_y))
476
-
477
- layout_images.append(dict(
478
- source=logo_uri,
479
- xref="x domain",
480
- yref="y domain",
481
- x=domain_x,
482
- y=domain_y,
483
- sizex=0.04,
484
- sizey=0.06,
485
- xanchor="center",
486
- yanchor="middle",
487
- layer="above"
488
- ))
 
 
 
 
 
489
  except Exception:
490
  pass
491
 
 
458
  encoded_logo = base64.b64encode(f.read()).decode('utf-8')
459
  logo_uri = f"data:image/svg+xml;base64,{encoded_logo}"
460
 
461
+ if x_type == "date":
462
+ # For date axes, use data coordinates directly
463
+ layout_images.append(dict(
464
+ source=logo_uri,
465
+ xref="x",
466
+ yref="y",
467
+ x=x_val,
468
+ y=y_val,
469
+ sizex=15 * 24 * 60 * 60 * 1000, # ~15 days in milliseconds
470
+ sizey=3, # score units
471
+ xanchor="center",
472
+ yanchor="middle",
473
+ layer="above"
474
+ ))
475
  else:
476
+ # For log axes, use domain coordinates (0-1 range)
477
+ if x_type == "log" and x_val > 0:
478
+ log_x = np.log10(x_val)
479
+ domain_x = (log_x - x_range_log[0]) / (x_range_log[1] - x_range_log[0])
480
+ else:
481
+ domain_x = 0.5
482
+
483
+ domain_y = (y_val - y_range[0]) / (y_range[1] - y_range[0]) if (y_range[1] - y_range[0]) > 0 else 0.5
484
+
485
+ # Clamp to valid range
486
+ domain_x = max(0, min(1, domain_x))
487
+ domain_y = max(0, min(1, domain_y))
488
+
489
+ layout_images.append(dict(
490
+ source=logo_uri,
491
+ xref="x domain",
492
+ yref="y domain",
493
+ x=domain_x,
494
+ y=domain_y,
495
+ sizex=0.04,
496
+ sizey=0.06,
497
+ xanchor="center",
498
+ yanchor="middle",
499
+ layer="above"
500
+ ))
501
  except Exception:
502
  pass
503