duongthienz commited on
Commit
4948296
·
verified ·
1 Parent(s): 5468940

Update utils.py

Browse files
Files changed (1) hide show
  1. utils.py +13 -17
utils.py CHANGED
@@ -538,30 +538,26 @@ def build_fig_timeline(speakers_dataFrame, currTotalTime, speaker_color_map, get
538
  )
539
  fig.update_yaxes(autorange="reversed")
540
 
541
- # Add vertical shading for multi-voice intervals.
542
- # add_vrect doesn't support hover, so we also add an invisible scatter
543
- # trace on top of each band to carry the tooltip.
544
  MV_COLOR = "#64A377"
 
 
 
545
  for start_s, end_s in (mv_intervals or []):
546
  x0_dt = base + dt.timedelta(seconds=start_s)
547
  x1_dt = base + dt.timedelta(seconds=end_s)
548
- fig.add_vrect(
549
- x0=x0_dt, x1=x1_dt,
550
- fillcolor=MV_COLOR,
551
- opacity=0.30,
552
- layer="below",
553
- line_width=0,
554
- )
555
- # Invisible scatter at midpoint to carry hover tooltip
556
- mid_dt = base + dt.timedelta(seconds=(start_s + end_s) / 2)
557
  fig.add_trace(go.Scatter(
558
- x=[mid_dt],
559
- y=[None],
560
- mode="markers",
561
- marker=dict(size=0, opacity=0),
 
 
562
  showlegend=False,
 
563
  hovertemplate=(
564
- f"<b>Resource: Multi Voice</b><br>"
565
  f"Start: {_seconds_to_hhmmss(start_s)}<br>"
566
  f"Finish: {_seconds_to_hhmmss(end_s)}"
567
  "<extra></extra>"
 
538
  )
539
  fig.update_yaxes(autorange="reversed")
540
 
541
+ # Add vertical shading for multi-voice intervals as filled scatter shapes.
542
+ # go.Scatter with fill="toself" supports hover; add_vrect does not.
 
543
  MV_COLOR = "#64A377"
544
+ # We need the y-axis range — use a large span that covers all speaker rows
545
+ y_speakers = df["Resource"].unique().tolist()
546
+ y_min, y_max = -0.5, len(y_speakers) - 0.5
547
  for start_s, end_s in (mv_intervals or []):
548
  x0_dt = base + dt.timedelta(seconds=start_s)
549
  x1_dt = base + dt.timedelta(seconds=end_s)
 
 
 
 
 
 
 
 
 
550
  fig.add_trace(go.Scatter(
551
+ x=[x0_dt, x1_dt, x1_dt, x0_dt, x0_dt],
552
+ y=[y_min, y_min, y_max, y_max, y_min],
553
+ fill="toself",
554
+ fillcolor=f"rgba(100,163,119,0.25)",
555
+ line=dict(width=0),
556
+ mode="lines",
557
  showlegend=False,
558
+ yaxis="y",
559
  hovertemplate=(
560
+ f"<b>Multi Voice</b><br>"
561
  f"Start: {_seconds_to_hhmmss(start_s)}<br>"
562
  f"Finish: {_seconds_to_hhmmss(end_s)}"
563
  "<extra></extra>"