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{
|
rootAttrs := dagreGraphAttrs{
|
||||||
ranksep: 100,
|
|
||||||
edgesep: 40,
|
edgesep: 40,
|
||||||
nodesep: 60,
|
nodesep: 60,
|
||||||
}
|
}
|
||||||
|
isHorizontal := false
|
||||||
switch g.Root.Attributes.Direction.Value {
|
switch g.Root.Attributes.Direction.Value {
|
||||||
case "down":
|
case "down":
|
||||||
rootAttrs.rankdir = "TB"
|
rootAttrs.rankdir = "TB"
|
||||||
case "right":
|
case "right":
|
||||||
rootAttrs.rankdir = "LR"
|
rootAttrs.rankdir = "LR"
|
||||||
|
isHorizontal = true
|
||||||
case "left":
|
case "left":
|
||||||
rootAttrs.rankdir = "RL"
|
rootAttrs.rankdir = "RL"
|
||||||
|
isHorizontal = true
|
||||||
case "up":
|
case "up":
|
||||||
rootAttrs.rankdir = "BT"
|
rootAttrs.rankdir = "BT"
|
||||||
default:
|
default:
|
||||||
rootAttrs.rankdir = "TB"
|
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)
|
configJS := setGraphAttrs(rootAttrs)
|
||||||
if _, err := vm.RunString(configJS); err != nil {
|
if _, err := vm.RunString(configJS); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue