]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
When drawTicks is false, we should not include their size in the size of the axis 3192/head
authoretimberg <evert.timberg@gmail.com>
Tue, 23 Aug 2016 00:09:09 +0000 (20:09 -0400)
committeretimberg <evert.timberg@gmail.com>
Tue, 23 Aug 2016 00:09:09 +0000 (20:09 -0400)
src/core/core.scale.js
test/scale.linear.tests.js

index b3010874ce743ae10573343b811373b5dca26c57..11ec187f582dfa5a18ff48943ad5025fe3444ab7 100644 (file)
@@ -277,6 +277,7 @@ module.exports = function(Chart) {
                        var globalDefaults = Chart.defaults.global;
                        var tickOpts = opts.ticks;
                        var scaleLabelOpts = opts.scaleLabel;
+                       var gridLineOpts = opts.gridLines;
                        var display = opts.display;
                        var isHorizontal = me.isHorizontal();
 
@@ -294,12 +295,12 @@ module.exports = function(Chart) {
                                // subtract the margins to line up with the chartArea if we are a full width scale
                                minSize.width = me.isFullWidth() ? me.maxWidth - me.margins.left - me.margins.right : me.maxWidth;
                        } else {
-                               minSize.width = display ? tickMarkLength : 0;
+                               minSize.width = display && gridLineOpts.drawTicks ? tickMarkLength : 0;
                        }
 
                        // height
                        if (isHorizontal) {
-                               minSize.height = display ? tickMarkLength : 0;
+                               minSize.height = display && gridLineOpts.drawTicks ? tickMarkLength : 0;
                        } else {
                                minSize.height = me.maxHeight; // fill all the height
                        }
index 13d9f28da0681609abd8c2047f7709d3f8bb58d4..446aa3b8817755f803cb552af6a443d706c4807b 100644 (file)
@@ -730,4 +730,56 @@ describe('Linear Scale', function() {
                expect(yScale.width).toBeCloseToPixel(59);
                expect(yScale.height).toBeCloseToPixel(434);
        });
+
+       it('should fit correctly when display is turned off', function() {
+               chartInstance = window.acquireChart({
+                       type: 'line',
+                       data: {
+                               datasets: [{
+                                       xAxisID: 'xScale0',
+                                       yAxisID: 'yScale0',
+                                       data: [{
+                                               x: 10,
+                                               y: 100
+                                       }, {
+                                               x: -10,
+                                               y: 0
+                                       }, {
+                                               x: 0,
+                                               y: 0
+                                       }, {
+                                               x: 99,
+                                               y: 7
+                                       }]
+                               }],
+                       },
+                       options: {
+                               scales: {
+                                       xAxes: [{
+                                               id: 'xScale0',
+                                               type: 'linear',
+                                               position: 'bottom'
+                                       }],
+                                       yAxes: [{
+                                               id: 'yScale0',
+                                               type: 'linear',
+                                               gridLines: {
+                                                       drawTicks: false,
+                                                       drawBorder: false
+                                               },
+                                               scaleLabel: {
+                                                       display: false
+                                               },
+                                               ticks: {
+                                                       display: false,
+                                                       padding: 0
+                                               }
+                                       }]
+                               }
+                       }
+               });
+
+               var yScale = chartInstance.scales.yScale0;
+               expect(yScale.width).toBeCloseToPixel(0);
+       });
 });