-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
159 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import cytoscape, { CytoscapeOptions } from "cytoscape"; | ||
import { CytoscapeJsonStructure } from "~/lib/typings/cytoscape"; | ||
|
||
export const getCytoscapeConfig = ( | ||
container: HTMLElement | null, | ||
data: CytoscapeJsonStructure | ||
): CytoscapeOptions => { | ||
const theme = document.documentElement.getAttribute("data-theme") || "light"; | ||
const isDark = theme === "dark"; | ||
|
||
const nodeBackgroundColor = isDark ? "#555" : "#0074D9"; | ||
const nodeTextColor = isDark ? "#EEE" : "#A9A9A9"; | ||
const edgeColor = isDark ? "#888" : "#A9A9A9"; | ||
|
||
return { | ||
container, | ||
elements: data, | ||
layout: { | ||
name: "concentric", | ||
animate: false, | ||
padding: 10, | ||
avoidOverlap: true, | ||
fit: true, | ||
nodeDimensionsIncludeLabels: true, | ||
spacingFactor: 0.6, | ||
minNodeSpacing: 1, | ||
}, | ||
style: [ | ||
{ | ||
selector: "node", | ||
style: { | ||
label: (node: cytoscape.NodeSingular) => { | ||
const type = node.data("type"); | ||
return type === "container" | ||
? node.data("name") | ||
: node.data("hostName"); | ||
}, | ||
"background-image": (node: cytoscape.NodeSingular) => { | ||
const type = node.data("type"); | ||
if (type === "container") { | ||
return isDark | ||
? "/assets/_graph-icons/container-dark.svg" | ||
: "/assets/_graph-icons/container-light.svg"; | ||
} else { | ||
return isDark | ||
? "/assets/_graph-icons/server-dark.svg" | ||
: "/assets/_graph-icons/server-light.svg"; | ||
} | ||
}, | ||
"background-color": nodeBackgroundColor, | ||
"background-fit": "contain", | ||
"background-clip": "none", | ||
"background-opacity": 0, | ||
color: nodeTextColor, | ||
"text-valign": "bottom", | ||
"text-halign": "center", | ||
width: "40", | ||
height: "40", | ||
}, | ||
}, | ||
{ | ||
selector: "edge", | ||
style: { | ||
width: 1, | ||
"line-color": edgeColor, | ||
"curve-style": "bezier", | ||
}, | ||
}, | ||
], | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,59 @@ | ||
import { useState } from "react"; | ||
import { useState, useEffect } from "react"; | ||
import CytoscapeGraph from "~/components/cytoscape-graph"; | ||
import NodeDetailsModal from "~/components/node-details-modal"; | ||
import { getCytoscapeJson } from "~/lib/dataFetcher"; | ||
|
||
const elements = await getCytoscapeJson(); | ||
import { singleNodeData } from "~/lib/typings/cytoscape"; | ||
import { Loader2 } from "lucide-react"; | ||
|
||
export default function GraphPage() { | ||
const [isModalOpen, setIsModalOpen] = useState(false); | ||
const [selectedNodeData, setSelectedNodeData] = useState<any>(null); | ||
const [elements, setElements] = useState<unknown>(null); | ||
const [isLoading, setIsLoading] = useState(true); | ||
const [, setIsModalOpen] = useState(false); | ||
const [, setSelectedNodeData] = useState<singleNodeData | null>(null); | ||
|
||
useEffect(() => { | ||
const loadData = async () => { | ||
try { | ||
const data = await getCytoscapeJson(); | ||
setElements(JSON.parse(data)); | ||
} catch (error) { | ||
console.error("Error loading graph data:", error); | ||
} finally { | ||
setIsLoading(false); | ||
} | ||
}; | ||
|
||
loadData(); | ||
}, []); | ||
|
||
const handleNodeClick = (nodeData: any) => { | ||
const handleNodeClick = (nodeData: singleNodeData) => { | ||
if (!nodeData?.id) { | ||
console.error("Invalid node data:", nodeData); | ||
return; | ||
} | ||
setSelectedNodeData(nodeData); | ||
setIsModalOpen(true); | ||
}; | ||
|
||
return ( | ||
<> | ||
<div className="p-8 h-full"> | ||
<h1 className="text-2xl font-bold mb-4">Cytoscape Graph</h1> | ||
<CytoscapeGraph data={JSON.parse(elements)} /> | ||
<NodeDetailsModal | ||
isOpen={isModalOpen} | ||
onClose={() => setIsModalOpen(false)} | ||
nodeData={selectedNodeData} | ||
/> | ||
<div className="relative h-full p-8"> | ||
<div | ||
className={`absolute inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm transition-opacity duration-300 ${ | ||
isLoading ? "opacity-100" : "opacity-0 pointer-events-none" | ||
}`} | ||
> | ||
<Loader2 className="h-12 w-12 animate-spin text-primary" /> | ||
</div> | ||
|
||
<div> | ||
<h1 className="text-2xl font-bold mb-4">Raw Cytoscape Data</h1> | ||
<pre> | ||
<code>{elements}</code> | ||
</pre> | ||
<div | ||
className={`h-full transition-opacity duration-300 ${ | ||
isLoading ? "opacity-0" : "opacity-100" | ||
}`} | ||
> | ||
<h1 className="text-4xl font-bold mb-4">Container Graph</h1> | ||
{elements && ( | ||
<CytoscapeGraph data={elements} onNodeClick={handleNodeClick} /> | ||
)} | ||
</div> | ||
</> | ||
</div> | ||
); | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes