[Kst] [Bug 111044] precision not always enough when in data mode

George Staikos staikos at kde.org
Mon Sep 19 21:39:25 CEST 2005


------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
         
http://bugs.kde.org/show_bug.cgi?id=111044         
staikos kde org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED



------- Additional Comments From staikos kde org  2005-09-19 21:39 -------
SVN commit 462040 by staikos:

- remove some apparently dead code
- increase data mode precision.  Rounding really isn't right.  I tried to make
a fast heuristic for determining the precision automatically but I think it's
too much work and not worth the effort.

BUG: 111044


 M  +23 -50    kst2dplot.cpp  


--- trunk/extragear/graphics/kst/kst/kst2dplot.cpp #462039:462040
 @ -3730,22 +3730,36  @
 }
 
 
+template<class T>
+inline T kstClamp(const T& x, const T& low, const T& high) {
+  if (x < low)       return low;
+  else if (high < x) return high;
+  else               return x;
+}
+
+
 void Kst2DPlot::highlightNearestDataPoint(bool bRepaint, QWidget *view, const QPoint& pos) {
   QString msg;
+  int precision = 15;
 
-  if (Curves.count() > 0) {
+  if (!Curves.isEmpty()) {
     QString name;
     double newxpos, newypos;
     double xmin, ymin;
     double xmax, ymax;
-    uint length;
 
-    if (getNearestDataPoint(pos, newxpos, newypos, name, xmin, ymin, xmax, ymax)) {
+    if (getNearestDataPoint(pos, newxpos, newypos, name, xmin, xmax, ymin, ymax)) {
       QString xlabel;
       QString ylabel;
       QString msgXOffset;
       QString msgYOffset;
 
+#if 0
+      // Determine if we need to expand precision
+      precision = kstClamp(int(ceil(log10(1.0 / (xmax - xmin)))) + 2, precision, 15);
+      precision = kstClamp(int(ceil(log10(1.0 / (ymax - ymin)))) + 2, precision, 15);
+#endif
+
       if (_copy_x != newxpos || _copy_y != newypos) {
         QPainter p(view);
 
 @ -3759,6 +3773,7  @
       }
 
       if (_isXAxisInterpreted) {
+        uint length;
         genAxisTickLabelFullPrecision(_xAxisInterpretation, _xAxisDisplay,
                                       _xAxisTimezoneLocal, _xAxisTimezoneHrs,
                                       xlabel, length, newxpos, isXLog(), true);
 @ -3772,13 +3787,14  @
           }
         }
       } else {
-        xlabel = QString::number(newxpos,'G');
+        xlabel = QString::number(newxpos, 'G', precision);
         if (_cursorOffset) {
-          msgXOffset = QString::number(newxpos-_cursor_x,'G');
+          msgXOffset = QString::number(newxpos - _cursor_x, 'G', precision);
         }
       }
 
       if (_isYAxisInterpreted) {
+        uint length;
         genAxisTickLabelFullPrecision(_yAxisInterpretation, _yAxisDisplay,
                                       _yAxisTimezoneLocal, _yAxisTimezoneHrs,
                                       ylabel, length, newypos, isYLog(), true);
 @ -3792,9 +3808,9  @
           }
         }
       } else {
-        ylabel = QString::number(newypos,'G');
+        ylabel = QString::number(newypos, 'G', precision);
         if (_cursorOffset) {
-          msgYOffset = QString::number(newypos-_cursor_y,'G');
+          msgYOffset = QString::number(newypos - _cursor_y, 'G', precision);
         }
       }
 
 @ -3804,49 +3820,6  @
         msg = i18n("Curve name, (x, y)", "%3 (%1, %2)").arg(xlabel).arg(ylabel).arg(name);
       }
     }
-
-//     // display the z value of the topmost image underneath cursor, if available...
-//     if (_images.count() > 0) {
-//       double zValue;
-//       double xpos = 0.0;
-//       double ypos = 0.0;
-//       bool found = false;
-//       int i = _images.count() - 1;
-// 
-//       while (i >= 0 && !found) {
-//         if (_images[i]->getNearestZ(xpos, ypos, zValue)) {
-//           found = true;
-//         }
-//         i--;
-//       }
-// 
-//       if (found) {
-//         QString xlabel, ylabel;
-//         uint length;
-// 
-//         if (_isXAxisInterpreted) {
-//           genAxisTickLabelFullPrecision(_xAxisInterpretation, _xAxisDisplay,
-//                                         _xAxisTimezoneLocal, _xAxisTimezoneHrs,
-//                                         xlabel, length, xpos, isXLog(), true);
-//         } else {
-//           xlabel = QString::number(xpos,'G');
-//         }
-// 
-//         if (_isYAxisInterpreted) {
-//           genAxisTickLabelFullPrecision(_yAxisInterpretation, _yAxisDisplay,
-//                                         _yAxisTimezoneLocal, _yAxisTimezoneHrs,
-//                                         ylabel, length, ypos, isYLog(), true);
-//         } else {
-//           ylabel = QString::number(ypos,'G');
-//         }
-// 
-//         if (!msg.isEmpty()) {
-//           msg = i18n("Label, Image name (x, y, z)", "%5, %4 (%1, %2, %3)" ).arg(xlabel).arg(ylabel).arg(zValue,0,'G').arg(_images[i+1]->tagName()).arg(msg);
-//         } else {
-//           msg = i18n("Image name (x, y, z)", "%4 (%1, %2, %3)" ).arg(xlabel).arg(ylabel).arg(zValue,0,'G').arg(_images[i+1]->tagName());
-//         }
-//       }
-//     }
   }
 
   KstApp::inst()->slotUpdateDataMsg(msg);


More information about the Kst mailing list