jexp / neo4j-graphviz

minimal javascript library/tool to generate graphviz visualization from a neo4j cypher query
MIT License
36 stars 4 forks source link

Mapping properties to labels #4

Open RamblingCookieMonster opened 6 years ago

RamblingCookieMonster commented 6 years ago

Hi!

I'm a bit of a neo4j and javascript newbie, so apologies if this doesn't make sense.

It might be handy to allow a user-specific map of label(s) to property, so that titles make sense for a particular database.

Absolutely not how you would implement it, but for example, we're using a hard coded bit like this:

var LabelMap = {};
LabelMap['Server'] = 'DotsHostname';
LabelMap['Group'] = 'ADSamAccountName';
LabelMap['User'] = 'ADSamAccountName';
LabelMap['MSSqlInstance'] = 'SQLInstance';
LabelMap['Service'] = 'name';
function name(node) {
    for (var Prop in LabelMap) {
        if (LabelMap.hasOwnProperty(Prop) && labels(node).includes(Prop)) {
            return node.properties[LabelMap[Prop]];
        }
    }
    var x = ["^name$","^title$","^label$","value","name$","title$","label$",""];
    var props = node.properties;
    for (var i=0;i<x.length;i++) {
        for (let k in props) {
            if (props.hasOwnProperty(k) && k.toLowerCase().match(x[i])) return props[k];
        }
    }
    return node.identity.toString();
}

Not sure what the best route would be to expose this (e.g. in PowerShell I might simply allow a hashtable param so someone could just specify -LabelMap @{User='ADSamAccountName';Service='name'}). Just going to keep things hard coded on our side for now, given that this seems a bit inactive

Cheers!

jexp commented 6 years ago

Sure, feel free to customize it. on a command-line it would probably use a comma separated list of label:property pairs.