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

fix(lineage): magical lineage layout fix #9187

Merged
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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) {
jjoyce0510 marked this conversation as resolved.
Show resolved Hide resolved
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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kinda interesting..
so you are going through list of nodes.. the first time you find you'll have an index and you'll see if the index is in the list of indexes.
the second time you hit, it won't be in the list of indexes. got it..

.filter(({ node }) => node.status?.removed !== true);

const layerSize = filteredNodesInCurrentLayer.length;
Expand Down