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

Logarithm axes in plots library #15

Closed
wants to merge 8 commits into from

Conversation

jamesrswift
Copy link
Collaborator

@jamesrswift jamesrswift commented Jul 13, 2024

This is a very early draft, but as this has been a highly sought after feature, I'm making this draft PR public to allow for collaboration.

This implementation adds axis options {x}-mode that takes "lin" (default) or "log", which is passed through context to _prepare for scaling in plot-space (the infinite xy plane) to take place, which passes it forward to util.compute-stroke-paths and util.compute-fill-paths. Concurrently, ticks are then calculated from compute-logarithmic-ticks which applies the inverse of that transformation on tick marks.

Implementation quirks:

  • axis parameters such as min and max are not transformed in any way. This flaw can be fixed with a good deal of work, so it may not be worth the effort,

To do:

  • Provide a better heuristic for choosing tick mark locations in compute-logarithmic-ticks. Its a copy/paste of the linear one at the moment because I wanted to see it working
  • The rendering of the grid will need changing as well
  • Support bases other than base 10
  • Move scaling from prepare to a more suitable location

I'm sure there's more but its late. This is very much open for feedback even in its draft state because its definitively a feature to get right on the first attempt.

Pretty pictures:
image

@jamesrswift
Copy link
Collaborator Author

Current state:
image

@johannes-wolf johannes-wolf self-requested a review July 14, 2024 12:29
@jamesrswift
Copy link
Collaborator Author

Minor tick marks seem to be a tricky thing here - not sure what a good heuristic is. I think minor tick steps should be exponents? Like should a tick step of 0.5 would place a tick half way between powers?

@jamesrswift
Copy link
Collaborator Author

Since the recent commit allowing custom function transforms I made a new branch from that commit as I wanted to change the tactic I was going with. I'll close this PR as the branch isn't going to be updated, and I'll make a new PR from the new branch once I get a barely working implementation ... working. For anyone interested in following before then, I'm doing the work here: https://github.com/JamesxX/cetz-plot/tree/log-mode-attempt-3 (yes there was an attempt 2 that went in the box of deleted shame)

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.

1 participant