@contrail/data-grouping 1.0.4 → 1.0.6
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/README.md +1 -1
- package/lib/data-group-generator/data-group-generator.d.ts +6 -0
- package/lib/data-group-generator/data-group-generator.js +66 -0
- package/lib/data-group-generator/index.d.ts +1 -0
- package/lib/data-group-generator/index.js +17 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.js +19 -17
- package/lib/interfaces.d.ts +20 -14
- package/lib/interfaces.js +2 -2
- package/package.json +43 -43
package/README.md
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
Library for use with @contrail/documents that allows for the quick/automation generation of
|
1
|
+
Library for use with @contrail/documents that allows for the quick/automation generation of
|
2
2
|
documents based on templates and layout options.
|
@@ -0,0 +1,6 @@
|
|
1
|
+
import { DataGroup, DataGroupStructure, DataGroupingProperty } from "../interfaces";
|
2
|
+
export declare class DataGroupGenerator {
|
3
|
+
static buildChildDataGroups(data: any, parentGroup: DataGroup, groupingProperties: any, leafNodeDataCount: any, currentDepth: any): void;
|
4
|
+
static buildDataGroupStructure(data: Array<any>, groupingProperties: Array<DataGroupingProperty>, leafNodeDataCount: number, currentDepth?: number): DataGroupStructure;
|
5
|
+
static createFrameGroupsForData(parentGroup: DataGroup, data: Array<any>, leafNodeDataCount: number): Array<DataGroup>;
|
6
|
+
}
|
@@ -0,0 +1,66 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.DataGroupGenerator = void 0;
|
4
|
+
const util_1 = require("@contrail/util");
|
5
|
+
class DataGroupGenerator {
|
6
|
+
static buildChildDataGroups(data, parentGroup, groupingProperties, leafNodeDataCount, currentDepth) {
|
7
|
+
const groupingProperty = groupingProperties[currentDepth];
|
8
|
+
const index = groupingProperty.scope + "." + groupingProperty.property.slug;
|
9
|
+
const distinctValues = [...new Set(data.filter(obj => util_1.ObjectUtil.getByPath(obj, index))
|
10
|
+
.map(obj => util_1.ObjectUtil.getByPath(obj, index)))
|
11
|
+
].sort((v1, v2) => {
|
12
|
+
return v1 > v2 ? 1 : -1;
|
13
|
+
});
|
14
|
+
for (let val of distinctValues) {
|
15
|
+
const groupData = data.filter(obj => util_1.ObjectUtil.getByPath(obj, index) === val);
|
16
|
+
const group = {
|
17
|
+
data: [],
|
18
|
+
subGroups: [],
|
19
|
+
properties: {},
|
20
|
+
name: ''
|
21
|
+
};
|
22
|
+
group.properties[groupingProperty.property.slug] = val;
|
23
|
+
group.name = val;
|
24
|
+
if (currentDepth === groupingProperties.length - 1) {
|
25
|
+
group.subGroups = this.createFrameGroupsForData(group, groupData, leafNodeDataCount);
|
26
|
+
}
|
27
|
+
else if (currentDepth < groupingProperties.length - 1) {
|
28
|
+
this.buildChildDataGroups(groupData, group, groupingProperties, leafNodeDataCount, currentDepth + 1);
|
29
|
+
}
|
30
|
+
parentGroup.subGroups.push(group);
|
31
|
+
}
|
32
|
+
}
|
33
|
+
static buildDataGroupStructure(data, groupingProperties, leafNodeDataCount, currentDepth = 0) {
|
34
|
+
const structure = {
|
35
|
+
rootGroup: {
|
36
|
+
subGroups: [],
|
37
|
+
name: "root",
|
38
|
+
properties: {},
|
39
|
+
data: [],
|
40
|
+
},
|
41
|
+
groupingProperties: [],
|
42
|
+
depth: groupingProperties ? groupingProperties.length + 1 : 0,
|
43
|
+
};
|
44
|
+
this.buildChildDataGroups(data, structure.rootGroup, groupingProperties, leafNodeDataCount, 0);
|
45
|
+
return structure;
|
46
|
+
}
|
47
|
+
static createFrameGroupsForData(parentGroup, data, leafNodeDataCount) {
|
48
|
+
const dataLength = data.length;
|
49
|
+
const frameCount = Math.ceil(dataLength / leafNodeDataCount);
|
50
|
+
const groups = [];
|
51
|
+
for (let i = 1; i <= frameCount; i++) {
|
52
|
+
const startIndex = (i - 1) * leafNodeDataCount;
|
53
|
+
const endIndex = startIndex + leafNodeDataCount;
|
54
|
+
let groupData = data.slice(startIndex, endIndex);
|
55
|
+
const group = {
|
56
|
+
data: groupData,
|
57
|
+
subGroups: [],
|
58
|
+
name: parentGroup.name,
|
59
|
+
properties: parentGroup.properties,
|
60
|
+
};
|
61
|
+
groups.push(group);
|
62
|
+
}
|
63
|
+
return groups;
|
64
|
+
}
|
65
|
+
}
|
66
|
+
exports.DataGroupGenerator = DataGroupGenerator;
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './data-group-generator';
|
@@ -0,0 +1,17 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
12
|
+
}));
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15
|
+
};
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
+
__exportStar(require("./data-group-generator"), exports);
|
package/lib/index.d.ts
CHANGED
@@ -1 +1,2 @@
|
|
1
|
-
export * from './interfaces';
|
1
|
+
export * from './interfaces';
|
2
|
+
export * from './data-group-generator';
|
package/lib/index.js
CHANGED
@@ -1,17 +1,19 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
-
if (k2 === undefined) k2 = k;
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
-
}
|
8
|
-
Object.defineProperty(o, k2, desc);
|
9
|
-
}) : (function(o, m, k, k2) {
|
10
|
-
if (k2 === undefined) k2 = k;
|
11
|
-
o[k2] = m[k];
|
12
|
-
}));
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15
|
-
};
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
-
__exportStar(require("./interfaces"), exports);
|
1
|
+
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
12
|
+
}));
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15
|
+
};
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
+
__exportStar(require("./interfaces"), exports);
|
18
|
+
;
|
19
|
+
__exportStar(require("./data-group-generator"), exports);
|
package/lib/interfaces.d.ts
CHANGED
@@ -1,14 +1,20 @@
|
|
1
|
-
import { TypeProperty } from "@contrail/types";
|
2
|
-
export interface DataGroup {
|
3
|
-
subGroups: Array<DataGroup>;
|
4
|
-
name: string;
|
5
|
-
properties: {
|
6
|
-
[key: string]: any;
|
7
|
-
};
|
8
|
-
data: Array<any>;
|
9
|
-
}
|
10
|
-
export interface DataGroupStructure {
|
11
|
-
rootGroup: DataGroup;
|
12
|
-
depth: number;
|
13
|
-
groupingProperties: Array<
|
14
|
-
}
|
1
|
+
import { TypeProperty } from "@contrail/types";
|
2
|
+
export interface DataGroup {
|
3
|
+
subGroups: Array<DataGroup>;
|
4
|
+
name: string;
|
5
|
+
properties: {
|
6
|
+
[key: string]: any;
|
7
|
+
};
|
8
|
+
data: Array<any>;
|
9
|
+
}
|
10
|
+
export interface DataGroupStructure {
|
11
|
+
rootGroup: DataGroup;
|
12
|
+
depth: number;
|
13
|
+
groupingProperties: Array<DataGroupingProperty>;
|
14
|
+
}
|
15
|
+
export interface DataGroupingProperty {
|
16
|
+
property: TypeProperty;
|
17
|
+
values?: Array<string>;
|
18
|
+
scope: string;
|
19
|
+
sort: string;
|
20
|
+
}
|
package/lib/interfaces.js
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
package/package.json
CHANGED
@@ -1,43 +1,43 @@
|
|
1
|
-
{
|
2
|
-
"name": "@contrail/data-grouping",
|
3
|
-
"version": "1.0.
|
4
|
-
"description": "Utilities and interfaces for grouping data into hierarchial data structures based on properties.",
|
5
|
-
"main": "lib/index.js",
|
6
|
-
"types": "lib/index.d.ts",
|
7
|
-
"scripts": {
|
8
|
-
"build": "tsc",
|
9
|
-
"format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\"",
|
10
|
-
"lint": "tslint -p tsconfig.json",
|
11
|
-
"test": "jest"
|
12
|
-
},
|
13
|
-
"keywords": [],
|
14
|
-
"author": "",
|
15
|
-
"license": "ISC",
|
16
|
-
"devDependencies": {
|
17
|
-
"@types/jest": "^23.3.14",
|
18
|
-
"jest": "^23.6.0",
|
19
|
-
"prettier": "^1.19.1",
|
20
|
-
"ts-jest": "^23.10.5",
|
21
|
-
"tslint": "^5.11.0",
|
22
|
-
"tslint-config-prettier": "^1.18.0",
|
23
|
-
"typescript": "^4.0.0"
|
24
|
-
},
|
25
|
-
"jest": {
|
26
|
-
"moduleFileExtensions": [
|
27
|
-
"js",
|
28
|
-
"json",
|
29
|
-
"ts"
|
30
|
-
],
|
31
|
-
"rootDir": "src",
|
32
|
-
"testRegex": ".spec.ts$",
|
33
|
-
"transform": {
|
34
|
-
"^.+\\.(t|j)s$": "ts-jest"
|
35
|
-
},
|
36
|
-
"coverageDirectory": "../coverage",
|
37
|
-
"testEnvironment": "node"
|
38
|
-
},
|
39
|
-
"dependencies": {
|
40
|
-
"@contrail/documents": "^1.0.38",
|
41
|
-
"@contrail/types": "^3.0.27"
|
42
|
-
}
|
43
|
-
}
|
1
|
+
{
|
2
|
+
"name": "@contrail/data-grouping",
|
3
|
+
"version": "1.0.6",
|
4
|
+
"description": "Utilities and interfaces for grouping data into hierarchial data structures based on properties.",
|
5
|
+
"main": "lib/index.js",
|
6
|
+
"types": "lib/index.d.ts",
|
7
|
+
"scripts": {
|
8
|
+
"build": "tsc",
|
9
|
+
"format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\"",
|
10
|
+
"lint": "tslint -p tsconfig.json",
|
11
|
+
"test": "jest"
|
12
|
+
},
|
13
|
+
"keywords": [],
|
14
|
+
"author": "",
|
15
|
+
"license": "ISC",
|
16
|
+
"devDependencies": {
|
17
|
+
"@types/jest": "^23.3.14",
|
18
|
+
"jest": "^23.6.0",
|
19
|
+
"prettier": "^1.19.1",
|
20
|
+
"ts-jest": "^23.10.5",
|
21
|
+
"tslint": "^5.11.0",
|
22
|
+
"tslint-config-prettier": "^1.18.0",
|
23
|
+
"typescript": "^4.0.0"
|
24
|
+
},
|
25
|
+
"jest": {
|
26
|
+
"moduleFileExtensions": [
|
27
|
+
"js",
|
28
|
+
"json",
|
29
|
+
"ts"
|
30
|
+
],
|
31
|
+
"rootDir": "src",
|
32
|
+
"testRegex": ".spec.ts$",
|
33
|
+
"transform": {
|
34
|
+
"^.+\\.(t|j)s$": "ts-jest"
|
35
|
+
},
|
36
|
+
"coverageDirectory": "../coverage",
|
37
|
+
"testEnvironment": "node"
|
38
|
+
},
|
39
|
+
"dependencies": {
|
40
|
+
"@contrail/documents": "^1.0.38",
|
41
|
+
"@contrail/types": "^3.0.27"
|
42
|
+
}
|
43
|
+
}
|