[chronojump] force sensor graph load gets resized if points are outside margins



commit 2510294012fe524dd4dff046d6a384d68cec5573
Author: Xavier de Blas <xaviblas gmail com>
Date:   Wed Oct 25 19:43:32 2017 +0200

    force sensor graph load gets resized if points are outside margins

 src/forceSensor.cs     |   20 ++++++++++++++------
 src/gui/forceSensor.cs |   10 ++++++++--
 2 files changed, 22 insertions(+), 8 deletions(-)
---
diff --git a/src/forceSensor.cs b/src/forceSensor.cs
index 7714903..1556f2c 100644
--- a/src/forceSensor.cs
+++ b/src/forceSensor.cs
@@ -64,15 +64,23 @@ public class ForceSensorCapturePoints
                forces.Add(force);
                Points.Add(new Gdk.Point(
                                        Convert.ToInt32(widthG * time / RealWidthG),
-                                       Convert.ToInt32( (heightG/2) - ( force * heightG / RealHeightG) )
+                                       GetForceInPx(force)
                                        ));
        }
 
        public int GetForceInPx(double force)
        {
-               return Convert.ToInt32( (heightG/2) - ( force * heightG / RealHeightG) );
+               //return Convert.ToInt32( (heightG/2) - ( force * heightG / RealHeightG) );
+               return Convert.ToInt32( heightG - ( force * heightG / RealHeightG) -100 );
        }
 
+       /*
+       public int SetRealWidthG(double time)
+       {
+               RealWidthG = Convert.ToInt32(time / widthG);
+       }
+       */
+
        private Gdk.Point getLastPoint()
        {
                return Points[Points.Count -1];
@@ -81,20 +89,20 @@ public class ForceSensorCapturePoints
        public bool OutsideGraph()
        {
                Gdk.Point p = getLastPoint();
+               LogB.Information("p.Y: " + p.Y + "; heightG: " +  heightG);
                if(p.X > widthG)
                {
                        RealWidthG *= 2;
                        return true;
                }
-               if(p.Y < 0)
+               if(p.Y < 0 || p.Y > heightG)
                {
-                       RealHeightG *= 2;
+                       RealHeightG *= 2; //TODO: adjust differently < 0 than > heightG
                        return true;
                }
                return false;
        }
 
-       //reprocess all points with new RealWidthG, RealHeightG
        public void Redo()
        {
                for(int i=0; i < NumCaptured; i ++)
@@ -102,7 +110,7 @@ public class ForceSensorCapturePoints
                        //LogB.Information("RedoPRE X: " + Points[i].X.ToString() + "; Y: " + 
Points[i].Y.ToString());
                        Points[i] = new Gdk.Point(
                                        Convert.ToInt32(widthG * times[i] / RealWidthG),
-                                       Convert.ToInt32( (heightG/2) - ( forces[i] * heightG / RealHeightG) )
+                                       GetForceInPx(forces[i])
                                        );
                        //LogB.Information("RedoPOST X: " + Points[i].X.ToString() + "; Y: " + 
Points[i].Y.ToString());
                }
diff --git a/src/gui/forceSensor.cs b/src/gui/forceSensor.cs
index f97c2f7..4087918 100644
--- a/src/gui/forceSensor.cs
+++ b/src/gui/forceSensor.cs
@@ -412,7 +412,6 @@ public partial class ChronoJumpWindow
                                );
                UtilGtk.ErasePaint(force_capture_drawingarea, force_capture_pixmap);
 
-               int count = 0;
                while(! forceProcessFinish && ! forceProcessCancel)
                {
                        str = portFS.ReadLine();
@@ -447,7 +446,7 @@ public partial class ChronoJumpWindow
                        forceSensorLast = force;
 
                        fscPoints.Add(time, force);
-                       fscPoints.NumCaptured = ++ count;
+                       fscPoints.NumCaptured ++;
                        if(fscPoints.OutsideGraph())
                        {
                                redoingPoints = true;
@@ -754,6 +753,13 @@ public partial class ChronoJumpWindow
                                {
                                        double force = Convert.ToDouble(strFull[1]);
                                        fscPoints.Add(Convert.ToInt32(strFull[0]), force);
+                                       fscPoints.NumCaptured ++;
+
+                                       //redo in case points goes out the graph
+                                       //TODO: calculate this on loading file counting rows (contents.Count 
-1)
+                                       //      and adjust RealWidthG and RealHeightG
+                                       if(fscPoints.OutsideGraph())
+                                               fscPoints.Redo();
 
                                        lastForce = force;
                                        if(force > maxForce)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]