PhET-iO API Documentation

This document is a snapshot of all of the phet-io and simulation api for this given sha.

Current Type Documentation

Common Code

TAccordionBox (extends TNode)
A traditional accordionBox
events: expanded,collapsed
TAquaRadioButton (extends TRadioButton)
A radio button which looks like the Mac "Aqua" radio buttons
events: fired
setCircleButtonVisible: (TBoolean) ➞ TVoid
Sets whether the circular part of the radio button will be displayed.
TArray (extends TObject)
A wrapper for the built-in JS array type, with the element type specified.
TBarrierRectangle (extends TNode)
Shown when a dialog is present, so that clicking on the invisible barrier rectangle will dismiss the dialog
events: fired
TBoolean (extends TObject)
Wrapper for the built-in JS boolean type (true/false)
TBounds2 (extends TObject)
a 2-dimensional bounds rectangle
TBounds3 (extends TObject)
a 3-dimensional bounds (bounding box)
TButtonListener (extends TObject)
Button listener
events: up,over,down,out,fire
TCheckBox (extends TNode)
A traditional checkbox
events: toggled
isChecked: () ➞ TBoolean
Returns true if the checkbox is checked, false otherwise
link: (TFunctionWrapper) ➞ TVoid
Link a listener to the underlying checked TProperty. The listener receives an immediate callback with the current value (true/false)
setChecked: (TBoolean) ➞ TVoid
Sets whether the checkbox is checked or not
TColor (extends TObject)
A color, with rgba
TComboBox (extends TNode)
A traditional combo box
events: fired,popupShown,popupHidden
TComboBoxItemNode (extends TNode)
A traditional item node for a combo box
events: fired
TDerivedProperty (extends TProperty)
Like TProperty, but not settable. Instead it is derived from other TDerivedProperty or TProperty instances
events: changed
setValue: (TObject) ➞ TVoid
Errors out when you try to set a derived property.
TDialog (extends TPanel)
A dialog panel
TEvents (extends TObject)
Event system, with multiple channels defined by string keys
events: documentation,fromStateObject,typeName,methods,supertype,getMethodDeclaration,allMethods
addListener: (TString,TFunctionWrapper) ➞ TVoid
Adds a listener to the specified event channel
removeListener: (TString,TFunctionWrapper) ➞ TVoid
Removes a listener that was added with addListener
TFaucet (extends TNode)
Faucet that emits fluid, typically user-controllable
events: startTapToDispense,endTapToDispense
TFocus (extends TObject)
A wrapper type for the instance in the simulation which currently has keyboard focus.
TFont (extends TObject)
Font handling for text drawing. Options:
style: normal // normal | italic | oblique
variant: normal // normal | small-caps
weight: normal // normal | bold | bolder | lighter | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900
stretch: normal // normal | ultra-condensed | extra-condensed | condensed | semi-condensed | semi-expanded | expanded | extra-expanded | ultra-expanded
size: 10px // absolute-size | relative-size | length | percentage -- unitless number interpreted as px. absolute suffixes: cm, mm, in, pt, pc, px. relative suffixes: em, ex, ch, rem, vw, vh, vmin, vmax.
lineHeight: normal // normal | number | length | percentage -- NOTE: Canvas spec forces line-height to normal
family: sans-serif // comma-separated list of families, including generic families (serif, sans-serif, cursive, fantasy, monospace). ideally escape with double-quotes

TFunctionWrapper (extends TObject)
Wrapper for the built-in JS function type
THSlider (extends TNode)
A traditional slider component, with a knob and possibly tick marks
setMajorTicksVisible: (TBoolean) ➞ TVoid
Set whether the major tick marks should be shown
setMinorTicksVisible: (TBoolean) ➞ TVoid
Set whether the minor tick marks should be shown
THSliderTrack (extends TNode)
The track for a knob of a traditional slider
TJoistButton (extends TNode)
The buttons used in the home screen and navigation bar
events: fired
TMenuItem (extends TNode)
The item buttons shown in a popup menu
events: fired
TNavigationBarScreenButton (extends TNode)
A pressable button in the simulation's navigation bar
events: fired
TNode (extends TObject)
The base type for graphical and potentially interactive objects
addPickableListener: (TFunctionWrapper) ➞ TVoid
Adds a listener for when pickability of the node changes
addVisibleListener: (TFunctionWrapper) ➞ TVoid
Adds a listener for when visibility of the node changes
isPickable: () ➞ TBoolean
Gets whether the node is pickable (and hence interactive)
isVisible: () ➞ TBoolean
Gets a Boolean value indicating whether the node can be seen and interacted with
setOpacity: (TNumber) ➞ TVoid
Set opacity between 0-1 (inclusive)
setPickable: (TBoolean) ➞ TVoid
Set whether the node will be pickable (and hence interactive)
setRotation: (TNumber) ➞ TVoid
Set the rotation of the node, in radians
setVisible: (TBoolean) ➞ TVoid
Set whether the node will be visible (and interactive)
TNumber (extends TObject)
Wrapper for the built-in JS number type (floating point, but also represents integers)
TNumberControl (extends TNode)
A numeric readout with a background
TObject
The root of the wrapper object hierarchy
TObservableArray (extends TObject)
An array that sends notifications when its values have changed.
events: itemAdded,itemRemoved
addItemAddedListener: (TFunctionWrapper) ➞ TVoid
Add a listener that is called when an item is added to the observable array.
addItemRemovedListener: (TFunctionWrapper) ➞ TVoid
Add a listener that is called when an item is removed from the observable array.
getLength: () ➞ undefined
Get the number of elements in the observable array
TOnOffSwitch (extends TNode)
A traditional switch component
events: toggled
TOptionsDialog (extends TDialog)
A dialog panel
TPanel (extends TNode)
A container for other TNodes
TParticle (extends TObject)
The model for a single particle such as an electron, proton, or neutron.
TParticleAtom (extends TObject)
A model of an atom that tracks and arranges the subatomic particles, i.e. protons, neutrons, and electrons, of which it is comprised. When particles are added, they are moved into the appropriate places. This object also keeps track of things like atomic number, mass number, and charge.
TPeriodicTableCell (extends TObject)
undefined
events: fired
TPhETIO (extends TObject)
Mediator for the phet-io module, with systemwide methods for communicating with the sim or other globals
events: simStarted,state,stateDelta,frameCompleted,stepSimulation,inputEvent,displaySize
addExpressions: (TArray) ➞ TVoid
Set expressions to take effect before the simulation is launched, similar to phetioExpressions, see TObject
addInstanceAddedListener: (TFunctionWrapper) ➞ TVoid
Adds a listener that receives a callback whenever a new sim instance has been prepared for interoperability
addInstanceRemovedListener: (TFunctionWrapper) ➞ TVoid
Removes a listener that was added with addInstanceAddedListener
addPhETIOEventsListener: (TFunctionWrapper) ➞ TVoid
Adds a listener to the phetioEvents event channel, for data analysis
endEvent: (TNumber) ➞ TVoid
End a message
getPhETIOIDs: () ➞ TArray
Gets a list of all of the wrapped instances which are available for interoperability.
getRandomSeed: () ➞ TNumber
Get the random seed, used for replicable playbacks
getState: () ➞ TObject
Gets the full state of the simulation
getValues: (TArray) ➞ TObject
Get the current values for multiple Property/DerivedProperty at the same time. Useful for collecting data to be plotted, so values will be consistent.
invokeInputEvent: (TString) ➞ TVoid
Plays back a recorded input event into the simulation.
isInteractive: () ➞ TBoolean
Gets whether the sim can be interacted with (via mouse/touch).
launchSimulation: () ➞ TVoid
Finish launching the simulation, called from a wrapper after all cross-frame initialization is complete
rasterizeDisplay: (TFunctionWrapper) ➞ TVoid
Rasterize the display, asynchronously
setDisplaySize: (TNumber,TNumber) ➞ TVoid
set the size of the visible region for the simulation
setInteractive: (TBoolean) ➞ TVoid
Sets whether the sim can be interacted with (via mouse/touch).
setPlaybackMode: (TBoolean) ➞ TVoid
Disable the sim clock driver so that time will only pass as it is played back from a log file.
setRandomSeed: (TNumber) ➞ TVoid
Set the random seed, used for replicable playbacks
setSimStartedMetadata: (TObject) ➞ TVoid
Set additional data that is added to the simStarted event.
setState: (TObject) ➞ TVoid
Sets the full state of the simulation
simulateError: () ➞ TVoid
Simulate an error for testing purposes
startEvent: (TObject) ➞ TNumber
Begin a message
stepSimulation: (TNumber) ➞ TVoid
Steps one frame of the simulation.
triggerEvent: (TObject) ➞ TVoid
Start and end a message
TPhetMenu (extends TNode)
The PhET Menu in the bottom right of the screen
TProperty (extends TObject)
Model values that can send out notifications when the value changes. This is different from the traditional observer pattern in that listeners also receive a callback with the current value when the listeners are registered.
events: changed
getValue: () ➞ TObject
Gets the current value.
link: (TFunctionWrapper) ➞ TVoid
Add a listener which will be called when the value changes. The listener also gets an immediate callback with the current value.
setValue: (TObject) ➞ TVoid
Sets the value of the property, and triggers notifications if the value is different
unlink: (TFunctionWrapper) ➞ TVoid
Removes a listener
TPushButton (extends TNode)
A pressable button in the simulation
events: fired
addListener: (TFunctionWrapper) ➞ TVoid
Adds a listener that is called back when the button is pressed.
fire: () ➞ TVoid
Performs the action associated with the button
TRadioButton (extends TNode)
A traditional radio button
events: fired
TRadioButtonGroupMember (extends TNode)
A traditional radio button
events: fired
TRandom (extends TObject)
Generates pseudorandom values
TResetAllButton (extends TPushButton)
The round (typically orange) button that restores the simulation screen to its initial state
events: fired
TRoundMomentaryButton (extends TNode)
Button that performs an action while it is being pressed, and stops the action when released
events: pressed,released,releasedDisabled
TScreen (extends TObject)
A single screen for a PhET simulation
TScreenButton (extends TNode)
A pressable button in the simulation, in the home screen
events: fired
TSim (extends TObject)
The type for the simulation instance
events: simStarted
addEventListener: (TString,TFunctionWrapper) ➞ TVoid
Add an event listener to the sim instance
disableRequestAnimationFrame: () ➞ TVoid
Prevents the simulation from animating/updating
getScreenshotDataURL: () ➞ TString
Gets a base64 representation of a screenshot of the simulation as a data url
TSimIFrameAPI (extends TObject)
Instance of a SimIFrameAPI.
events: invoked
TSphereBucket (extends TObject)
A model of a bucket into which spherical objects can be placed.
TString (extends TObject)
Wrapper for the built-in JS string type
TTandem (extends TObject)
Tandems give sim elements their phet-io identifiers
TTandemEmitter (extends TObject)
Emitters indicate when events have occurred, with optional arguments describing the event
events: emitted
addListener: (TFunctionWrapper) ➞ TVoid
Add a listener which will be called when the emitter emits.
TTandemSimpleDragHandler (extends TObject)
Drag listener for objects that can be dragged by the user.
events: dragStarted,dragged,dragEnded
TText (extends TNode)
The tandem wrapper type for the scenery Text node
events: textChanged
addTextChangedListener: (TFunctionWrapper) ➞ TVoid
Add a listener for when the text has changed.
getFontOptions: () ➞ TFont
Get font options for this TText instance as an object
getMaxWidth: () ➞ TNumber
Get maximum width of text box in px
getText: () ➞ TString
Get the text content
setFontOptions: (TFont) ➞ TVoid
Set font options for this TText instance, e.g. {size: 16, weight: bold}
setMaxWidth: (TNumber) ➞ TVoid
Set maximum width of text box in px. If text is wider than maxWidth at its default font size, it is scaled down to fit.
setText: (TString) ➞ TVoid
Set the text content
TToggleButton (extends TNode)
A button that toggles state (in/out) when pressed
events: toggled
TVector2 (extends TObject)
A numerical object with x/y scalar values
TVector3 (extends TObject)
Basic 3-dimensional vector, represented as (x,y,z)
TVerticalCheckBoxGroup (extends TNode)
A vertical group of checkboxes
TVoid (extends TObject)
Type for which there is no instance, usually to mark functions without a return value
TWavelengthSlider (extends TNode)
A slider that shows wavelengths for selection

