Skip to content

Commit

Permalink
Add support for multi-line xLabels
Browse files Browse the repository at this point in the history
  • Loading branch information
Timer committed Sep 14, 2015
1 parent 3c4b1f6 commit d1b411f
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/Chart.Core.js
Original file line number Diff line number Diff line change
Expand Up @@ -1574,9 +1574,15 @@
fit: function(){
// First we need the width of the yLabels, assuming the xLabels aren't rotated

// To support multi-line labels, we must compute the maximum number of stacked labels
var labelStackCount = 1;
each(this.xLabels, (function(label, index) {
labelStackCount = Math.max(labelStackCount, label.split('\n').length);
}), this);

// To do that we need the base line at the top and base of the chart, assuming there is no x label rotation
this.startPoint = (this.display) ? this.fontSize : 0;
this.endPoint = (this.display) ? this.height - (this.fontSize * 1.5) - 5 : this.height; // -5 to pad labels
this.endPoint = this.display ? this.height - (this.fontSize * labelStackCount + this.fontSize * 0.5) - 5 : this.height; // -5 to pad labels

// Apply padding settings to the start and end point.
this.startPoint += this.padding;
Expand Down Expand Up @@ -1809,7 +1815,9 @@
ctx.font = this.font;
ctx.textAlign = (isRotated) ? "right" : "center";
ctx.textBaseline = (isRotated) ? "middle" : "top";
ctx.fillText(label, 0, 0);
each(label.split('\n'), function(line, index2) {
ctx.fillText(line, 0, index2 * this.fontSize);
}, this);
ctx.restore();
},this);

Expand Down Expand Up @@ -2073,7 +2081,9 @@
ctx.textBaseline = 'top';
}

ctx.fillText(this.labels[i], pointLabelPosition.x, pointLabelPosition.y);
each(this.labels[i].split('\n'), function(line, index2) {
ctx.fillText(line, pointLabelPosition.x, pointLabelPosition.y + index2 * this.fontSize);
}, this);
}
}
}
Expand Down

0 comments on commit d1b411f

Please sign in to comment.