neo4j-contrib / neovis.js

Neo4j + vis.js = neovis.js. Graph visualizations in the browser with data from Neo4j.
Apache License 2.0
1.59k stars 325 forks source link

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

Open aguinaldoabbj opened 3 years ago

aguinaldoabbj commented 3 years ago

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?

thebestnom commented 3 years ago

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 😅

aguinaldoabbj commented 3 years ago

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;}
thebestnom commented 3 years ago

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