@linkurious/ogma-linkurious-parser 4.0.0 → 4.0.3

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 (47) hide show
  1. package/README.md +1 -1
  2. package/dist/captions/captions.js +4 -5
  3. package/dist/captions/captions.js.map +1 -1
  4. package/dist/filters/filters.d.ts +1 -1
  5. package/dist/filters/filters.js +1 -0
  6. package/dist/filters/filters.js.map +1 -1
  7. package/dist/index.js +34 -33
  8. package/dist/index.js.map +1 -1
  9. package/dist/ogma/features/OgmaStore.js +2 -1
  10. package/dist/ogma/features/OgmaStore.js.map +1 -1
  11. package/dist/ogma/features/captions.js +1 -0
  12. package/dist/ogma/features/captions.js.map +1 -1
  13. package/dist/ogma/features/reactive.js +1 -0
  14. package/dist/ogma/features/reactive.js.map +1 -1
  15. package/dist/ogma/features/selectors.d.ts +5 -5
  16. package/dist/ogma/features/selectors.js +21 -12
  17. package/dist/ogma/features/selectors.js.map +1 -1
  18. package/dist/ogma/features/styles.d.ts +7 -7
  19. package/dist/ogma/features/styles.js +1 -0
  20. package/dist/ogma/features/styles.js.map +1 -1
  21. package/dist/ogma/features/transformations.d.ts +1 -1
  22. package/dist/ogma/features/transformations.js +16 -17
  23. package/dist/ogma/features/transformations.js.map +1 -1
  24. package/dist/ogma/index.js +14 -18
  25. package/dist/ogma/index.js.map +1 -1
  26. package/dist/styles/edgeAttributes.d.ts +8 -8
  27. package/dist/styles/edgeAttributes.js +16 -15
  28. package/dist/styles/edgeAttributes.js.map +1 -1
  29. package/dist/styles/itemAttributes.d.ts +24 -28
  30. package/dist/styles/itemAttributes.js +31 -23
  31. package/dist/styles/itemAttributes.js.map +1 -1
  32. package/dist/styles/nodeAttributes.d.ts +8 -8
  33. package/dist/styles/nodeAttributes.js +23 -20
  34. package/dist/styles/nodeAttributes.js.map +1 -1
  35. package/dist/styles/styleRule.d.ts +8 -8
  36. package/dist/styles/styleRule.js +2 -0
  37. package/dist/styles/styleRule.js.map +1 -1
  38. package/dist/styles/styleRules.d.ts +5 -5
  39. package/dist/styles/styleRules.js +20 -16
  40. package/dist/styles/styleRules.js.map +1 -1
  41. package/dist/tools/colorPalette.js +1 -0
  42. package/dist/tools/colorPalette.js.map +1 -1
  43. package/dist/tools/ogmaTool.js +1 -0
  44. package/dist/tools/ogmaTool.js.map +1 -1
  45. package/dist/tools/tools.js +2 -1
  46. package/dist/tools/tools.js.map +1 -1
  47. package/package.json +5 -5
package/README.md CHANGED
@@ -69,7 +69,7 @@ async function main() {
69
69
  ogma.setContainer('graph-container');
70
70
 
71
71
  // Initialize the visualization content & styles
72
- ogma.initVisualization(visualizationConfiguration);
72
+ await ogma.initVisualization(visualizationConfiguration);
73
73
  }
74
74
  }
75
75
 
@@ -1,5 +1,6 @@
1
1
  'use strict';
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Captions = void 0;
3
4
  const rest_client_1 = require("@linkurious/rest-client");
4
5
  const tools_1 = require("../tools/tools");
