Initializing help system before first use

Formatter

Data formatting and system default format definitions

Method summary

name description
formatEntityValue For a given entity convert the original value to the display value.
formatNumber Format a number using a specified format definition.
getFormattedLabel For a given entity in a scenario get the formatted label for the original value.
setEntityFormatter Attach a formatting function for a specific entity.

Members

members
format - {
type
string }
System default formats. Can be overridden globally.
details
Properties:
properties
Name Type Description
integer
type
string
Default formatting string used for integers.
decimal
type
string
Default formatting string used for decimal numbers.
Example
examples
insight.Formatter.format.decimal = '#.#' // display decimals with 1 point precision.

Methods

method
formatEntityValue ( entity, originalValue, key ) → {string}

For a given entity convert the original value to the display value.

Parameters:
params
Name Type Argument Description
entity
type
ModelEntity
The entity instance
originalValue
type
string
The original value
key
type
Array.<*>
optional  The array key for the value, if applicable
details
Returns:
returns table
Type Description
type
string
The formatted value
Example
examples
var view = insight.getView();
var entity = view.getApp().getModelSchema().getEntity(name);
insight.Formatter.formatEntityValue(entity, 1234);
Back to Top
method
formatNumber ( original, format, locale ) → {string}

Format a number using a specified format definition.

Parameters:
params
Name Type Argument Description
original
type
number | string
Original number
format
type
string
Format definition
locale
type
string
optional  Locale to use for formatting
details
Returns:
returns table
Type Description
type
string
The formatted number as a string. Empty string if original is null or undefined.
Example
examples
insight.Formatter.formatNumber(12.75, '00#'); // returns the string '013'
Back to Top
method
getFormattedLabel ( entity, scenario, originalValue, key ) → {string}

For a given entity in a scenario get the formatted label for the original value. Will discover associated label entity and use corresponding value from that.

Parameters:
params
Name Type Argument Description
entity
type
ModelEntity
The entity instance
scenario
type
Scenario
The scenario to use when formatting the value
originalValue
type
string
The original value
key
type
Array.<*>
optional  The array key for the value, if applicable
details
Returns:
returns table
Type Description
type
string
The formatted value
Example
examples
var view = insight.getView();
var entity = view.getApp().getModelSchema().getEntity(name);
// Scenario instance is passed in to ScenarioObserver#notify callbacks
insight.Formatter.getFormattedLabel(entity, scenario, value);
Back to Top
method
setEntityFormatter ( entity, formatter )

Attach a formatting function for a specific entity.

Parameters:
params
Name Type Description
entity
type
ModelEntity | string
Either an Insight entity or an entity name
formatter
type
function
The formatter function.

Callback arguments:
  • {*} value Original value as a primitive data type
  • {Array.<*>} [key] The array key for the value, if applicable
Callback return:
  • {*} The formatted value as a primitive type
details
Example
examples
function myFormatFunction(value, key) {
 // process value and return as formatted string.
}
insight.Formatter.setEntityFormatter(name, myFormatFunction);
Back to Top

© 2001-2020 Fair Isaac Corporation. All rights reserved. This documentation is the property of Fair Isaac Corporation (“FICO”). Receipt or possession of this documentation does not convey rights to disclose, reproduce, make derivative works, use, or allow others to use it except solely for internal evaluation purposes to determine whether to purchase a license to the software described in this documentation, or as otherwise set forth in a written software license agreement between you and FICO (or a FICO affiliate). Use of this documentation and the software described in it must conform strictly to the foregoing permitted uses, and no other use is permitted.