Skip to content

Commit

Permalink
When a radial scale is rotated using the startAngle option, the tick …
Browse files Browse the repository at this point in the history
…labels did not appear in the correct places. (chartjs#4682)
  • Loading branch information
etimberg authored and yofreke committed Dec 30, 2017
1 parent 108b637 commit 3bbdbcf
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/scales/scale.radialLinear.js
Expand Up @@ -473,6 +473,7 @@ module.exports = function(Chart) {

if (opts.display) {
var ctx = me.ctx;
var startAngle = this.getIndexAngle(0);

// Tick Font
var tickFontSize = valueOrDefault(tickOpts.fontSize, globalDefaults.defaultFontSize);
Expand All @@ -484,7 +485,6 @@ module.exports = function(Chart) {
// Don't draw a centre value (if it is minimum)
if (index > 0 || tickOpts.reverse) {
var yCenterOffset = me.getDistanceFromCenterForValue(me.ticksAsNumbers[index]);
var yHeight = me.yCenter - yCenterOffset;

// Draw circular lines around the scale
if (gridLineOpts.display && index !== 0) {
Expand All @@ -495,12 +495,16 @@ module.exports = function(Chart) {
var tickFontColor = valueOrDefault(tickOpts.fontColor, globalDefaults.defaultFontColor);
ctx.font = tickLabelFont;

ctx.save();
ctx.translate(me.xCenter, me.yCenter);
ctx.rotate(startAngle);

if (tickOpts.showLabelBackdrop) {
var labelWidth = ctx.measureText(label).width;
ctx.fillStyle = tickOpts.backdropColor;
ctx.fillRect(
me.xCenter - labelWidth / 2 - tickOpts.backdropPaddingX,
yHeight - tickFontSize / 2 - tickOpts.backdropPaddingY,
-labelWidth / 2 - tickOpts.backdropPaddingX,
-yCenterOffset - tickFontSize / 2 - tickOpts.backdropPaddingY,
labelWidth + tickOpts.backdropPaddingX * 2,
tickFontSize + tickOpts.backdropPaddingY * 2
);
Expand All @@ -509,7 +513,8 @@ module.exports = function(Chart) {
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
ctx.fillStyle = tickFontColor;
ctx.fillText(label, me.xCenter, yHeight);
ctx.fillText(label, 0, -yCenterOffset);
ctx.restore();
}
}
});
Expand Down

0 comments on commit 3bbdbcf

Please sign in to comment.