@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.
Files changed (39) hide show
  1. package/dist/captions/captions.js +42 -54
  2. package/dist/captions/captions.js.map +1 -1
  3. package/dist/filters/filters.d.ts +1 -1
  4. package/dist/filters/filters.js +55 -76
  5. package/dist/filters/filters.js.map +1 -1
  6. package/dist/index.js +34 -33
  7. package/dist/index.js.map +1 -1
  8. package/dist/ogma/features/OgmaStore.js +16 -30
  9. package/dist/ogma/features/OgmaStore.js.map +1 -1
  10. package/dist/ogma/features/captions.js +43 -87
  11. package/dist/ogma/features/captions.js.map +1 -1
  12. package/dist/ogma/features/reactive.js +58 -75
  13. package/dist/ogma/features/reactive.js.map +1 -1
  14. package/dist/ogma/features/selectors.d.ts +5 -5
  15. package/dist/ogma/features/selectors.js +25 -16
  16. package/dist/ogma/features/selectors.js.map +1 -1
  17. package/dist/ogma/features/styles.js +115 -137
  18. package/dist/ogma/features/styles.js.map +1 -1
  19. package/dist/ogma/features/transformations.js +39 -87
  20. package/dist/ogma/features/transformations.js.map +1 -1
  21. package/dist/ogma/index.js +140 -230
  22. package/dist/ogma/index.js.map +1 -1
  23. package/dist/styles/edgeAttributes.js +31 -47
  24. package/dist/styles/edgeAttributes.js.map +1 -1
  25. package/dist/styles/itemAttributes.js +33 -42
  26. package/dist/styles/itemAttributes.js.map +1 -1
  27. package/dist/styles/nodeAttributes.js +49 -71
  28. package/dist/styles/nodeAttributes.js.map +1 -1
  29. package/dist/styles/styleRule.js +57 -68
  30. package/dist/styles/styleRule.js.map +1 -1
  31. package/dist/styles/styleRules.js +150 -192
  32. package/dist/styles/styleRules.js.map +1 -1
  33. package/dist/tools/colorPalette.js +1 -0
  34. package/dist/tools/colorPalette.js.map +1 -1
  35. package/dist/tools/ogmaTool.js +28 -30
  36. package/dist/tools/ogmaTool.js.map +1 -1
  37. package/dist/tools/tools.js +88 -91
  38. package/dist/tools/tools.js.map +1 -1
  39. package/package.json +7 -7
@@ -1,92 +1,78 @@
1
1
  'use strict';
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- extendStatics(d, b);
11
- function __() { this.constructor = d; }
12
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13
- };
14
- })();
15
2
  Object.defineProperty(exports, "__esModule", { value: true });
16
- var rest_client_1 = require("@linkurious/rest-client");
17
- var tools_1 = require("../tools/tools");
18
- var itemAttributes_1 = require("./itemAttributes");
3
+ exports.EdgeAttributes = exports.EdgeWidthExtrema = void 0;
4
+ const rest_client_1 = require("@linkurious/rest-client");
5
+ const tools_1 = require("../tools/tools");
6
+ const itemAttributes_1 = require("./itemAttributes");
19
7
  var EdgeWidthExtrema;
20
8
  (function (EdgeWidthExtrema) {
21
9
  EdgeWidthExtrema[EdgeWidthExtrema["MIN"] = 50] = "MIN";
22
10
  EdgeWidthExtrema[EdgeWidthExtrema["MAX"] = 200] = "MAX";
23
11
  })(EdgeWidthExtrema = exports.EdgeWidthExtrema || (exports.EdgeWidthExtrema = {}));
