( plan: ExplainPlan, selectedNodeId?: string | null, )
| 8 | // --------------------------------------------------------------------------- |
| 9 | |
| 10 | export function explainPlanToFlow( |
| 11 | plan: ExplainPlan, |
| 12 | selectedNodeId?: string | null, |
| 13 | ): { |
| 14 | nodes: Node[]; |
| 15 | edges: Edge[]; |
| 16 | } { |
| 17 | const maxCost = getMaxCost(plan.root); |
| 18 | const maxTime = getMaxTime(plan.root); |
| 19 | const rawNodes: Node[] = []; |
| 20 | const edges: Edge[] = []; |
| 21 | |
| 22 | function walk(node: ExplainNode) { |
| 23 | const data: ExplainPlanNodeData = { |
| 24 | node, |
| 25 | maxCost, |
| 26 | maxTime, |
| 27 | hasAnalyzeData: plan.has_analyze_data, |
| 28 | isSelected: selectedNodeId === node.id, |
| 29 | }; |
| 30 | |
| 31 | rawNodes.push({ |
| 32 | id: node.id, |
| 33 | type: "explainPlan", |
| 34 | position: { x: 0, y: 0 }, |
| 35 | data, |
| 36 | }); |
| 37 | |
| 38 | for (const child of node.children) { |
| 39 | edges.push({ |
| 40 | id: `${node.id}-${child.id}`, |
| 41 | source: node.id, |
| 42 | target: child.id, |
| 43 | animated: true, |
| 44 | style: { stroke: "#6366f1" }, |
| 45 | }); |
| 46 | walk(child); |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | walk(plan.root); |
| 51 | |
| 52 | return layoutExplainNodes(rawNodes, edges); |
| 53 | } |
| 54 | |
| 55 | // --------------------------------------------------------------------------- |
| 56 | // Dagre layout |
no test coverage detected