[chronojump] Lots of improvements to CairoBars



commit ddc443da8530c47671228e0220a43274a7eac48f
Author: Xavier de Blas <xaviblas gmail com>
Date:   Wed Aug 25 01:24:24 2021 +0200

    Lots of improvements to CairoBars

 src/gui/cairo/bars.cs   | 79 +++++++++++++++++++++++++++++--------------------
 src/gui/eventExecute.cs | 54 +++++++++++++++++++++++++++++++--
 2 files changed, 98 insertions(+), 35 deletions(-)
---
diff --git a/src/gui/cairo/bars.cs b/src/gui/cairo/bars.cs
index 1628e3b31..f9a329511 100644
--- a/src/gui/cairo/bars.cs
+++ b/src/gui/cairo/bars.cs
@@ -31,7 +31,7 @@ public abstract class CairoBars : CairoGeneric
        //protected string jumpType;
        //protected string runType;
        protected string date;
-       protected Cairo.Color colorSerie1;
+       protected Cairo.Color colorSerieA;
 
        protected Cairo.Context g;
        protected int lineWidthDefault = 2;
@@ -331,6 +331,9 @@ public abstract class CairoBars : CairoGeneric
        //reccomended to 1st paint the grid, then the axis
        protected void paintGrid(gridTypes gridType, bool niceAutoValues)
        {
+               if(minY == maxY)
+                       return;
+
                g.LineWidth = 1; //to allow to be shown the red arrows on jumpsWeightFVProfile
 
                if(niceAutoValues)
@@ -339,6 +342,12 @@ public abstract class CairoBars : CairoGeneric
                        paintGridInt (g, minX, maxX, minY, maxY, 1, gridType);
        }
 
+       public string YVariable {
+               set { yVariable = value; }
+       }
+       public string YUnits {
+               set { yUnits = value; }
+       }
 }
 
 public class CairoBars1Series : CairoBars
@@ -366,7 +375,7 @@ public class CairoBars1Series : CairoBars
                this.area = area;
                this.title = title;
 
-               this.colorSerie1 = colorFromGdk(Config.ColorBackground); //but note if we are using system 
colors, this will not match
+               this.colorSerieA = colorFromGdk(Config.ColorBackground); //but note if we are using system 
colors, this will not match
        }
 
        protected override void findPointMaximums()
@@ -400,7 +409,7 @@ public class CairoBars1Series : CairoBars
                        double x = (graphWidth - 2*outerMargins) * (p.X-.5)/point_l.Count - barDesplLeft + 
outerMargins;
                        double y = calculatePaintY(p.Y);
 
-                       drawRoundedRectangle (true, x, y, barWidth, graphHeight -y -outerMargins, 4, g, 
colorSerie1);
+                       drawRoundedRectangle (true, x, y, barWidth, graphHeight -y -outerMargins, 4, g, 
colorSerieA);
 
                        plotResultOnBar(x + barWidth/2, y, graphHeight -outerMargins, p.Y, resultFontHeight, 
barWidth, -1);
 
@@ -441,7 +450,7 @@ public class CairoBars2HSeries : CairoBars
        private List<PointF> pointB_l;
        private List<string> names_l;
 
-       private Cairo.Color colorSerie2;
+       private Cairo.Color colorSerieB;
 
        //constructor when there are no points
        public CairoBars2HSeries (DrawingArea area, string font)
@@ -464,9 +473,9 @@ public class CairoBars2HSeries : CairoBars
                this.area = area;
                this.title = title;
 
-               this.colorSerie1 = colorFromGdk(Config.ColorBackground); //but note if we are using system 
colors, this will not match
-               colorSerie2 = colorFromGdk(UtilGtk.GetColorShifted(Config.ColorBackground,
+               colorSerieA = colorFromGdk(UtilGtk.GetColorShifted(Config.ColorBackground,
                                        ! UtilGtk.ColorIsDark(Config.ColorBackground)));
+               colorSerieB = colorFromGdk(Config.ColorBackground); //but note if we are using system colors, 
this will not match
        }
 
        protected override void findPointMaximums()
@@ -498,35 +507,41 @@ public class CairoBars2HSeries : CairoBars
                double valueABSep = 0;
                int resultFontHeight = getBarsResultFontHeight (barWidth*1.5);
 
+               //TODO: do the plotResultOnBar calls at the end of this for, with another for (knowing the 
X,Y of the bars)
                for(int i = 0; i < pointA_l.Count; i ++)
                {
-                       PointF p = pointA_l[i];
-
-                       double adjustX = -barDesplLeft;
-                       //if(valueB > 0)
-                               adjustX = -2 * barDesplLeft -.5 * valueABSep;
-
-                       double x = (graphWidth - 2*outerMargins) * p.X/maxX - barDesplLeft + adjustX + 
outerMargins;
-                       double y = calculatePaintY(p.Y);
-
-                       drawRoundedRectangle (true, x, y, barWidth, graphHeight -y -outerMargins, 4, g, 
colorSerie1);
-                       double yStartPointA = plotResultOnBar(x + barWidth/2, y, graphHeight -outerMargins, 
p.Y, resultFontHeight, barWidth, -1);
-
-                       //print the type at bottom
-                       printText(x + barWidth + valueABSep/2, graphHeight -outerMargins + textHeight/2, 0, 
textHeight,
+                       PointF pA = pointA_l[i];
+                       PointF pB = pointB_l[i];
+                       double pAyStart = 0;
+
+                       if(pA.Y > 0)
+                       {
+                               double adjustX = -barDesplLeft;
+                               if(pB.Y > 0)
+                                       adjustX = -2 * barDesplLeft -.5 * valueABSep;
+
+                               double x = (graphWidth - 2*outerMargins) * pA.X/maxX - barDesplLeft + adjustX 
+ outerMargins;
+                               double y = calculatePaintY(pA.Y);
+
+                               drawRoundedRectangle (true, x, y, barWidth, graphHeight -y -outerMargins, 4, 
g, colorSerieA);
+                               pAyStart = plotResultOnBar(x + barWidth/2, y, graphHeight -outerMargins, 
pA.Y, resultFontHeight, barWidth, -1);
+                       }
+                       if(pB.Y > 0)
+                       {
+                               double adjustX = -barDesplLeft;
+                               if(pA.Y > 0)
+                                       adjustX = .5 * valueABSep;
+
+                               double x = (graphWidth - 2*outerMargins) * pB.X/maxX - barDesplLeft + adjustX 
+ outerMargins;
+                               double y = calculatePaintY(pB.Y);
+
+                               drawRoundedRectangle (true, x, y, barWidth, graphHeight -y - outerMargins, 4, 
g, colorSerieB);
+                               plotResultOnBar(x + barWidth/2, y, graphHeight -outerMargins, pB.Y, 
resultFontHeight, barWidth, pAyStart);
+                       }
+
+                       printText( (graphWidth - 2*outerMargins) * pA.X/maxX + -barDesplLeft + outerMargins,
+                                       graphHeight -outerMargins + textHeight/2, 0, textHeight,
                                        names_l[i], g, alignTypes.CENTER);
-
-                       p = pointB_l[i];
-
-                       adjustX = -barDesplLeft;
-                       //if(valueA > 0)
-                               adjustX = .5 * valueABSep;
-
-                       x = (graphWidth - 2*outerMargins) * p.X/maxX - barDesplLeft + adjustX + outerMargins;
-                       y = calculatePaintY(p.Y);
-
-                       drawRoundedRectangle (true, x, y, barWidth, graphHeight -y - outerMargins, 4, g, 
colorSerie2);
-                       plotResultOnBar(x + barWidth/2, y, graphHeight -outerMargins, p.Y, resultFontHeight, 
barWidth, yStartPointA);
                }
        }
 
