@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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nodeAttributes.js","sourceRo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EAAE,KAAK,CAAC,CAAC;qBAChF;iBACF;qBAAM;oBACL,MAAM,GAAG,SAAS,CAAC;iBACpB;YACH,CAAC,CAAC,CAAC;SACJ;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;IAED;;;;;OAKG;IACW,oCAAqB,GAAnC,UAAoC,KAAa,EAAE,IAAe,EAAE,KAAa;QAAb,sBAAA,EAAA,aAAa;QAC/E,OAAO,KAAK;YACV,CAAC,CAAC,IAAI,CAAC,yBAAyB,CAC5B,KAAK,EACL,IAAI,CAAC,KAAK,CAAC,IAAI,EACf,eAAe,CAAC,GAAG,EACnB,eAAe,CAAC,GAAG,CACpB;YACH,CAAC,CAAC,IAAI,CAAC,4BAA4B,CAC/B,KAAK,EACL,IAAI,CAAC,KAAK,CAAC,IAAI,EACf,eAAe,CAAC,GAAG,EACnB,eAAe,CAAC,GAAG,CACpB,CAAC;IACR,CAAC;IAED;;OAEG;IACI,4BAAG,GAAV,UACE,QAAoB;QAQpB,IAAI,CAAC,aAAK,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE;YAC9B,OAAO;gBACL,KAAK,EAAE,0BAAS;aACjB,CAAC;SACH;QACD,IAAM,aAAa,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC1C,OAAO;YACL,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC;YAC3B,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC;YAC3B,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC;YAC3B,IAAI,EAAE,aAAa,CAAC,IAAI;YACxB,KAAK,EAAE,aAAa,CAAC,KAAK;SAC3B,CAAC;IACJ,CAAC;IACH,qBAAC;AAAD,CAAC,AA/ND,CAAoC,+BAAc,GA+NjD;AA/NY,wCAAc","sourcesContent":["'use strict';\nimport {Color} from '@linkurious/ogma';\nimport {LkNodeData, OgmaNodeShape, IStyleImage, IStyleIcon} from '@linkurious/rest-client';\nimport sha1 from 'sha1';\n\nimport {Tools} from '../tools/tools';\nimport {OgmaTools} from '..';\n\nimport {StyleRule} from './styleRule';\nimport {BASE_GREY, ItemAttributes} from './itemAttributes';\n\nexport interface OgmaImage extends IStyleImage {\n url?: string;\n}\n\nexport enum NodeSizeExtrema {\n MIN = 50,\n MAX = 500\n}\n\nexport class NodeAttributes extends ItemAttributes {\n constructor(rulesMap: {\n color?: Array<StyleRule>;\n icon?: Array<StyleRule>;\n image?: Array<StyleRule>;\n shape?: Array<StyleRule>;\n size?: Array<StyleRule>;\n }) {\n super(rulesMap);\n }\n\n /**\n * Run the callback if an item match with a style in the array of rules\n */\n private static matchStyle(\n styleRules: Array<StyleRule>,\n itemData: LkNodeData,\n callback: (style: StyleRule) => unknown\n ): void {\n if (!Tools.isDefined(itemData)) {\n return;\n }\n if (!Tools.isDefined(styleRules)) {\n return;\n }\n for (let i = 0; i < styleRules.length; ++i) {\n if (styleRules[i].canApplyTo(itemData)) {\n callback(styleRules[i]);\n break;\n }\n }\n }\n\n /**\n * Generate color for a given node (call only if _rulesMap.color is defined\n */\n public color(itemData: LkNodeData): Color | Array<Color> {\n if (!Tools.isDefined(itemData)) {\n return [BASE_GREY];\n }\n const hash = sha1(JSON.stringify(itemData));\n const cachedColor = this.colorsCache.get(hash);\n if (cachedColor !== undefined) {\n return cachedColor;\n }\n let colors = [];\n for (let i = 0; i < itemData.categories.length; ++i) {\n let c = null;\n for (let j = 0; j < this._rulesMap.color!.length; ++j) {\n const rule = this._rulesMap.color![j];\n if (\n rule.itemType !== undefined &&\n rule.itemType !== null &&\n rule.itemType !== itemData.categories[i]\n ) {\n continue;\n }\n if (rule.canApplyTo(itemData)) {\n if (typeof rule.style.color === 'object') {\n const propValue = Tools.getIn(itemData, rule.style.color.input);\n if (Array.isArray(propValue)) {\n c = ItemAttributes.autoColor(itemData.categories[i], rule.style.ignoreCase);\n } else {\n c = ItemAttributes.autoColor(`${propValue}`, rule.style.ignoreCase);\n }\n } else {\n c = rule.style.color;\n }\n break;\n }\n }\n colors.push(c);\n }\n colors = colors.filter((c) => Tools.isDefined(c));\n if (colors.length === 0) {\n colors = [BASE_GREY];\n }\n const finalColor = colors.length === 1 ? colors[0] : colors;\n this.colorsCache.set(hash, finalColor);\n return finalColor;\n }\n\n /**\n * Generate icon for a given node\n */\n public icon(\n itemData: LkNodeData\n ): {\n icon?: IStyleIcon;\n image?: OgmaImage | null;\n } {\n const rawColors = this.color(itemData);\n const color = Array.isArray(rawColors) ? rawColors[0] : rawColors;\n let result = {};\n const rules = [...(this._rulesMap.image || []), ...(this._rulesMap.icon || [])];\n if (!Tools.isDefined(itemData)) {\n return {\n icon: {},\n image: {}\n };\n }\n for (let i = 0; i < rules.length; ++i) {\n if (rules[i].canApplyTo(itemData)) {\n if ('icon' in rules[i].style) {\n result = {\n icon: {\n content: rules[i].style.icon.content,\n font: rules[i].style.icon.font,\n scale: 0.5,\n color: OgmaTools.isBright(color) ? '#000000' : '#FFFFFF'\n }\n };\n } else if ('image' in rules[i].style) {\n result = {\n image: {\n url:\n Tools.getType(rules[i].style.image.url) === 'imageUrl' ||\n Tools.getType(rules[i].style.image.url) === 'image'\n ? rules[i].style.image.url\n : Tools.getIn(itemData, rules[i].style.image.url.path),\n scale: rules[i].style.image.scale,\n fit: rules[i].style.image.fit,\n tile: rules[i].style.image.tile,\n minVisibleSize: 0\n }\n };\n }\n break;\n }\n }\n\n return result;\n }\n\n /**\n * Generate shape for a given node\n */\n public shape(itemData: LkNodeData): OgmaNodeShape | undefined {\n let result = undefined;\n if (this._rulesMap.shape !== undefined) {\n NodeAttributes.matchStyle(this._rulesMap.shape, itemData, (styleRule) => {\n result = styleRule.style.shape;\n });\n }\n return result;\n }\n\n /**\n * Generate size for a given node\n */\n public size(itemData: LkNodeData): number | undefined {\n let result = undefined;\n if (this._rulesMap.size !== undefined) {\n NodeAttributes.matchStyle(this._rulesMap.size, itemData, (styleRule) => {\n const sizeStyle = styleRule.style.size;\n if (sizeStyle.type === 'autoRange') {\n if (\n sizeStyle.input !== undefined &&\n sizeStyle.max !== undefined &&\n sizeStyle.min !== undefined\n ) {\n const propertyName: string = sizeStyle.input[1];\n const propertyValue = Tools.parseNumber(itemData.properties[propertyName]);\n //to update with the correct enum type\n const isLog = sizeStyle.scale && sizeStyle.scale === 'logarithmic';\n result = NodeAttributes.getAutomaticRangeSize(propertyValue, styleRule, isLog);\n }\n } else {\n result = sizeStyle;\n }\n });\n }\n return result;\n }\n\n /**\n * return the corresponding size to the value\n * @param value\n * @param rule\n * @param isLog\n */\n public static getAutomaticRangeSize(value: number, rule: StyleRule, isLog = false): string {\n return isLog\n ? this.getAutomaticRangeStyleLog(\n value,\n rule.style.size,\n NodeSizeExtrema.MIN,\n NodeSizeExtrema.MAX\n )\n : this.getAutomaticRangeStyleLinear(\n value,\n rule.style.size,\n NodeSizeExtrema.MIN,\n NodeSizeExtrema.MAX\n );\n }\n\n /**\n * Return an object containing all node attributes needed by Ogma to style a node\n */\n public all(\n itemData: LkNodeData\n ): {\n radius?: number | undefined;\n color: Color | Array<Color>;\n shape?: OgmaNodeShape | undefined;\n icon?: IStyleIcon;\n image?: IStyleImage | null;\n } {\n if (!Tools.isDefined(itemData)) {\n return {\n color: BASE_GREY\n };\n }\n const generatedIcon = this.icon(itemData);\n return {\n radius: this.size(itemData),\n color: this.color(itemData),\n shape: this.shape(itemData),\n icon: generatedIcon.icon,\n image: generatedIcon.image\n };\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"nodeAttributes.js","sourceRoot":"","sources":["../../src/styles/nodeAttributes.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;AAGb,gDAAwB;AAExB,0CAAqC;AACrC,0BAA6B;AAG7B,qDAA2D;AAM3D,IAAY,eAGX;AAHD,WAAY,eAAe;IACzB,oDAAQ,CAAA;IACR,qDAAS,CAAA;AACX,CAAC,EAHW,eAAe,GAAf,uBAAe,KAAf,uBAAe,QAG1B;AAED,MAAa,cAAe,SAAQ,+BAA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AI,CAAC,yBAAyB,CAC5B,KAAK,EACL,IAAI,CAAC,KAAK,CAAC,IAAI,EACf,eAAe,CAAC,GAAG,EACnB,eAAe,CAAC,GAAG,CACpB;YACH,CAAC,CAAC,IAAI,CAAC,4BAA4B,CAC/B,KAAK,EACL,IAAI,CAAC,KAAK,CAAC,IAAI,EACf,eAAe,CAAC,GAAG,EACnB,eAAe,CAAC,GAAG,CACpB,CAAC;IACR,CAAC;IAED;;OAEG;IACI,GAAG,CACR,QAAoB;QAQpB,IAAI,CAAC,aAAK,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE;YAC9B,OAAO;gBACL,KAAK,EAAE,0BAAS;aACjB,CAAC;SACH;QACD,MAAM,aAAa,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC1C,OAAO;YACL,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC;YAC3B,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC;YAC3B,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC;YAC3B,IAAI,EAAE,aAAa,CAAC,IAAI;YACxB,KAAK,EAAE,aAAa,CAAC,KAAK;SAC3B,CAAC;IACJ,CAAC;CACF;AA/ND,wCA+NC","sourcesContent":["'use strict';\nimport {Color} from '@linkurious/ogma';\nimport {LkNodeData, OgmaNodeShape, IStyleImage, IStyleIcon} from '@linkurious/rest-client';\nimport sha1 from 'sha1';\n\nimport {Tools} from '../tools/tools';\nimport {OgmaTools} from '..';\n\nimport {StyleRule} from './styleRule';\nimport {BASE_GREY, ItemAttributes} from './itemAttributes';\n\nexport interface OgmaImage extends IStyleImage {\n url?: string;\n}\n\nexport enum NodeSizeExtrema {\n MIN = 50,\n MAX = 500\n}\n\nexport class NodeAttributes extends ItemAttributes {\n constructor(rulesMap: {\n color?: Array<StyleRule>;\n icon?: Array<StyleRule>;\n image?: Array<StyleRule>;\n shape?: Array<StyleRule>;\n size?: Array<StyleRule>;\n }) {\n super(rulesMap);\n }\n\n /**\n * Run the callback if an item match with a style in the array of rules\n */\n private static matchStyle(\n styleRules: Array<StyleRule>,\n itemData: LkNodeData,\n callback: (style: StyleRule) => unknown\n ): void {\n if (!Tools.isDefined(itemData)) {\n return;\n }\n if (!Tools.isDefined(styleRules)) {\n return;\n }\n for (let i = 0; i < styleRules.length; ++i) {\n if (styleRules[i].canApplyTo(itemData)) {\n callback(styleRules[i]);\n break;\n }\n }\n }\n\n /**\n * Generate color for a given node (call only if _rulesMap.color is defined\n */\n public color(itemData: LkNodeData): Color | Array<Color> {\n if (!Tools.isDefined(itemData)) {\n return [BASE_GREY];\n }\n const hash = sha1(JSON.stringify(itemData));\n const cachedColor = this.colorsCache.get(hash);\n if (cachedColor !== undefined) {\n return cachedColor;\n }\n let colors = [];\n for (let i = 0; i < itemData.categories.length; ++i) {\n let c = null;\n for (let j = 0; j < this._rulesMap.color!.length; ++j) {\n const rule = this._rulesMap.color![j];\n if (\n rule.itemType !== undefined &&\n rule.itemType !== null &&\n rule.itemType !== itemData.categories[i]\n ) {\n continue;\n }\n if (rule.canApplyTo(itemData)) {\n if (typeof rule.style.color === 'object') {\n const propValue = Tools.getIn(itemData, rule.style.color.input);\n if (Array.isArray(propValue)) {\n c = ItemAttributes.autoColor(itemData.categories[i], rule.style.ignoreCase);\n } else {\n c = ItemAttributes.autoColor(`${propValue}`, rule.style.ignoreCase);\n }\n } else {\n c = rule.style.color;\n }\n break;\n }\n }\n colors.push(c);\n }\n colors = colors.filter((c) => Tools.isDefined(c));\n if (colors.length === 0) {\n colors = [BASE_GREY];\n }\n const finalColor = colors.length === 1 ? colors[0] : colors;\n this.colorsCache.set(hash, finalColor);\n return finalColor;\n }\n\n /**\n * Generate icon for a given node\n */\n public icon(\n itemData: LkNodeData\n ): {\n icon?: IStyleIcon;\n image?: OgmaImage | null;\n } {\n const rawColors = this.color(itemData);\n const color = Array.isArray(rawColors) ? rawColors[0] : rawColors;\n let result = {};\n const rules = [...(this._rulesMap.image || []), ...(this._rulesMap.icon || [])];\n if (!Tools.isDefined(itemData)) {\n return {\n icon: {},\n image: {}\n };\n }\n for (let i = 0; i < rules.length; ++i) {\n if (rules[i].canApplyTo(itemData)) {\n if ('icon' in rules[i].style) {\n result = {\n icon: {\n content: rules[i].style.icon.content,\n font: rules[i].style.icon.font,\n scale: 0.5,\n color: OgmaTools.isBright(color) ? '#000000' : '#FFFFFF'\n }\n };\n } else if ('image' in rules[i].style) {\n result = {\n image: {\n url:\n Tools.getType(rules[i].style.image.url) === 'imageUrl' ||\n Tools.getType(rules[i].style.image.url) === 'image'\n ? rules[i].style.image.url\n : Tools.getIn(itemData, rules[i].style.image.url.path),\n scale: rules[i].style.image.scale,\n fit: rules[i].style.image.fit,\n tile: rules[i].style.image.tile,\n minVisibleSize: 0\n }\n };\n }\n break;\n }\n }\n\n return result;\n }\n\n /**\n * Generate shape for a given node\n */\n public shape(itemData: LkNodeData): OgmaNodeShape | undefined {\n let result = undefined;\n if (this._rulesMap.shape !== undefined) {\n NodeAttributes.matchStyle(this._rulesMap.shape, itemData, (styleRule) => {\n result = styleRule.style.shape;\n });\n }\n return result;\n }\n\n /**\n * Generate size for a given node\n */\n public size(itemData: LkNodeData): number | undefined {\n let result = undefined;\n if (this._rulesMap.size !== undefined) {\n NodeAttributes.matchStyle(this._rulesMap.size, itemData, (styleRule) => {\n const sizeStyle = styleRule.style.size;\n if (sizeStyle.type === 'autoRange') {\n if (\n sizeStyle.input !== undefined &&\n sizeStyle.max !== undefined &&\n sizeStyle.min !== undefined\n ) {\n const propertyName: string = sizeStyle.input[1];\n const propertyValue = Tools.parseNumber(itemData.properties[propertyName]);\n //to update with the correct enum type\n const isLog = sizeStyle.scale && sizeStyle.scale === 'logarithmic';\n result = NodeAttributes.getAutomaticRangeSize(propertyValue, styleRule, isLog);\n }\n } else {\n result = sizeStyle;\n }\n });\n }\n return result;\n }\n\n /**\n * return the corresponding size to the value\n * @param value\n * @param rule\n * @param isLog\n */\n public static getAutomaticRangeSize(value: number, rule: StyleRule, isLog = false): string {\n return isLog\n ? this.getAutomaticRangeStyleLog(\n value,\n rule.style.size,\n NodeSizeExtrema.MIN,\n NodeSizeExtrema.MAX\n )\n : this.getAutomaticRangeStyleLinear(\n value,\n rule.style.size,\n NodeSizeExtrema.MIN,\n NodeSizeExtrema.MAX\n );\n }\n\n /**\n * Return an object containing all node attributes needed by Ogma to style a node\n */\n public all(\n itemData: LkNodeData\n ): {\n radius?: number | undefined;\n color: Color | Array<Color>;\n shape?: OgmaNodeShape | undefined;\n icon?: IStyleIcon;\n image?: IStyleImage | null;\n } {\n if (!Tools.isDefined(itemData)) {\n return {\n color: BASE_GREY\n };\n }\n const generatedIcon = this.icon(itemData);\n return {\n radius: this.size(itemData),\n color: this.color(itemData),\n shape: this.shape(itemData),\n icon: generatedIcon.icon,\n image: generatedIcon.image\n };\n }\n}\n"]}
|
package/dist/styles/styleRule.js
CHANGED
|
@@ -1,21 +1,15 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
var __spreadArrays = (this && this.__spreadArrays) || function () {
|
|
3
|
-
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
|
|
4
|
-
for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
|
5
|
-
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
|
6
|
-
r[k] = a[j];
|
|
7
|
-
return r;
|
|
8
|
-
};
|
|
9
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
3
|
+
exports.StyleRule = exports.StyleRuleType = void 0;
|
|
4
|
+
const rest_client_1 = require("@linkurious/rest-client");
|
|
5
|
+
const __1 = require("..");
|
|
6
|
+
const tools_1 = require("../tools/tools");
|
|
13
7
|
var StyleRuleType;
|
|
14
8
|
(function (StyleRuleType) {
|
|
15
9
|
StyleRuleType["AUTO_RANGE"] = "autoRange";
|
|
16
10
|
})(StyleRuleType = exports.StyleRuleType || (exports.StyleRuleType = {}));
|
|
17
|
-
|
|
18
|
-
|
|
11
|
+
class StyleRule {
|
|
12
|
+
constructor(model) {
|
|
19
13
|
this.type = model.type;
|
|
20
14
|
this.input = model.input;
|
|
21
15
|
this.index = model.index;
|
|
@@ -23,41 +17,37 @@ var StyleRule = /** @class */ (function () {
|
|
|
23
17
|
this.style = model.style;
|
|
24
18
|
this.value = model.value;
|
|
25
19
|
}
|
|
26
|
-
|
|
20
|
+
static isAutomaticRange(rule) {
|
|
27
21
|
return (rule.style !== undefined &&
|
|
28
22
|
((rule.style.width !== undefined &&
|
|
29
23
|
rule.style.width.type === StyleRuleType.AUTO_RANGE) ||
|
|
30
24
|
(rule.style.size !== undefined &&
|
|
31
25
|
rule.style.size.type === StyleRuleType.AUTO_RANGE)));
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
},
|
|
51
|
-
enumerable: true,
|
|
52
|
-
configurable: true
|
|
53
|
-
});
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Return an int describing specificity of the style. 4 = very specific / 1 = not specific
|
|
29
|
+
*
|
|
30
|
+
* @return {number}
|
|
31
|
+
*/
|
|
32
|
+
get specificity() {
|
|
33
|
+
if (this.itemType !== undefined && this.input !== undefined) {
|
|
34
|
+
return 4;
|
|
35
|
+
}
|
|
36
|
+
if (this.itemType === undefined && this.input !== undefined) {
|
|
37
|
+
return 3;
|
|
38
|
+
}
|
|
39
|
+
if (this.itemType !== undefined && this.input === undefined) {
|
|
40
|
+
return 2;
|
|
41
|
+
}
|
|
42
|
+
return 1;
|
|
43
|
+
}
|
|
54
44
|
/**
|
|
55
45
|
* Return true if this style match values
|
|
56
46
|
*/
|
|
57
|
-
|
|
47
|
+
matchValues(itemType, input, value) {
|
|
58
48
|
if (tools_1.Tools.isDefined(input)) {
|
|
59
49
|
return (((itemType === this.itemType || !tools_1.Tools.isDefined(this.itemType)) &&
|
|
60
|
-
tools_1.Tools.isEqual(
|
|
50
|
+
tools_1.Tools.isEqual(['properties', ...input], this.input) &&
|
|
61
51
|
tools_1.Tools.isEqual(value, this.value)) ||
|
|
62
52
|
(this.type === 'any' &&
|
|
63
53
|
!tools_1.Tools.isDefined(this.input) &&
|
|
@@ -68,16 +58,16 @@ var StyleRule = /** @class */ (function () {
|
|
|
68
58
|
return itemType === this.itemType && !tools_1.Tools.isDefined(this.input);
|
|
69
59
|
}
|
|
70
60
|
return !tools_1.Tools.isDefined(this.input);
|
|
71
|
-
}
|
|
72
|
-
|
|
61
|
+
}
|
|
62
|
+
static inputExists(type, input) {
|
|
73
63
|
return type !== rest_client_1.SelectorType.ANY;
|
|
74
|
-
}
|
|
64
|
+
}
|
|
75
65
|
/**
|
|
76
66
|
* Return true if a style can apply to a node
|
|
77
67
|
*/
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
68
|
+
canApplyTo(data) {
|
|
69
|
+
const types = 'categories' in data ? data.categories : [data.type];
|
|
70
|
+
let typePredicate = false;
|
|
81
71
|
switch (this.type) {
|
|
82
72
|
case rest_client_1.SelectorType.ANY:
|
|
83
73
|
typePredicate = StyleRule.checkAny(data, this.style);
|
|
@@ -104,29 +94,29 @@ var StyleRule = /** @class */ (function () {
|
|
|
104
94
|
break;
|
|
105
95
|
}
|
|
106
96
|
return typePredicate && StyleRule.checkItemType(types, this.itemType);
|
|
107
|
-
}
|
|
97
|
+
}
|
|
108
98
|
/**
|
|
109
99
|
* Return true or false on rule type 'any' if the current node match the rule
|
|
110
100
|
*/
|
|
111
|
-
|
|
101
|
+
static checkAny(data, style) {
|
|
112
102
|
// return true if autoColor by a property and this property exists in node
|
|
113
103
|
if (typeof style.color === 'object') {
|
|
114
104
|
return tools_1.Tools.isDefined(tools_1.Tools.getIn(data, style.color.input));
|
|
115
105
|
}
|
|
116
106
|
return true;
|
|
117
|
-
}
|
|
107
|
+
}
|
|
118
108
|
/**
|
|
119
109
|
* Return true or false on rule type 'noValue' if the current node match the rule
|
|
120
110
|
*/
|
|
121
|
-
|
|
111
|
+
static checkNoValue(data, input) {
|
|
122
112
|
return !tools_1.Tools.valueExists(tools_1.Tools.getIn(data, input));
|
|
123
|
-
}
|
|
113
|
+
}
|
|
124
114
|
/**
|
|
125
115
|
* Return true or false on rule type 'NaN' if the current node match the rule
|
|
126
116
|
*/
|
|
127
|
-
|
|
117
|
+
static checkNan(data, input) {
|
|
128
118
|
return !tools_1.Tools.isNumber(tools_1.Tools.getIn(data, input));
|
|
129
|
-
}
|
|
119
|
+
}
|
|
130
120
|
/**
|
|
131
121
|
* Return true if predicate is true for the node value
|
|
132
122
|
*
|
|
@@ -134,38 +124,38 @@ var StyleRule = /** @class */ (function () {
|
|
|
134
124
|
* @param comparator
|
|
135
125
|
* @return {boolean}
|
|
136
126
|
*/
|
|
137
|
-
|
|
127
|
+
static checkRange(value, comparator) {
|
|
138
128
|
return ((comparator['<='] === undefined || value <= comparator['<=']) &&
|
|
139
129
|
(comparator['<'] === undefined || value < comparator['<']) &&
|
|
140
130
|
(comparator['>'] === undefined || value > comparator['>']) &&
|
|
141
131
|
(comparator['>='] === undefined || value >= comparator['>=']));
|
|
142
|
-
}
|
|
132
|
+
}
|
|
143
133
|
/**
|
|
144
134
|
* Return true or false on rule type 'is' if the current node match the rule
|
|
145
135
|
*/
|
|
146
|
-
|
|
136
|
+
static checkIs(data, input, value) {
|
|
147
137
|
if (!tools_1.Tools.isDefined(input)) {
|
|
148
138
|
return false;
|
|
149
139
|
}
|
|
150
|
-
|
|
151
|
-
|
|
140
|
+
const itemValue = tools_1.Tools.getIn(data, input);
|
|
141
|
+
let formattedValue = itemValue;
|
|
152
142
|
if (tools_1.Tools.isDefined(itemValue) &&
|
|
153
143
|
typeof itemValue === 'object' &&
|
|
154
144
|
(itemValue.type === 'date' || itemValue.type === 'datetime')) {
|
|
155
|
-
|
|
145
|
+
let timezone = itemValue.timezone;
|
|
156
146
|
if (itemValue.timezone === 'Z') {
|
|
157
147
|
timezone = '+00:00';
|
|
158
148
|
}
|
|
159
149
|
formattedValue = tools_1.Tools.formatDate(itemValue.value, itemValue.type === 'datetime', tools_1.Tools.timezoneToMilliseconds(timezone) / 1000);
|
|
160
150
|
}
|
|
161
151
|
return tools_1.Tools.isEqual(formattedValue, value);
|
|
162
|
-
}
|
|
152
|
+
}
|
|
163
153
|
/**
|
|
164
154
|
* Check that value of itemType match for the node
|
|
165
155
|
*/
|
|
166
|
-
|
|
156
|
+
static checkItemType(types, itemType) {
|
|
167
157
|
return StyleRule.matchCategory(types, itemType) || StyleRule.matchAny(itemType);
|
|
168
|
-
}
|
|
158
|
+
}
|
|
169
159
|
/**
|
|
170
160
|
* Return true if itemType is defined and category exists in an array of categories
|
|
171
161
|
*
|
|
@@ -173,32 +163,31 @@ var StyleRule = /** @class */ (function () {
|
|
|
173
163
|
* @param {string} itemType
|
|
174
164
|
* @return {boolean}
|
|
175
165
|
*/
|
|
176
|
-
|
|
166
|
+
static matchCategory(types, itemType) {
|
|
177
167
|
return (tools_1.Tools.isDefined(itemType) &&
|
|
178
168
|
(Array.isArray(types) ? types.includes(itemType) : tools_1.Tools.isEqual(types, itemType)));
|
|
179
|
-
}
|
|
169
|
+
}
|
|
180
170
|
/**
|
|
181
171
|
* Return true if itemType is undefined
|
|
182
172
|
*
|
|
183
173
|
* @param {string} itemType
|
|
184
174
|
* @return {boolean}
|
|
185
175
|
*/
|
|
186
|
-
|
|
176
|
+
static matchAny(itemType) {
|
|
187
177
|
return itemType === undefined;
|
|
188
|
-
}
|
|
178
|
+
}
|
|
189
179
|
/**
|
|
190
180
|
* Return the color for a type
|
|
191
181
|
*/
|
|
192
|
-
|
|
193
|
-
|
|
182
|
+
getTypeColor(type) {
|
|
183
|
+
let color;
|
|
194
184
|
if (StyleRule.checkItemType([type], this.itemType) &&
|
|
195
185
|
this.type === rest_client_1.SelectorType.ANY &&
|
|
196
186
|
!tools_1.Tools.isDefined(this.input)) {
|
|
197
187
|
color = __1.ItemAttributes.getTypeColor(this, type);
|
|
198
188
|
}
|
|
199
189
|
return color;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
}());
|
|
190
|
+
}
|
|
191
|
+
}
|
|
203
192
|
exports.StyleRule = StyleRule;
|
|
204
193
|
//# sourceMappingURL=styleRule.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"styleRule.js","sourceRoot":"","sources":["../../src/styles/styleRule.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;;;;AAEb,uDAQiC;AAEjC,wBAAkC;AAClC,wCAAqC;AAErC,IAAY,aAEX;AAFD,WAAY,aAAa;IACvB,yCAAwB,CAAA;AAC1B,CAAC,EAFW,aAAa,GAAb,qBAAa,KAAb,qBAAa,QAExB;AAED;IAQE,mBAAY,KAA0C;QACpD,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC;QACvB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;QACzB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;QACzB,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC;QAC/B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;QACzB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;IAC3B,CAAC;IAEa,0BAAgB,GAA9B,UAA+B,IAAyC;QACtE,OAAO,CACL,IAAI,CAAC,KAAK,KAAK,SAAS;YACxB,CAAC,CAAE,IAAI,CAAC,KAAoB,CAAC,KAAK,KAAK,SAAS;gBAC5C,IAAI,CAAC,KAAoB,CAAC,KAAyB,CAAC,IAAI,KAAK,aAAa,CAAC,UAAU,CAAC;gBACxF,C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\nimport {\n IEdgeStyle,\n IStyleRule,\n LkEdgeData,\n LkNodeData,\n INodeStyle,\n SelectorType,\n IStyleAutoRange\n} from '@linkurious/rest-client';\n\nimport {ItemAttributes} from '..';\nimport {Tools} from '../tools/tools';\n\nexport enum StyleRuleType {\n AUTO_RANGE = 'autoRange'\n}\n\nexport class StyleRule implements IStyleRule<INodeStyle | IEdgeStyle> {\n public type: SelectorType;\n public input: string[] | undefined;\n public index: number;\n public itemType?: string;\n public value: any;\n public style: any;\n\n constructor(model: IStyleRule<INodeStyle | IEdgeStyle>) {\n this.type = model.type;\n this.input = model.input;\n this.index = model.index;\n this.itemType = model.itemType;\n this.style = model.style;\n this.value = model.value;\n }\n\n public static isAutomaticRange(rule: IStyleRule<IEdgeStyle | INodeStyle>): boolean {\n return (\n rule.style !== undefined &&\n (((rule.style as IEdgeStyle).width !== undefined &&\n ((rule.style as IEdgeStyle).width as IStyleAutoRange).type === StyleRuleType.AUTO_RANGE) ||\n ((rule.style as INodeStyle).size !== undefined &&\n ((rule.style as INodeStyle).size as IStyleAutoRange).type === StyleRuleType.AUTO_RANGE))\n );\n }\n\n /**\n * Return an int describing specificity of the style. 4 = very specific / 1 = not specific\n *\n * @return {number}\n */\n get specificity(): 1 | 2 | 3 | 4 {\n if (this.itemType !== undefined && this.input !== undefined) {\n return 4;\n }\n if (this.itemType === undefined && this.input !== undefined) {\n return 3;\n }\n if (this.itemType !== undefined && this.input === undefined) {\n return 2;\n }\n return 1;\n }\n\n /**\n * Return true if this style match values\n */\n public matchValues(\n itemType: string | undefined,\n input: Array<string> | undefined,\n value: any\n ): boolean {\n if (Tools.isDefined(input)) {\n return (\n ((itemType === this.itemType || !Tools.isDefined(this.itemType)) &&\n Tools.isEqual(['properties', ...input], this.input) &&\n Tools.isEqual(value, this.value)) ||\n (this.type === 'any' &&\n !Tools.isDefined(this.input) &&\n typeof this.style.color === 'object' &&\n this.style.color.input[1] === input[0])\n );\n }\n\n if (Tools.isDefined(this.itemType)) {\n return itemType === this.itemType && !Tools.isDefined(this.input);\n }\n\n return !Tools.isDefined(this.input);\n }\n\n public static inputExists(\n type: SelectorType,\n input: Array<string> | undefined\n ): input is Array<string> {\n return type !== SelectorType.ANY;\n }\n\n /**\n * Return true if a style can apply to a node\n */\n public canApplyTo(data: LkNodeData | LkEdgeData): boolean {\n const types = 'categories' in data ? data.categories : [data.type];\n let typePredicate = false;\n switch (this.type) {\n case SelectorType.ANY:\n typePredicate = StyleRule.checkAny(data, this.style);\n break;\n\n case SelectorType.NO_VALUE:\n if (StyleRule.inputExists(this.type, this.input)) {\n typePredicate = StyleRule.checkNoValue(data, this.input);\n }\n break;\n\n case SelectorType.NAN:\n if (StyleRule.inputExists(this.type, this.input)) {\n typePredicate = StyleRule.checkNan(data, this.input);\n }\n break;\n\n case SelectorType.RANGE:\n if (StyleRule.inputExists(this.type, this.input)) {\n typePredicate = StyleRule.checkRange(Tools.getIn(data, this.input), this.value);\n }\n break;\n\n case SelectorType.IS:\n if (StyleRule.inputExists(this.type, this.input)) {\n typePredicate = StyleRule.checkIs(data, this.input, this.value);\n }\n break;\n }\n return typePredicate && StyleRule.checkItemType(types, this.itemType);\n }\n\n /**\n * Return true or false on rule type 'any' if the current node match the rule\n */\n public static checkAny(data: LkNodeData | LkEdgeData, style: INodeStyle | IEdgeStyle): boolean {\n // return true if autoColor by a property and this property exists in node\n if (typeof style.color === 'object') {\n return Tools.isDefined(Tools.getIn(data, style.color.input));\n }\n return true;\n }\n\n /**\n * Return true or false on rule type 'noValue' if the current node match the rule\n */\n public static checkNoValue(data: LkNodeData | LkEdgeData, input: Array<string>): boolean {\n return !Tools.valueExists(Tools.getIn(data, input));\n }\n\n /**\n * Return true or false on rule type 'NaN' if the current node match the rule\n */\n public static checkNan(data: LkNodeData | LkEdgeData, input: Array<string>): boolean {\n return !Tools.isNumber(Tools.getIn(data, input));\n }\n\n /**\n * Return true if predicate is true for the node value\n *\n * @param value\n * @param comparator\n * @return {boolean}\n */\n public static checkRange(\n value: number,\n comparator: {[key in '<=' | '<' | '>' | '>=']?: number}\n ): boolean {\n return (\n (comparator['<='] === undefined || value <= comparator['<=']) &&\n (comparator['<'] === undefined || value < comparator['<']) &&\n (comparator['>'] === undefined || value > comparator['>']) &&\n (comparator['>='] === undefined || value >= comparator['>='])\n );\n }\n\n /**\n * Return true or false on rule type 'is' if the current node match the rule\n */\n public static checkIs(data: LkNodeData | LkEdgeData, input: Array<string>, value: any): boolean {\n if (!Tools.isDefined(input)) {\n return false;\n }\n const itemValue = Tools.getIn(data, input);\n let formattedValue = itemValue;\n if (\n Tools.isDefined(itemValue) &&\n typeof itemValue === 'object' &&\n (itemValue.type === 'date' || itemValue.type === 'datetime')\n ) {\n let timezone = itemValue.timezone;\n if (itemValue.timezone === 'Z') {\n timezone = '+00:00';\n }\n formattedValue = Tools.formatDate(\n itemValue.value,\n itemValue.type === 'datetime',\n Tools.timezoneToMilliseconds(timezone) / 1000\n );\n }\n return Tools.isEqual(formattedValue, value);\n }\n\n /**\n * Check that value of itemType match for the node\n */\n public static checkItemType(types: Array<string>, itemType: string | undefined): boolean {\n return StyleRule.matchCategory(types, itemType) || StyleRule.matchAny(itemType);\n }\n\n /**\n * Return true if itemType is defined and category exists in an array of categories\n *\n * @param {Array<string> | string} types\n * @param {string} itemType\n * @return {boolean}\n */\n public static matchCategory(\n types: Array<string> | string,\n itemType: string | undefined\n ): boolean {\n return (\n Tools.isDefined(itemType) &&\n (Array.isArray(types) ? types.includes(itemType) : Tools.isEqual(types, itemType))\n );\n }\n\n /**\n * Return true if itemType is undefined\n *\n * @param {string} itemType\n * @return {boolean}\n */\n public static matchAny(itemType: any | null): boolean {\n return itemType === undefined;\n }\n\n /**\n * Return the color for a type\n */\n public getTypeColor(type: string): string | undefined | null {\n let color;\n if (\n StyleRule.checkItemType([type], this.itemType) &&\n this.type === SelectorType.ANY &&\n !Tools.isDefined(this.input)\n ) {\n color = ItemAttributes.getTypeColor(this, type);\n }\n return color;\n }\n}\n"]}
|
|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C;IAED;;;;;;OAMG;IACI,MAAM,CAAC,aAAa,CACzB,KAA6B,EAC7B,QAA4B;QAE5B,OAAO,CACL,aAAK,CAAC,SAAS,CAAC,QAAQ,CAAC;YACzB,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,aAAK,CAAC,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,CACnF,CAAC;IACJ,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,QAAQ,CAAC,QAAoB;QACzC,OAAO,QAAQ,KAAK,SAAS,CAAC;IAChC,CAAC;IAED;;OAEG;IACI,YAAY,CAAC,IAAY;QAC9B,IAAI,KAAK,CAAC;QACV,IACE,SAAS,CAAC,aAAa,CAAC,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC;YAC9C,IAAI,CAAC,IAAI,KAAK,0BAAY,CAAC,GAAG;YAC9B,CAAC,aAAK,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,EAC5B;YACA,KAAK,GAAG,kBAAc,CAAC,YAAY,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;SACjD;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AA5OD,8BA4OC","sourcesContent":["'use strict';\n\nimport {\n IEdgeStyle,\n IStyleRule,\n LkEdgeData,\n LkNodeData,\n INodeStyle,\n SelectorType,\n IStyleAutoRange\n} from '@linkurious/rest-client';\n\nimport {ItemAttributes} from '..';\nimport {Tools} from '../tools/tools';\n\nexport enum StyleRuleType {\n AUTO_RANGE = 'autoRange'\n}\n\nexport class StyleRule implements IStyleRule<INodeStyle | IEdgeStyle> {\n public type: SelectorType;\n public input: string[] | undefined;\n public index: number;\n public itemType?: string;\n public value: any;\n public style: any;\n\n constructor(model: IStyleRule<INodeStyle | IEdgeStyle>) {\n this.type = model.type;\n this.input = model.input;\n this.index = model.index;\n this.itemType = model.itemType;\n this.style = model.style;\n this.value = model.value;\n }\n\n public static isAutomaticRange(rule: IStyleRule<IEdgeStyle | INodeStyle>): boolean {\n return (\n rule.style !== undefined &&\n (((rule.style as IEdgeStyle).width !== undefined &&\n ((rule.style as IEdgeStyle).width as IStyleAutoRange).type === StyleRuleType.AUTO_RANGE) ||\n ((rule.style as INodeStyle).size !== undefined &&\n ((rule.style as INodeStyle).size as IStyleAutoRange).type === StyleRuleType.AUTO_RANGE))\n );\n }\n\n /**\n * Return an int describing specificity of the style. 4 = very specific / 1 = not specific\n *\n * @return {number}\n */\n get specificity(): 1 | 2 | 3 | 4 {\n if (this.itemType !== undefined && this.input !== undefined) {\n return 4;\n }\n if (this.itemType === undefined && this.input !== undefined) {\n return 3;\n }\n if (this.itemType !== undefined && this.input === undefined) {\n return 2;\n }\n return 1;\n }\n\n /**\n * Return true if this style match values\n */\n public matchValues(\n itemType: string | undefined,\n input: Array<string> | undefined,\n value: any\n ): boolean {\n if (Tools.isDefined(input)) {\n return (\n ((itemType === this.itemType || !Tools.isDefined(this.itemType)) &&\n Tools.isEqual(['properties', ...input], this.input) &&\n Tools.isEqual(value, this.value)) ||\n (this.type === 'any' &&\n !Tools.isDefined(this.input) &&\n typeof this.style.color === 'object' &&\n this.style.color.input[1] === input[0])\n );\n }\n\n if (Tools.isDefined(this.itemType)) {\n return itemType === this.itemType && !Tools.isDefined(this.input);\n }\n\n return !Tools.isDefined(this.input);\n }\n\n public static inputExists(\n type: SelectorType,\n input: Array<string> | undefined\n ): input is Array<string> {\n return type !== SelectorType.ANY;\n }\n\n /**\n * Return true if a style can apply to a node\n */\n public canApplyTo(data: LkNodeData | LkEdgeData): boolean {\n const types = 'categories' in data ? data.categories : [data.type];\n let typePredicate = false;\n switch (this.type) {\n case SelectorType.ANY:\n typePredicate = StyleRule.checkAny(data, this.style);\n break;\n\n case SelectorType.NO_VALUE:\n if (StyleRule.inputExists(this.type, this.input)) {\n typePredicate = StyleRule.checkNoValue(data, this.input);\n }\n break;\n\n case SelectorType.NAN:\n if (StyleRule.inputExists(this.type, this.input)) {\n typePredicate = StyleRule.checkNan(data, this.input);\n }\n break;\n\n case SelectorType.RANGE:\n if (StyleRule.inputExists(this.type, this.input)) {\n typePredicate = StyleRule.checkRange(Tools.getIn(data, this.input), this.value);\n }\n break;\n\n case SelectorType.IS:\n if (StyleRule.inputExists(this.type, this.input)) {\n typePredicate = StyleRule.checkIs(data, this.input, this.value);\n }\n break;\n }\n return typePredicate && StyleRule.checkItemType(types, this.itemType);\n }\n\n /**\n * Return true or false on rule type 'any' if the current node match the rule\n */\n public static checkAny(data: LkNodeData | LkEdgeData, style: INodeStyle | IEdgeStyle): boolean {\n // return true if autoColor by a property and this property exists in node\n if (typeof style.color === 'object') {\n return Tools.isDefined(Tools.getIn(data, style.color.input));\n }\n return true;\n }\n\n /**\n * Return true or false on rule type 'noValue' if the current node match the rule\n */\n public static checkNoValue(data: LkNodeData | LkEdgeData, input: Array<string>): boolean {\n return !Tools.valueExists(Tools.getIn(data, input));\n }\n\n /**\n * Return true or false on rule type 'NaN' if the current node match the rule\n */\n public static checkNan(data: LkNodeData | LkEdgeData, input: Array<string>): boolean {\n return !Tools.isNumber(Tools.getIn(data, input));\n }\n\n /**\n * Return true if predicate is true for the node value\n *\n * @param value\n * @param comparator\n * @return {boolean}\n */\n public static checkRange(\n value: number,\n comparator: {[key in '<=' | '<' | '>' | '>=']?: number}\n ): boolean {\n return (\n (comparator['<='] === undefined || value <= comparator['<=']) &&\n (comparator['<'] === undefined || value < comparator['<']) &&\n (comparator['>'] === undefined || value > comparator['>']) &&\n (comparator['>='] === undefined || value >= comparator['>='])\n );\n }\n\n /**\n * Return true or false on rule type 'is' if the current node match the rule\n */\n public static checkIs(data: LkNodeData | LkEdgeData, input: Array<string>, value: any): boolean {\n if (!Tools.isDefined(input)) {\n return false;\n }\n const itemValue = Tools.getIn(data, input);\n let formattedValue = itemValue;\n if (\n Tools.isDefined(itemValue) &&\n typeof itemValue === 'object' &&\n (itemValue.type === 'date' || itemValue.type === 'datetime')\n ) {\n let timezone = itemValue.timezone;\n if (itemValue.timezone === 'Z') {\n timezone = '+00:00';\n }\n formattedValue = Tools.formatDate(\n itemValue.value,\n itemValue.type === 'datetime',\n Tools.timezoneToMilliseconds(timezone) / 1000\n );\n }\n return Tools.isEqual(formattedValue, value);\n }\n\n /**\n * Check that value of itemType match for the node\n */\n public static checkItemType(types: Array<string>, itemType: string | undefined): boolean {\n return StyleRule.matchCategory(types, itemType) || StyleRule.matchAny(itemType);\n }\n\n /**\n * Return true if itemType is defined and category exists in an array of categories\n *\n * @param {Array<string> | string} types\n * @param {string} itemType\n * @return {boolean}\n */\n public static matchCategory(\n types: Array<string> | string,\n itemType: string | undefined\n ): boolean {\n return (\n Tools.isDefined(itemType) &&\n (Array.isArray(types) ? types.includes(itemType) : Tools.isEqual(types, itemType))\n );\n }\n\n /**\n * Return true if itemType is undefined\n *\n * @param {string} itemType\n * @return {boolean}\n */\n public static matchAny(itemType: any | null): boolean {\n return itemType === undefined;\n }\n\n /**\n * Return the color for a type\n */\n public getTypeColor(type: string): string | undefined | null {\n let color;\n if (\n StyleRule.checkItemType([type], this.itemType) &&\n this.type === SelectorType.ANY &&\n !Tools.isDefined(this.input)\n ) {\n color = ItemAttributes.getTypeColor(this, type);\n }\n return color;\n }\n}\n"]}
|