neo4j-contrib / neovis.js

Neo4j + vis.js = neovis.js. Graph visualizations in the browser with data from Neo4j.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to change the color shade of nodes according to a node attribute?

hantongyou opened this issue · comments

For example, I want to use neovis to draw a influence graph of each node. And there is an attribute "influence" which is between 0 and 1, now how to use this attribute to adjust the node color shape? When influence is smaller the color would be lighter.

You can use advanved config to put a function in the color that the color would be a function that's get the attribute value and the output would be a color probably from a color
Maybe somthing like this
https://stackoverflow.com/questions/10848990/rgb-values-to-0-to-1-scale

however my code did not work like I expected. Here is my code:

{
[NeoVis.NEOVIS_ADVANCED_CONFIG]:{
                static:{
                    // group:labels[i],
                },
                function:{
                    title:(node)=>{
                        // console.log(Object.keys(node.properties));
                        return NeoVis.objectToTitleHtml(node, Object.keys(node.properties))},
                    label:(node)=>{
                        if(node.properties.indexName.length>=10)
                            return (node,node.properties.indexName.substr(0,10)+"...")
                        else
                            return (node,node.properties.indexName+"...")
                    },
                    color:(node)=>{
                        return (node,(0,0,255*node.properties.Contribution))
                    }
                    
                    }
            }
}

It seems like nothing has changed.

image

Thanks! Now i use opacity instead of color the problem has been fixed perfectly.
image