e5a1f3210aacbff7c4e6a292e4aa20ba05984ca3733358048859bea66f4928ab05ffbee21e52c7c7590e20035df6a20952f5278dba1aa59b43ed50693cfa86 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. import { DimensionIndex, DimensionName, OptionDataItem, ParsedValue, ParsedValueNumeric } from '../util/types.js';
  2. import { DataProvider } from './helper/dataProvider.js';
  3. import OrdinalMeta from './OrdinalMeta.js';
  4. import { Source } from './Source.js';
  5. export declare const CtorUint32Array: ArrayConstructor | Uint32ArrayConstructor;
  6. export declare const CtorUint16Array: ArrayConstructor | Uint16ArrayConstructor;
  7. export declare const CtorInt32Array: ArrayConstructor | Int32ArrayConstructor;
  8. export declare const CtorFloat64Array: ArrayConstructor | Float64ArrayConstructor;
  9. /**
  10. * Multi dimensional data store
  11. */
  12. declare const dataCtors: {
  13. readonly float: ArrayConstructor | Float64ArrayConstructor;
  14. readonly int: ArrayConstructor | Int32ArrayConstructor;
  15. readonly ordinal: ArrayConstructor;
  16. readonly number: ArrayConstructor;
  17. readonly time: ArrayConstructor | Float64ArrayConstructor;
  18. };
  19. export declare type DataStoreDimensionType = keyof typeof dataCtors;
  20. declare type EachCb = (...args: any) => void;
  21. declare type FilterCb = (...args: any) => boolean;
  22. declare type MapCb = (...args: any) => ParsedValue | ParsedValue[];
  23. export declare type DimValueGetter = (this: DataStore, dataItem: any, property: string, dataIndex: number, dimIndex: DimensionIndex) => ParsedValue;
  24. export interface DataStoreDimensionDefine {
  25. /**
  26. * Default to be float.
  27. */
  28. type?: DataStoreDimensionType;
  29. /**
  30. * Only used in SOURCE_FORMAT_OBJECT_ROWS and SOURCE_FORMAT_KEYED_COLUMNS to retrieve value
  31. * by "object property".
  32. * For example, in `[{bb: 124, aa: 543}, ...]`, "aa" and "bb" is "object property".
  33. *
  34. * Deliberately name it as "property" rather than "name" to prevent it from been used in
  35. * SOURCE_FORMAT_ARRAY_ROWS, becuase if it comes from series, it probably
  36. * can not be shared by different series.
  37. */
  38. property?: string;
  39. /**
  40. * When using category axis.
  41. * Category strings will be collected and stored in ordinalMeta.categories.
  42. * And store will store the index of categories.
  43. */
  44. ordinalMeta?: OrdinalMeta;
  45. /**
  46. * Offset for ordinal parsing and collect
  47. */
  48. ordinalOffset?: number;
  49. }
  50. /**
  51. * Basically, DataStore API keep immutable.
  52. */
  53. declare class DataStore {
  54. private _chunks;
  55. private _provider;
  56. private _rawExtent;
  57. private _extent;
  58. private _indices;
  59. private _count;
  60. private _rawCount;
  61. private _dimensions;
  62. private _dimValueGetter;
  63. private _calcDimNameToIdx;
  64. defaultDimValueGetter: DimValueGetter;
  65. /**
  66. * Initialize from data
  67. */
  68. initData(provider: DataProvider, inputDimensions: DataStoreDimensionDefine[], dimValueGetter?: DimValueGetter): void;
  69. getProvider(): DataProvider;
  70. /**
  71. * Caution: even when a `source` instance owned by a series, the created data store
  72. * may still be shared by different sereis (the source hash does not use all `source`
  73. * props, see `sourceManager`). In this case, the `source` props that are not used in
  74. * hash (like `source.dimensionDefine`) probably only belongs to a certain series and
  75. * thus should not be fetch here.
  76. */
  77. getSource(): Source;
  78. /**
  79. * @caution Only used in dataStack.
  80. */
  81. ensureCalculationDimension(dimName: DimensionName, type: DataStoreDimensionType): DimensionIndex;
  82. collectOrdinalMeta(dimIdx: number, ordinalMeta: OrdinalMeta): void;
  83. getOrdinalMeta(dimIdx: number): OrdinalMeta;
  84. getDimensionProperty(dimIndex: DimensionIndex): DataStoreDimensionDefine['property'];
  85. /**
  86. * Caution: Can be only called on raw data (before `this._indices` created).
  87. */
  88. appendData(data: ArrayLike<any>): number[];
  89. appendValues(values: any[][], minFillLen?: number): {
  90. start: number;
  91. end: number;
  92. };
  93. private _initDataFromProvider;
  94. count(): number;
  95. /**
  96. * Get value. Return NaN if idx is out of range.
  97. */
  98. get(dim: DimensionIndex, idx: number): ParsedValue;
  99. getValues(idx: number): ParsedValue[];
  100. getValues(dimensions: readonly DimensionIndex[], idx?: number): ParsedValue[];
  101. /**
  102. * @param dim concrete dim
  103. */
  104. getByRawIndex(dim: DimensionIndex, rawIdx: number): ParsedValue;
  105. /**
  106. * Get sum of data in one dimension
  107. */
  108. getSum(dim: DimensionIndex): number;
  109. /**
  110. * Get median of data in one dimension
  111. */
  112. getMedian(dim: DimensionIndex): number;
  113. /**
  114. * Retreive the index with given raw data index
  115. */
  116. indexOfRawIndex(rawIndex: number): number;
  117. /**
  118. * Retreive the index of nearest value
  119. * @param dim
  120. * @param value
  121. * @param [maxDistance=Infinity]
  122. * @return If and only if multiple indices has
  123. * the same value, they are put to the result.
  124. */
  125. indicesOfNearest(dim: DimensionIndex, value: number, maxDistance?: number): number[];
  126. getIndices(): ArrayLike<number>;
  127. /**
  128. * Data filter.
  129. */
  130. filter(dims: DimensionIndex[], cb: FilterCb): DataStore;
  131. /**
  132. * Select data in range. (For optimization of filter)
  133. * (Manually inline code, support 5 million data filtering in data zoom.)
  134. */
  135. selectRange(range: {
  136. [dimIdx: number]: [number, number];
  137. }): DataStore;
  138. /**
  139. * Data mapping to a new List with given dimensions
  140. */
  141. map(dims: DimensionIndex[], cb: MapCb): DataStore;
  142. /**
  143. * @caution Danger!! Only used in dataStack.
  144. */
  145. modify(dims: DimensionIndex[], cb: MapCb): void;
  146. private _updateDims;
  147. /**
  148. * Large data down sampling using largest-triangle-three-buckets
  149. * @param {string} valueDimension
  150. * @param {number} targetCount
  151. */
  152. lttbDownSample(valueDimension: DimensionIndex, rate: number): DataStore;
  153. /**
  154. * Large data down sampling on given dimension
  155. * @param sampleIndex Sample index for name and id
  156. */
  157. downSample(dimension: DimensionIndex, rate: number, sampleValue: (frameValues: ArrayLike<ParsedValue>) => ParsedValueNumeric, sampleIndex: (frameValues: ArrayLike<ParsedValue>, value: ParsedValueNumeric) => number): DataStore;
  158. /**
  159. * Data iteration
  160. * @param ctx default this
  161. * @example
  162. * list.each('x', function (x, idx) {});
  163. * list.each(['x', 'y'], function (x, y, idx) {});
  164. * list.each(function (idx) {})
  165. */
  166. each(dims: DimensionIndex[], cb: EachCb): void;
  167. /**
  168. * Get extent of data in one dimension
  169. */
  170. getDataExtent(dim: DimensionIndex): [number, number];
  171. /**
  172. * Get raw data index.
  173. * Do not initialize.
  174. * Default `getRawIndex`. And it can be changed.
  175. */
  176. getRawIndex: (idx: number) => number;
  177. /**
  178. * Get raw data item
  179. */
  180. getRawDataItem(idx: number): OptionDataItem;
  181. /**
  182. * Clone shallow.
  183. *
  184. * @param clonedDims Determine which dims to clone. Will share the data if not specified.
  185. */
  186. clone(clonedDims?: DimensionIndex[], ignoreIndices?: boolean): DataStore;
  187. private _copyCommonProps;
  188. private _cloneIndices;
  189. private _getRawIdxIdentity;
  190. private _getRawIdx;
  191. private _updateGetRawIdx;
  192. private static internalField;
  193. }
  194. export default DataStore;