wavesjs / waves-ui

A library to display and edit audio data and timeseries data in the browser.
http://wavesjs.github.io/waves-ui/
BSD 3-Clause "New" or "Revised" License
122 stars 16 forks source link

CenteredZoomState - Prevent timeline.offset on right side? #37

Open justinlevi opened 7 years ago

justinlevi commented 7 years ago

I have created a CustomCenteredZoomState class which extends ui.states.CenteredZoomState. I see the example to prevent the timeline.offset from going negative, but I'm struggling with how to limit the user from scrolling the waveform infinitely in the positive direction.

I see Example 2, but I'm not sure the best way to get the view.width in this class? I would like to limit dragging to the maximum of the audio track if that makes sense. I'll keep working at it, just wondering if this is something that has already been solved...

    // Example 1: Prevent timeline.offset to be negative
    timeContext.offset = Math.min(timeContext.offset, 0);
    //
    // Example 2: Keep in container when zoomed out
    // if (timeContext.stretchRatio < 1) {
    //   const minOffset = timeContext.timeToPixel.invert(0);
    //   const maxOffset = timeContext.timeToPixel.invert(view.width - timeContext.timeToPixel(timeContext.duration));
    //   timeContext.offset = Math.max(timeContext.offset, minOffset);
    //   timeContext.offset = Math.min(timeContext.offset, maxOffset);
    // }