Skip to content

save Restore Node Positions

Kevin Murphy edited this page Jan 3, 2014 · 1 revision

It is now possible to save and restore node positions using two new methods, getNodePositions() and setNodePositions():

adj = rand(10, 10) > 0.9; 
g = graphViz4Matlab(adj);
X = g.getNodePositions();
X(1, :) = [0.5 0.5]; 
g.setNodePositions(X)
  • Coordinates are normalized so that {{{0}}} is the bottom left hand corner, and {{{1}}} is the top right.

  • X(i, 1) is the x-position of the ith node, and X(i, 2) is its y position.

  • To move a single node, you can use g.moveNode(i, xpos, ypos);

  • Coordinates specify a node's center. You must take into account its current diameter to avoid moving it off the visible screen. This code moves node 1 to the bottom left corner.

    diameter = g.nodeArray(1).width radius = diameter/2; g.moveNode(1, radius, radius);