@sisense/sdk-data 0.16.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dimensional-model/analytics/factory.d.ts +47 -0
- package/dist/dimensional-model/analytics/factory.js +140 -0
- package/dist/dimensional-model/factory.js +1 -1
- package/dist/dimensional-model/filters/factory.d.ts +34 -1
- package/dist/dimensional-model/filters/factory.js +56 -0
- package/dist/dimensional-model/filters/filters.d.ts +4 -0
- package/dist/dimensional-model/filters/filters.js +2 -0
- package/dist/dimensional-model/interfaces.d.ts +15 -2
- package/dist/dimensional-model/measures/factory.d.ts +547 -177
- package/dist/dimensional-model/measures/factory.js +547 -177
- package/dist/index.d.ts +42 -36
- package/dist/index.js +42 -36
- package/dist/translation/resources/en.d.ts +1 -1
- package/dist/translation/resources/en.js +1 -1
- package/dist/translation/resources/index.d.ts +2 -2
- package/dist/translation/resources/uk.js +1 -1
- package/dist/utils.d.ts +16 -0
- package/dist/utils.js +63 -0
- package/package.json +14 -3
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { Attribute, Measure } from '../interfaces.js';
|
|
2
|
+
/** @internal */
|
|
3
|
+
export declare const BOX_WHISKER: {
|
|
4
|
+
BOX_MIN_VALUE_NAME: string;
|
|
5
|
+
BOX_MEDIAN_VALUE_NAME: string;
|
|
6
|
+
BOX_MAX_VALUE_NAME: string;
|
|
7
|
+
WHISKER_MIN_VALUE_NAME: string;
|
|
8
|
+
WHISKER_MAX_VALUE_NAME: string;
|
|
9
|
+
OUTLIER_COUNT_VALUE_NAME: string;
|
|
10
|
+
OUTLIER_MIN_VALUE_NAME: string;
|
|
11
|
+
OUTLIER_MAX_VALUE_NAME: string;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Returns an array of values for box whisker plot using interquartile range (IQR) calculations.
|
|
15
|
+
*
|
|
16
|
+
* @param {Attribute} target - The target attribute for calculations.
|
|
17
|
+
* @returns {Measure[]} An array of measures representing IQR values for box whisker plots.
|
|
18
|
+
*/
|
|
19
|
+
export declare function boxWhiskerIqrValues(target: Attribute): Measure[];
|
|
20
|
+
/**
|
|
21
|
+
* Returns an array of extremum values for box whisker plot.
|
|
22
|
+
*
|
|
23
|
+
* @param {Attribute} target - The target attribute for calculations.
|
|
24
|
+
* @returns {Measure[]} An array of measures representing extremum values for box whisker plots.
|
|
25
|
+
*/
|
|
26
|
+
export declare function boxWhiskerExtremumsValues(target: Attribute): Measure[];
|
|
27
|
+
/**
|
|
28
|
+
* Returns an array of values for box whisker plot using standard deviation calculations.
|
|
29
|
+
*
|
|
30
|
+
* @param {Attribute} target - The target attribute for calculations.
|
|
31
|
+
* @returns {Measure[]} An array of measures representing standard deviation values for box whisker plots.
|
|
32
|
+
*/
|
|
33
|
+
export declare function boxWhiskerStdDevValues(target: Attribute): Measure[];
|
|
34
|
+
/**
|
|
35
|
+
* Returns an attribute representing outlier points based on interquartile range (IQR) calculations.
|
|
36
|
+
*
|
|
37
|
+
* @param {Attribute} target - The target attribute for calculations.
|
|
38
|
+
* @returns {Attribute} An attribute representing outliers for box whisker plots using IQR.
|
|
39
|
+
*/
|
|
40
|
+
export declare const boxWhiskerIqrOutliers: (target: Attribute) => Attribute;
|
|
41
|
+
/**
|
|
42
|
+
* Returns an attribute representing outlier points based on standard deviation calculations.
|
|
43
|
+
*
|
|
44
|
+
* @param {Attribute} target - The target attribute for calculations.
|
|
45
|
+
* @returns {Attribute} An attribute representing outliers for box whisker plots using standard deviation.
|
|
46
|
+
*/
|
|
47
|
+
export declare const boxWhiskerStdDevOutliers: (target: Attribute) => Attribute;
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import cloneDeep from 'lodash/cloneDeep.js';
|
|
2
|
+
import { customFormula } from '../measures/factory.js';
|
|
3
|
+
/** @internal */
|
|
4
|
+
export const BOX_WHISKER = {
|
|
5
|
+
BOX_MIN_VALUE_NAME: 'Box Min',
|
|
6
|
+
BOX_MEDIAN_VALUE_NAME: 'Box Median',
|
|
7
|
+
BOX_MAX_VALUE_NAME: 'Box Max',
|
|
8
|
+
WHISKER_MIN_VALUE_NAME: 'Whisker Min',
|
|
9
|
+
WHISKER_MAX_VALUE_NAME: 'Whisker Max',
|
|
10
|
+
OUTLIER_COUNT_VALUE_NAME: 'Outlier Count',
|
|
11
|
+
OUTLIER_MIN_VALUE_NAME: 'Outlier Min',
|
|
12
|
+
OUTLIER_MAX_VALUE_NAME: 'Outlier Max',
|
|
13
|
+
};
|
|
14
|
+
function boxWhiskerCommonValues(target) {
|
|
15
|
+
return [
|
|
16
|
+
customFormula(BOX_WHISKER.BOX_MIN_VALUE_NAME, 'QUARTILE([Attr], 1)', {
|
|
17
|
+
Attr: target,
|
|
18
|
+
}),
|
|
19
|
+
customFormula(BOX_WHISKER.BOX_MEDIAN_VALUE_NAME, 'MEDIAN([Attr])', {
|
|
20
|
+
Attr: target,
|
|
21
|
+
}),
|
|
22
|
+
customFormula(BOX_WHISKER.BOX_MAX_VALUE_NAME, 'QUARTILE([Attr], 3)', {
|
|
23
|
+
Attr: target,
|
|
24
|
+
}),
|
|
25
|
+
];
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Returns an array of values for box whisker plot using interquartile range (IQR) calculations.
|
|
29
|
+
*
|
|
30
|
+
* @param {Attribute} target - The target attribute for calculations.
|
|
31
|
+
* @returns {Measure[]} An array of measures representing IQR values for box whisker plots.
|
|
32
|
+
*/
|
|
33
|
+
export function boxWhiskerIqrValues(target) {
|
|
34
|
+
return [
|
|
35
|
+
...boxWhiskerCommonValues(target),
|
|
36
|
+
customFormula(BOX_WHISKER.WHISKER_MIN_VALUE_NAME, 'LOWERWHISKERMAX_IQR([Attr])', {
|
|
37
|
+
Attr: target,
|
|
38
|
+
}),
|
|
39
|
+
customFormula(BOX_WHISKER.WHISKER_MAX_VALUE_NAME, 'UPPERWHISKERMIN_IQR([Attr])', {
|
|
40
|
+
Attr: target,
|
|
41
|
+
}),
|
|
42
|
+
customFormula(BOX_WHISKER.OUTLIER_COUNT_VALUE_NAME, 'OUTLIERSCOUNT_IQR([Attr])', {
|
|
43
|
+
Attr: target,
|
|
44
|
+
}),
|
|
45
|
+
];
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Returns an array of extremum values for box whisker plot.
|
|
49
|
+
*
|
|
50
|
+
* @param {Attribute} target - The target attribute for calculations.
|
|
51
|
+
* @returns {Measure[]} An array of measures representing extremum values for box whisker plots.
|
|
52
|
+
*/
|
|
53
|
+
export function boxWhiskerExtremumsValues(target) {
|
|
54
|
+
return [
|
|
55
|
+
...boxWhiskerCommonValues(target),
|
|
56
|
+
customFormula(BOX_WHISKER.WHISKER_MIN_VALUE_NAME, 'MIN([Attr])', {
|
|
57
|
+
Attr: target,
|
|
58
|
+
}),
|
|
59
|
+
customFormula(BOX_WHISKER.WHISKER_MAX_VALUE_NAME, 'MAX([Attr])', {
|
|
60
|
+
Attr: target,
|
|
61
|
+
}),
|
|
62
|
+
];
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Returns an array of values for box whisker plot using standard deviation calculations.
|
|
66
|
+
*
|
|
67
|
+
* @param {Attribute} target - The target attribute for calculations.
|
|
68
|
+
* @returns {Measure[]} An array of measures representing standard deviation values for box whisker plots.
|
|
69
|
+
*/
|
|
70
|
+
export function boxWhiskerStdDevValues(target) {
|
|
71
|
+
return [
|
|
72
|
+
...boxWhiskerCommonValues(target),
|
|
73
|
+
customFormula(BOX_WHISKER.WHISKER_MIN_VALUE_NAME, 'LOWERWHISKERMAX_STDEVP([Attr])', {
|
|
74
|
+
Attr: target,
|
|
75
|
+
}),
|
|
76
|
+
customFormula(BOX_WHISKER.WHISKER_MAX_VALUE_NAME, 'UPPERWHISKERMIN_STDEVP([Attr])', {
|
|
77
|
+
Attr: target,
|
|
78
|
+
}),
|
|
79
|
+
customFormula(BOX_WHISKER.OUTLIER_COUNT_VALUE_NAME, 'OUTLIERSCOUNT_STDEVP([Attr])', {
|
|
80
|
+
Attr: target,
|
|
81
|
+
}),
|
|
82
|
+
];
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Returns an attribute representing outlier points based on interquartile range (IQR) calculations.
|
|
86
|
+
*
|
|
87
|
+
* @param {Attribute} target - The target attribute for calculations.
|
|
88
|
+
* @returns {Attribute} An attribute representing outliers for box whisker plots using IQR.
|
|
89
|
+
*/
|
|
90
|
+
export const boxWhiskerIqrOutliers = (target) => {
|
|
91
|
+
const outliersAttrWithInnerFilter = cloneDeep(target);
|
|
92
|
+
const outliersMax = customFormula(BOX_WHISKER.OUTLIER_MAX_VALUE_NAME, '(UPPERWHISKERMIN_IQR([Attr]), all([Attr]))', {
|
|
93
|
+
Attr: target,
|
|
94
|
+
});
|
|
95
|
+
const outliersMin = customFormula(BOX_WHISKER.OUTLIER_MIN_VALUE_NAME, '(LOWERWHISKERMAX_IQR([Attr]), all([Attr]))', {
|
|
96
|
+
Attr: target,
|
|
97
|
+
});
|
|
98
|
+
outliersAttrWithInnerFilter.name = `${outliersAttrWithInnerFilter.name} (Outliers)`;
|
|
99
|
+
outliersAttrWithInnerFilter.jaql = () => {
|
|
100
|
+
return Object.assign(Object.assign({}, target.jaql()), { filter: {
|
|
101
|
+
or: [
|
|
102
|
+
{
|
|
103
|
+
fromNotEqual: outliersMax.jaql(true),
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
toNotEqual: outliersMin.jaql(true),
|
|
107
|
+
},
|
|
108
|
+
],
|
|
109
|
+
} });
|
|
110
|
+
};
|
|
111
|
+
return outliersAttrWithInnerFilter;
|
|
112
|
+
};
|
|
113
|
+
/**
|
|
114
|
+
* Returns an attribute representing outlier points based on standard deviation calculations.
|
|
115
|
+
*
|
|
116
|
+
* @param {Attribute} target - The target attribute for calculations.
|
|
117
|
+
* @returns {Attribute} An attribute representing outliers for box whisker plots using standard deviation.
|
|
118
|
+
*/
|
|
119
|
+
export const boxWhiskerStdDevOutliers = (target) => {
|
|
120
|
+
const outliersAttrWithInnerFilter = cloneDeep(target);
|
|
121
|
+
const outliersMax = customFormula(BOX_WHISKER.OUTLIER_MAX_VALUE_NAME, '(UPPERWHISKERMIN_STDEVP([Attr]), all([Attr]))', {
|
|
122
|
+
Attr: target,
|
|
123
|
+
});
|
|
124
|
+
const outliersMin = customFormula(BOX_WHISKER.OUTLIER_MIN_VALUE_NAME, '(LOWERWHISKERMAX_STDEVP([Attr]), all([Attr]))', {
|
|
125
|
+
Attr: target,
|
|
126
|
+
});
|
|
127
|
+
outliersAttrWithInnerFilter.jaql = () => {
|
|
128
|
+
return Object.assign(Object.assign({}, target.jaql()), { filter: {
|
|
129
|
+
or: [
|
|
130
|
+
{
|
|
131
|
+
fromNotEqual: outliersMax.jaql(true),
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
toNotEqual: outliersMin.jaql(true),
|
|
135
|
+
},
|
|
136
|
+
],
|
|
137
|
+
} });
|
|
138
|
+
};
|
|
139
|
+
return outliersAttrWithInnerFilter;
|
|
140
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DateDimension, LevelAttribute, Attribute, Measure, Filter, BaseMeasure } from '../interfaces.js';
|
|
1
|
+
import { DateDimension, LevelAttribute, Attribute, Measure, Filter, BaseMeasure, FilterRelationNode, FilterRelation } from '../interfaces.js';
|
|
2
2
|
/**
|
|
3
3
|
* Creates a filter representing a union of multiple filters of the same attribute.
|
|
4
4
|
*
|
|
@@ -313,3 +313,36 @@ export declare function topRanking(attribute: Attribute, measure: Measure, count
|
|
|
313
313
|
* @returns A filter representing a bottom ranking logic on the given attribute by the given measure
|
|
314
314
|
*/
|
|
315
315
|
export declare function bottomRanking(attribute: Attribute, measure: Measure, count: number): Filter;
|
|
316
|
+
/**
|
|
317
|
+
* Set of logic operators for filter relation construction
|
|
318
|
+
*
|
|
319
|
+
* These operators are still in beta.
|
|
320
|
+
*
|
|
321
|
+
* @example
|
|
322
|
+
```tsx
|
|
323
|
+
import { filters } from '@sisense/sdk-data';
|
|
324
|
+
|
|
325
|
+
// define filters
|
|
326
|
+
const revenueFilter = filters.greaterThan(DM.Commerce.Revenue, 1000);
|
|
327
|
+
const countryFilter = filters.members(DM.Commerce.Country, ['USA', 'Canada']);
|
|
328
|
+
const genderFilter = filters.doesntContain(DM.Commerce.Gender, 'Unspecified');
|
|
329
|
+
const costFilter = filters.between(DM.Commerce.Cost, 1000, 2000);
|
|
330
|
+
|
|
331
|
+
// create filter relation of two filters
|
|
332
|
+
const orFilerRelations = filterFactory.logic.or(revenueFilter, countryFilter);
|
|
333
|
+
// revenueFilter OR countryFilter
|
|
334
|
+
|
|
335
|
+
// filter relations can have nested filter relations
|
|
336
|
+
const mixedFilterRelations = filterFactory.logic.and(genderFilter, orFilerRelations);
|
|
337
|
+
// genderFilter AND (revenueFilter OR countryFilter)
|
|
338
|
+
|
|
339
|
+
// array, specified in filter relations, will be converted to an intersection of filters automatically
|
|
340
|
+
const arrayFilterRelations = filterFactory.logic.or([genderFilter, costFilter], mixedFilterRelations);
|
|
341
|
+
// (genderFilter AND costFilter) OR (genderFilter AND (revenueFilter OR countryFilter))
|
|
342
|
+
```
|
|
343
|
+
* @beta
|
|
344
|
+
*/
|
|
345
|
+
export declare namespace logic {
|
|
346
|
+
const and: (left: FilterRelationNode, right: FilterRelationNode) => FilterRelation;
|
|
347
|
+
const or: (left: FilterRelationNode, right: FilterRelationNode) => FilterRelation;
|
|
348
|
+
}
|
|
@@ -402,3 +402,59 @@ export function topRanking(attribute, measure, count) {
|
|
|
402
402
|
export function bottomRanking(attribute, measure, count) {
|
|
403
403
|
return new RankingFilter(attribute, measure, RankingOperators.Bottom, count);
|
|
404
404
|
}
|
|
405
|
+
const relate = (node) => {
|
|
406
|
+
if (Array.isArray(node)) {
|
|
407
|
+
const [first, ...rest] = node;
|
|
408
|
+
return rest.length === 0
|
|
409
|
+
? relate(first)
|
|
410
|
+
: {
|
|
411
|
+
operator: 'AND',
|
|
412
|
+
left: relate(first),
|
|
413
|
+
right: relate(rest),
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
return node;
|
|
417
|
+
};
|
|
418
|
+
/**
|
|
419
|
+
* Set of logic operators for filter relation construction
|
|
420
|
+
*
|
|
421
|
+
* These operators are still in beta.
|
|
422
|
+
*
|
|
423
|
+
* @example
|
|
424
|
+
```tsx
|
|
425
|
+
import { filters } from '@sisense/sdk-data';
|
|
426
|
+
|
|
427
|
+
// define filters
|
|
428
|
+
const revenueFilter = filters.greaterThan(DM.Commerce.Revenue, 1000);
|
|
429
|
+
const countryFilter = filters.members(DM.Commerce.Country, ['USA', 'Canada']);
|
|
430
|
+
const genderFilter = filters.doesntContain(DM.Commerce.Gender, 'Unspecified');
|
|
431
|
+
const costFilter = filters.between(DM.Commerce.Cost, 1000, 2000);
|
|
432
|
+
|
|
433
|
+
// create filter relation of two filters
|
|
434
|
+
const orFilerRelations = filterFactory.logic.or(revenueFilter, countryFilter);
|
|
435
|
+
// revenueFilter OR countryFilter
|
|
436
|
+
|
|
437
|
+
// filter relations can have nested filter relations
|
|
438
|
+
const mixedFilterRelations = filterFactory.logic.and(genderFilter, orFilerRelations);
|
|
439
|
+
// genderFilter AND (revenueFilter OR countryFilter)
|
|
440
|
+
|
|
441
|
+
// array, specified in filter relations, will be converted to an intersection of filters automatically
|
|
442
|
+
const arrayFilterRelations = filterFactory.logic.or([genderFilter, costFilter], mixedFilterRelations);
|
|
443
|
+
// (genderFilter AND costFilter) OR (genderFilter AND (revenueFilter OR countryFilter))
|
|
444
|
+
```
|
|
445
|
+
* @beta
|
|
446
|
+
*/
|
|
447
|
+
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
448
|
+
export var logic;
|
|
449
|
+
(function (logic) {
|
|
450
|
+
logic.and = (left, right) => ({
|
|
451
|
+
operator: 'AND',
|
|
452
|
+
left: relate(left),
|
|
453
|
+
right: relate(right),
|
|
454
|
+
});
|
|
455
|
+
logic.or = (left, right) => ({
|
|
456
|
+
operator: 'OR',
|
|
457
|
+
left: relate(left),
|
|
458
|
+
right: relate(right),
|
|
459
|
+
});
|
|
460
|
+
})(logic = logic || (logic = {}));
|
|
@@ -88,6 +88,10 @@ declare abstract class AbstractFilter extends DimensionalElement implements Filt
|
|
|
88
88
|
* Filter type
|
|
89
89
|
*/
|
|
90
90
|
readonly filterType: string;
|
|
91
|
+
/**
|
|
92
|
+
* Global filter identifier
|
|
93
|
+
*/
|
|
94
|
+
readonly guid: string;
|
|
91
95
|
constructor(att: Attribute, filterType: string);
|
|
92
96
|
get name(): string;
|
|
93
97
|
/**
|
|
@@ -14,6 +14,7 @@ import { DateLevels, MetadataTypes } from '../types.js';
|
|
|
14
14
|
import { create } from '../factory.js';
|
|
15
15
|
import { DimensionalBaseMeasure } from '../measures/measures.js';
|
|
16
16
|
import { TranslatableError } from '../../translation/translatable-error.js';
|
|
17
|
+
import { guidFast } from '../../utils.js';
|
|
17
18
|
/**
|
|
18
19
|
* Different text operators that can be used with text filters
|
|
19
20
|
*
|
|
@@ -100,6 +101,7 @@ class AbstractFilter extends DimensionalElement {
|
|
|
100
101
|
this.filterType = filterType;
|
|
101
102
|
AbstractFilter.checkAttributeSupport(att);
|
|
102
103
|
this.attribute = att;
|
|
104
|
+
this.guid = guidFast(13);
|
|
103
105
|
}
|
|
104
106
|
get name() {
|
|
105
107
|
return hash(this.jaql());
|
|
@@ -62,7 +62,7 @@ export interface Element {
|
|
|
62
62
|
}
|
|
63
63
|
/**
|
|
64
64
|
* Base interface for measure, which is typically numeric aggregation over {@link Attribute}(s).
|
|
65
|
-
* See {@link
|
|
65
|
+
* See {@link measureFactory} for how to create measures.
|
|
66
66
|
*
|
|
67
67
|
*/
|
|
68
68
|
export interface Measure extends Element {
|
|
@@ -321,9 +321,13 @@ export interface LevelAttribute extends Attribute {
|
|
|
321
321
|
};
|
|
322
322
|
}
|
|
323
323
|
/**
|
|
324
|
-
* Base interface for filter. See {@link
|
|
324
|
+
* Base interface for filter. See {@link filterFactory} for how to create filters.
|
|
325
325
|
*/
|
|
326
326
|
export interface Filter extends Element {
|
|
327
|
+
/**
|
|
328
|
+
* Global filter identifier
|
|
329
|
+
*/
|
|
330
|
+
readonly guid: string;
|
|
327
331
|
/**
|
|
328
332
|
* Attribute this filter instance is filtering
|
|
329
333
|
*/
|
|
@@ -342,3 +346,12 @@ export interface Filter extends Element {
|
|
|
342
346
|
export interface CustomFormulaContext {
|
|
343
347
|
[key: string]: Attribute | Measure;
|
|
344
348
|
}
|
|
349
|
+
export declare type FilterRelationNode = Filter | Filter[] | FilterRelation | FilterRelationJaqlNode;
|
|
350
|
+
export interface FilterRelation {
|
|
351
|
+
left: FilterRelationNode;
|
|
352
|
+
right: FilterRelationNode;
|
|
353
|
+
operator: 'AND' | 'OR';
|
|
354
|
+
}
|
|
355
|
+
export declare type FilterRelationJaqlNode = {
|
|
356
|
+
instanceid: string;
|
|
357
|
+
};
|