Skip to content

Automatic layout does not work on hierarchical diagrams with links with parent #455

Closed
@javitank

Description

@javitank

I have created a demo on https://jsfiddle.net/0nns5ca4/4/

The demo has the same code as Discrete Event System Specification (http://resources.jointjs.com/demos/devs) but adding the line:

joint.layout.DirectedGraph.layout(graph);

Automatic layout does not work and it gives the following error in dagre.js library:

Uncaught TypeError: Cannot set property 'rank' of undefined

Looking at the full code of dagre.js the error happens on the line return (label.rank = rank); because label is undefined in the following function:

function longestPath(g) {
  var visited = {};

  function dfs(v) {
    var label = g.node(v);
    if (_.has(visited, v)) {
      return label.rank;
    }
    visited[v] = true;

    var rank = _.min(_.map(g.outEdges(v), function(e) {
      return dfs(e.w) - g.edge(e).minlen;
    }));

    if (rank === Number.POSITIVE_INFINITY) {
      rank = 0;
    }

    return (label.rank = rank);
  }

  _.each(g.sources(), dfs);
}

I think the problem is related to any link with parent element. If you remove this links the automatic layout works ok.

Sorry if this is not a jointjs issue.
I'm not sure if is a problem with the graph that jointjs send to dagre or a problem with dagre itself or simply this use case is not supported.

I have also written a comment on David Durman blog (http://disq.us/p/1dbs6fe) on a related issue.

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions