@linkurious/ogma-linkurious-parser 3.1.12 → 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,49 +1,40 @@
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 tools_1 = require("../tools/tools");
12
- var Captions = /** @class */ (function () {
13
- function Captions() {
14
- }
3
+ const rest_client_1 = require("@linkurious/rest-client");
4
+ const tools_1 = require("../tools/tools");
5
+ class Captions {
15
6
  /**
16
7
  * Return label for each node
17
8
  */
18
- Captions.getText = function (itemData, schema, graphSchema) {
19
- var types = 'categories' in itemData ? itemData.categories : [itemData.type];
9
+ static getText(itemData, schema, graphSchema) {
10
+ const types = 'categories' in itemData ? itemData.categories : [itemData.type];
20
11
  if (Captions.captionExist(types, schema)) {
21
12
  return 'categories' in itemData
22
13
  ? Captions.generateNodeCaption(itemData, schema, graphSchema) || null
23
14
  : Captions.generateEdgeCaption(itemData, schema, graphSchema) || null;
24
15
  }
25
16
  if (itemData.properties !== undefined) {
26
- var heuristicCaptionElement = tools_1.CAPTION_HEURISTIC.find(function (value) {
17
+ const heuristicCaptionElement = tools_1.CAPTION_HEURISTIC.find((value) => {
27
18
  return itemData.properties[value] !== undefined;
28
19
  });
29
20
  if (heuristicCaptionElement !== undefined &&
30
21
  tools_1.Tools.isDefined(itemData.properties[heuristicCaptionElement])) {
31
- return ("" + tools_1.Tools.getValueFromLkProperty(itemData.properties[heuristicCaptionElement])).trim();
22
+ return `${tools_1.Tools.getValueFromLkProperty(itemData.properties[heuristicCaptionElement])}`.trim();
32
23
  }
33
24
  }
34
25
  return null;
35
- };
26
+ }
36
27
  /**
37
28
  * Return a readable string from an LkProperty
38
29
  */
39
- Captions.getLabel = function (propertyValue, propertyType) {
30
+ static getLabel(propertyValue, propertyType) {
40
31
  var _a;
41
32
  if (typeof propertyValue === 'object' && 'type' in propertyValue) {
42
33
  if (!('original' in propertyValue) && !('value' in propertyValue)) {
43
34
  return null;
44
35
  }
45
36
  if ('original' in propertyValue) {
46
- return "" + propertyValue.original;
37
+ return `${propertyValue.original}`;
47
38
  }
48
39
  if ('value' in propertyValue) {
49
40
  return tools_1.Tools.formatDate(new Date(new Date(propertyValue.value).getTime() +
@@ -54,64 +45,63 @@ var Captions = /** @class */ (function () {
54
45
  propertyType.options !== undefined) {
55
46
  return tools_1.Tools.formatCurrencyValue(propertyValue, propertyType.options);
56
47
  }
57
- return ("" + propertyValue).trim();
58
- };
48
+ return `${propertyValue}`.trim();
49
+ }
59
50
  /**
60
51
  * Return true if caption configuration exists in schema
61
52
  */
62
- Captions.captionExist = function (itemTypes, schema) {
63
- return itemTypes.some(function (type) { return tools_1.Tools.isDefined(schema[type]); });
64
- };
53
+ static captionExist(itemTypes, schema) {
54
+ return itemTypes.some((type) => tools_1.Tools.isDefined(schema[type]));
55
+ }
65
56
  /**
66
57
  * Generate text from node data and captions schema
67
58
  */
68
- Captions.generateNodeCaption = function (itemData, schema, graphSchema) {
69
- var _this = this;
70
- var categories = itemData.categories;
71
- var caption = [];
72
- var captionProps = [];
73
- categories.forEach(function (category) {
59
+ static generateNodeCaption(itemData, schema, graphSchema) {
60
+ const categories = itemData.categories;
61
+ const caption = [];
62
+ let captionProps = [];
63
+ categories.forEach((category) => {
74
64
  if (schema[category] && schema[category].active) {
75
65
  if (schema[category].displayName) {
76
66
  caption.push(category);
77
67
  }
78
- captionProps = __spreadArrays(captionProps, schema[category].properties);
68
+ captionProps = [...captionProps, ...schema[category].properties];
79
69
  }
80
70
  });
81
- tools_1.Tools.uniqBy(captionProps).forEach(function (propertyKey) {
71
+ tools_1.Tools.uniqBy(captionProps).forEach((propertyKey) => {
82
72
  if (itemData.properties[propertyKey] !== undefined) {
83
- var propertyType = graphSchema
73
+ const propertyType = graphSchema
84
74
  ? Captions.getPropertyType(graphSchema, propertyKey, categories[0])
85
75
  : undefined;
86
- caption.push(_this.getLabel(itemData.properties[propertyKey], propertyType));
76
+ caption.push(this.getLabel(itemData.properties[propertyKey], propertyType));
87
77
  }
88
78
  });
89
79
  return caption
90
- .filter(function (c) { return c !== null; })
80
+ .filter((c) => c !== null)
91
81
  .join(' - ')
92
82
  .trim();
93
- };
94
- Captions.getPropertyType = function (graphSchema, propertyKey, itemType) {
83
+ }
84
+ static getPropertyType(graphSchema, propertyKey, itemType) {
95
85
  var _a, _b;
96
- var typeGraphSchema = graphSchema.find(function (schemaType) { return schemaType.itemType === itemType; });
97
- var property = (_a = typeGraphSchema) === null || _a === void 0 ? void 0 : _a.properties.find(function (property) { return property.propertyKey === propertyKey; });
86
+ const typeGraphSchema = graphSchema.find((schemaType) => schemaType.itemType === itemType);
87
+ const property = (_a = typeGraphSchema) === null || _a === void 0 ? void 0 : _a.properties.find((property) => property.propertyKey === propertyKey);
98
88
  return (_b = property) === null || _b === void 0 ? void 0 : _b.propertyType;
99
- };
89
+ }
100
90
  /**
101
91
  * Generate text from edge data and captions schema
102
92
  */
103
- Captions.generateEdgeCaption = function (itemData, schema, graphSchema) {
104
- var type = itemData.type;
105
- var caption = [];
106
- var captionProps = [];
93
+ static generateEdgeCaption(itemData, schema, graphSchema) {
94
+ const type = itemData.type;
95
+ const caption = [];
96
+ let captionProps = [];
107
97
  if (schema[type] && schema[type].active) {
108
98
  if (schema[type].displayName) {
109
99
  caption.push(type);
110
100
  }
111
- captionProps = __spreadArrays(captionProps, schema[type].properties);
112
- tools_1.Tools.uniqBy(captionProps).forEach(function (propertyKey) {
101
+ captionProps = [...captionProps, ...schema[type].properties];
102
+ tools_1.Tools.uniqBy(captionProps).forEach((propertyKey) => {
113
103
  if (tools_1.Tools.isDefined(itemData.properties[propertyKey])) {
114
- var propertyType = graphSchema
104
+ const propertyType = graphSchema
115
105
  ? Captions.getPropertyType(graphSchema, propertyKey, type)
116
106
  : undefined;
117
107
  caption.push(Captions.getLabel(itemData.properties[propertyKey], propertyType));
@@ -120,8 +110,7 @@ var Captions = /** @class */ (function () {
120
110
  return caption.join(' - ').trim();
121
111
  }
122
112
  return '';
123
- };
124
- return Captions;
125
- }());
113
+ }
114
+ }
126
115
  exports.Captions = Captions;
127
116
  //# sourceMappingURL=captions.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"captions.js","sourceRoot":"","sources":["../../src/captions/captions.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;;;;AAEb,uDAUiC;AAEjC,wCAAwD;AAExD;IAAA;IA8IA,CAAC;IA7IC;;OAEG;IACW,gBAAO,GAArB,UACE,QAAiC,EACjC,MAA0B,EAC1B,WAAyC;QAEzC,IAAM,KAAK,GAAG,YAAY,IAAI,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QAC/E,IAAI,QAAQ,CAAC,YAAY,CAAC,KAAK,EAAE,MAAM,CAAC,EAAE;YACxC,OAAO,YAAY,IAAI,QAAQ;gBAC7B,CAAC,CAAC,QAAQ,CAAC,mBAAmB,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,CAAC,IAAI,IAAI;gBACrE,CAAC,CAAC,QAAQ,CAAC,mBAAmB,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,CAAC,IAAI,IAAI,CAAC;SACzE;QACD,IAAI,QAAQ,CAAC,UAAU,KAAK,SAAS,EAAE;YACrC,IAAM,uBAAuB,GAAG,yBAAiB,CAAC,IAAI,CAAC,UAAC,KAAK;gBAC3D,OAAO,QAAQ,CAAC,UAAU,CAAC,KAAK,CAAC,KAAK,SAAS,CAAC;YAClD,CAAC,CAAC,CAAC;Y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AS,CAAC;oBACd,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,QAAQ,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC;iBACjF;YACH,CAAC,CAAC,CAAC;YACH,OAAO,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC;SACnC;QACD,OAAO,EAAE,CAAC;IACZ,CAAC;IACH,eAAC;AAAD,CAAC,AA9ID,IA8IC;AA9IY,4BAAQ","sourcesContent":["'use strict';\n\nimport {\n GraphSchemaTypeWithAccess,\n ICaptionConfig,\n ItemFieldsCaptions,\n LkEdgeData,\n LkNodeData,\n LkProperty,\n PropertyType,\n PropertyTypeName,\n GraphSchemaPropertyWithAccess\n} from '@linkurious/rest-client';\n\nimport {CAPTION_HEURISTIC, Tools} from '../tools/tools';\n\nexport class Captions {\n /**\n * Return label for each node\n */\n public static getText(\n itemData: LkNodeData | LkEdgeData,\n schema: ItemFieldsCaptions,\n graphSchema?: GraphSchemaTypeWithAccess[]\n ): string | null {\n const types = 'categories' in itemData ? itemData.categories : [itemData.type];\n if (Captions.captionExist(types, schema)) {\n return 'categories' in itemData\n ? Captions.generateNodeCaption(itemData, schema, graphSchema) || null\n : Captions.generateEdgeCaption(itemData, schema, graphSchema) || null;\n }\n if (itemData.properties !== undefined) {\n const heuristicCaptionElement = CAPTION_HEURISTIC.find((value) => {\n return itemData.properties[value] !== undefined;\n });\n if (\n heuristicCaptionElement !== undefined &&\n Tools.isDefined(itemData.properties[heuristicCaptionElement])\n ) {\n return `${Tools.getValueFromLkProperty(\n itemData.properties[heuristicCaptionElement]\n )}`.trim();\n }\n }\n return null;\n }\n\n /**\n * Return a readable string from an LkProperty\n */\n private static getLabel(\n propertyValue: LkProperty,\n propertyType?: PropertyType | undefined\n ): string | null {\n if (typeof propertyValue === 'object' && 'type' in propertyValue) {\n if (!('original' in propertyValue) && !('value' in propertyValue)) {\n return null;\n }\n if ('original' in propertyValue) {\n return `${propertyValue.original}`;\n }\n if ('value' in propertyValue) {\n return Tools.formatDate(\n new Date(\n new Date(propertyValue.value).getTime() +\n Tools.timezoneToMilliseconds(propertyValue.timezone)\n ).toISOString()\n );\n }\n } else if (\n propertyType?.name === PropertyTypeName.NUMBER &&\n propertyType.options !== undefined\n ) {\n return Tools.formatCurrencyValue(propertyValue as number, propertyType.options);\n }\n return `${propertyValue}`.trim();\n }\n\n /**\n * Return true if caption configuration exists in schema\n */\n public static captionExist(itemTypes: Array<string>, schema: ItemFieldsCaptions): boolean {\n return itemTypes.some((type) => Tools.isDefined(schema[type]));\n }\n\n /**\n * Generate text from node data and captions schema\n */\n public static generateNodeCaption(\n itemData: LkNodeData,\n schema: {[key: string]: ICaptionConfig},\n graphSchema?: GraphSchemaTypeWithAccess[]\n ): string {\n const categories = itemData.categories;\n const caption: Array<string | null> = [];\n let captionProps: Array<string | null> = [];\n categories.forEach((category) => {\n if (schema[category] && schema[category].active) {\n if (schema[category].displayName) {\n caption.push(category);\n }\n captionProps = [...captionProps, ...schema[category].properties];\n }\n });\n Tools.uniqBy(captionProps).forEach((propertyKey) => {\n if (itemData.properties[propertyKey] !== undefined) {\n const propertyType = graphSchema\n ? Captions.getPropertyType(graphSchema, propertyKey, categories[0])\n : undefined;\n caption.push(this.getLabel(itemData.properties[propertyKey], propertyType));\n }\n });\n return caption\n .filter((c) => c !== null)\n .join(' - ')\n .trim();\n }\n\n public static getPropertyType(\n graphSchema: GraphSchemaTypeWithAccess[],\n propertyKey: string,\n itemType: string\n ): PropertyType | undefined {\n const typeGraphSchema = graphSchema.find((schemaType) => schemaType.itemType === itemType);\n const property = typeGraphSchema?.properties.find(\n (property) => property.propertyKey === propertyKey\n );\n return ((property as unknown) as GraphSchemaPropertyWithAccess)?.propertyType;\n }\n\n /**\n * Generate text from edge data and captions schema\n */\n public static generateEdgeCaption(\n itemData: LkEdgeData,\n schema: {[key: string]: ICaptionConfig},\n graphSchema?: GraphSchemaTypeWithAccess[]\n ): string {\n const type = itemData.type;\n const caption: Array<string | null> = [];\n let captionProps: Array<string | null> = [];\n if (schema[type] && schema[type].active) {\n if (schema[type].displayName) {\n caption.push(type);\n }\n captionProps = [...captionProps, ...schema[type].properties];\n Tools.uniqBy(captionProps).forEach((propertyKey) => {\n if (Tools.isDefined(itemData.properties[propertyKey])) {\n const propertyType = graphSchema\n ? Captions.getPropertyType(graphSchema, propertyKey, type)\n : undefined;\n caption.push(Captions.getLabel(itemData.properties[propertyKey], propertyType));\n }\n });\n return caption.join(' - ').trim();\n }\n return '';\n }\n}\n"]}
1
+ {"version":3,"file":"captions.js","sourceRoot":"","sources":["../../src/captions/captions.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,yDAUiC;AAEjC,0CAAwD;AAExD,MAAa,QAAQ;IACnB;;OAEG;IACI,MAAM,CAAC,OAAO,CACnB,QAAiC,EACjC,MAA0B,EAC1B,WAAyC;QAEzC,MAAM,KAAK,GAAG,YAAY,IAAI,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QAC/E,IAAI,QAAQ,CAAC,YAAY,CAAC,KAAK,EAAE,MAAM,CAAC,EAAE;YACxC,OAAO,YAAY,IAAI,QAAQ;gBAC7B,CAAC,CAAC,QAAQ,CAAC,mBAAmB,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,CAAC,IAAI,IAAI;gBACrE,CAAC,CAAC,QAAQ,CAAC,mBAAmB,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,CAAC,IAAI,IAAI,CAAC;SACzE;QACD,IAAI,QAAQ,CAAC,UAAU,KAAK,SAAS,EAAE;YACrC,MAAM,uBAAuB,GAAG,yBAAiB,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE;gBAC/D,OAAO,QAAQ,CAAC,UAAU,CAAC,KAAK,CAAC,KAAK,SAAS,CAAC;YAClD,CAAC,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AAW,EAAE,WAAW,EAAE,IAAI,CAAC;wBAC1D,CAAC,CAAC,SAAS,CAAC;oBACd,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,QAAQ,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC;iBACjF;YACH,CAAC,CAAC,CAAC;YACH,OAAO,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC;SACnC;QACD,OAAO,EAAE,CAAC;IACZ,CAAC;CACF;AA9ID,4BA8IC","sourcesContent":["'use strict';\n\nimport {\n GraphSchemaTypeWithAccess,\n ICaptionConfig,\n ItemFieldsCaptions,\n LkEdgeData,\n LkNodeData,\n LkProperty,\n PropertyType,\n PropertyTypeName,\n GraphSchemaPropertyWithAccess\n} from '@linkurious/rest-client';\n\nimport {CAPTION_HEURISTIC, Tools} from '../tools/tools';\n\nexport class Captions {\n /**\n * Return label for each node\n */\n public static getText(\n itemData: LkNodeData | LkEdgeData,\n schema: ItemFieldsCaptions,\n graphSchema?: GraphSchemaTypeWithAccess[]\n ): string | null {\n const types = 'categories' in itemData ? itemData.categories : [itemData.type];\n if (Captions.captionExist(types, schema)) {\n return 'categories' in itemData\n ? Captions.generateNodeCaption(itemData, schema, graphSchema) || null\n : Captions.generateEdgeCaption(itemData, schema, graphSchema) || null;\n }\n if (itemData.properties !== undefined) {\n const heuristicCaptionElement = CAPTION_HEURISTIC.find((value) => {\n return itemData.properties[value] !== undefined;\n });\n if (\n heuristicCaptionElement !== undefined &&\n Tools.isDefined(itemData.properties[heuristicCaptionElement])\n ) {\n return `${Tools.getValueFromLkProperty(\n itemData.properties[heuristicCaptionElement]\n )}`.trim();\n }\n }\n return null;\n }\n\n /**\n * Return a readable string from an LkProperty\n */\n private static getLabel(\n propertyValue: LkProperty,\n propertyType?: PropertyType | undefined\n ): string | null {\n if (typeof propertyValue === 'object' && 'type' in propertyValue) {\n if (!('original' in propertyValue) && !('value' in propertyValue)) {\n return null;\n }\n if ('original' in propertyValue) {\n return `${propertyValue.original}`;\n }\n if ('value' in propertyValue) {\n return Tools.formatDate(\n new Date(\n new Date(propertyValue.value).getTime() +\n Tools.timezoneToMilliseconds(propertyValue.timezone)\n ).toISOString()\n );\n }\n } else if (\n propertyType?.name === PropertyTypeName.NUMBER &&\n propertyType.options !== undefined\n ) {\n return Tools.formatCurrencyValue(propertyValue as number, propertyType.options);\n }\n return `${propertyValue}`.trim();\n }\n\n /**\n * Return true if caption configuration exists in schema\n */\n public static captionExist(itemTypes: Array<string>, schema: ItemFieldsCaptions): boolean {\n return itemTypes.some((type) => Tools.isDefined(schema[type]));\n }\n\n /**\n * Generate text from node data and captions schema\n */\n public static generateNodeCaption(\n itemData: LkNodeData,\n schema: {[key: string]: ICaptionConfig},\n graphSchema?: GraphSchemaTypeWithAccess[]\n ): string {\n const categories = itemData.categories;\n const caption: Array<string | null> = [];\n let captionProps: Array<string | null> = [];\n categories.forEach((category) => {\n if (schema[category] && schema[category].active) {\n if (schema[category].displayName) {\n caption.push(category);\n }\n captionProps = [...captionProps, ...schema[category].properties];\n }\n });\n Tools.uniqBy(captionProps).forEach((propertyKey) => {\n if (itemData.properties[propertyKey] !== undefined) {\n const propertyType = graphSchema\n ? Captions.getPropertyType(graphSchema, propertyKey, categories[0])\n : undefined;\n caption.push(this.getLabel(itemData.properties[propertyKey], propertyType));\n }\n });\n return caption\n .filter((c) => c !== null)\n .join(' - ')\n .trim();\n }\n\n public static getPropertyType(\n graphSchema: GraphSchemaTypeWithAccess[],\n propertyKey: string,\n itemType: string\n ): PropertyType | undefined {\n const typeGraphSchema = graphSchema.find((schemaType) => schemaType.itemType === itemType);\n const property = typeGraphSchema?.properties.find(\n (property) => property.propertyKey === propertyKey\n );\n return ((property as unknown) as GraphSchemaPropertyWithAccess)?.propertyType;\n }\n\n /**\n * Generate text from edge data and captions schema\n */\n public static generateEdgeCaption(\n itemData: LkEdgeData,\n schema: {[key: string]: ICaptionConfig},\n graphSchema?: GraphSchemaTypeWithAccess[]\n ): string {\n const type = itemData.type;\n const caption: Array<string | null> = [];\n let captionProps: Array<string | null> = [];\n if (schema[type] && schema[type].active) {\n if (schema[type].displayName) {\n caption.push(type);\n }\n captionProps = [...captionProps, ...schema[type].properties];\n Tools.uniqBy(captionProps).forEach((propertyKey) => {\n if (Tools.isDefined(itemData.properties[propertyKey])) {\n const propertyType = graphSchema\n ? Captions.getPropertyType(graphSchema, propertyKey, type)\n : undefined;\n caption.push(Captions.getLabel(itemData.properties[propertyKey], propertyType));\n }\n });\n return caption.join(' - ').trim();\n }\n return '';\n }\n}\n"]}
@@ -1,10 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- var rest_client_1 = require("@linkurious/rest-client");
4
- var tools_1 = require("../tools/tools");
5
- var Filters = /** @class */ (function () {
6
- function Filters() {
7
- }
3
+ const rest_client_1 = require("@linkurious/rest-client");
4
+ const tools_1 = require("../tools/tools");
5
+ class Filters {
8
6
  /**
9
7
  * Returns whether the node/edge should be *filtered* (a.k.a. *hidden*).
10
8
  *
@@ -16,7 +14,7 @@ var Filters = /** @class */ (function () {
16
14
  * @param filterRules
17
15
  * @param itemData
18
16
  */
19
- Filters.isFiltered = function (filterRules, itemData) {
17
+ static isFiltered(filterRules, itemData) {
20
18
  if (!tools_1.Tools.isDefined(itemData)) {
21
19
  return false;
22
20
  }
@@ -26,12 +24,12 @@ var Filters = /** @class */ (function () {
26
24
  else {
27
25
  return Filters.getFilterFunction(filterRules, false)(itemData);
28
26
  }
29
- };
30
- Filters.getFilterFunction = function (filterRules, isNode) {
31
- var filterKey = JSON.stringify(filterRules, null, '');
27
+ }
28
+ static getFilterFunction(filterRules, isNode) {
29
+ const filterKey = JSON.stringify(filterRules, null, '');
32
30
  // This cast is needed to tell the TypeScript compiler to trust us that "isNode" and "T" are dependent.
33
- var filterCache = (isNode ? Filters.nodeCache : Filters.edgeCache);
34
- var filterFunc = filterCache.get(filterKey);
31
+ const filterCache = (isNode ? Filters.nodeCache : Filters.edgeCache);
32
+ let filterFunc = filterCache.get(filterKey);
35
33
  if (!filterFunc) {
36
34
  filterFunc = Filters.createFilterFunction(filterRules, isNode);
37
35
  if (filterCache.size > Filters.FILTER_CACHE_SIZE) {
@@ -40,26 +38,23 @@ var Filters = /** @class */ (function () {
40
38
  filterCache.set(filterKey, filterFunc);
41
39
  }
42
40
  return filterFunc;
43
- };
44
- Filters.createFilterFunction = function (filterRules, isNode) {
45
- var filterFunctions = filterRules.map(function (filter) {
46
- return Filters.filterToFilterFunction(filter, isNode);
47
- });
41
+ }
42
+ static createFilterFunction(filterRules, isNode) {
43
+ const filterFunctions = filterRules.map((filter) => Filters.filterToFilterFunction(filter, isNode));
48
44
  /**
49
45
  * For each filterFunction, as soon as we find a filterFunction that says that a given
50
46
  * node/edge should be filtered/hidden, we return `true` for the node/edge.
51
47
  */
52
- return function (itemData) {
53
- for (var _i = 0, filterFunctions_1 = filterFunctions; _i < filterFunctions_1.length; _i++) {
54
- var filterFunction = filterFunctions_1[_i];
48
+ return (itemData) => {
49
+ for (const filterFunction of filterFunctions) {
55
50
  if (filterFunction(itemData)) {
56
51
  return true;
57
52
  }
58
53
  }
59
54
  return false;
60
55
  };
61
- };
62
- Filters.filterToFilterFunction = function (filter, isNode) {
56
+ }
57
+ static filterToFilterFunction(filter, isNode) {
63
58
  switch (filter.type) {
64
59
  case rest_client_1.SelectorType.ANY:
65
60
  return Filters.createAnyFilterFunction(filter, isNode);
@@ -72,10 +67,10 @@ var Filters = /** @class */ (function () {
72
67
  case rest_client_1.SelectorType.NAN:
73
68
  return Filters.createNaNFilterFunction(filter, isNode);
74
69
  }
75
- };
76
- Filters.createAnyFilterFunction = function (filter, isNode) {
70
+ }
71
+ static createAnyFilterFunction(filter, isNode) {
77
72
  if (isNode) {
78
- return function (itemData) {
73
+ return (itemData) => {
79
74
  if (filter.itemType === undefined) {
80
75
  return true;
81
76
  }
@@ -84,72 +79,56 @@ var Filters = /** @class */ (function () {
84
79
  }
85
80
  else {
86
81
  // isEdge
87
- return function (itemData) { return itemData.type === filter.itemType; };
82
+ return (itemData) => itemData.type === filter.itemType;
88
83
  }
89
- };
90
- Filters.createIsFilterFunction = function (filter, isNode) {
84
+ }
85
+ static createIsFilterFunction(filter, isNode) {
91
86
  if (isNode) {
92
- return function (itemData) {
93
- return itemData.categories.includes(filter.itemType) &&
94
- tools_1.Tools.getPropertyValue(tools_1.Tools.getIn(itemData, filter.input), true) === filter.value;
95
- };
87
+ return (itemData) => itemData.categories.includes(filter.itemType) &&
88
+ tools_1.Tools.getPropertyValue(tools_1.Tools.getIn(itemData, filter.input), true) === filter.value;
96
89
  }
97
90
  else {
98
91
  // isEdge
99
- return function (itemData) {
100
- return itemData.type === filter.itemType &&
101
- tools_1.Tools.getPropertyValue(tools_1.Tools.getIn(itemData, filter.input), true) === filter.value;
102
- };
92
+ return (itemData) => itemData.type === filter.itemType &&
93
+ tools_1.Tools.getPropertyValue(tools_1.Tools.getIn(itemData, filter.input), true) === filter.value;
103
94
  }
104
- };
105
- Filters.createNoValueFilterFunction = function (filter, isNode) {
95
+ }
96
+ static createNoValueFilterFunction(filter, isNode) {
106
97
  if (isNode) {
107
- return function (itemData) {
108
- return itemData.categories.includes(filter.itemType) &&
109
- !tools_1.Tools.isDefined(tools_1.Tools.getPropertyValue(tools_1.Tools.getIn(itemData, filter.input), true));
110
- };
98
+ return (itemData) => itemData.categories.includes(filter.itemType) &&
99
+ !tools_1.Tools.isDefined(tools_1.Tools.getPropertyValue(tools_1.Tools.getIn(itemData, filter.input), true));
111
100
  }
112
101
  else {
113
102
  // isEdge
114
- return function (itemData) {
115
- return itemData.type === filter.itemType &&
116
- !tools_1.Tools.isDefined(tools_1.Tools.getPropertyValue(tools_1.Tools.getIn(itemData, filter.input), true));
117
- };
103
+ return (itemData) => itemData.type === filter.itemType &&
104
+ !tools_1.Tools.isDefined(tools_1.Tools.getPropertyValue(tools_1.Tools.getIn(itemData, filter.input), true));
118
105
  }
119
- };
120
- Filters.createNaNFilterFunction = function (filter, isNode) {
106
+ }
107
+ static createNaNFilterFunction(filter, isNode) {
121
108
  if (isNode) {
122
- return function (itemData) {
123
- return itemData.categories.includes(filter.itemType) &&
124
- Filters.isNotANumber(tools_1.Tools.getPropertyValue(tools_1.Tools.getIn(itemData, filter.input), true));
125
- };
109
+ return (itemData) => itemData.categories.includes(filter.itemType) &&
110
+ Filters.isNotANumber(tools_1.Tools.getPropertyValue(tools_1.Tools.getIn(itemData, filter.input), true));
126
111
  }
127
112
  else {
128
113
  // isEdge
129
- return function (itemData) {
130
- return itemData.type === filter.itemType &&
131
- Filters.isNotANumber(tools_1.Tools.getPropertyValue(tools_1.Tools.getIn(itemData, filter.input), true));
132
- };
114
+ return (itemData) => itemData.type === filter.itemType &&
115
+ Filters.isNotANumber(tools_1.Tools.getPropertyValue(tools_1.Tools.getIn(itemData, filter.input), true));
133
116
  }
134
- };
135
- Filters.isNotANumber = function (value) {
117
+ }
118
+ static isNotANumber(value) {
136
119
  return tools_1.Tools.isDefined(value) && !tools_1.Tools.isNumber(value);
137
- };
138
- Filters.createRangeFilterFunction = function (filter, isNode) {
120
+ }
121
+ static createRangeFilterFunction(filter, isNode) {
139
122
  if (isNode) {
140
- return function (itemData) {
141
- return itemData.categories.includes(filter.itemType) &&
142
- Filters.valueShouldBeHidden(tools_1.Tools.getPropertyValue(tools_1.Tools.getIn(itemData, filter.input), false), filter.value);
143
- };
123
+ return (itemData) => itemData.categories.includes(filter.itemType) &&
124
+ Filters.valueShouldBeHidden(tools_1.Tools.getPropertyValue(tools_1.Tools.getIn(itemData, filter.input), false), filter.value);
144
125
  }
145
126
  else {
146
127
  // isEdge
147
- return function (itemData) {
148
- return itemData.type === filter.itemType &&
149
- Filters.valueShouldBeHidden(tools_1.Tools.getPropertyValue(tools_1.Tools.getIn(itemData, filter.input), false), filter.value);
150
- };
128
+ return (itemData) => itemData.type === filter.itemType &&
129
+ Filters.valueShouldBeHidden(tools_1.Tools.getPropertyValue(tools_1.Tools.getIn(itemData, filter.input), false), filter.value);
151
130
  }
152
- };
131
+ }
153
132
  /**
154
133
  * Returns true if `value` should be filtered/hidden.
155
134
  *
@@ -160,8 +139,8 @@ var Filters = /** @class */ (function () {
160
139
  *
161
140
  * Returns false (i.e. will not filter/hide) if `value` is not a number.
162
141
  */
163
- Filters.valueShouldBeHidden = function (value, range) {
164
- var n = tools_1.Tools.parseFloat(value);
142
+ static valueShouldBeHidden(value, range) {
143
+ const n = tools_1.Tools.parseFloat(value);
165
144
  if (Number.isNaN(n)) {
166
145
  return false;
167
146
  }
@@ -178,11 +157,10 @@ var Filters = /** @class */ (function () {
178
157
  (range['<='] !== undefined && n <= range['<=']) ||
179
158
  (range['>'] !== undefined && n > range['>']) ||
180
159
  (range['>='] !== undefined && n >= range['>=']));
181
- };
182
- Filters.nodeCache = new Map();
183
- Filters.edgeCache = new Map();
184
- Filters.FILTER_CACHE_SIZE = 5;
185
- return Filters;
186
- }());
160
+ }
161
+ }
187
162
  exports.Filters = Filters;
163
+ Filters.nodeCache = new Map();
164
+ Filters.edgeCache = new Map();
165
+ Filters.FILTER_CACHE_SIZE = 5;
188
166
  //# sourceMappingURL=filters.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"filters.js","sourceRoot":"","sources":["../../src/filters/filters.ts"],"names":[],"mappings":";;AAAA,uDAYiC;AAEjC,wCAAqC;AAIrC;IAAA;IAyNA,CAAC;IApNC;;;;;;;;;;OAUG;IACW,kBAAU,GAAxB,UACE,WAAgC,EAChC,QAAiC;QAEjC,IAAI,CAAC,aAAK,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE;YAC9B,OAAO,KAAK,CAAC;SACd;QAED,IAAI,YAAY,IAAI,QAAQ,EAAE;YAC5B,OAAO,OAAO,CAAC,iBAAiB,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC,QAAQ,CAAC,CAAC;SAC/D;aAAM;YACL,OAAO,OAAO,CAAC,iBAAi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;QACnE,IAAM,CAAC,GAAG,aAAK,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;QAClC,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE;YACnB,OAAO,KAAK,CAAC;SACd;QAED;;;;;;;;WAQG;QACH,OAAO,CACL,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,SAAS,IAAI,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;YAC5C,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,SAAS,IAAI,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,CAAC;YAC/C,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,SAAS,IAAI,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;YAC5C,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,SAAS,IAAI,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,CAAC,CAChD,CAAC;IACJ,CAAC;IAvNc,iBAAS,GAA4C,IAAI,GAAG,EAAE,CAAC;IAC/D,iBAAS,GAA4C,IAAI,GAAG,EAAE,CAAC;IAC/D,yBAAiB,GAAG,CAAC,CAAC;IAsNvC,cAAC;CAAA,AAzND,IAyNC;AAzNY,0BAAO","sourcesContent":["import {\n ItemSelector,\n LkEdgeData,\n LkNodeData,\n IRangeValues,\n SelectorType,\n ISelectorAny,\n ISelectorIs,\n ISelectorNoValue,\n ISelectorNaN,\n ISelectorRange,\n LkItemData\n} from '@linkurious/rest-client';\n\nimport {Tools} from '../tools/tools';\n\ntype FilterFunction<T extends LkItemData> = (itemData: T) => boolean;\n\nexport class Filters {\n private static nodeCache: Map<string, FilterFunction<LkNodeData>> = new Map();\n private static edgeCache: Map<string, FilterFunction<LkEdgeData>> = new Map();\n private static FILTER_CACHE_SIZE = 5;\n\n /**\n * Returns whether the node/edge should be *filtered* (a.k.a. *hidden*).\n *\n * Notes:\n * 1. `filterRules` are rules that match what should be filtered/hidden.\n * 2. `filterRules` are combined inclusively: as soon as one rule returns `true` for\n * an item, the item can be hidden/filtered.\n *\n * @param filterRules\n * @param itemData\n */\n public static isFiltered(\n filterRules: Array<ItemSelector>,\n itemData: LkNodeData | LkEdgeData\n ): boolean {\n if (!Tools.isDefined(itemData)) {\n return false;\n }\n\n if ('categories' in itemData) {\n return Filters.getFilterFunction(filterRules, true)(itemData);\n } else {\n return Filters.getFilterFunction(filterRules, false)(itemData);\n }\n }\n\n private static getFilterFunction<T extends LkNodeData | LkEdgeData>(\n filterRules: Array<ItemSelector>,\n isNode: boolean\n ): FilterFunction<T> {\n const filterKey = JSON.stringify(filterRules, null, '');\n\n // This cast is needed to tell the TypeScript compiler to trust us that \"isNode\" and \"T\" are dependent.\n const filterCache = (isNode ? Filters.nodeCache : Filters.edgeCache) as Map<\n string,\n FilterFunction<T>\n >;\n\n let filterFunc = filterCache.get(filterKey);\n if (!filterFunc) {\n filterFunc = Filters.createFilterFunction(filterRules, isNode);\n if (filterCache.size > Filters.FILTER_CACHE_SIZE) {\n filterCache.clear();\n }\n filterCache.set(filterKey, filterFunc);\n }\n return filterFunc;\n }\n\n private static createFilterFunction<T extends LkNodeData | LkEdgeData>(\n filterRules: Array<ItemSelector>,\n isNode: boolean\n ): FilterFunction<T> {\n const filterFunctions = filterRules.map((filter: ItemSelector) =>\n Filters.filterToFilterFunction(filter, isNode)\n );\n\n /**\n * For each filterFunction, as soon as we find a filterFunction that says that a given\n * node/edge should be filtered/hidden, we return `true` for the node/edge.\n */\n return (itemData: T): boolean => {\n for (const filterFunction of filterFunctions) {\n if (filterFunction(itemData)) {\n return true;\n }\n }\n return false;\n };\n }\n\n private static filterToFilterFunction<T extends LkNodeData | LkEdgeData>(\n filter: ItemSelector,\n isNode: boolean\n ): FilterFunction<T> {\n switch (filter.type) {\n case SelectorType.ANY:\n return Filters.createAnyFilterFunction(filter, isNode);\n case SelectorType.IS:\n return Filters.createIsFilterFunction(filter, isNode);\n case SelectorType.NO_VALUE:\n return Filters.createNoValueFilterFunction(filter, isNode);\n case SelectorType.RANGE:\n return Filters.createRangeFilterFunction(filter, isNode);\n case SelectorType.NAN:\n return Filters.createNaNFilterFunction(filter, isNode);\n }\n }\n\n private static createAnyFilterFunction<T extends LkNodeData | LkEdgeData>(\n filter: ISelectorAny,\n isNode: boolean\n ): FilterFunction<T> {\n if (isNode) {\n return (itemData: T) => {\n if (filter.itemType === undefined) {\n return true;\n }\n return (itemData as LkNodeData).categories.includes(filter.itemType);\n };\n } else {\n // isEdge\n return (itemData: T) => (itemData as LkEdgeData).type === filter.itemType;\n }\n }\n\n private static createIsFilterFunction<T extends LkNodeData | LkEdgeData>(\n filter: ISelectorIs,\n isNode: boolean\n ): FilterFunction<T> {\n if (isNode) {\n return (itemData: T) =>\n (itemData as LkNodeData).categories.includes(filter.itemType) &&\n Tools.getPropertyValue(Tools.getIn(itemData, filter.input), true) === filter.value;\n } else {\n // isEdge\n return (itemData: T) =>\n (itemData as LkEdgeData).type === filter.itemType &&\n Tools.getPropertyValue(Tools.getIn(itemData, filter.input), true) === filter.value;\n }\n }\n\n private static createNoValueFilterFunction<T extends LkNodeData | LkEdgeData>(\n filter: ISelectorNoValue,\n isNode: boolean\n ): FilterFunction<T> {\n if (isNode) {\n return (itemData: T) =>\n (itemData as LkNodeData).categories.includes(filter.itemType) &&\n !Tools.isDefined(Tools.getPropertyValue(Tools.getIn(itemData, filter.input), true));\n } else {\n // isEdge\n return (itemData: T) =>\n (itemData as LkEdgeData).type === filter.itemType &&\n !Tools.isDefined(Tools.getPropertyValue(Tools.getIn(itemData, filter.input), true));\n }\n }\n\n private static createNaNFilterFunction<T extends LkNodeData | LkEdgeData>(\n filter: ISelectorNaN,\n isNode: boolean\n ): FilterFunction<T> {\n if (isNode) {\n return (itemData: T) =>\n (itemData as LkNodeData).categories.includes(filter.itemType) &&\n Filters.isNotANumber(Tools.getPropertyValue(Tools.getIn(itemData, filter.input), true));\n } else {\n // isEdge\n return (itemData: T) =>\n (itemData as LkEdgeData).type === filter.itemType &&\n Filters.isNotANumber(Tools.getPropertyValue(Tools.getIn(itemData, filter.input), true));\n }\n }\n\n private static isNotANumber(value: any) {\n return Tools.isDefined(value) && !Tools.isNumber(value);\n }\n\n public static createRangeFilterFunction<T extends LkNodeData | LkEdgeData>(\n filter: ISelectorRange,\n isNode: boolean\n ): FilterFunction<T> {\n if (isNode) {\n return (itemData: T) =>\n (itemData as LkNodeData).categories.includes(filter.itemType) &&\n Filters.valueShouldBeHidden(\n Tools.getPropertyValue(Tools.getIn(itemData, filter.input), false),\n filter.value\n );\n } else {\n // isEdge\n return (itemData: T) =>\n (itemData as LkEdgeData).type === filter.itemType &&\n Filters.valueShouldBeHidden(\n Tools.getPropertyValue(Tools.getIn(itemData, filter.input), false),\n filter.value\n );\n }\n }\n\n /**\n * Returns true if `value` should be filtered/hidden.\n *\n * `range` describes what should be filtered/hidden:\n * - e.g. {\"<\":10, \">=\":20} => hide any value in ]-inf, 10[ *OR* in [20, +inf[\n * - e.g. {\"<=\":10} => hide any value in ]-inf, 10]\n * - e.g. {\">=\":20} => hide any value in [20, +inf[\n *\n * Returns false (i.e. will not filter/hide) if `value` is not a number.\n */\n public static valueShouldBeHidden(value: unknown, range: IRangeValues): boolean {\n const n = Tools.parseFloat(value);\n if (Number.isNaN(n)) {\n return false;\n }\n\n /**\n * As soon as we find a condition that says that `value` should be filtered/hidden,\n * we return `true`.\n *\n * If `range` contains multiple conditions, all are checked and if any condition causes\n * `value` to be in the filtered/hidden range, we return `true`.\n *\n * If no condition causes `value` to be filtered/hidden, we return `false`.\n */\n return (\n (range['<'] !== undefined && n < range['<']) ||\n (range['<='] !== undefined && n <= range['<=']) ||\n (range['>'] !== undefined && n > range['>']) ||\n (range['>='] !== undefined && n >= range['>='])\n );\n }\n}\n"]}
1
+ {"version":3,"file":"filters.js","sourceRoot":"","sources":["../../src/filters/filters.ts"],"names":[],"mappings":";;AAAA,yDAYiC;AAEjC,0CAAqC;AAIrC,MAAa,OAAO;IAKlB;;;;;;;;;;OAUG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AAC,QAAQ;gBACjD,OAAO,CAAC,mBAAmB,CACzB,aAAK,CAAC,gBAAgB,CAAC,aAAK,CAAC,KAAK,CAAC,QAAQ,EAAE,MAAM,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,EAClE,MAAM,CAAC,KAAK,CACb,CAAC;SACL;IACH,CAAC;IAED;;;;;;;;;OASG;IACI,MAAM,CAAC,mBAAmB,CAAC,KAAc,EAAE,KAAmB;QACnE,MAAM,CAAC,GAAG,aAAK,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;QAClC,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE;YACnB,OAAO,KAAK,CAAC;SACd;QAED;;;;;;;;WAQG;QACH,OAAO,CACL,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,SAAS,IAAI,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;YAC5C,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,SAAS,IAAI,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,CAAC;YAC/C,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,SAAS,IAAI,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;YAC5C,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,SAAS,IAAI,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,CAAC,CAChD,CAAC;IACJ,CAAC;;AAxNH,0BAyNC;AAxNgB,iBAAS,GAA4C,IAAI,GAAG,EAAE,CAAC;AAC/D,iBAAS,GAA4C,IAAI,GAAG,EAAE,CAAC;AAC/D,yBAAiB,GAAG,CAAC,CAAC","sourcesContent":["import {\n ItemSelector,\n LkEdgeData,\n LkNodeData,\n IRangeValues,\n SelectorType,\n ISelectorAny,\n ISelectorIs,\n ISelectorNoValue,\n ISelectorNaN,\n ISelectorRange,\n LkItemData\n} from '@linkurious/rest-client';\n\nimport {Tools} from '../tools/tools';\n\ntype FilterFunction<T extends LkItemData> = (itemData: T) => boolean;\n\nexport class Filters {\n private static nodeCache: Map<string, FilterFunction<LkNodeData>> = new Map();\n private static edgeCache: Map<string, FilterFunction<LkEdgeData>> = new Map();\n private static FILTER_CACHE_SIZE = 5;\n\n /**\n * Returns whether the node/edge should be *filtered* (a.k.a. *hidden*).\n *\n * Notes:\n * 1. `filterRules` are rules that match what should be filtered/hidden.\n * 2. `filterRules` are combined inclusively: as soon as one rule returns `true` for\n * an item, the item can be hidden/filtered.\n *\n * @param filterRules\n * @param itemData\n */\n public static isFiltered(\n filterRules: Array<ItemSelector>,\n itemData: LkNodeData | LkEdgeData\n ): boolean {\n if (!Tools.isDefined(itemData)) {\n return false;\n }\n\n if ('categories' in itemData) {\n return Filters.getFilterFunction(filterRules, true)(itemData);\n } else {\n return Filters.getFilterFunction(filterRules, false)(itemData);\n }\n }\n\n private static getFilterFunction<T extends LkNodeData | LkEdgeData>(\n filterRules: Array<ItemSelector>,\n isNode: boolean\n ): FilterFunction<T> {\n const filterKey = JSON.stringify(filterRules, null, '');\n\n // This cast is needed to tell the TypeScript compiler to trust us that \"isNode\" and \"T\" are dependent.\n const filterCache = (isNode ? Filters.nodeCache : Filters.edgeCache) as Map<\n string,\n FilterFunction<T>\n >;\n\n let filterFunc = filterCache.get(filterKey);\n if (!filterFunc) {\n filterFunc = Filters.createFilterFunction(filterRules, isNode);\n if (filterCache.size > Filters.FILTER_CACHE_SIZE) {\n filterCache.clear();\n }\n filterCache.set(filterKey, filterFunc);\n }\n return filterFunc;\n }\n\n private static createFilterFunction<T extends LkNodeData | LkEdgeData>(\n filterRules: Array<ItemSelector>,\n isNode: boolean\n ): FilterFunction<T> {\n const filterFunctions = filterRules.map((filter: ItemSelector) =>\n Filters.filterToFilterFunction(filter, isNode)\n );\n\n /**\n * For each filterFunction, as soon as we find a filterFunction that says that a given\n * node/edge should be filtered/hidden, we return `true` for the node/edge.\n */\n return (itemData: T): boolean => {\n for (const filterFunction of filterFunctions) {\n if (filterFunction(itemData)) {\n return true;\n }\n }\n return false;\n };\n }\n\n private static filterToFilterFunction<T extends LkNodeData | LkEdgeData>(\n filter: ItemSelector,\n isNode: boolean\n ): FilterFunction<T> {\n switch (filter.type) {\n case SelectorType.ANY:\n return Filters.createAnyFilterFunction(filter, isNode);\n case SelectorType.IS:\n return Filters.createIsFilterFunction(filter, isNode);\n case SelectorType.NO_VALUE:\n return Filters.createNoValueFilterFunction(filter, isNode);\n case SelectorType.RANGE:\n return Filters.createRangeFilterFunction(filter, isNode);\n case SelectorType.NAN:\n return Filters.createNaNFilterFunction(filter, isNode);\n }\n }\n\n private static createAnyFilterFunction<T extends LkNodeData | LkEdgeData>(\n filter: ISelectorAny,\n isNode: boolean\n ): FilterFunction<T> {\n if (isNode) {\n return (itemData: T) => {\n if (filter.itemType === undefined) {\n return true;\n }\n return (itemData as LkNodeData).categories.includes(filter.itemType);\n };\n } else {\n // isEdge\n return (itemData: T) => (itemData as LkEdgeData).type === filter.itemType;\n }\n }\n\n private static createIsFilterFunction<T extends LkNodeData | LkEdgeData>(\n filter: ISelectorIs,\n isNode: boolean\n ): FilterFunction<T> {\n if (isNode) {\n return (itemData: T) =>\n (itemData as LkNodeData).categories.includes(filter.itemType) &&\n Tools.getPropertyValue(Tools.getIn(itemData, filter.input), true) === filter.value;\n } else {\n // isEdge\n return (itemData: T) =>\n (itemData as LkEdgeData).type === filter.itemType &&\n Tools.getPropertyValue(Tools.getIn(itemData, filter.input), true) === filter.value;\n }\n }\n\n private static createNoValueFilterFunction<T extends LkNodeData | LkEdgeData>(\n filter: ISelectorNoValue,\n isNode: boolean\n ): FilterFunction<T> {\n if (isNode) {\n return (itemData: T) =>\n (itemData as LkNodeData).categories.includes(filter.itemType) &&\n !Tools.isDefined(Tools.getPropertyValue(Tools.getIn(itemData, filter.input), true));\n } else {\n // isEdge\n return (itemData: T) =>\n (itemData as LkEdgeData).type === filter.itemType &&\n !Tools.isDefined(Tools.getPropertyValue(Tools.getIn(itemData, filter.input), true));\n }\n }\n\n private static createNaNFilterFunction<T extends LkNodeData | LkEdgeData>(\n filter: ISelectorNaN,\n isNode: boolean\n ): FilterFunction<T> {\n if (isNode) {\n return (itemData: T) =>\n (itemData as LkNodeData).categories.includes(filter.itemType) &&\n Filters.isNotANumber(Tools.getPropertyValue(Tools.getIn(itemData, filter.input), true));\n } else {\n // isEdge\n return (itemData: T) =>\n (itemData as LkEdgeData).type === filter.itemType &&\n Filters.isNotANumber(Tools.getPropertyValue(Tools.getIn(itemData, filter.input), true));\n }\n }\n\n private static isNotANumber(value: any) {\n return Tools.isDefined(value) && !Tools.isNumber(value);\n }\n\n public static createRangeFilterFunction<T extends LkNodeData | LkEdgeData>(\n filter: ISelectorRange,\n isNode: boolean\n ): FilterFunction<T> {\n if (isNode) {\n return (itemData: T) =>\n (itemData as LkNodeData).categories.includes(filter.itemType) &&\n Filters.valueShouldBeHidden(\n Tools.getPropertyValue(Tools.getIn(itemData, filter.input), false),\n filter.value\n );\n } else {\n // isEdge\n return (itemData: T) =>\n (itemData as LkEdgeData).type === filter.itemType &&\n Filters.valueShouldBeHidden(\n Tools.getPropertyValue(Tools.getIn(itemData, filter.input), false),\n filter.value\n );\n }\n }\n\n /**\n * Returns true if `value` should be filtered/hidden.\n *\n * `range` describes what should be filtered/hidden:\n * - e.g. {\"<\":10, \">=\":20} => hide any value in ]-inf, 10[ *OR* in [20, +inf[\n * - e.g. {\"<=\":10} => hide any value in ]-inf, 10]\n * - e.g. {\">=\":20} => hide any value in [20, +inf[\n *\n * Returns false (i.e. will not filter/hide) if `value` is not a number.\n */\n public static valueShouldBeHidden(value: unknown, range: IRangeValues): boolean {\n const n = Tools.parseFloat(value);\n if (Number.isNaN(n)) {\n return false;\n }\n\n /**\n * As soon as we find a condition that says that `value` should be filtered/hidden,\n * we return `true`.\n *\n * If `range` contains multiple conditions, all are checked and if any condition causes\n * `value` to be in the filtered/hidden range, we return `true`.\n *\n * If no condition causes `value` to be filtered/hidden, we return `false`.\n */\n return (\n (range['<'] !== undefined && n < range['<']) ||\n (range['<='] !== undefined && n <= range['<=']) ||\n (range['>'] !== undefined && n > range['>']) ||\n (range['>='] !== undefined && n >= range['>='])\n );\n }\n}\n"]}
@@ -1,51 +1,36 @@
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 rxjs_1 = require("rxjs");
17
- var operators_1 = require("rxjs/operators");
18
- var tools_1 = require("../../tools/tools");
19
- var reactive_1 = require("./reactive");
20
- var OgmaStore = /** @class */ (function (_super) {
21
- __extends(OgmaStore, _super);
22
- function OgmaStore(d) {
23
- return _super.call(this, d) || this;
3
+ const rxjs_1 = require("rxjs");
4
+ const operators_1 = require("rxjs/operators");
5
+ const tools_1 = require("../../tools/tools");
6
+ const reactive_1 = require("./reactive");
7
+ class OgmaStore extends rxjs_1.BehaviorSubject {
8
+ constructor(d) {
9
+ super(d);
24
10
  }
25
11
  /**
26
12
  * Modify Ogma state based on a method
27
13
  */
28
- OgmaStore.prototype.dispatch = function (mapFn) {
14
+ dispatch(mapFn) {
29
15
  this.next(mapFn(this.value));
30
- };
16
+ }
31
17
  /**
32
18
  * Return a piece of state
33
19
  */
34
- OgmaStore.prototype.selectStore = function (mapFn) {
35
- return this.pipe(operators_1.map(mapFn), operators_1.distinctUntilChanged(function (p, n) { return tools_1.Tools.isEqual(p, n); }));
36
- };
20
+ selectStore(mapFn) {
21
+ return this.pipe(operators_1.map(mapFn), operators_1.distinctUntilChanged((p, n) => tools_1.Tools.isEqual(p, n)));
22
+ }
37
23
  /**
38
24
  * Clear the state of Ogma
39
25
  */
40
- OgmaStore.prototype.clear = function () {
26
+ clear() {
41
27
  this.next({
42
28
  selection: new reactive_1.DummyNodeList(),
43
29
  items: { node: [], edge: [] },
44
30
  changes: undefined,
45
31
  animation: false
46
32
  });
47
- };
48
- return OgmaStore;
49
- }(rxjs_1.BehaviorSubject));
33
+ }
34
+ }
50
35
  exports.OgmaStore = OgmaStore;
51
36
  //# sourceMappingURL=OgmaStore.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"OgmaStore.js","sourceRoot":"","sources":["../../../src/ogma/features/OgmaStore.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;;;;;;;;;;AAEb,6BAAiD;AACjD,4CAAyD;AAEzD,2CAAwC;AAExC,uCAAoD;AAEpD;IAA+B,6BAA0B;IACvD,mBAAY,CAAY;eACtB,kBAAM,CAAC,CAAC;IACV,CAAC;IAED;;OAEG;IACI,4BAAQ,GAAf,UAAgB,KAAsC;QACpD,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IAC/B,CAAC;IAED;;OAEG;IACI,+BAAW,GAAlB,UAAsB,KAA8B;QAClD,OAAO,IAAI,CAAC,IAAI,CACd,eAAG,CAAC,KAAK,CAAC,EACV,gCAAoB,CAAC,UAAC,CAAC,EAAE,CAAC,IAAK,OAAA,aAAK,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,EAAnB,CAAmB,CAAC,CACpD,CAAC;IACJ,CAAC;IAED;;OAEG;IACI,yBAAK,GAAZ;QACE,IAAI,CAAC,IAAI,CAAC;YACR,SAAS,EAAE,IAAI,wBAAa,EAAS;YACrC,KAAK,EAAE,EAAC,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAC;YAC3B,OAAO,EAAE,SAAS;YAClB,SAAS,EAAE,KAAK;SACjB,CAAC,CAAC;IACL,CAAC;IACH,gBAAC;AAAD,CAAC,AAjCD,CAA+B,sBAAe,GAiC7C;AAjCY,8BAAS","sourcesContent":["'use strict';\n\nimport {BehaviorSubject, Observable} from 'rxjs';\nimport {distinctUntilChanged, map} from 'rxjs/operators';\n\nimport {Tools} from '../../tools/tools';\n\nimport {DummyNodeList, OgmaState} from './reactive';\n\nexport class OgmaStore extends BehaviorSubject<OgmaState> {\n constructor(d: OgmaState) {\n super(d);\n }\n\n /**\n * Modify Ogma state based on a method\n */\n public dispatch(mapFn: (state: OgmaState) => OgmaState): void {\n this.next(mapFn(this.value));\n }\n\n /**\n * Return a piece of state\n */\n public selectStore<K>(mapFn: (state: OgmaState) => K): Observable<K> {\n return this.pipe(\n map(mapFn),\n distinctUntilChanged((p, n) => Tools.isEqual(p, n))\n );\n }\n\n /**\n * Clear the state of Ogma\n */\n public clear(): void {\n this.next({\n selection: new DummyNodeList() as any,\n items: {node: [], edge: []},\n changes: undefined,\n animation: false\n });\n }\n}\n"]}
1
+ {"version":3,"file":"OgmaStore.js","sourceRoot":"","sources":["../../../src/ogma/features/OgmaStore.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,+BAAiD;AACjD,8CAAyD;AAEzD,6CAAwC;AAExC,yCAAoD;AAEpD,MAAa,SAAU,SAAQ,sBAA0B;IACvD,YAAY,CAAY;QACtB,KAAK,CAAC,CAAC,CAAC,CAAC;IACX,CAAC;IAED;;OAEG;IACI,QAAQ,CAAC,KAAsC;QACpD,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IAC/B,CAAC;IAED;;OAEG;IACI,WAAW,CAAI,KAA8B;QAClD,OAAO,IAAI,CAAC,IAAI,CACd,eAAG,CAAC,KAAK,CAAC,EACV,gCAAoB,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,aAAK,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CACpD,CAAC;IACJ,CAAC;IAED;;OAEG;IACI,KAAK;QACV,IAAI,CAAC,IAAI,CAAC;YACR,SAAS,EAAE,IAAI,wBAAa,EAAS;YACrC,KAAK,EAAE,EAAC,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAC;YAC3B,OAAO,EAAE,SAAS;YAClB,SAAS,EAAE,KAAK;SACjB,CAAC,CAAC;IACL,CAAC;CACF;AAjCD,8BAiCC","sourcesContent":["'use strict';\n\nimport {BehaviorSubject, Observable} from 'rxjs';\nimport {distinctUntilChanged, map} from 'rxjs/operators';\n\nimport {Tools} from '../../tools/tools';\n\nimport {DummyNodeList, OgmaState} from './reactive';\n\nexport class OgmaStore extends BehaviorSubject<OgmaState> {\n constructor(d: OgmaState) {\n super(d);\n }\n\n /**\n * Modify Ogma state based on a method\n */\n public dispatch(mapFn: (state: OgmaState) => OgmaState): void {\n this.next(mapFn(this.value));\n }\n\n /**\n * Return a piece of state\n */\n public selectStore<K>(mapFn: (state: OgmaState) => K): Observable<K> {\n return this.pipe(\n map(mapFn),\n distinctUntilChanged((p, n) => Tools.isEqual(p, n))\n );\n }\n\n /**\n * Clear the state of Ogma\n */\n public clear(): void {\n this.next({\n selection: new DummyNodeList() as any,\n items: {node: [], edge: []},\n changes: undefined,\n animation: false\n });\n }\n}\n"]}