@linkurious/ogma-linkurious-parser 3.1.11 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/captions/captions.js +39 -50
- package/dist/captions/captions.js.map +1 -1
- package/dist/filters/filters.js +54 -76
- package/dist/filters/filters.js.map +1 -1
- package/dist/ogma/features/OgmaStore.js +15 -30
- package/dist/ogma/features/OgmaStore.js.map +1 -1
- package/dist/ogma/features/captions.js +42 -87
- package/dist/ogma/features/captions.js.map +1 -1
- package/dist/ogma/features/reactive.js +57 -75
- package/dist/ogma/features/reactive.js.map +1 -1
- package/dist/ogma/features/selectors.js +15 -15
- package/dist/ogma/features/selectors.js.map +1 -1
- package/dist/ogma/features/styles.js +114 -137
- package/dist/ogma/features/styles.js.map +1 -1
- package/dist/ogma/features/transformations.js +46 -94
- package/dist/ogma/features/transformations.js.map +1 -1
- package/dist/ogma/index.js +138 -221
- package/dist/ogma/index.js.map +1 -1
- package/dist/styles/edgeAttributes.js +30 -46
- package/dist/styles/edgeAttributes.js.map +1 -1
- package/dist/styles/itemAttributes.js +31 -41
- package/dist/styles/itemAttributes.js.map +1 -1
- package/dist/styles/nodeAttributes.js +48 -71
- package/dist/styles/nodeAttributes.js.map +1 -1
- package/dist/styles/styleRule.js +56 -68
- package/dist/styles/styleRule.js.map +1 -1
- package/dist/styles/styleRules.js +149 -192
- package/dist/styles/styleRules.js.map +1 -1
- package/dist/tools/ogmaTool.js +27 -30
- package/dist/tools/ogmaTool.js.map +1 -1
- package/dist/tools/tools.js +87 -91
- package/dist/tools/tools.js.map +1 -1
- package/package.json +5 -5
|
@@ -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
|
+
const rest_client_1 = require("@linkurious/rest-client");
|
|
4
|
+
const tools_1 = require("../tools/tools");
|
|
5
|
+
const itemAttributes_1 = require("./itemAttributes");
|
|
19
6
|
var EdgeWidthExtrema;
|
|
20
7
|
(function (EdgeWidthExtrema) {
|
|
21
8
|
EdgeWidthExtrema[EdgeWidthExtrema["MIN"] = 50] = "MIN";
|
|
22
9
|
EdgeWidthExtrema[EdgeWidthExtrema["MAX"] = 200] = "MAX";
|
|
23
10
|
})(EdgeWidthExtrema = exports.EdgeWidthExtrema || (exports.EdgeWidthExtrema = {}));
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return _super.call(this, rulesMap) || this;
|
|
11
|
+
class EdgeAttributes extends itemAttributes_1.ItemAttributes {
|
|
12
|
+
constructor(rulesMap) {
|
|
13
|
+
super(rulesMap);
|
|
28
14
|
}
|
|
29
15
|
/**
|
|
30
16
|
* Return rule that can be applied to the data
|
|
31
17
|
*/
|
|
32
|
-
|
|
18
|
+
static matchStyle(styleRules, data) {
|
|
33
19
|
if (data === undefined) {
|
|
34
20
|
return;
|
|
35
21
|
}
|
|
36
|
-
for (
|
|
22
|
+
for (let i = 0; i < styleRules.length; ++i) {
|
|
37
23
|
if (styleRules[i].canApplyTo(data)) {
|
|
38
24
|
return styleRules[i];
|
|
39
25
|
}
|
|
40
26
|
}
|
|
41
|
-
}
|
|
27
|
+
}
|
|
42
28
|
/**
|
|
43
29
|
* Generate color for a given edge (call only if _rulesMap.color exists)
|
|
44
30
|
*/
|
|
45
|
-
|
|
31
|
+
color(data) {
|
|
46
32
|
if (!tools_1.Tools.isDefined(data)) {
|
|
47
33
|
return itemAttributes_1.BASE_GREY;
|
|
48
34
|
}
|
|
49
|
-
|
|
50
|
-
for (
|
|
51
|
-
|
|
35
|
+
let color;
|
|
36
|
+
for (let j = 0; j < this._rulesMap.color.length; ++j) {
|
|
37
|
+
const rule = this._rulesMap.color[j];
|
|
52
38
|
if (rule.canApplyTo(data)) {
|
|
53
39
|
if (typeof rule.style.color === 'string') {
|
|
54
40
|
color = rule.style.color;
|
|
55
41
|
}
|
|
56
42
|
else if (typeof rule.style.color === 'object') {
|
|
57
|
-
|
|
58
|
-
color = itemAttributes_1.ItemAttributes.autoColor(
|
|
43
|
+
const propValue = tools_1.Tools.getIn(data, rule.style.color.input);
|
|
44
|
+
color = itemAttributes_1.ItemAttributes.autoColor(`${propValue}`, rule.style.ignoreCase);
|
|
59
45
|
}
|
|
60
46
|
break;
|
|
61
47
|
}
|
|
62
48
|
}
|
|
63
49
|
return tools_1.Tools.isDefined(color) ? color : itemAttributes_1.BASE_GREY;
|
|
64
|
-
}
|
|
50
|
+
}
|
|
65
51
|
/**
|
|
66
52
|
* Generate shape for a given node
|
|
67
53
|
*/
|
|
68
|
-
|
|
54
|
+
shape(data) {
|
|
69
55
|
var _a;
|
|
70
56
|
if (this._rulesMap.shape !== undefined) {
|
|
71
57
|
return (_a = EdgeAttributes.matchStyle(this._rulesMap.shape, data)) === null || _a === void 0 ? void 0 : _a.style.shape;
|
|
72
58
|
}
|
|
73
|
-
}
|
|
59
|
+
}
|
|
74
60
|
/**
|
|
75
61
|
* Generate size for a given node
|
|
76
62
|
*/
|
|
77
|
-
|
|
63
|
+
width(data) {
|
|
78
64
|
var _a;
|
|
79
65
|
if (this._rulesMap.width !== undefined) {
|
|
80
|
-
|
|
81
|
-
|
|
66
|
+
const styleRule = EdgeAttributes.matchStyle(this._rulesMap.width, data);
|
|
67
|
+
const widthStyle = (_a = styleRule) === null || _a === void 0 ? void 0 : _a.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,EAAE,EAAE,CAAC,EAAE;YAC1C,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;gBAClC,OAAO,UAAU,CAAC,CAAC,CAAC,CAAC;aACtB;SACF;IACH,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,IAAgB;QAC3B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R,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,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
|
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
|
+
const sha1_1 = __importDefault(require("sha1"));
|
|
7
|
+
const tools_1 = require("../tools/tools");
|
|
15
8
|
exports.BASE_GREY = '#7f7f7f';
|
|
16
9
|
exports.PALETTE = [
|
|
17
10
|
'#9467bd',
|
|
@@ -33,8 +26,8 @@ exports.PALETTE = [
|
|
|
33
26
|
'#ffbb78',
|
|
34
27
|
'#c49c94'
|
|
35
28
|
];
|
|
36
|
-
|
|
37
|
-
|
|
29
|
+
class ItemAttributes {
|
|
30
|
+
constructor(rulesMap) {
|
|
38
31
|
this.colorsCache = new Map();
|
|
39
32
|
this._rulesMap = {};
|
|
40
33
|
this.refresh(rulesMap);
|
|
@@ -42,41 +35,41 @@ var ItemAttributes = /** @class */ (function () {
|
|
|
42
35
|
/**
|
|
43
36
|
* Refresh the rules
|
|
44
37
|
*/
|
|
45
|
-
|
|
38
|
+
refresh(rulesMap) {
|
|
46
39
|
if (rulesMap.color !== undefined) {
|
|
47
40
|
this.colorsCache = new Map();
|
|
48
41
|
}
|
|
49
42
|
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 ?
|
|
43
|
+
color: rulesMap.color ? [...rulesMap.color].reverse() : this._rulesMap.color,
|
|
44
|
+
icon: rulesMap.icon ? [...rulesMap.icon].reverse() : this._rulesMap.icon,
|
|
45
|
+
image: rulesMap.image ? [...rulesMap.image].reverse() : this._rulesMap.image,
|
|
46
|
+
shape: rulesMap.shape ? [...rulesMap.shape].reverse() : this._rulesMap.shape,
|
|
47
|
+
size: rulesMap.size ? [...rulesMap.size].reverse() : this._rulesMap.size,
|
|
48
|
+
width: rulesMap.width ? [...rulesMap.width].reverse() : this._rulesMap.width
|
|
56
49
|
};
|
|
57
|
-
}
|
|
50
|
+
}
|
|
58
51
|
/**
|
|
59
52
|
* Return the color for a node when style color is auto
|
|
60
53
|
*/
|
|
61
|
-
|
|
54
|
+
static autoColor(value, ignoreCase) {
|
|
62
55
|
if (!tools_1.Tools.isDefined(value)) {
|
|
63
56
|
return exports.BASE_GREY;
|
|
64
57
|
}
|
|
65
58
|
return exports.PALETTE[ItemAttributes.getRandomUniqueColorPaletteIndex(value, exports.PALETTE.length, ignoreCase)];
|
|
66
|
-
}
|
|
59
|
+
}
|
|
67
60
|
/**
|
|
68
61
|
* Return a number from 0 to number of occurrence in a palette based on a property
|
|
69
62
|
*/
|
|
70
|
-
|
|
63
|
+
static getRandomUniqueColorPaletteIndex(input, modulo, ignoreCase) {
|
|
71
64
|
if (ignoreCase) {
|
|
72
65
|
input = input.toLowerCase();
|
|
73
66
|
}
|
|
74
67
|
return +('0x' + sha1_1.default(input).substr(-4)) % modulo;
|
|
75
|
-
}
|
|
68
|
+
}
|
|
76
69
|
/**
|
|
77
70
|
* Get color of a type
|
|
78
71
|
*/
|
|
79
|
-
|
|
72
|
+
static getTypeColor(rule, type) {
|
|
80
73
|
if (typeof rule.style.color === 'object' && rule.style.color.input[0] !== 'properties') {
|
|
81
74
|
return ItemAttributes.autoColor(type, rule.style.color.ignoreCase);
|
|
82
75
|
}
|
|
@@ -84,7 +77,7 @@ var ItemAttributes = /** @class */ (function () {
|
|
|
84
77
|
return rule.style.color;
|
|
85
78
|
}
|
|
86
79
|
return null;
|
|
87
|
-
}
|
|
80
|
+
}
|
|
88
81
|
/**
|
|
89
82
|
* return the corresponding size to the value with a linear function
|
|
90
83
|
* @param value
|
|
@@ -92,18 +85,17 @@ var ItemAttributes = /** @class */ (function () {
|
|
|
92
85
|
* @param higher
|
|
93
86
|
* @param extrema
|
|
94
87
|
*/
|
|
95
|
-
|
|
96
|
-
var max = _a.max, min = _a.min;
|
|
88
|
+
static getAutomaticRangeStyleLinear(value, { max, min }, lower, higher) {
|
|
97
89
|
// apply default style when min equal max
|
|
98
90
|
if (max === min || isNaN(value)) {
|
|
99
91
|
return '100%';
|
|
100
92
|
}
|
|
101
93
|
// calculate the linear function f(x) = ax + b
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
return size
|
|
106
|
-
}
|
|
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
|
+
}
|
|
107
99
|
/**
|
|
108
100
|
* return the corresponding size to the value with a logarithmic function
|
|
109
101
|
* @param value
|
|
@@ -111,8 +103,7 @@ var ItemAttributes = /** @class */ (function () {
|
|
|
111
103
|
* @param higher
|
|
112
104
|
* @param extrema
|
|
113
105
|
*/
|
|
114
|
-
|
|
115
|
-
var max = _a.max, min = _a.min;
|
|
106
|
+
static getAutomaticRangeStyleLog(value, { max, min }, lower, higher) {
|
|
116
107
|
// apply default style when min equal max
|
|
117
108
|
if (max === min || isNaN(value)) {
|
|
118
109
|
return '100%';
|
|
@@ -124,12 +115,11 @@ var ItemAttributes = /** @class */ (function () {
|
|
|
124
115
|
min += Math.abs(min) + 1;
|
|
125
116
|
}
|
|
126
117
|
// calculate the logarithmic function f(x) = Math.floor(a*log(x) + b)
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
return size
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
}());
|
|
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}%`;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
134
124
|
exports.ItemAttributes = ItemAttributes;
|
|
135
125
|
//# 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;AAEF,MAAa,cAAc;IAWzB,YAAY,QAOX;QAjBS,gBAAW,GAAsC,IAAI,GAAG,EAAE,CAAC;QAC3D,cAAS,GAOf,EAAE,CAAC;QAUL,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IACzB,CAAC;IAED;;OAEG;IACI,OAAO,CAAC,QAOd;QACC,IAAI,QAAQ,CAAC,KAAK,KAAK,SAAS,EAAE;YAChC,IAAI,CAAC,WAAW,GAAG,IAAI,GAAG,EAAE,CAAC;SAC9B;QACD,IAAI,CAAC,SA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C,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,55 @@
|
|
|
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
|
+
const sha1_1 = __importDefault(require("sha1"));
|
|
7
|
+
const tools_1 = require("../tools/tools");
|
|
8
|
+
const __1 = require("..");
|
|
9
|
+
const itemAttributes_1 = require("./itemAttributes");
|
|
30
10
|
var NodeSizeExtrema;
|
|
31
11
|
(function (NodeSizeExtrema) {
|
|
32
12
|
NodeSizeExtrema[NodeSizeExtrema["MIN"] = 50] = "MIN";
|
|
33
13
|
NodeSizeExtrema[NodeSizeExtrema["MAX"] = 500] = "MAX";
|
|
34
14
|
})(NodeSizeExtrema = exports.NodeSizeExtrema || (exports.NodeSizeExtrema = {}));
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
return _super.call(this, rulesMap) || this;
|
|
15
|
+
class NodeAttributes extends itemAttributes_1.ItemAttributes {
|
|
16
|
+
constructor(rulesMap) {
|
|
17
|
+
super(rulesMap);
|
|
39
18
|
}
|
|
40
19
|
/**
|
|
41
20
|
* Run the callback if an item match with a style in the array of rules
|
|
42
21
|
*/
|
|
43
|
-
|
|
22
|
+
static matchStyle(styleRules, itemData, callback) {
|
|
44
23
|
if (!tools_1.Tools.isDefined(itemData)) {
|
|
45
24
|
return;
|
|
46
25
|
}
|
|
47
26
|
if (!tools_1.Tools.isDefined(styleRules)) {
|
|
48
27
|
return;
|
|
49
28
|
}
|
|
50
|
-
for (
|
|
29
|
+
for (let i = 0; i < styleRules.length; ++i) {
|
|
51
30
|
if (styleRules[i].canApplyTo(itemData)) {
|
|
52
31
|
callback(styleRules[i]);
|
|
53
32
|
break;
|
|
54
33
|
}
|
|
55
34
|
}
|
|
56
|
-
}
|
|
35
|
+
}
|
|
57
36
|
/**
|
|
58
37
|
* Generate color for a given node (call only if _rulesMap.color is defined
|
|
59
38
|
*/
|
|
60
|
-
|
|
39
|
+
color(itemData) {
|
|
61
40
|
if (!tools_1.Tools.isDefined(itemData)) {
|
|
62
41
|
return [itemAttributes_1.BASE_GREY];
|
|
63
42
|
}
|
|
64
|
-
|
|
65
|
-
|
|
43
|
+
const hash = sha1_1.default(JSON.stringify(itemData));
|
|
44
|
+
const cachedColor = this.colorsCache.get(hash);
|
|
66
45
|
if (cachedColor !== undefined) {
|
|
67
46
|
return cachedColor;
|
|
68
47
|
}
|
|
69
|
-
|
|
70
|
-
for (
|
|
71
|
-
|
|
72
|
-
for (
|
|
73
|
-
|
|
48
|
+
let colors = [];
|
|
49
|
+
for (let i = 0; i < itemData.categories.length; ++i) {
|
|
50
|
+
let c = null;
|
|
51
|
+
for (let j = 0; j < this._rulesMap.color.length; ++j) {
|
|
52
|
+
const rule = this._rulesMap.color[j];
|
|
74
53
|
if (rule.itemType !== undefined &&
|
|
75
54
|
rule.itemType !== null &&
|
|
76
55
|
rule.itemType !== itemData.categories[i]) {
|
|
@@ -78,12 +57,12 @@ var NodeAttributes = /** @class */ (function (_super) {
|
|
|
78
57
|
}
|
|
79
58
|
if (rule.canApplyTo(itemData)) {
|
|
80
59
|
if (typeof rule.style.color === 'object') {
|
|
81
|
-
|
|
60
|
+
const propValue = tools_1.Tools.getIn(itemData, rule.style.color.input);
|
|
82
61
|
if (Array.isArray(propValue)) {
|
|
83
62
|
c = itemAttributes_1.ItemAttributes.autoColor(itemData.categories[i], rule.style.ignoreCase);
|
|
84
63
|
}
|
|
85
64
|
else {
|
|
86
|
-
c = itemAttributes_1.ItemAttributes.autoColor(
|
|
65
|
+
c = itemAttributes_1.ItemAttributes.autoColor(`${propValue}`, rule.style.ignoreCase);
|
|
87
66
|
}
|
|
88
67
|
}
|
|
89
68
|
else {
|
|
@@ -94,29 +73,29 @@ var NodeAttributes = /** @class */ (function (_super) {
|
|
|
94
73
|
}
|
|
95
74
|
colors.push(c);
|
|
96
75
|
}
|
|
97
|
-
colors = colors.filter(
|
|
76
|
+
colors = colors.filter((c) => tools_1.Tools.isDefined(c));
|
|
98
77
|
if (colors.length === 0) {
|
|
99
78
|
colors = [itemAttributes_1.BASE_GREY];
|
|
100
79
|
}
|
|
101
|
-
|
|
80
|
+
const finalColor = colors.length === 1 ? colors[0] : colors;
|
|
102
81
|
this.colorsCache.set(hash, finalColor);
|
|
103
82
|
return finalColor;
|
|
104
|
-
}
|
|
83
|
+
}
|
|
105
84
|
/**
|
|
106
85
|
* Generate icon for a given node
|
|
107
86
|
*/
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
87
|
+
icon(itemData) {
|
|
88
|
+
const rawColors = this.color(itemData);
|
|
89
|
+
const color = Array.isArray(rawColors) ? rawColors[0] : rawColors;
|
|
90
|
+
let result = {};
|
|
91
|
+
const rules = [...(this._rulesMap.image || []), ...(this._rulesMap.icon || [])];
|
|
113
92
|
if (!tools_1.Tools.isDefined(itemData)) {
|
|
114
93
|
return {
|
|
115
94
|
icon: {},
|
|
116
95
|
image: {}
|
|
117
96
|
};
|
|
118
97
|
}
|
|
119
|
-
for (
|
|
98
|
+
for (let i = 0; i < rules.length; ++i) {
|
|
120
99
|
if (rules[i].canApplyTo(itemData)) {
|
|
121
100
|
if ('icon' in rules[i].style) {
|
|
122
101
|
result = {
|
|
@@ -146,35 +125,35 @@ var NodeAttributes = /** @class */ (function (_super) {
|
|
|
146
125
|
}
|
|
147
126
|
}
|
|
148
127
|
return result;
|
|
149
|
-
}
|
|
128
|
+
}
|
|
150
129
|
/**
|
|
151
130
|
* Generate shape for a given node
|
|
152
131
|
*/
|
|
153
|
-
|
|
154
|
-
|
|
132
|
+
shape(itemData) {
|
|
133
|
+
let result = undefined;
|
|
155
134
|
if (this._rulesMap.shape !== undefined) {
|
|
156
|
-
NodeAttributes.matchStyle(this._rulesMap.shape, itemData,
|
|
135
|
+
NodeAttributes.matchStyle(this._rulesMap.shape, itemData, (styleRule) => {
|
|
157
136
|
result = styleRule.style.shape;
|
|
158
137
|
});
|
|
159
138
|
}
|
|
160
139
|
return result;
|
|
161
|
-
}
|
|
140
|
+
}
|
|
162
141
|
/**
|
|
163
142
|
* Generate size for a given node
|
|
164
143
|
*/
|
|
165
|
-
|
|
166
|
-
|
|
144
|
+
size(itemData) {
|
|
145
|
+
let result = undefined;
|
|
167
146
|
if (this._rulesMap.size !== undefined) {
|
|
168
|
-
NodeAttributes.matchStyle(this._rulesMap.size, itemData,
|
|
169
|
-
|
|
147
|
+
NodeAttributes.matchStyle(this._rulesMap.size, itemData, (styleRule) => {
|
|
148
|
+
const sizeStyle = styleRule.style.size;
|
|
170
149
|
if (sizeStyle.type === 'autoRange') {
|
|
171
150
|
if (sizeStyle.input !== undefined &&
|
|
172
151
|
sizeStyle.max !== undefined &&
|
|
173
152
|
sizeStyle.min !== undefined) {
|
|
174
|
-
|
|
175
|
-
|
|
153
|
+
const propertyName = sizeStyle.input[1];
|
|
154
|
+
const propertyValue = tools_1.Tools.parseNumber(itemData.properties[propertyName]);
|
|
176
155
|
//to update with the correct enum type
|
|
177
|
-
|
|
156
|
+
const isLog = sizeStyle.scale && sizeStyle.scale === 'logarithmic';
|
|
178
157
|
result = NodeAttributes.getAutomaticRangeSize(propertyValue, styleRule, isLog);
|
|
179
158
|
}
|
|
180
159
|
}
|
|
@@ -184,29 +163,28 @@ var NodeAttributes = /** @class */ (function (_super) {
|
|
|
184
163
|
});
|
|
185
164
|
}
|
|
186
165
|
return result;
|
|
187
|
-
}
|
|
166
|
+
}
|
|
188
167
|
/**
|
|
189
168
|
* return the corresponding size to the value
|
|
190
169
|
* @param value
|
|
191
170
|
* @param rule
|
|
192
171
|
* @param isLog
|
|
193
172
|
*/
|
|
194
|
-
|
|
195
|
-
if (isLog === void 0) { isLog = false; }
|
|
173
|
+
static getAutomaticRangeSize(value, rule, isLog = false) {
|
|
196
174
|
return isLog
|
|
197
175
|
? this.getAutomaticRangeStyleLog(value, rule.style.size, NodeSizeExtrema.MIN, NodeSizeExtrema.MAX)
|
|
198
176
|
: this.getAutomaticRangeStyleLinear(value, rule.style.size, NodeSizeExtrema.MIN, NodeSizeExtrema.MAX);
|
|
199
|
-
}
|
|
177
|
+
}
|
|
200
178
|
/**
|
|
201
179
|
* Return an object containing all node attributes needed by Ogma to style a node
|
|
202
180
|
*/
|
|
203
|
-
|
|
181
|
+
all(itemData) {
|
|
204
182
|
if (!tools_1.Tools.isDefined(itemData)) {
|
|
205
183
|
return {
|
|
206
184
|
color: itemAttributes_1.BASE_GREY
|
|
207
185
|
};
|
|
208
186
|
}
|
|
209
|
-
|
|
187
|
+
const generatedIcon = this.icon(itemData);
|
|
210
188
|
return {
|
|
211
189
|
radius: this.size(itemData),
|
|
212
190
|
color: this.color(itemData),
|
|
@@ -214,8 +192,7 @@ var NodeAttributes = /** @class */ (function (_super) {
|
|
|
214
192
|
icon: generatedIcon.icon,
|
|
215
193
|
image: generatedIcon.image
|
|
216
194
|
};
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
}(itemAttributes_1.ItemAttributes));
|
|
195
|
+
}
|
|
196
|
+
}
|
|
220
197
|
exports.NodeAttributes = NodeAttributes;
|
|
221
198
|
//# sourceMappingURL=nodeAttributes.js.map
|