almende / vis

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

How to make a uniform color for a set of nodes in neovis.js / vis.js #4217

Closed suchetaswabhav closed 5 years ago

suchetaswabhav commented 5 years ago

I am working with Neo4j application. And it creates nodal graph. To display the nodal graph on UI , we have Neovis.js. Neovis.js name taken from vis.js. The output that i get is -

organisationdashboard

Here in the picture, all the nodes have a different color. We have relationships like Department, Function, System, Parameter,etc. I want a uniform color for all the nodes with relationship - Parameter and all the nodes with relationship - Department, etc. As in this pic -

uniform-dash

Please suggest changes in the following codes. It will be very useful.

code -

visjs in Neovis.js

visjs: {
        interaction: {
            hover: true,
            hoverConnectedEdges: true,
            selectConnectedEdges: false,
    //        multiselect: true,
            multiselect: 'alwaysOn',
            zoomView: false,
            experimental: { }
        },
        physics: {
            barnesHut: {
                damping: 0.1
            }
        },
        nodes: {
            mass: 4,
            shape: 'neo',
            labelHighlightBold: false,
            widthConstraint: {
                maximum: 40
            },
            heightConstraint: {
                maximum: 40
            }
        },
        edges: {
            hoverWidth: 0,
            selectionWidth: 0,
            smooth: {
                type: 'continuous',
                roundness: 0.15
            },
            font: {
                size: 9,
                strokeWidth: 0,
                align: 'top'
            },
            color: {
                inherit: false
            },
            arrows: {
                to: {
                    enabled: true,
                    type: 'arrow',
                    scaleFactor: 0.5
                }
            }
        }

    }

front-end Neovis.js to display nodes

      var config = {
         container_id: "viz",
         server_url: "bolt://localhost:7474/",
         server_user: "neo4j",
         server_password: "ib1",
        labels: {
             //"Character": "name",
             "Banking": {
                 "caption": "name",
                 "size": "pagerank",
                 community: "community",

                 "sizeCypher": "MATCH (n) WHERE id(n) = {id} MATCH (n)-[r]-() RETURN sum(r.weight) AS c"
             },
             "Parameter": {
                "thickness": "weight",
                "caption": true,
                community: "community",
                "sizeCypher": "MATCH (n) WHERE id(n) = {id} MATCH (n)-[r]-() RETURN sum(r.weight) AS c"
            },
            "Method": {
               "thickness": "weight",
               "caption": true,
               community: "community",
               "sizeCypher": "MATCH (n) WHERE id(n) = {id} MATCH (n)-[r]-() RETURN sum(r.weight) AS c"
           },
           "Request": {
               "thickness": "weight",
               "caption": true,
               community: "community",
           },
           "Response": {
               "thickness": "weight",
               "caption": true,
               "community": "Pink"
           },
           "Paths": {
               "thickness": "weight",
               "caption": true,
               "community": "Purple"
           },
           "API": {
               "thickness": "weight",
               "caption": true,
               "community": "Black"
           },
           "Department": {
               "thickness": "weight",
               "caption": true,
               community: "community",
               "sizeCypher": "MATCH (n) WHERE id(n) = {id} MATCH (n)-[r]-() RETURN sum(r.weight) AS c"
           },
           "System": {
               "thickness": "weight",
               "caption": true,
               "community": "Red"
           },

         },
         relationships: {
             "Parameter": {
                 thickness: "weight",
                 caption: true,
                 community: "community",
                 color:'red'
             },
             "Method": {
                "thickness": "weight",
                "caption": true,
                "community": "Blue",
                'color':'red'
            },
            "Request": {
                "thickness": "weight",
                "caption": true,
                "community": "Red",
                'color':'green'
            },
            "Response": {
                "thickness": "weight",
                "caption": true,
                "community": "Red",
                'color':'black'
            },
            "Paths": {
                "thickness": "weight",
                "caption": true,
                "community": "Red",
                'color':'pink'
            },
            "API": {
                "thickness": "weight",
                "caption": true,
                "community": "Red",
                'color':'pink'
            },
            "Department": {
                "thickness": "weight",
                "caption": true,
                "community": "Red",
                'color':'pink'
            },
            "System": {
                "thickness": "weight",
                "caption": true,
                "community": "Red",
                'color':'pink'
            },
         },

         initial_cypher:cypherQuery ,        
        arrows: true,
        hierarchical_layout:true,
        hierarchical_sort_method:"directed",

     };         
ddazal commented 5 years ago

I think you're looking for groups. Maybe you can assign the group name to the nodes once the data from Neo4j has been fetched...anyway, check out the docs.

mojoaxel commented 5 years ago

This issue tracker is not supposed to be used for questions on how to use visjs. It is intended to be used for bug reports and feature requests! In case you face yourself with a usage question, then post your question e.g. on stackoverflow tagged with "vis.js".