Frontend School

Interactive Project Timeline Component

Machine Coding
hard

Interactive Project Timeline Component

Hard
React
TypeScript
UI
Frontend
Timeline

Overview

In many Adobe creative applications and project management tools, visualizing time-bound activities or assets is crucial. Users need to quickly understand the sequence, duration, and potential overlaps of various events within a project. This problem challenges you to build a core interactive timeline component that accurately displays events, handles overlaps, and allows for basic time navigation.

What you need to do / Task

Your task is to implement a responsive horizontal timeline component with the following features:

  1. Timeline Scale Rendering: Display a dynamic horizontal time scale (e.g., hours, minutes) that adjusts based on the current zoom level.
  2. Event Display: Render a collection of TimelineEvent items as visual blocks on the timeline. Each event has a start, end time, and a label.
  3. Accurate Positioning: Events must be positioned horizontally according to their start and end times relative to the visible timeline range and current zoom level.
  4. Overlap Resolution: Implement a strategy to visually distinguish events that overlap in time. For instance, stack them vertically or offset them to prevent complete obscuration.
  5. Current Time Indicator: Display a static vertical line indicating the 'current time' (e.g., now).
  6. Zoom Functionality: Provide controls (e.g., + and - buttons, or scroll wheel) to zoom in and out of the timeline. Zooming should adjust the visible time range and rescale event positioning accordingly.
  7. Event Selection: Allow users to click on an event to select it. The selected event should have a distinct visual style.

UI/UX expectations

  • Layout: The timeline should be a horizontal scrollable area. The time scale should be fixed at the top, while events are rendered below it.
  • Event Representation: Each event should be a rectangular block. Its width should correspond to its duration, and its horizontal position to its start time.
  • Overlap Visualization: Overlapping events should be clearly visible; avoid placing them directly on top of each other. A common approach is to stack them vertically.
  • Zoom Controls: Simple + and - buttons (or similar UI) should be available to control the zoom level.
  • Current Time Indicator: A distinct vertical line (e.g., red) should mark the current time.
  • Selection: Clicking an event should highlight it with a border or background change. Only one event can be selected at a time.

Acceptance criteria

  • The timeline renders with a visible, dynamic time scale.
  • All provided TimelineEvent items are displayed within the timeline area.
  • Events are accurately positioned and sized based on their start/end times and the current zoom level.
  • Events that overlap in time are visibly separated (e.g., stacked vertically).
  • Zooming in/out correctly adjusts the visible time range and the horizontal rendering of events and the scale.
  • A current time indicator is present and correctly positioned.
  • Clicking an event selects it, applying a distinct visual style. Clicking another event deselects the previous one and selects the new one.

Constraints

Constraints & assumptions

  • The total duration of the timeline is fixed (e.g., 24 hours or a specific project duration). You can define this. Assume a total span of 24 hours for simplicity.
  • Events will have start and end times. For this problem, you can use numbers representing milliseconds since a fixed epoch or simply relative minutes/hours from the start of the timeline.
  • Assume a maximum of 50-100 events. No advanced virtualization is required for this scale.
  • You are free to choose the units for your timeline (e.g., minutes, hours).
  • Use React and TypeScript.
  • Styling should be done using CSS (plain CSS or CSS modules).

Out of scope

  • Drag-and-drop functionality for events.
  • Complex animations or transitions.
  • Backend integration or persistent storage for events.
  • Extensive accessibility features beyond basic visual cues (e.g., full keyboard navigation for all elements).
  • Advanced performance optimizations like canvas rendering for thousands of events.

What interviewers evaluate

  • Architectural Design: How well the component is structured, separation of concerns, and state management.
  • Algorithmic Thinking: The approach to calculating event positions, durations, and especially handling overlaps efficiently.
  • React Proficiency: Effective use of React hooks, component lifecycle, and rendering patterns.
  • Code Quality: Readability, maintainability, type safety, and adherence to best practices.

Loading editor...