Skip to content

Improve auto link positioning to consider intermediate resources#275

Merged
ugwis merged 2 commits intoawslabs:mainfrom
ugwis:fix-autopos-hierarchy
Jan 28, 2026
Merged

Improve auto link positioning to consider intermediate resources#275
ugwis merged 2 commits intoawslabs:mainfrom
ugwis:fix-autopos-hierarchy

Conversation

@ugwis
Copy link
Member

@ugwis ugwis commented Jan 28, 2026

Summary

This PR improves the auto link positioning algorithm to consider intermediate resources in the hierarchy, resulting in better visual clarity and more intelligent link placement.

Problem

Currently, auto link positioning determines connection points based on:

  1. LCA (Lowest Common Ancestor) direction
  2. Distance between resources (dx, dy)

However, it doesn't account for intermediate resources between source and target, which can lead to links visually overlapping with resources in between.

Solution

Enhanced the auto-positioning algorithm with three key improvements:

1. Resource Counting

  • countResourcesInDirections(target, lca): Counts sibling resources in each direction (N/E/W/S) from resource to LCA child
  • Respects layout order: VerticalStack (North→South), HorizontalStack (West→East)

2. LCA Children Adjustment

  • adjustCountsForLCAChildren(lca, sourceChild, targetChild, sourceCounts, targetCounts): Adjusts counts based on intermediate LCA children
  • Example: For LCA{V1, V2, V3} with link V1→V3, adds V2 count to appropriate directions

3. Optimal Position Selection

  • selectOptimalPosition(counts, lcaDirection, dx, dy): Chooses best position with priority:
    1. Directions with minimum resource count
    2. LCA direction (aligned) when multiple candidates
    3. Perpendicular directions (based on dx/dy for tie-breaking)
    4. Opposite direction (last resort)

Changes

  • Modified AutoCalculatePositions() to use LCA child ancestors and apply adjustments
  • Enhanced perpendicular direction selection to consider resource position (dx/dy)
  • Added comprehensive test cases

Testing

  • All existing tests pass
  • New test cases added:
    • TestCountResourcesInDirections: Validates resource counting logic
    • TestAutoCalculatePositionsWithResourceCounts: Tests adjustment and position selection
    • TestAutoCalculatePositionsPerpendicularSelection: Validates perpendicular direction selection

Benefits

  • Links intelligently avoid intermediate resources
  • Better visual clarity in complex hierarchical diagrams
  • Maintains backward compatibility
  • Works with both straight and orthogonal link types

Related Issue

Closes #274

ugwis added 2 commits January 28, 2026 13:32
- Add countResourcesInDirections() to count siblings in each direction (N/E/W/S)
- Add adjustCountsForLCAChildren() to adjust counts based on intermediate LCA children
- Enhance selectOptimalPosition() to choose based on resource counts and LCA direction
- Improve perpendicular direction selection using resource position (dx/dy)
- Add comprehensive test cases for the new logic

This improvement helps links avoid intermediate resources more intelligently,
resulting in better visual clarity in complex hierarchical diagrams.
@ugwis ugwis merged commit 4249e5b into awslabs:main Jan 28, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve auto link positioning to consider intermediate resources in hierarchy

1 participant