[chronojump] forceSensor graph improvements: not simmetrical, better ablines, ...
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] forceSensor graph improvements: not simmetrical, better ablines, ...
- Date: Tue, 26 Dec 2017 00:12:55 +0000 (UTC)
commit 120142339f58605de4baff05e7e8ed25e10e5866
Author: Xavier de Blas <xaviblas gmail com>
Date: Tue Dec 26 01:11:02 2017 +0100
forceSensor graph improvements: not simmetrical, better ablines, ...
src/forceSensor.cs | 48 +++++++++++++++++++++++++++++++++++++-----------
src/gui/forceSensor.cs | 21 +++++++++++++++++----
2 files changed, 54 insertions(+), 15 deletions(-)
---
diff --git a/src/forceSensor.cs b/src/forceSensor.cs
index 800b78d..d800099 100644
--- a/src/forceSensor.cs
+++ b/src/forceSensor.cs
@@ -40,12 +40,18 @@ public class ForceSensorCapturePoints
private List<double> forces;
public int RealWidthG; //width of graph in microseconds (will be upgraded if needed)
+
+ public const int DefaultRealHeightG = 20;
+ public const int DefaultRealHeightGNeg = 10;
public int RealHeightG; //Newtons (will be upgraded if needed)
+ public int RealHeightGNeg; //Newtons (negative) (will be upgraded if needed)
private int widthG;
private int heightG;
private int marginLeft = 45; //px
private int marginRight = 30; //px
+ private int marginTop = 30; //px
+ private int marginBottom = 30; //px
//initialize
public ForceSensorCapturePoints(int widthG, int heightG)
@@ -65,7 +71,8 @@ public class ForceSensorCapturePoints
public void InitRealWidthHeight()
{
RealWidthG = 10000000; //width of graph in microseconds (will be upgraded if needed)
- RealHeightG = 60; //Newtons (will be upgraded when needed) (nice to see the +25 -25 marks)
+ RealHeightG = DefaultRealHeightG; //Newtons (will be upgraded when needed) (nice to see the
+25 -25 marks)
+ RealHeightGNeg = DefaultRealHeightGNeg; //Newtons (will be upgraded when needed) (nice to see
the +25 -25 marks)
}
public void Add(int time, double force)
@@ -83,10 +90,25 @@ public class ForceSensorCapturePoints
public int GetForceInPx(double force)
{
+ /*
+ * simmetrical positive / negative
return Convert.ToInt32(
(heightG/2)
- ( Util.DivideSafe((force * heightG), (1.0 * RealHeightG)) )
);
+ */
+ return Convert.ToInt32(
+ heightG
+ - Util.DivideSafe(
+ (force * (heightG - (marginTop + marginBottom))),
+ (1.0 * (RealHeightG + RealHeightGNeg))
+ )
+ - Util.DivideSafe(
+ RealHeightGNeg * (heightG - (marginTop + marginBottom)),
+ (1.0 * (RealHeightG + RealHeightGNeg))
+ )
+ - marginBottom
+ );
}
private Gdk.Point getLastPoint()
@@ -99,17 +121,24 @@ public class ForceSensorCapturePoints
{
Gdk.Point p = getLastPoint();
//LogB.Information("p.Y: " + p.Y + "; heightG: " + heightG);
+ bool outsideGraph = false;
+
if(p.X > widthG)
{
RealWidthG *= 2;
- return true;
+ outsideGraph = true;
}
- if(p.Y < 0 || p.Y > heightG)
+ if(p.Y < 0)
{
- RealHeightG *= 2; //TODO: adjust differently < 0 than > heightG
- return true;
+ RealHeightG *= 2;
+ outsideGraph = true;
}
- return false;
+ else if(p.Y > heightG)
+ {
+ RealHeightGNeg *= 2;
+ outsideGraph = true;
+ }
+ return outsideGraph;
}
// this is called at load signal, checks if last X is outside the graph and max/min force
public bool OutsideGraph(int lastTime, double maxForce, double minForce)
@@ -120,11 +149,8 @@ public class ForceSensorCapturePoints
{
RealWidthG = lastTime + GetTimeInPx(marginLeft) + GetTimeInPx(marginRight);
- double absoluteMaxForce = maxForce;
- if(Math.Abs(minForce) > absoluteMaxForce)
- absoluteMaxForce = Math.Abs(minForce);
-
- RealHeightG = Convert.ToInt32(2 * absoluteMaxForce + absoluteMaxForce * .2);
+ RealHeightG = Convert.ToInt32(maxForce);
+ RealHeightGNeg = Convert.ToInt32(Math.Abs(minForce));
return true;
}
diff --git a/src/gui/forceSensor.cs b/src/gui/forceSensor.cs
index f3e0f33..bfa4475 100644
--- a/src/gui/forceSensor.cs
+++ b/src/gui/forceSensor.cs
@@ -537,6 +537,7 @@ public partial class ChronoJumpWindow
force_capture_drawingarea.Allocation.Width,
force_capture_drawingarea.Allocation.Height
);
+
forcePaintHVLines(fscPoints.RealHeightG, -1 * fscPoints.RealHeightG, 10);
event_execute_ButtonFinish.Clicked -= new EventHandler(on_finish_clicked);
@@ -814,7 +815,8 @@ LogB.Information(" fc I ");
//mark meaning screen should be erased
if(fscPoints.NumPainted == -1) {
UtilGtk.ErasePaint(force_capture_drawingarea, force_capture_pixmap);
- forcePaintHVLines(forceSensorValues.ForceMax, forceSensorValues.ForceMin,
fscPoints.RealWidthG);
+ forcePaintHVLines(forceSensorValues.ForceMax * 2, forceSensorValues.ForceMin
* 2, fscPoints.RealWidthG);
+ //forcePaintHVLines(forceSensorValues.ForceMax, forceSensorValues.ForceMin,
fscPoints.RealWidthG);
fscPoints.NumPainted = 0;
}
@@ -1119,8 +1121,9 @@ LogB.Information(" fc R ");
absoluteMaxForce = Math.Abs(minForce);
//show 10 steps positive, 10 negative
- int temp = Convert.ToInt32(absoluteMaxForce / 10.0);
+ int temp = Convert.ToInt32(Util.DivideSafe(absoluteMaxForce, 10.0));
int step = temp;
+
if(step <= 10)
step = temp;
else if(step <= 100)
@@ -1132,10 +1135,20 @@ LogB.Information(" fc R ");
else //if(step <= 100000)
step = temp - (temp % 10000);
+ //fix crash when no force
+ if(step == 0)
+ step = 1;
+
for(int i = step; i <= absoluteMaxForce ; i += step)
{
- forcePaintHLine(i);
- forcePaintHLine(i *-1);
+ if(maxForce >= i || ForceSensorCapturePoints.DefaultRealHeightG >= i)
+ {
+ forcePaintHLine(i);
+ }
+ if(minForce <= (i * -1) || (ForceSensorCapturePoints.DefaultRealHeightGNeg * -1) <=
(i * -1))
+ {
+ forcePaintHLine(i *-1);
+ }
}
int lastTimeInSeconds = lastTime / 1000000; //from microseconds to seconds
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]