Specific Types for Faradays Law

There are no specific types for this sim

PhET-iO Query Parameters

{
    /**
     * For phet-io use relative path for finding the sim, instead of launching from phet-io.colorado.edu
     */
    relativeSimPath: { type: 'flag' },

    /**
     * when running a simulation using phetio.js, outputs states and deltas within the phetioEvents data stream, see phetio.js
     */
    phetioEmitDeltas: {
      type: 'boolean',
      defaultValue: false
    },

    /**
     * when emitting deltas using phetio.js (see phetioEmitDeltas) emit deltas that are empty, to simplify playback in some systems like Metacog.
     */
    phetioEmitEmptyDeltas: {
      type: 'boolean',
      defaultValue: false
    },

    /**
     * emit the Scenery input events such as pointer moves, presses, releases, dt values and window resizes
     * to support playback in a live simulation.
     */
    phetioEmitInputEvents: {
      type: 'boolean',
      defaultValue: false
    },

    /**
     * when running a simulation using phetio.js, outputs the state at the end of every frame\
     */
    phetioEmitStates: {
      type: 'boolean',
      defaultValue: false
    },

    /**
     * evaluate expressions on phet-io wrapper objects, like: ?phetioExpressions=[["beaker.beakerScreen.soluteSelector","setVisible",[true]]]
     */
    phetioExpressions: {
      type: 'string',
      defaultValue: '[]'
    },

    /**
     * Specifies where to log phetioEvents
     */
    phetioLog: {
      type: 'string',
      defaultValue: null,
      validValues: [
        null, // no logging
        'console', // stream to console in JSON format
        'lines' // stream colorized human-readable events to the console (Chrome and Firefox only)
      ]
    },

    /**
     * Causes a phet-io simulation to launch, even without a wrapper "go-ahead" step, see phet-io#181
     */
    phetioStandalone: { type: 'flag' },

    /**
     * When running as phet-io assertions are normally thrown when uninstrumented objects are encountered.
     * Setting this to false will allow the simulation to proceed.  Useful for partially instrumented simulations.
     */
    phetioValidateTandems: {
      type: 'boolean',
      defaultValue: true
    },

    /**
     * This is a debug tool for instrumentation. It is designed to be used to get a large list of instances that aren't
     * yet tandemized. See https://github.com/phetsims/phet-io/issues/1047 for more details.
     */
    printMissingTandems: {
      type: 'flag'
    },

    /**
     * Identifier for a single simulation run
     */
    sessionID: {
      type: 'string',
      defaultValue: null
    }
  }

