comments, renaming
This commit is contained in:
parent
5b7634fe26
commit
182af8dc39
4 changed files with 19 additions and 17 deletions
|
|
@ -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) {
|
func (obj *Object) ShiftDescendants(dx, dy float64) {
|
||||||
// also need to shift edges of descendants that are shifted
|
// also need to shift edges of descendants that are shifted
|
||||||
movedEdges := make(map[*Edge]struct{})
|
movedEdges := make(map[*Edge]struct{})
|
||||||
|
|
@ -1968,13 +1970,13 @@ func (obj *Object) IsMultiple() bool {
|
||||||
return obj.Style.Multiple != nil && obj.Style.Multiple.Value == "true"
|
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 obj.Style.ThreeDee != nil && obj.Style.ThreeDee.Value == "true"
|
||||||
}
|
}
|
||||||
|
|
||||||
// return width/height adjustments to account for shapes with 3d or multiple
|
// GetModifierElementAdjustments returns width/height adjustments to account for shapes with 3d or multiple
|
||||||
func (obj *Object) GetDimensionAdjustments() (dx, dy float64) {
|
func (obj *Object) GetModifierElementAdjustments() (dx, dy float64) {
|
||||||
if obj.Is3d() {
|
if obj.Is3D() {
|
||||||
if obj.Shape.Value == d2target.ShapeHexagon {
|
if obj.Shape.Value == d2target.ShapeHexagon {
|
||||||
dy = d2target.THREE_DEE_OFFSET / 2
|
dy = d2target.THREE_DEE_OFFSET / 2
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -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
|
// reserve extra space for 3d/multiple by providing dagre the larger dimensions
|
||||||
dx, dy := obj.GetDimensionAdjustments()
|
dx, dy := obj.GetModifierElementAdjustments()
|
||||||
width += dx
|
width += dx
|
||||||
height += dy
|
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
|
// remove the extra width/height we added for 3d/multiple after all objects/connections are placed
|
||||||
// and shift the shapes down accordingly
|
// and shift the shapes down accordingly
|
||||||
for _, obj := range g.Objects {
|
for _, obj := range g.Objects {
|
||||||
dx, dy := obj.GetDimensionAdjustments()
|
dx, dy := obj.GetModifierElementAdjustments()
|
||||||
if dx != 0 || dy != 0 {
|
if dx != 0 || dy != 0 {
|
||||||
obj.TopLeft.Y += dy
|
obj.TopLeft.Y += dy
|
||||||
obj.ShiftDescendants(0, 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
|
var originalSrcTL, originalDstTL *geo.Point
|
||||||
// if the edge passes through 3d/multiple, use the offset box for tracing to border
|
// 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 &&
|
if start.X > edge.Src.TopLeft.X+srcDx &&
|
||||||
start.Y < edge.Src.TopLeft.Y+edge.Src.Height-srcDy {
|
start.Y < edge.Src.TopLeft.Y+edge.Src.Height-srcDy {
|
||||||
originalSrcTL = edge.Src.TopLeft.Copy()
|
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
|
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 &&
|
if end.X > edge.Dst.TopLeft.X+dstDx &&
|
||||||
end.Y < edge.Dst.TopLeft.Y+edge.Dst.Height-dstDy {
|
end.Y < edge.Dst.TopLeft.Y+edge.Dst.Height-dstDy {
|
||||||
originalDstTL = edge.Dst.TopLeft.Copy()
|
originalDstTL = edge.Dst.TopLeft.Copy()
|
||||||
|
|
|
||||||
|
|
@ -223,7 +223,7 @@ func Layout(ctx context.Context, g *d2graph.Graph, opts *ConfigurableOpts) (err
|
||||||
width = go2.Max(width, float64(obj.LabelDimensions.Width))
|
width = go2.Max(width, float64(obj.LabelDimensions.Width))
|
||||||
}
|
}
|
||||||
// reserve extra space for 3d/multiple by providing elk the larger dimensions
|
// reserve extra space for 3d/multiple by providing elk the larger dimensions
|
||||||
dx, dy := obj.GetDimensionAdjustments()
|
dx, dy := obj.GetModifierElementAdjustments()
|
||||||
width += dx
|
width += dx
|
||||||
height += dy
|
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
|
// remove the extra width/height we added for 3d/multiple after all objects/connections are placed
|
||||||
// and shift the shapes down accordingly
|
// and shift the shapes down accordingly
|
||||||
for _, obj := range g.Objects {
|
for _, obj := range g.Objects {
|
||||||
dx, dy := obj.GetDimensionAdjustments()
|
dx, dy := obj.GetModifierElementAdjustments()
|
||||||
if dx != 0 || dy != 0 {
|
if dx != 0 || dy != 0 {
|
||||||
obj.TopLeft.Y += dy
|
obj.TopLeft.Y += dy
|
||||||
obj.ShiftDescendants(0, 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
|
var originalSrcTL, originalDstTL *geo.Point
|
||||||
// if the edge passes through 3d/multiple, use the offset box for tracing to border
|
// 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 &&
|
if start.X > edge.Src.TopLeft.X+srcDx &&
|
||||||
start.Y < edge.Src.TopLeft.Y+edge.Src.Height-srcDy {
|
start.Y < edge.Src.TopLeft.Y+edge.Src.Height-srcDy {
|
||||||
originalSrcTL = edge.Src.TopLeft.Copy()
|
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
|
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 &&
|
if end.X > edge.Dst.TopLeft.X+dstDx &&
|
||||||
end.Y < edge.Dst.TopLeft.Y+edge.Dst.Height-dstDy {
|
end.Y < edge.Dst.TopLeft.Y+edge.Dst.Height-dstDy {
|
||||||
originalDstTL = edge.Dst.TopLeft.Copy()
|
originalDstTL = edge.Dst.TopLeft.Copy()
|
||||||
|
|
@ -561,7 +561,7 @@ func deleteBends(g *d2graph.Graph) {
|
||||||
}
|
}
|
||||||
|
|
||||||
isHorizontal := math.Ceil(start.Y) == math.Ceil(corner.Y)
|
isHorizontal := math.Ceil(start.Y) == math.Ceil(corner.Y)
|
||||||
dx, dy := endpoint.GetDimensionAdjustments()
|
dx, dy := endpoint.GetModifierElementAdjustments()
|
||||||
|
|
||||||
// Make sure it's still attached
|
// Make sure it's still attached
|
||||||
if isHorizontal {
|
if isHorizontal {
|
||||||
|
|
|
||||||
|
|
@ -642,7 +642,7 @@ func defineShadowFilter(writer io.Writer) {
|
||||||
</defs>`)
|
</defs>`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func render3dRect(targetShape d2target.Shape) string {
|
func render3DRect(targetShape d2target.Shape) string {
|
||||||
moveTo := func(p d2target.Point) string {
|
moveTo := func(p d2target.Point) string {
|
||||||
return fmt.Sprintf("M%d,%d", p.X+targetShape.Pos.X, p.Y+targetShape.Pos.Y)
|
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
|
return borderMask + mainShapeRendered + renderedSides + renderedBorder
|
||||||
}
|
}
|
||||||
|
|
||||||
func render3dHexagon(targetShape d2target.Shape) string {
|
func render3DHexagon(targetShape d2target.Shape) string {
|
||||||
moveTo := func(p d2target.Point) string {
|
moveTo := func(p d2target.Point) string {
|
||||||
return fmt.Sprintf("M%d,%d", p.X+targetShape.Pos.X, p.Y+targetShape.Pos.Y)
|
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)
|
borderRadius = float64(targetShape.BorderRadius)
|
||||||
}
|
}
|
||||||
if targetShape.ThreeDee {
|
if targetShape.ThreeDee {
|
||||||
fmt.Fprint(writer, render3dRect(targetShape))
|
fmt.Fprint(writer, render3DRect(targetShape))
|
||||||
} else {
|
} else {
|
||||||
if !targetShape.DoubleBorder {
|
if !targetShape.DoubleBorder {
|
||||||
if targetShape.Multiple {
|
if targetShape.Multiple {
|
||||||
|
|
@ -1088,7 +1088,7 @@ func drawShape(writer io.Writer, diagramHash string, targetShape d2target.Shape,
|
||||||
}
|
}
|
||||||
case d2target.ShapeHexagon:
|
case d2target.ShapeHexagon:
|
||||||
if targetShape.ThreeDee {
|
if targetShape.ThreeDee {
|
||||||
fmt.Fprint(writer, render3dHexagon(targetShape))
|
fmt.Fprint(writer, render3DHexagon(targetShape))
|
||||||
} else {
|
} else {
|
||||||
if targetShape.Multiple {
|
if targetShape.Multiple {
|
||||||
multiplePathData := shape.NewShape(shapeType, geo.NewBox(multipleTL, width, height)).GetSVGPathData()
|
multiplePathData := shape.NewShape(shapeType, geo.NewBox(multipleTL, width, height)).GetSVGPathData()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue