@linkurious/ogma-linkurious-parser 4.1.6 → 4.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/dist/index.cjs +4 -0
  2. package/dist/index.cjs.map +1 -0
  3. package/dist/index.d.ts +5 -5
  4. package/dist/index.mjs +4082 -0
  5. package/dist/index.mjs.map +1 -0
  6. package/dist/ogma/features/nodeGrouping.d.ts +15 -1
  7. package/dist/tools/ogmaTool.d.ts +3 -1
  8. package/package.json +23 -21
  9. package/dist/captions/captions.js +0 -115
  10. package/dist/captions/captions.js.map +0 -1
  11. package/dist/filters/filters.js +0 -167
  12. package/dist/filters/filters.js.map +0 -1
  13. package/dist/index.js +0 -56
  14. package/dist/index.js.map +0 -1
  15. package/dist/ogma/features/OgmaStore.js +0 -37
  16. package/dist/ogma/features/OgmaStore.js.map +0 -1
  17. package/dist/ogma/features/captions.js +0 -117
  18. package/dist/ogma/features/captions.js.map +0 -1
  19. package/dist/ogma/features/nodeGrouping.js +0 -283
  20. package/dist/ogma/features/nodeGrouping.js.map +0 -1
  21. package/dist/ogma/features/reactive.js +0 -132
  22. package/dist/ogma/features/reactive.js.map +0 -1
  23. package/dist/ogma/features/selectors.js +0 -97
  24. package/dist/ogma/features/selectors.js.map +0 -1
  25. package/dist/ogma/features/styles.js +0 -689
  26. package/dist/ogma/features/styles.js.map +0 -1
  27. package/dist/ogma/features/transformations.js +0 -86
  28. package/dist/ogma/features/transformations.js.map +0 -1
  29. package/dist/ogma/index.js +0 -326
  30. package/dist/ogma/index.js.map +0 -1
  31. package/dist/styles/edgeAttributes.js +0 -115
  32. package/dist/styles/edgeAttributes.js.map +0 -1
  33. package/dist/styles/itemAttributes.js +0 -133
  34. package/dist/styles/itemAttributes.js.map +0 -1
  35. package/dist/styles/nodeAttributes.js +0 -228
  36. package/dist/styles/nodeAttributes.js.map +0 -1
  37. package/dist/styles/styleRule.js +0 -194
  38. package/dist/styles/styleRule.js.map +0 -1
  39. package/dist/styles/styleRules.js +0 -292
  40. package/dist/styles/styleRules.js.map +0 -1
  41. package/dist/tools/colorPalette.js +0 -145
  42. package/dist/tools/colorPalette.js.map +0 -1
  43. package/dist/tools/ogmaTool.js +0 -86
  44. package/dist/tools/ogmaTool.js.map +0 -1
  45. package/dist/tools/tools.js +0 -409
  46. package/dist/tools/tools.js.map +0 -1
@@ -1,8 +1,17 @@
1
- import { Transformation, NodeList, StyleRule } from '@linkurious/ogma';
1
+ import { Transformation, NodeList, StyleRule, PixelSize, Point } from '@linkurious/ogma';
2
2
  import { IVizNodeGroupInfo, LkEdgeData, LkNodeData, NodeGroupingRule } from '@linkurious/rest-client';
3
3
  import { LKOgma } from '../index';
4
4
  export declare const LKE_NODE_GROUPING_EDGE = "LKE_NODE_GROUPING_EDGE";
5
5
  export declare const LKE_NODE_GROUPING_NODE = "LKE_NODE_GROUPING_NODE";
