[chronojump] Much better code for CairoBars1Series X, and .7 between bars. Easier to change ratios. Maybe future



commit 2ee88acbf562d1d38edf7cfcacee0a51f0209452
Author: Xavier de Blas <xaviblas gmail com>
Date:   Thu Mar 31 11:17:02 2022 +0200

    Much better code for CairoBars1Series X, and .7 between bars. Easier to change ratios. Maybe future on 
preferences.

 src/gui/cairo/bars.cs | 35 ++++++++++++++++++++++++++++++-----
 1 file changed, 30 insertions(+), 5 deletions(-)
---
diff --git a/src/gui/cairo/bars.cs b/src/gui/cairo/bars.cs
index 75f6bdb36..912790d64 100644
--- a/src/gui/cairo/bars.cs
+++ b/src/gui/cairo/bars.cs
@@ -1046,11 +1046,32 @@ public class CairoBars1Series : CairoBars
        protected override void plotBars ()
        {
                 //calculate separation between series and bar width
-                double distanceBetweenCols = Convert.ToInt32((graphWidth - 
(leftMargin+rightMargin))*(1+.5)/barMain_l.Count) -
-                        Convert.ToInt32((graphWidth - (leftMargin+rightMargin))*(0+.5)/barMain_l.Count);
+               /*
+                  | LM |graphWidthUsable| RM |
+                  | LM |  __   __   __  | RM |
+                  | LM | |  | |  | |  | | RM |
+                  | LM | |  | |  | |  | | RM |
+                  | LM |s|  |b|  |b|  |s| RM |
+
+                  LM, RM: Left Margin, Right margin
+                  s: sideWidthRatio (here .5)
+                  b: spaceBetweenBarsRatio (here .5)
+                */
+               double graphWidthUsable = graphWidth -(leftMargin+rightMargin);
+               double barWidthRatio = 1; //barWidth will be 1 respect the following two objects:
+               double sideWidthRatio = .5; //at left of the bars have the space of .5 barWidth, same for the 
right
+               if(type == Type.ENCODER && barMain_l.Count > 1) //on encoder margins are shown to draw the 
mice, and just a bit more
+                       sideWidthRatio = 0.25;
+
+               double spaceBetweenBarsRatio = .7;
+               /*
+                  divide graphWidhtUsable by total objects (bars, leftrightspace, spacesbetweenbars)
+                  for 3 bars on ratios 1, .5, .5, this will be 5
+                  */
+               double barWidth = UtilAll.DivideSafe(graphWidthUsable,
+                       barMain_l.Count * barWidthRatio + 2*sideWidthRatio + (barMain_l.Count-1) * 
spaceBetweenBarsRatio);
+               double distanceBetweenCols = barWidth * spaceBetweenBarsRatio;
 
-                barWidth = Convert.ToInt32(.5*distanceBetweenCols);
-                double barDesplLeft = Convert.ToInt32(.5*barWidth);
                resultFontHeight = getBarsResultFontHeight (barWidth*1.5); //*1.5 because there is space at 
left and right
                LogB.Information("resultFontHeight: " + resultFontHeight.ToString());
 
@@ -1058,7 +1079,11 @@ public class CairoBars1Series : CairoBars
                {
                        PointF p = barMain_l[i];
 
-                       double x = (graphWidth - (leftMargin+rightMargin)) * (p.X-.5)/barMain_l.Count - 
barDesplLeft + leftMargin;
+                       double spacesBetweenBars = 0;
+                       if(i >= 1)
+                               spacesBetweenBars = i*distanceBetweenCols;
+
+                       double x = leftMargin + sideWidthRatio*barWidth + i*barWidth + spacesBetweenBars;
                        double y = calculatePaintY(p.Y);
 
                        Cairo.Color barColor = colorSerieA;


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