QUnit.test( 'sibling positioning', function( assert ) { const rootNode = new Node( { tagName: 'div' } ); const display = new Display( rootNode ); // eslint-disable-line document.body.appendChild( display.domElement ); // test bounds are set for basic input elements const buttonElement = new Rectangle( 5, 5, 5, 5, { tagName: 'button' } ); const divElement = new Rectangle( 0, 0, 20, 20, { tagName: 'div', focusable: true } ); const inputElement = new Rectangle( 10, 3, 25, 5, { tagName: 'input', inputType: 'range' } ); rootNode.addChild( buttonElement ); rootNode.addChild( divElement ); rootNode.addChild( inputElement ); // udpdate so the display to position elements display.updateDisplay(); assert.ok( siblingBoundsCorrect( buttonElement ), 'button element child of root correctly positioned' ); assert.ok( siblingBoundsCorrect( divElement ), 'div element child of root correctly positioned' ); assert.ok( siblingBoundsCorrect( inputElement ), 'input element child of root correctly positioned' ); // test that bounds are set correctly once we have a hierarchy and add transformations rootNode.removeChild( buttonElement ); rootNode.removeChild( divElement ); rootNode.removeChild( inputElement ); rootNode.addChild( divElement ); divElement.addChild( buttonElement ); buttonElement.addChild( inputElement ); // arbitrary transformations down the tree (should be propagated to input element) divElement.setCenter( new Vector2( 50, 50 ) ); buttonElement.setScaleMagnitude( 0.89 ); inputElement.setRotation( Math.PI / 4 ); // udpdate so the display to position elements display.updateDisplay(); assert.ok( siblingBoundsCorrect( buttonElement ), 'button element descendant correctly positioned' ); assert.ok( siblingBoundsCorrect( inputElement ), 'input element descendant correctly positioned' ); // when inner content of an element changes, its client bounds change - make sure that the element still matches // the Node buttonElement.innerHTML = 'Some Test'; display.updateDisplay(); assert.ok( siblingBoundsCorrect( buttonElement ), 'button element descendant correclty positioned after inner content changed' ); // remove the display element so it doesn't interfere with qunit api document.body.removeChild( display.domElement ); } );
sensor.activeProperty.link( active => { if ( active ) { if ( backLayer.hasChild( temperatureAndColorSensorNode ) ) { backLayer.removeChild( temperatureAndColorSensorNode ); } sensorLayer.addChild( temperatureAndColorSensorNode ); } else { if ( sensorLayer.hasChild( temperatureAndColorSensorNode ) ) { sensorLayer.removeChild( temperatureAndColorSensorNode ); } backLayer.addChild( temperatureAndColorSensorNode ); } } );
model.savedQuadraticProperty.link( savedQuadratic => { // remove and dispose any previously-saved line if ( savedLineNode ) { allLinesParent.removeChild( savedLineNode ); savedLineNode.dispose(); savedLineNode = null; } if ( savedQuadratic ) { savedLineNode = new QuadraticNode( new Property( savedQuadratic ), model.graph.xRange, model.graph.yRange, model.modelViewTransform, viewProperties.equationForm, viewProperties.equationsVisibleProperty, { lineWidth: GQConstants.SAVED_QUADRATIC_LINE_WIDTH, preventVertexAndEquationOverlap: options.preventVertexAndEquationOverlap } ); // Add it in the foreground, so the user can see it. // See https://github.com/phetsims/graphing-quadratics/issues/36 allLinesParent.addChild( savedLineNode ); } } );