From 276b171d93ec977ce6de869c7be808830e5e5fbb Mon Sep 17 00:00:00 2001 From: Toan Date: Thu, 11 Jun 2020 15:59:02 +0700 Subject: [PATCH] when window scroll, the tooltip show incorrect position coz its missing offset of window.scrollXY --- src/diagrams/class/classDb.js | 4 ++-- src/diagrams/flowchart/flowDb.js | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/diagrams/class/classDb.js b/src/diagrams/class/classDb.js index 70ac17a04..c605734c2 100644 --- a/src/diagrams/class/classDb.js +++ b/src/diagrams/class/classDb.js @@ -272,8 +272,8 @@ const setupToolTips = function(element) { .style('opacity', '.9'); tooltipElem .html(el.attr('title')) - .style('left', rect.left + (rect.right - rect.left) / 2 + 'px') - .style('top', rect.top - 14 + document.body.scrollTop + 'px'); + .style('left', window.scrollX + rect.left + (rect.right - rect.left) / 2 + 'px') + .style('top', window.scrollY + rect.top - 14 + document.body.scrollTop + 'px'); el.classed('hover', true); }) .on('mouseout', function() { diff --git a/src/diagrams/flowchart/flowDb.js b/src/diagrams/flowchart/flowDb.js index 723ea6f05..c2ed7392e 100644 --- a/src/diagrams/flowchart/flowDb.js +++ b/src/diagrams/flowchart/flowDb.js @@ -324,6 +324,7 @@ const setupToolTips = function(element) { .on('mouseover', function() { const el = select(this); const title = el.attr('title'); + // Dont try to draw a tooltip if no data is provided if (title === null) { return; @@ -336,8 +337,8 @@ const setupToolTips = function(element) { .style('opacity', '.9'); tooltipElem .html(el.attr('title')) - .style('left', rect.left + (rect.right - rect.left) / 2 + 'px') - .style('top', rect.top - 14 + document.body.scrollTop + 'px'); + .style('left', window.scrollX + rect.left + (rect.right - rect.left) / 2 + 'px') + .style('top', window.scrollY + rect.top - 14 + document.body.scrollTop + 'px'); el.classed('hover', true); }) .on('mouseout', function() {