@linkurious/ogma-linkurious-parser 4.1.4 → 4.1.5

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.
@@ -174,7 +174,10 @@ class NodeGroupingTransformation {
174
174
  * @param node reference to the virtual node
175
175
  */
176
176
  _getNodeGroupingCaption(node) {
177
- if (node !== undefined && node.isVirtual()) {
177
+ var _a;
178
+ // TODO: Normally there is no need to check if getSubNodes return a value, Ogma issue
179
+ //https://github.com/Linkurious/ogma/issues/3876
180
+ if (node !== undefined && node.isVirtual() && ((_a = node.getSubNodes()) === null || _a === void 0 ? void 0 : _a.get(0)) !== undefined) {
178
181
  // get the property value of the first node of the group (all nodes share the same property value)
179
182
  const lkPropertyValue = node
180
183
  .getSubNodes()
@@ -1 +1 @@
1
- {"version":3,"file":"nodeGrouping.js","sourceRoot":"","sources":["../../../src/ogma/features/nodeGrouping.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAEA,gDAAwB;AAExB,oCAAqD;AACrD,6CAAwC;AAE3B,QAAA,sBAAsB,GAAG,wBAAwB,CAAC;AAClD,QAAA,sBAAsB,GAAG,wBAAwB,CAAC;AAE/D,MAAa,0BAA0B;IAMrC,YAAY,IAAY;QACtB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACpB,CAAC;IAED;;;OAGG;IACI,eAAe,CAAC,IAAkC;QACvD,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;IACxB,CAAC;IAED;;;;OAIG;IACU,kBAAkB;;YAC7B,IAAI,IAAI,CAAC,cAAc,KAAK,SAAS,EAAE,CAAC;gBACtC,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,eAAe,CAAC;oBAC/D,eAAe,EAAE,CAAC,IAAI,EAAE,EAAE;;wBACxB,IAAI,IAAI,CAAC,0BAA0B,CAAC,IAAI,CAAC,EAAE,CAAC;4BAC1C,OAAO,SAAS,CAAC;wBACnB,CAAC;6BAAM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CAAC;gBACnD,CAAC;YACH,CAAC,CAAC,CACH,CAAC;QACJ,CAAC;KAAA;IAED;;;OAGG;IACK,6BAA6B;QACnC,MAAM,YAAY,GAAG,IAAI,CAAC,+BAA+B,EAAE,CAAC;QAC5D,OAAO,YAAY,CAAC,WAAW,EAAE,CAAC;IACpC,CAAC;IAEO,0BAA0B,CAAC,IAAsB;;QACvD,MAAM,aAAa,GAAG,IAAI,CAAC,OAAO,CAAC;YACjC,YAAY;YACZ,MAAA,MAAA,IAAI,CAAC,SAAS,0CAAE,eAAe,CAAC,WAAW,mCAAI,EAAE;SAClD,CAAC,CAAC;QACH,OAAO,GAAG,aAAK,CAAC,sBAAsB,CAAC,aAAa,CAAC,EAAE,CAAC;IAC1D,CAAC;IAED;;OAEG;IACK,gBAAgB,CAAC,KAAuC;;QAC9D,MAAM,aAAa,GAAG,IAAI,CAAC,0BAA0B,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QACpE,OAAO,IAAA,cAAI,EACT,GAAG,MAAA,IAAI,CAAC,SAAS,0CAAE,IAAI,IAAI,MAAA,IAAI,CAAC,SAAS,0CAAE,eAAe,CAAC,SAAS,CAAC,IAAI,CACvE,GAAG,CACJ,IAAI,aAAa,EAAE,CACrB,CAAC;IACJ,CAAC;CACF;AAxPD,gEAwPC","sourcesContent":["import {Transformation, Node, NodeList, StyleRule} from '@linkurious/ogma';\nimport {LkEdgeData, LkNodeData, MissingValue, NodeGroupingRule} from '@linkurious/rest-client';\nimport sha1 from 'sha1';\n\nimport {FORCE_LAYOUT_CONFIG, LKOgma} from '../index';\nimport {Tools} from '../../tools/tools';\n\nexport const LKE_NODE_GROUPING_EDGE = 'LKE_NODE_GROUPING_EDGE';\nexport const LKE_NODE_GROUPING_NODE = 'LKE_NODE_GROUPING_NODE';\n\nexport class NodeGroupingTransformation {\n public transformation?: Transformation<LkNodeData, LkEdgeData>;\n public groupRule?: NodeGroupingRule;\n public nodeGroupingStyleRule?: StyleRule<LkNodeData, LkEdgeData>;\n private _ogma: LKOgma;\n\n constructor(ogma: LKOgma) {\n this._ogma = ogma;\n }\n\n /**\n * Set the grouping rule\n * @param rule of grouping\n */\n public setGroupingRule(rule: NodeGroupingRule | undefined): void {\n this.groupRule = rule;\n }\n\n /**\n * create a node grouping transformation\n * It uses groupRule to define the rule\n * Group the nodes based on a category type and a property value\n */\n public async initTransformation(): Promise<void> {\n if (this.transformation === undefined) {\n this.transformation = this._ogma.transformations.addNodeGrouping({\n groupIdFunction: (node) => {\n if (this._isRuleNotApplicableToNode(node)) {\n return undefined;\n } else {\n const propertyValue = this._findGroupingPropertyValue(node);\n // groupRule is defined if not we returned undefined\n // node with same value will be part of the same group\n return `${this.groupRule?.groupingOptions.itemTypes.join('-')}-${propertyValue}`\n .toLowerCase()\n .trim();\n }\n },\n nodeGenerator: (nodes) => {\n return {\n data: {\n categories: [LKE_NODE_GROUPING_NODE],\n properties: {},\n nodeGroupId: this._findNodeGroupId(nodes)\n }\n };\n },\n edgeGenerator: () => {\n return {\n data: {\n type: LKE_NODE_GROUPING_EDGE\n }\n };\n },\n showContents: true,\n padding: 10\n });\n } else {\n await this.refreshTransformation();\n }\n }\n\n /**\n * refresh the transformation\n * Called when there is a change in the rule\n */\n public async refreshTransformation(): Promise<void> {\n if (this.transformation !== undefined) {\n await this.transformation.refresh();\n await this._unpinNodes(this._getAllTransformationRawNodes());\n } else {\n await this.initTransformation();\n }\n }\n\n /**\n * init node grouping style\n */\n public initNodeGroupingStyle(): void {\n this.nodeGroupingStyleRule = this._ogma.styles.addRule({\n nodeAttributes: {\n // Any default style will go here\n text: {\n content: (node: Node<LkNodeData> | undefined): string | undefined => {\n return this._getNodeGroupingCaption(node);\n },\n style: 'bold'\n },\n layer: -1,\n color: 'rgba(240, 240, 240)',\n innerStroke: {\n color: '#7f7f7f',\n width: 2\n }\n },\n nodeSelector: (node) => {\n // TODO: Tools.isDefined(node.getSubNodes()) is a work around for an ogma issue visible when using image export plugin with Node grouping\n // remove when updating to Ogma v5.1.x\n return node.isVirtual() && Tools.isDefined(node.getSubNodes());\n },\n // the style will be updated when data object is updated\n nodeDependencies: {self: {data: true}}\n });\n }\n\n public async refreshNodeGroupingStyle(): Promise<void> {\n await this.nodeGroupingStyleRule?.refresh();\n }\n\n /**\n * run layout on all subnodes of virtual nodes\n */\n public async runLayoutOnAllSubNodes(): Promise<void> {\n await this._ogma.transformations.afterNextUpdate();\n const rawNodesList = this._getAllTransformationRawNodes();\n const promisesList: Promise<void>[] = [];\n for (let i = 0; i < rawNodesList.length; i++) {\n // rawNodesList[i] is not null because each group has at least one node\n const subNodes = rawNodesList[i]!;\n promisesList.push(this.runSubNodesLayout(subNodes));\n }\n await Promise.all(promisesList);\n }\n\n /**\n * Run the layout on the subnodes of the virtual node\n * @param subNodes nodes part of a virtual node\n */\n public async runSubNodesLayout(subNodes: NodeList<LkNodeData, LkEdgeData>): Promise<void> {\n if (subNodes.size === 0 || subNodes.size === 1) {\n return;\n }\n\n const noEdges = subNodes.getAdjacentEdges({bothExtremities: true}).size === 0;\n if (noEdges) {\n await this._runCirclePack(subNodes);\n } else {\n await this._runForceLayout(subNodes);\n }\n }\n\n /**\n * Get the virtual nodes of the transformation\n * @private\n */\n public getVirtualNodesOfTransformation(): NodeList<LkNodeData, LkEdgeData> {\n // @ts-ignore getContext exists on the transformation but hidden by the types\n return this.transformation.getContext().metaNodes;\n }\n\n /**\n * Return the caption of a virtual node\n * @param node reference to the virtual node\n */\n private _getNodeGroupingCaption(node: Node<LkNodeData> | undefined): string | undefined {\n if (node !== undefined && node.isVirtual()) {\n // get the property value of the first node of the group (all nodes share the same property value)\n const lkPropertyValue = node\n .getSubNodes()!\n .get(0)\n .getData(['properties', this.groupRule!.groupingOptions.propertyKey]);\n const propertyValue = Tools.getValueFromLkProperty(lkPropertyValue);\n const size = node.getSubNodes()!.filter((e) => !e.hasClass('filtered')).size;\n return `${propertyValue} (${size})`;\n }\n }\n\n /**\n * Run the circle pack layout on the subnodes\n * @param subNodes\n */\n private async _runCirclePack(subNodes: NodeList<LkNodeData, LkEdgeData>): Promise<void> {\n await this._ogma.algorithms.circlePack({\n nodes: subNodes,\n margin: 10,\n sort: 'asc'\n });\n }\n\n private async _runForceLayout(subNodes: NodeList<LkNodeData, LkEdgeData>): Promise<void> {\n await this._ogma.layouts.force({\n nodes: subNodes,\n ...FORCE_LAYOUT_CONFIG\n });\n }\n\n private _isRuleNotApplicableToNode(node: Node<LkNodeData>): boolean {\n const propertyValue = node.getData([\n 'properties',\n this.groupRule?.groupingOptions.propertyKey ?? ''\n ]);\n return (\n // if the group rule is not defined\n this.groupRule === undefined ||\n // if rule is applied to a different category\n this.groupRule.groupingOptions.itemTypes.every(\n (itemType) => !node.getData('categories').includes(itemType)\n ) ||\n // if the property value is not defined\n !Tools.isDefined(propertyValue) ||\n // if the property value is missing\n (typeof propertyValue === 'object' && (propertyValue as MissingValue).status === 'missing')\n );\n }\n\n /**\n * Unpin list of nodes\n * @param nodes\n * @private\n */\n private async _unpinNodes(nodes: Array<NodeList | null>): Promise<void> {\n await Promise.all(\n nodes.map((nodeList) => {\n if (nodeList !== null) {\n return nodeList.setAttribute('layoutable', true);\n }\n })\n );\n }\n\n /**\n * Get all the raw nodes part of the transformation\n * @private\n */\n private _getAllTransformationRawNodes(): Array<NodeList | null> {\n const virtualNodes = this.getVirtualNodesOfTransformation();\n return virtualNodes.getSubNodes();\n }\n\n private _findGroupingPropertyValue(node: Node<LkNodeData>): string {\n const propertyValue = node.getData([\n 'properties',\n this.groupRule?.groupingOptions.propertyKey ?? ''\n ]);\n return `${Tools.getValueFromLkProperty(propertyValue)}`;\n }\n\n /**\n * Return a hashed string that represents the group id\n */\n private _findNodeGroupId(nodes: NodeList<LkNodeData, LkEdgeData>): string {\n const propertyValue = this._findGroupingPropertyValue(nodes.get(0));\n return sha1(\n `${this.groupRule?.name}-${this.groupRule?.groupingOptions.itemTypes.join(\n '-'\n )}-${propertyValue}`\n );\n }\n}\n"]}
1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QACH,OAAO,GAAG,aAAK,CAAC,sBAAsB,CAAC,aAAa,CAAC,EAAE,CAAC;IAC1D,CAAC;IAED;;OAEG;IACK,gBAAgB,CAAC,KAAuC;;QAC9D,MAAM,aAAa,GAAG,IAAI,CAAC,0BAA0B,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QACpE,OAAO,IAAA,cAAI,EACT,GAAG,MAAA,IAAI,CAAC,SAAS,0CAAE,IAAI,IAAI,MAAA,IAAI,CAAC,SAAS,0CAAE,eAAe,CAAC,SAAS,CAAC,IAAI,CACvE,GAAG,CACJ,IAAI,aAAa,EAAE,CACrB,CAAC;IACJ,CAAC;CACF;AA1PD,gEA0PC","sourcesContent":["import {Transformation, Node, NodeList, StyleRule} from '@linkurious/ogma';\nimport {LkEdgeData, LkNodeData, MissingValue, NodeGroupingRule} from '@linkurious/rest-client';\nimport sha1 from 'sha1';\n\nimport {FORCE_LAYOUT_CONFIG, LKOgma} from '../index';\nimport {Tools} from '../../tools/tools';\n\nexport const LKE_NODE_GROUPING_EDGE = 'LKE_NODE_GROUPING_EDGE';\nexport const LKE_NODE_GROUPING_NODE = 'LKE_NODE_GROUPING_NODE';\n\nexport class NodeGroupingTransformation {\n public transformation?: Transformation<LkNodeData, LkEdgeData>;\n public groupRule?: NodeGroupingRule;\n public nodeGroupingStyleRule?: StyleRule<LkNodeData, LkEdgeData>;\n private _ogma: LKOgma;\n\n constructor(ogma: LKOgma) {\n this._ogma = ogma;\n }\n\n /**\n * Set the grouping rule\n * @param rule of grouping\n */\n public setGroupingRule(rule: NodeGroupingRule | undefined): void {\n this.groupRule = rule;\n }\n\n /**\n * create a node grouping transformation\n * It uses groupRule to define the rule\n * Group the nodes based on a category type and a property value\n */\n public async initTransformation(): Promise<void> {\n if (this.transformation === undefined) {\n this.transformation = this._ogma.transformations.addNodeGrouping({\n groupIdFunction: (node) => {\n if (this._isRuleNotApplicableToNode(node)) {\n return undefined;\n } else {\n const propertyValue = this._findGroupingPropertyValue(node);\n // groupRule is defined if not we returned undefined\n // node with same value will be part of the same group\n return `${this.groupRule?.groupingOptions.itemTypes.join('-')}-${propertyValue}`\n .toLowerCase()\n .trim();\n }\n },\n nodeGenerator: (nodes) => {\n return {\n data: {\n categories: [LKE_NODE_GROUPING_NODE],\n properties: {},\n nodeGroupId: this._findNodeGroupId(nodes)\n }\n };\n },\n edgeGenerator: () => {\n return {\n data: {\n type: LKE_NODE_GROUPING_EDGE\n }\n };\n },\n showContents: true,\n padding: 10\n });\n } else {\n await this.refreshTransformation();\n }\n }\n\n /**\n * refresh the transformation\n * Called when there is a change in the rule\n */\n public async refreshTransformation(): Promise<void> {\n if (this.transformation !== undefined) {\n await this.transformation.refresh();\n await this._unpinNodes(this._getAllTransformationRawNodes());\n } else {\n await this.initTransformation();\n }\n }\n\n /**\n * init node grouping style\n */\n public initNodeGroupingStyle(): void {\n this.nodeGroupingStyleRule = this._ogma.styles.addRule({\n nodeAttributes: {\n // Any default style will go here\n text: {\n content: (node: Node<LkNodeData> | undefined): string | undefined => {\n return this._getNodeGroupingCaption(node);\n },\n style: 'bold'\n },\n layer: -1,\n color: 'rgba(240, 240, 240)',\n innerStroke: {\n color: '#7f7f7f',\n width: 2\n }\n },\n nodeSelector: (node) => {\n // TODO: Tools.isDefined(node.getSubNodes()) is a work around for an ogma issue visible when using image export plugin with Node grouping\n // remove when updating to Ogma v5.1.x\n return node.isVirtual() && Tools.isDefined(node.getSubNodes());\n },\n // the style will be updated when data object is updated\n nodeDependencies: {self: {data: true}}\n });\n }\n\n public async refreshNodeGroupingStyle(): Promise<void> {\n await this.nodeGroupingStyleRule?.refresh();\n }\n\n /**\n * run layout on all subnodes of virtual nodes\n */\n public async runLayoutOnAllSubNodes(): Promise<void> {\n await this._ogma.transformations.afterNextUpdate();\n const rawNodesList = this._getAllTransformationRawNodes();\n const promisesList: Promise<void>[] = [];\n for (let i = 0; i < rawNodesList.length; i++) {\n // rawNodesList[i] is not null because each group has at least one node\n const subNodes = rawNodesList[i]!;\n promisesList.push(this.runSubNodesLayout(subNodes));\n }\n await Promise.all(promisesList);\n }\n\n /**\n * Run the layout on the subnodes of the virtual node\n * @param subNodes nodes part of a virtual node\n */\n public async runSubNodesLayout(subNodes: NodeList<LkNodeData, LkEdgeData>): Promise<void> {\n if (subNodes.size === 0 || subNodes.size === 1) {\n return;\n }\n\n const noEdges = subNodes.getAdjacentEdges({bothExtremities: true}).size === 0;\n if (noEdges) {\n await this._runCirclePack(subNodes);\n } else {\n await this._runForceLayout(subNodes);\n }\n }\n\n /**\n * Get the virtual nodes of the transformation\n * @private\n */\n public getVirtualNodesOfTransformation(): NodeList<LkNodeData, LkEdgeData> {\n // @ts-ignore getContext exists on the transformation but hidden by the types\n return this.transformation.getContext().metaNodes;\n }\n\n /**\n * Return the caption of a virtual node\n * @param node reference to the virtual node\n */\n private _getNodeGroupingCaption(node: Node<LkNodeData> | undefined): string | undefined {\n // TODO: Normally there is no need to check if getSubNodes return a value, Ogma issue\n //https://github.com/Linkurious/ogma/issues/3876\n if (node !== undefined && node.isVirtual() && node.getSubNodes()?.get(0) !== undefined) {\n // get the property value of the first node of the group (all nodes share the same property value)\n const lkPropertyValue = node\n .getSubNodes()!\n .get(0)\n .getData(['properties', this.groupRule!.groupingOptions.propertyKey]);\n const propertyValue = Tools.getValueFromLkProperty(lkPropertyValue);\n const size = node.getSubNodes()!.filter((e) => !e.hasClass('filtered')).size;\n return `${propertyValue} (${size})`;\n }\n }\n\n /**\n * Run the circle pack layout on the subnodes\n * @param subNodes\n */\n private async _runCirclePack(subNodes: NodeList<LkNodeData, LkEdgeData>): Promise<void> {\n await this._ogma.algorithms.circlePack({\n nodes: subNodes,\n margin: 10,\n sort: 'asc'\n });\n }\n\n private async _runForceLayout(subNodes: NodeList<LkNodeData, LkEdgeData>): Promise<void> {\n await this._ogma.layouts.force({\n nodes: subNodes,\n ...FORCE_LAYOUT_CONFIG\n });\n }\n\n private _isRuleNotApplicableToNode(node: Node<LkNodeData>): boolean {\n const propertyValue = node.getData([\n 'properties',\n this.groupRule?.groupingOptions.propertyKey ?? ''\n ]);\n return (\n // if the group rule is not defined\n this.groupRule === undefined ||\n // if rule is applied to a different category\n this.groupRule.groupingOptions.itemTypes.every(\n (itemType) => !node.getData('categories').includes(itemType)\n ) ||\n // if the property value is not defined\n !Tools.isDefined(propertyValue) ||\n // if the property value is missing\n (typeof propertyValue === 'object' && (propertyValue as MissingValue).status === 'missing')\n );\n }\n\n /**\n * Unpin list of nodes\n * @param nodes\n * @private\n */\n private async _unpinNodes(nodes: Array<NodeList | null>): Promise<void> {\n await Promise.all(\n nodes.map((nodeList) => {\n if (nodeList !== null) {\n return nodeList.setAttribute('layoutable', true);\n }\n })\n );\n }\n\n /**\n * Get all the raw nodes part of the transformation\n * @private\n */\n private _getAllTransformationRawNodes(): Array<NodeList | null> {\n const virtualNodes = this.getVirtualNodesOfTransformation();\n return virtualNodes.getSubNodes();\n }\n\n private _findGroupingPropertyValue(node: Node<LkNodeData>): string {\n const propertyValue = node.getData([\n 'properties',\n this.groupRule?.groupingOptions.propertyKey ?? ''\n ]);\n return `${Tools.getValueFromLkProperty(propertyValue)}`;\n }\n\n /**\n * Return a hashed string that represents the group id\n */\n private _findNodeGroupId(nodes: NodeList<LkNodeData, LkEdgeData>): string {\n const propertyValue = this._findGroupingPropertyValue(nodes.get(0));\n return sha1(\n `${this.groupRule?.name}-${this.groupRule?.groupingOptions.itemTypes.join(\n '-'\n )}-${propertyValue}`\n );\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@linkurious/ogma-linkurious-parser",
3
- "version": "4.1.4",
3
+ "version": "4.1.5",
4
4
  "author": "Linkurious SAS",
5
5
  "description": "Parse and load a Linkurious visualization in Ogma with one line of code ",
6
6
  "files": [
@@ -54,7 +54,7 @@
54
54
  },
55
55
  "devDependencies": {
56
56
  "@linkurious/ogma": "5.1.1",
57
- "@linkurious/rest-client": "4.1.4",
57
+ "@linkurious/rest-client": "4.1.5",
58
58
  "@rollup/plugin-buble": "0.21.3",
59
59
  "@rollup/plugin-commonjs": "17.0.0",
60
60
  "@rollup/plugin-json": "4.1.0",