mirror of
https://github.com/openziti/zrok.git
synced 2024-11-26 01:54:09 +01:00
account added to network graph; rounded rectangles (#107)
This commit is contained in:
parent
2fb9e4fa9b
commit
dcf662ebff
@ -60,7 +60,7 @@ const Console = (props) => {
|
|||||||
</Navbar.Collapse>
|
</Navbar.Collapse>
|
||||||
</Container>
|
</Container>
|
||||||
</Navbar>
|
</Navbar>
|
||||||
<Visualizer overview={overview} />
|
<Visualizer user={props.user} overview={overview} />
|
||||||
<Enable show={showEnableModal} onHide={closeEnableModal} token={props.user.token} />
|
<Enable show={showEnableModal} onHide={closeEnableModal} token={props.user.token} />
|
||||||
<Version show={showVersionModal} onHide={closeVersionModal} />
|
<Version show={showVersionModal} onHide={closeVersionModal} />
|
||||||
</Container>
|
</Container>
|
||||||
|
@ -2,6 +2,7 @@ import {withSize} from "react-sizeme";
|
|||||||
import {useEffect, useRef} from "react";
|
import {useEffect, useRef} from "react";
|
||||||
import {ForceGraph2D} from "react-force-graph";
|
import {ForceGraph2D} from "react-force-graph";
|
||||||
import * as d3 from "d3-force-3d";
|
import * as d3 from "d3-force-3d";
|
||||||
|
import {roundRect} from "./draw";
|
||||||
|
|
||||||
const Network = (props) => {
|
const Network = (props) => {
|
||||||
const targetRef = useRef();
|
const targetRef = useRef();
|
||||||
@ -11,15 +12,19 @@ const Network = (props) => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fg = targetRef.current;
|
const fg = targetRef.current;
|
||||||
fg.d3Force('collide', d3.forceCollide().radius(30));
|
fg.d3Force('collide', d3.forceCollide().radius(35));
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const paintNode = (node, ctx) => {
|
const paintNode = (node, ctx) => {
|
||||||
let nodeColor = "#777";
|
let nodeColor = "#555";
|
||||||
let textColor = "white";
|
let textColor = "white";
|
||||||
switch(node.type) {
|
switch(node.type) {
|
||||||
|
case "environment":
|
||||||
|
nodeColor = "#777";
|
||||||
|
textColor = "black";
|
||||||
|
break;
|
||||||
case "service":
|
case "service":
|
||||||
nodeColor = "#7e67e2";
|
nodeColor = "#291A66";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -27,10 +32,17 @@ const Network = (props) => {
|
|||||||
ctx.textAlign = "center";
|
ctx.textAlign = "center";
|
||||||
ctx.font = "6px 'JetBrains Mono'";
|
ctx.font = "6px 'JetBrains Mono'";
|
||||||
let extents = ctx.measureText(node.label);
|
let extents = ctx.measureText(node.label);
|
||||||
let nodeWidth = extents.width + 5;
|
let nodeWidth = extents.width + 10;
|
||||||
|
|
||||||
ctx.fillStyle = nodeColor;
|
ctx.fillStyle = nodeColor;
|
||||||
ctx.fillRect(node.x - (nodeWidth / 2), node.y - 7, nodeWidth, 14);
|
roundRect(ctx, node.x - (nodeWidth / 2), node.y - 7, nodeWidth, 14, 1.25);
|
||||||
|
ctx.fill();
|
||||||
|
|
||||||
|
switch(node.type) {
|
||||||
|
case "service":
|
||||||
|
ctx.strokeStyle = "#433482";
|
||||||
|
ctx.stroke();
|
||||||
|
}
|
||||||
|
|
||||||
ctx.fillStyle = textColor;
|
ctx.fillStyle = textColor;
|
||||||
ctx.fillText(node.label, node.x, node.y);
|
ctx.fillText(node.label, node.x, node.y);
|
||||||
@ -51,7 +63,9 @@ const Network = (props) => {
|
|||||||
linkWidth={1.5}
|
linkWidth={1.5}
|
||||||
nodeCanvasObject={paintNode}
|
nodeCanvasObject={paintNode}
|
||||||
backgroundColor={"#3b2693"}
|
backgroundColor={"#3b2693"}
|
||||||
cooldownTicks={100}
|
cooldownTicks={300}
|
||||||
|
d3VelocityDecay={0.3}
|
||||||
|
d3AlphaDecay={0.0128}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ const Visualizer = (props) => {
|
|||||||
const [networkGraph, setNetworkGraph] = useState({nodes: [], links: []});
|
const [networkGraph, setNetworkGraph] = useState({nodes: [], links: []});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setNetworkGraph(mergeGraph(networkGraph, props.overview));
|
setNetworkGraph(mergeGraph(networkGraph, props.user, props.overview));
|
||||||
}, [props]);
|
}, [props]);
|
||||||
|
|
||||||
// fgRef to access force graph controls from this component
|
// fgRef to access force graph controls from this component
|
||||||
|
12
ui/src/console/visualizer/draw.js
Normal file
12
ui/src/console/visualizer/draw.js
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
export const roundRect = (ctx, x, y, w, h, r) => {
|
||||||
|
if (w < 2 * r) r = w / 2;
|
||||||
|
if (h < 2 * r) r = h / 2;
|
||||||
|
ctx.beginPath();
|
||||||
|
ctx.moveTo(x+r, y);
|
||||||
|
ctx.arcTo(x+w, y, x+w, y+h, r);
|
||||||
|
ctx.arcTo(x+w, y+h, x, y+h, r);
|
||||||
|
ctx.arcTo(x, y+h, x, y, r);
|
||||||
|
ctx.arcTo(x, y, x+w, y, r);
|
||||||
|
ctx.closePath();
|
||||||
|
return this;
|
||||||
|
}
|
@ -15,11 +15,19 @@ const nodesEqual = (a, b) => {
|
|||||||
return a.every((e, i) => e.id === b[i].id);
|
return a.every((e, i) => e.id === b[i].id);
|
||||||
}
|
}
|
||||||
|
|
||||||
export const mergeGraph = (oldGraph, newOverview) => {
|
export const mergeGraph = (oldGraph, user, newOverview) => {
|
||||||
let newGraph = {
|
let newGraph = {
|
||||||
nodes: [],
|
nodes: [],
|
||||||
links: []
|
links: []
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let accountNode = {
|
||||||
|
id: user.token,
|
||||||
|
label: user.email,
|
||||||
|
type: "account"
|
||||||
|
}
|
||||||
|
newGraph.nodes.push(accountNode);
|
||||||
|
|
||||||
newOverview.forEach(env => {
|
newOverview.forEach(env => {
|
||||||
let envNode = {
|
let envNode = {
|
||||||
id: env.environment.zId,
|
id: env.environment.zId,
|
||||||
@ -27,6 +35,11 @@ export const mergeGraph = (oldGraph, newOverview) => {
|
|||||||
type: "environment"
|
type: "environment"
|
||||||
};
|
};
|
||||||
newGraph.nodes.push(envNode);
|
newGraph.nodes.push(envNode);
|
||||||
|
newGraph.links.push({
|
||||||
|
target: accountNode.id,
|
||||||
|
source: envNode.id,
|
||||||
|
color: "#777"
|
||||||
|
});
|
||||||
if(env.services) {
|
if(env.services) {
|
||||||
env.services.forEach(svc => {
|
env.services.forEach(svc => {
|
||||||
let svcLabel = svc.token;
|
let svcLabel = svc.token;
|
||||||
|
Loading…
Reference in New Issue
Block a user