Skip to content

Commit

Permalink
move 'Max EMF' display to PickupCoilDebuggerPanel, #66
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelzoom committed Jun 20, 2024
1 parent 40ef9b6 commit 8d60e54
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 42 deletions.
1 change: 1 addition & 0 deletions js/common/FELConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ const FELConstants = {
TITLE_FONT: TITLE_FONT,
CONTROL_FONT: CONTROL_FONT,
TICK_LABEL_FONT: TICK_LABEL_FONT,
DEVELOPER_CONTROL_FONT: new PhetFont( 12 ),

// Preferences
PREFERENCES_LABEL_FONT: new PhetFont( {
Expand Down
42 changes: 5 additions & 37 deletions js/common/view/FELDeveloperAccordionBox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import AccordionBox from '../../../../sun/js/AccordionBox.js';
import faradaysElectromagneticLab from '../../faradaysElectromagneticLab.js';
import { HBox, Node, Text, VBox } from '../../../../scenery/js/imports.js';
import { Node, Text, VBox } from '../../../../scenery/js/imports.js';
import FELConstants from '../../common/FELConstants.js';
import BooleanProperty from '../../../../axon/js/BooleanProperty.js';
import Tandem from '../../../../tandem/js/Tandem.js';
Expand All @@ -26,24 +26,20 @@ import NumberControl from '../../../../scenery-phet/js/NumberControl.js';
import PickupCoil from '../model/PickupCoil.js';
import Electromagnet from '../model/Electromagnet.js';
import { FELDeveloperNumberControl } from './FELDeveloperNumberControl.js';
import NumberDisplay from '../../../../scenery-phet/js/NumberDisplay.js';
import TReadOnlyProperty from '../../../../axon/js/TReadOnlyProperty.js';
import Range from '../../../../dot/js/Range.js';

const VBOX_SPACING = 15;

export default class FELDeveloperAccordionBox extends AccordionBox {

public static readonly CONTROL_FONT = new PhetFont( 12 );
public static readonly SUBTITLE_FONT = new PhetFont( {
size: 12,
size: FELConstants.DEVELOPER_CONTROL_FONT.size,
weight: 'bold'
} );

protected constructor( content: Node ) {

const titleText = new Text( 'Developer', {
font: FELConstants.CONTROL_FONT
font: FELConstants.DEVELOPER_CONTROL_FONT
} );

super( content, {
Expand Down Expand Up @@ -81,7 +77,6 @@ export default class FELDeveloperAccordionBox extends AccordionBox {
new Text( 'Pickup Coil', {
font: FELDeveloperAccordionBox.SUBTITLE_FONT
} ),
new MaxEMFDisplay( pickupCoil.emfProperty, pickupCoil.maxEMFProperty.range ),
new FELDeveloperNumberControl( 'Max EMF:', pickupCoil.maxEMFProperty, {
useCommaSeparator: true
} ),
Expand Down Expand Up @@ -120,40 +115,13 @@ export default class FELDeveloperAccordionBox extends AccordionBox {
class FELDeveloperCheckbox extends Checkbox {
public constructor( labelString: string, property: Property<boolean> ) {
const text = new Text( labelString, {
font: FELDeveloperAccordionBox.CONTROL_FONT
font: FELConstants.DEVELOPER_CONTROL_FONT
} );
super( property, text, {
boxWidth: new Text( 'X', { font: FELDeveloperAccordionBox.CONTROL_FONT } ).height,
boxWidth: new Text( 'X', { font: FELConstants.DEVELOPER_CONTROL_FONT } ).height,
tandem: Tandem.OPT_OUT
} );
}
}

class MaxEMFDisplay extends HBox {
public constructor( emfProperty: TReadOnlyProperty<number>, emfRange: Range, decimalPlaces = 0 ) {

const maxEMFProperty = new NumberProperty( emfProperty.value );
emfProperty.link( emf => {
if ( emf > maxEMFProperty.value ) {
maxEMFProperty.value = emf;
}
} );

const maxEMFText = new Text( 'Max EMF:', {
font: FELDeveloperAccordionBox.CONTROL_FONT
} );
const maxEMFNumberDisplay = new NumberDisplay( maxEMFProperty, emfRange, {
numberFormatter: value => FELDeveloperNumberControl.formatValue( value, decimalPlaces, true ),
textOptions: {
font: FELDeveloperAccordionBox.CONTROL_FONT
}
} );

super( {
children: [ maxEMFText, maxEMFNumberDisplay ],
spacing: 5
} );
}
}

faradaysElectromagneticLab.register( 'FELDeveloperAccordionBox', FELDeveloperAccordionBox );
6 changes: 3 additions & 3 deletions js/common/view/FELDeveloperNumberControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import Dimension2 from '../../../../dot/js/Dimension2.js';
import faradaysElectromagneticLab from '../../faradaysElectromagneticLab.js';
import StrictOmit from '../../../../phet-core/js/types/StrictOmit.js';
import optionize from '../../../../phet-core/js/optionize.js';
import FELDeveloperAccordionBox from './FELDeveloperAccordionBox.js';
import FELConstants from '../FELConstants.js';

const TICK_TEXT_OPTIONS = {
font: new PhetFont( 10 )
Expand Down Expand Up @@ -73,7 +73,7 @@ export class FELDeveloperNumberControl extends NumberControl {
delta: sliderStep,
layoutFunction: createLayoutFunction( resetButton ),
titleNodeOptions: {
font: FELDeveloperAccordionBox.CONTROL_FONT
font: FELConstants.DEVELOPER_CONTROL_FONT
},
sliderOptions: {
soundGenerator: null,
Expand All @@ -94,7 +94,7 @@ export class FELDeveloperNumberControl extends NumberControl {
numberFormatter: value => FELDeveloperNumberControl.formatValue( value, options.decimalPlaces, options.useCommaSeparator ),
maxWidth: 100,
textOptions: {
font: FELDeveloperAccordionBox.CONTROL_FONT
font: FELConstants.DEVELOPER_CONTROL_FONT
}
},
tandem: Tandem.OPT_OUT
Expand Down
17 changes: 15 additions & 2 deletions js/common/view/PickupCoilDebuggerPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import FELConstants from '../FELConstants.js';
import Utils from '../../../../dot/js/Utils.js';
import Tandem from '../../../../tandem/js/Tandem.js';
import DerivedStringProperty from '../../../../axon/js/DerivedStringProperty.js';
import NumberProperty from '../../../../axon/js/NumberProperty.js';

const PHI = '\u03A6'; // flux
const DELTA_PHI = `\u2206${PHI}`; // delta flux
Expand Down Expand Up @@ -65,6 +66,16 @@ export default class PickupCoilDebuggerPanel extends Panel {
const emfStringProperty = new DerivedStringProperty( [ pickupCoil.emfProperty ],
emf => `${Utils.toFixedNumber( emf, 0 ).toLocaleString()}` );

const maxEMFProperty = new NumberProperty( pickupCoil.emfProperty.value );
pickupCoil.emfProperty.link( emf => {
if ( emf > maxEMFProperty.value ) {
maxEMFProperty.value = emf;
}
} );

const maxEMFStringProperty = new DerivedStringProperty( [ maxEMFProperty ],
maxEMF => `${Utils.toFixedNumber( maxEMF, 0 ).toLocaleString()}` );

const titleText = new Text( 'Pickup Coil debugger', {
font: FELConstants.TITLE_FONT
} );
Expand All @@ -76,14 +87,16 @@ export default class PickupCoilDebuggerPanel extends Panel {
[
new RichText( `${PHI} =`, LABEL_TEXT_OPTIONS ),
new RichText( `${DELTA_PHI} =`, LABEL_TEXT_OPTIONS ),
new RichText( 'EMF =', LABEL_TEXT_OPTIONS )
new RichText( 'EMF =', LABEL_TEXT_OPTIONS ),
new RichText( 'Max EMF =', LABEL_TEXT_OPTIONS )
],

// Values
[
new RichText( fluxStringProperty, VALUE_TEXT_OPTIONS ),
new RichText( deltaFluxStringProperty, VALUE_TEXT_OPTIONS ),
new RichText( emfStringProperty, VALUE_TEXT_OPTIONS )
new RichText( emfStringProperty, VALUE_TEXT_OPTIONS ),
new RichText( maxEMFStringProperty, VALUE_TEXT_OPTIONS )
]
]
} );
Expand Down

0 comments on commit 8d60e54

Please sign in to comment.