Skip to content

Commit 6b67009

Browse files
Merge pull request #586 from neo4j-labs/fix/fixNoNodeOnGraph
Removing Orphan Rels error on Graph
2 parents e24c952 + 73ab48d commit 6b67009

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/chart/graph/util/RecordUtils.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,12 @@ function extractGraphEntitiesFromField(
122122
}
123123
}
124124

125+
const isValidLink = (link, nodes) => {
126+
if (nodes[link.source] == null || nodes[link.target] == null) {
127+
return false;
128+
}
129+
return true;
130+
};
125131
export function buildGraphVisualizationObjectFromRecords(
126132
records: any[], // Neo4jRecord[],
127133
nodes: Record<string, any>[],
@@ -162,6 +168,7 @@ export function buildGraphVisualizationObjectFromRecords(
162168
);
163169
});
164170
});
171+
165172
// Assign proper curvatures and colors to relationships.
166173
// Assigning curvature is needed for pairs of nodes that have multiple relationships between them, or self-loops.
167174
const linksList = Object.values(links).map((linkArray) => {
@@ -176,6 +183,12 @@ export function buildGraphVisualizationObjectFromRecords(
176183
});
177184
});
178185

186+
linksList.forEach((link, idx, object) => {
187+
if (!isValidLink(link[0], nodes)) {
188+
object.splice(idx, 1);
189+
}
190+
});
191+
179192
// Assign proper colors to nodes.
180193
const totalColors = colorScheme ? colorScheme.length : 0;
181194
const nodeLabelsList = fields.map((e) => e[0]);

0 commit comments

Comments
 (0)