[chronojump] First implementation of CairoBarsGuideManage on



commit eb7359b46384f98a63cb2f7af7d67e63883f25c2
Author: Xavier de Blas <xaviblas gmail com>
Date:   Sat Aug 28 10:46:23 2021 +0200

    First implementation of CairoBarsGuideManage on

 src/gui/cairo/bars.cs   | 148 +++++++++++++++++++++++++++++++++++++++++++++---
 src/gui/eventExecute.cs |  14 ++++-
 2 files changed, 152 insertions(+), 10 deletions(-)
---
diff --git a/src/gui/cairo/bars.cs b/src/gui/cairo/bars.cs
index 6e59970a3..5b1a996c1 100644
--- a/src/gui/cairo/bars.cs
+++ b/src/gui/cairo/bars.cs
@@ -33,9 +33,11 @@ public abstract class CairoBars : CairoGeneric
        //protected string runType;
        protected string date;
        protected Cairo.Color colorSerieA;
+       protected CairoBarsGuideManage cairoBarsGuideManage;
+       protected bool usePersonGuides;
 
        protected Cairo.Context g;
-       protected int lineWidthDefault = 2;
+       protected int lineWidthDefault = 1; //was 2;
        protected string xVariable = "";
        protected string yVariable = "Height";
        protected string xUnits = "";
@@ -55,12 +57,134 @@ public abstract class CairoBars : CairoGeneric
        protected Cairo.Color yellow;
 
 
-       public virtual void GraphInit (string font)
+       public virtual void GraphInit (string font, bool usePersonGuides) //need to set rightMargin
        {
+               this.usePersonGuides = usePersonGuides;
+
                textHeight = 14;
                initGraph(font, 1); //.8 if writeTextAtRight
        }
 
