-
Notifications
You must be signed in to change notification settings - Fork 10
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
How to improve RulerNode usage #116
Comments
The pendulum-lab ruler has no insets, so the min and max tick labels are not needed. But otherwise, RulerNode assumes that there's a label for every major tick:
An unfortunate implementation, I agree - it was ported from the Java implementation (piccolophet.RulerNode). A better API would specify a mapping between tick values and labels, ala HSlider. Options: (1) Rewrite RulerNode, a lot of work, and 11 (2) Modify RulerNode so that empty strings (and null values?) are ignored in |
I followed the initial path of (2) for refactoring, but I can't guarantee unitsMajorTickIndex is actually a valid (non-negative integer) index. The else-if clause on line 135 (checking if majorTickIndex > options.unitsMajorTickIndex ) will only be triggered if unitsMajorTickIndex is negative OR a non-integer value (majorTickIndex starts at 0 and increases by 1, and since equality is checked first, we can guarantee the else-if won't fire if it's a non-negative integer). Either it's (a) dead code and can be removed, or (b) fractional/negative indices are supported, I just made the change to prevent adding the empty labels as children. I'll move any cleanup/optimization work to a scenery-phet issue (like not creating the empty labels we toss, so that we can actually pass in null). |
Closing here, see phetsims/scenery-phet#213 for further RulerNode improvement discussion. |
Reopening. In #116 (comment), @jonathanolson said:
Neither is the case. The |
My bad, looking into it. |
Not something you necessarily have to resolve for this issue. When I said in #116 (comment):
I was assuming that you wouldn't create or layout the Text node associated with the empty tick. But you're still doing that (line 106), then not adding it at line 117. That's fine if it simplifies the code. |
... and I don't completely understand the |
Creating the Text node isn't great, but it only slows down the creation of the ruler, not its display. It does simplify the code and changes for now. Will plan to handle the cleanup and refactoring in phetsims/scenery-phet#213, since it's related to how we set the maxWidth of the units label to fit within ticks. |
Desired general appearance is a ruler from 0 to 200cm where every multiple of 20 cm is labeled (excluding 0 and 200cm).
It looks like MLL is giving empty-string tick labels for 0, 200, and every 20*n+10 (multiple of 10 that isn't a multiple of 20):
I was wondering if @pixelzoom could provide a brief recommendation for how this should be done, and if using empty tick labels is the correct approach (hopefully not?). If it is correct, I'd prefer to not add the Text nodes.
The text was updated successfully, but these errors were encountered: