phetsims / projectile-data-lab

"Projectile Data Lab" is an educational simulation in HTML5, by PhET Interactive Simulations.
GNU General Public License v3.0
0 stars 0 forks source link

Automatically hide the stopwatch when auto-generate data is enabled. #180

Closed samreid closed 6 months ago

samreid commented 6 months ago

From https://github.com/phetsims/projectile-data-lab/issues/146 we would like to automatically hide the stopwatch when auto-generate data is enabled. We tried to do so but ran into a problem that StopwatchNode does not support a DerivedProperty for visibleProperty since it sets its own visibility via this.visible = .... We may reach out to @pixelzoom for support on this.

pixelzoom commented 6 months ago

Relevant code in StopwatchNode.ts:

    const stopwatchVisibleListener = ( visible: boolean ) => {
300   this.visible = visible;
      if ( visible ) {
        this.moveToFront();
      }
      else {

        // interrupt user interactions when the stopwatch is made invisible
        this.interruptSubtreeInput();
      }
    };

Line 300 is the issue; it fails if a DerivedProperty is provided, which would be the natural way to address this in PDL.

pixelzoom commented 6 months ago

In code review https://github.com/phetsims/projectile-data-lab/issues/32:

Here's a patch that allows StopWatchNode to work correctly with a readonly (e.g. derived) visibleProperty. It's low-risk that this will break other sims, but you should test (I did not).

Subject: [PATCH] link to https://github.com/phetsims/scenery-phet/issues/843 in comments
---
Index: js/StopwatchNode.ts
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/js/StopwatchNode.ts b/js/StopwatchNode.ts
--- a/js/StopwatchNode.ts   (revision 12c83d2e3eebd0fbd4f35e5064d27f4790ca572f)
+++ b/js/StopwatchNode.ts   (date 1709588457640)
@@ -177,6 +177,7 @@
       otherControls: [],

       includePlayPauseResetButtons: true,
+      visibleProperty: stopwatch.isVisibleProperty,

       // Tandem is required to make sure the buttons are instrumented
       tandem: Tandem.REQUIRED,
