Provides access to a numeric value of a Subject. Has options for setting number of significant digits to show, and upper/lower limit on value. Default is 3 significant digits, lower limit of zero, and upper limit is infinity. See Parameter for more information.

See Internationalization for information about localized and language-independent strings.

Implements

Constructors

  • Parameters

    • subject: Subject

      the Subject whose value this ParameterNumber represents

    • name: string

      the language-independent name of this Parameter; the English name can be passed in here because it will be run thru Util.toName.

    • localName: string

      the localized name of this Parameter

    • getter: (() => number)

      A function with no arguments that returns the value of this Parameter

        • (): number
        • Returns number

    • setter: ((n) => void)

      A function with one argument that sets the value of this Parameter

        • (n): void
        • Parameters

          • n: number

          Returns void

    • Optional opt_choices: string[]

      the translated localized strings corresponding to the values (optional)

    • Optional opt_values: number[]

      the numbers corresponding to the choices that the parameter can be set to (optional). When specified, only these values are allowed.

    Returns ParameterNumber

Properties

choices_: string[] = []

the translated localized strings corresponding to the values

decimalPlaces_: number = -1

Fixed number of fractional decimal places to show, or –1 if variable.

getter_: (() => number)

A method of Subject with no arguments that returns the value of this Parameter

Type declaration

    • (): number
    • A method of Subject with no arguments that returns the value of this Parameter

      Returns number

setter_: ((n) => void)

A method of Subject with one argument that sets the value of this Parameter

Type declaration

    • (n): void
    • A method of Subject with one argument that sets the value of this Parameter

      Parameters

      • n: number

      Returns void

subject_: Subject

the Subject which provides notification of changes in this Parameter

units_: string = ''

units string such as ' (kg)', to be appended to name when displayed in a

values_: number[] = []

the integers corresponding to the choices

Methods

  • Returns the suggested number of decimal places to show or –1 if variable.

    Returns number

    suggested number of decimal places to show or –1 if variable

  • Returns the lower limit; the Parameter value is not allowed to be less than this, setValue will throw an Error in that case.

    Returns number

    the lower limit of the Parameter value

  • Name of this SubjectEvent, either the language-independent name for scripting purposes or the localized name for display to user.

    The language-independent name should be the same as the English version but capitalized and with spaces and dashes replaced by underscore, see Util.toName and nameEquals.

    Parameters

    • Optional opt_localized: boolean

      true means return the localized version of the name; default is false which means return the language independent name.

    Returns string

    name of this object

  • Returns the suggested number of significant digits to show, see setSignifDigits.

    Returns number

    suggested number of significant digits to show

  • Returns the units string such as " (kg)", to be appended to name when displayed in a user interface control.

    Returns string

  • Returns the upper limit; the Parameter value is not allowed to be greater than this, setValue will throw an Error in that case.

    Returns number

    the upper limit of the Parameter value

  • Returns the set of values corresponding to getChoices that this Parameter can be set to.

    Returns string[]

    set of values that this Parameter can be set to, in string form.

  • Returns whether the value is being automatically computed; setting the value of this Parameter has no effect.

    Examples of automatically computed Parameters: the variables that give the current energy of a simulation. Another example is when the size of a graph's SimView is under control of an AutoScale.

    Returns boolean

    whether the value is being automatically computed

  • Whether this SubjectEvent has the given name, adjusting for the transformation to a language-independent form of the name, as is done by Util.toName.

    Parameters

    • name: string

      the English or language-independent version of the name

    Returns boolean

    whether this SubjectEvent has the given name (adjusted to language-independent form)

  • Sets the choices and values associated with this Parameter. See Internationalization.

    Parameters

    • choices: string[]

      localized strings giving name of each choice

    • values: number[]

      the values corresponding to each choice

    • Optional opt_broadcast: boolean

      whether to broadcast this change to the Subject's Observers, default is true

    Returns void

    Throws

    if values is of different length than choices

  • Sets suggested number of decimal places to show.

    Parameters

    • decimals: number

      suggested number of decimal places to show, or –1 if variable

    Returns ParameterNumber

    this Parameter for chaining setters

  • Sets the value of this Parameter after converting the given string to the appropriate type (boolean, number or string).

    Parameters

    • value: string

      the value to set this Parameter to, in string form

    Returns void

    Throws

    if the string cannot be converted to the needed type

  • Sets the lower limit; the Parameter value is not allowed to be less than this, setValue will throw an Error in that case.

    Parameters

    • lowerLimit: number

      the lower limit of the Parameter value

    Returns ParameterNumber

    this ParameterNumber for chaining setters

    Throws

    if the value is currently less than the lower limit, or the lower limit is not a number

  • Sets suggested number of significant digits to show. This affects the number of decimal places that are displayed. Examples: if significant digits is 3, then we would show numbers as: 12345, 1234, 123, 12.3, 1.23, 0.123, 0.0123, 0.00123.

    Parameters

    • signifDigits: number

      suggested number of significant digits to show

    Returns ParameterNumber

    this ParameterNumber for chaining setters

  • Sets the upper limit; the Parameter value is not allowed to be more than this, setValue will throw an Error in that case.

    Parameters

    • upperLimit: number

      the upper limit of the Parameter value

    Returns ParameterNumber

    this ParameterNumber for chaining setters

    Throws

    if the value is currently greater than the upper limit, or the upper limit is not a number

  • Sets the value of this ParameterNumber.

    Parameters

    • value: number

      the value to set this ParameterNumber to

    Returns void

  • Returns a minimal string representation of this object, usually giving just identity information like the class name and name of the object.

    For an object whose main purpose is to represent another Printable object, it is recommended to include the result of calling toStringShort on that other object. For example, calling toStringShort() on a DisplayShape might return something like this:

    DisplayShape{polygon:Polygon{'chain3'}}
    

    Returns string

    a minimal string representation of this object.

Generated using TypeDoc