[chronojump] Graph run start in displays 0 speed at beginning



commit 5c9f739af9ed48179eb478761c159f49636ddffb
Author: Xavier de Blas <xaviblas gmail com>
Date:   Fri Jun 10 14:50:51 2016 +0200

    Graph run start in displays 0 speed at beginning

 src/execute/run.cs       |    5 ++-
 src/gui/chronojump.cs    |    1 +
 src/gui/eventExecute.cs  |   55 +++++++++++++++++++++++++++++++++++-----------
 src/gui/usefulObjects.cs |    5 +++-
 src/run.cs               |    5 ++++
 src/util.cs              |   15 +++++++++++-
 6 files changed, 68 insertions(+), 18 deletions(-)
---
diff --git a/src/execute/run.cs b/src/execute/run.cs
index cbc9c9c..9224fbf 100644
--- a/src/execute/run.cs
+++ b/src/execute/run.cs
@@ -684,7 +684,7 @@ public class RunIntervalExecute : RunExecute
                                                //update graph
                                                PrepareEventGraphRunIntervalObject = new 
PrepareEventGraphRunInterval(
                                                                distanceIntervalFixed, myRaceTime, 
intervalTimesString, 
-                                                               distanceTotal, distancesString);
+                                                               distanceTotal, distancesString, startIn);
 
                                                needUpdateGraphType = eventType.RUNINTERVAL;
                                                needUpdateGraph = true;
@@ -966,7 +966,8 @@ public class RunIntervalExecute : RunExecute
                        fakeButtonFinished.Click();
 
                        PrepareEventGraphRunIntervalObject = new PrepareEventGraphRunInterval(
-                                       distanceIntervalFixed, Util.GetLast(intervalTimesString), 
intervalTimesString, distanceTotal, distancesString);
+                                       distanceIntervalFixed, Util.GetLast(intervalTimesString), 
+                                       intervalTimesString, distanceTotal, distancesString, startIn);
                        needUpdateGraphType = eventType.RUNINTERVAL;
                        needUpdateGraph = true;
 
diff --git a/src/gui/chronojump.cs b/src/gui/chronojump.cs
index 143a10d..9b3a9d1 100644
--- a/src/gui/chronojump.cs
+++ b/src/gui/chronojump.cs
@@ -5163,6 +5163,7 @@ LogB.Debug("X");
                                                                currentRunInterval.IntervalTimesString, 
                                                                distanceTotal,
                                                                runType.DistancesString,
+                                                               currentRunInterval.StartIn,
                                                                preferences.volumeOn, 
repetitiveConditionsWin);
                                        }
                                        break;
diff --git a/src/gui/eventExecute.cs b/src/gui/eventExecute.cs
index 1e675f9..b27a406 100644
--- a/src/gui/eventExecute.cs
+++ b/src/gui/eventExecute.cs
@@ -679,7 +679,7 @@ public partial class ChronoJumpWindow
        // run interval
        // distanceTotal is passed because it can change in variable distances test
        public void PrepareRunIntervalGraph(double distance, double lastTime, string timesString, double 
distanceTotal, string distancesString,
-                       bool volumeOn, RepetitiveConditionsWindow repetitiveConditionsWin) {
+                       bool startIn, bool volumeOn, RepetitiveConditionsWindow repetitiveConditionsWin) {
                //check graph properties window is not null (propably user has closed it with the DeleteEvent
                //then create it, but not show it
                if(eventGraphConfigureWin == null)
@@ -704,13 +704,15 @@ public partial class ChronoJumpWindow
                int bottomMargin = 0; 
                //if min value of graph is automatic
                if(eventGraphConfigureWin.Min == -1) { 
-                       if(distancesString == "")
+                       if(startIn)
+                               minValue = 0;
+                       else if(distancesString == "")
                                minValue = distance / Util.GetMax(timesString); //getMax because is in the 
"denominador"
                        else
                                minValue = Util.GetRunIVariableDistancesSpeeds(distancesString, timesString, 
false);
                } else {
                        minValue = eventGraphConfigureWin.Min;
-               }               
+               }
 
                int tracks = Util.GetNumberOfJumps(timesString, true); 
 
