Search code examples
neo4jgraph-visualization

How to iteratively expand nodes (on clicking) using popoto.js?


I am developing a web interface to the neo4j database using popoto.js. Currently, I am able to display a start node and expand the graph up to 3-4 levels by clicking on the node relationships. It seems that the underlying query that popoto uses gets updated along with the expanding graph and after a certain point the query becomes invalid and popoto resets the graph. What I am trying to create is an interface where I can expand any node in the graph (and hence expanding the overall graph) similar to what is possible in the neo4j browser. How can I achieve this?


Solution

  • Popoto.js handles this automatically but the schema has to be defined in the following way to assist it.

    export const schema = {
        Person: {
            label: "Person",
            value: {
                name: ""
            },
            rel: [
                {
                    label: "works_at",
                    target: {
                        label: "company",
                    },
                },
                {
                    label: "studies_at",
                    target: {
                        label: "college",
                    }
                }
            ]
        },
        Company: {
            label: "company",
            value: {
                name: ""
            },
            rel: [
                {
                    label: "works_at",
                    target: {
                        label: "person",
                    },
                }
            ]
        }
        }