[chronojump] Cairo XY grid with decimals



commit 83fb10d12f3e0df63f4cb26e0dbc7443efe5af84
Author: Xavier de Blas <xaviblas gmail com>
Date:   Thu Jan 2 16:39:19 2020 +0100

    Cairo XY grid with decimals

 src/gui/cairo/xy.cs | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
---
diff --git a/src/gui/cairo/xy.cs b/src/gui/cairo/xy.cs
index 9ad11ef2..cda8dbf8 100644
--- a/src/gui/cairo/xy.cs
+++ b/src/gui/cairo/xy.cs
@@ -290,8 +290,8 @@ public abstract class CairoXY
                        return;
 
                //show 5 steps positive, 5 negative (if possible)
-               int temp = Convert.ToInt32(Util.DivideSafe(max - min, seps));
-               int step = temp;
+               double temp = Util.DivideSafe(max - min, seps);
+               double step = temp;
 
                //to have values multiples than 10, 100 ...
                if(step <= 10)
@@ -319,18 +319,18 @@ public abstract class CairoXY
                        if(horiz)
                        {
                                int ytemp = Convert.ToInt32(calculatePaintY(i, graphHeight, max, min, 
outerMargins + innerMargins, outerMargins + innerMargins));
-                               if(ytemp < outerMargins)
+                               if(ytemp < outerMargins || ytemp > graphHeight - outerMargins)
                                        continue;
                                g.MoveTo(outerMargins, ytemp);
                                g.LineTo(graphWidth - outerMargins, ytemp);
-                               printText(Convert.ToInt32(outerMargins/2), ytemp, 0, textHeight, 
Convert.ToInt32(i).ToString(), g, true);
+                               printText(Convert.ToInt32(outerMargins/2), ytemp, 0, textHeight, 
Util.TrimDecimals(i, 1), g, true);
                        } else {
                                int xtemp = Convert.ToInt32(calculatePaintX(i, graphWidth, max, min, 
outerMargins + innerMargins, outerMargins + innerMargins));
-                               if(xtemp > graphWidth - outerMargins)
+                               if(xtemp < outerMargins || xtemp > graphWidth - outerMargins)
                                        continue;
                                g.MoveTo(xtemp, graphHeight - outerMargins);
                                g.LineTo(xtemp, outerMargins);
-                               printText(xtemp, graphHeight - Convert.ToInt32(outerMargins/2), 0, 
textHeight, Convert.ToInt32(i).ToString(), g, true);
+                               printText(xtemp, graphHeight - Convert.ToInt32(outerMargins/2), 0, 
textHeight, Util.TrimDecimals(i, 1), g, true);
                        }
                }
                g.Stroke ();


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