[chronojump] Several improvements on raceAnalyzer capture tab scatterplots
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] Several improvements on raceAnalyzer capture tab scatterplots
- Date: Thu, 8 Apr 2021 10:46:29 +0000 (UTC)
commit a4717e710544e0f75efae067b59f4a160140af44
Author: Xavier de Blas <xaviblas gmail com>
Date: Thu Apr 8 12:46:02 2021 +0200
Several improvements on raceAnalyzer capture tab scatterplots
src/gui/app1/runEncoder.cs | 45 +++++++++++++++++--------
src/gui/cairo/raceAnalyzer.cs | 78 ++++++++++++++++++++++---------------------
src/gui/cairo/xy.cs | 55 +++++++++++++++++++++---------
3 files changed, 110 insertions(+), 68 deletions(-)
---
diff --git a/src/gui/app1/runEncoder.cs b/src/gui/app1/runEncoder.cs
index 5e3a3c10..de224a7e 100644
--- a/src/gui/app1/runEncoder.cs
+++ b/src/gui/app1/runEncoder.cs
@@ -266,9 +266,15 @@ public partial class ChronoJumpWindow
runEncoderButtonsSensitive(false);
sensitiveLastTestButtons(false);
+ //reset capture tab graphs
if(cairoRadial != null)
cairoRadial.ResetSpeedMax();
+ if(cairoGraphRaceAnalyzer_dt != null)
+ cairoGraphRaceAnalyzer_dt.Reset();
+ if(cairoGraphRaceAnalyzer_st != null)
+ cairoGraphRaceAnalyzer_st.Reset();
+
if(chronopicRegister.NumConnectedOfType(ChronopicRegisterPort.Types.ARDUINO_RUN_ENCODER) == 0)
{
event_execute_label_message.Text = runEncoderNotConnectedString;
@@ -917,8 +923,8 @@ public partial class ChronoJumpWindow
cairoRadial = new CairoRadial(drawingarea_race_analyzer_capture,
preferences.fontType.ToString());
cairoRadial.GraphSpeedMaxAndDistance(reCGSD.RunEncoderCaptureSpeedMax,
reCGSD.RunEncoderCaptureDistance);
- updateRaceAnalyzerCapturePositionTime();
- updateRaceAnalyzerCaptureSpeedTime();
+ updateRaceAnalyzerCapturePositionTime(true);
+ updateRaceAnalyzerCaptureSpeedTime(true);
}
// <---- capture tab graphs end ----
@@ -1319,7 +1325,7 @@ public partial class ChronoJumpWindow
LogB.Information(" re B ");
//LogB.Information(capturingRunEncoder.ToString())
- if(! runEncoderCaptureThread.IsAlive || runEncoderProcessFinish || runEncoderProcessCancel ||
runEncoderProcessError)
+ if(! runEncoderCaptureThread.IsAlive || runEncoderProcessFinish || runEncoderProcessCancel ||
runEncoderProcessError) //capture ends
{
LogB.Information(" re C ");
button_video_play_this_test_contacts.Sensitive = false;
@@ -1395,8 +1401,8 @@ public partial class ChronoJumpWindow
forceSensorDoGraphAI();
*/
- updateRaceAnalyzerCapturePositionTime();
- updateRaceAnalyzerCaptureSpeedTime();
+ updateRaceAnalyzerCapturePositionTime(true);
+ updateRaceAnalyzerCaptureSpeedTime(true);
}
LogB.Information(" re C finish 2");
} else if(runEncoderProcessCancel || runEncoderProcessError)
@@ -1438,6 +1444,16 @@ public partial class ChronoJumpWindow
if(reCGSD != null)
cairoRadial.GraphSpeedMaxAndDistance(reCGSD.RunEncoderCaptureSpeedMax,
reCGSD.RunEncoderCaptureDistance);
+ /*
+ LogB.Information("cairoGraphRaceAnalyzerPoints_dt_l: ");
+ foreach(PointF p in cairoGraphRaceAnalyzerPoints_dt_l)
+ LogB.Information(p.ToString());
+
+ LogB.Information("cairoGraphRaceAnalyzerPoints_st_l: ");
+ foreach(PointF p in cairoGraphRaceAnalyzerPoints_st_l)
+ LogB.Information(p.ToString());
+ */
+
LogB.ThreadEnded();
runEncoderButtonsSensitive(true);
@@ -1456,7 +1472,7 @@ public partial class ChronoJumpWindow
return false;
}
- else
+ else //capture continues
{
event_execute_label_message.Text = runEncoderPulseMessage;
@@ -1464,8 +1480,9 @@ public partial class ChronoJumpWindow
cairoRadial.GraphSpeedAndDistance(reCGSD.RunEncoderCaptureSpeed,
reCGSD.RunEncoderCaptureDistance);
//TODO: activate again when there's a real time update (not repaint all) method
- updateRaceAnalyzerCapturePositionTime();
- updateRaceAnalyzerCaptureSpeedTime();
+ //false: it will not be redrawn if there are no new points
+ updateRaceAnalyzerCapturePositionTime(false);
+ updateRaceAnalyzerCaptureSpeedTime(false);
if(runEncoderPulseMessage == capturingMessage)
event_execute_button_finish.Sensitive = true;
@@ -1879,32 +1896,32 @@ public partial class ChronoJumpWindow
static List<PointF> cairoGraphRaceAnalyzerPoints_dt_l; //distancetime
private void on_drawingarea_race_analyzer_capture_position_time_expose_event (object o,
ExposeEventArgs args)
{
- updateRaceAnalyzerCapturePositionTime();
+ updateRaceAnalyzerCapturePositionTime(true);
}
CairoGraphRaceAnalyzer cairoGraphRaceAnalyzer_st;
static List<PointF> cairoGraphRaceAnalyzerPoints_st_l; //speed/time
private void on_drawingarea_race_analyzer_capture_speed_time_expose_event (object o, ExposeEventArgs
args)
{
- updateRaceAnalyzerCaptureSpeedTime();
+ updateRaceAnalyzerCaptureSpeedTime(true);
}
- private void updateRaceAnalyzerCapturePositionTime()
+ private void updateRaceAnalyzerCapturePositionTime(bool forceRedraw)
{
if(cairoGraphRaceAnalyzer_dt == null)
cairoGraphRaceAnalyzer_dt = new CairoGraphRaceAnalyzer(
drawingarea_race_analyzer_capture_position_time, "title",
Catalog.GetString("Distance"), "m");
- cairoGraphRaceAnalyzer_dt.DoSendingList (preferences.fontType.ToString(),
cairoGraphRaceAnalyzerPoints_dt_l);
+ cairoGraphRaceAnalyzer_dt.DoSendingList (preferences.fontType.ToString(),
cairoGraphRaceAnalyzerPoints_dt_l, forceRedraw);
}
- private void updateRaceAnalyzerCaptureSpeedTime()
+ private void updateRaceAnalyzerCaptureSpeedTime(bool forceRedraw)
{
if(cairoGraphRaceAnalyzer_st == null)
cairoGraphRaceAnalyzer_st = new CairoGraphRaceAnalyzer(
drawingarea_race_analyzer_capture_speed_time, "title",
Catalog.GetString("Speed"), "m/s");
- cairoGraphRaceAnalyzer_st.DoSendingList (preferences.fontType.ToString(),
cairoGraphRaceAnalyzerPoints_st_l);
+ cairoGraphRaceAnalyzer_st.DoSendingList (preferences.fontType.ToString(),
cairoGraphRaceAnalyzerPoints_st_l, forceRedraw);
}
}
diff --git a/src/gui/cairo/raceAnalyzer.cs b/src/gui/cairo/raceAnalyzer.cs
index 075553ce..24bb9204 100644
--- a/src/gui/cairo/raceAnalyzer.cs
+++ b/src/gui/cairo/raceAnalyzer.cs
@@ -27,7 +27,7 @@ using Cairo;
public class CairoGraphRaceAnalyzer : CairoXY
{
- //static int lastPointPainted;
+ int points_list_painted;
/*
//constructor when there are no points
@@ -49,11 +49,9 @@ public class CairoGraphRaceAnalyzer : CairoXY
// static bool doing;
//regular constructor
public CairoGraphRaceAnalyzer (
-// List<PointF> point_l,
DrawingArea area, string title,
string yVariable, string yUnits)
{
-// this.point_l = point_l;
this.area = area;
this.title = title;
this.colorBackground = colorFromGdk(Config.ColorBackground); //but note if we are using
system colors, this will not match
@@ -64,52 +62,56 @@ public class CairoGraphRaceAnalyzer : CairoXY
this.yUnits = yUnits;
// doing = false;
-// lastPointPainted = -1;
+ points_list_painted = 0;
}
- /*
- public override bool PassData (List<PointF> point_l)
+ public void Reset()
{
- */
- /*
- if(doing)
- return false;
- else
- doing = true;
- */
-/*
- foreach(PointF p in points_list)
-
- this.point_l = point_l;
- return true;
+ minX = 1000000;
+ maxX = 0;
+ minY = 1000000;
+ maxY = 0;
+ absoluteMaxX = 0;
+ absoluteMaxY = 0;
+
+ points_list_painted = 0;
}
- */
- public override void DoSendingList (string font, List<PointF> points_list)
+ public override void DoSendingList (string font, List<PointF> points_list, bool forceRedraw)
{
LogB.Information("at RaceAnalyzerGraph.Do");
- initGraph(font, .9);
-
-//maybe do a copy of points_list or only consider last of them (using lastPointPainted)
-
- //because point_l is updated while foreach in findPointMaximums() and plotRealPoints()
- //TODO: on realtime do something better in order to just pass the new points and redo the
graph just if margins changed
- //this new method will not have problems of changing the point_l list while iterating it
-// try {
-//
- if(points_list != null)
- findPointMaximums(false, points_list);
- //TODO: have a way to pass the x min max if we want to have two graphs with same x
+
+ bool initGraphDone = false;
+ bool maxValuesChanged = false;
+ if(points_list != null)
+ maxValuesChanged = findPointMaximums(false, points_list);
+
+ if(maxValuesChanged || forceRedraw || points_list.Count != points_list_painted)
+ {
+ initGraph( font, .9, (maxValuesChanged || forceRedraw) );
+ initGraphDone = true;
+ points_list_painted = 0;
+ }
+
+ if(maxValuesChanged || forceRedraw)
+ {
paintGrid(gridTypes.BOTH, true);
paintAxis();
+ }
- pointsRadius = 1;
- if(points_list != null)
- plotRealPoints(false, points_list);
-// } catch {}
+ pointsRadius = 1;
+ if( points_list != null &&
+ (maxValuesChanged || forceRedraw || points_list.Count != points_list_painted)
)
+ {
- endGraphDisposing(g);
-// doing = false;
+ plotRealPoints(false, points_list, points_list_painted);
+ points_list_painted = points_list.Count;
+ }
+
+ if(initGraphDone)
+ endGraphDisposing(g);
+
+ //doing = false;
}
protected override void writeTitle()
diff --git a/src/gui/cairo/xy.cs b/src/gui/cairo/xy.cs
index cc6fc764..4336925a 100644
--- a/src/gui/cairo/xy.cs
+++ b/src/gui/cairo/xy.cs
@@ -66,8 +66,8 @@ public abstract class CairoXY : CairoGeneric
protected double minY = 1000000;
protected double maxY = 0;
double yAtMMaxY;
- double absoluteMaxX;
- double absoluteMaxY;
+ protected double absoluteMaxX;
+ protected double absoluteMaxY;
protected int graphWidth;
protected int graphHeight;
@@ -112,11 +112,15 @@ public abstract class CairoXY : CairoGeneric
public virtual void Do(string font)
{
}
- public virtual void DoSendingList(string font, List<PointF> points_list)
+ public virtual void DoSendingList(string font, List<PointF> points_list, bool forceRedraw)
{
}
protected void initGraph(string font, double widthPercent1)
+ {
+ initGraph(font, widthPercent1, true);
+ }
+ protected void initGraph(string font, double widthPercent1, bool clearDrawingArea)
{
this.font = font;
LogB.Information("Font: " + font);
@@ -125,10 +129,13 @@ public abstract class CairoXY : CairoGeneric
//1 create context
g = Gdk.CairoHelper.Create (area.GdkWindow);
-
- //2 clear DrawingArea (white)
- g.SetSourceRGB(1,1,1);
- g.Paint();
+
+ if(clearDrawingArea)
+ {
+ //2 clear DrawingArea (white)
+ g.SetSourceRGB(1,1,1);
+ g.Paint();
+ }
graphWidth = Convert.ToInt32(area.Allocation.Width * widthPercent1);
graphHeight = area.Allocation.Height;
@@ -153,13 +160,15 @@ public abstract class CairoXY : CairoGeneric
//showFullGraph means that has to plot both axis at 0 and maximums have to be f0,v0
//used by default on jumpsWeightFVProfile
//called from almost all methods
- protected void findPointMaximums(bool showFullGraph)
+ //true if changed
+ protected bool findPointMaximums(bool showFullGraph)
{
- findPointMaximums(showFullGraph, point_l);
+ return findPointMaximums(showFullGraph, point_l);
}
//called from raceAnalyzer (sending it own list of points)
- protected void findPointMaximums(bool showFullGraph, List<PointF> points_list)
+ //true if changed
+ protected bool findPointMaximums(bool showFullGraph, List<PointF> points_list)
{
//foreach(PointF p in points_list)
/*
@@ -209,8 +218,19 @@ public abstract class CairoXY : CairoGeneric
separateMinXMaxXIfNeeded();
separateMinYMaxYIfNeeded();
- absoluteMaxX = maxX;
- absoluteMaxY = maxY;
+ bool changed = false;
+ if(maxX != absoluteMaxX)
+ {
+ absoluteMaxX = maxX;
+ changed = true;
+ }
+ if(maxY != absoluteMaxY)
+ {
+ absoluteMaxY = maxY;
+ changed = true;
+ }
+
+ return changed;
}
protected void plotAlternativeLineWithRealPoints (double ax, double ay, double bx, double by, bool
showFullGraph)
@@ -423,17 +443,20 @@ public abstract class CairoXY : CairoGeneric
//called from almost all methods
protected void plotRealPoints (bool joinByLine)
{
- plotRealPoints (joinByLine, point_l);
+ plotRealPoints (joinByLine, point_l, 0);
}
//called from raceAnalyzer (sending it own list of points)
- protected void plotRealPoints (bool joinByLine, List<PointF> points_list)
+ protected void plotRealPoints (bool joinByLine, List<PointF> points_list, int startAt)
{
if(joinByLine) //draw line first to not overlap the points
{
bool firstDone = false;
- foreach(PointF p in points_list)
+ //foreach(PointF p in points_list)
+ for(int i = startAt; i < points_list.Count; i ++)
{
+ PointF p = points_list[i];
+
double xgraph = calculatePaintX(p.X);
double ygraph = calculatePaintY(p.Y);
@@ -458,7 +481,7 @@ public abstract class CairoXY : CairoGeneric
//for(int i = start; i < points_list.Count; i ++)
*/
- for(int i = 0; i < points_list.Count; i ++)
+ for(int i = startAt; i < points_list.Count; i ++)
{
PointF p = points_list[i];
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]