code-dot-org icon indicating copy to clipboard operation
code-dot-org copied to clipboard

Music: timeline fix

Open breville opened this issue 1 month ago • 2 comments

This makes a small adjustment to avoid the vertical overflow of timeline elements.

before

Screenshot 2025-12-02 at 9 57 50 PM

after

Screenshot 2025-12-02 at 9 56 44 PM

breville avatar Dec 03 '25 01:12 breville

LGTM! Is it worth a brief code comment explaining the magic number 2?

@hannahbergam I'm glad you asked, because I didn't have a great answer beyond it working for this fairly obvious case.

We work out the event height here, and part of that height is a gap at the bottom, calculated here. It turns out that with recent layout changes, our bar height is 132px but we actually get 127px to render these events.

I wrote a little code to output each row count, and its respective remaining vertical space, with negative space implying an overflow. I then adjusted the bar height down until we didn't get any overflow.

for (var rowCount = 5; rowCount <= 45; rowCount++) { 
  let eventHeight = Math.floor(128 / rowCount); 
  let gap = eventHeight > 8 ? 3 : eventHeight > 6 ? 2 : 1; 
  console.log(rowCount + ':', 127 - (eventHeight * rowCount - gap))  
}

It turns out that compensating by 4 pixels (i.e. assuming the bar height is 128px) was the magic number, so I've updated that.

breville avatar Dec 03 '25 06:12 breville

LGTM! Is it worth a brief code comment explaining the magic number 2?

@hannahbergam I'm glad you asked, because I didn't have a great answer beyond it working for this fairly obvious case.

We work out the event height here, and part of that height is a gap at the bottom, calculated here. It turns out that with recent layout changes, our bar height is 132px but we actually get 127px to render these events.

I wrote a little code to output each row count, and its respective remaining vertical space, with negative space implying an overflow. I then adjusted the bar height down until we didn't get any overflow.


for (var rowCount = 5; rowCount <= 45; rowCount++) { 

  let eventHeight = Math.floor(128 / rowCount); 

  let gap = eventHeight > 8 ? 3 : eventHeight > 6 ? 2 : 1; 

  console.log(rowCount + ':', 127 - (eventHeight * rowCount - gap))  

}

It turns out that compensating by 4 pixels (i.e. assuming the bar height is 128px) was the magic number, so I've updated that.

Oh wild- thank you for the explanation and the update! Looks good.

hannahbergam avatar Dec 03 '25 18:12 hannahbergam