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

Removing Orphan Rels error on Graph #586

Merged
merged 1 commit into from
Aug 23, 2023
Merged
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
13 changes: 13 additions & 0 deletions src/chart/graph/util/RecordUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ function extractGraphEntitiesFromField(
}
}

const isValidLink = (link, nodes) => {
if (nodes[link.source] == null || nodes[link.target] == null) {
return false;
}
return true;
};
export function buildGraphVisualizationObjectFromRecords(
records: any[], // Neo4jRecord[],
nodes: Record<string, any>[],
Expand Down Expand Up @@ -162,6 +168,7 @@ export function buildGraphVisualizationObjectFromRecords(
);
});
});

// Assign proper curvatures and colors to relationships.
// Assigning curvature is needed for pairs of nodes that have multiple relationships between them, or self-loops.
const linksList = Object.values(links).map((linkArray) => {
Expand All @@ -176,6 +183,12 @@ export function buildGraphVisualizationObjectFromRecords(
});
});

linksList.forEach((link, idx, object) => {
if (!isValidLink(link[0], nodes)) {
object.splice(idx, 1);
}
});

// Assign proper colors to nodes.
const totalColors = colorScheme ? colorScheme.length : 0;
const nodeLabelsList = fields.map((e) => e[0]);
Expand Down