Skip to content

fix: Center period labels over their own period when using ticklabelindex - #7934

Merged
camdecoster merged 17 commits into
plotly:mainfrom
my-tien:7876-ticklabelindex-positioning
Oct 7, 2026
Merged

camdecoster merged 17 commits into
plotly:mainfrom
my-tien:7876-ticklabelindex-positioning

Conversation

@my-tien

@my-tien my-tien commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Fixes #7876 by rewriting the way period label positioning works when using ticklabelindex.

Previously, the next labeled tick was used as the period end for the previous tick. This was problematic when using ticklabelindex, because sometimes the next labeled period is not necessarily adjacent to the last labeled period.
Now positionPeriodTicks can accept an array of periodEndTicks instead.

@my-tien
my-tien marked this pull request as draft August 5, 2026 13:01
@my-tien
my-tien marked this pull request as ready for review August 5, 2026 13:32
@robertclaus
robertclaus requested a review from camdecoster August 6, 2026 19:33

@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.

Most of this works, but there are a few changes that need to be made. I'm happy to talk through how to do some of this.

Comment thread src/plots/cartesian/axes.js Outdated
Comment thread src/plots/cartesian/axes.js Outdated
Comment on lines +1013 to +1015
// for period label positioning when using `ticklabelindex`:
// for each tick in `allTicklabelVals` holds the neighboring period end tick
var periodEndTicks;

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.

Instead of saving an array of end ticks for each tick, what if we save the end tick to each tick? Then you could check for an end tick on each tick and use a different code path. You'd also be able to get rid of the new arg in positionPeriodTicks.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Let me know if I didn't implement it as you intended.

Comment thread src/plots/cartesian/axes.js Outdated
// This minor tick will be labeled instead of the major tick.
if (isPeriod) periodEndTicks = []; // for each minor tick at the start of a labeled period this will hold the neighboring period end tick.

const labelTickValsAscending = minorTickVals

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.

What should happen if there's a major tick that doesn't coincide with a minor tick? Should that also be included?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No, when ticklabelindex is used, only minor ticks should labeled. This step is just to handle the special case when a minor tick coincides with a major tick in which case the major tick should be labeled instead (because the minor could be removed later).

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.

Even if the major ticks aren't displayed, they're still used when determining which tick to display. From the description for ticklabelindex:

draw the label for the minor tick that is n positions away from the major tick

Without that major tick, the count will be off.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, now all major ticks and all non-overlapping minor ticks are in allTicklabelVals.

Comment thread src/plots/cartesian/axes.js
Comment thread src/plots/cartesian/axes.js Outdated
Comment thread src/plots/cartesian/axes.js
@camdecoster camdecoster changed the title Fix #7876: Ticklabelindex positioning fix: Center period labels over their own period when using ticklabelindex Sep 23, 2026
Comment thread src/plots/cartesian/axes.js Outdated

@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.

There are still a couple of things to address. I added some more context to my earlier comments.

ALso, could you please do a pass to make sure you're not using var in any of the new code?

Comment thread src/plots/cartesian/axes.js Outdated
// This minor tick will be labeled instead of the major tick.
if (isPeriod) periodEndTicks = []; // for each minor tick at the start of a labeled period this will hold the neighboring period end tick.

const labelTickValsAscending = minorTickVals

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.

Even if the major ticks aren't displayed, they're still used when determining which tick to display. From the description for ticklabelindex:

draw the label for the minor tick that is n positions away from the major tick

Without that major tick, the count will be off.

Comment thread src/plots/cartesian/axes.js
@my-tien
my-tien requested a review from camdecoster October 6, 2026 17:33
my-tien and others added 4 commits October 7, 2026 15:14
If no tickformat is specified, ax._actualDelta wasn't set and so periodX was also not set inside positionPeriodTicks.
@camdecoster
camdecoster merged commit 236e43f into plotly:main Oct 7, 2026
76 of 77 checks passed
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]: period labels can be positioned incorrectly when using ticklabelindex with only one minor tick

2 participants