Skip to content

Calculate hidden minor ticks if ticklabelindex is set.#7735

Open
my-tien wants to merge 13 commits intoplotly:masterfrom
my-tien:calculate-hidden-minor-ticks
Open

Calculate hidden minor ticks if ticklabelindex is set.#7735
my-tien wants to merge 13 commits intoplotly:masterfrom
my-tien:calculate-hidden-minor-ticks

Conversation

@my-tien
Copy link
Copy Markdown
Contributor

@my-tien my-tien commented Mar 27, 2026

Closes #7423

This PR ensures that the ticklabelindex axis property has an effect even if minor ticks are not visible. Labels are then drawn at possibly invisible minor tick labels n positions away from a major tick.
This makes it possible to draw the label for a period to the left of a major tick which was previously not always possible. See this issue for two examples where it was previously not possible: #7423

Disclaimer I am required to add that…

the software is provided "as is", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. in no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the software or the use or other dealings in the software.

@emilykl
Copy link
Copy Markdown
Contributor

emilykl commented Apr 15, 2026

Thanks for the PR, @my-tien! Sorry for the delay, I'll review ASAP.

Have you looked into the failing image tests yet?

@emilykl emilykl self-assigned this Apr 15, 2026
@my-tien
Copy link
Copy Markdown
Contributor Author

my-tien commented Apr 22, 2026

Hi @emilykl, not yet! I'll try to do it next week.

my-tien added 4 commits April 27, 2026 14:40
This additional minor tick was added for ticklabel placement via ticklabelindex only. It should never be rendered.
…dden-minor-ticks

Undoes update of date_axes_period_ticklabelindex.png and date_axes_period2_ticklabelindex.png because they changed in the main branch. Have to do the update with the output of the next CI run.
…xes_period2_ticklabelindex.

This time after having merged master into this branch.
@my-tien
Copy link
Copy Markdown
Contributor Author

my-tien commented Apr 27, 2026

Failing baseline image tests are resolved. I also updated date_axe_period_ticklabelindex.png and date_axe_period2_ticklabelindex.png.
In each image, the left-most label of one of the axes is now drawn when it was previously omitted. I think this is actually more correct than before.

@emilykl emilykl self-requested a review April 28, 2026 15:58
@emilykl
Copy link
Copy Markdown
Contributor

emilykl commented Apr 28, 2026

@my-tien Great! I'm taking a look.


// check if ticklabelIndex makes sense, otherwise ignore it
if(!minorTickVals || minorTickVals.length < 2) {
if(!minorTickVals || minorTickVals.length < 3) {
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.

@my-tien From the comments I understand you've modified the logic to add an additional minor tick before tick0, hence these changes, but could you explain the reason for adding that additional tick?

Comment on lines +1306 to 1314
if (ticklabelIndex) {
if (allTicklabelVals.indexOf(tickVals[i]) === -1) {
hideLabel(t);
}
} else {
if (tickVals[i].skipLabel) {
hideLabel(t);
}
}
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 is just a style change, correct? The code is logically equivalent before and after the change, right?

IMO it would be clearer to leave as-is, but add extra parentheses around the && clause to clarify it's evaluated first.

i.e. if(a || (b && c))

Or, otherwise, maybe

Suggested change
if (ticklabelIndex) {
if (allTicklabelVals.indexOf(tickVals[i]) === -1) {
hideLabel(t);
}
} else {
if (tickVals[i].skipLabel) {
hideLabel(t);
}
}
if (ticklabelIndex && allTicklabelVals.indexOf(tickVals[i]) === -1) {
hideLabel(t);
} else if (tickVals[i].skipLabel) {
hideLabel(t);
}

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.

I reverted the code. No strong opinion on my end 👍

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.

Actually, this does something different. Only if ticklabelindex is false should the tickVals[i].skipLabel check be done.

Comment thread draftlogs/7735_change.md Outdated
Copy link
Copy Markdown
Contributor

@emilykl emilykl left a comment

Choose a reason for hiding this comment

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

@my-tien Thank you for the PR. This change looks good to me.

I have a few requests concerning the image tests:

  • Could you combine the 3 new image mocks into one single mock with 3 subplots? This will help keep the total number of image tests down and keep the CI faster.

  • Could you explicitly set dtick and tick0 for the minor ticks in each mock, to make the expected behavior clear?

  • We are no longer following the convention of prefixing new mocks and baselines with zz-, so you can remove that prefix from the filenames. If this causes any small changes in other baselines, you can simply commit those changed baselines as part of this PR.

I added a note to the PR description that this will close #7423; please let me know if you think that's not the case.

@emilykl emilykl assigned my-tien and unassigned emilykl Apr 28, 2026
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.

ticklabelindex property does not work for dticks spanning multiple periods

2 participants