@@ -718,7 +720,7 @@ public partial class ChronoJumpWindow
                paintRunInterval (event_execute_drawingarea, distance, distanceTotal, distancesString,
                                lastTime, timesString, Util.GetAverage(timesString), 
                                maxValue, minValue, tracks, topMargin, bottomMargin,
-                               Util.GetPosMax(timesString), Util.GetPosMin(timesString),
+                               Util.GetPosMax(timesString), Util.GetPosMin(timesString), startIn,
                                volumeOn, repetitiveConditionsWin);
                
                // -- refresh
@@ -1355,14 +1357,13 @@ public partial class ChronoJumpWindow
 
        private void paintRunInterval (Gtk.DrawingArea drawingarea, double distance, double distanceTotal, 
string distancesString, double lastTime, 
                        string timesString, double avgTime, double maxValue, double minValue, int tracks, int 
topMargin, int bottomMargin, 
-                       int hightValuePosition, int lowValuePosition,
+                       int hightValuePosition, int lowValuePosition, bool startIn,
                        bool volumeOn, RepetitiveConditionsWindow repetitiveConditionsWin)
        {
                //int topMargin = 10; 
                int ancho=drawingarea.Allocation.Width;
                int alto=drawingarea.Allocation.Height;
-               
-               
+       
                UtilGtk.ErasePaint(event_execute_drawingarea, event_execute_pixmap);
                
                writeMarginsText(maxValue, minValue, alto);
@@ -1382,6 +1383,10 @@ public partial class ChronoJumpWindow
                        
                        string [] myTimesStringFull = timesString.Split(new char[] {'='});
                        int count = 0;
+                       int added0Value = 0;
+                       if(startIn)
+                               added0Value = 1;
+
                        double oldValue = 0;
                        double myTimeDouble = 0;
 
@@ -1402,21 +1407,44 @@ public partial class ChronoJumpWindow
                                else
                                        myValue = Util.GetRunIVariableDistancesStringRow(distancesString, 
count) / myTimeDouble;
 
-                               if (count > 0) {
+                               if(count == 0 && startIn) {
                                        event_execute_pixmap.DrawLine(myPen,
-                                                       Convert.ToInt32((ancho - event_execute_rightMargin) 
*(count-.5)/tracks), calculatePaintHeight(oldValue, alto, maxValue, minValue, topMargin, bottomMargin),
-                                                       Convert.ToInt32((ancho - event_execute_rightMargin) 
*(count+.5)/tracks), calculatePaintHeight(myValue, alto, maxValue, minValue, topMargin, bottomMargin));
+                                                       Convert.ToInt32((ancho - event_execute_rightMargin) 
*(count - .5 + added0Value)/(tracks + added0Value)), 
+                                                       //calculatePaintHeight(0, alto, maxValue, minValue, 
topMargin, bottomMargin),
+                                                       alto,
+                                                       Convert.ToInt32((ancho - event_execute_rightMargin) 
*(count + .5 + added0Value)/(tracks + added0Value)), 
+                                                       calculatePaintHeight(myValue, alto, maxValue, 
minValue, topMargin, bottomMargin));
+                               } 
+                               else if (count > 0) {
+                                       event_execute_pixmap.DrawLine(myPen,
+                                                       Convert.ToInt32((ancho - event_execute_rightMargin) 
*(count - .5 + added0Value)/(tracks + added0Value)), 
+                                                       calculatePaintHeight(oldValue, alto, maxValue, 
minValue, topMargin, bottomMargin),
+                                                       Convert.ToInt32((ancho - event_execute_rightMargin) 
*(count + .5 + added0Value)/(tracks + added0Value)), 
+                                                       calculatePaintHeight(myValue, alto, maxValue, 
minValue, topMargin, bottomMargin));
                                }
                                
                                //paint Y lines
