phetsims / resistance-in-a-wire

"Resistance in a Wire" is an educational simulation in HTML5, by PhET Interactive Simulations.
http://phet.colorado.edu/en/simulation/resistance-in-a-wire
GNU General Public License v3.0
1 stars 4 forks source link

SliderUnit should use nested options #210

Closed zepumph closed 4 years ago

zepumph commented 4 years ago

This is also the case for ohms-law, and I think they could both be implemented in a very similar way. @twant said she would investigate. Thanks!

Perhaps something like:


      a11yMapValue: value => Util.toFixedNumber( value, 2 ),
      keyboardStep: 1,
      shiftKeyboardStep: 0.01,
      startDrag: _.noop,
      sliderOptions:{

        trackFillEnabled: 'black',
        trackSize: new Dimension2( ResistanceInAWireConstants.SLIDER_HEIGHT - 30, 4 ),
        thumbSize: new Dimension2( 22, 45 ),
        thumbFill: '#c3c4c5',
        thumbFillHighlighted: '#dedede',
        tandem: tandem.createTandem( 'slider' ),
        startDrag: function( event ) {
          if ( event.type === 'keydown' ) {
            self.keyboardDragging = true;
          }
          options.startDrag && options.startDrag( event );
        },
        endDrag: function( event ) {
          self.keyboardDragging = false;
          options.endDrag && options.endDrag( event );
        },

        // physical values in this sim can have up to 2 decimals
        constrainValue: function( value ) {
          return Util.toFixedNumber( value, 2 );
        },

        // a11y
        roundToStepSize: true, // default keyboard step rounds to pedegogically useful values

        // a11y
        containerTagName: 'li',
        labelContent: labelContent,
        labelTagName: 'label'
      },
      endDrag: _.noop
    }, options );
twant commented 4 years ago

@zepumph I pushed some changes to accomplish this. Would love your review. I noticed two different ways to handle the startDrag and stopDrag options between RIAW and Ohm's Law. I kept both for now, but would particularly love your advice about whether to condense down to a single way to handle these options.

zepumph commented 4 years ago

Review:

Overall things are looking really good. Thanks for taking the lead on this. Let me know if you have any questions.

twant commented 4 years ago

Just pushed a change that should hopefully resolve the CT error documented in #211. Apologies again for not fixing this earlier @zepumph @pixelzoom! I'll keep an eye on CT to make sure the error is resolved with this change.

twant commented 4 years ago

@zepumph regarding the startDrag and endDrag options, I've moved them back to the top level options. I think I understand the piece you're referring to from NumberControl (where we used options.delta in the sliderOptions), but would appreciate you checking over this change to confirm that it's consistent with the structure you were imagining.

In terms of gracefully wrapping the options, I'm not sure whether that favors the Ohm's Law or the RIAW handling of startDrag and stopDrag -- can we discuss Tuesday?

zepumph commented 4 years ago

n terms of gracefully wrapping the options, I'm not sure whether that favors the Ohm's Law or the RIAW handling of startDrag and stopDrag -- can we discuss Tuesday?

Yes indeed. I think that for the most part I was looking at RIAW and trying to make sure we didn't lose functionality. Now looking at OL, it is more idiomatic to what was done in NumberControl, and makes more sense because it only uses a single option. I will get back to you about the best pattern.

zepumph commented 4 years ago

Other changes look good.

zepumph commented 4 years ago

I think wrapping the options is the best holdover pattern until https://github.com/phetsims/scenery/issues/1016 or https://github.com/phetsims/sun/issues/536 are figured out.