diff --git a/src/gui/eventExecute.cs b/src/gui/eventExecute.cs
index 9c637a4de..2c1a93dec 100644
--- a/src/gui/eventExecute.cs
+++ b/src/gui/eventExecute.cs
@@ -726,6 +726,7 @@ public partial class ChronoJumpWindow
                event_execute_drawingarea.QueueDraw();
 
                // B) Paint cairo graph
+               cairoPaintBarsPre.UseHeights = useHeights;
                cairoPaintBarsPre.Paint();
        }
 
@@ -3143,7 +3144,11 @@ public partial class ChronoJumpWindow
 //to prepare data before calling cairo method
 public abstract class CairoPaintBarsPre
 {
+       //jump simple
        public PrepareEventGraphJumpSimple eventGraphJumpsStored;
+       public bool UseHeights;
+
+       //run simple
        public PrepareEventGraphRunSimple eventGraphRunsStored;
 
        protected DrawingArea darea;
@@ -3231,17 +3236,60 @@ public class CairoPaintBarsPreJumpSimple : CairoPaintBarsPre
 
        protected override void paintSpecific()
        {
-               List<PointF> point_l = new List<PointF>();
+               List<PointF> pointA_l = new List<PointF>();
+               List<PointF> pointB_l = new List<PointF>();
                List<string> names_l = new List<string>();
 
+               /*
+                * check if one bar has to be shown or two
+                * this is important when we are showing multitests
+                */
+               bool showBarA = false; //tc or fall
+               bool showBarB = false; //tv or height
+               foreach(Jump jump in eventGraphJumpsStored.jumpsAtSQL)
+               {
+                       if(jump.Fall > 0 || jump.Tc > 0) //jump.Tc to include takeOff, takeOffWeiht
+                               showBarA = true;
+                       if(jump.Tv > 0)
+                               showBarB = true;
+
+                       //if both found do not need to search more
+                       if(showBarA && showBarB)
+                               break;
+               }
+
                int countToDraw = eventGraphJumpsStored.jumpsAtSQL.Count;
                foreach(Jump jump in eventGraphJumpsStored.jumpsAtSQL)
                {
-                       point_l.Add(new PointF(countToDraw --, Util.GetHeightInCentimeters(jump.Tv)));
+                       double valueA = jump.Fall;
+                       double valueB = Util.GetHeightInCentimeters(jump.Tv); //jump height
+                       if(! UseHeights) {
+                               valueA = jump.Tc;
+                               valueB = jump.Tv;
+                       }
+
+                       pointA_l.Add(new PointF(countToDraw, valueA));
+                       pointB_l.Add(new PointF(countToDraw, valueB));
+                       countToDraw --;
+
                        names_l.Add(jump.Type);
                }
 
-               CairoBars2HSeries cbjt = new CairoBars2HSeries (point_l, point_l, names_l, darea, title);
+               CairoBars cbjt;
+               if(showBarA && showBarB) //Dja, Djna
+                       cbjt = new CairoBars2HSeries (pointA_l, pointB_l, names_l, darea, title);
+               else if (showBarA) //takeOff, takeOffWeight
+                       cbjt = new CairoBars1Series (pointA_l, names_l, darea, title);
+               else //rest of the jumps: sj, cmj, ..
+                       cbjt = new CairoBars1Series (pointB_l, names_l, darea, title);
+
+               if(UseHeights) {
+                       cbjt.YVariable = "Height";
+                       cbjt.YUnits = "cm";
+               } else {
+                       cbjt.YVariable = "Time";
+                       cbjt.YUnits = "s";
+               }
                cbjt.Do(fontStr);
        }
 }


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