Skip to content

Commit

Permalink
Refactor tooltip draw function to extract drawBackground method
Browse files Browse the repository at this point in the history
See issue #3416.
  • Loading branch information
mjeanroy authored and etimberg committed Oct 4, 2016
1 parent 365bdbb commit b64cab0
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/core/core.tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,12 @@ module.exports = function(Chart) {
});
}
},
drawBackground: function(pt, vm, ctx, tooltipSize, opacity) {
var bgColor = helpers.color(vm.backgroundColor);
ctx.fillStyle = bgColor.alpha(opacity * bgColor.alpha()).rgbString();
helpers.drawRoundedRectangle(ctx, pt.x, pt.y, tooltipSize.width, tooltipSize.height, vm.cornerRadius);
ctx.fill();
},
draw: function() {
var ctx = this._chart.ctx;
var vm = this._view;
Expand All @@ -689,10 +695,7 @@ module.exports = function(Chart) {

if (this._options.enabled) {
// Draw Background
var bgColor = helpers.color(vm.backgroundColor);
ctx.fillStyle = bgColor.alpha(opacity * bgColor.alpha()).rgbString();
helpers.drawRoundedRectangle(ctx, pt.x, pt.y, tooltipSize.width, tooltipSize.height, vm.cornerRadius);
ctx.fill();
this.drawBackground(pt, vm, ctx, tooltipSize, opacity);

// Draw Caret
this.drawCaret(pt, tooltipSize, opacity);
Expand Down

0 comments on commit b64cab0

Please sign in to comment.