BoxOfColors commited on
Commit
3c63946
·
1 Parent(s): da46dda

Fix pending regen waveform segment boundary misalignment

Browse files

_build_regen_pending_html was using segments[i+1][0] as each segment's
right edge, while _build_waveform_html uses the contact-edge midpoint
(segments[i][1] + segments[i+1][0]) / 2. Align both to the same formula
so segment boundaries don't shift when the pending placeholder is shown.

Files changed (1) hide show
  1. app.py +11 -8
app.py CHANGED
@@ -1995,16 +1995,19 @@ def _build_regen_pending_html(segments: list, regen_seg_idx: int, slot_id: str,
1995
  active_color = "rgba(255,180,0,0.55)"
1996
  duration = segments[-1][1] if segments else 1.0
1997
 
 
 
 
 
 
 
 
1998
  seg_divs = ""
1999
  for i, seg in enumerate(segments):
2000
- # Draw only the non-overlapping (unique) portion of each segment so that
2001
- # overlapping windows don't visually bleed into adjacent segments.
2002
- # Each segment owns the region from its own start up to the next segment's
2003
- # start (or its own end for the final segment).
2004
- seg_start = seg[0]
2005
- seg_end = segments[i + 1][0] if i + 1 < len(segments) else seg[1]
2006
- left_pct = seg_start / duration * 100
2007
- width_pct = (seg_end - seg_start) / duration * 100
2008
  color = active_color if i == regen_seg_idx else seg_colors[i % len(seg_colors)]
2009
  extra = "border:2px solid #ffb300;animation:wf_pulse 0.8s ease-in-out infinite alternate;" if i == regen_seg_idx else ""
2010
  seg_divs += (
 
1995
  active_color = "rgba(255,180,0,0.55)"
1996
  duration = segments[-1][1] if segments else 1.0
1997
 
1998
+ # Compute contact edges: midpoint of overlap between consecutive segments.
1999
+ # Matches the contact-edge formula used in _build_waveform_html's canvas JS
2000
+ # so segment boundaries stay visually identical during pending regen.
2001
+ contact_edges = []
2002
+ for i in range(len(segments) - 1):
2003
+ contact_edges.append((segments[i][1] + segments[i + 1][0]) / 2)
2004
+
2005
  seg_divs = ""
2006
  for i, seg in enumerate(segments):
2007
+ left_t = 0.0 if i == 0 else contact_edges[i - 1]
2008
+ right_t = duration if i == len(segments) - 1 else contact_edges[i]
2009
+ left_pct = left_t / duration * 100
2010
+ width_pct = (right_t - left_t) / duration * 100
 
 
 
 
2011
  color = active_color if i == regen_seg_idx else seg_colors[i % len(seg_colors)]
2012
  extra = "border:2px solid #ffb300;animation:wf_pulse 0.8s ease-in-out infinite alternate;" if i == regen_seg_idx else ""
2013
  seg_divs += (