Skip to content

Commit

Permalink
Merge pull request #1928 from alixander/small-width-label
Browse files Browse the repository at this point in the history
fix custom label positions for nodes with constrained widths
  • Loading branch information
alixander authored May 2, 2024
2 parents 36eee25 + f1035c9 commit bc053b2
Show file tree
Hide file tree
Showing 13 changed files with 621 additions and 250 deletions.
1 change: 1 addition & 0 deletions ci/release/changelogs/next.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
#### Bugfixes ⛑️

- Local relative icons are relative to the d2 file instead of CLI invoke path [#1924](https://github.com/terrastruct/d2/pull/1924)
- Custom label positions weren't being read when the width was smaller than the label [#1928](https://github.com/terrastruct/d2/pull/1928)
13 changes: 6 additions & 7 deletions d2layouts/d2dagrelayout/layout.go
Original file line number Diff line number Diff line change
Expand Up @@ -570,13 +570,12 @@ func positionLabelsIcons(obj *d2graph.Object) {
} else {
obj.LabelPosition = go2.Pointer(label.InsideMiddleCenter.String())
}
}

if float64(obj.LabelDimensions.Width) > obj.Width || float64(obj.LabelDimensions.Height) > obj.Height {
if len(obj.ChildrenArray) > 0 {
obj.LabelPosition = go2.Pointer(label.OutsideTopCenter.String())
} else {
obj.LabelPosition = go2.Pointer(label.OutsideBottomCenter.String())
if float64(obj.LabelDimensions.Width) > obj.Width || float64(obj.LabelDimensions.Height) > obj.Height {
if len(obj.ChildrenArray) > 0 {
obj.LabelPosition = go2.Pointer(label.OutsideTopCenter.String())
} else {
obj.LabelPosition = go2.Pointer(label.OutsideBottomCenter.String())
}
}
}
}
Expand Down
13 changes: 6 additions & 7 deletions d2layouts/d2elklayout/layout.go
Original file line number Diff line number Diff line change
Expand Up @@ -1148,13 +1148,12 @@ func positionLabelsIcons(obj *d2graph.Object) {
} else {
obj.LabelPosition = go2.Pointer(label.InsideMiddleCenter.String())
}
}

if float64(obj.LabelDimensions.Width) > obj.Width || float64(obj.LabelDimensions.Height) > obj.Height {
if len(obj.ChildrenArray) > 0 {
obj.LabelPosition = go2.Pointer(label.OutsideTopCenter.String())
} else {
obj.LabelPosition = go2.Pointer(label.OutsideBottomCenter.String())
if float64(obj.LabelDimensions.Width) > obj.Width || float64(obj.LabelDimensions.Height) > obj.Height {
if len(obj.ChildrenArray) > 0 {
obj.LabelPosition = go2.Pointer(label.OutsideTopCenter.String())
} else {
obj.LabelPosition = go2.Pointer(label.OutsideBottomCenter.String())
}
}
}
}
3 changes: 0 additions & 3 deletions d2target/d2target.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,6 @@ func (diagram Diagram) BoundingBox() (topLeft, bottomRight Point) {

if targetShape.Label != "" {
labelPosition := label.FromString(targetShape.LabelPosition)
if !labelPosition.IsOutside() {
continue
}

shapeType := DSL_SHAPE_TO_SHAPE_TYPE[targetShape.Type]
s := shape.NewShape(shapeType,
Expand Down

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

170 changes: 85 additions & 85 deletions e2etests/testdata/regression/glob_dimensions/dagre/sketch.exp.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
86 changes: 43 additions & 43 deletions e2etests/testdata/regression/glob_dimensions/elk/board.exp.json

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

Loading

0 comments on commit bc053b2

Please sign in to comment.