Calling GoLayout multiple times

Hello,

  • I am using a Text Node with a Diamond shape and the text node has 4 ports(a conditional)
  • From the right port of the conditional I have a link to another node and from the bottom port of the conditional I have a link to a third node. Nothing is linked to the left or top ports of the conditional.
  • I also have a link which goes from the bottom of the node to the right of the conditional to the top port of the node on the bottom of the conditional. (I need to represent an AND condition)
  • What is happening is that if I call the PerformLayout function a few times in a row, the node on the right moves further right with each call to the PerformLayout function.
Why is that happening.

I tried many different things, I tried calling the ComputeRoute() and CalculateStroke but no result.

I need to be able to call Perform Layout more than one time.

The funny thing is that if I remove the link going form the bottom of the node to the right of the conditional to the top of the node at the bottom of the conditional , everything works well and PerformLayout() renders the same result no matter how many times I call it.

Thanks very much.

Susan

Can you reproduce that situation with the Flowgrammer sample?

I tried that but I need to change too much of teh code.

However what I did is a very simple application and was able to reproduce the condition.

Below is the code of my simple api.


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Northwoods.Go;
using Northwoods.Go.Layout;

namespace WindowsApplication1
{
    public partial class Form1 : Form
    {
        GoLayoutLayeredDigraph layout = new GoLayoutLayeredDigraph(); 

        public Form1()
        {
            
            
            InitializeComponent();
            layout.Document = goView1.Document;
            goView1.Dock = DockStyle.Fill;
            GoShape s = new GoDiamond();
            GoShape s1 = new GoRoundedRectangle();
            GoShape s2 = new GoRectangle();
            

            GoTextNode x = new GoTextNode();
            x.Background = s;
            GoTextNode x1 = new GoTextNode();
            x1.Background = s1;
            GoTextNode x2 = new GoTextNode();
            x2.Background = s2;

            goView1.Document.Add(x);
            goView1.Document.Add(x1);
            goView1.Document.Add(x2);

            GoLink l = new GoLink();
            GoLink l1 = new GoLink();
            GoLink l2 = new GoLink();



            l.FromPort = x.BottomPort;
            l.ToPort = x2.TopPort;

            goView1.Document.LinksLayer.Add(l);

            l1.FromPort = x.RightPort;
            l1.ToPort = x1.TopPort;

            goView1.Document.LinksLayer.Add(l1);
            l2.FromPort = x1.BottomPort;
            l2.ToPort = x2.TopPort;

            goView1.Document.LinksLayer.Add(l2);
            layout.DirectionOption = GoLayoutDirection.Down;
            layout.PerformLayout();
          



        }

        private void button1_Click(object sender, EventArgs e)
        {
            layout.PerformLayout();
        }
    }
}

This is the entire application. It is basically 3 nodes and a button.

Notice what happens when you click on the Button1

Do you know of any workaround

Susan

If you change your button1_Click code to:

layout.Network = null;
layout.PerformLayout();
then you won't have that problem. Or more generally, create a new GoLayoutLayeredDigraph each time you want to call PerformLayout.
I'm not sure what how that residual memory of the Network is causing the behavior you see.

Thank you Walter,

That really did help.

Susan

Similar problem.

I modified FlowCharter to illustrate the issue. Add the following code to MainForm(), replacing fileSaveAllMenuItem_Click().

protected void fileSaveAllMenuItem_Click(Object sender, EventArgs evt) 
{
   GraphViewWindow canvas = this.ActiveMdiChild as GraphViewWindow;
   if (canvas != null)
   {
  LayoutDocument(canvas.Doc);
   }
}

 public void LayoutDocument(GraphDoc doc)
{
   GoLayoutLayeredDigraph m_layout = new GoLayoutLayeredDigraph();

   m_layout.Network = null;
   m_layout.DirectionOption = GoLayoutDirection.Down;
   m_layout.LayeringOption = GoLayoutLayeredDigraphLayering.OptimalLinkLength;
   m_layout.PackOption = GoLayoutLayeredDigraphPack.Median;
   m_layout.AggressiveOption = GoLayoutLayeredDigraphAggressive.More;
   m_layout.Document = doc;
   m_layout.PerformLayout();
}

Add reference and using for Northwoods.Go.Layout. And if you want to be fancy replace the “Save All” menu text with “Layout”.

Build a graph in the following format:

           A
            |
      C - B
       |   |
      D - E

Not sure link direction matters, but A->B->C->D->E and B->E

Layout.

Layout again. Notice the graph layout has changed. Slightly, typically one link is moved, but a problem when I am trying to implement a “Restore to default layout” feature.

Note further layouts do not change the graph.

Any suggestions?

Thank You
Jack

Perhaps I’m not getting the same behavior as you, but I notice that a subsequent layout just moves the nodes by a very small fraction of a pixel. It’s so small that you cannot see it.

Is that what you are referring to?

I am definitely getting noticeable movement of the second layout. On the order of several pixels.

Perhaps the initial graph layout makes a difference. I’ve sent the initial layout, after first layout and after second layout graphs from the FlowCharter example to gosales.

Also sent the code change to FlowCharter->MainForm().

Thank You
Jack

Thanks for sending the files. OK, for that particular graph (InitialLayout.dat), I get the behavior I think you are talking about.

If you don’t set the PackOption property, it doesn’t happen. In fact, I wouldn’t bother to set any of the options except for the direction. That doesn’t mean you’ll always get the same results, though.

The real point I think is that none of the layout algorithms are guaranteed to be produce the same results independent of how the initial graph was constructed.