Utility Functions
The following Javascript functions are provided as helper methods for formatting and extracting data from each callback or elsewhere within an application referencing the OAS Web HMI libraries.
OAS.init() : forces a reinitialization of the OAS_config for the entire page
Use OAS.init() after making any changes to OAS_config. For example, when altering any trend_binding features, you can then call OAS.init() to force the OAS_config to reload with the new settings.
OAS.Flot.buildTrendData(data) : convert trend data to Flot series data
- data: object
This utility converts the data returned in the trend callback into data series objects directly usable by the Flot charting library. This should only be executed within the context of a trend callback and only when using the Flot library.
OAS.Util.padleft(value, pad, len) : left-pad a string with another string
- value: string
The original string to be padded. This can also be anything that can be converted to a string, like a numeric.
- pad: string
The padding string, typically a single character (e.g. ‘0’ when padding numbers)
- len: number
The desired total length of the output string. For example, if you want to convert the number 9 to ‘009’ you would callOAS.Util.padleft(9,'0',3)
.
OAS.Util.formatDate(dt, format) : convert a Javascript Date object to a formatted string
- dt: date
The date to be converted.
- format: string
A standard date formatting string which replaces specific tokens with parts of the date and time. Valid tokens:
yyyy : 4-digit year yy : 2-digit year mm : 2-digit month (e.g. February = '02') dd : 2-digit day of the month HH : 2-digit hours (24 hour format) hh : 2-digit hours (12 hour format) MM : 2-digit minutes ss : 2-digit seconds aa : am/pm designator AA : AM/PM designator
Examples: (January 6, 1970 2:23 pm as date input)
"yyyy-mm-dd HH:MM:ss" > 1970-01-06 14:23:00 "mm/dd/yy hh:MM aa" > 01/06/1970 02:23 pm OAS.Trend.getTrendBinding(data)
- data: object
This utility returns an instance of a Trend Binding object given a set of data returned in the trend callback. This is useful for determining which chart and set of pens the data is for, since the trend binding calls are asynchronous.