[Kst] [Bug 125299] when axes are reversed, mouse zooming is borked

Duncan Hanson duncan.hanson at gmail.com
Wed Jun 7 19:43:06 CEST 2006


------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
You are on the CC list for the bug, or are watching someone who is.
         
http://bugs.kde.org/show_bug.cgi?id=125299         




------- Additional Comments From duncan.hanson gmail com  2006-06-07 19:43 -------
SVN commit 549185 by dhanson:

CCBUG:125299 partial fix. change the way that dx_per_pix is calculated slightly. redo calculation of dy_per_pix. there will still be problems with 1) clicking on lines in logarithmic graphs. I don't see an easy way to solve this.

 M  +19 -10    kst2dplot.cpp  


--- trunk/extragear/graphics/kst/src/libkstapp/kst2dplot.cpp #549184:549185
 @ -6081,6 +6081,7  @
 
 
 void Kst2DPlot::mouseDoubleClickEvent(QWidget *view, QMouseEvent *e) {
+  // allow user to edit a curve if click was close enough.
   Q_UNUSED(view)
   KstBaseCurvePtr curve;
   QRect pr = GetPlotRegion();
 @ -6091,28 +6092,36  @
 
   getCursorPos(pos, xpos, ypos, xmin, xmax, ymin, ymax);
 
-  // convert 1 pixel to plot units.
-  double dx_per_pix = double(pos.x() + 2 - pr.left()) / double(pr.width()) * (xmax - xmin) + xmin;
-  if (isXLog()) {
-    dx_per_pix = pow(_xLogBase, dx_per_pix);
+  // calculate max x distance.
+  double dx_per_pix;
+  if (!isXLog()) {
+    dx_per_pix = (xmax - xmin)/pr.width();
+  } else {
+    dx_per_pix = xpos*log(_xLogBase)*(xmax - xmin)/pr.width();
   }
-  dx_per_pix -= xpos;
-  double dx = 5*dx_per_pix;
+  double dx = fabs(5.0*dx_per_pix); //~5 pixels.
 
+  // calculate max y distance.
+  double dy_per_pix;
+  if (!isYLog()) {
+    dy_per_pix = (ymin - ymax)/pr.height();
+  } else {
+    dy_per_pix = ypos*log(_yLogBase)*(ymin - ymax)/pr.height();
+  }
+  double dy = fabs(5.0*dy_per_pix); //~5 pixels.
+
   for (KstBaseCurveList::Iterator i = Curves.begin(); i != Curves.end(); ++i) {
     (*i)->readLock();
     double distance = (*i)->distanceToPoint(xpos, dx, ypos);
     (*i)->readUnlock();
-    if (isYLog()) {
-      distance = log(distance);
-    }
+
     if (distance < best_distance || !curve) {
       best_distance = distance;
       curve = *i;
     }
   }
 
-  if (curve && fabs(best_distance * pr.height() / (ymax - ymin)) <= 5) {
+  if (curve && fabs(best_distance) <= dy) {
     curve->readLock();
     KstDataObjectPtr provider = curve->providerDataObject();
     if (provider) {


More information about the Kst mailing list