UNPKG

ni-data-types

Version:

Non-standard data types used by the webcharts team.

3 lines (2 loc) 15.8 kB
!function(){"use strict";var o=Number.MAX_SAFE_INTEGER||9007199254740991,a=2082844800,u=function(t){var r,e,n,i,s;this.epochDiffInSeconds=a,"string"==typeof t?(i=t.split(":"),this.seconds=Math.floor(parseFloat(i[0])),0xfffffffffffff800<(s=parseFloat(i[1]))&&(s=0xfffffffffffff800),this.fractions=Math.ceil(s/2048)/(o+1)):t instanceof Date?(r=t.getTime(),e=Math.floor(r/1e3),this.seconds=e+this.epochDiffInSeconds,n=(r%1e3+1e3)%1e3,this.fractions=n/1e3):"number"==typeof t?(e=Math.floor(t),this.seconds=e,this.fractions=t-e):t instanceof u?(this.seconds=t.seconds,this.fractions=t.fractions):(this.seconds=0,this.fractions=0)},t=u.prototype;t.toString=function(){return Math.floor(this.seconds)+":"+Math.round(this.fractions*(o+1)*2048)},t.toJSON=function(){return this.toString()},t.toDate=function(){return new Date(1e3*(this.seconds-this.epochDiffInSeconds+this.fractions))},t.valueOf=function(){return this.seconds+this.fractions},t.toAbsoluteTime=function(){return this.seconds+this.fractions+62135596800-a},t.compare=function(t){return this.seconds<t.seconds?-1:this.seconds>t.seconds?1:this.fractions<t.fractions?-1:this.fractions>t.fractions?1:0},t.add=function(t){this.seconds+=Math.floor(t);var r=t-Math.floor(t);return 1<=(r+=this.fractions)&&(--r,this.seconds+=1),this.fractions=r,this},window.NITimestamp=u}(),function(){"use strict";var r=window.NITimestamp,e=function(t){if("string"==typeof t)try{t=JSON.parse(t)}catch(t){throw"Can't create an analog waveform from this value"}if(t instanceof e)this.t0=new r(t.t0||"0:0"),this.channelName=t.channelName,this.dt=t.dt,this.Y=t.Y;else if("object"==typeof t)this.t0=new r(t.t0||"0:0"),this.channelName=t.channelName,this.dt=t.dt||0,this.Y=t.Y;else{if(void 0!==t)throw"Can't create an analog waveform from this value";this.dt=0,this.Y=[],this.t0=new r}},t=e.prototype;t.sampleCount=function(){return this.Y.length},t.toTimeAndValueArray=function(){for(var t=[],r=0,e=this.t0;r<this.Y.length;r++,e=e.add(this.dt))t.push([e.toAbsoluteTime(),this.Y[r]]);return t},t.appendArray=function(t){if(Array.isArray(t))for(var r=0;r<t.length;r++)this.Y.push(t[r])},t.appendWaveform=function(t){var r;t instanceof e&&(t.dt!==this.dt?(this.t0=t.t0,this.dt=t.dt,this.Y=t.Y.slice(0)):(r=new window.NITimestamp(this.t0).add(this.dt*this.sampleCount()),0===t.t0.compare(r)?this.appendArray(t.Y):(this.t0=t.t0,this.dt=t.dt,this.Y=t.Y.slice(0))))},t.toJSON=function(){return{t0:this.t0.toString(),channelName:this.channelName,dt:this.dt,Y:this.Y}},window.NIAnalogWaveform=e}(),function(){"use strict";function t(){}t.isCssColorInRGBAFormat=function(t){return(t=t.trim()).startsWith("rgb")},t.isCssColorInHexFormat=function(t){return(t=t.trim()).startsWith("#")},t.isCssColorInRGBAOrHexFormat=function(t){return this.isCssColorInRGBAFormat(t)||this.isCssColorInHexFormat(t)},t.ARGBIntegerToCssRGBA=function(t){var r=(t>>>=0)>>>24;return"rgba("+[(16711680&t)>>>16,(65280&t)>>>8,255&t,r=Number((r/255).toFixed(2))].join(",")+")"},t.ARGBIntegerToCssHex=function(t){var r=255&(t>>>=0),e=(65280&t)>>>8,n=(16711680&t)>>>16,i=t>>>24;return 1===(n=n.toString(16)).length&&(n="0"+n),1===(e=e.toString(16)).length&&(e="0"+e),1===(r=r.toString(16)).length&&(r="0"+r),1===(i=i.toString(16)).length&&(i="0"+i),("#"+n+e+r+i).toUpperCase()},t.cssRGBAToARGBInteger=function(t){var r=function(t){if(0===t.indexOf("rgb"))return-1===t.indexOf("rgba")&&(t+=",1"),t.match(/[.\d]+/g).map(function(t){return+Number(t)})}(t=t.trim()),e=255&r[0],n=255&r[1],i=255&r[2];return((255&Math.round(255*r[3]))<<24)+(e<<16)+(n<<8)+i>>>0},t.cssRGBAToCssHex=function(t){t=t.trim();var r=this.cssRGBAToARGBInteger(t);return this.ARGBIntegerToCssHex(r)},t.cssHexToARGBInteger=function(t){var r=(t=t.trim()).substring(1).split(""),e=["f","f"];return 3===r.length?r=[r[0],r[0],r[1],r[1],r[2],r[2]]:8===r.length&&(e=[r[6],r[7]],r=r.slice(0,6)),r=e.join("")+r.join(""),parseInt(r,16)},t.cssHexToCssRGBA=function(t){t=t.trim();var r=this.cssHexToARGBInteger(t);return this.ARGBIntegerToCssRGBA(r)},t.cssColorToARGBInteger=function(t){return this.isCssColorInRGBAFormat(t)?this.cssRGBAToARGBInteger(t):this.isCssColorInHexFormat(t)?this.cssHexToARGBInteger(t):void 0},window.NIColorValueConverters=t}(),function(){"use strict";window.NIComplex=function(t,r){if("string"==typeof t){var e=this.parseFromString(t);this.realPart=e[0],this.imaginaryPart=e[1]}else{if("number"!=typeof t)throw new Error("Can't create complex number");if(this.realPart=t,"number"==typeof r)this.imaginaryPart=r;else{if(void 0!==r)throw new Error("Can't create complex number: invalid imaginary part");this.imaginaryPart=0}}};function h(t){var r;if(""===t)return 0;if(c.test(t))return NaN;if(-1===t.search(/[eE]/)){if(!e.test(t)&&!a.test(t))throw new Error("Invalid real part format");r=parseFloat(t)}else{if(!s.test(t))throw new Error("Invalid real part scientific notation");r=parseFloat(t)}return r}function l(t){var r;if(""===t)return 0;if(c.test(t))return NaN;var e=t.slice(0,-1);if(-1===t.search(/[eE]/)){if(!n.test(t)&&!u.test(t))throw new Error("Invalid imaginary part format");if(f.test(t))return parseFloat(e+"1");r=parseFloat(e)}else{if(!o.test(t))throw new Error("Invalid imaginary part scientific notation");r=parseFloat(e)}return r}var i=/\s+/g,p=/([^eE][-+])|([eE][-+][iInN])/,e=/^[-+]?([0-9]+|[0-9]+\.|[0-9]*\.[0-9]+)$/,n=/^[-+]?([0-9]*|[0-9]+\.|[0-9]*\.[0-9]+)i$/,s=/^[-+]?([0-9]+|[0-9]+\.|[0-9]+\.|[0-9]*\.[0-9]+)[eE][-+]?[0-9]+$/,o=/^[-+]?([0-9]+|[0-9]+\.|[0-9]+\.|[0-9]*\.[0-9]+)[eE][-+]?[0-9]+i$/,a=/^[-+]?Infinity$/,u=/^[-+]?Infinityi$/,d=/[iI]nf(inity)?/g,f=/^[-+]?i$/,c=/^[-+]?NaNi?$/,m=/^[-+]?([0-9]+|[0-9]+\.[0-9]+)([eE][-+]?[0-9]+)?[-+]([0-9]+|[0-9]+\.[0-9]+)([eE][-+]?[0-9]+)?i$/,y=/^[+\-]?(?:0|[1-9]\d*)(?:\.\d*)?(?:[eE][+\-]?\d+)?$/,g=/^[+\-]?((?:0|[1-9]\d*)(?:\.\d*)?(?:[eE][+\-]?\d+)?)?i$/,w=/^([+\-]?(?:0|[1-9]\d*)(?:\.\d*)?(?:[eE][+\-]?\d+)?)(Y|Z|E|P|T|G|M|k|c|m|u|n|p|f|a|z|y){1}(?!i)$/,I=/^([+\-]?(?:0|[1-9]\d*)(?:\.\d*)?(?:[eE][+\-]?\d+)?)(Y|Z|E|P|T|G|M|k|c|m|u|n|p|f|a|z|y){1}i$/,N=/^([+\-]?(?:0|[1-9]\d*)(?:\.\d*)?(?:[eE][+\-]?\d+)?E)(?!i)([+\-]?(?:0|[1-9]\d*)(?:\.\d*)?(?:[eE][+\-]?\d+)?E)i$/,v=/^([+\-]?(?:0|[1-9]\d*)(?:\.\d*)?(?:[eE][+\-]?\d+)?E)i([+\-]?(?:0|[1-9]\d*)(?:\.\d*)?(?:[eE][+\-]?\d+)?E)$/,t=window.NIComplex.prototype,A=function(t){var r=w.exec(t),e=r[1],n=r[2];return parseFloat(e)*parseFloat("1e"+{Y:24,Z:21,E:18,P:15,T:12,G:9,M:6,k:3,c:-2,m:-3,u:-6,n:-9,p:-12,f:-15,a:-18,z:-21,y:-24}[n])};t.parseFromString=function(t){if(t=t.replace(i,""),y.test(t))return[parseFloat(t),0];if(g.test(t)){var r=t.slice(0,-1);return f.test(t)&&(r+="1"),[0,parseFloat(r)]}return m.test(t)?(n=(e=t).search(p),[parseFloat(e.substring(0,n+1)),parseFloat(e.substring(n+1,e.length-1))]):function(t){var r,e;if(""===t||null==t)throw new Error("Invalid number format");if(t=t.replace(d,"Infinity"),N.test(t)){var n=(s=N.exec(t))[1],i=s[2];return[A(n),A(i)]}if(v.test(t)){var s,n=(s=v.exec(t))[2],i=s[1];return[A(n),A(i)]}var o=t.search(p);o<t.search(/i[-+]|i$/)?(r=t.substring(0,o+1),e=t.substring(o+1)):(e=t.substring(0,o+1),r=t.substring(o+1));var a,u,f=w.test(r),c=I.test(e);if(f&&(a=A(r),isNaN(a)))throw new Error("Invalid real part format");if(c&&(u=A(e.slice(0,e.length-1)),isNaN(u)))throw new Error("Invalid imaginary part format");return void 0!==a&&void 0!==u?[a,u]:void 0!==a?[a,l(e)]:void 0!==u?[h(r),u]:[h(r),l(e)]}(t);var e,n},t.compare=function(t){var r=Math.sqrt(Math.pow(t.realPart,2)+Math.pow(t.imaginaryPart,2)),e=Math.sqrt(Math.pow(this.realPart,2)+Math.pow(this.imaginaryPart,2));return r<e?1:e<r?-1:0},t.toString=function(){return 0<=this.imaginaryPart?this.realPart+" + "+this.imaginaryPart+"i":this.realPart+" - "+Math.abs(this.imaginaryPart)+"i"}}(),function(){"use strict";window.NINumericFormatters=function(){};function h(t){var r=t;"string"!=typeof t&&(r=t.toString());var e="";-1!==r.indexOf("e")&&(e=r.substring(r.indexOf("e"),r.length),r=r.substring(0,r.indexOf("e")));var n=r.indexOf(".");if(-1!==n){for(var i=r.lastIndexOf("0");i===r.length-1;)i=(r=r.slice(0,-1)).lastIndexOf("0");n===r.length-1&&(r=r.slice(0,-1))}return("0"!==r&&"-0"!==r?r:"0")+e.toUpperCase()}var t=window.NINumericFormatters.prototype;t.toSiNotation=function(t,r){var e,n,i=0;if(isFinite(r)&&null!==r&&(i=20<r?20:r<0?0:r),0===t)return"0";if(null==t)return null===t?"null":"undefined";if(!isFinite(t))return isNaN(t)?"NaN":t.toString();var s,o,a,u=Math.floor((a=Math.abs(t),Math.log(a)*Math.LOG10E));o=8,3<=(s=u)?o=24<=s?16:Math.floor(s/3)+8:(s<=-3&&(o=s<=-24?0:Math.round((s-1)/3)+8),-2!==s&&-1!==s||(o=7)),e=t/(n={conversion:parseFloat("1e"+3*(o-8)),extension:["y","z","a","f","p","n","μ","m","","k","M","G","T","P","E","Z","Y"][o]}).conversion,(45<=u||u<=-45)&&(e=e.toExponential(i)),-1===e.toString().indexOf("e")&&(e=e.toFixed(i));var f=h(e),c="";return"0"!==f&&"-0"!==f&&(c=n.extension),f+c},t.toDecPrecisionNotation=function(t,r){return null==t?null===t?"null":"undefined":isFinite(t)?(s=isFinite(r)&&null!==r?(n=(e=Math.abs(t).toString()).indexOf("."),i=-1!==e.indexOf("e")||-1!==e.indexOf("E"),(!(-1!==n&&n<r)||i)&&(r<1||21<r||r>e.length)?t.toPrecision():t.toPrecision(r)):t.toPrecision(),h(s)):isNaN(t)?"NaN":t.toString();var e,n,i,s},t.toDecFixedNotation=function(t,r){if(null==t)return null===t?"null":"undefined";if(!isFinite(t))return isNaN(t)?"NaN":t.toString();var e="",n=t;t<0&&(e="-",n=Math.abs(t));return e+(!isFinite(r)||null===r||r<0||20<r?n.toFixed():n.toFixed(r)).toUpperCase()}}(),function(){function r(t){return t===l.SINGLE||t===l.DOUBLE}function e(t){switch(t){case l.INT8:case l.INT16:case l.INT32:case l.INT64:return!0;default:return!1}}function n(t){switch(t){case l.UINT8:case l.UINT16:case l.UINT32:case l.UINT64:return!0;default:return!1}}function i(t){return t===l.INT64||t===l.UINT64}function s(t){return e(t)||n(t)}function o(t){return t===l.COMPLEXSINGLE||t===l.COMPLEXDOUBLE}function a(t){return s(t)||o(t)||r(t)}function u(t){if(a(t))return!1;switch(t){case l.VOID:case l.BOOLEAN:case l.STRING:case l.PATH:case l.TIMESTAMP:case l.DIGITALWAVEFORM:return!1}return!0}function f(t){if(r=t,e=1,Object.keys(r).length!==e)throw new Error(t.name+' must only have the property "name".');var r,e}function c(t){var r=t.subtype;if(!1==(r.name!==l.ARRAY))throw new Error("Invalid Array subtype: "+r.name);p(r);var e=t.rank;if("number"!=typeof e||isNaN(e)||e<=0)throw new Error('Array type property "rank" must be an integer greater than 0.');var n=t.size;if(void 0!==n){if(!1===Array.isArray(n))throw new Error('Array type property "size" must be an array of integers.');if(!1===n.reduce(function(t,r){return t&&"number"==typeof r&&0<=r},!0))throw new Error('Array type property "size" must contain only natural numbers.')}}function h(t){return null===t||"object"!=typeof t||u(t.name)?t:t.name}function t(t,r){return"subtype"===t||""===t?Array.isArray(r)?r.map(h):h(r):r}var l=Object.freeze({VOID:"Void",BOOLEAN:"Boolean",UINT8:"UInt8",UINT16:"UInt16",UINT32:"UInt32",UINT64:"UInt64",INT8:"Int8",INT16:"Int16",INT32:"Int32",INT64:"Int64",SINGLE:"Single",DOUBLE:"Double",COMPLEXSINGLE:"ComplexSingle",COMPLEXDOUBLE:"ComplexDouble",STRING:"String",PATH:"Path",TIMESTAMP:"Timestamp",ENUM:"Enum",CLUSTER:"Cluster",ARRAY:"Array",ANALOGWAVEFORM:"AnalogWaveform",DIGITALWAVEFORM:"DigitalWaveform"}),p=function(t){if(null===t||"object"!=typeof t)throw new Error("Descriptor should be a JSON encoded string or a valid format Object. Value found: "+t);var r=t.name;if(u(r))switch(r){case l.ENUM:!function(t){var r=t.subtype;if(null===r||"object"!=typeof r)throw new Error("Enum subtype must be a valid descriptor.");if(!1===n(r.name)||!0===i(r.name))throw new Error("Enum unsupported subtype: "+r.name)}(t);break;case l.ARRAY:c(t);break;case l.CLUSTER:!function(t){var r=t.fields,e=t.subtype;if(!1===Array.isArray(r))throw new Error('Cluster type must have a "fields" property of type array.');if(!1===r.reduce(function(t,r){return t&&"string"==typeof r},!0))throw new Error('Cluster type property "fields", must be an array of strings.');if(void 0!==e){if(!1===Array.isArray(e))throw new Error('Cluster type property "subtype" must be an array of types.');if(r.length!==e.length)throw new Error('Cluster properties "fields" and "subtype", must be arrays with the same length.');var n=0;try{for(;n<e.length;n++){var i=e[n];p(i)}}catch(t){throw new Error('Cluster property "subtype" contains an invalid type descriptor.\n'+t.message)}}}(t);break;case l.ANALOGWAVEFORM:!function(t){var r=t.subtype;if(void 0===r)throw new Error(l.ANALOGWAVEFORM+' must have a property called "subtype".');if(!1===a(r.name))throw new Error(l.ANALOGWAVEFORM+" subtype only accepts numerics. "+r.name+" was found instead.")}(t);break;default:throw new Error("Unknown type: "+r)}else f(t)},d=function(t){if("string"==typeof t)return{name:t};for(var r in t){var e;t.hasOwnProperty(r)&&(e=t[r],"subtype"===r&&(Array.isArray(e)?t[r]=e.map(d):t[r]=d(e)))}return t},m=function(t){var r,e,n=("string"==typeof(r=t)&&(e=u(r)?JSON.parse(r):r),null!==r&&"object"==typeof r&&(e=r),e=d(e));p(n),this._descriptor=n},y=m.prototype;!function(t){var r,e=t.prototype;for(var n in l){l.hasOwnProperty(n)&&(e["is"+(r=l[n])]=function(t){function r(){return this._descriptor.name===t}try{Object.defineProperty(r,"name",{value:"is"+t})}catch(t){}return r}(r))}}(m),y.toJSON=function(){return JSON.stringify(this._descriptor)},y.toShortJSON=function(){return JSON.stringify(this._descriptor,t)},y.isNumeric=function(){return a(this._descriptor.name)},y.isFloat=function(){return r(this._descriptor.name)},y.isSignedInteger=function(){return e(this._descriptor.name)},y.isUnsignedInteger=function(){return n(this._descriptor.name)},y.is64BitInteger=function(){return i(this._descriptor.name)},y.isInteger=function(){return s(this._descriptor.name)},y.isComplex=function(){return o(this._descriptor.name)},y.isTimeStamp=function(){return this._descriptor.name===l.TIMESTAMP},y.isAggregateType=function(){return u(this._descriptor.name)},y.makeArray=function(t,r){if(this.isArray())throw new Error("Not possible to create an array from an array.");void 0===t&&(t=1);var e=JSON.parse(this.toShortJSON());return new m({name:l.ARRAY,rank:t,subtype:e,size:r})},y.getName=function(){return this._descriptor.name},y.getSubtype=function(){if(void 0!==this._nisubtype)return this._nisubtype;var t=this._descriptor.subtype;return Array.isArray(t)?this._nisubtype=t.map(function(t){return new m(t)}):"object"==typeof t&&null!==t&&(this._nisubtype=new m(t)),this._nisubtype},y.getRank=function(){return this._descriptor.rank},y.getSize=function(){return this._descriptor.size},y.getFields=function(){return this._descriptor.fields},y.equals=function(t){return t instanceof m&&(t.getName()===this.getName()&&(a=t.getFields(),u=this.getFields(),!(Array.isArray(a)&&Array.isArray(u)?a.length!==u.length||!a.reduce(function(t,r,e){return t&&r===u[e]},!0):a!==u)&&(s=t.getSubtype(),o=this.getSubtype(),!!(void 0===s&&s===o||(s instanceof m&&o instanceof m?s.equals(o):Array.isArray(s)&&Array.isArray(o)&&s.reduce(function(t,r,e){return t&&r.equals(o[e])},!0)))&&(e=t.getRank(),i=this.getRank(),(void 0===e&&e===i||e===i)&&(r=t.getSize(),n=this.getSize(),!!(void 0===r&&r===n||r.length===n.length&&r.reduce(function(t,r,e){return t&&r===n[e]},!0)))))));var r,n,e,i,s,o,a,u},window.NITypes=Object.freeze({VOID:new m('"Void"'),BOOLEAN:new m('"Boolean"'),UINT8:new m('"UInt8"'),UINT16:new m('"UInt16"'),UINT32:new m('"UInt32"'),UINT64:new m('"UInt64"'),INT8:new m('"Int8"'),INT16:new m('"Int16"'),INT32:new m('"Int32"'),INT64:new m('"Int64"'),SINGLE:new m('"Single"'),DOUBLE:new m('"Double"'),COMPLEXSINGLE:new m('"ComplexSingle"'),COMPLEXDOUBLE:new m('"ComplexDouble"'),STRING:new m('"String"'),PATH:new m('"Path"'),TIMESTAMP:new m('"Timestamp"'),DIGITALWAVEFORM:new m('"DigitalWaveform"')}),window.NIType=m,window.NITypeNames=l}(); //# sourceMappingURL=ni-data-types.min.js.map