Frontend School

Configurable Shipment Volume Trend Chart

Machine Coding
medium

Configurable Shipment Volume Trend Chart

Medium
React
TypeScript
UI
Data Visualization
State Management

Overview

At Shiprocket, understanding shipment trends is crucial for operational planning and business strategy. We need a flexible tool that allows our analysts to quickly visualize shipment volume over different time granularities. This problem challenges you to build a simplified, interactive chart builder component that dynamically displays shipment volume based on user-selected time periods.

What you need to do / Task

  1. Implement Data Aggregation: Given a mock dataset of individual shipments, process this data to aggregate total shipment volume based on a selected time granularity (Daily, Weekly, Monthly). Helper functions for generating date keys and labels are provided.
  2. Build Granularity Selector: Create a UI control (e.g., radio buttons) that allows users to switch between "Daily", "Weekly", and "Monthly" views.
  3. Render Bar Chart: Display the aggregated shipment volume as a simple bar chart. Each bar should represent a period (day, week, or month), and its height should correspond proportionally to the total volume for that period.
  4. Dynamic Updates: Ensure the chart updates immediately when the user changes the time granularity.

UI/UX expectations

  • The granularity selector should be clearly visible and allow easy switching between options.
  • The chart should be displayed prominently below the selector.
  • Each bar in the chart should be visually distinct. Its height should be a clear visual representation of the volume.
  • Labels for each bar (e.g., "Jan 1", "Week 1", "Jan 2023") and a Y-axis indicator for volume are expected.
  • The overall layout should be clean and readable, even with minimal styling.

Acceptance criteria

  • User can select "Daily", "Weekly", or "Monthly" granularity.
  • Selecting a granularity correctly aggregates and displays shipment volume for that period from the mock data.
  • The bar chart visually represents the aggregated data, with bar heights proportional to volume.
  • Meaningful labels for each bar (e.g., date, week number, month name) are present and correctly formatted.
  • The chart updates dynamically without a full page reload when granularity changes.
  • No console errors are present during interaction.

Constraints

Constraints & assumptions

  • You must use React with TypeScript.
  • No external charting libraries (e.g., Recharts, Chart.js, Nivo). Build the chart using basic HTML/CSS (divs, flexbox, grid) or SVG if preferred for visual elements.
  • The provided mock data and date helper functions should be used as a starting point.
  • Focus on functional components and React Hooks.
  • Assume a modern browser environment.

Out of scope

  • Extensive styling or pixel-perfect design beyond basic readability and visual representation.
  • Accessibility beyond basic semantic HTML elements.
  • Handling of very large datasets or performance optimization for millions of data points.
  • Date range selection (e.g., custom start/end dates) beyond the predefined granularity options.

What interviewers evaluate

  • Correctness and efficiency of data aggregation logic.
  • Effective use of React state management and component composition.
  • Clear separation of concerns and maintainable code structure.
  • Ability to translate data into a dynamic visual representation.

Loading editor...