Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
d211bce
Add TemporalSpan model
horatiualmasan Jul 7, 2026
0c66a38
update
horatiualmasan Jul 7, 2026
3e04899
fix
horatiualmasan Jul 7, 2026
bd48016
try eager load
horatiualmasan Jul 7, 2026
f668678
fix warning
horatiualmasan Jul 7, 2026
f3956d1
Add video annotation from activitynet
horatiualmasan Jul 8, 2026
07ddf00
remove not needed joins
horatiualmasan Jul 8, 2026
37441f5
Merge branch 'horatiu-lig-9805-import-activitynet-style-event-annotat…
horatiualmasan Jul 8, 2026
ebe86db
simplify
horatiualmasan Jul 8, 2026
84a4063
Merge branch 'main' into horatiu-lig-9805-import-activitynet-style-ev…
horatiualmasan Jul 15, 2026
47ec651
fix merge
horatiualmasan Jul 15, 2026
9f97a84
add example sctipt
horatiualmasan Jul 15, 2026
d95200c
format
horatiualmasan Jul 15, 2026
6a243bd
update
horatiualmasan Jul 15, 2026
1a24532
Merge branch 'main' into horatiu-lig-9805-import-activitynet-style-ev…
horatiualmasan Jul 15, 2026
d32cbe4
Consider also own annotations for video filter
horatiualmasan Jul 16, 2026
3acc186
Merge branch 'horatiu-lig-9805-import-activitynet-style-event-annotat…
horatiualmasan Jul 16, 2026
bdc02d2
fix merge error
horatiualmasan Jul 16, 2026
a9d31fd
Add useVideoPlayback hook with tests
horatiualmasan Jul 16, 2026
5a07a5b
Wire custom control bar into VideoPlayer
horatiualmasan Jul 16, 2026
ebad55a
Use custom player in VideoDetails with deep-link start time
horatiualmasan Jul 16, 2026
1d6d5ae
Add presentation-only VideoControls component
horatiualmasan Jul 16, 2026
2cdba41
format
horatiualmasan Jul 16, 2026
9f287db
Add Storybook stories for VideoControls
horatiualmasan Jul 16, 2026
ecef795
Use custom player in VideoDetails with deep-link start time
horatiualmasan Jul 16, 2026
e2a18ce
format
horatiualmasan Jul 16, 2026
7dede03
Wire custom control bar into VideoPlayer
horatiualmasan Jul 16, 2026
2dc2a47
Add useVideoPlayback hook with tests
horatiualmasan Jul 16, 2026
ab6acde
Add Storybook stories for VideoControls
horatiualmasan Jul 16, 2026
35328bb
update
horatiualmasan Jul 16, 2026
8395952
fix error in test stub
horatiualmasan Jul 16, 2026
f8ef40d
Merge branch 'horatiu-lig-9807-show-event-bars-on-the-timeline.d' of …
horatiualmasan Jul 16, 2026
30b1ea2
skip test
horatiualmasan Jul 16, 2026
feae9e1
Merge branch 'horatiu-lig-9807-show-event-bars-on-the-timeline.c' int…
horatiualmasan Jul 16, 2026
776baa3
reenable test
horatiualmasan Jul 16, 2026
0f2b999
Add video event model (toVideoEvents, assignEventLanes)
horatiualmasan Jul 16, 2026
717ebf2
add AnnotationType.CLASSIFICATION
horatiualmasan Jul 17, 2026
30718ba
update
horatiualmasan Jul 17, 2026
d467a37
Merge branch 'main' into horatiu-lig-9807-show-event-bars-on-the-time…
horatiualmasan Jul 17, 2026
cf0ee5e
Merge branch 'horatiu-lig-9807-show-event-bars-on-the-timeline.a' int…
horatiualmasan Jul 17, 2026
a604ba9
Merge branch 'horatiu-lig-9807-show-event-bars-on-the-timeline.b' int…
horatiualmasan Jul 17, 2026
9563c27
Merge branch 'horatiu-lig-9807-show-event-bars-on-the-timeline.c' int…
horatiualmasan Jul 17, 2026
07ad39d
Merge branch 'horatiu-lig-9807-show-event-bars-on-the-timeline.d' int…
horatiualmasan Jul 17, 2026
93bd70a
Merge branch 'main' into horatiu-lig-9807-show-event-bars-on-the-time…
LeonardoRosaa Jul 20, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lightly_studio_view/src/lib/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ export {
getGridThumbnailRequestSize
} from './getGridThumbnailURL/getGridThumbnailURL';
export { getVideoURLById } from './getVideoURLById/getVideoURLById';
export {
toVideoEvents,
assignEventLanes,
type VideoEvent,
type LaneAssignedEvent
} from './videoEvents/videoEvents';
export { getURL } from './getURL/getURL';
export { fetchCollection } from './fetchCollection';
export { fetchCollectionHierarchy } from './fetchCollectionHierarchy';
Expand Down
110 changes: 110 additions & 0 deletions lightly_studio_view/src/lib/utils/videoEvents/videoEvents.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import { describe, it, expect } from 'vitest';
import type { AnnotationView } from '$lib/api/lightly_studio_local';
import { toVideoEvents, assignEventLanes, type VideoEvent } from './videoEvents';

