Preserve the position of a node in a hierarchical layout after the node has been replaced

Article ID: 2242
Last updated: 28 May, 2018
Article ID: 2242
Last updated: 28 May, 2018
Revision: 3
Views: 643
Posted: 15 Apr, 2004
by Dean J.
Updated: 28 May, 2018
by Gargani A.

Question

How to preserve the position of a node in a hierarchical layout after the node has been replaced?

Answer

Replacing a single node in the grapher may cause major differences at the

next layout of the nodes. The incremental mode helps to preserve the old

positions when new nodes are added to a grapher laid out with the class

IlvHierarchicalLayout.

These are the steps for replacing a node with minimal impact on the overall

layout:

  1. Perform layout on the graph.
  2. Set the incremental mode to true.
  3. Get the center coordinates of the node:

    IlvRect bbox = oldnode.boundingBox();

    float centerX = bbox.x + 0.5f * bbox.width;

    float centerY = bbox.y + 0.5f * bbox.height;

  4. Replace the node.
  5. Set the position of the new node so that its center matches

    the position of the old node:

    IlvRect bbox = newnode.boundingBox();

    manager.moveObject(newnode,

    centerX - 0.5f * bbox.width,

    centerY - 0.5f * bbox.height,

    true);

  6. Perform layout on the graph again.

This article was:   Helpful | Not helpful
Report an issue
Article ID: 2242
Last updated: 28 May, 2018
Revision: 3
Views: 643
Posted: 15 Apr, 2004 by Dean J.
Updated: 28 May, 2018 by Gargani A.
Also listed in


Others in this category