Open artarf opened 10 years ago
Here is suggested fix:
diff --git a/lib/render.js b/lib/render.js
index 1610b89..a36aa8e 100644
--- a/lib/render.js
+++ b/lib/render.js
@@ -128,6 +128,10 @@ function preProcessGraph(g) {
g.edges().forEach(function(e) {
var edge = g.edge(e);
+ if (typeof edge === "undefined") {
+ g.setEdge(e, {});
+ edge = g.edge(e);
+ }
if (!_.has(edge, "label")) { edge.label = ""; }
_.defaults(edge, EDGE_DEFAULT_ATTRS);
});
Thank you, this helped me to resolve problem with this library.
just ran into this problem... and this helped me solve it.
I also run into this problem. The issue for me here is that the diagnostics here is nonexistent. All I get is TypeError: Cannot set property 'label' of undefined
.
In my case this is always an error on my side. However, I would like to see what am I trying connect to a missing node. I suggest adding validation in the code to show some info (e.g. dump the other node id).
My
nodes
has no "undefined" value :(fixed
But the graph is not what I want.
--- Got it:
Because I setEdge
's value is "undefined", fixed it.
This happened to me too and this issue helped solve it, thank you! Long story short, don't forget to call setDefaultEdgeLabel
even for a graph that was created using dagre.graphlib.json.read
. Like this:
let graph;
if (localStorage.getItem('dagre')) {
graph = dagre.graphlib.json.read(JSON.parse(localStorage.getItem('dagre')));
}
else {
graph = new dagre.graphlib.Graph();
graph.setGraph({});
- graph.setDefaultEdgeLabel(() => ({}));
graph.setNode('Root', measure('Root'));
dagre.layout(graph);
localStorage.setItem('dagre', JSON.stringify(dagre.graphlib.json.write(graph)));
}
+graph.setDefaultEdgeLabel(() => ({}));
This ensures that setDefaultEdgeLabel
is called for newly created as well as JSON-reconstructed graphs.
Here's unit test I used:
This situation occurs at least when graph is deserialised using
graphlib.json.read()
. It callsGraph.setEdge()
with object and value (even if the value isundefined
).