* The z index for the border of a scale is now configurable instead of being 1 higher as the grid z index.
* Linear scales now add and subtracts `5%` of the max value to the range if the min and max are the same instead of `1`.
* If the tooltip callback returns `undefined`, then the default callback will be used.
+* `maintainAspectRatio` respects container height.
#### Type changes
* The order of the `ChartMeta` parameters have been changed from `<Element, DatasetElement, Type>` to `<Type, Element, DatasetElement>`.
// If the canvas has width, but no height, default to aspectRatio of 2 (canvas default)
height = round1(width / 2);
}
+
+ if (aspectRatio && height > containerSize.height) {
+ height = containerSize.height;
+ width = round1(Math.floor(height * aspectRatio));
+ }
+
return {
width,
height
done();
});
canvas.parentNode.style.width = '455px';
+ canvas.parentNode.style.height = '455px';
});
});
wrapper.style.width = '450px';
});
- it('should not resize the canvas when parent height changes', function(done) {
+ it('should maintain aspect ratio when parent height changes', function(done) {
var chart = acquireChart({
options: {
responsive: true,
waitForResize(chart, function() {
expect(chart).toBeChartOfSize({
- dw: 320, dh: 160,
- rw: 320, rh: 160,
+ dw: 300, dh: 150,
+ rw: 300, rh: 150,
});
done();
done();
});
chart.canvas.parentNode.style.width = '400px';
+ chart.canvas.parentNode.style.height = '400px';
});
it ('should notify initially disabled plugin in correct order', function() {
expect(nativePosition).toEqual({x: chartPosition.x, y: chartPosition.y});
});
});
+
+ it('should respect aspect ratio and container width', () => {
+ const container = document.createElement('div');
+ container.style.width = '200px';
+ container.style.height = '500px';
+
+ document.body.appendChild(container);
+
+ const target = document.createElement('div');
+ target.style.width = '500px';
+ target.style.height = '500px';
+ container.appendChild(target);
+
+ expect(helpers.getMaximumSize(target, 200, 500, 1)).toEqual(jasmine.objectContaining({width: 200, height: 200}));
+
+ document.body.removeChild(container);
+ });
+
+ it('should respect aspect ratio and container height', () => {
+ const container = document.createElement('div');
+ container.style.width = '500px';
+ container.style.height = '200px';
+
+ document.body.appendChild(container);
+
+ const target = document.createElement('div');
+ target.style.width = '500px';
+ target.style.height = '500px';
+ container.appendChild(target);
+
+ expect(helpers.getMaximumSize(target, 500, 200, 1)).toEqual(jasmine.objectContaining({width: 200, height: 200}));
+
+ document.body.removeChild(container);
+ });
});
});
describe('config.options.responsive: true (maintainAspectRatio: true)', function() {
- it('should fill parent width and use aspect ratio to calculate height', function() {
+ it('should fit parent using aspect ratio to calculate size', function() {
var chart = acquireChart({
options: {
responsive: true,
});
expect(chart).toBeChartOfSize({
- dw: 300, dh: 490,
- rw: 300, rh: 490,
+ dw: 214, dh: 350,
+ rw: 214, rh: 350,
});
});
});