-
Notifications
You must be signed in to change notification settings - Fork 25
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
Scale.log fixes #2035
Scale.log fixes #2035
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Ignored Deployment
|
For This also fixes #1798. (I throw an error when min >= max; note: this might break some existing Squiggle models). |
This is now also a global runtime error. |
For |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems good! I like the functionality - code generally looks okay, though I don't understand d3 as well.
Kudos for figuring this out, seems gnarly. |
It seems like that issue is not totally fixed - in the case that there's a min but no max. d2 = Plot.dist({ |
Fixes #2031.
The root cause for this is that
d3.scaleLog().ticks()
andd3.scaleLog.tickFormat()
are special.Full docs: https://github.com/d3/d3-scale/tree/main#log_ticks
I'll try to explain what's going on.
D3 scales have two methods,
.ticks(count)
and.tickFormat(count, specifier)
. First one outputs an array of ticks to render, and second one return a format function that turns values into strings.There are two modes for
.ticks(count)
on log scales:Example:
Example:
(I think there might be off-by-one error here in d3's implementation, but it's not very important; d3.ticks() is never guaranteed to be precise)
Since the second mode outputs a lot of ticks, and ticks in [5..10] range are close to each other,
tickFormat()
returns an empty string for some ticks.This affects both hover values and actual ticks.
For hovers, there's a special mode for tickFormat,
tickFormat(Infinity)
, that I now use indrawCursorLines
.For tick labels, the problem was that we have our own algorithm for fitting labels in
drawAxes
, which forces labels to never overlap. But it could be unlucky and pick only the ticks that are empty. (I'm not sure about the details, but skipping empty labels helped.)