6
+ interface CircularLayoutOptions {
7
+ radii: PixelSize[] | number[];
8
+ cx?: number;
9
+ cy?: number;
10
+ startAngle?: number;
11
+ clockwise?: boolean;
12
+ getRadius?: (radius: PixelSize) => number;
13
+ distanceRatio?: number;
14
+ }
6
15
  export declare class NodeGroupingTransformation {
7
16
  transformation?: Transformation<LkNodeData, LkEdgeData>;
8
17
  groupRule?: NodeGroupingRule;
@@ -59,6 +68,7 @@ export declare class NodeGroupingTransformation {
59
68
  * @param subNodes
60
69
  */
61
70
  private _runCirclePack;
71
+ private _runChainLayout;
62
72
  private _runForceLayout;
63
73
  private _isRuleNotApplicableToNode;
64
74
  /**
@@ -77,4 +87,8 @@ export declare class NodeGroupingTransformation {
77
87
  * Return a hashed string that represents the group id
78
88
  */
79
89
  private _findNodeGroupId;
90
+ _runCircularLayout({ radii, clockwise, cx, cy, startAngle, getRadius, distanceRatio }: CircularLayoutOptions): Point[];
91
+ private _runTwoNodesLayout;
92
+ private isStar;
80
93
  }
94
+ export {};
@@ -1,4 +1,4 @@
1
- import { Color, NodeList, Node, EdgeList, Edge } from '@linkurious/ogma';
1
+ import { Color, NodeList, Node, EdgeList, Edge, NodeId } from '@linkurious/ogma';
2
2
  import { LkEdgeData, LkNodeData } from '@linkurious/rest-client';
3
3
  export declare class OgmaTools {
4
4
  /**
@@ -23,4 +23,6 @@ export declare class OgmaTools {
23
23
  static isBright(color: Color): boolean;
24
24
  static isNode(item: Node<LkNodeData, LkEdgeData> | Edge<LkEdgeData, LkNodeData>): item is Node<LkNodeData, LkEdgeData>;
25
25
  static isNodeList(items: NodeList<LkNodeData, LkEdgeData> | EdgeList<LkEdgeData, LkNodeData>): items is NodeList<LkNodeData, LkEdgeData>;
26
+ static topologicalSort(nodes: NodeList): NodeId[];
27
+ static isStar(nodes: NodeList): false | Node<any, any>;
26
28
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@linkurious/ogma-linkurious-parser",
3
- "version": "4.1.6",
3
+ "version": "4.1.8",
4
4
  "author": "Linkurious SAS",
5
5
  "description": "Parse and load a Linkurious visualization in Ogma with one line of code ",
6
6
  "files": [
@@ -10,18 +10,25 @@
10
10
  "access": "public"
11
11
  },
12
12
  "private": false,
13
- "main": "./dist/index.js",
13
+ "type": "module",
14
+ "main": "./dist/index.cjs",
15
+ "module": "./dist/index.mjs",
14
16
  "types": "./dist/index.d.ts",
15
17
  "engines": {
16
- "node": "20.17.0"
18
+ "node": "20.18.0"
19
+ },
20
+ "exports": {
21
+ ".": {
22
+ "import": "./dist/index.mjs",
23
+ "require": "./dist/index.cjs"
24
+ }
17
25
  },
18
26
  "scripts": {
19
- "build": "tsc -b",
20
- "compile": "tsc -b",
21
- "tsc": "tsc -b",
22
- "build:rollup": "rollup -c",
23
- "test": "mocha -r ts-node/register/transpile-only tests/**/*.spec.ts",
24
- "test:unit": "nyc --reporter=text-summary --reporter=cobertura --report-dir=reports mocha -r ts-node/register/transpile-only --reporter mocha-multi-reporters --reporter-options configFile=.test-reporters.json tests/**/*.spec.ts",
27
+ "build": "npm run compile && npm run build:bundle",
28
+ "compile": "tsc --emitDeclarationOnly",
29
+ "build:bundle": "vite build",
30
+ "test": "mocha -r tsx tests/**/*.spec.ts",
31
+ "test:unit": "nyc --reporter=text-summary --reporter=cobertura --report-dir=reports mocha -r tsx --reporter mocha-multi-reporters --reporter-options configFile=.test-reporters.json tests/**/*.spec.ts",
25
32
  "clean": "rm -rf node_modules; rm -rf package-lock.json; rm -rf dist",
26
33
  "lint": "eslint --fix --ext .ts .",
27
34
  "lint:ci": "eslint -f checkstyle -o reports/checkstyle.xml --ext .ts .",
@@ -54,11 +61,7 @@
54
61
  },
55
62
  "devDependencies": {
56
63
  "@linkurious/ogma": "5.1.1",
57
- "@linkurious/rest-client": "4.1.6",
58
- "@rollup/plugin-buble": "0.21.3",
59
- "@rollup/plugin-commonjs": "17.0.0",
60
- "@rollup/plugin-json": "4.1.0",
61
- "@rollup/plugin-node-resolve": "11.0.1",
64
+ "@linkurious/rest-client": "4.1.8",
62
65
  "@types/chai": "4.2.17",
63
66
  "@types/lodash": "4.14.182",
64
67
  "@types/mocha": "5.2.7",
@@ -69,17 +72,16 @@
69
72
  "eslint": "8.57.0",
70
73
  "eslint-config-prettier": "6.10.1",
71
74
  "eslint-plugin-import": "2.29.0",
72
- "eslint-plugin-prettier": "3.4.0",
75
+ "eslint-plugin-prettier": "5.2.1",
73
76
  "mocha": "9.2.0",
74
77
  "mocha-junit-reporter": "2.0.2",
75
78
  "mocha-multi-reporters": "1.5.1",
76
79
  "nyc": "15.1.0",
77
- "prettier": "2.2.1",
78
- "rollup": "2.47.0",
79
- "rollup-plugin-node-globals": "1.4.0",
80
- "rollup-plugin-typescript2": "0.29.0",
80
+ "prettier": "3.3.3",
81
81
  "should": "11.1.0",
82
- "ts-node": "10.9.1",
83
- "typescript": "5.5.4"
82
+ "tslib": "2.8.0",
83
+ "tsx": "4.19.2",
84
+ "typescript": "5.5.4",
85
+ "vite": "5.4.10"
84
86
  }
85
87
  }