-                               if(eventGraphConfigureWin.VerticalGrid) 
-                                       event_execute_pixmap.DrawLine(pen_beige_discont, 
Convert.ToInt32((ancho - event_execute_rightMargin) *(count+.5)/tracks), topMargin, Convert.ToInt32((ancho - 
event_execute_rightMargin) *(count+.5)/tracks), alto-topMargin);
+                               if(eventGraphConfigureWin.VerticalGrid) {
+                                       if(count == 0 && startIn) {
+                                               event_execute_pixmap.DrawLine(pen_beige_discont, 
+                                                               Convert.ToInt32((ancho - 
event_execute_rightMargin) *(count -.5 + added0Value)/(tracks + added0Value)), 
+                                                               topMargin,
+                                                               Convert.ToInt32((ancho - 
event_execute_rightMargin) *(count -.5 + added0Value)/(tracks + added0Value)), 
+                                                               alto-topMargin);
+                                       }
+                                       
+                                       event_execute_pixmap.DrawLine(pen_beige_discont, 
+                                                       Convert.ToInt32((ancho - event_execute_rightMargin) 
*(count +.5 + added0Value)/(tracks + added0Value)), 
+                                                       topMargin, 
+                                                       Convert.ToInt32((ancho - event_execute_rightMargin) 
*(count +.5 + added0Value)/(tracks + added0Value)), 
+                                                       alto-topMargin);
+                               }
 
                                oldValue = myValue;
                                count ++;
                        }
                        
-                       drawCircleAndWriteValue(myPen, myValue, --count, tracks, ancho, alto, maxValue, 
minValue, topMargin, bottomMargin);
+                       drawCircleAndWriteValue(myPen, myValue, (--count) + added0Value, tracks, ancho, alto, 
maxValue, minValue, topMargin, bottomMargin);
                
 
                        //bells & images
@@ -1809,6 +1837,7 @@ public partial class ChronoJumpWindow
                                                        
currentEventExecute.PrepareEventGraphRunIntervalObject.timesString,
                                                        
currentEventExecute.PrepareEventGraphRunIntervalObject.distanceTotal,
                                                        
currentEventExecute.PrepareEventGraphRunIntervalObject.distancesString,
+                                                       
currentEventExecute.PrepareEventGraphRunIntervalObject.startIn,
                                                        volumeOnHere, repetitiveConditionsWin);
                                }
                                break;
diff --git a/src/gui/usefulObjects.cs b/src/gui/usefulObjects.cs
index 9265527..b583034 100644
--- a/src/gui/usefulObjects.cs
+++ b/src/gui/usefulObjects.cs
@@ -180,16 +180,19 @@ public class PrepareEventGraphRunInterval {
        public string timesString;
        public double distanceTotal; //we pass this because it's dificult to calculate in runs with variable 
distances
        public string distancesString; //we pass this because it's dificult to calculate in runs with 
variable distances
+       public bool startIn;
 
        public PrepareEventGraphRunInterval() {
        }
 
-       public PrepareEventGraphRunInterval(double distance, double lastTime, string timesString, double 
distanceTotal, string distancesString) {
+       public PrepareEventGraphRunInterval(double distance, double lastTime, string timesString, 
+                       double distanceTotal, string distancesString, bool startIn) {
                this.distance = distance;
                this.lastTime = lastTime;
                this.timesString = timesString;
                this.distanceTotal = distanceTotal;
                this.distancesString = distancesString;
+               this.startIn = startIn;
        }
 
        ~PrepareEventGraphRunInterval() {}
diff --git a/src/run.cs b/src/run.cs
index 03c0928..fe9f603 100644
--- a/src/run.cs
+++ b/src/run.cs
@@ -230,6 +230,11 @@ public class RunInterval : Run
                get { return tracksLimited; }
        }
                
+       public bool StartIn
+       {
+               get { return startIn; }
+       }
+               
        public override double Speed
        {
                get { 
diff --git a/src/util.cs b/src/util.cs
index 89ab698..cc67b7b 100644
--- a/src/util.cs
+++ b/src/util.cs
@@ -1713,7 +1713,12 @@ public class Util
 
                        double distance = Convert.ToDouble(distances[distPos]);
 
-                       double speed = distance / time;
+                       double speed;
+                       if(distance == 0 || time == 0)
+                               speed = 0;
+                       else
+                               speed = distance / time;
+
                        if(max) {
                                if(speed > searchedValue) 
                                        searchedValue = speed;
@@ -1753,7 +1758,13 @@ public class Util
                        } else 
                                distance = distanceInterval;
 
-                       speeds += sep + (distance / time * 1.0).ToString();
+                       double speedNow;
+                       if(distance == 0 || time == 0)
+                               speedNow = 0;
+                       else
+                               speedNow = distance / time;
+                       
+                       speeds += sep + (speedNow * 1.0).ToString();
                        sep = separator;
                }
                //fill the row with 0's equalling largest row


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