Non-standard data types used by the webcharts team.
npm install ni-data-typesThis repository contains support for non-standard Javascript data types needed for engineering and scientific applications.
Contains all the information needed to fully describe a NIType, as as an API to retrieve the information. It can be constructed from a JSON encoded string or a full notation object.
``javascript
var booleanType = new NIType('"Boolean"'); // A single boolean.
var arrayType = new NIType({name: 'Array', rank: 1, subtype:{name: 'Boolean'}}); // 1-D array of booleans.
var arraySubtype = arrayType.getSubtype(); // An instance of NIType
console.log(arraySubtype.isBoolean()); // true
console.log(booleanType.isBoolean()); // true
console.log(booleanType.equals(arraySubtype)); // true
console.log(booleanType.equals(arrayType)); // false
`
For more information, you can look at the docs of NIType.
Can be constructed from a string representing
* complex numbers with real part before imaginary part or imaginary part before real part
* complex numbers represented with scientific notation
* complex numbers whose real and/or imaginary parts contain metric (SI) prefixes, such as kilo (k) or mega (M).
* complex numbers with only real or imaginary part
* complex numbers containing NaN as imaginary part, real part, or both
* +/-infinity, +/-inf, +/-Infinity, +/-Inf
* complex numbers that have the imaginary part represented only as +/-i or i
Can be constructed from numbers
* first paramater value is used for the real part and the second one for the imaginary part
It throw errors for any type of invalid input
`javascript`
var complex = new NIComplex('1 + 2i');
var complex1 = new NIComplex(1, 2);
var complex2 = new NIComplex(1);
var wrongComplex = new NIComplex('not a number'); // will throw
Complex numbers are objects containing two IEEE754 numbers, realPart and imaginaryPart.
`javascript`
var complex = new NIComplex('1 + 2i');
var re = complex.realPart;
var im = complex.imaginaryPart;NITimestamp. High precision timestamps
A NITimestamp is a data structure used to represent time with the high precision needed by scientific and engineering applications. An NITimestamp is composed by a pair of:
seconds*, a integer number representing seconds passed since the _epoch_
fractions*, an integer number between 0 and 252 - 1 representing the fractions of seconds in the timestamp. A fraction is one second divided by 252.
The main design goals of the NITimestamp is interoperability with [LabVIEW Timestamp], and as a consequence:
1. the _epoch_ used in NITimestamps is the [LabVIEW epoch] (1 January 1904).
2. the serialization format of the NITimestamp is using Int64, UInt64
`javascript`
var timestamp = new NITimestamp(); // the epoch
var timestamp2 = new NITimestamp('0:0'); // the epoch
var timestamp3 = new NITimestamp(new Date(Date.now())); // current time
var timestamp4 = new NITimestamp(35.27); // 35.27 seconds past the epoch
var timestamp5 = new NITimestamp(timestamp); // copy a timestamp
The NITimestamp constructor can be called with no parameters or with different types of parameters:
1. a string in the format "123:567890" where
* the first part is an INT64 serialized to a decimal string, representing the nr. of seconds relative to _epoch_
* the second part is a UINT64 serialized to a decimal string, representing the fractional part of the seconds
2. a javascript Date
3. a Number, representing the seconds passed since the _epoch_
4. a NITimestamp.
A NIAnalogWaveform represents a series of analog data samples. The main use case for it is for samples acquired periodically with a constant time interval between them.
A NIColorValueConverters has static functions that allow conversion between formats like RGBA, ARGB and hexadecimal.
`javascript
var integerColor = window.NIColorValueConverters.rgbaToInteger('rgb(237, 12, 140, 1)'); // Returns 4281020467
var hexColor = window.NIColorValueConverters.argbIntegerColorToRgbaHexColor(integerColor); // Returns "#ED0C8CFF"
``
[LabVIEW epoch]: https://en.wikipedia.org/wiki/Epoch_(reference_date)
[LabVIEW Timestamp]: http://www.ni.com/tutorial/7900/en/