[Kst] branches/work/kst/portto4/kst/src

Adam Treat treat at kde.org
Fri Oct 5 15:29:33 CEST 2007


SVN commit 721550 by treat:

* Add get/set for logbase and don't hardcode.
* Fix hackup for log mode.
* Investigate kst2dplot for solutions.


 M  +52 -5     libkstapp/plotrenderitem.cpp  
 M  +8 -0      libkstapp/plotrenderitem.h  
 M  +7 -8      libkstapp/vectorcurverenderitem.cpp  
 M  +3 -0      libkstmath/kstrelation.h  


--- branches/work/kst/portto4/kst/src/libkstapp/plotrenderitem.cpp #721549:721550
@@ -31,7 +31,9 @@
   _xAxisZoomMode(Auto),
   _yAxisZoomMode(AutoBorder),
   _isXAxisLog(false),
-  _isYAxisLog(false) {
+  _isYAxisLog(false),
+  _xLogBase(10.0),
+  _yLogBase(10.0) {
 
   setName(tr("Plot Render"));
   setParentItem(parentItem);
@@ -99,6 +101,16 @@
 }
 
 
+qreal PlotRenderItem::xLogBase() const {
+  return _xLogBase;
+}
+
+
+void PlotRenderItem::setXLogBase(qreal xLogBase) {
+  _xLogBase = xLogBase;
+}
+
+
 bool PlotRenderItem::isYAxisLog() const {
   return _isYAxisLog;
 }
@@ -109,6 +121,16 @@
 }
 
 
