Skip to content

Commit 90cdf8a

Browse files
committed
feat: Replace MiniMap with traversal path display after DFS/BFS completion
1 parent b8c13f3 commit 90cdf8a

2 files changed

Lines changed: 60 additions & 6 deletions

File tree

src/components/GraphVisualizer.jsx

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import ReactFlow, {
1010
} from "reactflow";
1111
import "reactflow/dist/style.css";
1212
import { useGraphStore } from "../store/graphStore";
13+
import { TraversalPath } from "./TraversalPath";
1314

1415
const nodeTypes = {};
1516

@@ -139,12 +140,24 @@ export const GraphVisualizer = () => {
139140
>
140141
<Background color="#aaa" gap={16} />
141142
<Controls />
142-
<MiniMap
143-
nodeColor={(node) => getNodeColor(node.id, traversalState)}
144-
nodeStrokeWidth={3}
145-
zoomable
146-
pannable
147-
/>
143+
{traversalState.isComplete ? (
144+
<div style={{
145+
position: 'absolute',
146+
bottom: 20,
147+
right: 20,
148+
zIndex: 1000,
149+
maxWidth: 300
150+
}}>
151+
<TraversalPath />
152+
</div>
153+
) : (
154+
<MiniMap
155+
nodeColor={(node) => getNodeColor(node.id, traversalState)}
156+
nodeStrokeWidth={3}
157+
zoomable
158+
pannable
159+
/>
160+
)}
148161
</ReactFlow>
149162
</div>
150163
</Card>

src/components/TraversalPath.jsx

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import React from 'react';
2+
import { Card, Typography } from 'antd';
3+
import { useGraphStore } from '../store/graphStore';
4+
5+
const { Text } = Typography;
6+
7+
export const TraversalPath = () => {
8+
const { traversalState, algorithm } = useGraphStore();
9+
const { visitOrder, isComplete } = traversalState;
10+
11+
if (!visitOrder || visitOrder.length === 0) {
12+
return null;
13+
}
14+
15+
const pathString = visitOrder.join(' → ');
16+
17+
return (
18+
<Card
19+
title={`${algorithm} Traversal Path`}
20+
size="small"
21+
style={{ marginTop: 16 }}
22+
>
23+
<div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
24+
<Text strong>Path: </Text>
25+
<Text code style={{ fontSize: '14px' }}>
26+
{pathString}
27+
</Text>
28+
{isComplete && (
29+
<Text type="success" style={{ marginLeft: 8 }}>
30+
✓ Complete
31+
</Text>
32+
)}
33+
</div>
34+
<div style={{ marginTop: 8 }}>
35+
<Text type="secondary">
36+
Nodes visited: {visitOrder.length}
37+
</Text>
38+
</div>
39+
</Card>
40+
);
41+
};

0 commit comments

Comments
 (0)