Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plot: Add predefined tick formatters #18

Merged
merged 2 commits into from
Jul 29, 2024
Merged

Conversation

johannes-wolf
Copy link
Member

@johannes-wolf johannes-wolf commented Jul 20, 2024

This PR adds a new file formats.typ that defines some tick formatters.

  • fraction: Formatting tick labels as fractions
  • multiple-of: Formatting tick labels as a multiple of a constant (e.g. pi)
  • sci: Scientific number formatter

I've changed the "lines" gallery entry to some better looking one that show approximations of sin x and uses the new functions.

@johannes-wolf johannes-wolf added the 🎁 feature New feature or request label Jul 20, 2024
@johannes-wolf johannes-wolf force-pushed the predefined-tick-formats branch 3 times, most recently from 6b276e8 to 2f32249 Compare July 20, 2024 11:50
}

// Pre-computed table of fractions
#let _common-denoms = range(2, 11 + 1).map(d => {
Copy link
Member Author

@johannes-wolf johannes-wolf Jul 20, 2024

Choose a reason for hiding this comment

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

Idk. about this. It is the simplest solution I came up with and I think if you really want other fractions, it is fine requiring specifying a fixed denominator.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there a reason for 11 + 1 instead of 12?

Copy link
Member Author

Choose a reason for hiding this comment

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

To highlight that, we generate fractions up to n/11, not 12 (because range being zero-based).

Copy link
Collaborator

@jamesrswift jamesrswift left a comment

Choose a reason for hiding this comment

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

This looks good to me. Perhaps for a separate PR, it might be worth adding another tick formatter that places the exponent at the top of an axis like so
image

But this is a nice PR :)

@johannes-wolf johannes-wolf merged commit 6ec2a93 into master Jul 29, 2024
1 check passed
@johannes-wolf johannes-wolf deleted the predefined-tick-formats branch July 29, 2024 16:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🎁 feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants