]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Refactor tooltip draw function to extract drawBackground method
authorMickael Jeanroy <mickael.jeanroy@gmail.com>
Tue, 4 Oct 2016 15:08:55 +0000 (17:08 +0200)
committerEvert Timberg <evert.timberg+github@gmail.com>
Tue, 4 Oct 2016 18:10:56 +0000 (14:10 -0400)
See issue #3416.

src/core/core.tooltip.js

index 1c9a1fdb1bb1aece4d18f9a66bcef04d7b82fae4..54f9f49f5f777e44a061c17e06341c17daa25b0d 100755 (executable)
@@ -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;
@@ -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);