Locate new added node without change the others

Probably I can read some books on “algorithm for the Visualization of graph” but i will take a long before i will be able to resolve my issue.

I don’t want to set Layout conditions to automatically relocate all nodes on Added or Removed nodes event, because I want keep the user location choice as long as he doesn’t decide to reorganize his diagram.

But in some particular place (droponto, or programmaticaly node adding) I want to place these nodes.

Can you tell me, if there exists a function that place only one Node (following the choosen layout) and let all the other nodes location unchanged.

Thanks
Aurore

Well, perhaps you remember: incremental layout only with ForceDirectedLayout

If you could imagine using a TreeLayout, for example, and a single node was added that was connected from an existing node in the middle of the tree, where would you want that node to go? It’s quite possible that there would be no room for the node to be placed without it overlapping other nodes.

Even if you had the flexibility to place the new node at either end of the existing collection of sibling nodes, there might not be room because different parts of the tree happen to be adjacent.

But if you know what you want to do, perhaps you could implement this yourself.

In fact, in treelayout or LayeredLayout it’s quite simple in my case, new nodes will be added after the last node.

My difficult is in starlayout, I don’t know where trying to set my node.

In facts, it doesn’t matter if the added node overlap some others, i’d like just that those droponto will be move correctly.

Thanks for your time.

Oh, and just in case it wasn’t already clear to you (or someone else reading this post), if you have set Diagram.Layout to be some kind of layout such as TreeLayout, you can set its Conditions property to not include LayoutChange values for adding or removing nodes or links.

Alternatively, you could just use the default Diagram.Layout and perform any layouts programmatically when desired, without ever setting the Diagram.Layout property.

(crossing posts)

Ah, well, your “star layout” is presumably our ForceDirectedLayout, so there is a solution there. Basically you just need to set ForceDirectedVertex.IsFixed to true for all of the nodes that you don’t want to move, or override ForceDirectedLayout.IsFixed to achieve the same effect.

I suspect in your case the latter might be easier to implement – the override would return true unless the argument’s ForceDirectedVertex.Node is a “new” node.

I’m sorry to be stupid but can you precise your idea.

I’ve tried to use my own ForceDirecteLayout class in order to override IsFixed function, but how can we decide from vertex.Node that it is a “new” node ?

[code] public class IncrementalForceDirectedLayout : ForceDirectedLayout {
public IEnumerable NewNodes { get; set; }

public override void DoLayout(IEnumerable<Node> nodes, IEnumerable<Link> links) {
  base.DoLayout(nodes, links);
  this.NewNodes = null;  // reset so that it doesn't affect future layouts
}

protected override bool IsFixed(ForceDirectedVertex v) {
  if (this.NewNodes == null) return base.IsFixed(v);  // default behavior
  return !this.NewNodes.Contains(v.Node);  // fixed position if not in NewNodes
}

}[/code]
Install with either:
myDiagram.Layout = new IncrementalForceDirectedLayout();
or:
go:Diagram.Layout
<local:IncrementalForceDirectedLayout />
</go:Diagram.Layout>

Now, if you want a layout of only new nodes dropped from a different Diagram (such as a Palette):

myDiagram.ExternalObjectsDropped += (s, e) => { . . . maybe connect SelectedParts to existing nodes . . . var layout = myDiagram.Layout as IncrementalForceDirectedLayout; if (layout != null) layout.NewNodes = myDiagram.SelectedParts.OfType<Node>().ToList(); };
Presumably your Diagram.ExternalObjectsDropped event handler will either explicitly connect any newly dropped nodes, available in the Diagram.SelectedParts collection, or it will depend on the behavior of automatically linking new nodes using Part.DropOntoBehavior.

This IncrementalForceDirectedLayout can also be used when programmatically adding nodes with links to your diagram. Just set its NewNodes property before you commit your transaction.