Skip to content

Commit 4a824de

Browse files
committed
limitless visualizer
1 parent 284beaf commit 4a824de

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/components/sorting/SelectionSortVisualizer.jsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ const COLORS = {
88
};
99

1010
export default function SelectionSortVisualizer({ array, highlight }) {
11+
const maxValue = Math.max(...array, 1); // Avoid division by zero
12+
const containerHeight = 288; // px (matches h-72)
13+
1114
return (
1215
<div className="flex items-end justify-center space-x-2 h-72 mt-10 transition-all duration-500">
1316
{array.map((value, idx) => {
@@ -19,7 +22,8 @@ export default function SelectionSortVisualizer({ array, highlight }) {
1922
if (highlight?.type === "swap" && highlight.indices?.includes(idx))
2023
color = COLORS.swap;
2124

22-
const height = Math.max(value * 5, 15); // Ensures visibility for small numbers
25+
// Normalize height relative to the maximum value
26+
const height = Math.max((value / maxValue) * containerHeight, 15); // minimum 15px for visibility
2327

2428
return (
2529
<div

0 commit comments

Comments
 (0)