Skip to content

Commit 9ca1f4c

Browse files
authored
Merge pull request #2 from yuxizhe/main
fix: improve graph rendering logic
2 parents 6e32ad7 + 50d7783 commit 9ca1f4c

File tree

1 file changed

+24
-41
lines changed

1 file changed

+24
-41
lines changed

hyperdb/templates/hypergraph_viewer.html

Lines changed: 24 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,16 @@
88
<script src="https://unpkg.com/react@18/umd/react.production.min.js"></script>
99
<script src="https://unpkg.com/react-dom@18/umd/react-dom.production.min.js"></script>
1010
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
11-
<script src="https://cdn.tailwindcss.com"></script>
11+
<script src="https://unpkg.com/@tailwindcss/browser@4"></script>
1212
<!-- <script src="./data.js"></script> -->
13-
<script>
14-
tailwind.config = {
15-
theme: {
16-
extend: {
17-
fontFamily: {
18-
sans: ['"Segoe UI"', "Tahoma", "Geneva", "Verdana", "sans-serif"],
19-
},
20-
backdropBlur: {
21-
xs: "2px",
22-
},
23-
colors: {
24-
primary: {
25-
50: "#faf5ff",
26-
500: "#8b5cf6",
27-
600: "#7c3aed",
28-
700: "#6d28d9",
29-
},
30-
},
31-
},
32-
},
33-
};
34-
</script>
13+
<style type="text/tailwindcss">
14+
@theme {
15+
--color-primary-50: #faf5ff;
16+
--color-primary-500: #8b5cf6;
17+
--color-primary-600: #7c3aed;
18+
--color-primary-700: #6d28d9;
19+
}
20+
</style>
3521
</head>
3622
<body>
3723
<div id="root"></div>
@@ -288,7 +274,7 @@
288274
},
289275
},
290276
layout: {
291-
type: "force",
277+
type: hyperData.nodes.length > 100 ? "force-atlas2" : "force",
292278
clustering: visualizationMode === "graph" ? false : true,
293279
preventOverlap: true,
294280
nodeClusterBy:
@@ -303,15 +289,12 @@
303289
useEffect(() => {
304290
if (!graphDataFormatted || !containerRef.current) return;
305291

306-
// 销毁之前的图形实例
307-
if (graphRef.current) {
308-
console.log(graphRef.current);
292+
// 销毁之前的图形实例并清空画布
293+
if (graphRef.current && !graphRef.current.destroyed) {
309294
graphRef.current.clear();
310-
graphRef.current.options.plugins = [];
311-
graphRef.current.destroy();
312-
// graphRef.current.stopLayout && graphRef.current.stopLayout(); // 停止布局
313-
// graphRef.current.destroy && graphRef.current.destroy();
314-
// graphRef.current = null;
295+
if (containerRef.current) {
296+
containerRef.current.innerHTML = "";
297+
}
315298
}
316299

317300
const graph = new Graph({
@@ -361,18 +344,18 @@
361344

362345
return () => {
363346
window.removeEventListener("resize", handleResize);
364-
if (graphRef.current) {
365-
// graphRef.current.clear();
366-
// graphRef.current.stopLayout && graphRef.current.stopLayout(); // 停止布局
367-
graphRef.current.destroy && graphRef.current.destroy();
368-
graphRef.current = null;
347+
if (graphRef.current && !graphRef.current.destroyed) {
348+
graphRef.current.clear();
349+
}
350+
if (containerRef.current) {
351+
containerRef.current.innerHTML = "";
369352
}
370353
};
371354
}, [graphDataFormatted, visualizationMode]);
372355

373356
return (
374357
<div className="flex h-screen bg-gradient-to-br from-gray-50 to-gray-100">
375-
<div className="w-80 bg-white/95 backdrop-blur-sm border-r border-gray-200/50 p-6 overflow-y-auto shadow-xl">
358+
<div className="w-80 h-screen overflow-hidden bg-white/95 backdrop-blur-sm border-r border-gray-200/50 p-6 shadow-xl">
376359
<h2 className="text-2xl font-bold text-gray-800 mb-6 flex items-center">
377360
Hypergraph-DB
378361
</h2>
@@ -473,7 +456,7 @@ <h2 className="text-2xl font-bold text-gray-800 mb-6 flex items-center">
473456
)}
474457
</div>
475458

476-
<div className=" overflow-y-auto border border-gray-200 rounded-xl bg-white shadow-inner">
459+
<div className="overflow-y-scroll hide-scrollbar h-[50vh] relative border border-gray-200 rounded-xl bg-white shadow-inner">
477460
{filteredVertices.length === 0 ? (
478461
<div className="p-4 text-center text-gray-500">
479462
{searchTerm
@@ -534,7 +517,7 @@ <h2 className="text-2xl font-bold text-gray-800 mb-6 flex items-center">
534517
</div>
535518

536519
<div className="flex-1 flex flex-col bg-white/10 backdrop-blur-sm">
537-
<div className="bg-white/95 p-6 border-b border-gray-200/50 flex justify-between items-center shadow-sm">
520+
<div className="bg-white/95 p-4 border-b border-gray-200/50 flex justify-between items-center shadow-sm">
538521
<div className="flex items-center gap-4">
539522
<h3 className="text-xl font-semibold text-gray-800 m-0">
540523
{visualizationMode === "hyper" ? "Hypergraph" : "Graph"}{" "}
@@ -610,7 +593,7 @@ <h3 className="text-xl font-semibold text-gray-800 m-0">
610593
{!loading && (
611594
<div
612595
ref={containerRef}
613-
className="w-full min-h-[95vh] rounded-xl"
596+
className="w-full h-[calc(100vh-100px)] rounded-xl"
614597
/>
615598
)}
616599
</div>

0 commit comments

Comments
 (0)