Bad layer spacing of LayeredDigraph

I get a poor layer spacing while using LayeredDigraph, see screenshot:

The circle nodes with the labels on the right seem to be arranged too far right hand side.
That layout is not only bad looking but even causes overlappings.
(Both are not acceptable for our product.)

For your problem analysis I add the results of the original NodeMinLayerSpace method and the creating code:
CYP2C9-rcy size={Width=59,27083, Height=36,07291} tl=True bR=39,63541
CYP2C9-rcy size={Width=59,27083, Height=36,07291} tl=False bR=39,63542
cpd size={Width=43,99739, Height=22,5} tl=True bR=21,25
cpd size={Width=43,99739, Height=22,5} tl=False bR=42,74739
cpd-CYP2C9 Metabolite size={Width=165,5273, Height=22,5} tl=True bR=21,25
cpd-CYP2C9 Metabolite size={Width=165,5273, Height=22,5} tl=False bR=164,2773
CYP2C9 size={Width=74,37499, Height=22,5} tl=True bR=21,25
CYP2C9 size={Width=74,37499, Height=22,5} tl=False bR=73,12499
CYP3A4-rcy size={Width=58,68228, Height=36,07291} tl=True bR=39,34114
CYP3A4-rcy size={Width=58,68228, Height=36,07291} tl=False bR=39,34114
cpd-CYP3A4 Metabolite size={Width=164,7916, Height=22,5} tl=True bR=21,25
cpd-CYP3A4 Metabolite size={Width=164,7916, Height=22,5} tl=False bR=163,5416
CYP3A4 size={Width=73,63931, Height=22,5} tl=True bR=21,25
CYP3A4 size={Width=73,63931, Height=22,5} tl=False bR=72,38931
CYP3A4-asdasd size={Width=78,85937, Height=36,07291} tl=True bR=49,42969
CYP3A4-asdasd size={Width=78,85937, Height=36,07291} tl=False bR=49,42968
cpd-CYP3A4 Complex size={Width=155,8073, Height=22,5} tl=True bR=21,25
cpd-CYP3A4 Complex size={Width=155,8073, Height=22,5} tl=False bR=154,5573
IFNAR1-ba size={Width=53,34895, Height=36,07291} tl=True bR=36,67447
IFNAR1-ba size={Width=53,34895, Height=36,07291} tl=False bR=36,67448
IFNAR1 size={Width=69,91536, Height=22,5} tl=True bR=21,25
IFNAR1 size={Width=69,91536, Height=22,5} tl=False bR=68,66536
cpd-IFNAR1 Complex size={Width=152,0833, Height=22,5} tl=True bR=21,25
cpd-IFNAR1 Complex size={Width=152,0833, Height=22,5} tl=False bR=150,8333
CYP2C9 size={Width=74,37499, Height=22,5} tl=True bR=21,25
CYP2C9 size={Width=74,37499, Height=22,5} tl=False bR=73,12499
CYP3A4 size={Width=73,63931, Height=22,5} tl=True bR=21,25
CYP3A4 size={Width=73,63931, Height=22,5} tl=False bR=72,38931
Prod1 size={Width=58,07941, Height=22,5} tl=True bR=21,25
Prod1 size={Width=58,07941, Height=22,5} tl=False bR=56,82941
R1 size={Width=38, Height=36,07291} tl=True bR=29
R1 size={Width=38, Height=36,07291} tl=False bR=29

  protected override float NodeMinLayerSpace(GoLayoutLayeredDigraphNode node, bool topleft)
  {
     string name = "NoNode"; string text = "";

     var goNode = node.GoObject as GoNode;
     if (goNode != null)
     {
        name = goNode.Text;
        text = goNode.Size.ToString();
     }

     float baseResult = base.NodeMinLayerSpace(node, topleft);
     Console.WriteLine(name + " size=" + text + " tl=" + topleft + " bR=" + baseResult);
     return baseResult;
  }

And here are the option settings before calling the PerformLayout:

     LayerSpacing = 20F;
     ColumnSpacing = 20F;
     DirectionOption = GoLayoutDirection.Right;
     CycleRemoveOption = GoLayoutLayeredDigraphCycleRemove.DepthFirst;
     LayeringOption = GoLayoutLayeredDigraphLayering.OptimalLinkLength;
     InitializeOption = GoLayoutLayeredDigraphInitIndices.DepthFirstOut;
     Iterations = 4;
     AggressiveOption = GoLayoutLayeredDigraphAggressive.Less;
     PackOption =  GoLayoutLayeredDigraphPack.Straighten;
     SetsPortSpots = false;

Do you see a reason for that odd layer spacing?
Could you recommend something to overcome this problem?

Kind regards
JJ

Perhaps you are interested in the defintions of the node and port:

  public ElementBaseNode()
  {
      AutoResizes = false;
     Shape = new GoEllipse(); 
     Color = DiagramColors.MoleculeNode;

     Port = new BasePort(this, true);

     Text = "";
     LabelSpot = MiddleRight;
  }

  public virtual string Name
  {
     get { return Text; }
     set { Text = value; }
  }

  public BasePort()
  {
     FromSpot = NoSpot;
     ToSpot = NoSpot;
     Brush = null;
     IsValidSelfNode = false;
     IsValidDuplicateLinks = false;

     // Default: do not allow linking
     SetLinkValidator((n1, n2, o1, o2) => false);
  }

Here is a supplementing information, I found playing around with the NodeMinLayerSpace method:

If I invert the topleft parameter:
protected override float NodeMinLayerSpace(GoLayoutLayeredDigraphNode node, bool topleft)
{
return base.NodeMinLayerSpace(node, !topleft);
}

the spacing is fine:

Could you please explain, what’s the reason for this strange behavior.
Is there a bug or lack in your internal code?

Kind regards

Your <span =“Apple-style-span” style=": rgb248, 248, 252; “>ElementBaseNode is derived from GoBasicNode, correct?
<span =“Apple-style-span” style=”: rgb248, 248, 252; “>

<span =“Apple-style-span” style=”: rgb248, 248, 252; “>Do you override Location or Position in that class? or change SelectionObject?
<span =“Apple-style-span” style=”: rgb248, 248, 252; “>

<span =“Apple-style-span” style=”: rgb248, 248, 252; ">Are you doing other overrides of the Layout class?

ElementBaseNode is derived from GoBasicNode.

Location or Position is not overridden. SelectionObject is not changed.

No other overrides of the Layout class are done.

Can't the behaviour reproduced with code from the snippets I have sent you? (Especially LabelSpot = MiddleRight;)

I’ll give it a try tomorrow.