Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get Node by ID #467

Open
JBatUN opened this issue Feb 13, 2020 · 0 comments
Open

Get Node by ID #467

JBatUN opened this issue Feb 13, 2020 · 0 comments

Comments

@JBatUN
Copy link

JBatUN commented Feb 13, 2020

I'm writing an auto-layouter that transforms the JSON export format into a graph structure. The structure is then run through a layouter (GraphVis, etc.) to generate position coordinates for each node in the patch. The idea would be to then use the positions to issue move commands to reposition each of the nodes.

So far creating the graph structure has been straight forward. But I can't figure out out to get a node by id to issue the move event.

Here's the current code to get the idea:

function autoLayout() {

var nodes = [];
var edges = [];

function getProject() {
    // Use export json parse format to generate
    // graph structure from events
    return project();
}

function createGraph() {

    let project = getProject();
    let pgraph = project.commands
    console.log(pgraph)

    let o = 0;
    let olen = pgraph.length
    for ( o; o < olen; o++ ) {

        if ( pgraph[o].event === 'patch/add-node' && pgraph[o].nodeType !== 'util/nodelist' ) {
            let node = new Object();
            node.id = pgraph[o].nodeId;
            node.title = pgraph[o].nodeTitle;
            nodes.push(node);
        }
        
        if ( pgraph[o].event === 'node/add-outlet' ) {
            let edge = new Object();
            edge.source = pgraph[o].nodeId;

                for ( p = o+1; p < olen; p++ ) {
                    if ( pgraph[p].event === 'node/add-outlet' ) {
                        edge.target = pgraph[p].nodeId;
                        break;
                    }
                }

            if ( H.Obj.has_own(edge, 'target') ) {
                edges.push(edge)
            }
        }
    }

    console.log(nodes)
    console.log(edges)
}

function runLayouter() {

    // THIS IS THE MISSING PIECE
    **let n = Rpd.getNodeById(id);**
    n.move(pos_x, pos_y)
}

function createMoves() {



}

createGraph()

}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant