[Kst] extragear/graphics/kst/src/libkstapp

Andrew Walker arwalker at sumusltd.com
Mon Feb 12 21:46:43 CET 2007


SVN commit 632987 by arwalker:

ensure we don't create plots on the right edge of the window that are wider than all the other plots

 M  +20 -12    kstviewobject.cpp  


--- trunk/extragear/graphics/kst/src/libkstapp/kstviewobject.cpp #632986:632987
@@ -700,7 +700,7 @@
   KstViewObjectList childrenCopy;
   double ave_w = 0.0;
   bool dirty = false;
-  
+
   for (KstViewObjectList::ConstIterator i = _children.begin(); i != _children.end(); ++i) {
     if ((*i)->followsFlow()) {
       childrenCopy.append(*i);
@@ -709,12 +709,12 @@
   }
 
   int cnt = childrenCopy.count();
-  
+
   if (cnt < 1) {
     return;
   }
   ave_w /= double(cnt);
-  
+
   // FIXME: don't allow regrid to a number of columns that will result in
   //        >= height() plots in a column
   if (cols <= 0) {
@@ -754,13 +754,12 @@
   // unless there is another plot which is closer, in which case the 
   // plot gets dumped into an un-assigned list for placement into a
   // random un-filled grid space.
-  // the Location is defined relative to the left-middle.
+  // the location is defined relative to the left-middle.
   // QUESTION: should we use the middle-middle instead?
   // NOTE: the choice of grid location assumes a regular grid, which is
   // broken when supressed axis/labels are taken into account.  This
   // could have an effect if the plots are grown by >50%.
   for (int i = 0; i < cnt; ++i) {
-    //r = int(childrenCopy[i]->aspectRatio().y*rows+0.5); //use top
     r = int((childrenCopy[i]->aspectRatio().y+childrenCopy[i]->aspectRatio().h/2)*rows); // use center
     c = int(childrenCopy[i]->aspectRatio().x*_columns+0.5);
 
@@ -796,7 +795,7 @@
     }
   }
   // now dump the unassigned plots in random holes.
-  // Question: should be dump them in the closest holes?
+  // Question: should we dump them in the closest holes?
   CR = 0;
   for (int i = 0; i < n_unassigned; ++i) {
     for (; plotLoc[CR] != -1; ++CR) { }
@@ -807,7 +806,7 @@
   double sum_HR = 0.0;
   KstViewObject *ob;
   double hr;
-  
+
   for (r=0; r<rows; r++) {
     HR[r] = 10.0;
     for (c=0; c<_columns; c++) {
@@ -831,7 +830,6 @@
   int y = 0;
   for (r=0; r<rows; r++) {
     y += h;
-    //h = _geom.height() / rows;
     h = int(double(_geom.height()) * HR[r]/sum_HR);
     for (c=0; c<_columns; c++) {
       CR = c + r*_columns;
@@ -841,14 +839,24 @@
         c = CR % _columns;
         QPoint pt(w*c, y);
 
-        // adjust the last column to be sure that we don't spill over
+        // if necessary adjust the last column so that we don't spill over
         if (c == _columns-1) {
-          sz.setWidth(_geom.width() - w*c);
+          // only adjust the final width if necessary as we would rather have a gap
+          // at the right edge of the window than a column of plots that is significantly 
+          // wider than all the others
+          if (w*_columns > _geom.width()) {
+            sz.setWidth(_geom.width() - w*c);
+          }
         }
 
-        // adjust the last row to be sure that we don't spill over
+        // if necessary adjust the last row so that we don't spill over
         if (r == rows - 1) {
-          sz.setHeight(_geom.height() - y);
+          // only adjust the final height if necessary as we would rather have a gap
+          // at the bottom edge of the window than a row of plots that is significantly 
+          // taller than all the others
+          if (y + h > _geom.height()) {
+            sz.setHeight(_geom.height() - y);
+          }
         }
 
         ob = childrenCopy[plotLoc[CR]];


More information about the Kst mailing list