@linkurious/ogma-linkurious-parser 3.1.13 → 4.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.
- package/dist/captions/captions.js +42 -54
- package/dist/captions/captions.js.map +1 -1
- package/dist/filters/filters.d.ts +1 -1
- package/dist/filters/filters.js +55 -76
- package/dist/filters/filters.js.map +1 -1
- package/dist/index.js +34 -33
- package/dist/index.js.map +1 -1
- package/dist/ogma/features/OgmaStore.js +16 -30
- package/dist/ogma/features/OgmaStore.js.map +1 -1
- package/dist/ogma/features/captions.js +43 -87
- package/dist/ogma/features/captions.js.map +1 -1
- package/dist/ogma/features/reactive.js +58 -75
- package/dist/ogma/features/reactive.js.map +1 -1
- package/dist/ogma/features/selectors.d.ts +5 -5
- package/dist/ogma/features/selectors.js +25 -16
- package/dist/ogma/features/selectors.js.map +1 -1
- package/dist/ogma/features/styles.js +115 -137
- package/dist/ogma/features/styles.js.map +1 -1
- package/dist/ogma/features/transformations.js +39 -87
- package/dist/ogma/features/transformations.js.map +1 -1
- package/dist/ogma/index.js +140 -230
- package/dist/ogma/index.js.map +1 -1
- package/dist/styles/edgeAttributes.js +31 -47
- package/dist/styles/edgeAttributes.js.map +1 -1
- package/dist/styles/itemAttributes.js +33 -42
- package/dist/styles/itemAttributes.js.map +1 -1
- package/dist/styles/nodeAttributes.js +49 -71
- package/dist/styles/nodeAttributes.js.map +1 -1
- package/dist/styles/styleRule.js +57 -68
- package/dist/styles/styleRule.js.map +1 -1
- package/dist/styles/styleRules.js +150 -192
- package/dist/styles/styleRules.js.map +1 -1
- package/dist/tools/colorPalette.js +1 -0
- package/dist/tools/colorPalette.js.map +1 -1
- package/dist/tools/ogmaTool.js +28 -30
- package/dist/tools/ogmaTool.js.map +1 -1
- package/dist/tools/tools.js +88 -91
- package/dist/tools/tools.js.map +1 -1
- package/package.json +7 -7
|
@@ -1,16 +1,10 @@
|
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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");
|
|
14
8
|
var StyleType;
|
|
15
9
|
(function (StyleType) {
|
|
16
10
|
StyleType["COLOR"] = "color";
|
|
@@ -21,146 +15,116 @@ var StyleType;
|
|
|
21
15
|
StyleType["WIDTH"] = "width";
|
|
22
16
|
})(StyleType = exports.StyleType || (exports.StyleType = {}));
|
|
23
17
|
exports.SORTING_RULE = ['specificity', 'itemType', 'index'];
|
|
24
|
-
|
|
25
|
-
|
|
18
|
+
class StyleRules {
|
|
19
|
+
constructor(rules) {
|
|
26
20
|
this._rules = rules;
|
|
27
21
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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
|
-
});
|
|
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 {any}
|
|
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 {any}
|
|
91
|
+
*/
|
|
92
|
+
get edgeRules() {
|
|
93
|
+
return {
|
|
94
|
+
color: this.color,
|
|
95
|
+
shape: this.shape,
|
|
96
|
+
width: this.width
|
|
97
|
+
};
|
|
98
|
+
}
|
|
134
99
|
/**
|
|
135
100
|
* Generate a legend with an array of style rules and existing items in visualization
|
|
136
101
|
*/
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
var result = {};
|
|
102
|
+
generateLegend(itemsData) {
|
|
103
|
+
const result = {};
|
|
140
104
|
if (itemsData.length === 0) {
|
|
141
105
|
return result;
|
|
142
106
|
}
|
|
143
107
|
if ('categories' in itemsData[0]) {
|
|
144
|
-
Object.keys(this.nodeRules).forEach(
|
|
145
|
-
result[style] = StyleRules.getLegendForStyle(style,
|
|
108
|
+
Object.keys(this.nodeRules).forEach((style) => {
|
|
109
|
+
result[style] = StyleRules.getLegendForStyle(style, this.nodeRules[style], itemsData);
|
|
146
110
|
});
|
|
147
111
|
}
|
|
148
112
|
else {
|
|
149
|
-
Object.keys(this.edgeRules).forEach(
|
|
150
|
-
result[style] = StyleRules.getLegendForStyle(style,
|
|
113
|
+
Object.keys(this.edgeRules).forEach((style) => {
|
|
114
|
+
result[style] = StyleRules.getLegendForStyle(style, this.edgeRules[style], itemsData);
|
|
151
115
|
});
|
|
152
116
|
}
|
|
153
117
|
return result;
|
|
154
|
-
}
|
|
118
|
+
}
|
|
155
119
|
/**
|
|
156
120
|
* Return the legend for a specific style type (color, icon, image...)
|
|
157
121
|
*/
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
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) => {
|
|
164
128
|
return styleRule.canApplyTo(itemData);
|
|
165
129
|
});
|
|
166
130
|
if (ruleExistsInViz) {
|
|
@@ -169,10 +133,10 @@ var StyleRules = /** @class */ (function () {
|
|
|
169
133
|
}
|
|
170
134
|
else if (styleType === StyleType.ICON && 'image' in styleRule.style) {
|
|
171
135
|
// style is a custom icon
|
|
172
|
-
|
|
173
|
-
? StyleRules.getTypeLabel(styleRule.itemType)
|
|
174
|
-
:
|
|
175
|
-
|
|
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;
|
|
176
140
|
if (imageStyle.url &&
|
|
177
141
|
typeof imageStyle.url === 'object' &&
|
|
178
142
|
imageStyle.url.type === 'data') {
|
|
@@ -181,95 +145,91 @@ var StyleRules = /** @class */ (function () {
|
|
|
181
145
|
// thus bloating the legend.
|
|
182
146
|
}
|
|
183
147
|
else {
|
|
184
|
-
|
|
148
|
+
const value = styleRule.style.image;
|
|
185
149
|
StyleRules.updateLegend(result, { label: label, value: value });
|
|
186
150
|
}
|
|
187
151
|
}
|
|
188
152
|
else {
|
|
189
|
-
|
|
190
|
-
? StyleRules.getTypeLabel(styleRule.itemType)
|
|
191
|
-
:
|
|
192
|
-
|
|
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 = styleRule.style[styleType];
|
|
193
157
|
StyleRules.updateLegend(result, { label: label, value: value });
|
|
194
158
|
}
|
|
195
159
|
}
|
|
196
|
-
};
|
|
197
|
-
for (var i = 0; i < styles.length; i++) {
|
|
198
|
-
_loop_1(i);
|
|
199
160
|
}
|
|
200
161
|
return result;
|
|
201
|
-
}
|
|
162
|
+
}
|
|
202
163
|
/**
|
|
203
164
|
* Sanitize value for legend
|
|
204
165
|
*/
|
|
205
|
-
|
|
166
|
+
static sanitizeValue(styleType, value) {
|
|
206
167
|
switch (styleType) {
|
|
207
168
|
case rest_client_1.SelectorType.NO_VALUE:
|
|
208
169
|
return 'is undefined';
|
|
209
170
|
case rest_client_1.SelectorType.NAN:
|
|
210
171
|
return 'is not an number';
|
|
211
172
|
case rest_client_1.SelectorType.RANGE:
|
|
212
|
-
|
|
213
|
-
Object.keys(value).forEach(
|
|
173
|
+
let template = '';
|
|
174
|
+
Object.keys(value).forEach((k, i) => {
|
|
214
175
|
if (i > 0) {
|
|
215
|
-
|
|
176
|
+
template += ' and ';
|
|
216
177
|
}
|
|
217
|
-
|
|
178
|
+
template += `${k} ${value[k]}`;
|
|
218
179
|
});
|
|
219
|
-
return
|
|
180
|
+
return template;
|
|
220
181
|
}
|
|
221
|
-
return typeof value === 'object' ?
|
|
222
|
-
}
|
|
182
|
+
return typeof value === 'object' ? `= ${JSON.stringify(value)}` : `= ${value}`;
|
|
183
|
+
}
|
|
223
184
|
/**
|
|
224
185
|
* Add items in legend for automatic coloring
|
|
225
186
|
*/
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
itemsData.forEach(
|
|
229
|
-
|
|
187
|
+
static addLegendAutoColors(itemsData, styleRule, currentLegend) {
|
|
188
|
+
const propertyKey = styleRule.style.color.input[1];
|
|
189
|
+
itemsData.forEach((data) => {
|
|
190
|
+
const propValue = tools_1.Tools.getIn(data, styleRule.style.color.input);
|
|
230
191
|
if (Array.isArray(propValue)) {
|
|
231
|
-
propValue.forEach(
|
|
232
|
-
|
|
233
|
-
? StyleRules.getTypeLabel(styleRule.itemType)
|
|
234
|
-
:
|
|
235
|
-
|
|
192
|
+
propValue.forEach((value) => {
|
|
193
|
+
const label = styleRule.style.color.input.includes('properties')
|
|
194
|
+
? `${StyleRules.getTypeLabel(styleRule.itemType)}.${propertyKey} = ${value}`
|
|
195
|
+
: `${StyleRules.getTypeLabel(value)}`;
|
|
196
|
+
const color = itemAttributes_1.ItemAttributes.autoColor(value, styleRule.style.color.ignoreCase);
|
|
236
197
|
StyleRules.updateLegend(currentLegend, { label: label, value: color });
|
|
237
198
|
});
|
|
238
199
|
}
|
|
239
200
|
else {
|
|
240
|
-
|
|
241
|
-
? StyleRules.getTypeLabel(styleRule.itemType)
|
|
242
|
-
:
|
|
243
|
-
|
|
201
|
+
const label = styleRule.style.color.input.includes('properties')
|
|
202
|
+
? `${StyleRules.getTypeLabel(styleRule.itemType)}.${propertyKey} = ${propValue}`
|
|
203
|
+
: `${StyleRules.getTypeLabel(propValue)}`;
|
|
204
|
+
const value = itemAttributes_1.ItemAttributes.autoColor(propValue, styleRule.style.color.ignoreCase);
|
|
244
205
|
StyleRules.updateLegend(currentLegend, { label: label, value: value });
|
|
245
206
|
}
|
|
246
207
|
});
|
|
247
|
-
}
|
|
208
|
+
}
|
|
248
209
|
/**
|
|
249
210
|
* Return the label of item type for a legend item
|
|
250
211
|
*/
|
|
251
|
-
|
|
212
|
+
static getTypeLabel(type) {
|
|
252
213
|
return type === undefined ? 'All' : type === null ? 'Others' : type;
|
|
253
|
-
}
|
|
214
|
+
}
|
|
254
215
|
/**
|
|
255
216
|
* Check if a legend item already exists and overwrite it / push it
|
|
256
217
|
*/
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
var indexOfLegendItem = legend.map(function (r) { return r.label; }).indexOf(label);
|
|
218
|
+
static updateLegend(legend, { label, value }) {
|
|
219
|
+
const indexOfLegendItem = legend.map((r) => r.label).indexOf(label);
|
|
260
220
|
if (indexOfLegendItem < 0) {
|
|
261
221
|
legend.push({ label: label, value: value });
|
|
262
222
|
}
|
|
263
223
|
else {
|
|
264
224
|
legend[indexOfLegendItem] = { label: label, value: value };
|
|
265
225
|
}
|
|
266
|
-
}
|
|
226
|
+
}
|
|
267
227
|
/**
|
|
268
228
|
* return an array of StyleRule, containing only the desired style
|
|
269
229
|
*/
|
|
270
|
-
|
|
230
|
+
static getBy(styleType, rules) {
|
|
271
231
|
return rules
|
|
272
|
-
.filter(
|
|
232
|
+
.filter((style) => {
|
|
273
233
|
switch (styleType) {
|
|
274
234
|
case StyleType.COLOR:
|
|
275
235
|
return style.style.color !== undefined;
|
|
@@ -285,25 +245,24 @@ var StyleRules = /** @class */ (function () {
|
|
|
285
245
|
return 'width' in style.style && style.style.width !== undefined;
|
|
286
246
|
}
|
|
287
247
|
})
|
|
288
|
-
.map(
|
|
289
|
-
}
|
|
248
|
+
.map((style) => StyleRules.getRule(style, styleType));
|
|
249
|
+
}
|
|
290
250
|
/**
|
|
291
251
|
* From a RawStyle, generate a StyleRule of a specific style
|
|
292
252
|
*/
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
rule.style = (_a = {}, _a[styleType] = rule.style[styleType], _a);
|
|
253
|
+
static getRule(rawRule, styleType) {
|
|
254
|
+
const rule = tools_1.Tools.clone(rawRule);
|
|
255
|
+
rule.style = { [styleType]: rule.style[styleType] };
|
|
297
256
|
return new styleRule_1.StyleRule(rule);
|
|
298
|
-
}
|
|
257
|
+
}
|
|
299
258
|
/**
|
|
300
259
|
* Check for non unique index in styles rules and update them if exists
|
|
301
260
|
*/
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
sanitizedStyles.node = sanitizedStyles.node.map(
|
|
261
|
+
static sanitizeStylesIndex(styles) {
|
|
262
|
+
const seenIndex = [];
|
|
263
|
+
const sanitizedStyles = tools_1.Tools.clone(styles);
|
|
264
|
+
let maxIndex = Math.max(...[...styles.node.map((s) => s.index), ...styles.edge.map((s) => s.index)]) + 1;
|
|
265
|
+
sanitizedStyles.node = sanitizedStyles.node.map((style) => {
|
|
307
266
|
if (seenIndex.includes(style.index)) {
|
|
308
267
|
style.index = maxIndex;
|
|
309
268
|
maxIndex++;
|
|
@@ -313,7 +272,7 @@ var StyleRules = /** @class */ (function () {
|
|
|
313
272
|
}
|
|
314
273
|
return style;
|
|
315
274
|
});
|
|
316
|
-
sanitizedStyles.edge = sanitizedStyles.edge.map(
|
|
275
|
+
sanitizedStyles.edge = sanitizedStyles.edge.map((style) => {
|
|
317
276
|
if (seenIndex.includes(style.index)) {
|
|
318
277
|
style.index = maxIndex;
|
|
319
278
|
maxIndex++;
|
|
@@ -324,8 +283,7 @@ var StyleRules = /** @class */ (function () {
|
|
|
324
283
|
return style;
|
|
325
284
|
});
|
|
326
285
|
return sanitizedStyles;
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
}());
|
|
286
|
+
}
|
|
287
|
+
}
|
|
330
288
|
exports.StyleRules = StyleRules;
|
|
331
289
|
//# 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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,EAAE,CAAC;aACZ;iBAAM;gBACL,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;aAC7B;YACD,OAAO,KAAK,CAAC;QACf,CAAC,CAAC,CAAC;QACH,eAAe,CAAC,IAAI,GAAG,eAAe,CAAC,IAAI,CAAC,GAAG,CAAC,UAAC,KAAK;YACpD,IAAI,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE;gBACnC,KAAK,CAAC,KAAK,GAAG,QAAQ,CAAC;gBACvB,QAAQ,EAAE,CAAC;aACZ;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;IACH,iBAAC;AAAD,CAAC,AA7TD,IA6TC;AA7TY,gCAAU","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"]}
|
|
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,KAAK;QACd,OAAO,IAAA,cAAM,EAAC,UAAU,CAAC,KAAK,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,oBAAY,CAAC,CAAC;IAC9E,CAAC;IAED;;;;OAIG;IACH,IAAW,IAAI;QACb,OAAO,IAAA,cAAM,EACX;YACE,GAAG,CAAC,UAAU,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;YACxD,GAAG,CAAC,UAAU,CAAC,KAAK,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;SAC1D,EACD,oBAAY,CACb,CAAC;IACJ,CAAC;IAED;;;;OAIG;IACH,IAAW,KAAK;QACd,OAAO,IAAA,cAAM,EAAC,UAAU,CAAC,KAAK,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,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AC,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;gBACnC,KAAK,CAAC,KAAK,GAAG,QAAQ,CAAC;gBACvB,QAAQ,EAAE,CAAC;aACZ;iBAAM;gBACL,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;aAC7B;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;gBACnC,KAAK,CAAC,KAAK,GAAG,QAAQ,CAAC;gBACvB,QAAQ,EAAE,CAAC;aACZ;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"]}
|