@linkurious/ogma-linkurious-parser 3.1.12 → 4.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.
@@ -1,16 +1,9 @@
1
1
  'use strict';
2
- var __spreadArrays = (this && this.__spreadArrays) || function () {
3
- for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
4
- for (var r = Array(s), k = 0, i = 0; i < il; i++)
5
- for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
6
- r[k] = a[j];
7
- return r;
8
- };
9
2
  Object.defineProperty(exports, "__esModule", { value: true });
10
- var rest_client_1 = require("@linkurious/rest-client");
11
- var tools_1 = require("../tools/tools");
12
- var styleRule_1 = require("./styleRule");
13
- var itemAttributes_1 = require("./itemAttributes");
3
+ const rest_client_1 = require("@linkurious/rest-client");
4
+ const tools_1 = require("../tools/tools");
5
+ const styleRule_1 = require("./styleRule");
6
+ const itemAttributes_1 = require("./itemAttributes");
14
7
  var StyleType;
15
8
  (function (StyleType) {
16
9
  StyleType["COLOR"] = "color";
@@ -21,146 +14,116 @@ var StyleType;
21
14
  StyleType["WIDTH"] = "width";
22
15
  })(StyleType = exports.StyleType || (exports.StyleType = {}));
23
16
  exports.SORTING_RULE = ['specificity', 'itemType', 'index'];
