Spaces:
Running
Running
Commit
·
fc5fea2
1
Parent(s):
e707a20
formatting issues
Browse files- src/components/force-directed-graph.tsx +63 -157
- src/components/runs-list.tsx +1 -1
- src/components/viewer-tab.tsx +13 -39
src/components/force-directed-graph.tsx
CHANGED
@@ -55,6 +55,51 @@ export default function ForceDirectedGraph({
|
|
55 |
}>({ nodes: [], links: [] });
|
56 |
const containerRef = useRef<HTMLDivElement>(null);
|
57 |
const graphRef = useRef<ForceGraphMethods<GraphNode, GraphLink>>(null);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
|
59 |
// Build graph data ONLY when runs change, not when runId changes
|
60 |
useEffect(() => {
|
@@ -113,23 +158,6 @@ export default function ForceDirectedGraph({
|
|
113 |
nodeObj.fy = centerY + radius * Math.sin(angle * index);
|
114 |
});
|
115 |
|
116 |
-
// for (let i = 0; i < 10; i++) {
|
117 |
-
// nodes.push({ id: `node${i}`, type: i === 0 || i === 9 ? "fixed" : "fluid", radius: 5, runIds: [0] });
|
118 |
-
// }
|
119 |
-
|
120 |
-
// for (let i = 0; i < 9; i++) {
|
121 |
-
// links.push({
|
122 |
-
// source: `node${i}`,
|
123 |
-
// target: `node${i + 1}`,
|
124 |
-
// runId: 0,
|
125 |
-
// });
|
126 |
-
// }
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
const tmpGraphData: { nodes: GraphNode[]; links: GraphLink[] } = {
|
134 |
nodes: Array.from(nodesMap.values()),
|
135 |
links: linksList,
|
@@ -138,139 +166,7 @@ export default function ForceDirectedGraph({
|
|
138 |
setGraphData(tmpGraphData);
|
139 |
|
140 |
return;
|
141 |
-
|
142 |
-
// nodes: [],
|
143 |
-
// links: [],
|
144 |
-
// };
|
145 |
-
// const nodesMap = new Map<string, GraphNode>();
|
146 |
-
// const linksList: GraphLink[] = [];
|
147 |
-
// // const mainNodeSet: Set<GraphNode> = new Set();
|
148 |
-
|
149 |
-
// // First identify all main nodes (start and destination)
|
150 |
-
// // runs.forEach((run, runIndex) => {
|
151 |
-
// // mainNodeSet.add({
|
152 |
-
// // id: run.start_article,
|
153 |
-
// // type: "fixed",
|
154 |
-
// // radius: 7,
|
155 |
-
// // runIds: [runIndex],
|
156 |
-
// // isMainNode: true,
|
157 |
-
// // });
|
158 |
-
// // mainNodeSet.add({
|
159 |
-
// // id: run.destination_article,
|
160 |
-
// // type: "fixed",
|
161 |
-
// // radius: 7,
|
162 |
-
// // runIds: [runIndex],
|
163 |
-
// // isMainNode: true,
|
164 |
-
// // });
|
165 |
-
// // });
|
166 |
-
|
167 |
-
// // Process all runs to build data with metadata
|
168 |
-
// runs.forEach((run, runIndex) => {
|
169 |
-
// for (let i = 0; i < run.steps.length - 1; i++) {
|
170 |
-
// const step = run.steps[i];
|
171 |
-
// const nextStep = run.steps[i + 1];
|
172 |
-
|
173 |
-
// // Update or create source node
|
174 |
-
// if (!nodesMap.has(step.article)) {
|
175 |
-
// const isMainNode = i === 0 || i === run.steps.length - 2;
|
176 |
-
// nodesMap.set(step.article, {
|
177 |
-
// id: step.article,
|
178 |
-
// type: isMainNode ? "fixed" : "fluid",
|
179 |
-
// radius: isMainNode ? 7 : 5,
|
180 |
-
// runIds: [runIndex],
|
181 |
-
// isMainNode,
|
182 |
-
// });
|
183 |
-
// } else {
|
184 |
-
// const node = nodesMap.get(step.article)!;
|
185 |
-
// if (!node.runIds.includes(runIndex)) {
|
186 |
-
// node.runIds.push(runIndex);
|
187 |
-
// }
|
188 |
-
// }
|
189 |
-
|
190 |
-
// // Update or create target node
|
191 |
-
// if (!nodesMap.has(nextStep.article)) {
|
192 |
-
// const isMainNode = i === 0;
|
193 |
-
// nodesMap.set(nextStep.article, {
|
194 |
-
// id: nextStep.article,
|
195 |
-
// type: isMainNode ? "fixed" : "fluid",
|
196 |
-
// radius: isMainNode ? 7 : 5,
|
197 |
-
// runIds: [runIndex],
|
198 |
-
// isMainNode,
|
199 |
-
// });
|
200 |
-
// } else {
|
201 |
-
// const node = nodesMap.get(nextStep.article)!;
|
202 |
-
// if (!node.runIds.includes(runIndex)) {
|
203 |
-
// node.runIds.push(runIndex);
|
204 |
-
// }
|
205 |
-
// }
|
206 |
-
|
207 |
-
// // Create or update link
|
208 |
-
// const linkId = `${step.article}->${nextStep.article}`;
|
209 |
-
// linksList.push({
|
210 |
-
// source: step.article,
|
211 |
-
// target: nextStep.article,
|
212 |
-
// runId: runIndex,
|
213 |
-
// id: linkId,
|
214 |
-
// });
|
215 |
-
|
216 |
-
// // if (!linksMap.has(linkId)) {
|
217 |
-
// // linksMap.set(linkId, {
|
218 |
-
// // source: step.article,
|
219 |
-
// // target: nextStep.article,
|
220 |
-
// // runIds: [runIndex],
|
221 |
-
// // id: linkId
|
222 |
-
// // });
|
223 |
-
// // } else {
|
224 |
-
// // const link = linksMap.get(linkId)!;
|
225 |
-
// // if (!link.runIds.includes(runIndex)) {
|
226 |
-
// // link.runIds.push(runIndex);
|
227 |
-
// // }
|
228 |
-
// // }
|
229 |
-
// }
|
230 |
-
// });
|
231 |
-
|
232 |
-
// // Position main nodes in a circle
|
233 |
-
// // const mainNodes = Array.from(mainNodeSet);
|
234 |
-
// const radius = 400; // Radius of the circle
|
235 |
-
// const centerX = 0; // Center X coordinate
|
236 |
-
// const centerY = 0; // Center Y coordinate
|
237 |
-
|
238 |
-
// const mainNodes = Array.from(nodesMap.values()).filter(
|
239 |
-
// (node) => node.type === "fixed"
|
240 |
-
// );
|
241 |
-
|
242 |
-
// mainNodes.forEach((node, index) => {
|
243 |
-
// const angle = (index * 2 * Math.PI) / mainNodes.length;
|
244 |
-
// if (node) {
|
245 |
-
// node.fx = centerX + radius * Math.cos(angle);
|
246 |
-
// node.fy = centerY + radius * Math.sin(angle);
|
247 |
-
// }
|
248 |
-
// });
|
249 |
-
|
250 |
-
// // Convert maps to arrays for the graph
|
251 |
-
// newGraphData.nodes = Array.from(nodesMap.values());
|
252 |
-
// newGraphData.links = linksList;
|
253 |
-
|
254 |
-
// // Convert string IDs to actual node objects in links
|
255 |
-
// newGraphData.links = linksList
|
256 |
-
// .map((link) => {
|
257 |
-
// const sourceNode = nodesMap.get(link.source as string);
|
258 |
-
// const targetNode = nodesMap.get(link.target as string);
|
259 |
-
|
260 |
-
// // Only create links when both nodes exist
|
261 |
-
// if (sourceNode && targetNode) {
|
262 |
-
// return {
|
263 |
-
// ...link,
|
264 |
-
// source: sourceNode,
|
265 |
-
// target: targetNode,
|
266 |
-
// };
|
267 |
-
// }
|
268 |
-
// // Skip this link if nodes don't exist
|
269 |
-
// return null;
|
270 |
-
// })
|
271 |
-
// .filter(Boolean) as GraphLink[];
|
272 |
-
|
273 |
-
// setGraphData(newGraphData);
|
274 |
}, [runs]); // Only depends on runs, not runId
|
275 |
|
276 |
// Set up the force simulation
|
@@ -289,7 +185,7 @@ export default function ForceDirectedGraph({
|
|
289 |
"link",
|
290 |
d3
|
291 |
.forceLink(graphData.links)
|
292 |
-
.id((d:
|
293 |
.distance(linkDistance)
|
294 |
.strength(0.9)
|
295 |
);
|
@@ -305,7 +201,7 @@ export default function ForceDirectedGraph({
|
|
305 |
"collide",
|
306 |
d3
|
307 |
.forceCollide()
|
308 |
-
.radius((d:
|
309 |
);
|
310 |
graphRef.current.d3Force("center", d3.forceCenter(0, 0));
|
311 |
|
@@ -319,6 +215,13 @@ export default function ForceDirectedGraph({
|
|
319 |
}
|
320 |
}, [graphData]);
|
321 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
322 |
// Full page resize handler
|
323 |
useEffect(() => {
|
324 |
const handleResize = () => {
|
@@ -368,15 +271,14 @@ export default function ForceDirectedGraph({
|
|
368 |
};
|
369 |
|
370 |
return (
|
371 |
-
<div className="w-full h-full flex items-center justify-center">
|
372 |
-
<div ref={containerRef} className="w-full h-full">
|
373 |
<ForceGraph2D
|
374 |
ref={graphRef}
|
375 |
graphData={graphData}
|
376 |
nodeLabel="id"
|
377 |
nodeColor={getNodeColor}
|
378 |
linkColor={getLinkColor}
|
379 |
-
// nodeRelSize={getNodeSize}
|
380 |
linkWidth={(link) => {
|
381 |
return isLinkInCurrentRun(link) ? 4 : 1;
|
382 |
}}
|
@@ -430,8 +332,12 @@ export default function ForceDirectedGraph({
|
|
430 |
ctx.fillText(label, node.x!, node.y! + 8 + fontSize / 2);
|
431 |
}
|
432 |
}}
|
433 |
-
width={containerRef.current?.clientWidth || 800}
|
434 |
-
height={containerRef.current?.clientHeight || 800}
|
|
|
|
|
|
|
|
|
435 |
/>
|
436 |
</div>
|
437 |
</div>
|
|
|
55 |
}>({ nodes: [], links: [] });
|
56 |
const containerRef = useRef<HTMLDivElement>(null);
|
57 |
const graphRef = useRef<ForceGraphMethods<GraphNode, GraphLink>>(null);
|
58 |
+
const [dimensions, setDimensions] = useState({ width: 0, height: 0 });
|
59 |
+
|
60 |
+
// Track container dimensions
|
61 |
+
useEffect(() => {
|
62 |
+
if (!containerRef.current) return;
|
63 |
+
|
64 |
+
const updateDimensions = () => {
|
65 |
+
if (containerRef.current) {
|
66 |
+
const parent = containerRef.current.parentElement;
|
67 |
+
const width = parent ? parent.clientWidth : containerRef.current.clientWidth;
|
68 |
+
const height = parent ? parent.clientHeight : containerRef.current.clientHeight;
|
69 |
+
|
70 |
+
// Constrain dimensions to reasonable values
|
71 |
+
const constrainedWidth = Math.min(width, window.innerWidth);
|
72 |
+
const constrainedHeight = Math.min(height, window.innerHeight);
|
73 |
+
|
74 |
+
setDimensions({
|
75 |
+
width: constrainedWidth,
|
76 |
+
height: constrainedHeight,
|
77 |
+
});
|
78 |
+
}
|
79 |
+
};
|
80 |
+
|
81 |
+
// Initial measurement
|
82 |
+
updateDimensions();
|
83 |
+
|
84 |
+
// Set up resize observer
|
85 |
+
const resizeObserver = new ResizeObserver(updateDimensions);
|
86 |
+
resizeObserver.observe(containerRef.current);
|
87 |
+
|
88 |
+
if (containerRef.current.parentElement) {
|
89 |
+
resizeObserver.observe(containerRef.current.parentElement);
|
90 |
+
}
|
91 |
+
|
92 |
+
// Clean up
|
93 |
+
return () => {
|
94 |
+
if (containerRef.current) {
|
95 |
+
resizeObserver.unobserve(containerRef.current);
|
96 |
+
if (containerRef.current.parentElement) {
|
97 |
+
resizeObserver.unobserve(containerRef.current.parentElement);
|
98 |
+
}
|
99 |
+
}
|
100 |
+
resizeObserver.disconnect();
|
101 |
+
};
|
102 |
+
}, []);
|
103 |
|
104 |
// Build graph data ONLY when runs change, not when runId changes
|
105 |
useEffect(() => {
|
|
|
158 |
nodeObj.fy = centerY + radius * Math.sin(angle * index);
|
159 |
});
|
160 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
161 |
const tmpGraphData: { nodes: GraphNode[]; links: GraphLink[] } = {
|
162 |
nodes: Array.from(nodesMap.values()),
|
163 |
links: linksList,
|
|
|
166 |
setGraphData(tmpGraphData);
|
167 |
|
168 |
return;
|
169 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
170 |
}, [runs]); // Only depends on runs, not runId
|
171 |
|
172 |
// Set up the force simulation
|
|
|
185 |
"link",
|
186 |
d3
|
187 |
.forceLink(graphData.links)
|
188 |
+
.id((d: GraphNode) => d.id)
|
189 |
.distance(linkDistance)
|
190 |
.strength(0.9)
|
191 |
);
|
|
|
201 |
"collide",
|
202 |
d3
|
203 |
.forceCollide()
|
204 |
+
.radius((d: GraphNode) => (d.radius || 5) + COLLISION_PADDING)
|
205 |
);
|
206 |
graphRef.current.d3Force("center", d3.forceCenter(0, 0));
|
207 |
|
|
|
215 |
}
|
216 |
}, [graphData]);
|
217 |
|
218 |
+
// Recenter graph when dimensions change
|
219 |
+
useEffect(() => {
|
220 |
+
if (dimensions.width > 0 && dimensions.height > 0 && graphRef.current) {
|
221 |
+
graphRef.current.zoomToFit(400);
|
222 |
+
}
|
223 |
+
}, [dimensions]);
|
224 |
+
|
225 |
// Full page resize handler
|
226 |
useEffect(() => {
|
227 |
const handleResize = () => {
|
|
|
271 |
};
|
272 |
|
273 |
return (
|
274 |
+
<div className="w-full h-full flex items-center justify-center relative overflow-hidden">
|
275 |
+
<div ref={containerRef} className="w-full h-full absolute inset-0">
|
276 |
<ForceGraph2D
|
277 |
ref={graphRef}
|
278 |
graphData={graphData}
|
279 |
nodeLabel="id"
|
280 |
nodeColor={getNodeColor}
|
281 |
linkColor={getLinkColor}
|
|
|
282 |
linkWidth={(link) => {
|
283 |
return isLinkInCurrentRun(link) ? 4 : 1;
|
284 |
}}
|
|
|
332 |
ctx.fillText(label, node.x!, node.y! + 8 + fontSize / 2);
|
333 |
}
|
334 |
}}
|
335 |
+
width={dimensions.width || containerRef.current?.clientWidth || 800}
|
336 |
+
height={dimensions.height || containerRef.current?.clientHeight || 800}
|
337 |
+
enableNodeDrag={true}
|
338 |
+
enableZoomInteraction={true}
|
339 |
+
cooldownTicks={100}
|
340 |
+
cooldownTime={2000}
|
341 |
/>
|
342 |
</div>
|
343 |
</div>
|
src/components/runs-list.tsx
CHANGED
@@ -21,7 +21,7 @@ export default function RunsList({
|
|
21 |
selectedRunId,
|
22 |
}: RunsListProps) {
|
23 |
return (
|
24 |
-
<div className="h-
|
25 |
{runs.map((run, index) => (
|
26 |
<Card
|
27 |
key={index}
|
|
|
21 |
selectedRunId,
|
22 |
}: RunsListProps) {
|
23 |
return (
|
24 |
+
<div className="h-full w-full overflow-y-auto overflow-x-hidden space-y-2 pr-1">
|
25 |
{runs.map((run, index) => (
|
26 |
<Card
|
27 |
key={index}
|
src/components/viewer-tab.tsx
CHANGED
@@ -25,11 +25,6 @@ type Run = {
|
|
25 |
hops: number;
|
26 |
};
|
27 |
|
28 |
-
const datasets = [
|
29 |
-
{ id: "dataset1", name: "Eureka-Lab/PHYBench" },
|
30 |
-
{ id: "dataset2", name: "Eureka-Lab/PHYBench-LLM" },
|
31 |
-
];
|
32 |
-
|
33 |
export default function ViewerTab() {
|
34 |
const [selectedDataset, setSelectedDataset] = useState<string>("");
|
35 |
const [selectedRun, setSelectedRun] = useState<number | null>(null);
|
@@ -84,48 +79,27 @@ export default function ViewerTab() {
|
|
84 |
}, [runs]);
|
85 |
|
86 |
return (
|
87 |
-
<div className="grid grid-cols-1 md:grid-cols-12 gap-4">
|
88 |
-
<div className="md:col-span-3">
|
89 |
-
|
90 |
-
<
|
91 |
-
<SelectTrigger className="w-full">
|
92 |
-
<SelectValue placeholder="SELECT DATASET" />
|
93 |
-
</SelectTrigger>
|
94 |
-
<SelectContent>
|
95 |
-
{datasets.map((dataset) => (
|
96 |
-
<SelectItem key={dataset.id} value={dataset.id}>
|
97 |
-
{dataset.name}
|
98 |
-
</SelectItem>
|
99 |
-
))}
|
100 |
-
</SelectContent>
|
101 |
-
</Select>
|
102 |
-
<Button onClick={fetchDataset}>Fetch Dataset</Button>
|
103 |
-
{loading && <p>Loading...</p>}
|
104 |
-
</div> */}
|
105 |
-
|
106 |
-
<div className="bg-card rounded-lg p-3 border">
|
107 |
-
<h3 className="text-sm font-medium mb-2 text-muted-foreground">
|
108 |
Available Runs
|
109 |
</h3>
|
110 |
-
<
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
|
|
|
|
115 |
</div>
|
116 |
</div>
|
117 |
|
118 |
-
<div className="md:col-span-
|
119 |
-
<Card className="
|
120 |
<ForceDirectedGraph runs={filterRuns} runId={selectedRun} />
|
121 |
</Card>
|
122 |
</div>
|
123 |
-
|
124 |
-
{/* <div className="md:col-span-4">
|
125 |
-
<Card className="w-full h-[600px] p-4">
|
126 |
-
<ReasoningTrace run={runs[selectedRun]} />
|
127 |
-
</Card>
|
128 |
-
</div> */}
|
129 |
</div>
|
130 |
);
|
131 |
}
|
|
|
25 |
hops: number;
|
26 |
};
|
27 |
|
|
|
|
|
|
|
|
|
|
|
28 |
export default function ViewerTab() {
|
29 |
const [selectedDataset, setSelectedDataset] = useState<string>("");
|
30 |
const [selectedRun, setSelectedRun] = useState<number | null>(null);
|
|
|
79 |
}, [runs]);
|
80 |
|
81 |
return (
|
82 |
+
<div className="grid grid-cols-1 md:grid-cols-12 gap-4 h-[calc(100vh-80px)] max-h-[calc(100vh-80px)] overflow-hidden p-2">
|
83 |
+
<div className="md:col-span-3 flex flex-col max-h-full overflow-hidden">
|
84 |
+
<div className="bg-card rounded-lg p-3 border flex-grow overflow-hidden flex flex-col">
|
85 |
+
<h3 className="text-sm font-medium mb-2 text-muted-foreground flex-shrink-0">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
Available Runs
|
87 |
</h3>
|
88 |
+
<div className="flex-grow overflow-hidden">
|
89 |
+
<RunsList
|
90 |
+
runs={filterRuns}
|
91 |
+
onSelectRun={handleRunSelect}
|
92 |
+
selectedRunId={selectedRun}
|
93 |
+
/>
|
94 |
+
</div>
|
95 |
</div>
|
96 |
</div>
|
97 |
|
98 |
+
<div className="md:col-span-9 max-h-full overflow-hidden">
|
99 |
+
<Card className="w-full h-full flex items-center justify-center p-0 m-0 overflow-hidden">
|
100 |
<ForceDirectedGraph runs={filterRuns} runId={selectedRun} />
|
101 |
</Card>
|
102 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
103 |
</div>
|
104 |
);
|
105 |
}
|