From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Sun, 5 Jan 2020 15:42:42 +0000 (-0800) Subject: Remove minSize (#6910) X-Git-Tag: v3.0.0-alpha~159 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ecb0784f0dbebc3df41234dcb0654b864aef3296;p=thirdparty%2FChart.js.git Remove minSize (#6910) --- diff --git a/docs/getting-started/v3-migration.md b/docs/getting-started/v3-migration.md index cf8388183..906154674 100644 --- a/docs/getting-started/v3-migration.md +++ b/docs/getting-started/v3-migration.md @@ -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 diff --git a/src/core/core.scale.js b/src/core/core.scale.js index 0c8cbb646..ee51e113d 100644 --- a/src/core/core.scale.js +++ b/src/core/core.scale.js @@ -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 }; diff --git a/src/plugins/plugin.legend.js b/src/plugins/plugin.legend.js index c5509f766..76c975a70 100644 --- a/src/plugins/plugin.legend.js +++ b/src/plugins/plugin.legend.js @@ -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]); diff --git a/src/plugins/plugin.title.js b/src/plugins/plugin.title.js index 452f921e7..3e2fa79ef 100644 --- a/src/plugins/plugin.title.js +++ b/src/plugins/plugin.title.js @@ -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; diff --git a/test/specs/plugin.title.tests.js b/test/specs/plugin.title.tests.js index 66b9d0f90..086add558 100644 --- a/test/specs/plugin.title.tests.js +++ b/test/specs/plugin.title.tests.js @@ -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([{