Frontend School

Dynamic Bar Chart Configurator

Machine Coding
hard

Dynamic Bar Chart Configurator

Hard
React
TypeScript
UI Components
Data Visualization
State Management

Overview

Data analysts often need to quickly visualize raw data to identify trends and patterns. This problem focuses on building a crucial component for our internal analytics platform: a dynamic chart configurator. This component allows users to interactively define the structure and basic aesthetics of a bar chart from a given dataset, making data exploration intuitive and efficient.

What you need to do / Task

Your primary task is to build a React component, ChartConfigurator, that enables users to configure a simple bar chart. The component should provide controls to select the primary dimension for the X-axis, the metric for the Y-axis, and a custom color for the bars.

  1. Component Structure: Create a ChartConfigurator component that encapsulates the configuration logic and UI.
  2. Data Selection Controls: Implement UI elements (e.g., <select> dropdowns) for:
    • Choosing an X-axis Dimension from a predefined list of categorical fields (availableDimensions).
    • Choosing a Y-axis Metric from a predefined list of numerical fields (availableMetrics).
    • Inputting a Bar Color (e.g., a text input for hex codes or named colors).
  3. Real-time Configuration Preview: Display the current chart configuration as a structured output (e.g., a JSON string or a visually simplified text representation) that updates immediately as users interact with the controls. This preview should reflect the selected X-axis dimension, Y-axis metric, and bar color.

UI/UX expectations

  • The layout should be clean and functional, with configuration controls clearly separated from the chart preview area.
  • Use standard HTML form elements (<label>, <select>, <input>) for accessibility.
  • Each control should have a clear label indicating its purpose.
  • The configuration preview should update instantly with no noticeable lag as selections change.
  • No need for complex styling beyond basic readability.

Acceptance criteria

  • The ChartConfigurator component renders successfully without errors.
  • Dropdowns for X-axis Dimension and Y-axis Metric are populated with the provided availableDimensions and availableMetrics data respectively.
  • Selecting a value from the X-axis Dimension dropdown updates the internal state and the configuration preview.
  • Selecting a value from the Y-axis Metric dropdown updates the internal state and the configuration preview.
  • Entering text into the Bar Color input updates the internal state and the configuration preview.
  • The configuration preview accurately displays the currently selected X-axis dimension, Y-axis metric, and bar color in a readable format (e.g., JSON or key-value pairs).
  • All user interactions are type-safe and handled correctly using TypeScript.

Constraints

Constraints & assumptions

  • You must use React with TypeScript.
  • The chart type is fixed to 'bar'. You do not need to implement a chart type selector.
  • You are provided with mock data (mockRawData), a list of availableDimensions, and availableMetrics. You do not need to fetch data or derive these lists dynamically from mockRawData.
  • The barColor input can be a simple text field; no need for a full-fledged color picker component.
  • Focus on the configuration UI and state management; do not implement an actual visual charting library (e.g., D3.js, Chart.js). The "Chart Preview" is purely a representation of the configuration object.
  • Target completion time: ~45 minutes.

Out of scope

  • Implementing complex data aggregation or transformation logic.
  • Full error handling for invalid user inputs (e.g., non-hex color codes).
  • Advanced accessibility features beyond semantic HTML.
  • Responsive design for various screen sizes.
  • Saving or loading configurations.

What interviewers evaluate

  • Component Architecture: How well the component is structured, its modularity, and separation of concerns.
  • State Management: Effective and idiomatic use of React hooks (e.g., useState, useEffect) to manage component state and side effects.
  • Type Safety: Correct and robust application of TypeScript for props, state, and data structures.
  • Dynamic UI: The ability to build an interactive UI that responds promptly and correctly to user input.
  • Code Quality: Readability, maintainability, and adherence to best practices for React and TypeScript development.

Loading editor...