summaryrefslogtreecommitdiff
path: root/src/components/Graph.tsx
diff options
context:
space:
mode:
authorYuren Hao <97327730+YurenHao0426@users.noreply.github.com>2025-08-06 02:01:22 -0700
committerGitHub <noreply@github.com>2025-08-06 02:01:22 -0700
commite5cbd188c6fc654e8ababd37922c018bc8527c44 (patch)
treeaa89a6d2998ecfc60254e17fd0d3cdb5449a8248 /src/components/Graph.tsx
parent79ec5fd1f0188a88f937737185c542e644cf98e4 (diff)
parentcaa18e81e8eb03fb03a82d0d3526994c9ba41ac2 (diff)
Merge pull request #1 from YurenHao0426/codex/test-uiuc-api-cors-response
feat: scaffold prereq graph project
Diffstat (limited to 'src/components/Graph.tsx')
-rw-r--r--src/components/Graph.tsx49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/components/Graph.tsx b/src/components/Graph.tsx
new file mode 100644
index 0000000..5e81b38
--- /dev/null
+++ b/src/components/Graph.tsx
@@ -0,0 +1,49 @@
+import CytoscapeComponent from "react-cytoscapejs";
+import cytoscape from "cytoscape";
+import dagre from "cytoscape-dagre";
+import { useMemo } from "react";
+
+cytoscape.use(dagre);
+
+type Catalog = Record<string, string[]>;
+
+export default function Graph({ catalog }: { catalog: Catalog }) {
+ const elements = useMemo(() => {
+ const els: any[] = [];
+ Object.keys(catalog).forEach(id => {
+ els.push({ data: { id } });
+ catalog[id].forEach(p =>
+ els.push({
+ data: { id: `${p}->${id}`, source: p, target: id }
+ })
+ );
+ });
+ return els;
+ }, [catalog]);
+
+ return (
+ <CytoscapeComponent
+ elements={elements}
+ stylesheet={[
+ {
+ selector: "node",
+ style: {
+ "background-color": "#3182bd",
+ label: "data(id)",
+ color: "#fff"
+ }
+ },
+ {
+ selector: "edge",
+ style: {
+ width: 2,
+ "target-arrow-shape": "triangle",
+ "curve-style": "bezier"
+ }
+ }
+ ]}
+ layout={{ name: "dagre", rankDir: "TB", nodeSep: 30, rankSep: 50 }}
+ style={{ width: "100%", height: "90vh" }}
+ />
+ );
+}