Скрыть узлы и края в Cytoscape на основе значения - PullRequest
0 голосов
/ 27 марта 2020

Я играю с Cytoscape и у меня есть следующий код:

this.cy = cytoscape({
            container: this.cyto.nativeElement,
            elements: nodes.concat(relations),
            style: JSON.parse(`[{
                    "selector": "node",
                    "style": {
                        "color": "#292d30",
                        "label": "data(node_type)",
                        "text-valign": "center",
                        "text-halign": "center",
                        "text-wrap": "wrap",
                        "width": "data(length)",
                        "height": "data(length)",
                        "background-color": "data(color)"
                    }
                }, {
                    "selector": "edge",
                    "style": {
                        "color": "#fff",
                        "label": "data(node_type)",
                        "font-size": "12",
                        "edge-text-rotation": "autorotate",
                        "width": "1",
                        "text-wrap": "wrap",
                        "display": "data(display)"
                    }
                }]`),
            layout: {
                name: this.settingsLayout || 'circle'
            }
        });

Если бы я должен был console.log элементы, это выглядит так:

[
    {
        "data":
        {   "id": "99214f5a",
            "node_type": "fake_record",
            "length": 143,
            "color": "#8dd3c7",
            "layout": "cose",
            "entity_type": 1,
            "properties": {"id": "3", "name": "Joe Bloggs", "address": "15 fake street"},
            "name": "fake_record",
            "neighbour_count": 0}
    },
    {
        "data":
        {   "id": "f137fb3a",
            "node_type": "fake_record",
            "length": 143,
            "color": "#8dd3c7",
            "layout": "cose",
            "entity_type": 1,
            "properties": {"id": "2", "name": "Jane Bloggs", "address": "15 fake street"},
            "name": "fake_record",
            "neighbour_count": 2}
    },
    {
        "data":
        {   "id": "f9e8d093",
            "node_type": "fake_record",
            "length": 143,
            "color": "#8dd3c7",
            "layout": "cose",
            "entity_type": 1,
            "properties": {"id": "2", "name": "Joe Bloggs", "address": "1 real lane"},
            "name": "fake_record",
            "neighbour_count": 2}
    },
    {
        "data":
        {   "id": "1",
            "source": "99214f5a",
            "target": "f137fb3a",
            "confidence": 1,
            "l_values": {"address": "15 fake street"},
            "r_values": {"address": "15 fake street"}
        }
    },
    {
        "data":
        {   "id": "1",
            "source": "99214f5a",
            "target": "f9e8d093",
            "confidence": 0.5,
            "l_values": {"name": "Joe Bloggs"},
            "r_values": {"name": "Joe Bloggs"}
        }
    }
]

По существу при создании цитопейзажа я хочу иметь возможность фильтровать наши узлы и ребра по значению достоверности.

Я могу очень легко фильтровать отношения, выполняя это

elements: nodes.concat(rels.filter(r => r.data.confidence >= 0.6))

Однако я не могу понять, как фильтровать соответствующие узлы тоже.

...