plugins/incub/visualizer/old/src/js/demo_vivagraph.js
function addToGlobalNodes(node){
    var nodeToAdd = {
        "_id": node.id(),
        "_world": node.world(),
        "_time": node.time(),
        "_type": (node.nodeTypeName() ? node.nodeTypeName() : "default")
    };

    var containsRel = false;
    // add all the attributes of the node to the JSON
    graph.resolver().resolveState(node, false).each(function (attributeKey, elemType, elem) {
        var key = graph.resolver().hashToString(attributeKey);

        if(elemType == org.mwg.Type.BOOL || elemType == org.mwg.Type.STRING || elemType == org.mwg.Type.INT
            || elemType == org.mwg.Type.LONG || elemType == org.mwg.Type.DOUBLE) { //primitive types
            nodeToAdd[key] = elem;
        } else if(elemType == org.mwg.Type.RELATION) { //classic relation
            nodeToAdd[key] = [];
            for (var i = 0; i < elem.size(); ++i){
                nodeToAdd[key].push(elem.get(i));
            }
            containsRel = true;
        } else if(elemType == org.mwg.Type.LONG_TO_LONG_ARRAY_MAP) { //indexed relation
            nodeToAdd[key] = [];
            elem.each(function(relKey,relIdNode) {
                nodeToAdd[key].push(relIdNode);
            });
            containsRel = true;
        } else {
            throw "Type(" + elemType + ") is not yet managed. Please update the debugger."
        }
    });
    // if the node contains a relationship, we add them into a global variable to deal with the relationships later
    if (containsRel){
        gNodesWithRel.push(nodeToAdd);
    }

    // we sort the nodes per type
    if (gNodesPerType[nodeToAdd._type] == null){
        gNodesPerType[nodeToAdd._type] = [];
        colorsByNodeType[nodeToAdd._type] = getRandomColor(); // add the type of the node to the type list and assign a color to the type
    }
    gNodesPerType[nodeToAdd._type].push(nodeToAdd);

    // finally we add them to the global array containing all the nodes
    gAllNodes.push(nodeToAdd);

}
function addToGlobalNodes(node){
    var nodeToAdd = {
        "_id": node.id(),
        "_world": node.world(),
        "_time": node.time(),
        "_type": (node.nodeTypeName() ? node.nodeTypeName() : "default")
    };

    var containsRel = false;
    // add all the attributes of the node to the JSON
    graph.resolver().resolveState(node, false).each(function (attributeKey, elemType, elem) {
        var key = graph.resolver().hashToString(attributeKey);

        if(elemType == org.mwg.Type.BOOL || elemType == org.mwg.Type.STRING || elemType == org.mwg.Type.INT
            || elemType == org.mwg.Type.LONG || elemType == org.mwg.Type.DOUBLE) { //primitive types
            nodeToAdd[key] = elem;
        } else if(elemType == org.mwg.Type.RELATION) { //classic relation
            nodeToAdd[key] = [];
            for (var i = 0; i < elem.size(); ++i){
                nodeToAdd[key].push(elem.get(i));
            }
            containsRel = true;
        } else if(elemType == org.mwg.Type.LONG_TO_LONG_ARRAY_MAP) { //indexed relation
            nodeToAdd[key] = [];
            elem.each(function(relKey,relIdNode) {
                nodeToAdd[key].push(relIdNode);
            });
            containsRel = true;
        } else {
            throw "Type(" + elemType + ") is not yet managed. Please update the debugger."
        }
    });
    // if the node contains a relationship, we add them into a global variable to deal with the relationships later
    if (containsRel){
        gNodesWithRel.push(nodeToAdd);
    }

    // we sort the nodes per type
    if (gNodesPerType[nodeToAdd._type] == null){
        gNodesPerType[nodeToAdd._type] = [];
        colorsByNodeType[nodeToAdd._type] = getRandomColor(); // add the type of the node to the type list and assign a color to the type
    }
    gNodesPerType[nodeToAdd._type].push(nodeToAdd);

    // finally we add them to the global array containing all the nodes
    gAllNodes.push(nodeToAdd);

}
function addToGlobalNodes ( node ) { var nodeToAdd = { "_id" : node . id ( ) , "_world" : node . world ( ) , "_time" : node . time ( ) , "_type" : ( node . nodeTypeName ( ) ? node . nodeTypeName ( ) : "default" ) } ; var containsRel = false ; // add all the attributes of the node to the JSON graph . resolver ( ) . resolveState ( node , false ) . each ( function ( attributeKey , elemType , elem ) { var key = graph . resolver ( ) . hashToString ( attributeKey ) ; if ( elemType == org . mwg . Type . BOOL || elemType == org . mwg . Type . STRING || elemType == org . mwg . Type . INT || elemType == org . mwg . Type . LONG || elemType == org . mwg . Type . DOUBLE ) { //primitive types nodeToAdd [ key ] = elem ; } else if ( elemType == org . mwg . Type . RELATION ) { //classic relation nodeToAdd [ key ] = [ ] ; for ( var i = 0 ; i < elem . size ( ) ; ++ i ) { nodeToAdd [ key ] . push ( elem . get ( i ) ) ; } containsRel = true ; } else if ( elemType == org . mwg . Type . LONG_TO_LONG_ARRAY_MAP ) { //indexed relation nodeToAdd [ key ] = [ ] ; elem . each ( function ( relKey , relIdNode ) { nodeToAdd [ key ] . push ( relIdNode ) ; } ) ; containsRel = true ; } else { throw "Type(" + elemType + ") is not yet managed. Please update the debugger." } } ) ; // if the node contains a relationship, we add them into a global variable to deal with the relationships later if ( containsRel ) { gNodesWithRel . push ( nodeToAdd ) ; } // we sort the nodes per type if ( gNodesPerType [ nodeToAdd . _type ] == null ) { gNodesPerType [ nodeToAdd . _type ] = [ ] ; colorsByNodeType [ nodeToAdd . _type ] = getRandomColor ( ) ; // add the type of the node to the type list and assign a color to the type } gNodesPerType [ nodeToAdd . _type ] . push ( nodeToAdd ) ; // finally we add them to the global array containing all the nodes gAllNodes . push ( nodeToAdd ) ; }
Transform every node from mwg and add them to a global var
@param node
Transform every node from mwg and add them to a global var