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
-
format - {
typestring }
-
System default formats. Can be overridden globally.details
Properties:
propertiesName Type Description integer typestringDefault formatting string used for integers. decimal typestringDefault formatting string used for decimal numbers. Example
examplesinsight.Formatter.format.decimal = '#.#' // display decimals with 1 point precision.
members
Methods
- formatEntityValue ( entity, originalValue, key ) → {string}
-
For a given entity convert the original value to the display value.
Parameters:
paramsName Type Argument Description entity typeModelEntityThe entity instance originalValue typestringThe original value key typeArray.<*>optional The array key for the value, if applicable detailsReturns:returns tableType Description typestringThe formatted value Example
examples
Back to Topvar view = insight.getView(); var entity = view.getProject().getModelSchema().getEntity(name); insight.Formatter.formatEntityValue(entity, 1234);
- formatNumber ( original, format, locale ) → {string}
-
Format a number using a specified format definition.
Parameters:
paramsName Type Argument Description original typenumber | stringOriginal number format typestringFormat definition locale typestringoptional Locale to use for formatting detailsReturns:returns tableType Description typestringThe formatted number as a string. Empty string if original is null or undefined. Example
examples
Back to Topinsight.Formatter.formatNumber(12.75, '00#'); // returns the string '013'
- 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:
paramsName Type Argument Description entity typeModelEntityThe entity instance scenario typeScenarioThe scenario to use when formatting the value originalValue typestringThe original value key typeArray.<*>optional The array key for the value, if applicable detailsReturns:returns tableType Description typestringThe formatted value Example
examples
Back to Topvar view = insight.getView(); var entity = view.getProject().getModelSchema().getEntity(name); // Scenario instance is passed in to ScenarioObserver#notify callbacks insight.Formatter.getFormattedLabel(entity, scenario, value);
- setEntityFormatter ( entity, formatter )
-
Attach a formatting function for a specific entity.
Parameters:
paramsName Type Description entity typeModelEntity | stringEither an Insight entity or an entity name formatter typefunctionThe formatter function. Callback arguments: - {*} value Original value as a primitive data type
- {Array.<*>} [key] The array key for the value, if applicable
- {*} The formatted value as a primitive type
detailsExample
examples
Back to Topfunction myFormatFunction(value, key) { // process value and return as formatted string. } insight.Formatter.setEntityFormatter(name, myFormatFunction);
method
method
method
method