Skip to content

Commit c989f8b

Browse files
authored
Merge pull request #50 from SujalTripathi/feat/dp-visualizer-ui
feat: Create initial UI for DP Visualizer
2 parents 2636196 + a695db5 commit c989f8b

File tree

1 file changed

+98
-17
lines changed

1 file changed

+98
-17
lines changed
Lines changed: 98 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,109 @@
11
import React, { useState } from 'react';
2-
import { useTheme } from '../contexts/ThemeContext';
2+
import { Play, RotateCcw, Puzzle, Hash } from 'lucide-react';
33

44
const DPVisualizer = () => {
5-
const { classes, getThemedGradient } = useTheme();
6-
const [algorithm, setAlgorithm] = useState('lcs');
7-
5+
const [selectedProblem, setSelectedProblem] = useState('fibonacci');
6+
const [inputValue, setInputValue] = useState(8); // Example: n for Fibonacci
7+
8+
const handleVisualize = () => console.log('Visualize clicked!', { selectedProblem, inputValue });
9+
const handleReset = () => {
10+
setInputValue(0);
11+
console.log('Reset clicked!');
12+
};
13+
814
return (
9-
<div className={`min-h-screen transition-all duration-500 py-8 ${classes.bgGradient}`}>
10-
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 space-y-6">
11-
<div className={`${classes.cardBg} border rounded-xl shadow-soft p-6`}>
12-
<h1 className={`text-3xl font-bold ${classes.textPrimary} mb-2`}>
13-
Dynamic Programming Visualizer
14-
</h1>
15-
<p className={classes.textSecondary}>
16-
Visualize dynamic programming algorithms and optimization problems
17-
</p>
18-
</div>
15+
<div className="w-full min-h-screen bg-slate-50 p-4 sm:p-8">
16+
{/* Spacer div */}
17+
<div className="h-24"></div>
18+
19+
{/* 1. Gradient Header Card */}
20+
<div className="max-w-7xl mx-auto p-6 mb-8 bg-gradient-to-r from-blue-500 to-purple-600 rounded-xl shadow-lg">
21+
<h1 className="text-4xl font-bold text-white tracking-tight">
22+
Dynamic Programming Visualizer
23+
</h1>
24+
<p className="mt-2 text-blue-100">
25+
Visualize dynamic programming algorithms and optimization problems.
26+
</p>
27+
</div>
28+
29+
<div className="max-w-7xl mx-auto grid grid-cols-1 lg:grid-cols-3 gap-8">
1930

20-
<div className={`${classes.cardBg} border rounded-xl shadow-soft p-6`}>
21-
<p className={classes.textSecondary}>DP visualizer coming soon...</p>
31+
{/* 2. Left Column: Inputs & Controls Card */}
32+
<div className="lg:col-span-1">
33+
<div className="bg-white p-6 rounded-xl shadow-md border border-slate-200">
34+
<h2 className="text-xl font-bold text-slate-800 mb-6 flex items-center gap-2">
35+
<Puzzle size={22} className="text-indigo-500" />
36+
Problem & Controls
37+
</h2>
38+
39+
{/* Problem Selection */}
40+
<div className="mb-4">
41+
<label htmlFor="dp-problem" className="block text-sm font-medium text-slate-600 mb-2">
42+
Select a Problem
43+
</label>
44+
<select
45+
id="dp-problem"
46+
value={selectedProblem}
47+
onChange={(e) => setSelectedProblem(e.target.value)}
48+
className="w-full p-3 bg-slate-100 text-slate-800 rounded-lg border border-slate-300 focus:outline-none focus:ring-2 focus:ring-indigo-500"
49+
>
50+
<option value="fibonacci">Fibonacci Sequence</option>
51+
<option value="knapsack">0/1 Knapsack</option>
52+
<option value="lcs">Longest Common Subsequence</option>
53+
</select>
54+
</div>
55+
56+
{/* Conditional Inputs based on selected problem */}
57+
<div className="mb-6">
58+
<label htmlFor="main-input" className="block text-sm font-medium text-slate-600 mb-2">
59+
Input (n)
60+
</label>
61+
<input
62+
id="main-input"
63+
type="number"
64+
value={inputValue}
65+
onChange={(e) => setInputValue(Number(e.target.value))}
66+
className="w-full p-3 bg-slate-100 text-slate-800 placeholder-slate-400 rounded-lg border border-slate-300 focus:outline-none focus:ring-2 focus:ring-indigo-500 transition"
67+
placeholder="Enter a number..."
68+
/>
69+
</div>
70+
71+
{/* Buttons */}
72+
<div className="flex flex-col sm:flex-row gap-4">
73+
<button
74+
onClick={handleVisualize}
75+
className="flex flex-1 items-center justify-center gap-2 bg-indigo-600 hover:bg-indigo-700 text-white font-semibold py-3 px-4 rounded-lg transition-transform transform hover:scale-105 shadow-md"
76+
>
77+
<Play size={20} />
78+
Visualize
79+
</button>
80+
<button
81+
onClick={handleReset}
82+
className="flex flex-1 items-center justify-center gap-2 bg-slate-500 hover:bg-slate-600 text-white font-semibold py-3 px-4 rounded-lg transition-transform transform hover:scale-105 shadow-md"
83+
>
84+
<RotateCcw size={20} />
85+
Reset
86+
</button>
87+
</div>
88+
</div>
2289
</div>
90+
91+
{/* 3. Right Column: Display Area Card */}
92+
<div className="lg:col-span-2">
93+
<div className="bg-white p-6 rounded-xl shadow-md border border-slate-200 min-h-[300px]">
94+
<h2 className="text-xl font-bold text-slate-800 mb-6 flex items-center gap-2">
95+
<Hash size={22} className="text-indigo-500" />
96+
Visualization
97+
</h2>
98+
<div className="p-4 bg-slate-100 rounded-lg text-center text-slate-500">
99+
The visualization area for the {selectedProblem} problem will appear here.
100+
</div>
101+
</div>
102+
</div>
103+
23104
</div>
24105
</div>
25106
);
26107
};
27108

28-
export default DPVisualizer;
109+
export default DPVisualizer;

0 commit comments

Comments
 (0)