Skip to content

Commit

Permalink
magical lineage layout fix
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe-lyons committed Nov 6, 2023
1 parent 3a9452c commit c02d47f
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions datahub-web-react/src/app/lineage/utils/layoutTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@ function getParentRelationship(direction: Direction, parent: VizNode | null, nod
return directionRelationships?.find((r) => r?.entity?.urn === node?.urn);
}

function firstAppearanceIndices(arr) {
const seen = new Set(); // To track which strings have been seen
const result = [] as number[];

for (let i = 0; i < arr.length; i++) {
if (!seen.has(arr[i])) {
seen.add(arr[i]); // Add the string to the set
result.push(i); // Save the index
}
}

return result;
}

function layoutNodesForOneDirection(
data: NodeData,
direction: Direction,
Expand All @@ -54,12 +68,10 @@ function layoutNodesForOneDirection(
while (nodesInCurrentLayer.length > 0) {
// if we've already added a node to the viz higher up dont add it again
const urnsToAddInCurrentLayer = Array.from(new Set(nodesInCurrentLayer.map(({ node }) => node.urn || '')));
const nodesToAddInCurrentLayer = urnsToAddInCurrentLayer
.filter((urn, pos) => urnsToAddInCurrentLayer.indexOf(urn) === pos)
.filter((urn) => !nodesByUrn[urn || '']);
const positionsToAddInCurrentLayer = firstAppearanceIndices(urnsToAddInCurrentLayer);

const filteredNodesInCurrentLayer = nodesInCurrentLayer
.filter(({ node }) => nodesToAddInCurrentLayer.indexOf(node.urn || '') > -1)
.filter((_, idx) => positionsToAddInCurrentLayer.indexOf(idx) > -1)
.filter(({ node }) => node.status?.removed !== true);

const layerSize = filteredNodesInCurrentLayer.length;
Expand Down

0 comments on commit c02d47f

Please sign in to comment.