Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show radial scale labels correctly when rotated #4682

Merged
merged 1 commit into from Aug 21, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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