PhET Query Parameters

{

    // Whether accessibility features are enabled or not.  Use this option to render the Parallel DOM for
    // keyboard navigation and screen reader based auditory descriptions.
    accessibility: { type: 'flag' },

    /**
     * Master volume control for the simulation (for Vibe sounds).
     * 1.0 is unity volume, 2.0 is double volume, etc.
     */
    audioVolume: {
      type: 'number',
      defaultValue: 1,
      isValidValue: function( value ) { return value >= 0; }
    },

    /**
     * specifies the brand that should be used in requirejs mode
     */
    brand: {
      type: 'string',
      defaultValue: 'adapted-from-phet',
      validValues: [ 'phet', 'phet-io', 'adapted-from-phet' ]
    },

    /**
     * When present, will trigger changes that are more similar to the build environment.
     * Right now, this includes computing higher-resolution mipmaps for the mipmap plugin.
     */
    buildCompatible: { type: 'flag' },

    /**
     * enables cache busting in requirejs mode.
     */
    cacheBuster: {
      type: 'boolean',
      defaultValue: true
    },

    /**
     * The color profile used at startup, relevant only for sims that support multiple color profiles.
     * Such sims are required to have a 'default' profile.  If a sim supports a 'project mode' then
     * it should also have a 'projector' profile.  Other profile names are not currently standardized.
     */
    colorProfile: {
      type: 'string',
      defaultValue: 'default'
    },

    /**
     * enables developer-only features, such as showing the layout bounds
     */
    dev: { type: 'flag' },

    /**
     * enables assertions
     */
    ea: { type: 'flag' },

    /**
     * Enables all assertions, as above but with more time-consuming checks
     */
    eall: { type: 'flag' },

    /**
     * Randomly sends mouse events to sim.
     */
    fuzzMouse: { type: 'flag' },

    /**
     * if fuzzMouse=true, this is the average number of mouse events to synthesize per frame.
     */
    fuzzRate: {
      type: 'number',
      defaultValue: 100,
      isValidValue: function( value ) { return value > 0; }
    },

    /**
     * When a simulation is run from the PhET iOS app, it should set this flag. It alters statistics that the sim sends
     * to Google Analytics and potentially other sources in the future.
     */
    'phet-app': { type: 'flag' },

    /**
     * When a simulation is run from the PhET Android app, it should set this flag. It alters statistics that the sim sends
     * to Google Analytics and potentially other sources in the future.
     */
    'phet-android-app': { type: 'flag' },

    /**
     * Launches the game-up-camera code which delivers images to requests in BrainPOP/Game Up/SnapThought
     */
    gameUp: { type: 'flag' },

    /**
     * Enables logging for game-up-camera, see gameUp
     */
    gameUpLogging: { type: 'flag' },

    /**
     * test with a specific locale
     */
    locale: {
      type: 'string',
      defaultValue: 'en'
    },

    /**
     * plays event logging back from the server, provide an optional name for the session
     */
    playbackInputEventLog: { type: 'flag' },

    /**
     * Fires a post-message when the sim is about to change to another URL
     */
    postMessageOnBeforeUnload: { type: 'flag' },

    /**
     * passes errors to test-sims
     */
    postMessageOnError: { type: 'flag' },

    /**
     * triggers a post-message that fires when the sim finishes loading, currently used by aqua test-sims
     */
    postMessageOnLoad: { type: 'flag' },

    /**
     * shows profiling information for the sim
     */
    profiler: { type: 'flag' },

    /**
     * adds a menu item that will open a window with a QR code with the URL of the simulation
     */
    qrCode: { type: 'flag' },

    /**
     * enables input event logging, provide an optional name for the session, log is available via PhET menu
     */
    recordInputEventLog: { type: 'flag' },

    /**
     * Specify a renderer for the Sim's rootNode to use.
     */
    rootRenderer: {
      type: 'string',
      defaultValue: null,
      validValues: [ null, 'canvas', 'svg', 'dom', 'webgl' ] // see Node.setRenderer
    },

    /**
     * Array of one or more logs to enable in scenery 0.2+, delimited with commas.
     * For example: ?sceneryLog=Display,Drawable,WebGLBlock results in [ 'Display', 'Drawable', 'WebGLBlock' ]
     */
    sceneryLog: {
      type: 'array',
      elementSchema: {
        type: 'string'
      },
      defaultValue: null
    },

    /**
     * Scenery logs will be output to a string instead of the window
     */
    sceneryStringLog: { type: 'flag' },

    /**
     * Indicates the screen that will be initially selected on the home screen.
     * If showHomeScreen is false, go immediately to this screen.
     * Like query parameter 'screens', the value is 1-based; e.g. 'screenIndex=2' selects the 2nd screen.
     * Use this query parameter only with multi-screen sims.
     */
    screenIndex: {
      type: 'number',
      defaultValue: 1
    },

    /**
     * Specifies the set of screens that appear in the sim, and their order.  Uses 1-based (not zero-based) and ","
     * delimited string such as "1,3,4" to get the 1st, 3rd and 4th screen.
     */
    screens: {
      type: 'array',
      elementSchema: {
        type: 'number'
      },
      defaultValue: null
    },

    /**
     * Displays an overlay of the current bounds of each CanvasNode
     */
    showCanvasNodeBounds: { type: 'flag' },

    /**
     * Displays an overlay of the current bounds of each scenery.FittedBlock
     */
    showFittedBlockBounds: { type: 'flag' },

    /**
     * if false, go immediately to screenIndex
     */
    showHomeScreen: {
      type: 'boolean',
      defaultValue: true
    },

    /**
     * Shows pointer areas as dashed lines. touchAreas are red, mouseAreas are blue.
     */
    showPointerAreas: { type: 'flag' },

    /**
     * Displays a semi-transparent cursor indicator for the location of each active pointer on the screen.
     */
    showPointers: { type: 'flag' },

    /**
     * Shows the visible bounds in ScreenView.js, for debugging the layout outside of the "dev" bounds
     */
    showVisibleBounds: { type: 'flag' },

    /**
     * override strings, value is JSON that is identical to string.json files
     */
    strings: {
      type: 'string',
      defaultValue: null
    },

    /**
     * Sets a string used for various i18n test.  The values are:
     *
     * double: duplicates all of the translated strings which will allow to see (a) if all strings
     *   are translated and (b) whether the layout can accommodate longer strings from other languages.
     *   Note this is a heuristic rule that does not cover all cases.
     *
     * long: an exceptionally long string will be substituted for all strings. Use this to test for layout problems.
     *
     * rtl: a string that tests RTL (right-to-left) capabilities will be substituted for all strings
     *
     * xss: tests for security issues related to https://github.com/phetsims/special-ops/issues/18,
     *   and running a sim should NOT redirect to another page. Preferably should be used for built versions or
     *   other versions where assertions are not enabled (brackets can cause issues for SubSupText, etc.)
     *
     * none|null: the normal translated string will be shown
     *
     * {string}: if any other string provided, that string will be substituted everywhere. This facilitates testing
     *   specific cases, like whether the word 'vitesse' would substitute for 'speed' well.  Also, using "/u20" it
     *   will show whitespace for all of the strings, making it easy to identify non-translated strings.
     */
    stringTest: {
      type: 'string',
      defaultValue: null
    },

    /**
     * Enables WebGL rendering. See https://github.com/phetsims/scenery/issues/289
     */
    webgl: {
      type: 'boolean',
      defaultValue: true
    }
  }