@vuu-ui/vuu-data-local 2.1.18 → 2.1.19-beta.2

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.
Files changed (46) hide show
  1. package/package.json +11 -14
  2. package/src/array-data-source/aggregate-utils.js +121 -0
  3. package/src/array-data-source/array-data-source.js +671 -0
  4. package/src/array-data-source/array-data-utils.js +41 -0
  5. package/src/array-data-source/group-utils.js +138 -0
  6. package/src/array-data-source/sort-utils.js +56 -0
  7. package/src/index.js +3 -0
  8. package/src/json-data-source/JsonDataSource.js +319 -0
  9. package/src/tree-data-source/IconProvider.js +11 -0
  10. package/src/tree-data-source/TreeDataSource.js +353 -0
  11. package/cjs/array-data-source/aggregate-utils.js +0 -237
  12. package/cjs/array-data-source/aggregate-utils.js.map +0 -1
  13. package/cjs/array-data-source/array-data-source.js +0 -912
  14. package/cjs/array-data-source/array-data-source.js.map +0 -1
  15. package/cjs/array-data-source/array-data-utils.js +0 -62
  16. package/cjs/array-data-source/array-data-utils.js.map +0 -1
  17. package/cjs/array-data-source/group-utils.js +0 -187
  18. package/cjs/array-data-source/group-utils.js.map +0 -1
  19. package/cjs/array-data-source/sort-utils.js +0 -73
  20. package/cjs/array-data-source/sort-utils.js.map +0 -1
  21. package/cjs/index.js +0 -12
  22. package/cjs/index.js.map +0 -1
  23. package/cjs/json-data-source/JsonDataSource.js +0 -404
  24. package/cjs/json-data-source/JsonDataSource.js.map +0 -1
  25. package/cjs/tree-data-source/IconProvider.js +0 -28
  26. package/cjs/tree-data-source/IconProvider.js.map +0 -1
  27. package/cjs/tree-data-source/TreeDataSource.js +0 -434
  28. package/cjs/tree-data-source/TreeDataSource.js.map +0 -1
  29. package/esm/array-data-source/aggregate-utils.js +0 -235
  30. package/esm/array-data-source/aggregate-utils.js.map +0 -1
  31. package/esm/array-data-source/array-data-source.js +0 -910
  32. package/esm/array-data-source/array-data-source.js.map +0 -1
  33. package/esm/array-data-source/array-data-utils.js +0 -59
  34. package/esm/array-data-source/array-data-utils.js.map +0 -1
  35. package/esm/array-data-source/group-utils.js +0 -183
  36. package/esm/array-data-source/group-utils.js.map +0 -1
  37. package/esm/array-data-source/sort-utils.js +0 -69
  38. package/esm/array-data-source/sort-utils.js.map +0 -1
  39. package/esm/index.js +0 -4
  40. package/esm/index.js.map +0 -1
  41. package/esm/json-data-source/JsonDataSource.js +0 -402
  42. package/esm/json-data-source/JsonDataSource.js.map +0 -1
  43. package/esm/tree-data-source/IconProvider.js +0 -26
  44. package/esm/tree-data-source/IconProvider.js.map +0 -1
  45. package/esm/tree-data-source/TreeDataSource.js +0 -432
  46. package/esm/tree-data-source/TreeDataSource.js.map +0 -1
