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

[radar] Handling of Point Label Color as Array #5153

Closed
wants to merge 6 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 37 additions & 5 deletions src/scales/scale.radialLinear.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,15 +267,47 @@ module.exports = function(Chart) {
var pointLabelPosition = scale.getPointPosition(i, outerDistance + 5);

// Keep this in loop since we may support array properties here
var pointLabelFontColor = valueOrDefault(pointLabelOpts.fontColor, globalDefaults.defaultFontColor);
ctx.font = plFont.font;
ctx.fillStyle = pointLabelFontColor;

var angleRadians = scale.getIndexAngle(i);
var angle = helpers.toDegrees(angleRadians);
ctx.textAlign = getTextAlignForAngle(angle);
adjustPointPositionForLabelHeight(angle, scale._pointLabelSizes[i], pointLabelPosition);
fillText(ctx, scale.pointLabels[i] || '', pointLabelPosition, plFont.size);

// Point Label Color
var pointLabelFontColor = null;
if (pointLabelOpts.fontColor) {
// handle scale.pointLabels[i] as string or array combined with pointLabelFontColor as string or array or none given.
if (helpers.isArray(scale.pointLabels[i])) {
var yOffset = 0;
for (var x = 0; x < scale.pointLabels[i].length; x++) {
if (helpers.isArray(pointLabelOpts.fontColor)) {
pointLabelFontColor = valueOrDefault(pointLabelOpts.fontColor[x], globalDefaults.defaultFontColor);
} else {
pointLabelFontColor = valueOrDefault(pointLabelOpts.fontColor, globalDefaults.defaultFontColor);
}
var pointLabelPositionNew = helpers.clone(pointLabelPosition);
pointLabelPositionNew.y += yOffset;
adjustPointPositionForLabelHeight(angle, scale._pointLabelSizes[i], pointLabelPositionNew);
ctx.fillStyle = pointLabelFontColor;
fillText(ctx, scale.pointLabels[i][x] || '', pointLabelPositionNew, plFont.size);
// Extra 3px for some label spacing
yOffset += plFont.size + 3;
}
} else {
if (helpers.isArray(pointLabelOpts.fontColor)) {
pointLabelFontColor = valueOrDefault(pointLabelOpts.fontColor[0], globalDefaults.defaultFontColor);
} else {
pointLabelFontColor = valueOrDefault(pointLabelOpts.fontColor, globalDefaults.defaultFontColor);
}
adjustPointPositionForLabelHeight(angle, scale._pointLabelSizes[i], pointLabelPosition);
ctx.fillStyle = pointLabelFontColor;
fillText(ctx, scale.pointLabels[i] || '', pointLabelPosition, plFont.size);
}
} else {
pointLabelFontColor = valueOrDefault(pointLabelOpts.fontColor, globalDefaults.defaultFontColor);
adjustPointPositionForLabelHeight(angle, scale._pointLabelSizes[i], pointLabelPosition);
ctx.fillStyle = pointLabelFontColor;
fillText(ctx, scale.pointLabels[i] || '', pointLabelPosition, plFont.size);
}
}
}
}
Expand Down