]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Improve drawing when title is placed below legend boxes
authoretimberg <evert.timberg@gmail.com>
Tue, 24 Nov 2015 03:12:34 +0000 (22:12 -0500)
committeretimberg <evert.timberg@gmail.com>
Tue, 24 Nov 2015 03:12:34 +0000 (22:12 -0500)
src/core/core.legend.js

index ab6943e89c0777a0066a54adfd4f5923889f031d..f4d6fab4d8090362d45088502dbb8320d778ab9f 100644 (file)
                                if (this.isHorizontal()) {
 
                                        // Title Spacing if on top
-                                       if (this.options.title.display && this.options.title.position == 'top') {
-                                               cursor.y += this.options.title.fontSize + (this.options.title.padding * 2);
+                                       if (this.options.title.display) {
+                                               if (this.options.title.position === 'top') {
+                                                       cursor.y += this.options.title.fontSize + (this.options.title.padding * 2);
+                                               } else {
+                                                       // bottom
+                                                       cursor.y += this.options.labels.padding;
+                                               }
                                        }
 
                                        // Labels
 
                                                var textWidth = ctx.measureText(label).width;
                                                var width = this.options.labels.boxWidth + (this.options.labels.fontSize / 2) + textWidth;
+                                               
                                                if (cursor.x + width >= this.width) {
                                                        cursor.y += this.options.labels.fontSize + (this.options.labels.padding);
                                                        cursor.line++;
                                        }, this);
 
                                        // Title Spacing if on bottom
-                                       if (this.options.title.display && this.options.title.position == 'bottom') {
+                                       if (this.options.title.display && this.options.title.position === 'bottom') {
                                                cursor.y += this.options.title.fontSize + (this.options.title.padding * 2);
                                        }
 
                                                ctx.font = helpers.fontString(this.options.title.fontSize, this.options.title.fontStyle, this.options.title.fontFamily);
 
                                                var titleX = this.left + ((this.right - this.left) / 2); // midpoint of the width
-                                               var titleY = this.options.position == 'bottom' ? this.bottom - (this.options.title.fontSize / 2) - this.options.title.padding : this.top + (this.options.title.fontSize / 2) + this.options.title.padding;
+                                               var titleY = this.options.title.position == 'bottom' ? this.bottom - (this.options.title.fontSize / 2) - this.options.title.padding : this.top + (this.options.title.fontSize / 2) + this.options.title.padding;
 
                                                ctx.fillText(this.options.title.text, titleX, titleY);
                                        }