Skip to content

Commit

Permalink
Remove cellTextFontSize option from NuclideChartCell. Create nuclide …
Browse files Browse the repository at this point in the history
…chart in static function in NuclideChartNode. Create chartTransform in static function in NuclideChartAccordionBox. Create icon node for Nuclide Chart, CompleteNuclideChartIconNode. See #46.
  • Loading branch information
Luisav1 committed May 26, 2023
1 parent eac693c commit 79a3c1d
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 40 deletions.
28 changes: 28 additions & 0 deletions js/chart-intro/view/CompleteNuclideChartIconNode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2023, University of Colorado Boulder

/**
* Icon node for NuclideChart.
*
* @author Luisa Vargas
* @author Marla Schulz (PhET Interactive Simulations)
*/

import buildANucleus from '../../buildANucleus.js';
import NuclideChartNode from './NuclideChartNode.js';
import NuclideChartAccordionBox from './NuclideChartAccordionBox.js';
import { Node } from '../../../../scenery/js/imports.js';

class CompleteNuclideChartIconNode extends Node {

public constructor() {

const cellLayerNode = new Node();
const smallChartTransform = NuclideChartAccordionBox.getChartTransform( 5 );
NuclideChartNode.createNuclideChart( cellLayerNode, smallChartTransform, smallChartTransform.modelToViewDeltaX( 1 ) );

super( { children: [ cellLayerNode ] } );
}
}

buildANucleus.register( 'CompleteNuclideChartIconNode', CompleteNuclideChartIconNode );
export default CompleteNuclideChartIconNode;
22 changes: 12 additions & 10 deletions js/chart-intro/view/NuclideChartAccordionBox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,9 @@ class NuclideChartAccordionBox extends AccordionBox {
public constructor( protonCountProperty: TReadOnlyProperty<number>, neutronCountProperty: TReadOnlyProperty<number>,
minWidth: number, selectedNuclideChartProperty: TReadOnlyProperty<SelectedChartType> ) {

const getChartTransform = ( scaleFactor: number ) => new ChartTransform( {
viewWidth: BANConstants.CHART_MAX_NUMBER_OF_NEUTRONS * scaleFactor,
modelXRange: new Range( BANConstants.DEFAULT_INITIAL_NEUTRON_COUNT, BANConstants.CHART_MAX_NUMBER_OF_NEUTRONS ),
viewHeight: BANConstants.CHART_MAX_NUMBER_OF_PROTONS * scaleFactor,
modelYRange: new Range( BANConstants.DEFAULT_INITIAL_PROTON_COUNT, BANConstants.CHART_MAX_NUMBER_OF_PROTONS )
} );

const partialChartTransform = getChartTransform( 20 );
const focusedChartTransform = getChartTransform( 10 );
const zoomInChartTransform = getChartTransform( 30 );
const partialChartTransform = NuclideChartAccordionBox.getChartTransform( 20 );
const focusedChartTransform = NuclideChartAccordionBox.getChartTransform( 10 );
const zoomInChartTransform = NuclideChartAccordionBox.getChartTransform( 30 );

const nuclideChartAndNumberLines = new NuclideChartAndNumberLines( protonCountProperty, neutronCountProperty,
partialChartTransform );
Expand Down Expand Up @@ -99,6 +92,15 @@ class NuclideChartAccordionBox extends AccordionBox {
cornerRadius: BANConstants.PANEL_CORNER_RADIUS
} );
}

public static getChartTransform( scaleFactor: number ): ChartTransform {
return new ChartTransform( {
viewWidth: BANConstants.CHART_MAX_NUMBER_OF_NEUTRONS * scaleFactor,
modelXRange: new Range( BANConstants.DEFAULT_INITIAL_NEUTRON_COUNT, BANConstants.CHART_MAX_NUMBER_OF_NEUTRONS ),
viewHeight: BANConstants.CHART_MAX_NUMBER_OF_PROTONS * scaleFactor,
modelYRange: new Range( BANConstants.DEFAULT_INITIAL_PROTON_COUNT, BANConstants.CHART_MAX_NUMBER_OF_PROTONS )
} );
}
}

buildANucleus.register( 'NuclideChartAccordionBox', NuclideChartAccordionBox );
Expand Down
6 changes: 2 additions & 4 deletions js/chart-intro/view/NuclideChartCell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@

import { Color, Rectangle, RectangleOptions, TPaint } from '../../../../scenery/js/imports.js';
import buildANucleus from '../../buildANucleus.js';
import optionize from '../../../../phet-core/js/optionize.js';
import optionize, { EmptySelfOptions } from '../../../../phet-core/js/optionize.js';

type SelfOptions = {
cellTextFontSize: number;
};
type SelfOptions = EmptySelfOptions;

type NuclideChartCellOptions = SelfOptions & RectangleOptions;

Expand Down
62 changes: 36 additions & 26 deletions js/chart-intro/view/NuclideChartNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,35 +56,13 @@ class NuclideChartNode extends Node {
}, providedOptions );
super( options );

// keep track of the cells of the chart
this.cells = [];
const cellLength = chartTransform.modelToViewDeltaX( 1 );
const cellLayerNode = new Node();

// create and add the chart cells to the chart. row is proton number and column is neutron number.
chartTransform.forEachSpacing( Orientation.VERTICAL, 1, 0, 'strict', ( row, viewPosition ) => {
const populatedCellsInRow = POPULATED_CELLS[ row ];
const rowCells: ( NuclideChartCell | null )[] = [];
populatedCellsInRow.forEach( column => {

// get first decay in available decays to color the cell according to that decay type
const decayType = AtomIdentifier.getAvailableDecays( row, column )[ 0 ];

const color = AtomIdentifier.isStable( row, column ) ? BANColors.stableColorProperty.value :
decayType === undefined ? BANColors.unknownColorProperty.value : // no available decays, unknown decay type
DecayType.enumeration.getValue( decayType.toString() ).colorProperty.value;
// keep track of the cells of the chart
this.cells = NuclideChartNode.createNuclideChart( cellLayerNode, chartTransform, cellLength );

// create and add the NuclideChartCell
const cell = new NuclideChartCell( cellLength, row, column, decayType, {
fill: color,
cellTextFontSize: options.cellTextFontSize,
lineWidth: chartTransform.modelToViewDeltaX( BANConstants.NUCLIDE_CHART_CELL_LINE_WIDTH )
} );
cell.translation = new Vector2( chartTransform.modelToViewX( column ), viewPosition );
this.addChild( cell );
rowCells.push( cell );
} );
this.cells.push( rowCells );
} );
this.addChild( cellLayerNode );

const arrowNode = new ArrowNode( 0, 0, 0, 0, {
tailWidth: 3,
Expand Down Expand Up @@ -162,6 +140,38 @@ class NuclideChartNode extends Node {
}
} );
}

public static createNuclideChart( cellLayerNode: Node, chartTransform: ChartTransform, cellLength: number ): ( NuclideChartCell | null )[][] {
const cells: ( NuclideChartCell | null )[][] = [];

// create and add the chart cells to the chart. row is proton number and column is neutron number.
chartTransform.forEachSpacing( Orientation.VERTICAL, 1, 0, 'strict', ( row, viewPosition ) => {
const populatedCellsInRow = POPULATED_CELLS[ row ];
const rowCells: ( NuclideChartCell | null )[] = [];
populatedCellsInRow.forEach( column => {

// get first decay in available decays to color the cell according to that decay type
const decayType = AtomIdentifier.getAvailableDecays( row, column )[ 0 ];

const color = AtomIdentifier.isStable( row, column ) ? BANColors.stableColorProperty.value :
decayType === undefined ? BANColors.unknownColorProperty.value : // no available decays, unknown decay type
DecayType.enumeration.getValue( decayType.toString() ).colorProperty.value;

// create and add the NuclideChartCell
const cell = new NuclideChartCell( cellLength, row, column, decayType, {
fill: color,
lineWidth: chartTransform.modelToViewDeltaX( BANConstants.NUCLIDE_CHART_CELL_LINE_WIDTH )
} );
cell.translation = new Vector2( chartTransform.modelToViewX( column ), viewPosition );
cellLayerNode.addChild( cell );
rowCells.push( cell );
} );
cells.push( rowCells );
} );

return cells;
}

}

buildANucleus.register( 'NuclideChartNode', NuclideChartNode );
Expand Down

0 comments on commit 79a3c1d

Please sign in to comment.