@@ -299,7 +300,6 @@
     }

     const stopwatchVisibleListener = ( visible: boolean ) => {
-      this.visible = visible;
       if ( visible ) {
         this.moveToFront();
       }

In PDLStopwatchNode, you'll want to do something like:

    const options = optionize<PDLStopwatchNodeOptions, SelfOptions, StopwatchNodeOptions>()( {
-      visibleProperty: stopwatch.isVisibleProperty,
+      visibleProperty: new DerivedProperty.and(
+.           [ stopwatch.isVisibleProperty, PDLPreferences.autoGenerateDataProperty ],
+            ( stopwatchIsVisible, autoGenerateData ) => stopwatchIsVisible && !autoGenerateData ),

Back to @samreid and @matthew-blackman for next steps.

matthew-blackman commented 6 months ago

@samreid and I implemented the recommendation from @pixelzoom in the following patch:

```diff Subject: [PATCH] Update sound category names - see https://github.com/phetsims/projectile-data-lab/issues/228 --- Index: scenery-phet/js/StopwatchNode.ts IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/scenery-phet/js/StopwatchNode.ts b/scenery-phet/js/StopwatchNode.ts --- a/scenery-phet/js/StopwatchNode.ts (revision cce96f69ac534072a4e4a166f57f5e99f731fe5a) +++ b/scenery-phet/js/StopwatchNode.ts (date 1709751080493) @@ -177,6 +177,7 @@ otherControls: [], includePlayPauseResetButtons: true, + visibleProperty: stopwatch.isVisibleProperty, // Tandem is required to make sure the buttons are instrumented tandem: Tandem.REQUIRED, @@ -299,7 +300,6 @@ } const stopwatchVisibleListener = ( visible: boolean ) => { - this.visible = visible; if ( visible ) { this.moveToFront(); } Index: projectile-data-lab/js/common-vsm/model/VSMModel.ts IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/projectile-data-lab/js/common-vsm/model/VSMModel.ts b/projectile-data-lab/js/common-vsm/model/VSMModel.ts --- a/projectile-data-lab/js/common-vsm/model/VSMModel.ts (revision 9278f00267109339bc6c35de18e41ec6a216b615) +++ b/projectile-data-lab/js/common-vsm/model/VSMModel.ts (date 1709751422792) @@ -215,6 +215,11 @@ // View coordinates. Positioned so it doesn't overlap with the histogram or field sign. position: new Vector2( 650, 350 ) } ); + + // If the auto-generate data preference is selected, stop the stopwatch since it will be hidden. + PDLPreferences.autoGenerateDataProperty.lazyLink( () => { + this.stopwatch.isRunningProperty.value = false; + } ); } /** Index: projectile-data-lab/js/common-vsm/view/PDLStopwatchNode.ts IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/projectile-data-lab/js/common-vsm/view/PDLStopwatchNode.ts b/projectile-data-lab/js/common-vsm/view/PDLStopwatchNode.ts --- a/projectile-data-lab/js/common-vsm/view/PDLStopwatchNode.ts (revision 9278f00267109339bc6c35de18e41ec6a216b615) +++ b/projectile-data-lab/js/common-vsm/view/PDLStopwatchNode.ts (date 1709751204677) @@ -18,6 +18,7 @@ import DerivedStringProperty from '../../../../axon/js/DerivedStringProperty.js'; import TReadOnlyProperty from '../../../../axon/js/TReadOnlyProperty.js'; import DerivedProperty from '../../../../axon/js/DerivedProperty.js'; +import PDLPreferences from '../../common/PDLPreferences.js'; type SelfOptions = { launchButtonEnabledProperty: TReadOnlyProperty; @@ -68,7 +69,8 @@ } ); const options = optionize()( { - visibleProperty: stopwatch.isVisibleProperty, + visibleProperty: new DerivedProperty( [ stopwatch.isVisibleProperty, PDLPreferences.autoGenerateDataProperty ], + ( stopwatchIsVisible, autoGenerateData ) => stopwatchIsVisible && !autoGenerateData ), includePlayPauseResetButtons: false, otherControls: [ launchStopButton ] }, providedOptions ); ```

This is working well in PDL, and we'd like to do further testing on other sims before committing this to common code.

samreid commented 6 months ago

I ran the snapshot comparison test with no working copy changes and got this result:

``` acid-base-solutions 3066b2 2225 area-builder 0a1b49 3461 area-model-algebra 433095 5203 area-model-decimals e6d446 6158 area-model-introduction 60ace3 7046 area-model-multiplication 578bb0 8380 arithmetic 72a1ad 10352 atomic-interactions 18e073 11494 balancing-act 95d836 13068 balancing-chemical-equations 21513f 14006 balloons-and-static-electricity fb5399 16591 bamboo f08980 17427 beers-law-lab be83cc 19031 bending-light ddbb87 20509 blackbody-spectrum 740738 21261 blast 4deb14 21706 build-a-fraction 08577f 24193 build-a-molecule fe014f 26655 build-a-nucleus 85da0b 28325 build-an-atom 5f7ae0 29416 bumper 750171 29799 buoyancy 675f1f 34390 calculus-grapher f5e0c8 39370 capacitor-lab-basics 01541d 40899 center-and-variability 9f0ae2 45502 chains f36cad 46052 charges-and-fields 52c8a1 47025 circuit-construction-kit-ac b0c7b4 51387 circuit-construction-kit-ac-virtual-lab 5cef96 55921 circuit-construction-kit-black-box-study 12d035 60194 circuit-construction-kit-common 966d0f 60728 circuit-construction-kit-dc 7bb291 64457 circuit-construction-kit-dc-virtual-lab 4936dc 69060 collision-lab 3708f7 70936 color-vision 548242 72671 concentration d1339c 73638 coulombs-law 561ba8 76087 curve-fitting e0f2ba 76952 density cc6721 79141 diffusion df19b4 80289 eating-exercise-and-energy 01e084 80658 energy-forms-and-changes 0353ab 83702 energy-skate-park 65437c 87813 energy-skate-park-basics 73d191 90079 equality-explorer b9bfdc 92671 equality-explorer-basics 8a07fe 94133 equality-explorer-two-variables 48fe27 95178 estimation c28180 96525 example-sim 267d48 97147 expression-exchange 43de7d 99587 faradays-electromagnetic-lab 91f4e9 104342 faradays-law 79b5f8 105402 fluid-pressure-and-flow 8f0624 107963 forces-and-motion-basics ba946e 110522 fourier-making-waves ada86f 114449 fraction-comparison a91d19 115258 fraction-matcher 407e52 116581 fractions-equality e357bf 118136 fractions-intro 9f01cd 120201 fractions-mixed-numbers 4aa06e 122732 friction 16ba59 124106 function-builder 33587d 126861 function-builder-basics dbabdc 130044 gas-properties c06225 132659 gases-intro 759336 134577 gene-expression-essentials 8d11b9 136133 generator 506902 138196 geometric-optics 539896 141234 geometric-optics-basics 5f64f7 143833 graphing-lines 9e9141 145588 graphing-quadratics b612f2 146902 graphing-slope-intercept e6a828 148559 gravity-and-orbits a55b35 150439 gravity-force-lab d5cb76 152080 gravity-force-lab-basics ae73c6 153528 greenhouse-effect 706969 155562 griddle c26a86 156165 hookes-law 7e74ff 157529 interaction-dashboard 14e71a 160990 isotopes-and-atomic-mass 4d7772 163419 john-travoltage b0fc4f 164294 joist 2ea283 164818 keplers-laws cfb923 168753 least-squares-regression 7f2982 169638 magnet-and-compass 195249 171187 magnets-and-electromagnets 6e4dc0 173244 make-a-ten 038e5f 174268 masses-and-springs cd2377 176042 masses-and-springs-basics 628ac1 177453 mean-share-and-balance 2cfd46 181192 mobius fc77c5 181818 models-of-the-hydrogen-atom 246a66 183845 molarity 926ab8 184786 molecule-polarity c346d4 186009 molecule-shapes 6fe67f 187568 molecule-shapes-basics ca9b66 188879 molecules-and-light e209f7 190623 my-solar-system 596660 192785 natural-selection 7a6d54 194834 neuron 7ef873 196230 nitroglycerin 0a46ca 196680 normal-modes 456417 197897 number-compare 86bbaa 199565 number-line-distance f27e56 201629 number-line-integers b46d08 204396 number-line-operations 46ccf8 206078 number-play 1c5e4c 208062 ohms-law 8e29b2 208906 optics-lab 39b280 211312 pendulum-lab 1342c9 212932 ph-scale 08c28b 214131 ph-scale-basics 35247d 214738 phet-io-test-sim e7425a 215193 plinko-probability 6ce7bf 216553 projectile-motion f73243 218929 projectile-data-lab 2a2f31 223729 proportion-playground c4d30b 226167 quadrilateral 655e49 227505 ratio-and-proportion 2275d3 229021 reactants-products-and-leftovers 0f8dcc 231142 resistance-in-a-wire 0e5c02 232045 rutherford-scattering c162ab 233379 scenery-phet dc5624 235072 simula-rasa 0a0e80 235474 sound-waves a6f6eb 237769 states-of-matter d7a0ab 239753 states-of-matter-basics 52c407 241118 sun f9bedb 241861 tambo e54316 242789 tappi a58db1 243629 trig-tour 7e6a10 244972 twixt 320397 245777 under-pressure 09a81c 247065 unit-rates 614956 248936 vector-addition f99568 250802 vector-addition-equations 55f53d 252120 vegas 1cae3d 252896 vibe 11b2d7 253275 wave-interference c81a52 256062 wave-on-a-string e5601b 257137 waves-intro 7e1c31 258988 wilder 546b28 259568 xray-diffraction e36788 260701 ```

Here are the results. The middle column is a synthetic test I did where I intentionally changed the title of balancing act to make sure it was caught (and it was). It also revealed some spurious changes:

image image image
samreid commented 6 months ago

I do not see problems specific to the stopwatch based on those changes alone. Next I manually tested Kepler's Laws, Capacitor Lab: Basics and Circuit Construction Kit: AC and they all behaved as expected. I think we should commit and see if CT finds anything else.

Precommit hooks seem ok:

node chipper/js/scripts/precommit-hook-multi.js
detected changed repos: projectile-data-lab, scenery-phet
projectile-data-lab: Success
scenery-phet: Success
Done in 77897ms