Skip to content

Commit

Permalink
Implement addend equals zero scenarios, see: #40
Browse files Browse the repository at this point in the history
  • Loading branch information
marlitas committed Jan 28, 2025
1 parent 413525c commit 171e091
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions js/common/view/BarModelNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,25 +58,26 @@ export default class BarModelNode extends VBox {
numberVisibleProperty: model.rightAddendVisibleProperty
} );
const addendsNode = new Node( {
children: [ leftAddendRectangle, rightAddendRectangle ]
children: [ leftAddendRectangle, rightAddendRectangle ],
excludeInvisibleChildrenFromBounds: true
} );

/**
* Hook up the rectangles to listeners so that they update accordingly
*/
ManualConstraint.create( addendsNode, [ leftAddendRectangle, rightAddendRectangle ], ( leftAddendRectangleProxy, rightAddendRectangleProxy ) => {
rightAddendRectangleProxy.left = leftAddendRectangleProxy.right - LINE_WIDTH;
rightAddendRectangleProxy.left = leftAddendRectangleProxy.visible ? leftAddendRectangleProxy.right - LINE_WIDTH : totalRectangle.left;
} );
Multilink.multilink( [ model.totalProperty, model.leftAddendProperty, model.rightAddendProperty ], ( total, leftAddend, rightAddend ) => {

// We need to handle the case where the total is 0, because we can't divide by 0
if ( total !== 0 ) {
leftAddendRectangle.rectWidth = leftAddend / total * TOTAL_WIDTH;
leftAddendRectangle.visible = leftAddend > 0;
rightAddendRectangle.rectWidth = rightAddend / total * TOTAL_WIDTH;
rightAddendRectangle.visible = rightAddend > 0;
}
else {

//TODO: @CC how do we want this to look?
leftAddendRectangle.rectWidth = 0;
rightAddendRectangle.rectWidth = 0;
}
Expand Down

0 comments on commit 171e091

Please sign in to comment.