Skip to content

Commit

Permalink
Fix issue chartjs#4441 - y-axis labels partially hidden due to restri…
Browse files Browse the repository at this point in the history
…ctive initial fitting. (chartjs#4942)

* 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
  • Loading branch information
jcopperfield authored and etimberg committed Nov 25, 2017
1 parent fc0fd43 commit 5928ed4
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/core/core.layoutService.js
Expand Up @@ -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;
}

Expand Down
30 changes: 30 additions & 0 deletions test/specs/core.layoutService.tests.js
Expand Up @@ -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']);
});
});
});

0 comments on commit 5928ed4

Please sign in to comment.