From d4e5827aae9ae6025ccb90b8461ad41b10aa8c62 Mon Sep 17 00:00:00 2001 From: pixelzoom Date: Fri, 10 Mar 2023 17:19:28 -0700 Subject: [PATCH] move instantiation of TangentScrubber and AreaUnderCurveScrubber so they are not instantiated for screens that do not include them --- js/common/model/CalculusGrapherModel.ts | 41 +++++++++---------------- js/derivative/model/DerivativeModel.ts | 14 ++++++++- js/integral/IntegralScreen.ts | 2 +- js/integral/model/IntegralModel.ts | 15 +++++++-- 4 files changed, 41 insertions(+), 31 deletions(-) diff --git a/js/common/model/CalculusGrapherModel.ts b/js/common/model/CalculusGrapherModel.ts index 94de405b..2e349d98 100644 --- a/js/common/model/CalculusGrapherModel.ts +++ b/js/common/model/CalculusGrapherModel.ts @@ -1,7 +1,7 @@ // Copyright 2020-2023, University of Colorado Boulder /** - * Base class for the top-level model of every screen in the 'Calculus Grapher' simulation. + * CalculusGrapherModel is the base class for the top-level model of every screen in the 'Calculus Grapher' simulation. * * @author Brandon Li * @author Martin Veillette @@ -28,8 +28,6 @@ import CalculusGrapherConstants from '../CalculusGrapherConstants.js'; import ReferenceLine from './ReferenceLine.js'; import LabeledLine from './LabeledLine.js'; import LabeledPoint from './LabeledPoint.js'; -import TangentScrubber from './TangentScrubber.js'; -import AreaUnderCurveScrubber from './AreaUnderCurveScrubber.js'; import GraphSet from './GraphSet.js'; import CalculusGrapherPreferences from './CalculusGrapherPreferences.js'; import BooleanIO from '../../../../tandem/js/types/BooleanIO.js'; @@ -46,11 +44,11 @@ type SelfOptions = { // Identifies the curve manipulation modes that are supported by the screen associated with this model. curveManipulationModeChoices?: CurveManipulationMode[]; - // Should the TangentScrubber be instrumented for PhET-iO? - phetioTangentScrubberInstrumented?: boolean; + // Should the model create a TangentScrubber? + hasTangentScrubber?: boolean; - // Should the AreaUnderCurveScrubber be instrumented for PhET-iO? - phetioAreaUnderCurveScrubberInstrumented?: boolean; + // Should the model create an AreaUnderCurveScrubber? + hasAreaUnderCurveScrubber?: boolean; }; export type CalculusGrapherModelOptions = SelfOptions & PickRequired; @@ -88,11 +86,12 @@ export default class CalculusGrapherModel implements TModel { // Model elements for the various tools public readonly referenceLine: ReferenceLine; - public readonly tangentScrubber: TangentScrubber; - public readonly areaUnderCurveScrubber: AreaUnderCurveScrubber; public readonly labeledPoints: LabeledPoint[]; public readonly labeledLines: LabeledLine[]; + // Tandem that can be used to add additional tools in the subclasses + protected readonly toolsTandem: Tandem; + // These exist so that we have something to link to from the view. // See https://github.com/phetsims/calculus-grapher/issues/198 public readonly labeledPointsLinkableElement: PhetioObject; @@ -105,8 +104,8 @@ export default class CalculusGrapherModel implements TModel { // SelfOptions graphSet: providedOptions.graphSets[ 0 ], curveManipulationModeChoices: CurveManipulationMode.enumeration.values, - phetioTangentScrubberInstrumented: false, - phetioAreaUnderCurveScrubberInstrumented: false + hasTangentScrubber: false, + hasAreaUnderCurveScrubber: false }, providedOptions ); assert && assert( options.graphSets.length > 0, 'there must be at least one valid graphSet' ); @@ -174,27 +173,17 @@ export default class CalculusGrapherModel implements TModel { this.secondDerivativeCurve = new DerivativeCurve( this.derivativeCurve, createCurveTandem( GraphType.SECOND_DERIVATIVE ) ); this.integralCurve = new IntegralCurve( this.originalCurve, createCurveTandem( GraphType.INTEGRAL ) ); - const toolsTandem = options.tandem.createTandem( 'tools' ); + this.toolsTandem = options.tandem.createTandem( 'tools' ); this.referenceLine = new ReferenceLine( this.integralCurve, this.originalCurve, this.derivativeCurve, this.secondDerivativeCurve, - toolsTandem.createTandem( 'referenceLine' ) - ); - - this.tangentScrubber = new TangentScrubber( - this.integralCurve, this.originalCurve, this.derivativeCurve, this.secondDerivativeCurve, - options.phetioTangentScrubberInstrumented ? toolsTandem.createTandem( 'tangentScrubber' ) : Tandem.OPT_OUT - ); - - this.areaUnderCurveScrubber = new AreaUnderCurveScrubber( - this.integralCurve, this.originalCurve, this.derivativeCurve, this.secondDerivativeCurve, - options.phetioAreaUnderCurveScrubberInstrumented ? toolsTandem.createTandem( 'areaUnderCurveScrubber' ) : Tandem.OPT_OUT + this.toolsTandem.createTandem( 'referenceLine' ) ); // This exists so that we have something we can link to from the view. // See https://github.com/phetsims/calculus-grapher/issues/198 this.labeledPointsLinkableElement = new PhetioObject( { - tandem: toolsTandem.createTandem( 'labeledPoints' ), + tandem: this.toolsTandem.createTandem( 'labeledPoints' ), phetioState: false } ); @@ -210,7 +199,7 @@ export default class CalculusGrapherModel implements TModel { // This exists so that we have something we can link to from the view. // See https://github.com/phetsims/calculus-grapher/issues/198 this.labeledLinesLinkableElement = new PhetioObject( { - tandem: toolsTandem.createTandem( 'labeledLines' ), + tandem: this.toolsTandem.createTandem( 'labeledLines' ), phetioState: false } ); @@ -237,8 +226,6 @@ export default class CalculusGrapherModel implements TModel { // Reset tools this.referenceLine.reset(); - this.tangentScrubber.reset(); - this.areaUnderCurveScrubber.reset(); // Do not reset this.labeledPoints, because they are configured only via PhET-iO. // Do not reset this.labeledLines, because they are configured only via PhET-iO. } diff --git a/js/derivative/model/DerivativeModel.ts b/js/derivative/model/DerivativeModel.ts index ea1d04de..11f52f17 100644 --- a/js/derivative/model/DerivativeModel.ts +++ b/js/derivative/model/DerivativeModel.ts @@ -13,6 +13,7 @@ import CalculusGrapherModel, { CalculusGrapherModelOptions } from '../../common/ import optionize, { EmptySelfOptions } from '../../../../phet-core/js/optionize.js'; import CurveManipulationMode from '../../common/model/CurveManipulationMode.js'; import PickRequired from '../../../../phet-core/js/types/PickRequired.js'; +import TangentScrubber from '../../common/model/TangentScrubber.js'; type SelfOptions = EmptySelfOptions; @@ -20,6 +21,8 @@ type DerivativeModelOptions = SelfOptions & PickRequired()( { @@ -31,10 +34,19 @@ export default class DerivativeModel extends CalculusGrapherModel { CurveManipulationMode.TILT, CurveManipulationMode.SHIFT ], - phetioTangentScrubberInstrumented: true + hasTangentScrubber: true }, providedOptions ); super( options ); + + this.tangentScrubber = new TangentScrubber( this.integralCurve, this.originalCurve, this.derivativeCurve, + this.secondDerivativeCurve, this.toolsTandem.createTandem( 'tangentScrubber' ) + ); + } + + public override reset(): void { + this.tangentScrubber.reset(); + super.reset(); } } calculusGrapher.register( 'DerivativeModel', DerivativeModel ); diff --git a/js/integral/IntegralScreen.ts b/js/integral/IntegralScreen.ts index 4ef9f2a7..2c21d6bd 100644 --- a/js/integral/IntegralScreen.ts +++ b/js/integral/IntegralScreen.ts @@ -1,7 +1,7 @@ // Copyright 2020-2023, University of Colorado Boulder /** - * The 'Integral Lab' screen. + * The 'Integral' screen. * * @author Brandon Li * @author Martin Veillette diff --git a/js/integral/model/IntegralModel.ts b/js/integral/model/IntegralModel.ts index ab5df376..c11ab831 100644 --- a/js/integral/model/IntegralModel.ts +++ b/js/integral/model/IntegralModel.ts @@ -1,7 +1,7 @@ // Copyright 2020-2023, University of Colorado Boulder /** - * Top-level model for the 'Integral Lab' screen. + * Top-level model for the 'Integral' screen. * * @author Brandon Li * @author Martin Veillette @@ -13,6 +13,7 @@ import CalculusGrapherModel, { CalculusGrapherModelOptions } from '../../common/ import optionize, { EmptySelfOptions } from '../../../../phet-core/js/optionize.js'; import CurveManipulationMode from '../../common/model/CurveManipulationMode.js'; import PickRequired from '../../../../phet-core/js/types/PickRequired.js'; +import AreaUnderCurveScrubber from '../../common/model/AreaUnderCurveScrubber.js'; type SelfOptions = EmptySelfOptions; @@ -20,6 +21,8 @@ type IntegralModelOptions = SelfOptions & PickRequired()( { @@ -31,10 +34,18 @@ export default class IntegralModel extends CalculusGrapherModel { CurveManipulationMode.TILT, CurveManipulationMode.SHIFT ], - phetioAreaUnderCurveScrubberInstrumented: true + hasAreaUnderCurveScrubber: true }, providedOptions ); super( options ); + + this.areaUnderCurveScrubber = new AreaUnderCurveScrubber( this.integralCurve, this.originalCurve, + this.derivativeCurve, this.secondDerivativeCurve, this.toolsTandem.createTandem( 'areaUnderCurveScrubber' ) ); + } + + public override reset(): void { + this.areaUnderCurveScrubber.reset(); + super.reset(); } }