5
6
  class Captions {
@@ -28,7 +29,6 @@ class Captions {
28
29
  * Return a readable string from an LkProperty
29
30
  */
30
31
  static getLabel(propertyValue, propertyType) {
31
- var _a;
32
32
  if (typeof propertyValue === 'object' && 'type' in propertyValue) {
33
33
  if (!('original' in propertyValue) && !('value' in propertyValue)) {
34
34
  return null;
@@ -41,7 +41,7 @@ class Captions {
41
41
  tools_1.Tools.timezoneToMilliseconds(propertyValue.timezone)).toISOString());
42
42
  }
43
43
  }
44
- else if (((_a = propertyType) === null || _a === void 0 ? void 0 : _a.name) === rest_client_1.PropertyTypeName.NUMBER &&
44
+ else if ((propertyType === null || propertyType === void 0 ? void 0 : propertyType.name) === rest_client_1.PropertyTypeName.NUMBER &&
45
45
  propertyType.options !== undefined) {
46
46
  return tools_1.Tools.formatCurrencyValue(propertyValue, propertyType.options);
47
47
  }
@@ -82,10 +82,9 @@ class Captions {
82
82
  .trim();
83
83
  }
84
84
  static getPropertyType(graphSchema, propertyKey, itemType) {
85
- var _a, _b;
86
85
  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);
88
- return (_b = property) === null || _b === void 0 ? void 0 : _b.propertyType;
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;
89
88
  }
90
89
  /**
91
90
  * Generate text from edge data and captions schema
@@ -1 +1 @@
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,CAAC,CAAC;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AAW,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
+ {"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,CAA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,CAAC,EAAE;oBACrD,MAAM,YAAY,GAAG,WAAW;wBAC9B,CAAC,CAAC,QAAQ,CAAC,eAAe,CAAC,WAAW,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,5 +1,5 @@
1
1
  import { ItemSelector, LkEdgeData, LkNodeData, IRangeValues, ISelectorRange, LkItemData } from '@linkurious/rest-client';
2
- declare type FilterFunction<T extends LkItemData> = (itemData: T) => boolean;
2
+ type FilterFunction<T extends LkItemData> = (itemData: T) => boolean;
3
3
  export declare class Filters {
4
4
  private static nodeCache;
5
5
  private static edgeCache;
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Filters = void 0;
3
4
  const rest_client_1 = require("@linkurious/rest-client");
4
5
  const tools_1 = require("../tools/tools");
5
6
  class Filters {
@@ -1 +1 @@
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;YAC9B,OAAO,KAAK,CAAC;SACd;QAED,IAAI,YAAY,IAAI,QAAQ,EAAE;YAC5B,OAAO,OAAO,C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C;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
+ {"version":3,"file":"filters.js","sourceRoot":"","sources":["../../src/filters/filters.ts"],"names":[],"mappings":";;;AAAA,yDAYiC;AAEjC,0CAAqC;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AE,CACpB,QAAuB,CAAC,IAAI,KAAK,MAAM,CAAC,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"]}
package/dist/index.js CHANGED
@@ -1,53 +1,54 @@
1
1
  'use strict';
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ 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;
3
4
  var ogma_1 = require("@linkurious/ogma");
4
- exports.Edge = ogma_1.Edge;
5
- exports.EdgeList = ogma_1.EdgeList;
6
- exports.Node = ogma_1.Node;
7
- exports.NodeList = ogma_1.NodeList;
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; } });
8
9
  var captions_1 = require("./captions/captions");
9
- exports.Captions = captions_1.Captions;
10
+ Object.defineProperty(exports, "Captions", { enumerable: true, get: function () { return captions_1.Captions; } });
10
11
  var itemAttributes_1 = require("./styles/itemAttributes");
11
- exports.ItemAttributes = itemAttributes_1.ItemAttributes;
12
- exports.BASE_GREY = itemAttributes_1.BASE_GREY;
13
- exports.PALETTE = itemAttributes_1.PALETTE;
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; } });
14
15
  var edgeAttributes_1 = require("./styles/edgeAttributes");
15
- exports.EdgeAttributes = edgeAttributes_1.EdgeAttributes;
16
+ Object.defineProperty(exports, "EdgeAttributes", { enumerable: true, get: function () { return edgeAttributes_1.EdgeAttributes; } });
16
17
  var nodeAttributes_1 = require("./styles/nodeAttributes");
17
- exports.NodeAttributes = nodeAttributes_1.NodeAttributes;
18
+ Object.defineProperty(exports, "NodeAttributes", { enumerable: true, get: function () { return nodeAttributes_1.NodeAttributes; } });
18
19
  var styleRule_1 = require("./styles/styleRule");
19
- exports.StyleRule = styleRule_1.StyleRule;
20
- exports.StyleRuleType = styleRule_1.StyleRuleType;
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; } });
21
22
  var styleRules_1 = require("./styles/styleRules");
22
- exports.StyleRules = styleRules_1.StyleRules;
23
- exports.StyleType = styleRules_1.StyleType;
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; } });
24
25
  var styles_1 = require("./ogma/features/styles");
25
- exports.StylesViz = styles_1.StylesViz;
26
- exports.FILTER_OPACITY = styles_1.FILTER_OPACITY;
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; } });
27
28
  var transformations_1 = require("./ogma/features/transformations");
28
- exports.TransformationsViz = transformations_1.TransformationsViz;
29
+ Object.defineProperty(exports, "TransformationsViz", { enumerable: true, get: function () { return transformations_1.TransformationsViz; } });
29
30
  var captions_2 = require("./ogma/features/captions");
30
- exports.CaptionsViz = captions_2.CaptionsViz;
31
+ Object.defineProperty(exports, "CaptionsViz", { enumerable: true, get: function () { return captions_2.CaptionsViz; } });
31
32
  var ogmaTool_1 = require("./tools/ogmaTool");
32
- exports.OgmaTools = ogmaTool_1.OgmaTools;
33
+ Object.defineProperty(exports, "OgmaTools", { enumerable: true, get: function () { return ogmaTool_1.OgmaTools; } });
33
34
  var colorPalette_1 = require("./tools/colorPalette");
34
- exports.HTML_COLORS = colorPalette_1.HTML_COLORS;
35
+ Object.defineProperty(exports, "HTML_COLORS", { enumerable: true, get: function () { return colorPalette_1.HTML_COLORS; } });
35
36
  var filters_1 = require("./filters/filters");
36
- exports.Filters = filters_1.Filters;
37
+ Object.defineProperty(exports, "Filters", { enumerable: true, get: function () { return filters_1.Filters; } });
37
38
  var OgmaStore_1 = require("./ogma/features/OgmaStore");
38
- exports.OgmaStore = OgmaStore_1.OgmaStore;
39
+ Object.defineProperty(exports, "OgmaStore", { enumerable: true, get: function () { return OgmaStore_1.OgmaStore; } });
39
40
  var selectors_1 = require("./ogma/features/selectors");
40
- exports.getSelectionSize = selectors_1.getSelectionSize;
41
- exports.getSelectionState = selectors_1.getSelectionState;
42
- exports.getSelectionEntity = selectors_1.getSelectionEntity;
43
- exports.getUniqSelection = selectors_1.getUniqSelection;
44
- exports.getUniqSelectionTypes = selectors_1.getUniqSelectionTypes;
45
- exports.getUniqSelectionEntity = selectors_1.getUniqSelectionEntity;
46
- exports.getSelectionProperties = selectors_1.getSelectionProperties;
47
- exports.hasSelectionProperties = selectors_1.hasSelectionProperties;
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; } });
48
49
  var ogma_2 = require("./ogma");
49
- exports.LKOgma = ogma_2.LKOgma;
50
- exports.ANIMATION_DURATION = ogma_2.ANIMATION_DURATION;
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; } });
51
52
  var tools_1 = require("./tools/tools");
52
- exports.Tools = tools_1.Tools;
53
+ Object.defineProperty(exports, "Tools", { enumerable: true, get: function () { return tools_1.Tools; } });
53
54
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,yCAsB0B;AArBxB,sBAAA,IAAI,CAAA;AACJ,0BAAA,QAAQ,CAAA;AACR,sBAAA,IAAI,CAAA;AACJ,0BAAA,QAAQ,CAAA;AAoBV,gDAA6C;AAArC,8BAAA,QAAQ,CAAA;AAChB,0DAA2E;AAAnE,0CAAA,cAAc,CAAA;AAAE,qCAAA,SAAS,CAAA;AAAE,mCAAA,OAAO,CAAA;AAC1C,0DAAuD;AAA/C,0CAAA,cAAc,CAAA;AACtB,0DAAuD;AAA/C,0CAAA,cAAc,CAAA;AACtB,gDAA4D;AAApD,gCAAA,SAAS,CAAA;AAAE,oCAAA,aAAa,CAAA;AAChC,kDAAkE;AAA1D,kCAAA,UAAU,CAAA;AAAE,iCAAA,SAAS,CAAA;AAC7B,iDAA+E;AAAvE,6BAAA,SAAS,CAAA;AAAgB,kCAAA,cAAc,CAAA;AAC/C,mEAAmE;AAA3D,+CAAA,kBAAkB,CAAA;AAC1B,qDAAmE;AAA3D,iCAAA,WAAW,CAAA;AAEnB,6CAA2C;AAAnC,+BAAA,SAAS,CAAA;AACjB,qDAAiD;AAAzC,qCAAA,WAAW,CAAA;AACnB,6CAA0C;AAAlC,4BAAA,OAAO,CAAA;AACf,uDAAoD;AAA5C,gCAAA,SAAS,CAAA;AACjB,uDASmC;AARjC,uCAAA,gBAAgB,CAAA;AAChB,wCAAA,iBAAiB,CAAA;AACjB,yCAAA,kBAAkB,CAAA;AAClB,uCAAA,gBAAgB,CAAA;AAChB,4CAAA,qBAAqB,CAAA;AACrB,6CAAA,sBAAsB,CAAA;AACtB,6CAAA,sBAAsB,CAAA;AACtB,6CAAA,sBAAsB,CAAA;AAExB,+BAAkD;AAA1C,wBAAA,MAAM,CAAA;AAAE,oCAAA,kBAAkB,CAAA;AAClC,uCAAoC;AAA5B,wBAAA,KAAK,CAAA","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"]}
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","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"]}
@@ -1,5 +1,6 @@
1
1
  'use strict';
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OgmaStore = void 0;
3
4
  const rxjs_1 = require("rxjs");
4
5
  const operators_1 = require("rxjs/operators");
5
6
  const tools_1 = require("../../tools/tools");
@@ -18,7 +19,7 @@ class OgmaStore extends rxjs_1.BehaviorSubject {
18
19
  * Return a piece of state
19
20
  */
20
21
  selectStore(mapFn) {
21
- return this.pipe(operators_1.map(mapFn), operators_1.distinctUntilChanged((p, n) => tools_1.Tools.isEqual(p, n)));
22
+ return this.pipe((0, operators_1.map)(mapFn), (0, operators_1.distinctUntilChanged)((p, n) => tools_1.Tools.isEqual(p, n)));
22
23
  }
23
24
  /**
24
25
  * Clear the state of Ogma
@@ -1 +1 @@
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"]}
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"]}
@@ -9,6 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.CaptionsViz = void 0;
12
13
  const __1 = require("../..");
13
14
  const tools_1 = require("../../tools/tools");
14
15
  class CaptionsViz {
@@ -1 +1 @@
1
- {"version":3,"file":"captions.js","sourceRoot":"","sources":["../../../src/ogma/features/captions.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;;;;;;AAKb,6BAAuC;AACvC,6CAAwC;AAOxC,MAAa,WAAW;IAUtB,YACE,IAAY,EACJ,kBAAsC,EACtC,kBAAsC;QADtC,uBAAkB,GAAlB,kBAAkB,CAAoB;QACtC,uBAAkB,GAAlB,kBAAkB,CAAoB;QATxC,mBAAc,GAAiB,EAAC,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAC,CAAC;QACpD,iBAAY,GAGhB,EAAC,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAC,CAAC;QAOvB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACpB,CAAC;IAED,IAAW,WAAW,CAAC,WAGtB;QACC,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC;IAClC,CAAC;IAED;;OAEG;IACI,aAAa,CAAC,MAAoB;QACvC,IAAI,CAAC,cAAc,GAAG,MAAM,CAAC;IAC/B,CAAC;IAED;;OAEG;IACU,eAAe,CAAC,MAAoB;;YAC/C,IAAI,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,iBAAiB,EAAE;gBAC3C,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;gBAC5C,MAAM,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,kBAAkB,EAAE,CAAC;aAClD;iBAAM;gBACL,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,kBAAkB,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;aACvD;YACD,IAAI,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,iBAAiB,EAAE;gBAC3C,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;gBAC5C,MAAM,IAAI,C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AAc,CAAC,IAAI,GAAG,MAAM,CAAC;SACnC;QACD,IAAI,CAAC,aAAK,CAAC,SAAS,CAAC,IAAI,CAAC,iBAAiB,CAAC,EAAE;YAC5C,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC;gBACjD,cAAc,EAAE;oBACd,IAAI,EAAE;wBACJ,OAAO,EAAE,CAAC,IAA2B,EAAE,EAAE;4BACvC,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,CAAC,OAAO,EAAE,KAAK,SAAS,EAAE;gCACtD,OAAO,EAAE,CAAC;6BACX;4BACD,MAAM,KAAK,GAAG,YAAQ,CAAC,OAAO,CAC5B,IAAI,CAAC,OAAO,EAAE,EACd,IAAI,CAAC,cAAc,CAAC,IAAI,EACxB,IAAI,CAAC,YAAY,CAAC,IAAI,CACvB,CAAC;4BACF,OAAO,aAAK,CAAC,SAAS,CAAC,IAAI,CAAC,kBAAkB,CAAC;gCAC7C,CAAC,CAAC,aAAK,CAAC,QAAQ,CAAC,KAAK,EAAE,QAAQ,EAAE,IAAI,CAAC,kBAAkB,CAAC;gCAC1D,CAAC,CAAC,KAAK,CAAC;wBACZ,CAAC;qBACF;iBACF;gBACD,YAAY,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,IAAI,CAAC,SAAS,EAAE;gBAC7D,uHAAuH;gBACvH,gBAAgB,EAAE,EAAC,IAAI,EAAE,EAAC,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,aAAa,CAAC,EAAC,EAAC;aACpE,CAAC,CAAC;SACJ;aAAM;YACL,OAAO,IAAI,CAAC,iBAAiB,CAAC,OAAO,EAAE,CAAC;SACzC;IACH,CAAC;CACF;AArHD,kCAqHC","sourcesContent":["'use strict';\n\nimport * as Ogma from '@linkurious/ogma';\nimport {GraphSchemaTypeWithAccess, ItemFieldsCaptions} from '@linkurious/rest-client';\n\nimport {Captions, LKOgma} from '../..';\nimport {Tools} from '../../tools/tools';\n\nexport interface CaptionState {\n node: ItemFieldsCaptions;\n edge: ItemFieldsCaptions;\n}\n\nexport class CaptionsViz {\n public nodesCaptionsRule!: Ogma.StyleRule;\n public edgesCaptionsRule!: Ogma.StyleRule;\n private _ogma: LKOgma;\n private _captionSchema: CaptionState = {node: {}, edge: {}};\n private _graphSchema: {\n node: Array<GraphSchemaTypeWithAccess>;\n edge: Array<GraphSchemaTypeWithAccess>;\n } = {node: [], edge: []};\n\n constructor(\n ogma: LKOgma,\n private _nodeMaxTextLength: number | undefined,\n private _edgeMaxTextLength: number | undefined\n ) {\n this._ogma = ogma;\n }\n\n public set graphSchema(graphSchema: {\n node: Array<GraphSchemaTypeWithAccess>;\n edge: Array<GraphSchemaTypeWithAccess>;\n }) {\n this._graphSchema = graphSchema;\n }\n\n /**\n * Refresh the schema\n */\n public refreshSchema(schema: CaptionState): void {\n this._captionSchema = schema;\n }\n\n /**\n * Refresh visualization captions rules\n */\n public async initVizCaptions(schema: CaptionState): Promise<void> {\n if (this._ogma.LKCaptions.nodesCaptionsRule) {\n this._ogma.LKCaptions.refreshSchema(schema);\n await this._ogma.LKCaptions.updateNodeCaptions();\n } else {\n this._ogma.LKCaptions.updateNodeCaptions(schema.node);\n }\n if (this._ogma.LKCaptions.edgesCaptionsRule) {\n this._ogma.LKCaptions.refreshSchema(schema);\n await this._ogma.LKCaptions.updateEdgeCaptions();\n } else {\n this._ogma.LKCaptions.updateEdgeCaptions(schema.edge);\n }\n }\n\n /**\n * Create or update nodeCaptionRule\n */\n public updateNodeCaptions(schema?: ItemFieldsCaptions): Promise<void> | void {\n if (schema) {\n this._captionSchema.node = schema;\n }\n if (!Tools.isDefined(this.nodesCaptionsRule)) {\n this.nodesCaptionsRule = this._ogma.styles.addRule({\n nodeAttributes: {\n text: {\n content: (node: Ogma.Node | undefined) => {\n if (node === undefined) {\n return ``;\n }\n const value = Captions.getText(\n node.getData(),\n this._captionSchema.node,\n this._graphSchema.node\n );\n return Tools.isDefined(this._nodeMaxTextLength)\n ? Tools.truncate(value, 'middle', this._nodeMaxTextLength)\n : value;\n }\n }\n },\n nodeDependencies: {self: {data: true}}\n });\n } else {\n return this.nodesCaptionsRule.refresh();\n }\n }\n\n /**\n * Create or update edgeCaptionRule\n */\n public updateEdgeCaptions(schema?: ItemFieldsCaptions): Promise<void> | void {\n if (schema) {\n this._captionSchema.edge = schema;\n }\n if (!Tools.isDefined(this.edgesCaptionsRule)) {\n this.edgesCaptionsRule = this._ogma.styles.addRule({\n edgeAttributes: {\n text: {\n content: (edge: Ogma.Edge | undefined) => {\n if (edge === undefined || edge.getData() === undefined) {\n return ``;\n }\n const value = Captions.getText(\n edge.getData(),\n this._captionSchema.edge,\n this._graphSchema.edge\n );\n return Tools.isDefined(this._edgeMaxTextLength)\n ? Tools.truncate(value, 'middle', this._edgeMaxTextLength)\n : value;\n }\n }\n },\n edgeSelector: (edge) => !edge.isVirtual() && edge.isVisible(),\n // ogma will trigger the rendering if data change or the shape change (to trigger the rendering when edges are grouped)\n edgeDependencies: {self: {data: true, attributes: ['shape.style']}}\n });\n } else {\n return this.edgesCaptionsRule.refresh();\n }\n }\n}\n"]}
1
+ {"version":3,"file":"captions.js","sourceRoot":"","sources":["../../../src/ogma/features/captions.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;;;;;;;AAKb,6BAAuC;AACvC,6CAAwC;AAOxC,MAAa,WAAW;IAUtB,YACE,IAAY,EACJ,kBAAsC,EACtC,kBAAsC;QADtC,uBAAkB,GAAlB,kBAAkB,CAAoB;QACtC,uBAAkB,GAAlB,kBAAkB,CAAoB;QATxC,mBAAc,GAAiB,EAAC,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAC,CAAC;QACpD,iBAAY,GAGhB,EAAC,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAC,CAAC;QAOvB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACp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,CAAC;4BACF,OAAO,aAAK,CAAC,SAAS,CAAC,IAAI,CAAC,kBAAkB,CAAC;gCAC7C,CAAC,CAAC,aAAK,CAAC,QAAQ,CAAC,KAAK,EAAE,QAAQ,EAAE,IAAI,CAAC,kBAAkB,CAAC;gCAC1D,CAAC,CAAC,KAAK,CAAC;wBACZ,CAAC;qBACF;iBACF;gBACD,YAAY,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,IAAI,CAAC,SAAS,EAAE;gBAC7D,uHAAuH;gBACvH,gBAAgB,EAAE,EAAC,IAAI,EAAE,EAAC,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,aAAa,CAAC,EAAC,EAAC;aACpE,CAAC,CAAC;SACJ;aAAM;YACL,OAAO,IAAI,CAAC,iBAAiB,CAAC,OAAO,EAAE,CAAC;SACzC;IACH,CAAC;CACF;AArHD,kCAqHC","sourcesContent":["'use strict';\n\nimport * as Ogma from '@linkurious/ogma';\nimport {GraphSchemaTypeWithAccess, ItemFieldsCaptions} from '@linkurious/rest-client';\n\nimport {Captions, LKOgma} from '../..';\nimport {Tools} from '../../tools/tools';\n\nexport interface CaptionState {\n node: ItemFieldsCaptions;\n edge: ItemFieldsCaptions;\n}\n\nexport class CaptionsViz {\n public nodesCaptionsRule!: Ogma.StyleRule;\n public edgesCaptionsRule!: Ogma.StyleRule;\n private _ogma: LKOgma;\n private _captionSchema: CaptionState = {node: {}, edge: {}};\n private _graphSchema: {\n node: Array<GraphSchemaTypeWithAccess>;\n edge: Array<GraphSchemaTypeWithAccess>;\n } = {node: [], edge: []};\n\n constructor(\n ogma: LKOgma,\n private _nodeMaxTextLength: number | undefined,\n private _edgeMaxTextLength: number | undefined\n ) {\n this._ogma = ogma;\n }\n\n public set graphSchema(graphSchema: {\n node: Array<GraphSchemaTypeWithAccess>;\n edge: Array<GraphSchemaTypeWithAccess>;\n }) {\n this._graphSchema = graphSchema;\n }\n\n /**\n * Refresh the schema\n */\n public refreshSchema(schema: CaptionState): void {\n this._captionSchema = schema;\n }\n\n /**\n * Refresh visualization captions rules\n */\n public async initVizCaptions(schema: CaptionState): Promise<void> {\n if (this._ogma.LKCaptions.nodesCaptionsRule) {\n this._ogma.LKCaptions.refreshSchema(schema);\n await this._ogma.LKCaptions.updateNodeCaptions();\n } else {\n this._ogma.LKCaptions.updateNodeCaptions(schema.node);\n }\n if (this._ogma.LKCaptions.edgesCaptionsRule) {\n this._ogma.LKCaptions.refreshSchema(schema);\n await this._ogma.LKCaptions.updateEdgeCaptions();\n } else {\n this._ogma.LKCaptions.updateEdgeCaptions(schema.edge);\n }\n }\n\n /**\n * Create or update nodeCaptionRule\n */\n public updateNodeCaptions(schema?: ItemFieldsCaptions): Promise<void> | void {\n if (schema) {\n this._captionSchema.node = schema;\n }\n if (!Tools.isDefined(this.nodesCaptionsRule)) {\n this.nodesCaptionsRule = this._ogma.styles.addRule({\n nodeAttributes: {\n text: {\n content: (node: Ogma.Node | undefined) => {\n if (node === undefined) {\n return ``;\n }\n const value = Captions.getText(\n node.getData(),\n this._captionSchema.node,\n this._graphSchema.node\n );\n return Tools.isDefined(this._nodeMaxTextLength)\n ? Tools.truncate(value, 'middle', this._nodeMaxTextLength)\n : value;\n }\n }\n },\n nodeDependencies: {self: {data: true}}\n });\n } else {\n return this.nodesCaptionsRule.refresh();\n }\n }\n\n /**\n * Create or update edgeCaptionRule\n */\n public updateEdgeCaptions(schema?: ItemFieldsCaptions): Promise<void> | void {\n if (schema) {\n this._captionSchema.edge = schema;\n }\n if (!Tools.isDefined(this.edgesCaptionsRule)) {\n this.edgesCaptionsRule = this._ogma.styles.addRule({\n edgeAttributes: {\n text: {\n content: (edge: Ogma.Edge | undefined) => {\n if (edge === undefined || edge.getData() === undefined) {\n return ``;\n }\n const value = Captions.getText(\n edge.getData(),\n this._captionSchema.edge,\n this._graphSchema.edge\n );\n return Tools.isDefined(this._edgeMaxTextLength)\n ? Tools.truncate(value, 'middle', this._edgeMaxTextLength)\n : value;\n }\n }\n },\n edgeSelector: (edge) => !edge.isVirtual() && edge.isVisible(),\n // ogma will trigger the rendering if data change or the shape change (to trigger the rendering when edges are grouped)\n edgeDependencies: {self: {data: true, attributes: ['shape.style']}}\n });\n } else {\n return this.edgesCaptionsRule.refresh();\n }\n }\n}\n"]}
@@ -1,5 +1,6 @@
1
1
  'use strict';
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DummyNodeList = exports.RxViz = void 0;
3
4
  const index_1 = require("../index");
4
5
  const OgmaStore_1 = require("./OgmaStore");
5
6
  class RxViz {
@@ -1 +1 @@
1
- {"version":3,"file":"reactive.js","sourceRoot":"","sources":["../../../src/ogma/features/reactive.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAKb,oCAAoD;AAEpD,2CAAsC;AAStC,MAAa,KAAK;IAUhB,YAAY,IAAY;QARhB,WAAM,GAAc,IAAI,qBAAS,CAAC;YACxC,SAAS,EAAE,IAAI,aAAa,EAAS;YACrC,KAAK,EAAE,EAAC,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAC;YAC3B,OAAO,EAAE,SAAS;YAClB,SAAS,EAAE,KAAK;SACjB,CAAC,CAAC;QAID,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,uBAAuB,EAAE,CAAC;IACjC,CAAC;IAED,IAAW,KAAK;QACd,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED;;OAEG;IACI,uBAAuB;QAC5B,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,CAAqB,EAAE,EAAE;YACxD,MAAM,YAAY,GAAG,EAAE,KAAK,CAAC;YAC7B,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,iCAAK,KAAK,KAAE,SAAS,EAAE,IAAI,IA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AAE,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE;aACpC,IACD;IACJ,CAAC;IAED;;OAEG;IACK,kBAAkB,CAAC,KAAgB;QACzC,uCACK,KAAK,KACR,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,gBAAgB,EAAE,IACxC;IACJ,CAAC;IAED;;OAEG;IACK,kBAAkB,CAAC,KAAgB;QACzC,uCACK,KAAK,KACR,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,gBAAgB,EAAE,IACxC;IACJ,CAAC;CACF;AAvID,sBAuIC;AAED,MAAa,aAAa;IAA1B;QACS,SAAI,GAAG,CAAC,CAAC;QACT,WAAM,GAAG,IAAI,CAAC;IACvB,CAAC;CAAA;AAHD,sCAGC","sourcesContent":["'use strict';\n\nimport Ogma, {NodeList, EdgeList} from '@linkurious/ogma';\nimport {LkEdgeData, LkNodeData} from '@linkurious/rest-client';\n\nimport {ANIMATION_DURATION, LKOgma} from '../index';\n\nimport {OgmaStore} from './OgmaStore';\n\nexport interface OgmaState {\n selection: NodeList<LkNodeData, LkEdgeData> | EdgeList<LkEdgeData, LkNodeData>;\n items: {node: Array<string | number>; edge: Array<string | number>};\n changes: {entityType: 'node' | 'edge'; input: string | string[] | null; value: any} | undefined;\n animation: boolean;\n}\n\nexport class RxViz {\n private _ogma: Ogma;\n private _store: OgmaStore = new OgmaStore({\n selection: new DummyNodeList() as any,\n items: {node: [], edge: []},\n changes: undefined,\n animation: false\n });\n private _animationThrottle: any;\n\n constructor(ogma: LKOgma) {\n this._ogma = ogma;\n this.listenToSelectionEvents();\n }\n\n public get store(): OgmaStore {\n return this._store;\n }\n\n /**\n * Listen to ogma events and update the state\n */\n public listenToSelectionEvents(): void {\n let count = 0;\n this._ogma.events.on('animate', (e: {duration: number}) => {\n const animationEnd = ++count;\n this._store.dispatch((state) => ({...state, animation: true}));\n clearTimeout(this._animationThrottle);\n this._animationThrottle = setTimeout(() => {\n if (count === animationEnd) {\n this._store.dispatch((state) => ({...state, animation: false}));\n }\n }, e.duration + ANIMATION_DURATION + 100);\n });\n\n this._ogma.events.on('dragStart', () => {\n this._store.dispatch((state) => ({...state, animation: true}));\n });\n\n this._ogma.events.on('dragEnd', () => {\n this._store.dispatch((state) => ({...state, animation: false}));\n });\n\n this._ogma.events.on('addNodes', () => {\n this._store.dispatch(this.storeItems.bind(this));\n });\n this._ogma.events.on('removeNodes', () => {\n this._store.dispatch(this.storeItems.bind(this));\n });\n this._ogma.events.on('addEdges', () => {\n this._store.dispatch(this.storeItems.bind(this));\n });\n this._ogma.events.on('removeEdges', () => {\n this._store.dispatch(this.storeItems.bind(this));\n });\n\n this._ogma.events.on('nodesSelected', () => {\n this._store.dispatch(this.storeNodeSelection.bind(this));\n });\n\n this._ogma.events.on('edgesSelected', () => {\n this._store.dispatch(this.storeEdgeSelection.bind(this));\n });\n\n this._ogma.events.on('nodesUnselected', () => {\n this._store.dispatch(this.storeNodeSelection.bind(this));\n });\n\n this._ogma.events.on('edgesUnselected', () => {\n this._store.dispatch(this.storeEdgeSelection.bind(this));\n });\n\n this._ogma.events.on('updateNodeData', (evt) => {\n if (evt !== undefined) {\n evt.changes.forEach((change) => {\n this._store.dispatch((state) => ({\n ...state,\n changes: {\n entityType: 'node',\n input: change.property,\n value: change.newValues[0]\n }\n }));\n });\n }\n });\n\n this._ogma.events.on('updateEdgeData', (evt) => {\n if (evt !== undefined) {\n evt.changes.forEach((change) => {\n this._store.dispatch((state) => ({\n ...state,\n changes: {\n entityType: 'edge',\n input: change.property,\n value: change.newValues[0]\n }\n }));\n });\n }\n });\n }\n\n /**\n * Store new items in state\n */\n private storeItems(state: OgmaState): OgmaState {\n return {\n ...state,\n items: {\n node: this._ogma.getNodes().getId(),\n edge: this._ogma.getEdges().getId()\n }\n };\n }\n\n /**\n * Store new node selection in state\n */\n private storeNodeSelection(state: OgmaState): OgmaState {\n return {\n ...state,\n selection: this._ogma.getSelectedNodes()\n };\n }\n\n /**\n * store new edge selection in state\n */\n private storeEdgeSelection(state: OgmaState): OgmaState {\n return {\n ...state,\n selection: this._ogma.getSelectedEdges()\n };\n }\n}\n\nexport class DummyNodeList {\n public size = 0;\n public isNode = true;\n}\n"]}
1
+ {"version":3,"file":"reactive.js","sourceRoot":"","sources":["../../../src/ogma/features/reactive.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;AAKb,oCAAoD;AAEpD,2CAAsC;AAStC,MAAa,KAAK;IAUhB,YAAY,IAAY;QARhB,WAAM,GAAc,IAAI,qBAAS,CAAC;YACxC,SAAS,EAAE,IAAI,aAAa,EAAS;YACrC,KAAK,EAAE,EAAC,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAC;YAC3B,OAAO,EAAE,SAAS;YAClB,SAAS,EAAE,KAAK;SACjB,CAAC,CAAC;QAID,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,uBAAuB,EAAE,CAAC;IACjC,CAAC;IAED,IAAW,KAAK;QACd,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED;;OAEG;IACI,uBAAuB;QAC5B,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,CAAqB,EAAE,EAAE;YACxD,MAAM,YAAY,GAAG,EAAE,KAAK,CAAC;YAC7B,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,iCAAK,KAAK,KAAE,SAAS,EAAE,IAAI,IAAE,CAAC,CAAC;YAC/D,YAAY,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;YACtC,IAAI,CAAC,kBAAkB,GAAG,UAAU,CAAC,GAAG,EAAE;gBACxC,IAAI,KAAK,KAAK,YAAY,EAAE;oBAC1B,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,iCAAK,KAAK,KAAE,SAA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ACK,KAAK,KACR,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,gBAAgB,EAAE,IACxC;IACJ,CAAC;CACF;AAvID,sBAuIC;AAED,MAAa,aAAa;IAA1B;QACS,SAAI,GAAG,CAAC,CAAC;QACT,WAAM,GAAG,IAAI,CAAC;IACvB,CAAC;CAAA;AAHD,sCAGC","sourcesContent":["'use strict';\n\nimport Ogma, {NodeList, EdgeList} from '@linkurious/ogma';\nimport {LkEdgeData, LkNodeData} from '@linkurious/rest-client';\n\nimport {ANIMATION_DURATION, LKOgma} from '../index';\n\nimport {OgmaStore} from './OgmaStore';\n\nexport interface OgmaState {\n selection: NodeList<LkNodeData, LkEdgeData> | EdgeList<LkEdgeData, LkNodeData>;\n items: {node: Array<string | number>; edge: Array<string | number>};\n changes: {entityType: 'node' | 'edge'; input: string | string[] | null; value: any} | undefined;\n animation: boolean;\n}\n\nexport class RxViz {\n private _ogma: Ogma;\n private _store: OgmaStore = new OgmaStore({\n selection: new DummyNodeList() as any,\n items: {node: [], edge: []},\n changes: undefined,\n animation: false\n });\n private _animationThrottle: any;\n\n constructor(ogma: LKOgma) {\n this._ogma = ogma;\n this.listenToSelectionEvents();\n }\n\n public get store(): OgmaStore {\n return this._store;\n }\n\n /**\n * Listen to ogma events and update the state\n */\n public listenToSelectionEvents(): void {\n let count = 0;\n this._ogma.events.on('animate', (e: {duration: number}) => {\n const animationEnd = ++count;\n this._store.dispatch((state) => ({...state, animation: true}));\n clearTimeout(this._animationThrottle);\n this._animationThrottle = setTimeout(() => {\n if (count === animationEnd) {\n this._store.dispatch((state) => ({...state, animation: false}));\n }\n }, e.duration + ANIMATION_DURATION + 100);\n });\n\n this._ogma.events.on('dragStart', () => {\n this._store.dispatch((state) => ({...state, animation: true}));\n });\n\n this._ogma.events.on('dragEnd', () => {\n this._store.dispatch((state) => ({...state, animation: false}));\n });\n\n this._ogma.events.on('addNodes', () => {\n this._store.dispatch(this.storeItems.bind(this));\n });\n this._ogma.events.on('removeNodes', () => {\n this._store.dispatch(this.storeItems.bind(this));\n });\n this._ogma.events.on('addEdges', () => {\n this._store.dispatch(this.storeItems.bind(this));\n });\n this._ogma.events.on('removeEdges', () => {\n this._store.dispatch(this.storeItems.bind(this));\n });\n\n this._ogma.events.on('nodesSelected', () => {\n this._store.dispatch(this.storeNodeSelection.bind(this));\n });\n\n this._ogma.events.on('edgesSelected', () => {\n this._store.dispatch(this.storeEdgeSelection.bind(this));\n });\n\n this._ogma.events.on('nodesUnselected', () => {\n this._store.dispatch(this.storeNodeSelection.bind(this));\n });\n\n this._ogma.events.on('edgesUnselected', () => {\n this._store.dispatch(this.storeEdgeSelection.bind(this));\n });\n\n this._ogma.events.on('updateNodeData', (evt) => {\n if (evt !== undefined) {\n evt.changes.forEach((change) => {\n this._store.dispatch((state) => ({\n ...state,\n changes: {\n entityType: 'node',\n input: change.property,\n value: change.newValues[0]\n }\n }));\n });\n }\n });\n\n this._ogma.events.on('updateEdgeData', (evt) => {\n if (evt !== undefined) {\n evt.changes.forEach((change) => {\n this._store.dispatch((state) => ({\n ...state,\n changes: {\n entityType: 'edge',\n input: change.property,\n value: change.newValues[0]\n }\n }));\n });\n }\n });\n }\n\n /**\n * Store new items in state\n */\n private storeItems(state: OgmaState): OgmaState {\n return {\n ...state,\n items: {\n node: this._ogma.getNodes().getId(),\n edge: this._ogma.getEdges().getId()\n }\n };\n }\n\n /**\n * Store new node selection in state\n */\n private storeNodeSelection(state: OgmaState): OgmaState {\n return {\n ...state,\n selection: this._ogma.getSelectedNodes()\n };\n }\n\n /**\n * store new edge selection in state\n */\n private storeEdgeSelection(state: OgmaState): OgmaState {\n return {\n ...state,\n selection: this._ogma.getSelectedEdges()\n };\n }\n}\n\nexport class DummyNodeList {\n public size = 0;\n public isNode = true;\n}\n"]}
@@ -1,7 +1,7 @@
1
1
  import { EntityType, LkEdgeData, LkNodeData } from '@linkurious/rest-client';
2
2
  import { Edge, Node } from '@linkurious/ogma';
3
3
  import { OgmaState } from './reactive';
4
- export declare type SelectionState = 'selection' | 'multiSelection' | 'noSelection';
4
+ export type SelectionState = 'selection' | 'multiSelection' | 'noSelection';
5
5
  /**
6
6
  * Return the current size of the selection
7
7
  */
@@ -21,18 +21,18 @@ export declare const getUniqSelection: (state: OgmaState) => Node<LkNodeData, Lk
21
21
  /**
22
22
  * Return the types of the current selection (if only one item is selected)
23
23
  */
24
- export declare const getUniqSelectionTypes: (state: OgmaState) => string[] | undefined;
24
+ export declare const getUniqSelectionTypes: (state: OgmaState) => Array<string> | undefined;
25
25
  /**
26
26
  * Return the entityType of the current selection if there's only one item selected
27
27
  */
28
- export declare const getUniqSelectionEntity: (state: OgmaState) => "node" | "edge" | undefined;
28
+ export declare const getUniqSelectionEntity: (state: OgmaState) => 'node' | 'edge' | undefined;
29
29
  /**
30
30
  * Return the properties of the current selection if there's only one item selected
31
31
  */
32
- export declare const getSelectionProperties: (state: OgmaState) => {
32
+ export declare const getSelectionProperties: (state: OgmaState) => Array<{
33
33
  key: string;
34
34
  value: any;
35
- }[];
35
+ }>;
36
36
  /**
37
37
  * Return true if the current selection has properties
38
38
  */
@@ -1,16 +1,18 @@
1
1
  'use strict';
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hasSelectionProperties = exports.getSelectionProperties = exports.getUniqSelectionEntity = exports.getUniqSelectionTypes = exports.getUniqSelection = exports.getSelectionEntity = exports.getSelectionState = exports.getSelectionSize = void 0;
3
4
  const rest_client_1 = require("@linkurious/rest-client");
4
5
  /**
5
6
  * Return the current size of the selection
6
7
  */
7
- exports.getSelectionSize = (state) => {
8
+ const getSelectionSize = (state) => {
8
9
  return state.selection.size;
9
10
  };
11
+ exports.getSelectionSize = getSelectionSize;
10
12
  /**
11
13
  * Return the current state of the selection
12
14
  */
13
- exports.getSelectionState = (state) => {
15
+ const getSelectionState = (state) => {
14
16
  switch (state.selection.size) {
15
17
  case 1:
16
18
  return 'selection';
@@ -20,26 +22,29 @@ exports.getSelectionState = (state) => {
20
22
  return 'multiSelection';
21
23
  }
22
24
  };
25
+ exports.getSelectionState = getSelectionState;
23
26
  /**
24
27
  * Get the entityType of the current selection
25
28
  */
26
- exports.getSelectionEntity = (state) => {
29
+ const getSelectionEntity = (state) => {
27
30
  if (state.selection.size === 0) {
28
31
  return undefined;
29
32
  }
30
33
  return state.selection.isNode ? rest_client_1.EntityType.NODE : rest_client_1.EntityType.EDGE;
31
34
  };
35
+ exports.getSelectionEntity = getSelectionEntity;
32
36
  /**
33
37
  * Return the item selection if there's only one item selected
34
38
  */
35
- exports.getUniqSelection = (state) => {
39
+ const getUniqSelection = (state) => {
36
40
  return state.selection.size === 1 ? state.selection.get(0) : undefined;
37
41
  };
42
+ exports.getUniqSelection = getUniqSelection;
38
43
  /**
39
44
  * Return the types of the current selection (if only one item is selected)
40
45
  */
41
- exports.getUniqSelectionTypes = (state) => {
42
- const uniqSelection = exports.getUniqSelection(state);
46
+ const getUniqSelectionTypes = (state) => {
47
+ const uniqSelection = (0, exports.getUniqSelection)(state);
43
48
  if (uniqSelection === undefined) {
44
49
  return undefined;
45
50
  }
@@ -50,11 +55,12 @@ exports.getUniqSelectionTypes = (state) => {
50
55
  return [uniqSelection.getData('type')];
51
56
  }
52
57
  };
58
+ exports.getUniqSelectionTypes = getUniqSelectionTypes;
53
59
  /**
54
60
  * Return the entityType of the current selection if there's only one item selected
55
61
  */
56
- exports.getUniqSelectionEntity = (state) => {
57
- const uniqSelection = exports.getUniqSelection(state);
62
+ const getUniqSelectionEntity = (state) => {
63
+ const uniqSelection = (0, exports.getUniqSelection)(state);
58
64
  if (uniqSelection === undefined) {
59
65
  return undefined;
60
66
  }
@@ -63,11 +69,12 @@ exports.getUniqSelectionEntity = (state) => {
63
69
  }
64
70
  return 'edge';
65
71
  };
72
+ exports.getUniqSelectionEntity = getUniqSelectionEntity;
66
73
  /**
67
74
  * Return the properties of the current selection if there's only one item selected
68
75
  */
69
- exports.getSelectionProperties = (state) => {
70
- const uniqSelection = exports.getUniqSelection(state);
76
+ const getSelectionProperties = (state) => {
77
+ const uniqSelection = (0, exports.getUniqSelection)(state);
71
78
  if (uniqSelection !== undefined) {
72
79
  const properties = uniqSelection.getData().properties;
73
80
  return Object.keys(properties).map((propKey) => {
@@ -79,10 +86,12 @@ exports.getSelectionProperties = (state) => {
79
86
  }
80
87
  return [];
81
88
  };
89
+ exports.getSelectionProperties = getSelectionProperties;
82
90
  /**
83
91
  * Return true if the current selection has properties
84
92
  */
85
- exports.hasSelectionProperties = (state) => {
86
- return exports.getSelectionProperties(state).length > 0;
93
+ const hasSelectionProperties = (state) => {
94
+ return (0, exports.getSelectionProperties)(state).length > 0;
87
95
  };
96
+ exports.hasSelectionProperties = hasSelectionProperties;
88
97
  //# sourceMappingURL=selectors.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"selectors.js","sourceRoot":"","sources":["../../../src/ogma/features/selectors.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,yDAA2E;AAO3E;;GAEG;AACU,QAAA,gBAAgB,GAAG,CAAC,KAAgB,EAAU,EAAE;IAC3D,OAAQ,KAAK,CAAC,SAAkC,CAAC,IAAI,CAAC;AACxD,CAAC,CAAC;AAEF;;GAEG;AACU,QAAA,iBAAiB,GAAG,CAAC,KAAgB,EAAkB,EAAE;IACpE,QAAS,KAAK,CAAC,SAAkC,CAAC,IAAI,EAAE;QACtD,KAAK,CAAC;YACJ,OAAO,WAAW,CAAC;QAErB,KAAK,CAAC;YACJ,OAAO,aAAa,CAAC;QAEvB;YACE,OAAO,gBAAgB,CAAC;KAC3B;AACH,CAAC,CAAC;AAEF;;GAEG;AACU,QAAA,kBAAkB,GAAG,CAAC,KAAgB,EAA0B,EAAE;IAC7E,IAAI,KAAK,CAAC,SAAS,CAAC,IAAI,KAAK,CAAC,EAAE;QAC9B,OAAO,SAAS,CAAC;KAClB;IACD,OAAQ,KAAK,CAAC,SAAkC,CAAC,MAAM,CAAC,CAAC,CAAC,wBAAU,CAAC,IAAI,CAAC,CAAC,CAAC,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AC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE;YAC7C,OAAO;gBACL,GAAG,EAAE,OAAO;gBACZ,KAAK,EAAE,UAAU,CAAC,OAAO,CAAC;aAC3B,CAAC;QACJ,CAAC,CAAC,CAAC;KACJ;IACD,OAAO,EAAE,CAAC;AACZ,CAAC,CAAC;AAEF;;GAEG;AACU,QAAA,sBAAsB,GAAG,CAAC,KAAgB,EAAW,EAAE;IAClE,OAAO,8BAAsB,CAAC,KAAK,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;AAClD,CAAC,CAAC","sourcesContent":["'use strict';\n\nimport {EntityType, LkEdgeData, LkNodeData} from '@linkurious/rest-client';\nimport {Edge, ItemList, Node} from '@linkurious/ogma';\n\nimport {OgmaState} from './reactive';\n\nexport type SelectionState = 'selection' | 'multiSelection' | 'noSelection';\n\n/**\n * Return the current size of the selection\n */\nexport const getSelectionSize = (state: OgmaState): number => {\n return (state.selection as ItemList<LkNodeData>).size;\n};\n\n/**\n * Return the current state of the selection\n */\nexport const getSelectionState = (state: OgmaState): SelectionState => {\n switch ((state.selection as ItemList<LkNodeData>).size) {\n case 1:\n return 'selection';\n\n case 0:\n return 'noSelection';\n\n default:\n return 'multiSelection';\n }\n};\n\n/**\n * Get the entityType of the current selection\n */\nexport const getSelectionEntity = (state: OgmaState): EntityType | undefined => {\n if (state.selection.size === 0) {\n return undefined;\n }\n return (state.selection as ItemList<LkNodeData>).isNode ? EntityType.NODE : EntityType.EDGE;\n};\n\n/**\n * Return the item selection if there's only one item selected\n */\nexport const getUniqSelection = (\n state: OgmaState\n): Node<LkNodeData, LkEdgeData> | Edge<LkEdgeData, LkNodeData> | undefined => {\n return state.selection.size === 1 ? state.selection.get(0) : undefined;\n};\n\n/**\n * Return the types of the current selection (if only one item is selected)\n */\nexport const getUniqSelectionTypes = (state: OgmaState): Array<string> | undefined => {\n const uniqSelection = getUniqSelection(state);\n if (uniqSelection === undefined) {\n return undefined;\n }\n if (uniqSelection.isNode) {\n return uniqSelection.getData('categories');\n } else {\n return [uniqSelection.getData('type')];\n }\n};\n\n/**\n * Return the entityType of the current selection if there's only one item selected\n */\nexport const getUniqSelectionEntity = (state: OgmaState): 'node' | 'edge' | undefined => {\n const uniqSelection = getUniqSelection(state);\n if (uniqSelection === undefined) {\n return undefined;\n }\n if (uniqSelection.isNode) {\n return 'node';\n }\n return 'edge';\n};\n\n/**\n * Return the properties of the current selection if there's only one item selected\n */\nexport const getSelectionProperties = (state: OgmaState): Array<{key: string; value: any}> => {\n const uniqSelection = getUniqSelection(state);\n if (uniqSelection !== undefined) {\n const properties = uniqSelection.getData().properties;\n return Object.keys(properties).map((propKey) => {\n return {\n key: propKey,\n value: properties[propKey]\n };\n });\n }\n return [];\n};\n\n/**\n * Return true if the current selection has properties\n */\nexport const hasSelectionProperties = (state: OgmaState): boolean => {\n return getSelectionProperties(state).length > 0;\n};\n"]}
1
+ {"version":3,"file":"selectors.js","sourceRoot":"","sources":["../../../src/ogma/features/selectors.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;AAEb,yDAA2E;AAO3E;;GAEG;AACI,MAAM,gBAAgB,GAAG,CAAC,KAAgB,EAAU,EAAE;IAC3D,OAAQ,KAAK,CAAC,SAAkC,CAAC,IAAI,CAAC;AACxD,CAAC,CAAC;AAFW,QAAA,gBAAgB,oBAE3B;AAEF;;GAEG;AACI,MAAM,iBAAiB,GAAG,CAAC,KAAgB,EAAkB,EAAE;IACpE,QAAS,KAAK,CAAC,SAAkC,CAAC,IAAI,EAAE;QACtD,KAAK,CAAC;YACJ,OAAO,WAAW,CAAC;QAErB,KAAK,CAAC;YACJ,OAAO,aAAa,CAAC;QAEvB;YACE,OAAO,gBAAgB,CAAC;KAC3B;AACH,CAAC,CAAC;AAXW,QAAA,iBAAiB,qBAW5B;AAEF;;GAEG;AACI,MAAM,kBAAkB,GAAG,CAAC,KAAgB,EAA0B,EAAE;IAC7E,IAAI,KAAK,CAAC,SAAS,CAAC,IAAI,KAAK,CAA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I,MAAM,sBAAsB,GAAG,CAAC,KAAgB,EAAoC,EAAE;IAC3F,MAAM,aAAa,GAAG,IAAA,wBAAgB,EAAC,KAAK,CAAC,CAAC;IAC9C,IAAI,aAAa,KAAK,SAAS,EAAE;QAC/B,MAAM,UAAU,GAAG,aAAa,CAAC,OAAO,EAAE,CAAC,UAAU,CAAC;QACtD,OAAO,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE;YAC7C,OAAO;gBACL,GAAG,EAAE,OAAO;gBACZ,KAAK,EAAE,UAAU,CAAC,OAAO,CAAC;aAC3B,CAAC;QACJ,CAAC,CAAC,CAAC;KACJ;IACD,OAAO,EAAE,CAAC;AACZ,CAAC,CAAC;AAZW,QAAA,sBAAsB,0BAYjC;AAEF;;GAEG;AACI,MAAM,sBAAsB,GAAG,CAAC,KAAgB,EAAW,EAAE;IAClE,OAAO,IAAA,8BAAsB,EAAC,KAAK,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;AAClD,CAAC,CAAC;AAFW,QAAA,sBAAsB,0BAEjC","sourcesContent":["'use strict';\n\nimport {EntityType, LkEdgeData, LkNodeData} from '@linkurious/rest-client';\nimport {Edge, ItemList, Node} from '@linkurious/ogma';\n\nimport {OgmaState} from './reactive';\n\nexport type SelectionState = 'selection' | 'multiSelection' | 'noSelection';\n\n/**\n * Return the current size of the selection\n */\nexport const getSelectionSize = (state: OgmaState): number => {\n return (state.selection as ItemList<LkNodeData>).size;\n};\n\n/**\n * Return the current state of the selection\n */\nexport const getSelectionState = (state: OgmaState): SelectionState => {\n switch ((state.selection as ItemList<LkNodeData>).size) {\n case 1:\n return 'selection';\n\n case 0:\n return 'noSelection';\n\n default:\n return 'multiSelection';\n }\n};\n\n/**\n * Get the entityType of the current selection\n */\nexport const getSelectionEntity = (state: OgmaState): EntityType | undefined => {\n if (state.selection.size === 0) {\n return undefined;\n }\n return (state.selection as ItemList<LkNodeData>).isNode ? EntityType.NODE : EntityType.EDGE;\n};\n\n/**\n * Return the item selection if there's only one item selected\n */\nexport const getUniqSelection = (\n state: OgmaState\n): Node<LkNodeData, LkEdgeData> | Edge<LkEdgeData, LkNodeData> | undefined => {\n return state.selection.size === 1 ? state.selection.get(0) : undefined;\n};\n\n/**\n * Return the types of the current selection (if only one item is selected)\n */\nexport const getUniqSelectionTypes = (state: OgmaState): Array<string> | undefined => {\n const uniqSelection = getUniqSelection(state);\n if (uniqSelection === undefined) {\n return undefined;\n }\n if (uniqSelection.isNode) {\n return uniqSelection.getData('categories');\n } else {\n return [uniqSelection.getData('type')];\n }\n};\n\n/**\n * Return the entityType of the current selection if there's only one item selected\n */\nexport const getUniqSelectionEntity = (state: OgmaState): 'node' | 'edge' | undefined => {\n const uniqSelection = getUniqSelection(state);\n if (uniqSelection === undefined) {\n return undefined;\n }\n if (uniqSelection.isNode) {\n return 'node';\n }\n return 'edge';\n};\n\n/**\n * Return the properties of the current selection if there's only one item selected\n */\nexport const getSelectionProperties = (state: OgmaState): Array<{key: string; value: any}> => {\n const uniqSelection = getUniqSelection(state);\n if (uniqSelection !== undefined) {\n const properties = uniqSelection.getData().properties;\n return Object.keys(properties).map((propKey) => {\n return {\n key: propKey,\n value: properties[propKey]\n };\n });\n }\n return [];\n};\n\n/**\n * Return true if the current selection has properties\n */\nexport const hasSelectionProperties = (state: OgmaState): boolean => {\n return getSelectionProperties(state).length > 0;\n};\n"]}