-
Notifications
You must be signed in to change notification settings - Fork 110
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
1 parent
96eb246
commit 334637b
Showing
13 changed files
with
331 additions
and
1,060 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
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
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 |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import "@xyflow/react/dist/style.css"; | ||
import "./react-flow.css"; | ||
import {Background, Controls, ReactFlow, ReactFlowProvider, useEdgesState, useNodesState} from "@xyflow/react"; | ||
import {VisualOverview} from "./model/visualizer.ts"; | ||
import {useEffect} from "react"; | ||
import {stratify, tree} from "d3-hierarchy"; | ||
|
||
interface VisualizerProps { | ||
overview: VisualOverview; | ||
} | ||
|
||
const Visualizer = ({ overview }: VisualizerProps) => { | ||
const [nodes, setNodes, onNodesChange] = useNodesState([]); | ||
const [edges, setEdges, onEdgesChange] = useEdgesState([]); | ||
|
||
const layout = (nodes, edges): VisualOverview => { | ||
if(!nodes) { | ||
return { nodes: [], edges: [] }; | ||
} | ||
let g = tree(); | ||
if(nodes.length === 0) return { nodes, edges }; | ||
// const { width, height } = document.querySelector(`[data-id="$nodes[0].id"]`).getBoundingClientRect(); | ||
const width = 100; | ||
const height = 40; | ||
const hierarchy = stratify() | ||
.id((node) => node.id) | ||
.parentId((node) => edges.find((edge) => edge.target === node.id)?.source); | ||
const root = hierarchy(nodes); | ||
const layout = g.nodeSize([width * 2, height * 2])(root); | ||
return { | ||
nodes: layout | ||
.descendants() | ||
.map((node) => ({ ...node.data, position: { x: node.x, y: node.y }})), | ||
edges, | ||
} | ||
} | ||
|
||
useEffect(() => { | ||
let layouted = layout(overview.nodes, overview.edges); | ||
setNodes(layouted.nodes); | ||
setEdges(layouted.edges); | ||
}, [overview]); | ||
|
||
return ( | ||
<ReactFlow | ||
nodes={nodes} | ||
edges={edges} | ||
onNodesChange={onNodesChange} | ||
onEdgesChange={onEdgesChange} | ||
fitView | ||
> | ||
<Background/> | ||
<Controls /> | ||
</ReactFlow> | ||
); | ||
} | ||
|
||
export default ({ overview }: VisualizerProps) => { | ||
return ( | ||
<div style={{ height: "400px" }}> | ||
<ReactFlowProvider> | ||
<Visualizer overview={overview}/> | ||
</ReactFlowProvider> | ||
</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
File renamed without changes
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
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,18 +1,34 @@ | ||
import {Overview} from "../api"; | ||
import {Edge, Node} from "@xyflow/react"; | ||
|
||
export class VisualOverview { | ||
nodes: Node[]; | ||
edges: Edge[]; | ||
} | ||
|
||
const buildVisualizerGraph = (overview: Overview): VisualOverview => { | ||
let out = new VisualOverview(); | ||
out.nodes = [ | ||
{ id: "1", position: { x: 0, y: 0 }, data: { label: "[email protected]" } } | ||
]; | ||
out.edges = []; | ||
|
||
const buildVisualizerGraph = (overview: Overview) => { | ||
let nodes = [ | ||
{ id: "1", label: "[email protected]" } | ||
] | ||
let edges = []; | ||
overview.environments?.forEach((env, i) => { | ||
nodes.push({ id: (i+2).toString(), label: env.environment?.description! }); | ||
edges.push({ source: (i+2).toString(), target: "1", id: (i+2)+"-1" }); | ||
out.nodes.push({ | ||
id: (i+2).toString(), | ||
position: { x: 0, y: 0 }, | ||
data: { label: env.environment?.description! }, | ||
}); | ||
out.edges.push({ | ||
id: "e" + (i+2) + "-1", | ||
source: "1", | ||
target: (i+2).toString() | ||
}); | ||
}) | ||
return { | ||
nodes: nodes, | ||
edges: edges, | ||
} | ||
|
||
console.log(out); | ||
|
||
return out; | ||
} | ||
|
||
export default buildVisualizerGraph; |
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,8 @@ | ||
.react-flow__node { | ||
font-family: "Poppins", sans-serif; | ||
color: #241775; | ||
border: 1px solid #241775; | ||
} | ||
.react-flow__attribution { | ||
display: none; | ||
} |