Skip to content

Commit f6a354d

Browse files
authored
Improve Graph View Performance (#65031)
* Add various improvements to graph view * fix tests
1 parent 01888df commit f6a354d

7 files changed

Lines changed: 568 additions & 309 deletions

File tree

airflow-core/src/airflow/ui/public/i18n/locales/en/components.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@
9191
"otherDagRuns": "+Other Dag Runs",
9292
"taskCount_one": "{{count}} Task",
9393
"taskCount_other": "{{count}} Tasks",
94-
"taskGroup": "Task Group"
94+
"taskGroup": "Task Group",
95+
"zoomToTask": "Zoom to selected task"
9596
},
9697
"limitedList": "+{{count}} more",
9798
"limitedList.allItems": "All {{count}} items:",

airflow-core/src/airflow/ui/src/components/Graph/Edge.tsx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,32 +20,32 @@ import { Text, useToken } from "@chakra-ui/react";
2020
import { Group } from "@visx/group";
2121
import { LinePath } from "@visx/shape";
2222
import type { Edge as EdgeType } from "@xyflow/react";
23+
import { useNodesData } from "@xyflow/react";
2324
import type { ElkPoint } from "elkjs";
2425

2526
import type { EdgeData } from "./reactflowUtils";
2627

2728
type Props = EdgeType<EdgeData>;
2829

29-
const CustomEdge = ({ data }: Props) => {
30+
const CustomEdge = ({ data, source, target }: Props) => {
3031
const [strokeColor, blueColor, dataEdgeColor] = useToken("colors", [
3132
"border.inverted",
3233
"blue.500",
3334
"purple.500",
3435
]);
3536

37+
// Read isSelected directly from the node store so that selection changes
38+
// don't require the parent to rebuild and pass down a new edges array.
39+
// useNodesData subscribes to data changes for these specific node IDs only.
40+
const nodesData = useNodesData([source, target]);
41+
const isSelected = nodesData.some((node) => Boolean(node.data.isSelected));
42+
3643
if (data === undefined) {
3744
return undefined;
3845
}
3946
const { rest } = data;
4047

41-
// Determine edge color based on type
42-
const getEdgeColor = () => {
43-
if (rest.isSelected) {
44-
return rest.edgeType === "data" ? dataEdgeColor : blueColor;
45-
}
46-
47-
return strokeColor;
48-
};
48+
const edgeStrokeColor = isSelected ? (rest.edgeType === "data" ? dataEdgeColor : blueColor) : strokeColor;
4949

5050
return (
5151
<>
@@ -73,9 +73,9 @@ const CustomEdge = ({ data }: Props) => {
7373
<LinePath
7474
data={[section.startPoint, ...(section.bendPoints ?? []), section.endPoint]}
7575
key={section.id}
76-
stroke={getEdgeColor()}
76+
stroke={edgeStrokeColor}
7777
strokeDasharray={rest.isSetupTeardown ? "10,5" : undefined}
78-
strokeWidth={rest.isSelected ? 3 : 1}
78+
strokeWidth={isSelected ? 3 : 1}
7979
x={(point: ElkPoint) => point.x}
8080
y={(point: ElkPoint) => point.y}
8181
/>

0 commit comments

Comments
 (0)