Skip to content

Commit

Permalink
[Asset graph] Make zooming in / zooming out of large graph buttery sm…
Browse files Browse the repository at this point in the history
…ooth (#16971)

## Summary & Motivation

Filtering out edges that are within a group when we're only showing the
group node because they're not visible (they're hidden behind the group
node). Not rendering these hidden edges significantly improves the
performance of zooming in and out.

## How I Tested These Changes

Locally
  • Loading branch information
salazarm authored Oct 3, 2023
1 parent 2e55f3a commit 3b54364
Showing 1 changed file with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import {AssetNode, AssetNodeMinimal} from './AssetNode';
import {AssetNodeLink} from './ForeignNode';
import {SidebarAssetInfo} from './SidebarAssetInfo';
import {GraphData, graphHasCycles, GraphNode, tokenForAssetKey} from './Utils';
import {AssetGraphLayout} from './layout';
import {AssetGraphLayout, AssetLayoutEdge} from './layout';
import {AssetGraphExplorerSidebar} from './sidebar/Sidebar';
import {AssetNodeForGraphQueryFragment} from './types/useAssetGraphData.types';
import {AssetGraphFetchScope, AssetGraphQueryItem, useAssetGraphData} from './useAssetGraphData';
Expand Down Expand Up @@ -326,7 +326,12 @@ const AssetGraphExplorerWithData: React.FC<WithDataProps> = ({
viewportRect={viewportRect}
selected={selectedGraphNodes.map((n) => n.id)}
highlighted={highlighted}
edges={layout.edges}
edges={filterEdges(
layout.edges,
allowGroupsOnlyZoomLevel,
scale,
assetGraphData,
)}
strokeWidth={allowGroupsOnlyZoomLevel ? Math.max(4, 3 / scale) : 4}
baseColor={
allowGroupsOnlyZoomLevel && scale < GROUPS_ONLY_SCALE
Expand Down Expand Up @@ -607,3 +612,24 @@ const TopbarWrapper = styled.div`
}
}
`;

function filterEdges(
edges: AssetLayoutEdge[],
allowGroupsOnlyZoomLevel: boolean,
scale: number,
graphData: GraphData,
) {
if (allowGroupsOnlyZoomLevel && scale < GROUPS_ONLY_SCALE) {
return edges.filter((e) => {
const fromAsset = graphData.nodes[e.fromId];
const toAsset = graphData.nodes[e.toId];
// If the assets are in the same asset group then filter out the edge
return (
fromAsset?.definition.groupName !== toAsset?.definition.groupName ||
fromAsset?.definition.repository.id !== toAsset?.definition.repository.id ||
fromAsset?.definition.repository.location.id !== toAsset?.definition.repository.location.id
);
});
}
return edges;
}

1 comment on commit 3b54364

@github-actions
Copy link

Choose a reason for hiding this comment

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

Deploy preview for dagit-core-storybook ready!

✅ Preview
https://dagit-core-storybook-adz0c15wi-elementl.vercel.app

Built with commit 3b54364.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.