You are a senior AI software engineer. Your goal is to deliver a full web application that lets end users define a small set of items and instantly see them plotted on a two-dimensional uncertainty matrix. Follow these guidelines:
Objective
Build an interactive app that asks for:
A list of item names (free-text tags).
For each item, a slider or numeric input for Impact (0–10).
For each item, a slider or numeric input for Uncertainty (0–10).
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Note: Write modular, well-commented code. After each major code block, briefly explain your reasoning and assumptions to ensure transparency and allow for future iteration.
Assistant
Uncertainty Matrix Web Application
I'll design a React + TypeScript application that meets your requirements. Let's break this down into logical components and implement them step by step.
import React, { useState, useEffect } from 'react';
import MatrixInputForm from './components/MatrixInputForm';
import UncertaintyMatrixChart from './components/UncertaintyMatrixChart';
import SummaryTable from './components/SummaryTable';
import Callout from './components/Callout';
import { MatrixItem, QuadrantCounts, QuadrantAverages } from './types/types';
import { exportToCSV, exportChartToPNG } from './utils/exportUtils';
const App: React.FC = () => {
// Initialize with two example items
const [items, setItems] = useState<MatrixItem[]>([
{ id: '1', name: 'New Product Launch', impact: 8, uncertainty: 7 },
{ id: '2', name: 'Process Optimization', impact: 6, uncertainty: 3 }
]);
const [quadrantCounts, setQuadrantCounts] = useState<QuadrantCounts>({
highImpactHighUncertainty: 0,
highImpactLowUncertainty: 0,
lowImpactHighUncertainty: 0,
lowImpactLowUncertainty: 0
});
const [quadrantAverages, setQuadrantAverages] = useState<QuadrantAverages>({
highImpactHighUncertainty: { impact: 0, uncertainty: 0 },
highImpactLowUncertainty: { impact: 0, uncertainty: 0 },
lowImpactHighUncertainty: { impact: 0, uncertainty: 0 },
lowImpactLowUncertainty: { impact: 0, uncertainty: 0 }
});
// Calculate quadrant statistics whenever items change
useEffect(() => {
const midpoint = 5;
// Initialize counts and sums
const counts: QuadrantCounts = {
highImpactHighUncertainty: 0,
highImpactLowUncertainty: 0,
lowImpactHighUncertainty: 0,
lowImpactLowUncertainty: 0
};
const sums = {
highImpactHighUncertainty: { impact: 0, uncertainty: 0 },
highImpactLowUncertainty: { impact: 0, uncertainty: 0 },
lowImpactHighUncertainty: { impact: 0, uncertainty: 0 },
lowImpactLowUncertainty: { impact: 0, uncertainty: 0 }
};
// Categorize each item
items.forEach(item => {
if (item.impact >= midpoint && item.uncertainty >= midpoint) {
counts.highImpactHighUncertainty++;
sums.highImpactHighUncertainty.impact += item.impact;
sums.highImpactHighUncertainty.uncertainty += item.uncertainty;
} else if (item.impact >= midpoint && item.uncertainty < midpoint) {
counts.highImpactLowUncertainty++;
sums.highImpactLowUncertainty.impact += item.impact;
sums.highImpactLowUncertainty.uncertainty += item.uncertainty;
} else if (item.impact < midpoint && item.uncertainty >= midpoint) {
counts.lowImpactHighUncertainty++;
sums.lowImpactHighUncertainty.impact += item.impact;
sums.lowImpactHighUncertainty.uncertainty += item.uncertainty;
} else {
counts.lowImpactLowUncertainty++;
sums.lowImpactLowUncertainty.impact += item.impact;
sums.lowImpactLowUncertainty.uncertainty += item.uncertainty;
}
});
// Calculate averages
const averages: QuadrantAverages = {
highImpactHighUncertainty: {
impact: counts.highImpactHighUncertainty ? sums.highImpactHighUncertainty.impact / counts.highImpactHighUncertainty : 0,
uncertainty: counts.highImpactHighUncertainty ? sums.highImpactHighUncertainty.uncertainty / counts.highImpactHighUncertainty : 0
},
highImpactLowUncertainty: {
impact: counts.highImpactLowUncertainty ? sums.highImpactLowUncertainty.impact / counts.highImpactLowUncertainty : 0,
uncertainty: counts.highImpactLowUncertainty ? sums.highImpactLowUncertainty.uncertainty / counts.highImpactLowUncertainty : 0
},
lowImpactHighUncertainty: {
impact: counts.lowImpactHighUncertainty ? sums.lowImpactHighUncertainty.impact / counts.lowImpactHighUncertainty : 0,
uncertainty: counts.lowImpactHighUncertainty ? sums.lowImpactHighUncertainty.uncertainty / counts.lowImpactHighUncertainty : 0
},
lowImpactLowUncertainty: {
impact: counts.lowImpactLowUncertainty ? sums.lowImpactLowUncertainty.impact / counts.lowImpactLowUncertainty : 0,
uncertainty: counts.lowImpactLowUncertainty ? sums.lowImpactLowUncertainty.uncertainty / counts.lowImpactLowUncertainty : 0
}
};
setQuadrantCounts(counts);
setQuadrantAverages(averages);
}, [items]);
return (
<div className="container mx-auto p-4 max-w-6xl">
<h1 className="text-3xl font-bold mb-6 text-center">Uncertainty Matrix Tool</h1>
<Callout title="How to use this tool">
<p className="mb-2">This tool helps you visualize items based on their impact and uncertainty.</p>
<p className="mb-2">Add items, adjust their impact and uncertainty scores using the sliders, and see how they're positioned on the matrix.</p>
<p>The matrix is divided into four quadrants based on the midpoint (5) of the 0-10 scales.</p>
</Callout>
<div className="grid grid-cols-1 lg:grid-cols-2 gap-8">
<div>
<h2 className="text-xl font-semibold mb-4">Items</h2>
<MatrixInputForm items={items} onItemsChange={setItems} />
</div>
<div>
<h2 className="text-xl font-semibold mb-4">Summary Statistics</h2>
<SummaryTable quadrantCounts={quadrantCounts} quadrantAverages={quadrantAverages} />
</div>
</div>
<div className="mt-8">
<UncertaintyMatrixChart items={items} />
</div>
<div className="mt-8 flex space-x-4">
<button
onClick={() => exportToCSV(items)}
className="bg-green-500 text-white px-4 py-2 rounded hover:bg-green-600"
>
Export Data as CSV
</button>
<button
onClick={() => exportChartToPNG('uncertainty-matrix-chart', 'uncertainty-matrix.png')}
className="bg-purple-500 text-white px-4 py-2 rounded hover:bg-purple-600"
>
Export Chart as PNG
</button>
</div>
<div className="mt-8">
<Callout title="Understanding the Matrix">
<p className="mb-2">The matrix is divided into four quadrants:</p>
<ul className="list-disc pl-5 mb-2">
<li><strong>High Impact, High Uncertainty:</strong> Items that could have significant consequences but are hard to predict.</li>
<li><strong>High Impact, Low Uncertainty:</strong> Items with predictable but significant outcomes.</li>
<li><strong>Low Impact, High Uncertainty:</strong> Items with unpredictable but limited consequences.</li>
<li><strong>Low Impact, Low Uncertainty:</strong> Items with predictable and limited outcomes.</li>
</ul>
<p>Use this visualization to prioritize items and allocate resources appropriately.</p>
</Callout>
</div>
</div>
);
};
export default App;
src/main.tsx
typescript
import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App';
import './styles.css';
ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<App />
</React.StrictMode>
);
6. README.md
markdown
# Uncertainty Matrix Web Application
A tool for visualizing items based on their impact and uncertainty scores.
## Features
- Add and remove items with custom names
- Adjust impact and uncertainty scores with sliders
- Real-time visualization on a 2D matrix
- Quadrant-based summary statistics
- Export functionality for data and charts
## Getting Started
### Prerequisites
- Node.js (v16 or later)
- npm or yarn
### Installation
1. Clone the repository
2. Install dependencies:
```bash
npm install
Start the development server:
bash
npm run dev
Usage
Add items by entering names and clicking "Add Item"
Adjust the impact and uncertainty sliders for each item
View the real-time updates on the matrix and summary table
Export your data or chart as needed
Extending the Application
Adding More Axes
To add more dimensions to the analysis:
Add new properties to the MatrixItem type
Create additional input controls in the MatrixInputForm component
Update the visualization to incorporate the new dimensions (consider using a radar chart or parallel coordinates plot)
Adding Qualitative Annotations
To add qualitative data:
Add a text field to each item for notes/annotations
Update the tooltip in the chart to display this information
Consider adding a modal for more detailed annotations
Testing
Run the test suite with:
bash
npm test
Design Rationale
Library Choices
React + TypeScript: Provides a robust foundation with type safety for better maintainability
Recharts: Offers a good balance between simplicity and customization for data visualization
Tailwind CSS: Enables rapid UI development with utility-first styling
Minimal Inputs
The application starts with just two example items to:
Reduce cognitive load for new users
Provide immediate visual feedback
Demonstrate the tool's capabilities without overwhelming users
Bias Awareness
The sliders use a 0-10 scale with a midpoint at 5 to:
Provide a clear boundary between quadrants
Avoid anchoring bias by not labeling the midpoint as "neutral"
Use consistent increments to prevent scale compression bias
Potential Extensions
Multi-axis support: Add more dimensions to the analysis
Collaboration features: Allow multiple users to contribute to the same matrix
Historical tracking: Save and compare different versions of the matrix over time
Advanced filtering: Filter items based on various criteria
Custom quadrant boundaries: Allow users to adjust the quadrant boundaries
code
## Design Rationale and Implementation Notes
1. **Component Structure**:
- I've organized the application into clear, modular components with well-defined responsibilities.
- The `MatrixInputForm` handles all user input and item management.
- The `UncertaintyMatrixChart` focuses solely on visualization.
- The `SummaryTable` displays calculated statistics.
- The `Callout` component provides reusable help/information boxes.
2. **State Management**:
- Used React's built-in hooks (`useState`, `useEffect`) for state management since the application is relatively simple.
- The parent `App` component maintains the state and passes down necessary props to child components.
- The `useEffect` hook recalculates quadrant statistics whenever items change.
3. **Visualization**:
- Chose Recharts over D3.js for its simplicity and React integration.
- The scatter plot clearly shows the relationship between impact and uncertainty.
- Reference lines at the midpoint (5) visually divide the chart into quadrants.
- Custom tooltips provide additional information when hovering over points.
4. **User Experience**:
- Default items provide immediate feedback and demonstrate functionality.
- Sliders with numeric displays make it easy to adjust values precisely.
- Callout components provide contextual help without overwhelming the interface.
- Export functionality allows users to save their work.
5. **Type Safety**:
- Used TypeScript to define clear interfaces for all data structures.
- This helps prevent errors and makes the code more maintainable.
6. **Responsive Design**:
- Used Tailwind CSS for responsive styling that works on different screen sizes.
- The layout adapts to show components side-by-side on larger screens and stacked on mobile.
7. **Performance Considerations**:
- The application is designed to be reactive, updating the visualization immediately when inputs change.
- Calculations are optimized to run only when necessary (using `useEffect` dependencies).
This implementation provides a solid foundation that can be extended with additional features as needed while maintaining good performance and user experience.