[chronojump/michrolab] cairo XY where x is datetime, on click show date in days instead of percentage of year
- From: Xavier Padullés <xpadulles src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump/michrolab] cairo XY where x is datetime, on click show date in days instead of percentage of year
- Date: Thu, 6 Oct 2022 10:53:02 +0000 (UTC)
commit 9be1ec5e62ff58521cb7114bd4747bfd3912415f
Author: Xavier de Blas <xaviblas gmail com>
Date: Fri Sep 23 20:36:54 2022 +0200
cairo XY where x is datetime, on click show date in days instead of percentage of year
src/gui/cairo/jumpsRunsEvolution.cs | 8 ++++++--
src/gui/cairo/jumpsWeightFVProfile.cs | 2 +-
src/gui/cairo/xy.cs | 34 +++++++++++++++++++++++++++-------
src/jumpsRunsEvolution.cs | 10 +++++++++-
4 files changed, 43 insertions(+), 11 deletions(-)
---
diff --git a/src/gui/cairo/jumpsRunsEvolution.cs b/src/gui/cairo/jumpsRunsEvolution.cs
index 16dbd9d66..d9707bc7b 100644
--- a/src/gui/cairo/jumpsRunsEvolution.cs
+++ b/src/gui/cairo/jumpsRunsEvolution.cs
@@ -143,10 +143,12 @@ public class JumpsEvolutionGraph : EvolutionGraph
//regular constructor
public JumpsEvolutionGraph (
- List<PointF> point_l, double slope, double intercept,
+ List<PointF> point_l, List<DateTime> dates_l,
+ double slope, double intercept,
DrawingArea area, string title, string jumpType, string date)
{
this.point_l = point_l;
+ this.dates_l = dates_l;
this.slope = slope;
this.intercept = intercept;
this.area = area;
@@ -193,11 +195,13 @@ public class RunsEvolutionGraph : EvolutionGraph
//regular constructor
public RunsEvolutionGraph (
- List<PointF> point_l, double slope, double intercept,
+ List<PointF> point_l, List<DateTime> dates_l,
+ double slope, double intercept,
DrawingArea area, string title, string runType, string date,
bool showTime, bool metersSecondsPreferred)
{
this.point_l = point_l;
+ this.dates_l = dates_l;
this.slope = slope;
this.intercept = intercept;
this.area = area;
diff --git a/src/gui/cairo/jumpsWeightFVProfile.cs b/src/gui/cairo/jumpsWeightFVProfile.cs
index 8bc20ed5f..61320cd74 100644
--- a/src/gui/cairo/jumpsWeightFVProfile.cs
+++ b/src/gui/cairo/jumpsWeightFVProfile.cs
@@ -218,7 +218,7 @@ public class JumpsWeightFVProfileGraph : CairoXY
), false);
}
- protected override void writeSelectedValues(int line, PointF pClosest)
+ protected override void writeSelectedValues (int line, PointF pClosest, int closestPos)
{
g.SelectFontFace(font, Cairo.FontSlant.Normal, Cairo.FontWeight.Normal);
g.SetFontSize(textHeight);
diff --git a/src/gui/cairo/xy.cs b/src/gui/cairo/xy.cs
index 24f232565..ef0d94354 100644
--- a/src/gui/cairo/xy.cs
+++ b/src/gui/cairo/xy.cs
@@ -29,6 +29,7 @@ public abstract class CairoXY : CairoGeneric
{
//used on construction
protected List<PointF> point_l;
+ protected List<DateTime> dates_l; //used on button press to know day date instead of date as double
protected bool predictedPointDone;
//regression line straight
@@ -570,6 +571,7 @@ public abstract class CairoXY : CairoGeneric
g.SelectFontFace(font, Cairo.FontSlant.Normal, Cairo.FontWeight.Normal);
}
+ protected PointF pClosest;
protected void writeCoordinatesOfMouseClick (double graphX, double graphY, double realX, double realY)
{
int line = 4;
@@ -589,11 +591,11 @@ public abstract class CairoXY : CairoGeneric
LogB.Information("calling findClosestGraphPoint ...");
// 2) find closest point (including predicted point if any)
- PointF pClosest = findClosestGraphPoint(graphX, graphY);
+ int closestPos = findClosestGraphPointPos (graphX, graphY);
LogB.Information("writeSelectedValues ...");
// 3) write text at right
- writeSelectedValues(line, pClosest);
+ writeSelectedValues (line, pClosest, closestPos);
LogB.Information("painting rectangle ...");
// 4) paint rectangle around that point
@@ -608,10 +610,14 @@ public abstract class CairoXY : CairoGeneric
* using graphPoints and not real points because X and Y scale can be very different
* and this would be stranger for user to have a point selected far away to the "graph" closest point
*/
- private PointF findClosestGraphPoint(double graphX, double graphY)
+ //return the position in point_l, -1 if predicted is used
+ //the position is useful for jumpsRunsEvolution and asymmetry to know the real date on date_l
+ private int findClosestGraphPointPos (double graphX, double graphY)
{
double distMin = 10000000;
- PointF pClosest = point_l[0];
+ pClosest = point_l[0];
+ int count = 0;
+ int found = 0;
foreach(PointF p in point_l)
{
double dist = Math.Sqrt(Math.Pow(graphX - calculatePaintX(p.X), 2) + Math.Pow(graphY
- calculatePaintY(p.Y), 2));
@@ -619,17 +625,22 @@ public abstract class CairoXY : CairoGeneric
{
distMin = dist;
pClosest = p;
+ found = count;
}
+ count ++;
}
//also check predicted point if exists
if(predictedPointDone && Math.Sqrt(Math.Pow(graphX - calculatePaintX(xAtMMaxY), 2) +
Math.Pow(graphY - calculatePaintY(yAtMMaxY), 2)) < distMin)
+ {
pClosest = new PointF(xAtMMaxY, yAtMMaxY);
+ return -1;
+ }
- return pClosest;
+ return found;
}
- protected virtual void writeSelectedValues(int line, PointF pClosest)
+ protected virtual void writeSelectedValues(int line, PointF pClosest, int closestPos)
{
g.SelectFontFace(font, Cairo.FontSlant.Normal, Cairo.FontWeight.Normal);
g.SetFontSize(textHeight);
@@ -638,10 +649,19 @@ public abstract class CairoXY : CairoGeneric
writeTextAtRight(line, Catalog.GetString("Selected") + ":", false);
g.SetSourceRGB(0, 0, 0);
- writeTextAtRight(line +1, string.Format("- {0}: {1} {2}", xVariable,
Util.TrimDecimals(pClosest.X, 2), xUnits), false);
+ if (closestPos >= 0 && dates_l != null && dates_l.Count > 0 && closestPos < dates_l.Count)
+ writeTextAtRight(line +1, string.Format("- {0}: {1} {2}", xVariable, printXDateTime
(dates_l[closestPos]), xUnits), false);
+ else
+ writeTextAtRight(line +1, string.Format("- {0}: {1} {2}", xVariable,
Util.TrimDecimals(pClosest.X, 2), xUnits), false);
+
writeTextAtRight(line +2, string.Format("- {0}: {1} {2}", yVariable,
Util.TrimDecimals(pClosest.Y, 2), yUnits), false);
}
+ //on jumpsAsymmetry is overrided and only prints time
+ protected virtual string printXDateTime (DateTime dt)
+ {
+ return (dt.ToString ());
+ }
protected override double calculatePaintX (double realX)
{
diff --git a/src/jumpsRunsEvolution.cs b/src/jumpsRunsEvolution.cs
index 67fdd9dc1..d0f928aec 100644
--- a/src/jumpsRunsEvolution.cs
+++ b/src/jumpsRunsEvolution.cs
@@ -15,7 +15,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * Copyright (C) 2019-2021 Xavier de Blas <xaviblas gmail com>
+ * Copyright (C) 2019-2022 Xavier de Blas <xaviblas gmail com>
*/
using System;
@@ -26,6 +26,7 @@ using System.Collections.Generic; //List
public abstract class JumpsRunsEvolution
{
protected List<PointF> point_l;
+ protected List<DateTime> dates_l; //used on button press to know day date instead of date as double
protected LeastSquaresLine ls;
public abstract void Calculate(int personID, string type, bool onlyBestInSession);
@@ -56,6 +57,10 @@ public abstract class JumpsRunsEvolution
{
get { return point_l; }
}
+ public List<DateTime> Dates_l
+ {
+ get { return dates_l; }
+ }
public double Slope
{
@@ -82,6 +87,7 @@ public class JumpsEvolution : JumpsRunsEvolution
//2 convert to list of PointF
point_l = new List<PointF>();
+ dates_l = new List<DateTime>();
int currentSession = -1;
foreach(Jump j in jump_l)
{
@@ -98,6 +104,7 @@ public class JumpsEvolution : JumpsRunsEvolution
double dtDouble = UtilDate.DateTimeYearDayAsDouble(dt);
point_l.Add(new PointF(dtDouble, Util.GetHeightInCentimeters(j.Tv)));
+ dates_l.Add(dt);
}
getLeastSquaresLine ();
@@ -172,6 +179,7 @@ public class RunsEvolution : JumpsRunsEvolution
r.MetersSecondsPreferred = metersSecondsPreferred;
point_l.Add(new PointF(dtDouble, r.Speed));
}
+ dates_l.Add(dt);
}
distance_l = Util.SortDoublesListString(distance_l);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]