diff --git a/ui/src/common/high_precision_time_span.ts b/ui/src/common/high_precision_time_span.ts index b45ca21e87..02dcad136d 100644 --- a/ui/src/common/high_precision_time_span.ts +++ b/ui/src/common/high_precision_time_span.ts @@ -167,6 +167,18 @@ export class HighPrecisionTimeSpan { return this; } + /** + * Clamp duration to some minimum value. The start remains the same, just the + * duration is changed. + */ + clampDuration(minDuration: number): HighPrecisionTimeSpan { + if (this.duration < minDuration) { + return new HighPrecisionTimeSpan(this.start, minDuration); + } else { + return this; + } + } + /** * Checks whether this span completely contains a time instant. */ diff --git a/ui/src/common/high_precision_time_span_unittest.ts b/ui/src/common/high_precision_time_span_unittest.ts index 3e8e59d3b8..08b7b79ce6 100644 --- a/ui/src/common/high_precision_time_span_unittest.ts +++ b/ui/src/common/high_precision_time_span_unittest.ts @@ -122,6 +122,15 @@ describe('HighPrecisionTimeSpan', () => { expect(result.duration).toBeCloseTo(1); }); + test('clampDuration', () => { + const span = new HPTimeSpan(hptime('5'), 1); + const clamped = span.clampDuration(10); + + expect(clamped.start.integral).toBe(5n); + expect(clamped.start.fractional).toBeCloseTo(0); + expect(clamped.duration).toBeCloseTo(10); + }); + test('equality', () => { const span = new HPTimeSpan(hptime('10'), 10); expect(span.equals(span)).toBe(true); diff --git a/ui/src/frontend/timeline.ts b/ui/src/frontend/timeline.ts index 0f29b76c7a..bdd244ebbc 100644 --- a/ui/src/frontend/timeline.ts +++ b/ui/src/frontend/timeline.ts @@ -18,7 +18,6 @@ import {HighPrecisionTimeSpan} from '../common/high_precision_time_span'; import {Area, State} from '../common/state'; import {raf} from '../core/raf_scheduler'; import {Store} from '../public'; - import {ratelimit} from './rate_limiters'; interface Range { @@ -110,10 +109,10 @@ export class Timeline { // Set visible window using a high precision time span updateVisibleTimeHP(ts: HighPrecisionTimeSpan) { - this._visibleWindow = ts.intersect( - this.traceSpan.start, - this.traceSpan.end, - ); + this._visibleWindow = ts + .clampDuration(MIN_DURATION) + .fitWithin(this.traceSpan.start, this.traceSpan.end); + this.rateLimitedPoker(); }