diff --git a/src/plugins/kibi_core/lib/query_engine.js b/src/plugins/kibi_core/lib/query_engine.js index 3042cd54c..1f0877e69 100644 --- a/src/plugins/kibi_core/lib/query_engine.js +++ b/src/plugins/kibi_core/lib/query_engine.js @@ -346,7 +346,8 @@ QueryEngine.prototype._loadScripts = function () { 'select-by-edge-count', 'show-nodes-count-by-type', 'replace-investment-nodes', - 'shortest-path' + 'shortest-path', + 'expand-by-relation' ]; self.log.info('Loading scripts'); diff --git a/src/plugins/kibi_core/lib/scripts/expand-by-relation.json b/src/plugins/kibi_core/lib/scripts/expand-by-relation.json new file mode 100644 index 000000000..8acfe7994 --- /dev/null +++ b/src/plugins/kibi_core/lib/scripts/expand-by-relation.json @@ -0,0 +1,9 @@ +{ + "title": "Expand by relation", + "description": "Expands the selected nodes using the selected relations", + "st_scriptSource": "function beforeAll(graphModel, graphSelection) {\n const relations = _getKibiRelations();\n \n let relevantNodes = [];\n if(graphSelection.length === 0) {\n _.each(graphModel.nodes, function(node) {\n relevantNodes.push(node.id);\n });\n } else {\n relevantNodes = graphSelection;\n }\n \n let relevantRel = {};\n _.each(relations, function(relation) {\n _.each(relevantNodes, function (nodeId) {\n var from = new RegExp(relation.indices[0].indexPatternId);\n var to = new RegExp(relation.indices[1].indexPatternId);\n\n let nodeIndex = nodeId.substring(0, nodeId.indexOf('/'));\n if (from.test(nodeIndex) || to.test(nodeIndex)) {\n if(!relevantRel[relation.id]) {\n relevantRel[relation.id] = relation;\n }\n }\n });\n });\n \n console.log(relevantRel);\n let html = '
';\n _.each(relevantRel, function (rel) {\n html = html + ' ' + rel.label + '
';\n });\n \n html = html + '
';\n _openModal('Select the relation you want to expand', html);\n\n return {\n model: null,\n selection: null\n };\n}\n\nfunction onModalOk(scope, graphModel) {\n let selectedRel = [];\n\n for (var rel in scope.relations) {\n if (scope.relations.hasOwnProperty(rel)) {\n if (scope.relations[rel]) {\n selectedRel.push(rel);\n }\n }\n }\n\n return selectedRel;\n}\n\nfunction afterModalClosed(graphModel, graphSelection, onOkModalResult) {\n let selection;\n if (graphSelection && graphSelection.length > 0) {\n selection = graphSelection;\n } else {\n selection = [];\n _.each(graphModel.nodes, function (node) {\n selection.push(node.id); \n });\n }\n \n let query = 'g.V(' + JSON.stringify(selection)\n + ').bothE().as(\"e\").bothV().as(\"v\").properties().select(\"e\", \"v\").mapValues().dedup()';\n\n let relationsSet = new Set(onOkModalResult);\n return _runGremlinQuery(query).then(function (results) {\n let filteredResults = [];\n let nodeIdSet = new Set();\n \n _.each(results, function (item) {\n if (item.type === 'edge') {\n if (relationsSet.has(item.label)) {\n nodeIdSet.add(item.inV);\n nodeIdSet.add(item.outV);\n filteredResults.push(item);\n }\n }\n });\n \n _.each(results, function (item) {\n if (item.type === 'vertex') {\n if (nodeIdSet.has(item.id)) {\n filteredResults.push(item);\n }\n }\n });\n \n _addResultsToGraph(filteredResults);\n });\n}", + "version": 1, + "kibanaSavedObjectMeta": { + "searchSourceJSON": "{}" + } +}