import React from "react"; import { LogItemWithMeta } from "./types"; import { borderColorClasses, colorClasses, formatDuration } from "./utils"; import { cn } from "../../hooks"; const clamp = (value: number, min: number, max: number) => Math.min(Math.max(value, min), max); export interface TimelineEventBarProps { item: LogItemWithMeta; isHovered: boolean; onMouseEnter: () => void; onMouseLeave: () => void; onClick?: (time: number) => void; viewStart: number; viewWindow: number; timeToPercent: (time: number) => number; index?: number; } /** * Individual timeline event bar component. * Renders a single event with its launch wait line and execution bar. */ export function TimelineProcessBar({ item, isHovered, onMouseEnter, onMouseLeave, onClick, viewStart, viewWindow, timeToPercent, }: TimelineEventBarProps) { const viewEnd = viewStart + viewWindow; const isHaltedStep = item.isHaltedStep; const barStart = item.startTime; const barEnd = item.startTime !== undefined && item.duration !== undefined ? item.startTime + item.duration : undefined; return (
{/* Launch Wait Line */} {item.createTime !== undefined && item.startTime !== undefined && item.createTime < item.startTime && item.color && (
)} {/* Execution Bar */} {item.startTime !== undefined && item.duration !== undefined && !isHaltedStep && (
{ if (onClick && item.startTime !== undefined) { e.stopPropagation(); // Calculate click position within the bar const rect = e.currentTarget.getBoundingClientRect(); const clickX = e.clientX - rect.left; const clickPercent = clickX / rect.width; const clickTime = item.startTime + item.duration! * clickPercent; onClick(clickTime); } }} /> )} {/* Visible Label for Execution Bar */} {item.startTime !== undefined && item.duration !== undefined && !isHaltedStep && (() => { const visibleStart = Math.max(barStart!, viewStart); const visibleEnd = Math.min(barEnd!, viewEnd); if (visibleEnd <= visibleStart) return null; const visibleDuration = visibleEnd - visibleStart; const visibleWidthPercent = (visibleDuration / viewWindow) * 100; if (visibleWidthPercent < 4) return null; return (
{formatDuration(item.duration)}
); })()} {/* Start Circle */} {item.startTime !== undefined && item.duration !== undefined && !isHaltedStep && item.color && (
)} {/* Special Halted Step Visualization */} {isHaltedStep && item.startTime !== undefined && item.duration !== undefined && (
)} {/* Halted Step Label */} {isHaltedStep && item.startTime !== undefined && item.duration !== undefined && (() => { const visibleStart = Math.max(barStart!, viewStart); const visibleEnd = Math.min(barEnd!, viewEnd); if (visibleEnd <= visibleStart) return null; const visibleDuration = visibleEnd - visibleStart; const visibleWidthPercent = (visibleDuration / viewWindow) * 100; return (
{visibleWidthPercent > 7 && ( Halted )} {visibleWidthPercent < 7 && }
); })()}
); }