tgdwyer / WebCola

Javascript constraint-based graph layout
http://marvl.infotech.monash.edu/webcola/
MIT License
2.01k stars 257 forks source link

routeEdge() leads to "TypeError: v is undefined" #256

Open codethief opened 6 years ago

codethief commented 6 years ago

I'm using WebCola 3.3.8 and am not able to get edge routing to work. I always end up with:

TypeError: v is undefined Stack trace: ../../../../webcola/dist/src/geom.js/TangentVisibilityGraph.prototype.addEdgeIfVisible ../../../../webcola/dist/src/geom.js/TangentVisibilityGraph.prototype.addPoint ../../../../webcola/dist/src/layout.js/Layout.prototype.routeEdge

This is what my TypeScript code looks like (roughly):

class Node implements cola.InputNode {
    public x: number;
    public y: number;
    public height: number;
    public width: number;
    public fixed: number = 0;
    public fixedWeight: number;
}

class Edge {
    public source: any;
    public target: any;
}

let nodes: Node[] = [ /* … */ ];
let edges: Edge[] = [ /* … */ ];
let constraints = [ /* … */ ];

let webcola = cola.d3adaptor(d3);
webcola
    .size([500, 500])
    .avoidOverlaps(true)
    .constraints(constraints)
    .symmetricDiffLinkLengths(120, 1)
    .handleDisconnected(true)
    .nodes(nodes)
    .links(edges)
    .start(30, 30, 30);

let d3edges = d3.select(".edges").selectAll(".edge").data(edges);
let lineFunction = d3.line<any>().curve(d3.curveBasis)
    .x(d => d.x)
    .y(d => d.y);

webcola.on("end", () => {
    webcola.prepareEdgeRouting();
    d3edges.attr("d", edge => lineFunction(webcola.routeEdge(edge, 0, undefined))); 
});

I'd be very grateful for any pointers as to what I'm doing wrong (if I am).

PS: It would be extremely helpful if the return type of routeEdge() was documented.

PPS: How come the end callback ends up being called in an infinite loop if the callback throws an error like the one above? This causes an extreme CPU load and makes it almost impossible to open the browser console / debug the issue. (I tried it in both Firefox and Chromium.)

nfeldman-at-onshape commented 5 years ago

I've encountered the same error. Did you ever find a solution?

codethief commented 5 years ago

Unfortunately not, no :(