]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Fix issue #4441 - y-axis labels partially hidden due to restrictive initial fitting...
authorjcopperfield <33193571+jcopperfield@users.noreply.github.com>
Sat, 25 Nov 2017 13:28:57 +0000 (14:28 +0100)
committerEvert Timberg <evert.timberg+github@gmail.com>
Sat, 25 Nov 2017 13:28:57 +0000 (08:28 -0500)
* Fix issue 4441:
 - y-axis labels partially hidden due to restrictive initial fitting.

* Add regression test to linear scale

* Moved regression test from linear scale to core layout service

src/core/core.layoutService.js
test/specs/core.layoutService.tests.js

index 5649f113dc234241836581c52df5006995a8f091..df28f974eb1110e15c4045d31ee2991a68ab8df1 100644 (file)
@@ -194,7 +194,7 @@ module.exports = function(Chart) {
                                        minSize = box.update(box.fullWidth ? chartWidth : maxChartAreaWidth, horizontalBoxHeight);
                                        maxChartAreaHeight -= minSize.height;
                                } else {
-                                       minSize = box.update(verticalBoxWidth, chartAreaHeight);
+                                       minSize = box.update(verticalBoxWidth, maxChartAreaHeight);
                                        maxChartAreaWidth -= minSize.width;
                                }
 
index b3d57642666ba207979a2a0e4802fe8bbf33a104..a8673971b064704981060ebec506e8250b1ebfa1 100644 (file)
@@ -550,4 +550,34 @@ describe('Test the layout service', function() {
                        expect(isOrderCorrect).toBe(true);
                });
        });
+
+       describe('box sizing', function() {
+               it('should correctly compute y-axis width to fit labels', function() {
+                       var chart = window.acquireChart({
+                               type: 'bar',
+                               data: {
+                                       labels: ['tick 1', 'tick 2', 'tick 3', 'tick 4', 'tick 5'],
+                                       datasets: [{
+                                               data: [0, 2.25, 1.5, 1.25, 2.5]
+                                       }],
+                               },
+                               options: {
+                                       legend: {
+                                               display: false,
+                                       },
+                               },
+                       }, {
+                               canvas: {
+                                       height: 256,
+                                       width: 256
+                               }
+                       });
+                       var yAxis = chart.scales['y-axis-0'];
+
+                       // issue #4441: y-axis labels partially hidden.
+                       // minimum horizontal space required to fit labels
+                       expect(yAxis.width).toBeCloseToPixel(33);
+                       expect(yAxis.ticks).toEqual(['2.5', '2.0', '1.5', '1.0', '0.5', '0']);
+               });
+       });
 });