tgdwyer / WebCola

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

assertion failed in chrome but not firefox #130

Closed shortorian closed 9 years ago

shortorian commented 9 years ago

I'm trying to set up a network graph whose groups can expand or collapse on click, similar to GerHobbelt's example for d3.

My example seems to run fine with seven nodes, but if I try a more complex network I get an assertion failed error. In the non-minified cola.js, this occurs on line 1479. I'm really not sure how to go about resolving this problem and I haven't come up with a good way to simplify my script to demonstrate it, so here's a link to an html document with my complete script. That's a working version which references this JSON network. An example network that doesn't work is here, or you should be able to plug in the standard miserables.json

Any advice on this would be helpful; thanks!

Update: I primarily use the Chrome browser but I just tried the script above in Friefox and I don't get any errors. I'm using Chrome 44.0.2403.125 and Firefox 39.0. The behavior is consistent in both browsers (assertion failed in Chrome, no errors in Firefox) regardless of whether I use minified or non-minified versions of cola and d3. I can stick with Firefox for now but I'd like to know what I'm doing wrong if anyone has the time to give me some advice.

tgdwyer commented 9 years ago

if you can set it up in a standalone jsfiddle I'll try to debug for you

On 3 August 2015 at 19:25, shortda notifications@github.com wrote:

I'm trying to set up a network graph whose groups can expand or collapse on click, similar to GerHobbelt's example http://bl.ocks.org/GerHobbelt/3071239 for d3.

My example seems to run fine with seven nodes, but if I try a more complex network I get an assertion failed error. In the non-minified cola.js, this occurs on line 1479. I'm really not sure how to go about resolving this problem and I haven't come up with a good way to simplify my script to demonstrate it, so here's a link https://github.com/shortda/colaCables/blob/master/colaCollapse.html to an html document with my complete script. That's a working version which references this JSON network https://github.com/shortda/colaCables/blob/master/cableTest.json. An example network that doesn't work is here https://github.com/shortda/colaCables/blob/master/cables.json, or you should be able to plug in the standard miserables.json

Any advice on this would be helpful; thanks!

— Reply to this email directly or view it on GitHub https://github.com/tgdwyer/WebCola/issues/130.

Dr Tim Dwyer BSc BCS(Hons) PhD Senior Lecturer and Larkins Fellow Caulfield School of Information Technology Mobile: 0481 240 767 (from overseas: +61 481 240 767)

shortorian commented 9 years ago

Thanks! JSFiddle is here, and the issue above looks the same as when I host it locally.

tgdwyer commented 9 years ago

The problem was because you were not specifying bounds for the nodes. I added:

net.nodes.forEach(function (v) { v.width = v.height = drad * 2; });

right before the call to setup layout and the assertion went away. new fiddle

As an added bonus, your node circles will not overlap each others' bounding boxes, or the bounds of groups :-)

shortorian commented 9 years ago

Thanks for your quick update! However, I'm confused: I thought I took care of the node sizes in the d3.json block via graph.nodes.forEach(function(n) { n.width = nodeSize[0]; n.height = nodeSize[1]; }); This is around line 320 in the fiddle. Why didn't my first attempt to set node bounds work?

tgdwyer commented 9 years ago

It seems you don't copy width and height across to your "displayNodes" in the netork() function.

shortorian commented 9 years ago

I guess I don't understand how the referencing works; I thought that by getting editing the JSON nodes, then getting a reference to them in network() and pushing that reference to displayNodes I wouldn't need to worry about copying individual attributes. Thanks again!

manacoa commented 9 years ago

I'm also getting this error with Chrome and not Firefox. It happens about 50% of the times I run the layout. width and height are definitely set ok on the nodes before calling start().

It''s not practical to publish the code (it's huge!) but perhaps you could give me a clue for other problems to look for? Any other essential attributes?

Thanks!

PS. I should also note that it appears at around 7 nodes. Less than that and there are no errors (and it doesn't matter which node I remove).