@linkurious/ogma-linkurious-parser 4.1.7 → 4.1.9

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 (47) hide show
  1. package/dist/index.cjs +4 -0
  2. package/dist/index.cjs.map +1 -0
  3. package/dist/index.d.ts +5 -5
  4. package/dist/index.mjs +4099 -0
  5. package/dist/index.mjs.map +1 -0
  6. package/dist/ogma/features/nodeGrouping.d.ts +15 -1
  7. package/dist/styles/styleRules.d.ts +8 -0
  8. package/dist/tools/ogmaTool.d.ts +3 -1
  9. package/package.json +23 -21
  10. package/dist/captions/captions.js +0 -115
  11. package/dist/captions/captions.js.map +0 -1
  12. package/dist/filters/filters.js +0 -167
  13. package/dist/filters/filters.js.map +0 -1
  14. package/dist/index.js +0 -56
  15. package/dist/index.js.map +0 -1
  16. package/dist/ogma/features/OgmaStore.js +0 -37
  17. package/dist/ogma/features/OgmaStore.js.map +0 -1
  18. package/dist/ogma/features/captions.js +0 -117
  19. package/dist/ogma/features/captions.js.map +0 -1
  20. package/dist/ogma/features/nodeGrouping.js +0 -283
  21. package/dist/ogma/features/nodeGrouping.js.map +0 -1
  22. package/dist/ogma/features/reactive.js +0 -132
  23. package/dist/ogma/features/reactive.js.map +0 -1
  24. package/dist/ogma/features/selectors.js +0 -97
  25. package/dist/ogma/features/selectors.js.map +0 -1
  26. package/dist/ogma/features/styles.js +0 -689
  27. package/dist/ogma/features/styles.js.map +0 -1
  28. package/dist/ogma/features/transformations.js +0 -86
  29. package/dist/ogma/features/transformations.js.map +0 -1
  30. package/dist/ogma/index.js +0 -326
  31. package/dist/ogma/index.js.map +0 -1
  32. package/dist/styles/edgeAttributes.js +0 -115
  33. package/dist/styles/edgeAttributes.js.map +0 -1
  34. package/dist/styles/itemAttributes.js +0 -133
  35. package/dist/styles/itemAttributes.js.map +0 -1
  36. package/dist/styles/nodeAttributes.js +0 -228
  37. package/dist/styles/nodeAttributes.js.map +0 -1
  38. package/dist/styles/styleRule.js +0 -194
  39. package/dist/styles/styleRule.js.map +0 -1
  40. package/dist/styles/styleRules.js +0 -292
  41. package/dist/styles/styleRules.js.map +0 -1
  42. package/dist/tools/colorPalette.js +0 -145
  43. package/dist/tools/colorPalette.js.map +0 -1
  44. package/dist/tools/ogmaTool.js +0 -86
  45. package/dist/tools/ogmaTool.js.map +0 -1
  46. package/dist/tools/tools.js +0 -409
  47. package/dist/tools/tools.js.map +0 -1
