MCPcopy Create free account
hub / github.com/codag-megalith/codag-visualizer / generateEdgePath

Function generateEdgePath

frontend/src/webview-client/utils.ts:157–201  ·  view source on GitHub ↗
(
    edge: any,
    sourceNode: any,
    targetNode: any,
    workflowGroups: any[],
    targetWidth: number = 200,
    targetHeight: number = 54,
    sourceWidth: number = 200,
    sourceHeight: number = 54,
    allEdges: any[] = []
)

Source from the content-addressed store, hash-verified

155 * For top-down layout: exit bottom, bend horizontally, enter top
156 */
157export function generateEdgePath(
158 edge: any,
159 sourceNode: any,
160 targetNode: any,
161 workflowGroups: any[],
162 targetWidth: number = 200,
163 targetHeight: number = 54,
164 sourceWidth: number = 200,
165 sourceHeight: number = 54,
166 allEdges: any[] = []
167): string {
168 // Validate nodes exist and have valid coordinates
169 if (!sourceNode || !targetNode ||
170 typeof sourceNode.x !== 'number' || typeof sourceNode.y !== 'number' ||
171 typeof targetNode.x !== 'number' || typeof targetNode.y !== 'number' ||
172 isNaN(sourceNode.x) || isNaN(sourceNode.y) ||
173 isNaN(targetNode.x) || isNaN(targetNode.y)) {
174 console.warn(`Invalid edge coordinates for ${edge.source} -> ${edge.target}`);
175 return '';
176 }
177
178 // Use dynamic dimensions from node if available
179 const srcWidth = sourceNode.width || sourceWidth;
180 const srcHeight = sourceNode.height || sourceHeight;
181 const tgtWidth = targetNode.width || targetWidth;
182 const tgtHeight = targetNode.height || targetHeight;
183
184 // For top-down layout: source exits from bottom, target enters from top
185 const startX = sourceNode.x;
186 const startY = sourceNode.y + srcHeight / 2; // Bottom of source
187 const endX = targetNode.x;
188 const endY = targetNode.y - tgtHeight / 2 - ARROW_HEAD_LENGTH; // Top of target (with arrow offset)
189
190 // If nodes are vertically aligned (or very close), draw straight line
191 if (Math.abs(startX - endX) < 5) {
192 return `M${startX},${startY} L${endX},${endY}`;
193 }
194
195 // Create orthogonal path with one horizontal segment
196 // Midpoint Y is halfway between source bottom and target top
197 const midY = (startY + endY) / 2;
198
199 // Path: down from source, horizontal, down to target
200 return `M${startX},${startY} L${startX},${midY} L${endX},${midY} L${endX},${endY}`;
201}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected