real bounding box (for circles and ellipses)

This commit is contained in:
Nils Schneider 2012-06-07 23:35:32 +02:00
parent 80c2cd394b
commit 5ac77b9411

View file

@ -182,10 +182,12 @@ force.on("tick", function() {
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
var o = nodes[i] var o = nodes[i]
if (!o.fixed) { if (!o.fixed) {
if (o.x < 10) o.x = 10 node = d3.select(document.getElementById(o.id))[0][0]
if (o.x > size[0] - 10) o.x = size[0] - 10 box = bounding_box(node)
if (o.y < 10) o.y = 10 if (o.x < box.rx) o.x = box.rx
if (o.y > size[1] - 10) o.y = size[1] - 10 if (o.x > size[0] - box.rx) o.x = size[0] - box.rx
if (o.y < box.ry) o.y = box.ry
if (o.y > size[1] - box.ry) o.y = size[1] - box.ry
} }
} }
@ -357,6 +359,9 @@ function update() {
) )
var nodeEnter = node.enter().append("g") var nodeEnter = node.enter().append("g")
.attr("id", function (d) {
return d.id
})
.attr("class", "node") .attr("class", "node")
.on("mouseover", fade(.2)) .on("mouseover", fade(.2))
.on("mouseout", fade(1)) .on("mouseout", fade(1))
@ -441,6 +446,24 @@ function update() {
show_node(hashstr) show_node(hashstr)
} }
function bounding_box(d) {
var c = d.firstChild
var r = {}
switch(c.nodeName) {
case "ellipse":
r.rx = c.rx.animVal.value
r.ry = c.ry.animVal.value
break;
case "circle":
r.rx = r.rz = c.r.animVal.value
break;
default:
r.rx = r.ry = 10
}
return r
}
reload() reload()
var timer = window.setInterval(reload, 30000) var timer = window.setInterval(reload, 30000)