Remove minSize (#6910)

This commit is contained in:
Ben McCann 2020-01-05 07:42:42 -08:00 committed by Evert Timberg
parent c9fa553fb2
commit ecb0784f0d
5 changed files with 40 additions and 58 deletions

View File

@ -96,6 +96,7 @@ Animation system was completely rewritten in Chart.js v3. Each property can now
* `helpers.roundedRect`
* `helpers.scaleMerge`
* `helpers.where`
* `ILayoutItem.minSize`
* `IPlugin.afterScaleUpdate`. Use `afterLayout` instead
* `Line.calculatePointY`
* `Scale.getRightValue`
@ -185,3 +186,7 @@ Animation system was completely rewritten in Chart.js v3. Each property can now
#### Interactions
* Interaction mode methods now return an array of objects containing the `element`, `datasetIndex`, and `index`
#### Layout
* `ILayoutItem.update` no longer has a return value

View File

@ -435,6 +435,7 @@ class Scale extends Element {
me.beforeUpdate();
// Absorb the master measurements
// TODO: make some of these variables private
me.maxWidth = maxWidth;
me.maxHeight = maxHeight;
me.margins = helpers.extend({
@ -500,10 +501,6 @@ class Scale extends Element {
// IMPORTANT: after this point, we consider that `this.ticks` will NEVER change!
me.afterUpdate();
// TODO(v3): remove minSize as a public property and return value from all layout boxes. It is unused
// make maxWidth and maxHeight private
return me.minSize;
}
/**
@ -657,7 +654,7 @@ class Scale extends Element {
fit() {
var me = this;
// Reset
var minSize = me.minSize = {
var minSize = {
width: 0,
height: 0
};

View File

@ -142,8 +142,6 @@ class Legend extends Element {
me.afterFit();
//
me.afterUpdate();
return me.minSize;
}
afterUpdate() {}
@ -175,7 +173,7 @@ class Legend extends Element {
me.paddingBottom = 0;
// Reset minSize
me.minSize = {
me._minSize = {
width: 0,
height: 0
};
@ -225,7 +223,7 @@ class Legend extends Element {
// Reset hit boxes
var hitboxes = me.legendHitBoxes = [];
var minSize = me.minSize;
var minSize = me._minSize;
var isHorizontal = me.isHorizontal();
if (isHorizontal) {
@ -342,7 +340,7 @@ class Legend extends Element {
return;
}
var rtlHelper = getRtlHelper(opts.rtl, me.left, me.minSize.width);
var rtlHelper = getRtlHelper(opts.rtl, me.left, me._minSize.width);
var ctx = me.ctx;
var fontColor = valueOrDefault(labelOpts.fontColor, defaults.fontColor);
var labelFont = helpers.options._parseFont(labelOpts);
@ -455,18 +453,18 @@ class Legend extends Element {
var x = cursor.x;
var y = cursor.y;
rtlHelper.setWidth(me.minSize.width);
rtlHelper.setWidth(me._minSize.width);
// Use (me.left + me.minSize.width) and (me.top + me.minSize.height)
// Use (me.left + me._minSize.width) and (me.top + me._minSize.height)
// instead of me.right and me.bottom because me.width and me.height
// may have been changed since me.minSize was calculated
// may have been changed since me._minSize was calculated
if (isHorizontal) {
if (i > 0 && x + width + labelOpts.padding > me.left + me.minSize.width) {
if (i > 0 && x + width + labelOpts.padding > me.left + me._minSize.width) {
y = cursor.y += itemHeight;
cursor.line++;
x = cursor.x = me.left + alignmentOffset(legendWidth, lineWidths[cursor.line]);
}
} else if (i > 0 && y + itemHeight > me.top + me.minSize.height) {
} else if (i > 0 && y + itemHeight > me.top + me._minSize.height) {
x = cursor.x = x + me.columnWidths[cursor.line] + labelOpts.padding;
cursor.line++;
y = cursor.y = me.top + alignmentOffset(legendHeight, columnHeights[cursor.line]);

View File

@ -59,8 +59,6 @@ class Title extends Element {
//
me.afterUpdate();
return me.minSize;
}
afterUpdate() {}
@ -82,12 +80,6 @@ class Title extends Element {
me.top = 0;
me.bottom = me.height;
}
// Reset minSize
me.minSize = {
width: 0,
height: 0
};
}
afterSetDimensions() {}
@ -103,7 +95,7 @@ class Title extends Element {
fit() {
var me = this;
var opts = me.options;
var minSize = me.minSize = {};
var minSize = {};
var isHorizontal = me.isHorizontal();
var lineCount, textSize;

View File

@ -26,22 +26,18 @@ describe('Title block tests', function() {
options: options
});
var minSize = title.update(400, 200);
title.update(400, 200);
expect(minSize).toEqual({
width: 0,
height: 0
});
expect(title.width).toEqual(0);
expect(title.height).toEqual(0);
// Now we have a height since we display
title.options.display = true;
minSize = title.update(400, 200);
title.update(400, 200);
expect(minSize).toEqual({
width: 400,
height: 34.4
});
expect(title.width).toEqual(400);
expect(title.height).toEqual(34.4);
});
it('should update correctly when vertical', function() {
@ -56,22 +52,18 @@ describe('Title block tests', function() {
options: options
});
var minSize = title.update(200, 400);
title.update(200, 400);
expect(minSize).toEqual({
width: 0,
height: 0
});
expect(title.width).toEqual(0);
expect(title.height).toEqual(0);
// Now we have a height since we display
title.options.display = true;
minSize = title.update(200, 400);
title.update(200, 400);
expect(minSize).toEqual({
width: 34.4,
height: 400
});
expect(title.width).toEqual(34.4);
expect(title.height).toEqual(400);
});
it('should have the correct size when there are multiple lines of text', function() {
@ -88,12 +80,10 @@ describe('Title block tests', function() {
options: options
});
var minSize = title.update(200, 400);
title.update(200, 400);
expect(minSize).toEqual({
width: 56,
height: 400
});
expect(title.width).toEqual(56);
expect(title.height).toEqual(400);
});
it('should draw correctly horizontally', function() {
@ -117,11 +107,11 @@ describe('Title block tests', function() {
// Now we have a height since we display
title.options.display = true;
var minSize = title.update(400, 200);
title.update(400, 200);
title.top = 50;
title.left = 100;
title.bottom = title.top + minSize.height;
title.right = title.left + minSize.width;
title.bottom = title.top + title.height;
title.right = title.left + title.width;
title.draw();
expect(context.getCalls()).toEqual([{
@ -170,11 +160,11 @@ describe('Title block tests', function() {
// Now we have a height since we display
title.options.display = true;
var minSize = title.update(200, 400);
title.update(200, 400);
title.top = 50;
title.left = 100;
title.bottom = title.top + minSize.height;
title.right = title.left + minSize.width;
title.bottom = title.top + title.height;
title.right = title.left + title.width;
title.draw();
expect(context.getCalls()).toEqual([{
@ -206,11 +196,11 @@ describe('Title block tests', function() {
// Reset call tracker
context.resetCalls();
minSize = title.update(200, 400);
title.update(200, 400);
title.top = 50;
title.left = 100;
title.bottom = title.top + minSize.height;
title.right = title.left + minSize.width;
title.bottom = title.top + title.height;
title.right = title.left + title.width;
title.draw();
expect(context.getCalls()).toEqual([{