package/package.json CHANGED
@@ -1,34 +1,31 @@
1
1
  {
2
- "version": "2.1.18",
2
+ "version": "2.1.19-beta.2",
3
3
  "author": "heswell",
4
+ "type": "module",
4
5
  "license": "Apache-2.0",
5
6
  "devDependencies": {
6
- "@vuu-ui/vuu-data-types": "2.1.18",
7
- "@vuu-ui/vuu-table-types": "2.1.18",
8
- "@vuu-ui/vuu-filter-types": "2.1.18",
9
- "@vuu-ui/vuu-protocol-types": "2.1.18"
7
+ "@vuu-ui/vuu-data-types": "2.1.19-beta.2",
8
+ "@vuu-ui/vuu-table-types": "2.1.19-beta.2",
9
+ "@vuu-ui/vuu-filter-types": "2.1.19-beta.2",
10
+ "@vuu-ui/vuu-protocol-types": "2.1.19-beta.2"
10
11
  },
11
12
  "dependencies": {
12
- "@vuu-ui/vuu-filter-parser": "2.1.18",
13
- "@vuu-ui/vuu-utils": "2.1.18"
13
+ "@vuu-ui/vuu-filter-parser": "2.1.19-beta.2",
14
+ "@vuu-ui/vuu-utils": "2.1.19-beta.2"
14
15
  },
15
16
  "sideEffects": false,
16
17
  "files": [
17
18
  "README.md",
18
- "esm",
19
- "cjs",
19
+ "src",
20
20
  "/types"
21
21
  ],
22
22
  "exports": {
23
23
  ".": {
24
- "require": "./cjs/index.js",
25
- "import": "./esm/index.js",
24
+ "import": "./src/index.js",
26
25
  "types": "./types/index.d.ts"
27
26
  }
28
27
  },
29
- "main": "cjs/index.js",
30
- "module": "esm/index.js",
28
+ "module": "index.js",
31
29
  "name": "@vuu-ui/vuu-data-local",
32
- "type": "module",
33
30
  "types": "types/index.d.ts"
34
31
  }
