Overview
TheTimeline class provides chronological event logging for the simulation. Each UI module creates its own timeline instance to display execution events as they happen.
Class: Timeline
Location
source/js/ui/timeline.js
Constructor
timeline.js
container- DOM element where timeline events will be rendered
Example Instantiation
ui.js
Methods
addEvent(text)
Adds a new event to the timeline with a timestamp.
Parameters:
text- String describing the event
- Creates a timestamped log entry
- Prepends (adds to top) so newest events appear first
- Uses HH:MM:SS format in 24-hour time
timeline.js
clear()
Removes all events from the timeline.
Example:
timeline.js
ui.js
Event Flow
The timeline integrates with the simulation execution cycle:Event Types by Scenario
Mutex (Bank Scenario)
Semaphore (Printer Scenario)
Condition Variables (Restaurant Scenario)
Barrier (Race Scenario)
Monitor (Library Scenario)
Join/Await (House Construction Scenario)
Peterson’s Algorithm (Robot Station Scenario)
Timeline Styling
The timeline uses a monospace font and consistent styling:Event Ordering
Events are displayed in reverse chronological order (newest first):prepend() instead of append():
Integration with UI Modules
Each UI module creates its own timeline:Typical Usage Pattern
ui.js
Event Sources
Timeline events come from:- Engine Execution -
engine.step()returns event strings - UI Messages - Status updates from UI module
- Scenario Initialization - Setup messages when creating scenarios
Engine Events
Generated inengine.js by the execute() method:
engine.js
UI Status Messages
ui.js
Scenario Setup Messages
ui.js
Best Practices
- Clear on New Scenario - Always clear the timeline when starting fresh
- Use Emojis - Visual icons help distinguish event types quickly
- Be Descriptive - Include relevant details (thread names, amounts, etc.)
- Handle Empty Events - Check
events.lengthbefore iterating - Prevent Duplicates - Use
simulationFinishedflag for final messages
Timeline Container Requirements
The container should:- Be scrollable if events overflow
- Have a dark background for readability
- Support monospace font rendering
Next Steps
- UI Overview - Learn about UI module architecture
- Renderer API - Understand visual rendering
- Engine API - See how events are generated