Cannot get Dagre to run

419 views
Skip to first unread message

Eason

unread,
Oct 8, 2014, 2:54:35 AM10/8/14
to da...@googlegroups.com

and I get this error once when I run it: 

 Cannot set property 'width' of undefined (http://localhost:8080/dagre/dagre.js:475)

I tried to debug and I found inputGraph.graph() inside function updateInputGraph is undefined
in line 475: 
inputGraph.graph().width = layoutGraph.graph().width;

This is strange that I followed the tutorial and cannot get it run.
Can someone help me?

Chris Pettitt

unread,
Oct 8, 2014, 9:07:08 AM10/8/14
to Eason, da...@googlegroups.com
The example in the wiki has been updated - thanks for pointing out the problem. Immediately after creating the graph, set the graph label to an empty object:

// Set an object for the graph label
g.setGraph({});

- Chris


--
You received this message because you are subscribed to the Google Groups "dagre" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dagre+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Eason

unread,
Oct 8, 2014, 10:39:50 PM10/8/14
to Chris Pettitt, da...@googlegroups.com
Thanks for the quick reply and quick update, it works!

And your reply solved my another question so that now I know g.setGraph({} is the place to set layout configuration.
It would be good to indicate this out in your great wiki too.

And I still have one question left, 
is there a formal way to get all nodes data out of graph instead of graph._nodes ?

Thanks

Chris Pettitt

unread,
Oct 8, 2014, 10:57:26 PM10/8/14
to Eason, da...@googlegroups.com
If you want to get the data out as JSON, you can use dagre.graphlib.json.write:

console.log(JSON.stringify(dagre.graphlib.json.write(g), null, 2))
{
  "options": {
    "directed": true,
    "multigraph": false,
    "compound": false
  },
  "nodes": [
    {
      "v": "1",
      "value": {
        "foo": "bar"
      }
    },
    {
      "v": "2",
      "value": {
        "foo": "baz"
      }
    }
  ],
  "edges": []
}

The JSON format can also be read back in.

If you just want to iterate over the nodes and get their values:

g.nodes().forEach(function(v) { console.log(v, g.node(v)); })
1 { foo: 'bar' }
2 { foo: 'baz' }

Eason

unread,
Oct 8, 2014, 11:32:33 PM10/8/14
to Chris Pettitt, da...@googlegroups.com

2014-10-09 10:57 GMT+08:00 Chris Pettitt <ch...@samsarin.com>:
dagre.graphlib.json.write(g)

Awesome, json is exactly what I want. 
Thank you very much for such a great lib!

Reply all
Reply to author
Forward
0 new messages