UNPKG

@chartshq/datamodel

Version:

An environment with `node`, `rustup` and `wasm-pack` set up.

1 lines 2.56 kB
var __extends=this&&this.__extends||function(){var t=function(e,a){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var a in e)e.hasOwnProperty(a)&&(t[a]=e[a])})(e,a)};return function(e,a){function i(){this.constructor=e}t(e,a),e.prototype=null===a?Object.create(a):(i.prototype=a.prototype,new i)}}();import{AbstractWasmField}from"./field";import{sanitizeNumbers,saveIndecesToMemory,saveNumbersToMemory,getIndecesFromMemory,getWasmSchema}from"./utils";import DateTimeFormatter from"../../../data/utils/date-time-formatter";import Invalid from"../../../data/invalid/invalid";var Temporal=function(t){function e(e,a){var i=t.call(this,e)||this;return i._cachedDomain=[],i._cachedData=[],i._wasmField=a,i._cachedFormattedData=[],i}return __extends(e,t),e.prototype.domain=function(){if(this._wasmField){var t=this._wasmField.get_domain();t.length&&(this._cachedDomain=[t[0],t[1]])}return this._cachedDomain},e.prototype.data=function(){var t=this;if(0===this._cachedData.length&&this._wasmField){var e=getIndecesFromMemory(this._wasmField.get_data_info(),this._wasmField.get_rows_count()).map(function(e){var a=t._wasmField.get_value_at_index(e);return Number.isFinite(a)?a:new Invalid(NaN)});this._cachedData=e}return this._cachedData},e.prototype.formattedData=function(t){if(0===this._cachedFormattedData.length||t){var e=this.data(),a=t||this._schema.format;if(this._cachedFormattedData=e,a instanceof Function){var i=[];e.forEach(function(t){var e;e=t instanceof Invalid?t:a(t),i.push(e)}),this._cachedFormattedData=i}else if("string"==typeof a||a instanceof String){var r=[];e.forEach(function(t){var e;e=t instanceof Invalid?t:DateTimeFormatter.formatAs(new Date(t),a),r.push(e)}),this._cachedFormattedData=r}}return this._cachedFormattedData},e.prototype.getRowsCount=function(){return this._wasmField?this._wasmField.get_rows_count():0},e.prototype.dispose=function(){this._cachedDomain=[],this._cachedData=[],this._cachedFormattedData=[],this._wasmField&&this._wasmField.free()},e.prototype.minimumConsecutiveDifference=function(){var t=this._wasmField?this._wasmField.min_consecutive_diff():1/0;return isFinite(t)?t:NaN},e}(AbstractWasmField);export default Temporal;export var temporalFieldCreator=function(t,e,a){var i=sanitizeNumbers(t),r=i.indices,o=i.values,n=Number.MAX_VALUE,s=void 0;return a&&(n=a.add_field(getWasmSchema(e),[]),s=a.get_temporal_field(n),saveIndecesToMemory(s.get_data_indices(),r),saveNumbersToMemory(s.get_data_ptr(),o)),{field:new Temporal(e,s),index:n}};