Skip to content

Commit

Permalink
reset a couple more things on the second screen, #167
Browse files Browse the repository at this point in the history
  • Loading branch information
zepumph committed Aug 25, 2023
1 parent c4f58a3 commit 242dd71
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 16 deletions.
2 changes: 2 additions & 0 deletions js/chart-intro/model/ChartIntroModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ class ChartIntroModel extends BANModel<ParticleNucleus> {
}
} );
super.reset();
this.selectedNuclideChartProperty.reset();
this.decayEquationModel.reset();

// Put this last to make sure that this.particleAtom can be cleared first (by supertype).
this.miniParticleAtom.clear();
Expand Down
6 changes: 6 additions & 0 deletions js/chart-intro/model/DecayEquationModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ class DecayEquationModel {
private getCurrentCellModel( cellModelArray: NuclideChartCellModel[][], protonNumber: number, massNumber: number ): NuclideChartCellModel | null {
return _.find( cellModelArray[ protonNumber ], cellModel => cellModel.neutronNumber === massNumber - protonNumber ) || null;
}

public reset(): void {
this.currentCellModelProperty.reset();
this.finalProtonNumberProperty.reset();
this.finalMassNumberProperty.reset();
}
}

buildANucleus.register( 'DecayEquationModel', DecayEquationModel );
Expand Down
41 changes: 25 additions & 16 deletions js/chart-intro/view/ChartIntroScreenView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import AlphaParticle from '../../common/model/AlphaParticle.js';
import BANQueryParameters from '../../common/BANQueryParameters.js';
import TinyProperty from '../../../../axon/js/TinyProperty.js';
import NuclearShellModelText from './NuclearShellModelText.js';
import Property from '../../../../axon/js/Property.js';

// types
export type NuclideChartIntroScreenViewOptions = BANScreenViewOptions;
Expand All @@ -59,6 +60,8 @@ class ChartIntroScreenView extends BANScreenView<ChartIntroModel> {

// positions and sizes particles in the miniParticleAtom
private readonly miniAtomMVT: ModelViewTransform2;
private readonly showMagicNumbersProperty: Property<boolean>;
private readonly nuclideChartAccordionBox: NuclideChartAccordionBox;

public constructor( model: ChartIntroModel, providedOptions?: NuclideChartIntroScreenViewOptions ) {

Expand Down Expand Up @@ -188,41 +191,41 @@ class ChartIntroScreenView extends BANScreenView<ChartIntroModel> {
this.addChild( rightDashedLine );

// Whether to show a special highlight for magic-numbered nuclides in the charts
const showMagicNumbersProperty = new BooleanProperty( false );
this.showMagicNumbersProperty = new BooleanProperty( false );

// create the nuclideChartAccordionBox
const nuclideChartAccordionBox = new NuclideChartAccordionBox(
this.nuclideChartAccordionBox = new NuclideChartAccordionBox(
this.model.particleAtom.protonCountProperty, this.model.particleAtom.neutronCountProperty, this.model.selectedNuclideChartProperty, this.model.decayEquationModel,
this.decayAtom.bind( this ), showMagicNumbersProperty, this.model.hasIncomingParticlesProperty, {
this.decayAtom.bind( this ), this.showMagicNumbersProperty, this.model.hasIncomingParticlesProperty, {
minWidth: periodicTableAndIsotopeSymbol.width
} );

// position and add the nuclideChartAccordionBox
nuclideChartAccordionBox.top = periodicTableAndIsotopeSymbol.bottom + CHART_VERTICAL_MARGINS;
nuclideChartAccordionBox.left = periodicTableAndIsotopeSymbol.left;
this.addChild( nuclideChartAccordionBox );
this.nuclideChartAccordionBox.top = periodicTableAndIsotopeSymbol.bottom + CHART_VERTICAL_MARGINS;
this.nuclideChartAccordionBox.left = periodicTableAndIsotopeSymbol.left;
this.addChild( this.nuclideChartAccordionBox );

// create and add the radio buttons that select the chart type view in the nuclideChartAccordionBox
const partialChartRadioButton = new RectangularRadioButtonGroup<SelectedChartType>(
const partialChartRadioButtonGroup = new RectangularRadioButtonGroup<SelectedChartType>(
this.model.selectedNuclideChartProperty, [
{ value: 'partial', createNode: () => new CompleteNuclideChartIconNode() },
{ value: 'zoom', createNode: () => new ZoomInNuclideChartIconNode() }
], {
left: nuclideChartAccordionBox.left,
top: nuclideChartAccordionBox.bottom + CHART_VERTICAL_MARGINS,
left: this.nuclideChartAccordionBox.left,
top: this.nuclideChartAccordionBox.bottom + CHART_VERTICAL_MARGINS,
orientation: 'horizontal',
radioButtonOptions: { baseColor: BANColors.chartRadioButtonsBackgroundColorProperty }
} );
this.addChild( partialChartRadioButton );
this.addChild( partialChartRadioButtonGroup );

// create and add the checkbox to show special highlight for magic-numbered nuclides in the charts
const showMagicNumbersCheckbox = new Checkbox( showMagicNumbersProperty,
const showMagicNumbersCheckbox = new Checkbox( this.showMagicNumbersProperty,
new Text( BuildANucleusStrings.magicNumbersStringProperty, { font: BANConstants.LEGEND_FONT, maxWidth: 145 } ), {
boxWidth: 15,
touchAreaYDilation: 4
} );
showMagicNumbersCheckbox.left = partialChartRadioButton.right + CHART_VERTICAL_MARGINS;
showMagicNumbersCheckbox.top = nuclideChartAccordionBox.bottom + CHART_VERTICAL_MARGINS;
showMagicNumbersCheckbox.left = partialChartRadioButtonGroup.right + CHART_VERTICAL_MARGINS;
showMagicNumbersCheckbox.top = this.nuclideChartAccordionBox.bottom + CHART_VERTICAL_MARGINS;
this.addChild( showMagicNumbersCheckbox );

// create and add the fullChartDialog and 'Full Chart' button
Expand All @@ -239,16 +242,16 @@ class ChartIntroScreenView extends BANScreenView<ChartIntroModel> {
listener: () => fullChartDialog.show()
} );
fullChartTextButton.left = showMagicNumbersCheckbox.left;
fullChartTextButton.bottom = partialChartRadioButton.bottom;
fullChartTextButton.bottom = partialChartRadioButtonGroup.bottom;
this.addChild( fullChartTextButton );

// add the particleView layer nodes after everything else so particles are in the top layer
this.addChild( this.particleAtomNode );
this.addChild( this.energyLevelLayer );

this.pdomPlayAreaNode.pdomOrder = this.pdomPlayAreaNode.pdomOrder!.concat( [
nuclideChartAccordionBox,
partialChartRadioButton,
this.nuclideChartAccordionBox,
partialChartRadioButtonGroup,
showMagicNumbersCheckbox,
fullChartTextButton
] );
Expand All @@ -258,6 +261,12 @@ class ChartIntroScreenView extends BANScreenView<ChartIntroModel> {
} );
}

protected override reset(): void {
this.showMagicNumbersProperty.reset();
this.nuclideChartAccordionBox.reset();
super.reset();
}

/**
* Returns whether the nucleon is within a rectangular capture radius defined by the left edge of the proton arrow
* buttons, the right edge of the neutron arrow buttons, below the periodic table, and above the arrow buttons.
Expand Down

0 comments on commit 242dd71

Please sign in to comment.