@lumeer/pivot 0.0.1

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.
@@ -0,0 +1,92 @@
1
+ /*
2
+ * Lumeer: Modern Data Definition and Processing Platform
3
+ *
4
+ * Copyright (C) since 2017 Lumeer.io, s.r.o. and/or its affiliates.
5
+ *
6
+ * This program is free software: you can redistribute it and/or modify
7
+ * it under the terms of the GNU General Public License as published by
8
+ * the Free Software Foundation, either version 3 of the License, or
9
+ * (at your option) any later version.
10
+ *
11
+ * This program is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ * GNU General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU General Public License
17
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
18
+ */
19
+
20
+ import {cleanQueryAttribute, Query, QueryStem} from '@lumeer/data-filters';
21
+ import {deepObjectsEquals, hex2rgba} from '@lumeer/utils';
22
+ import {LmrPivotAttribute, LmrPivotConfig, LmrPivotConfigVersion, LmrPivotStemConfig} from './lmr-pivot-config';
23
+ import {COLOR_LIGHT, COLOR_PRIMARY} from './lmr-pivot-constants';
24
+
25
+ export function pivotAttributesAreSame(a1: LmrPivotAttribute, a2: LmrPivotAttribute): boolean {
26
+ return deepObjectsEquals(cleanQueryAttribute(a1), cleanQueryAttribute(a2));
27
+ }
28
+
29
+ export function isPivotConfigChanged(viewConfig: LmrPivotConfig, currentConfig: LmrPivotConfig): boolean {
30
+ if (!!viewConfig.mergeTables !== !!currentConfig.mergeTables && (currentConfig.stemsConfigs || []).length > 1) {
31
+ return true;
32
+ }
33
+
34
+ return pivotStemConfigsHasChanged(viewConfig.stemsConfigs || [], currentConfig.stemsConfigs || []);
35
+ }
36
+
37
+ function pivotStemConfigsHasChanged(s1: LmrPivotStemConfig[], s2: LmrPivotStemConfig[]): boolean {
38
+ if (s1.length !== s2.length) {
39
+ return true;
40
+ }
41
+
42
+ return s1.some((stemConfig, index) => pivotStemConfigHasChanged(stemConfig, s2[index]));
43
+ }
44
+
45
+ function pivotStemConfigHasChanged(s1: LmrPivotStemConfig, s2: LmrPivotStemConfig): boolean {
46
+ return (
47
+ !deepObjectsEquals(s1.rowAttributes || [], s2.rowAttributes || []) ||
48
+ !deepObjectsEquals(s1.columnAttributes || [], s2.columnAttributes || []) ||
49
+ !deepObjectsEquals(s1.valueAttributes || [], s2.valueAttributes || [])
50
+ );
51
+ }
52
+
53
+ export function createDefaultPivotConfig(query: Query): LmrPivotConfig {
54
+ const stems = (query && query.stems) || [];
55
+ const stemsConfigs = stems.map(stem => createDefaultPivotStemConfig(stem));
56
+ return {version: LmrPivotConfigVersion.V1, stemsConfigs: stemsConfigs, mergeTables: true};
57
+ }
58
+
59
+ export function createDefaultPivotStemConfig(stem?: QueryStem): LmrPivotStemConfig {
60
+ return {stem, rowAttributes: [], columnAttributes: [], valueAttributes: []};
61
+ }
62
+
63
+ export function pivotConfigIsEmpty(config: LmrPivotConfig): boolean {
64
+ return (config.stemsConfigs || []).every(stemConfig => pivotStemConfigIsEmpty(stemConfig));
65
+ }
66
+
67
+ export function pivotStemConfigIsEmpty(config: LmrPivotStemConfig): boolean {
68
+ return (
69
+ ((config && config.rowAttributes) || []).length === 0 &&
70
+ ((config && config.columnAttributes) || []).length === 0 &&
71
+ ((config && config.valueAttributes) || []).length === 0
72
+ );
73
+ }
74
+
75
+ export function contrastColor(color: string, returnCodes?: {dark: string; light: string}, opacity?: number): string {
76
+ if (!color) {
77
+ return returnCodes ? returnCodes.dark : COLOR_PRIMARY;
78
+ }
79
+
80
+ const f = parseInt(color.indexOf('#') === 0 ? color.slice(1) : color, 16),
81
+ R = f >> 16,
82
+ G = (f >> 8) & 0x00ff,
83
+ B = f & 0x0000ff;
84
+
85
+ const luminance = (0.299 * R + 0.587 * G + 0.114 * B) / 255;
86
+
87
+ if (luminance > 0.5) {
88
+ return returnCodes ? returnCodes.dark : hex2rgba(COLOR_PRIMARY, opacity || 1);
89
+ } else {
90
+ return returnCodes ? returnCodes.light : hex2rgba(COLOR_LIGHT, opacity || 1);
91
+ }
92
+ }
@@ -0,0 +1,11 @@
1
+ /*
2
+ * Public API Surface of lmr-pivot-table
3
+ */
4
+
5
+ export * from './lib/lmr-pivot-table.component';
6
+ export * from './lib/lmr-pivot-table.module';
7
+ export * from './lib/util/lmr-pivot-config';
8
+ export * from './lib/util/lmr-pivot-data';
9
+ export * from './lib/util/lmr-pivot-table';
10
+ export * from './lib/util/pivot-util';
11
+ export * from './lib/directives/lmr-templates.directive';
@@ -0,0 +1,14 @@
1
+ /* To learn more about this file see: https://angular.io/config/tsconfig. */
2
+ {
3
+ "extends": "../../tsconfig.json",
4
+ "compilerOptions": {
5
+ "outDir": "../../out-tsc/lib",
6
+ "declaration": true,
7
+ "declarationMap": true,
8
+ "inlineSources": true,
9
+ "types": []
10
+ },
11
+ "exclude": [
12
+ "**/*.spec.ts"
13
+ ]
14
+ }
@@ -0,0 +1,10 @@
1
+ /* To learn more about this file see: https://angular.io/config/tsconfig. */
2
+ {
3
+ "extends": "./tsconfig.lib.json",
4
+ "compilerOptions": {
5
+ "declarationMap": false
6
+ },
7
+ "angularCompilerOptions": {
8
+ "compilationMode": "partial"
9
+ }
10
+ }
@@ -0,0 +1,14 @@
1
+ /* To learn more about this file see: https://angular.io/config/tsconfig. */
2
+ {
3
+ "extends": "../../tsconfig.json",
4
+ "compilerOptions": {
5
+ "outDir": "../../out-tsc/spec",
6
+ "types": [
7
+ "jasmine"
8
+ ]
9
+ },
10
+ "include": [
11
+ "**/*.spec.ts",
12
+ "**/*.d.ts"
13
+ ]
14
+ }