set dagre ranksep according to max edge label size
This commit is contained in:
parent
2cffb51217
commit
707f5b9dd7
1 changed files with 14 additions and 1 deletions
|
|
@ -64,22 +64,35 @@ func Layout(ctx context.Context, g *d2graph.Graph) (err error) {
|
|||
}
|
||||
|
||||
rootAttrs := dagreGraphAttrs{
|
||||
ranksep: 100,
|
||||
edgesep: 40,
|
||||
nodesep: 60,
|
||||
}
|
||||
isHorizontal := false
|
||||
switch g.Root.Attributes.Direction.Value {
|
||||
case "down":
|
||||
rootAttrs.rankdir = "TB"
|
||||
case "right":
|
||||
rootAttrs.rankdir = "LR"
|
||||
isHorizontal = true
|
||||
case "left":
|
||||
rootAttrs.rankdir = "RL"
|
||||
isHorizontal = true
|
||||
case "up":
|
||||
rootAttrs.rankdir = "BT"
|
||||
default:
|
||||
rootAttrs.rankdir = "TB"
|
||||
}
|
||||
|
||||
maxLabelSize := 0
|
||||
for _, edge := range g.Edges {
|
||||
size := edge.LabelDimensions.Width
|
||||
if !isHorizontal {
|
||||
size = edge.LabelDimensions.Height
|
||||
}
|
||||
maxLabelSize = go2.Max(maxLabelSize, size)
|
||||
}
|
||||
rootAttrs.ranksep = go2.Max(100, maxLabelSize+40)
|
||||
|
||||
configJS := setGraphAttrs(rootAttrs)
|
||||
if _, err := vm.RunString(configJS); err != nil {
|
||||
return err
|
||||
|
|
|
|||
Loading…
Reference in a new issue