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