diff --git a/d2graph/d2graph.go b/d2graph/d2graph.go index b95a53b3d..006bfae85 100644 --- a/d2graph/d2graph.go +++ b/d2graph/d2graph.go @@ -1918,6 +1918,8 @@ func (obj *Object) IterDescendants(apply func(parent, child *Object)) { } } +// ShiftDescendants moves Object's descendants (not including itself) +// descendants' edges are also moved by the same dx and dy (the whole route is moved if both ends are a descendant) func (obj *Object) ShiftDescendants(dx, dy float64) { // also need to shift edges of descendants that are shifted movedEdges := make(map[*Edge]struct{}) @@ -1968,13 +1970,13 @@ func (obj *Object) IsMultiple() bool { return obj.Style.Multiple != nil && obj.Style.Multiple.Value == "true" } -func (obj *Object) Is3d() bool { +func (obj *Object) Is3D() bool { return obj.Style.ThreeDee != nil && obj.Style.ThreeDee.Value == "true" } -// return width/height adjustments to account for shapes with 3d or multiple -func (obj *Object) GetDimensionAdjustments() (dx, dy float64) { - if obj.Is3d() { +// GetModifierElementAdjustments returns width/height adjustments to account for shapes with 3d or multiple +func (obj *Object) GetModifierElementAdjustments() (dx, dy float64) { + if obj.Is3D() { if obj.Shape.Value == d2target.ShapeHexagon { dy = d2target.THREE_DEE_OFFSET / 2 } else { diff --git a/d2layouts/d2dagrelayout/layout.go b/d2layouts/d2dagrelayout/layout.go index 1ae32ef54..db9c4f4b3 100644 --- a/d2layouts/d2dagrelayout/layout.go +++ b/d2layouts/d2dagrelayout/layout.go @@ -169,7 +169,7 @@ func Layout(ctx context.Context, g *d2graph.Graph, opts *ConfigurableOpts) (err } } // reserve extra space for 3d/multiple by providing dagre the larger dimensions - dx, dy := obj.GetDimensionAdjustments() + dx, dy := obj.GetModifierElementAdjustments() width += dx height += dy @@ -415,7 +415,7 @@ func Layout(ctx context.Context, g *d2graph.Graph, opts *ConfigurableOpts) (err // remove the extra width/height we added for 3d/multiple after all objects/connections are placed // and shift the shapes down accordingly for _, obj := range g.Objects { - dx, dy := obj.GetDimensionAdjustments() + dx, dy := obj.GetModifierElementAdjustments() if dx != 0 || dy != 0 { obj.TopLeft.Y += dy obj.ShiftDescendants(0, dy) @@ -474,7 +474,7 @@ func Layout(ctx context.Context, g *d2graph.Graph, opts *ConfigurableOpts) (err var originalSrcTL, originalDstTL *geo.Point // if the edge passes through 3d/multiple, use the offset box for tracing to border - if srcDx, srcDy := edge.Src.GetDimensionAdjustments(); srcDx != 0 || srcDy != 0 { + if srcDx, srcDy := edge.Src.GetModifierElementAdjustments(); srcDx != 0 || srcDy != 0 { if start.X > edge.Src.TopLeft.X+srcDx && start.Y < edge.Src.TopLeft.Y+edge.Src.Height-srcDy { originalSrcTL = edge.Src.TopLeft.Copy() @@ -482,7 +482,7 @@ func Layout(ctx context.Context, g *d2graph.Graph, opts *ConfigurableOpts) (err edge.Src.TopLeft.Y -= srcDy } } - if dstDx, dstDy := edge.Dst.GetDimensionAdjustments(); dstDx != 0 || dstDy != 0 { + if dstDx, dstDy := edge.Dst.GetModifierElementAdjustments(); dstDx != 0 || dstDy != 0 { if end.X > edge.Dst.TopLeft.X+dstDx && end.Y < edge.Dst.TopLeft.Y+edge.Dst.Height-dstDy { originalDstTL = edge.Dst.TopLeft.Copy() diff --git a/d2layouts/d2elklayout/layout.go b/d2layouts/d2elklayout/layout.go index 51aa0cee8..5c29020a2 100644 --- a/d2layouts/d2elklayout/layout.go +++ b/d2layouts/d2elklayout/layout.go @@ -223,7 +223,7 @@ func Layout(ctx context.Context, g *d2graph.Graph, opts *ConfigurableOpts) (err width = go2.Max(width, float64(obj.LabelDimensions.Width)) } // reserve extra space for 3d/multiple by providing elk the larger dimensions - dx, dy := obj.GetDimensionAdjustments() + dx, dy := obj.GetModifierElementAdjustments() width += dx height += dy @@ -464,7 +464,7 @@ func Layout(ctx context.Context, g *d2graph.Graph, opts *ConfigurableOpts) (err // remove the extra width/height we added for 3d/multiple after all objects/connections are placed // and shift the shapes down accordingly for _, obj := range g.Objects { - dx, dy := obj.GetDimensionAdjustments() + dx, dy := obj.GetModifierElementAdjustments() if dx != 0 || dy != 0 { obj.TopLeft.Y += dy obj.ShiftDescendants(0, dy) @@ -484,7 +484,7 @@ func Layout(ctx context.Context, g *d2graph.Graph, opts *ConfigurableOpts) (err var originalSrcTL, originalDstTL *geo.Point // if the edge passes through 3d/multiple, use the offset box for tracing to border - if srcDx, srcDy := edge.Src.GetDimensionAdjustments(); srcDx != 0 || srcDy != 0 { + if srcDx, srcDy := edge.Src.GetModifierElementAdjustments(); srcDx != 0 || srcDy != 0 { if start.X > edge.Src.TopLeft.X+srcDx && start.Y < edge.Src.TopLeft.Y+edge.Src.Height-srcDy { originalSrcTL = edge.Src.TopLeft.Copy() @@ -492,7 +492,7 @@ func Layout(ctx context.Context, g *d2graph.Graph, opts *ConfigurableOpts) (err edge.Src.TopLeft.Y -= srcDy } } - if dstDx, dstDy := edge.Dst.GetDimensionAdjustments(); dstDx != 0 || dstDy != 0 { + if dstDx, dstDy := edge.Dst.GetModifierElementAdjustments(); dstDx != 0 || dstDy != 0 { if end.X > edge.Dst.TopLeft.X+dstDx && end.Y < edge.Dst.TopLeft.Y+edge.Dst.Height-dstDy { originalDstTL = edge.Dst.TopLeft.Copy() @@ -561,7 +561,7 @@ func deleteBends(g *d2graph.Graph) { } isHorizontal := math.Ceil(start.Y) == math.Ceil(corner.Y) - dx, dy := endpoint.GetDimensionAdjustments() + dx, dy := endpoint.GetModifierElementAdjustments() // Make sure it's still attached if isHorizontal { diff --git a/d2renderers/d2svg/d2svg.go b/d2renderers/d2svg/d2svg.go index db014662c..ab9f04eac 100644 --- a/d2renderers/d2svg/d2svg.go +++ b/d2renderers/d2svg/d2svg.go @@ -642,7 +642,7 @@ func defineShadowFilter(writer io.Writer) { `) } -func render3dRect(targetShape d2target.Shape) string { +func render3DRect(targetShape d2target.Shape) string { moveTo := func(p d2target.Point) string { return fmt.Sprintf("M%d,%d", p.X+targetShape.Pos.X, p.Y+targetShape.Pos.Y) } @@ -738,7 +738,7 @@ func render3dRect(targetShape d2target.Shape) string { return borderMask + mainShapeRendered + renderedSides + renderedBorder } -func render3dHexagon(targetShape d2target.Shape) string { +func render3DHexagon(targetShape d2target.Shape) string { moveTo := func(p d2target.Point) string { return fmt.Sprintf("M%d,%d", p.X+targetShape.Pos.X, p.Y+targetShape.Pos.Y) } @@ -995,7 +995,7 @@ func drawShape(writer io.Writer, diagramHash string, targetShape d2target.Shape, borderRadius = float64(targetShape.BorderRadius) } if targetShape.ThreeDee { - fmt.Fprint(writer, render3dRect(targetShape)) + fmt.Fprint(writer, render3DRect(targetShape)) } else { if !targetShape.DoubleBorder { if targetShape.Multiple { @@ -1088,7 +1088,7 @@ func drawShape(writer io.Writer, diagramHash string, targetShape d2target.Shape, } case d2target.ShapeHexagon: if targetShape.ThreeDee { - fmt.Fprint(writer, render3dHexagon(targetShape)) + fmt.Fprint(writer, render3DHexagon(targetShape)) } else { if targetShape.Multiple { multiplePathData := shape.NewShape(shapeType, geo.NewBox(multipleTL, width, height)).GetSVGPathData()