@@ -1,115 +0,0 @@
1
- 'use strict';
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Captions = void 0;
4
- const rest_client_1 = require("@linkurious/rest-client");
5
- const tools_1 = require("../tools/tools");
6
- class Captions {
7
- /**
8
- * Return label for each node
9
- */
10
- static getText(itemData, schema, graphSchema) {
11
- const types = 'categories' in itemData ? itemData.categories : [itemData.type];
12
- if (Captions.captionExist(types, schema)) {
13
- return 'categories' in itemData
14
- ? Captions.generateNodeCaption(itemData, schema, graphSchema) || null
15
- : Captions.generateEdgeCaption(itemData, schema, graphSchema) || null;
16
- }
17
- if (itemData.properties !== undefined) {
18
- const heuristicCaptionElement = tools_1.CAPTION_HEURISTIC.find((value) => {
19
- return itemData.properties[value] !== undefined;
20
- });
21
- if (heuristicCaptionElement !== undefined &&
22
- tools_1.Tools.isDefined(itemData.properties[heuristicCaptionElement])) {
23
- return `${tools_1.Tools.getValueFromLkProperty(itemData.properties[heuristicCaptionElement])}`.trim();
24
- }
25
- }
26
- return null;
27
- }
28
- /**
29
- * Return a readable string from an LkProperty
30
- */
31
- static getLabel(propertyValue, propertyType) {
32
- if (typeof propertyValue === 'object' && 'type' in propertyValue) {
33
- if (!('original' in propertyValue) && !('value' in propertyValue)) {
34
- return null;
35
- }
36
- if ('original' in propertyValue) {
37
- return `${propertyValue.original}`;
38
- }
39
- if ('value' in propertyValue) {
40
- return tools_1.Tools.formatDate(new Date(new Date(propertyValue.value).getTime() +
41
- tools_1.Tools.timezoneToMilliseconds(propertyValue.timezone)).toISOString());
42
- }
43
- }
44
- else if ((propertyType === null || propertyType === void 0 ? void 0 : propertyType.name) === rest_client_1.PropertyTypeName.NUMBER &&
45
- propertyType.options !== undefined) {
46
- return tools_1.Tools.formatCurrencyValue(propertyValue, propertyType.options);
47
- }
48
- return `${propertyValue}`.trim();
49
- }
50
- /**
51
- * Return true if caption configuration exists in schema
52
- */
53
- static captionExist(itemTypes, schema) {
54
- return itemTypes.some((type) => tools_1.Tools.isDefined(schema[type]));
55
- }
56
- /**
57
- * Generate text from node data and captions schema
58
- */
59
- static generateNodeCaption(itemData, schema, graphSchema) {
60
- const categories = itemData.categories;
61
- const caption = [];
62
- let captionProps = [];
63
- categories.forEach((category) => {
64
- if (schema[category] && schema[category].active) {
65
- if (schema[category].displayName) {
66
- caption.push(category);
67
- }
68
- captionProps = [...captionProps, ...schema[category].properties];
69
- }
70
- });
71
- tools_1.Tools.uniqBy(captionProps).forEach((propertyKey) => {
72
- if (itemData.properties[propertyKey] !== undefined) {
73
- const propertyType = graphSchema
74
- ? Captions.getPropertyType(graphSchema, propertyKey, categories[0])
75
- : undefined;
76
- caption.push(this.getLabel(itemData.properties[propertyKey], propertyType));
77
- }
78
- });
79
- return caption
80
- .filter((c) => c !== null)
81
- .join(' - ')
82
- .trim();
83
- }
84
- static getPropertyType(graphSchema, propertyKey, itemType) {
85
- const typeGraphSchema = graphSchema.find((schemaType) => schemaType.itemType === itemType);
86
- const property = typeGraphSchema === null || typeGraphSchema === void 0 ? void 0 : typeGraphSchema.properties.find((property) => property.propertyKey === propertyKey);
87
- return property === null || property === void 0 ? void 0 : property.propertyType;
88
- }
89
- /**
90
- * Generate text from edge data and captions schema
91
- */
92
- static generateEdgeCaption(itemData, schema, graphSchema) {
93
- const type = itemData.type;
94
- const caption = [];
95
- let captionProps = [];
96
- if (schema[type] && schema[type].active) {
97
- if (schema[type].displayName) {
98
- caption.push(type);
99
- }
100
- captionProps = [...captionProps, ...schema[type].properties];
101
- tools_1.Tools.uniqBy(captionProps).forEach((propertyKey) => {
102
- if (tools_1.Tools.isDefined(itemData.properties[propertyKey])) {
103
- const propertyType = graphSchema
104
- ? Captions.getPropertyType(graphSchema, propertyKey, type)
105
- : undefined;
106
- caption.push(Captions.getLabel(itemData.properties[propertyKey], propertyType));
107
- }
108
- });
109
- return caption.join(' - ').trim();
110
- }
111
- return '';
112
- }
113
- }
114
- exports.Captions = Captions;
115
- //# sourceMappingURL=captions.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"captions.js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AAC,EAAE,YAAY,CAAC,CAAC,CAAC;gBAClF,CAAC;YACH,CAAC,CAAC,CAAC;YACH,OAAO,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC;QACpC,CAAC;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,167 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Filters = void 0;
4
- const rest_client_1 = require("@linkurious/rest-client");
5
- const tools_1 = require("../tools/tools");
6
- class Filters {
7
- /**
8
- * Returns whether the node/edge should be *filtered* (a.k.a. *hidden*).
9
- *
10
- * Notes:
11
- * 1. `filterRules` are rules that match what should be filtered/hidden.
12
- * 2. `filterRules` are combined inclusively: as soon as one rule returns `true` for
13
- * an item, the item can be hidden/filtered.
14
- *
15
- * @param filterRules
16
- * @param itemData
17
- */
18
- static isFiltered(filterRules, itemData) {
19
- if (!tools_1.Tools.isDefined(itemData)) {
20
- return false;
21
- }
22
- if ('categories' in itemData) {
23
- return Filters.getFilterFunction(filterRules, true)(itemData);
24
- }
25
- else {
26
- return Filters.getFilterFunction(filterRules, false)(itemData);
27
- }
28
- }
29
- static getFilterFunction(filterRules, isNode) {
30
- const filterKey = JSON.stringify(filterRules, null, '');
31
- // This cast is needed to tell the TypeScript compiler to trust us that "isNode" and "T" are dependent.
32
- const filterCache = (isNode ? Filters.nodeCache : Filters.edgeCache);
33
- let filterFunc = filterCache.get(filterKey);
34
- if (!filterFunc) {
35
- filterFunc = Filters.createFilterFunction(filterRules, isNode);
36
- if (filterCache.size > Filters.FILTER_CACHE_SIZE) {
37
- filterCache.clear();
38
- }
39
- filterCache.set(filterKey, filterFunc);
40
- }
41
- return filterFunc;
42
- }
43
- static createFilterFunction(filterRules, isNode) {
44
- const filterFunctions = filterRules.map((filter) => Filters.filterToFilterFunction(filter, isNode));
45
- /**
46
- * For each filterFunction, as soon as we find a filterFunction that says that a given
47
- * node/edge should be filtered/hidden, we return `true` for the node/edge.
48
- */
49
- return (itemData) => {
50
- for (const filterFunction of filterFunctions) {
51
- if (filterFunction(itemData)) {
52
- return true;
53
- }
54
- }
55
- return false;
56
- };
57
- }
58
- static filterToFilterFunction(filter, isNode) {
59
- switch (filter.type) {
60
- case rest_client_1.SelectorType.ANY:
61
- return Filters.createAnyFilterFunction(filter, isNode);
62
- case rest_client_1.SelectorType.IS:
63
- return Filters.createIsFilterFunction(filter, isNode);
64
- case rest_client_1.SelectorType.NO_VALUE:
65
- return Filters.createNoValueFilterFunction(filter, isNode);
66
- case rest_client_1.SelectorType.RANGE:
67
- return Filters.createRangeFilterFunction(filter, isNode);
68
- case rest_client_1.SelectorType.NAN:
69
- return Filters.createNaNFilterFunction(filter, isNode);
70
- }
71
- }
72
- static createAnyFilterFunction(filter, isNode) {
73
- if (isNode) {
74
- return (itemData) => {
75
- if (filter.itemType === undefined) {
76
- return true;
77
- }
78
- return itemData.categories.includes(filter.itemType);
79
- };
80
- }
81
- else {
82
- // isEdge
83
- return (itemData) => itemData.type === filter.itemType;
84
- }
85
- }
86
- static createIsFilterFunction(filter, isNode) {
87
- if (isNode) {
88
- return (itemData) => itemData.categories.includes(filter.itemType) &&
89
- tools_1.Tools.getPropertyValue(tools_1.Tools.getIn(itemData, filter.input), true) === filter.value;
90
- }
91
- else {
92
- // isEdge
93
- return (itemData) => itemData.type === filter.itemType &&
94
- tools_1.Tools.getPropertyValue(tools_1.Tools.getIn(itemData, filter.input), true) === filter.value;
95
- }
96
- }
97
- static createNoValueFilterFunction(filter, isNode) {
98
- if (isNode) {
99
- return (itemData) => itemData.categories.includes(filter.itemType) &&
100
- !tools_1.Tools.isDefined(tools_1.Tools.getPropertyValue(tools_1.Tools.getIn(itemData, filter.input), true));
101
- }
102
- else {
103
- // isEdge
104
- return (itemData) => itemData.type === filter.itemType &&
105
- !tools_1.Tools.isDefined(tools_1.Tools.getPropertyValue(tools_1.Tools.getIn(itemData, filter.input), true));
106
- }
107
- }
108
- static createNaNFilterFunction(filter, isNode) {
109
- if (isNode) {
110
- return (itemData) => itemData.categories.includes(filter.itemType) &&
111
- Filters.isNotANumber(tools_1.Tools.getPropertyValue(tools_1.Tools.getIn(itemData, filter.input), true));
112
- }
113
- else {
114
- // isEdge
115
- return (itemData) => itemData.type === filter.itemType &&
116
- Filters.isNotANumber(tools_1.Tools.getPropertyValue(tools_1.Tools.getIn(itemData, filter.input), true));
117
- }
118
- }
119
- static isNotANumber(value) {
120
- return tools_1.Tools.isDefined(value) && !tools_1.Tools.isNumber(value);
121
- }
122
- static createRangeFilterFunction(filter, isNode) {
123
- if (isNode) {
124
- return (itemData) => itemData.categories.includes(filter.itemType) &&
125
- Filters.valueShouldBeHidden(tools_1.Tools.getPropertyValue(tools_1.Tools.getIn(itemData, filter.input), false), filter.value);
126
- }
127
- else {
128
- // isEdge
129
- return (itemData) => itemData.type === filter.itemType &&
130
- Filters.valueShouldBeHidden(tools_1.Tools.getPropertyValue(tools_1.Tools.getIn(itemData, filter.input), false), filter.value);
131
- }
132
- }
133
- /**
134
- * Returns true if `value` should be filtered/hidden.
135
- *
136
- * `range` describes what should be filtered/hidden:
137
- * - e.g. {"<":10, ">=":20} => hide any value in ]-inf, 10[ *OR* in [20, +inf[
138
- * - e.g. {"<=":10} => hide any value in ]-inf, 10]
139
- * - e.g. {">=":20} => hide any value in [20, +inf[
140
- *
141
- * Returns false (i.e. will not filter/hide) if `value` is not a number.
142
- */
143
- static valueShouldBeHidden(value, range) {
144
- const n = tools_1.Tools.parseFloat(value);
145
- if (Number.isNaN(n)) {
146
- return false;
147
- }
148
- /**
149
- * As soon as we find a condition that says that `value` should be filtered/hidden,
150
- * we return `true`.
151
- *
152
- * If `range` contains multiple conditions, all are checked and if any condition causes
153
- * `value` to be in the filtered/hidden range, we return `true`.
154
- *
155
- * If no condition causes `value` to be filtered/hidden, we return `false`.
156
- */
157
- return ((range['<'] !== undefined && n < range['<']) ||
158
- (range['<='] !== undefined && n <= range['<=']) ||
159
- (range['>'] !== undefined && n > range['>']) ||
160
- (range['>='] !== undefined && n >= range['>=']));
161
- }
162
- }
163
- exports.Filters = Filters;
164
- Filters.nodeCache = new Map();
165
- Filters.edgeCache = new Map();
166
- Filters.FILTER_CACHE_SIZE = 5;
167
- //# sourceMappingURL=filters.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"filters.js","sourceRoot":"","sources":["../../src/filters/filters.ts"],"names":[],"mappings":";;;AAAA,yDAYiC;AAEjC,0CAAqC;AAIrC,MAAa,OAAO;IAKlB;;;;;;;;;;OAUG;IACI,MAAM,CAAC,UAAU,CACtB,WAAgC,EAChC,QAAiC;QAEjC,IAAI,CAAC,aAAK,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC/B,OAAO,KAAK,CAAC;QACf,CAAC;QAED,IAAI,YAAY,IAAI,QAAQ,EAAE,CAAC;YAC7B,OAAO,OAAO,CAAC,iBAAiB,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC,QAAQ,CAAC,CAAC;QAChE,CAAC;aAAM,CAAC;YACN,OAAO,OAAO,CAAC,iBAAiB,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC,QAAQ,CAAC,CAAC;QACjE,CAAC;IACH,CAAC;IAEO,MAAM,CAAC,iBAAiB,CAC9B,WAAgC,EAChC,MAAe;QAEf,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC;QAExD,uGAAuG;QACvG,MAAM,WAAW,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAGlE,CAAC;QAEF,IAAI,UAAU,GAAG,WAAW,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QAC5C,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,UAAU,GAAG,OAAO,CAAC,oBAAoB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AI,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"]}
package/dist/index.js DELETED
@@ -1,56 +0,0 @@
1
- 'use strict';
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LKE_NODE_GROUPING_EDGE = exports.Tools = exports.ANIMATION_DURATION = exports.LKOgma = exports.hasSelectionProperties = exports.getSelectionProperties = exports.getUniqSelectionEntity = exports.getUniqSelectionTypes = exports.getUniqSelection = exports.getSelectionEntity = exports.getSelectionState = exports.getSelectionSize = exports.OgmaStore = exports.Filters = exports.HTML_COLORS = exports.OgmaTools = exports.CaptionsViz = exports.TransformationsViz = exports.FILTER_OPACITY = exports.StylesViz = exports.StyleType = exports.StyleRules = exports.StyleRuleType = exports.StyleRule = exports.NodeAttributes = exports.EdgeAttributes = exports.PALETTE = exports.BASE_GREY = exports.ItemAttributes = exports.Captions = exports.NodeList = exports.Node = exports.EdgeList = exports.Edge = void 0;
4
- var ogma_1 = require("@linkurious/ogma");
5
- Object.defineProperty(exports, "Edge", { enumerable: true, get: function () { return ogma_1.Edge; } });
6
- Object.defineProperty(exports, "EdgeList", { enumerable: true, get: function () { return ogma_1.EdgeList; } });
7
- Object.defineProperty(exports, "Node", { enumerable: true, get: function () { return ogma_1.Node; } });
8
- Object.defineProperty(exports, "NodeList", { enumerable: true, get: function () { return ogma_1.NodeList; } });
9
- var captions_1 = require("./captions/captions");
10
- Object.defineProperty(exports, "Captions", { enumerable: true, get: function () { return captions_1.Captions; } });
11
- var itemAttributes_1 = require("./styles/itemAttributes");
12
- Object.defineProperty(exports, "ItemAttributes", { enumerable: true, get: function () { return itemAttributes_1.ItemAttributes; } });
13
- Object.defineProperty(exports, "BASE_GREY", { enumerable: true, get: function () { return itemAttributes_1.BASE_GREY; } });
14
- Object.defineProperty(exports, "PALETTE", { enumerable: true, get: function () { return itemAttributes_1.PALETTE; } });
15
- var edgeAttributes_1 = require("./styles/edgeAttributes");
16
- Object.defineProperty(exports, "EdgeAttributes", { enumerable: true, get: function () { return edgeAttributes_1.EdgeAttributes; } });
17
- var nodeAttributes_1 = require("./styles/nodeAttributes");
18
- Object.defineProperty(exports, "NodeAttributes", { enumerable: true, get: function () { return nodeAttributes_1.NodeAttributes; } });
19
- var styleRule_1 = require("./styles/styleRule");
20
- Object.defineProperty(exports, "StyleRule", { enumerable: true, get: function () { return styleRule_1.StyleRule; } });
21
- Object.defineProperty(exports, "StyleRuleType", { enumerable: true, get: function () { return styleRule_1.StyleRuleType; } });
22
- var styleRules_1 = require("./styles/styleRules");
23
- Object.defineProperty(exports, "StyleRules", { enumerable: true, get: function () { return styleRules_1.StyleRules; } });
24
- Object.defineProperty(exports, "StyleType", { enumerable: true, get: function () { return styleRules_1.StyleType; } });
25
- var styles_1 = require("./ogma/features/styles");
26
- Object.defineProperty(exports, "StylesViz", { enumerable: true, get: function () { return styles_1.StylesViz; } });
27
- Object.defineProperty(exports, "FILTER_OPACITY", { enumerable: true, get: function () { return styles_1.FILTER_OPACITY; } });
28
- var transformations_1 = require("./ogma/features/transformations");
29
- Object.defineProperty(exports, "TransformationsViz", { enumerable: true, get: function () { return transformations_1.TransformationsViz; } });
30
- var captions_2 = require("./ogma/features/captions");
31
- Object.defineProperty(exports, "CaptionsViz", { enumerable: true, get: function () { return captions_2.CaptionsViz; } });
32
- var ogmaTool_1 = require("./tools/ogmaTool");
33
- Object.defineProperty(exports, "OgmaTools", { enumerable: true, get: function () { return ogmaTool_1.OgmaTools; } });
34
- var colorPalette_1 = require("./tools/colorPalette");
35
- Object.defineProperty(exports, "HTML_COLORS", { enumerable: true, get: function () { return colorPalette_1.HTML_COLORS; } });
36
- var filters_1 = require("./filters/filters");
37
- Object.defineProperty(exports, "Filters", { enumerable: true, get: function () { return filters_1.Filters; } });
38
- var OgmaStore_1 = require("./ogma/features/OgmaStore");
39
- Object.defineProperty(exports, "OgmaStore", { enumerable: true, get: function () { return OgmaStore_1.OgmaStore; } });
40
- var selectors_1 = require("./ogma/features/selectors");
41
- Object.defineProperty(exports, "getSelectionSize", { enumerable: true, get: function () { return selectors_1.getSelectionSize; } });
42
- Object.defineProperty(exports, "getSelectionState", { enumerable: true, get: function () { return selectors_1.getSelectionState; } });
43
- Object.defineProperty(exports, "getSelectionEntity", { enumerable: true, get: function () { return selectors_1.getSelectionEntity; } });
44
- Object.defineProperty(exports, "getUniqSelection", { enumerable: true, get: function () { return selectors_1.getUniqSelection; } });
45
- Object.defineProperty(exports, "getUniqSelectionTypes", { enumerable: true, get: function () { return selectors_1.getUniqSelectionTypes; } });
46
- Object.defineProperty(exports, "getUniqSelectionEntity", { enumerable: true, get: function () { return selectors_1.getUniqSelectionEntity; } });
47
- Object.defineProperty(exports, "getSelectionProperties", { enumerable: true, get: function () { return selectors_1.getSelectionProperties; } });
48
- Object.defineProperty(exports, "hasSelectionProperties", { enumerable: true, get: function () { return selectors_1.hasSelectionProperties; } });
49
- var ogma_2 = require("./ogma");
50
- Object.defineProperty(exports, "LKOgma", { enumerable: true, get: function () { return ogma_2.LKOgma; } });
51
- Object.defineProperty(exports, "ANIMATION_DURATION", { enumerable: true, get: function () { return ogma_2.ANIMATION_DURATION; } });
52
- var tools_1 = require("./tools/tools");
53
- Object.defineProperty(exports, "Tools", { enumerable: true, get: function () { return tools_1.Tools; } });
54
- var nodeGrouping_1 = require("./ogma/features/nodeGrouping");
55
- Object.defineProperty(exports, "LKE_NODE_GROUPING_EDGE", { enumerable: true, get: function () { return nodeGrouping_1.LKE_NODE_GROUPING_EDGE; } });
56
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;AAEb,yCAsB0B;AArBxB,4FAAA,IAAI,OAAA;AACJ,gGAAA,QAAQ,OAAA;AACR,4FAAA,IAAI,OAAA;AACJ,gGAAA,QAAQ,OAAA;AAoBV,gDAA6C;AAArC,oGAAA,QAAQ,OAAA;AAChB,0DAA2E;AAAnE,gHAAA,cAAc,OAAA;AAAE,2GAAA,SAAS,OAAA;AAAE,yGAAA,OAAO,OAAA;AAC1C,0DAAuD;AAA/C,gHAAA,cAAc,OAAA;AACtB,0DAAuD;AAA/C,gHAAA,cAAc,OAAA;AACtB,gDAA4D;AAApD,sGAAA,SAAS,OAAA;AAAE,0GAAA,aAAa,OAAA;AAChC,kDAAkE;AAA1D,wGAAA,UAAU,OAAA;AAAE,uGAAA,SAAS,OAAA;AAC7B,iDAA+E;AAAvE,mGAAA,SAAS,OAAA;AAAgB,wGAAA,cAAc,OAAA;AAC/C,mEAAmE;AAA3D,qHAAA,kBAAkB,OAAA;AAC1B,qDAAmE;AAA3D,uGAAA,WAAW,OAAA;AAEnB,6CAA2C;AAAnC,qGAAA,SAAS,OAAA;AACjB,qDAAiD;AAAzC,2GAAA,WAAW,OAAA;AACnB,6CAA0C;AAAlC,kGAAA,OAAO,OAAA;AACf,uDAAoD;AAA5C,sGAAA,SAAS,OAAA;AACjB,uDASmC;AARjC,6GAAA,gBAAgB,OAAA;AAChB,8GAAA,iBAAiB,OAAA;AACjB,+GAAA,kBAAkB,OAAA;AAClB,6GAAA,gBAAgB,OAAA;AAChB,kHAAA,qBAAqB,OAAA;AACrB,mHAAA,sBAAsB,OAAA;AACtB,mHAAA,sBAAsB,OAAA;AACtB,mHAAA,sBAAsB,OAAA;AAExB,+BAAkD;AAA1C,8FAAA,MAAM,OAAA;AAAE,0GAAA,kBAAkB,OAAA;AAClC,uCAAoC;AAA5B,8FAAA,KAAK,OAAA;AAEb,6DAAoE;AAA5D,sHAAA,sBAAsB,OAAA","sourcesContent":["'use strict';\n\nexport {\n Edge,\n EdgeList,\n Node,\n NodeList,\n EdgeId,\n NodeId,\n RawEdge,\n RawItem,\n RawNode,\n PropertyPath,\n Item,\n ItemId,\n EdgeStyle,\n PixelSize,\n EdgeExtremity,\n EdgeType,\n GeoModeOptions,\n EdgesDataEvent,\n NodesDataEvent,\n NodesDragEndEvent,\n NodesEvent\n} from '@linkurious/ogma';\n\nexport {Captions} from './captions/captions';\nexport {ItemAttributes, BASE_GREY, PALETTE} from './styles/itemAttributes';\nexport {EdgeAttributes} from './styles/edgeAttributes';\nexport {NodeAttributes} from './styles/nodeAttributes';\nexport {StyleRule, StyleRuleType} from './styles/styleRule';\nexport {StyleRules, StyleType, Legend} from './styles/styleRules';\nexport {StylesViz, StylesConfig, FILTER_OPACITY} from './ogma/features/styles';\nexport {TransformationsViz} from './ogma/features/transformations';\nexport {CaptionsViz, CaptionState} from './ogma/features/captions';\nexport {OgmaState} from './ogma/features/reactive';\nexport {OgmaTools} from './tools/ogmaTool';\nexport {HTML_COLORS} from './tools/colorPalette';\nexport {Filters} from './filters/filters';\nexport {OgmaStore} from './ogma/features/OgmaStore';\nexport {\n getSelectionSize,\n getSelectionState,\n getSelectionEntity,\n getUniqSelection,\n getUniqSelectionTypes,\n getUniqSelectionEntity,\n getSelectionProperties,\n hasSelectionProperties\n} from './ogma/features/selectors';\nexport {LKOgma, ANIMATION_DURATION} from './ogma';\nexport {Tools} from './tools/tools';\n\nexport {LKE_NODE_GROUPING_EDGE} from './ogma/features/nodeGrouping';\n"]}
@@ -1,37 +0,0 @@
1
- 'use strict';
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.OgmaStore = void 0;
4
- const rxjs_1 = require("rxjs");
5
- const operators_1 = require("rxjs/operators");
6
- const tools_1 = require("../../tools/tools");
7
- const reactive_1 = require("./reactive");
8
- class OgmaStore extends rxjs_1.BehaviorSubject {
9
- constructor(d) {
10
- super(d);
11
- }
12
- /**
13
- * Modify Ogma state based on a method
14
- */
15
- dispatch(mapFn) {
16
- this.next(mapFn(this.value));
17
- }
18
- /**
19
- * Return a piece of state
20
- */
21
- selectStore(mapFn) {
22
- return this.pipe((0, operators_1.map)(mapFn), (0, operators_1.distinctUntilChanged)((p, n) => tools_1.Tools.isEqual(p, n)));
23
- }
24
- /**
25
- * Clear the state of Ogma
26
- */
27
- clear() {
28
- this.next({
29
- selection: new reactive_1.DummyNodeList(),
30
- items: { node: [], edge: [] },
31
- changes: undefined,
32
- animation: false
33
- });
34
- }
35
- }
36
- exports.OgmaStore = OgmaStore;
37
- //# sourceMappingURL=OgmaStore.js.map
@@ -1 +0,0 @@
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,IAAA,eAAG,EAAC,KAAK,CAAC,EACV,IAAA,gCAAoB,EAAC,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"]}