almende / vis

⚠️ This project is not maintained anymore! Please go to https://github.com/visjs
7.85k stars 1.48k forks source link

Vis.js Network Include all nodes related to 1 cluster #4067

Open pdanielkoe opened 6 years ago

pdanielkoe commented 6 years ago

Hi, sorry if this question has been asked. Here I have a network like below, image

what I would like to achieve:

here my code

network.on("doubleClick", function (params) {
    if (params.nodes.length == 1) {
        if (network.isCluster(params.nodes[0]) == true) {
            var openClusterObj = {};
            openClusterObj.releaseFunction = function (clusterPosition, containedNodesPositions) {
                return containedNodesPositions;
            };
            network.openCluster(params.nodes[0], openClusterObj);
        } else {
            var count_child = 0;
            var clusterOptionsByData = {
                joinCondition: function (childOptions) {
                    if (network.getConnectedNodes(params.nodes[0], "to").includes(childOptions.id)
                        || params.nodes[0] == childOptions.id) {
                        count_child++;
                        return true;
                    }
                    return false;
                },
                clusterNodeProperties: {
                    label: (nodes_dataset.get(params.nodes[0]).label + " [" + network.getConnectedNodes(params.nodes[0], "to").length + "]"),
                    borderWidth: 3,
                    x: nodes_dataset.get(params.nodes[0]).x,
                    y: nodes_dataset.get(params.nodes[0]).y,
                    group: nodes_dataset.get(params.nodes[0]).group
                }
            };
            network.cluster(clusterOptionsByData);
        }
    }
});

for the 1st layer (parent-child nodes) of cluster it works, like below: image image but when I click on the 'grandpa' node, it behave like below: image image I expecting like below: image

How should I improve the joinCondition to crawl all the related nodes 'top-down' direction:

joinCondition: function (childOptions) {
    if (network.getConnectedNodes(params.nodes[0], "to").includes(childOptions.id)
        || params.nodes[0] == childOptions.id) {
        count_child++;
        return true;
    }
    return false;
},

Thank you

Loxxe commented 6 years ago

3129

The examples in the comments works for me

pdanielkoe commented 6 years ago

Hi, after i add hierarchical: true,