[chronojump/FS-TFT-Menu] Several optimizations to CairoBars text above bar



commit ec16cfd53e0d03648e57111fc0cf6ad83da6909b
Author: Xavier de Blas <xaviblas gmail com>
Date:   Wed Mar 23 11:57:13 2022 +0100

    Several optimizations to CairoBars text above bar

 src/gui/cairo/bars.cs   | 34 ++++++++++++++++++++++++----------
 src/gui/eventExecute.cs | 20 ++++++++++----------
 2 files changed, 34 insertions(+), 20 deletions(-)
---
diff --git a/src/gui/cairo/bars.cs b/src/gui/cairo/bars.cs
index 24e0f2b21..520871fa7 100644
--- a/src/gui/cairo/bars.cs
+++ b/src/gui/cairo/bars.cs
@@ -28,6 +28,8 @@ public abstract class CairoBars : CairoGeneric
 {
        protected DrawingArea area;
        protected ImageSurface surface;
+
+       protected int fontHeightAboveBar; //will be reduced if does not fit. On encoder is bigger than other 
places, pass -1 if don't want to define
        protected int fontHeightForBottomNames;
        protected int marginForBottomNames;
        protected string title;
@@ -252,7 +254,8 @@ public abstract class CairoBars : CairoGeneric
 
        public virtual void PassData1Serie (List<PointF> pointMain_l,
                        List<Cairo.Color> colorMain_l, List<string> names_l,
-                       int fontHeightForBottomNames, int marginForBottomNames, string title, bool clickable)
+                       int fontHeightAboveBar, int fontHeightForBottomNames, int marginForBottomNames,
+                       string title, bool clickable)
        {
                //defined in CairoBars1Series
        }
@@ -260,7 +263,8 @@ public abstract class CairoBars : CairoGeneric
        public virtual void PassData2Series (List<PointF> pointMain_l, List<List<PointF>> pointSecondary_ll, 
bool mainAtLeft,
                        List<Cairo.Color> colorMain_l, List<Cairo.Color> colorSecondary_l, List<string> 
names_l,
                        string labelBarMain, string labelBarSecondary, bool labelRotateInFirstBar,
-                       int fontHeightForBottomNames, int marginForBottomNames, string title, bool clickable)
+                       int fontHeightAboveBar, int fontHeightForBottomNames, int marginForBottomNames,
+                       string title, bool clickable)
        {
                //defined in CairoBarsNHSeries
        }
@@ -544,7 +548,6 @@ public abstract class CairoBars : CairoGeneric
                return Convert.ToInt32(1.3 * te.Height * maxRows);
        }
 