+qreal PlotRenderItem::yLogBase() const {
+  return _yLogBase;
+}
+
+
+void PlotRenderItem::setYLogBase(qreal yLogBase) {
+  _yLogBase = yLogBase;
+}
+
+
 QRectF PlotRenderItem::plotRect() const {
   QRectF plotRect = rect();
   plotRect = plotRect.normalized();
@@ -154,7 +176,9 @@
 
       //If the axis is in log mode, the lower extent will be the
       //minimum value larger than zero.
-      if (!isXAxisLog() || relation->minX() > 0.0)
+      if (isXAxisLog())
+        minimum = minimum <= 0.0 ? relation->minPosX() : qMin(relation->minPosX(), minimum);
+      else
         minimum = qMin(relation->minX(), minimum);
 
       maximum = qMax(relation->maxX(), maximum);
@@ -164,7 +188,17 @@
   case Auto:
     break; //nothing more...
   case AutoBorder:
-    break; //FIXME auto mode, plus a 2.5% border on top and bottom.
+    if (isXAxisLog()) {
+      minimum = log10(minimum)/log10(xLogBase());
+      maximum = maximum > 0.0 ? log10(maximum) : 0.0;
+      qreal dx = qAbs(maximum - minimum) * 0.025;
+      maximum = pow(xLogBase(), maximum + dx);
+      minimum = pow(xLogBase(), minimum - dx);
+    } else {
+      qreal dx = qAbs(maximum - minimum) * 0.025;
+      maximum += dx;
+      minimum -= dx;
+    }
   case Expression:
     break; //FIXME limits are given by scalar equations
   case SpikeInsensitive:
@@ -189,7 +223,9 @@
 
       //If the axis is in log mode, the lower extent will be the
       //minimum value larger than zero.
-      if (!isYAxisLog() || relation->minY() > 0.0)
+      if (isYAxisLog())
+        minimum = minimum <= 0.0 ? relation->minPosY() : qMin(relation->minPosY(), minimum);
+      else
         minimum = qMin(relation->minY(), minimum);
 
       maximum = qMax(relation->maxY(), maximum);
@@ -199,7 +235,18 @@
   case Auto:
     break; //nothing more...
   case AutoBorder:
-    break; //FIXME auto mode, plus a 2.5% border on top and bottom.
+    if (isYAxisLog()) {
+      minimum = log10(minimum)/log10(yLogBase());
+      maximum = maximum > 0.0 ? log10(maximum) : 0.0;
+      qreal dy = qAbs(maximum - minimum) * 0.025;
+      maximum = pow(yLogBase(), maximum + dy);
+      minimum = pow(yLogBase(), minimum - dy);
+    } else {
+      qreal dy = qAbs(maximum - minimum) * 0.025;
+      maximum += dy;
+      minimum -= dy;
+    }
+    break; //auto mode, plus a 2.5% border on top and bottom.
   case Expression:
     break; //FIXME limits are given by scalar equations
   case SpikeInsensitive:
--- branches/work/kst/portto4/kst/src/libkstapp/plotrenderitem.h #721549:721550
@@ -49,9 +49,15 @@
     bool isXAxisLog() const;
     void setXAxisLog(bool log);
 
+    qreal xLogBase() const;
+    void setXLogBase(qreal xLogBase);
+
     bool isYAxisLog() const;
     void setYAxisLog(bool log);
 
+    qreal yLogBase() const;
+    void setYLogBase(qreal yLogBase);
+
     QRectF plotRect() const;
     QRectF computedProjectionRect() const;
 
@@ -118,6 +124,8 @@
     ZoomMode _yAxisZoomMode;
     bool _isXAxisLog;
     bool _isYAxisLog;
+    qreal _xLogBase;
+    qreal _yLogBase;
 
     KstRelationList _relationList;
     QRectF _projectionRect;
--- branches/work/kst/portto4/kst/src/libkstapp/vectorcurverenderitem.cpp #721549:721550
@@ -45,11 +45,11 @@
     KstCurveRenderContext context;
     context.painter = painter;
     context.window = QRect(); //no idea if this should be floating point
-    context.penWidth = 1.0; //FIXME hardcode
+    context.penWidth = 1; //FIXME hardcode
     context.xLog = isXAxisLog();
     context.yLog = isYAxisLog();
-    context.xLogBase = 10.0; //FIXME hardcode
-    context.yLogBase = 10.0; //FIXME hardcode
+    context.xLogBase = xLogBase();
+    context.yLogBase = yLogBase();
 
     //FIXME rename these methods in kstvcurve
     //FIXME Completely refactor KstCurveRenderContext now that we know what these are
@@ -61,11 +61,10 @@
     context.YMax = projectionRect().bottom();
 
     //Set the log box...
-    //Big FIXME!!
-    context.x_max = isXAxisLog() ? logXHi(context.XMax + .00001, context.xLogBase) : context.XMax;
-    context.y_max = isYAxisLog() ? logXHi(context.YMax + .00001, context.yLogBase) : context.YMax;
-    context.x_min = isXAxisLog() ? logXLo(context.XMin + .00001, context.xLogBase) : context.XMin;
-    context.y_min = isYAxisLog() ? logXLo(context.YMin + .00001, context.yLogBase) : context.YMin;
+    context.x_max = isXAxisLog() ? logXHi(context.XMax, context.xLogBase) : context.XMax;
+    context.y_max = isYAxisLog() ? logXHi(context.YMax, context.yLogBase) : context.YMax;
+    context.x_min = isXAxisLog() ? logXLo(context.XMin, context.xLogBase) : context.XMin;
+    context.y_min = isYAxisLog() ? logXLo(context.YMin, context.yLogBase) : context.YMin;
 
     //These are the bounding box in regular QGV coord
     context.Lx = plotRect().left();
--- branches/work/kst/portto4/kst/src/libkstmath/kstrelation.h #721549:721550
@@ -92,10 +92,13 @@
     virtual double maxY() const { return MaxY; }
     virtual double minY() const { return MinY; }
     virtual double minPosY() const { return MinPosY; }
+
+    //NoSpike
     virtual double ns_maxX()    const { return _ns_maxx; }
     virtual double ns_minX()    const { return _ns_minx; }
     virtual double ns_maxY()    const { return _ns_maxy; }
     virtual double ns_minY()    const { return _ns_miny; }
+
     virtual double minPosX() const { return MinPosX; }
     virtual double midX() const { return (MaxX+MinX)*0.5; }
     virtual double midY() const { return (MaxY+MinY)*0.5; }


More information about the Kst mailing list