From 51b7d008358519707c3d64eba92d31121ed1d5f7 Mon Sep 17 00:00:00 2001 From: Sam Reid Date: Thu, 4 May 2023 05:57:07 -0600 Subject: [PATCH] Move attributes to relevant model subclasses, see https://github.com/phetsims/center-and-variability/issues/153 --- js/common/model/CAVModel.ts | 15 +++------------ .../view/BottomRepresentationCheckboxGroup.ts | 3 ++- js/mean-and-median/model/MeanAndMedianModel.ts | 14 ++++++++++++++ 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/js/common/model/CAVModel.ts b/js/common/model/CAVModel.ts index d05d1b7a..4448fb5b 100644 --- a/js/common/model/CAVModel.ts +++ b/js/common/model/CAVModel.ts @@ -19,11 +19,8 @@ export default class CAVModel { // TODO: Some of these should move to subclasses public readonly isShowingPlayAreaMedianProperty: BooleanProperty; public readonly isShowingPlayAreaMeanProperty: BooleanProperty; - public readonly isShowingMeanPredictionProperty: BooleanProperty; public readonly isShowingMedianPredictionProperty: BooleanProperty; - public readonly medianPredictionProperty: NumberProperty; - public readonly meanPredictionProperty: NumberProperty; public readonly selectedSceneModelProperty: Property; public readonly soccerBallHasBeenDraggedProperty: Property; @@ -36,9 +33,7 @@ export default class CAVModel { this.isShowingPlayAreaMedianProperty = new BooleanProperty( false, { tandem: options.tandem.createTandem( 'isShowingPlayAreaMedianProperty' ) } ); - this.isShowingMeanPredictionProperty = new BooleanProperty( false, { - tandem: options.instrumentMeanPredictionProperty ? options.tandem.createTandem( 'isShowingMeanPredictionProperty' ) : Tandem.OPT_OUT - } ); + this.isShowingMedianPredictionProperty = new BooleanProperty( false, { tandem: options.tandem.createTandem( 'isShowingMedianPredictionProperty' ) } ); @@ -49,10 +44,6 @@ export default class CAVModel { range: CAVConstants.PHYSICAL_RANGE, tandem: options.tandem.createTandem( 'medianPredictionProperty' ) } ); - this.meanPredictionProperty = new NumberProperty( 1.5, { - range: CAVConstants.PHYSICAL_RANGE, - tandem: options.instrumentMeanPredictionProperty ? options.tandem.createTandem( 'meanPredictionProperty' ) : Tandem.OPT_OUT - } ); this.selectedSceneModelProperty = new Property( sceneModels[ 0 ], { validValues: sceneModels, @@ -78,10 +69,10 @@ export default class CAVModel { public reset(): void { this.medianPredictionProperty.reset(); - this.meanPredictionProperty.reset(); + this.isShowingPlayAreaMeanProperty.reset(); this.isShowingPlayAreaMedianProperty.reset(); - this.isShowingMeanPredictionProperty.reset(); + this.isShowingMedianPredictionProperty.reset(); this.sceneModels.forEach( sceneModel => sceneModel.reset() ); diff --git a/js/common/view/BottomRepresentationCheckboxGroup.ts b/js/common/view/BottomRepresentationCheckboxGroup.ts index a90e7fb0..650c373a 100644 --- a/js/common/view/BottomRepresentationCheckboxGroup.ts +++ b/js/common/view/BottomRepresentationCheckboxGroup.ts @@ -21,6 +21,7 @@ import PredictionThumbNode from './PredictionThumbNode.js'; import LinkableProperty from '../../../../axon/js/LinkableProperty.js'; import VariabilityModel from '../../variability/model/VariabilityModel.js'; import CAVModel from '../model/CAVModel.js'; +import MeanAndMedianModel from '../../mean-and-median/model/MeanAndMedianModel.js'; // constants const TEXT_OPTIONS = { @@ -109,7 +110,7 @@ export default class BottomRepresentationCheckboxGroup extends VerticalCheckboxG ); } - public static getPredictMeanCheckboxItem( alignGroup: AlignGroup, model: CAVModel ): VerticalCheckboxGroupItem { + public static getPredictMeanCheckboxItem( alignGroup: AlignGroup, model: MeanAndMedianModel ): VerticalCheckboxGroupItem { return BottomRepresentationCheckboxGroup.createPredictionItem( model.isShowingMeanPredictionProperty, CenterAndVariabilityStrings.predictMeanStringProperty, diff --git a/js/mean-and-median/model/MeanAndMedianModel.ts b/js/mean-and-median/model/MeanAndMedianModel.ts index af588cdd..93b643bc 100644 --- a/js/mean-and-median/model/MeanAndMedianModel.ts +++ b/js/mean-and-median/model/MeanAndMedianModel.ts @@ -12,6 +12,8 @@ import BooleanProperty from '../../../../axon/js/BooleanProperty.js'; import CAVSceneModel from '../../common/model/CAVSceneModel.js'; import CAVModel from '../../common/model/CAVModel.js'; import Tandem from '../../../../tandem/js/Tandem.js'; +import NumberProperty from '../../../../axon/js/NumberProperty.js'; +import CAVConstants from '../../common/CAVConstants.js'; // constants const HIGHLIGHT_ANIMATION_TIME_STEP = 0.25; // in seconds @@ -26,6 +28,8 @@ export default class MeanAndMedianModel extends CAVModel { public readonly isMedianAnimationCompleteProperty = new BooleanProperty( false ); public readonly isShowingTopMedianProperty: BooleanProperty; public readonly isShowingTopMeanProperty: BooleanProperty; + public readonly isShowingMeanPredictionProperty: BooleanProperty; + public readonly meanPredictionProperty: NumberProperty; public constructor( options: { tandem: Tandem } ) { @@ -62,6 +66,14 @@ export default class MeanAndMedianModel extends CAVModel { } } ); + this.meanPredictionProperty = new NumberProperty( 1.5, { + range: CAVConstants.PHYSICAL_RANGE, + tandem: options.tandem.createTandem( 'meanPredictionProperty' ) + } ); + this.isShowingMeanPredictionProperty = new BooleanProperty( false, { + tandem: options.tandem.createTandem( 'isShowingMeanPredictionProperty' ) + } ); + scene.objectValueBecameNonNullEmitter.addListener( () => this.updateAnimation() ); } @@ -71,6 +83,8 @@ export default class MeanAndMedianModel extends CAVModel { this.isMedianAnimationCompleteProperty.reset(); this.isShowingTopMeanProperty.reset(); this.isShowingTopMedianProperty.reset(); + this.meanPredictionProperty.reset(); + this.isShowingMeanPredictionProperty.reset(); } public override step( dt: number ): void {