[chronojump] Jumps/races barcharts if no data shows resizing message on test and or person selected



commit f5b1c44d95438affdee1d8d06c48a00e9198b0e7
Author: Xavier de Blas <xaviblas gmail com>
Date:   Tue Oct 5 16:41:47 2021 +0200

    Jumps/races barcharts if no data shows resizing message on test and or person selected

 src/gui/cairo/bars.cs   | 31 ++++++++++++++++++++++++++++++-
 src/gui/eventExecute.cs | 44 ++++++++++++++++++++++++++++++++++----------
 2 files changed, 64 insertions(+), 11 deletions(-)
---
diff --git a/src/gui/cairo/bars.cs b/src/gui/cairo/bars.cs
index c8ce3d693..cfde65ed6 100644
--- a/src/gui/cairo/bars.cs
+++ b/src/gui/cairo/bars.cs
@@ -587,6 +587,32 @@ public abstract class CairoBars : CairoGeneric
                printText(graphWidth/2 + leftMargin, textHeight/2, 0, textHeight+2,
                                title, g, alignTypes.CENTER);
        }
+
+       protected void writeMessageAtCenter(string message)
+       {
+               Cairo.TextExtents te;
+               int messageTextHeight = textHeight +2;
+
+               do {
+                       g.SetFontSize(messageTextHeight);
+                       te = g.TextExtents(message);
+                       if(te.Width >= graphWidth)
+                               messageTextHeight --;
+               } while (te.Width >= graphWidth && messageTextHeight >= 1);
+
+               g.Color = yellow; //to have contrast with the bar
+               g.Rectangle(graphWidth/2 -te.Width/2 -1, graphHeight/2 -messageTextHeight -1,
+                               te.Width +2, te.Height+2);
+               g.Fill();
+
+               g.Color = black;
+               printText (graphWidth/2, graphHeight/2 -messageTextHeight/2,
+                               0, messageTextHeight,
+                               message, g, alignTypes.CENTER);
+
+               g.SetFontSize(textHeight -2);
+       }
+
        /*
        protected void writeTitleAtRight()
        {
@@ -637,7 +663,7 @@ public class CairoBars1Series : CairoBars
        private List<string> names_l;
 
        //constructor when there are no points
-       public CairoBars1Series (DrawingArea area, string font)
+       public CairoBars1Series (DrawingArea area, string font, string testsNotFoundMessage)
        {
                this.area = area;
 
@@ -645,6 +671,9 @@ public class CairoBars1Series : CairoBars
                LogB.Information("constructor without points, area.GdkWindow is null:" + (area.GdkWindow == 
null).ToString());
                initGraph(font, 1); //.8 to have title at right
 
+               if(testsNotFoundMessage != "")
+                       writeMessageAtCenter(testsNotFoundMessage);
+
                endGraphDisposing(g);
        }
 
diff --git a/src/gui/eventExecute.cs b/src/gui/eventExecute.cs
index b109d77aa..3c37a6ea3 100644
--- a/src/gui/eventExecute.cs
+++ b/src/gui/eventExecute.cs
@@ -2233,14 +2233,19 @@ public abstract class CairoPaintBarsPre
        protected DrawingArea darea;
        protected string fontStr;
        protected Constants.Modes mode;
+       protected string personName;
+       protected string testName;
        protected string title;
        protected int pDN; //preferences.digitsNumber
 
-       protected void initialize(DrawingArea darea, string fontStr, Constants.Modes mode, string title, int 
pDN)
+       protected void initialize(DrawingArea darea, string fontStr, Constants.Modes mode,
+                       string personName, string testName, string title, int pDN)
        {
                this.darea = darea;
                this.fontStr = fontStr;
                this.mode = mode;
+               this.personName = personName;
+               this.testName = testName;
                this.title = title;
                this.pDN = pDN;
        }
@@ -2277,7 +2282,7 @@ public abstract class CairoPaintBarsPre
        protected void blankScreen (DrawingArea darea, string fontStr)
        {
                try {
-                       new CairoBars1Series (darea, fontStr);
+                       new CairoBars1Series (darea, fontStr, "");
                } catch {
                        LogB.Information("saved crash at with cairo paint (blank screen)");
                }
@@ -2294,7 +2299,7 @@ public abstract class CairoPaintBarsPre
                if(! haveDataToPlot())
                {
                        try {
-                               new CairoBars1Series (darea, fontStr);
+                               new CairoBars1Series (darea, fontStr, testsNotFound());
                        } catch {
                                LogB.Information("saved crash at with cairo paint");
                        }
@@ -2304,11 +2309,30 @@ public abstract class CairoPaintBarsPre
                paintSpecific();
        }
 
+       protected virtual string testsNotFound ()
+       {
+               if(personName != "")
+               {
+                       if(testName != "")
+                               return string.Format(Catalog.GetString("{0} has not run any {1} test in this 
session."),
+                                               personName, testName);
+                       else
+                               return string.Format(Catalog.GetString("{0} has not run any test in this 
session."),
+                                               personName);
+               } else {
+                       if(testName != "")
+                               return string.Format(Catalog.GetString("There are no {0} tests in this 
session."),
+                                               testName);
+                       else
+                               return Catalog.GetString("No tests in this session.");
+               }
+       }
+
        protected abstract bool storeCreated ();
        protected abstract bool haveDataToPlot ();
        protected abstract void paintSpecific();
 
-       protected string generateTitle (string personName, string testName)
+       protected string generateTitle ()
        {
                string titleStr = "";
                string sep = "";
@@ -2555,7 +2579,7 @@ public class CairoPaintBarsPreJumpSimple : CairoPaintBarsPre
 {
        public CairoPaintBarsPreJumpSimple (DrawingArea darea, string fontStr, Constants.Modes mode, string 
personName, string testName, int pDN)
        {
-               initialize (darea, fontStr, mode, generateTitle(personName, testName), pDN);
+               initialize (darea, fontStr, mode, personName, testName, generateTitle(), pDN);
        }
 
        public override void StoreEventGraphJumps (PrepareEventGraphJumpSimple eventGraph)
@@ -2714,7 +2738,7 @@ public class CairoPaintBarsPreJumpReactive : CairoPaintBarsPre
 {
        public CairoPaintBarsPreJumpReactive (DrawingArea darea, string fontStr, Constants.Modes mode, string 
personName, string testName, int pDN)
        {
-               initialize (darea, fontStr, mode, generateTitle(personName, testName), pDN);
+               initialize (darea, fontStr, mode, personName, testName, generateTitle(), pDN);
        }
 
        public override void StoreEventGraphJumpsRj (PrepareEventGraphJumpReactive eventGraph)
@@ -2837,7 +2861,7 @@ public class CairoPaintBarsPreRunSimple : CairoPaintBarsPre
 {
        public CairoPaintBarsPreRunSimple (DrawingArea darea, string fontStr, Constants.Modes mode, string 
personName, string testName, int pDN)
        {
-               initialize (darea, fontStr, mode, generateTitle(personName, testName), pDN);
+               initialize (darea, fontStr, mode, personName, testName, generateTitle(), pDN);
        }
 
        public override void StoreEventGraphRuns (PrepareEventGraphRunSimple eventGraph)
@@ -2935,7 +2959,7 @@ public class CairoPaintBarsPreRunInterval : CairoPaintBarsPre
 {
        public CairoPaintBarsPreRunInterval (DrawingArea darea, string fontStr, Constants.Modes mode, string 
personName, string testName, int pDN)
        {
-               initialize (darea, fontStr, mode, generateTitle(personName, testName), pDN);
+               initialize (darea, fontStr, mode, personName, testName, generateTitle(), pDN);
        }
 
        public override void StoreEventGraphRunsInterval (PrepareEventGraphRunInterval eventGraph)
@@ -3057,7 +3081,7 @@ public class CairoPaintBarsPreJumpReactiveRealtimeCapture : CairoPaintBarsPre
                        Constants.Modes mode, string personName, string testName, int pDN,// bool 
heightPreferred,
                        double lastTv, double lastTc, string tvString, string tcString)
        {
-               initialize (darea, fontStr, mode, Catalog.GetString("Last test:") + " " + 
generateTitle(personName, testName), pDN);
+               initialize (darea, fontStr, mode, personName, testName, Catalog.GetString("Last test:") + " " 
+ generateTitle(), pDN);
 
                this.lastTv = lastTv;
                this.lastTc = lastTc;
@@ -3182,7 +3206,7 @@ public class CairoPaintBarsPreRunIntervalRealtimeCapture : CairoPaintBarsPre
                        bool isRelative,
                        double lastDistance, double lastTime, string timesString, string distancesString)
        {
-               initialize (darea, fontStr, mode, Catalog.GetString("Last test:") + " " + 
generateTitle(personName, testName), pDN);
+               initialize (darea, fontStr, mode, personName, testName, Catalog.GetString("Last test:") + " " 
+ generateTitle(), pDN);
 
                this.lastDistance = lastDistance;
                this.lastTime = lastTime;


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