Skip to content

Commit

Permalink
Move attributes to relevant model subclasses, see #153
Browse files Browse the repository at this point in the history
  • Loading branch information
samreid committed May 4, 2023
1 parent d92fb59 commit 51b7d00
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
15 changes: 3 additions & 12 deletions js/common/model/CAVModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<CAVSceneModel>;
public readonly soccerBallHasBeenDraggedProperty: Property<boolean>;
Expand All @@ -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' )
} );
Expand All @@ -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,
Expand All @@ -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() );
Expand Down
3 changes: 2 additions & 1 deletion js/common/view/BottomRepresentationCheckboxGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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,
Expand Down
14 changes: 14 additions & 0 deletions js/mean-and-median/model/MeanAndMedianModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 } ) {

Expand Down Expand Up @@ -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() );
}

Expand All @@ -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 {
Expand Down

0 comments on commit 51b7d00

Please sign in to comment.