From d151185c9cd2e2b6c0b9eb02b35cf267a09c2638 Mon Sep 17 00:00:00 2001 From: gianluca-pepe <37369540+gianluca-pepe@users.noreply.github.com> Date: Thu, 24 Oct 2019 10:32:21 +0200 Subject: [PATCH] Replicate also inclusions involving replicated attributes in lite-mode --- src/view/render/easy-gscape-renderer.js | 30 +++++++++++++++++++------ src/view/style/graph-style.js | 2 +- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/view/render/easy-gscape-renderer.js b/src/view/render/easy-gscape-renderer.js index dc1d426f..fc458299 100644 --- a/src/view/render/easy-gscape-renderer.js +++ b/src/view/render/easy-gscape-renderer.js @@ -272,6 +272,7 @@ export default class EasyGscapeRenderer extends GrapholscapeRenderer { return new_edge } + /** * @param {array} edges - array of edges in json format * @param {cytoscape} cy @@ -595,30 +596,45 @@ export default class EasyGscapeRenderer extends GrapholscapeRenderer { let cy = node.cy() let all_classes = getAllInputs(node) let all_attributes = node.neighborhood('[type = "attribute"]') + let all_inclusion_attributes = cy.collection() + all_classes.forEach( (concept,i) => { all_attributes.forEach((attribute, j) => { - addAttribute(concept, i, attribute) + addAttribute(concept, i, attribute, 'attribute') }) }) cy.remove(all_attributes) + this.filterElem(all_inclusion_attributes) - function addAttribute(concept, i, attribute) { + function addAttribute(target, i, attribute, edge_classes) { let new_attribute = attribute.json() - new_attribute.position = concept.position() - new_attribute.data.id += '_'+i+'_'+concept.id() + new_attribute.position = target.position() + new_attribute.data.id += '_'+i+'_'+target.id() new_attribute.classes += ' repositioned' + //attribute.addClass('repositioned') cy.add(new_attribute) let edge = { data: { id: new_attribute.data.id + '_edge', target: new_attribute.data.id, - source: concept.id(), + source: target.id(), }, - classes: 'attribute', + classes: edge_classes, } - cy.add(edge) + + // recursively add new attributes connected to replicated attributes by inclusions + if (!target.hasClass('repositioned')) { + attribute.neighborhood('[type = "attribute"]').forEach( (inclusion_attribute, j) => { + if(all_attributes.contains(inclusion_attribute)) { + return + } + + addAttribute(cy.$id(new_attribute.data.id), j, inclusion_attribute, 'inclusion') + all_inclusion_attributes = all_inclusion_attributes.union(inclusion_attribute) + }) + } } function getAllInputs(node) { diff --git a/src/view/style/graph-style.js b/src/view/style/graph-style.js index 5edb96cf..3fd58254 100644 --- a/src/view/style/graph-style.js +++ b/src/view/style/graph-style.js @@ -38,7 +38,7 @@ export function getGraphStyle(theme) { }, { - selector: 'edge[type = "inclusion"], [type = "membership"]', + selector: 'edge[type = "inclusion"], [type = "membership"], edge.inclusion', style: { 'line-style': 'solid', 'target-arrow-shape': 'triangle',