Index: /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/SetGraphSize.c
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/SetGraphSize.c	(revision 13470)
+++ /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/SetGraphSize.c	(revision 13471)
@@ -7,4 +7,5 @@
 
   int fontsize, bump, Nc;
+  int textpad, textdY, WdY; 
   double PADx, PADy, Dx, Dy;
   double PXm, PXp, PYm, PYp;
@@ -32,9 +33,33 @@
   PYp = (graph[0].axis[2].islabel) ? 4*fontsize : 0;
  
-  /* size of the graph in Xwindow coordinates */
+  /* basic size of the graph in Xwindow coordinates */
   X0 = PADx + PXm + (Dx * section[0].x);
   Y0 = PADy + PYm + (Dy * section[0].y);
   dX = (Dx * section[0].dx) - PXp - PXm;
   dY = (Dy * section[0].dy) - PYp - PYm;
+
+  // if we are tied to an image, make mods as needed
+  if (section->image) {
+    textpad = graphic[0].font[0].ascent;
+    textdY = 6*textpad + 7*PAD1;
+    WdY = MAX (ZOOM_Y, textdY + 2*BUTTON_HEIGHT + PAD1);
+
+    switch (section->image->location) {
+      case 1:
+	Y0 = graphic[0].dy * section[0].y + 2*PAD1 + WdY + 2; // tied to image in Y
+	dY = graphic[0].dy * section[0].dy - 5*PAD1 - WdY - COLORPAD + 1;
+	break;
+      case 3:
+	dY = graphic[0].dy * section[0].dy - 5*PAD1 - WdY - COLORPAD - PADy - PYm;
+	break;
+      case 2:
+	X0 = graphic[0].dx * section[0].x  + 2*PAD1 + ZOOM_X;
+	dX = graphic[0].dx * section[0].dx - 3*PAD1 - ZOOM_X;
+	break;
+      case 4:
+	dX = graphic[0].dx * section[0].dx - 3*PAD1 - ZOOM_X - PADx - PXm;
+	break;
+    }
+  }
 
   /* define locations of coordinate axes */
Index: /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/SetImageSize.c
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/SetImageSize.c	(revision 13470)
+++ /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/SetImageSize.c	(revision 13471)
@@ -29,13 +29,13 @@
     case 0:
       if (section->graph) {
-	  image[0].picture.x = graph[0].axis[0].fx;
-	  image[0].picture.y = graph[0].axis[1].fy + graph[0].axis[1].dfy;
-	  image[0].picture.dx = graph[0].axis[0].dfx;
-	  image[0].picture.dy = -graph[0].axis[1].dfy;
-      } else {
+	  image[0].picture.x  = graph[0].axis[0].fx;
+	  image[0].picture.y  = graph[0].axis[1].fy + graph[0].axis[1].dfy;
+	  image[0].picture.dx = MAX(graph[0].axis[0].dfx + 1, 1);
+	  image[0].picture.dy = MAX(fabs(graph[0].axis[1].dfy) - 1, 1);
+      } else {
+	  image[0].picture.x  = Xs + PAD1;
+	  image[0].picture.y  = Ys + PAD1;
 	  image[0].picture.dx = dX - 2*PAD1; 
 	  image[0].picture.dy = dY - 2*PAD1;
-	  image[0].picture.x = Xs + PAD1;
-	  image[0].picture.y = Ys + PAD1;
       }
       if (USE_XWINDOW) CreatePicture (image, graphic);
@@ -48,8 +48,15 @@
       WdY = MAX (ZOOM_Y, textdY + 2*BUTTON_HEIGHT + PAD1);
 
-      image[0].picture.dx = dX - 2*PAD1; 
-      image[0].picture.dy = dY - 5*PAD1 - WdY - COLORPAD;
-      image[0].picture.x = Xs + PAD1;
-      image[0].picture.y = Ys + 2*PAD1 + COLORPAD;
+      if (section->graph) {
+	  image[0].picture.x = graph[0].axis[0].fx;
+	  image[0].picture.y = Ys + 2*PAD1 + COLORPAD;
+	  image[0].picture.dx = graph[0].axis[0].dfx;
+	  image[0].picture.dy = dY - 5*PAD1 - WdY - COLORPAD;
+      } else {
+	  image[0].picture.x  = Xs + PAD1;
+	  image[0].picture.y  = Ys + 2*PAD1 + COLORPAD;
+	  image[0].picture.dx = dX - 2*PAD1; 
+	  image[0].picture.dy = dY - 5*PAD1 - WdY - COLORPAD;
+      }
 
       image[0].cmapbar.dx = dX - 2*PAD1; 
@@ -108,8 +115,15 @@
       WdY = MAX (ZOOM_Y, textdY + 2*BUTTON_HEIGHT + PAD1);
 
-      image[0].picture.dx = dX - 2*PAD1; 
-      image[0].picture.dy = dY - 5*PAD1 - WdY - COLORPAD;
-      image[0].picture.x = Xs + PAD1;
-      image[0].picture.y = Ys + 4*PAD1 + COLORPAD + WdY;
+      if (section->graph) {
+	image[0].picture.x = graph[0].axis[0].fx;
+	image[0].picture.y = graph[0].axis[1].fy + graph[0].axis[1].dfy;
+	image[0].picture.dx = MAX(graph[0].axis[0].dfx, 1);
+	image[0].picture.dy = MAX(fabs(graph[0].axis[1].dfy) - 1, 1);
+      } else {
+	image[0].picture.dx = dX - 2*PAD1; 
+	image[0].picture.dy = dY - 5*PAD1 - WdY - COLORPAD;
+	image[0].picture.x = Xs + PAD1;
+	image[0].picture.y = Ys + 4*PAD1 + COLORPAD + WdY;
+      }
 
       image[0].cmapbar.dx = dX - 2*PAD1; 
@@ -164,8 +178,16 @@
 
     case 2:
-      image[0].picture.dx = dX - 3*PAD1 - ZOOM_X; 
-      image[0].picture.dy = dY - 3*PAD1 - COLORPAD;
-      image[0].picture.x = Xs + 2*PAD1 + ZOOM_X;
-      image[0].picture.y = Ys + 2*PAD1 + COLORPAD;
+
+      if (section->graph) {
+	image[0].picture.x = Xs + 2*PAD1 + ZOOM_X;
+	image[0].picture.y = graph[0].axis[1].fy + graph[0].axis[1].dfy;
+	image[0].picture.dx = dX - 3*PAD1 - ZOOM_X; 
+	image[0].picture.dy = MAX(fabs(graph[0].axis[1].dfy) - 1, 1);
+      } else {
+	image[0].picture.dx = dX - 3*PAD1 - ZOOM_X; 
+	image[0].picture.dy = dY - 3*PAD1 - COLORPAD;
+	image[0].picture.x = Xs + 2*PAD1 + ZOOM_X;
+	image[0].picture.y = Ys + 2*PAD1 + COLORPAD;
+      }
 
       image[0].cmapbar.dx = dX - 2*PAD1; 
@@ -221,8 +243,16 @@
 
     case 4:
-      image[0].picture.dx = dX - 3*PAD1 - ZOOM_X; 
-      image[0].picture.dy = dY - 3*PAD1 - COLORPAD;
-      image[0].picture.x = Xs + PAD1;
-      image[0].picture.y = Ys + 2*PAD1 + COLORPAD;
+
+      if (section->graph) {
+	image[0].picture.x = graph[0].axis[0].fx;
+	image[0].picture.y = graph[0].axis[1].fy + graph[0].axis[1].dfy;
+	image[0].picture.dx = dX - 3*PAD1 - ZOOM_X - graph[0].axis[0].fx; 
+	image[0].picture.dy = MAX(fabs(graph[0].axis[1].dfy) - 1, 1);
+      } else {
+	image[0].picture.dx = dX - 3*PAD1 - ZOOM_X; 
+	image[0].picture.dy = dY - 3*PAD1 - COLORPAD;
+	image[0].picture.x = Xs + PAD1;
+	image[0].picture.y = Ys + 2*PAD1 + COLORPAD;
+      }
 
       image[0].cmapbar.dx = dX - 2*PAD1; 