@@ -0,0 +1,121 @@
1
+ const aggregate_utils_count = (arr)=>arr.length;
2
+ const aggregateData = (aggregations, targetData, groupBy, leafData, columnMap, groupMap)=>{
3
+ const aggType = aggregations[aggregations.length - 1].aggType;
4
+ const groupIndices = groupBy.map((column)=>columnMap[column]);
5
+ switch(aggType){
6
+ case 1:
7
+ return aggregateSum(groupMap, leafData, columnMap, aggregations, targetData, groupIndices);
8
+ case 2:
9
+ return aggregateAverage(groupMap, leafData, columnMap, aggregations, targetData, groupIndices);
10
+ case 3:
11
+ return aggregateCount(groupMap, columnMap, aggregations, targetData, groupIndices);
12
+ case 4:
13
+ return aggregateHigh(groupMap, leafData, columnMap, aggregations, targetData, groupIndices);
14
+ case 5:
15
+ return aggregateLow(groupMap, leafData, columnMap, aggregations, targetData, groupIndices);
16
+ case 6:
17
+ return aggregateDistinct(groupMap, leafData, columnMap, aggregations, targetData, groupIndices);
18
+ }
19
+ };
20
+ function aggregateCount(groupMap, columnMap, aggregations, targetData, groupIndices) {
21
+ const counts = {};
22
+ const aggColumn = getAggColumn(columnMap, aggregations);
23
+ function countRecursive(map) {
24
+ if (Array.isArray(map)) return map.length;
25
+ {
26
+ let count = 0;
27
+ for(const key in map)count += 1 + countRecursive(map[key]);
28
+ return count;
29
+ }
30
+ }
31
+ for(const key in groupMap){
32
+ const count = countRecursive(groupMap[key]);
33
+ counts[key] = count;
34
+ }
35
+ for(let index = 0; index < targetData.length; index++)for(const key in counts)if (targetData[index][groupIndices[0]] === key) targetData[index][aggColumn] = counts[key];
36
+ return counts;
37
+ }
38
+ function getAggColumn(columnMap, aggregations) {
39
+ const columnName = aggregations[aggregations.length - 1].column;
40
+ const columnNumber = columnMap[columnName];
41
+ return columnNumber;
42
+ }
43
+ function aggregateSum(groupMap, leafData, columnMap, aggregations, targetData, groupIndices) {
44
+ const sums = {};
45
+ const aggColumn = getAggColumn(columnMap, aggregations);
46
+ function sumRecursive(map, leafData, aggColumn) {
47
+ if (Array.isArray(map)) {
48
+ let sum = 0;
49
+ for (const key of map)sum += Number(leafData[key][aggColumn]);
50
+ return sum;
51
+ }
52
+ {
53
+ let sum = 0;
54
+ for(const key in map)sum += sumRecursive(map[key], leafData, aggColumn);
55
+ return sum;
56
+ }
57
+ }
58
+ for(const key in groupMap){
59
+ const sum = Number(sumRecursive(groupMap[key], leafData, aggColumn));
60
+ sums[key] = sum;
61
+ }
62
+ for(let index = 0; index < targetData.length; index++)for(const key in sums)if (targetData[index][groupIndices[0]] === key) targetData[index][aggColumn] = sums[key];
63
+ return sums;
64
+ }
65
+ function aggregateAverage(groupMap, leafData, columnMap, aggregations, targetData, groupIndices) {
66
+ const averages = {};
67
+ const aggColumn = getAggColumn(columnMap, aggregations);
68
+ const count = aggregateCount(groupMap, columnMap, aggregations, targetData, groupIndices);
69
+ const sum = aggregateSum(groupMap, leafData, columnMap, aggregations, targetData, groupIndices);
70
+ for(const key in count){
71
+ let average = 0;
72
+ average = sum[key] / count[key];
73
+ averages[key] = average;
74
+ }
75
+ for(let index = 0; index < targetData.length; index++)for(const key in averages)if (targetData[index][groupIndices[0]] === key) targetData[index][aggColumn] = averages[key];
76
+ console.log("!!!! targetData", targetData);
77
+ console.log("!!!! averages", averages);
78
+ return averages;
79
+ }
80
+ function getLeafColumnData(map, leafData, aggColumn) {
81
+ const data = [];
82
+ if (Array.isArray(map)) for (const key of map)data.push(leafData[key][aggColumn]);
83
+ else for(const key in map)data.push(...getLeafColumnData(map[key], leafData, aggColumn));
84
+ return data;
85
+ }
86
+ function aggregateDistinct(groupMap, leafData, columnMap, aggregations, targetData, groupIndices) {
87
+ const distincts = {};
88
+ const aggColumn = getAggColumn(columnMap, aggregations);
89
+ for(const key in groupMap){
90
+ const leafColumnData = getLeafColumnData(groupMap[key], leafData, aggColumn);
91
+ const distinct = [
92
+ ...new Set(leafColumnData)
93
+ ];
94
+ distincts[key] = distinct.length;
95
+ }
96
+ for(let index = 0; index < targetData.length; index++)for(const key in distincts)if (targetData[index][groupIndices[0]] === key) targetData[index][aggColumn] = distincts[key];
97
+ return distincts;
98
+ }
99
+ function aggregateHigh(groupMap, leafData, columnMap, aggregations, targetData, groupIndices) {
100
+ const highs = {};
101
+ const aggColumn = getAggColumn(columnMap, aggregations);
102
+ for(const key in groupMap){
103
+ const leafColumnData = getLeafColumnData(groupMap[key], leafData, aggColumn);
104
+ const maxNumber = Math.max(...leafColumnData);
105
+ highs[key] = maxNumber;
106
+ }
107
+ for(let index = 0; index < targetData.length; index++)for(const key in highs)if (targetData[index][groupIndices[0]] === key) targetData[index][aggColumn] = highs[key];
108
+ return highs;
109
+ }
110
+ function aggregateLow(groupMap, leafData, columnMap, aggregations, targetData, groupIndices) {
111
+ const mins = {};
112
+ const aggColumn = getAggColumn(columnMap, aggregations);
113
+ for(const key in groupMap){
114
+ const leafColumnData = getLeafColumnData(groupMap[key], leafData, aggColumn);
115
+ const minNumber = Math.min(...leafColumnData);
116
+ mins[key] = minNumber;
117
+ }
118
+ for(let index = 0; index < targetData.length; index++)for(const key in mins)if (targetData[index][groupIndices[0]] === key) targetData[index][aggColumn] = mins[key];
119
+ return mins;
120
+ }
121
+ export { aggregateData, aggregate_utils_count as count };