Skip to content

fix: Apply hoverlabel.align to unified hover label items - #8104

Open
MannXo wants to merge 4 commits into
plotly:mainfrom
MannXo:fix/8100-unified-hoverlabel-align
Open

MannXo wants to merge 4 commits into
plotly:mainfrom
MannXo:fix/8100-unified-hoverlabel-align

Conversation

@MannXo

@MannXo MannXo commented Oct 3, 2026 •

Copy link
Copy Markdown

Description

Make hoverlabel.align take effect in x unified and y unified hover labels. The unified label draws its items through the legend, and the legend always anchored item text at the start. Each item now reads the hoverlabel.align value of its point, so the layout value and the trace values both apply. With 'right', the item text aligns to the right edge of the label. 'left' and 'auto' keep the current output.

The title of the label stays left-aligned. I can align it with the items too if you prefer.

Closes #8100.

Changes

  • Anchor the text of unified hover items that have hoverlabel.align: 'right' at the right edge of the label
  • Add a test to hover_test.js for the layout value and a trace value
  • Add draftlog

Screenshots

Repro from the issue, layout.hoverlabel.align: 'right'

Before After
image image

Testing

  • npm run test-jasmine -- hover legend --nowatch passes (357 specs). The new spec fails on main.
  • Open Plotly devtools and paste the following into the browser devtools console, then hover over a category:
    const gd = Tabs.fresh();
    Plotly.newPlot(
        gd,
        [
            { type: 'bar', x: ['A', 'B', 'C'], y: [3944, 2810, 1675], name: 'Series 1' },
            { type: 'bar', x: ['A', 'B', 'C'], y: [-266, -1020, -85], name: 'Series 2' },
            { type: 'bar', x: ['A', 'B', 'C'], y: [-44, -310, -7], name: 'Series 3' }
        ],
        { barmode: 'relative', hovermode: 'x unified', hoverlabel: { align: 'right' } }
    );

MannXo added 3 commits October 3, 2026 21:25
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 plotly#8100

@camdecoster camdecoster left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! This looks like a reasonable solution. Could you please address the failing test in CI? Also, could you update the hoverlabel.align description in fx/layout_attributes.js to fix the typo?

Comment thread test/jasmine/tests/hover_test.js Outdated
_hover(gd, { xval: 1 });
const [short, long] = getItems();
expect([short.anchor, long.anchor]).toEqual(['end', 'start']);
expect(short.right).toBeCloseTo(long.right, 0);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check is failing in CI. It's likely due to font rendering differences between your computer and CI. You could change the check to the following to make it a bit more forgiving:

Suggested change
expect(short.right).toBeCloseTo(long.right, 0);
expect(short.right).toBeWithin(long.right, 1);

@camdecoster camdecoster self-assigned this Oct 3, 2026
The description read "spans more two or more lines". The right-edge check compared positions to the nearest pixel, and font rendering differs between machines, so it failed in CI.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: hoverlabel.align is ignored in hovermode: "x unified"

2 participants