UNPKG

5.67 kBTypeScriptView Raw
1/**
2 * data transforms
3 *
4 * @packageDocumentation
5 */
6
7
8/**
9 * @public
10 */
11export declare interface Action {
12 type: ActionType;
13 field: string | null;
14 as: string | null;
15 options?: FillNullOptions;
16}
17
18/**
19 * @public
20 */
21export declare type ActionType = AggregationType | ConversionType | FillType;
22
23/**
24 * @public
25 */
26export declare type AggExtractorPair = {
27 agg: AggregationType;
28 measure: string;
29};
30
31/**
32 *
33 * @param rows - 数据
34 * @param options - 参数
35 *
36 * @public
37 */
38export declare function aggregate(rows: RowData[], options: AggregateParams): RowData[];
39
40/**
41 * @public
42 */
43export declare interface AggregateParams {
44 as: string[];
45 fields?: string[];
46 groupBy?: string | string[];
47 op: Operations[];
48}
49
50/**
51 * @public
52 */
53export declare const AGGREGATION: ["sum", "max", "min", "average", "avg", "median", "count", "distinct", "countd"];
54
55/**
56 * @public
57 */
58export declare type AggregationType = typeof AGGREGATION[number];
59
60/**
61 * @public
62 */
63export declare type AllSubspaceDatasetOptions = {
64 dimensions?: string[];
65 measures?: string[];
66 aggregations?: AggregationType[];
67 extractors?: ExtractorType[];
68 depth?: number;
69};
70
71/**
72 * @public
73 */
74export declare function autoSchema(data: RowData[], renameOption?: RenameOption, defaultAgg?: AggregationType): TransformSchema[];
75
76/**
77 * @public
78 */
79export declare function autoTransform(data: RowData[], renameOption?: RenameOption, defaultAgg?: AggregationType): AutoTransformResult;
80
81/**
82 * @public
83 */
84export declare interface AutoTransformResult {
85 result: RowData[];
86 schemas: TransformSchema[];
87}
88
89/**
90 * @public
91 */
92export declare type ColumnInfo = {
93 name: string;
94 data: any[];
95 domain: any[];
96};
97
98/**
99 * @public
100 */
101export declare function compositeExtractor(siblingGroup: SiblingGroup, aggPair: AggExtractorPair, extractorPairs?: SubExtractorPair[], depth?: number): RowData[];
102
103/**
104 * @public
105 */
106export declare const CONVERSION: ["toString", "toFloat", "toInt"];
107
108/**
109 * @public
110 */
111export declare type ConversionType = typeof CONVERSION[number];
112
113/**
114 * @public
115 */
116export declare class Dataset {
117 private _dataset;
118 private _dimensions;
119 private _measures;
120 private _dimensionTitles;
121 private _measureTitles;
122 constructor(dataset: RowData[]);
123 get dataset(): RowData[];
124 set dataset(dataset: RowData[]);
125 get dimensions(): ColumnInfo[];
126 get measures(): ColumnInfo[];
127 get dimensionTitles(): string[];
128 get measureTitles(): string[];
129 private _calculateDimensionsAndMeasures;
130 subspace(defineArray?: string[]): Subspace;
131 siblingGroup(subspace: Subspace, dimension: string): SiblingGroup;
132 allSubspaceDataset(options?: AllSubspaceDatasetOptions): RowData[][];
133}
134
135/**
136 * @public
137 */
138export declare type Extractor = (siblingGroup: SiblingGroup) => Measure[];
139
140/**
141 * @public
142 */
143export declare const EXTRACTORS: ["rank", "percent"];
144
145/**
146 * @public
147 */
148export declare const extractors: Record<ExtractorType, Extractor>;
149
150/**
151 * @public
152 */
153export declare type ExtractorType = typeof EXTRACTORS[number];
154
155/**
156 * @public
157 */
158export declare const FILL: ["fillNull", "removeNull"];
159
160/**
161 * @public
162 */
163export declare type FillNullOptions = FillNullOptionsBySmart | FillNullOptionsByAgg | FillNullOptionsByValue;
164
165/**
166 * @public
167 */
168export declare interface FillNullOptionsByAgg {
169 type: Extract<FillNullType, 'byAgg'>;
170 cfg: {
171 agg: AggregationType;
172 };
173}
174
175/**
176 * @public
177 */
178export declare interface FillNullOptionsBySmart {
179 type: Extract<FillNullType, 'bySmart'>;
180}
181
182/**
183 * @public
184 */
185export declare interface FillNullOptionsByValue {
186 type: Extract<FillNullType, 'byValue'>;
187 cfg: {
188 value: string | number;
189 };
190}
191
192/**
193 * @public
194 */
195export declare type FillNullType = 'bySmart' | 'byAgg' | 'byValue';
196
197/**
198 * @public
199 */
200export declare type FillType = typeof FILL[number];
201
202/**
203 * @public
204 */
205export declare type Measure = number[];
206
207/**
208 * aggregate operation
209 * @public
210 */
211export declare type Operations = 'sum' | 'average' | 'avg' | 'mean' | 'min' | 'max' | 'median' | 'variance' | 'stdevp' | 'stdev' | 'mode' | 'product' | 'count' | 'distinct' | 'countd' | 'valid';
212
213/**
214 * @public
215 */
216export declare function parse(data: RowData[], schemas: TransformSchema | TransformSchema[]): RowData[];
217
218/**
219 * @public
220 */
221export declare type RenameOption = boolean | 'origin' | 'brackets' | 'underline' | Function;
222
223/**
224 * 数据行
225 * @public
226 */
227export declare type RowData = Record<string, any>;
228
229/**
230 * @public
231 */
232export declare type SiblingGroup = {
233 datasetInfo: {
234 dimensionTitles: string[];
235 measureTitles: string[];
236 };
237 define: {
238 subspace: Subspace;
239 dimension: string;
240 };
241 subspaceList: Subspace[];
242 dataset: RowData[];
243};
244
245/**
246 * @public
247 */
248export declare type SubExtractorPair = {
249 extractor: ExtractorType;
250 dimension: string;
251};
252
253/**
254 * @public
255 */
256export declare type Subspace = {
257 define: Record<string, string>;
258 dataset: RowData[];
259};
260
261/**
262 * @public
263 */
264export declare interface TransformSchema {
265 groupBy?: string[];
266 actions: Action[];
267}
268
269/**
270 * Pivot specific field of each values.
271 * @public
272 * @param field - field
273 * @param values - unstack values
274 * @returns row datas
275 */
276export declare function unstack(data: RowData[], field: string, values: string[]): RowData[];
277
278export { }