[chronojump] Lots of fixes to Cairo Graphs



commit 348930eafabb93ef7ed0f84cf34bc7ab0777e85e
Author: Xavier de Blas <xaviblas gmail com>
Date:   Thu Aug 26 11:49:57 2021 +0200

    Lots of fixes to Cairo Graphs

 src/gui/cairo/bars.cs                 | 97 ++++++++++++++++++++---------------
 src/gui/cairo/generic.cs              | 56 ++++++++++----------
 src/gui/cairo/jumpsRjFatigue.cs       |  2 +-
 src/gui/cairo/jumpsRunsEvolution.cs   | 10 ++--
 src/gui/cairo/jumpsWeightFVProfile.cs | 13 +++--
 src/gui/cairo/raceAnalyzer.cs         | 10 ++--
 src/gui/cairo/xy.cs                   | 30 +++++------
 src/gui/eventExecute.cs               | 43 +++++++++-------
 8 files changed, 145 insertions(+), 116 deletions(-)
---
diff --git a/src/gui/cairo/bars.cs b/src/gui/cairo/bars.cs
index 0ac8e198b..c434a7501 100644
--- a/src/gui/cairo/bars.cs
+++ b/src/gui/cairo/bars.cs
@@ -71,9 +71,10 @@ public abstract class CairoBars : CairoGeneric
        protected void initGraph(string font, double widthPercent1, bool clearDrawingArea)
        {
                this.font = font;
-               LogB.Information("Font: " + font);
+               //LogB.Information("Font: " + font);
 
-               outerMargins = 18; //blank space outside the axis. //on plotBars is used only for X
+               leftMargin = 26;
+               rightMargin = 9;
                topMargin = 12;
                bottomMargin = 9;
 
@@ -112,12 +113,12 @@ public abstract class CairoBars : CairoGeneric
        protected void paintAxis(int width)
        {
                g.LineWidth = width;
-               g.MoveTo(outerMargins, 2*topMargin);
-               g.LineTo(outerMargins, graphHeight - bottomMargin);
-               g.LineTo(graphWidth - outerMargins, graphHeight - bottomMargin);
+               g.MoveTo(leftMargin, 3*topMargin);
+               g.LineTo(leftMargin, graphHeight - bottomMargin);
+               g.LineTo(graphWidth - rightMargin, graphHeight - bottomMargin);
                g.Stroke ();
 
-               printText(2, topMargin, 0, textHeight, getYAxisLabel(), g, alignTypes.LEFT);
+               printText(2, 2*topMargin, 0, textHeight -2, getYAxisLabel(), g, alignTypes.LEFT);
                printXAxisText();
                g.Stroke ();
 
@@ -127,7 +128,7 @@ public abstract class CairoBars : CairoGeneric
        //this combined with paintVerticalGridLine is different on RaceAnalyzer
        protected virtual void printXAxisText()
        {
-               printText(graphWidth - Convert.ToInt32(outerMargins/2), graphHeight - 2*bottomMargin, 0, 
textHeight,
+               printText(graphWidth - Convert.ToInt32(leftMargin/2), graphHeight - 2*bottomMargin, 0, 
textHeight -2,
                                getXAxisLabel(), g, alignTypes.LEFT);
        }
 
@@ -149,34 +150,36 @@ public abstract class CairoBars : CairoGeneric
        //TODO: check if for one value this is /0
        protected override double calculatePaintX (double realX)
        {
-               return outerMargins + (realX - minX) * UtilAll.DivideSafe(
-                               graphWidth - 2*outerMargins,
+               return leftMargin + (realX - minX) * UtilAll.DivideSafe(
+                               graphWidth - (leftMargin + rightMargin),
                                maxX - minX);
         }
        protected override double calculatePaintY (double realY)
        {
-                return graphHeight - (topMargin + bottomMargin) - UtilAll.DivideSafe(
-                               (realY - minY) * (graphHeight - 2*(topMargin + bottomMargin)),
-                               //maxY - minY);
-                               //have 10% extra margin on the top (highest values will be 10% far from max 
of the graph)
-                               1.1*maxY - minY);
+                return graphHeight - (topMargin + bottomMargin) //graph ata area
+                       - UtilAll.DivideSafe(
+                               (realY - minY) * (graphHeight - (topMargin+bottomMargin)),
+                               //maxY - minY)
+                               //have 20% extra margin on the top (highest values will be this % far from 
max of the graph, needed also because text is above)
+                               1.2*maxY - minY)
+                       + topMargin;
         }
 
-       protected void printText (double x, double y, double heightUnused, int textH,
+       protected override void printText (double x, double y, double heightUnused, int textH,
                        string text, Cairo.Context g, alignTypes align)
        {
                g.SetFontSize(textH);
 
-               int moveToLeft = 0;
+               double moveToLeft = 0;
                if(align == alignTypes.CENTER || align == alignTypes.RIGHT)
                {
                        Cairo.TextExtents te;
                        te = g.TextExtents(text);
                        
                        if(align == alignTypes.CENTER)
-                               moveToLeft = Convert.ToInt32(te.Width/2);
+                               moveToLeft = te.Width/2;
                        else
-                               moveToLeft = Convert.ToInt32(te.Width);
+                               moveToLeft = te.Width;
                }
 
                g.MoveTo(x - moveToLeft, y + textH/2);
@@ -258,14 +261,13 @@ public abstract class CairoBars : CairoGeneric
                return arr[minp];
        }
 
-       public int GetFontForBottomNames (List<Event> events, int longestWordSize)
+       public int GetFontForBottomNames (List<Event> events, string longestWord)
        {
-               // 1) set marginBetweenTexts to 1.1 character
+               // 1) set marginBetweenTexts to 1.0 character
                Cairo.TextExtents te = g.TextExtents("A");
-               double marginBetweenTexts = 1.1 * te.Width;
+               double marginBetweenTexts = 1.0 * te.Width;
 
-               // 2) create the longestWord to find its width
-               string longestWord = new string('A', longestWordSize);
+               // 2) find longestWord width
                te = g.TextExtents(longestWord);
 
                // 3) if longestWord * events.Count does not fit, iterate to find correct font size
@@ -285,10 +287,10 @@ public abstract class CairoBars : CairoGeneric
        {
                g.SetFontSize(fontHeight);
                Cairo.TextExtents te = g.TextExtents("A");
-               //LogB.Information(string.Format("GetBottomMarginForText, maxRows: {0}, fontHeight: {1}, 
result: {2}",
-               //                      maxRows, fontHeight, Convert.ToInt32(1.2 * te.Height * maxRows)));
+               LogB.Information(string.Format("GetBottomMarginForText, maxRows: {0}, fontHeight: {1}, 
result: {2}",
+                                       maxRows, fontHeight, Convert.ToInt32(1.3 * te.Height * maxRows)));
 
-               return Convert.ToInt32(1.2 * te.Height * maxRows);
+               return Convert.ToInt32(1.3 * te.Height * maxRows);
        }
 
        //TODO: at the moment we are not lowering decs, make resultsFontHeight and decs global variables
@@ -326,10 +328,19 @@ public abstract class CairoBars : CairoGeneric
                        int resultFontHeight, double barWidth, double yStartPointA)
        {
                int decs = 2; //can be 1 if need more space
-
                g.SetFontSize(resultFontHeight);
+
+               double maxLengthNumber = 9.99;
+               if(maxY >= 10)
+                       maxLengthNumber = 99.99;
+               if(maxY >= 100)
+                       maxLengthNumber = 999.99;
+               if(maxY >= 1000)
+                       maxLengthNumber = 9999.99;
+
                Cairo.TextExtents te;
-               te = g.TextExtents(Util.TrimDecimals(result,decs));
+               ///te = g.TextExtents(Util.TrimDecimals(result,decs));
+               te = g.TextExtents(maxLengthNumber.ToString());
 
                bool textAboveBar = true;
                /*
@@ -377,7 +388,7 @@ public abstract class CairoBars : CairoGeneric
 
        protected void writeTitleAtTop()
        {
-               printText(graphWidth/2 + outerMargins, textHeight/2, 0, textHeight,
+               printText(graphWidth/2 + leftMargin, textHeight/2, 0, textHeight+2,
                                title, g, alignTypes.CENTER);
        }
        /*
@@ -403,9 +414,9 @@ public abstract class CairoBars : CairoGeneric
                g.LineWidth = 1; //to allow to be shown the red arrows on jumpsWeightFVProfile
 
                if(niceAutoValues)
-                       paintGridNiceAutoValues (g, minX, maxX, minY, maxY, 5, gridType);
+                       paintGridNiceAutoValues (g, minX, maxX, minY, maxY, 5, gridType, textHeight -2);
                else
-                       paintGridInt (g, minX, maxX, minY, maxY, 1, gridType);
+                       paintGridInt (g, minX, maxX, minY, maxY, 1, gridType, textHeight -2);
        }
 
        public string YVariable {
@@ -458,21 +469,23 @@ public class CairoBars1Series : CairoBars
        protected override void plotBars ()
        {
                 //calculate separation between series and bar width
-                double distanceBetweenCols = Convert.ToInt32((graphWidth - 
2*outerMargins)*(1+.5)/point_l.Count) -
-                        Convert.ToInt32((graphWidth - 2*outerMargins)*(0+.5)/point_l.Count);
+                double distanceBetweenCols = Convert.ToInt32((graphWidth - 
(leftMargin+rightMargin))*(1+.5)/point_l.Count) -
+                        Convert.ToInt32((graphWidth - (leftMargin+rightMargin))*(0+.5)/point_l.Count);
 
                 double barWidth = Convert.ToInt32(.5*distanceBetweenCols);
                 double barDesplLeft = Convert.ToInt32(.5*barWidth);
                int resultFontHeight = getBarsResultFontHeight (barWidth*2);
+               LogB.Information("resultFontHeight: " + resultFontHeight.ToString());
 
                for(int i = 0; i < point_l.Count; i ++)
                {
                        PointF p = point_l[i];
 
-                       double x = (graphWidth - 2*outerMargins) * (p.X-.5)/point_l.Count - barDesplLeft + 
outerMargins;
+                       double x = (graphWidth - (leftMargin+rightMargin)) * (p.X-.5)/point_l.Count - 
barDesplLeft + leftMargin;
                        double y = calculatePaintY(p.Y);
 
                        drawRoundedRectangle (true, x, y, barWidth, graphHeight -y -bottomMargin, 4, g, 
colorSerieA);
+LogB.Information(string.Format("y: {0}, alto: {1}", y, graphHeight -y - bottomMargin));
                        plotResultOnBar(x + barWidth/2, y, graphHeight -bottomMargin, p.Y, resultFontHeight, 
barWidth, -1);
 
                        //print the type at bottom
@@ -499,10 +512,10 @@ public class CairoBars1Series : CairoBars
 
                 findPointMaximums();
 
-               g.SetFontSize(textHeight);// -2);
+               g.SetFontSize(textHeight);
                paintAxis(2);
                paintGrid(gridTypes.HORIZONTALLINES, true);
-               g.SetFontSize(textHeight);
+               //g.SetFontSize(textHeight);
 
                g.Color = black;
                plotBars ();
@@ -565,7 +578,7 @@ public class CairoBars2HSeries : CairoBars
        protected override void plotBars ()
        {
                 //calculate separation between series and bar width
-                double distanceBetweenCols = (graphWidth - 2*outerMargins)/maxX;
+                double distanceBetweenCols = (graphWidth - (leftMargin+rightMargin))/maxX;
 
                 double barWidth = .4*distanceBetweenCols;
                 double barDesplLeft = .5*barWidth;
@@ -587,7 +600,7 @@ public class CairoBars2HSeries : CairoBars
                                if(pB.Y > 0)
                                        adjustX = -2 * barDesplLeft -.5 * valueABSep;
 
-                               double x = (graphWidth - 2*outerMargins) * pA.X/maxX - barDesplLeft + adjustX 
+ outerMargins;
+                               double x = (graphWidth - (leftMargin+rightMargin)) * pA.X/maxX - barDesplLeft 
+ adjustX + leftMargin;
                                double y = calculatePaintY(pA.Y);
 
                                drawRoundedRectangle (true, x, y, barWidth, graphHeight -y 
-(topMargin+bottomMargin), 4, g, colorSerieA);
@@ -602,7 +615,7 @@ public class CairoBars2HSeries : CairoBars
                                if(pA.Y > 0)
                                        adjustX = .5 * valueABSep;
 
-                               double x = (graphWidth - 2*outerMargins) * pB.X/maxX - barDesplLeft + adjustX 
+ outerMargins;
+                               double x = (graphWidth - (leftMargin+rightMargin)) * pB.X/maxX - barDesplLeft 
+ adjustX + leftMargin;
                                double y = calculatePaintY(pB.Y);
 
                                drawRoundedRectangle (true, x, y, barWidth, graphHeight -y - 
(topMargin+bottomMargin), 4, g, colorSerieB);
@@ -612,7 +625,7 @@ public class CairoBars2HSeries : CairoBars
                                resultOnBarB_l.Add(new Point3F(0, 0, 0));
 
                        //print text at bottom
-                       printText( (graphWidth - 2*outerMargins) * pA.X/maxX + -barDesplLeft + outerMargins,
+                       printText( (graphWidth - (leftMargin+rightMargin)) * pA.X/maxX + -barDesplLeft + 
leftMargin,
                                        graphHeight -(topMargin+bottomMargin) + textHeight/2, 0, textHeight,
                                        names_l[i], g, alignTypes.CENTER);
                }
@@ -648,9 +661,11 @@ public class CairoBars2HSeries : CairoBars
 
                 findPointMaximums();
 
+               g.SetFontSize(textHeight);
                paintAxis(2);
+               //paintAxis(2, textHeight -2);
                paintGrid(gridTypes.HORIZONTALLINES, true);
-               g.SetFontSize(textHeight);
+               //g.SetFontSize(textHeight);
 
                g.Color = black;
                plotBars();
diff --git a/src/gui/cairo/generic.cs b/src/gui/cairo/generic.cs
index 156a38f4e..d29f4e0da 100644
--- a/src/gui/cairo/generic.cs
+++ b/src/gui/cairo/generic.cs
@@ -29,11 +29,13 @@ public abstract class CairoGeneric
        protected int graphHeight;
 
        //for all 4 sides
-       protected int outerMargins = 40; //blank space outside the axis.
-       protected int innerMargins = 30; //space between the axis and the real coordinates.
+       protected int outerMargin = 40; //blank space outside the axis.
+       protected int innerMargin = 30; //space between the axis and the real coordinates.
 
-       protected int topMargin = 20; //outerMargins/2;
-       protected int bottomMargin = 20; //outerMargins/2;
+       protected int leftMargin = 40;
+       protected int rightMargin = 40;
+       protected int topMargin = 40;
+       protected int bottomMargin = 40;
 
        protected string font;
        protected int textHeight = 12;
@@ -72,18 +74,18 @@ public abstract class CairoGeneric
        }
 
        protected enum alignTypes { LEFT, CENTER, RIGHT }
-       protected void printText (int x, int y, int height, int textHeight, string text, Cairo.Context g, 
alignTypes align)
+       protected virtual void printText (double x, double y, double height, int textHeight, string text, 
Cairo.Context g, alignTypes align)
        {
-               int moveToLeft = 0;
+               double moveToLeft = 0;
                if(align == alignTypes.CENTER || align == alignTypes.RIGHT)
                {
                        Cairo.TextExtents te;
                        te = g.TextExtents(text);
 
                        if(align == alignTypes.CENTER)
-                               moveToLeft = Convert.ToInt32(te.Width/2);
+                               moveToLeft = te.Width/2;
                        else
-                               moveToLeft = Convert.ToInt32(te.Width);
+                               moveToLeft = te.Width;
                }
 
                g.MoveTo( x - moveToLeft, ((y+y+height)/2) + textHeight/2 );
@@ -92,7 +94,7 @@ public abstract class CairoGeneric
 
        //TODO: fix if min == max (crashes)
        protected enum gridTypes { BOTH, HORIZONTALLINES, VERTICALLINES }
-       protected void paintGridNiceAutoValues (Cairo.Context g, double minX, double maxX, double minY, 
double maxY, int seps, gridTypes gridType)
+       protected void paintGridNiceAutoValues (Cairo.Context g, double minX, double maxX, double minY, 
double maxY, int seps, gridTypes gridType, int fontH)
        {
                var gridXTuple = getGridStepAndBoundaries ((decimal) minX, (decimal) maxX, seps);
                var gridYTuple = getGridStepAndBoundaries ((decimal) minY, (decimal) maxY, seps);
@@ -103,27 +105,27 @@ public abstract class CairoGeneric
                        for(double i = gridXTuple.Item1; i <= gridXTuple.Item2 ; i += gridXTuple.Item3)
                        {
                                int xtemp = Convert.ToInt32(calculatePaintX(i));
-                               if(xtemp <= outerMargins || xtemp >= graphWidth - outerMargins)
+                               if(xtemp <= leftMargin || xtemp >= graphWidth - rightMargin)
                                        continue;
 
-                               paintVerticalGridLine(g, xtemp, Util.TrimDecimals(i, 2));
+                               paintVerticalGridLine(g, xtemp, Util.TrimDecimals(i, 2), fontH);
                        }
 
                if(gridType != gridTypes.VERTICALLINES)
                        for(double i = gridYTuple.Item1; i <= gridYTuple.Item2 ; i += gridYTuple.Item3)
                        {
                                int ytemp = Convert.ToInt32(calculatePaintY(i));
-                               if(ytemp <= topMargin + bottomMargin || ytemp >= graphHeight - (topMargin + 
bottomMargin))
+                               if(ytemp <= topMargin || ytemp >= graphHeight -bottomMargin)
                                        continue;
 
-                               paintHorizontalGridLine(g, ytemp, Util.TrimDecimals(i, 2));
+                               paintHorizontalGridLine(g, ytemp, Util.TrimDecimals(i, 2), fontH);
                        }
                g.Stroke ();
                g.Restore();
        }
 
        //for a grid of integers
-       protected void paintGridInt (Cairo.Context g, double minX, double maxX, double minY, double maxY, int 
by, gridTypes gridType)
+       protected void paintGridInt (Cairo.Context g, double minX, double maxX, double minY, double maxY, int 
by, gridTypes gridType, int fontH)
        {
                g.Save();
                g.SetDash(new double[]{1, 2}, 0);
@@ -131,37 +133,39 @@ public abstract class CairoGeneric
                        for(double i = Math.Floor(minX); i <= Math.Ceiling(maxX) ; i += by)
                        {
                                int xtemp = Convert.ToInt32(calculatePaintX(i));
-                               if(xtemp <= outerMargins || xtemp >= graphWidth - outerMargins)
+                               if(xtemp <= leftMargin || xtemp >= graphWidth -rightMargin)
                                        continue;
 
-                               paintVerticalGridLine(g, xtemp, Util.TrimDecimals(i, 2));
+                               paintVerticalGridLine(g, xtemp, Util.TrimDecimals(i, 2), fontH);
                        }
 
                if(gridType != gridTypes.VERTICALLINES)
                        for(double i = Math.Floor(minX); i <= Math.Ceiling(maxY) ; i += by)
                        {
                                int ytemp = Convert.ToInt32(calculatePaintY(i));
-                               if(ytemp <= topMargin + bottomMargin || ytemp >= graphHeight - (topMargin + 
bottomMargin))
+                               if(ytemp <= topMargin || ytemp >= graphHeight -bottomMargin)
                                        continue;
 
-                               paintHorizontalGridLine(g, ytemp, Util.TrimDecimals(i, 2));
+                               paintHorizontalGridLine(g, ytemp, Util.TrimDecimals(i, 2), fontH);
                        }
                g.Stroke ();
                g.Restore();
        }
 
-       protected void paintHorizontalGridLine(Cairo.Context g, int ytemp, string text)
+       protected void paintHorizontalGridLine(Cairo.Context g, int ytemp, string text, int fontH)
        {
-               g.MoveTo(outerMargins, ytemp);
-               g.LineTo(graphWidth - outerMargins, ytemp);
-               printText(Convert.ToInt32(outerMargins/2), ytemp, 0, textHeight, text, g, alignTypes.CENTER);
+               g.MoveTo(leftMargin, ytemp);
+               g.LineTo(graphWidth - rightMargin, ytemp);
+               printText(leftMargin/2, ytemp, 0, fontH, text, g, alignTypes.CENTER);
+               LogB.Information("phgl fontH: " + fontH.ToString());
        }
        //this combined with printXAxisText is different on RaceAnalyzer
-       protected virtual void paintVerticalGridLine(Cairo.Context g, int xtemp, string text)
+       protected virtual void paintVerticalGridLine(Cairo.Context g, int xtemp, string text, int fontH)
        {
-               g.MoveTo(xtemp, graphHeight - (topMargin + bottomMargin));
-               g.LineTo(xtemp, (topMargin + bottomMargin));
-               printText(xtemp, graphHeight - bottomMargin, 0, textHeight, text, g, alignTypes.CENTER);
+               g.MoveTo(xtemp, topMargin);
+               g.LineTo(xtemp, graphHeight - bottomMargin);
+               printText(xtemp, graphHeight -(bottomMargin/2), 0, fontH, text, g, alignTypes.CENTER);
+               LogB.Information("pvgl fontH: " + fontH.ToString());
        }
 
        /*
diff --git a/src/gui/cairo/jumpsRjFatigue.cs b/src/gui/cairo/jumpsRjFatigue.cs
index d7fce3644..2ce240be4 100644
--- a/src/gui/cairo/jumpsRjFatigue.cs
+++ b/src/gui/cairo/jumpsRjFatigue.cs
@@ -157,7 +157,7 @@ public class JumpsRjFatigueGraph : CairoXY
                g.LineTo(xbp, yp + pointsRadius);
 
                printText(
-                               graphWidth - outerMargins,
+                               graphWidth - outerMargin,
                                Convert.ToInt32(yp),
                                0, textHeight, Util.TrimDecimals(y, 2), g, alignTypes.CENTER);
 
diff --git a/src/gui/cairo/jumpsRunsEvolution.cs b/src/gui/cairo/jumpsRunsEvolution.cs
index c6ba9e07c..4385cbc9b 100644
--- a/src/gui/cairo/jumpsRunsEvolution.cs
+++ b/src/gui/cairo/jumpsRunsEvolution.cs
@@ -78,12 +78,12 @@ public abstract class EvolutionGraph : CairoXY
                for(int year = Convert.ToInt32(Math.Floor(minX)) -1; year <= 
Convert.ToInt32(Math.Floor(maxX)); year ++)
                {
                        int xtemp = Convert.ToInt32(calculatePaintX(year));
-                       if( ! (xtemp < outerMargins || xtemp > graphWidth - outerMargins) )
+                       if( ! (xtemp < outerMargin || xtemp > graphWidth - outerMargin) )
                        {
                                if(paintMonths)
-                                       paintVerticalGridLine(g, xtemp, string.Format("{0} {1}", year, 
UtilDate.GetMonthName(0, true)));
+                                       paintVerticalGridLine(g, xtemp, string.Format("{0} {1}", year, 
UtilDate.GetMonthName(0, true)), textHeight);
                                else
-                                       paintVerticalGridLine(g, xtemp, year.ToString());
+                                       paintVerticalGridLine(g, xtemp, year.ToString(), textHeight);
                        }
 
                        if(! paintMonths)
@@ -100,10 +100,10 @@ public abstract class EvolutionGraph : CairoXY
                        {
                                LogB.Information(string.Format("year-month: {0}-{1}", year, month));
                                xtemp = Convert.ToInt32(calculatePaintX(year + month/12.0));
-                               if(xtemp < outerMargins || xtemp > graphWidth - outerMargins)
+                               if(xtemp < outerMargin || xtemp > graphWidth - outerMargin)
                                        continue;
 
-                               paintVerticalGridLine(g, xtemp, string.Format("{0} {1}", year, 
UtilDate.GetMonthName(month, true)));
+                               paintVerticalGridLine(g, xtemp, string.Format("{0} {1}", year, 
UtilDate.GetMonthName(month, true)), textHeight);
                        }
                }
 
diff --git a/src/gui/cairo/jumpsWeightFVProfile.cs b/src/gui/cairo/jumpsWeightFVProfile.cs
index 1c23b0be1..7ce15838f 100644
--- a/src/gui/cairo/jumpsWeightFVProfile.cs
+++ b/src/gui/cairo/jumpsWeightFVProfile.cs
@@ -75,12 +75,14 @@ public class JumpsWeightFVProfileGraph : CairoXY
                this.errorMessage = errorMessage;
                this.colorBackground = colorFromGdk(Config.ColorBackground); //but note if we are using 
system colors, this will not match
 
-               outerMargins = 50; //blank space outside the axis
-               topMargin = outerMargins/2;
-               bottomMargin = outerMargins/2;
+               outerMargin = 50; //blank space outside the axis
+               leftMargin = 50;
+               rightMargin = 50;
+               topMargin = 50;
+               bottomMargin = 50;
 
                if(showFullGraph)
-                       innerMargins = 0;
+                       innerMargin = 0;
 
                xVariable = speedStr;
                yVariable = forceStr;
@@ -138,6 +140,7 @@ public class JumpsWeightFVProfileGraph : CairoXY
 
                //findAbsoluteMaximums();
                paintGrid(gridTypes.BOTH, true);
+               LogB.Information("before paintAxis call , outerMargin: " + outerMargin);
                paintAxis();
 
                if(showFullGraph)
@@ -198,7 +201,7 @@ public class JumpsWeightFVProfileGraph : CairoXY
                double lineVertSpacing = 1;
 
                // first check if it fits at right, if does not fit reduce lineVertSpacing
-               if(Convert.ToInt32(graphHeight/2) + textHeight*2*(line+4) > graphHeight - outerMargins)
+               if(Convert.ToInt32(graphHeight/2) + textHeight*2*(line+4) > graphHeight - outerMargin)
                {
                        lineVertSpacing = .5;
                }
diff --git a/src/gui/cairo/raceAnalyzer.cs b/src/gui/cairo/raceAnalyzer.cs
index 63e5514e2..a37a6afb3 100644
--- a/src/gui/cairo/raceAnalyzer.cs
+++ b/src/gui/cairo/raceAnalyzer.cs
@@ -126,13 +126,13 @@ public class CairoGraphRaceAnalyzer : CairoXY
 
        protected override void printXAxisText()
        {
-               printText(graphWidth - outerMargins, graphHeight -Convert.ToInt32(.25 * outerMargins), 0, 
textHeight, getXAxisLabel(), g, alignTypes.CENTER);
+               printText(graphWidth - outerMargin, graphHeight -Convert.ToInt32(.25 * outerMargin), 0, 
textHeight, getXAxisLabel(), g, alignTypes.CENTER);
        }
-       protected override void paintVerticalGridLine(Cairo.Context g, int xtemp, string text)
+       protected override void paintVerticalGridLine(Cairo.Context g, int xtemp, string text, int fontH)
        {
-               g.MoveTo(xtemp, graphHeight - outerMargins);
-               g.LineTo(xtemp, outerMargins);
-               printText(xtemp, graphHeight -Convert.ToInt32(.75 * outerMargins), 0, textHeight, text, g, 
alignTypes.CENTER); //TODO: this only for raceAnalyzer
+               g.MoveTo(xtemp, graphHeight - outerMargin);
+               g.LineTo(xtemp, outerMargin);
+               printText(xtemp, graphHeight -Convert.ToInt32(.75 * outerMargin), 0, fontH, text, g, 
alignTypes.CENTER); //TODO: this only for raceAnalyzer
        }
 
        protected override void writeTitle()
diff --git a/src/gui/cairo/xy.cs b/src/gui/cairo/xy.cs
index 387521f05..0e291df39 100644
--- a/src/gui/cairo/xy.cs
+++ b/src/gui/cairo/xy.cs
@@ -121,10 +121,10 @@ public abstract class CairoXY : CairoGeneric
                this.font = font;
                LogB.Information("Font: " + font);
 
-               outerMargins = 40; //blank space outside the axis.
-               innerMargins = 30; //space between the axis and the real coordinates.
+               //outerMargin = 40; //blank space outside the axis.
+               //innerMargin = 30; //space between the axis and the real coordinates.
 
-               totalMargins = outerMargins + innerMargins;
+               totalMargins = outerMargin + innerMargin;
 
                //1 create context
                g = Gdk.CairoHelper.Create (area.GdkWindow);
@@ -339,18 +339,18 @@ public abstract class CairoXY : CairoGeneric
                g.LineWidth = 1; //to allow to be shown the red arrows on jumpsWeightFVProfile
 
                if(niceAutoValues)
-                       paintGridNiceAutoValues (g, minX, absoluteMaxX, minY, absoluteMaxY, 5, gridType);
+                       paintGridNiceAutoValues (g, minX, absoluteMaxX, minY, absoluteMaxY, 5, gridType, 
textHeight);
                else
-                       paintGridInt (g, minX, absoluteMaxX, minY, absoluteMaxY, 1, gridType);
+                       paintGridInt (g, minX, absoluteMaxX, minY, absoluteMaxY, 1, gridType, textHeight);
        }
 
        protected void paintAxis()
        {
-               g.MoveTo(outerMargins, outerMargins);
-               g.LineTo(outerMargins, graphHeight - outerMargins);
-               g.LineTo(graphWidth - outerMargins, graphHeight - outerMargins);
+               g.MoveTo(outerMargin, outerMargin);
+               g.LineTo(outerMargin, graphHeight - outerMargin);
+               g.LineTo(graphWidth - outerMargin, graphHeight - outerMargin);
                g.Stroke ();
-               printText(2, Convert.ToInt32(outerMargins/2), 0, textHeight, getYAxisLabel(), g, 
alignTypes.LEFT);
+               printText(2, Convert.ToInt32(outerMargin/2), 0, textHeight, getYAxisLabel(), g, 
alignTypes.LEFT);
                printXAxisText();
                g.Stroke ();
                g.LineWidth = 2;
@@ -359,7 +359,7 @@ public abstract class CairoXY : CairoGeneric
        //this combined with paintVerticalGridLine is different on RaceAnalyzer
        protected virtual void printXAxisText()
        {
-               printText(graphWidth - Convert.ToInt32(outerMargins/2), graphHeight - outerMargins, 0, 
textHeight, getXAxisLabel(), g, alignTypes.LEFT);
+               printText(graphWidth - Convert.ToInt32(outerMargin/2), graphHeight - outerMargin, 0, 
textHeight, getXAxisLabel(), g, alignTypes.LEFT);
        }
 
        protected string getXAxisLabel()
@@ -413,7 +413,7 @@ public abstract class CairoXY : CairoGeneric
                                ygraph = calculatePaintY(coefs[0] + coefs[1]*x + coefs[2]*Math.Pow(x,2));
 
                        // ---- do not plot line outer the axis ---->
-                       int om = outerMargins;
+                       int om = outerMargin;
 
                        // have a bit more distance
                        if(crossMarginType == predictedLineCrossMargins.CROSS)
@@ -525,9 +525,9 @@ public abstract class CairoXY : CairoGeneric
                //at axis
                g.Save();
                g.SetDash(new double[]{14, 6}, 0);
-               g.MoveTo(xgraph, graphHeight - outerMargins);
+               g.MoveTo(xgraph, graphHeight - outerMargin);
                g.LineTo(xgraph, ygraph);
-               g.LineTo(outerMargins, ygraph);
+               g.LineTo(outerMargin, ygraph);
                g.Stroke ();
                g.Restore();
 
@@ -595,8 +595,8 @@ public abstract class CairoXY : CairoGeneric
                // 2) exit if out of graph area
                LogB.Information(string.Format("graphX: {0}; graphY: {1}", graphX, graphY));
                if(
-                               graphX < outerMargins || graphX > graphWidth - outerMargins ||
-                               graphY < outerMargins || graphY > graphHeight - outerMargins )
+                               graphX < outerMargin || graphX > graphWidth - outerMargin ||
+                               graphY < outerMargin || graphY > graphHeight - outerMargin )
                        return;
 
                /* optional show real mouse click
diff --git a/src/gui/eventExecute.cs b/src/gui/eventExecute.cs
index 975c99198..5769aa9e1 100644
--- a/src/gui/eventExecute.cs
+++ b/src/gui/eventExecute.cs
@@ -1473,18 +1473,13 @@ public partial class ChronoJumpWindow
        {
                int longestWordSize = 0;
 
-string longestWord = "";
                foreach(Event ev in events)
                {
                        string [] textArray = ev.Description.Split(new char[] {' '});
                        foreach(string text in textArray)
-                       {
                                if(text.Length > longestWordSize)
-                               {
                                        longestWordSize = text.Length;
-longestWord = text;
-                               }
-                       }
+
                        //note jump type will be in one line
                        //if(ev.Description.Length > longestWordSize)
                        //              longestWordSize = ev.Description.Length;
@@ -1496,7 +1491,6 @@ longestWord = text;
                        if(ev.Simulated == -1 && event_execute_label_simulated.Length > longestWordSize)
                                longestWordSize = event_execute_label_simulated.Length;
                }
-LogB.Information("longestWord: " + longestWord);
 
                return longestWordSize;
        }
@@ -3226,14 +3220,14 @@ public abstract class CairoPaintBarsPre
        protected abstract void paintSpecific();
 
        //TODO: this is repeated on this file, think also if move it to gui/cairo/bars.cs
-       protected int calculateMaxRowsForText (List<Event> events, int longestWordSize, bool allJumps, bool 
runsPrintTime)
+       protected int calculateMaxRowsForTextCairo (List<Event> events, int longestWordSize, bool allJumps, 
bool runsPrintTime)
        {
                int maxRows = 0;
 
-LogB.Information("calculateMaxRowsForText");
+               //LogB.Information("calculateMaxRowsForText");
                foreach(Event ev in events)
                {
-LogB.Information("Event: " + ev.ToString());
+                       //LogB.Information("Event: " + ev.ToString());
                        int rows = 0;
                        if(allJumps)                    //to write the jump type (1st the jump type because 
it's only one row)
                                rows ++;
@@ -3265,14 +3259,16 @@ LogB.Information("Event: " + ev.ToString());
                        if(rows > maxRows)
                                maxRows = rows;
                }
+               //LogB.Information("maxRows: " + maxRows.ToString());
 
                return maxRows;
        }
 
        //TODO: need to add personName here
-       protected int findLongestWordSize (List<Event> events, bool allTypes, string simulatedLabel)
+       protected string findLongestWordCairo (List<Event> events, bool allTypes, string simulatedLabel)
        {
                int longestWordSize = 0;
+               string longestWord = ""; //debug
 
                foreach(Event ev in events)
                {
@@ -3280,19 +3276,30 @@ LogB.Information("Event: " + ev.ToString());
                        foreach(string text in textArray)
                        {
                                if(text.Length > longestWordSize)
+                               {
                                        longestWordSize = text.Length;
+                                       longestWord = text;
+                               }
                        }
 
                        //note jump type will be in one line
                        //TODO: check it in local user language (Catalog)
                        if(allTypes && ev.Type.Length > longestWordSize)
+                       {
                                longestWordSize = ev.Type.Length;
+                               longestWord = ev.Type;
+                       }
 
                        if(ev.Simulated == -1 && simulatedLabel.Length > longestWordSize)
+                       {
                                longestWordSize = simulatedLabel.Length;
+                               longestWord = simulatedLabel;
+                       }
                }
 
-               return longestWordSize;
+               LogB.Information("longestWord: " + longestWord);
+               //return longestWordSize;
+               return longestWord;
        }
 
        //person name or test type, or both
@@ -3568,10 +3575,10 @@ public class CairoPaintBarsPreRunSimple : CairoPaintBarsPre
                                eventGraphRunsStored.runsAtSQL[i].Description = ""; //to avoid showing 
description
                }
 
-               int longestWordSize = findLongestWordSize (events, eventGraphRunsStored.type == "", "(" + 
Catalog.GetString("Simulated") + ")"); // condition for "all runs"
-               int fontHeightForBottomNames = cbjt.GetFontForBottomNames (events, longestWordSize);
+               string longestWord = findLongestWordCairo (events, eventGraphRunsStored.type == "", "(" + 
Catalog.GetString("Simulated") + ")"); // condition for "all runs"
+               int fontHeightForBottomNames = cbjt.GetFontForBottomNames (events, longestWord);
 
-               int maxRowsForText = calculateMaxRowsForText (events, longestWordSize, 
eventGraphRunsStored.type == "", RunsShowTime); //also adds +1 if simulated
+               int maxRowsForText = calculateMaxRowsForTextCairo (events, longestWord.Length, 
eventGraphRunsStored.type == "", RunsShowTime); //also adds +1 if simulated
                int bottomMargin = cbjt.GetBottomMarginForText (maxRowsForText, fontHeightForBottomNames);
 
                LogB.Information(string.Format("fontHeightForBottomNames: {0}, bottomMargin: {1}", 
fontHeightForBottomNames, bottomMargin));
@@ -3582,10 +3589,10 @@ public class CairoPaintBarsPreRunSimple : CairoPaintBarsPre
                int countToDraw = eventGraphRunsStored.runsAtSQL.Count;
                foreach(Run run in eventGraphRunsStored.runsAtSQL)
                {
+                       // 1) Add data
                        point_l.Add(new PointF(countToDraw --, run.Distance/run.Time));
 
-                       //names_l.Add(Catalog.GetString(run.Type));
-
+                       // 2) Add bottom names
                        string typeRowString = "";
                        if (eventGraphRunsStored.type == "") //if "all runs" show run.Type
                                typeRowString = run.Type;
@@ -3600,7 +3607,7 @@ public class CairoPaintBarsPreRunSimple : CairoPaintBarsPre
                                                typeRowString,
                                                run.Description,
                                                thereIsASimulated, (run.Simulated == -1),
-                                               longestWordSize, maxRowsForText));
+                                               longestWord.Length, maxRowsForText));
                }
 
                cbjt.GraphDo(point_l, new List<PointF>(), names_l, fontHeightForBottomNames, bottomMargin, 
title);


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