-       //TODO: at the moment we are not lowering decs, make resultsFontHeight and decs global variables
        protected int getBarsResultFontHeight (double maxWidth)
        {
                double maxLengthNumber = 9.99;
@@ -560,6 +563,9 @@ public abstract class CairoBars : CairoGeneric
 
                //fix if label is wider than bar
                int optimalFontHeight = textHeight;
+               if(fontHeightAboveBar >= 0)
+                       optimalFontHeight = fontHeightAboveBar;
+
                for(int i = textHeight; te.Width >= maxWidth && i > 0; i --)
                {
                        //if(i <= 8)
@@ -588,8 +594,8 @@ public abstract class CairoBars : CairoGeneric
                        maxLengthNumber = 9999.99;
 
                Cairo.TextExtents te;
-               ///te = g.TextExtents(Util.TrimDecimals(result,decs));
-               te = g.TextExtents(maxLengthNumber.ToString());
+               te = g.TextExtents(Util.TrimDecimals(result,decs));
+               //te = g.TextExtents(maxLengthNumber.ToString());
 
                bool textAboveBar = true;
                /*
@@ -605,6 +611,8 @@ public abstract class CairoBars : CairoGeneric
                        yStart = y - 1.5*te.Height;
                }
 
+               /*
+                  Do not move the bar above to fix overlappings as it's very ugly
                //check if there's an overlap with pointA)
                if ( yStartPointA >= 0 && te.Width >= barWidth &&
                                ( yStart >= yStartPointA && yStart <= yStartPointA + te.Height ||
@@ -615,13 +623,15 @@ public abstract class CairoBars : CairoGeneric
 
                if( (yStart + te.Height) > alto )
                        yStart = alto - te.Height;
+               */
 
                if(textAboveBar)
                        g.SetSourceColor(white); //to just hide the horizontal grid
                else
                        g.SetSourceColor(yellow); //to have contrast with the bar
 
-               g.Rectangle(x - te.Width/2 -1, yStart-1, te.Width +2, te.Height+2);
+               //g.Rectangle(x - te.Width/2 -1, yStart-1, te.Width +2, te.Height+2);
+               g.Rectangle(x - te.Width/2, yStart, te.Width, te.Height);
                g.Fill();
 
                //write text
@@ -778,7 +788,7 @@ public class CairoBars1Series : CairoBars
 
                 double barWidth = Convert.ToInt32(.5*distanceBetweenCols);
                 double barDesplLeft = Convert.ToInt32(.5*barWidth);
-               int resultFontHeight = getBarsResultFontHeight (barWidth*2);
+               int resultFontHeight = getBarsResultFontHeight (barWidth*1.5); //*1.5 because there is space 
at left and right
                LogB.Information("resultFontHeight: " + resultFontHeight.ToString());
 
                for(int i = 0; i < pointMain_l.Count; i ++)
@@ -809,11 +819,13 @@ public class CairoBars1Series : CairoBars
        //done here and not in the constructor because most of this variables are known after construction
        public override void PassData1Serie (List<PointF> pointMain_l,
                        List<Cairo.Color> colorMain_l, List<string> names_l,
-                       int fontHeightForBottomNames, int marginForBottomNames, string title, bool clickable)
+                       int fontHeightAboveBar, int fontHeightForBottomNames, int marginForBottomNames,
+                       string title, bool clickable)
        {
                this.pointMain_l = pointMain_l;
                this.colorMain_l = colorMain_l;
                this.names_l = names_l;
+               this.fontHeightAboveBar = fontHeightAboveBar;
                this.fontHeightForBottomNames = fontHeightForBottomNames;
                this.marginForBottomNames = marginForBottomNames;
                this.title = title;
@@ -1043,7 +1055,7 @@ public class CairoBarsNHSeries : CairoBars
                if(pointSecondary_ll.Count == 2) //TODO: fix this for more columns
                        barWidth = .8*distanceBetweenCols/3; //three bars will be .8
                 double barDesplLeft = .5*barWidth;
-               int resultFontHeight = getBarsResultFontHeight (barWidth*1.5);
+               int resultFontHeight = getBarsResultFontHeight (barWidth*1.1);
                List<Point3F> resultOnBars_l = new List<Point3F>();
 
 
@@ -1169,7 +1181,8 @@ public class CairoBarsNHSeries : CairoBars
        public override void PassData2Series (List<PointF> pointMain_l, List<List<PointF>> pointSecondary_ll, 
bool mainAtLeft,
                        List<Cairo.Color> colorMain_l, List<Cairo.Color> colorSecondary_l, List<string> 
names_l,
                        string labelBarMain, string labelBarSecondary, bool labelRotateInFirstBar,
-                       int fontHeightForBottomNames, int marginForBottomNames, string title, bool clickable)
+                       int fontHeightAboveBar, int fontHeightForBottomNames, int marginForBottomNames,
+                       string title, bool clickable)
        {
                this.pointSecondary_ll = pointSecondary_ll;
                this.pointMain_l = pointMain_l;
@@ -1179,6 +1192,7 @@ public class CairoBarsNHSeries : CairoBars
                this.labelBarMain = labelBarMain;
                this.labelBarSecondary = labelBarSecondary;
                this.labelRotateInFirstBar = labelRotateInFirstBar;
+               this.fontHeightAboveBar = fontHeightAboveBar;
                this.fontHeightForBottomNames = fontHeightForBottomNames;
                this.marginForBottomNames = marginForBottomNames;
                this.title = title;
diff --git a/src/gui/eventExecute.cs b/src/gui/eventExecute.cs
index da7472e74..3b6f26e54 100644
--- a/src/gui/eventExecute.cs
+++ b/src/gui/eventExecute.cs
@@ -2640,15 +2640,15 @@ public class CairoPaintBarsPreJumpSimple : CairoPaintBarsPre
                        cb.PassData2Series (pointB_l, pointSecondary_ll, false,
                                        new List<Cairo.Color>(), new List<Cairo.Color>(), names_l,
                                        "", "", false,
-                                       fontHeightForBottomNames, bottomMargin, title, false);
+                                       -1, fontHeightForBottomNames, bottomMargin, title, false);
                } else if (showBarA) //takeOff, takeOffWeight
                        cb.PassData1Serie (pointA_l,
                                        new List<Cairo.Color>(), names_l,
-                                       fontHeightForBottomNames, bottomMargin, title, false);
+                                       -1, fontHeightForBottomNames, bottomMargin, title, false);
                else //rest of the jumps: sj, cmj, ..
                        cb.PassData1Serie (pointB_l,
                                        new List<Cairo.Color>(), names_l,
-                                       fontHeightForBottomNames, bottomMargin, title, false);
+                                       -1, fontHeightForBottomNames, bottomMargin, title, false);
 
                cb.GraphDo();
        }
