neovis.js icon indicating copy to clipboard operation
neovis.js copied to clipboard

[2.0.0] Node label doesn't accept newline character in a config function

Open aguinaldoabbj opened this issue 4 years ago • 3 comments

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:

weird

The funny thing is that both approaches work as expected in pure Vis.js...

Any ideas on that?

aguinaldoabbj avatar Sep 13 '21 23:09 aguinaldoabbj

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 😅

thebestnom avatar Sep 14 '21 10:09 thebestnom

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

toy_example export.csv I used this function for node labels:

(node) => {label=`${node.properties['name']} \n ${node.properties['name']}`; return label;}

aguinaldoabbj avatar Sep 14 '21 17:09 aguinaldoabbj

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'
			};

image

thebestnom avatar Sep 20 '21 13:09 thebestnom