Implement Option 1: Synchronized Swimlanes with Time Anchor

This commit is contained in:
2026-07-28 14:21:15 +05:30
parent 0def7a5b68
commit c921e0ddef
+119 -73
View File
@@ -47,77 +47,61 @@ export default function EventTimeline() {
return <span className="badge">{state}</span>; return <span className="badge">{state}</span>;
}; };
const groupedEvents = useMemo(() => { const chronologicalBlocks = useMemo(() => {
return { const blocks = {};
CO: events.filter(e => e.camera_zone === 'CO'), events.forEach(ev => {
Mill: events.filter(e => e.camera_zone === 'Mill'), // Group by Minute (HH:MM)
Conveyor: events.filter(e => e.camera_zone === 'Conveyor') const timeKey = ev.start_time.substring(0, 5);
}; if (!blocks[timeKey]) {
blocks[timeKey] = { timeKey, CO: [], Mill: [], Conveyor: [] };
}
if (ev.camera_zone === 'CO') blocks[timeKey].CO.push(ev);
if (ev.camera_zone === 'Mill') blocks[timeKey].Mill.push(ev);
if (ev.camera_zone === 'Conveyor') blocks[timeKey].Conveyor.push(ev);
});
// Sort chronologically
return Object.values(blocks).sort((a, b) => a.timeKey.localeCompare(b.timeKey));
}, [events]); }, [events]);
const renderTimeline = (zone, zoneEvents, index) => ( const renderEventCard = (ev, i, arrLength) => (
<div style={{ <div key={ev.id} style={{
flex: 1, display: 'flex', flexDirection: 'column',
overflowY: 'auto', paddingBottom: i < arrLength - 1 ? '1rem' : '0',
maxHeight: '70vh', marginBottom: i < arrLength - 1 ? '1rem' : '0',
paddingLeft: index === 0 ? '0' : '1.5rem', borderBottom: i < arrLength - 1 ? '1px solid rgba(255,255,255,0.05)' : 'none'
paddingRight: index === 2 ? '0' : '1.5rem',
borderRight: index === 2 ? 'none' : '1px solid rgba(255,255,255,0.05)'
}}> }}>
<h2 style={{ <div style={{ display: 'flex', justifyContent: 'space-between', marginBottom: '0.5rem' }}>
position: 'sticky', <span style={{ fontSize: '0.85rem', color: 'var(--text-secondary)' }}>
top: 0, {ev.start_time.substring(0, 5)} - {ev.end_time.substring(0, 5)}
background: 'var(--panel-bg)', </span>
backdropFilter: 'blur(16px)', {getStateBadge(ev.state)}
WebkitBackdropFilter: 'blur(16px)', </div>
paddingBottom: '1rem', <p style={{ margin: '0 0 0.5rem 0', fontWeight: '500' }}>{ev.event_description}</p>
paddingTop: '0.5rem', <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
borderBottom: '1px solid var(--panel-border)', <span style={{ fontSize: '0.8rem', opacity: 0.8 }}>Duration: {formatDuration(ev.state_duration_seconds)}</span>
zIndex: 10 <button
}}> disabled
{zone} Timeline style={{
</h2> display: 'flex', alignItems: 'center', gap: '0.25rem',
<div style={{ marginTop: '1rem' }}> padding: '0.25rem 0.5rem', borderRadius: '4px', border: '1px solid rgba(255,255,255,0.1)',
{zoneEvents.length === 0 ? ( background: 'rgba(255,255,255,0.05)', color: 'var(--text-secondary)',
<p style={{ opacity: 0.5, textAlign: 'center' }}>No events recorded.</p> cursor: 'not-allowed', fontSize: '0.75rem'
) : ( }}
zoneEvents.map((ev, i) => ( title="Video review is currently disabled"
<div key={ev.id} style={{ display: 'flex', flexDirection: 'column', padding: '1rem 0', borderBottom: i < zoneEvents.length -1 ? '1px dashed rgba(255,255,255,0.1)' : 'none' }}> >
<div style={{ display: 'flex', justifyContent: 'space-between', marginBottom: '0.5rem' }}> <Video size={12} /> View Video
<span style={{ fontSize: '0.85rem', color: 'var(--text-secondary)' }}> </button>
{ev.start_time.substring(0, 5)} - {ev.end_time.substring(0, 5)} </div>
</span> <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: '0.5rem', marginTop: '0.75rem', paddingTop: '0.5rem', borderTop: '1px solid rgba(255,255,255,0.05)', fontSize: '0.75rem', color: 'var(--text-secondary)' }}>
{getStateBadge(ev.state)} <div>
</div> <span style={{ opacity: 0.7 }}>Std Cycle: </span>
<p style={{ margin: '0 0 0.5rem 0', fontWeight: '500' }}>{ev.event_description}</p> <span style={{ color: 'var(--text)', fontWeight: '500' }}>N/A</span>
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}> </div>
<span style={{ fontSize: '0.8rem', opacity: 0.8 }}>Duration: {formatDuration(ev.state_duration_seconds)}</span> <div>
<button <span style={{ opacity: 0.7 }}>Manpower: </span>
disabled <span style={{ color: 'var(--text)', fontWeight: '500' }}>Nil</span>
style={{ </div>
display: 'flex', alignItems: 'center', gap: '0.25rem',
padding: '0.25rem 0.5rem', borderRadius: '4px', border: '1px solid rgba(255,255,255,0.1)',
background: 'rgba(255,255,255,0.05)', color: 'var(--text-secondary)',
cursor: 'not-allowed', fontSize: '0.75rem'
}}
title="Video review is currently disabled"
>
<Video size={12} /> View Video
</button>
</div>
<div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: '0.5rem', marginTop: '0.75rem', paddingTop: '0.5rem', borderTop: '1px solid rgba(255,255,255,0.05)', fontSize: '0.75rem', color: 'var(--text-secondary)' }}>
<div>
<span style={{ opacity: 0.7 }}>Std Cycle: </span>
<span style={{ color: 'var(--text)', fontWeight: '500' }}>N/A</span>
</div>
<div>
<span style={{ opacity: 0.7 }}>Manpower: </span>
<span style={{ color: 'var(--text)', fontWeight: '500' }}>Nil</span>
</div>
</div>
</div>
))
)}
</div> </div>
</div> </div>
); );
@@ -137,13 +121,75 @@ export default function EventTimeline() {
<ArrowLeft size={16} /> Back to Changeover Analytics <ArrowLeft size={16} /> Back to Changeover Analytics
</Link> </Link>
<h1>Event Timeline: {id}</h1> <h1>Event Timeline: {id}</h1>
<p>Location-wise sequential breakdown of events</p> <p>Synchronized Swimlane Timeline</p>
</div> </div>
<div className="glass-panel" style={{ display: 'flex', padding: '1.5rem', alignItems: 'stretch' }}> <div className="glass-panel" style={{ display: 'flex', flexDirection: 'column', padding: 0, overflow: 'hidden' }}>
{renderTimeline('CO', groupedEvents.CO, 0)}
{renderTimeline('Mill', groupedEvents.Mill, 1)} {/* Sticky Header Grid */}
{renderTimeline('Conveyor', groupedEvents.Conveyor, 2)} <div style={{
display: 'grid',
gridTemplateColumns: '80px 1fr 1fr 1fr',
gap: '1.5rem',
padding: '1.5rem 1.5rem 1rem 1.5rem',
background: 'var(--panel-bg)',
backdropFilter: 'blur(16px)',
WebkitBackdropFilter: 'blur(16px)',
borderBottom: '1px solid var(--panel-border)',
position: 'sticky',
top: 0,
zIndex: 10
}}>
<h2 style={{ margin: 0, fontSize: '1rem', color: 'var(--text-secondary)' }}>Time</h2>
<h2 style={{ margin: 0, fontSize: '1.1rem' }}>CO Timeline</h2>
<h2 style={{ margin: 0, fontSize: '1.1rem' }}>Mill Timeline</h2>
<h2 style={{ margin: 0, fontSize: '1.1rem' }}>Conveyor Timeline</h2>
</div>
{/* Scrollable Timeline Tracks Container */}
<div style={{ overflowY: 'auto', maxHeight: '65vh', padding: '0 1.5rem' }}>
{chronologicalBlocks.length === 0 ? (
<p style={{ padding: '2rem', textAlign: 'center', opacity: 0.5 }}>No events recorded.</p>
) : (
chronologicalBlocks.map((block, index) => (
<div key={block.timeKey} style={{
display: 'grid',
gridTemplateColumns: '80px 1fr 1fr 1fr',
gap: '1.5rem',
borderBottom: index < chronologicalBlocks.length - 1 ? '1px dashed rgba(255,255,255,0.1)' : 'none',
padding: '1.5rem 0'
}}>
{/* Time Anchor Left Column */}
<div style={{ position: 'relative' }}>
<div style={{
position: 'sticky',
top: '0',
fontWeight: '600',
color: 'var(--accent)',
fontSize: '1.1rem',
letterSpacing: '0.05em'
}}>
{block.timeKey}
</div>
</div>
{/* Event Columns */}
<div>
{block.CO.map((ev, i) => renderEventCard(ev, i, block.CO.length))}
</div>
<div>
{block.Mill.map((ev, i) => renderEventCard(ev, i, block.Mill.length))}
</div>
<div>
{block.Conveyor.map((ev, i) => renderEventCard(ev, i, block.Conveyor.length))}
</div>
</div>
))
)}
</div>
</div> </div>
</div> </div>
); );