Skip to content

Commit

Permalink
Add generics to GroupItemOptions Node and ToggleNode, see #170
Browse files Browse the repository at this point in the history
  • Loading branch information
samreid committed May 10, 2023
1 parent 1fd1021 commit 11b7768
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 21 deletions.
18 changes: 5 additions & 13 deletions js/variability/view/VariabilityAccordionBox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@ import CAVColors from '../../common/CAVColors.js';
import CAVAccordionBox from '../../common/view/CAVAccordionBox.js';
import CAVConstants from '../../common/CAVConstants.js';
import CAVSceneModel from '../../common/model/CAVSceneModel.js';
import CAVPlotNode from '../../common/view/CAVPlotNode.js';

export default class VariabilityAccordionBox extends CAVAccordionBox {

// private plotNode: Node;
private plotToggleNode: ToggleNode<CAVSceneModel | null>;
private plotToggleNode: ToggleNode<CAVSceneModel, VariabilityPlotNode>;

public constructor( model: VariabilityModel, layoutBounds: Bounds2, tandem: Tandem, top: number ) {

Expand Down Expand Up @@ -139,14 +138,15 @@ export default class VariabilityAccordionBox extends CAVAccordionBox {
return model.selectedSceneModelProperty.value.madValueProperty.value;
} );

const readoutsToggleNode = new ToggleNode( model.selectedVariabilityProperty, [
// TODO: Why can't this infer the type parameter? See https://github.com/phetsims/center-and-variability/issues/170
const readoutsToggleNode = new ToggleNode<VariabilityMeasure>( model.selectedVariabilityProperty, [
{
value: VariabilityMeasure.RANGE,
tandemName: 'rangeReadoutToggleNode',
createNode: tandem => {
const rangeReadoutValueProperty = new DerivedProperty( [ rangeValueProperty ],
rangeValue => rangeValue === null ? '?' : `${rangeValue}`
);
);

return new VariabilityReadoutText( rangeReadoutValueProperty,
CenterAndVariabilityStrings.rangeEqualsValuePatternStringProperty, {
Expand All @@ -162,12 +162,9 @@ export default class VariabilityAccordionBox extends CAVAccordionBox {
tandemName: 'iqrReadoutToggleNode',
createNode: tandem => {
const textReadoutGroup = new VBox( {
// x: -110,
// y: this.centerY - 20,
align: 'left',
spacing: 10
} );
// this.addChild( textReadoutGroup );

const medianReadoutValueProperty = new DerivedProperty( [ medianValueProperty ],
medianValue => medianValue === null ? '?' : `${medianValue}`
Expand Down Expand Up @@ -225,12 +222,7 @@ export default class VariabilityAccordionBox extends CAVAccordionBox {
}

public alignWithPlayAreaNumberLineNode( x: number ): void {

// TODO: HACK ALERT, see https://github.com/phetsims/center-and-variability/issues/170
this.plotToggleNode.children.forEach( child => {
const plotNode = child as CAVPlotNode;
plotNode.alignWithPlayAreaNumberLineNode( x );
} );
this.plotToggleNode.nodes.forEach( plotNode => plotNode.alignWithPlayAreaNumberLineNode( x ) );
}
}

Expand Down
12 changes: 4 additions & 8 deletions js/variability/view/VariabilityPlotNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ import CAVPlotNode from '../../common/view/CAVPlotNode.js';
export type CAVPlotOptions = NodeOptions & PickRequired<NodeOptions, 'tandem'>;

export default class VariabilityPlotNode extends Node {
private toggleNode: ToggleNode<VariabilityMeasure | null>;
private toggleNode: ToggleNode<VariabilityMeasure, CAVPlotNode>;

public constructor( model: VariabilityModel, sceneModel: VariabilitySceneModel, providedOptions: CAVPlotOptions ) {
super( providedOptions );

const toggleNode = new ToggleNode( model.selectedVariabilityProperty, [ {
// TODO: Why can't it infer reasonable types here? See https://github.com/phetsims/center-and-variability/issues/170
const toggleNode = new ToggleNode<VariabilityMeasure, CAVPlotNode>( model.selectedVariabilityProperty, [ {
createNode: tandem => new RangeNode( model, sceneModel, {
parentContext: 'accordion',
tandem: tandem.createTandem( 'rangeNode' )
Expand Down Expand Up @@ -59,12 +60,7 @@ export default class VariabilityPlotNode extends Node {
}

public alignWithPlayAreaNumberLineNode( x: number ): void {

// TODO: This could be a lot better https://github.com/phetsims/center-and-variability/issues/170
this.toggleNode.children.forEach( child => {
const plotNode = child as CAVPlotNode;
plotNode.alignWithPlayAreaNumberLineNode( x );
} );
this.toggleNode.nodes.forEach( plotNode => plotNode.alignWithPlayAreaNumberLineNode( x ) );
}
}

Expand Down

0 comments on commit 11b7768

Please sign in to comment.