24
- var StyleRules = /** @class */ (function () {
25
- function StyleRules(rules) {
17
+ class StyleRules {
18
+ constructor(rules) {
26
19
  this._rules = rules;
27
20
  }
28
- Object.defineProperty(StyleRules.prototype, "color", {
29
- /**
30
- * Return an array of StyleRule with only 'color' rules and sorted by specificity, itemType and index
31
- *
32
- * @return {Array<StyleRule>}
33
- */
34
- get: function () {
35
- return tools_1.sortBy(StyleRules.getBy(StyleType.COLOR, this._rules), exports.SORTING_RULE);
36
- },
37
- enumerable: true,
38
- configurable: true
39
- });
40
- Object.defineProperty(StyleRules.prototype, "icon", {
41
- /**
42
- * Return an array of StyleRule with only 'icon' rules and sorted by specificity, itemType and index
43
- *
44
- * @return {Array<StyleRule>}
45
- */
46
- get: function () {
47
- return tools_1.sortBy(__spreadArrays((StyleRules.getBy(StyleType.ICON, this._rules) || []), (StyleRules.getBy(StyleType.IMAGE, this._rules) || [])), exports.SORTING_RULE);
48
- },
49
- enumerable: true,
50
- configurable: true
51
- });
52
- Object.defineProperty(StyleRules.prototype, "image", {
53
- /**
54
- * Return an array of StyleRule with only 'image' rules and sorted by specificity, itemType and index
55
- *
56
- * @return {Array<StyleRule>}
57
- */
58
- get: function () {
59
- return tools_1.sortBy(StyleRules.getBy(StyleType.IMAGE, this._rules), exports.SORTING_RULE);
60
- },
61
- enumerable: true,
62
- configurable: true
63
- });
64
- Object.defineProperty(StyleRules.prototype, "shape", {
65
- /**
66
- * Return an array of StyleRule with only 'shape' rules and sorted by specificity, itemType and index
67
- *
68
- * @return {Array<StyleRule>}
69
- */
70
- get: function () {
71
- return tools_1.sortBy(StyleRules.getBy(StyleType.SHAPE, this._rules), exports.SORTING_RULE);
72
- },
73
- enumerable: true,
74
- configurable: true
75
- });
76
- Object.defineProperty(StyleRules.prototype, "size", {
77
- /**
78
- * Return an array of StyleRule with only 'size' rules and sorted by specificity, itemType and index
79
- *
80
- * @return {Array<StyleRule>}
81
- */
82
- get: function () {
83
- return tools_1.sortBy(StyleRules.getBy(StyleType.SIZE, this._rules), exports.SORTING_RULE);
84
- },
85
- enumerable: true,
86
- configurable: true
87
- });
88
- Object.defineProperty(StyleRules.prototype, "width", {
89
- /**
90
- * Return an array of StyleRule with only 'width' rules and sorted by specificity, itemType and index
91
- *
92
- * @return {Array<StyleRule>}
93
- */
94
- get: function () {
95
- return tools_1.sortBy(StyleRules.getBy(StyleType.WIDTH, this._rules), exports.SORTING_RULE);
96
- },
97
- enumerable: true,
98
- configurable: true
99
- });
100
- Object.defineProperty(StyleRules.prototype, "nodeRules", {
101
- /**
102
- * Return an object containing for each node style a sorted array of StyleRule
103
- *
104
- * @return {any}
105
- */
106
- get: function () {
107
- return {
108
- color: this.color,
109
- icon: this.icon,
110
- image: this.image,
111
- shape: this.shape,
112
- size: this.size
113
- };
114
- },
115
- enumerable: true,
116
- configurable: true
117
- });
118
- Object.defineProperty(StyleRules.prototype, "edgeRules", {
119
- /**
120
- * Return an object containing for each edge style a sorted array of StyleRule
121
- *
122
- * @return {any}
123
- */
124
- get: function () {
125
- return {
126
- color: this.color,
127
- shape: this.shape,
128
- width: this.width
129
- };
130
- },
131
- enumerable: true,
132
- configurable: true
133
- });
21
+ /**
22
+ * Return an array of StyleRule with only 'color' rules and sorted by specificity, itemType and index
23
+ *
24
+ * @return {Array<StyleRule>}
25
+ */
26
+ get color() {
27
+ return tools_1.sortBy(StyleRules.getBy(StyleType.COLOR, this._rules), exports.SORTING_RULE);
28
+ }
29
+ /**
30
+ * Return an array of StyleRule with only 'icon' rules and sorted by specificity, itemType and index
31
+ *
32
+ * @return {Array<StyleRule>}
33
+ */
34
+ get icon() {
35
+ return tools_1.sortBy([
36
+ ...(StyleRules.getBy(StyleType.ICON, this._rules) || []),
37
+ ...(StyleRules.getBy(StyleType.IMAGE, this._rules) || [])
38
+ ], exports.SORTING_RULE);
39
+ }
40
+ /**
41
+ * Return an array of StyleRule with only 'image' rules and sorted by specificity, itemType and index
42
+ *
43
+ * @return {Array<StyleRule>}
44
+ */
45
+ get image() {
46
+ return tools_1.sortBy(StyleRules.getBy(StyleType.IMAGE, this._rules), exports.SORTING_RULE);
47
+ }
48
+ /**
49
+ * Return an array of StyleRule with only 'shape' rules and sorted by specificity, itemType and index
50
+ *
51
+ * @return {Array<StyleRule>}
52
+ */
53
+ get shape() {
54
+ return tools_1.sortBy(StyleRules.getBy(StyleType.SHAPE, this._rules), exports.SORTING_RULE);
55
+ }
56
+ /**
57
+ * Return an array of StyleRule with only 'size' rules and sorted by specificity, itemType and index
58
+ *
59
+ * @return {Array<StyleRule>}
60
+ */
61
+ get size() {
62
+ return tools_1.sortBy(StyleRules.getBy(StyleType.SIZE, this._rules), exports.SORTING_RULE);
63
+ }
64
+ /**
65
+ * Return an array of StyleRule with only 'width' rules and sorted by specificity, itemType and index
66
+ *
67
+ * @return {Array<StyleRule>}
68
+ */
69
+ get width() {
70
+ return tools_1.sortBy(StyleRules.getBy(StyleType.WIDTH, this._rules), exports.SORTING_RULE);
71
+ }
72
+ /**
73
+ * Return an object containing for each node style a sorted array of StyleRule
74
+ *
75
+ * @return {any}
76
+ */
77
+ get nodeRules() {
78
+ return {
79
+ color: this.color,
80
+ icon: this.icon,
81
+ image: this.image,
82
+ shape: this.shape,
83
+ size: this.size
84
+ };
85
+ }
86
+ /**
87
+ * Return an object containing for each edge style a sorted array of StyleRule
88
+ *
89
+ * @return {any}
90
+ */
91
+ get edgeRules() {
92
+ return {
93
+ color: this.color,
94
+ shape: this.shape,
95
+ width: this.width
96
+ };
97
+ }
134
98
  /**
135
99
  * Generate a legend with an array of style rules and existing items in visualization
136
100
  */
137
- StyleRules.prototype.generateLegend = function (itemsData) {
138
- var _this = this;
139
- var result = {};
101
+ generateLegend(itemsData) {
102
+ const result = {};
140
103
  if (itemsData.length === 0) {
141
104
  return result;
142
105
  }
143
106
  if ('categories' in itemsData[0]) {
144
- Object.keys(this.nodeRules).forEach(function (style) {
145
- result[style] = StyleRules.getLegendForStyle(style, _this.nodeRules[style], itemsData);
107
+ Object.keys(this.nodeRules).forEach((style) => {
108
+ result[style] = StyleRules.getLegendForStyle(style, this.nodeRules[style], itemsData);
146
109
  });
147
110
  }
148
111
  else {
149
- Object.keys(this.edgeRules).forEach(function (style) {
150
- result[style] = StyleRules.getLegendForStyle(style, _this.edgeRules[style], itemsData);
112
+ Object.keys(this.edgeRules).forEach((style) => {
113
+ result[style] = StyleRules.getLegendForStyle(style, this.edgeRules[style], itemsData);
151
114
  });
152
115
  }
153
116
  return result;
154
- };
117
+ }
155
118
  /**
156
119
  * Return the legend for a specific style type (color, icon, image...)
157
120
  */
158
- StyleRules.getLegendForStyle = function (styleType, styles, itemsData) {
159
- var result = [];
160
- var data = itemsData.filter(function (i) { return i; });
161
- var _loop_1 = function (i) {
162
- var styleRule = new styleRule_1.StyleRule(styles[i]);
163
- var ruleExistsInViz = data.some(function (itemData) {
121
+ static getLegendForStyle(styleType, styles, itemsData) {
122
+ const result = [];
123
+ const data = itemsData.filter((i) => i);
124
+ for (let i = 0; i < styles.length; i++) {
125
+ const styleRule = new styleRule_1.StyleRule(styles[i]);
126
+ const ruleExistsInViz = data.some((itemData) => {
164
127
  return styleRule.canApplyTo(itemData);
165
128
  });
166
129
  if (ruleExistsInViz) {
@@ -169,10 +132,10 @@ var StyleRules = /** @class */ (function () {
169
132
  }
170
133
  else if (styleType === StyleType.ICON && 'image' in styleRule.style) {
171
134
  // style is a custom icon
172
- var label = tools_1.Tools.isDefined(styleRule.input)
173
- ? StyleRules.getTypeLabel(styleRule.itemType) + "." + styleRule.input[1] + " " + StyleRules.sanitizeValue(styleRule.type, styleRule.value)
174
- : "" + StyleRules.getTypeLabel(styleRule.itemType);
175
- var imageStyle = styleRule.style.image;
135
+ const label = tools_1.Tools.isDefined(styleRule.input)
136
+ ? `${StyleRules.getTypeLabel(styleRule.itemType)}.${styleRule.input[1]} ${StyleRules.sanitizeValue(styleRule.type, styleRule.value)}`
137
+ : `${StyleRules.getTypeLabel(styleRule.itemType)}`;
138
+ const imageStyle = styleRule.style.image;
176
139
  if (imageStyle.url &&
177
140
  typeof imageStyle.url === 'object' &&
178
141
  imageStyle.url.type === 'data') {
@@ -181,95 +144,91 @@ var StyleRules = /** @class */ (function () {
181
144
  // thus bloating the legend.
182
145
  }
183
146
  else {
184
- var value = styleRule.style.image;
147
+ const value = styleRule.style.image;
185
148
  StyleRules.updateLegend(result, { label: label, value: value });
186
149
  }
187
150
  }
188
151
  else {
189
- var label = tools_1.Tools.isDefined(styleRule.input)
190
- ? StyleRules.getTypeLabel(styleRule.itemType) + "." + styleRule.input[1] + " " + StyleRules.sanitizeValue(styleRule.type, styleRule.value)
191
- : "" + StyleRules.getTypeLabel(styleRule.itemType);
192
- var value = styleRule.style[styleType];
152
+ const label = tools_1.Tools.isDefined(styleRule.input)
153
+ ? `${StyleRules.getTypeLabel(styleRule.itemType)}.${styleRule.input[1]} ${StyleRules.sanitizeValue(styleRule.type, styleRule.value)}`
154
+ : `${StyleRules.getTypeLabel(styleRule.itemType)}`;
155
+ const value = styleRule.style[styleType];
193
156
  StyleRules.updateLegend(result, { label: label, value: value });
194
157
  }
195
158
  }
196
- };
197
- for (var i = 0; i < styles.length; i++) {
198
- _loop_1(i);
199
159
  }
200
160
  return result;
201
- };
161
+ }
202
162
  /**
203
163
  * Sanitize value for legend
204
164
  */
205
- StyleRules.sanitizeValue = function (styleType, value) {
165
+ static sanitizeValue(styleType, value) {
206
166
  switch (styleType) {
207
167
  case rest_client_1.SelectorType.NO_VALUE:
208
168
  return 'is undefined';
209
169
  case rest_client_1.SelectorType.NAN:
210
170
  return 'is not an number';
211
171
  case rest_client_1.SelectorType.RANGE:
212
- var template_1 = '';
213
- Object.keys(value).forEach(function (k, i) {
172
+ let template = '';
173
+ Object.keys(value).forEach((k, i) => {
214
174
  if (i > 0) {
215
- template_1 += ' and ';
175
+ template += ' and ';
216
176
  }
217
- template_1 += k + " " + value[k];
177
+ template += `${k} ${value[k]}`;
218
178
  });
219
- return template_1;
179
+ return template;
220
180
  }
221
- return typeof value === 'object' ? "= " + JSON.stringify(value) : "= " + value;
222
- };
181
+ return typeof value === 'object' ? `= ${JSON.stringify(value)}` : `= ${value}`;
182
+ }
223
183
  /**
224
184
  * Add items in legend for automatic coloring
225
185
  */
226
- StyleRules.addLegendAutoColors = function (itemsData, styleRule, currentLegend) {
227
- var propertyKey = styleRule.style.color.input[1];
228
- itemsData.forEach(function (data) {
229
- var propValue = tools_1.Tools.getIn(data, styleRule.style.color.input);
186
+ static addLegendAutoColors(itemsData, styleRule, currentLegend) {
187
+ const propertyKey = styleRule.style.color.input[1];
188
+ itemsData.forEach((data) => {
189
+ const propValue = tools_1.Tools.getIn(data, styleRule.style.color.input);
230
190
  if (Array.isArray(propValue)) {
231
- propValue.forEach(function (value) {
232
- var label = styleRule.style.color.input.includes('properties')
233
- ? StyleRules.getTypeLabel(styleRule.itemType) + "." + propertyKey + " = " + value
234
- : "" + StyleRules.getTypeLabel(value);
235
- var color = itemAttributes_1.ItemAttributes.autoColor(value, styleRule.style.color.ignoreCase);
191
+ propValue.forEach((value) => {
192
+ const label = styleRule.style.color.input.includes('properties')
193
+ ? `${StyleRules.getTypeLabel(styleRule.itemType)}.${propertyKey} = ${value}`
194
+ : `${StyleRules.getTypeLabel(value)}`;
195
+ const color = itemAttributes_1.ItemAttributes.autoColor(value, styleRule.style.color.ignoreCase);
236
196
  StyleRules.updateLegend(currentLegend, { label: label, value: color });
237
197
  });
238
198
  }
239
199
  else {
240
- var label = styleRule.style.color.input.includes('properties')
241
- ? StyleRules.getTypeLabel(styleRule.itemType) + "." + propertyKey + " = " + propValue
242
- : "" + StyleRules.getTypeLabel(propValue);
243
- var value = itemAttributes_1.ItemAttributes.autoColor(propValue, styleRule.style.color.ignoreCase);
200
+ const label = styleRule.style.color.input.includes('properties')
201
+ ? `${StyleRules.getTypeLabel(styleRule.itemType)}.${propertyKey} = ${propValue}`
202
+ : `${StyleRules.getTypeLabel(propValue)}`;
203
+ const value = itemAttributes_1.ItemAttributes.autoColor(propValue, styleRule.style.color.ignoreCase);
244
204
  StyleRules.updateLegend(currentLegend, { label: label, value: value });
245
205
  }
246
206
  });
247
- };
207
+ }
248
208
  /**
249
209
  * Return the label of item type for a legend item
250
210
  */
251
- StyleRules.getTypeLabel = function (type) {
211
+ static getTypeLabel(type) {
252
212
  return type === undefined ? 'All' : type === null ? 'Others' : type;
253
- };
213
+ }
254
214
  /**
255
215
  * Check if a legend item already exists and overwrite it / push it
256
216
  */
257
- StyleRules.updateLegend = function (legend, _a) {
258
- var label = _a.label, value = _a.value;
259
- var indexOfLegendItem = legend.map(function (r) { return r.label; }).indexOf(label);
217
+ static updateLegend(legend, { label, value }) {
218
+ const indexOfLegendItem = legend.map((r) => r.label).indexOf(label);
260
219
  if (indexOfLegendItem < 0) {
261
220
  legend.push({ label: label, value: value });
262
221
  }
263
222
  else {
264
223
  legend[indexOfLegendItem] = { label: label, value: value };
265
224
  }
266
- };
225
+ }
267
226
  /**
268
227
  * return an array of StyleRule, containing only the desired style
269
228
  */
270
- StyleRules.getBy = function (styleType, rules) {
229
+ static getBy(styleType, rules) {
271
230
  return rules
272
- .filter(function (style) {
231
+ .filter((style) => {
273
232
  switch (styleType) {
274
233
  case StyleType.COLOR:
275
234
  return style.style.color !== undefined;
@@ -285,25 +244,24 @@ var StyleRules = /** @class */ (function () {
285
244
  return 'width' in style.style && style.style.width !== undefined;
286
245
  }
287
246
  })
288
- .map(function (style) { return StyleRules.getRule(style, styleType); });
289
- };
247
+ .map((style) => StyleRules.getRule(style, styleType));
248
+ }
290
249
  /**
291
250
  * From a RawStyle, generate a StyleRule of a specific style
292
251
  */
293
- StyleRules.getRule = function (rawRule, styleType) {
294
- var _a;
295
- var rule = tools_1.Tools.clone(rawRule);
296
- rule.style = (_a = {}, _a[styleType] = rule.style[styleType], _a);
252
+ static getRule(rawRule, styleType) {
253
+ const rule = tools_1.Tools.clone(rawRule);
254
+ rule.style = { [styleType]: rule.style[styleType] };
297
255
  return new styleRule_1.StyleRule(rule);
298
- };
256
+ }
299
257
  /**
300
258
  * Check for non unique index in styles rules and update them if exists
301
259
  */
302
- StyleRules.sanitizeStylesIndex = function (styles) {
303
- var seenIndex = [];
304
- var sanitizedStyles = tools_1.Tools.clone(styles);
305
- var maxIndex = Math.max.apply(Math, __spreadArrays(styles.node.map(function (s) { return s.index; }), styles.edge.map(function (s) { return s.index; }))) + 1;
306
- sanitizedStyles.node = sanitizedStyles.node.map(function (style) {
260
+ static sanitizeStylesIndex(styles) {
261
+ const seenIndex = [];
262
+ const sanitizedStyles = tools_1.Tools.clone(styles);
263
+ let maxIndex = Math.max(...[...styles.node.map((s) => s.index), ...styles.edge.map((s) => s.index)]) + 1;
264
+ sanitizedStyles.node = sanitizedStyles.node.map((style) => {
307
265
  if (seenIndex.includes(style.index)) {
308
266
  style.index = maxIndex;
309
267
  maxIndex++;
@@ -313,7 +271,7 @@ var StyleRules = /** @class */ (function () {
313
271
  }
314
272
  return style;
315
273
  });
316
- sanitizedStyles.edge = sanitizedStyles.edge.map(function (style) {
274
+ sanitizedStyles.edge = sanitizedStyles.edge.map((style) => {
317
275
  if (seenIndex.includes(style.index)) {
318
276
  style.index = maxIndex;
319
277
  maxIndex++;
@@ -324,8 +282,7 @@ var StyleRules = /** @class */ (function () {
324
282
  return style;
325
283
  });
326
284
  return sanitizedStyles;
327
- };
328
- return StyleRules;
329
- }());
285
+ }
286
+ }
330
287
  exports.StyleRules = StyleRules;
331
288
  //# sourceMappingURL=styleRules.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"styleRules.js","sourceRoot":"","sources":["../../src/styles/styleRules.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;;;;AAEb,uDAUiC;AAEjC,wCAA6C;AAE7C,yCAAsC;AACtC,mDAAgD;AAEhD,IAAY,SAOX;AAPD,WAAY,SAAS;IACnB,4BAAe,CAAA;IACf,0BAAa,CAAA;IACb,0BAAa,CAAA;IACb,4BAAe,CAAA;IACf,4BAAe,CAAA;IACf,4BAAe,CAAA;AACjB,CAAC,EAPW,SAAS,GAAT,iBAAS,KAAT,iBAAS,QAOpB;AAMY,QAAA,YAAY,GAAG,CAAC,aAAa,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;AAEjE;IAGE,oBAAY,KAAiD;QAC3D,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACtB,CAAC;IAOD,sBAAW,6BAAK;QALhB;;;;WAIG;aACH;YACE,OAAO,cAAM,CAAC,UAAU,CAAC,KAAK,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,oBAAY,CAAC,CAAC;QAC9E,CAAC;;;OAAA;IAOD,sBAAW,4BAAI;QALf;;;;WAIG;aACH;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kEdgeData,\n LkNodeData,\n INodeStyle,\n SelectorType,\n IStyleIcon,\n IStyleImage,\n IStyles\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 {any}\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 {any}\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(style, this.nodeRules[style], itemsData);\n });\n } else {\n Object.keys(this.edgeRules).forEach((style: string) => {\n result[style] = StyleRules.getLegendForStyle(style, this.edgeRules[style], itemsData);\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: string,\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});\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 = styleRule.style[styleType];\n StyleRules.updateLegend(result, {label: label, value: value});\n }\n }\n }\n\n return result;\n }\n\n /**\n * Sanitize value for legend\n */\n public static sanitizeValue(styleType: SelectorType, value: any): string {\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 let template = '';\n Object.keys(value).forEach((k, i) => {\n if (i > 0) {\n template += ' and ';\n }\n template += `${k} ${value[k]}`;\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 propertyKey: string = styleRule.style.color.input[1];\n itemsData.forEach((data) => {\n const propValue = Tools.getIn(data, styleRule.style.color.input);\n if (Array.isArray(propValue)) {\n propValue.forEach((value) => {\n const label = styleRule.style.color.input.includes('properties')\n ? `${StyleRules.getTypeLabel(styleRule.itemType)}.${propertyKey} = ${value}`\n : `${StyleRules.getTypeLabel(value)}`;\n const color = ItemAttributes.autoColor(value, styleRule.style.color.ignoreCase);\n StyleRules.updateLegend(currentLegend, {label: label, value: color});\n });\n } else {\n const label = styleRule.style.color.input.includes('properties')\n ? `${StyleRules.getTypeLabel(styleRule.itemType)}.${propertyKey} = ${propValue}`\n : `${StyleRules.getTypeLabel(propValue)}`;\n const value = ItemAttributes.autoColor(propValue, styleRule.style.color.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"]}
1
+ {"version":3,"file":"styleRules.js","sourceRoot":"","sources":["../../src/styles/styleRules.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,yDAUiC;AAEjC,0CAA6C;AAE7C,2CAAsC;AACtC,qDAAgD;AAEhD,IAAY,SAOX;AAPD,WAAY,SAAS;IACnB,4BAAe,CAAA;IACf,0BAAa,CAAA;IACb,0BAAa,CAAA;IACb,4BAAe,CAAA;IACf,4BAAe,CAAA;IACf,4BAAe,CAAA;AACjB,CAAC,EAPW,SAAS,GAAT,iBAAS,KAAT,iBAAS,QAOpB;AAMY,QAAA,YAAY,GAAG,CAAC,aAAa,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;AAEjE,MAAa,UAAU;IAGrB,YAAY,KAAiD;QAC3D,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACtB,CAAC;IAED;;;;OAIG;IACH,IAAW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ACZ;iBAAM;gBACL,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;aAC7B;YACD,OAAO,KAAK,CAAC;QACf,CAAC,CAAC,CAAC;QACH,OAAO,eAAe,CAAC;IACzB,CAAC;CACF;AA7TD,gCA6TC","sourcesContent":["'use strict';\n\nimport {\n IEdgeStyle,\n IStyleRule,\n LkEdgeData,\n LkNodeData,\n INodeStyle,\n SelectorType,\n IStyleIcon,\n IStyleImage,\n IStyles\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 {any}\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 {any}\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(style, this.nodeRules[style], itemsData);\n });\n } else {\n Object.keys(this.edgeRules).forEach((style: string) => {\n result[style] = StyleRules.getLegendForStyle(style, this.edgeRules[style], itemsData);\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: string,\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});\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 = styleRule.style[styleType];\n StyleRules.updateLegend(result, {label: label, value: value});\n }\n }\n }\n\n return result;\n }\n\n /**\n * Sanitize value for legend\n */\n public static sanitizeValue(styleType: SelectorType, value: any): string {\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 let template = '';\n Object.keys(value).forEach((k, i) => {\n if (i > 0) {\n template += ' and ';\n }\n template += `${k} ${value[k]}`;\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 propertyKey: string = styleRule.style.color.input[1];\n itemsData.forEach((data) => {\n const propValue = Tools.getIn(data, styleRule.style.color.input);\n if (Array.isArray(propValue)) {\n propValue.forEach((value) => {\n const label = styleRule.style.color.input.includes('properties')\n ? `${StyleRules.getTypeLabel(styleRule.itemType)}.${propertyKey} = ${value}`\n : `${StyleRules.getTypeLabel(value)}`;\n const color = ItemAttributes.autoColor(value, styleRule.style.color.ignoreCase);\n StyleRules.updateLegend(currentLegend, {label: label, value: color});\n });\n } else {\n const label = styleRule.style.color.input.includes('properties')\n ? `${StyleRules.getTypeLabel(styleRule.itemType)}.${propertyKey} = ${propValue}`\n : `${StyleRules.getTypeLabel(propValue)}`;\n const value = ItemAttributes.autoColor(propValue, styleRule.style.color.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"]}