Bug 68040

Summary: DataMode doesn't show correct y-axis data
Product: [Applications] kst Reporter: Matthew Truch <matt>
Component: generalAssignee: George Staikos <staikos>
Status: RESOLVED FIXED    
Severity: normal    
Priority: NOR    
Version: 1.x   
Target Milestone: ---   
Platform: RedHat Enterprise Linux   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:

Description Matthew Truch 2003-11-12 19:11:46 UTC
Version:           0.94 (using KDE KDE 3.1)
Installed from:    RedHat RPMs
OS:          Linux

When DataMode is activated, the lower right mouse data box changes to show data for the nearest curve.  However, although the x-data changes, the y-data stays constant, no matter where on the plot you move the mouse.  

How to reproduce:  Plot a curve in kst (make sure it changes some in y over the visible range of the plot).  Activate DataMode.  Move mouse around.

Expected Behavior:  Lower right coordinates show coordinate pair cooresponding to nearest position of curve to mouse.
Comment 1 Matthew Truch 2003-11-12 19:48:06 UTC
I can't reproduce this bug when --enable-debug is passed to ./configure at compile time, only in other binaries.  
Comment 2 George Staikos 2003-11-12 21:43:17 UTC
Subject: Re: [Kst]  New: DataMode doesn't show correct y-axis data

On Wednesday 12 November 2003 13:11, Matthew Truch wrote:
> When DataMode is activated, the lower right mouse data box changes to show
> data for the nearest curve.  However, although the x-data changes, the
> y-data stays constant, no matter where on the plot you move the mouse.
>
> How to reproduce:  Plot a curve in kst (make sure it changes some in y over
> the visible range of the plot).  Activate DataMode.  Move mouse around.
>
> Expected Behavior:  Lower right coordinates show coordinate pair
> cooresponding to nearest position of curve to mouse.

  I can't reproduce this.

Comment 3 George Staikos 2003-11-24 06:32:45 UTC
Ah I see what's wrong
Comment 4 George Staikos 2003-11-24 07:28:48 UTC
Subject: kdeextragear-2/kst/kst

CVS commit by staikos: 

Interpolate y axis manually in data mode

CCMAIL: 68040-done@bugs.kde.org


  M +9 -1      kstview.cpp   1.57


--- kdeextragear-2/kst/kst/kstview.cpp  #1.56:1.57
@@ -405,5 +405,13 @@ void KstView::updateMouse() {
       for (KstBaseCurveList::Iterator i = pPlot->Curves.begin(); i != pPlot->Curves.end(); ++i) {
         double xpt = 0.0, ypt = 0.0;
-        (*i)->getPoint((*i)->sampleCount() * xpos / ((*i)->maxX() - (*i)->minX()), xpt, ypt);
+        double pt = (*i)->sampleCount() * xpos / ((*i)->maxX() - (*i)->minX());
+        (*i)->getPoint(pt, xpt, ypt);
+
+        // We have to get the previous point and interpolate y here, otherwise
+        // datamode y coordinates don't look right.
+        double xpt2 = 0.0, ypt2 = 0.0;
+        (*i)->getPoint(pt + 1, xpt2, ypt2);
+        ypt += (pt - xpt) * (ypt2 - ypt) / (xpt2 - xpt);
+
         if (fabs(ypos - ypt) < delta) {
           delta = fabs(ypos - ypt);


Comment 5 Netterfield 2003-12-20 16:18:05 UTC
I think that data mode should snap to the nearest actual data point, and not interpolate...  Mat?


Comment 6 Matthew Truch 2003-12-20 16:28:04 UTC
Quoth CBN: "I think that data mode should snap to the nearest actual data point, and not interpolate... Mat?"

I agree.  We want to see actual data in datamode.  
Comment 7 George Staikos 2003-12-21 07:02:20 UTC
Ok, we pretty much revert the last changes applied here. :-)
Comment 8 George Staikos 2003-12-23 05:34:50 UTC
Hm this makes for interesting behaviour with multiple curves on a plot.  Anyhow, I have this mostly implemented.  I will also add the point indicator as discussed.
Comment 9 George Staikos 2003-12-23 06:18:16 UTC
Subject: kdeextragear-2/kst/kst

CVS commit by staikos: 

data mode reverted to old behaviour with minor fixes

CCMAIL: 68040-done@bugs.kde.org


  M +10 -11    kstview.cpp   1.60


--- kdeextragear-2/kst/kst/kstview.cpp  #1.59:1.60
@@ -371,5 +371,5 @@ void KstView::updateMouse() {
   int plot = MouseInfo->getPlotNum();
   QString msg;
-  KstPlot* pPlot;
+  KstPlot *pPlot;
 
   if (plot >= 0 && (pPlot = KST::plotList.at(plot))) {
@@ -400,4 +400,5 @@ void KstView::updateMouse() {
     if (_dataMode) {
       double newypos = ypos;
+      double newxpos = xpos;
       KstBaseCurvePtr curve;
       double delta = 9e99;
@@ -405,15 +406,13 @@ void KstView::updateMouse() {
       for (KstBaseCurveList::Iterator i = pPlot->Curves.begin(); i != pPlot->Curves.end(); ++i) {
         double xpt = 0.0, ypt = 0.0;
-        double pt = (*i)->sampleCount() * xpos / ((*i)->maxX() - (*i)->minX());
-        (*i)->getPoint((int)pt, xpt, ypt);
-
-        // We have to get the previous point and interpolate y here, otherwise
-        // datamode y coordinates don't look right.
-        double xpt2 = 0.0, ypt2 = 0.0;
-        (*i)->getPoint((int)pt + 1, xpt2, ypt2);
-        ypt += (pt - xpt) * (ypt2 - ypt) / (xpt2 - xpt);
-
+        int pt = int((*i)->sampleCount() * xpos / ((*i)->maxX() - (*i)->minX()));
+        (*i)->getPoint(pt, xpt, ypt);
         if (fabs(ypos - ypt) < delta) {
           delta = fabs(ypos - ypt);
+          // Notice: This is not exactly the inverse of pt(xpos) since there
+          //         is float->int->float conversion.  This is by design and
+          //         varies for each i.  This is how we get the proper x
+          //         position for the corresponding "newypos".
+          newxpos = double(pt) * ((*i)->maxX() - (*i)->minX()) / (*i)->sampleCount();
           newypos = ypt;
           curve = *i;
@@ -421,5 +420,5 @@ void KstView::updateMouse() {
       }
       if (curve.data()) {
-        msg = i18n("%3 (%1, %2)").arg(xpos).arg(newypos,0,'G').arg(curve->tagName());
+        msg = i18n("%3 (%1, %2)").arg(newxpos).arg(newypos,0,'G').arg(curve->tagName());
         emit newDataMsg(msg);
         return;