From e251d06ef5a73b94baecf338a26e10835d9177c4 Mon Sep 17 00:00:00 2001 From: Aman Sharma <20aman@gmail.com> Date: Fri, 15 Apr 2016 00:11:09 -0400 Subject: [PATCH] Using the dynamic absolute position of the canvas, even for relative placement of the chart This will work with both relative and absolute position for the chart and will apply the tooltips appropriately. I have tested in a normal context and then also using the chart in the second column of two column table i.e. in a different position on the screen. Without this, the default tooltips will appear at the same position no matter where the chart is placed. They will appear misplaced. The fix I have provided allows the tooltips to appear smoothly with the chart, no matter where it is placed on the web page. --- samples/line-customTooltips.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/samples/line-customTooltips.html b/samples/line-customTooltips.html index 50c106420..6695cb663 100644 --- a/samples/line-customTooltips.html +++ b/samples/line-customTooltips.html @@ -90,14 +90,14 @@ } } - var offset = $(this._chart.canvas).offset(); + var position = $(this._chart.canvas)[0].getBoundingClientRect(); // Display, position, and set styles for font tooltipEl.css({ opacity: 1, width: tooltip.width ? (tooltip.width + 'px') : 'auto', - left: offset.left + tooltip.x + 'px', - top: offset.top + top + 'px', + left: position.left + tooltip.x + 'px', + top: position.top + top + 'px', fontFamily: tooltip._fontFamily, fontSize: tooltip.fontSize, fontStyle: tooltip._fontStyle, -- 2.47.2