@@ -2779,7 +2779,7 @@ public class CairoPaintBarsPreJumpReactive : CairoPaintBarsPre
                cb.PassData2Series (pointB_l, pointSecondary_ll, false,
                                new List<Cairo.Color>(), new List<Cairo.Color>(), names_l,
                                "", "", false,
-                               fontHeightForBottomNames, bottomMargin, title, false);
+                               -1, fontHeightForBottomNames, bottomMargin, title, false);
                cb.GraphDo();
        }
 }
@@ -2880,7 +2880,7 @@ public class CairoPaintBarsPreRunSimple : CairoPaintBarsPre
 
                cb.PassData1Serie (point_l,
                                new List<Cairo.Color>(), names_l,
-                               fontHeightForBottomNames, bottomMargin, title, false);
+                               -1, fontHeightForBottomNames, bottomMargin, title, false);
                cb.GraphDo();
        }
 }
@@ -2991,7 +2991,7 @@ public class CairoPaintBarsPreRunInterval : CairoPaintBarsPre
 
                cb.PassData1Serie (point_l,
                                new List<Cairo.Color>(), names_l,
-                               fontHeightForBottomNames, bottomMargin, title, false);
+                               -1, fontHeightForBottomNames, bottomMargin, title, false);
                cb.GraphDo();
        }
 }
@@ -3121,7 +3121,7 @@ public class CairoPaintBarsPreJumpReactiveRealtimeCapture : CairoPaintBarsPre
                cb.PassData2Series (pointB_l, pointSecondary_ll, false,
                                new List<Cairo.Color>(), new List<Cairo.Color>(), names_l,
                                "", "", false,
-                               14, 8, title, false);
+                               -1, 14, 8, title, false);
                cb.GraphDo();
        }
 }
@@ -3293,7 +3293,7 @@ public class CairoPaintBarsPreRunIntervalRealtimeCapture : CairoPaintBarsPre
 
                cb.PassData1Serie (point_l,
                                new List<Cairo.Color>(), names_l,
-                               14, 22, title, false); //22 because there are two rows
+                               -1, 14, 22, title, false); //22 because there are two rows
                cb.GraphDo();
        }
 }
@@ -3791,7 +3791,7 @@ public class CairoPaintBarplotPreEncoder : CairoPaintBarsPre
                if(pegbe.eccon == "c")
                        cb.PassData1Serie (dataA_l,
                                        colorMain_l, names_l,
-                                       14, 8, "my title", ! pegbe.capturing);
+                                       20, 14, 8, "my title", ! pegbe.capturing);
                else {
                        List<List<PointF>> pointSecondary_ll = new List<List<PointF>>();
                        pointSecondary_ll.Add(dataA_l);
@@ -3799,7 +3799,7 @@ public class CairoPaintBarplotPreEncoder : CairoPaintBarsPre
                        cb.PassData2Series (dataB_l, pointSecondary_ll, false,
                                        colorMain_l, colorSecondary_l, names_l,
                                        "Ecc", "Con", true,
-                                       14, 8, "my title", ! pegbe.capturing);
+                                       20, 14, 8, "my title", ! pegbe.capturing);
                }
 
                cb.GraphDo();


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