From 11b7768945037b9aab5413f4c7cb0117f2afa936 Mon Sep 17 00:00:00 2001 From: Sam Reid Date: Wed, 10 May 2023 07:07:16 -0600 Subject: [PATCH] Add generics to GroupItemOptions Node and ToggleNode, see https://github.com/phetsims/center-and-variability/issues/170 --- js/variability/view/VariabilityAccordionBox.ts | 18 +++++------------- js/variability/view/VariabilityPlotNode.ts | 12 ++++-------- 2 files changed, 9 insertions(+), 21 deletions(-) diff --git a/js/variability/view/VariabilityAccordionBox.ts b/js/variability/view/VariabilityAccordionBox.ts index 4c924815..05dcf4e3 100644 --- a/js/variability/view/VariabilityAccordionBox.ts +++ b/js/variability/view/VariabilityAccordionBox.ts @@ -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; + private plotToggleNode: ToggleNode; public constructor( model: VariabilityModel, layoutBounds: Bounds2, tandem: Tandem, top: number ) { @@ -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( model.selectedVariabilityProperty, [ { value: VariabilityMeasure.RANGE, tandemName: 'rangeReadoutToggleNode', createNode: tandem => { const rangeReadoutValueProperty = new DerivedProperty( [ rangeValueProperty ], rangeValue => rangeValue === null ? '?' : `${rangeValue}` - ); + ); return new VariabilityReadoutText( rangeReadoutValueProperty, CenterAndVariabilityStrings.rangeEqualsValuePatternStringProperty, { @@ -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}` @@ -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 ) ); } } diff --git a/js/variability/view/VariabilityPlotNode.ts b/js/variability/view/VariabilityPlotNode.ts index ef0bbcfb..16c5feba 100644 --- a/js/variability/view/VariabilityPlotNode.ts +++ b/js/variability/view/VariabilityPlotNode.ts @@ -23,12 +23,13 @@ import CAVPlotNode from '../../common/view/CAVPlotNode.js'; export type CAVPlotOptions = NodeOptions & PickRequired; export default class VariabilityPlotNode extends Node { - private toggleNode: ToggleNode; + private toggleNode: ToggleNode; 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( model.selectedVariabilityProperty, [ { createNode: tandem => new RangeNode( model, sceneModel, { parentContext: 'accordion', tandem: tandem.createTandem( 'rangeNode' ) @@ -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 ) ); } }