@@ -1,194 +0,0 @@
1
- 'use strict';
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.StyleRule = exports.StyleRuleType = void 0;
4
- const rest_client_1 = require("@linkurious/rest-client");
5
- const __1 = require("..");
6
- const tools_1 = require("../tools/tools");
7
- var StyleRuleType;
8
- (function (StyleRuleType) {
9
- StyleRuleType["AUTO_RANGE"] = "autoRange";
10
- })(StyleRuleType || (exports.StyleRuleType = StyleRuleType = {}));
11
- class StyleRule {
12
- constructor(model) {
13
- this.type = model.type;
14
- this.input = model.input;
15
- this.index = model.index;
16
- this.itemType = model.itemType;
17
- this.style = model.style;
18
- // cast to remove undefined from type
19
- this.value = model.value;
20
- }
21
- static isAutomaticRange(rule) {
22
- return (rule.style !== undefined &&
23
- ((rule.style.width !== undefined &&
24
- rule.style.width.type === StyleRuleType.AUTO_RANGE) ||
25
- (rule.style.size !== undefined &&
26
- rule.style.size.type === StyleRuleType.AUTO_RANGE)));
27
- }
28
- /**
29
- * Return an int describing specificity of the style. 4 = very specific / 1 = not specific
30
- *
31
- * @return {number}
32
- */
33
- get specificity() {
34
- if (this.itemType !== undefined && this.input !== undefined) {
35
- return 4;
36
- }
37
- if (this.itemType === undefined && this.input !== undefined) {
38
- return 3;
39
- }
40
- if (this.itemType !== undefined && this.input === undefined) {
41
- return 2;
42
- }
43
- return 1;
44
- }
45
- /**
46
- * Return true if this style match values
47
- */
48
- matchValues(itemType, input, value) {
49
- if (tools_1.Tools.isDefined(input)) {
50
- return (((itemType === this.itemType || !tools_1.Tools.isDefined(this.itemType)) &&
51
- tools_1.Tools.isEqual(['properties', ...input], this.input) &&
52
- tools_1.Tools.isEqual(value, this.value)) ||
53
- (this.type === 'any' &&
54
- !tools_1.Tools.isDefined(this.input) &&
55
- typeof this.style.color === 'object' &&
56
- this.style.color.input[1] === input[0]));
57
- }
58
- if (tools_1.Tools.isDefined(this.itemType)) {
59
- return itemType === this.itemType && !tools_1.Tools.isDefined(this.input);
60
- }
61
- return !tools_1.Tools.isDefined(this.input);
62
- }
63
- static inputExists(type, input) {
64
- return type !== rest_client_1.SelectorType.ANY;
65
- }
66
- /**
67
- * Return true if a style can apply to a node
68
- */
69
- canApplyTo(data) {
70
- const types = 'categories' in data ? data.categories : [data.type];
71
- let typePredicate = false;
72
- switch (this.type) {
73
- case rest_client_1.SelectorType.ANY:
74
- typePredicate = StyleRule.checkAny(data, this.style);
75
- break;
76
- case rest_client_1.SelectorType.NO_VALUE:
77
- if (StyleRule.inputExists(this.type, this.input)) {
78
- typePredicate = StyleRule.checkNoValue(data, this.input);
79
- }
80
- break;
81
- case rest_client_1.SelectorType.NAN:
82
- if (StyleRule.inputExists(this.type, this.input)) {
83
- typePredicate = StyleRule.checkNan(data, this.input);
84
- }
85
- break;
86
- case rest_client_1.SelectorType.RANGE:
87
- if (StyleRule.inputExists(this.type, this.input)) {
88
- typePredicate = StyleRule.checkRange(tools_1.Tools.getIn(data, this.input), this.value);
89
- }
90
- break;
91
- case rest_client_1.SelectorType.IS:
92
- if (StyleRule.inputExists(this.type, this.input)) {
93
- typePredicate = StyleRule.checkIs(data, this.input, this.value);
94
- }
95
- break;
96
- }
97
- return typePredicate && StyleRule.checkItemType(types, this.itemType);
98
- }
99
- /**
100
- * Return true or false on rule type 'any' if the current node match the rule
101
- */
102
- static checkAny(data, style) {
103
- // return true if autoColor by a property and this property exists in node
104
- if (typeof style.color === 'object') {
105
- return tools_1.Tools.isDefined(tools_1.Tools.getIn(data, style.color.input));
106
- }
107
- return true;
108
- }
109
- /**
110
- * Return true or false on rule type 'noValue' if the current node match the rule
111
- */
112
- static checkNoValue(data, input) {
113
- return !tools_1.Tools.valueExists(tools_1.Tools.getIn(data, input));
114
- }
115
- /**
116
- * Return true or false on rule type 'NaN' if the current node match the rule
117
- */
118
- static checkNan(data, input) {
119
- return !tools_1.Tools.isNumber(tools_1.Tools.getIn(data, input));
120
- }
121
- /**
122
- * Return true if predicate is true for the node value
123
- *
124
- * @param value
125
- * @param comparator
126
- * @return {boolean}
127
- */
128
- static checkRange(value, comparator) {
129
- return ((comparator['<='] === undefined || value <= comparator['<=']) &&
130
- (comparator['<'] === undefined || value < comparator['<']) &&
131
- (comparator['>'] === undefined || value > comparator['>']) &&
132
- (comparator['>='] === undefined || value >= comparator['>=']));
133
- }
134
- /**
135
- * Return true or false on rule type 'is' if the current node match the rule
136
- */
137
- static checkIs(data, input, value) {
138
- if (!tools_1.Tools.isDefined(input)) {
139
- return false;
140
- }
141
- const itemValue = tools_1.Tools.getIn(data, input);
142
- let formattedValue = itemValue;
143
- if (tools_1.Tools.isDefined(itemValue) &&
144
- typeof itemValue === 'object' &&
145
- (itemValue.type === 'date' || itemValue.type === 'datetime')) {
146
- let timezone = itemValue.timezone;
147
- if (itemValue.timezone === 'Z') {
148
- timezone = '+00:00';
149
- }
150
- formattedValue = tools_1.Tools.formatDate(itemValue.value, itemValue.type === 'datetime', tools_1.Tools.timezoneToMilliseconds(timezone) / 1000);
151
- }
152
- return tools_1.Tools.isEqual(formattedValue, value);
153
- }
154
- /**
155
- * Check that value of itemType match for the node
156
- */
157
- static checkItemType(types, itemType) {
158
- return StyleRule.matchCategory(types, itemType) || StyleRule.matchAny(itemType);
159
- }
160
- /**
161
- * Return true if itemType is defined and category exists in an array of categories
162
- *
163
- * @param {Array<string> | string} types
164
- * @param {string} itemType
165
- * @return {boolean}
166
- */
167
- static matchCategory(types, itemType) {
168
- return (tools_1.Tools.isDefined(itemType) &&
169
- (Array.isArray(types) ? types.includes(itemType) : tools_1.Tools.isEqual(types, itemType)));
170
- }
171
- /**
172
- * Return true if itemType is undefined
173
- *
174
- * @param {string} itemType
175
- * @return {boolean}
176
- */
177
- static matchAny(itemType) {
178
- return itemType === undefined;
179
- }
180
- /**
181
- * Return the color for a type
182
- */
183
- getTypeColor(type) {
184
- let color;
185
- if (StyleRule.checkItemType([type], this.itemType) &&
186
- this.type === rest_client_1.SelectorType.ANY &&
187
- !tools_1.Tools.isDefined(this.input)) {
188
- color = __1.ItemAttributes.getTypeColor(this, type);
189
- }
190
- return color;
191
- }
192
- }
193
- exports.StyleRule = StyleRule;
194
- //# sourceMappingURL=styleRule.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"styleRule.js","sourceRoot":"","sources":["../../src/styles/styleRule.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;AAEb,yDASiC;AAEjC,0BAAkC;AAClC,0CAAqC;AAErC,IAAY,aAEX;AAFD,WAAY,aAAa;IACvB,yCAAwB,CAAA;AAC1B,CAAC,EAFW,aAAa,6BAAb,aAAa,QAExB;AAED,MAAa,SAAS;IASpB,YAAY,KAAoB;QAC9B,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC;QACvB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;QACzB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;QACzB,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC;QAC/B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;QACzB,qCAAqC;QACrC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,KAAiD,CAAC;IACvE,CAAC;IAEM,MAAM,CAAC,gBAAgB,CAAC,IAAyC;QACtE,OAAO,CACL,IAAI,CAAC,KAAK,KAAK,SAAS;YACxB,CAAC,CAAE,IAAI,CAAC,KAAoB,CAAC,KAAK,KAAK,SAAS;gBAC5C,IAAI,CAAC,KAAoB,CAAC,KAAyB,CAAC,IAAI,KAAK,aAA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,CAAC,KAAK,CAAC,EAC5B,CAAC;YACD,KAAK,GAAG,kBAAc,CAAC,YAAY,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAClD,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AArPD,8BAqPC","sourcesContent":["'use strict';\n\nimport {\n IEdgeStyle,\n IStyleRule,\n LkEdgeData,\n LkNodeData,\n INodeStyle,\n IRangeValues,\n SelectorType,\n IStyleAutoRange\n} from '@linkurious/rest-client';\n\nimport {ItemAttributes} from '..';\nimport {Tools} from '../tools/tools';\n\nexport enum StyleRuleType {\n AUTO_RANGE = 'autoRange'\n}\n\nexport class StyleRule<T extends INodeStyle | IEdgeStyle = INodeStyle | IEdgeStyle>\n implements IStyleRule<T> {\n public type: SelectorType;\n public input: string[] | undefined;\n public index: number;\n public style: T;\n public itemType?: string;\n public value: IRangeValues | number | string | boolean;\n\n constructor(model: IStyleRule<T>) {\n this.type = model.type;\n this.input = model.input;\n this.index = model.index;\n this.itemType = model.itemType;\n this.style = model.style;\n // cast to remove undefined from type\n this.value = model.value as IRangeValues | number | string | boolean;\n }\n\n public static isAutomaticRange(rule: IStyleRule<IEdgeStyle | INodeStyle>): boolean {\n return (\n rule.style !== undefined &&\n (((rule.style as IEdgeStyle).width !== undefined &&\n ((rule.style as IEdgeStyle).width as IStyleAutoRange).type === StyleRuleType.AUTO_RANGE) ||\n ((rule.style as INodeStyle).size !== undefined &&\n ((rule.style as INodeStyle).size as IStyleAutoRange).type === StyleRuleType.AUTO_RANGE))\n );\n }\n\n /**\n * Return an int describing specificity of the style. 4 = very specific / 1 = not specific\n *\n * @return {number}\n */\n get specificity(): 1 | 2 | 3 | 4 {\n if (this.itemType !== undefined && this.input !== undefined) {\n return 4;\n }\n if (this.itemType === undefined && this.input !== undefined) {\n return 3;\n }\n if (this.itemType !== undefined && this.input === undefined) {\n return 2;\n }\n return 1;\n }\n\n /**\n * Return true if this style match values\n */\n public matchValues(\n itemType: string | undefined,\n input: Array<string> | undefined,\n value: string | undefined\n ): boolean {\n if (Tools.isDefined(input)) {\n return (\n ((itemType === this.itemType || !Tools.isDefined(this.itemType)) &&\n Tools.isEqual(['properties', ...input], this.input) &&\n Tools.isEqual(value, this.value)) ||\n (this.type === 'any' &&\n !Tools.isDefined(this.input) &&\n typeof this.style.color === 'object' &&\n this.style.color.input[1] === input[0])\n );\n }\n\n if (Tools.isDefined(this.itemType)) {\n return itemType === this.itemType && !Tools.isDefined(this.input);\n }\n\n return !Tools.isDefined(this.input);\n }\n\n public static inputExists(\n type: SelectorType,\n input: Array<string> | undefined\n ): input is Array<string> {\n return type !== SelectorType.ANY;\n }\n\n /**\n * Return true if a style can apply to a node\n */\n public canApplyTo(data: LkNodeData | LkEdgeData): boolean {\n const types = 'categories' in data ? data.categories : [data.type];\n let typePredicate = false;\n switch (this.type) {\n case SelectorType.ANY:\n typePredicate = StyleRule.checkAny(data, this.style);\n break;\n\n case SelectorType.NO_VALUE:\n if (StyleRule.inputExists(this.type, this.input)) {\n typePredicate = StyleRule.checkNoValue(data, this.input);\n }\n break;\n\n case SelectorType.NAN:\n if (StyleRule.inputExists(this.type, this.input)) {\n typePredicate = StyleRule.checkNan(data, this.input);\n }\n break;\n\n case SelectorType.RANGE:\n if (StyleRule.inputExists(this.type, this.input)) {\n typePredicate = StyleRule.checkRange(\n Tools.getIn(data, this.input),\n this.value as IRangeValues\n );\n }\n break;\n\n case SelectorType.IS:\n if (StyleRule.inputExists(this.type, this.input)) {\n typePredicate = StyleRule.checkIs(data, this.input, this.value);\n }\n break;\n }\n return typePredicate && StyleRule.checkItemType(types, this.itemType);\n }\n\n /**\n * Return true or false on rule type 'any' if the current node match the rule\n */\n public static checkAny(data: LkNodeData | LkEdgeData, style: INodeStyle | IEdgeStyle): boolean {\n // return true if autoColor by a property and this property exists in node\n if (typeof style.color === 'object') {\n return Tools.isDefined(Tools.getIn(data, style.color.input));\n }\n return true;\n }\n\n /**\n * Return true or false on rule type 'noValue' if the current node match the rule\n */\n public static checkNoValue(data: LkNodeData | LkEdgeData, input: Array<string>): boolean {\n return !Tools.valueExists(Tools.getIn(data, input));\n }\n\n /**\n * Return true or false on rule type 'NaN' if the current node match the rule\n */\n public static checkNan(data: LkNodeData | LkEdgeData, input: Array<string>): boolean {\n return !Tools.isNumber(Tools.getIn(data, input));\n }\n\n /**\n * Return true if predicate is true for the node value\n *\n * @param value\n * @param comparator\n * @return {boolean}\n */\n public static checkRange(\n value: number,\n comparator: {[key in '<=' | '<' | '>' | '>=']?: number}\n ): boolean {\n return (\n (comparator['<='] === undefined || value <= comparator['<=']) &&\n (comparator['<'] === undefined || value < comparator['<']) &&\n (comparator['>'] === undefined || value > comparator['>']) &&\n (comparator['>='] === undefined || value >= comparator['>='])\n );\n }\n\n /**\n * Return true or false on rule type 'is' if the current node match the rule\n */\n public static checkIs(\n data: LkNodeData | LkEdgeData,\n input: Array<string>,\n value: IRangeValues | number | string | boolean\n ): boolean {\n if (!Tools.isDefined(input)) {\n return false;\n }\n const itemValue = Tools.getIn(data, input);\n let formattedValue = itemValue;\n if (\n Tools.isDefined(itemValue) &&\n typeof itemValue === 'object' &&\n (itemValue.type === 'date' || itemValue.type === 'datetime')\n ) {\n let timezone = itemValue.timezone;\n if (itemValue.timezone === 'Z') {\n timezone = '+00:00';\n }\n formattedValue = Tools.formatDate(\n itemValue.value,\n itemValue.type === 'datetime',\n Tools.timezoneToMilliseconds(timezone) / 1000\n );\n }\n return Tools.isEqual(formattedValue, value);\n }\n\n /**\n * Check that value of itemType match for the node\n */\n public static checkItemType(types: Array<string>, itemType: string | undefined): boolean {\n return StyleRule.matchCategory(types, itemType) || StyleRule.matchAny(itemType);\n }\n\n /**\n * Return true if itemType is defined and category exists in an array of categories\n *\n * @param {Array<string> | string} types\n * @param {string} itemType\n * @return {boolean}\n */\n public static matchCategory(\n types: Array<string> | string,\n itemType: string | undefined\n ): boolean {\n return (\n Tools.isDefined(itemType) &&\n (Array.isArray(types) ? types.includes(itemType) : Tools.isEqual(types, itemType))\n );\n }\n\n /**\n * Return true if itemType is undefined\n *\n * @param {string} itemType\n * @return {boolean}\n */\n public static matchAny(itemType: string | null | undefined): boolean {\n return itemType === undefined;\n }\n\n /**\n * Return the color for a type\n */\n public getTypeColor(type: string): string | undefined | null {\n let color;\n if (\n StyleRule.checkItemType([type], this.itemType) &&\n this.type === SelectorType.ANY &&\n !Tools.isDefined(this.input)\n ) {\n color = ItemAttributes.getTypeColor(this, type);\n }\n return color;\n }\n}\n"]}
@@ -1,292 +0,0 @@
1
- 'use strict';
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.StyleRules = exports.SORTING_RULE = exports.StyleType = void 0;
4
- const rest_client_1 = require("@linkurious/rest-client");
5
- const tools_1 = require("../tools/tools");
6
- const styleRule_1 = require("./styleRule");
7
- const itemAttributes_1 = require("./itemAttributes");
8
- var StyleType;
9
- (function (StyleType) {
10
- StyleType["COLOR"] = "color";
11
- StyleType["ICON"] = "icon";
12
- StyleType["SIZE"] = "size";
13
- StyleType["IMAGE"] = "image";
14
- StyleType["SHAPE"] = "shape";
15
- StyleType["WIDTH"] = "width";
16
- })(StyleType || (exports.StyleType = StyleType = {}));
17
- exports.SORTING_RULE = ['specificity', 'itemType', 'index'];
18
- class StyleRules {
19
- constructor(rules) {
20
- this._rules = rules;
21
- }
22
- /**
23
- * Return an array of StyleRule with only 'color' rules and sorted by specificity, itemType and index
24
- *
25
- * @return {Array<StyleRule>}
26
- */
27
- get color() {
28
- return (0, tools_1.sortBy)(StyleRules.getBy(StyleType.COLOR, this._rules), exports.SORTING_RULE);
29
- }
30
- /**
31
- * Return an array of StyleRule with only 'icon' rules and sorted by specificity, itemType and index
32
- *
33
- * @return {Array<StyleRule>}
34
- */
35
- get icon() {
36
- return (0, tools_1.sortBy)([
37
- ...(StyleRules.getBy(StyleType.ICON, this._rules) || []),
38
- ...(StyleRules.getBy(StyleType.IMAGE, this._rules) || [])
39
- ], exports.SORTING_RULE);
40
- }
41
- /**
42
- * Return an array of StyleRule with only 'image' rules and sorted by specificity, itemType and index
43
- *
44
- * @return {Array<StyleRule>}
45
- */
46
- get image() {
47
- return (0, tools_1.sortBy)(StyleRules.getBy(StyleType.IMAGE, this._rules), exports.SORTING_RULE);
48
- }
49
- /**
50
- * Return an array of StyleRule with only 'shape' rules and sorted by specificity, itemType and index
51
- *
52
- * @return {Array<StyleRule>}
53
- */
54
- get shape() {
55
- return (0, tools_1.sortBy)(StyleRules.getBy(StyleType.SHAPE, this._rules), exports.SORTING_RULE);
56
- }
57
- /**
58
- * Return an array of StyleRule with only 'size' rules and sorted by specificity, itemType and index
59
- *
60
- * @return {Array<StyleRule>}
61
- */
62
- get size() {
63
- return (0, tools_1.sortBy)(StyleRules.getBy(StyleType.SIZE, this._rules), exports.SORTING_RULE);
64
- }
65
- /**
66
- * Return an array of StyleRule with only 'width' rules and sorted by specificity, itemType and index
67
- *
68
- * @return {Array<StyleRule>}
69
- */
70
- get width() {
71
- return (0, tools_1.sortBy)(StyleRules.getBy(StyleType.WIDTH, this._rules), exports.SORTING_RULE);
72
- }
73
- /**
74
- * Return an object containing for each node style a sorted array of StyleRule
75
- *
76
- * @return {{[key: string]: Array<StyleRule>} }
77
- */
78
- get nodeRules() {
79
- return {
80
- color: this.color,
81
- icon: this.icon,
82
- image: this.image,
83
- shape: this.shape,
84
- size: this.size
85
- };
86
- }
87
- /**
88
- * Return an object containing for each edge style a sorted array of StyleRule
89
- *
90
- * @return { {[key: string]: Array<StyleRule>}}
91
- */
92
- get edgeRules() {
93
- return {
94
- color: this.color,
95
- shape: this.shape,
96
- width: this.width
97
- };
98
- }
99
- /**
100
- * Generate a legend with an array of style rules and existing items in visualization
101
- */
102
- generateLegend(itemsData) {
103
- const result = {};
104
- if (itemsData.length === 0) {
105
- return result;
106
- }
107
- if ('categories' in itemsData[0]) {
108
- Object.keys(this.nodeRules).forEach((style) => {
109
- result[style] = StyleRules.getLegendForStyle(style, this.nodeRules[style], itemsData);
110
- });
111
- }
112
- else {
113
- Object.keys(this.edgeRules).forEach((style) => {
114
- result[style] = StyleRules.getLegendForStyle(style, this.edgeRules[style], itemsData);
115
- });
116
- }
117
- return result;
118
- }
119
- /**
120
- * Return the legend for a specific style type (color, icon, image...)
121
- */
122
- static getLegendForStyle(styleType, styles, itemsData) {
123
- const result = [];
124
- const data = itemsData.filter((i) => i);
125
- for (let i = 0; i < styles.length; i++) {
126
- const styleRule = new styleRule_1.StyleRule(styles[i]);
127
- const ruleExistsInViz = data.some((itemData) => {
128
- return styleRule.canApplyTo(itemData);
129
- });
130
- if (ruleExistsInViz) {
131
- if (styleType === StyleType.COLOR && typeof styleRule.style.color === 'object') {
132
- StyleRules.addLegendAutoColors(data, styleRule, result);
133
- }
134
- else if (styleType === StyleType.ICON && 'image' in styleRule.style) {
135
- // style is a custom icon
136
- const label = tools_1.Tools.isDefined(styleRule.input)
137
- ? `${StyleRules.getTypeLabel(styleRule.itemType)}.${styleRule.input[1]} ${StyleRules.sanitizeValue(styleRule.type, styleRule.value)}`
138
- : `${StyleRules.getTypeLabel(styleRule.itemType)}`;
139
- const imageStyle = styleRule.style.image;
140
- if (imageStyle.url &&
141
- typeof imageStyle.url === 'object' &&
142
- imageStyle.url.type === 'data') {
143
- // If the custom icon is read from a node property-value dynamically, then we
144
- // skip it from the legend, because it could be a different image for each node,
145
- // thus bloating the legend.
146
- }
147
- else {
148
- const value = styleRule.style.image;
149
- StyleRules.updateLegend(result, { label: label, value: value });
150
- }
151
- }
152
- else {
153
- const label = tools_1.Tools.isDefined(styleRule.input)
154
- ? `${StyleRules.getTypeLabel(styleRule.itemType)}.${styleRule.input[1]} ${StyleRules.sanitizeValue(styleRule.type, styleRule.value)}`
155
- : `${StyleRules.getTypeLabel(styleRule.itemType)}`;
156
- const value = styleType === StyleType.WIDTH
157
- ? styleRule.style[styleType]
158
- : styleRule.style[styleType];
159
- StyleRules.updateLegend(result, { label: label, value: value });
160
- }
161
- }
162
- }
163
- return result;
164
- }
165
- /**
166
- * Sanitize value for legend
167
- */
168
- static sanitizeValue(styleType, value) {
169
- let template = '';
170
- switch (styleType) {
171
- case rest_client_1.SelectorType.NO_VALUE:
172
- return 'is undefined';
173
- case rest_client_1.SelectorType.NAN:
174
- return 'is not an number';
175
- case rest_client_1.SelectorType.RANGE:
176
- Object.keys(value).forEach((k, i) => {
177
- if (i > 0) {
178
- template += ' and ';
179
- }
180
- template += `${k} ${value[k]}`;
181
- });
182
- return template;
183
- }
184
- return typeof value === 'object' ? `= ${JSON.stringify(value)}` : `= ${value}`;
185
- }
186
- /**
187
- * Add items in legend for automatic coloring
188
- */
189
- static addLegendAutoColors(itemsData, styleRule, currentLegend) {
190
- const colorStyle = styleRule.style.color;
191
- const propertyKey = colorStyle.input[1];
192
- itemsData.forEach((data) => {
193
- const propValue = tools_1.Tools.getIn(data, colorStyle.input);
194
- if (Array.isArray(propValue)) {
195
- propValue.forEach((value) => {
196
- const label = colorStyle.input.includes('properties')
197
- ? `${StyleRules.getTypeLabel(styleRule.itemType)}.${propertyKey} = ${value}`
198
- : `${StyleRules.getTypeLabel(value)}`;
199
- const color = itemAttributes_1.ItemAttributes.autoColor(value, colorStyle.ignoreCase);
200
- StyleRules.updateLegend(currentLegend, { label: label, value: color });
201
- });
202
- }
203
- else {
204
- const label = colorStyle.input.includes('properties')
205
- ? `${StyleRules.getTypeLabel(styleRule.itemType)}.${propertyKey} = ${propValue}`
206
- : `${StyleRules.getTypeLabel(propValue)}`;
207
- const value = itemAttributes_1.ItemAttributes.autoColor(propValue, colorStyle.ignoreCase);
208
- StyleRules.updateLegend(currentLegend, { label: label, value: value });
209
- }
210
- });
211
- }
212
- /**
213
- * Return the label of item type for a legend item
214
- */
215
- static getTypeLabel(type) {
216
- return type === undefined ? 'All' : type === null ? 'Others' : type;
217
- }
218
- /**
219
- * Check if a legend item already exists and overwrite it / push it
220
- */
221
- static updateLegend(legend, { label, value }) {
222
- const indexOfLegendItem = legend.map((r) => r.label).indexOf(label);
223
- if (indexOfLegendItem < 0) {
224
- legend.push({ label: label, value: value });
225
- }
226
- else {
227
- legend[indexOfLegendItem] = { label: label, value: value };
228
- }
229
- }
230
- /**
231
- * return an array of StyleRule, containing only the desired style
232
- */
233
- static getBy(styleType, rules) {
234
- return rules
235
- .filter((style) => {
236
- switch (styleType) {
237
- case StyleType.COLOR:
238
- return style.style.color !== undefined;
239
- case StyleType.ICON:
240
- return 'icon' in style.style && style.style.icon !== undefined;
241
- case StyleType.IMAGE:
242
- return 'image' in style.style && style.style.image !== undefined;
243
- case StyleType.SHAPE:
244
- return style.style.shape !== undefined;
245
- case StyleType.SIZE:
246
- return 'size' in style.style && style.style.size !== undefined;
247
- case StyleType.WIDTH:
248
- return 'width' in style.style && style.style.width !== undefined;
249
- }
250
- })
251
- .map((style) => StyleRules.getRule(style, styleType));
252
- }
253
- /**
254
- * From a RawStyle, generate a StyleRule of a specific style
255
- */
256
- static getRule(rawRule, styleType) {
257
- const rule = tools_1.Tools.clone(rawRule);
258
- rule.style = { [styleType]: rule.style[styleType] };
259
- return new styleRule_1.StyleRule(rule);
260
- }
261
- /**
262
- * Check for non unique index in styles rules and update them if exists
263
- */
264
- static sanitizeStylesIndex(styles) {
265
- const seenIndex = [];
266
- const sanitizedStyles = tools_1.Tools.clone(styles);
267
- let maxIndex = Math.max(...[...styles.node.map((s) => s.index), ...styles.edge.map((s) => s.index)]) + 1;
268
- sanitizedStyles.node = sanitizedStyles.node.map((style) => {
269
- if (seenIndex.includes(style.index)) {
270
- style.index = maxIndex;
271
- maxIndex++;
272
- }
273
- else {
274
- seenIndex.push(style.index);
275
- }
276
- return style;
277
- });
278
- sanitizedStyles.edge = sanitizedStyles.edge.map((style) => {
279
- if (seenIndex.includes(style.index)) {
280
- style.index = maxIndex;
281
- maxIndex++;
282
- }
283
- else {
284
- seenIndex.push(style.index);
285
- }
286
- return style;
287
- });
288
- return sanitizedStyles;
289
- }
290
- }
291
- exports.StyleRules = StyleRules;
292
- //# sourceMappingURL=styleRules.js.map
@@ -1 +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AG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;QAC5F,eAAe,CAAC,IAAI,GAAG,eAAe,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;YACxD,IAAI,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;gBACpC,KAAK,CAAC,KAAK,GAAG,QAAQ,CAAC;gBACvB,QAAQ,EAAE,CAAC;YACb,CAAC;iBAAM,CAAC;gBACN,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YAC9B,CAAC;YACD,OAAO,KAAK,CAAC;QACf,CAAC,CAAC,CAAC;QACH,eAAe,CAAC,IAAI,GAAG,eAAe,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;YACxD,IAAI,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;gBACpC,KAAK,CAAC,KAAK,GAAG,QAAQ,CAAC;gBACvB,QAAQ,EAAE,CAAC;YACb,CAAC;iBAAM,CAAC;gBACN,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YAC9B,CAAC;YACD,OAAO,KAAK,CAAC;QACf,CAAC,CAAC,CAAC;QACH,OAAO,eAAe,CAAC;IACzB,CAAC;CACF;AA5UD,gCA4UC","sourcesContent":["'use strict';\n\nimport {\n IEdgeStyle,\n IStyleRule,\n LkEdgeData,\n LkNodeData,\n INodeStyle,\n SelectorType,\n IStyleIcon,\n IStyleImage,\n IStyles,\n IStyleColor,\n IRangeValues\n} from '@linkurious/rest-client';\n\nimport {sortBy, Tools} from '../tools/tools';\n\nimport {StyleRule} from './styleRule';\nimport {ItemAttributes} from './itemAttributes';\n\nexport enum StyleType {\n COLOR = 'color',\n ICON = 'icon',\n SIZE = 'size',\n IMAGE = 'image',\n SHAPE = 'shape',\n WIDTH = 'width'\n}\n\nexport interface Legend {\n [key: string]: Array<{label: string; value: string | IStyleIcon | IStyleImage | number}>;\n}\n\nexport const SORTING_RULE = ['specificity', 'itemType', 'index'];\n\nexport class StyleRules {\n private _rules: Array<IStyleRule<INodeStyle | IEdgeStyle>>;\n\n constructor(rules: Array<IStyleRule<INodeStyle | IEdgeStyle>>) {\n this._rules = rules;\n }\n\n /**\n * Return an array of StyleRule with only 'color' rules and sorted by specificity, itemType and index\n *\n * @return {Array<StyleRule>}\n */\n public get color(): Array<StyleRule> {\n return sortBy(StyleRules.getBy(StyleType.COLOR, this._rules), SORTING_RULE);\n }\n\n /**\n * Return an array of StyleRule with only 'icon' rules and sorted by specificity, itemType and index\n *\n * @return {Array<StyleRule>}\n */\n public get icon(): Array<StyleRule> {\n return sortBy(\n [\n ...(StyleRules.getBy(StyleType.ICON, this._rules) || []),\n ...(StyleRules.getBy(StyleType.IMAGE, this._rules) || [])\n ],\n SORTING_RULE\n );\n }\n\n /**\n * Return an array of StyleRule with only 'image' rules and sorted by specificity, itemType and index\n *\n * @return {Array<StyleRule>}\n */\n public get image(): Array<StyleRule> {\n return sortBy(StyleRules.getBy(StyleType.IMAGE, this._rules), SORTING_RULE);\n }\n\n /**\n * Return an array of StyleRule with only 'shape' rules and sorted by specificity, itemType and index\n *\n * @return {Array<StyleRule>}\n */\n public get shape(): Array<StyleRule> {\n return sortBy(StyleRules.getBy(StyleType.SHAPE, this._rules), SORTING_RULE);\n }\n\n /**\n * Return an array of StyleRule with only 'size' rules and sorted by specificity, itemType and index\n *\n * @return {Array<StyleRule>}\n */\n public get size(): Array<StyleRule> {\n return sortBy(StyleRules.getBy(StyleType.SIZE, this._rules), SORTING_RULE);\n }\n\n /**\n * Return an array of StyleRule with only 'width' rules and sorted by specificity, itemType and index\n *\n * @return {Array<StyleRule>}\n */\n public get width(): Array<StyleRule> {\n return sortBy(StyleRules.getBy(StyleType.WIDTH, this._rules), SORTING_RULE);\n }\n\n /**\n * Return an object containing for each node style a sorted array of StyleRule\n *\n * @return {{[key: string]: Array<StyleRule>} }\n */\n public get nodeRules(): {[key: string]: Array<StyleRule>} {\n return {\n color: this.color,\n icon: this.icon,\n image: this.image,\n shape: this.shape,\n size: this.size\n };\n }\n\n /**\n * Return an object containing for each edge style a sorted array of StyleRule\n *\n * @return { {[key: string]: Array<StyleRule>}}\n */\n public get edgeRules(): {[key: string]: Array<StyleRule>} {\n return {\n color: this.color,\n shape: this.shape,\n width: this.width\n };\n }\n\n /**\n * Generate a legend with an array of style rules and existing items in visualization\n */\n public generateLegend(itemsData: Array<LkNodeData | LkEdgeData>): Legend {\n const result: Legend = {};\n if (itemsData.length === 0) {\n return result;\n }\n\n if ('categories' in itemsData[0]) {\n Object.keys(this.nodeRules).forEach((style: string) => {\n result[style] = StyleRules.getLegendForStyle(\n style as StyleType,\n this.nodeRules[style],\n itemsData\n );\n });\n } else {\n Object.keys(this.edgeRules).forEach((style: string) => {\n result[style] = StyleRules.getLegendForStyle(\n style as StyleType,\n this.edgeRules[style],\n itemsData\n );\n });\n }\n return result;\n }\n\n /**\n * Return the legend for a specific style type (color, icon, image...)\n */\n public static getLegendForStyle(\n styleType: StyleType,\n styles: Array<StyleRule>,\n itemsData: Array<LkNodeData | LkEdgeData>\n ): Array<{label: string; value: string | number | IStyleIcon | IStyleImage}> {\n const result: Array<{label: string; value: string | number | IStyleIcon | IStyleImage}> = [];\n const data = itemsData.filter((i) => i);\n for (let i = 0; i < styles.length; i++) {\n const styleRule = new StyleRule(styles[i]);\n const ruleExistsInViz = data.some((itemData) => {\n return styleRule.canApplyTo(itemData);\n });\n if (ruleExistsInViz) {\n if (styleType === StyleType.COLOR && typeof styleRule.style.color === 'object') {\n StyleRules.addLegendAutoColors(data, styleRule, result);\n } else if (styleType === StyleType.ICON && 'image' in styleRule.style) {\n // style is a custom icon\n const label = Tools.isDefined(styleRule.input)\n ? `${StyleRules.getTypeLabel(styleRule.itemType)}.${\n styleRule.input[1]\n } ${StyleRules.sanitizeValue(styleRule.type, styleRule.value)}`\n : `${StyleRules.getTypeLabel(styleRule.itemType)}`;\n const imageStyle = styleRule.style.image as IStyleImage;\n if (\n imageStyle.url &&\n typeof imageStyle.url === 'object' &&\n imageStyle.url.type === 'data'\n ) {\n // If the custom icon is read from a node property-value dynamically, then we\n // skip it from the legend, because it could be a different image for each node,\n // thus bloating the legend.\n } else {\n const value = styleRule.style.image;\n StyleRules.updateLegend(result, {label: label, value: value as string});\n }\n } else {\n const label = Tools.isDefined(styleRule.input)\n ? `${StyleRules.getTypeLabel(styleRule.itemType)}.${\n styleRule.input[1]\n } ${StyleRules.sanitizeValue(styleRule.type, styleRule.value)}`\n : `${StyleRules.getTypeLabel(styleRule.itemType)}`;\n const value =\n styleType === StyleType.WIDTH\n ? (styleRule.style as IEdgeStyle)[styleType]\n : (styleRule.style as INodeStyle)[styleType];\n StyleRules.updateLegend(result, {label: label, value: value as string});\n }\n }\n }\n\n return result;\n }\n\n /**\n * Sanitize value for legend\n */\n public static sanitizeValue(\n styleType: SelectorType,\n value: IRangeValues | number | string | boolean\n ): string {\n let template = '';\n switch (styleType) {\n case SelectorType.NO_VALUE:\n return 'is undefined';\n\n case SelectorType.NAN:\n return 'is not an number';\n\n case SelectorType.RANGE:\n Object.keys(value).forEach((k, i) => {\n if (i > 0) {\n template += ' and ';\n }\n template += `${k} ${(value as IRangeValues)[k as keyof IRangeValues]}`;\n });\n return template;\n }\n\n return typeof value === 'object' ? `= ${JSON.stringify(value)}` : `= ${value}`;\n }\n\n /**\n * Add items in legend for automatic coloring\n */\n public static addLegendAutoColors(\n itemsData: Array<LkNodeData | LkEdgeData>,\n styleRule: StyleRule,\n currentLegend: Array<{label: string; value: string | number | IStyleIcon | IStyleImage}>\n ): void {\n const colorStyle = styleRule.style.color as IStyleColor;\n const propertyKey: string = colorStyle.input[1];\n itemsData.forEach((data) => {\n const propValue = Tools.getIn(data, colorStyle.input);\n if (Array.isArray(propValue)) {\n propValue.forEach((value) => {\n const label = colorStyle.input.includes('properties')\n ? `${StyleRules.getTypeLabel(styleRule.itemType)}.${propertyKey} = ${value}`\n : `${StyleRules.getTypeLabel(value)}`;\n const color = ItemAttributes.autoColor(value, colorStyle.ignoreCase);\n StyleRules.updateLegend(currentLegend, {label: label, value: color});\n });\n } else {\n const label = colorStyle.input.includes('properties')\n ? `${StyleRules.getTypeLabel(styleRule.itemType)}.${propertyKey} = ${propValue}`\n : `${StyleRules.getTypeLabel(propValue)}`;\n const value = ItemAttributes.autoColor(propValue, colorStyle.ignoreCase);\n StyleRules.updateLegend(currentLegend, {label: label, value: value});\n }\n });\n }\n\n /**\n * Return the label of item type for a legend item\n */\n public static getTypeLabel(type: string | undefined | null): string {\n return type === undefined ? 'All' : type === null ? 'Others' : type;\n }\n\n /**\n * Check if a legend item already exists and overwrite it / push it\n */\n public static updateLegend(\n legend: Array<{label: string; value: string | number | IStyleIcon | IStyleImage}>,\n {label, value}: {[key: string]: string}\n ): void {\n const indexOfLegendItem = legend.map((r) => r.label).indexOf(label);\n if (indexOfLegendItem < 0) {\n legend.push({label: label, value: value});\n } else {\n legend[indexOfLegendItem] = {label: label, value: value};\n }\n }\n\n /**\n * return an array of StyleRule, containing only the desired style\n */\n public static getBy(\n styleType: StyleType,\n rules: Array<IStyleRule<INodeStyle | IEdgeStyle>>\n ): Array<StyleRule> {\n return rules\n .filter((style: IStyleRule<INodeStyle | IEdgeStyle>) => {\n switch (styleType) {\n case StyleType.COLOR:\n return style.style.color !== undefined;\n\n case StyleType.ICON:\n return 'icon' in style.style && style.style.icon !== undefined;\n\n case StyleType.IMAGE:\n return 'image' in style.style && style.style.image !== undefined;\n\n case StyleType.SHAPE:\n return style.style.shape !== undefined;\n\n case StyleType.SIZE:\n return 'size' in style.style && style.style.size !== undefined;\n\n case StyleType.WIDTH:\n return 'width' in style.style && style.style.width !== undefined;\n }\n })\n .map((style: IStyleRule<INodeStyle | IEdgeStyle>) => StyleRules.getRule(style, styleType));\n }\n\n /**\n * From a RawStyle, generate a StyleRule of a specific style\n */\n public static getRule(\n rawRule: IStyleRule<INodeStyle | IEdgeStyle>,\n styleType: StyleType\n ): StyleRule {\n const rule = Tools.clone(rawRule);\n rule.style = {[styleType]: rule.style[styleType]};\n return new StyleRule(rule);\n }\n\n /**\n * Check for non unique index in styles rules and update them if exists\n */\n public static sanitizeStylesIndex(styles: IStyles): IStyles {\n const seenIndex: Array<number> = [];\n const sanitizedStyles: IStyles = Tools.clone(styles);\n let maxIndex =\n Math.max(...[...styles.node.map((s) => s.index), ...styles.edge.map((s) => s.index)]) + 1;\n sanitizedStyles.node = sanitizedStyles.node.map((style) => {\n if (seenIndex.includes(style.index)) {\n style.index = maxIndex;\n maxIndex++;\n } else {\n seenIndex.push(style.index);\n }\n return style;\n });\n sanitizedStyles.edge = sanitizedStyles.edge.map((style) => {\n if (seenIndex.includes(style.index)) {\n style.index = maxIndex;\n maxIndex++;\n } else {\n seenIndex.push(style.index);\n }\n return style;\n });\n return sanitizedStyles;\n }\n}\n"]}