From b443746c7ffa3474150de44c39dc67dd73465e03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=B6stl?= Date: Tue, 27 Feb 2018 11:42:34 +0100 Subject: [PATCH] Fix text position in centered tooltips #2154 - Bug: when a tooltip displays a sufficiently long text (also depends on overall plot dimensions), the tooltip isn't rendered right or left but centered. In this case the tooltip text was partly rendered outside the tooltip box. --- src/components/fx/hover.js | 4 -- test/image/mocks/centered-tooltips.json | 58 +++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 test/image/mocks/centered-tooltips.json diff --git a/src/components/fx/hover.js b/src/components/fx/hover.js index 3d326d007cc..d1a360c9660 100644 --- a/src/components/fx/hover.js +++ b/src/components/fx/hover.js @@ -1124,10 +1124,6 @@ function alignHoverText(hoverLabels, rotateLabels) { tx2x = txx + alignShift * (d.txwidth + HOVERTEXTPAD), offsetX = 0, offsetY = d.offset; - if(d.anchor === 'middle') { - txx -= d.tx2width / 2; - tx2x -= d.tx2width / 2; - } if(rotateLabels) { offsetY *= -YSHIFTY; offsetX = d.offset * YSHIFTX; diff --git a/test/image/mocks/centered-tooltips.json b/test/image/mocks/centered-tooltips.json new file mode 100644 index 00000000000..7ccc8cb44c5 --- /dev/null +++ b/test/image/mocks/centered-tooltips.json @@ -0,0 +1,58 @@ +{ + "data": [ + { + "y": [ + 1, + 2, + 6, + 3, + 5, + 6 + ], + "x": [ + 0, + 1, + 2, + 3, + 4, + 5 + ], + "text": [ + "short label", + "short label", + "Very long label named San Francisco", + "Very long label named San Francisco", + "Very long label named San Francisco" + ] + }, + { + "y": [ + 6, + 5, + 1, + 4, + 1, + 0 + ], + "x": [ + 0, + 1, + 2, + 3, + 4, + 5 + ], + "text": [ + "short label", + "short label", + "Very long label named San Francisco", + "Very long label named San Francisco", + "Very long label named San Francisco" + ] + } + ], + "layout": { + "width": 400, + "height": 300 + } +}