fix: Apply hoverlabel.align to unified hover label items · plotly/plotly.js@79ee28d · GitHub
Skip to content

Commit 79ee28d

Browse files
committed
fix: Apply hoverlabel.align to unified hover label items
Unified hover labels draw their items through the legend, which always anchors item text at the start. The resolved hoverlabel.align of each point was never read there, so layout and trace values had no effect. Items with align 'right' now anchor at the right edge of the label. Closes #8100
1 parent c759b27 commit 79ee28d

3 files changed

Lines changed: 57 additions & 0 deletions

File tree

‎draftlogs/XXXX_fix.md‎

Lines changed: 1 addition & 0 deletions

‎src/components/legend/draw.js‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,6 +1064,17 @@ function computeLegendDimensions(gd, groups, traces, legendObj, scrollBox) {
10641064
Drawing.setRect(traceToggle, 0, -h / 2, w, h);
10651065
});
10661066

1067+
if (legendObj._inHover) {
1068+
const textRight = legendObj._width - bw2 - itemGap - titleSize[0];
1069+
traces.each(function (d) {
1070+
if (d[0].textAlign !== 'right') return;
1071+
d3.select(this)
1072+
.select('.' + legendId + 'text')
1073+
.attr('text-anchor', 'end')
1074+
.call(svgTextUtils.positionText, textRight);
1075+
});
1076+
}
1077+
10671078
// align legend title horizontally
10681079
var titleEl = scrollBox.select('.' + legendId + 'titletext');
10691080
if(titleEl.node()) {

‎test/jasmine/tests/hover_test.js‎

Lines changed: 45 additions & 0 deletions

0 commit comments

Comments
 (0)