-
-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
774 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
apps/client/src/features/viewers/timeline/Timeline.module.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
$timeline-entry-height: 20px; | ||
|
||
.timeline { | ||
flex: 1; | ||
} | ||
|
||
.timelineEvents { | ||
position: relative; | ||
height: 100%; | ||
} | ||
|
||
.entryColumn { | ||
position: absolute; | ||
background-color: var(--lighter, $gray-500); | ||
border-bottom: 0.25rem solid var(--color, $ui-white); | ||
border-right: 1px solid $ui-black; | ||
min-height: 80px; | ||
|
||
&.fullHeight { | ||
height: calc(100% - 4rem); | ||
} | ||
} | ||
|
||
.entryContent { | ||
padding-top: var(--top, 0); | ||
|
||
&.lastElement { | ||
text-align: right; | ||
transform: translateX(-100%); | ||
} | ||
} | ||
|
||
.entryText { | ||
position: relative; | ||
z-index: 2; | ||
color: $ui-white; | ||
padding-inline: 0.5em; | ||
width: fit-content; | ||
white-space: nowrap; | ||
|
||
&.textBg { | ||
background-color: var(--bg, $black-10); | ||
} | ||
} | ||
|
||
.start, | ||
.title { | ||
font-weight: 600; | ||
} | ||
|
||
// for elapsed events, we can hide some stuff | ||
[data-status='finished'] { | ||
color: $gray-500; | ||
.status { | ||
display: none; | ||
} | ||
} | ||
|
||
[data-status='live'] { | ||
font-weight: 600; | ||
color: $ui-white; | ||
|
||
.status { | ||
color: $active-red; | ||
} | ||
} | ||
|
||
[data-status='future'] { | ||
font-weight: 600; | ||
color: $gray-300; | ||
|
||
.status { | ||
color: $green-500; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
import { memo } from 'react'; | ||
import { useSearchParams } from 'react-router-dom'; | ||
import { useViewportSize } from '@mantine/hooks'; | ||
import { isOntimeEvent, MaybeNumber } from 'ontime-types'; | ||
import { dayInMs, getFirstEventNormal, getLastEventNormal, MILLIS_PER_HOUR } from 'ontime-utils'; | ||
|
||
import useRundown from '../../../common/hooks-query/useRundown'; | ||
import { isStringBoolean } from '../../viewers/common/viewUtils'; | ||
|
||
import { TimelineMarkers } from './timeline-markers/TimelineMarkers'; | ||
import { ProgressBar } from './timeline-progress-bar/TimelineProgressBar'; | ||
import { getElementPosition, getEndHour, getEstimatedWidth, getLaneLevel, getStartHour } from './timeline.utils'; | ||
import { ProgressStatus, TimelineEntry } from './TimelineEntry'; | ||
|
||
import style from './Timeline.module.scss'; | ||
|
||
export default memo(Timeline); | ||
|
||
function useTimeline() { | ||
const { data } = useRundown(); | ||
if (data.revision === -1) { | ||
return null; | ||
} | ||
|
||
const { firstEvent } = getFirstEventNormal(data.rundown, data.order); | ||
const { lastEvent } = getLastEventNormal(data.rundown, data.order); | ||
const firstStart = firstEvent?.timeStart ?? 0; | ||
const lastEnd = lastEvent?.timeEnd ?? 0; | ||
const normalisedLastEnd = lastEnd < firstStart ? lastEnd + dayInMs : lastEnd; | ||
|
||
// timeline is padded to nearest hours (floor and ceil) | ||
const startHour = getStartHour(firstStart) * MILLIS_PER_HOUR; | ||
const endHour = getEndHour(normalisedLastEnd) * MILLIS_PER_HOUR; | ||
|
||
return { | ||
rundown: data.rundown, | ||
order: data.order, | ||
startHour, | ||
endHour, | ||
}; | ||
} | ||
|
||
interface TimelineProps { | ||
selectedEventId: string | null; | ||
} | ||
|
||
function Timeline(props: TimelineProps) { | ||
const { selectedEventId } = props; | ||
const { width: screenWidth } = useViewportSize(); | ||
const timelineData = useTimeline(); | ||
const [searchParams] = useSearchParams(); | ||
const fullHeight = isStringBoolean(searchParams.get('fullHeight')); | ||
|
||
if (timelineData === null) { | ||
return null; | ||
} | ||
|
||
const { rundown, order, startHour, endHour } = timelineData; | ||
|
||
let hasTimelinePassedMidnight = false; | ||
let previousEventStartTime: MaybeNumber = null; | ||
let eventStatus: ProgressStatus = 'finished'; | ||
// a list of the right most element for each lane | ||
const rightMostElements: Record<number, number> = {}; | ||
|
||
return ( | ||
<div className={style.timeline}> | ||
<TimelineMarkers /> | ||
<ProgressBar startHour={startHour} endHour={endHour} /> | ||
<div className={style.timelineEvents}> | ||
{order.map((eventId) => { | ||
// for now we dont render delays and blocks | ||
const event = rundown[eventId]; | ||
if (!isOntimeEvent(event)) { | ||
return null; | ||
} | ||
|
||
// keep track of progress of rundown | ||
if (eventStatus === 'live') { | ||
eventStatus = 'future'; | ||
} | ||
if (eventId === selectedEventId) { | ||
eventStatus = 'live'; | ||
} | ||
|
||
// we need to offset the start to account for midnight | ||
if (!hasTimelinePassedMidnight) { | ||
hasTimelinePassedMidnight = previousEventStartTime !== null && event.timeStart < previousEventStartTime; | ||
} | ||
const normalisedStart = hasTimelinePassedMidnight ? event.timeStart + dayInMs : event.timeStart; | ||
previousEventStartTime = normalisedStart; | ||
|
||
const { left: elementLeftPosition, width: elementWidth } = getElementPosition( | ||
startHour, | ||
endHour, | ||
normalisedStart, | ||
event.duration, | ||
screenWidth, | ||
); | ||
const estimatedWidth = getEstimatedWidth(event.title); | ||
const estimatedRightPosition = elementLeftPosition + estimatedWidth; | ||
const laneLevel = getLaneLevel(rightMostElements, elementLeftPosition); | ||
|
||
if (rightMostElements[laneLevel] === undefined || rightMostElements[laneLevel] < estimatedRightPosition) { | ||
rightMostElements[laneLevel] = estimatedRightPosition; | ||
} | ||
|
||
return ( | ||
<TimelineEntry | ||
key={eventId} | ||
colour={event.colour} | ||
duration={event.duration} | ||
isLast={eventId === order[order.length - 1]} | ||
lane={laneLevel} | ||
left={elementLeftPosition} | ||
status={eventStatus} | ||
start={event.timeStart} | ||
title={event.title} | ||
width={elementWidth} | ||
mayGrow={elementWidth < estimatedWidth} | ||
fullHeight={fullHeight} | ||
/> | ||
); | ||
})} | ||
</div> | ||
</div> | ||
); | ||
} |
Oops, something went wrong.