var helpers = Chart.helpers;
+ /**
+ * Helper method to merge the opacity into a color
+ */
+ function mergeOpacity(colorString, opacity) {
+ var color = helpers.color(colorString);
+ return color.alpha(opacity * color.alpha()).rgbaString();
+ }
+
Chart.defaults.global.tooltips = {
enabled: true,
custom: null,
}
}
- var bgColor = helpers.color(vm.backgroundColor);
- ctx.fillStyle = bgColor.alpha(opacity * bgColor.alpha()).rgbString();
+ ctx.fillStyle = mergeOpacity(vm.backgroundColor, opacity);
ctx.beginPath();
ctx.moveTo(x1, y1);
ctx.lineTo(x2, y2);
var titleFontSize = vm.titleFontSize,
titleSpacing = vm.titleSpacing;
- var titleFontColor = helpers.color(vm.titleFontColor);
- ctx.fillStyle = titleFontColor.alpha(opacity * titleFontColor.alpha()).rgbString();
+ ctx.fillStyle = mergeOpacity(vm.titleFontColor, opacity);
ctx.font = helpers.fontString(titleFontSize, vm._titleFontStyle, vm._titleFontFamily);
var i, len;
ctx.textAlign = vm._bodyAlign;
ctx.textBaseline = 'top';
- var bodyFontColor = helpers.color(vm.bodyFontColor);
- var textColor = bodyFontColor.alpha(opacity * bodyFontColor.alpha()).rgbString();
+ var textColor = mergeOpacity(vm.bodyFontColor, opacity);
ctx.fillStyle = textColor;
ctx.font = helpers.fontString(bodyFontSize, vm._bodyFontStyle, vm._bodyFontFamily);
// Draw Legend-like boxes if needed
if (drawColorBoxes) {
// Fill a white rect so that colours merge nicely if the opacity is < 1
- ctx.fillStyle = helpers.color(vm.legendColorBackground).alpha(opacity).rgbaString();
+ ctx.fillStyle = mergeOpacity(vm.legendColorBackground, opacity);
ctx.fillRect(pt.x, pt.y, bodyFontSize, bodyFontSize);
// Border
- ctx.strokeStyle = helpers.color(vm.labelColors[i].borderColor).alpha(opacity).rgbaString();
+ ctx.strokeStyle = mergeOpacity(vm.labelColors[i].borderColor, opacity);
ctx.strokeRect(pt.x, pt.y, bodyFontSize, bodyFontSize);
// Inner square
- ctx.fillStyle = helpers.color(vm.labelColors[i].backgroundColor).alpha(opacity).rgbaString();
+ ctx.fillStyle = mergeOpacity(vm.labelColors[i].backgroundColor, opacity);
ctx.fillRect(pt.x + 1, pt.y + 1, bodyFontSize - 2, bodyFontSize - 2);
ctx.fillStyle = textColor;
ctx.textAlign = vm._footerAlign;
ctx.textBaseline = 'top';
- var footerFontColor = helpers.color(vm.footerFontColor);
- ctx.fillStyle = footerFontColor.alpha(opacity * footerFontColor.alpha()).rgbString();
+ ctx.fillStyle = mergeOpacity(vm.footerFontColor, opacity);
ctx.font = helpers.fontString(vm.footerFontSize, vm._footerFontStyle, vm._footerFontFamily);
helpers.each(footer, function(line) {
}
},
drawBackground: function(pt, vm, ctx, tooltipSize, opacity) {
- var bgColor = helpers.color(vm.backgroundColor);
- ctx.fillStyle = bgColor.alpha(opacity * bgColor.alpha()).rgbString();
+ ctx.fillStyle = mergeOpacity(vm.backgroundColor, opacity);
helpers.drawRoundedRectangle(ctx, pt.x, pt.y, tooltipSize.width, tooltipSize.height, vm.cornerRadius);
ctx.fill();
},