top = me.top,
left = me.left,
bottom = me.bottom,
- right = me.right;
+ right = me.right,
+ maxWidth;
ctx.fillStyle = valueOrDefault(opts.fontColor, globalDefaults.defaultFontColor); // render in correct colour
ctx.font = titleFont;
if (me.isHorizontal()) {
titleX = left + ((right - left) / 2); // midpoint of the width
titleY = top + ((bottom - top) / 2); // midpoint of the height
+ maxWidth = right - left;
} else {
titleX = opts.position === 'left' ? left + (fontSize / 2) : right - (fontSize / 2);
titleY = top + ((bottom - top) / 2);
+ maxWidth = bottom - top;
rotation = Math.PI * (opts.position === 'left' ? -0.5 : 0.5);
}
ctx.rotate(rotation);
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
- ctx.fillText(opts.text, 0, 0);
+ ctx.fillText(opts.text, 0, 0, maxWidth);
ctx.restore();
}
}