forked from OPCODE-Open-Spring-Fest/Algo-Visualizer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHeapVisualizer.jsx
More file actions
53 lines (48 loc) · 1.58 KB
/
HeapVisualizer.jsx
File metadata and controls
53 lines (48 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import React from "react";
import { motion, AnimatePresence } from "framer-motion";
function getHeapLevels(heap) {
const result = [];
let levelStart = 0;
let levelSize = 1;
while (levelStart < heap.length) {
result.push(heap.slice(levelStart, levelStart + levelSize));
levelStart += levelSize;
levelSize *= 2;
}
return result;
}
export default function HeapVisualizer({ heap }) {
const levels = getHeapLevels(heap);
return (
<div className="flex flex-col items-center mt-10 space-y-8">
<AnimatePresence>
{levels.map((level, i) => (
<motion.div
key={i}
className="flex justify-center space-x-8"
initial={{ opacity: 0, y: 30 }}
animate={{ opacity: 1, y: 0 }}
exit={{ opacity: 0, y: -30 }}
transition={{ duration: 0.4 }}
>
{level.map((val, j) => (
<motion.div
key={`${i}-${j}-${val}`}
layout
initial={{ scale: 0, opacity: 0 }}
animate={{ scale: 1, opacity: 1 }}
exit={{ scale: 0, opacity: 0 }}
transition={{ duration: 0.4 }}
className="bg-gradient-to-r from-purple-500 to-indigo-500 text-white font-semibold
w-16 h-16 flex items-center justify-center rounded-2xl shadow-md
transition-all duration-300 transform hover:scale-105"
>
{val}
</motion.div>
))}
</motion.div>
))}
</AnimatePresence>
</div>
);
}