@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,92 +1,78 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
extendStatics(d, b);
|
|
11
|
-
function __() { this.constructor = d; }
|
|
12
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
13
|
-
};
|
|
14
|
-
})();
|
|
15
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
3
|
+
exports.EdgeAttributes = exports.EdgeWidthExtrema = void 0;
|
|
4
|
+
const rest_client_1 = require("@linkurious/rest-client");
|
|
5
|
+
const tools_1 = require("../tools/tools");
|
|
6
|
+
const itemAttributes_1 = require("./itemAttributes");
|
|
19
7
|
var EdgeWidthExtrema;
|
|
20
8
|
(function (EdgeWidthExtrema) {
|
|
21
9
|
EdgeWidthExtrema[EdgeWidthExtrema["MIN"] = 50] = "MIN";
|
|
22
10
|
EdgeWidthExtrema[EdgeWidthExtrema["MAX"] = 200] = "MAX";
|
|
23
11
|
})(EdgeWidthExtrema = exports.EdgeWidthExtrema || (exports.EdgeWidthExtrema = {}));
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return _super.call(this, rulesMap) || this;
|
|
12
|
+
class EdgeAttributes extends itemAttributes_1.ItemAttributes {
|
|
13
|
+
constructor(rulesMap) {
|
|
14
|
+
super(rulesMap);
|
|
28
15
|
}
|
|
29
16
|
/**
|
|
30
17
|
* Return rule that can be applied to the data
|
|
31
18
|
*/
|
|
32
|
-
|
|
19
|
+
static matchStyle(styleRules, data) {
|
|
33
20
|
if (data === undefined) {
|
|
34
21
|
return;
|
|
35
22
|
}
|
|
36
|
-
for (
|
|
23
|
+
for (let i = 0; i < styleRules.length; ++i) {
|
|
37
24
|
if (styleRules[i].canApplyTo(data)) {
|
|
38
25
|
return styleRules[i];
|
|
39
26
|
}
|
|
40
27
|
}
|
|
41
|
-
}
|
|
28
|
+
}
|
|
42
29
|
/**
|
|
43
30
|
* Generate color for a given edge (call only if _rulesMap.color exists)
|
|
44
31
|
*/
|
|
45
|
-
|
|
32
|
+
color(data) {
|
|
46
33
|
if (!tools_1.Tools.isDefined(data)) {
|
|
47
34
|
return itemAttributes_1.BASE_GREY;
|
|
48
35
|
}
|
|
49
|
-
|
|
50
|
-
for (
|
|
51
|
-
|
|
36
|
+
let color;
|
|
37
|
+
for (let j = 0; j < this._rulesMap.color.length; ++j) {
|
|
38
|
+
const rule = this._rulesMap.color[j];
|
|
52
39
|
if (rule.canApplyTo(data)) {
|
|
53
40
|
if (typeof rule.style.color === 'string') {
|
|
54
41
|
color = rule.style.color;
|
|
55
42
|
}
|
|
56
43
|
else if (typeof rule.style.color === 'object') {
|
|
57
|
-
|
|
58
|
-
color = itemAttributes_1.ItemAttributes.autoColor(
|
|
44
|
+
const propValue = tools_1.Tools.getIn(data, rule.style.color.input);
|
|
45
|
+
color = itemAttributes_1.ItemAttributes.autoColor(`${propValue}`, rule.style.ignoreCase);
|
|
59
46
|
}
|
|
60
47
|
break;
|
|
61
48
|
}
|
|
62
49
|
}
|
|
63
50
|
return tools_1.Tools.isDefined(color) ? color : itemAttributes_1.BASE_GREY;
|
|
64
|
-
}
|
|
51
|
+
}
|
|
65
52
|
/**
|
|
66
53
|
* Generate shape for a given node
|
|
67
54
|
*/
|
|
68
|
-
|
|
55
|
+
shape(data) {
|
|
69
56
|
var _a;
|
|
70
57
|
if (this._rulesMap.shape !== undefined) {
|
|
71
58
|
return (_a = EdgeAttributes.matchStyle(this._rulesMap.shape, data)) === null || _a === void 0 ? void 0 : _a.style.shape;
|
|
72
59
|
}
|
|
73
|
-
}
|
|
60
|
+
}
|
|
74
61
|
/**
|
|
75
62
|
* Generate size for a given node
|
|
76
63
|
*/
|
|
77
|
-
|
|
78
|
-
var _a;
|
|
64
|
+
width(data) {
|
|
79
65
|
if (this._rulesMap.width !== undefined) {
|
|
80
|
-
|
|
81
|
-
|
|
66
|
+
const styleRule = EdgeAttributes.matchStyle(this._rulesMap.width, data);
|
|
67
|
+
const widthStyle = styleRule === null || styleRule === void 0 ? void 0 : styleRule.style.width;
|
|
82
68
|
if (tools_1.Tools.isDefined(styleRule) && widthStyle.type === 'autoRange') {
|
|
83
69
|
if (widthStyle.input !== undefined &&
|
|
84
70
|
widthStyle.max !== undefined &&
|
|
85
71
|
widthStyle.min !== undefined) {
|
|
86
|
-
|
|
87
|
-
|
|
72
|
+
const propertyName = widthStyle.input[1];
|
|
73
|
+
const propertyValue = tools_1.Tools.parseNumber(data.properties[propertyName]);
|
|
88
74
|
//to update with the correct enum type
|
|
89
|
-
|
|
75
|
+
const isLog = widthStyle.scale && widthStyle.scale === 'logarithmic';
|
|
90
76
|
return EdgeAttributes.getAutomaticRangeWidth(propertyValue, styleRule, isLog);
|
|
91
77
|
}
|
|
92
78
|
}
|
|
@@ -94,23 +80,22 @@ var EdgeAttributes = /** @class */ (function (_super) {
|
|
|
94
80
|
return widthStyle;
|
|
95
81
|
}
|
|
96
82
|
}
|
|
97
|
-
}
|
|
83
|
+
}
|
|
98
84
|
/**
|
|
99
85
|
* return the corresponding width to the value
|
|
100
86
|
* @param value
|
|
101
87
|
* @param rule
|
|
102
88
|
* @param isLog
|
|
103
89
|
*/
|
|
104
|
-
|
|
105
|
-
if (isLog === void 0) { isLog = false; }
|
|
90
|
+
static getAutomaticRangeWidth(value, rule, isLog = false) {
|
|
106
91
|
return isLog
|
|
107
92
|
? this.getAutomaticRangeStyleLog(value, rule.style.width, EdgeWidthExtrema.MIN, EdgeWidthExtrema.MAX)
|
|
108
93
|
: this.getAutomaticRangeStyleLinear(value, rule.style.width, EdgeWidthExtrema.MIN, EdgeWidthExtrema.MAX);
|
|
109
|
-
}
|
|
94
|
+
}
|
|
110
95
|
/**
|
|
111
96
|
* Return an object containing all node attributes needed by Ogma to style a node
|
|
112
97
|
*/
|
|
113
|
-
|
|
98
|
+
all(data) {
|
|
114
99
|
if (!tools_1.Tools.isDefined(data)) {
|
|
115
100
|
return {
|
|
116
101
|
color: itemAttributes_1.BASE_GREY,
|
|
@@ -123,8 +108,7 @@ var EdgeAttributes = /** @class */ (function (_super) {
|
|
|
123
108
|
shape: this.shape(data),
|
|
124
109
|
width: this.width(data)
|
|
125
110
|
};
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
}(itemAttributes_1.ItemAttributes));
|
|
111
|
+
}
|
|
112
|
+
}
|
|
129
113
|
exports.EdgeAttributes = EdgeAttributes;
|
|
130
114
|
//# sourceMappingURL=edgeAttributes.js.map
|
|
@@ -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,yDAAkE;AAElE,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,+BAAc;IAChD,YAAY,QAIX;QACC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAClB,CAAC;IAED;;OAEG;IACK,MAAM,CAAC,UAAU,CAAC,UAA4B,EAAE,IAAgB;QACtE,IAAI,IAAI,KAAK,SAAS,EAAE;YACtB,OAAO;SACR;QACD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,UAAU,CAAC,MAAM,EA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,KAAK,CAAC,KAAK,EAChB,gBAAgB,CAAC,GAAG,EACpB,gBAAgB,CAAC,GAAG,CACrB;YACH,CAAC,CAAC,IAAI,CAAC,4BAA4B,CAC/B,KAAK,EACL,IAAI,CAAC,KAAK,CAAC,KAAK,EAChB,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;AA7HD,wCA6HC","sourcesContent":["'use strict';\nimport {Color} from '@linkurious/ogma';\nimport {LkEdgeData, OgmaEdgeShape} 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 {\n constructor(rulesMap: {\n color?: Array<StyleRule>;\n shape?: Array<StyleRule>;\n width?: Array<StyleRule>;\n }) {\n super(rulesMap);\n }\n\n /**\n * Return rule that can be applied to the data\n */\n private static matchStyle(styleRules: Array<StyleRule>, data: LkEdgeData): StyleRule | 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.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 | undefined {\n if (this._rulesMap.width !== undefined) {\n const styleRule = EdgeAttributes.matchStyle(this._rulesMap.width, data);\n const widthStyle = styleRule?.style.width;\n if (Tools.isDefined(styleRule) && widthStyle.type === 'autoRange') {\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 //to update with the correct enum type\n const isLog = widthStyle.scale && widthStyle.scale === 'logarithmic';\n return EdgeAttributes.getAutomaticRangeWidth(propertyValue, styleRule, isLog);\n }\n } else {\n return widthStyle;\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(value: number, rule: StyleRule, isLog = false): string {\n return isLog\n ? this.getAutomaticRangeStyleLog(\n value,\n rule.style.width,\n EdgeWidthExtrema.MIN,\n EdgeWidthExtrema.MAX\n )\n : this.getAutomaticRangeStyleLinear(\n value,\n rule.style.width,\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;\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,17 +1,11 @@
|
|
|
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
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
10
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
11
4
|
};
|
|
12
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
|
|
14
|
-
|
|
6
|
+
exports.ItemAttributes = exports.PALETTE = exports.BASE_GREY = void 0;
|
|
7
|
+
const sha1_1 = __importDefault(require("sha1"));
|
|
8
|
+
const tools_1 = require("../tools/tools");
|
|
15
9
|
exports.BASE_GREY = '#7f7f7f';
|
|
16
10
|
exports.PALETTE = [
|
|
17
11
|
'#9467bd',
|
|
@@ -33,8 +27,8 @@ exports.PALETTE = [
|
|
|
33
27
|
'#ffbb78',
|
|
34
28
|
'#c49c94'
|
|
35
29
|
];
|
|
36
|
-
|
|
37
|
-
|
|
30
|
+
class ItemAttributes {
|
|
31
|
+
constructor(rulesMap) {
|
|
38
32
|
this.colorsCache = new Map();
|
|
39
33
|
this._rulesMap = {};
|
|
40
34
|
this.refresh(rulesMap);
|
|
@@ -42,41 +36,41 @@ var ItemAttributes = /** @class */ (function () {
|
|
|
42
36
|
/**
|
|
43
37
|
* Refresh the rules
|
|
44
38
|
*/
|
|
45
|
-
|
|
39
|
+
refresh(rulesMap) {
|
|
46
40
|
if (rulesMap.color !== undefined) {
|
|
47
41
|
this.colorsCache = new Map();
|
|
48
42
|
}
|
|
49
43
|
this._rulesMap = {
|
|
50
|
-
color: rulesMap.color ?
|
|
51
|
-
icon: rulesMap.icon ?
|
|
52
|
-
image: rulesMap.image ?
|
|
53
|
-
shape: rulesMap.shape ?
|
|
54
|
-
size: rulesMap.size ?
|
|
55
|
-
width: rulesMap.width ?
|
|
44
|
+
color: rulesMap.color ? [...rulesMap.color].reverse() : this._rulesMap.color,
|
|
45
|
+
icon: rulesMap.icon ? [...rulesMap.icon].reverse() : this._rulesMap.icon,
|
|
46
|
+
image: rulesMap.image ? [...rulesMap.image].reverse() : this._rulesMap.image,
|
|
47
|
+
shape: rulesMap.shape ? [...rulesMap.shape].reverse() : this._rulesMap.shape,
|
|
48
|
+
size: rulesMap.size ? [...rulesMap.size].reverse() : this._rulesMap.size,
|
|
49
|
+
width: rulesMap.width ? [...rulesMap.width].reverse() : this._rulesMap.width
|
|
56
50
|
};
|
|
57
|
-
}
|
|
51
|
+
}
|
|
58
52
|
/**
|
|
59
53
|
* Return the color for a node when style color is auto
|
|
60
54
|
*/
|
|
61
|
-
|
|
55
|
+
static autoColor(value, ignoreCase) {
|
|
62
56
|
if (!tools_1.Tools.isDefined(value)) {
|
|
63
57
|
return exports.BASE_GREY;
|
|
64
58
|
}
|
|
65
59
|
return exports.PALETTE[ItemAttributes.getRandomUniqueColorPaletteIndex(value, exports.PALETTE.length, ignoreCase)];
|
|
66
|
-
}
|
|
60
|
+
}
|
|
67
61
|
/**
|
|
68
62
|
* Return a number from 0 to number of occurrence in a palette based on a property
|
|
69
63
|
*/
|
|
70
|
-
|
|
64
|
+
static getRandomUniqueColorPaletteIndex(input, modulo, ignoreCase) {
|
|
71
65
|
if (ignoreCase) {
|
|
72
66
|
input = input.toLowerCase();
|
|
73
67
|
}
|
|
74
|
-
return +('0x' + sha1_1.default(input).substr(-4)) % modulo;
|
|
75
|
-
}
|
|
68
|
+
return +('0x' + (0, sha1_1.default)(input).substr(-4)) % modulo;
|
|
69
|
+
}
|
|
76
70
|
/**
|
|
77
71
|
* Get color of a type
|
|
78
72
|
*/
|
|
79
|
-
|
|
73
|
+
static getTypeColor(rule, type) {
|
|
80
74
|
if (typeof rule.style.color === 'object' && rule.style.color.input[0] !== 'properties') {
|
|
81
75
|
return ItemAttributes.autoColor(type, rule.style.color.ignoreCase);
|
|
82
76
|
}
|
|
@@ -84,7 +78,7 @@ var ItemAttributes = /** @class */ (function () {
|
|
|
84
78
|
return rule.style.color;
|
|
85
79
|
}
|
|
86
80
|
return null;
|
|
87
|
-
}
|
|
81
|
+
}
|
|
88
82
|
/**
|
|
89
83
|
* return the corresponding size to the value with a linear function
|
|
90
84
|
* @param value
|
|
@@ -92,18 +86,17 @@ var ItemAttributes = /** @class */ (function () {
|
|
|
92
86
|
* @param higher
|
|
93
87
|
* @param extrema
|
|
94
88
|
*/
|
|
95
|
-
|
|
96
|
-
var max = _a.max, min = _a.min;
|
|
89
|
+
static getAutomaticRangeStyleLinear(value, { max, min }, lower, higher) {
|
|
97
90
|
// apply default style when min equal max
|
|
98
91
|
if (max === min || isNaN(value)) {
|
|
99
92
|
return '100%';
|
|
100
93
|
}
|
|
101
94
|
// calculate the linear function f(x) = ax + b
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
return size
|
|
106
|
-
}
|
|
95
|
+
const a = (higher - lower) / (max - min);
|
|
96
|
+
const b = (lower * max - higher * min) / (max - min);
|
|
97
|
+
const size = Math.floor(value * a + b);
|
|
98
|
+
return `${size}%`;
|
|
99
|
+
}
|
|
107
100
|
/**
|
|
108
101
|
* return the corresponding size to the value with a logarithmic function
|
|
109
102
|
* @param value
|
|
@@ -111,8 +104,7 @@ var ItemAttributes = /** @class */ (function () {
|
|
|
111
104
|
* @param higher
|
|
112
105
|
* @param extrema
|
|
113
106
|
*/
|
|
114
|
-
|
|
115
|
-
var max = _a.max, min = _a.min;
|
|
107
|
+
static getAutomaticRangeStyleLog(value, { max, min }, lower, higher) {
|
|
116
108
|
// apply default style when min equal max
|
|
117
109
|
if (max === min || isNaN(value)) {
|
|
118
110
|
return '100%';
|
|
@@ -124,12 +116,11 @@ var ItemAttributes = /** @class */ (function () {
|
|
|
124
116
|
min += Math.abs(min) + 1;
|
|
125
117
|
}
|
|
126
118
|
// calculate the logarithmic function f(x) = Math.floor(a*log(x) + b)
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
return size
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
}());
|
|
119
|
+
const a = (higher - lower) / (Math.log(max) - Math.log(min));
|
|
120
|
+
const b = (lower * Math.log(max) - higher * Math.log(min)) / (Math.log(max) - Math.log(min));
|
|
121
|
+
const size = Math.floor(a * Math.log(value) + b);
|
|
122
|
+
return `${size}%`;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
134
125
|
exports.ItemAttributes = ItemAttributes;
|
|
135
126
|
//# sourceMappingURL=itemAttributes.js.map
|
|
@@ -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;AAGxB,0CAAqC;AAMxB,QAAA,SAAS,GAAG,SAAS,CAAC;AACtB,QAAA,OAAO,GAAG;IACrB,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;CACV,CAAC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C7D,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;QAC7F,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;QAEjD,OAAO,GAAG,IAAI,GAAG,CAAC;IACpB,CAAC;CACF;AA7ID,wCA6IC","sourcesContent":["'use strict';\n\nimport sha1 from 'sha1';\nimport {Color} from '@linkurious/ogma';\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 {\n protected colorsCache: Map<string, Color | Array<Color>> = new Map();\n protected _rulesMap: {\n color?: Array<StyleRule>;\n icon?: Array<StyleRule>;\n image?: Array<StyleRule>;\n shape?: Array<StyleRule>;\n size?: Array<StyleRule>;\n width?: Array<StyleRule>;\n } = {};\n\n constructor(rulesMap: {\n color?: Array<StyleRule>;\n icon?: Array<StyleRule>;\n image?: Array<StyleRule>;\n shape?: Array<StyleRule>;\n size?: Array<StyleRule>;\n width?: Array<StyleRule>;\n }) {\n this.refresh(rulesMap);\n }\n\n /**\n * Refresh the rules\n */\n public refresh(rulesMap: {\n color?: Array<StyleRule>;\n icon?: Array<StyleRule>;\n image?: Array<StyleRule>;\n shape?: Array<StyleRule>;\n size?: Array<StyleRule>;\n width?: Array<StyleRule>;\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(rule: StyleRule, type: string): string | 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}: {max: number; min: number},\n lower: EdgeWidthExtrema | NodeSizeExtrema,\n higher: EdgeWidthExtrema | NodeSizeExtrema\n ): string {\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 * 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}: {max: number; min: number},\n lower: EdgeWidthExtrema | NodeSizeExtrema,\n higher: EdgeWidthExtrema | NodeSizeExtrema\n ): string {\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"]}
|
|
@@ -1,76 +1,56 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
extendStatics(d, b);
|
|
11
|
-
function __() { this.constructor = d; }
|
|
12
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
13
|
-
};
|
|
14
|
-
})();
|
|
15
|
-
var __spreadArrays = (this && this.__spreadArrays) || function () {
|
|
16
|
-
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
|
|
17
|
-
for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
|
18
|
-
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
|
19
|
-
r[k] = a[j];
|
|
20
|
-
return r;
|
|
21
|
-
};
|
|
22
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
4
|
};
|
|
25
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
6
|
+
exports.NodeAttributes = exports.NodeSizeExtrema = void 0;
|
|
7
|
+
const sha1_1 = __importDefault(require("sha1"));
|
|
8
|
+
const tools_1 = require("../tools/tools");
|
|
9
|
+
const __1 = require("..");
|
|
10
|
+
const itemAttributes_1 = require("./itemAttributes");
|
|
30
11
|
var NodeSizeExtrema;
|
|
31
12
|
(function (NodeSizeExtrema) {
|
|
32
13
|
NodeSizeExtrema[NodeSizeExtrema["MIN"] = 50] = "MIN";
|
|
33
14
|
NodeSizeExtrema[NodeSizeExtrema["MAX"] = 500] = "MAX";
|
|
34
15
|
})(NodeSizeExtrema = exports.NodeSizeExtrema || (exports.NodeSizeExtrema = {}));
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
return _super.call(this, rulesMap) || this;
|
|
16
|
+
class NodeAttributes extends itemAttributes_1.ItemAttributes {
|
|
17
|
+
constructor(rulesMap) {
|
|
18
|
+
super(rulesMap);
|
|
39
19
|
}
|
|
40
20
|
/**
|
|
41
21
|
* Run the callback if an item match with a style in the array of rules
|
|
42
22
|
*/
|
|
43
|
-
|
|
23
|
+
static matchStyle(styleRules, itemData, callback) {
|
|
44
24
|
if (!tools_1.Tools.isDefined(itemData)) {
|
|
45
25
|
return;
|
|
46
26
|
}
|
|
47
27
|
if (!tools_1.Tools.isDefined(styleRules)) {
|
|
48
28
|
return;
|
|
49
29
|
}
|
|
50
|
-
for (
|
|
30
|
+
for (let i = 0; i < styleRules.length; ++i) {
|
|
51
31
|
if (styleRules[i].canApplyTo(itemData)) {
|
|
52
32
|
callback(styleRules[i]);
|
|
53
33
|
break;
|
|
54
34
|
}
|
|
55
35
|
}
|
|
56
|
-
}
|
|
36
|
+
}
|
|
57
37
|
/**
|
|
58
38
|
* Generate color for a given node (call only if _rulesMap.color is defined
|
|
59
39
|
*/
|
|
60
|
-
|
|
40
|
+
color(itemData) {
|
|
61
41
|
if (!tools_1.Tools.isDefined(itemData)) {
|
|
62
42
|
return [itemAttributes_1.BASE_GREY];
|
|
63
43
|
}
|
|
64
|
-
|
|
65
|
-
|
|
44
|
+
const hash = (0, sha1_1.default)(JSON.stringify(itemData));
|
|
45
|
+
const cachedColor = this.colorsCache.get(hash);
|
|
66
46
|
if (cachedColor !== undefined) {
|
|
67
47
|
return cachedColor;
|
|
68
48
|
}
|
|
69
|
-
|
|
70
|
-
for (
|
|
71
|
-
|
|
72
|
-
for (
|
|
73
|
-
|
|
49
|
+
let colors = [];
|
|
50
|
+
for (let i = 0; i < itemData.categories.length; ++i) {
|
|
51
|
+
let c = null;
|
|
52
|
+
for (let j = 0; j < this._rulesMap.color.length; ++j) {
|
|
53
|
+
const rule = this._rulesMap.color[j];
|
|
74
54
|
if (rule.itemType !== undefined &&
|
|
75
55
|
rule.itemType !== null &&
|
|
76
56
|
rule.itemType !== itemData.categories[i]) {
|
|
@@ -78,12 +58,12 @@ var NodeAttributes = /** @class */ (function (_super) {
|
|
|
78
58
|
}
|
|
79
59
|
if (rule.canApplyTo(itemData)) {
|
|
80
60
|
if (typeof rule.style.color === 'object') {
|
|
81
|
-
|
|
61
|
+
const propValue = tools_1.Tools.getIn(itemData, rule.style.color.input);
|
|
82
62
|
if (Array.isArray(propValue)) {
|
|
83
63
|
c = itemAttributes_1.ItemAttributes.autoColor(itemData.categories[i], rule.style.ignoreCase);
|
|
84
64
|
}
|
|
85
65
|
else {
|
|
86
|
-
c = itemAttributes_1.ItemAttributes.autoColor(
|
|
66
|
+
c = itemAttributes_1.ItemAttributes.autoColor(`${propValue}`, rule.style.ignoreCase);
|
|
87
67
|
}
|
|
88
68
|
}
|
|
89
69
|
else {
|
|
@@ -94,29 +74,29 @@ var NodeAttributes = /** @class */ (function (_super) {
|
|
|
94
74
|
}
|
|
95
75
|
colors.push(c);
|
|
96
76
|
}
|
|
97
|
-
colors = colors.filter(
|
|
77
|
+
colors = colors.filter((c) => tools_1.Tools.isDefined(c));
|
|
98
78
|
if (colors.length === 0) {
|
|
99
79
|
colors = [itemAttributes_1.BASE_GREY];
|
|
100
80
|
}
|
|
101
|
-
|
|
81
|
+
const finalColor = colors.length === 1 ? colors[0] : colors;
|
|
102
82
|
this.colorsCache.set(hash, finalColor);
|
|
103
83
|
return finalColor;
|
|
104
|
-
}
|
|
84
|
+
}
|
|
105
85
|
/**
|
|
106
86
|
* Generate icon for a given node
|
|
107
87
|
*/
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
88
|
+
icon(itemData) {
|
|
89
|
+
const rawColors = this.color(itemData);
|
|
90
|
+
const color = Array.isArray(rawColors) ? rawColors[0] : rawColors;
|
|
91
|
+
let result = {};
|
|
92
|
+
const rules = [...(this._rulesMap.image || []), ...(this._rulesMap.icon || [])];
|
|
113
93
|
if (!tools_1.Tools.isDefined(itemData)) {
|
|
114
94
|
return {
|
|
115
95
|
icon: {},
|
|
116
96
|
image: {}
|
|
117
97
|
};
|
|
118
98
|
}
|
|
119
|
-
for (
|
|
99
|
+
for (let i = 0; i < rules.length; ++i) {
|
|
120
100
|
if (rules[i].canApplyTo(itemData)) {
|
|
121
101
|
if ('icon' in rules[i].style) {
|
|
122
102
|
result = {
|
|
@@ -146,35 +126,35 @@ var NodeAttributes = /** @class */ (function (_super) {
|
|
|
146
126
|
}
|
|
147
127
|
}
|
|
148
128
|
return result;
|
|
149
|
-
}
|
|
129
|
+
}
|
|
150
130
|
/**
|
|
151
131
|
* Generate shape for a given node
|
|
152
132
|
*/
|
|
153
|
-
|
|
154
|
-
|
|
133
|
+
shape(itemData) {
|
|
134
|
+
let result = undefined;
|
|
155
135
|
if (this._rulesMap.shape !== undefined) {
|
|
156
|
-
NodeAttributes.matchStyle(this._rulesMap.shape, itemData,
|
|
136
|
+
NodeAttributes.matchStyle(this._rulesMap.shape, itemData, (styleRule) => {
|
|
157
137
|
result = styleRule.style.shape;
|
|
158
138
|
});
|
|
159
139
|
}
|
|
160
140
|
return result;
|
|
161
|
-
}
|
|
141
|
+
}
|
|
162
142
|
/**
|
|
163
143
|
* Generate size for a given node
|
|
164
144
|
*/
|
|
165
|
-
|
|
166
|
-
|
|
145
|
+
size(itemData) {
|
|
146
|
+
let result = undefined;
|
|
167
147
|
if (this._rulesMap.size !== undefined) {
|
|
168
|
-
NodeAttributes.matchStyle(this._rulesMap.size, itemData,
|
|
169
|
-
|
|
148
|
+
NodeAttributes.matchStyle(this._rulesMap.size, itemData, (styleRule) => {
|
|
149
|
+
const sizeStyle = styleRule.style.size;
|
|
170
150
|
if (sizeStyle.type === 'autoRange') {
|
|
171
151
|
if (sizeStyle.input !== undefined &&
|
|
172
152
|
sizeStyle.max !== undefined &&
|
|
173
153
|
sizeStyle.min !== undefined) {
|
|
174
|
-
|
|
175
|
-
|
|
154
|
+
const propertyName = sizeStyle.input[1];
|
|
155
|
+
const propertyValue = tools_1.Tools.parseNumber(itemData.properties[propertyName]);
|
|
176
156
|
//to update with the correct enum type
|
|
177
|
-
|
|
157
|
+
const isLog = sizeStyle.scale && sizeStyle.scale === 'logarithmic';
|
|
178
158
|
result = NodeAttributes.getAutomaticRangeSize(propertyValue, styleRule, isLog);
|
|
179
159
|
}
|
|
180
160
|
}
|
|
@@ -184,29 +164,28 @@ var NodeAttributes = /** @class */ (function (_super) {
|
|
|
184
164
|
});
|
|
185
165
|
}
|
|
186
166
|
return result;
|
|
187
|
-
}
|
|
167
|
+
}
|
|
188
168
|
/**
|
|
189
169
|
* return the corresponding size to the value
|
|
190
170
|
* @param value
|
|
191
171
|
* @param rule
|
|
192
172
|
* @param isLog
|
|
193
173
|
*/
|
|
194
|
-
|
|
195
|
-
if (isLog === void 0) { isLog = false; }
|
|
174
|
+
static getAutomaticRangeSize(value, rule, isLog = false) {
|
|
196
175
|
return isLog
|
|
197
176
|
? this.getAutomaticRangeStyleLog(value, rule.style.size, NodeSizeExtrema.MIN, NodeSizeExtrema.MAX)
|
|
198
177
|
: this.getAutomaticRangeStyleLinear(value, rule.style.size, NodeSizeExtrema.MIN, NodeSizeExtrema.MAX);
|
|
199
|
-
}
|
|
178
|
+
}
|
|
200
179
|
/**
|
|
201
180
|
* Return an object containing all node attributes needed by Ogma to style a node
|
|
202
181
|
*/
|
|
203
|
-
|
|
182
|
+
all(itemData) {
|
|
204
183
|
if (!tools_1.Tools.isDefined(itemData)) {
|
|
205
184
|
return {
|
|
206
185
|
color: itemAttributes_1.BASE_GREY
|
|
207
186
|
};
|
|
208
187
|
}
|
|
209
|
-
|
|
188
|
+
const generatedIcon = this.icon(itemData);
|
|
210
189
|
return {
|
|
211
190
|
radius: this.size(itemData),
|
|
212
191
|
color: this.color(itemData),
|
|
@@ -214,8 +193,7 @@ var NodeAttributes = /** @class */ (function (_super) {
|
|
|
214
193
|
icon: generatedIcon.icon,
|
|
215
194
|
image: generatedIcon.image
|
|
216
195
|
};
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
}(itemAttributes_1.ItemAttributes));
|
|
196
|
+
}
|
|
197
|
+
}
|
|
220
198
|
exports.NodeAttributes = NodeAttributes;
|
|
221
199
|
//# sourceMappingURL=nodeAttributes.js.map
|