]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Updating to use the absolute position even if the chart canvas element is having... 2255/head
authorAman Sharma <20aman@gmail.com>
Wed, 13 Apr 2016 18:34:26 +0000 (14:34 -0400)
committerAman Sharma <20aman@gmail.com>
Wed, 13 Apr 2016 18:34:26 +0000 (14:34 -0400)
This will work with both relative and absolute position for the chart

samples/pie-customTooltips.html

index 732317de464398d4daf99ce623d460f0d1349696..97d79d0f6d6aed3e0050d9633a3a382ba70cf69e 100644 (file)
             top = tooltip.y + tooltip.caretHeight + tooltip.caretPadding;
         }
 
+        //Function to find absolution position of the element and not just it's relative position
+        function getPosition (element) {
+            var top = 0, left = 0;
+            do {
+                top += element.offsetTop || 0;
+                left += element.offsetLeft || 0;
+                element = element.offsetParent;
+            } while (element);
+
+            return {
+                top: top,
+                left: left
+            };
+        };
+
+        //Finding absolute position of the chart canvas
+        var position = getPosition(tooltip.chart.canvas)
+        
         // Display, position, and set styles for font
         tooltipEl.css({
             opacity: 1,
-            left: tooltip.chart.canvas.offsetLeft + tooltip.x + 'px',
-            top: tooltip.chart.canvas.offsetTop + top + 'px',
+            left: position.left + tooltip.x + 'px',
+            top: position.top + top + 'px',
             fontFamily: tooltip.fontFamily,
             fontSize: tooltip.fontSize,
             fontStyle: tooltip.fontStyle,