Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[APM] Service map layout root nodes fix #59514

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ function getLayoutOptions(
};
}

function selectRoots(elements: cytoscape.ElementDefinition[]): string[] {
const nodes = cytoscape({ elements }).nodes();
const unconnectedNodes = nodes.roots().intersection(nodes.leaves());
function selectRoots(cy: cytoscape.Core): string[] {
const nodes = cy.nodes();
const roots = nodes.roots();
const rumNodes = nodes.filter(node => isRumAgentName(node.data('agentName')));
return rumNodes.union(unconnectedNodes).map(node => node.id());
return rumNodes.union(roots).map(node => node.id());
}

export function Cytoscape({
Expand Down Expand Up @@ -118,7 +118,7 @@ export function Cytoscape({
}

if (event.cy.elements().length > 0) {
const selectedRoots = selectRoots(elements);
const selectedRoots = selectRoots(event.cy);
const layout = cy.layout(
getLayoutOptions(selectedRoots, height, width)
);
Expand All @@ -130,7 +130,7 @@ export function Cytoscape({
}
}
},
[cy, serviceName, elements, height, width]
[cy, serviceName, height, width]
);

// Trigger a custom "data" event when data changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,15 @@ export function getCytoscapeElements(

// instead of adding connections in two directions,
// we add a `bidirectional` flag to use in styling
// and hide the inverse edge when rendering
const dedupedConnections = (sortBy(
Object.values(connectionsById),
// make sure that order is stable
'id'
) as ConnectionWithId[]).reduce<
Array<ConnectionWithId & { bidirectional?: boolean }>
Array<
ConnectionWithId & { bidirectional?: boolean; isInverseEdge?: boolean }
>
>((prev, connection) => {
const reversedConnection = prev.find(
c =>
Expand All @@ -151,7 +154,10 @@ export function getCytoscapeElements(

if (reversedConnection) {
reversedConnection.bidirectional = true;
return prev;
return prev.concat({
...connection,
isInverseEdge: true
});
}

return prev.concat(connection);
Expand All @@ -160,6 +166,7 @@ export function getCytoscapeElements(
const cyEdges = dedupedConnections.map(connection => {
return {
group: 'edges' as const,
classes: connection.isInverseEdge ? 'invisible' : undefined,
data: {
id: connection.id,
source: connection.source.id,
Expand Down