Skip to content

Commit

Permalink
add list item that describes IR layers, see #374
Browse files Browse the repository at this point in the history
  • Loading branch information
jbphet committed Nov 28, 2023
1 parent 532c352 commit f6662ad
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 23 deletions.
17 changes: 17 additions & 0 deletions js/layer-model/view/LayerModelObservationWindowPDOMNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import ObservationWindowPDOMNode from '../../common/view/ObservationWindowPDOMNode.js';
import greenhouseEffect from '../../greenhouseEffect.js';
import LayerModelModel from '../model/LayerModelModel.js';
import { Node } from '../../../../scenery/js/imports.js';
import InfraredAbsorbingLayersDescriptionProperty from './describers/InfraredAbsorbingLayersDescriptionProperty.js';
import StringUtils from '../../../../phetcommon/js/util/StringUtils.js';

/**
* Responsible for PDOM content related to the observation window used in the waves screen.
Expand All @@ -14,6 +17,20 @@ class LayerModelObservationWindowPDOMNode extends ObservationWindowPDOMNode {

public constructor( model: LayerModelModel ) {
super( model.sunEnergySource.isShiningProperty );

// Create a string Property that describes the number of infrared-absorbing layers in the atmosphere.
const infraredAbsorbingLayersPhraseProperty = new InfraredAbsorbingLayersDescriptionProperty(
model.numberOfActiveAtmosphereLayersProperty
);

// Create the node that will place the description of IR layers into the PDOM.
const irLayersItemNode = new Node( { tagName: 'li' } );
this.addChild( irLayersItemNode );

// Update the PDOM item when the description string changes.
infraredAbsorbingLayersPhraseProperty.link( infraredAbsorbingLayersPhrase => {
irLayersItemNode.innerContent = StringUtils.capitalize( infraredAbsorbingLayersPhrase ) + '.';
} );
}
}

Expand Down
26 changes: 4 additions & 22 deletions js/layer-model/view/LayerModelScreenSummaryContentNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import GreenhouseEffectScreenSummaryContentNode from '../../common/view/Greenhou
import DerivedProperty from '../../../../axon/js/DerivedProperty.js';
import StringUtils from '../../../../phetcommon/js/util/StringUtils.js';
import TemperatureDescriber from '../../common/view/describers/TemperatureDescriber.js';
import InfraredAbsorbingLayersDescriptionProperty from './describers/InfraredAbsorbingLayersDescriptionProperty.js';

export default class LayerModelScreenSummaryContentNode extends GreenhouseEffectScreenSummaryContentNode {

Expand All @@ -25,28 +26,9 @@ export default class LayerModelScreenSummaryContentNode extends GreenhouseEffect
GreenhouseEffectStrings.a11y.layerModel.screenSummary.controlAreaDescriptionStringProperty
);

// A derived Property containing a string that represents the number of infrared-absorbing layers in the atmosphere,
// for example, "one infrared absorbing layer in atmosphere".
const infraredAbsorbingLayersPhraseProperty = new DerivedProperty(
[ model.numberOfActiveAtmosphereLayersProperty ],
numberOfActiveAtmosphereLayers => {

// parameter checking
assert && assert(
numberOfActiveAtmosphereLayers >= 0,
`numberOfActiveAtmosphereLayers must be positive, got ${numberOfActiveAtmosphereLayers}`
);

return StringUtils.fillIn(
GreenhouseEffectStrings.a11y.layerModel.observationWindow.numberOfAbsorbingLayersPatternStringProperty,
{
number: numberOfActiveAtmosphereLayers > 0 ?
numberOfActiveAtmosphereLayers :
GreenhouseEffectStrings.a11y.qualitativeAmountDescriptions.noStringProperty, // say 'no' for zero
s: numberOfActiveAtmosphereLayers === 1 ? '' : 's' // use plural except for a single layer
}
);
}
// a string Property that describes the number of infrared-absorbing layers in the atmosphere
const infraredAbsorbingLayersPhraseProperty = new InfraredAbsorbingLayersDescriptionProperty(
model.numberOfActiveAtmosphereLayersProperty
);

// A derived property containing a string that describes the surface temperature, for example, "Earth's surface
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright 2023, University of Colorado Boulder

/**
* InfraredAbsorbingLayersDescriptionProperty is a Property<string> that describes the current number of the IR-
* absorbing layers in the atmosphere. For example, one possible value is "2 infrared absorbing layers in atmosphere".
*
* @author John Blanco (PhET Interactive Simulations)
*/
import greenhouseEffect from '../../../greenhouseEffect.js';
import StringProperty from '../../../../../axon/js/StringProperty.js';
import Multilink from '../../../../../axon/js/Multilink.js';
import TRangedProperty from '../../../../../axon/js/TRangedProperty.js';
import GreenhouseEffectStrings from '../../../GreenhouseEffectStrings.js';
import StringUtils from '../../../../../phetcommon/js/util/StringUtils.js';

class InfraredAbsorbingLayersDescriptionProperty extends StringProperty {
public constructor( numberOfActiveAtmosphereLayersProperty: TRangedProperty ) {
super( '' );

// Monitor the intensity Property and update the value of the string.
Multilink.multilink( [ numberOfActiveAtmosphereLayersProperty ], numberOfActiveAtmosphereLayers => {

// parameter checking
assert && assert(
numberOfActiveAtmosphereLayers >= 0,
`numberOfActiveAtmosphereLayers must be positive, got ${numberOfActiveAtmosphereLayers}`
);

this.value = StringUtils.fillIn(
GreenhouseEffectStrings.a11y.layerModel.observationWindow.numberOfAbsorbingLayersPatternStringProperty,
{
number: numberOfActiveAtmosphereLayers > 0 ?
numberOfActiveAtmosphereLayers :
GreenhouseEffectStrings.a11y.qualitativeAmountDescriptions.noStringProperty, // say 'no' for zero
s: numberOfActiveAtmosphereLayers === 1 ? '' : 's' // use plural except for a single layer
}
);
}
);
}
}

greenhouseEffect.register( 'InfraredAbsorbingLayersDescriptionProperty', InfraredAbsorbingLayersDescriptionProperty );
export default InfraredAbsorbingLayersDescriptionProperty;
2 changes: 1 addition & 1 deletion js/waves/view/WaveLandscapeObservationWindowPDOMNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class WaveLandscapeObservationWindowPDOMNode extends LandscapeObservationWindowP
EnergyRepresentation.WAVE
);

// if the sun isn't shining yet, hide this portion of the content
// If the sun isn't shining yet, hide this portion of the content.
this.sunlightItemNode.pdomVisible = isShining;
}
);
Expand Down

0 comments on commit f6662ad

Please sign in to comment.