fix #7749 - horizontal line graph improvements
authorAlan <alan@roojs.com>
Thu, 3 Aug 2023 08:01:31 +0000 (16:01 +0800)
committerAlan <alan@roojs.com>
Thu, 3 Aug 2023 08:01:31 +0000 (16:01 +0800)
g.bar.horizontal.js

index 6b82ca4..bf1e438 100644 (file)
@@ -58,6 +58,7 @@ Roo = typeof(Roo) != 'undefined' ? Roo:  (imports ? imports.seed.Roo.Roo: {});
             leftAxisWidth = 0,
             leftAxisLabels = opts.leftaxislabels || [];
             leftAxisFontSize = opts.leftaxisfontsize || 16,
+            rightPadding = 50;
             bottomAxisHeight = 0,
             bottomAxisStep = opts.bottomaxisstep || 10;
             bottomAxisFontSize = opts.bottomaxisfontsize || 16,
@@ -81,10 +82,21 @@ Roo = typeof(Roo) != 'undefined' ? Roo:  (imports ? imports.seed.Roo.Roo: {});
             }
         }
 
+        var step = max / bottomAxisStep;
+        var factor = 1;
+
+        if(step > 10) {
+            if(step % 10 != 0) {
+                factor = 10;
+            }
+        }
+
+        max = Math.ceil(step / factor) * factor * bottomAxisStep;
+
         // background
         paper.rect(0, 0, width, height).attr({ stroke: "none", fill: background });
 
-        var barWidth = (width - leftAxisWidth); // maximum width of bar
+        var barWidth = (width - leftAxisWidth - rightPadding); // maximum width of bar
         var barHeight = (height - bottomAxisHeight) / (len * (100 + gutter) + gutter) * 100;
         var barGutter = barHeight * (gutter / 100);
 
@@ -94,7 +106,7 @@ Roo = typeof(Roo) != 'undefined' ? Roo:  (imports ? imports.seed.Roo.Roo: {});
                 paper,
                 leftAxisWidth,
                 height - bottomAxisHeight,
-                width - leftAxisWidth,
+                barWidth,
                 max,
                 bottomAxisStep,
                 bottomAxisHeight,
@@ -160,12 +172,13 @@ Roo = typeof(Roo) != 'undefined' ? Roo:  (imports ? imports.seed.Roo.Roo: {});
 
     MHBarchart.prototype.bottomAxis = function (paper, x, y, length, max, steps, axisHeight, axisFont, axisFontSize, axisFontWeight, axisFontColor)
     {
+
         var path = ["M", x, y, "l", length, 0],
             text = paper.set(),
             d = Math.ceil(max / steps),
             dl = length / steps;
 
-        for(var i = 0; i < steps; i++) {
+        for(var i = 0; i <= steps; i++) {
             paper.text(x + i * dl, y + axisHeight / 2, i * d).attr({ 
                 "font-size": axisFontSize,
                 "font-family": axisFont,