]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Remove minSize (#6910)
authorBen McCann <322311+benmccann@users.noreply.github.com>
Sun, 5 Jan 2020 15:42:42 +0000 (07:42 -0800)
committerEvert Timberg <evert.timberg+github@gmail.com>
Sun, 5 Jan 2020 15:42:42 +0000 (10:42 -0500)
docs/getting-started/v3-migration.md
src/core/core.scale.js
src/plugins/plugin.legend.js
src/plugins/plugin.title.js
test/specs/plugin.title.tests.js

index cf838818339a77321abe2d79aa9d7b0daca7f5b6..90615467433d24a8690fcdcdc2a8a5dfd1f46d73 100644 (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
index 0c8cbb646338e8077e3b62e67897440943550a55..ee51e113dc927ab54ef7216737f5d316de076103 100644 (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
                };
index c5509f76663cbab3537897d98b9aee2ac1710e09..76c975a70ea22117df3485f19a1b554953bad679 100644 (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]);
index 452f921e7a477f35ad0d6d5e467799a5197be4a0..3e2fa79efa087ab0914826d0630ba33569fdef84 100644 (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;
 
index 66b9d0f90941f7f0a9d949630d4100e9ca6a5ada..086add5583ada5352affc6acb69dc4a531d4d9e1 100644 (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([{