@linkurious/ogma-linkurious-parser 4.0.0 → 4.0.3
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/README.md +1 -1
- package/dist/captions/captions.js +4 -5
- package/dist/captions/captions.js.map +1 -1
- package/dist/filters/filters.d.ts +1 -1
- package/dist/filters/filters.js +1 -0
- 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 +2 -1
- package/dist/ogma/features/OgmaStore.js.map +1 -1
- package/dist/ogma/features/captions.js +1 -0
- package/dist/ogma/features/captions.js.map +1 -1
- package/dist/ogma/features/reactive.js +1 -0
- package/dist/ogma/features/reactive.js.map +1 -1
- package/dist/ogma/features/selectors.d.ts +5 -5
- package/dist/ogma/features/selectors.js +21 -12
- package/dist/ogma/features/selectors.js.map +1 -1
- package/dist/ogma/features/styles.d.ts +7 -7
- package/dist/ogma/features/styles.js +1 -0
- package/dist/ogma/features/styles.js.map +1 -1
- package/dist/ogma/features/transformations.d.ts +1 -1
- package/dist/ogma/features/transformations.js +16 -17
- package/dist/ogma/features/transformations.js.map +1 -1
- package/dist/ogma/index.js +14 -18
- package/dist/ogma/index.js.map +1 -1
- package/dist/styles/edgeAttributes.d.ts +8 -8
- package/dist/styles/edgeAttributes.js +16 -15
- package/dist/styles/edgeAttributes.js.map +1 -1
- package/dist/styles/itemAttributes.d.ts +24 -28
- package/dist/styles/itemAttributes.js +31 -23
- package/dist/styles/itemAttributes.js.map +1 -1
- package/dist/styles/nodeAttributes.d.ts +8 -8
- package/dist/styles/nodeAttributes.js +23 -20
- package/dist/styles/nodeAttributes.js.map +1 -1
- package/dist/styles/styleRule.d.ts +8 -8
- package/dist/styles/styleRule.js +2 -0
- package/dist/styles/styleRule.js.map +1 -1
- package/dist/styles/styleRules.d.ts +5 -5
- package/dist/styles/styleRules.js +20 -16
- 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 +1 -0
- package/dist/tools/ogmaTool.js.map +1 -1
- package/dist/tools/tools.js +2 -1
- package/dist/tools/tools.js.map +1 -1
- package/package.json +5 -5
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EdgeAttributes = exports.EdgeWidthExtrema = void 0;
|
|
3
4
|
const rest_client_1 = require("@linkurious/rest-client");
|
|
4
5
|
const tools_1 = require("../tools/tools");
|
|
5
6
|
const itemAttributes_1 = require("./itemAttributes");
|
|
@@ -41,7 +42,7 @@ class EdgeAttributes extends itemAttributes_1.ItemAttributes {
|
|
|
41
42
|
}
|
|
42
43
|
else if (typeof rule.style.color === 'object') {
|
|
43
44
|
const propValue = tools_1.Tools.getIn(data, rule.style.color.input);
|
|
44
|
-
color = itemAttributes_1.ItemAttributes.autoColor(`${propValue}`, rule.style.ignoreCase);
|
|
45
|
+
color = itemAttributes_1.ItemAttributes.autoColor(`${propValue}`, rule.style.color.ignoreCase);
|
|
45
46
|
}
|
|
46
47
|
break;
|
|
47
48
|
}
|
|
@@ -61,23 +62,23 @@ class EdgeAttributes extends itemAttributes_1.ItemAttributes {
|
|
|
61
62
|
* Generate size for a given node
|
|
62
63
|
*/
|
|
63
64
|
width(data) {
|
|
64
|
-
var _a;
|
|
65
65
|
if (this._rulesMap.width !== undefined) {
|
|
66
66
|
const styleRule = EdgeAttributes.matchStyle(this._rulesMap.width, data);
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
if (widthStyle
|
|
70
|
-
widthStyle.
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
67
|
+
if (styleRule !== undefined) {
|
|
68
|
+
const widthStyle = styleRule === null || styleRule === void 0 ? void 0 : styleRule.style.width;
|
|
69
|
+
if (widthStyle !== undefined && this.isAutoRange(widthStyle)) {
|
|
70
|
+
if (widthStyle.input !== undefined &&
|
|
71
|
+
widthStyle.max !== undefined &&
|
|
72
|
+
widthStyle.min !== undefined) {
|
|
73
|
+
const propertyName = widthStyle.input[1];
|
|
74
|
+
const propertyValue = tools_1.Tools.parseNumber(data.properties[propertyName]);
|
|
75
|
+
const isLog = widthStyle.scale && widthStyle.scale === rest_client_1.AutoRangeScale.LOGARITHMIC;
|
|
76
|
+
return EdgeAttributes.getAutomaticRangeWidth(propertyValue, styleRule, isLog);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
return widthStyle;
|
|
77
81
|
}
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
return widthStyle;
|
|
81
82
|
}
|
|
82
83
|
}
|
|
83
84
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"edgeAttributes.js","sourceRoot":"","sources":["../../src/styles/edgeAttributes.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC
|
|
1
|
+
{"version":3,"file":"edgeAttributes.js","sourceRoot":"","sources":["../../src/styles/edgeAttributes.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;AAEb,yDAMiC;AAEjC,0CAAqC;AAGrC,qDAA2D;AAE3D,IAAY,gBAGX;AAHD,WAAY,gBAAgB;IAC1B,sDAAQ,CAAA;IACR,uDAAS,CAAA;AACX,CAAC,EAHW,gBAAgB,GAAhB,wBAAgB,KAAhB,wBAAgB,QAG3B;AAED,MAAa,cAAe,SAAQ,+BAA0B;IAC5D,YAAY,QAIX;QACC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAClB,CAAC;IAED;;OAEG;IACK,MAAM,CAAC,UAAU,CACvB,UAAwC,EACxC,IAAgB;QAEhB,IAAI,IAAI,KAAK,SAAS,EAAE;YACtB,OAAO;SACR;QACD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,UAAU,CAAC,MAAM,EAAE,EAAE,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,yBAAyB,CAC5B,KAAK,EACL,IAAI,CAAC,KAAK,CAAC,KAAwB,EACnC,gBAAgB,CAAC,GAAG,EACpB,gBAAgB,CAAC,GAAG,CACrB;YACH,CAAC,CAAC,IAAI,CAAC,4BAA4B,CAC/B,KAAK,EACL,IAAI,CAAC,KAAK,CAAC,KAAwB,EACnC,gBAAgB,CAAC,GAAG,EACpB,gBAAgB,CAAC,GAAG,CACrB,CAAC;IACR,CAAC;IAED;;OAEG;IACI,GAAG,CACR,IAAgB;QAMhB,IAAI,CAAC,aAAK,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE;YAC1B,OAAO;gBACL,KAAK,EAAE,0BAAS;gBAChB,KAAK,EAAE,2BAAa,CAAC,KAAK;gBAC1B,KAAK,EAAE,MAAM;aACd,CAAC;SACH;QACD,OAAO;YACL,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;YACvB,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;YACvB,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;SACxB,CAAC;IACJ,CAAC;CACF;AArID,wCAqIC","sourcesContent":["'use strict';\nimport {Color} from '@linkurious/ogma';\nimport {\n AutoRangeScale,\n IEdgeStyle,\n LkEdgeData,\n OgmaEdgeShape,\n IStyleAutoRange\n} from '@linkurious/rest-client';\n\nimport {Tools} from '../tools/tools';\n\nimport {StyleRule} from './styleRule';\nimport {BASE_GREY, ItemAttributes} from './itemAttributes';\n\nexport enum EdgeWidthExtrema {\n MIN = 50,\n MAX = 200\n}\n\nexport class EdgeAttributes extends ItemAttributes<IEdgeStyle> {\n constructor(rulesMap: {\n color?: Array<StyleRule<IEdgeStyle>>;\n shape?: Array<StyleRule<IEdgeStyle>>;\n width?: Array<StyleRule<IEdgeStyle>>;\n }) {\n super(rulesMap);\n }\n\n /**\n * Return rule that can be applied to the data\n */\n private static matchStyle(\n styleRules: Array<StyleRule<IEdgeStyle>>,\n data: LkEdgeData\n ): StyleRule<IEdgeStyle> | undefined {\n if (data === undefined) {\n return;\n }\n for (let i = 0; i < styleRules.length; ++i) {\n if (styleRules[i].canApplyTo(data)) {\n return styleRules[i];\n }\n }\n }\n\n /**\n * Generate color for a given edge (call only if _rulesMap.color exists)\n */\n public color(data: LkEdgeData): Color {\n if (!Tools.isDefined(data)) {\n return BASE_GREY;\n }\n let color;\n for (let j = 0; j < this._rulesMap.color!.length; ++j) {\n const rule = this._rulesMap.color![j];\n if (rule.canApplyTo(data)) {\n if (typeof rule.style.color === 'string') {\n color = rule.style.color;\n } else if (typeof rule.style.color === 'object') {\n const propValue = Tools.getIn(data, rule.style.color.input);\n color = ItemAttributes.autoColor(`${propValue}`, rule.style.color.ignoreCase);\n }\n break;\n }\n }\n return Tools.isDefined(color) ? color : BASE_GREY;\n }\n\n /**\n * Generate shape for a given node\n */\n public shape(data: LkEdgeData): OgmaEdgeShape | undefined {\n if (this._rulesMap.shape !== undefined) {\n return EdgeAttributes.matchStyle(this._rulesMap.shape, data)?.style.shape;\n }\n }\n\n /**\n * Generate size for a given node\n */\n public width(data: LkEdgeData): string | number | undefined {\n if (this._rulesMap.width !== undefined) {\n const styleRule = EdgeAttributes.matchStyle(this._rulesMap.width, data);\n if (styleRule !== undefined) {\n const widthStyle = styleRule?.style.width;\n if (widthStyle !== undefined && this.isAutoRange(widthStyle)) {\n if (\n widthStyle.input !== undefined &&\n widthStyle.max !== undefined &&\n widthStyle.min !== undefined\n ) {\n const propertyName: string = widthStyle.input[1];\n const propertyValue = Tools.parseNumber(data.properties[propertyName]);\n const isLog = widthStyle.scale && widthStyle.scale === AutoRangeScale.LOGARITHMIC;\n return EdgeAttributes.getAutomaticRangeWidth(propertyValue, styleRule, isLog);\n }\n } else {\n return widthStyle;\n }\n }\n }\n }\n\n /**\n * return the corresponding width to the value\n * @param value\n * @param rule\n * @param isLog\n */\n public static getAutomaticRangeWidth(\n value: number,\n rule: StyleRule<IEdgeStyle>,\n isLog = false\n ): string | undefined {\n return isLog\n ? this.getAutomaticRangeStyleLog(\n value,\n rule.style.width as IStyleAutoRange,\n EdgeWidthExtrema.MIN,\n EdgeWidthExtrema.MAX\n )\n : this.getAutomaticRangeStyleLinear(\n value,\n rule.style.width as IStyleAutoRange,\n EdgeWidthExtrema.MIN,\n EdgeWidthExtrema.MAX\n );\n }\n\n /**\n * Return an object containing all node attributes needed by Ogma to style a node\n */\n public all(\n data: LkEdgeData\n ): {\n color: Color;\n shape: OgmaEdgeShape | undefined;\n width: string | undefined | number;\n } {\n if (!Tools.isDefined(data)) {\n return {\n color: BASE_GREY,\n shape: OgmaEdgeShape.ARROW,\n width: '100%'\n };\n }\n return {\n color: this.color(data),\n shape: this.shape(data),\n width: this.width(data)\n };\n }\n}\n"]}
|
|
@@ -1,37 +1,38 @@
|
|
|
1
1
|
import { Color } from '@linkurious/ogma';
|
|
2
|
+
import { IEdgeStyle, INodeStyle, IStyleAutoRange } from '@linkurious/rest-client';
|
|
2
3
|
import { StyleRule } from './styleRule';
|
|
3
4
|
import { NodeSizeExtrema } from './nodeAttributes';
|
|
4
5
|
import { EdgeWidthExtrema } from './edgeAttributes';
|
|
5
6
|
export declare const BASE_GREY = "#7f7f7f";
|
|
6
7
|
export declare const PALETTE: string[];
|
|
7
|
-
export declare class ItemAttributes {
|
|
8
|
+
export declare class ItemAttributes<T extends INodeStyle | IEdgeStyle> {
|
|
8
9
|
protected colorsCache: Map<string, Color | Array<Color>>;
|
|
9
10
|
protected _rulesMap: {
|
|
10
|
-
color?: Array<StyleRule
|
|
11
|
-
icon?: Array<StyleRule
|
|
12
|
-
image?: Array<StyleRule
|
|
13
|
-
shape?: Array<StyleRule
|
|
14
|
-
size?: Array<StyleRule
|
|
15
|
-
width?: Array<StyleRule
|
|
11
|
+
color?: Array<StyleRule<T>>;
|
|
12
|
+
icon?: Array<StyleRule<T>>;
|
|
13
|
+
image?: Array<StyleRule<T>>;
|
|
14
|
+
shape?: Array<StyleRule<T>>;
|
|
15
|
+
size?: Array<StyleRule<T>>;
|
|
16
|
+
width?: Array<StyleRule<T>>;
|
|
16
17
|
};
|
|
17
18
|
constructor(rulesMap: {
|
|
18
|
-
color?: Array<StyleRule
|
|
19
|
-
icon?: Array<StyleRule
|
|
20
|
-
image?: Array<StyleRule
|
|
21
|
-
shape?: Array<StyleRule
|
|
22
|
-
size?: Array<StyleRule
|
|
23
|
-
width?: Array<StyleRule
|
|
19
|
+
color?: Array<StyleRule<T>>;
|
|
20
|
+
icon?: Array<StyleRule<T>>;
|
|
21
|
+
image?: Array<StyleRule<T>>;
|
|
22
|
+
shape?: Array<StyleRule<T>>;
|
|
23
|
+
size?: Array<StyleRule<T>>;
|
|
24
|
+
width?: Array<StyleRule<T>>;
|
|
24
25
|
});
|
|
25
26
|
/**
|
|
26
27
|
* Refresh the rules
|
|
27
28
|
*/
|
|
28
29
|
refresh(rulesMap: {
|
|
29
|
-
color?: Array<StyleRule
|
|
30
|
-
icon?: Array<StyleRule
|
|
31
|
-
image?: Array<StyleRule
|
|
32
|
-
shape?: Array<StyleRule
|
|
33
|
-
size?: Array<StyleRule
|
|
34
|
-
width?: Array<StyleRule
|
|
30
|
+
color?: Array<StyleRule<T>>;
|
|
31
|
+
icon?: Array<StyleRule<T>>;
|
|
32
|
+
image?: Array<StyleRule<T>>;
|
|
33
|
+
shape?: Array<StyleRule<T>>;
|
|
34
|
+
size?: Array<StyleRule<T>>;
|
|
35
|
+
width?: Array<StyleRule<T>>;
|
|
35
36
|
}): void;
|
|
36
37
|
/**
|
|
37
38
|
* Return the color for a node when style color is auto
|
|
@@ -44,7 +45,7 @@ export declare class ItemAttributes {
|
|
|
44
45
|
/**
|
|
45
46
|
* Get color of a type
|
|
46
47
|
*/
|
|
47
|
-
static getTypeColor(rule: StyleRule
|
|
48
|
+
static getTypeColor(rule: StyleRule<IEdgeStyle | INodeStyle>, type: string): string | undefined | null;
|
|
48
49
|
/**
|
|
49
50
|
* return the corresponding size to the value with a linear function
|
|
50
51
|
* @param value
|
|
@@ -52,10 +53,7 @@ export declare class ItemAttributes {
|
|
|
52
53
|
* @param higher
|
|
53
54
|
* @param extrema
|
|
54
55
|
*/
|
|
55
|
-
static getAutomaticRangeStyleLinear(value: number, { max, min }:
|
|
56
|
-
max: number;
|
|
57
|
-
min: number;
|
|
58
|
-
}, lower: EdgeWidthExtrema | NodeSizeExtrema, higher: EdgeWidthExtrema | NodeSizeExtrema): string;
|
|
56
|
+
static getAutomaticRangeStyleLinear(value: number, { max, min }: IStyleAutoRange, lower: EdgeWidthExtrema | NodeSizeExtrema, higher: EdgeWidthExtrema | NodeSizeExtrema): string | undefined;
|
|
59
57
|
/**
|
|
60
58
|
* return the corresponding size to the value with a logarithmic function
|
|
61
59
|
* @param value
|
|
@@ -63,8 +61,6 @@ export declare class ItemAttributes {
|
|
|
63
61
|
* @param higher
|
|
64
62
|
* @param extrema
|
|
65
63
|
*/
|
|
66
|
-
static getAutomaticRangeStyleLog(value: number, { max, min }:
|
|
67
|
-
|
|
68
|
-
min: number;
|
|
69
|
-
}, lower: EdgeWidthExtrema | NodeSizeExtrema, higher: EdgeWidthExtrema | NodeSizeExtrema): string;
|
|
64
|
+
static getAutomaticRangeStyleLog(value: number, { max, min }: IStyleAutoRange, lower: EdgeWidthExtrema | NodeSizeExtrema, higher: EdgeWidthExtrema | NodeSizeExtrema): string | undefined;
|
|
65
|
+
isAutoRange(value: string | number | IStyleAutoRange): value is IStyleAutoRange;
|
|
70
66
|
}
|
|
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ItemAttributes = exports.PALETTE = exports.BASE_GREY = void 0;
|
|
6
7
|
const sha1_1 = __importDefault(require("sha1"));
|
|
7
8
|
const tools_1 = require("../tools/tools");
|
|
8
9
|
exports.BASE_GREY = '#7f7f7f';
|
|
@@ -64,7 +65,7 @@ class ItemAttributes {
|
|
|
64
65
|
if (ignoreCase) {
|
|
65
66
|
input = input.toLowerCase();
|
|
66
67
|
}
|
|
67
|
-
return +('0x' + sha1_1.default(input).substr(-4)) % modulo;
|
|
68
|
+
return +('0x' + (0, sha1_1.default)(input).substr(-4)) % modulo;
|
|
68
69
|
}
|
|
69
70
|
/**
|
|
70
71
|
* Get color of a type
|
|
@@ -86,15 +87,17 @@ class ItemAttributes {
|
|
|
86
87
|
* @param extrema
|
|
87
88
|
*/
|
|
88
89
|
static getAutomaticRangeStyleLinear(value, { max, min }, lower, higher) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
90
|
+
if (max !== undefined && min !== undefined) {
|
|
91
|
+
// apply default style when min equal max
|
|
92
|
+
if (max === min || isNaN(value)) {
|
|
93
|
+
return '100%';
|
|
94
|
+
}
|
|
95
|
+
// calculate the linear function f(x) = ax + b
|
|
96
|
+
const a = (higher - lower) / (max - min);
|
|
97
|
+
const b = (lower * max - higher * min) / (max - min);
|
|
98
|
+
const size = Math.floor(value * a + b);
|
|
99
|
+
return `${size}%`;
|
|
92
100
|
}
|
|
93
|
-
// calculate the linear function f(x) = ax + b
|
|
94
|
-
const a = (higher - lower) / (max - min);
|
|
95
|
-
const b = (lower * max - higher * min) / (max - min);
|
|
96
|
-
const size = Math.floor(value * a + b);
|
|
97
|
-
return `${size}%`;
|
|
98
101
|
}
|
|
99
102
|
/**
|
|
100
103
|
* return the corresponding size to the value with a logarithmic function
|
|
@@ -104,21 +107,26 @@ class ItemAttributes {
|
|
|
104
107
|
* @param extrema
|
|
105
108
|
*/
|
|
106
109
|
static getAutomaticRangeStyleLog(value, { max, min }, lower, higher) {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
+
if (min !== undefined && max !== undefined) {
|
|
111
|
+
// apply default style when min equal max
|
|
112
|
+
if (max === min || isNaN(value)) {
|
|
113
|
+
return '100%';
|
|
114
|
+
}
|
|
115
|
+
// apply an offset for all the values (including min and max)
|
|
116
|
+
if (min < 1) {
|
|
117
|
+
value += Math.abs(min) + 1;
|
|
118
|
+
max += Math.abs(min) + 1;
|
|
119
|
+
min += Math.abs(min) + 1;
|
|
120
|
+
}
|
|
121
|
+
// calculate the logarithmic function f(x) = Math.floor(a*log(x) + b)
|
|
122
|
+
const a = (higher - lower) / (Math.log(max) - Math.log(min));
|
|
123
|
+
const b = (lower * Math.log(max) - higher * Math.log(min)) / (Math.log(max) - Math.log(min));
|
|
124
|
+
const size = Math.floor(a * Math.log(value) + b);
|
|
125
|
+
return `${size}%`;
|
|
110
126
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
max += Math.abs(min) + 1;
|
|
115
|
-
min += Math.abs(min) + 1;
|
|
116
|
-
}
|
|
117
|
-
// calculate the logarithmic function f(x) = Math.floor(a*log(x) + b)
|
|
118
|
-
const a = (higher - lower) / (Math.log(max) - Math.log(min));
|
|
119
|
-
const b = (lower * Math.log(max) - higher * Math.log(min)) / (Math.log(max) - Math.log(min));
|
|
120
|
-
const size = Math.floor(a * Math.log(value) + b);
|
|
121
|
-
return `${size}%`;
|
|
127
|
+
}
|
|
128
|
+
isAutoRange(value) {
|
|
129
|
+
return typeof value === 'object' && (value === null || value === void 0 ? void 0 : value.type) === 'autoRange';
|
|
122
130
|
}
|
|
123
131
|
}
|
|
124
132
|
exports.ItemAttributes = ItemAttributes;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"itemAttributes.js","sourceRoot":"","sources":["../../src/styles/itemAttributes.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC
|
|
1
|
+
{"version":3,"file":"itemAttributes.js","sourceRoot":"","sources":["../../src/styles/itemAttributes.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;AAEb,gDAAwB;AAIxB,0CAAqC;AAMxB,QAAA,SAAS,GAAG,SAAS,CAAC;AACtB,QAAA,OAAO,GAAG;IACrB,SAAS;IACT,SAAS;IAC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GAAG,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;gBACzB,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;aAC1B;YACD,sEAAsE;YACtE,MAAM,CAAC,GAAG,CAAC,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;YAC7D,MAAM,CAAC,GAAG,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;YAC7F,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;YAEjD,OAAO,GAAG,IAAI,GAAG,CAAC;SACnB;IACH,CAAC;IAEM,WAAW,CAAC,KAAwC;QACzD,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,IAAI,MAAK,WAAW,CAAC;IAClE,CAAC;CACF;AAxJD,wCAwJC","sourcesContent":["'use strict';\n\nimport sha1 from 'sha1';\nimport {Color} from '@linkurious/ogma';\nimport {IEdgeStyle, INodeStyle, IStyleAutoRange} from '@linkurious/rest-client';\n\nimport {Tools} from '../tools/tools';\n\nimport {StyleRule} from './styleRule';\nimport {NodeSizeExtrema} from './nodeAttributes';\nimport {EdgeWidthExtrema} from './edgeAttributes';\n\nexport const BASE_GREY = '#7f7f7f';\nexport const PALETTE = [\n '#9467bd',\n '#e377c2',\n '#1f77b4',\n '#17becf',\n '#2ca02c',\n '#bcbd22',\n '#d62728',\n '#ff7f0e',\n '#8c564b',\n '#c5b0d5',\n '#f7b6d2',\n '#aec7e8',\n '#9edae5',\n '#98df8a',\n '#dbdb8d',\n '#ff9896',\n '#ffbb78',\n '#c49c94'\n];\n\nexport class ItemAttributes<T extends INodeStyle | IEdgeStyle> {\n protected colorsCache: Map<string, Color | Array<Color>> = new Map();\n protected _rulesMap: {\n color?: Array<StyleRule<T>>;\n icon?: Array<StyleRule<T>>;\n image?: Array<StyleRule<T>>;\n shape?: Array<StyleRule<T>>;\n size?: Array<StyleRule<T>>;\n width?: Array<StyleRule<T>>;\n } = {};\n\n constructor(rulesMap: {\n color?: Array<StyleRule<T>>;\n icon?: Array<StyleRule<T>>;\n image?: Array<StyleRule<T>>;\n shape?: Array<StyleRule<T>>;\n size?: Array<StyleRule<T>>;\n width?: Array<StyleRule<T>>;\n }) {\n this.refresh(rulesMap);\n }\n\n /**\n * Refresh the rules\n */\n public refresh(rulesMap: {\n color?: Array<StyleRule<T>>;\n icon?: Array<StyleRule<T>>;\n image?: Array<StyleRule<T>>;\n shape?: Array<StyleRule<T>>;\n size?: Array<StyleRule<T>>;\n width?: Array<StyleRule<T>>;\n }): void {\n if (rulesMap.color !== undefined) {\n this.colorsCache = new Map();\n }\n this._rulesMap = {\n color: rulesMap.color ? [...rulesMap.color].reverse() : this._rulesMap.color,\n icon: rulesMap.icon ? [...rulesMap.icon].reverse() : this._rulesMap.icon,\n image: rulesMap.image ? [...rulesMap.image].reverse() : this._rulesMap.image,\n shape: rulesMap.shape ? [...rulesMap.shape].reverse() : this._rulesMap.shape,\n size: rulesMap.size ? [...rulesMap.size].reverse() : this._rulesMap.size,\n width: rulesMap.width ? [...rulesMap.width].reverse() : this._rulesMap.width\n };\n }\n\n /**\n * Return the color for a node when style color is auto\n */\n public static autoColor(value: string, ignoreCase?: boolean): string {\n if (!Tools.isDefined(value)) {\n return BASE_GREY;\n }\n return PALETTE[\n ItemAttributes.getRandomUniqueColorPaletteIndex(value, PALETTE.length, ignoreCase)\n ];\n }\n\n /**\n * Return a number from 0 to number of occurrence in a palette based on a property\n */\n private static getRandomUniqueColorPaletteIndex(\n input: string,\n modulo: number,\n ignoreCase: boolean | undefined\n ): number {\n if (ignoreCase) {\n input = input.toLowerCase();\n }\n return +('0x' + sha1(input).substr(-4)) % modulo;\n }\n\n /**\n * Get color of a type\n */\n public static getTypeColor(\n rule: StyleRule<IEdgeStyle | INodeStyle>,\n type: string\n ): string | undefined | null {\n if (typeof rule.style.color === 'object' && rule.style.color.input[0] !== 'properties') {\n return ItemAttributes.autoColor(type, rule.style.color.ignoreCase);\n }\n if (!Tools.isDefined(rule.input) && typeof rule.style.color !== 'object') {\n return rule.style.color;\n }\n return null;\n }\n\n /**\n * return the corresponding size to the value with a linear function\n * @param value\n * @param lower\n * @param higher\n * @param extrema\n */\n public static getAutomaticRangeStyleLinear(\n value: number,\n {max, min}: IStyleAutoRange,\n lower: EdgeWidthExtrema | NodeSizeExtrema,\n higher: EdgeWidthExtrema | NodeSizeExtrema\n ): string | undefined {\n if (max !== undefined && min !== undefined) {\n // apply default style when min equal max\n if (max === min || isNaN(value)) {\n return '100%';\n }\n\n // calculate the linear function f(x) = ax + b\n const a = (higher - lower) / (max - min);\n const b = (lower * max - higher * min) / (max - min);\n const size = Math.floor(value * a + b);\n\n return `${size}%`;\n }\n }\n\n /**\n * return the corresponding size to the value with a logarithmic function\n * @param value\n * @param lower\n * @param higher\n * @param extrema\n */\n public static getAutomaticRangeStyleLog(\n value: number,\n {max, min}: IStyleAutoRange,\n lower: EdgeWidthExtrema | NodeSizeExtrema,\n higher: EdgeWidthExtrema | NodeSizeExtrema\n ): string | undefined {\n if (min !== undefined && max !== undefined) {\n // apply default style when min equal max\n if (max === min || isNaN(value)) {\n return '100%';\n }\n // apply an offset for all the values (including min and max)\n if (min < 1) {\n value += Math.abs(min) + 1;\n max += Math.abs(min) + 1;\n min += Math.abs(min) + 1;\n }\n // calculate the logarithmic function f(x) = Math.floor(a*log(x) + b)\n const a = (higher - lower) / (Math.log(max) - Math.log(min));\n const b = (lower * Math.log(max) - higher * Math.log(min)) / (Math.log(max) - Math.log(min));\n const size = Math.floor(a * Math.log(value) + b);\n\n return `${size}%`;\n }\n }\n\n public isAutoRange(value: string | number | IStyleAutoRange): value is IStyleAutoRange {\n return typeof value === 'object' && value?.type === 'autoRange';\n }\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Color } from '@linkurious/ogma';
|
|
2
|
-
import {
|
|
2
|
+
import { INodeStyle, IStyleIcon, IStyleImage, LkNodeData, OgmaNodeShape } from '@linkurious/rest-client';
|
|
3
3
|
import { StyleRule } from './styleRule';
|
|
4
4
|
import { ItemAttributes } from './itemAttributes';
|
|
5
5
|
export interface OgmaImage extends IStyleImage {
|
|
@@ -9,13 +9,13 @@ export declare enum NodeSizeExtrema {
|
|
|
9
9
|
MIN = 50,
|
|
10
10
|
MAX = 500
|
|
11
11
|
}
|
|
12
|
-
export declare class NodeAttributes extends ItemAttributes {
|
|
12
|
+
export declare class NodeAttributes extends ItemAttributes<INodeStyle> {
|
|
13
13
|
constructor(rulesMap: {
|
|
14
|
-
color?: Array<StyleRule
|
|
15
|
-
icon?: Array<StyleRule
|
|
16
|
-
image?: Array<StyleRule
|
|
17
|
-
shape?: Array<StyleRule
|
|
18
|
-
size?: Array<StyleRule
|
|
14
|
+
color?: Array<StyleRule<INodeStyle>>;
|
|
15
|
+
icon?: Array<StyleRule<INodeStyle>>;
|
|
16
|
+
image?: Array<StyleRule<INodeStyle>>;
|
|
17
|
+
shape?: Array<StyleRule<INodeStyle>>;
|
|
18
|
+
size?: Array<StyleRule<INodeStyle>>;
|
|
19
19
|
});
|
|
20
20
|
/**
|
|
21
21
|
* Run the callback if an item match with a style in the array of rules
|
|
@@ -46,7 +46,7 @@ export declare class NodeAttributes extends ItemAttributes {
|
|
|
46
46
|
* @param rule
|
|
47
47
|
* @param isLog
|
|
48
48
|
*/
|
|
49
|
-
static getAutomaticRangeSize(value: number, rule: StyleRule
|
|
49
|
+
static getAutomaticRangeSize(value: number, rule: StyleRule<INodeStyle>, isLog?: boolean): string | undefined;
|
|
50
50
|
/**
|
|
51
51
|
* Return an object containing all node attributes needed by Ogma to style a node
|
|
52
52
|
*/
|
|
@@ -3,6 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.NodeAttributes = exports.NodeSizeExtrema = void 0;
|
|
7
|
+
const rest_client_1 = require("@linkurious/rest-client");
|
|
6
8
|
const sha1_1 = __importDefault(require("sha1"));
|
|
7
9
|
const tools_1 = require("../tools/tools");
|
|
8
10
|
const __1 = require("..");
|
|
@@ -40,14 +42,14 @@ class NodeAttributes extends itemAttributes_1.ItemAttributes {
|
|
|
40
42
|
if (!tools_1.Tools.isDefined(itemData)) {
|
|
41
43
|
return [itemAttributes_1.BASE_GREY];
|
|
42
44
|
}
|
|
43
|
-
const hash = sha1_1.default(JSON.stringify(itemData));
|
|
45
|
+
const hash = (0, sha1_1.default)(JSON.stringify(itemData));
|
|
44
46
|
const cachedColor = this.colorsCache.get(hash);
|
|
45
47
|
if (cachedColor !== undefined) {
|
|
46
48
|
return cachedColor;
|
|
47
49
|
}
|
|
48
50
|
let colors = [];
|
|
49
51
|
for (let i = 0; i < itemData.categories.length; ++i) {
|
|
50
|
-
let
|
|
52
|
+
let color = null;
|
|
51
53
|
for (let j = 0; j < this._rulesMap.color.length; ++j) {
|
|
52
54
|
const rule = this._rulesMap.color[j];
|
|
53
55
|
if (rule.itemType !== undefined &&
|
|
@@ -59,19 +61,19 @@ class NodeAttributes extends itemAttributes_1.ItemAttributes {
|
|
|
59
61
|
if (typeof rule.style.color === 'object') {
|
|
60
62
|
const propValue = tools_1.Tools.getIn(itemData, rule.style.color.input);
|
|
61
63
|
if (Array.isArray(propValue)) {
|
|
62
|
-
|
|
64
|
+
color = itemAttributes_1.ItemAttributes.autoColor(itemData.categories[i], rule.style.color.ignoreCase);
|
|
63
65
|
}
|
|
64
66
|
else {
|
|
65
|
-
|
|
67
|
+
color = itemAttributes_1.ItemAttributes.autoColor(`${propValue}`, rule.style.color.ignoreCase);
|
|
66
68
|
}
|
|
67
69
|
}
|
|
68
70
|
else {
|
|
69
|
-
|
|
71
|
+
color = rule.style.color;
|
|
70
72
|
}
|
|
71
73
|
break;
|
|
72
74
|
}
|
|
73
75
|
}
|
|
74
|
-
colors.push(
|
|
76
|
+
colors.push(color);
|
|
75
77
|
}
|
|
76
78
|
colors = colors.filter((c) => tools_1.Tools.isDefined(c));
|
|
77
79
|
if (colors.length === 0) {
|
|
@@ -85,6 +87,7 @@ class NodeAttributes extends itemAttributes_1.ItemAttributes {
|
|
|
85
87
|
* Generate icon for a given node
|
|
86
88
|
*/
|
|
87
89
|
icon(itemData) {
|
|
90
|
+
var _a, _b;
|
|
88
91
|
const rawColors = this.color(itemData);
|
|
89
92
|
const color = Array.isArray(rawColors) ? rawColors[0] : rawColors;
|
|
90
93
|
let result = {};
|
|
@@ -97,26 +100,27 @@ class NodeAttributes extends itemAttributes_1.ItemAttributes {
|
|
|
97
100
|
}
|
|
98
101
|
for (let i = 0; i < rules.length; ++i) {
|
|
99
102
|
if (rules[i].canApplyTo(itemData)) {
|
|
100
|
-
|
|
103
|
+
const style = rules[i].style;
|
|
104
|
+
if ('icon' in style && typeof style.icon === 'object') {
|
|
101
105
|
result = {
|
|
102
106
|
icon: {
|
|
103
|
-
content:
|
|
104
|
-
font:
|
|
107
|
+
content: (_a = style.icon) === null || _a === void 0 ? void 0 : _a.content,
|
|
108
|
+
font: (_b = style.icon) === null || _b === void 0 ? void 0 : _b.font,
|
|
105
109
|
scale: 0.5,
|
|
106
110
|
color: __1.OgmaTools.isBright(color) ? '#000000' : '#FFFFFF'
|
|
107
111
|
}
|
|
108
112
|
};
|
|
109
113
|
}
|
|
110
|
-
else if ('image' in
|
|
114
|
+
else if ('image' in style && typeof style.image === 'object') {
|
|
111
115
|
result = {
|
|
112
116
|
image: {
|
|
113
|
-
url: tools_1.Tools.getType(
|
|
114
|
-
tools_1.Tools.getType(
|
|
115
|
-
?
|
|
116
|
-
: tools_1.Tools.getIn(itemData,
|
|
117
|
-
scale:
|
|
118
|
-
fit:
|
|
119
|
-
tile:
|
|
117
|
+
url: tools_1.Tools.getType(style.image.url) === 'imageUrl' ||
|
|
118
|
+
tools_1.Tools.getType(style.image.url) === 'image'
|
|
119
|
+
? style.image.url
|
|
120
|
+
: tools_1.Tools.getIn(itemData, style.image.url.path),
|
|
121
|
+
scale: style.image.scale,
|
|
122
|
+
fit: style.image.fit,
|
|
123
|
+
tile: style.image.tile,
|
|
120
124
|
minVisibleSize: 0
|
|
121
125
|
}
|
|
122
126
|
};
|
|
@@ -146,14 +150,13 @@ class NodeAttributes extends itemAttributes_1.ItemAttributes {
|
|
|
146
150
|
if (this._rulesMap.size !== undefined) {
|
|
147
151
|
NodeAttributes.matchStyle(this._rulesMap.size, itemData, (styleRule) => {
|
|
148
152
|
const sizeStyle = styleRule.style.size;
|
|
149
|
-
if (sizeStyle
|
|
153
|
+
if (this.isAutoRange(sizeStyle)) {
|
|
150
154
|
if (sizeStyle.input !== undefined &&
|
|
151
155
|
sizeStyle.max !== undefined &&
|
|
152
156
|
sizeStyle.min !== undefined) {
|
|
153
157
|
const propertyName = sizeStyle.input[1];
|
|
154
158
|
const propertyValue = tools_1.Tools.parseNumber(itemData.properties[propertyName]);
|
|
155
|
-
|
|
156
|
-
const isLog = sizeStyle.scale && sizeStyle.scale === 'logarithmic';
|
|
159
|
+
const isLog = sizeStyle.scale && sizeStyle.scale === rest_client_1.AutoRangeScale.LOGARITHMIC;
|
|
157
160
|
result = NodeAttributes.getAutomaticRangeSize(propertyValue, styleRule, isLog);
|
|
158
161
|
}
|
|
159
162
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3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,qBAAqB,CAAC,aAAa,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;qBAChF;iBACF;qBAAM;oBACL,MAAM,GAAG,SAAS,CAAC;iBACpB;YACH,CAAC,CAAC,CAAC;SACJ;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,qBAAqB,CAAC,KAAa,EAAE,IAAe,EAAE,KAAK,GAAG,KAAK;QAC/E,OAAO,KAAK;YACV,CAAC,CAAC,IAAI,CAAC,yBAAyB,CAC5B,KAAK,EACL,IAAI,CAAC,KAAK,CAAC,IAAI,EACf,eAAe,CAAC,GAAG,EACnB,eAAe,CAAC,GAAG,CACpB;YACH,CAAC,CAAC,IAAI,CAAC,4BAA4B,CAC/B,KAAK,EACL,IAAI,CAAC,KAAK,CAAC,IAAI,EACf,eAAe,CAAC,GAAG,EACnB,eAAe,CAAC,GAAG,CACpB,CAAC;IACR,CAAC;IAED;;OAEG;IACI,GAAG,CACR,QAAoB;QAQpB,IAAI,CAAC,aAAK,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE;YAC9B,OAAO;gBACL,KAAK,EAAE,0BAAS;aACjB,CAAC;SACH;QACD,MAAM,aAAa,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC1C,OAAO;YACL,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC;YAC3B,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC;YAC3B,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC;YAC3B,IAAI,EAAE,aAAa,CAAC,IAAI;YACxB,KAAK,EAAE,aAAa,CAAC,KAAK;SAC3B,CAAC;IACJ,CAAC;CACF;AA/ND,wCA+NC","sourcesContent":["'use strict';\nimport {Color} from '@linkurious/ogma';\nimport {LkNodeData, OgmaNodeShape, IStyleImage, IStyleIcon} from '@linkurious/rest-client';\nimport sha1 from 'sha1';\n\nimport {Tools} from '../tools/tools';\nimport {OgmaTools} from '..';\n\nimport {StyleRule} from './styleRule';\nimport {BASE_GREY, ItemAttributes} from './itemAttributes';\n\nexport interface OgmaImage extends IStyleImage {\n url?: string;\n}\n\nexport enum NodeSizeExtrema {\n MIN = 50,\n MAX = 500\n}\n\nexport class NodeAttributes extends ItemAttributes {\n constructor(rulesMap: {\n color?: Array<StyleRule>;\n icon?: Array<StyleRule>;\n image?: Array<StyleRule>;\n shape?: Array<StyleRule>;\n size?: Array<StyleRule>;\n }) {\n super(rulesMap);\n }\n\n /**\n * Run the callback if an item match with a style in the array of rules\n */\n private static matchStyle(\n styleRules: Array<StyleRule>,\n itemData: LkNodeData,\n callback: (style: StyleRule) => unknown\n ): void {\n if (!Tools.isDefined(itemData)) {\n return;\n }\n if (!Tools.isDefined(styleRules)) {\n return;\n }\n for (let i = 0; i < styleRules.length; ++i) {\n if (styleRules[i].canApplyTo(itemData)) {\n callback(styleRules[i]);\n break;\n }\n }\n }\n\n /**\n * Generate color for a given node (call only if _rulesMap.color is defined\n */\n public color(itemData: LkNodeData): Color | Array<Color> {\n if (!Tools.isDefined(itemData)) {\n return [BASE_GREY];\n }\n const hash = sha1(JSON.stringify(itemData));\n const cachedColor = this.colorsCache.get(hash);\n if (cachedColor !== undefined) {\n return cachedColor;\n }\n let colors = [];\n for (let i = 0; i < itemData.categories.length; ++i) {\n let c = null;\n for (let j = 0; j < this._rulesMap.color!.length; ++j) {\n const rule = this._rulesMap.color![j];\n if (\n rule.itemType !== undefined &&\n rule.itemType !== null &&\n rule.itemType !== itemData.categories[i]\n ) {\n continue;\n }\n if (rule.canApplyTo(itemData)) {\n if (typeof rule.style.color === 'object') {\n const propValue = Tools.getIn(itemData, rule.style.color.input);\n if (Array.isArray(propValue)) {\n c = ItemAttributes.autoColor(itemData.categories[i], rule.style.ignoreCase);\n } else {\n c = ItemAttributes.autoColor(`${propValue}`, rule.style.ignoreCase);\n }\n } else {\n c = rule.style.color;\n }\n break;\n }\n }\n colors.push(c);\n }\n colors = colors.filter((c) => Tools.isDefined(c));\n if (colors.length === 0) {\n colors = [BASE_GREY];\n }\n const finalColor = colors.length === 1 ? colors[0] : colors;\n this.colorsCache.set(hash, finalColor);\n return finalColor;\n }\n\n /**\n * Generate icon for a given node\n */\n public icon(\n itemData: LkNodeData\n ): {\n icon?: IStyleIcon;\n image?: OgmaImage | null;\n } {\n const rawColors = this.color(itemData);\n const color = Array.isArray(rawColors) ? rawColors[0] : rawColors;\n let result = {};\n const rules = [...(this._rulesMap.image || []), ...(this._rulesMap.icon || [])];\n if (!Tools.isDefined(itemData)) {\n return {\n icon: {},\n image: {}\n };\n }\n for (let i = 0; i < rules.length; ++i) {\n if (rules[i].canApplyTo(itemData)) {\n if ('icon' in rules[i].style) {\n result = {\n icon: {\n content: rules[i].style.icon.content,\n font: rules[i].style.icon.font,\n scale: 0.5,\n color: OgmaTools.isBright(color) ? '#000000' : '#FFFFFF'\n }\n };\n } else if ('image' in rules[i].style) {\n result = {\n image: {\n url:\n Tools.getType(rules[i].style.image.url) === 'imageUrl' ||\n Tools.getType(rules[i].style.image.url) === 'image'\n ? rules[i].style.image.url\n : Tools.getIn(itemData, rules[i].style.image.url.path),\n scale: rules[i].style.image.scale,\n fit: rules[i].style.image.fit,\n tile: rules[i].style.image.tile,\n minVisibleSize: 0\n }\n };\n }\n break;\n }\n }\n\n return result;\n }\n\n /**\n * Generate shape for a given node\n */\n public shape(itemData: LkNodeData): OgmaNodeShape | undefined {\n let result = undefined;\n if (this._rulesMap.shape !== undefined) {\n NodeAttributes.matchStyle(this._rulesMap.shape, itemData, (styleRule) => {\n result = styleRule.style.shape;\n });\n }\n return result;\n }\n\n /**\n * Generate size for a given node\n */\n public size(itemData: LkNodeData): number | undefined {\n let result = undefined;\n if (this._rulesMap.size !== undefined) {\n NodeAttributes.matchStyle(this._rulesMap.size, itemData, (styleRule) => {\n const sizeStyle = styleRule.style.size;\n if (sizeStyle.type === 'autoRange') {\n if (\n sizeStyle.input !== undefined &&\n sizeStyle.max !== undefined &&\n sizeStyle.min !== undefined\n ) {\n const propertyName: string = sizeStyle.input[1];\n const propertyValue = Tools.parseNumber(itemData.properties[propertyName]);\n //to update with the correct enum type\n const isLog = sizeStyle.scale && sizeStyle.scale === 'logarithmic';\n result = NodeAttributes.getAutomaticRangeSize(propertyValue, styleRule, isLog);\n }\n } else {\n result = sizeStyle;\n }\n });\n }\n return result;\n }\n\n /**\n * return the corresponding size to the value\n * @param value\n * @param rule\n * @param isLog\n */\n public static getAutomaticRangeSize(value: number, rule: StyleRule, isLog = false): string {\n return isLog\n ? this.getAutomaticRangeStyleLog(\n value,\n rule.style.size,\n NodeSizeExtrema.MIN,\n NodeSizeExtrema.MAX\n )\n : this.getAutomaticRangeStyleLinear(\n value,\n rule.style.size,\n NodeSizeExtrema.MIN,\n NodeSizeExtrema.MAX\n );\n }\n\n /**\n * Return an object containing all node attributes needed by Ogma to style a node\n */\n public all(\n itemData: LkNodeData\n ): {\n radius?: number | undefined;\n color: Color | Array<Color>;\n shape?: OgmaNodeShape | undefined;\n icon?: IStyleIcon;\n image?: IStyleImage | null;\n } {\n if (!Tools.isDefined(itemData)) {\n return {\n color: BASE_GREY\n };\n }\n const generatedIcon = this.icon(itemData);\n return {\n radius: this.size(itemData),\n color: this.color(itemData),\n shape: this.shape(itemData),\n icon: generatedIcon.icon,\n image: generatedIcon.image\n };\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"nodeAttributes.js","sourceRoot":"","sources":["../../src/styles/nodeAttributes.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;AAEb,yDASiC;AACjC,gDAAwB;AAExB,0CAAqC;AACrC,0BAA6B;AAG7B,qDAA2D;AAM3D,IAAY,eAGX;AAHD,WAAY,eAAe;IACzB,oDAAQ,CAAA;IACR,qDAAS,CAAA;AACX,CAAC,EAHW,eAAe,GAAf,uBAAe,KAAf,uBAAe,QAG1B;AAED,MAAa,cAAe,SAAQ,+BAA0B;IAC5D,YAAY,Q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,4BAA4B,CAC/B,KAAK,EACL,IAAI,CAAC,KAAK,CAAC,IAAuB,EAClC,eAAe,CAAC,GAAG,EACnB,eAAe,CAAC,GAAG,CACpB,CAAC;IACR,CAAC;IAED;;OAEG;IACI,GAAG,CACR,QAAoB;QAQpB,IAAI,CAAC,aAAK,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE;YAC9B,OAAO;gBACL,KAAK,EAAE,0BAAS;aACjB,CAAC;SACH;QACD,MAAM,aAAa,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC1C,OAAO;YACL,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC;YAC3B,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC;YAC3B,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC;YAC3B,IAAI,EAAE,aAAa,CAAC,IAAI;YACxB,KAAK,EAAE,aAAa,CAAC,KAAK;SAC3B,CAAC;IACJ,CAAC;CACF;AAvOD,wCAuOC","sourcesContent":["'use strict';\nimport {Color} from '@linkurious/ogma';\nimport {\n AutoRangeScale,\n IImageDataValue,\n INodeStyle,\n IStyleAutoRange,\n IStyleIcon,\n IStyleImage,\n LkNodeData,\n OgmaNodeShape\n} from '@linkurious/rest-client';\nimport sha1 from 'sha1';\n\nimport {Tools} from '../tools/tools';\nimport {OgmaTools} from '..';\n\nimport {StyleRule} from './styleRule';\nimport {BASE_GREY, ItemAttributes} from './itemAttributes';\n\nexport interface OgmaImage extends IStyleImage {\n url?: string;\n}\n\nexport enum NodeSizeExtrema {\n MIN = 50,\n MAX = 500\n}\n\nexport class NodeAttributes extends ItemAttributes<INodeStyle> {\n constructor(rulesMap: {\n color?: Array<StyleRule<INodeStyle>>;\n icon?: Array<StyleRule<INodeStyle>>;\n image?: Array<StyleRule<INodeStyle>>;\n shape?: Array<StyleRule<INodeStyle>>;\n size?: Array<StyleRule<INodeStyle>>;\n }) {\n super(rulesMap);\n }\n\n /**\n * Run the callback if an item match with a style in the array of rules\n */\n private static matchStyle(\n styleRules: Array<StyleRule<INodeStyle>>,\n itemData: LkNodeData,\n callback: (style: StyleRule<INodeStyle>) => unknown\n ): void {\n if (!Tools.isDefined(itemData)) {\n return;\n }\n if (!Tools.isDefined(styleRules)) {\n return;\n }\n for (let i = 0; i < styleRules.length; ++i) {\n if (styleRules[i].canApplyTo(itemData)) {\n callback(styleRules[i]);\n break;\n }\n }\n }\n\n /**\n * Generate color for a given node (call only if _rulesMap.color is defined\n */\n public color(itemData: LkNodeData): Color | Array<Color> {\n if (!Tools.isDefined(itemData)) {\n return [BASE_GREY];\n }\n const hash = sha1(JSON.stringify(itemData));\n const cachedColor = this.colorsCache.get(hash);\n if (cachedColor !== undefined) {\n return cachedColor;\n }\n let colors: Array<string | null> = [];\n for (let i = 0; i < itemData.categories.length; ++i) {\n let color = null;\n for (let j = 0; j < this._rulesMap.color!.length; ++j) {\n const rule = this._rulesMap.color![j];\n if (\n rule.itemType !== undefined &&\n rule.itemType !== null &&\n rule.itemType !== itemData.categories[i]\n ) {\n continue;\n }\n if (rule.canApplyTo(itemData)) {\n if (typeof rule.style.color === 'object') {\n const propValue = Tools.getIn(itemData, rule.style.color.input);\n if (Array.isArray(propValue)) {\n color = ItemAttributes.autoColor(itemData.categories[i], rule.style.color.ignoreCase);\n } else {\n color = ItemAttributes.autoColor(`${propValue}`, rule.style.color.ignoreCase);\n }\n } else {\n color = rule.style.color as string;\n }\n break;\n }\n }\n colors.push(color);\n }\n colors = colors.filter((c) => Tools.isDefined(c));\n if (colors.length === 0) {\n colors = [BASE_GREY];\n }\n const finalColor = colors.length === 1 ? colors[0] : colors;\n this.colorsCache.set(hash, finalColor);\n return finalColor;\n }\n\n /**\n * Generate icon for a given node\n */\n public icon(\n itemData: LkNodeData\n ): {\n icon?: IStyleIcon;\n image?: OgmaImage | null;\n } {\n const rawColors = this.color(itemData);\n const color = Array.isArray(rawColors) ? rawColors[0] : rawColors;\n let result = {};\n const rules = [...(this._rulesMap.image || []), ...(this._rulesMap.icon || [])];\n if (!Tools.isDefined(itemData)) {\n return {\n icon: {},\n image: {}\n };\n }\n for (let i = 0; i < rules.length; ++i) {\n if (rules[i].canApplyTo(itemData)) {\n const style = rules[i].style;\n if ('icon' in style && typeof style.icon === 'object') {\n result = {\n icon: {\n content: style.icon?.content as string,\n font: style.icon?.font,\n scale: 0.5,\n color: OgmaTools.isBright(color) ? '#000000' : '#FFFFFF'\n }\n };\n } else if ('image' in style && typeof style.image === 'object') {\n result = {\n image: {\n url:\n Tools.getType(style.image.url as string) === 'imageUrl' ||\n Tools.getType(style.image.url as string) === 'image'\n ? style.image.url\n : Tools.getIn(itemData, (style.image.url as IImageDataValue).path),\n scale: style.image.scale,\n fit: style.image.fit,\n tile: style.image.tile,\n minVisibleSize: 0\n }\n };\n }\n break;\n }\n }\n\n return result;\n }\n\n /**\n * Generate shape for a given node\n */\n public shape(itemData: LkNodeData): OgmaNodeShape | undefined {\n let result = undefined;\n if (this._rulesMap.shape !== undefined) {\n NodeAttributes.matchStyle(this._rulesMap.shape, itemData, (styleRule) => {\n result = styleRule.style.shape;\n });\n }\n return result;\n }\n\n /**\n * Generate size for a given node\n */\n public size(itemData: LkNodeData): number | undefined {\n let result = undefined;\n if (this._rulesMap.size !== undefined) {\n NodeAttributes.matchStyle(\n this._rulesMap.size,\n itemData,\n (styleRule: StyleRule<INodeStyle>) => {\n const sizeStyle = styleRule.style.size as string | number | IStyleAutoRange;\n if (this.isAutoRange(sizeStyle)) {\n if (\n sizeStyle.input !== undefined &&\n sizeStyle.max !== undefined &&\n sizeStyle.min !== undefined\n ) {\n const propertyName: string = sizeStyle.input[1];\n const propertyValue = Tools.parseNumber(itemData.properties[propertyName]);\n const isLog = sizeStyle.scale && sizeStyle.scale === AutoRangeScale.LOGARITHMIC;\n result = NodeAttributes.getAutomaticRangeSize(propertyValue, styleRule, isLog);\n }\n } else {\n result = sizeStyle;\n }\n }\n );\n }\n return result;\n }\n\n /**\n * return the corresponding size to the value\n * @param value\n * @param rule\n * @param isLog\n */\n public static getAutomaticRangeSize(\n value: number,\n rule: StyleRule<INodeStyle>,\n isLog = false\n ): string | undefined {\n return isLog\n ? this.getAutomaticRangeStyleLog(\n value,\n rule.style.size as IStyleAutoRange,\n NodeSizeExtrema.MIN,\n NodeSizeExtrema.MAX\n )\n : this.getAutomaticRangeStyleLinear(\n value,\n rule.style.size as IStyleAutoRange,\n NodeSizeExtrema.MIN,\n NodeSizeExtrema.MAX\n );\n }\n\n /**\n * Return an object containing all node attributes needed by Ogma to style a node\n */\n public all(\n itemData: LkNodeData\n ): {\n radius?: number | undefined;\n color: Color | Array<Color>;\n shape?: OgmaNodeShape | undefined;\n icon?: IStyleIcon;\n image?: IStyleImage | null;\n } {\n if (!Tools.isDefined(itemData)) {\n return {\n color: BASE_GREY\n };\n }\n const generatedIcon = this.icon(itemData);\n return {\n radius: this.size(itemData),\n color: this.color(itemData),\n shape: this.shape(itemData),\n icon: generatedIcon.icon,\n image: generatedIcon.image\n };\n }\n}\n"]}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { IEdgeStyle, IStyleRule, LkEdgeData, LkNodeData, INodeStyle, SelectorType } from '@linkurious/rest-client';
|
|
1
|
+
import { IEdgeStyle, IStyleRule, LkEdgeData, LkNodeData, INodeStyle, IRangeValues, SelectorType } from '@linkurious/rest-client';
|
|
2
2
|
export declare enum StyleRuleType {
|
|
3
3
|
AUTO_RANGE = "autoRange"
|
|
4
4
|
}
|
|
5
|
-
export declare class StyleRule
|
|
5
|
+
export declare class StyleRule<T extends INodeStyle | IEdgeStyle = INodeStyle | IEdgeStyle> implements IStyleRule<T> {
|
|
6
6
|
type: SelectorType;
|
|
7
7
|
input: string[] | undefined;
|
|
8
8
|
index: number;
|
|
9
|
+
style: T;
|
|
9
10
|
itemType?: string;
|
|
10
|
-
value:
|
|
11
|
-
|
|
12
|
-
constructor(model: IStyleRule<INodeStyle | IEdgeStyle>);
|
|
11
|
+
value: IRangeValues | number | string | boolean;
|
|
12
|
+
constructor(model: IStyleRule<T>);
|
|
13
13
|
static isAutomaticRange(rule: IStyleRule<IEdgeStyle | INodeStyle>): boolean;
|
|
14
14
|
/**
|
|
15
15
|
* Return an int describing specificity of the style. 4 = very specific / 1 = not specific
|
|
@@ -20,7 +20,7 @@ export declare class StyleRule implements IStyleRule<INodeStyle | IEdgeStyle> {
|
|
|
20
20
|
/**
|
|
21
21
|
* Return true if this style match values
|
|
22
22
|
*/
|
|
23
|
-
matchValues(itemType: string | undefined, input: Array<string> | undefined, value:
|
|
23
|
+
matchValues(itemType: string | undefined, input: Array<string> | undefined, value: string): boolean;
|
|
24
24
|
static inputExists(type: SelectorType, input: Array<string> | undefined): input is Array<string>;
|
|
25
25
|
/**
|
|
26
26
|
* Return true if a style can apply to a node
|
|
@@ -51,7 +51,7 @@ export declare class StyleRule implements IStyleRule<INodeStyle | IEdgeStyle> {
|
|
|
51
51
|
/**
|
|
52
52
|
* Return true or false on rule type 'is' if the current node match the rule
|
|
53
53
|
*/
|
|
54
|
-
static checkIs(data: LkNodeData | LkEdgeData, input: Array<string>, value:
|
|
54
|
+
static checkIs(data: LkNodeData | LkEdgeData, input: Array<string>, value: IRangeValues | number | string | boolean): boolean;
|
|
55
55
|
/**
|
|
56
56
|
* Check that value of itemType match for the node
|
|
57
57
|
*/
|
|
@@ -70,7 +70,7 @@ export declare class StyleRule implements IStyleRule<INodeStyle | IEdgeStyle> {
|
|
|
70
70
|
* @param {string} itemType
|
|
71
71
|
* @return {boolean}
|
|
72
72
|
*/
|
|
73
|
-
static matchAny(itemType:
|
|
73
|
+
static matchAny(itemType: string | null | undefined): boolean;
|
|
74
74
|
/**
|
|
75
75
|
* Return the color for a type
|
|
76
76
|
*/
|
package/dist/styles/styleRule.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StyleRule = exports.StyleRuleType = void 0;
|
|
3
4
|
const rest_client_1 = require("@linkurious/rest-client");
|
|
4
5
|
const __1 = require("..");
|
|
5
6
|
const tools_1 = require("../tools/tools");
|
|
@@ -14,6 +15,7 @@ class StyleRule {
|
|
|
14
15
|
this.index = model.index;
|
|
15
16
|
this.itemType = model.itemType;
|
|
16
17
|
this.style = model.style;
|
|
18
|
+
// cast to remove undefined from type
|
|
17
19
|
this.value = model.value;
|
|
18
20
|
}
|
|
19
21
|
static isAutomaticRange(rule) {
|