mirror of
https://github.com/openziti/zrok.git
synced 2024-11-26 01:54:09 +01:00
better merge algorithm (#107)
This commit is contained in:
parent
f6b36f3ca7
commit
b05733b602
@ -11,7 +11,7 @@ const Network = (props) => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fg = targetRef.current;
|
const fg = targetRef.current;
|
||||||
fg.d3Force('collide', d3.forceCollide(32));
|
fg.d3Force('collide', d3.forceCollide(22));
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const paintNode = (node, ctx) => {
|
const paintNode = (node, ctx) => {
|
||||||
|
@ -8,7 +8,7 @@ const Visualizer = (props) => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setNetworkGraph(mergeGraph(networkGraph, props.overview));
|
setNetworkGraph(mergeGraph(networkGraph, props.overview));
|
||||||
}, [props.overview]);
|
}, [props]);
|
||||||
|
|
||||||
// fgRef to access force graph controls from this component
|
// fgRef to access force graph controls from this component
|
||||||
let fgRef = () => { };
|
let fgRef = () => { };
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
export const mergeGraph = (oldGraph, newOverview) => {
|
export const mergeGraph = (oldGraph, newOverview) => {
|
||||||
let graph = {
|
let newGraph = {
|
||||||
nodes: [],
|
nodes: [],
|
||||||
links: []
|
links: []
|
||||||
}
|
}
|
||||||
newOverview.forEach(env => {
|
newOverview.forEach(env => {
|
||||||
graph.nodes.push({
|
newGraph.nodes.push({
|
||||||
id: env.environment.zId,
|
id: env.environment.zId,
|
||||||
label: env.environment.description,
|
label: env.environment.description,
|
||||||
type: "environment"
|
type: "environment"
|
||||||
@ -15,13 +15,13 @@ export const mergeGraph = (oldGraph, newOverview) => {
|
|||||||
if(svc.backendProxyEndpoint !== "") {
|
if(svc.backendProxyEndpoint !== "") {
|
||||||
svcLabel = svc.backendProxyEndpoint;
|
svcLabel = svc.backendProxyEndpoint;
|
||||||
}
|
}
|
||||||
graph.nodes.push({
|
newGraph.nodes.push({
|
||||||
id: svc.token,
|
id: svc.token,
|
||||||
label: svcLabel,
|
label: svcLabel,
|
||||||
type: "service",
|
type: "service",
|
||||||
val: 10
|
val: 10
|
||||||
});
|
});
|
||||||
graph.links.push({
|
newGraph.links.push({
|
||||||
target: env.environment.zId,
|
target: env.environment.zId,
|
||||||
source: svc.token,
|
source: svc.token,
|
||||||
color: "#777"
|
color: "#777"
|
||||||
@ -29,14 +29,12 @@ export const mergeGraph = (oldGraph, newOverview) => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
graph.nodes.forEach(newNode => {
|
// we want to preserve nodes that exist in the new graph, and remove those that don't.
|
||||||
let found = oldGraph.nodes.find(oldNode => oldNode.id === newNode.id);
|
oldGraph.nodes = oldGraph.nodes.filter(oldNode => newGraph.nodes.find(newNode => newNode.id === oldNode.id));
|
||||||
if(found) {
|
// and then do the opposite; add any nodes that are in newGraph that are missing from oldGraph.
|
||||||
newNode.vx = found.vx;
|
oldGraph.nodes.push(...newGraph.nodes.filter(newNode => !oldGraph.nodes.find(oldNode => oldNode.id === newNode.id)));
|
||||||
newNode.vy = found.vy;
|
return {
|
||||||
newNode.x = found.x;
|
nodes: oldGraph.nodes,
|
||||||
newNode.y = found.y;
|
links: newGraph.links,
|
||||||
}
|
};
|
||||||
})
|
|
||||||
return graph;
|
|
||||||
};
|
};
|
Loading…
Reference in New Issue
Block a user