Skip to content

Commit

Permalink
Create DecayEquationView.ts and return the decayLikelihoodPercent alo…
Browse files Browse the repository at this point in the history
…ng with the decayType information in AtomIdentifier.js. See #46.
  • Loading branch information
Luisav1 committed Jul 5, 2023
1 parent 1db0593 commit 98092b7
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 7 deletions.
3 changes: 3 additions & 0 deletions build-a-nucleus-strings_en.json
Original file line number Diff line number Diff line change
Expand Up @@ -173,5 +173,8 @@
},
"axis.neutronNumber": {
"value": "Neutron Number"
},
"mostLikelyDecayPattern": {
"value": "Most likely decay ({{decayLikelihoodPercent}}%)"
}
}
4 changes: 3 additions & 1 deletion js/BuildANucleusStrings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ type StringsType = {
'protonNumberStringProperty': LocalizedStringProperty;
'neutronNumber': string;
'neutronNumberStringProperty': LocalizedStringProperty;
}
};
'mostLikelyDecayPattern': string;
'mostLikelyDecayPatternStringProperty': LocalizedStringProperty;
};

const BuildANucleusStrings = getStringModule( 'BUILD_A_NUCLEUS' ) as StringsType;
Expand Down
12 changes: 8 additions & 4 deletions js/chart-intro/model/NuclideChartCellModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,23 @@ class NuclideChartCellModel {

public readonly protonNumber: number;
public readonly neutronNumber: number;
public readonly decayType: DecayType | null;
public readonly decayType: DecayType | undefined;
public readonly colorProperty: ColorProperty;
public readonly decayTypeLikelihoodPercent: number | null;

public constructor( protonNumber: number, neutronNumber: number ) {

// get first decay in available decays to color the cell according to that decay type
const decayType = AtomIdentifier.getAvailableDecays( protonNumber, neutronNumber )[ 0 ];
// @ts-expect-error webstorm doesn't know that this is an object of { string: number }, it thinks it's { string: undefined }
const decayTypeAndPercent: { string: number } = AtomIdentifier.getAvailableDecaysAndPercents( protonNumber, neutronNumber )[ 0 ];

this.protonNumber = protonNumber;
this.neutronNumber = neutronNumber;
this.decayType = DecayType.enumeration.getValue( decayType );
this.decayType = decayTypeAndPercent !== undefined ? DecayType.enumeration.getValue( Object.keys( decayTypeAndPercent )[ 0 ] ) : undefined;
// @ts-expect-error webstorm doesn't know that decayTypeAndPercent[ this.decayType.name ] is a number and not 'any'
this.decayTypeLikelihoodPercent = this.decayType === undefined ? null : decayTypeAndPercent[ this.decayType.name ];
this.colorProperty = AtomIdentifier.isStable( protonNumber, neutronNumber ) ? BANColors.stableColorProperty :
decayType === undefined ? BANColors.unknownColorProperty : // no available decays, unknown decay type
this.decayType === undefined ? BANColors.unknownColorProperty : // no available decays, unknown decay type
this.decayType.colorProperty;
}
}
Expand Down
30 changes: 30 additions & 0 deletions js/chart-intro/view/DecayEquationView.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright 2023, University of Colorado Boulder

import buildANucleus from '../../buildANucleus.js';
import DecayEquationModel from '../model/DecayEquationModel.js';
import BuildANucleusStrings from '../../BuildANucleusStrings.js';
import StringUtils from '../../../../phetcommon/js/util/StringUtils.js';
import AtomIdentifier from '../../../../shred/js/AtomIdentifier.js';
import { Text } from '../../../../scenery/js/imports.js';

/**
* Node that represents the view of a decay equation.
*
* @author Luisa Vargas
* @author Marla Schulz (PhET Interactive Simulations)
*/

class DecayEquationView {

public constructor( decayEquationModel: DecayEquationModel ) {

const mostLikelyDecayString = new Text( StringUtils.fillIn( BuildANucleusStrings.mostLikelyDecayPattern, {
decayLikelihoodPercent: AtomIdentifier.getAvailableDecaysAndPercents()
} ) );
console.log( mostLikelyDecayString );

}
}

buildANucleus.register( 'DecayEquationView', DecayEquationView );
export default DecayEquationView;
4 changes: 2 additions & 2 deletions js/decay/model/DecayModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ class DecayModel extends BANModel<ParticleAtom> {
// function which would return whether a given nuclide (defined by the number of protons and neutrons) has a certain
// available decay type
const createDecayEnabledListener = ( protonCount: number, neutronCount: number, decayType: DecayType ): boolean => {
const decays = AtomIdentifier.getAvailableDecays( protonCount, neutronCount );
const decays = AtomIdentifier.getAvailableDecaysAndPercents( protonCount, neutronCount );

// temporarily disable the beta minus decay for U-237 since that freezes the sim. See https://github.com/phetsims/build-a-nucleus/issues/42.
if ( protonCount === 92 && neutronCount === 145 && decayType === DecayType.BETA_MINUS_DECAY ) {
return false;
}

return decays.includes( decayType.name );
return decays.find( decay => Object.keys( decay ).includes( decayType.name ) ) !== undefined;
};

// create the decay enabled properties
Expand Down

0 comments on commit 98092b7

Please sign in to comment.