From 3658c486911c51b7fc76d8b986dfa70ab0e9c483 Mon Sep 17 00:00:00 2001 From: Othmane Bentaleb Date: Thu, 15 Feb 2024 18:07:32 +0100 Subject: [PATCH 1/2] fix: tooltip pointer position in hovermode x --- src/components/fx/hover.js | 38 +++++++++++++------------------------- 1 file changed, 13 insertions(+), 25 deletions(-) diff --git a/src/components/fx/hover.js b/src/components/fx/hover.js index 59642856e86..33c657d6981 100644 --- a/src/components/fx/hover.js +++ b/src/components/fx/hover.js @@ -999,35 +999,23 @@ function createHoverText(hoverData, opts) { var halfWidth = tbb.width / 2 + HOVERTEXTPAD; + var tooltipMidX = lx; if(lx < halfWidth) { - lx = halfWidth; - - lpath.attr('d', 'M-' + (halfWidth - HOVERARROWSIZE) + ',0' + - 'L-' + (halfWidth - HOVERARROWSIZE * 2) + ',' + topsign + HOVERARROWSIZE + - 'H' + (halfWidth) + - 'v' + topsign + (HOVERTEXTPAD * 2 + tbb.height) + - 'H-' + halfWidth + - 'V' + topsign + HOVERARROWSIZE + - 'Z'); + tooltipMidX = halfWidth; } else if(lx > (fullLayout.width - halfWidth)) { - lx = fullLayout.width - halfWidth; - - lpath.attr('d', 'M' + (halfWidth - HOVERARROWSIZE) + ',0' + - 'L' + halfWidth + ',' + topsign + HOVERARROWSIZE + - 'v' + topsign + (HOVERTEXTPAD * 2 + tbb.height) + - 'H-' + halfWidth + - 'V' + topsign + HOVERARROWSIZE + - 'H' + (halfWidth - HOVERARROWSIZE * 2) + 'Z'); - } else { - lpath.attr('d', 'M0,0' + - 'L' + HOVERARROWSIZE + ',' + topsign + HOVERARROWSIZE + - 'H' + (halfWidth) + - 'v' + topsign + (HOVERTEXTPAD * 2 + tbb.height) + - 'H-' + (halfWidth) + - 'V' + topsign + HOVERARROWSIZE + - 'H-' + HOVERARROWSIZE + 'Z'); + tooltipMidX = fullLayout.width - halfWidth; } + lpath.attr('d', 'M' + (lx - tooltipMidX) + ',0' + + 'L' + (lx - tooltipMidX + HOVERARROWSIZE) + ',' + topsign + HOVERARROWSIZE + + 'H' + (halfWidth) + + 'v' + topsign + (HOVERTEXTPAD * 2 + tbb.height) + + 'H-' + halfWidth + + 'V' + topsign + HOVERARROWSIZE + + 'H' + (lx - tooltipMidX - HOVERARROWSIZE) + + 'Z'); + + lx = tooltipMidX; commonLabelRect.minX = lx - halfWidth; commonLabelRect.maxX = lx + halfWidth; if(xa.side === 'top') { From a1ddd19049abe1cc98ded0a8a486e73eda8af719 Mon Sep 17 00:00:00 2001 From: Othmane BENTALEB Date: Mon, 26 Feb 2024 19:41:56 +0100 Subject: [PATCH 2/2] review feedbacks --- draftlogs/6900_fix.md | 1 + src/components/fx/hover.js | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) create mode 100644 draftlogs/6900_fix.md diff --git a/draftlogs/6900_fix.md b/draftlogs/6900_fix.md new file mode 100644 index 00000000000..098e9e06ec6 --- /dev/null +++ b/draftlogs/6900_fix.md @@ -0,0 +1 @@ +- Fix tooltip pointer position calculation when hovermode is set to 'x' - [issue [#6900](https://github.com/plotly/plotly.js/issues/6900) | PR [#6901](https://github.com/plotly/plotly.js/pull/6901)] \ No newline at end of file diff --git a/src/components/fx/hover.js b/src/components/fx/hover.js index 33c657d6981..c04b0a7f65b 100644 --- a/src/components/fx/hover.js +++ b/src/components/fx/hover.js @@ -1008,9 +1008,9 @@ function createHoverText(hoverData, opts) { lpath.attr('d', 'M' + (lx - tooltipMidX) + ',0' + 'L' + (lx - tooltipMidX + HOVERARROWSIZE) + ',' + topsign + HOVERARROWSIZE + - 'H' + (halfWidth) + + 'H' + halfWidth + 'v' + topsign + (HOVERTEXTPAD * 2 + tbb.height) + - 'H-' + halfWidth + + 'H' + (-halfWidth) + 'V' + topsign + HOVERARROWSIZE + 'H' + (lx - tooltipMidX - HOVERARROWSIZE) + 'Z');