Skip to content

Commit

Permalink
uninstrument Text, #339
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelzoom committed Jul 22, 2023
1 parent bb680dc commit fdd3e08
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 77 deletions.
49 changes: 13 additions & 36 deletions js/common/view/AddMutationsPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@
*/

import DerivedProperty from '../../../../axon/js/DerivedProperty.js';
import TReadOnlyProperty from '../../../../axon/js/TReadOnlyProperty.js';
import optionize, { combineOptions, EmptySelfOptions, optionize3 } from '../../../../phet-core/js/optionize.js';
import StrictOmit from '../../../../phet-core/js/types/StrictOmit.js';
import PickRequired from '../../../../phet-core/js/types/PickRequired.js';
import { AlignBox, AlignBoxOptions, AlignGroup, HBox, HBoxOptions, Image, Node, NodeOptions, Rectangle, TColor, Text, TextOptions, VBox, VBoxOptions } from '../../../../scenery/js/imports.js';
import { AlignBox, AlignBoxOptions, AlignGroup, HBox, HBoxOptions, Image, Node, NodeOptions, Rectangle, TColor, Text, VBox, VBoxOptions } from '../../../../scenery/js/imports.js';
import RectangularPushButton, { RectangularPushButtonOptions } from '../../../../sun/js/buttons/RectangularPushButton.js';
import NumberIO from '../../../../tandem/js/types/NumberIO.js';
import naturalSelection from '../../naturalSelection.js';
Expand Down Expand Up @@ -98,8 +97,18 @@ export default class AddMutationsPanel extends NaturalSelectionPanel {
} );

// title
const titleText = new TitleNode( numberOfRowsVisibleProperty, {
tandem: options.tandem.createTandem( 'titleText' )
const titleStringProperty = new DerivedStringProperty( [
numberOfRowsVisibleProperty,
NaturalSelectionStrings.addMutationStringProperty,
NaturalSelectionStrings.addMutationsStringProperty
],
( numberOfRowsVisible, addMutationString, addMutationsString ) =>
( numberOfRowsVisible === 1 ) ? addMutationString : addMutationsString, {
tandem: options.tandem.createTandem( 'titleStringProperty' )
} );
const titleText = new Text( titleStringProperty, {
font: NaturalSelectionConstants.TITLE_FONT,
maxWidth: 180 // determined empirically
} );

const content = new VBox( combineOptions<VBoxOptions>( {}, NaturalSelectionConstants.VBOX_OPTIONS, {
Expand Down Expand Up @@ -365,36 +374,4 @@ class AlleleIcon extends Node {
}
}

type TitleNodeSelfOptions = EmptySelfOptions;
type TitleNodeOptions = TitleNodeSelfOptions & PickRequired<Text, 'tandem'>;

/**
* TitleNode supports dynamic locale, and changes between singular/plural based on how many Rows are visible.
*/
class TitleNode extends Text {

public constructor( numberOfRowsVisibleProperty: TReadOnlyProperty<number>, providedOptions: TitleNodeOptions ) {

const options = optionize<TitleNodeOptions, TitleNodeSelfOptions, TextOptions>()( {

// TextOptions
font: NaturalSelectionConstants.TITLE_FONT,
maxWidth: 180, // determined empirically
isDisposable: false
}, providedOptions );

const stringProperty = new DerivedStringProperty( [
numberOfRowsVisibleProperty,
NaturalSelectionStrings.addMutationStringProperty,
NaturalSelectionStrings.addMutationsStringProperty
],
( numberOfRowsVisible, addMutationString, addMutationsString ) =>
( numberOfRowsVisible === 1 ) ? addMutationString : addMutationsString, {
tandem: options.tandem.createTandem( Text.STRING_PROPERTY_TANDEM_NAME )
} );

super( stringProperty, options );
}
}

naturalSelection.register( 'AddMutationsPanel', AddMutationsPanel );
57 changes: 16 additions & 41 deletions js/common/view/EnvironmentalFactorsPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@

import DerivedProperty from '../../../../axon/js/DerivedProperty.js';
import Property from '../../../../axon/js/Property.js';
import TReadOnlyProperty from '../../../../axon/js/TReadOnlyProperty.js';
import optionize, { combineOptions, EmptySelfOptions, optionize4 } from '../../../../phet-core/js/optionize.js';
import { combineOptions, optionize4 } from '../../../../phet-core/js/optionize.js';
import StrictOmit from '../../../../phet-core/js/types/StrictOmit.js';
import PickRequired from '../../../../phet-core/js/types/PickRequired.js';
import { AlignGroup, Text, TextOptions, VBox, VBoxOptions } from '../../../../scenery/js/imports.js';
import { AlignGroup, Text, VBox, VBoxOptions } from '../../../../scenery/js/imports.js';
import NumberIO from '../../../../tandem/js/types/NumberIO.js';
import naturalSelection from '../../naturalSelection.js';
import NaturalSelectionStrings from '../../NaturalSelectionStrings.js';
Expand Down Expand Up @@ -85,51 +83,28 @@ export default class EnvironmentalFactorsPanel extends NaturalSelectionPanel {
} );

// title
const titleText = new TitleText( numberOfCheckboxesVisibleProperty, {
tandem: options.tandem.createTandem( 'titleText' )
const titleStringProperty = new DerivedStringProperty( [
numberOfCheckboxesVisibleProperty,
NaturalSelectionStrings.environmentalFactorStringProperty,
NaturalSelectionStrings.environmentalFactorsStringProperty
], ( numberOfCheckboxesVisible, environmentalFactor, environmentalFactors ) =>
( numberOfCheckboxesVisible === 1 ) ? environmentalFactor : environmentalFactors, {
tandem: options.tandem.createTandem( 'titleStringProperty' )
} );

const content = new VBox( combineOptions<VBoxOptions>( {}, NaturalSelectionConstants.VBOX_OPTIONS, {
children: [ titleText, ...checkboxes ]
} ) );

super( content, options );
}
}

type TitleTextSelfOptions = EmptySelfOptions;
type TitleTextOptions = TitleTextSelfOptions & PickRequired<Text, 'tandem'>;

/**
* TitleText supports dynamic locale, and changes between singular/plural based on how many checkboxes are visible.
*/
class TitleText extends Text {

public constructor( numberOfCheckboxesVisibleProperty: TReadOnlyProperty<number>, providedOptions: TitleTextOptions ) {

const options = optionize<TitleTextOptions, TitleTextSelfOptions, TextOptions>()( {

// TextOptions
const titleText = new Text( titleStringProperty, {
font: NaturalSelectionConstants.TITLE_FONT,
maxWidth: 175, // determined empirically,
phetioVisiblePropertyInstrumented: true,
visiblePropertyOptions: {
phetioFeatured: true
},
isDisposable: false
}, providedOptions );

const stringProperty = new DerivedStringProperty( [
numberOfCheckboxesVisibleProperty,
NaturalSelectionStrings.environmentalFactorStringProperty,
NaturalSelectionStrings.environmentalFactorsStringProperty
], ( numberOfCheckboxesVisible, environmentalFactor, environmentalFactors ) =>
( numberOfCheckboxesVisible === 1 ) ? environmentalFactor : environmentalFactors, {
tandem: options.tandem.createTandem( Text.STRING_PROPERTY_TANDEM_NAME )

}
} );

super( stringProperty, options );
const content = new VBox( combineOptions<VBoxOptions>( {}, NaturalSelectionConstants.VBOX_OPTIONS, {
children: [ titleText, ...checkboxes ]
} ) );

super( content, options );
}
}

Expand Down

0 comments on commit fdd3e08

Please sign in to comment.