neovis.js
neovis.js copied to clipboard
[2.0.0] Node label doesn't accept newline character in a config function
Hi again @thebestnom,
I'm trying to build a label for a Neovis node from concatenating two node properties in Neo4j using a config function:
(node) => {label=node.properties['propA']+"\n"+node.properties['propB']; return label;}
If I use the "\n", neovis throws the following error:
Function type property field must be a function
I believe these lines of Neovis code should be blamed:
_runFunction(func, node) {
if (typeof func === 'function') {
return func(node);
}
throw new Error('Function type property field must be a function');
}
If I try the same thing using backticks, like:
(node) => {label=`${node.properties['propA']} \n ${node.properties['propB']}`; return label;}
No exception is thrown, but weird stuff happens:

The funny thing is that both approaches work as expected in pure Vis.js...
Any ideas on that?
No idea, that's so weird. Finally will have time today to check that and Ill debug, can you send me a minimal working dataset? I can make one myself but it will make my life easier 😅
No idea, that's so weird. Finally will have time today to check that and Ill debug, can you send me a minimal working dataset? I can make one myself but it will make my life easier
For sure, it happens with the toy got dataset you used
export.csv
I used this function for node labels:
(node) => {label=`${node.properties['name']} \n ${node.properties['name']}`; return label;}
tested now, didn't got the first error you got (Function type property field must be a function)
also, this is what I get for
var config = {
container_id: 'viz',
neo4j: {
server_url: 'bolt://localhost:7687',
server_user: 'neo4j',
server_password: 'password'
},
visConfig: {
nodes: {
shape: 'triangle'
},
edges: {
arrows: {
to: {enabled: true}
}
},
},
labels: {
Please: {
group: 'community',
[NeoVis.NEOVIS_ADVANCED_CONFIG]: {
cypher: {
value: "MATCH (n) WHERE id(n) = $id RETURN n.pagerank"
},
function: {
title: NeoVis.objectToTitleHtml,
label: node => {
const label = `${node.properties.name}\n${node.properties.pagerank}`;
return label;
}
},
}
}
},
relationships: {
REAL: {
value: 'weight',
[NeoVis.NEOVIS_ADVANCED_CONFIG]: {
function: {
title: NeoVis.objectToTitleHtml
},
}
}
},
initial_cypher: 'MATCH (n)-[r]->(m) RETURN n,r,m'
};
