Skip to content

Conversation

mhdirkse
Copy link
Collaborator

No description provided.

@mhdirkse
Copy link
Collaborator Author

This pull request makes edges that span multiple layers prettier. Before, edges always changed direction when they crossed a layer, see the figure below:

image

With this PR, we can produce this:

image

The algorithm reduces the number of direction changes for edges that span multiple layers. To do this, the algorithm needs to group the intermediate edges by original edge. I took the chance to do a big refactoring of the code. The coordinates of the nodes and the edges are calculated in file graphics/layout.ts that is part of the library. The datastructures needed for this calculation are in model/layout-model.ts. That file introduces class Connector that stands for one endpoint of an intermediate edge. The sequence of the Connector objects that belong to a node can be calculated without knowing coordinates.

While developing, I discovered a bug that showed when you omitted nodes in the playground. Each row of the sequence editor has a x-control that allows you to hide the node. But then the intermediate edges that belong to an original edge are not necessarily shown and the shown intermediate edges may be disconnected. Before calculating coordinates of edges, groups of connected intermediate edges are established. File graphics/horizontal-conflict.ts also needs a hack because there can be nodes without "predecessors". When the algorithm determines x-coordinates, it uses the x-coordinates of the nodes on an adjacent layer (the predecessors).

Reducing the number of direction changes is done as follows. First, initial line segments are calculated. For each traversed intermediate node, a vertical line segment is created. For each intermediate edge, a line segment is drawn from the endpoint of the previous vertical segment to the start point of the next vertical segment. If an original edge goes from Start to Int_1 to End, then we have the following segments:

  • A segment for the connection from Start to Int_1.
  • A vertical line segment for Int_1.
  • A segment for the connection from Int_1 to End.

After establishing the line initial line segments, the algorithm tries to join them again. One constraint is that joined lines should not cross nodes. Another constraint is that modified line segments should pass layers reasonably close the point originally calculated. Extra dimensions have been introduced in the dimension editor to tweak this behavior. This calculation uses function objects to allow testing. The mechanics of traversing intermediate edges and considering options to join segments is in function straighten in file graphics/straightened-line.ts. Judging a line segment is done through a function pointer that is injected from file graphics/layout.ts.

@mhdirkse mhdirkse marked this pull request as ready for review March 31, 2025 18:28
@mhdirkse mhdirkse merged commit c9c5e38 into master Apr 4, 2025
1 check 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.

2 participants