From: Evert Timberg Date: Sun, 5 Jun 2016 00:48:26 +0000 (-0400) Subject: Merge branch 'multiline_labels' of https://github.com/Tarqwyn/Chart.js into Tarqwyn... X-Git-Tag: v2.1.5~15^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=76d284c4aeefe81216b2e00f4e356f69f6d308b0;p=thirdparty%2FChart.js.git Merge branch 'multiline_labels' of https://github.com/Tarqwyn/Chart.js into Tarqwyn-multiline_labels Conflicts: src/core/core.scale.js --- 76d284c4aeefe81216b2e00f4e356f69f6d308b0 diff --cc src/core/core.scale.js index eea019911,a3efa3f59..171527b43 --- a/src/core/core.scale.js +++ b/src/core/core.scale.js @@@ -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 @@@ -602,10 -597,21 +605,21 @@@ 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