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))
}
}
}
}
The color function should return a string
https://visjs.github.io/vis-network/docs/network/nodes.html