(input: {
initialEntityIds: Set<string>;
expandedEntityIds: Set<string>;
expandedEventIds: Set<string>;
entityById: Map<string, ProjectGraphEntityRecord>;
eventById: Map<string, ProjectGraphEventRecord>;
eventIdsByEntityId: Map<string, string[]>;
entityIdsByEventId: Map<string, string[]>;
edges: ProjectGraphRecord["edges"];
positionByNodeId: Map<string, GraphPosition>;
selectedNodeId: string | null;
})
| 312 | } |
| 313 | |
| 314 | function buildVisibleGraph(input: { |
| 315 | initialEntityIds: Set<string>; |
| 316 | expandedEntityIds: Set<string>; |
| 317 | expandedEventIds: Set<string>; |
| 318 | entityById: Map<string, ProjectGraphEntityRecord>; |
| 319 | eventById: Map<string, ProjectGraphEventRecord>; |
| 320 | eventIdsByEntityId: Map<string, string[]>; |
| 321 | entityIdsByEventId: Map<string, string[]>; |
| 322 | edges: ProjectGraphRecord["edges"]; |
| 323 | positionByNodeId: Map<string, GraphPosition>; |
| 324 | selectedNodeId: string | null; |
| 325 | }): { nodes: GraphNode[]; edges: GraphEdge[] } { |
| 326 | const visibleEntityIds = new Set(input.initialEntityIds); |
| 327 | const visibleEventIds = new Set<string>(); |
| 328 | |
| 329 | for (const entityId of input.expandedEntityIds) { |
| 330 | visibleEntityIds.add(entityId); |
| 331 | for (const eventId of input.eventIdsByEntityId.get(entityId) ?? []) { |
| 332 | visibleEventIds.add(eventId); |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | for (const eventId of input.expandedEventIds) { |
| 337 | visibleEventIds.add(eventId); |
| 338 | for (const entityId of input.entityIdsByEventId.get(eventId) ?? []) { |
| 339 | visibleEntityIds.add(entityId); |
| 340 | } |
| 341 | } |
| 342 | |
| 343 | const nodes: GraphNode[] = []; |
| 344 | const entityIds = [...visibleEntityIds] |
| 345 | .filter((id) => input.entityById.has(id)) |
| 346 | .sort((a, b) => compareEntities(input.entityById.get(a), input.entityById.get(b))); |
| 347 | const eventIds = [...visibleEventIds] |
| 348 | .filter((id) => input.eventById.has(id)) |
| 349 | .sort((a, b) => compareEvents(input.eventById.get(a), input.eventById.get(b))); |
| 350 | |
| 351 | for (const entityId of entityIds) { |
| 352 | const entity = input.entityById.get(entityId); |
| 353 | if (!entity) continue; |
| 354 | const position = input.positionByNodeId.get(entity.id) ?? fallbackPosition(); |
| 355 | nodes.push(createGraphNode({ |
| 356 | id: entity.id, |
| 357 | label: entity.name, |
| 358 | kind: "entity", |
| 359 | expanded: input.expandedEntityIds.has(entity.id), |
| 360 | x: position.x, |
| 361 | y: position.y, |
| 362 | root: position.root |
| 363 | })); |
| 364 | } |
| 365 | |
| 366 | for (const eventId of eventIds) { |
| 367 | const event = input.eventById.get(eventId); |
| 368 | if (!event) continue; |
| 369 | const position = input.positionByNodeId.get(event.id) ?? fallbackPosition(); |
| 370 | nodes.push(createGraphNode({ |
| 371 | id: event.id, |
no test coverage detected