+       public void PassGuidesData (CairoBarsGuideManage cairoBarsGuideManage)
+       {
+               this.cairoBarsGuideManage = cairoBarsGuideManage;
+       }
+
+       protected void drawGuides ()
+       {
+               //TODO: draw first the more bold, maybe create list in that order, to make the smaller be 
inside the bolder
+               //foreach(CairoBarsGuide cbg in cairoBarsGuideManage.L)
+               //      drawHorizontalGuide (cbg);
+
+               int xStart = 6;
+               if(usePersonGuides)
+               {
+                       drawGuidesPerson(xStart);
+                       xStart += (24 + 6);
+               }
+
+               drawGuidesGroup(xStart);
+       }
+       //TODO: mix both next methods, just use correct variables
+       protected void drawGuidesPerson (int xStart)
+       {
+               Cairo.ImageSurface imgSurface = new Cairo.ImageSurface(
+                               
"/home/xavier/informatica/progs_meus/chronojump/images/md/ic_person_outline_blue_24dp_1x.png");
+               g.SetSourceSurface (imgSurface, graphWidth -rightMargin +xStart, 
topMargin);//Convert.ToInt32(calculatePaintY(cbg.Y))-12);
+               g.Paint ();
+
+               double bottom = calculatePaintY(cairoBarsGuideManage.GetTipPersonMin());
+               double top = calculatePaintY(cairoBarsGuideManage.GetTipPersonMax());
+               if(top != bottom) // if only 1 value (top == bottom), do not draw the arrow
+                       plotArrowPassingGraphPoints (g, black,
+                                       graphWidth -rightMargin +xStart +12,
+                                       bottom,
+                                       graphWidth -rightMargin +xStart +12,
+                                       top,
+                                       false, true, 0);
+
+               //draw the avg
+               g.Color = black;
+               g.MoveTo(graphWidth - rightMargin +xStart +6, 
calculatePaintY(cairoBarsGuideManage.GetTipPersonAVG()));
+               g.LineTo(graphWidth - rightMargin +xStart +18, 
calculatePaintY(cairoBarsGuideManage.GetTipPersonAVG()));
+               g.Stroke ();
+       }
+       protected void drawGuidesGroup (int xStart)
+       {
+               Cairo.ImageSurface imgSurface = new Cairo.ImageSurface(
+                               
"/home/xavier/informatica/progs_meus/chronojump/images/md/image_group_outline.png");
+               g.SetSourceSurface (imgSurface, graphWidth -rightMargin +xStart, 
topMargin);//Convert.ToInt32(calculatePaintY(cbg.Y))-12);
+               g.Paint ();
+
+               double bottom = calculatePaintY(cairoBarsGuideManage.GetTipGroupMin());
+               double top = calculatePaintY(cairoBarsGuideManage.GetTipGroupMax());
+               if(top != bottom) // if only 1 value (top == bottom), do not draw the arrow
+                       plotArrowPassingGraphPoints (g, black,
+                                       graphWidth -rightMargin +xStart +12,
+                                       bottom,
+                                       graphWidth -rightMargin +xStart +12,
+                                       top,
+                                       false, true, 0);
+
+               //draw the avg
+               g.Color = black;
+               g.MoveTo(graphWidth - rightMargin +xStart +6, 
calculatePaintY(cairoBarsGuideManage.GetTipGroupAVG()));
+               g.LineTo(graphWidth - rightMargin +xStart +18, 
calculatePaintY(cairoBarsGuideManage.GetTipGroupAVG()));
+               g.Stroke ();
+       }
+
+       //TODO: move this to generic (if needed)
+       protected void drawHorizontalGuide (CairoBarsGuide cbg)
+       {
+               /*
+               g.LineWidth = cbg.Width;
+               g.Color = cbg.Color;
+
+               g.MoveTo(leftMargin, calculatePaintY(cbg.Y));
+               g.LineTo(graphWidth -rightMargin +cbg.ExtraRightDist, calculatePaintY(cbg.Y));
+               g.Stroke ();
+
+               g.LineWidth = lineWidthDefault;
+               g.Color = black;
+               */
+
+               /*
+               plotArrowPassingGraphPoints (g, cbg.Color,
+                               leftMargin, calculatePaintY(cbg.Y),
+                               graphWidth -rightMargin,// +cbg.ExtraRightDist,
+                               calculatePaintY(cbg.Y), true, 0);
+                               */
+
+               /*
+               plotArrowPassingGraphPoints (g, black, //black to not have overlapped lines with different 
colors
+                               graphWidth -rightMargin -10,// +cbg.ExtraRightDist,
+                               calculatePaintY(cbg.Y),
+                               graphWidth -rightMargin +10,
+                               calculatePaintY(cbg.Y),
+                               true, 0);
+
+               g.Color = cbg.Color;
+               printText(graphWidth -rightMargin +cbg.ExtraRightDist, calculatePaintY(cbg.Y),
+                               0, textHeight -2, cbg.C.ToString(), g, alignTypes.LEFT); //TODO: solve align 
of letter that has to be higher, when it is an icon this will not be a problem, just compare it with the arrow
+               g.Color = black;
+                               */
+               /*
+               Cairo.ImageSurface imgSurface;
+               if(cbg.Genum == CairoBarsGuide.GuideEnum.SESSION_MAX || cbg.Genum == 
CairoBarsGuide.GuideEnum.SESSION_AVG)
+               {
+                       imgSurface = new Cairo.ImageSurface(
+                                       
"/home/xavier/informatica/progs_meus/chronojump/images/md/image_group_outline.png");
+                       g.SetSourceSurface (imgSurface, graphWidth -rightMargin +32, 
12);//Convert.ToInt32(calculatePaintY(cbg.Y))-12);
+               } else {
+                       imgSurface = new Cairo.ImageSurface(
+                                       
"/home/xavier/informatica/progs_meus/chronojump/images/md/ic_person_outline_blue_24dp_1x.png");
+                       g.SetSourceSurface (imgSurface, graphWidth -rightMargin +4, 
12);//Convert.ToInt32(calculatePaintY(cbg.Y))-12);
+               }
+
+               g.Paint ();
+               */
+       }
+
        public abstract void GraphDo (List<PointF> pointA_l, List<PointF> pointB_l,
                        List<string> names_l, int fontHeightForBottomNames, int marginForBottomNames, string 
title);
 
@@ -74,7 +198,9 @@ public abstract class CairoBars : CairoGeneric
                //LogB.Information("Font: " + font);
 
                leftMargin = 26;
-               rightMargin = 9;
+               rightMargin = 42; //images are 24 px, separate 6 px from grapharea, and 12 px from 
absoluteright
+               if(usePersonGuides)
+                       rightMargin = 70;
                topMargin = 12;
                bottomMargin = 9;
 
