fix group padding

This commit is contained in:
Alexander Wang 2022-12-05 09:54:45 -08:00
parent fff6637a03
commit d7a2e1ac45
No known key found for this signature in database
GPG key ID: D89FA31966BDBECE
5 changed files with 24 additions and 32 deletions

View file

@ -189,10 +189,10 @@ func (sd *sequenceDiagram) placeGroup(group *d2graph.Object) {
for _, m := range sd.messages {
if m.ContainedBy(group) {
for _, p := range m.Route {
minX = math.Min(minX, p.X)
minY = math.Min(minY, p.Y)
maxX = math.Max(maxX, p.X)
maxY = math.Max(maxY, p.Y)
minX = math.Min(minX, p.X-HORIZONTAL_PAD)
minY = math.Min(minY, p.Y-MIN_MESSAGE_DISTANCE/2.)
maxX = math.Max(maxX, p.X+HORIZONTAL_PAD)
maxY = math.Max(maxY, p.Y+MIN_MESSAGE_DISTANCE/2.)
}
}
}
@ -213,18 +213,16 @@ func (sd *sequenceDiagram) placeGroup(group *d2graph.Object) {
}
}
if inGroup {
minY = math.Min(minY, n.TopLeft.Y)
maxY = math.Max(maxY, n.TopLeft.Y+n.Height)
minX = math.Min(minX, n.TopLeft.X)
maxX = math.Max(maxX, n.TopLeft.X+n.Width)
minX = math.Min(minX, n.TopLeft.X-HORIZONTAL_PAD)
minY = math.Min(minY, n.TopLeft.Y-MIN_MESSAGE_DISTANCE/2.)
maxY = math.Max(maxY, n.TopLeft.Y+n.Height+HORIZONTAL_PAD)
maxX = math.Max(maxX, n.TopLeft.X+n.Width+MIN_MESSAGE_DISTANCE/2.)
}
}
hasNested := false
for _, ch := range group.ChildrenArray {
for _, g := range sd.groups {
if ch == g {
hasNested = true
minX = math.Min(minX, ch.TopLeft.X-GROUP_CONTAINER_PADDING)
minY = math.Min(minY, ch.TopLeft.Y-GROUP_CONTAINER_PADDING)
maxX = math.Max(maxX, ch.TopLeft.X+ch.Width+GROUP_CONTAINER_PADDING)
@ -233,12 +231,6 @@ func (sd *sequenceDiagram) placeGroup(group *d2graph.Object) {
}
}
}
if !hasNested {
minX -= HORIZONTAL_PAD
minY -= MIN_MESSAGE_DISTANCE / 2.
maxX += HORIZONTAL_PAD
maxY += MIN_MESSAGE_DISTANCE / 2.
}
group.Box = geo.NewBox(
geo.NewPoint(

View file

@ -200,10 +200,10 @@
"type": "",
"pos": {
"x": 221,
"y": 566
"y": 526
},
"width": 368,
"height": 650,
"height": 730,
"opacity": 1,
"strokeDash": 0,
"strokeWidth": 2,
@ -278,7 +278,7 @@
"x": 245,
"y": 1306
},
"width": 453,
"width": 443,
"height": 466,
"opacity": 1,
"strokeDash": 0,
@ -355,8 +355,8 @@
"x": 601,
"y": 1822
},
"width": 268,
"height": 206,
"width": 258,
"height": 216,
"opacity": 1,
"strokeDash": 0,
"strokeWidth": 2,

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 474 KiB

After

Width:  |  Height:  |  Size: 474 KiB

View file

@ -200,10 +200,10 @@
"type": "",
"pos": {
"x": 221,
"y": 566
"y": 526
},
"width": 368,
"height": 650,
"height": 730,
"opacity": 1,
"strokeDash": 0,
"strokeWidth": 2,
@ -278,7 +278,7 @@
"x": 245,
"y": 1306
},
"width": 453,
"width": 443,
"height": 466,
"opacity": 1,
"strokeDash": 0,
@ -355,8 +355,8 @@
"x": 601,
"y": 1822
},
"width": 268,
"height": 206,
"width": 258,
"height": 216,
"opacity": 1,
"strokeDash": 0,
"strokeWidth": 2,

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 474 KiB

After

Width:  |  Height:  |  Size: 474 KiB