Bug 118726 - Axes: expression vs fixed limits and save/restore problem
Summary: Axes: expression vs fixed limits and save/restore problem
Status: RESOLVED FIXED
Alias: None
Product: kst
Classification: Applications
Component: general (show other bugs)
Version: 1.x
Platform: unspecified Solaris
: HI normal
Target Milestone: ---
Assignee: kst
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-12-20 17:25 UTC by Nicolas Brisset
Modified: 2006-09-18 16:36 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nicolas Brisset 2005-12-20 17:25:24 UTC
Version:           1.2.0_devel (using KDE 3.4.0, compiled sources)
Compiler:          gcc version 3.4.3
OS:                SunOS (sun4u) release 5.8

Some zoom settings (or axis states) are not correctly saved and restored. Example:
- plot one variable (say var1 vs time) from any file
- plot dialog->Limits: set expressions to be [var1-Max]-10 to [var1-Max]
- now, scroll with arrow keys or the mouse (which is like setting fixed values in the expression fields)
- Hit "R" and look at the limit settings: the expression is gone 

Expected behavior: the expression is preserved and can be restored. 

Thinking about this in a more general way, I think the issue we have here is that we merged 'fixed values' and 'expressions', while they correspond to different approaches:
- with fixed values you want to look at a precise place, and if you come back to it later you expect to see the exact same [xmin,xmax,ymin,ymax] view
- with expressions you want to plot a logical part of your data (last n seconds, or values close to the max, etc) and if the data changes, you expect the view to change as well.

I actually remember I was confused the first time I tried to set fixed numerical values, as I thought "expressions" would only be equations :-) I don't think it is a good idea to add options in the already-quite-crowded UI, but maybe changing the text from "Expression" to "Expression or fixed values" and making sure that expressions are saved and restored would be the right way to do it.
Another approach might be to have an editable combo where we'd store values input by hand (not those set by mouse/keyboard zoom actions to avoid getting a huge list), so that it is easy to come back to them later.
Comment 1 George Staikos 2005-12-20 17:43:36 UTC
  This is one aspect of a much larger problem throughout Kst.  Frames are 
assumed to be the unit of measurement and that's just not the case anymore.  
We need to come up with a new object for measurement of vector indices and 
use that to preserve time units, expressions, and more.  This will not be 
fixed in 1.2.0.  It's too dangerous to play with this stuff when we're trying 
to stabilize.
Comment 2 Nicolas Brisset 2005-12-20 17:46:37 UTC
OK. Maybe still change the UI string if it is still time wrt to i18n as this is cheap and will surely help new users ?
Comment 3 Netterfield 2005-12-20 17:47:46 UTC
Frames are an RVector/datasource property only.
Comment 4 George Staikos 2005-12-20 17:54:40 UTC
On Tuesday 20 December 2005 11:47, netterfield@astro.utoronto.ca wrote:
> 17:47 ------- Frames are an RVector/datasource property only.


  Right.  The bigger problem is that it is also an assumption that indexing 
will always be based on frames.  If you read data as time right now, you 
can't get the time value back in the dialog later because it gets converted 
into frames and stored like that.

  It's the same systematic problem everywhere we accept non-numeric inputs 
now.
Comment 5 Andrew Walker 2006-03-13 23:31:22 UTC
There are two aspects to this problem:

1) when you make any changes to the plot axes in the plot dialog these changes are not added to the undo stack, so hitting 'R' will never return to them
2) even if they were added to the undo stack the fixed limits are remembered only as numeric values, not text - so expression limits would be discarded

The solution to these problems would be relatively simple.
Comment 6 Netterfield 2006-06-17 01:19:38 UTC
I think Andrew has accurately identified the bug here, and it may as well be fixed now... I assume that you would make the undo stack text rather than numbers?
Comment 7 George Staikos 2006-06-17 01:25:46 UTC
  We had talked about making a more complex datatype for locations in 
datastreams.  I think that's a better route than using strings.
Comment 8 Netterfield 2006-06-17 01:43:04 UTC
This is not for vector indexes.  It is for plot limits, which are only entered as strings, or as one of the auto modes.
Comment 9 Netterfield 2006-06-19 04:20:46 UTC
The bug here is that:
  -popping an expression based range in a 2d plot doesn't work.
  -saving an expression based range in a 2d plot doesn't work.

George, please confirm the following or provide a counter proposal:
For push/pop, it is appropriate to just add qstrings for _xMinExp, etc to KstPlotScale, which gets pushed and popped, because kst2dplot currently holds the expressions as qstrings.  For storage, they should go into the kstfiles as strings, in the same way as equations.
Comment 10 Andrew Walker 2006-06-21 20:20:44 UTC
On a more general note, Nicolas' original entry was talking about making a change to the axis range from the plot dialog. At present no such changes are popped onto the undo stack, only changes made through context menu items and mouse actions. Do we want to be able to undo all the corresponding plot dialog actions?
Comment 11 George Staikos 2006-06-21 20:39:53 UTC
This is a dangerous path to follow.  It will start to set expectations for 
undo that we just can't provide.  I've never seen undo that undoes in a 
completely different context either.
Comment 12 Andrew Walker 2006-06-21 21:06:46 UTC
Then perhaps this bug report should be closed as INVALID? 
Comment 13 George Staikos 2006-09-18 16:36:54 UTC
SVN commit 586024 by staikos:

