( payload: WireFileCodePayload, rows: readonly FileCallRow[] )
| 391 | * legible next to the gutter. |
| 392 | */ |
| 393 | export function buildFileArcs( |
| 394 | payload: WireFileCodePayload, |
| 395 | rows: readonly FileCallRow[] |
| 396 | ): FileArc[] { |
| 397 | const path = payload.file.path; |
| 398 | const arcs: FileArc[] = []; |
| 399 | let maxSpan = 1; |
| 400 | |
| 401 | for (const row of rows) { |
| 402 | const target = row.call.relation.node; |
| 403 | if (target.file !== path) continue; |
| 404 | for (const line of row.lines) { |
| 405 | // A recursive call sits ON its own definition line often enough to be |
| 406 | // worth skipping: a zero-height arc is a dot, not a drawing. |
| 407 | if (line === target.line) continue; |
| 408 | const span = Math.abs(target.line - line); |
| 409 | if (span > maxSpan) maxSpan = span; |
| 410 | arcs.push({ |
| 411 | key: `${row.key}:${line}`, |
| 412 | fromLine: line, |
| 413 | toLine: target.line, |
| 414 | ownerId: row.ownerId, |
| 415 | targetId: target.id, |
| 416 | targetName: target.name, |
| 417 | uncertain: row.call.relation.uncertain, |
| 418 | synthesized: row.via !== null, |
| 419 | d: '', |
| 420 | minLine: Math.min(line, target.line), |
| 421 | maxLine: Math.max(line, target.line), |
| 422 | }); |
| 423 | } |
| 424 | } |
| 425 | |
| 426 | const scale = Math.log1p(maxSpan); |
| 427 | for (const arc of arcs) { |
| 428 | const span = arc.maxLine - arc.minLine; |
| 429 | const depth = |
| 430 | ARC_MIN_DEPTH + |
| 431 | (ARC_MAX_DEPTH - ARC_MIN_DEPTH) * (scale > 0 ? Math.log1p(span) / scale : 0); |
| 432 | arc.d = arcPath(arc.fromLine, arc.toLine, depth); |
| 433 | } |
| 434 | |
| 435 | // Long arcs first so short ones paint on top of them — the innermost arc is |
| 436 | // the one a reader is most likely to be aiming at. |
| 437 | arcs.sort((a, b) => b.maxLine - b.minLine - (a.maxLine - a.minLine)); |
| 438 | return arcs; |
| 439 | } |
| 440 | |
| 441 | /** |
| 442 | * Half an ellipse from one line to another, bulging into the arc column. |
no test coverage detected