forked from Github/frigate
Timeline tweaks (#10693)
* make segment height static * fix timeline overscrolling * better alignment of motion timeline segments
This commit is contained in:
@@ -82,7 +82,7 @@ export function useCameraMotionNextTimestamp(
|
||||
});
|
||||
|
||||
const noMotionRanges = useMemo(() => {
|
||||
if (!motionData || !reviewItems) {
|
||||
if (!motionData || !reviewItems || !motionData) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -100,8 +100,7 @@ export function useCameraMotionNextTimestamp(
|
||||
alignStartDateToTimeline(timeRangeSegmentEnd)) %
|
||||
segmentDuration;
|
||||
|
||||
const startIndex =
|
||||
offset > 0 ? Math.floor(offset / (segmentDuration / 15)) : 0;
|
||||
const startIndex = Math.abs(Math.floor(offset / 15));
|
||||
|
||||
for (
|
||||
let i = startIndex;
|
||||
|
||||
@@ -42,10 +42,12 @@ function useDraggableElement({
|
||||
setIsDragging,
|
||||
setDraggableElementPosition,
|
||||
}: DraggableElementProps) {
|
||||
const segmentHeight = 8;
|
||||
const [clientYPosition, setClientYPosition] = useState<number | null>(null);
|
||||
const [initialClickAdjustment, setInitialClickAdjustment] = useState(0);
|
||||
const [elementScrollIntoView, setElementScrollIntoView] = useState(true);
|
||||
const [scrollEdgeSize, setScrollEdgeSize] = useState<number>();
|
||||
const [fullTimelineHeight, setFullTimelineHeight] = useState<number>();
|
||||
const [segments, setSegments] = useState<HTMLDivElement[]>([]);
|
||||
const { alignStartDateToTimeline, getCumulativeScrollTop } = useTimelineUtils(
|
||||
{
|
||||
@@ -137,15 +139,9 @@ function useDraggableElement({
|
||||
|
||||
const timestampToPixels = useCallback(
|
||||
(time: number) => {
|
||||
const { scrollHeight: timelineHeight } =
|
||||
timelineRef.current as HTMLDivElement;
|
||||
|
||||
const segmentHeight =
|
||||
timelineHeight / (timelineDuration / segmentDuration);
|
||||
|
||||
return ((timelineStartAligned - time) / segmentDuration) * segmentHeight;
|
||||
},
|
||||
[segmentDuration, timelineRef, timelineStartAligned, timelineDuration],
|
||||
[segmentDuration, timelineStartAligned],
|
||||
);
|
||||
|
||||
const updateDraggableElementPosition = useCallback(
|
||||
@@ -226,21 +222,17 @@ function useDraggableElement({
|
||||
showDraggableElement &&
|
||||
isDragging &&
|
||||
clientYPosition &&
|
||||
segments
|
||||
segments &&
|
||||
fullTimelineHeight
|
||||
) {
|
||||
const { scrollHeight: timelineHeight, scrollTop: scrolled } =
|
||||
timelineRef.current;
|
||||
|
||||
const segmentHeight =
|
||||
timelineHeight / (timelineDuration / segmentDuration);
|
||||
const { scrollTop: scrolled } = timelineRef.current;
|
||||
|
||||
const parentScrollTop = getCumulativeScrollTop(timelineRef.current);
|
||||
|
||||
// bottom of timeline
|
||||
const elementEarliest = draggableElementEarliestTime
|
||||
? timestampToPixels(draggableElementEarliestTime)
|
||||
: segmentHeight * (timelineDuration / segmentDuration) -
|
||||
segmentHeight * 3.5;
|
||||
: fullTimelineHeight - segmentHeight * 1.5;
|
||||
|
||||
// top of timeline - default 2 segments added for draggableElement visibility
|
||||
const elementLatest = draggableElementLatestTime
|
||||
@@ -314,7 +306,11 @@ function useDraggableElement({
|
||||
scrollEdgeSize)) /
|
||||
scrollEdgeSize,
|
||||
);
|
||||
timelineRef.current.scrollTop += segmentHeight * intensity;
|
||||
const newScrollTop = Math.min(
|
||||
fullTimelineHeight - segmentHeight,
|
||||
timelineRef.current.scrollTop + segmentHeight * intensity,
|
||||
);
|
||||
timelineRef.current.scrollTop = newScrollTop;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -374,11 +370,7 @@ function useDraggableElement({
|
||||
!isDragging &&
|
||||
segments.length > 0
|
||||
) {
|
||||
const { scrollHeight: timelineHeight, scrollTop: scrolled } =
|
||||
timelineRef.current;
|
||||
|
||||
const segmentHeight =
|
||||
timelineHeight / (timelineDuration / segmentDuration);
|
||||
const { scrollTop: scrolled } = timelineRef.current;
|
||||
|
||||
const alignedSegmentTime = alignStartDateToTimeline(draggableElementTime);
|
||||
|
||||
@@ -426,6 +418,7 @@ function useDraggableElement({
|
||||
|
||||
useEffect(() => {
|
||||
if (timelineRef.current && draggableElementTime && timelineCollapsed) {
|
||||
setFullTimelineHeight(timelineRef.current.scrollHeight);
|
||||
const alignedSegmentTime = alignStartDateToTimeline(draggableElementTime);
|
||||
|
||||
let segmentElement = timelineRef.current.querySelector(
|
||||
@@ -435,8 +428,12 @@ function useDraggableElement({
|
||||
if (!segmentElement) {
|
||||
// segment not found, maybe we collapsed over a collapsible segment
|
||||
let searchTime = alignedSegmentTime;
|
||||
while (searchTime >= timelineStartAligned - timelineDuration) {
|
||||
searchTime -= segmentDuration;
|
||||
|
||||
while (
|
||||
searchTime < timelineStartAligned &&
|
||||
searchTime < timelineStartAligned + timelineDuration
|
||||
) {
|
||||
searchTime += segmentDuration;
|
||||
segmentElement = timelineRef.current.querySelector(
|
||||
`[data-segment-id="${searchTime}"]`,
|
||||
);
|
||||
@@ -456,10 +453,11 @@ function useDraggableElement({
|
||||
}, [timelineCollapsed]);
|
||||
|
||||
useEffect(() => {
|
||||
if (timelineRef.current) {
|
||||
if (timelineRef.current && segments) {
|
||||
setScrollEdgeSize(timelineRef.current.clientHeight * 0.03);
|
||||
setFullTimelineHeight(timelineRef.current.scrollHeight);
|
||||
}
|
||||
}, [timelineRef]);
|
||||
}, [timelineRef, segments]);
|
||||
|
||||
return { handleMouseDown, handleMouseUp, handleMouseMove };
|
||||
}
|
||||
|
||||
@@ -40,13 +40,9 @@ export function useTimelineUtils({
|
||||
|
||||
const getVisibleTimelineDuration = useCallback(() => {
|
||||
if (timelineRef?.current && timelineDuration) {
|
||||
const {
|
||||
scrollHeight: timelineHeight,
|
||||
clientHeight: visibleTimelineHeight,
|
||||
} = timelineRef.current;
|
||||
const { clientHeight: visibleTimelineHeight } = timelineRef.current;
|
||||
|
||||
const segmentHeight =
|
||||
timelineHeight / (timelineDuration / segmentDuration);
|
||||
const segmentHeight = 8;
|
||||
|
||||
const visibleTime =
|
||||
(visibleTimelineHeight / segmentHeight) * segmentDuration;
|
||||
|
||||
Reference in New Issue
Block a user