@@ -108,7 +234,7 @@ public abstract class CairoBars : CairoGeneric
                yellow = colorFromRGB(255,238,102);
        }
 
-       protected abstract void findPointMaximums();
+       protected abstract void findMaximums(); //includes point and guides
 
        protected void paintAxis(int width)
        {
@@ -452,12 +578,15 @@ public class CairoBars1Series : CairoBars
                this.colorSerieA = colorFromGdk(Config.ColorBackground); //but note if we are using system 
colors, this will not match
        }
 
-       protected override void findPointMaximums()
+       protected override void findMaximums()
        {
                foreach(PointF p in point_l)
                        if(p.Y > maxY)
                                maxY = p.Y;
 
+               if(cairoBarsGuideManage != null  && cairoBarsGuideManage.GetMax() > maxY)
+                       maxY = cairoBarsGuideManage.GetMax();
+
                //points X start at 1
                minX = 0;
                maxX = point_l.Count + 1;
@@ -510,13 +639,16 @@ LogB.Information(string.Format("y: {0}, alto: {1}", y, graphHeight -y - bottomMa
                LogB.Information(string.Format("bottomMargin pre: {0}, marginForBottomNames: {1}", 
bottomMargin, marginForBottomNames));
                bottomMargin += marginForBottomNames;
 
-                findPointMaximums();
+                findMaximums();
 
                g.SetFontSize(textHeight);
                paintAxis(2);
                paintGrid(gridTypes.HORIZONTALLINES, true);
                //g.SetFontSize(textHeight);
 
+               if(cairoBarsGuideManage != null)
+                       drawGuides();
+
                g.Color = black;
                plotBars ();
 
@@ -557,7 +689,7 @@ public class CairoBars2HSeries : CairoBars
                colorSerieB = colorFromGdk(Config.ColorBackground); //but note if we are using system colors, 
this will not match
        }
 
-       protected override void findPointMaximums()
+       protected override void findMaximums()
        {
                foreach(PointF p in pointA_l)
                        if(p.Y > maxY)
@@ -659,7 +791,7 @@ public class CairoBars2HSeries : CairoBars
 
                bottomMargin += marginForBottomNames;
 
-                findPointMaximums();
+                findMaximums();
 
                g.SetFontSize(textHeight);
                paintAxis(2);
diff --git a/src/gui/eventExecute.cs b/src/gui/eventExecute.cs
index 73d734a7e..ea913c752 100644
--- a/src/gui/eventExecute.cs
+++ b/src/gui/eventExecute.cs
@@ -3541,7 +3541,7 @@ public class CairoPaintBarsPreJumpSimple : CairoPaintBarsPre
                        cbjt.YUnits = "s";
                }
 
-               cbjt.GraphInit(fontStr);
+               cbjt.GraphInit(fontStr, ! ShowPersonNames);     //usePersonGuides
                if(showBarA && showBarB) //Dja, Djna
                        cbjt.GraphDo (pointA_l, pointB_l, names_l, 14, 0, title);
                else if (showBarA) //takeOff, takeOffWeight
@@ -3580,7 +3580,7 @@ public class CairoPaintBarsPreRunSimple : CairoPaintBarsPre
                cbjt.YVariable = Catalog.GetString("Speed");
                cbjt.YUnits = "m/s";
 
-               cbjt.GraphInit(fontStr);
+               cbjt.GraphInit(fontStr, ! ShowPersonNames);     //usePersonGuides
 
                //TODO: add in parent class?
                List<Event> events = Run.RunListToEventList(eventGraphRunsStored.runsAtSQL);
@@ -3631,6 +3631,16 @@ public class CairoPaintBarsPreRunSimple : CairoPaintBarsPre
                                                longestWord.Length, maxRowsForText));
                }
 
+               cbjt.PassGuidesData (new CairoBarsGuideManage(
+                                       ! ShowPersonNames,      //usePersonGuides
+                                       eventGraphRunsStored.sessionMAXAtSQL,
+                                       eventGraphRunsStored.sessionAVGAtSQL,
+                                       eventGraphRunsStored.sessionMINAtSQL,
+                                       eventGraphRunsStored.personMAXAtSQLAllSessions,
+                                       eventGraphRunsStored.personMAXAtSQL,
+                                       eventGraphRunsStored.personAVGAtSQL,
+                                       eventGraphRunsStored.personMINAtSQL));
+
                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]