Web forum is in read-only mode. Login as active registered customer for write access
  Forum Search   New Posts New Posts

Struggling with the basics and forcelayout

 Post Reply Post Reply
Author
Jason Chapman View Drop Down
New Member
New Member
Avatar

Joined: 19 Oct 2018
Posts: 11
Post Options Post Options   Quote Jason Chapman Quote  Post ReplyReply Direct Link To This Post Topic: Struggling with the basics and forcelayout
    Posted: 07 Aug 2019 at 4:26pm
Hi,  
This is my first run at the diagram studio and the lack of some really basic programmatic examples is making my head hurt.  I've spent about 1/2 a day on this and need to put it down for a bit, so a good time to ask a question.  I was trying to throw a load of ellipses (which represent a single rooted hierarchy) with a number of child ellipses.  It is action one ellipse per web page in a "up linked" site.

The following is cobbled from your examples and help file, so needs tidying obvs.
This just puts all the ellipses on top of each other and then I use the forceLayout example and it basically all the ellipses dissappear.  If you use the navigator, it looks like it makes the canvas / scroll area really really huge, i.e. the red box becomes a pixel.

I thought I could throw the 800 odd ellipses on there and it would lay them out for me.  While I am it, there are 10 examples?  I am looking for pretty basic programmatic manipulation of the diagram.

TIA
JAC

procedure TfraPageDiagram.AddObject(v: TjHTMLFile);
var
 MyBlock : TDiagramBlock;
 idx : Integer;
 myLine : TDiagramLine;
begin
  MyBlock := TDiagramBlock.Create(atdgrmDiagram.Owner);
  with MyBlock do
  begin
    Left := 10;
    Top := 10;
    Shape := bsEllipse;
//    Text:=v.UpdatedFileName;
    TextCells[0].Text:=v.UpdatedFileName;
    Width := 50;
    Height := 30;
    Obj :=V;
    MyBlock.LinkPoints.Add((MyBlock.Right - MyBlock.Left)/2,MyBlock.top,aoup);
    MyBlock.LinkPoints.Add((MyBlock.Right - MyBlock.Left)/2,MyBlock.bottom,aoDown);


    Diagram := atdgrmDiagram;

    if v.Parent <> nil then
    begin
      idx:=atdgrmDiagram.BlockCount-1;
      while idx >= 0  do
      begin
        if atdgrmDiagram.Blocks[idx].Obj = v.Parent then
        begin
          MyLine := TDiagramLine.Create(atdgrmDiagram.Owner);
          myLine.Diagram := atdgrmDiagram;
          myLine.SourceLinkPoint.AnchorLink := MyBlock.LinkPoints[0]; //link start point to someblock
          myLine.TargetLinkPoint.AnchorLink := atdgrmDiagram.Blocks[idx].LinkPoints[1]; // link end point to anotherblock
          myLine.RequiresConnections:=true;
        end;
       Dec(idx);
      end;
    end;
  end;
end;
Back to Top
Wagner R. Landgraf View Drop Down
TMS Support
TMS Support
Avatar

Joined: 18 May 2010
Posts: 2399
Post Options Post Options   Quote Wagner R. Landgraf Quote  Post ReplyReply Direct Link To This Post Posted: 10 Aug 2019 at 2:20am
Hello Jason,
You provided the code that creates and places a new ellipse in the diagram. That code looks correct, and from what you said, I understand you confirms that part is ok?
Indeed all the objects are being placed in the same location (Left=10, Top=10). I would suggest you try to find a better placement for those ellipses, using some logic that fits your needs (add each ellipse X pixels from the right and Y pixels from the bottom of previous ellipse, for example, or just X pixels from the right until end of diagram area and then add Y pixels to bottom and X going back to 10, etc.).
The force diagram is not a strict layout diagram. It just simulates a repulsion force between all objects (they are "expelled" from each other). The parameters of the algorithm control how strong is that force, and how long the objects keep going away until they stop. You can try to reduce the RepulsionConstant parameter to see if it works. You can also play with the other parameters, when it comes to force layout you might need some try and error approach because the results really depend on your initial layout.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down