Skip to content

fix: keep reversed scale titles aligned#12244

Open
d3v07 wants to merge 2 commits intochartjs:masterfrom
d3v07:fix/12239-reversed-scale-title-align
Open

fix: keep reversed scale titles aligned#12244
d3v07 wants to merge 2 commits intochartjs:masterfrom
d3v07:fix/12239-reversed-scale-title-align

Conversation

@d3v07
Copy link
Copy Markdown

@d3v07 d3v07 commented Apr 22, 2026

Summary

  • stop reversed scales from flipping title text alignment to the opposite end
  • add a regression test covering align: 'start' and align: 'end' across cartesian scale positions

Fixes #12239

Repro

Verification

  • pnpm run build
  • pnpm exec eslint src/core/core.scale.js test/specs/core.scale.tests.js
  • local browser repro confirming reverse no longer changes the title draw calls for align=start or align=end

Copilot AI review requested due to automatic review settings April 22, 2026 16:49
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes axis title alignment so reversing a cartesian scale no longer flips title.align (“start”/“end”) to the opposite end, and adds a regression test for the behavior.

Changes:

  • Update internal titleAlign logic so reverse no longer influences title text alignment.
  • Add regression tests asserting title draw calls are identical for reverse: true vs reverse: false across cartesian edge positions.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/core/core.scale.js Removes reverse from title alignment calculation to keep start/end alignment stable when scales are reversed.
test/specs/core.scale.tests.js Adds a regression test comparing captured title draw calls between reversed and non-reversed scales for align: 'start'/'end'.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/core/core.scale.js Outdated
Comment on lines 122 to 127
function titleAlign(align, position) {
/** @type {CanvasTextAlign} */
let ret = _toLeftRightCenter(align);
if ((reverse && position !== 'right') || (!reverse && position === 'right')) {
if (position === 'right') {
ret = reverseAlign(ret);
}
Comment thread test/specs/core.scale.tests.js Outdated
Comment on lines +890 to +893
['top', 'bottom', 'left', 'right'].forEach(function(position) {
['start', 'end'].forEach(function(align) {
it('should not reposition the ' + position + ' scale title when reverse=true and align=' + align, function() {
expect(getScaleTitleCalls(position, align, true)).toEqual(getScaleTitleCalls(position, align, false));
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.

Axis titles are misaligned when the scale is reversed

2 participants