Closed samreid closed 1 year ago
We might be able to hack our way around to make the current implementation do this, but I don't advise going down that path. Carousel and PageControl were not designed to support this behavior, and should be leveraging new scenery layout features to do so.
So my recommendation is:
This will be a complex rewrite, and will take considerable time (20-30 hours optimistically?)
I don't know the relative priority of this. But my advice is put this on a wish list, defer it for now, and live with the "holes" until higher-priority developement work and goals are accomplished.
Some ideas and prototypes being developed in https://github.com/phetsims/circuit-construction-kit-common/issues/630
For https://github.com/phetsims/circuit-construction-kit-common/issues/630, there is a minimally invasive working prototype that has the desired behavior. I tested the behavior of function builder and the sun carousel test, and it doesn't seem disrupted. I'd like to commit and request review.
UPDATE: I'm not fully familiar with Function Builder, so I'm not sure if I'm testing all the functionality.
... I'd like to commit and request review.
You've added CarouselOptions.isScrollingNodeLayoutBox
, which seems like a workaround. There's no reason for this option, it's the behavior that all Carousel's should exhibit. Or am I missing something? Or is it temporary?
isScrollingNodeLayoutBox
defaults to false
, and I don't see it used in any sims. (I'm fully pulled.) Please describe how to test it.
Where have you addressed PageControl? Does it work correctly when the number of pages in the carousel has changed?
Taking isScrollingNodeLayoutBox
for a test-drive in function-builder, the patch below causes this assertion failure on startup:
assert.js:28 Uncaught Error: Assertion failed: itemIndex out of range: -1 at window.assertions.assertFunction (assert.js:28:13) at Carousel.itemIndexToPageNumber (Carousel.ts:485:15) at Carousel.scrollToItemIndex (Carousel.ts:458:39) at Carousel.scrollToItem (Carousel.ts:469:10) at getCarouselPosition (SceneNode.js? [sm]:449:12) at SceneNode.js? [sm]:352:44 at Array.forEach (
) at PatternsSceneNode.populateFunctionCarousels (SceneNode.js? [sm]:349:33) at PatternsSceneNode.completeInitialization (SceneNode.js? [sm]:340:10) at FBScreenView.js? [sm]:91:30
Since what's in master is now buggy, this issue is blocking until @samreid's prototype is removed or completed.
Here's my recommendation:
Revert https://github.com/phetsims/sun/commit/fc9df1de5cb8513c26889e12f89b9b77c86bbb7f. This prototype does not address significant parts of the functionality of Carousel (and PageControl!), and in fact causes (failing) problems.
Defer changes to Carousel (and PageControl!) until a future date. This feature needs to be discussed, scoped, prioritized, scheduled, and (most importantly) done correctly. Prototyping before discussing and prioritizing feels premature.
Defer the CCK request in https://github.com/phetsims/circuit-construction-kit-common/issues/630 until a client actually asks for it. PhET spends too much time working on features that no one has asked for, while things that need to be completed are not.
Since what's in master is now buggy,
This is incorrect. The reason the patch above fails on startup is that function builder is telling the carousel to scroll to an item that is not displayed in the carousel.
This patch avoids scrolling to a non-displayed object, and starts up correctly:
Here is a patch that alternatively hides/shows the first item using setInterval:
There is a layout overlap problem, where carousel items are cut off though:
Since what's in master is now buggy,
This is incorrect. The reason the patch above fails on startup is that function builder is telling the carousel to scroll to an item that is not displayed in the carousel.
You changed the implementation such that Carousel crashes when one of it's supported features is used. How is that not a bug?
There's no reason for this option, it's the behavior that all Carousel's should exhibit. Or am I missing something? Or is it temporary?
This can be opt-in for now until it is well-established, then the option can be removed in the future.
And your short-term plan for addressing PageControl is ...?
You changed the implementation such that Carousel crashes when one of it's supported features is used.
Is one of Carousel's supported features scrolling to an object that is not displayed?
And your short-term plan for addressing PageControl is ...?
A plan for that has not yet been developed.
My recommendation is to remove this hack/bandaid from Carousel, and live with "holes" in the CCK release until we have resources to properly implement this feature for Carousel and PageControl. If you want to proceed with the hack/bandaid, then I'd prefer not to be involved with Carousel and PageControl.
Partial progress towards a more long-term implementation for Carousel:
I'm continuing to work on this since even after hearing the 20+ hours time estimate, the designer said:
My personal preference would be to invest the time into carousel because it's not going away, but I cannot make this call. I added the sun issue to the PhET-iO project board for further discussion.
In https://github.com/phetsims/circuit-construction-kit-common/issues/630, we determined this feature is critical to one of this month's high priority projects, and @jbphet, @matthew-blackman and I worked on an implementation that follows @pixelzoom's recommendations in https://github.com/phetsims/sun/issues/814#issuecomment-1334463348. We have been working in patches, but we would like to move to branches to make it possible to commit progress and coordinate. We would also like to request review from @pixelzoom review once @jbphet @matthew-blackman and I are ready (hopefully in the next few business days). So I'll start creating branches.
After the above commits, we observed in the LanguageSelectionNode that the highlights change the size of items in the carousel and it makes the layout jump around. We recommend that the highlighted items should have the same size as regular items and will commit that in a moment. Heads up to @jessegreenberg if you want to review that commit (note it is in a branch).
In the next commit (coming up after this comment), we saw that number suite common was doing a lot of extra work to put the items in pages. But now that is handled by the Carousel, so I'll commit that too... Heads up to @chrisklus since he is responsible dev for that repo.
For reference, here are the repos with branches so far:
build-a-molecule
circuit-construction-kit-common
function-builder
joist
number-line-operations
number-suite-common
sun
I think the majority of the above commits are from merging master. I also added the list to perennial so we can use commands using for-each.sh carousel-dynamic
.
Notes from discussion with @zepumph:
MK: Changes for carousel instrumentation should happen now since it is our first instrumented sim with carousels.
Should carousel items have metadata like this? We should be using GroupItemOptions plus more??
// Describes one radio button
export type RectangularRadioButtonGroupItem<T> = {
value: T; // value associated with the button
label?: Node; // optional label that appears outside the button
phetioDocumentation?: string; // optional documentation for PhET-iO
labelContent?: PDOMValueType; // optional label for a11y (description and voicing)
voicingContextResponse?: VoicingResponse;
descriptionContent?: PDOMValueType; // optional label for a11y
options?: StrictOmit<RectangularRadioButtonOptions, 'tandem'>; // options passed to RectangularRadioButton constructor
} & GroupItemOptions;
We think this is the right time for doing that.
PhET-iO Designed Features:
@matthew-blackman and I would like to commit to the branches, and to bring in the work from https://github.com/phetsims/circuit-construction-kit-common/issues/923 into the branches (to avoid patches on top of branches or branches on top of branches). Some questions about this commit:
Those commits (all in branches) are working for about half of the repos that use Carousel. I didn't want to leave partial progress in patches.
@zepumph @matthew-blackman and I discussed about whether it is OK to commit improvements that may not run or may have lint/type errors to branches. @marlitas also advocated for this previously. We think we should be able to do so. We think it might interfere with our ability to bisect, but we aren't sure about that and think it could be worth it anyways.
I started working on CarouselIO and having it report the indices of its items. It's unclear whether the pattern:
Is ideal, or whether that was just convenient and where we ended up. How difficult would it be to simulate that same UI if all the state is in the CarouselIO?
@zepumph @matthew-blackman and I are making good progress. Next steps we are aware of:
Sims to check:
Support for some cases where a hole is supposed to be there? (like the last item was dragged out?)
If you set the visibility of the alignBox with Carousel.setItemVisibility (implemented in https://github.com/phetsims/sun/commit/b2232c6a547088924e5aa6d1fdefeefb7fd90c8a), then the Carousel will reflow, and gaps will collapse, but if you set the visibility of the Node returned in the createNode function (this is on your own, no API support), then there will remain a hole in the Carousel. Yay!!!
@samreid and I were able to update all usages of Carousel to the new pattern on the carousel-dynamic branches. We did some pixel polishing comparing to the published versions when possible. The only worrisome usage we decided to punt on is in expression exchange. There we now have a carousel that is clearly not centers. We didn't understand exactly why, but the offset in https://github.com/phetsims/expression-exchange/blob/798a1103cc249fba3b6e168f8a43c7288e46ce8f/js/common/view/CoinTermCreatorNode.js#L73-L74 seemed suspicious.
Oops, that greenhouse effect commit didn't have anything to do with this issue. Just a random lint fix though.
I addressed the expression exchange centering issue and spot checked that other sims seem ok.
Issues discovered during review with @arouinfar and @matthew-blackman:
Increase margins for CCK
I believe increased margins were desired for every single Carousel we looked at in the last 24 hours. Should we change the default back to something larger like it was last week?
Here's a patch that skips invisible children for move forward/back,
That change does not belong in scenery Node.ts, I'll move it to IndexedNodeIO in a forthcoming commit.
Instructions for Carousel code review. Please note all code for the review is developed in branches, so you will not see the changes or new features until you check out the branches.
circuitConstructionKitDc.introScreen.view.circuitElementToolbox.carousel.items.resistorToolNode.visibleProperty
to false. The layout should adjust. Pressing "Test" should preserve the visibilities and layout in the launched sim. Removing items can remove pages, and PageControl automatically updates. If the user is on the last page when its last item is removed, it automatically moves to the previous page. A Carousel always has at least one page, even if there are no items.circuitConstructionKitDc.introScreen.view.circuitElementToolbox.carousel.items.resistorToolNode
and pressing "move up" or "move down" on it. Pressing "Test" should preserve the visibilities and layout in the launched sim.circuitConstructionKitDc.introScreen.view.circuitElementToolbox.carousel.items.lightBulbToolNode.visibleProperty
then moving the resistor circuitConstructionKitDc.introScreen.view.circuitElementToolbox.carousel.items.resistorToolNode
up one time used to have no effect, because it was moving the resistor past the invisible light bulb. We changed it so that pressing "move up" or "move down" ignores invisible neighbors for purposes of indexing. That change is in IndexedNodeIO and should be cherry picked into ph-scale and ph-scale basics for https://github.com/phetsims/ph-scale/issues/266. The solution works for Carousel and ComboBox.createNode
+ tandemName
. This led to a little work in Function Builder and other sims that need to reference the actual created Nodes. The Carousel has the 3 levels of detail: // Items hold the data to create the carouselItemNode
private readonly items: CarouselItem[];
// each AlignBox holds a carouselItemNode and ensures proper sizing in the Carousel
private readonly alignBoxes: AlignBox[];
// created from createNode() in CarouselItem
public readonly carouselItemNodes: Node[];
Disposal. Carousels create their items via createNode, and hence can dispose the created nodes.
Some sims (like Area Builder) duplicated code to show a panel and a carousel. The carousel now hides the previous/next buttons if it is a one-page carousel. This allows us to avoid duplicated code and continue using Carousel in cases like that.
Removed the option to "hide carousel buttons when they are disabled" because it did not have a consistent look and feel across sims, and because where it was used, it felt unbalanced/asymmetrical. Note that this looks odd for carousel combo box that has a small number of items. Our understanding was that is OK--this is not yet a production component. That case looks like this:
In reviewing all of the sims that use Carousel, we checked that they looked good and reasonable, and we did not spend undue effort trying to make everything identical with what's in master or on the PhET website.
perennial/data/carousel-dynamic
cd {{directory where all sims are checked out}}/
for-each.sh carousel-dynamic git checkout carousel-dynamic
for-each.sh carousel-dynamic git pull
In discussion with me, @pixelzoom @zepumph and @matthew-blackman, we recommend scheduling a different reviewer. While it is true that @pixelzoom wrote the initial version of Carousel, this is mostly a rewrite (Carousel 2.0) with a similar API. Also @pixelzoom would do a good job reviewing it. But after seeing the scope, @pixelzoom advised that it would be about 2 full days and he would need to push everything else back (including higher priority things). Therefore we (all 4 of us) concluded we would like to request another reviewer for now. This will help us move out of the branches (prevent divergence) and move forward with Circuit Construction Kit. Once @pixelzoom's higher priorities have resolved, he can take a 2nd look if necessary. So we would like to reach out and request another developer for this review. Instructions are listed in https://github.com/phetsims/sun/issues/814#issuecomment-1379727179. If there is not an obvious reviewer from #pistachio that would be appropriate, we can schedule one within #boba-phet. Perhaps @jbphet once his publications are underway.
UPDATE: @kathy-phet said:
@jonathanolson would be a possible reviewer for this once the GA deployments are taken care of. @jbphet will have a11y work to focus on, so isn't as available.
And @jonathanolson agreed to review. I met with him to discuss the instructions above.
Looks like things will need to be merged or otherwise to get TS happy, so I'm noting a patch here of my current review progress:
@jonathanolson editing this to add some clarity. While completing the CCK tree review on 1/24/23, @arouinfar @samreid and I found that pageNumberProperty has a static set of valid values. If a page is hidden due to removed elements, the Studio interface still shows a radio button for the missing page.
@samreid and @matthew-blackman made dynamic range, and now there is a get/setValue interface. Valid values include the visible pages. Range property includes the total number of pages.
Ran into trouble regenerating the API, so placing updates in the following patch:
Subject: [PATCH] Replace validValues with isValidValue in pageNumberProperty to check if page number exists when setting via studio, add range to pageNumberProperty showing initial number of pages - see https://github.com/phetsims/sun/issues/814
---
Index: js/Carousel.ts
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/js/Carousel.ts b/js/Carousel.ts
--- a/js/Carousel.ts (revision 361897928bfaff44a9ec2e80a7798417ab570436)
+++ b/js/Carousel.ts (date 1674585128830)
@@ -19,6 +19,7 @@
import stepTimer from '../../axon/js/stepTimer.js';
import Timer from '../../axon/js/Timer.js';
import Dimension2 from '../../dot/js/Dimension2.js';
+import Range from '../../dot/js/Range.js';
import { Shape } from '../../kite/js/imports.js';
import InstanceRegistry from '../../phet-core/js/documentation/InstanceRegistry.js';
import optionize, { combineOptions } from '../../phet-core/js/optionize.js';
@@ -308,7 +309,8 @@
const pageNumberProperty = new NumberProperty( options.defaultPageNumber, {
tandem: options.tandem.createTandem( 'pageNumberProperty' ),
numberType: 'Integer',
- validValues: _.range( this.numberOfPagesProperty.value ),
+ isValidValue: ( value: number ) => value < this.numberOfPagesProperty.value && value >= 0,
+ range: new Range( 0, this.numberOfPagesProperty.value - 1 ),
phetioFeatured: true
} );
We had ComboBox errors when regenerating the API in the branches, but we need to commit that patch in the prior commit.
Review isn't complete, but I've done significant amounts of work to Carousel / PageControl that's worth a "review inside a review". @samreid can you see the changes I've done above?
I'd also benefit from having someone more experienced with phet-io tag along for IndexedNodeIO review.
I'm to the point where I'll be scanning the other commits for changes (I'd consider the files Carousel/CarouselButton/PageControl to be fully reviewed now).
Review complete, and I fixed up the ordering issues that showed up during today's meetings.
Hey! @jbphet noticed the expression-exchange carousel is resizing on the 2nd screen when "All Coefficients" checkbox is toggled.
It looks like the content items are changing sizes. We'll probably want a good way to support minimum sizes for cells (to pass to the align boxes). Any thoughts on how to support this (should the sim just be wrapping it in things that don't change size?)
@zepumph and I made a cursory review a few days ago. @chrisklus said a minor disruption would be OK as long as major functionality in Number Play lab screen is preserved. @pixelzoom requested not to disrupt the Beer's Law Lab SHAs, but we have created those RCs. I'll take a look at the expression-exchange carousel behavior. I see in master it does not resize.
I reproduced the problem in expression exchange where carousel items change size and the carousel resizes. I agree it doesn't look so good.
The worst case looks like this:
Any thoughts on how to support this (should the sim just be wrapping it in things that don't change size?)
I followed that strategy in this patch:
It looks reasonable enough in every circumstance I tried, but it also seems kind of brittle if some coins or terms change size and this doesn't accommodate. Luckily I didn't see any translateable strings in the coins or terms. If this is the last part, we may proceed and request help from @jbphet if pixel polishing is necessary.
I'm using these URLs for testing behavior vs published:
https://phet.colorado.edu/sims/html/area-builder/latest/area-builder_en.html http://localhost/main/area-builder/area-builder_en.html
https://phet.colorado.edu/sims/html/balancing-act/latest/balancing-act_en.html http://localhost/main/balancing-act/balancing-act_en.html
https://phet.colorado.edu/sims/html/build-a-molecule/latest/build-a-molecule_en.html http://localhost/main/build-a-molecule/build-a-molecule_en.html
https://phet.colorado.edu/sims/html/circuit-construction-kit-ac/latest/circuit-construction-kit-ac_en.html http://localhost/main/circuit-construction-kit-ac/circuit-construction-kit-ac_en.html
https://phet.colorado.edu/sims/html/circuit-construction-kit-common/latest/circuit-construction-kit-common_en.html http://localhost/main/circuit-construction-kit-common/circuit-construction-kit-common_en.html
https://phet.colorado.edu/sims/html/circuit-construction-kit-dc/latest/circuit-construction-kit-dc_en.html http://localhost/main/circuit-construction-kit-dc/circuit-construction-kit-dc_en.html
https://phet.colorado.edu/sims/html/expression-exchange/latest/expression-exchange_en.html http://localhost/main/expression-exchange/expression-exchange_en.html
https://phet.colorado.edu/sims/html/function-builder/latest/function-builder_en.html http://localhost/main/function-builder/function-builder_en.html
https://phet.colorado.edu/sims/html/function-builder-basics/latest/function-builder-basics_en.html http://localhost/main/function-builder-basics/function-builder-basics_en.html
https://phet.colorado.edu/sims/html/geometric-optics/latest/geometric-optics_en.html http://localhost/main/geometric-optics/geometric-optics_en.html
https://phet.colorado.edu/sims/html/joist/latest/joist_en.html http://localhost/main/joist/joist_en.html
https://phet.colorado.edu/sims/html/number-line-operations/latest/number-line-operations_en.html http://localhost/main/number-line-operations/number-line-operations_en.html
https://phet.colorado.edu/sims/html/number-suite-common/latest/number-suite-common_en.html http://localhost/main/number-suite-common/number-suite-common_en.html
https://phet.colorado.edu/sims/html/scenery/latest/scenery_en.html http://localhost/main/scenery/scenery_en.html
https://phet.colorado.edu/sims/html/sun/latest/sun_en.html http://localhost/main/sun/sun_en.html
Everything else seems to be working, so I'm going to go for it. I'll open an expression exchange issue for @jbphet to take a closer look once merged back to master.
Merge complete. Still to do:
OK I opened or commented in all appropriate side issues. I want to wait for some CT columns to complete and to have more confidence the branches are all merged to master and pushed. After that, we can delete the branches.
CT caught an error in number line operations, which I fixed above. It also caught a bug in build-a-molecule, which I could not figure out, so I opened a side issue and assigned to @jonathanolson.
All work merged to master, has been reviewed. Side issues opened as appropriate. Branches deleted. Closing.
In https://github.com/phetsims/circuit-construction-kit-common/issues/630 it was requested that the carousel not leave empty layout holes when circuit elements are removed via visibleProperty = false in PhET-iO. The implementation could also support non-phet-io use cases, like adding/removing the non-ohmic bulb in CCK DC (Lab screen, Advanced, Add Real Bulbs). Sim-specific details are described in https://github.com/phetsims/circuit-construction-kit-common/issues/630. Summarizing the requests:
Circuit Construction Kit: DC: PhET-iO has the additional complexities:
As far as I understand from https://github.com/phetsims/circuit-construction-kit-common/issues/630, this feature is requested for the upcoming milestone release of CCK DC PhET-iO.
@pixelzoom can you please advise how to proceed, and help us estimate the time/complexity if we implement this?