function makeAnnotation(overrides: Partial<AnnotationView>): AnnotationView {
return {
sample_id: 'a1',
parent_sample_id: 'video-1',
annotation_collection_id: 'coll-1',
annotation_type: 'classification',
annotation_label: { annotation_label_name: 'Jump' },
created_at: new Date(),
temporal_span_details: { start_time_s: 1, end_time_s: 4 },
...overrides
} as AnnotationView;
}

function makeEvent(overrides: Partial<VideoEvent>): VideoEvent {
return {
id: 'e',
annotationCollectionId: 'coll-1',
label: 'x',
startTimeS: 0,
endTimeS: 1,
color: 'rgba(0,0,0,1)',
contrastColor: 'rgba(255,255,255,1)',
...overrides
};
}

describe('toVideoEvents', () => {
it('keeps only classification annotations with a temporal span', () => {
const events = toVideoEvents([
makeAnnotation({ sample_id: 'with-span' }),
makeAnnotation({ sample_id: 'no-span', temporal_span_details: null }),
makeAnnotation({ sample_id: 'not-classification', annotation_type: 'object_detection' })
]);

expect(events.map((event) => event.id)).toEqual(['with-span']);
});

it('maps span times and label onto the event', () => {
const [event] = toVideoEvents([
makeAnnotation({
sample_id: 'e1',
annotation_label: { annotation_label_name: 'Run' },
temporal_span_details: { start_time_s: 2.5, end_time_s: 7 }
})
]);

expect(event).toMatchObject({ id: 'e1', label: 'Run', startTimeS: 2.5, endTimeS: 7 });
expect(event.color).toBeTruthy();
expect(event.contrastColor).toBeTruthy();
});

it('sorts events by start time', () => {
const events = toVideoEvents([
makeAnnotation({
sample_id: 'late',
temporal_span_details: { start_time_s: 9, end_time_s: 10 }
}),
makeAnnotation({
sample_id: 'early',
temporal_span_details: { start_time_s: 1, end_time_s: 2 }
})
]);

expect(events.map((event) => event.id)).toEqual(['early', 'late']);
});

it('returns an empty array when annotations are undefined', () => {
expect(toVideoEvents()).toEqual([]);
});
});

describe('assignEventLanes', () => {
it('places non-overlapping events on the same lane', () => {
const { events, laneCount } = assignEventLanes([
makeEvent({ id: 'a', startTimeS: 0, endTimeS: 2 }),
makeEvent({ id: 'b', startTimeS: 2, endTimeS: 4 })
]);

expect(laneCount).toBe(1);
expect(events.every((event) => event.lane === 0)).toBe(true);
});

it('stacks overlapping events onto separate lanes', () => {
const { events, laneCount } = assignEventLanes([
makeEvent({ id: 'a', startTimeS: 0, endTimeS: 5 }),
makeEvent({ id: 'b', startTimeS: 1, endTimeS: 3 }),
makeEvent({ id: 'c', startTimeS: 2, endTimeS: 4 })
]);

expect(laneCount).toBe(3);
expect(events.find((event) => event.id === 'a')?.lane).toBe(0);
expect(events.find((event) => event.id === 'b')?.lane).toBe(1);
expect(events.find((event) => event.id === 'c')?.lane).toBe(2);
});

it('reuses a freed lane once an earlier event has ended', () => {
const { laneCount } = assignEventLanes([
makeEvent({ id: 'a', startTimeS: 0, endTimeS: 2 }),
makeEvent({ id: 'b', startTimeS: 1, endTimeS: 3 }),
makeEvent({ id: 'c', startTimeS: 2, endTimeS: 4 })
]);

// 'c' can reuse 'a's lane, so only two lanes are needed.
expect(laneCount).toBe(2);
});
});
90 changes: 90 additions & 0 deletions lightly_studio_view/src/lib/utils/videoEvents/videoEvents.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import { AnnotationType, type AnnotationView } from '$lib/api/lightly_studio_local';
import { getColorByLabel } from '$lib/utils/getColorByLabel';

/**
* A time-bounded "event" on a video timeline.
*
* Events are derived from classification annotations that carry a temporal
* span (start/end time in seconds), e.g. ActivityNet-style event annotations
* imported onto the video sample itself.
*/
export interface VideoEvent {
/** Unique id of the event (the annotation's sample id). */
id: string;
/** Collection the underlying annotation belongs to (needed to persist edits). */
annotationCollectionId: string;
/** Human-readable class label. */
label: string;
/** Event start time, in seconds. */
startTimeS: number;
/** Event end time, in seconds. */
endTimeS: number;
/** Fill color derived deterministically from the label. */
color: string;
/** Contrast color for text/borders on top of {@link color}. */
contrastColor: string;
}

/** A {@link VideoEvent} placed on a horizontal lane to avoid visual overlap. */
export interface LaneAssignedEvent extends VideoEvent {
/** Zero-based lane (row) index the event was placed in. */
lane: number;
}

const EVENT_FILL_ALPHA = 0.7;

/**
* Extracts imported events from a sample's annotations.
*
* Keeps only classification annotations that carry a temporal span and maps
* them into {@link VideoEvent}s sorted by start time.
*/
export function toVideoEvents(annotations: AnnotationView[] = []): VideoEvent[] {
return annotations
.filter(
(annotation) =>
annotation.annotation_type === AnnotationType.CLASSIFICATION &&
annotation.temporal_span_details != null
)
.map((annotation) => {
const span = annotation.temporal_span_details!;
const label = annotation.annotation_label.annotation_label_name;
const { color, contrastColor } = getColorByLabel(label, EVENT_FILL_ALPHA);
return {
id: annotation.sample_id,
annotationCollectionId: annotation.annotation_collection_id,
label,
startTimeS: span.start_time_s,
endTimeS: span.end_time_s,
color,
contrastColor
} satisfies VideoEvent;
})
.sort((a, b) => a.startTimeS - b.startTimeS);
}

/**
* Greedily assigns each event to the first lane whose previous event has
* already ended, so overlapping events stack into separate rows instead of
* hiding one another.
*
* @returns The events annotated with a `lane` index and the total lane count.
*/
export function assignEventLanes(events: VideoEvent[]): {
events: LaneAssignedEvent[];
laneCount: number;
} {
const sorted = [...events].sort((a, b) => a.startTimeS - b.startTimeS);
const laneEndTimes: number[] = [];

const placed = sorted.map((event) => {
let lane = laneEndTimes.findIndex((endTime) => endTime <= event.startTimeS);
if (lane === -1) {
lane = laneEndTimes.length;
}
laneEndTimes[lane] = event.endTimeS;
return { ...event, lane } satisfies LaneAssignedEvent;
});

return { events: placed, laneCount: laneEndTimes.length };
}
Loading