-
Notifications
You must be signed in to change notification settings - Fork 607
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
Cannot set property 'order' of undefined #234
Comments
More insight, in the order function Line 29 in 7e050f8
When the initial Line 34 in 7e050f8
However later on on line 52 the Line 52 in 7e050f8
|
How are you building your |
Hi @j6k4m8, I am actually using the Directed Graph Layout from JointJS that uses Dagre. I am actually building a JointJS graph. JointJS is then building a GraphLib graph to pass to Dagre. I am trying to figure out if the issue is with 1) us passing bad data to Joint JS, 2) a bug in JointJS translating into GraphLib, or 3) a bug in Dagre. Mainly I am hoping to understand what could cause undefined to wind up in those arrays, so maybe i could trace backwards and figure it out. Or if there is some validation I can put at some step in the process to detect issues. At the moment, most of the graphs work just fine, but several of them exhibit this behavior. But the error is buried so deeply in Dagre that it is not obvious what the issue might be and where to start looking. |
Some more debugging. In one of the calls to this method: Line 43 in 7e050f8
Several elements in the layering array go from string values to undefined. |
And finally... in this method: function buildLayerMatrix(g) {
var layering = _.map(_.range(maxRank(g) + 1), function() { return []; });
_.each(g.nodes(), function(v) {
var node = g.node(v),
rank = node.rank;
if (!_.isUndefined(rank)) {
layering[rank][node.order] = v;
}
});
return layering;
}
|
to clarify, SOME nodes in the graph are undefined and some are not? Or is it all-or-nothing per graph? |
So in terms of the graph, I don't think the nodes are undefined at all. What is happening is that there is a matrix called function assignOrder(g, layering) {
_.each(layering, function(layer) {
_.each(layer, function(v, i) {
g.node(v).order = i;
});
});
} So because an element in the layering matrix is |
Ah — so just some of the node-lookups are failing. That's what I meant! Sorry, I misspoke — but you still answered my question :) I'm trying to figure out a similar problem right now; I think that there must be some discontinuity (incompatible version updates between libraries, perhaps?) where dagre expects a certain structure to the graph that isn't being fully satisfied by external libraries. Have you tried making a graph of the same size as your real graph, but comprised of a bunch of the same repeated node (with a different ID)? That'll tell you if it's a structural problem with dagre/Joint or some weird corner-case having to do with the attributes of your graph. |
I will have to try that. I have been working on isolating the problem in the source data. I know for example if I take all the edges out of the graph it works just fine. There is a large amount of data so it is somewhat hard to isolate. |
Looking here: Line 29 in 7e050f8
However after this method is called from the layout method Line 35 in 7e050f8
The result is that several nodes do NOT have a rank defined. I think this is partially the cause of the above issue. |
More information.. Prior to calling the nestedGraph method Line 34 in 7e050f8
All the nodes in the graph look something like this: {
"0b7c8847-5ad5-4115-b7a0-cee55295a23c": {width: 300, height: 300}
"0b50f2ad-7697-4392-8a5d-9a2744b9deaa": {width: 300, height: 300}
} After calling the nestingGraph method several new nodes are added to the graph, that look like this: {
"62c2d840-0375-4b24-baf2-4bddba883dbe": {width: 1, height: 1, borderTop: "_bt12391", borderBottom: "_bb12392"},
"64bd51ba-a559-4b00-9c49-fe8a0d1d9212": {width: 1, height: 1, borderTop: "_bt12379", borderBottom: "_bb12380"}
} It is these nodes that wind up with no rank after the {
"cb00a654-4cb8-4bf0-b5c7-73509c33da77": {width: 300, height: 300, rank: -37},
"cbd9fe77-e741-4ea7-a436-271478396aaa": {width: 1, height: 1, borderTop: "_bt23166", borderBottom: "_bb23167"},
"cbd0306c-701d-4ff1-818d-1445f4ddef1f": {width: 300, height: 300, rank: -85},
"cbe818d9-58c3-494d-9685-dd4b3dcbecb9": {width: 300, height: 300, rank: -67},
"cc84afd3-b37b-4940-ab1d-07f48d148dc9": {width: 1, height: 1, borderTop: "_bt23186", borderBottom: "_bb23187"},
"cc449908-b667-42b5-a17b-3917edd95d55": {width: 300, height: 300, rank: -1},
"cd6c78da-b2a6-4b35-8121-ae3c0003fc04": {width: 300, height: 300, rank: -37}
} Node sure if these are creating the problem directly but seems to be relevant. |
One more bit of oddness. In the for (var i = 0, lastBest = 0; lastBest < 4; ++i, ++lastBest) {
sweepLayerGraphs(i % 2 ? downLayerGraphs : upLayerGraphs, i % 4 >= 2);
layering = util.buildLayerMatrix(g);
var cc = crossCount(g, layering);
if (cc < bestCC) {
lastBest = 0;
best = _.cloneDeep(layering);
bestCC = cc;
}
} On the first run, best.filter(layer => layer.indexOf(undefined) >= 0).length = 28
layering.filter(layer => layer.indexOf(undefined) >= 0).length = 0 So somehow the deepClone is resulting in arrays with undefined values. |
It turns out that they layer has indices that are not set.
Lodash is inserting |
Putting this all together here is what is going on in the layout method:
So the interplay of the |
Upon further inspection, when |
After much work, I have been able to reproduce this issue in dagre directly. There is gist that demonstrates the issue. The graph structure is pretty simple. 23 total nodes, 8 of them are parents / containers, and 15 of them are children. There are only 7 edges. There is a source code file that reproduces the issue as well as a visualization of the graph structure in the gist. https://gist.github.com/mmacfadden/2c923a6c7209308745296d489289f316 |
I hit a similar issue, but in my case function assignOrder(g, layering) {
_.forEach(layering, function(layer) {
_.forEach(layer, function(v, i) {
g.node(v).order = i;
});
});
} edit: I recall i saw that on my browser, but when running in cli, v is undefined. So maybe i looked it wrong. |
@mmacfadden thanks to your reproducer and some guesswork i think i found out the problem. Let me explain, the problems seems to be related to the way See a reproducer of what i mean: var _ = require("lodash");
var arr = [];
arr[0] = 0;
arr[1] = 1;
arr[4] = 4;
arr[5] = 5;
console.log(arr);
console.log('for var i in arr:');
for (var i in arr) {
console.log(`arr[${i}] = ${arr[i]}`);
}
console.log('_forEach:');
_.forEach(arr, function(v, i) {
console.log(`arr[${i}] = ${v}`);
}); This yields:
|
@j6k4m8 can you take a look at #234 (comment)?
to
|
I tried with
|
It seems that |
Hm. I'm not sure what the benefit of having |
I did something quick to remove the gaps and shifting the order, but other error appeared after that
I'm not sure if this is related to the fact that we aren't using connected DAG's as needed by the rank algorithm. Reproducer of @mmacfadden is: and the (big) graph (using cose layout) that showed this bug to me is: |
It might be related to the lack of connected DAGs, however, I have several other instances of not-connected DAGs that work. In fact, in my reproducer, removing any one node seems to allow it to work. |
Yes, I have seen the same too, not really sure what the problem might really be, but the fact that the algorithm is for connected DAGs makes me think that it might fail on some non connected DAGs (not sure which ones). We might have to read to check why it needs connected DAGs |
@josejulio, just an aside, but as lovely as that graph looks using a directed algorithm like dagre (like a dragon!), using a spring/force algorithm like webcola or d3-force will bring out more of the symmetry. There is so much repeated structure which is getting squished and tangled in order to put everything in ranks, and it doesn't look like the ranks add meaning. (To the contrary, a lot of edges are pointing upward?) |
thanks for the suggestions @gordonwoodhull |
Any fix for this yet?? |
Having the same issue. |
Having the same issue. |
Having the same issue, but only in a test environment. Not in my box. Can't help but wonder if it has to do with the minified file. |
Fixed it on my end by removing the following options from my Uglify compression options:
as well as enabling parallelization (but I don't think this would be related at all). One of the unsafe flags has to be doing something funny that doesn't play well with dagre. Hopefully this helps someone else ✨ !! |
I am also having this issue. I'm using I'm using dagre Thanks a bunch! EDITS: grammar, included a version number |
I am still having this issue in 2021, any progress on this? |
I've been using this library for a bit and it was working fine, now i suddenly have this same error. Any progress here? |
For people that come here later, at least in my case, I found the issue and it was a really easy fix. When I add a node, I track the host field associated with it and do grouping so that all nodes with the same host are grouped together.
However, I was doing some dummy data and the host field was blank, i.e. |
Why is there no solution in 2022 😭 |
@Revadike, it's likely because this project has no maintainer, as announced in the README. |
## Summary & Motivation Fixes this issue dagrejs/dagre#234 ## How I Tested These Changes I copied the JSON of a graph from a customer who was hitting this error and saw that the graph was able to correctly render with this patch.
We just ran into this problem (May 2024). I'm a bit surprised this has been an active issue for just over 6 years. Any chance the authoring team can make a decision to Won't Fix or hopefully put in the queue to address. |
we ended up using https://github.com/kieler/elkjs because of this and never looked back. |
We moved over to elkjs yesterday. |
For anyone still interested in a workaround for this bug. I did a bit of digging, and it turns out that non-consecutive diff --git a/lib/order/index.js b/lib/order/index.js
--- a/lib/order/index.js
+++ b/lib/order/index.js
@@ -41,6 +41,10 @@ function order(g) {
sweepLayerGraphs(i % 2 ? downLayerGraphs : upLayerGraphs, i % 4 >= 2);
layering = util.buildLayerMatrix(g);
+
+ const orderIsBroken = layering.some(layer => layer.length !== Object.keys(layer).length);
+ if (orderIsBroken) continue;
+
var cc = crossCount(g, layering);
if (cc < bestCC) {
lastBest = 0; |
I believe this PR #304 proposed something similar to you @ul . Also I tried applying your changes, util.ts:46 Uncaught (in promise) TypeError: Cannot set properties of undefined (setting 'rank')
at r (util.ts:46:19)
at util.ts:39:14
at Array.map (<anonymous>)
at r (util.ts:34:42)
at util.ts:39:14
at Array.map (<anonymous>)
at r (util.ts:34:42)
at Array.forEach (<anonymous>)
at Ff (util.ts:49:15)
at Rn (network-simplex.ts:51:3) This is still an issue. |
@adminy Stack trace is different, it's likely a different issue that was hidden by this one. Do you have a minimal reproducible example? I'm keen to look into it. |
Greetings. I am seeing the following error:
After doing some debugging I see the following:
In this function
layer
is an array, seemingly containing strings (maybe id's). When this error crops up, it seems that several items in thelayer
array areundefined
. Thereforeg.node(undefined)
also returns undefined and produces the error.I am currently going through our code to see what might be causing the issue, but was hoping that maybe the authors had some insight into what I might look for.
The text was updated successfully, but these errors were encountered: