Skip to content

Commit

Permalink
Add limiting bounds to ZoomInChartNode.ts view of the nuclide chart. #46
Browse files Browse the repository at this point in the history
.
  • Loading branch information
Luisav1 committed May 12, 2023
1 parent 5a53370 commit 2bb4415
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions js/chart-intro/view/ZoomInChartNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { Shape } from '../../../../kite/js/imports.js';
import Multilink from '../../../../axon/js/Multilink.js';
import AtomIdentifier from '../../../../shred/js/AtomIdentifier.js';
import { Color, Path } from '../../../../scenery/js/imports.js';
import Utils from '../../../../dot/js/Utils.js';

class ZoomInChartNode extends NuclideChartNode {

Expand All @@ -24,20 +25,21 @@ class ZoomInChartNode extends NuclideChartNode {

const squareLength = chartTransform.modelToViewDeltaX( 5 );

let borderPath: Path | null;
const borderPath = new Path( null, { stroke: Color.BLACK, lineWidth: 3 } );
this.addChild( borderPath );
Multilink.multilink( [ protonCountProperty, neutronCountProperty ], ( protonCount, neutronCount ) => {
const cellX = neutronCount;
const cellY = protonCount;
if ( borderPath ) {
this.removeChild( borderPath );
}
if ( AtomIdentifier.doesExist( protonCount, neutronCount ) ) {

// limit the bounds of the ZoomInChartNode to avoid showing white space
const clampedCellX = Utils.clamp( cellX, 2, 10 );
const clampedCellY = Utils.clamp( cellY, 2, 8 );

// clip chart to 2 cellLength's around current cell
const clipArea = Shape.rectangle( chartTransform.modelToViewX( cellX - 2 ), chartTransform.modelToViewY( cellY + 2 ),
const clipArea = Shape.rectangle( chartTransform.modelToViewX( clampedCellX - 2 ), chartTransform.modelToViewY( clampedCellY + 2 ),
squareLength, squareLength );
borderPath = new Path( clipArea, { stroke: Color.BLACK, lineWidth: 3 } );
this.addChild( borderPath );
borderPath.shape = clipArea;
this.clipArea = clipArea;
}
} );
Expand Down

0 comments on commit 2bb4415

Please sign in to comment.