Skip to content

Commit

Permalink
Merge pull request #981 from alixander/elk-port-spacing
Browse files Browse the repository at this point in the history
improve elk port spacing
  • Loading branch information
alixander authored Mar 7, 2023
2 parents a60e952 + 412f53e commit 4e53c27
Show file tree
Hide file tree
Showing 47 changed files with 2,097 additions and 2,114 deletions.
2 changes: 2 additions & 0 deletions ci/release/changelogs/next.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#### Improvements 🧹

- ELK nodes with > 1 connection grow to ensure padding around ports [#981](https://github.com/terrastruct/d2/pull/981)

#### Bugfixes ⛑️

- Accept absolute paths again on the CLI. [#979](https://github.com/terrastruct/d2/pull/979)
Expand Down
21 changes: 21 additions & 0 deletions d2layouts/d2elklayout/layout.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ var DefaultOpts = ConfigurableOpts{
SelfLoopSpacing: 50.0,
}

var port_spacing = 40.

type elkOpts struct {
Thoroughness int `json:"elk.layered.thoroughness,omitempty"`
EdgeEdgeBetweenLayersSpacing int `json:"elk.layered.spacing.edgeEdgeBetweenLayers,omitempty"`
Expand Down Expand Up @@ -176,6 +178,25 @@ func Layout(ctx context.Context, g *d2graph.Graph, opts *ConfigurableOpts) (err
}

walk(g.Root, nil, func(obj, parent *d2graph.Object) {
incoming := 0.
outgoing := 0.
for _, e := range g.Edges {
if e.Src == obj {
outgoing++
}
if e.Dst == obj {
incoming++
}
}
if incoming >= 2 || outgoing >= 2 {
switch g.Root.Attributes.Direction.Value {
case "right", "left":
obj.Height = math.Max(obj.Height, math.Max(incoming, outgoing)*port_spacing)
default:
obj.Width = math.Max(obj.Width, math.Max(incoming, outgoing)*port_spacing)
}
}

height := obj.Height
width := obj.Width
if obj.LabelWidth != nil && obj.LabelHeight != nil {
Expand Down
Binary file modified e2etests-cli/testdata/TestCLI_E2E/internal_linked_pdf.exp.pdf
Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 4e53c27

Please sign in to comment.