This makes expressions work in the zoom stack as expected, and even to an
extent across the plot dialog.  It's a bit strange to have undo work across
the dialog and in the main view, but after playing with it, I can see why it
feels more intuitive.
BUG: 118726


 M  +30 -14    kst2dplot.cpp  
 M  +2 -2      kstplotdialog_i.cpp  


--- trunk/extragear/graphics/kst/src/libkstapp/kst2dplot.cpp #586023:586024
@@ -979,7 +979,12 @@
   bool first;
   int count;
 
-  switch (_xScaleMode) {
+  KstScaleModeType t = _xScaleMode;
+  if (t == EXPRESSION && _xMinParsedValid && _xMaxParsedValid && _xMinParsed->isConst() && _xMaxParsed->isConst()) {
+    t = FIXED;
+  }
+
+  switch (t) {
     case AUTOBORDER:  // set scale so all of all curves fits
     case AUTO:  // set scale so all of all curves fits
       XMin = 0.0;
@@ -1182,7 +1187,12 @@
       break;
   }
 
-  switch (_yScaleMode) {
+  t = _yScaleMode;
+  if (t == EXPRESSION && _yMinParsedValid && _yMaxParsedValid && _yMinParsed->isConst() && _yMaxParsed->isConst()) {
+    t = FIXED;
+  }
+
+  switch (t) {
     case AUTOBORDER:  // set scale so all of all curves fits
     case AUTO:  // set scale so all of all curves fits
       YMin = 0.0;
@@ -2897,6 +2907,10 @@
   ps->yscalemode = _yScaleMode;
   ps->xlog = _xLog;
   ps->ylog = _yLog;
+  ps->xMinExp = _xMinExp;
+  ps->xMaxExp = _xMaxExp;
+  ps->yMinExp = _yMinExp;
+  ps->yMaxExp = _yMaxExp;
 
   _plotScaleList.append(ps);
 }
@@ -2914,6 +2928,16 @@
     _yScaleMode = ps->yscalemode;
     _xLog = ps->xlog;
     _yLog = ps->ylog;
+    _xMinExp = ps->xMinExp;
+    _xMaxExp = ps->xMaxExp;
+    _yMinExp = ps->yMinExp;
+    _yMaxExp = ps->yMaxExp;
+    _xMinParsedValid = reparse(_xMinExp, &_xMinParsed);
+    _xMaxParsedValid = reparse(_xMaxExp, &_xMaxParsed);
+    _yMinParsedValid = reparse(_yMinExp, &_yMinParsed);
+    _yMaxParsedValid = reparse(_yMaxExp, &_yMaxParsed);
+    optimizeXExps();
+    optimizeYExps();
     return true;
   }
   return false;
@@ -6396,11 +6420,8 @@
 void Kst2DPlot::optimizeXExps() {
   if (_xMinParsedValid && _xMaxParsedValid && _xMinParsed->isConst() && _xMaxParsed->isConst()) {
     Equation::Context ctx;
-    double min, max;
-
-    setXScaleMode(FIXED);
-    min = _xMinParsed->value(&ctx);
-    max = _xMaxParsed->value(&ctx);
+    double min = _xMinParsed->value(&ctx);
+    double max = _xMaxParsed->value(&ctx);
     if (min > max) {
       double tmp = max;
       max = min;
@@ -6414,7 +6435,6 @@
         min -= fabs(min) * 0.01;
       }
     }
-    setXScale(min, max);
   }
 }
 
@@ -6422,11 +6442,8 @@
 void Kst2DPlot::optimizeYExps() {
   if (_yMinParsedValid && _yMaxParsedValid && _yMinParsed->isConst() && _yMaxParsed->isConst()) {
     Equation::Context ctx;
-    double min, max;
-
-    setYScaleMode(FIXED);
-    min = _yMinParsed->value(&ctx);
-    max = _yMaxParsed->value(&ctx);
+    double min = _yMinParsed->value(&ctx);
+    double max = _yMaxParsed->value(&ctx);
     if (min > max) {
       double tmp = max;
       max = min;
@@ -6440,7 +6457,6 @@
         min -= fabs(min) * 0.01;
       }
     }
-    setYScale(min, max);
   }
 }
 
--- trunk/extragear/graphics/kst/src/libkstapp/kstplotdialog_i.cpp #586023:586024
@@ -832,7 +832,6 @@
 
 void KstPlotDialogI::applyRange(Kst2DPlotPtr plot) {
   Kst2DPlotList plots;
-  Kst2DPlotPtr  plotExtra;
 
   if (rangeThisPlot->isChecked()) {
     plots += plot;
@@ -846,7 +845,7 @@
   }
 
   for (uint i = 0; i < plots.size(); i++) {
-    plotExtra = plots[i];
+    Kst2DPlotPtr plotExtra = plots[i];
 
     // do X Scale
     if (XAC->isChecked()) {
@@ -898,6 +897,7 @@
       KstDebug::self()->log(i18n( "Internal error: No Y scale type checked in %1." ).arg(Select->currentText()), KstDebug::Error);
     }
     plotExtra->setDirty();
+    plotExtra->pushScale();
   }
 }