strathausen / dracula

JavaScript layout and representation of connected graphs.
https://www.graphdracula.net
MIT License
834 stars 132 forks source link

No edges between rectangles #18

Closed kuzeko closed 11 years ago

kuzeko commented 11 years ago

When adding edges between nodes with text inside them, if one of the two is a rect the edge won't show up.

I tracked the problem down to the graffle file where getBBox is not working for the set passed as input to the Connection function.

Not sure if it may be due also to a RaphalelJs bug.

The custom rendered I'm using is :

filledRenderer : function(r, n) {
        var frame = {};
        var label = {};
        if(typeof n.round === 'undefined' || !n.round) {
            frame = r.rect(n.point[0], n.point[1], 90, 30);
            label = r.text(n.point[0]+45, n.point[1]+15, n.label);
        } else {
            frame = r.ellipse(n.point[0], n.point[1], 50, 18);
            label = r.text(n.point[0], n.point[1], n.label);
        }
        frame.attr({"fill": "#69c", "stroke-width": 1, r : "5px"});
        var set = r.set()
          .push(frame)
          .push(label);
        return set;
    }
monomon commented 11 years ago

Why do you initialize frame and label to empty objects? I wouldn't.. just set them to undefined if you want to. Otherwise seems fine. Have you tried to debug and see what "set" is at the end? How many items does it contain?

kuzeko commented 11 years ago

Apart from that detail of object initialisation.

Here is a demo on JsBin http://jsbin.com/uhumip/2/

the Set contains 2 objects, the label and the figure.

monomon commented 11 years ago

The problem is in line 65 of your code frame.attr({"fill": "#69c", "stroke-width": 1, r : "5px"}); "r" should be a number, not a string. That is why only the rect is failing.

You could say it is a raphael bug though, because they should be vetting their input (that's a general problem of html/css, it is horrific to have to parse and build strings with measures all the time).

kuzeko commented 11 years ago

What a moron I am!

Sorry & thanks!

monomon commented 11 years ago

Haha no problem. I wouldn't have known that if I was writing, either.

I recently started learning debugging, and it has been very useful.