@linkurious/ogma-linkurious-parser 4.1.6 → 4.1.8
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/index.cjs +4 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +5 -5
- package/dist/index.mjs +4082 -0
- package/dist/index.mjs.map +1 -0
- package/dist/ogma/features/nodeGrouping.d.ts +15 -1
- package/dist/tools/ogmaTool.d.ts +3 -1
- package/package.json +23 -21
- package/dist/captions/captions.js +0 -115
- package/dist/captions/captions.js.map +0 -1
- package/dist/filters/filters.js +0 -167
- package/dist/filters/filters.js.map +0 -1
- package/dist/index.js +0 -56
- package/dist/index.js.map +0 -1
- package/dist/ogma/features/OgmaStore.js +0 -37
- package/dist/ogma/features/OgmaStore.js.map +0 -1
- package/dist/ogma/features/captions.js +0 -117
- package/dist/ogma/features/captions.js.map +0 -1
- package/dist/ogma/features/nodeGrouping.js +0 -283
- package/dist/ogma/features/nodeGrouping.js.map +0 -1
- package/dist/ogma/features/reactive.js +0 -132
- package/dist/ogma/features/reactive.js.map +0 -1
- package/dist/ogma/features/selectors.js +0 -97
- package/dist/ogma/features/selectors.js.map +0 -1
- package/dist/ogma/features/styles.js +0 -689
- package/dist/ogma/features/styles.js.map +0 -1
- package/dist/ogma/features/transformations.js +0 -86
- package/dist/ogma/features/transformations.js.map +0 -1
- package/dist/ogma/index.js +0 -326
- package/dist/ogma/index.js.map +0 -1
- package/dist/styles/edgeAttributes.js +0 -115
- package/dist/styles/edgeAttributes.js.map +0 -1
- package/dist/styles/itemAttributes.js +0 -133
- package/dist/styles/itemAttributes.js.map +0 -1
- package/dist/styles/nodeAttributes.js +0 -228
- package/dist/styles/nodeAttributes.js.map +0 -1
- package/dist/styles/styleRule.js +0 -194
- package/dist/styles/styleRule.js.map +0 -1
- package/dist/styles/styleRules.js +0 -292
- package/dist/styles/styleRules.js.map +0 -1
- package/dist/tools/colorPalette.js +0 -145
- package/dist/tools/colorPalette.js.map +0 -1
- package/dist/tools/ogmaTool.js +0 -86
- package/dist/tools/ogmaTool.js.map +0 -1
- package/dist/tools/tools.js +0 -409
- package/dist/tools/tools.js.map +0 -1
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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");
|
|
7
|
-
var EdgeWidthExtrema;
|
|
8
|
-
(function (EdgeWidthExtrema) {
|
|
9
|
-
EdgeWidthExtrema[EdgeWidthExtrema["MIN"] = 50] = "MIN";
|
|
10
|
-
EdgeWidthExtrema[EdgeWidthExtrema["MAX"] = 200] = "MAX";
|
|
11
|
-
})(EdgeWidthExtrema || (exports.EdgeWidthExtrema = EdgeWidthExtrema = {}));
|
|
12
|
-
class EdgeAttributes extends itemAttributes_1.ItemAttributes {
|
|
13
|
-
constructor(rulesMap) {
|
|
14
|
-
super(rulesMap);
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Return rule that can be applied to the data
|
|
18
|
-
*/
|
|
19
|
-
static matchStyle(styleRules, data) {
|
|
20
|
-
if (data === undefined) {
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
for (let i = 0; i < styleRules.length; ++i) {
|
|
24
|
-
if (styleRules[i].canApplyTo(data)) {
|
|
25
|
-
return styleRules[i];
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Generate color for a given edge (call only if _rulesMap.color exists)
|
|
31
|
-
*/
|
|
32
|
-
color(data) {
|
|
33
|
-
if (!tools_1.Tools.isDefined(data)) {
|
|
34
|
-
return itemAttributes_1.BASE_GREY;
|
|
35
|
-
}
|
|
36
|
-
let color;
|
|
37
|
-
for (let j = 0; j < this._rulesMap.color.length; ++j) {
|
|
38
|
-
const rule = this._rulesMap.color[j];
|
|
39
|
-
if (rule.canApplyTo(data)) {
|
|
40
|
-
if (typeof rule.style.color === 'string') {
|
|
41
|
-
color = rule.style.color;
|
|
42
|
-
}
|
|
43
|
-
else if (typeof rule.style.color === 'object') {
|
|
44
|
-
const propValue = tools_1.Tools.getIn(data, rule.style.color.input);
|
|
45
|
-
color = itemAttributes_1.ItemAttributes.autoColor(`${propValue}`, rule.style.color.ignoreCase);
|
|
46
|
-
}
|
|
47
|
-
break;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return tools_1.Tools.isDefined(color) ? color : itemAttributes_1.BASE_GREY;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Generate shape for a given node
|
|
54
|
-
*/
|
|
55
|
-
shape(data) {
|
|
56
|
-
var _a;
|
|
57
|
-
if (this._rulesMap.shape !== undefined) {
|
|
58
|
-
return (_a = EdgeAttributes.matchStyle(this._rulesMap.shape, data)) === null || _a === void 0 ? void 0 : _a.style.shape;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Generate size for a given node
|
|
63
|
-
*/
|
|
64
|
-
width(data) {
|
|
65
|
-
if (this._rulesMap.width !== undefined) {
|
|
66
|
-
const styleRule = EdgeAttributes.matchStyle(this._rulesMap.width, data);
|
|
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;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* return the corresponding width to the value
|
|
87
|
-
* @param value
|
|
88
|
-
* @param rule
|
|
89
|
-
* @param isLog
|
|
90
|
-
*/
|
|
91
|
-
static getAutomaticRangeWidth(value, rule, isLog = false) {
|
|
92
|
-
return isLog
|
|
93
|
-
? this.getAutomaticRangeStyleLog(value, rule.style.width, EdgeWidthExtrema.MIN, EdgeWidthExtrema.MAX)
|
|
94
|
-
: this.getAutomaticRangeStyleLinear(value, rule.style.width, EdgeWidthExtrema.MIN, EdgeWidthExtrema.MAX);
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Return an object containing all node attributes needed by Ogma to style a node
|
|
98
|
-
*/
|
|
99
|
-
all(data) {
|
|
100
|
-
if (!tools_1.Tools.isDefined(data)) {
|
|
101
|
-
return {
|
|
102
|
-
color: itemAttributes_1.BASE_GREY,
|
|
103
|
-
shape: rest_client_1.OgmaEdgeShape.ARROW,
|
|
104
|
-
width: '100%'
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
return {
|
|
108
|
-
color: this.color(data),
|
|
109
|
-
shape: this.shape(data),
|
|
110
|
-
width: this.width(data)
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
exports.EdgeAttributes = EdgeAttributes;
|
|
115
|
-
//# sourceMappingURL=edgeAttributes.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"edgeAttributes.js","sourceRoot":"","sources":["../../src/styles/edgeAttributes.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;AAEb,yDAMiC;AAEjC,0CAAqC;AAGrC,qDAA2D;AAE3D,IA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AI,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,133 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.ItemAttributes = exports.PALETTE = exports.BASE_GREY = void 0;
|
|
7
|
-
const sha1_1 = __importDefault(require("sha1"));
|
|
8
|
-
const tools_1 = require("../tools/tools");
|
|
9
|
-
exports.BASE_GREY = '#7f7f7f';
|
|
10
|
-
exports.PALETTE = [
|
|
11
|
-
'#9467bd',
|
|
12
|
-
'#e377c2',
|
|
13
|
-
'#1f77b4',
|
|
14
|
-
'#17becf',
|
|
15
|
-
'#2ca02c',
|
|
16
|
-
'#bcbd22',
|
|
17
|
-
'#d62728',
|
|
18
|
-
'#ff7f0e',
|
|
19
|
-
'#8c564b',
|
|
20
|
-
'#c5b0d5',
|
|
21
|
-
'#f7b6d2',
|
|
22
|
-
'#aec7e8',
|
|
23
|
-
'#9edae5',
|
|
24
|
-
'#98df8a',
|
|
25
|
-
'#dbdb8d',
|
|
26
|
-
'#ff9896',
|
|
27
|
-
'#ffbb78',
|
|
28
|
-
'#c49c94'
|
|
29
|
-
];
|
|
30
|
-
class ItemAttributes {
|
|
31
|
-
constructor(rulesMap) {
|
|
32
|
-
this.colorsCache = new Map();
|
|
33
|
-
this._rulesMap = {};
|
|
34
|
-
this.refresh(rulesMap);
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Refresh the rules
|
|
38
|
-
*/
|
|
39
|
-
refresh(rulesMap) {
|
|
40
|
-
if (rulesMap.color !== undefined) {
|
|
41
|
-
this.colorsCache = new Map();
|
|
42
|
-
}
|
|
43
|
-
this._rulesMap = {
|
|
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
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Return the color for a node when style color is auto
|
|
54
|
-
*/
|
|
55
|
-
static autoColor(value, ignoreCase) {
|
|
56
|
-
if (!tools_1.Tools.isDefined(value)) {
|
|
57
|
-
return exports.BASE_GREY;
|
|
58
|
-
}
|
|
59
|
-
return exports.PALETTE[ItemAttributes.getRandomUniqueColorPaletteIndex(value, exports.PALETTE.length, ignoreCase)];
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Return a number from 0 to number of occurrence in a palette based on a property
|
|
63
|
-
*/
|
|
64
|
-
static getRandomUniqueColorPaletteIndex(input, modulo, ignoreCase) {
|
|
65
|
-
if (ignoreCase) {
|
|
66
|
-
input = input.toLowerCase();
|
|
67
|
-
}
|
|
68
|
-
return +('0x' + (0, sha1_1.default)(input).substr(-4)) % modulo;
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Get color of a type
|
|
72
|
-
*/
|
|
73
|
-
static getTypeColor(rule, type) {
|
|
74
|
-
if (typeof rule.style.color === 'object' && rule.style.color.input[0] !== 'properties') {
|
|
75
|
-
return ItemAttributes.autoColor(type, rule.style.color.ignoreCase);
|
|
76
|
-
}
|
|
77
|
-
if (!tools_1.Tools.isDefined(rule.input) && typeof rule.style.color !== 'object') {
|
|
78
|
-
return rule.style.color;
|
|
79
|
-
}
|
|
80
|
-
return null;
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* return the corresponding size to the value with a linear function
|
|
84
|
-
* @param value
|
|
85
|
-
* @param lower
|
|
86
|
-
* @param higher
|
|
87
|
-
* @param extrema
|
|
88
|
-
*/
|
|
89
|
-
static getAutomaticRangeStyleLinear(value, { max, min }, lower, higher) {
|
|
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}%`;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* return the corresponding size to the value with a logarithmic function
|
|
104
|
-
* @param value
|
|
105
|
-
* @param lower
|
|
106
|
-
* @param higher
|
|
107
|
-
* @param extrema
|
|
108
|
-
*/
|
|
109
|
-
static getAutomaticRangeStyleLog(value, { max, min }, lower, higher) {
|
|
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}%`;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
isAutoRange(value) {
|
|
129
|
-
return typeof value === 'object' && (value === null || value === void 0 ? void 0 : value.type) === 'autoRange';
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
exports.ItemAttributes = ItemAttributes;
|
|
133
|
-
//# sourceMappingURL=itemAttributes.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"itemAttributes.js","sourceRoot":"","sources":["../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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 | undefined, 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,228 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.NodeAttributes = exports.NodeSizeExtrema = void 0;
|
|
7
|
-
const rest_client_1 = require("@linkurious/rest-client");
|
|
8
|
-
const sha1_1 = __importDefault(require("sha1"));
|
|
9
|
-
const tools_1 = require("../tools/tools");
|
|
10
|
-
const __1 = require("..");
|
|
11
|
-
const itemAttributes_1 = require("./itemAttributes");
|
|
12
|
-
var NodeSizeExtrema;
|
|
13
|
-
(function (NodeSizeExtrema) {
|
|
14
|
-
NodeSizeExtrema[NodeSizeExtrema["MIN"] = 50] = "MIN";
|
|
15
|
-
NodeSizeExtrema[NodeSizeExtrema["MAX"] = 500] = "MAX";
|
|
16
|
-
})(NodeSizeExtrema || (exports.NodeSizeExtrema = NodeSizeExtrema = {}));
|
|
17
|
-
class NodeAttributes extends itemAttributes_1.ItemAttributes {
|
|
18
|
-
constructor(rulesMap) {
|
|
19
|
-
super(rulesMap);
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Run the callback if an item match with a style in the array of rules
|
|
23
|
-
*/
|
|
24
|
-
static matchStyle(styleRules, itemData, callback) {
|
|
25
|
-
if (!tools_1.Tools.isDefined(itemData)) {
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
if (!tools_1.Tools.isDefined(styleRules)) {
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
for (let i = 0; i < styleRules.length; ++i) {
|
|
32
|
-
if (styleRules[i].canApplyTo(itemData)) {
|
|
33
|
-
callback(styleRules[i]);
|
|
34
|
-
break;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Generate color for a given node (call only if _rulesMap.color is defined
|
|
40
|
-
*/
|
|
41
|
-
color(itemData) {
|
|
42
|
-
if (!tools_1.Tools.isDefined(itemData)) {
|
|
43
|
-
return [itemAttributes_1.BASE_GREY];
|
|
44
|
-
}
|
|
45
|
-
const hash = (0, sha1_1.default)(JSON.stringify(itemData));
|
|
46
|
-
const cachedColor = this.colorsCache.get(hash);
|
|
47
|
-
if (cachedColor !== undefined) {
|
|
48
|
-
return cachedColor;
|
|
49
|
-
}
|
|
50
|
-
let colors = [];
|
|
51
|
-
for (let i = 0; i < itemData.categories.length; ++i) {
|
|
52
|
-
let color = null;
|
|
53
|
-
for (let j = 0; j < this._rulesMap.color.length; ++j) {
|
|
54
|
-
const rule = this._rulesMap.color[j];
|
|
55
|
-
if (rule.itemType !== undefined &&
|
|
56
|
-
rule.itemType !== null &&
|
|
57
|
-
rule.itemType !== itemData.categories[i]) {
|
|
58
|
-
continue;
|
|
59
|
-
}
|
|
60
|
-
if (rule.canApplyTo(itemData)) {
|
|
61
|
-
if (typeof rule.style.color === 'object') {
|
|
62
|
-
const propValue = tools_1.Tools.getIn(itemData, rule.style.color.input);
|
|
63
|
-
if (Array.isArray(propValue)) {
|
|
64
|
-
color = itemAttributes_1.ItemAttributes.autoColor(itemData.categories[i], rule.style.color.ignoreCase);
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
color = itemAttributes_1.ItemAttributes.autoColor(`${propValue}`, rule.style.color.ignoreCase);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
color = rule.style.color;
|
|
72
|
-
}
|
|
73
|
-
break;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
colors.push(color);
|
|
77
|
-
}
|
|
78
|
-
colors = colors.filter((c) => tools_1.Tools.isDefined(c));
|
|
79
|
-
if (colors.length === 0) {
|
|
80
|
-
colors = [itemAttributes_1.BASE_GREY];
|
|
81
|
-
}
|
|
82
|
-
const finalColor = colors.length === 1 ? colors[0] : colors;
|
|
83
|
-
this.colorsCache.set(hash, finalColor);
|
|
84
|
-
return finalColor;
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Generate icon for a given node
|
|
88
|
-
*/
|
|
89
|
-
icon(itemData) {
|
|
90
|
-
var _a, _b;
|
|
91
|
-
const rawColors = this.color(itemData);
|
|
92
|
-
const color = Array.isArray(rawColors) ? rawColors[0] : rawColors;
|
|
93
|
-
let result = {};
|
|
94
|
-
const rules = [...(this._rulesMap.image || []), ...(this._rulesMap.icon || [])];
|
|
95
|
-
if (!tools_1.Tools.isDefined(itemData)) {
|
|
96
|
-
return {
|
|
97
|
-
icon: {},
|
|
98
|
-
image: {}
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
for (let i = 0; i < rules.length; ++i) {
|
|
102
|
-
if (rules[i].canApplyTo(itemData)) {
|
|
103
|
-
const style = rules[i].style;
|
|
104
|
-
if ('icon' in style && typeof style.icon === 'object') {
|
|
105
|
-
result = {
|
|
106
|
-
icon: {
|
|
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,
|
|
109
|
-
scale: 0.5,
|
|
110
|
-
color: __1.OgmaTools.isBright(color) ? '#000000' : '#FFFFFF'
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
else if ('image' in style && typeof style.image === 'object') {
|
|
115
|
-
const imageUrlValue = NodeAttributes.getImageUrlFromStyleRule(style.image.url, itemData, this._baseUrl);
|
|
116
|
-
if (imageUrlValue !== undefined) {
|
|
117
|
-
result = {
|
|
118
|
-
image: {
|
|
119
|
-
url: imageUrlValue,
|
|
120
|
-
scale: style.image.scale,
|
|
121
|
-
fit: style.image.fit,
|
|
122
|
-
tile: style.image.tile,
|
|
123
|
-
minVisibleSize: 0
|
|
124
|
-
}
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
break;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
return result;
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* Generate shape for a given node
|
|
135
|
-
*/
|
|
136
|
-
shape(itemData) {
|
|
137
|
-
let result = undefined;
|
|
138
|
-
if (this._rulesMap.shape !== undefined) {
|
|
139
|
-
NodeAttributes.matchStyle(this._rulesMap.shape, itemData, (styleRule) => {
|
|
140
|
-
result = styleRule.style.shape;
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
return result;
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* Generate size for a given node
|
|
147
|
-
*/
|
|
148
|
-
size(itemData) {
|
|
149
|
-
let result = undefined;
|
|
150
|
-
if (this._rulesMap.size !== undefined) {
|
|
151
|
-
NodeAttributes.matchStyle(this._rulesMap.size, itemData, (styleRule) => {
|
|
152
|
-
const sizeStyle = styleRule.style.size;
|
|
153
|
-
if (this.isAutoRange(sizeStyle)) {
|
|
154
|
-
if (sizeStyle.input !== undefined &&
|
|
155
|
-
sizeStyle.max !== undefined &&
|
|
156
|
-
sizeStyle.min !== undefined) {
|
|
157
|
-
const propertyName = sizeStyle.input[1];
|
|
158
|
-
const propertyValue = tools_1.Tools.parseNumber(itemData.properties[propertyName]);
|
|
159
|
-
const isLog = sizeStyle.scale && sizeStyle.scale === rest_client_1.AutoRangeScale.LOGARITHMIC;
|
|
160
|
-
result = NodeAttributes.getAutomaticRangeSize(propertyValue, styleRule, isLog);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
else {
|
|
164
|
-
result = sizeStyle;
|
|
165
|
-
}
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
return result;
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
|
-
* return the corresponding size to the value
|
|
172
|
-
* @param value
|
|
173
|
-
* @param rule
|
|
174
|
-
* @param isLog
|
|
175
|
-
*/
|
|
176
|
-
static getAutomaticRangeSize(value, rule, isLog = false) {
|
|
177
|
-
return isLog
|
|
178
|
-
? this.getAutomaticRangeStyleLog(value, rule.style.size, NodeSizeExtrema.MIN, NodeSizeExtrema.MAX)
|
|
179
|
-
: this.getAutomaticRangeStyleLinear(value, rule.style.size, NodeSizeExtrema.MIN, NodeSizeExtrema.MAX);
|
|
180
|
-
}
|
|
181
|
-
/**
|
|
182
|
-
* Return an object containing all node attributes needed by Ogma to style a node
|
|
183
|
-
*/
|
|
184
|
-
all(itemData) {
|
|
185
|
-
if (!tools_1.Tools.isDefined(itemData)) {
|
|
186
|
-
return {
|
|
187
|
-
color: itemAttributes_1.BASE_GREY
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
const generatedIcon = this.icon(itemData);
|
|
191
|
-
return {
|
|
192
|
-
radius: this.size(itemData),
|
|
193
|
-
color: this.color(itemData),
|
|
194
|
-
shape: this.shape(itemData),
|
|
195
|
-
icon: generatedIcon.icon,
|
|
196
|
-
image: generatedIcon.image
|
|
197
|
-
};
|
|
198
|
-
}
|
|
199
|
-
/**
|
|
200
|
-
* Return the value of the image url from a style rule or undefined
|
|
201
|
-
* @param value
|
|
202
|
-
* @param itemData
|
|
203
|
-
* @param baseUrl
|
|
204
|
-
*/
|
|
205
|
-
static getImageUrlFromStyleRule(value, itemData, baseUrl) {
|
|
206
|
-
let imageUrl;
|
|
207
|
-
if (typeof value === 'string' && ['imageUrl', 'image'].includes(tools_1.Tools.getType(value))) {
|
|
208
|
-
imageUrl = value;
|
|
209
|
-
}
|
|
210
|
-
else if (typeof value === 'object') {
|
|
211
|
-
imageUrl = tools_1.Tools.getIn(itemData, value.path);
|
|
212
|
-
}
|
|
213
|
-
// if base url is defined, we need to create a new URL to get the absolute path
|
|
214
|
-
if (imageUrl !== undefined && baseUrl !== undefined) {
|
|
215
|
-
return new URL(imageUrl, baseUrl).href;
|
|
216
|
-
}
|
|
217
|
-
return imageUrl;
|
|
218
|
-
}
|
|
219
|
-
/**
|
|
220
|
-
* Set the base url (it will be used for image url while styling nodes)
|
|
221
|
-
* @param baseUrl bse url
|
|
222
|
-
*/
|
|
223
|
-
setBaseUrl(baseUrl) {
|
|
224
|
-
this._baseUrl = baseUrl;
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
exports.NodeAttributes = NodeAttributes;
|
|
228
|
-
//# sourceMappingURL=nodeAttributes.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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,+BAAf,eAAe,QAG1B;AAED,MAAa,cAAe,SAAQ,+BAA0B;IAI5D,YAAY,QAMX;QACC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAClB,CAAC;IAED;;OAEG;IACK,MAAM,CAAC,UAAU,CACvB,UAAwC,EACxC,QAAoB,EACpB,QAAmD;QAEnD,I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,IAAI,GAAG,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC;QACzC,CAAC;QACD,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED;;;OAGG;IACI,UAAU,CAAC,OAAgB;QAChC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IAC1B,CAAC;CACF;AA9QD,wCA8QC","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 // Base url, used for image urls\n private _baseUrl?: string;\n\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 const imageUrlValue = NodeAttributes.getImageUrlFromStyleRule(\n style.image.url,\n itemData,\n this._baseUrl\n );\n if (imageUrlValue !== undefined) {\n result = {\n image: {\n url: imageUrlValue,\n scale: style.image.scale,\n fit: style.image.fit,\n tile: style.image.tile,\n minVisibleSize: 0\n }\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 /**\n * Return the value of the image url from a style rule or undefined\n * @param value\n * @param itemData\n * @param baseUrl\n */\n public static getImageUrlFromStyleRule(\n value: string | IImageDataValue | undefined,\n itemData: LkNodeData,\n baseUrl?: string\n ): string | undefined {\n let imageUrl: string | undefined;\n if (typeof value === 'string' && ['imageUrl', 'image'].includes(Tools.getType(value)!)) {\n imageUrl = value;\n } else if (typeof value === 'object') {\n imageUrl = Tools.getIn(itemData, value.path);\n }\n\n // if base url is defined, we need to create a new URL to get the absolute path\n if (imageUrl !== undefined && baseUrl !== undefined) {\n return new URL(imageUrl, baseUrl).href;\n }\n return imageUrl;\n }\n\n /**\n * Set the base url (it will be used for image url while styling nodes)\n * @param baseUrl bse url\n */\n public setBaseUrl(baseUrl?: string): void {\n this._baseUrl = baseUrl;\n }\n}\n"]}
|