24
- var EdgeAttributes = /** @class */ (function (_super) {
25
- __extends(EdgeAttributes, _super);
26
- function EdgeAttributes(rulesMap) {
27
- return _super.call(this, rulesMap) || this;
12
+ class EdgeAttributes extends itemAttributes_1.ItemAttributes {
13
+ constructor(rulesMap) {
14
+ super(rulesMap);
28
15
  }
29
16
  /**
30
17
  * Return rule that can be applied to the data
31
18
  */
32
- EdgeAttributes.matchStyle = function (styleRules, data) {
19
+ static matchStyle(styleRules, data) {
33
20
  if (data === undefined) {
34
21
  return;
35
22
  }
36
- for (var i = 0; i < styleRules.length; ++i) {
23
+ for (let i = 0; i < styleRules.length; ++i) {
37
24
  if (styleRules[i].canApplyTo(data)) {
38
25
  return styleRules[i];
39
26
  }
40
27
  }
41
- };
28
+ }
42
29
  /**
43
30
  * Generate color for a given edge (call only if _rulesMap.color exists)
44
31
  */
45
- EdgeAttributes.prototype.color = function (data) {
32
+ color(data) {
46
33
  if (!tools_1.Tools.isDefined(data)) {
47
34
  return itemAttributes_1.BASE_GREY;
48
35
  }
49
- var color;
50
- for (var j = 0; j < this._rulesMap.color.length; ++j) {
51
- var rule = this._rulesMap.color[j];
36
+ let color;
37
+ for (let j = 0; j < this._rulesMap.color.length; ++j) {
38
+ const rule = this._rulesMap.color[j];
52
39
  if (rule.canApplyTo(data)) {
53
40
  if (typeof rule.style.color === 'string') {
54
41
  color = rule.style.color;
55
42
  }
56
43
  else if (typeof rule.style.color === 'object') {
57
- var propValue = tools_1.Tools.getIn(data, rule.style.color.input);
58
- color = itemAttributes_1.ItemAttributes.autoColor("" + propValue, rule.style.ignoreCase);
44
+ const propValue = tools_1.Tools.getIn(data, rule.style.color.input);
45
+ color = itemAttributes_1.ItemAttributes.autoColor(`${propValue}`, rule.style.ignoreCase);
59
46
  }
60
47
  break;
61
48
  }
62
49
  }
63
50
  return tools_1.Tools.isDefined(color) ? color : itemAttributes_1.BASE_GREY;
64
- };
51
+ }
65
52
  /**
66
53
  * Generate shape for a given node
67
54
  */
68
- EdgeAttributes.prototype.shape = function (data) {
55
+ shape(data) {
69
56
  var _a;
70
57
  if (this._rulesMap.shape !== undefined) {
71
58
  return (_a = EdgeAttributes.matchStyle(this._rulesMap.shape, data)) === null || _a === void 0 ? void 0 : _a.style.shape;
72
59
  }
73
- };
60
+ }
74
61
  /**
75
62
  * Generate size for a given node
76
63
  */
77
- EdgeAttributes.prototype.width = function (data) {
78
- var _a;
64
+ width(data) {
79
65
  if (this._rulesMap.width !== undefined) {
80
- var styleRule = EdgeAttributes.matchStyle(this._rulesMap.width, data);
81
- var widthStyle = (_a = styleRule) === null || _a === void 0 ? void 0 : _a.style.width;
66
+ const styleRule = EdgeAttributes.matchStyle(this._rulesMap.width, data);
67
+ const widthStyle = styleRule === null || styleRule === void 0 ? void 0 : styleRule.style.width;
82
68
  if (tools_1.Tools.isDefined(styleRule) && widthStyle.type === 'autoRange') {
83
69
  if (widthStyle.input !== undefined &&
84
70
  widthStyle.max !== undefined &&
85
71
  widthStyle.min !== undefined) {
86
- var propertyName = widthStyle.input[1];
87
- var propertyValue = tools_1.Tools.parseNumber(data.properties[propertyName]);
72
+ const propertyName = widthStyle.input[1];
73
+ const propertyValue = tools_1.Tools.parseNumber(data.properties[propertyName]);
88
74
  //to update with the correct enum type
89
- var isLog = widthStyle.scale && widthStyle.scale === 'logarithmic';
75
+ const isLog = widthStyle.scale && widthStyle.scale === 'logarithmic';
90
76
  return EdgeAttributes.getAutomaticRangeWidth(propertyValue, styleRule, isLog);
91
77
  }
92
78
  }
@@ -94,23 +80,22 @@ var EdgeAttributes = /** @class */ (function (_super) {
94
80
  return widthStyle;
95
81
  }
96
82
  }
97
- };
83
+ }
98
84
  /**
99
85
  * return the corresponding width to the value
100
86
  * @param value
101
87
  * @param rule
102
88
  * @param isLog
103
89
  */
104
- EdgeAttributes.getAutomaticRangeWidth = function (value, rule, isLog) {
105
- if (isLog === void 0) { isLog = false; }
90
+ static getAutomaticRangeWidth(value, rule, isLog = false) {
106
91
  return isLog
107
92
  ? this.getAutomaticRangeStyleLog(value, rule.style.width, EdgeWidthExtrema.MIN, EdgeWidthExtrema.MAX)
108
93
  : this.getAutomaticRangeStyleLinear(value, rule.style.width, EdgeWidthExtrema.MIN, EdgeWidthExtrema.MAX);
109
- };
94
+ }
110
95
  /**
111
96
  * Return an object containing all node attributes needed by Ogma to style a node
112
97
  */
113
- EdgeAttributes.prototype.all = function (data) {
98
+ all(data) {
114
99
  if (!tools_1.Tools.isDefined(data)) {
115
100
  return {
116
101
  color: itemAttributes_1.BASE_GREY,
@@ -123,8 +108,7 @@ var EdgeAttributes = /** @class */ (function (_super) {
123
108
  shape: this.shape(data),
124
109
  width: this.width(data)
125
110
  };
126
- };
127
- return EdgeAttributes;
128
- }(itemAttributes_1.ItemAttributes));
111
+ }
112
+ }
129
113
  exports.EdgeAttributes = EdgeAttributes;
130
114
  //# sourceMappingURL=edgeAttributes.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"edgeAttributes.js","sourceRoot":"","sources":["../../src/styles/edgeAttributes.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;;;;;;;;;;AAEb,uDAAkE;AAElE,wCAAqC;AAGrC,mDAA2D;AAE3D,IAAY,gBAGX;AAHD,WAAY,gBAAgB;IAC1B,sDAAQ,CAAA;IACR,uDAAS,CAAA;AACX,CAAC,EAHW,gBAAgB,GAAhB,wBAAgB,KAAhB,wBAAgB,QAG3B;AAED;IAAoC,kCAAc;IAChD,wBAAY,QAIX;eACC,kBAAM,QAAQ,CAAC;IACjB,CAAC;IAED;;OAEG;IACY,yBAAU,GAAzB,UAA0B,UAA4B,EAAE,IAAgB;QACtE,IAAI,IAAI,KAAK,SAAS,EAAE;YACtB,OAAO;SACR;QACD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,UAAU,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE;YAC1C,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;gBAClC,OAAO,UAAU,CAAC,CAAC,CAAC,CAAC;aACtB;SACF;IACH,CAAC;IAED;;OAEG;IACI,8BAAK,GAAZ,UAAa,IAAgB;QAC3B,IAAI,CAAC,aAAK,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE;YAC1B,OAAO,0BAAS,CAAC;SAClB;QACD,IAAI,KAAK,CAAC;QACV,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,KAAM,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE;YACrD,IAAM,IAAI,GAAG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D,OAAO;YACL,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;YACvB,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;YACvB,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;SACxB,CAAC;IACJ,CAAC;IACH,qBAAC;AAAD,CAAC,AA7HD,CAAoC,+BAAc,GA6HjD;AA7HY,wCAAc","sourcesContent":["'use strict';\nimport {Color} from '@linkurious/ogma';\nimport {LkEdgeData, OgmaEdgeShape} from '@linkurious/rest-client';\n\nimport {Tools} from '../tools/tools';\n\nimport {StyleRule} from './styleRule';\nimport {BASE_GREY, ItemAttributes} from './itemAttributes';\n\nexport enum EdgeWidthExtrema {\n MIN = 50,\n MAX = 200\n}\n\nexport class EdgeAttributes extends ItemAttributes {\n constructor(rulesMap: {\n color?: Array<StyleRule>;\n shape?: Array<StyleRule>;\n width?: Array<StyleRule>;\n }) {\n super(rulesMap);\n }\n\n /**\n * Return rule that can be applied to the data\n */\n private static matchStyle(styleRules: Array<StyleRule>, data: LkEdgeData): StyleRule | undefined {\n if (data === undefined) {\n return;\n }\n for (let i = 0; i < styleRules.length; ++i) {\n if (styleRules[i].canApplyTo(data)) {\n return styleRules[i];\n }\n }\n }\n\n /**\n * Generate color for a given edge (call only if _rulesMap.color exists)\n */\n public color(data: LkEdgeData): Color {\n if (!Tools.isDefined(data)) {\n return BASE_GREY;\n }\n let color;\n for (let j = 0; j < this._rulesMap.color!.length; ++j) {\n const rule = this._rulesMap.color![j];\n if (rule.canApplyTo(data)) {\n if (typeof rule.style.color === 'string') {\n color = rule.style.color;\n } else if (typeof rule.style.color === 'object') {\n const propValue = Tools.getIn(data, rule.style.color.input);\n color = ItemAttributes.autoColor(`${propValue}`, rule.style.ignoreCase);\n }\n break;\n }\n }\n return Tools.isDefined(color) ? color : BASE_GREY;\n }\n\n /**\n * Generate shape for a given node\n */\n public shape(data: LkEdgeData): OgmaEdgeShape | undefined {\n if (this._rulesMap.shape !== undefined) {\n return EdgeAttributes.matchStyle(this._rulesMap.shape, data)?.style.shape;\n }\n }\n\n /**\n * Generate size for a given node\n */\n public width(data: LkEdgeData): string | undefined {\n if (this._rulesMap.width !== undefined) {\n const styleRule = EdgeAttributes.matchStyle(this._rulesMap.width, data);\n const widthStyle = styleRule?.style.width;\n if (Tools.isDefined(styleRule) && widthStyle.type === 'autoRange') {\n if (\n widthStyle.input !== undefined &&\n widthStyle.max !== undefined &&\n widthStyle.min !== undefined\n ) {\n const propertyName: string = widthStyle.input[1];\n const propertyValue = Tools.parseNumber(data.properties[propertyName]);\n //to update with the correct enum type\n const isLog = widthStyle.scale && widthStyle.scale === 'logarithmic';\n return EdgeAttributes.getAutomaticRangeWidth(propertyValue, styleRule, isLog);\n }\n } else {\n return widthStyle;\n }\n }\n }\n\n /**\n * return the corresponding width to the value\n * @param value\n * @param rule\n * @param isLog\n */\n public static getAutomaticRangeWidth(value: number, rule: StyleRule, isLog = false): string {\n return isLog\n ? this.getAutomaticRangeStyleLog(\n value,\n rule.style.width,\n EdgeWidthExtrema.MIN,\n EdgeWidthExtrema.MAX\n )\n : this.getAutomaticRangeStyleLinear(\n value,\n rule.style.width,\n EdgeWidthExtrema.MIN,\n EdgeWidthExtrema.MAX\n );\n }\n\n /**\n * Return an object containing all node attributes needed by Ogma to style a node\n */\n public all(\n data: LkEdgeData\n ): {\n color: Color;\n shape: OgmaEdgeShape | undefined;\n width: string | undefined;\n } {\n if (!Tools.isDefined(data)) {\n return {\n color: BASE_GREY,\n shape: OgmaEdgeShape.ARROW,\n width: '100%'\n };\n }\n return {\n color: this.color(data),\n shape: this.shape(data),\n width: this.width(data)\n };\n }\n}\n"]}
1
+ {"version":3,"file":"edgeAttributes.js","sourceRoot":"","sources":["../../src/styles/edgeAttributes.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;AAEb,yDAAkE;AAElE,0CAAqC;AAGrC,qDAA2D;AAE3D,IAAY,gBAGX;AAHD,WAAY,gB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,KAAK,GAAG,UAAU,CAAC,KAAK,IAAI,UAAU,CAAC,KAAK,KAAK,aAAa,CAAC;oBACrE,OAAO,cAAc,CAAC,sBAAsB,CAAC,aAAa,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;iBAC/E;aACF;iBAAM;gBACL,OAAO,UAAU,CAAC;aACnB;SACF;IACH,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,sBAAsB,CAAC,KAAa,EAAE,IAAe,EAAE,KAAK,GAAG,KAAK;QAChF,OAAO,KAAK;YACV,CAAC,CAAC,IAAI,CAAC,yBAAyB,CAC5B,KAAK,EACL,IAAI,CAAC,KAAK,CAAC,KAAK,EAChB,gBAAgB,CAAC,GAAG,EACpB,gBAAgB,CAAC,GAAG,CACrB;YACH,CAAC,CAAC,IAAI,CAAC,4BAA4B,CAC/B,KAAK,EACL,IAAI,CAAC,KAAK,CAAC,KAAK,EAChB,gBAAgB,CAAC,GAAG,EACpB,gBAAgB,CAAC,GAAG,CACrB,CAAC;IACR,CAAC;IAED;;OAEG;IACI,GAAG,CACR,IAAgB;QAMhB,IAAI,CAAC,aAAK,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE;YAC1B,OAAO;gBACL,KAAK,EAAE,0BAAS;gBAChB,KAAK,EAAE,2BAAa,CAAC,KAAK;gBAC1B,KAAK,EAAE,MAAM;aACd,CAAC;SACH;QACD,OAAO;YACL,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;YACvB,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;YACvB,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;SACxB,CAAC;IACJ,CAAC;CACF;AA7HD,wCA6HC","sourcesContent":["'use strict';\nimport {Color} from '@linkurious/ogma';\nimport {LkEdgeData, OgmaEdgeShape} from '@linkurious/rest-client';\n\nimport {Tools} from '../tools/tools';\n\nimport {StyleRule} from './styleRule';\nimport {BASE_GREY, ItemAttributes} from './itemAttributes';\n\nexport enum EdgeWidthExtrema {\n MIN = 50,\n MAX = 200\n}\n\nexport class EdgeAttributes extends ItemAttributes {\n constructor(rulesMap: {\n color?: Array<StyleRule>;\n shape?: Array<StyleRule>;\n width?: Array<StyleRule>;\n }) {\n super(rulesMap);\n }\n\n /**\n * Return rule that can be applied to the data\n */\n private static matchStyle(styleRules: Array<StyleRule>, data: LkEdgeData): StyleRule | undefined {\n if (data === undefined) {\n return;\n }\n for (let i = 0; i < styleRules.length; ++i) {\n if (styleRules[i].canApplyTo(data)) {\n return styleRules[i];\n }\n }\n }\n\n /**\n * Generate color for a given edge (call only if _rulesMap.color exists)\n */\n public color(data: LkEdgeData): Color {\n if (!Tools.isDefined(data)) {\n return BASE_GREY;\n }\n let color;\n for (let j = 0; j < this._rulesMap.color!.length; ++j) {\n const rule = this._rulesMap.color![j];\n if (rule.canApplyTo(data)) {\n if (typeof rule.style.color === 'string') {\n color = rule.style.color;\n } else if (typeof rule.style.color === 'object') {\n const propValue = Tools.getIn(data, rule.style.color.input);\n color = ItemAttributes.autoColor(`${propValue}`, rule.style.ignoreCase);\n }\n break;\n }\n }\n return Tools.isDefined(color) ? color : BASE_GREY;\n }\n\n /**\n * Generate shape for a given node\n */\n public shape(data: LkEdgeData): OgmaEdgeShape | undefined {\n if (this._rulesMap.shape !== undefined) {\n return EdgeAttributes.matchStyle(this._rulesMap.shape, data)?.style.shape;\n }\n }\n\n /**\n * Generate size for a given node\n */\n public width(data: LkEdgeData): string | undefined {\n if (this._rulesMap.width !== undefined) {\n const styleRule = EdgeAttributes.matchStyle(this._rulesMap.width, data);\n const widthStyle = styleRule?.style.width;\n if (Tools.isDefined(styleRule) && widthStyle.type === 'autoRange') {\n if (\n widthStyle.input !== undefined &&\n widthStyle.max !== undefined &&\n widthStyle.min !== undefined\n ) {\n const propertyName: string = widthStyle.input[1];\n const propertyValue = Tools.parseNumber(data.properties[propertyName]);\n //to update with the correct enum type\n const isLog = widthStyle.scale && widthStyle.scale === 'logarithmic';\n return EdgeAttributes.getAutomaticRangeWidth(propertyValue, styleRule, isLog);\n }\n } else {\n return widthStyle;\n }\n }\n }\n\n /**\n * return the corresponding width to the value\n * @param value\n * @param rule\n * @param isLog\n */\n public static getAutomaticRangeWidth(value: number, rule: StyleRule, isLog = false): string {\n return isLog\n ? this.getAutomaticRangeStyleLog(\n value,\n rule.style.width,\n EdgeWidthExtrema.MIN,\n EdgeWidthExtrema.MAX\n )\n : this.getAutomaticRangeStyleLinear(\n value,\n rule.style.width,\n EdgeWidthExtrema.MIN,\n EdgeWidthExtrema.MAX\n );\n }\n\n /**\n * Return an object containing all node attributes needed by Ogma to style a node\n */\n public all(\n data: LkEdgeData\n ): {\n color: Color;\n shape: OgmaEdgeShape | undefined;\n width: string | undefined;\n } {\n if (!Tools.isDefined(data)) {\n return {\n color: BASE_GREY,\n shape: OgmaEdgeShape.ARROW,\n width: '100%'\n };\n }\n return {\n color: this.color(data),\n shape: this.shape(data),\n width: this.width(data)\n };\n }\n}\n"]}
@@ -1,17 +1,11 @@
1
1
  'use strict';
2
- var __spreadArrays = (this && this.__spreadArrays) || function () {
3
- for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
4
- for (var r = Array(s), k = 0, i = 0; i < il; i++)
5
- for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
6
- r[k] = a[j];
7
- return r;
8
- };
9
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
10
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
11
4
  };
12
5
  Object.defineProperty(exports, "__esModule", { value: true });
13
- var sha1_1 = __importDefault(require("sha1"));
14
- var tools_1 = require("../tools/tools");
6
+ exports.ItemAttributes = exports.PALETTE = exports.BASE_GREY = void 0;
7
+ const sha1_1 = __importDefault(require("sha1"));
8
+ const tools_1 = require("../tools/tools");
15
9
  exports.BASE_GREY = '#7f7f7f';
16
10
  exports.PALETTE = [
17
11
  '#9467bd',
@@ -33,8 +27,8 @@ exports.PALETTE = [
33
27
  '#ffbb78',
34
28
  '#c49c94'
35
29
  ];
36
- var ItemAttributes = /** @class */ (function () {
37
- function ItemAttributes(rulesMap) {
30
+ class ItemAttributes {
31
+ constructor(rulesMap) {
38
32
  this.colorsCache = new Map();
39
33
  this._rulesMap = {};
40
34
  this.refresh(rulesMap);
@@ -42,41 +36,41 @@ var ItemAttributes = /** @class */ (function () {
42
36
  /**
43
37
  * Refresh the rules
44
38
  */
45
- ItemAttributes.prototype.refresh = function (rulesMap) {
39
+ refresh(rulesMap) {
46
40
  if (rulesMap.color !== undefined) {
47
41
  this.colorsCache = new Map();
48
42
  }
49
43
  this._rulesMap = {
50
- color: rulesMap.color ? __spreadArrays(rulesMap.color).reverse() : this._rulesMap.color,
51
- icon: rulesMap.icon ? __spreadArrays(rulesMap.icon).reverse() : this._rulesMap.icon,
52
- image: rulesMap.image ? __spreadArrays(rulesMap.image).reverse() : this._rulesMap.image,
53
- shape: rulesMap.shape ? __spreadArrays(rulesMap.shape).reverse() : this._rulesMap.shape,
54
- size: rulesMap.size ? __spreadArrays(rulesMap.size).reverse() : this._rulesMap.size,
55
- width: rulesMap.width ? __spreadArrays(rulesMap.width).reverse() : this._rulesMap.width
44
+ color: rulesMap.color ? [...rulesMap.color].reverse() : this._rulesMap.color,
45
+ icon: rulesMap.icon ? [...rulesMap.icon].reverse() : this._rulesMap.icon,
46
+ image: rulesMap.image ? [...rulesMap.image].reverse() : this._rulesMap.image,
47
+ shape: rulesMap.shape ? [...rulesMap.shape].reverse() : this._rulesMap.shape,
48
+ size: rulesMap.size ? [...rulesMap.size].reverse() : this._rulesMap.size,
49
+ width: rulesMap.width ? [...rulesMap.width].reverse() : this._rulesMap.width
56
50
  };
57
- };
51
+ }
58
52
  /**
59
53
  * Return the color for a node when style color is auto
60
54
  */
61
- ItemAttributes.autoColor = function (value, ignoreCase) {
55
+ static autoColor(value, ignoreCase) {
62
56
  if (!tools_1.Tools.isDefined(value)) {
63
57
  return exports.BASE_GREY;
64
58
  }
65
59
  return exports.PALETTE[ItemAttributes.getRandomUniqueColorPaletteIndex(value, exports.PALETTE.length, ignoreCase)];
66
- };
60
+ }
67
61
  /**
68
62
  * Return a number from 0 to number of occurrence in a palette based on a property
69
63
  */
70
- ItemAttributes.getRandomUniqueColorPaletteIndex = function (input, modulo, ignoreCase) {
64
+ static getRandomUniqueColorPaletteIndex(input, modulo, ignoreCase) {
71
65
  if (ignoreCase) {
72
66
  input = input.toLowerCase();
73
67
  }
74
- return +('0x' + sha1_1.default(input).substr(-4)) % modulo;
75
- };
68
+ return +('0x' + (0, sha1_1.default)(input).substr(-4)) % modulo;
69
+ }
76
70
  /**
77
71
  * Get color of a type
78
72
  */
79
- ItemAttributes.getTypeColor = function (rule, type) {
73
+ static getTypeColor(rule, type) {
80
74
  if (typeof rule.style.color === 'object' && rule.style.color.input[0] !== 'properties') {
81
75
  return ItemAttributes.autoColor(type, rule.style.color.ignoreCase);
82
76
  }
@@ -84,7 +78,7 @@ var ItemAttributes = /** @class */ (function () {
84
78
  return rule.style.color;
85
79
  }
86
80
  return null;
87
- };
81
+ }
88
82
  /**
89
83
  * return the corresponding size to the value with a linear function
90
84
  * @param value
@@ -92,18 +86,17 @@ var ItemAttributes = /** @class */ (function () {
92
86
  * @param higher
93
87
  * @param extrema
94
88
  */
95
- ItemAttributes.getAutomaticRangeStyleLinear = function (value, _a, lower, higher) {
96
- var max = _a.max, min = _a.min;
89
+ static getAutomaticRangeStyleLinear(value, { max, min }, lower, higher) {
97
90
  // apply default style when min equal max
98
91
  if (max === min || isNaN(value)) {
99
92
  return '100%';
100
93
  }
101
94
  // calculate the linear function f(x) = ax + b
102
- var a = (higher - lower) / (max - min);
103
- var b = (lower * max - higher * min) / (max - min);
104
- var size = Math.floor(value * a + b);
105
- return size + "%";
106
- };
95
+ const a = (higher - lower) / (max - min);
96
+ const b = (lower * max - higher * min) / (max - min);
97
+ const size = Math.floor(value * a + b);
98
+ return `${size}%`;
99
+ }
107
100
  /**
108
101
  * return the corresponding size to the value with a logarithmic function
109
102
  * @param value
@@ -111,8 +104,7 @@ var ItemAttributes = /** @class */ (function () {
111
104
  * @param higher
112
105
  * @param extrema
113
106
  */
114
- ItemAttributes.getAutomaticRangeStyleLog = function (value, _a, lower, higher) {
115
- var max = _a.max, min = _a.min;
107
+ static getAutomaticRangeStyleLog(value, { max, min }, lower, higher) {
116
108
  // apply default style when min equal max
117
109
  if (max === min || isNaN(value)) {
118
110
  return '100%';
@@ -124,12 +116,11 @@ var ItemAttributes = /** @class */ (function () {
124
116
  min += Math.abs(min) + 1;
125
117
  }
126
118
  // calculate the logarithmic function f(x) = Math.floor(a*log(x) + b)
127
- var a = (higher - lower) / (Math.log(max) - Math.log(min));
128
- var b = (lower * Math.log(max) - higher * Math.log(min)) / (Math.log(max) - Math.log(min));
129
- var size = Math.floor(a * Math.log(value) + b);
130
- return size + "%";
131
- };
132
- return ItemAttributes;
133
- }());
119
+ const a = (higher - lower) / (Math.log(max) - Math.log(min));
120
+ const b = (lower * Math.log(max) - higher * Math.log(min)) / (Math.log(max) - Math.log(min));
121
+ const size = Math.floor(a * Math.log(value) + b);
122
+ return `${size}%`;
123
+ }
124
+ }
134
125
  exports.ItemAttributes = ItemAttributes;
135
126
  //# sourceMappingURL=itemAttributes.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"itemAttributes.js","sourceRoot":"","sources":["../../src/styles/itemAttributes.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;;;;;;;AAEb,8CAAwB;AAGxB,wCAAqC;AAMxB,QAAA,SAAS,GAAG,SAAS,CAAC;AACtB,QAAA,OAAO,GAAG;IACrB,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;CACV,CAAC;AAEF;IAWE,wBAAY,QAOX;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AG,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;QAC7F,IAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;QAEjD,OAAU,IAAI,MAAG,CAAC;IACpB,CAAC;IACH,qBAAC;AAAD,CAAC,AA7ID,IA6IC;AA7IY,wCAAc","sourcesContent":["'use strict';\n\nimport sha1 from 'sha1';\nimport {Color} from '@linkurious/ogma';\n\nimport {Tools} from '../tools/tools';\n\nimport {StyleRule} from './styleRule';\nimport {NodeSizeExtrema} from './nodeAttributes';\nimport {EdgeWidthExtrema} from './edgeAttributes';\n\nexport const BASE_GREY = '#7f7f7f';\nexport const PALETTE = [\n '#9467bd',\n '#e377c2',\n '#1f77b4',\n '#17becf',\n '#2ca02c',\n '#bcbd22',\n '#d62728',\n '#ff7f0e',\n '#8c564b',\n '#c5b0d5',\n '#f7b6d2',\n '#aec7e8',\n '#9edae5',\n '#98df8a',\n '#dbdb8d',\n '#ff9896',\n '#ffbb78',\n '#c49c94'\n];\n\nexport class ItemAttributes {\n protected colorsCache: Map<string, Color | Array<Color>> = new Map();\n protected _rulesMap: {\n color?: Array<StyleRule>;\n icon?: Array<StyleRule>;\n image?: Array<StyleRule>;\n shape?: Array<StyleRule>;\n size?: Array<StyleRule>;\n width?: Array<StyleRule>;\n } = {};\n\n constructor(rulesMap: {\n color?: Array<StyleRule>;\n icon?: Array<StyleRule>;\n image?: Array<StyleRule>;\n shape?: Array<StyleRule>;\n size?: Array<StyleRule>;\n width?: Array<StyleRule>;\n }) {\n this.refresh(rulesMap);\n }\n\n /**\n * Refresh the rules\n */\n public refresh(rulesMap: {\n color?: Array<StyleRule>;\n icon?: Array<StyleRule>;\n image?: Array<StyleRule>;\n shape?: Array<StyleRule>;\n size?: Array<StyleRule>;\n width?: Array<StyleRule>;\n }): void {\n if (rulesMap.color !== undefined) {\n this.colorsCache = new Map();\n }\n this._rulesMap = {\n color: rulesMap.color ? [...rulesMap.color].reverse() : this._rulesMap.color,\n icon: rulesMap.icon ? [...rulesMap.icon].reverse() : this._rulesMap.icon,\n image: rulesMap.image ? [...rulesMap.image].reverse() : this._rulesMap.image,\n shape: rulesMap.shape ? [...rulesMap.shape].reverse() : this._rulesMap.shape,\n size: rulesMap.size ? [...rulesMap.size].reverse() : this._rulesMap.size,\n width: rulesMap.width ? [...rulesMap.width].reverse() : this._rulesMap.width\n };\n }\n\n /**\n * Return the color for a node when style color is auto\n */\n public static autoColor(value: string, ignoreCase?: boolean): string {\n if (!Tools.isDefined(value)) {\n return BASE_GREY;\n }\n return PALETTE[\n ItemAttributes.getRandomUniqueColorPaletteIndex(value, PALETTE.length, ignoreCase)\n ];\n }\n\n /**\n * Return a number from 0 to number of occurrence in a palette based on a property\n */\n private static getRandomUniqueColorPaletteIndex(\n input: string,\n modulo: number,\n ignoreCase: boolean | undefined\n ): number {\n if (ignoreCase) {\n input = input.toLowerCase();\n }\n return +('0x' + sha1(input).substr(-4)) % modulo;\n }\n\n /**\n * Get color of a type\n */\n public static getTypeColor(rule: StyleRule, type: string): string | null {\n if (typeof rule.style.color === 'object' && rule.style.color.input[0] !== 'properties') {\n return ItemAttributes.autoColor(type, rule.style.color.ignoreCase);\n }\n if (!Tools.isDefined(rule.input) && typeof rule.style.color !== 'object') {\n return rule.style.color;\n }\n return null;\n }\n\n /**\n * return the corresponding size to the value with a linear function\n * @param value\n * @param lower\n * @param higher\n * @param extrema\n */\n public static getAutomaticRangeStyleLinear(\n value: number,\n {max, min}: {max: number; min: number},\n lower: EdgeWidthExtrema | NodeSizeExtrema,\n higher: EdgeWidthExtrema | NodeSizeExtrema\n ): string {\n // apply default style when min equal max\n if (max === min || isNaN(value)) {\n return '100%';\n }\n\n // calculate the linear function f(x) = ax + b\n const a = (higher - lower) / (max - min);\n const b = (lower * max - higher * min) / (max - min);\n const size = Math.floor(value * a + b);\n\n return `${size}%`;\n }\n\n /**\n * return the corresponding size to the value with a logarithmic function\n * @param value\n * @param lower\n * @param higher\n * @param extrema\n */\n public static getAutomaticRangeStyleLog(\n value: number,\n {max, min}: {max: number; min: number},\n lower: EdgeWidthExtrema | NodeSizeExtrema,\n higher: EdgeWidthExtrema | NodeSizeExtrema\n ): string {\n // apply default style when min equal max\n if (max === min || isNaN(value)) {\n return '100%';\n }\n // apply an offset for all the values (including min and max)\n if (min < 1) {\n value += Math.abs(min) + 1;\n max += Math.abs(min) + 1;\n min += Math.abs(min) + 1;\n }\n // calculate the logarithmic function f(x) = Math.floor(a*log(x) + b)\n const a = (higher - lower) / (Math.log(max) - Math.log(min));\n const b = (lower * Math.log(max) - higher * Math.log(min)) / (Math.log(max) - Math.log(min));\n const size = Math.floor(a * Math.log(value) + b);\n\n return `${size}%`;\n }\n}\n"]}
1
+ {"version":3,"file":"itemAttributes.js","sourceRoot":"","sources":["../../src/styles/itemAttributes.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;AAEb,gDAAwB;AAGxB,0CAAqC;AAMxB,QAAA,SAAS,GAAG,SAAS,CAAC;AACtB,QAAA,OAAO,GAAG;IACrB,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;CACV,CAAC;AAEF,MAAa,cAAc;IAWzB,YAAY,QAOX;QAjBS,gBAAW,GAAsC,IAAI,GAAG,EAAE,CAAC;QAC3D,cAAS,GAOf,EAAE,CAAC;QAUL,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IACzB,CAAC;IAED;;OAEG;IACI,OAAO,CAAC,QAOd;QACC,IAAI,QAAQ,CAAC,KAAK,KAAK,SAAS,EAAE;YAChC,IA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I,CAAC,KAAK,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;QAEjD,OAAO,GAAG,IAAI,GAAG,CAAC;IACpB,CAAC;CACF;AA7ID,wCA6IC","sourcesContent":["'use strict';\n\nimport sha1 from 'sha1';\nimport {Color} from '@linkurious/ogma';\n\nimport {Tools} from '../tools/tools';\n\nimport {StyleRule} from './styleRule';\nimport {NodeSizeExtrema} from './nodeAttributes';\nimport {EdgeWidthExtrema} from './edgeAttributes';\n\nexport const BASE_GREY = '#7f7f7f';\nexport const PALETTE = [\n '#9467bd',\n '#e377c2',\n '#1f77b4',\n '#17becf',\n '#2ca02c',\n '#bcbd22',\n '#d62728',\n '#ff7f0e',\n '#8c564b',\n '#c5b0d5',\n '#f7b6d2',\n '#aec7e8',\n '#9edae5',\n '#98df8a',\n '#dbdb8d',\n '#ff9896',\n '#ffbb78',\n '#c49c94'\n];\n\nexport class ItemAttributes {\n protected colorsCache: Map<string, Color | Array<Color>> = new Map();\n protected _rulesMap: {\n color?: Array<StyleRule>;\n icon?: Array<StyleRule>;\n image?: Array<StyleRule>;\n shape?: Array<StyleRule>;\n size?: Array<StyleRule>;\n width?: Array<StyleRule>;\n } = {};\n\n constructor(rulesMap: {\n color?: Array<StyleRule>;\n icon?: Array<StyleRule>;\n image?: Array<StyleRule>;\n shape?: Array<StyleRule>;\n size?: Array<StyleRule>;\n width?: Array<StyleRule>;\n }) {\n this.refresh(rulesMap);\n }\n\n /**\n * Refresh the rules\n */\n public refresh(rulesMap: {\n color?: Array<StyleRule>;\n icon?: Array<StyleRule>;\n image?: Array<StyleRule>;\n shape?: Array<StyleRule>;\n size?: Array<StyleRule>;\n width?: Array<StyleRule>;\n }): void {\n if (rulesMap.color !== undefined) {\n this.colorsCache = new Map();\n }\n this._rulesMap = {\n color: rulesMap.color ? [...rulesMap.color].reverse() : this._rulesMap.color,\n icon: rulesMap.icon ? [...rulesMap.icon].reverse() : this._rulesMap.icon,\n image: rulesMap.image ? [...rulesMap.image].reverse() : this._rulesMap.image,\n shape: rulesMap.shape ? [...rulesMap.shape].reverse() : this._rulesMap.shape,\n size: rulesMap.size ? [...rulesMap.size].reverse() : this._rulesMap.size,\n width: rulesMap.width ? [...rulesMap.width].reverse() : this._rulesMap.width\n };\n }\n\n /**\n * Return the color for a node when style color is auto\n */\n public static autoColor(value: string, ignoreCase?: boolean): string {\n if (!Tools.isDefined(value)) {\n return BASE_GREY;\n }\n return PALETTE[\n ItemAttributes.getRandomUniqueColorPaletteIndex(value, PALETTE.length, ignoreCase)\n ];\n }\n\n /**\n * Return a number from 0 to number of occurrence in a palette based on a property\n */\n private static getRandomUniqueColorPaletteIndex(\n input: string,\n modulo: number,\n ignoreCase: boolean | undefined\n ): number {\n if (ignoreCase) {\n input = input.toLowerCase();\n }\n return +('0x' + sha1(input).substr(-4)) % modulo;\n }\n\n /**\n * Get color of a type\n */\n public static getTypeColor(rule: StyleRule, type: string): string | null {\n if (typeof rule.style.color === 'object' && rule.style.color.input[0] !== 'properties') {\n return ItemAttributes.autoColor(type, rule.style.color.ignoreCase);\n }\n if (!Tools.isDefined(rule.input) && typeof rule.style.color !== 'object') {\n return rule.style.color;\n }\n return null;\n }\n\n /**\n * return the corresponding size to the value with a linear function\n * @param value\n * @param lower\n * @param higher\n * @param extrema\n */\n public static getAutomaticRangeStyleLinear(\n value: number,\n {max, min}: {max: number; min: number},\n lower: EdgeWidthExtrema | NodeSizeExtrema,\n higher: EdgeWidthExtrema | NodeSizeExtrema\n ): string {\n // apply default style when min equal max\n if (max === min || isNaN(value)) {\n return '100%';\n }\n\n // calculate the linear function f(x) = ax + b\n const a = (higher - lower) / (max - min);\n const b = (lower * max - higher * min) / (max - min);\n const size = Math.floor(value * a + b);\n\n return `${size}%`;\n }\n\n /**\n * return the corresponding size to the value with a logarithmic function\n * @param value\n * @param lower\n * @param higher\n * @param extrema\n */\n public static getAutomaticRangeStyleLog(\n value: number,\n {max, min}: {max: number; min: number},\n lower: EdgeWidthExtrema | NodeSizeExtrema,\n higher: EdgeWidthExtrema | NodeSizeExtrema\n ): string {\n // apply default style when min equal max\n if (max === min || isNaN(value)) {\n return '100%';\n }\n // apply an offset for all the values (including min and max)\n if (min < 1) {\n value += Math.abs(min) + 1;\n max += Math.abs(min) + 1;\n min += Math.abs(min) + 1;\n }\n // calculate the logarithmic function f(x) = Math.floor(a*log(x) + b)\n const a = (higher - lower) / (Math.log(max) - Math.log(min));\n const b = (lower * Math.log(max) - higher * Math.log(min)) / (Math.log(max) - Math.log(min));\n const size = Math.floor(a * Math.log(value) + b);\n\n return `${size}%`;\n }\n}\n"]}
@@ -1,76 +1,56 @@
1
1
  'use strict';
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- extendStatics(d, b);
11
- function __() { this.constructor = d; }
12
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13
- };
14
- })();
15
- var __spreadArrays = (this && this.__spreadArrays) || function () {
16
- for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
17
- for (var r = Array(s), k = 0, i = 0; i < il; i++)
18
- for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
19
- r[k] = a[j];
20
- return r;
21
- };
22
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
23
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
24
4
  };
25
5
  Object.defineProperty(exports, "__esModule", { value: true });
26
- var sha1_1 = __importDefault(require("sha1"));
27
- var tools_1 = require("../tools/tools");
28
- var __1 = require("..");
29
- var itemAttributes_1 = require("./itemAttributes");
6
+ exports.NodeAttributes = exports.NodeSizeExtrema = void 0;
7
+ const sha1_1 = __importDefault(require("sha1"));
8
+ const tools_1 = require("../tools/tools");
9
+ const __1 = require("..");
10
+ const itemAttributes_1 = require("./itemAttributes");
30
11
  var NodeSizeExtrema;
31
12
  (function (NodeSizeExtrema) {
32
13
  NodeSizeExtrema[NodeSizeExtrema["MIN"] = 50] = "MIN";
33
14
  NodeSizeExtrema[NodeSizeExtrema["MAX"] = 500] = "MAX";
34
15
  })(NodeSizeExtrema = exports.NodeSizeExtrema || (exports.NodeSizeExtrema = {}));
35
- var NodeAttributes = /** @class */ (function (_super) {
36
- __extends(NodeAttributes, _super);
37
- function NodeAttributes(rulesMap) {
38
- return _super.call(this, rulesMap) || this;
16
+ class NodeAttributes extends itemAttributes_1.ItemAttributes {
17
+ constructor(rulesMap) {
18
+ super(rulesMap);
39
19
  }
40
20
  /**
41
21
  * Run the callback if an item match with a style in the array of rules
42
22
  */
43
- NodeAttributes.matchStyle = function (styleRules, itemData, callback) {
23
+ static matchStyle(styleRules, itemData, callback) {
44
24
  if (!tools_1.Tools.isDefined(itemData)) {
45
25
  return;
46
26
  }
47
27
  if (!tools_1.Tools.isDefined(styleRules)) {
48
28
  return;
49
29
  }
50
- for (var i = 0; i < styleRules.length; ++i) {
30
+ for (let i = 0; i < styleRules.length; ++i) {
51
31
  if (styleRules[i].canApplyTo(itemData)) {
52
32
  callback(styleRules[i]);
53
33
  break;
54
34
  }
55
35
  }
56
- };
36
+ }
57
37
  /**
58
38
  * Generate color for a given node (call only if _rulesMap.color is defined
59
39
  */
60
- NodeAttributes.prototype.color = function (itemData) {
40
+ color(itemData) {
61
41
  if (!tools_1.Tools.isDefined(itemData)) {
62
42
  return [itemAttributes_1.BASE_GREY];
63
43
  }
64
- var hash = sha1_1.default(JSON.stringify(itemData));
65
- var cachedColor = this.colorsCache.get(hash);
44
+ const hash = (0, sha1_1.default)(JSON.stringify(itemData));
45
+ const cachedColor = this.colorsCache.get(hash);
66
46
  if (cachedColor !== undefined) {
67
47
  return cachedColor;
68
48
  }
69
- var colors = [];
70
- for (var i = 0; i < itemData.categories.length; ++i) {
71
- var c = null;
72
- for (var j = 0; j < this._rulesMap.color.length; ++j) {
73
- var rule = this._rulesMap.color[j];
49
+ let colors = [];
50
+ for (let i = 0; i < itemData.categories.length; ++i) {
51
+ let c = null;
52
+ for (let j = 0; j < this._rulesMap.color.length; ++j) {
53
+ const rule = this._rulesMap.color[j];
74
54
  if (rule.itemType !== undefined &&
75
55
  rule.itemType !== null &&
76
56
  rule.itemType !== itemData.categories[i]) {
@@ -78,12 +58,12 @@ var NodeAttributes = /** @class */ (function (_super) {
78
58
  }
79
59
  if (rule.canApplyTo(itemData)) {
80
60
  if (typeof rule.style.color === 'object') {
81
- var propValue = tools_1.Tools.getIn(itemData, rule.style.color.input);
61
+ const propValue = tools_1.Tools.getIn(itemData, rule.style.color.input);
82
62
  if (Array.isArray(propValue)) {
83
63
  c = itemAttributes_1.ItemAttributes.autoColor(itemData.categories[i], rule.style.ignoreCase);
84
64
  }
85
65
  else {
86
- c = itemAttributes_1.ItemAttributes.autoColor("" + propValue, rule.style.ignoreCase);
66
+ c = itemAttributes_1.ItemAttributes.autoColor(`${propValue}`, rule.style.ignoreCase);
87
67
  }
88
68
  }
89
69
  else {
@@ -94,29 +74,29 @@ var NodeAttributes = /** @class */ (function (_super) {
94
74
  }
95
75
  colors.push(c);
96
76
  }
97
- colors = colors.filter(function (c) { return tools_1.Tools.isDefined(c); });
77
+ colors = colors.filter((c) => tools_1.Tools.isDefined(c));
98
78
  if (colors.length === 0) {
99
79
  colors = [itemAttributes_1.BASE_GREY];
100
80
  }
101
- var finalColor = colors.length === 1 ? colors[0] : colors;
81
+ const finalColor = colors.length === 1 ? colors[0] : colors;
102
82
  this.colorsCache.set(hash, finalColor);
103
83
  return finalColor;
104
- };
84
+ }
105
85
  /**
106
86
  * Generate icon for a given node
107
87
  */
108
- NodeAttributes.prototype.icon = function (itemData) {
109
- var rawColors = this.color(itemData);
110
- var color = Array.isArray(rawColors) ? rawColors[0] : rawColors;
111
- var result = {};
112
- var rules = __spreadArrays((this._rulesMap.image || []), (this._rulesMap.icon || []));
88
+ icon(itemData) {
89
+ const rawColors = this.color(itemData);
90
+ const color = Array.isArray(rawColors) ? rawColors[0] : rawColors;
91
+ let result = {};
92
+ const rules = [...(this._rulesMap.image || []), ...(this._rulesMap.icon || [])];
113
93
  if (!tools_1.Tools.isDefined(itemData)) {
114
94
  return {
115
95
  icon: {},
116
96
  image: {}
117
97
  };
118
98
  }
119
- for (var i = 0; i < rules.length; ++i) {
99
+ for (let i = 0; i < rules.length; ++i) {
120
100
  if (rules[i].canApplyTo(itemData)) {
121
101
  if ('icon' in rules[i].style) {
122
102
  result = {
@@ -146,35 +126,35 @@ var NodeAttributes = /** @class */ (function (_super) {
146
126
  }
147
127
  }
148
128
  return result;
149
- };
129
+ }
150
130
  /**
151
131
  * Generate shape for a given node
152
132
  */
153
- NodeAttributes.prototype.shape = function (itemData) {
154
- var result = undefined;
133
+ shape(itemData) {
134
+ let result = undefined;
155
135
  if (this._rulesMap.shape !== undefined) {
156
- NodeAttributes.matchStyle(this._rulesMap.shape, itemData, function (styleRule) {
136
+ NodeAttributes.matchStyle(this._rulesMap.shape, itemData, (styleRule) => {
157
137
  result = styleRule.style.shape;
158
138
  });
159
139
  }
160
140
  return result;
161
- };
141
+ }
162
142
  /**
163
143
  * Generate size for a given node
164
144
  */
165
- NodeAttributes.prototype.size = function (itemData) {
166
- var result = undefined;
145
+ size(itemData) {
146
+ let result = undefined;
167
147
  if (this._rulesMap.size !== undefined) {
168
- NodeAttributes.matchStyle(this._rulesMap.size, itemData, function (styleRule) {
169
- var sizeStyle = styleRule.style.size;
148
+ NodeAttributes.matchStyle(this._rulesMap.size, itemData, (styleRule) => {
149
+ const sizeStyle = styleRule.style.size;
170
150
  if (sizeStyle.type === 'autoRange') {
171
151
  if (sizeStyle.input !== undefined &&
172
152
  sizeStyle.max !== undefined &&
173
153
  sizeStyle.min !== undefined) {
174
- var propertyName = sizeStyle.input[1];
175
- var propertyValue = tools_1.Tools.parseNumber(itemData.properties[propertyName]);
154
+ const propertyName = sizeStyle.input[1];
155
+ const propertyValue = tools_1.Tools.parseNumber(itemData.properties[propertyName]);
176
156
  //to update with the correct enum type
177
- var isLog = sizeStyle.scale && sizeStyle.scale === 'logarithmic';
157
+ const isLog = sizeStyle.scale && sizeStyle.scale === 'logarithmic';
178
158
  result = NodeAttributes.getAutomaticRangeSize(propertyValue, styleRule, isLog);
179
159
  }
180
160
  }
@@ -184,29 +164,28 @@ var NodeAttributes = /** @class */ (function (_super) {
184
164
  });
185
165
  }
186
166
  return result;
187
- };
167
+ }
188
168
  /**
189
169
  * return the corresponding size to the value
190
170
  * @param value
191
171
  * @param rule
192
172
  * @param isLog
193
173
  */
194
- NodeAttributes.getAutomaticRangeSize = function (value, rule, isLog) {
195
- if (isLog === void 0) { isLog = false; }
174
+ static getAutomaticRangeSize(value, rule, isLog = false) {
196
175
  return isLog
197
176
  ? this.getAutomaticRangeStyleLog(value, rule.style.size, NodeSizeExtrema.MIN, NodeSizeExtrema.MAX)
198
177
  : this.getAutomaticRangeStyleLinear(value, rule.style.size, NodeSizeExtrema.MIN, NodeSizeExtrema.MAX);
199
- };
178
+ }
200
179
  /**
201
180
  * Return an object containing all node attributes needed by Ogma to style a node
202
181
  */
203
- NodeAttributes.prototype.all = function (itemData) {
182
+ all(itemData) {
204
183
  if (!tools_1.Tools.isDefined(itemData)) {
205
184
  return {
206
185
  color: itemAttributes_1.BASE_GREY
207
186
  };
208
187
  }
209
- var generatedIcon = this.icon(itemData);
188
+ const generatedIcon = this.icon(itemData);
210
189
  return {
211
190
  radius: this.size(itemData),
212
191
  color: this.color(itemData),
@@ -214,8 +193,7 @@ var NodeAttributes = /** @class */ (function (_super) {
214
193
  icon: generatedIcon.icon,
215
194
  image: generatedIcon.image
216
195
  };
217
- };
218
- return NodeAttributes;
219
- }(itemAttributes_1.ItemAttributes));
196
+ }
197
+ }
220
198
  exports.NodeAttributes = NodeAttributes;
221
199
  //# sourceMappingURL=nodeAttributes.js.map