# Forcing a graph not to resize

This code:

Clear[ighamiltMol,timeList,hamiltMol,];

timeList={Abs[0.333333 E^(-I t) + 0.333333 E^(I t) + 0.166667 E^(-2 I t) +
0.166667 E^(2 I t)]^2,
Abs[0.\[VeryThinSpace]+ 0.166667 E^(-I t) - 0.166667 E^(I t) +
0.166667 E^(-2 I t) - 0.166667 E^(2 I t)]^2,
Abs[-0.166667 E^(-I t) - 0.166667 E^(I t) + 0.166667 E^(-2 I t) +
0.166667 E^(2 I t)]^2,
Abs[-0.333333 E^(-I t) + 0.333333 E^(I t) + 0.166667 E^(-2 I t) -
0.166667 E^(2 I t)]^2,
Abs[0.\[VeryThinSpace]- 0.166667 E^(-I t) - 0.166667 E^(I t) +
0.166667 E^(-2 I t) + 0.166667 E^(2 I t)]^2,
Abs[0.166667 E^(-I t) - 0.166667 E^(I t) + 0.166667 E^(-2 I t) -
0.166667 E^(2 I t)]^2}

hamiltMol={{0, 1, 0, 0, 0, 1}, {1, 0, 1, 0, 0, 0}, {0, 1, 0, 1, 0, 0}, {0, 0, 1,
0, 1, 0}, {0, 0, 0, 1, 0, 1}, {1, 0, 0, 0, 1, 0}}

ighamiltMol =
VertexLabels -> Placed["Name", Tooltip],
GraphStyle -> "SpringEmbedding",
VertexShapeFunction -> (Disk[#1, timeList[[#2]]] &)];

Animator[Dynamic[t], {0, 19}, .5]
ighamiltMol


Generates this animation (2 pictures shown, notice the resizing):

I would like my disks' radii not to exceed 2/3 of the distance between two vertices, so that the graph needs no resizing.

The same method applied to GraphPlot[] and GraphPlot3D[] also does not work, producing results like those obtained with AdjacencyGraph[]. I've tried setting a DataRange->{}, but it doesn't work either. Rescale[]ing didn't work.

(Note that this is not a problem in a Graphics[] environment.)

I don't know what to try next.

-
Your pasted code is incomplete. E.g. in the first snippet, hamiltMoland timeCoeff are not defined. – Yves Klett Mar 16 '12 at 7:34
They are - commented out. hamiltMol is an adjacency matrix and timeCoeff[] looks in a table containing complex exponentials, one per vertex. The problem occurs even with a square and a Sin[] varying disk radius. – CHM Mar 16 '12 at 8:16
Working code will get you more takers. Just paste in a toy example, if the original is too complex. – Yves Klett Mar 16 '12 at 8:44
@YvesKlett The code has been edited. – CHM Mar 16 '12 at 20:15

Assuming that timecoeff is scaled between 0 and 1 you could do something like this (I just made something up for timecoeff and hamiltMol):

Clear[ighamiltMol, t]; t = 0;
timeCoeff[i_] := (1 + Sin[t + 2.5 i])/2
hamiltMol = NestList[RotateRight, {0, 1, 0, 0, 0, 1}, 5];

ighamiltMol =
EdgeShapeFunction -> (Line[#1] &),
VertexLabels -> Placed["Name", Tooltip],
GraphStyle -> "SpringEmbedding",
VertexShapeFunction -> ({{Opacity[0], Disk[#1, #3]},
Disk[#1, #3 timeCoeff[#2] ]} &),
VertexSize ->
4/3];(*timeCoeff[] looks in a list of complex \
exponentials*)Animator[Dynamic[t], {0, 2 Pi}, .1]
ighamiltMol


This works by using a VertexShapeFunction which consists of two disks on top of each other, namely a transparent one with a fixed radius, and a solid one with a varying radius. The option VertexSize -> 4/3 makes sure that the maximum radius is equal to 2/3 time the mimimum length of all vertices.

-
Changing VertexSize doesn't work for me, neither does adding a normalization factor to timeCoeff[]. I think the problem lies in the space that's allocated for the graph by Mathematica - it's constantly updated. What I'd like is for the graph to be centered in a wider canvas, so there's no need to resize. – CHM Mar 16 '12 at 20:33
The invisible disks should prevent the size of the graph from changing as t changes. VertexSize only works in combination with multiplying the radius of the disks with the third argument supplied to VertexShapeFunction. – Heike Mar 16 '12 at 20:43
Turns out EdgeShapeFunction was essential. Thank you =) – CHM Mar 16 '12 at 20:59
Heike, congratulations on the first tag badge! – Mr.Wizard Mar 18 '12 at 18:53
Thanks @Mr.Wizard. – Heike Mar 18 '12 at 19:12