]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Merge branch 'multiline_labels' of https://github.com/Tarqwyn/Chart.js into Tarqwyn...
authorEvert Timberg <evert.timberg+github@gmail.com>
Sun, 5 Jun 2016 00:48:26 +0000 (20:48 -0400)
committerEvert Timberg <evert.timberg+github@gmail.com>
Sun, 5 Jun 2016 00:48:26 +0000 (20:48 -0400)
Conflicts:
src/core/core.scale.js

1  2 
src/core/core.scale.js

index eea019911eed7f16382752a509ff80d429569c96,a3efa3f59b412d51197e6e47ebb78eff0c1ab570..171527b43fc18945bf42bc8341dafa6eab27f887
@@@ -315,24 -311,26 +316,26 @@@ module.exports = function(Chart) 
  
                        if (tickOpts.display && display) {
                                // Don't bother fitting the ticks if we are not showing them
 -                              if (!this.longestTextCache) {
 -                                      this.longestTextCache = {};
 +                              if (!me.longestTextCache) {
 +                                      me.longestTextCache = {};
                                }
  
 -                              var largestTextWidth = helpers.longestText(this.ctx, tickLabelFont, this.ticks, this.longestTextCache);
 -                              var tallestLabelHeightInLines = helpers.numberOfLabelLines(this.ticks);
 +                              var largestTextWidth = helpers.longestText(me.ctx, tickLabelFont, me.ticks, me.longestTextCache);
++                              var tallestLabelHeightInLines = helpers.numberOfLabelLines(me.ticks);
+                               var lineSpace = tickFontSize * 0.5;
  
                                if (isHorizontal) {
                                        // A horizontal axis is more constrained by the height.
 -                                      this.longestLabelWidth = largestTextWidth;
 +                                      me.longestLabelWidth = largestTextWidth;
  
                                        // TODO - improve this calculation
-                                       var labelHeight = (Math.sin(helpers.toRadians(me.labelRotation)) * me.longestLabelWidth) + 1.5 * tickFontSize;
 -                                      var labelHeight = (Math.sin(helpers.toRadians(this.labelRotation)) * this.longestLabelWidth) + (tickFontSize * tallestLabelHeightInLines) + (lineSpace * tallestLabelHeightInLines);
++                                      var labelHeight = (Math.sin(helpers.toRadians(me.labelRotation)) * me.longestLabelWidth) + (tickFontSize * tallestLabelHeightInLines) + (lineSpace * tallestLabelHeightInLines);
  
 -                                      minSize.height = Math.min(this.maxHeight, minSize.height + labelHeight);
 -                                      this.ctx.font = tickLabelFont;
 +                                      minSize.height = Math.min(me.maxHeight, minSize.height + labelHeight);
 +                                      me.ctx.font = tickLabelFont;
  
 -                                      var firstLabelWidth = this.ctx.measureText(this.ticks[0]).width;
 -                                      var lastLabelWidth = this.ctx.measureText(this.ticks[this.ticks.length - 1]).width;
 +                                      var firstLabelWidth = me.ctx.measureText(me.ticks[0]).width;
 +                                      var lastLabelWidth = me.ctx.measureText(me.ticks[me.ticks.length - 1]).width;
  
                                        // Ensure that our ticks are always inside the canvas. When rotated, ticks are right aligned which means that the right padding is dominated
                                        // by the font height
                                                context.font = tickLabelFont;
                                                context.textAlign = (isRotated) ? "right" : "center";
                                                context.textBaseline = (isRotated) ? "middle" : options.position === "top" ? "bottom" : "top";
-                                               context.fillText(label, 0, 0);
+                                       
+                                               if (helpers.isArray(label)) {
+                                                       for (var i = 0, y = 0; i < label.length; ++i) {
+                                                               // We just make sure the multiline element is a string here..
+                                                               context.fillText('' + label[i], 0, y);
+                                                               // apply same lineSpacing as calculated @ L#320
+                                                               y += (tickFontSize * 1.5);
+                                                       }
+                                               } else {
+                                                       context.fillText(label, 0, 0);
+                                               }
+                                               
                                                context.restore();
                                        }
 -                              }, this);
 +                              }, me);
  
                                if (scaleLabel.display) {
                                        // Draw the scale label