@chartshq/datamodel
Version:
An environment with `node`, `rustup` and `wasm-pack` set up.
1 lines • 1.83 kB
JavaScript
var __extends=this&&this.__extends||function(){var t=function(e,o){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var o in e)e.hasOwnProperty(o)&&(t[o]=e[o])})(e,o)};return function(e,o){function r(){this.constructor=e}t(e,o),e.prototype=null===o?Object.create(o):(r.prototype=o.prototype,new r)}}();import{AbstractWasmField}from"./field";import{getIndecesFromMemory,getWasmSchema,saveIndecesToMemory}from"./utils";import{ROW_ID,FieldType,FieldSubtype}from"../../../constants/fields";var RowId=function(t){function e(e,o){var r=t.call(this,e)||this;return r._cachedDomain=[],r._cachedData=[],r._wasmField=o,r}return __extends(e,t),e.prototype.displayName=function(){return this._schema.name},e.prototype.domain=function(){return[]},e.prototype.formattedData=function(){return[]},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){return t._wasmField.get_value_at_index(e)});this._cachedData=e}return this._cachedData},e.prototype.getRowsCount=function(){return this._wasmField?this._wasmField.get_rows_count():0},e.prototype.getValueAtIndex=function(t){return this.data()[t]},e.prototype.dispose=function(){this._cachedDomain=[],this._cachedData=[],this._wasmField&&this._wasmField.free()},e}(AbstractWasmField);export default RowId;export var idFieldCreator=function(t,e,o){var r=void 0,n=Number.MAX_VALUE;return o&&(n=o.add_field(getWasmSchema(e),[]),r=o.get_id_field(n),saveIndecesToMemory(r.get_data_ptr(),t)),{field:new RowId(e,r),index:n}};export var getIdFieldSchema=function(){return{name:ROW_ID,format:function(t){return t},displayName:ROW_ID,type:FieldType.MEASURE,subtype:FieldSubtype.ROWID,defAggFn:"sum"}};