Skip to content

Commit

Permalink
Address REVIEW comment by creating a new variable to keep track of th…
Browse files Browse the repository at this point in the history
…e xPosition index. See #112.
  • Loading branch information
Luisav1 committed Aug 17, 2023
1 parent dfa7067 commit be21b34
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions js/chart-intro/view/NucleonShellView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import ParticleType from '../../common/model/ParticleType.js';
import Vector2 from '../../../../dot/js/Vector2.js';
import optionize, { EmptySelfOptions } from '../../../../phet-core/js/optionize.js';
import { FIRST_LEVEL_CAPACITY, ParticleShellPosition, SECOND_LEVEL_CAPACITY } from '../model/ParticleNucleus.js';
import EnergyLevelType from '../model/EnergyLevelType.js';

type EnergyLevelNodeOptions = EmptySelfOptions & NodeOptions;

Expand Down Expand Up @@ -64,24 +65,27 @@ class NucleonShellView extends Node {
// update the stroke color and width of the respective energy levels as the nucleon number changes
const boldEnergyLevelWidth = 4;
const defaultEnergyLevelWidth = 1;
let xPositionIndex; // the xPosition from 1 to 5 for the second and third energy levels
nucleonCountProperty.link( nucleonNumber => {
if ( nucleonNumber <= FIRST_LEVEL_CAPACITY ) {
energyLevels[ 0 ].stroke = Color.interpolateRGBA( emptyLayerColor, fullLayerColor, nucleonNumber / FIRST_LEVEL_CAPACITY );
const firstEnergyLevel = EnergyLevelType.NONE.yPosition; // set to first energy level where yPosition = 0
energyLevels[ firstEnergyLevel ].stroke = Color.interpolateRGBA( emptyLayerColor, fullLayerColor, nucleonNumber / FIRST_LEVEL_CAPACITY );

// if the energy level is full (2 particles on the lower energy level), double the lineWidth
energyLevels[ 0 ].lineWidth = nucleonNumber === FIRST_LEVEL_CAPACITY ? boldEnergyLevelWidth : defaultEnergyLevelWidth;
energyLevels[ firstEnergyLevel ].lineWidth = nucleonNumber === FIRST_LEVEL_CAPACITY ? boldEnergyLevelWidth : defaultEnergyLevelWidth;
}
else {
let energyLevelNumber = 1;
if ( nucleonNumber > SECOND_LEVEL_CAPACITY + FIRST_LEVEL_CAPACITY ) {
nucleonNumber -= SECOND_LEVEL_CAPACITY;
energyLevelNumber = FIRST_LEVEL_CAPACITY;
let energyLevelNumber = EnergyLevelType.FIRST.yPosition; // initialize to second energy level where yPosition = 1
xPositionIndex = nucleonNumber; // initialize to the current nucleonNumber
if ( nucleonNumber > ( SECOND_LEVEL_CAPACITY + FIRST_LEVEL_CAPACITY ) ) {
xPositionIndex = nucleonNumber - SECOND_LEVEL_CAPACITY;
energyLevelNumber = EnergyLevelType.SECOND.yPosition;
}
nucleonNumber -= FIRST_LEVEL_CAPACITY; // REVIEW: instead of mutating the listener variable, it is better to name a new one (less confusing that way)
energyLevels[ energyLevelNumber ].stroke = Color.interpolateRGBA( emptyLayerColor, fullLayerColor, nucleonNumber / SECOND_LEVEL_CAPACITY );
xPositionIndex = xPositionIndex - FIRST_LEVEL_CAPACITY;
energyLevels[ energyLevelNumber ].stroke = Color.interpolateRGBA( emptyLayerColor, fullLayerColor, xPositionIndex / SECOND_LEVEL_CAPACITY );

// if the energy level is full (6 particles on the upper and middle energy levels), double the lineWidth
energyLevels[ energyLevelNumber ].lineWidth = nucleonNumber === SECOND_LEVEL_CAPACITY ? boldEnergyLevelWidth : defaultEnergyLevelWidth;
energyLevels[ energyLevelNumber ].lineWidth = xPositionIndex === SECOND_LEVEL_CAPACITY ? boldEnergyLevelWidth : defaultEnergyLevelWidth;
}
} );
}
Expand Down

0 comments on commit be21b34

Please sign in to comment.